Salome HOME
Addition of notification mechanism in evalyfx.
[modules/yacs.git] / src / evalyfx / YACSEvalYFXPattern.hxx
1 // Copyright (C) 2012-2015  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 // 
19 // Author : Anthony Geay (EDF R&D)
20
21 #ifndef __YACSEVALYFXPATTERN_HXX__
22 #define __YACSEVALYFXPATTERN_HXX__
23
24 #include "YACSEvalPort.hxx"
25
26 #include <vector>
27
28 namespace YACS
29 {
30   namespace ENGINE
31   {
32     class Proc;
33     class TypeCode;
34     class ForEachLoop;
35     class ComposedNode;
36     class InputPyPort;
37   }
38 }
39
40 class YACSEvalYFX;
41 class YACSEvalObserver;
42 class YACSEvalListOfResources;
43 class ResourcesManager_cpp;
44 class YACSEvalYFXRunOnlyPatternInternalObserver;
45
46 class YACSEvalYFXPattern
47 {
48 public:
49   virtual ~YACSEvalYFXPattern();
50   std::vector< YACSEvalInputPort *> getFreeInputPorts() const;
51   std::vector< YACSEvalOutputPort *> getFreeOutputPorts() const;
52   static YACSEvalYFXPattern *FindPatternFrom(YACSEvalYFX *boss, YACS::ENGINE::Proc *scheme, bool ownScheme);
53   bool isAlreadyComputedResources() const;
54   void checkNonAlreadyComputedResources() const;
55   void checkAlreadyComputedResources() const;
56   void checkLocked() const;
57   void checkNonLocked() const;
58   static void CheckNodeIsOK(YACS::ENGINE::ComposedNode *node);
59   void registerObserver(YACSEvalObserver *observer);
60   YACSEvalObserver *getObserver() const { return _observer; }
61   YACSEvalYFX *getBoss() const { return _boss; }
62   virtual void setOutPortsOfInterestForEvaluation(const std::vector<YACSEvalOutputPort *>& outputs) = 0;
63   virtual void resetOutputsOfInterest() = 0;
64   virtual void generateGraph() = 0;
65   virtual void resetGeneratedGraph() = 0;
66   virtual void assignRandomVarsInputs() = 0;
67   virtual int assignNbOfBranches() = 0;
68   virtual bool isLocked() const = 0;
69   virtual YACSEvalListOfResources *giveResources() = 0;
70   virtual YACS::ENGINE::Proc *getUndergroundGeneratedGraph() const = 0;
71   virtual std::vector<YACSEvalSeqAny *> getResults() const = 0;
72   virtual void emitStart() const = 0;
73 public:
74   static const char DFT_PROC_NAME[];
75 protected:
76   YACSEvalYFXPattern(YACSEvalYFX *boss, YACS::ENGINE::Proc *scheme, bool ownScheme);
77   YACS::ENGINE::TypeCode *createSeqTypeCodeFrom(YACS::ENGINE::Proc *scheme, const std::string& zeType);
78   void setResources(YACSEvalListOfResources *res);
79   void resetResources();
80   YACSEvalListOfResources *getResourcesInternal() const { return _res; }
81   ResourcesManager_cpp *getCatalogInAppli() const { return _rm; }
82   static YACSEvalSeqAny *BuildValueInPort(YACS::ENGINE::InputPyPort *port);
83 private:
84   void cleanScheme();
85 private:
86   YACSEvalYFX *_boss;
87   bool _ownScheme;
88   YACS::ENGINE::Proc *_scheme;
89   ResourcesManager_cpp *_rm;
90   YACSEvalListOfResources *_res;
91   mutable YACSEvalObserver *_observer;
92 protected:
93   std::vector< YACSEvalInputPort > _inputs;
94   std::vector< YACSEvalOutputPort > _outputs;
95 };
96
97 class YACSEvalYFXRunOnlyPattern : public YACSEvalYFXPattern
98 {
99 public:
100   YACSEvalYFXRunOnlyPattern(YACSEvalYFX *boss, YACS::ENGINE::Proc *scheme, bool ownScheme, YACS::ENGINE::ComposedNode *runNode);
101   ~YACSEvalYFXRunOnlyPattern();
102   void setOutPortsOfInterestForEvaluation(const std::vector<YACSEvalOutputPort *>& outputsOfInterest);
103   void resetOutputsOfInterest();
104   void generateGraph();
105   void resetGeneratedGraph();
106   int assignNbOfBranches();
107   void assignRandomVarsInputs();
108   bool isLocked() const;
109   YACSEvalListOfResources *giveResources();
110   YACS::ENGINE::Proc *getUndergroundGeneratedGraph() const;
111   std::vector<YACSEvalSeqAny *> getResults() const;
112   void emitStart() const;
113   //
114   YACS::ENGINE::ForEachLoop *getUndergroundForEach() const { return _FEInGeneratedGraph; }
115   static bool IsMatching(YACS::ENGINE::Proc *scheme, YACS::ENGINE::ComposedNode *& runNode);
116 public:
117   static const char GATHER_NODE_NAME[];
118 private:
119   void buildInputPorts();
120   void buildOutputPorts();
121 private:
122   YACS::ENGINE::ComposedNode *_runNode;
123   std::vector<YACSEvalOutputPort *> _outputsOfInterest;
124   YACS::ENGINE::Proc *_generatedGraph;
125   YACS::ENGINE::ForEachLoop *_FEInGeneratedGraph;
126   YACSEvalYFXRunOnlyPatternInternalObserver *_obs;
127 };
128
129 #endif