fsm/engine.c > using the console to test a thread (or worker) prototype (back 30 years ago)
This commit is contained in:
parent
270b408d28
commit
924968ca26
|
@ -1,5 +1,5 @@
|
||||||
# Fichier de commande pour gnuplot
|
# Fichier de commande pour gnuplot
|
||||||
# En ligne de commande : load "a_main.plt"
|
# En ligne de commande : load "data/gnuplot/a_cmd.plt"
|
||||||
#
|
#
|
||||||
set zeroaxis
|
set zeroaxis
|
||||||
plot cos(x),\
|
plot cos(x),\
|
|
@ -1,3 +1,5 @@
|
||||||
|
-7.000 -0.657
|
||||||
|
-6.000 0.279
|
||||||
-5.000 0.959
|
-5.000 0.959
|
||||||
-4.000 0.757
|
-4.000 0.757
|
||||||
-3.000 -0.141
|
-3.000 -0.141
|
||||||
|
@ -9,3 +11,5 @@
|
||||||
3.000 0.141
|
3.000 0.141
|
||||||
4.000 -0.757
|
4.000 -0.757
|
||||||
5.000 -0.959
|
5.000 -0.959
|
||||||
|
6.000 -0.279
|
||||||
|
7.000 0.657
|
|
@ -100,6 +100,9 @@ void fsm_tools_list_test(); // def: measure/manage; call: measure/manage;
|
||||||
void fsm_rule_trig_measure (int rule_id, int object_id, int measure_id);
|
void fsm_rule_trig_measure (int rule_id, int object_id, int measure_id);
|
||||||
|
|
||||||
|
|
||||||
|
// --------------------------------------------------------------- WIP ------
|
||||||
|
void fsm_engine_init();
|
||||||
|
|
||||||
// --------------------------------------------------------------- WIP ------
|
// --------------------------------------------------------------- WIP ------
|
||||||
int fsm_journal_push (journal **jj, int v_value);
|
int fsm_journal_push (journal **jj, int v_value);
|
||||||
int fsm_journal_pop (journal **jj);
|
int fsm_journal_pop (journal **jj);
|
||||||
|
@ -110,7 +113,13 @@ void fsm_journal_seek (journal *jj, int vv);
|
||||||
|
|
||||||
|
|
||||||
// --------------------------------------------------------------- WIP ------
|
// --------------------------------------------------------------- WIP ------
|
||||||
void fsm_data_new_insert (data_list d, int *p_data);
|
void fsm_add_data (data_list d, int *p_data, int *p_target);
|
||||||
void fsm_data_new_concat (data_list d, int *p_data, int *p_target);
|
int fsm_get_data (data_list d, int from, int to);
|
||||||
void *fsm_data_get(); // (data_list d, int from, int to);
|
void fsm_remove_data (data_list d, int *p_data);
|
||||||
void fsm_data_erase (data_list d, int from, int to);
|
|
||||||
|
|
||||||
|
// --------------------------------------------------------------- WIP ------
|
||||||
|
void fsm_disp_add_chart (disp_list d, int *p_chart);
|
||||||
|
int fsm_disp_get_chart (disp_list d, int from, int to);
|
||||||
|
void fsm_disp_remove_chart (disp_list d, int *p_chart);
|
||||||
|
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
/* ------------------------------------ */
|
|
||||||
double H(
|
|
||||||
double x)
|
|
||||||
{
|
|
||||||
if(x>0.)return(1.);
|
|
||||||
else return(0.);
|
|
||||||
}
|
|
||||||
/* ------------------------------------ */
|
|
|
@ -1,52 +0,0 @@
|
||||||
/* --------------------------------------------------------------- */
|
|
||||||
/* gnuplot : xdef.h */
|
|
||||||
/* https://fr.wikibooks.org/wiki/Mathc_gnuplot/Fichiers_h_:_xdef */
|
|
||||||
/* --------------------------------------------------------------- */
|
|
||||||
|
|
||||||
#ifndef PI
|
|
||||||
#define PI 3.14159265359
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* ------------------------------------ */
|
|
||||||
void clrscrn(void)
|
|
||||||
{
|
|
||||||
printf("\n\n\n\n\n\n\n\n\n\n\n"
|
|
||||||
"\n\n\n\n\n\n\n\n\n\n\n"
|
|
||||||
"\n\n\n\n\n\n\n\n\n\n\n");
|
|
||||||
}
|
|
||||||
/* ------------------------------------ */
|
|
||||||
void Pause(void)
|
|
||||||
{
|
|
||||||
int i=300;
|
|
||||||
int j;
|
|
||||||
|
|
||||||
while(--i){j=600000;while(--j);}
|
|
||||||
}
|
|
||||||
/* ------------------------------------ */
|
|
||||||
/* First file name : */
|
|
||||||
/* */
|
|
||||||
/* char fname[]= "a_paaa"; */
|
|
||||||
/* ------------------------------------ */
|
|
||||||
char *NewName(
|
|
||||||
char *name
|
|
||||||
)
|
|
||||||
{
|
|
||||||
if(name[5]<'z')
|
|
||||||
|
|
||||||
++name[5];
|
|
||||||
|
|
||||||
else if(name[4]<'z')
|
|
||||||
{
|
|
||||||
name[5]='a';
|
|
||||||
++name[4];
|
|
||||||
}
|
|
||||||
else if(name[3]<'z')
|
|
||||||
{
|
|
||||||
name[5]='a';
|
|
||||||
name[4]='a';
|
|
||||||
++name[3];
|
|
||||||
}
|
|
||||||
|
|
||||||
return(name);
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,32 +0,0 @@
|
||||||
/* ------------------------------------------------------------------ */
|
|
||||||
/* gnuplot : xfx_x.h */
|
|
||||||
/* https://fr.wikibooks.org/wiki/Mathc_gnuplot/Fichiers_h_:_xfx_x */
|
|
||||||
/* ------------------------------------------------------------------ */
|
|
||||||
|
|
||||||
/* ------------------------------------
|
|
||||||
f'(a) = f(a+h) - f(a-h)
|
|
||||||
-------------
|
|
||||||
2h
|
|
||||||
---------------------------------- */
|
|
||||||
double fx_x(
|
|
||||||
double (*P_f)(double x),
|
|
||||||
double a,
|
|
||||||
double h
|
|
||||||
)
|
|
||||||
{
|
|
||||||
return( ( ((*P_f)(a+h))-((*P_f)(a-h)) ) / (2.*h) );
|
|
||||||
}
|
|
||||||
/* ------------------------------------
|
|
||||||
f''(a) = f(a+h) - 2 f(a) + f(a-h)
|
|
||||||
----------------------
|
|
||||||
h**2
|
|
||||||
---------------------------------- */
|
|
||||||
double fx_xx(
|
|
||||||
double (*P_f)(double x),
|
|
||||||
double a,
|
|
||||||
double h
|
|
||||||
)
|
|
||||||
{
|
|
||||||
return( (((*P_f)(a+h))-2*((*P_f)(a))+((*P_f)(a-h))) / (h*h) );
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,70 +0,0 @@
|
||||||
/* ------------------------------------------------------------------ */
|
|
||||||
/* gnuplot : xfxy_x.h */
|
|
||||||
/* https://fr.wikibooks.org/wiki/Mathc_gnuplot/Fichiers_h_:_xfxy_x */
|
|
||||||
/* ------------------------------------------------------------------ */
|
|
||||||
|
|
||||||
#include "xspv.h"
|
|
||||||
|
|
||||||
double fxy_x(
|
|
||||||
double (*P_f)(double x, double y),
|
|
||||||
double h,
|
|
||||||
point2d p
|
|
||||||
)
|
|
||||||
{
|
|
||||||
double tplsh;
|
|
||||||
double tmnsh;
|
|
||||||
|
|
||||||
tplsh = ((*P_f)(p.x+h,p.y));
|
|
||||||
tmnsh = ((*P_f)(p.x-h,p.y));
|
|
||||||
|
|
||||||
return(( tplsh-tmnsh)/(2.*h) );
|
|
||||||
}
|
|
||||||
/* ------------------------------------ */
|
|
||||||
double fxy_y(
|
|
||||||
double (*P_f)(double x, double y),
|
|
||||||
double h,
|
|
||||||
point2d p
|
|
||||||
)
|
|
||||||
{
|
|
||||||
double tplsh;
|
|
||||||
double tmnsh;
|
|
||||||
|
|
||||||
tplsh = ((*P_f)(p.x,p.y+h));
|
|
||||||
tmnsh = ((*P_f)(p.x,p.y-h));
|
|
||||||
|
|
||||||
return(( tplsh-tmnsh)/(2.*h) );
|
|
||||||
}
|
|
||||||
/* ------------------------------------ */
|
|
||||||
double fxy_xx(
|
|
||||||
double (*P_f)(double x, double y),
|
|
||||||
double h,
|
|
||||||
point2d p
|
|
||||||
)
|
|
||||||
{
|
|
||||||
double t;
|
|
||||||
double tplsh;
|
|
||||||
double tmnsh;
|
|
||||||
|
|
||||||
t = ((*P_f)(p.x , p.y));
|
|
||||||
tplsh = ((*P_f)(p.x+h, p.y));
|
|
||||||
tmnsh = ((*P_f)(p.x-h, p.y));
|
|
||||||
|
|
||||||
return( (tplsh-2*t+tmnsh)/(h*h) );
|
|
||||||
}
|
|
||||||
/* ------------------------------------ */
|
|
||||||
double fxy_yy(
|
|
||||||
double (*P_f)(double x, double y),
|
|
||||||
double h,
|
|
||||||
point2d p
|
|
||||||
)
|
|
||||||
{
|
|
||||||
double t;
|
|
||||||
double tplsh;
|
|
||||||
double tmnsh;
|
|
||||||
|
|
||||||
t = ((*P_f)(p.x, p.y ));
|
|
||||||
tplsh = ((*P_f)(p.x, p.y+h));
|
|
||||||
tmnsh = ((*P_f)(p.x, p.y-h));
|
|
||||||
|
|
||||||
return( (tplsh-2*t+tmnsh)/(h*h) );
|
|
||||||
}
|
|
|
@ -1,51 +0,0 @@
|
||||||
/* ------------------------------------------------------------------ */
|
|
||||||
/* gnuplot : xfxyz_x.h */
|
|
||||||
/* https://fr.wikibooks.org/wiki/Mathc_gnuplot/Fichiers_h_:_xfxyz_x */
|
|
||||||
/* ------------------------------------------------------------------ */
|
|
||||||
|
|
||||||
#include "xspv.h"
|
|
||||||
|
|
||||||
double fxyz_x(
|
|
||||||
double (*P_f)(double x, double y, double z),
|
|
||||||
double h,
|
|
||||||
point3d p
|
|
||||||
)
|
|
||||||
{
|
|
||||||
double tplsh;
|
|
||||||
double tmnsh;
|
|
||||||
|
|
||||||
tplsh = ((*P_f)(p.x+h,p.y,p.z));
|
|
||||||
tmnsh = ((*P_f)(p.x-h,p.y,p.z));
|
|
||||||
|
|
||||||
return(( tplsh-tmnsh)/(2.*h) );
|
|
||||||
}
|
|
||||||
/* ------------------------------------ */
|
|
||||||
double fxyz_y(
|
|
||||||
double (*P_f)(double x, double y, double z),
|
|
||||||
double h,
|
|
||||||
point3d p
|
|
||||||
)
|
|
||||||
{
|
|
||||||
double tplsh;
|
|
||||||
double tmnsh;
|
|
||||||
|
|
||||||
tplsh = ((*P_f)(p.x,p.y+h,p.z));
|
|
||||||
tmnsh = ((*P_f)(p.x,p.y-h,p.z));
|
|
||||||
|
|
||||||
return(( tplsh-tmnsh)/(2.*h) );
|
|
||||||
}
|
|
||||||
/* ------------------------------------ */
|
|
||||||
double fxyz_z(
|
|
||||||
double (*P_f)(double x, double y, double z),
|
|
||||||
double h,
|
|
||||||
point3d p
|
|
||||||
)
|
|
||||||
{
|
|
||||||
double tplsh;
|
|
||||||
double tmnsh;
|
|
||||||
|
|
||||||
tplsh = ((*P_f)(p.x,p.y,p.z+h));
|
|
||||||
tmnsh = ((*P_f)(p.x,p.y,p.z-h));
|
|
||||||
|
|
||||||
return(( tplsh-tmnsh)/(2.*h) );
|
|
||||||
}
|
|
|
@ -1,70 +0,0 @@
|
||||||
/* --------------------------------------------------------------- */
|
|
||||||
/* gnuplot : xplt.h */
|
|
||||||
/* https://fr.wikibooks.org/wiki/Mathc_gnuplot/Fichiers_h_:_xplt */
|
|
||||||
/* --------------------------------------------------------------- */
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
double xmini; double xmaxi;
|
|
||||||
double ymini; double ymaxi;
|
|
||||||
|
|
||||||
}W_Ctrl, *PW_Ctrl;
|
|
||||||
/* ------------------------------------ */
|
|
||||||
W_Ctrl i_WGnuplot(
|
|
||||||
double xmini, double xmaxi,
|
|
||||||
double ymini, double ymaxi
|
|
||||||
)
|
|
||||||
{
|
|
||||||
W_Ctrl w = {xmini,xmaxi,ymini,ymaxi};
|
|
||||||
|
|
||||||
return (w);}
|
|
||||||
/* ------------------------------------ */
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
double xmini; double xmaxi;
|
|
||||||
double ymini; double ymaxi;
|
|
||||||
double zmini; double zmaxi;
|
|
||||||
|
|
||||||
}Ws_Ctrl, *PWs_Ctrl;
|
|
||||||
/* ------------------------------------ */
|
|
||||||
Ws_Ctrl i_WsGnuplot(
|
|
||||||
double xmini, double xmaxi,
|
|
||||||
double ymini, double ymaxi,
|
|
||||||
double zmini, double zmaxi
|
|
||||||
)
|
|
||||||
{
|
|
||||||
Ws_Ctrl w = {xmini,xmaxi,ymini,ymaxi,zmini,zmaxi};
|
|
||||||
|
|
||||||
return (w);}
|
|
||||||
/* ------------------------------------ */
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
double rot_x; double rot_z;
|
|
||||||
double scale; double scale_z;
|
|
||||||
|
|
||||||
}View_Ctrl, *PView_Ctrl;
|
|
||||||
/* ------------------------------------ */
|
|
||||||
View_Ctrl i_VGnuplot(
|
|
||||||
double rot_x, double rot_z,
|
|
||||||
double scale, double scale_z
|
|
||||||
)
|
|
||||||
{
|
|
||||||
View_Ctrl V = {rot_x,rot_z,scale_z,scale_z};
|
|
||||||
|
|
||||||
return (V);}
|
|
||||||
/* ------------------------------------ */
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
double mini; double maxi;
|
|
||||||
double step;
|
|
||||||
|
|
||||||
}t_Ctrl, *Pt_Ctrl;
|
|
||||||
/* ------------------------------------ */
|
|
||||||
t_Ctrl i_time(
|
|
||||||
double mini, double maxi,
|
|
||||||
double step
|
|
||||||
)
|
|
||||||
{
|
|
||||||
t_Ctrl t = {mini,maxi,step};
|
|
||||||
|
|
||||||
return (t);}
|
|
|
@ -1,60 +0,0 @@
|
||||||
/* --------------------------------------------------------------- */
|
|
||||||
/* gnuplot : xspv.h */
|
|
||||||
/* https://fr.wikibooks.org/wiki/Mathc_gnuplot/Fichiers_h_:_xspv */
|
|
||||||
/* --------------------------------------------------------------- */
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
double x; double y;
|
|
||||||
|
|
||||||
}point2d, *Ppoint2d;
|
|
||||||
/* ------------------------------------ */
|
|
||||||
point2d i_point2d(
|
|
||||||
double x, double y
|
|
||||||
)
|
|
||||||
{
|
|
||||||
point2d p = {x,y};
|
|
||||||
|
|
||||||
return (p);}
|
|
||||||
/* ------------------------------------ */
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
double x; double y; double z;
|
|
||||||
|
|
||||||
}point3d, *Ppoint3d;
|
|
||||||
/* ------------------------------------ */
|
|
||||||
point3d i_point3d(
|
|
||||||
double x, double y, double z
|
|
||||||
)
|
|
||||||
{
|
|
||||||
point3d p = {x,y,z};
|
|
||||||
|
|
||||||
return (p);}
|
|
||||||
/* ------------------------------------ */
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
double i; double j;
|
|
||||||
|
|
||||||
}vector2d, *Pvector2d;
|
|
||||||
/* ------------------------------------ */
|
|
||||||
vector2d i_vector2d(
|
|
||||||
double i, double j
|
|
||||||
)
|
|
||||||
{
|
|
||||||
vector2d v = {i,j};
|
|
||||||
|
|
||||||
return (v);}
|
|
||||||
/* ------------------------------------ */
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
double i; double j; double k;
|
|
||||||
|
|
||||||
}vector3d, *Pvector3d;
|
|
||||||
/* ------------------------------------ */
|
|
||||||
vector3d i_vector3d(
|
|
||||||
double i, double j, double k
|
|
||||||
)
|
|
||||||
{
|
|
||||||
vector3d v = {i,j,k};
|
|
||||||
|
|
||||||
return (v);}
|
|
|
@ -60,10 +60,13 @@
|
||||||
|
|
||||||
void fsm_init()
|
void fsm_init()
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
fsm_measures_list_init();
|
fsm_measures_list_init();
|
||||||
fsm_results_list_init();
|
fsm_results_list_init();
|
||||||
fsm_displayable_list_init();
|
fsm_displayable_list_init();
|
||||||
fsm_preferences_init();
|
fsm_preferences_init();
|
||||||
|
*/
|
||||||
|
fsm_engine_init(); // pour avancer, en attendant... 😇️
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,92 @@
|
||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Gem-graph client *
|
||||||
|
* Finite State Machine Engine *
|
||||||
|
* *
|
||||||
|
* Copyright © 2024 Libre en Communs <contact@a-lec.org> *
|
||||||
|
* Copyright © 2024 Jean Sirmai <jean@a-lec.org> *
|
||||||
|
* *
|
||||||
|
* This file is part of Gem-graph. *
|
||||||
|
* *
|
||||||
|
* This program is free software: you can redistribute it and/or modify it *
|
||||||
|
* under the terms of the GNU Affero General Public License *
|
||||||
|
* as published by the Free Software Foundation, *
|
||||||
|
* either version 3 of the License, *
|
||||||
|
* or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This program is distributed in the hope that it will be useful, *
|
||||||
|
* but WITHOUT ANY WARRANTY; *
|
||||||
|
* without even the implied warranty of MERCHANTABILITY *
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. *
|
||||||
|
* See the GNU Affero General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Affero General Public License *
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include "../../include/fsm.h"
|
||||||
|
#include "../../include/signal.h"
|
||||||
|
#include "../../include/widget.h"
|
||||||
|
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* OOOOOOOOOOO OOOOO OOO OOO */
|
||||||
|
/* OO OO OO OOOO OOOO */
|
||||||
|
/* OO OO OO OO OO OO */
|
||||||
|
/* OOOOOO OO OO OO OO OO */
|
||||||
|
/* OO OO OO OOO OO */
|
||||||
|
/* OO OO OO OO */
|
||||||
|
/* OO OO OOO OO OO */
|
||||||
|
/* OO OOOOOO OO OO */
|
||||||
|
/* */
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
static void proto_proto_proto_engine();
|
||||||
|
void fsm_engine_init()
|
||||||
|
{
|
||||||
|
if (0) printf ("src/fsm/engine.c | src/fsm/engine.c fsm_engine_init()\n");
|
||||||
|
proto_proto_proto_engine();
|
||||||
|
// \x1b[1F \x1b[2K == move to the beginning of previous line and clear it
|
||||||
|
}
|
||||||
|
|
||||||
|
static void proto_proto_proto_engine()
|
||||||
|
{
|
||||||
|
int milliseconds = 200;
|
||||||
|
struct timespec rem;
|
||||||
|
struct timespec req= {
|
||||||
|
(int)(milliseconds / 1000), /* secs (Must be Non-Negative) */
|
||||||
|
(milliseconds % 1000) * 1000000 /* nano (Must be in range of 0 to 999999999) */
|
||||||
|
};
|
||||||
|
while (true) {
|
||||||
|
printf("x \n\x1b[1F\x1b[2K"); nanosleep(&req , &rem);
|
||||||
|
printf("x \n\x1b[1F\x1b[2K"); nanosleep(&req , &rem);
|
||||||
|
printf(" x \n\x1b[1F\x1b[2K"); nanosleep(&req , &rem);
|
||||||
|
printf(" x \n\x1b[1F\x1b[2K"); nanosleep(&req , &rem);
|
||||||
|
printf(" x \n\x1b[1F\x1b[2K"); nanosleep(&req , &rem);
|
||||||
|
printf(" x \n\x1b[1F\x1b[2K"); nanosleep(&req , &rem);
|
||||||
|
printf(" x \n\x1b[1F\x1b[2K"); nanosleep(&req , &rem);
|
||||||
|
printf(" x \n\x1b[1F\x1b[2K"); nanosleep(&req , &rem);
|
||||||
|
printf(" x \n\x1b[1F\x1b[2K"); nanosleep(&req , &rem);
|
||||||
|
printf(" x \n\x1b[1F\x1b[2K"); nanosleep(&req , &rem);
|
||||||
|
printf(" x \n\x1b[1F\x1b[2K"); nanosleep(&req , &rem);
|
||||||
|
printf(" x \n\x1b[1F\x1b[2K"); nanosleep(&req , &rem);
|
||||||
|
printf(" x \n\x1b[1F\x1b[2K"); nanosleep(&req , &rem);
|
||||||
|
printf(" x \n\x1b[1F\x1b[2K"); nanosleep(&req , &rem);
|
||||||
|
printf(" x \n\x1b[1F\x1b[2K"); nanosleep(&req , &rem);
|
||||||
|
printf(" x \n\x1b[1F\x1b[2K"); nanosleep(&req , &rem);
|
||||||
|
printf(" x \n\x1b[1F\x1b[2K"); nanosleep(&req , &rem);
|
||||||
|
printf(" x \n\x1b[1F\x1b[2K"); nanosleep(&req , &rem);
|
||||||
|
printf(" x \n\x1b[1F\x1b[2K"); nanosleep(&req , &rem);
|
||||||
|
printf(" x \n\x1b[1F\x1b[2K"); nanosleep(&req , &rem);
|
||||||
|
printf(" x \n\x1b[1F\x1b[2K"); nanosleep(&req , &rem);
|
||||||
|
printf(" x \n\x1b[1F\x1b[2K"); nanosleep(&req , &rem);
|
||||||
|
printf(" x \n\x1b[1F\x1b[2K"); nanosleep(&req , &rem);
|
||||||
|
printf(" x \n\x1b[1F\x1b[2K"); nanosleep(&req , &rem);
|
||||||
|
printf(" x \n\x1b[1F\x1b[2K"); nanosleep(&req , &rem);
|
||||||
|
printf("x \n\x1b[1F\x1b[2K"); nanosleep(&req , &rem);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,156 @@
|
||||||
|
package engine;
|
||||||
|
|
||||||
|
import java.lang.System.out;
|
||||||
|
import measures.MeasuresManager;
|
||||||
|
import resources.P;
|
||||||
|
import rule.FormulasManager;
|
||||||
|
import rule.FormulasManagerAccess;
|
||||||
|
import session.ViewControls;
|
||||||
|
import state.StateManager;
|
||||||
|
import state.StateManagerLocal;
|
||||||
|
import views.MODEL;
|
||||||
|
import views.ViewsManagerAccess;
|
||||||
|
|
||||||
|
/* 2020-11 [prototype 0.0]
|
||||||
|
MonoThread executes a while(true) loop with two instructions:
|
||||||
|
(1) search a place where a transition can be done
|
||||||
|
(2) do the transition
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
if (session.MainView.isStartStopButtonSelected())
|
||||||
|
{
|
||||||
|
state.StateManagerLocal.chooseLocalOrigin(false);
|
||||||
|
new SingleTransition(true);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
public class SingleTransition {
|
||||||
|
|
||||||
|
protected volatile boolean is_done = false;
|
||||||
|
protected volatile String elapsed;
|
||||||
|
public SingleTransition (boolean mono) {if (mono) perform_a_transition();}
|
||||||
|
|
||||||
|
private synchronized static final void perform_a_transition()
|
||||||
|
{
|
||||||
|
// if (step_by_step) StateManagerLocal.circlePresentState();
|
||||||
|
if(ViewControls.isDoSelected()) SingleTransition.execute_do (SingleTransition.prepare_do (false));
|
||||||
|
else if(ViewControls.isUndoSelected()) SingleTransition.execute_undo(SingleTransition.prepare_undo(false));
|
||||||
|
else if(ViewControls.isRedoSelected()) SingleTransition.execute_redo(SingleTransition.prepare_redo(false));
|
||||||
|
// if (ViewControls.undo_buffer < UNDO_STACK_SIZE) ViewControls.setTimeBufferBar(ViewControls.undo_buffer); MainView.addElapsedTime();
|
||||||
|
}
|
||||||
|
public static final int prepare_do (final boolean step_by_step)
|
||||||
|
{
|
||||||
|
// ThreadsManager.addCycle(); // {nb_cycles ++;} This cycle can be inefficient if no formula can be applied
|
||||||
|
selected_formula = FormulasManager.iterateToFindAFormula();
|
||||||
|
// if(selected_formula > -1) out.println(" prepare_do "+ state.StateManagerLocal.getInfoDebug());
|
||||||
|
return selected_formula;
|
||||||
|
}
|
||||||
|
public static final void execute_do (final int formula_key) { // formula.doActions(); out.print(" execute_do: formula key=" + formula_key +" ");
|
||||||
|
if (formula_key < 0) { if(StateManagerLocal.comment_origins) out.println("execute_do failure: formula key=" + formula_key); return;}
|
||||||
|
|
||||||
|
MeasuresManager.startMeasuringAFormulaEffect(formula_key); // out.println("execute_do formula name = "+ FormulasManager.formula.get(formula_key).name);
|
||||||
|
FormulasManager.getFormula().get (formula_key) .doActions(); // {for (i = 0; i < action.length; i++) action[i].doAction (); StateManagerLocal.endRule(action_swap, action_name);}
|
||||||
|
MeasuresManager.endMeasuringAFormulaEffect(formula_key);
|
||||||
|
writePresentState (formula_key);
|
||||||
|
present ++; if (present == UNDO_STACK_SIZE) present = 0; // MainView.setStartStopButtonSelected(false);// if (present == 1); {MainView.setStartStopButtonSelected(false); } //out.println("MonoThread.execute_do > stop ! (present == 1)");
|
||||||
|
ViewControls .execDo();
|
||||||
|
doRepaint();
|
||||||
|
if (DO_UNDO_REDO_comment) comment_do(formula_key); // if (MonoThreadTest.present == 12) MainView.setStartStopButtonSelected(false);
|
||||||
|
}
|
||||||
|
public static final int prepare_undo (final boolean step_by_step) { // MonoThreadTest.present --; return MonoThreadTest. f [MonoThreadTest.present];
|
||||||
|
if (ViewControls.isUndoBufferEmpty()) {out.println("prepare_undo stop !");} // undo_buffer is always >= 0
|
||||||
|
else {present --; if (present == -1) present = UNDO_STACK_SIZE -1; ViewControls.execUndo();}
|
||||||
|
final int formula_key = readPresentState(step_by_step);
|
||||||
|
// if (step_by_step) StateManagerLocal.circlePresentState();
|
||||||
|
return formula_key;
|
||||||
|
}
|
||||||
|
public static final void execute_undo (final int formula_key) { // formula.unDoActions(); {for (i = 0; i < action.length; i++) ...}
|
||||||
|
FormulasManager.getFormula().get (formula_key) .unDoActions(); // {for (i = 0; i < action.length; i++) action[i].doAction (); StateManagerLocal.endRule(action_swap, action_name);}
|
||||||
|
ViewControls.setRedoSelected();
|
||||||
|
// StateManagerLocal.circlePresentState();
|
||||||
|
// ThreadsManager.removeEfficientCycle(); // {nb_effective_cycles --;}
|
||||||
|
doRepaint();
|
||||||
|
if (DO_UNDO_REDO_comment) comment_undo();
|
||||||
|
}
|
||||||
|
public static final int prepare_redo (final boolean step_by_step) { // return MonoThreadTest. f [MonoThreadTest.present];
|
||||||
|
final int formula_key = readPresentState(step_by_step);
|
||||||
|
// ThreadsManager.addEfficientCycle(); // {nb_effective_cycles ++;}
|
||||||
|
// if (step_by_step) StateManagerLocal.circlePresentState();
|
||||||
|
return formula_key;
|
||||||
|
}
|
||||||
|
public static final void execute_redo (final int formula_key) { // formula.doActions(); {for (i = 0; i < action.length; i++) ...}
|
||||||
|
// the redo_buffer is always >= 0 (if the re_do buffer is empty, the re_do button is deactivated)
|
||||||
|
if (! ViewControls.isRedoBufferEmpty()) {
|
||||||
|
FormulasManager.getFormula().get (formula_key).doActions(); // {for (i = 0; i < action.length; i++) action[i].doAction (); StateManagerLocal.endRule(action_swap, action_name);}
|
||||||
|
present ++; if (present == UNDO_STACK_SIZE) present = 0;
|
||||||
|
ViewControls.execRedo();
|
||||||
|
}
|
||||||
|
ViewControls.setUndoSelected();
|
||||||
|
doRepaint();
|
||||||
|
if (DO_UNDO_REDO_comment) comment_redo();
|
||||||
|
}
|
||||||
|
public final static void writePresentState (final int formula_key) { // x [present] = StateManagerLocal.local_space_origin_X; ...
|
||||||
|
|
||||||
|
formula [present] = (short) formula_key;
|
||||||
|
o [present] = (byte) StateManagerLocal.getReferenceOrientation_1();
|
||||||
|
switch(StateManager.space_dimension) {
|
||||||
|
case THREE: z [present] = (byte) StateManagerLocal.local_space_origin_Z; // no break;
|
||||||
|
case TWO: y [present] = (byte) StateManagerLocal.local_space_origin_Y; // no break;
|
||||||
|
case ONE: x [present] = (byte) StateManagerLocal.local_space_origin_X; // no break;
|
||||||
|
default:;}
|
||||||
|
}
|
||||||
|
private final static int readPresentState (final boolean step_by_step) { // StateManagerLocal.local_space_origin_X = x [present]; ...
|
||||||
|
|
||||||
|
switch(StateManager.space_dimension) {
|
||||||
|
case THREE : StateManagerLocal.local_space_origin_Z = z [present]; // no break
|
||||||
|
case TWO : StateManagerLocal.local_space_origin_Y = y [present]; // no break
|
||||||
|
case ONE : StateManagerLocal.local_space_origin_X = x [present]; // no break;
|
||||||
|
default:;}
|
||||||
|
StateManagerLocal.setReferenceOrientation_1 (o [present]);
|
||||||
|
return formula[present];
|
||||||
|
}
|
||||||
|
private final static void doRepaint() {ViewsManagerAccess.getView(MODEL.SPACE, "MonoThread.execute_do_undo_redo()").repaint(); }
|
||||||
|
public static int selected_formula;
|
||||||
|
public static int present = 0;
|
||||||
|
public final static int UNDO_STACK_SIZE = 3000; // resources.Parameters.UNDO_STACK_SIZE; // This parameter is also used by ViewControls to display the BufferProgressBarValue
|
||||||
|
protected final static short[] formula = new short [UNDO_STACK_SIZE];
|
||||||
|
protected final static byte[] x = new byte [UNDO_STACK_SIZE];
|
||||||
|
protected final static byte[] y = new byte [UNDO_STACK_SIZE];
|
||||||
|
protected final static byte[] z = new byte [UNDO_STACK_SIZE];
|
||||||
|
protected final static byte[] o = new byte [UNDO_STACK_SIZE];
|
||||||
|
private final static byte s6 = 6, s2 = 2;
|
||||||
|
public final static boolean DO_UNDO_REDO_comment = false; // true false
|
||||||
|
protected final static void comment_do (int rank)
|
||||||
|
{
|
||||||
|
if (present == 0) present = UNDO_STACK_SIZE;
|
||||||
|
out.println(" do -----> "+
|
||||||
|
P.aa(present,s6) + " ("+ P.aa(ViewControls.undo_buffer - 1,s2) +"+1="+ P.aa(ViewControls.undo_buffer,s2) +" /"+
|
||||||
|
P.aa(ViewControls.redo_buffer,s2) +" -"+ P.aa(ViewControls.redo_buffer,s2) +") "+
|
||||||
|
P.aa("xyzo ("+ P.aa(x[present - 1],2) +","+ P.aa(y[present - 1],2) +","+ P.aa(z[present - 1],2) +")",12) +" "+ o[present - 1] +" " +
|
||||||
|
// "from:"+ P.aa(from[present - 1],4) +" to:"+ P.aa(to[present - 1],4) +
|
||||||
|
" f="+ formula[present - 1] +
|
||||||
|
"");
|
||||||
|
if (present == UNDO_STACK_SIZE) present = 0;
|
||||||
|
}
|
||||||
|
protected final static void comment_undo () {
|
||||||
|
// present ++; if (present == stack_size) present = 0; // This comment is triggered after present was decreased of one unit
|
||||||
|
out.println(" undo <--| "+
|
||||||
|
P.aa(present,s6) + " ("+ P.aa(ViewControls.undo_buffer + 1,s2) +"-1="+ P.aa(ViewControls.undo_buffer,s2) +" /"+
|
||||||
|
P.aa(ViewControls.redo_buffer - 1,s2) +"+1="+ P.aa(ViewControls.redo_buffer,s2) +") "+
|
||||||
|
P.aa("xyzo ("+ P.aa(x[present],2) +","+ P.aa(y[present],2) +","+ P.aa(z[present],2) +")",12) +" "+ o[present] +" " +
|
||||||
|
// "from:"+ P.aa(from[present],4) +" to:"+ P.aa(to[present],4) +
|
||||||
|
" f="+ formula[present] +
|
||||||
|
"");
|
||||||
|
}
|
||||||
|
protected final static void comment_redo () {
|
||||||
|
if (present == 0) present = UNDO_STACK_SIZE;
|
||||||
|
out.println(" redo |--> "+
|
||||||
|
P.aa(present,s6) + " ("+P.aa(ViewControls.undo_buffer - 1,s2) +"+1="+ P.aa(ViewControls.undo_buffer,s2) + " /"+
|
||||||
|
P.aa(ViewControls.redo_buffer + 1,s2) +"-1="+ P.aa(ViewControls.redo_buffer,s2) +") "+
|
||||||
|
P.aa("xyzo ("+ P.aa(x[present - 1],2) +","+ P.aa(y[present - 1],2) +","+ P.aa(z[present - 1],2) +")",12) +" "+ o[present - 1] +" " +
|
||||||
|
// "from:"+ P.aa(from[present - 1],4) +" to:"+ P.aa(to[present - 1],4) +
|
||||||
|
" f="+ formula[present - 1] +
|
||||||
|
"");
|
||||||
|
if (present == UNDO_STACK_SIZE) present = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -42,43 +42,10 @@
|
||||||
/* ex : filter, concat, inverse, scale, correlate, etc. */
|
/* ex : filter, concat, inverse, scale, correlate, etc. */
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
void fsm_data_new_insert (data_list d, int *p_data) {}
|
void fsm_add_data (data_list d, int *p_data, int *p_target) {}
|
||||||
void fsm_data_new_concat (data_list d, int *p_data, int *p_target) {}
|
int fsm_get_data (data_list d, int from, int to) {return 0;}
|
||||||
void fsm_data_erase (data_list d, int from, int to) {}
|
void fsm_remove_data (data_list d, int *p_data) {}
|
||||||
|
|
||||||
char heq[] = "sin(x)";
|
|
||||||
char geq[] = "cos(x)";
|
|
||||||
|
|
||||||
void *fsm_data_get () // (data_list d, int from, int to)
|
|
||||||
{
|
|
||||||
int v[10];
|
|
||||||
for (int i = 0; i < 10; i++) {v[i] = rand() % 10; printf("%d ", v[i]);}
|
|
||||||
printf("\n");
|
|
||||||
|
|
||||||
FILE *fp;
|
|
||||||
double a;
|
|
||||||
fp = fopen("list.txt","w");
|
|
||||||
for(a = -5.0; a <= 5.0; a++) fprintf(fp, " %6.3f %6.3f\n", a, sin(a));
|
|
||||||
fclose(fp);
|
|
||||||
printf("file list.txt opened\npress 'return' to continue.");
|
|
||||||
getchar();
|
|
||||||
|
|
||||||
fp = fopen("a_main.plt","w");
|
|
||||||
|
|
||||||
fprintf(fp,"# Fichier de commande pour gnuplot \n"
|
|
||||||
"# En ligne de commande : load \"a_main.plt\"\n"
|
|
||||||
"#\n"
|
|
||||||
" set zeroaxis\n"
|
|
||||||
" plot %s,\\\n"
|
|
||||||
" %s \n\n"
|
|
||||||
" reset", geq, heq);
|
|
||||||
fclose(fp);
|
|
||||||
|
|
||||||
printf("\n\nload \"a_main.plt\" with gnuplot."
|
|
||||||
"\n\npress return to continue. ");
|
|
||||||
getchar();
|
|
||||||
|
|
||||||
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// http://www.gnuplot.info/
|
||||||
|
// https://fr.wikipedia.org/wiki/Gnuplot
|
||||||
|
// https://fr.wikibooks.org/wiki/Mathc_gnuplot
|
||||||
|
|
|
@ -33,11 +33,16 @@
|
||||||
|
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
/* An editable list of displayed results is defined and maintained here */
|
/* An editable list of displayable results is defined and maintained here */
|
||||||
/* (see : fsm/measure/manage.c) */
|
/* (see : fsm/measure/manage.c) */
|
||||||
/* - - - */
|
/* - - - */
|
||||||
/* NB some data may be displayed simultaneously in different pages */
|
/* NB some data may be displayed simultaneously in different pages */
|
||||||
/* ex : pages SYNTH & RESULTS */
|
/* ex : pages SYNTH & RESULTS */
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
// "graph", "chart", "plot" and "diagram" are ambiguous terms, used interchangeably.
|
||||||
|
|
||||||
|
void fsm_disp_add_chart (disp_list d, int *p_chart) {}
|
||||||
|
int fsm_disp_get_chart (disp_list d, int from, int to) {return 0;}
|
||||||
|
void fsm_disp_remove_chart (disp_list d, int *p_chart) {}
|
||||||
|
|
||||||
|
|
|
@ -79,10 +79,12 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// use gnuplot ? gtkwave ? TODO check
|
// use gnuplot ? gtkwave ? TODO check ---------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void fsm_add_measure (char *measure_name) {fsm_msg (2, 0, measure_name, 2);}
|
void fsm_add_measure (char *measure_name) {fsm_msg (2, 0, measure_name, 2);}
|
||||||
void fsm_measures_list_init() {if (0) fsm_tools_list_test(); fsm_data_get();}
|
void fsm_measures_list_init() {if (0) fsm_tools_list_test();}
|
||||||
void fsm_rule_trig_measure (int rule_id, int object_id, int measure_id) {}
|
void fsm_rule_trig_measure (int rule_id, int object_id, int measure_id) {}
|
||||||
|
|
||||||
|
|
|
@ -137,6 +137,9 @@ void fsm_tools_list_view (tool_list *ml)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
void fsm_tools_list_test()
|
void fsm_tools_list_test()
|
||||||
{
|
{
|
||||||
tool_list *ex_tool = NULL;
|
tool_list *ex_tool = NULL;
|
||||||
|
|
|
@ -153,11 +153,11 @@ int main (int argc, char **argv)
|
||||||
|
|
||||||
app = gtk_application_new ("org.gem-graph", G_APPLICATION_DEFAULT_FLAGS);
|
app = gtk_application_new ("org.gem-graph", G_APPLICATION_DEFAULT_FLAGS);
|
||||||
|
|
||||||
fsm_init (); // fsm = finite state machine (see : src/fsm/dispatch.c)
|
|
||||||
|
|
||||||
g_signal_connect (app, "activate", G_CALLBACK (on_windows_activation), NULL);
|
g_signal_connect (app, "activate", G_CALLBACK (on_windows_activation), NULL);
|
||||||
// on_windows_activation <> see : src/widget/dispatch
|
// on_windows_activation <> see : src/widget/dispatch
|
||||||
|
|
||||||
|
fsm_init (); // fsm = finite state machine (see : src/fsm/dispatch.c)
|
||||||
|
|
||||||
status = g_application_run (G_APPLICATION (app), argc, argv);
|
status = g_application_run (G_APPLICATION (app), argc, argv);
|
||||||
g_object_unref (app);
|
g_object_unref (app);
|
||||||
|
|
||||||
|
|
|
@ -61,13 +61,17 @@ void on_windows_activation (GtkApplication *app)
|
||||||
// g_application_activate (G_APPLICATION (app)); < how ? > in main.c is
|
// g_application_activate (G_APPLICATION (app)); < how ? > in main.c is
|
||||||
// g_signal_connect (app, "activate", G_CALLBACK (on_windows_activation), NULL);
|
// g_signal_connect (app, "activate", G_CALLBACK (on_windows_activation), NULL);
|
||||||
|
|
||||||
|
printf(" We apologise for the temporary interruption to the window. 😇️\n\
|
||||||
|
Please, ask 'src/widget/dispatch.c on_windows_activation (GtkApplication *app)'\n\
|
||||||
|
to call: widget_design_main_window (main_window)\n");
|
||||||
|
/*
|
||||||
main_window = GTK_WINDOW (gtk_application_window_new (app));
|
main_window = GTK_WINDOW (gtk_application_window_new (app));
|
||||||
dialog_window = GTK_WINDOW (gtk_application_window_new (app));
|
dialog_window = GTK_WINDOW (gtk_application_window_new (app));
|
||||||
text_window = GTK_WINDOW (gtk_application_window_new (app));
|
text_window = GTK_WINDOW (gtk_application_window_new (app));
|
||||||
|
|
||||||
widget_design_main_window (main_window); // def: widget/topbar/dispatch
|
widget_design_main_window (main_window); // def: widget/topbar/dispatch
|
||||||
widget_design_dialog_window (main_window, dialog_window);
|
widget_design_dialog_window (main_window, dialog_window);
|
||||||
widget_design_text_window (main_window, text_window);
|
widget_design_text_window (main_window, text_window);*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
|
@ -142,6 +142,10 @@ static GtkWidget *peek(Stack *stack)
|
||||||
// Serializes a GIcon into a GVariant. An equivalent GIcon can be retrieved back
|
// Serializes a GIcon into a GVariant. An equivalent GIcon can be retrieved back
|
||||||
// by calling g_icon_deserialize() on the returned value.
|
// by calling g_icon_deserialize() on the returned value.
|
||||||
// Oui mais : comment obtenir une GIcon à partir d'une GtkImage ?
|
// Oui mais : comment obtenir une GIcon à partir d'une GtkImage ?
|
||||||
|
//
|
||||||
|
// 🤔️ voir aussi:
|
||||||
|
// https://docs.gtk.org/gio/method.Icon.hash.html
|
||||||
|
// A #guint containing a hash for the icon, suitable for use in a GHashTable...
|
||||||
|
|
||||||
static void *push_images_onto_stack (Stack stack_b);
|
static void *push_images_onto_stack (Stack stack_b);
|
||||||
static GtkWidget *do_rtfd (Stack stack_b);
|
static GtkWidget *do_rtfd (Stack stack_b);
|
||||||
|
|
|
@ -42,3 +42,11 @@ void *widget_get_rules_tree_tools_pane ()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// GTK possède un espace mémoire où les widgets sont alloués/désalloués
|
||||||
|
// Un widget ne conserve pas son pointeur. Son adresse peut donc changer.
|
||||||
|
// Créer une stack de widget avec un outil hors GTK n'est pas faisable. Donc :
|
||||||
|
// TODO (voir le détail dans : compare.c)
|
||||||
|
// Pour obtenir une GIcon à partir d'une GtkImage, je peux la sérialiser :
|
||||||
|
// https://docs.gtk.org/gio/method.Icon.serialize.html 🤔️
|
||||||
|
// https://docs.gtk.org/gio/method.Icon.hash.html
|
||||||
|
// A #guint containing a hash for the icon, suitable for use in a GHashTable...
|
||||||
|
|
Loading…
Reference in New Issue