1 // File : SMESH_smesh.hxx
2 // Created : Fri Nov 18 12:05:18 2005
3 // Author : Edward AGAPOV (eap)
5 #ifndef SMESH_smesh_HeaderFile
6 #define SMESH_smesh_HeaderFile
8 #include <Standard_DefineHandle.hxx>
9 #include <Standard_Type.hxx>
10 #include <Standard_Transient.hxx>
11 #include <TCollection_AsciiString.hxx>
12 #include <TColStd_SequenceOfAsciiString.hxx>
13 #include <TColStd_SequenceOfInteger.hxx>
19 * \brief Tool converting SMESH engine calls into commands defined in smesh.py
21 * This file was created in order to respond to requirement of bug PAL10494:
22 * SMESH python dump uses idl interface.
24 * The creation reason is that smesh.py commands defining hypotheses encapsulate
25 * several SMESH engine method calls. As well, the dependencies between smesh.py
26 * classes differ from ones between SMESH IDL interfaces.
28 * The only API method here is SMESH_2smeshpy::ConvertScript(), the rest ones are
31 * See comments to _pyHypothesis class to know how to assure convertion of a new hypothesis
34 class Resource_DataMapOfAsciiStringAsciiString;
40 * \brief Convert a python script using commands of smesh.py
41 * \param theScript - Input script
42 * \param theEntry2AccessorMethod - The returning method names to access to
43 * objects wrapped with python class
44 * \retval TCollection_AsciiString - Convertion result
46 static TCollection_AsciiString
47 ConvertScript(const TCollection_AsciiString& theScript,
48 Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod);
51 * \brief Return the name of the python file wrapping IDL API
52 * \retval TCollection_AsciiString - The file name
54 static char* SmeshpyName() { return "smesh"; }
55 static char* GenName() { return "smesh.smesh"; }
58 // =====================
60 // =====================
69 DEFINE_STANDARD_HANDLE (_pyCommand ,Standard_Transient);
70 DEFINE_STANDARD_HANDLE (_pyObject ,Standard_Transient);
71 DEFINE_STANDARD_HANDLE (_pyGen ,_pyObject);
72 DEFINE_STANDARD_HANDLE (_pyMesh ,_pyObject);
73 DEFINE_STANDARD_HANDLE (_pyHypothesis,_pyObject);
74 DEFINE_STANDARD_HANDLE (_pyAlgorithm ,_pyHypothesis);
77 * \brief Class operating on a command string looking like
78 * ResultValue = Object.Method( Arg1, Arg2,...)
80 class _pyCommand: public Standard_Transient
82 int myOrderNb; // position within the script
83 TCollection_AsciiString myString;
84 TCollection_AsciiString myRes, myObj, myMeth;
85 TColStd_SequenceOfAsciiString myArgs;
86 TColStd_SequenceOfInteger myBegPos; //!< where myRes, myObj, ... begin
87 std::list< Handle(_pyCommand) > myDependentCmds;
88 enum { UNKNOWN=-1, EMPTY=0, RESULT_IND, OBJECT_IND, METHOD_IND, ARG1_IND };
89 int GetBegPos( int thePartIndex );
90 void SetBegPos( int thePartIndex, int thePosition );
91 void SetPart( int thePartIndex, const TCollection_AsciiString& theNewPart,
92 TCollection_AsciiString& theOldPart);
93 void FindAllArgs() { GetArg(1); }
96 _pyCommand( const TCollection_AsciiString& theString, int theNb )
97 : myString( theString ), myOrderNb( theNb ) {};
98 TCollection_AsciiString & GetString() { return myString; }
99 int GetOrderNb() const { return myOrderNb; }
100 void SetOrderNb( int theNb ) { myOrderNb = theNb; }
101 int Length() { return myString.Length(); }
102 void Clear() { myString.Clear(); myBegPos.Clear(); }
103 bool IsEmpty() const { return myString.IsEmpty(); }
104 const TCollection_AsciiString & GetResultValue();
105 const TCollection_AsciiString & GetObject();
106 const TCollection_AsciiString & GetMethod();
107 const TCollection_AsciiString & GetArg( int index );
108 int GetNbArgs() { FindAllArgs(); return myArgs.Length(); }
109 //Handle(TColStd_HSequenceOfAsciiString) GetArgs();
110 void SetResultValue( const TCollection_AsciiString& theResult )
111 { GetResultValue(); SetPart( RESULT_IND, theResult, myRes ); }
112 void SetObject(const TCollection_AsciiString& theObject)
113 { GetObject(); SetPart( OBJECT_IND, theObject, myObj ); }
114 void SetMethod(const TCollection_AsciiString& theMethod)
115 { GetMethod(); SetPart( METHOD_IND, theMethod, myMeth ); }
116 void SetArg( int index, const TCollection_AsciiString& theArg);
118 static bool SkipSpaces( const TCollection_AsciiString & theSring, int & thePos );
119 static TCollection_AsciiString GetWord( const TCollection_AsciiString & theSring,
120 int & theStartPos, const bool theForward,
121 const bool dotIsWord = false);
122 void AddDependantCmd( Handle(_pyCommand) cmd)
123 { return myDependentCmds.push_back( cmd ); }
124 bool SetDependentCmdsAfter() const;
126 DEFINE_STANDARD_RTTI (_pyCommand)
130 * \brief Root of all objects
132 typedef TCollection_AsciiString _pyID;
134 class _pyObject: public Standard_Transient
136 Handle(_pyCommand) myCreationCmd;
138 _pyObject(const Handle(_pyCommand)& theCreationCmd): myCreationCmd(theCreationCmd) {}
139 const _pyID& GetID() { return myCreationCmd->GetResultValue(); }
140 const Handle(_pyCommand)& GetCreationCmd() { return myCreationCmd; }
141 void SetCreationCmd( Handle(_pyCommand) cmd ) { myCreationCmd = cmd; }
142 int GetCommandNb() { return myCreationCmd->GetOrderNb(); }
143 virtual void Process(const Handle(_pyCommand) & theCommand) = 0;
144 virtual void Flush() = 0;
146 DEFINE_STANDARD_RTTI (_pyObject)
150 * \brief Class corresponding to SMESH_Gen. It holds info on existing
151 * meshes and hypotheses
153 class _pyGen: public _pyObject
156 _pyGen(Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod);
158 void AddCommand( const TCollection_AsciiString& theCommand );
159 void Process( const Handle(_pyCommand)& theCommand );
161 Handle(_pyHypothesis) FindHyp( const _pyID& theHypID );
162 Handle(_pyHypothesis) FindAlgo( const _pyID& theGeom, const _pyID& theMesh,
163 const TCollection_AsciiString& theAlgoType);
164 void ExchangeCommands( Handle(_pyCommand) theCmd1, Handle(_pyCommand) theCmd2 );
165 void SetCommandAfter( Handle(_pyCommand) theCmd, Handle(_pyCommand) theAfterCmd );
166 std::list< Handle(_pyCommand) >& GetCommands() { return myCommands; }
167 void SetAccessorMethod(const _pyID& theID, const char* theMethod );
169 std::map< _pyID, Handle(_pyMesh) > myMeshes;
170 std::list< Handle(_pyHypothesis) > myHypos;
171 std::list< Handle(_pyCommand) > myCommands;
173 Resource_DataMapOfAsciiStringAsciiString& myID2AccessorMethod;
175 DEFINE_STANDARD_RTTI (_pyGen)
179 * \brief Contains commands concerning mesh substructures
181 class _pyMesh: public _pyObject
183 std::list< Handle(_pyCommand) > myAddHypCmds;
184 std::list< Handle(_pyCommand) > mySubmeshes;
186 _pyMesh(const Handle(_pyCommand) theCreationCmd);
187 const _pyID& GetGeom() { return GetCreationCmd()->GetArg(1); }
188 void Process( const Handle(_pyCommand)& theCommand);
191 static void AddMeshAccess( const Handle(_pyCommand)& theCommand )
192 { theCommand->SetObject( theCommand->GetObject() + ".GetMesh()" ); }
194 DEFINE_STANDARD_RTTI (_pyMesh)
198 * \brief Root class for hypothesis
200 * HOWTO assure convertion of a new hypothesis
201 * In NewHypothesis():
202 * 1. add a case for the name of the new hypothesis and
203 * 2. initialize _pyHypothesis fields:
204 * . myDim - hypothesis dimention;
205 * . myType - type name of the algorithm creating the hypothesis;
206 * . myCreationMethod - method name of the algorithm creating the hypothesis;
207 * . append to myArgMethods interface methods setting param values in the
208 * order they are used when myCreationMethod is called. It is supposed that
209 * each interface method sets only one parameter, if it is not so, you are
210 * to derive a specific class from _pyHypothesis that would redefine Process(),
211 * see _pyComplexParamHypo for example
213 class _pyHypothesis: public _pyObject
216 bool myIsAlgo, /*myIsLocal, */myIsWrapped, myIsConverted;
217 int myDim, myAdditionCmdNb;
218 _pyID myGeom, myMesh;
219 TCollection_AsciiString myCreationMethod, myType;
220 TColStd_SequenceOfAsciiString myArgs;
221 TColStd_SequenceOfAsciiString myArgMethods;
222 std::list<Handle(_pyCommand)> myArgCommands;
223 std::list<Handle(_pyCommand)> myUnknownCommands;
225 _pyHypothesis(const Handle(_pyCommand)& theCreationCmd);
226 virtual bool IsAlgo() const { return myIsAlgo; }
227 bool IsWrapped() const { return myIsWrapped; }
228 bool & IsConverted() { return myIsConverted; }
229 int GetDim() const { return myDim; }
230 const _pyID & GetGeom() const { return myGeom; }
231 void SetMesh( const _pyID& theMeshId) { if ( myMesh.IsEmpty() ) myMesh = theMeshId; }
232 const _pyID & GetMesh() const { return myMesh; }
233 const TCollection_AsciiString GetType() { return myType; }
234 bool IsWrappable(const _pyID& theMesh) { return !myIsWrapped && myMesh == theMesh; }
235 virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
236 const _pyID& theMesh);
237 static Handle(_pyHypothesis) NewHypothesis( const Handle(_pyCommand)& theCreationCmd);
238 // bool HasMesh() const { return !myMesh.IsEmpty(); }
239 // void SetGeom( const _pyID& theGeomID ) { myGeom = theGeomID; }
240 void Process( const Handle(_pyCommand)& theCommand);
243 DEFINE_STANDARD_RTTI (_pyHypothesis)
247 * \brief Class for hypotheses having several parameters modified by one method
249 class _pyComplexParamHypo: public _pyHypothesis
252 _pyComplexParamHypo(const Handle(_pyCommand)& theCreationCmd): _pyHypothesis(theCreationCmd) {}
253 void Process( const Handle(_pyCommand)& theCommand);
255 DEFINE_STANDARD_RTTI (_pyComplexParamHypo)
257 DEFINE_STANDARD_HANDLE (_pyComplexParamHypo, _pyHypothesis);
261 * \brief Class representing NumberOfSegments hypothesis
263 class _pyNumberOfSegmentsHyp: public _pyHypothesis
266 _pyNumberOfSegmentsHyp(const Handle(_pyCommand)& theCrCmd): _pyHypothesis(theCrCmd) {}
267 virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
268 const _pyID& theMesh);
270 DEFINE_STANDARD_RTTI (_pyNumberOfSegmentsHyp)
272 DEFINE_STANDARD_HANDLE (_pyNumberOfSegmentsHyp, _pyHypothesis);
275 * \brief Class representing smesh.Mesh_Algorithm
277 class _pyAlgorithm: public _pyHypothesis
280 _pyAlgorithm(const Handle(_pyCommand)& theCreationCmd);
281 virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
282 const _pyID& theMesh);
284 DEFINE_STANDARD_RTTI (_pyAlgorithm)