From 924968ca26abf0921984493963dcdf0fbf46eace Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Sat, 31 Aug 2024 09:12:59 +0200 Subject: [PATCH] fsm/engine.c > using the console to test a thread (or worker) prototype (back 30 years ago) --- .../2024-07-14 | 0 a_main.plt => data/gnuplot/a_cmd.plt | 2 +- list.txt => data/gnuplot/sin | 4 + include/fsm.h | 17 +- include/heaviside.h | 8 - include/xdef.h | 52 ------ include/xfx_x.h | 32 ---- include/xfxy_x.h | 70 -------- include/xfxyz_x.h | 51 ------ include/xplt.h | 70 -------- include/xspv.h | 60 ------- src/fsm/dispatch.c | 3 + src/fsm/engine.c | 92 +++++++++++ src/fsm/engine.java | 156 ++++++++++++++++++ src/fsm/measure/data_list.c | 45 +---- src/fsm/measure/disp_list.c | 7 +- src/fsm/measure/manage.c | 6 +- src/fsm/measure/tool_list.c | 3 + src/main.c | 4 +- src/widget/dispatch.c | 6 +- src/widget/rules/tree_tools/compare.c | 4 + src/widget/rules/tree_tools/dispatch.c | 8 + 22 files changed, 307 insertions(+), 393 deletions(-) rename 2024-07 audit proto-gg.html => audit/2024-07-14 (100%) rename a_main.plt => data/gnuplot/a_cmd.plt (58%) rename list.txt => data/gnuplot/sin (73%) delete mode 100644 include/heaviside.h delete mode 100644 include/xdef.h delete mode 100644 include/xfx_x.h delete mode 100644 include/xfxy_x.h delete mode 100644 include/xfxyz_x.h delete mode 100644 include/xplt.h delete mode 100644 include/xspv.h create mode 100644 src/fsm/engine.c create mode 100644 src/fsm/engine.java diff --git a/2024-07 audit proto-gg.html b/audit/2024-07-14 similarity index 100% rename from 2024-07 audit proto-gg.html rename to audit/2024-07-14 diff --git a/a_main.plt b/data/gnuplot/a_cmd.plt similarity index 58% rename from a_main.plt rename to data/gnuplot/a_cmd.plt index f15987f..11b4378 100644 --- a/a_main.plt +++ b/data/gnuplot/a_cmd.plt @@ -1,5 +1,5 @@ # 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 plot cos(x),\ diff --git a/list.txt b/data/gnuplot/sin similarity index 73% rename from list.txt rename to data/gnuplot/sin index 0da200a..adff780 100644 --- a/list.txt +++ b/data/gnuplot/sin @@ -1,3 +1,5 @@ + -7.000 -0.657 + -6.000 0.279 -5.000 0.959 -4.000 0.757 -3.000 -0.141 @@ -9,3 +11,5 @@ 3.000 0.141 4.000 -0.757 5.000 -0.959 + 6.000 -0.279 + 7.000 0.657 diff --git a/include/fsm.h b/include/fsm.h index 492da69..a8d6ea2 100644 --- a/include/fsm.h +++ b/include/fsm.h @@ -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); +// --------------------------------------------------------------- WIP ------ +void fsm_engine_init(); + // --------------------------------------------------------------- WIP ------ int fsm_journal_push (journal **jj, int v_value); int fsm_journal_pop (journal **jj); @@ -110,7 +113,13 @@ void fsm_journal_seek (journal *jj, int vv); // --------------------------------------------------------------- WIP ------ -void fsm_data_new_insert (data_list d, int *p_data); -void fsm_data_new_concat (data_list d, int *p_data, int *p_target); -void *fsm_data_get(); // (data_list d, int from, int to); -void fsm_data_erase (data_list d, int from, int to); +void fsm_add_data (data_list d, int *p_data, int *p_target); +int fsm_get_data (data_list d, int from, int to); +void fsm_remove_data (data_list d, int *p_data); + + +// --------------------------------------------------------------- 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); + diff --git a/include/heaviside.h b/include/heaviside.h deleted file mode 100644 index e49f74a..0000000 --- a/include/heaviside.h +++ /dev/null @@ -1,8 +0,0 @@ -/* ------------------------------------ */ -double H( -double x) -{ - if(x>0.)return(1.); - else return(0.); -} -/* ------------------------------------ */ diff --git a/include/xdef.h b/include/xdef.h deleted file mode 100644 index 3ae00c1..0000000 --- a/include/xdef.h +++ /dev/null @@ -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); -} - diff --git a/include/xfx_x.h b/include/xfx_x.h deleted file mode 100644 index 92becb4..0000000 --- a/include/xfx_x.h +++ /dev/null @@ -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) ); -} - diff --git a/include/xfxy_x.h b/include/xfxy_x.h deleted file mode 100644 index c16e08e..0000000 --- a/include/xfxy_x.h +++ /dev/null @@ -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) ); -} diff --git a/include/xfxyz_x.h b/include/xfxyz_x.h deleted file mode 100644 index ee737bc..0000000 --- a/include/xfxyz_x.h +++ /dev/null @@ -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) ); -} diff --git a/include/xplt.h b/include/xplt.h deleted file mode 100644 index 0f322c2..0000000 --- a/include/xplt.h +++ /dev/null @@ -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);} diff --git a/include/xspv.h b/include/xspv.h deleted file mode 100644 index ae88360..0000000 --- a/include/xspv.h +++ /dev/null @@ -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);} diff --git a/src/fsm/dispatch.c b/src/fsm/dispatch.c index 685aedb..f69e58b 100644 --- a/src/fsm/dispatch.c +++ b/src/fsm/dispatch.c @@ -60,10 +60,13 @@ void fsm_init() { + /* fsm_measures_list_init(); fsm_results_list_init(); fsm_displayable_list_init(); fsm_preferences_init(); + */ + fsm_engine_init(); // pour avancer, en attendant... 😇️ } diff --git a/src/fsm/engine.c b/src/fsm/engine.c new file mode 100644 index 0000000..e24ab07 --- /dev/null +++ b/src/fsm/engine.c @@ -0,0 +1,92 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * +* * +* Gem-graph client * +* Finite State Machine Engine * +* * +* Copyright © 2024 Libre en Communs * +* Copyright © 2024 Jean Sirmai * +* * +* 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 . * +* * +* * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include +#include +#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); + } +} diff --git a/src/fsm/engine.java b/src/fsm/engine.java new file mode 100644 index 0000000..d810ab5 --- /dev/null +++ b/src/fsm/engine.java @@ -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; + } +} + diff --git a/src/fsm/measure/data_list.c b/src/fsm/measure/data_list.c index 04c02a7..7b9dff4 100644 --- a/src/fsm/measure/data_list.c +++ b/src/fsm/measure/data_list.c @@ -42,43 +42,10 @@ /* ex : filter, concat, inverse, scale, correlate, etc. */ /******************************************************************************/ -void fsm_data_new_insert (data_list d, int *p_data) {} -void fsm_data_new_concat (data_list d, int *p_data, int *p_target) {} -void fsm_data_erase (data_list d, int from, int to) {} - -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; -} +void fsm_add_data (data_list d, int *p_data, int *p_target) {} +int fsm_get_data (data_list d, int from, int to) {return 0;} +void fsm_remove_data (data_list d, int *p_data) {} +// http://www.gnuplot.info/ +// https://fr.wikipedia.org/wiki/Gnuplot +// https://fr.wikibooks.org/wiki/Mathc_gnuplot diff --git a/src/fsm/measure/disp_list.c b/src/fsm/measure/disp_list.c index 0a7dc8f..8518b41 100644 --- a/src/fsm/measure/disp_list.c +++ b/src/fsm/measure/disp_list.c @@ -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) */ /* - - - */ /* NB some data may be displayed simultaneously in different pages */ /* 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) {} diff --git a/src/fsm/measure/manage.c b/src/fsm/measure/manage.c index 6aef9b2..cb07600 100644 --- a/src/fsm/measure/manage.c +++ b/src/fsm/measure/manage.c @@ -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_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) {} diff --git a/src/fsm/measure/tool_list.c b/src/fsm/measure/tool_list.c index fd62142..2130023 100644 --- a/src/fsm/measure/tool_list.c +++ b/src/fsm/measure/tool_list.c @@ -137,6 +137,9 @@ void fsm_tools_list_view (tool_list *ml) } + +//------------------------------------------------------------------------------ + void fsm_tools_list_test() { tool_list *ex_tool = NULL; diff --git a/src/main.c b/src/main.c index 31051e2..1015486 100644 --- a/src/main.c +++ b/src/main.c @@ -153,11 +153,11 @@ int main (int argc, char **argv) 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); // 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); g_object_unref (app); diff --git a/src/widget/dispatch.c b/src/widget/dispatch.c index 31f033c..3d959aa 100644 --- a/src/widget/dispatch.c +++ b/src/widget/dispatch.c @@ -61,13 +61,17 @@ void on_windows_activation (GtkApplication *app) // g_application_activate (G_APPLICATION (app)); < how ? > in main.c is // 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)); dialog_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_dialog_window (main_window, dialog_window); - widget_design_text_window (main_window, text_window); + widget_design_text_window (main_window, text_window);*/ } /******************************************************************************/ diff --git a/src/widget/rules/tree_tools/compare.c b/src/widget/rules/tree_tools/compare.c index 2a9afa2..7e007ac 100644 --- a/src/widget/rules/tree_tools/compare.c +++ b/src/widget/rules/tree_tools/compare.c @@ -142,6 +142,10 @@ static GtkWidget *peek(Stack *stack) // Serializes a GIcon into a GVariant. An equivalent GIcon can be retrieved back // by calling g_icon_deserialize() on the returned value. // 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 GtkWidget *do_rtfd (Stack stack_b); diff --git a/src/widget/rules/tree_tools/dispatch.c b/src/widget/rules/tree_tools/dispatch.c index 5b705af..bcd30c5 100644 --- a/src/widget/rules/tree_tools/dispatch.c +++ b/src/widget/rules/tree_tools/dispatch.c @@ -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...