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
32 class Resource_DataMapOfAsciiStringAsciiString;
38 * \brief Convert a python script using commands of smesh.py
39 * \param theScript - Input script
40 * \param theEntry2AccessorMethod - The returning method names to access to
41 * objects wrapped with python class
42 * \retval TCollection_AsciiString - Convertion result
44 static TCollection_AsciiString
45 ConvertScript(const TCollection_AsciiString& theScript,
46 Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod);
49 * \brief Return the name of the python file wrapping IDL API
50 * \retval TCollection_AsciiString - The file name
52 static char* SmeshpyName() { return "smesh"; }
53 static char* GenName() { return "smesh.smesh"; }
56 // =====================
58 // =====================
67 DEFINE_STANDARD_HANDLE (_pyCommand ,Standard_Transient);
68 DEFINE_STANDARD_HANDLE (_pyObject ,Standard_Transient);
69 DEFINE_STANDARD_HANDLE (_pyGen ,_pyObject);
70 DEFINE_STANDARD_HANDLE (_pyMesh ,_pyObject);
71 DEFINE_STANDARD_HANDLE (_pyHypothesis,_pyObject);
72 DEFINE_STANDARD_HANDLE (_pyAlgorithm ,_pyHypothesis);
75 * \brief Class operating on a command string looking like
76 * ResultValue = Object.Method( Arg1, Arg2,...)
78 class _pyCommand: public Standard_Transient
80 int myOrderNb; // position within the script
81 TCollection_AsciiString myString;
82 TCollection_AsciiString myRes, myObj, myMeth;
83 TColStd_SequenceOfAsciiString myArgs;
84 TColStd_SequenceOfInteger myBegPos; //!< where myRes, myObj, ... begin
85 enum { UNKNOWN=-1, EMPTY=0, RESULT_IND, OBJECT_IND, METHOD_IND, ARG1_IND };
86 int GetBegPos( int thePartIndex );
87 void SetBegPos( int thePartIndex, int thePosition );
88 void SetPart( int thePartIndex, const TCollection_AsciiString& theNewPart,
89 TCollection_AsciiString& theOldPart);
90 void FindAllArgs() { GetArg(1); }
93 _pyCommand( const TCollection_AsciiString& theString, int theNb )
94 : myString( theString ), myOrderNb( theNb ) {};
95 TCollection_AsciiString & GetString() { return myString; }
96 int GetOrderNb() const { return myOrderNb; }
97 void SetOrderNb( int theNb ) { myOrderNb = theNb; }
98 int Length() { return myString.Length(); }
99 void Clear() { myString.Clear(); myBegPos.Clear(); }
100 bool IsEmpty() const { return myString.IsEmpty(); }
101 const TCollection_AsciiString & GetResultValue();
102 const TCollection_AsciiString & GetObject();
103 const TCollection_AsciiString & GetMethod();
104 const TCollection_AsciiString & GetArg( int index );
105 int GetNbArgs() { FindAllArgs(); return myArgs.Length(); }
106 //Handle(TColStd_HSequenceOfAsciiString) GetArgs();
107 void SetResultValue( const TCollection_AsciiString& theResult )
108 { GetResultValue(); SetPart( RESULT_IND, theResult, myRes ); }
109 void SetObject(const TCollection_AsciiString& theObject)
110 { GetObject(); SetPart( OBJECT_IND, theObject, myObj ); }
111 void SetMethod(const TCollection_AsciiString& theMethod)
112 { GetMethod(); SetPart( METHOD_IND, theMethod, myMeth ); }
113 void SetArg( int index, const TCollection_AsciiString& theArg);
115 static bool SkipSpaces( const TCollection_AsciiString & theSring, int & thePos );
116 static TCollection_AsciiString GetWord( const TCollection_AsciiString & theSring,
117 int & theStartPos, const bool theForward,
118 const bool dotIsWord = false);
119 DEFINE_STANDARD_RTTI (_pyCommand)
123 * \brief Root of all objects
125 typedef TCollection_AsciiString _pyID;
127 class _pyObject: public Standard_Transient
129 Handle(_pyCommand) myCreationCmd;
131 _pyObject(const Handle(_pyCommand)& theCreationCmd): myCreationCmd(theCreationCmd) {}
132 const _pyID& GetID() { return myCreationCmd->GetResultValue(); }
133 const Handle(_pyCommand)& GetCreationCmd() { return myCreationCmd; }
134 int GetCommandNb() { return myCreationCmd->GetOrderNb(); }
135 virtual void Process(const Handle(_pyCommand) & theCommand) = 0;
136 virtual void Flush() = 0;
138 DEFINE_STANDARD_RTTI (_pyObject)
142 * \brief Class corresponding to SMESH_Gen. It holds info on existing
143 * meshes and hypotheses
145 class _pyGen: public _pyObject
148 _pyGen(Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod);
150 void AddCommand( const TCollection_AsciiString& theCommand );
151 void Process( const Handle(_pyCommand)& theCommand );
153 Handle(_pyHypothesis) FindHyp( const _pyID& theHypID );
154 Handle(_pyHypothesis) FindAlgo( const _pyID& theGeom, const _pyID& theMesh,
155 const TCollection_AsciiString& theAlgoType);
156 void ExchangeCommands( Handle(_pyCommand) theCmd1, Handle(_pyCommand) theCmd2 );
157 void SetCommandAfter( Handle(_pyCommand) theCmd, Handle(_pyCommand) theAfterCmd );
158 std::list< Handle(_pyCommand) >& GetCommands() { return myCommands; }
159 void SetAccessorMethod(const _pyID& theID, const char* theMethod );
161 std::map< _pyID, Handle(_pyMesh) > myMeshes;
162 std::list< Handle(_pyHypothesis) > myHypos;
163 std::list< Handle(_pyCommand) > myCommands;
165 Resource_DataMapOfAsciiStringAsciiString& myID2AccessorMethod;
167 DEFINE_STANDARD_RTTI (_pyGen)
171 * \brief Contains commands concerning mesh substructures
173 class _pyMesh: public _pyObject
175 std::list< Handle(_pyCommand) > myAddHypCmds;
176 std::list< Handle(_pyCommand) > mySubmeshes;
178 _pyMesh(const Handle(_pyCommand) theCreationCmd);
179 const _pyID& GetGeom() { return GetCreationCmd()->GetArg(1); }
180 void Process( const Handle(_pyCommand)& theCommand);
183 static void AddMeshAccess( const Handle(_pyCommand)& theCommand )
184 { theCommand->SetObject( theCommand->GetObject() + ".GetMesh()" ); }
186 DEFINE_STANDARD_RTTI (_pyMesh)
190 * \brief Root class for smesh.Mesh_Algorithm
192 class _pyHypothesis: public _pyObject
195 bool myIsAlgo, /*myIsLocal, */myIsWrapped, myIsConverted;
196 int myDim, myAdditionCmdNb;
197 _pyID myGeom, myMesh;
198 TCollection_AsciiString myCreationMethod, myType;
199 TColStd_SequenceOfAsciiString myArgs;
200 TColStd_SequenceOfAsciiString myArgMethods;
201 std::list<Handle(_pyCommand)> myArgCommands;
202 std::list<Handle(_pyCommand)> myUnknownCommands;
204 _pyHypothesis(const Handle(_pyCommand)& theCreationCmd);
205 virtual bool IsAlgo() const { return myIsAlgo; }
206 bool IsWrapped() const { return myIsWrapped; }
207 bool & IsConverted() { return myIsConverted; }
208 int GetDim() const { return myDim; }
209 const _pyID & GetGeom() const { return myGeom; }
210 void SetMesh( const _pyID& theMeshId) { if ( myMesh.IsEmpty() ) myMesh = theMeshId; }
211 const _pyID & GetMesh() const { return myMesh; }
212 const TCollection_AsciiString GetType() { return myType; }
213 bool IsWrappable(const _pyID& theMesh) { return !myIsWrapped && myMesh == theMesh; }
214 virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
215 const _pyID& theMesh);
216 static Handle(_pyHypothesis) NewHypothesis( const Handle(_pyCommand)& theCreationCmd);
217 // bool HasMesh() const { return !myMesh.IsEmpty(); }
218 // void SetGeom( const _pyID& theGeomID ) { myGeom = theGeomID; }
219 void Process( const Handle(_pyCommand)& theCommand);
222 DEFINE_STANDARD_RTTI (_pyHypothesis)
226 * \brief Class for hypotheses having several parameters modified by one method
228 class _pyComplexParamHypo: public _pyHypothesis
231 _pyComplexParamHypo(const Handle(_pyCommand)& theCreationCmd): _pyHypothesis(theCreationCmd) {}
232 void Process( const Handle(_pyCommand)& theCommand);
234 DEFINE_STANDARD_RTTI (_pyComplexParamHypo)
236 DEFINE_STANDARD_HANDLE (_pyComplexParamHypo, _pyHypothesis);
240 * \brief Class representing NumberOfSegments hypothesis
242 class _pyNumberOfSegmentsHyp: public _pyHypothesis
245 _pyNumberOfSegmentsHyp(const Handle(_pyCommand)& theCrCmd): _pyHypothesis(theCrCmd) {}
246 virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
247 const _pyID& theMesh);
249 DEFINE_STANDARD_RTTI (_pyNumberOfSegmentsHyp)
251 DEFINE_STANDARD_HANDLE (_pyNumberOfSegmentsHyp, _pyHypothesis);
254 * \brief Class representing smesh.Mesh_Algorithm
256 class _pyAlgorithm: public _pyHypothesis
259 _pyAlgorithm(const Handle(_pyCommand)& theCreationCmd);
260 virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
261 const _pyID& theMesh);
263 DEFINE_STANDARD_RTTI (_pyAlgorithm)