C++ main module for gpm Package  1.0
GPMG_Project.h
Go to the documentation of this file.
1 #ifndef GPMG_Project_H
2 #define GPMG_Project_H
3 
4 #include "UI_Object.h"
5 #include "UI_Class.h"
6 
7 #include "CORE_Out.h"
8 
9 #include "GPM_ModelGraph.h"
10 #include "GPM_ModelFunction.h"
11 #include "GPM_ModelClassFactory.h"
12 
14 
22 class GPMG_Project : public UI_Object {
23  SP_OBJECT(GPMG_Project);
24 
25  // ATTRIBUTES
26 public:
27  static const tFlag NODE_ENVIRONMENT;
28  static const tFlag EDGE_ENVIRONMENT;
29  static const tFlag PORT_ENVIRONMENT;
30  static const tFlag GLOBAL_ENVIRONMENT;
31  static const tFlag N_ENVIRONMENTS;
32 
33  static const tFlag PATTERN_GRAPH;
34  static const tFlag TRANSFORMER_GRAPH;
35  static const tFlag PT_CONNECTION;
36  static const tFlag INIT_GRAPH;
37  static const tFlag RESULT_GRAPH;
38  static const tFlag UNKNOWN_GRAPH;
39 
40  static const tFlag EXPR;
41  static const tFlag EXPRTK;
42 
43 
44 private:
45  //default environment
46  map<tString,SP::GPM_Variable> mEnvironments[4];
47  SV::GPM_CompositorFunction mFunctions;
48 
49  tFlag mExpressionType;
50 
51  int mRulesNumber;
52  int mIterationsNumber;
53 
54  vector<tString> mResultGraphFiles;
55 
56  // min &max points for the graph
57  tReal mMinPoint[3],mMaxPoint[3];
58  // min & max values for variables
59  // variable Name{"@Node",@PORT","@EDGE} --> {minValue,maxValue}
60  map<tString,tReal*> mBoundsValue;
61  int mIterations;
62 
63 
64 
65  // ASSOCIATIONS
66 
67  // graphs load from graph files
68  SP::GPM_ModelGraph mInitGraph;
69 
70  // rules load from rules files
71  SV::GPM_ModelFunction mRules;
72 
73  // gpm class fatory
74  SP::GPM_ModelClassFactory mClassFactory;
75 
76 
77 
78 protected:
79  // METHODS
80 
81  // CONSTRUCTORS
82 
84  GPMG_Project(void);
85 
86 
87 
88  // DESTRUCTORS
89 
90 
93  virtual ~GPMG_Project(void);
94 
95 
96 public:
97 
98  // NEW
101  inline static SP::GPMG_Project New() {
102  SP::GPMG_Project p(new GPMG_Project,GPMG_Project::Delete());
103  p->setThis(p);
104  return p;
105  }
106 
107  // SET methods
108 public:
109 
112  tBoolean loadData(const tString& projectFile);
115  tBoolean saveData(const tString& projectFile);
116 
117 
118  // Environments
119 
122  inline void setClassFactory(SP::GPM_ModelClassFactory cf) {
123  mClassFactory=cf;
124  }
127  inline const GPM_ModelClassFactory& getClassFactory() const {
128  return *mClassFactory.get();
129  }
130 
133  //void setExpressionType(const tFlag& expr);
134 
135 
139  void clearEnvironment(const tFlag& index);
140 
148  inline void addToEnvironment(const tFlag& index,
149  const tString& name,
150  const tFlag type,
151  const int& card,
152  const double *value) {
153  SP::GPM_Variable var=GPM_Variable::New();
154  var->setValue(card,value,type);
155 
156  addToEnvironment(index,name,var);
157  }
163  inline void addToEnvironment(const tFlag& index,
164  const tString& name,
165  const double &value) {
166  SP::GPM_Variable var=GPM_Variable::New();
167  var->setValue(value);
168 
169  addToEnvironment(index,name,var);
170  }
176  inline void addToEnvironment(const tFlag& index,
177  const tString& name,
178  const tString &value) {
179  SP::GPM_Variable var=GPM_Variable::New();
180  var->setValue(value);
181 
182  addToEnvironment(index,name,var);
183  }
184 
191  inline void addToEnvironment(const tFlag& index,
192  const tString& name,
193  const int& n,
194  const double *value) {
195  SP::GPM_Variable var=GPM_Variable::New();
196  var->setValue(n,value);
197  addToEnvironment(index,name,var);
198  }
199 
205  void addToEnvironment(const tFlag& index,
206  const tString& name,
207  SP::GPM_Variable var) ;
208 
209 
212  inline void setIterationsNumber(const int& n) {
213  mIterationsNumber=n;
214  }
215 
216 
219  void getVertexVariableNames(vector<tString>& vars) const;
220 
221  // GET methods
222 public:
226  return mExpressionType;
227  }
228 
229 
232  inline int getIterationsNumber() const{
233  return mIterationsNumber;
234  }
237  inline int getIterationsDone() const{
238  return mIterations;
239  }
240 
243  inline const tReal* getMinPoint() const {
244  return mMinPoint;
245  }
248  inline const tReal* getMaxPoint() const {
249  return mMaxPoint;
250  }
253  inline const map<tString,tReal*>& getBoundsValue() const {
254  return mBoundsValue;
255  }
256 
259  const map<tString,SP::GPM_Variable>& getEnvironment(const tFlag& index) const;
260 
263  const map<tString,SP::GPM_Variable>& getGlobalVariables() const {
264  return mEnvironments[GLOBAL_ENVIRONMENT];
265  }
266 
267 public:
268 
272  return mInitGraph.get();
273  }
276  inline const GPM_ModelGraph* getInitGraph() const {
277  return mInitGraph.get();
278  }
279 
282  inline tBoolean loadInitGraph(const tString& fn,CORE_Out& io) {
283  mInitGraph=GPM_ModelGraph::New();
284  tBoolean succeeds=mInitGraph->loadFromFile(fn,io);
285  if (mInitGraph!=null) mInitGraph->buildEnvironments(mEnvironments[NODE_ENVIRONMENT],
286  mEnvironments[PORT_ENVIRONMENT],
287  mEnvironments[EDGE_ENVIRONMENT]);
288 
289  return succeeds;
290  }
293  inline tBoolean saveInitGraph(const tString& fn) const {
294  return mInitGraph->saveToFile(fn);
295  }
296 
299  void clearInitGraph();
300 
303  void generateQuadInitGraph(const int& nTriangles,const tBoolean& withMiddle,
304  const int& n,const int& m,const tReal& w,const tReal& h,const tReal& xmin,const tReal& ymin);
305 
308  inline void updateGraphsEnvironments() {
309  if (mInitGraph.get()!=null) mInitGraph->updateGraphElementsEnvironment(mEnvironments[NODE_ENVIRONMENT],
310  mEnvironments[PORT_ENVIRONMENT],
311  mEnvironments[EDGE_ENVIRONMENT]);
312 
313  int nRules=mRules.getSize();
314  for (int i=0;i<nRules;i++) {
315  GPM_ModelFunction *rule=mRules.get(i);
316  if (rule!=null) {
317  rule->setGlobalVariables(mEnvironments[GLOBAL_ENVIRONMENT]);
318  rule->setGlobalFunctions(mFunctions);
319  GPM_PortGraph &pgraph=rule->getPatternGraph();
320  pgraph.updateGraphElementsEnvironment(mEnvironments[NODE_ENVIRONMENT],
321  mEnvironments[PORT_ENVIRONMENT],
322  mEnvironments[EDGE_ENVIRONMENT]);
323  GPM_PortGraph &tgraph=rule->getTransformerGraph();
324  tgraph.updateGraphElementsEnvironment(mEnvironments[NODE_ENVIRONMENT],
325  mEnvironments[PORT_ENVIRONMENT],
326  mEnvironments[EDGE_ENVIRONMENT]);
327  }
328  }
329  }
330 
331 
332 
333 
336  const SV::GPM_ModelFunction& getRules() const {
337  return mRules;
338  }
341  SV::GPM_ModelFunction& getRules() {
342  return mRules;
343  }
344 
347  void clearRule(const int& index);
348 
349  // RUN the project
352  tBoolean canBeRun() const;
353 
357  void setResultGraphFiles(const vector<tString>& files);
358 
361  const vector<tString>& getResultGraphFiles() const {
362  return mResultGraphFiles;
363  }
364 
367  int run(const tString& projectFile,const int& iter0,const int& iterationsNumber,CORE_Out& io,GPMG_MovieGraphWindow* visualizer,tString&errorMessage,tBoolean& succeeds);
368 
369  // UI Class saver & loader
372  virtual void saveToUIClass(UI_Class& mclass) const;
375  virtual void loadFromUIClass(const UI_Class& mclass);
376 private:
377 
380  void clearScales();
383  void updateScales(const GPM_ModelGraph& graph);
384 
387  void saveClass(const tString& key,const GPM_Variable& var,UI_Class& mclass) const;
388 
391  void loadClass(const tString& key,GPM_Variable& var,const UI_Class& mclass) const;
392 
393 public:
397  return mFunctions.getSize();
398  }
399 
402  inline const GPM_CompositorFunction* getGlobalFunction(const int& i) const {
403  if ((i>=0) && (i<mFunctions.getSize())) return mFunctions.get(i);
404  return null;
405  };
409  if ((i>=0) && (i<mFunctions.getSize())) return mFunctions.get(i);
410  return null;
411  };
412 
415  SV::GPM_CompositorFunction& getGlobalFunctions();
418  const SV::GPM_CompositorFunction& getGlobalFunctions() const;
419 
420 
423  void setGlobalFunctions(SV::GPM_CompositorFunction fs) ;
424 
426  return (mClassFactory->newFunction().get()!=null);
427  }
428 
429 };
430 
431 #endif
void addToEnvironment(const tFlag &index, const tString &name, const int &n, const double *value)
add an array of double to environment
Definition: GPMG_Project.h:191
void generateQuadInitGraph(const int &nTriangles, const tBoolean &withMiddle, const int &n, const int &m, const tReal &w, const tReal &h, const tReal &xmin, const tReal &ymin)
generate graph as grid
Definition: GPMG_Project.cpp:560
tBoolean saveInitGraph(const tString &fn) const
load the iit graph of themodel
Definition: GPMG_Project.h:293
void setResultGraphFiles(const vector< tString > &files)
get the result graph files :
Definition: GPMG_Project.cpp:755
static const tFlag INIT_GRAPH
Definition: GPMG_Project.h:36
const GPM_ModelClassFactory & getClassFactory() const
set the class factory
Definition: GPMG_Project.h:127
tBoolean areCompositorFunctionsAvailabled()
Definition: GPMG_Project.h:425
const GPM_CompositorFunction * getGlobalFunction(const int &i) const
get the function at index i
Definition: GPMG_Project.h:402
const GPM_PortGraph & getTransformerGraph() const
get the transformer graph for reading
Definition: GPM_Function.h:95
static const tFlag EDGE_ENVIRONMENT
Definition: GPMG_Project.h:28
void updateGraphsEnvironments()
update the environments of initial graph & graphs of rules
Definition: GPMG_Project.h:308
void clearInitGraph()
clear the init graph
Definition: GPMG_Project.cpp:557
This class describes a model graph.
Definition: GPM_ModelGraph.h:21
void addToEnvironment(const tFlag &index, const tString &name, const tFlag type, const int &card, const double *value)
add variable to environment
Definition: GPMG_Project.h:148
DEFINE_SPTR(GPMG_Project)
const SV::GPM_ModelFunction & getRules() const
get the rules for reading
Definition: GPMG_Project.h:336
static const tFlag UNKNOWN_GRAPH
Definition: GPMG_Project.h:38
static SP::GPM_Variable New()
Definition: GPM_Variable.h:59
#define tBoolean
Definition: types.h:35
static const tFlag RESULT_GRAPH
Definition: GPMG_Project.h:37
static SP::GPMG_Project New()
create a new instance of class
Definition: GPMG_Project.h:101
const map< tString, SP::GPM_Variable > & getGlobalVariables() const
get the default port variables
Definition: GPMG_Project.h:263
SV::GPM_CompositorFunction & getGlobalFunctions()
get the function at index
Definition: GPMG_Project.cpp:574
static const tFlag PATTERN_GRAPH
Definition: GPMG_Project.h:33
#define null
Definition: types.h:13
void setGlobalFunctions(const SV::GPM_CompositorFunction &fcts)
set the global functions
Definition: GPM_ModelFunction.h:141
void getVertexVariableNames(vector< tString > &vars) const
get the vertex variable names
Definition: GPMG_Project.cpp:215
const tReal * getMinPoint() const
get the min point of the graphs
Definition: GPMG_Project.h:243
This class describes a compositor function used in rules.
Definition: GPM_CompositorFunction.h:18
static const tFlag N_ENVIRONMENTS
Definition: GPMG_Project.h:31
const GPM_PortGraph & getPatternGraph() const
get the pattern graph for reading
Definition: GPM_Function.h:76
virtual ~GPMG_Project(void)
destroy an object.
Definition: GPMG_Project.cpp:46
static const tFlag PORT_ENVIRONMENT
Definition: GPMG_Project.h:29
void setClassFactory(SP::GPM_ModelClassFactory cf)
set the class factory
Definition: GPMG_Project.h:122
int getGlobalFunctionsNumber() const
get the function number
Definition: GPMG_Project.h:396
const vector< tString > & getResultGraphFiles() const
get the result graph files
Definition: GPMG_Project.h:361
tBoolean loadInitGraph(const tString &fn, CORE_Out &io)
load the iint graph of themodel
Definition: GPMG_Project.h:282
This class describes a node.
Definition: GPM_Variable.h:16
int getIterationsNumber() const
get the iterations number
Definition: GPMG_Project.h:232
This class is the class to save GPM classes.
Definition: GPM_ModelClassFactory.h:16
GPM_ModelGraph * getInitGraph()
get the init graph of the project
Definition: GPMG_Project.h:271
const map< tString, tReal * > & getBoundsValue() const
get the bounds
Definition: GPMG_Project.h:253
void clearRule(const int &index)
clear the rule at index
Definition: GPMG_Project.cpp:569
static const tFlag EXPRTK
Definition: GPMG_Project.h:41
tBoolean canBeRun() const
return true if the project can be run
Definition: GPMG_Project.cpp:396
SV::GPM_ModelFunction & getRules()
get the rules for writing
Definition: GPMG_Project.h:341
virtual void loadFromUIClass(const UI_Class &mclass)
how to load the object from a Meta Model class
Definition: GPMG_Project.cpp:50
This class describes a project.
Definition: GPMG_Project.h:22
static const tFlag NODE_ENVIRONMENT
Definition: GPMG_Project.h:27
#define tString
Definition: types.h:36
This class describes a graph which is a list of vertices, ports & edges.
Definition: GPM_PortGraph.h:22
const tReal * getMaxPoint() const
get the max point of the graphs
Definition: GPMG_Project.h:248
tBoolean saveData(const tString &projectFile)
save the data of the model from project file name
Definition: GPMG_Project.cpp:239
GPMG_Project(void)
create an object
Definition: GPMG_Project.cpp:28
this class describes a window to show movie of graphs
Definition: GPMG_MovieGraphWindow.h:17
void setGlobalFunctions(SV::GPM_CompositorFunction fs)
get the function at index i by copping functions of fs
Definition: GPMG_Project.cpp:742
const GPM_ModelGraph * getInitGraph() const
get the init graph of the project
Definition: GPMG_Project.h:276
this class describes the output by default write on standart output
Definition: CORE_Out.h:21
void setIterationsNumber(const int &n)
set the iterations number
Definition: GPMG_Project.h:212
void setGlobalVariables(const map< tString, SP::GPM_Variable > &variables)
set the global variable
Definition: GPM_ModelFunction.cpp:71
void addToEnvironment(const tFlag &index, const tString &name, const double &value)
add a double variable to environment
Definition: GPMG_Project.h:163
const map< tString, SP::GPM_Variable > & getEnvironment(const tFlag &index) const
get the default port variables
Definition: GPMG_Project.cpp:232
This class describes a pattern function.
Definition: GPM_ModelFunction.h:23
void updateGraphElementsEnvironment(const map< tString, SP::GPM_Variable > &nodeEnvironment, const map< tString, SP::GPM_Variable > &portEnvironment, const map< tString, SP::GPM_Variable > &edgeEnvironment)
update the environment of all graph elements (reverse method of build environments) ...
Definition: GPM_PortGraph.cpp:925
tBoolean loadData(const tString &projectFile)
load the data of the model from project file name
Definition: GPMG_Project.cpp:307
GPM_CompositorFunction * getGlobalFunction(const int &i)
get the function at index i
Definition: GPMG_Project.h:408
static const tFlag PT_CONNECTION
Definition: GPMG_Project.h:35
void clearEnvironment(const tFlag &index)
set the expression type
Definition: GPMG_Project.cpp:200
tFlag getExpressionType()
set the expression type
Definition: GPMG_Project.h:225
int run(const tString &projectFile, const int &iter0, const int &iterationsNumber, CORE_Out &io, GPMG_MovieGraphWindow *visualizer, tString &errorMessage, tBoolean &succeeds)
run the project
Definition: GPMG_Project.cpp:411
static const tFlag EXPR
Definition: GPMG_Project.h:40
int getIterationsDone() const
get the iterations done
Definition: GPMG_Project.h:237
static SP::GPM_ModelGraph New()
create a test class
Definition: GPM_ModelGraph.h:56
#define tReal
Definition: types.h:18
static const tFlag GLOBAL_ENVIRONMENT
Definition: GPMG_Project.h:30
static const tFlag TRANSFORMER_GRAPH
Definition: GPMG_Project.h:34
virtual void saveToUIClass(UI_Class &mclass) const
how to save the object from a mate model class
Definition: GPMG_Project.cpp:107
void addToEnvironment(const tFlag &index, const tString &name, const tString &value)
add a string variable to environment
Definition: GPMG_Project.h:176
#define tFlag
Definition: types.h:14