Salome HOME
Merge branch 'V7_7_BR'
[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 #ifdef WIN32
29 #define NOMINMAX
30 #endif
31
32 namespace YACS
33 {
34   namespace ENGINE
35   {
36     class Proc;
37     class TypeCode;
38     class ForEachLoop;
39     class ComposedNode;
40     class InputPyPort;
41   }
42 }
43
44 class YACSEvalYFX;
45 class YACSEvalObserver;
46 class YACSEvalListOfResources;
47 class ResourcesManager_cpp;
48 class YACSEvalYFXRunOnlyPatternInternalObserver;
49
50 class YACSEvalYFXPattern
51 {
52 public:
53   virtual ~YACSEvalYFXPattern();
54   std::vector< YACSEvalInputPort *> getFreeInputPorts() const;
55   std::vector< YACSEvalOutputPort *> getFreeOutputPorts() const;
56   static YACSEvalYFXPattern *FindPatternFrom(YACSEvalYFX *boss, YACS::ENGINE::Proc *scheme, bool ownScheme);
57   void setParallelizeStatus(bool newVal) { _parallelizeStatus=newVal; }
58   bool getParallelizeStatus() const { return _parallelizeStatus; }
59   bool isAlreadyComputedResources() const;
60   void checkNonAlreadyComputedResources() const;
61   void checkAlreadyComputedResources() const;
62   void checkLocked() const;
63   void checkNonLocked() const;
64   static void CheckNodeIsOK(YACS::ENGINE::ComposedNode *node);
65   void registerObserver(YACSEvalObserver *observer);
66   YACSEvalObserver *getObserver() const { return _observer; }
67   YACSEvalYFX *getBoss() const { return _boss; }
68   virtual void setOutPortsOfInterestForEvaluation(const std::vector<YACSEvalOutputPort *>& outputs) = 0;
69   virtual void resetOutputsOfInterest() = 0;
70   virtual void generateGraph() = 0;
71   virtual void resetGeneratedGraph() = 0;
72   virtual void assignRandomVarsInputs() = 0;
73   virtual int assignNbOfBranches() = 0;
74   virtual bool isLocked() const = 0;
75   virtual YACSEvalListOfResources *giveResources() = 0;
76   virtual YACS::ENGINE::Proc *getUndergroundGeneratedGraph() const = 0;
77   virtual std::vector<YACSEvalSeqAny *> getResults() const = 0;
78   virtual void emitStart() const = 0;
79 public:
80   static const char DFT_PROC_NAME[];
81 protected:
82   YACSEvalYFXPattern(YACSEvalYFX *boss, YACS::ENGINE::Proc *scheme, bool ownScheme);
83   YACS::ENGINE::TypeCode *createSeqTypeCodeFrom(YACS::ENGINE::Proc *scheme, const std::string& zeType);
84   void setResources(YACSEvalListOfResources *res);
85   void resetResources();
86   YACSEvalListOfResources *getResourcesInternal() const { return _res; }
87   ResourcesManager_cpp *getCatalogInAppli() const { return _rm; }
88   static YACSEvalSeqAny *BuildValueInPort(YACS::ENGINE::InputPyPort *port);
89 private:
90   void cleanScheme();
91 private:
92   YACSEvalYFX *_boss;
93   bool _ownScheme;
94   bool _parallelizeStatus;
95   YACS::ENGINE::Proc *_scheme;
96   ResourcesManager_cpp *_rm;
97   YACSEvalListOfResources *_res;
98   mutable YACSEvalObserver *_observer;
99 protected:
100   std::vector< YACSEvalInputPort > _inputs;
101   std::vector< YACSEvalOutputPort > _outputs;
102 };
103
104 class YACSEvalYFXRunOnlyPattern : public YACSEvalYFXPattern
105 {
106 public:
107   YACSEvalYFXRunOnlyPattern(YACSEvalYFX *boss, YACS::ENGINE::Proc *scheme, bool ownScheme, YACS::ENGINE::ComposedNode *runNode);
108   ~YACSEvalYFXRunOnlyPattern();
109   void setOutPortsOfInterestForEvaluation(const std::vector<YACSEvalOutputPort *>& outputsOfInterest);
110   void resetOutputsOfInterest();
111   void generateGraph();
112   void resetGeneratedGraph();
113   int assignNbOfBranches();
114   void assignRandomVarsInputs();
115   bool isLocked() const;
116   YACSEvalListOfResources *giveResources();
117   YACS::ENGINE::Proc *getUndergroundGeneratedGraph() const;
118   std::vector<YACSEvalSeqAny *> getResults() const;
119   void emitStart() const;
120   //
121   YACS::ENGINE::ForEachLoop *getUndergroundForEach() const { return _FEInGeneratedGraph; }
122   static bool IsMatching(YACS::ENGINE::Proc *scheme, YACS::ENGINE::ComposedNode *& runNode);
123 public:
124   static const char GATHER_NODE_NAME[];
125 private:
126   void buildInputPorts();
127   void buildOutputPorts();
128 private:
129   YACS::ENGINE::ComposedNode *_runNode;
130   std::vector<YACSEvalOutputPort *> _outputsOfInterest;
131   YACS::ENGINE::Proc *_generatedGraph;
132   YACS::ENGINE::ForEachLoop *_FEInGeneratedGraph;
133   YACSEvalYFXRunOnlyPatternInternalObserver *_obs;
134 };
135
136 #endif