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);
76 typedef TCollection_AsciiString _pyID;
78 // ===========================================================
80 * \brief Class operating on a command string looking like
81 * ResultValue = Object.Method( Arg1, Arg2,...)
83 // ===========================================================
85 class _pyCommand: public Standard_Transient
87 int myOrderNb; //!< position within the script
88 TCollection_AsciiString myString; //!< command text
89 TCollection_AsciiString myRes, myObj, myMeth; //!< found parts of command
90 TColStd_SequenceOfAsciiString myArgs; //!< found arguments
91 TColStd_SequenceOfInteger myBegPos; //!< where myRes, myObj, ... begin
92 std::list< Handle(_pyCommand) > myDependentCmds; //!< commands that sould follow me in the script
94 enum { UNKNOWN=-1, EMPTY=0, RESULT_IND, OBJECT_IND, METHOD_IND, ARG1_IND };
95 int GetBegPos( int thePartIndex );
96 void SetBegPos( int thePartIndex, int thePosition );
97 void SetPart( int thePartIndex, const TCollection_AsciiString& theNewPart,
98 TCollection_AsciiString& theOldPart);
99 void FindAllArgs() { GetArg(1); }
103 _pyCommand( const TCollection_AsciiString& theString, int theNb )
104 : myString( theString ), myOrderNb( theNb ) {};
105 TCollection_AsciiString & GetString() { return myString; }
106 int GetOrderNb() const { return myOrderNb; }
107 void SetOrderNb( int theNb ) { myOrderNb = theNb; }
108 int Length() { return myString.Length(); }
109 void Clear() { myString.Clear(); myBegPos.Clear(); }
110 bool IsEmpty() const { return myString.IsEmpty(); }
111 const TCollection_AsciiString & GetResultValue();
112 const TCollection_AsciiString & GetObject();
113 const TCollection_AsciiString & GetMethod();
114 const TCollection_AsciiString & GetArg( int index );
115 int GetNbArgs() { FindAllArgs(); return myArgs.Length(); }
116 //Handle(TColStd_HSequenceOfAsciiString) GetArgs();
117 void SetResultValue( const TCollection_AsciiString& theResult )
118 { GetResultValue(); SetPart( RESULT_IND, theResult, myRes ); }
119 void SetObject(const TCollection_AsciiString& theObject)
120 { GetObject(); SetPart( OBJECT_IND, theObject, myObj ); }
121 void SetMethod(const TCollection_AsciiString& theMethod)
122 { GetMethod(); SetPart( METHOD_IND, theMethod, myMeth ); }
123 void SetArg( int index, const TCollection_AsciiString& theArg);
125 static bool SkipSpaces( const TCollection_AsciiString & theSring, int & thePos );
126 static TCollection_AsciiString GetWord( const TCollection_AsciiString & theSring,
127 int & theStartPos, const bool theForward,
128 const bool dotIsWord = false);
129 void AddDependantCmd( Handle(_pyCommand) cmd)
130 { return myDependentCmds.push_back( cmd ); }
131 bool SetDependentCmdsAfter() const;
133 bool AddAccessorMethod( _pyID theObjectID, const char* theAcsMethod );
135 DEFINE_STANDARD_RTTI (_pyCommand)
139 * \brief Root of all objects
142 class _pyObject: public Standard_Transient
144 Handle(_pyCommand) myCreationCmd;
146 _pyObject(const Handle(_pyCommand)& theCreationCmd): myCreationCmd(theCreationCmd) {}
147 const _pyID& GetID() { return myCreationCmd->GetResultValue(); }
148 const Handle(_pyCommand)& GetCreationCmd() { return myCreationCmd; }
149 void SetCreationCmd( Handle(_pyCommand) cmd ) { myCreationCmd = cmd; }
150 int GetCommandNb() { return myCreationCmd->GetOrderNb(); }
151 virtual void Process(const Handle(_pyCommand) & theCommand) = 0;
152 virtual void Flush() = 0;
153 virtual const char* AccessorMethod() const;
155 DEFINE_STANDARD_RTTI (_pyObject)
159 * \brief Class corresponding to SMESH_Gen. It holds info on existing
160 * meshes and hypotheses
162 class _pyGen: public _pyObject
165 _pyGen(Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod);
167 void AddCommand( const TCollection_AsciiString& theCommand );
168 void Process( const Handle(_pyCommand)& theCommand );
170 Handle(_pyHypothesis) FindHyp( const _pyID& theHypID );
171 Handle(_pyHypothesis) FindAlgo( const _pyID& theGeom, const _pyID& theMesh,
172 const TCollection_AsciiString& theAlgoType);
173 void ExchangeCommands( Handle(_pyCommand) theCmd1, Handle(_pyCommand) theCmd2 );
174 void SetCommandAfter( Handle(_pyCommand) theCmd, Handle(_pyCommand) theAfterCmd );
175 std::list< Handle(_pyCommand) >& GetCommands() { return myCommands; }
176 void SetAccessorMethod(const _pyID& theID, const char* theMethod );
177 const char* AccessorMethod() const { return SMESH_2smeshpy::GenName(); }
179 std::map< _pyID, Handle(_pyMesh) > myMeshes;
180 std::list< Handle(_pyHypothesis) > myHypos;
181 std::list< Handle(_pyCommand) > myCommands;
184 Resource_DataMapOfAsciiStringAsciiString& myID2AccessorMethod;
186 DEFINE_STANDARD_RTTI (_pyGen)
190 * \brief Contains commands concerning mesh substructures
192 #define _pyMesh_ACCESS_METHOD "GetMesh()"
193 class _pyMesh: public _pyObject
195 std::list< Handle(_pyHypothesis) > myHypos;
196 std::list< Handle(_pyCommand) > myAddHypCmds;
197 std::list< Handle(_pyCommand) > mySubmeshes;
200 _pyMesh(const Handle(_pyCommand) theCreationCmd);
201 const _pyID& GetGeom() { return GetCreationCmd()->GetArg(1); }
202 void Process( const Handle(_pyCommand)& theCommand);
204 const char* AccessorMethod() const { return _pyMesh_ACCESS_METHOD; }
206 static void AddMeshAccess( const Handle(_pyCommand)& theCommand )
207 { theCommand->SetObject( theCommand->GetObject() + "." _pyMesh_ACCESS_METHOD ); }
209 DEFINE_STANDARD_RTTI (_pyMesh)
211 #undef _pyMesh_ACCESS_METHOD
214 * \brief Root class for hypothesis
216 * HOWTO assure convertion of a new hypothesis
217 * In NewHypothesis():
218 * 1. add a case for the name of the new hypothesis and
219 * 2. initialize _pyHypothesis fields:
220 * . myDim - hypothesis dimention;
221 * . myType - type name of the algorithm creating the hypothesis;
222 * . myCreationMethod - method name of the algorithm creating the hypothesis;
223 * . append to myArgMethods interface methods setting param values in the
224 * order they are used when myCreationMethod is called. It is supposed that
225 * each interface method sets only one parameter, if it is not so, you are
226 * to derive a specific class from _pyHypothesis that would redefine Process(),
227 * see _pyComplexParamHypo for example
229 class _pyHypothesis: public _pyObject
232 bool myIsAlgo, /*myIsLocal, */myIsWrapped, myIsConverted;
233 int myDim, myAdditionCmdNb;
234 _pyID myGeom, myMesh;
235 TCollection_AsciiString myCreationMethod, myType;
236 TColStd_SequenceOfAsciiString myArgs;
237 TColStd_SequenceOfAsciiString myArgMethods;
238 std::list<Handle(_pyCommand)> myArgCommands;
239 std::list<Handle(_pyCommand)> myUnknownCommands;
241 _pyHypothesis(const Handle(_pyCommand)& theCreationCmd);
242 virtual bool IsAlgo() const { return myIsAlgo; }
243 bool IsWrapped() const { return myIsWrapped; }
244 bool & IsConverted() { return myIsConverted; }
245 int GetDim() const { return myDim; }
246 const _pyID & GetGeom() const { return myGeom; }
247 void SetMesh( const _pyID& theMeshId) { if ( myMesh.IsEmpty() ) myMesh = theMeshId; }
248 const _pyID & GetMesh() const { return myMesh; }
249 const TCollection_AsciiString GetType() { return myType; }
250 bool IsWrappable(const _pyID& theMesh) { return !myIsWrapped && myMesh == theMesh; }
251 virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
252 const _pyID& theMesh);
253 static Handle(_pyHypothesis) NewHypothesis( const Handle(_pyCommand)& theCreationCmd);
254 // bool HasMesh() const { return !myMesh.IsEmpty(); }
255 // void SetGeom( const _pyID& theGeomID ) { myGeom = theGeomID; }
256 void Process( const Handle(_pyCommand)& theCommand);
259 DEFINE_STANDARD_RTTI (_pyHypothesis)
263 * \brief Class for hypotheses having several parameters modified by one method
265 class _pyComplexParamHypo: public _pyHypothesis
268 _pyComplexParamHypo(const Handle(_pyCommand)& theCreationCmd): _pyHypothesis(theCreationCmd) {}
269 void Process( const Handle(_pyCommand)& theCommand);
271 DEFINE_STANDARD_RTTI (_pyComplexParamHypo)
273 DEFINE_STANDARD_HANDLE (_pyComplexParamHypo, _pyHypothesis);
277 * \brief Class representing NumberOfSegments hypothesis
279 class _pyNumberOfSegmentsHyp: public _pyHypothesis
282 _pyNumberOfSegmentsHyp(const Handle(_pyCommand)& theCrCmd): _pyHypothesis(theCrCmd) {}
283 virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
284 const _pyID& theMesh);
287 DEFINE_STANDARD_RTTI (_pyNumberOfSegmentsHyp)
289 DEFINE_STANDARD_HANDLE (_pyNumberOfSegmentsHyp, _pyHypothesis);
292 * \brief Class representing smesh.Mesh_Algorithm
294 class _pyAlgorithm: public _pyHypothesis
297 _pyAlgorithm(const Handle(_pyCommand)& theCreationCmd);
298 virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
299 const _pyID& theMesh);
300 const char* AccessorMethod() const { return "GetAlgorithm()"; }
302 DEFINE_STANDARD_RTTI (_pyAlgorithm)