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 enum { UNKNOWN=-1, EMPTY=0, RESULT_IND, OBJECT_IND, METHOD_IND, ARG1_IND };
88 int GetBegPos( int thePartIndex );
89 void SetBegPos( int thePartIndex, int thePosition );
90 void SetPart( int thePartIndex, const TCollection_AsciiString& theNewPart,
91 TCollection_AsciiString& theOldPart);
92 void FindAllArgs() { GetArg(1); }
95 _pyCommand( const TCollection_AsciiString& theString, int theNb )
96 : myString( theString ), myOrderNb( theNb ) {};
97 TCollection_AsciiString & GetString() { return myString; }
98 int GetOrderNb() const { return myOrderNb; }
99 void SetOrderNb( int theNb ) { myOrderNb = theNb; }
100 int Length() { return myString.Length(); }
101 void Clear() { myString.Clear(); myBegPos.Clear(); }
102 bool IsEmpty() const { return myString.IsEmpty(); }
103 const TCollection_AsciiString & GetResultValue();
104 const TCollection_AsciiString & GetObject();
105 const TCollection_AsciiString & GetMethod();
106 const TCollection_AsciiString & GetArg( int index );
107 int GetNbArgs() { FindAllArgs(); return myArgs.Length(); }
108 //Handle(TColStd_HSequenceOfAsciiString) GetArgs();
109 void SetResultValue( const TCollection_AsciiString& theResult )
110 { GetResultValue(); SetPart( RESULT_IND, theResult, myRes ); }
111 void SetObject(const TCollection_AsciiString& theObject)
112 { GetObject(); SetPart( OBJECT_IND, theObject, myObj ); }
113 void SetMethod(const TCollection_AsciiString& theMethod)
114 { GetMethod(); SetPart( METHOD_IND, theMethod, myMeth ); }
115 void SetArg( int index, const TCollection_AsciiString& theArg);
117 static bool SkipSpaces( const TCollection_AsciiString & theSring, int & thePos );
118 static TCollection_AsciiString GetWord( const TCollection_AsciiString & theSring,
119 int & theStartPos, const bool theForward,
120 const bool dotIsWord = false);
121 DEFINE_STANDARD_RTTI (_pyCommand)
125 * \brief Root of all objects
127 typedef TCollection_AsciiString _pyID;
129 class _pyObject: public Standard_Transient
131 Handle(_pyCommand) myCreationCmd;
133 _pyObject(const Handle(_pyCommand)& theCreationCmd): myCreationCmd(theCreationCmd) {}
134 const _pyID& GetID() { return myCreationCmd->GetResultValue(); }
135 const Handle(_pyCommand)& GetCreationCmd() { return myCreationCmd; }
136 int GetCommandNb() { return myCreationCmd->GetOrderNb(); }
137 virtual void Process(const Handle(_pyCommand) & theCommand) = 0;
138 virtual void Flush() = 0;
140 DEFINE_STANDARD_RTTI (_pyObject)
144 * \brief Class corresponding to SMESH_Gen. It holds info on existing
145 * meshes and hypotheses
147 class _pyGen: public _pyObject
150 _pyGen(Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod);
152 void AddCommand( const TCollection_AsciiString& theCommand );
153 void Process( const Handle(_pyCommand)& theCommand );
155 Handle(_pyHypothesis) FindHyp( const _pyID& theHypID );
156 Handle(_pyHypothesis) FindAlgo( const _pyID& theGeom, const _pyID& theMesh,
157 const TCollection_AsciiString& theAlgoType);
158 void ExchangeCommands( Handle(_pyCommand) theCmd1, Handle(_pyCommand) theCmd2 );
159 void SetCommandAfter( Handle(_pyCommand) theCmd, Handle(_pyCommand) theAfterCmd );
160 std::list< Handle(_pyCommand) >& GetCommands() { return myCommands; }
161 void SetAccessorMethod(const _pyID& theID, const char* theMethod );
163 std::map< _pyID, Handle(_pyMesh) > myMeshes;
164 std::list< Handle(_pyHypothesis) > myHypos;
165 std::list< Handle(_pyCommand) > myCommands;
167 Resource_DataMapOfAsciiStringAsciiString& myID2AccessorMethod;
169 DEFINE_STANDARD_RTTI (_pyGen)
173 * \brief Contains commands concerning mesh substructures
175 class _pyMesh: public _pyObject
177 std::list< Handle(_pyCommand) > myAddHypCmds;
178 std::list< Handle(_pyCommand) > mySubmeshes;
180 _pyMesh(const Handle(_pyCommand) theCreationCmd);
181 const _pyID& GetGeom() { return GetCreationCmd()->GetArg(1); }
182 void Process( const Handle(_pyCommand)& theCommand);
185 static void AddMeshAccess( const Handle(_pyCommand)& theCommand )
186 { theCommand->SetObject( theCommand->GetObject() + ".GetMesh()" ); }
188 DEFINE_STANDARD_RTTI (_pyMesh)
192 * \brief Root class for hypothesis
194 * HOWTO assure convertion of a new hypothesis
195 * In NewHypothesis():
196 * 1. add a case for the name of the new hypothesis and
197 * 2. initialize _pyHypothesis fields:
198 * . myDim - hypothesis dimention;
199 * . myType - type name of the algorithm creating the hypothesis;
200 * . myCreationMethod - method name of the algorithm creating the hypothesis;
201 * . append to myArgMethods interface methods setting param values in the
202 * order they are used when myCreationMethod is called. It is supposed that
203 * each interface method sets only one parameter, if it is not so, you are
204 * to derive a specific class from _pyHypothesis that would redefine Process(),
205 * see _pyComplexParamHypo for example
207 class _pyHypothesis: public _pyObject
210 bool myIsAlgo, /*myIsLocal, */myIsWrapped, myIsConverted;
211 int myDim, myAdditionCmdNb;
212 _pyID myGeom, myMesh;
213 TCollection_AsciiString myCreationMethod, myType;
214 TColStd_SequenceOfAsciiString myArgs;
215 TColStd_SequenceOfAsciiString myArgMethods;
216 std::list<Handle(_pyCommand)> myArgCommands;
217 std::list<Handle(_pyCommand)> myUnknownCommands;
219 _pyHypothesis(const Handle(_pyCommand)& theCreationCmd);
220 virtual bool IsAlgo() const { return myIsAlgo; }
221 bool IsWrapped() const { return myIsWrapped; }
222 bool & IsConverted() { return myIsConverted; }
223 int GetDim() const { return myDim; }
224 const _pyID & GetGeom() const { return myGeom; }
225 void SetMesh( const _pyID& theMeshId) { if ( myMesh.IsEmpty() ) myMesh = theMeshId; }
226 const _pyID & GetMesh() const { return myMesh; }
227 const TCollection_AsciiString GetType() { return myType; }
228 bool IsWrappable(const _pyID& theMesh) { return !myIsWrapped && myMesh == theMesh; }
229 virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
230 const _pyID& theMesh);
231 static Handle(_pyHypothesis) NewHypothesis( const Handle(_pyCommand)& theCreationCmd);
232 // bool HasMesh() const { return !myMesh.IsEmpty(); }
233 // void SetGeom( const _pyID& theGeomID ) { myGeom = theGeomID; }
234 void Process( const Handle(_pyCommand)& theCommand);
237 DEFINE_STANDARD_RTTI (_pyHypothesis)
241 * \brief Class for hypotheses having several parameters modified by one method
243 class _pyComplexParamHypo: public _pyHypothesis
246 _pyComplexParamHypo(const Handle(_pyCommand)& theCreationCmd): _pyHypothesis(theCreationCmd) {}
247 void Process( const Handle(_pyCommand)& theCommand);
249 DEFINE_STANDARD_RTTI (_pyComplexParamHypo)
251 DEFINE_STANDARD_HANDLE (_pyComplexParamHypo, _pyHypothesis);
255 * \brief Class representing NumberOfSegments hypothesis
257 class _pyNumberOfSegmentsHyp: public _pyHypothesis
260 _pyNumberOfSegmentsHyp(const Handle(_pyCommand)& theCrCmd): _pyHypothesis(theCrCmd) {}
261 virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
262 const _pyID& theMesh);
264 DEFINE_STANDARD_RTTI (_pyNumberOfSegmentsHyp)
266 DEFINE_STANDARD_HANDLE (_pyNumberOfSegmentsHyp, _pyHypothesis);
269 * \brief Class representing smesh.Mesh_Algorithm
271 class _pyAlgorithm: public _pyHypothesis
274 _pyAlgorithm(const Handle(_pyCommand)& theCreationCmd);
275 virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
276 const _pyID& theMesh);
278 DEFINE_STANDARD_RTTI (_pyAlgorithm)