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);
122 * \brief Root of all objects
124 typedef TCollection_AsciiString _pyID;
126 class _pyObject: public Standard_Transient
128 Handle(_pyCommand) myCreationCmd;
130 _pyObject(const Handle(_pyCommand)& theCreationCmd): myCreationCmd(theCreationCmd) {}
131 const _pyID& GetID() { return myCreationCmd->GetResultValue(); }
132 const Handle(_pyCommand)& GetCreationCmd() { return myCreationCmd; }
133 int GetCommandNb() { return myCreationCmd->GetOrderNb(); }
134 virtual void Process(const Handle(_pyCommand) & theCommand) = 0;
135 virtual void Flush() = 0;
139 * \brief Class corresponding to SMESH_Gen. It holds info on existing
140 * meshes and hypotheses
142 class _pyGen: public _pyObject
145 _pyGen(Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod);
147 void AddCommand( const TCollection_AsciiString& theCommand );
148 void Process( const Handle(_pyCommand)& theCommand );
150 Handle(_pyHypothesis) FindHyp( const _pyID& theHypID );
151 Handle(_pyHypothesis) FindAlgo( const _pyID& theGeom, const _pyID& theMesh,
152 const TCollection_AsciiString& theAlgoType);
153 void ExchangeCommands( Handle(_pyCommand) theCmd1, Handle(_pyCommand) theCmd2 );
154 void SetCommandAfter( Handle(_pyCommand) theCmd, Handle(_pyCommand) theAfterCmd );
155 std::list< Handle(_pyCommand) >& GetCommands() { return myCommands; }
156 void SetAccessorMethod(const _pyID& theID, const char* theMethod );
158 std::map< _pyID, Handle(_pyMesh) > myMeshes;
159 std::list< Handle(_pyHypothesis) > myHypos;
160 std::list< Handle(_pyCommand) > myCommands;
162 Resource_DataMapOfAsciiStringAsciiString& myID2AccessorMethod;
166 * \brief Contains commands concerning mesh substructures
168 class _pyMesh: public _pyObject
170 std::list< Handle(_pyCommand) > myAddHypCmds;
171 std::list< Handle(_pyCommand) > mySubmeshes;
173 _pyMesh(const Handle(_pyCommand) theCreationCmd);
174 const _pyID& GetGeom() { return GetCreationCmd()->GetArg(1); }
175 void Process( const Handle(_pyCommand)& theCommand);
178 static void AddMeshAccess( const Handle(_pyCommand)& theCommand )
179 { theCommand->SetObject( theCommand->GetObject() + ".GetMesh()" ); }
183 * \brief Root class for smesh.Mesh_Algorithm
185 class _pyHypothesis: public _pyObject
188 bool myIsAlgo, /*myIsLocal, */myIsWrapped, myIsConverted;
189 int myDim, myAdditionCmdNb;
190 _pyID myGeom, myMesh;
191 TCollection_AsciiString myCreationMethod, myType;
192 TColStd_SequenceOfAsciiString myArgs;
193 TColStd_SequenceOfAsciiString myArgMethods;
194 std::list<Handle(_pyCommand)> myArgCommands;
195 std::list<Handle(_pyCommand)> myUnknownCommands;
197 _pyHypothesis(const Handle(_pyCommand)& theCreationCmd);
198 virtual bool IsAlgo() const { return myIsAlgo; }
199 bool IsWrapped() const { return myIsWrapped; }
200 bool & IsConverted() { return myIsConverted; }
201 int GetDim() const { return myDim; }
202 const _pyID & GetGeom() const { return myGeom; }
203 void SetMesh( const _pyID& theMeshId) { if ( myMesh.IsEmpty() ) myMesh = theMeshId; }
204 const _pyID & GetMesh() const { return myMesh; }
205 const TCollection_AsciiString GetType() { return myType; }
206 bool IsWrappable(const _pyID& theMesh) { return !myIsWrapped && myMesh == theMesh; }
207 virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
208 const _pyID& theMesh);
209 static Handle(_pyHypothesis) NewHypothesis( const Handle(_pyCommand)& theCreationCmd);
210 // bool HasMesh() const { return !myMesh.IsEmpty(); }
211 // void SetGeom( const _pyID& theGeomID ) { myGeom = theGeomID; }
212 void Process( const Handle(_pyCommand)& theCommand);
217 * \brief Class for hypotheses having several parameters modified by one method
219 class _pyComplexParamHypo: public _pyHypothesis
222 _pyComplexParamHypo(const Handle(_pyCommand)& theCreationCmd): _pyHypothesis(theCreationCmd) {}
223 void Process( const Handle(_pyCommand)& theCommand);
225 DEFINE_STANDARD_HANDLE (_pyComplexParamHypo, _pyHypothesis);
229 * \brief Class representing NumberOfSegments hypothesis
231 class _pyNumberOfSegmentsHyp: public _pyHypothesis
234 _pyNumberOfSegmentsHyp(const Handle(_pyCommand)& theCrCmd): _pyHypothesis(theCrCmd) {}
235 virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
236 const _pyID& theMesh);
238 DEFINE_STANDARD_HANDLE (_pyNumberOfSegmentsHyp, _pyHypothesis);
241 * \brief Class representing smesh.Mesh_Algorithm
243 class _pyAlgorithm: public _pyHypothesis
246 _pyAlgorithm(const Handle(_pyCommand)& theCreationCmd);
247 virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
248 const _pyID& theMesh);