1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/
20 // File : SMESH_smesh.hxx
21 // Created : Fri Nov 18 12:05:18 2005
22 // Author : Edward AGAPOV (eap)
24 #ifndef SMESH_smesh_HeaderFile
25 #define SMESH_smesh_HeaderFile
27 #include <Standard_DefineHandle.hxx>
28 #include <Standard_Type.hxx>
29 #include <Standard_Transient.hxx>
30 #include <TCollection_AsciiString.hxx>
31 #include <TColStd_SequenceOfAsciiString.hxx>
32 #include <TColStd_SequenceOfInteger.hxx>
38 * \brief Tool converting SMESH engine calls into commands defined in smesh.py
40 * This file was created in order to respond to requirement of bug PAL10494:
41 * SMESH python dump uses idl interface.
43 * The creation reason is that smesh.py commands defining hypotheses encapsulate
44 * several SMESH engine method calls. As well, the dependencies between smesh.py
45 * classes differ from ones between SMESH IDL interfaces.
47 * The only API method here is SMESH_2smeshpy::ConvertScript(), the rest ones are
50 * See comments to _pyHypothesis class to know how to assure convertion of a new hypothesis
53 class Resource_DataMapOfAsciiStringAsciiString;
59 * \brief Convert a python script using commands of smesh.py
60 * \param theScript - Input script
61 * \param theEntry2AccessorMethod - The returning method names to access to
62 * objects wrapped with python class
63 * \retval TCollection_AsciiString - Convertion result
65 static TCollection_AsciiString
66 ConvertScript(const TCollection_AsciiString& theScript,
67 Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod);
70 * \brief Return the name of the python file wrapping IDL API
71 * \retval TCollection_AsciiString - The file name
73 static char* SmeshpyName() { return "smesh"; }
74 static char* GenName() { return "smesh.smesh"; }
77 // =====================
79 // =====================
88 DEFINE_STANDARD_HANDLE (_pyCommand ,Standard_Transient);
89 DEFINE_STANDARD_HANDLE (_pyObject ,Standard_Transient);
90 DEFINE_STANDARD_HANDLE (_pyGen ,_pyObject);
91 DEFINE_STANDARD_HANDLE (_pyMesh ,_pyObject);
92 DEFINE_STANDARD_HANDLE (_pyHypothesis,_pyObject);
93 DEFINE_STANDARD_HANDLE (_pyAlgorithm ,_pyHypothesis);
95 typedef TCollection_AsciiString _pyID;
97 // ===========================================================
99 * \brief Class operating on a command string looking like
100 * ResultValue = Object.Method( Arg1, Arg2,...)
102 // ===========================================================
104 class _pyCommand: public Standard_Transient
106 int myOrderNb; //!< position within the script
107 TCollection_AsciiString myString; //!< command text
108 TCollection_AsciiString myRes, myObj, myMeth; //!< found parts of command
109 TColStd_SequenceOfAsciiString myArgs; //!< found arguments
110 TColStd_SequenceOfInteger myBegPos; //!< where myRes, myObj, ... begin
111 std::list< Handle(_pyCommand) > myDependentCmds; //!< commands that sould follow me in the script
113 enum { UNKNOWN=-1, EMPTY=0, RESULT_IND, OBJECT_IND, METHOD_IND, ARG1_IND };
114 int GetBegPos( int thePartIndex );
115 void SetBegPos( int thePartIndex, int thePosition );
116 void SetPart( int thePartIndex, const TCollection_AsciiString& theNewPart,
117 TCollection_AsciiString& theOldPart);
118 void FindAllArgs() { GetArg(1); }
122 _pyCommand( const TCollection_AsciiString& theString, int theNb )
123 : myString( theString ), myOrderNb( theNb ) {};
124 TCollection_AsciiString & GetString() { return myString; }
125 int GetOrderNb() const { return myOrderNb; }
126 void SetOrderNb( int theNb ) { myOrderNb = theNb; }
127 int Length() { return myString.Length(); }
128 void Clear() { myString.Clear(); myBegPos.Clear(); }
129 bool IsEmpty() const { return myString.IsEmpty(); }
130 const TCollection_AsciiString & GetResultValue();
131 const TCollection_AsciiString & GetObject();
132 const TCollection_AsciiString & GetMethod();
133 const TCollection_AsciiString & GetArg( int index );
134 int GetNbArgs() { FindAllArgs(); return myArgs.Length(); }
135 //Handle(TColStd_HSequenceOfAsciiString) GetArgs();
136 void SetResultValue( const TCollection_AsciiString& theResult )
137 { GetResultValue(); SetPart( RESULT_IND, theResult, myRes ); }
138 void SetObject(const TCollection_AsciiString& theObject)
139 { GetObject(); SetPart( OBJECT_IND, theObject, myObj ); }
140 void SetMethod(const TCollection_AsciiString& theMethod)
141 { GetMethod(); SetPart( METHOD_IND, theMethod, myMeth ); }
142 void SetArg( int index, const TCollection_AsciiString& theArg);
144 static bool SkipSpaces( const TCollection_AsciiString & theSring, int & thePos );
145 static TCollection_AsciiString GetWord( const TCollection_AsciiString & theSring,
146 int & theStartPos, const bool theForward,
147 const bool dotIsWord = false);
148 void AddDependantCmd( Handle(_pyCommand) cmd)
149 { return myDependentCmds.push_back( cmd ); }
150 bool SetDependentCmdsAfter() const;
152 bool AddAccessorMethod( _pyID theObjectID, const char* theAcsMethod );
154 DEFINE_STANDARD_RTTI (_pyCommand)
158 * \brief Root of all objects
161 class _pyObject: public Standard_Transient
163 Handle(_pyCommand) myCreationCmd;
165 _pyObject(const Handle(_pyCommand)& theCreationCmd): myCreationCmd(theCreationCmd) {}
166 const _pyID& GetID() { return myCreationCmd->GetResultValue(); }
167 const Handle(_pyCommand)& GetCreationCmd() { return myCreationCmd; }
168 void SetCreationCmd( Handle(_pyCommand) cmd ) { myCreationCmd = cmd; }
169 int GetCommandNb() { return myCreationCmd->GetOrderNb(); }
170 virtual void Process(const Handle(_pyCommand) & theCommand) = 0;
171 virtual void Flush() = 0;
172 virtual const char* AccessorMethod() const;
174 DEFINE_STANDARD_RTTI (_pyObject)
178 * \brief Class corresponding to SMESH_Gen. It holds info on existing
179 * meshes and hypotheses
181 class _pyGen: public _pyObject
184 _pyGen(Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod);
186 void AddCommand( const TCollection_AsciiString& theCommand );
187 void Process( const Handle(_pyCommand)& theCommand );
189 Handle(_pyHypothesis) FindHyp( const _pyID& theHypID );
190 Handle(_pyHypothesis) FindAlgo( const _pyID& theGeom, const _pyID& theMesh,
191 const TCollection_AsciiString& theAlgoType);
192 void ExchangeCommands( Handle(_pyCommand) theCmd1, Handle(_pyCommand) theCmd2 );
193 void SetCommandAfter( Handle(_pyCommand) theCmd, Handle(_pyCommand) theAfterCmd );
194 std::list< Handle(_pyCommand) >& GetCommands() { return myCommands; }
195 void SetAccessorMethod(const _pyID& theID, const char* theMethod );
196 const char* AccessorMethod() const { return SMESH_2smeshpy::GenName(); }
198 std::map< _pyID, Handle(_pyMesh) > myMeshes;
199 std::list< Handle(_pyHypothesis) > myHypos;
200 std::list< Handle(_pyCommand) > myCommands;
203 Resource_DataMapOfAsciiStringAsciiString& myID2AccessorMethod;
205 DEFINE_STANDARD_RTTI (_pyGen)
209 * \brief Contains commands concerning mesh substructures
211 #define _pyMesh_ACCESS_METHOD "GetMesh()"
212 class _pyMesh: public _pyObject
214 std::list< Handle(_pyHypothesis) > myHypos;
215 std::list< Handle(_pyCommand) > myAddHypCmds;
216 std::list< Handle(_pyCommand) > mySubmeshes;
219 _pyMesh(const Handle(_pyCommand) theCreationCmd);
220 const _pyID& GetGeom() { return GetCreationCmd()->GetArg(1); }
221 void Process( const Handle(_pyCommand)& theCommand);
223 const char* AccessorMethod() const { return _pyMesh_ACCESS_METHOD; }
225 static void AddMeshAccess( const Handle(_pyCommand)& theCommand )
226 { theCommand->SetObject( theCommand->GetObject() + "." _pyMesh_ACCESS_METHOD ); }
228 DEFINE_STANDARD_RTTI (_pyMesh)
230 #undef _pyMesh_ACCESS_METHOD
233 * \brief Root class for hypothesis
235 * HOWTO assure convertion of a new hypothesis
236 * In NewHypothesis():
237 * 1. add a case for the name of the new hypothesis and
238 * 2. initialize _pyHypothesis fields:
239 * . myDim - hypothesis dimention;
240 * . myType - type name of the algorithm creating the hypothesis;
241 * . myCreationMethod - method name of the algorithm creating the hypothesis;
242 * . append to myArgMethods interface methods setting param values in the
243 * order they are used when myCreationMethod is called. It is supposed that
244 * each interface method sets only one parameter, if it is not so, you are
245 * to derive a specific class from _pyHypothesis that would redefine Process(),
246 * see _pyComplexParamHypo for example
248 class _pyHypothesis: public _pyObject
251 bool myIsAlgo, /*myIsLocal, */myIsWrapped, myIsConverted;
252 int myDim, myAdditionCmdNb;
253 _pyID myGeom, myMesh;
254 TCollection_AsciiString myCreationMethod, myType;
255 TColStd_SequenceOfAsciiString myArgs;
256 TColStd_SequenceOfAsciiString myArgMethods;
257 std::list<Handle(_pyCommand)> myArgCommands;
258 std::list<Handle(_pyCommand)> myUnknownCommands;
260 _pyHypothesis(const Handle(_pyCommand)& theCreationCmd);
261 virtual bool IsAlgo() const { return myIsAlgo; }
262 bool IsWrapped() const { return myIsWrapped; }
263 bool & IsConverted() { return myIsConverted; }
264 int GetDim() const { return myDim; }
265 const _pyID & GetGeom() const { return myGeom; }
266 void SetMesh( const _pyID& theMeshId) { if ( myMesh.IsEmpty() ) myMesh = theMeshId; }
267 const _pyID & GetMesh() const { return myMesh; }
268 const TCollection_AsciiString GetType() { return myType; }
269 bool IsWrappable(const _pyID& theMesh) { return !myIsWrapped && myMesh == theMesh; }
270 virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
271 const _pyID& theMesh);
272 static Handle(_pyHypothesis) NewHypothesis( const Handle(_pyCommand)& theCreationCmd);
273 // bool HasMesh() const { return !myMesh.IsEmpty(); }
274 // void SetGeom( const _pyID& theGeomID ) { myGeom = theGeomID; }
275 void Process( const Handle(_pyCommand)& theCommand);
278 DEFINE_STANDARD_RTTI (_pyHypothesis)
282 * \brief Class for hypotheses having several parameters modified by one method
284 class _pyComplexParamHypo: public _pyHypothesis
287 _pyComplexParamHypo(const Handle(_pyCommand)& theCreationCmd): _pyHypothesis(theCreationCmd) {}
288 void Process( const Handle(_pyCommand)& theCommand);
290 DEFINE_STANDARD_RTTI (_pyComplexParamHypo)
292 DEFINE_STANDARD_HANDLE (_pyComplexParamHypo, _pyHypothesis);
296 * \brief Class representing NumberOfSegments hypothesis
298 class _pyNumberOfSegmentsHyp: public _pyHypothesis
301 _pyNumberOfSegmentsHyp(const Handle(_pyCommand)& theCrCmd): _pyHypothesis(theCrCmd) {}
302 virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
303 const _pyID& theMesh);
306 DEFINE_STANDARD_RTTI (_pyNumberOfSegmentsHyp)
308 DEFINE_STANDARD_HANDLE (_pyNumberOfSegmentsHyp, _pyHypothesis);
311 * \brief Class representing smesh.Mesh_Algorithm
313 class _pyAlgorithm: public _pyHypothesis
316 _pyAlgorithm(const Handle(_pyCommand)& theCreationCmd);
317 virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
318 const _pyID& theMesh);
319 const char* AccessorMethod() const { return "GetAlgorithm()"; }
321 DEFINE_STANDARD_RTTI (_pyAlgorithm)