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/ or email : webmaster.salome@opencascade.com
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>
37 // ===========================================================================================
39 * \brief Tool converting SMESH engine calls into commands defined in smesh.py
41 * This file was created in order to respond to requirement of bug PAL10494:
42 * SMESH python dump uses idl interface.
44 * The creation reason is that smesh.py commands defining hypotheses encapsulate
45 * several SMESH engine method calls. As well, the dependencies between smesh.py
46 * classes differ from ones between SMESH IDL interfaces.
48 * The only API method here is SMESH_2smeshpy::ConvertScript(), the rest ones are
51 * See comments to _pyHypothesis class to know how to assure convertion of a new hypothesis
53 // ===========================================================================================
55 class Resource_DataMapOfAsciiStringAsciiString;
61 * \brief Convert a python script using commands of smesh.py
62 * \param theScript - Input script
63 * \param theEntry2AccessorMethod - The returning method names to access to
64 * objects wrapped with python class
65 * \retval TCollection_AsciiString - Convertion result
67 static TCollection_AsciiString
68 ConvertScript(const TCollection_AsciiString& theScript,
69 Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod);
72 * \brief Return the name of the python file wrapping IDL API
73 * \retval TCollection_AsciiString - The file name
75 static char* SmeshpyName() { return "smesh"; }
76 static char* GenName() { return "smesh.smesh"; }
79 // ===========================================================================================
80 // =====================
82 // =====================
83 // ===========================================================================================
92 DEFINE_STANDARD_HANDLE (_pyCommand ,Standard_Transient);
93 DEFINE_STANDARD_HANDLE (_pyObject ,Standard_Transient);
94 DEFINE_STANDARD_HANDLE (_pyGen ,_pyObject);
95 DEFINE_STANDARD_HANDLE (_pyMesh ,_pyObject);
96 DEFINE_STANDARD_HANDLE (_pyHypothesis,_pyObject);
97 DEFINE_STANDARD_HANDLE (_pyAlgorithm ,_pyHypothesis);
99 typedef TCollection_AsciiString _pyID;
101 // ===========================================================
103 * \brief Class operating on a command string looking like
104 * ResultValue = Object.Method( Arg1, Arg2,...)
106 // ===========================================================
108 class _pyCommand: public Standard_Transient
110 int myOrderNb; //!< position within the script
111 TCollection_AsciiString myString; //!< command text
112 TCollection_AsciiString myRes, myObj, myMeth; //!< found parts of command
113 TColStd_SequenceOfAsciiString myArgs; //!< found arguments
114 TColStd_SequenceOfInteger myBegPos; //!< where myRes, myObj, ... begin
115 std::list< Handle(_pyCommand) > myDependentCmds; //!< commands that sould follow me in the script
117 enum { UNKNOWN=-1, EMPTY=0, RESULT_IND, OBJECT_IND, METHOD_IND, ARG1_IND };
118 int GetBegPos( int thePartIndex );
119 void SetBegPos( int thePartIndex, int thePosition );
120 void SetPart( int thePartIndex, const TCollection_AsciiString& theNewPart,
121 TCollection_AsciiString& theOldPart);
122 void FindAllArgs() { GetArg(1); }
126 _pyCommand( const TCollection_AsciiString& theString, int theNb )
127 : myString( theString ), myOrderNb( theNb ) {};
128 TCollection_AsciiString & GetString() { return myString; }
129 int GetOrderNb() const { return myOrderNb; }
130 void SetOrderNb( int theNb ) { myOrderNb = theNb; }
131 int Length() { return myString.Length(); }
132 void Clear() { myString.Clear(); myBegPos.Clear(); }
133 bool IsEmpty() const { return myString.IsEmpty(); }
134 TCollection_AsciiString GetIndentation();
135 const TCollection_AsciiString & GetResultValue();
136 const TCollection_AsciiString & GetObject();
137 const TCollection_AsciiString & GetMethod();
138 const TCollection_AsciiString & GetArg( int index );
139 int GetNbArgs() { FindAllArgs(); return myArgs.Length(); }
140 //Handle(TColStd_HSequenceOfAsciiString) GetArgs();
141 void SetResultValue( const TCollection_AsciiString& theResult )
142 { GetResultValue(); SetPart( RESULT_IND, theResult, myRes ); }
143 void SetObject(const TCollection_AsciiString& theObject)
144 { GetObject(); SetPart( OBJECT_IND, theObject, myObj ); }
145 void SetMethod(const TCollection_AsciiString& theMethod)
146 { GetMethod(); SetPart( METHOD_IND, theMethod, myMeth ); }
147 void SetArg( int index, const TCollection_AsciiString& theArg);
149 static bool SkipSpaces( const TCollection_AsciiString & theSring, int & thePos );
150 static TCollection_AsciiString GetWord( const TCollection_AsciiString & theSring,
151 int & theStartPos, const bool theForward,
152 const bool dotIsWord = false);
153 void AddDependantCmd( Handle(_pyCommand) cmd, bool prepend = false)
154 { if (prepend) myDependentCmds.push_front( cmd ); else myDependentCmds.push_back( cmd ); }
155 bool SetDependentCmdsAfter() const;
157 bool AddAccessorMethod( _pyID theObjectID, const char* theAcsMethod );
159 DEFINE_STANDARD_RTTI (_pyCommand)
162 // -------------------------------------------------------------------------------------
164 * \brief Root of all objects
166 // -------------------------------------------------------------------------------------
168 class _pyObject: public Standard_Transient
170 Handle(_pyCommand) myCreationCmd;
172 _pyObject(const Handle(_pyCommand)& theCreationCmd): myCreationCmd(theCreationCmd) {}
173 const _pyID& GetID() { return myCreationCmd->GetResultValue(); }
174 static _pyID FatherID(const _pyID & childID);
175 const Handle(_pyCommand)& GetCreationCmd() { return myCreationCmd; }
176 void SetCreationCmd( Handle(_pyCommand) cmd ) { myCreationCmd = cmd; }
177 int GetCommandNb() { return myCreationCmd->GetOrderNb(); }
178 virtual void Process(const Handle(_pyCommand) & theCommand) = 0;
179 virtual void Flush() = 0;
180 virtual const char* AccessorMethod() const;
182 DEFINE_STANDARD_RTTI (_pyObject)
185 // -------------------------------------------------------------------------------------
187 * \brief Class corresponding to SMESH_Gen. It holds info on existing
188 * meshes and hypotheses
190 // -------------------------------------------------------------------------------------
191 class _pyGen: public _pyObject
194 _pyGen(Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod);
196 Handle(_pyCommand) AddCommand( const TCollection_AsciiString& theCommand );
197 void Process( const Handle(_pyCommand)& theCommand );
199 Handle(_pyHypothesis) FindHyp( const _pyID& theHypID );
200 Handle(_pyHypothesis) FindAlgo( const _pyID& theGeom, const _pyID& theMesh,
201 const TCollection_AsciiString& theAlgoType);
202 void ExchangeCommands( Handle(_pyCommand) theCmd1, Handle(_pyCommand) theCmd2 );
203 void SetCommandAfter( Handle(_pyCommand) theCmd, Handle(_pyCommand) theAfterCmd );
204 std::list< Handle(_pyCommand) >& GetCommands() { return myCommands; }
205 void SetAccessorMethod(const _pyID& theID, const char* theMethod );
206 bool AddMeshAccessorMethod( Handle(_pyCommand) theCmd ) const;
207 bool AddAlgoAccessorMethod( Handle(_pyCommand) theCmd ) const;
208 const char* AccessorMethod() const { return SMESH_2smeshpy::GenName(); }
210 std::map< _pyID, Handle(_pyMesh) > myMeshes;
211 std::list< Handle(_pyHypothesis) > myHypos;
212 std::list< Handle(_pyCommand) > myCommands;
215 Resource_DataMapOfAsciiStringAsciiString& myID2AccessorMethod;
217 DEFINE_STANDARD_RTTI (_pyGen)
220 // -------------------------------------------------------------------------------------
222 * \brief Contains commands concerning mesh substructures
224 // -------------------------------------------------------------------------------------
225 #define _pyMesh_ACCESS_METHOD "GetMesh()"
226 class _pyMesh: public _pyObject
228 std::list< Handle(_pyHypothesis) > myHypos;
229 std::list< Handle(_pyCommand) > myAddHypCmds;
230 std::list< Handle(_pyCommand) > mySubmeshes;
233 _pyMesh(const Handle(_pyCommand) theCreationCmd);
234 const _pyID& GetGeom() { return GetCreationCmd()->GetArg(1); }
235 void Process( const Handle(_pyCommand)& theCommand);
237 const char* AccessorMethod() const { return _pyMesh_ACCESS_METHOD; }
239 static void AddMeshAccess( const Handle(_pyCommand)& theCommand )
240 { theCommand->SetObject( theCommand->GetObject() + "." _pyMesh_ACCESS_METHOD ); }
242 DEFINE_STANDARD_RTTI (_pyMesh)
244 #undef _pyMesh_ACCESS_METHOD
246 // -------------------------------------------------------------------------------------
248 * \brief Root class for hypothesis
250 * HOWTO assure convertion of a new hypothesis
251 * In NewHypothesis():
252 * 1. add a case for the name of the new hypothesis and
253 * 2. initialize _pyHypothesis fields:
254 * . myDim - hypothesis dimention;
255 * . myType - type name of the algorithm creating the hypothesis;
256 * . myCreationMethod - method name of the algorithm creating the hypothesis;
257 * . append to myArgMethods interface methods setting param values in the
258 * order they are used when myCreationMethod is called. It is supposed that
259 * each interface method sets only one parameter, if it is not so, you are
260 * to derive a specific class from _pyHypothesis that would redefine Process(),
261 * see _pyComplexParamHypo for example
263 // -------------------------------------------------------------------------------------
264 class _pyHypothesis: public _pyObject
267 bool myIsAlgo, myIsWrapped; //myIsLocal, myIsConverted;
268 //int myDim/*, myAdditionCmdNb*/;
269 _pyID myGeom, myMesh;
270 TCollection_AsciiString myCreationMethod, myType;
271 TColStd_SequenceOfAsciiString myArgs;
272 TColStd_SequenceOfAsciiString myArgMethods;
273 TColStd_SequenceOfInteger myNbArgsByMethod;
274 std::list<Handle(_pyCommand)> myArgCommands;
275 std::list<Handle(_pyCommand)> myUnknownCommands;
277 _pyHypothesis(const Handle(_pyCommand)& theCreationCmd);
278 void SetConvMethodAndType(const char* creationMethod, const char* type=0)
279 { myCreationMethod = (char*)creationMethod; if ( type ) myType = (char*)type; }
280 // void SetDimMethodType(const int dim, const char* creationMethod, const char* type=0)
281 // { myDim = dim; myCreationMethod = (char*)creationMethod; if ( type ) myType = (char*)type; }
282 void AddArgMethod(const char* method, const int nbArgs = 1)
283 { myArgMethods.Append( (char*)method ); myNbArgsByMethod.Append( nbArgs ); }
284 const TColStd_SequenceOfAsciiString& GetArgs() const { return myArgs; }
285 const TCollection_AsciiString& GetCreationMethod() const { return myCreationMethod; }
286 const std::list<Handle(_pyCommand)>& GetArgCommands() const { return myArgCommands; }
287 void ClearAllCommands();
288 virtual bool IsAlgo() const { return myIsAlgo; }
289 bool IsWrapped() const { return myIsWrapped; }
290 //bool & IsConverted() { return myIsConverted; }
291 //int GetDim() const { return myDim; }
292 const _pyID & GetGeom() const { return myGeom; }
293 void SetMesh( const _pyID& theMeshId) { if ( myMesh.IsEmpty() ) myMesh = theMeshId; }
294 const _pyID & GetMesh() const { return myMesh; }
295 const TCollection_AsciiString GetType() { return myType; }
296 bool IsWrappable(const _pyID& theMesh) { return !myIsWrapped && myMesh == theMesh; }
297 virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
298 const _pyID& theMesh);
299 static Handle(_pyHypothesis) NewHypothesis( const Handle(_pyCommand)& theCreationCmd);
300 // bool HasMesh() const { return !myMesh.IsEmpty(); }
301 // void SetGeom( const _pyID& theGeomID ) { myGeom = theGeomID; }
302 void Process( const Handle(_pyCommand)& theCommand);
305 DEFINE_STANDARD_RTTI (_pyHypothesis)
308 // -------------------------------------------------------------------------------------
310 * \brief Class representing smesh.Mesh_Algorithm
312 // -------------------------------------------------------------------------------------
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)
324 // -------------------------------------------------------------------------------------
326 * \brief Class for hypotheses having several parameters modified by one method
328 // -------------------------------------------------------------------------------------
329 class _pyComplexParamHypo: public _pyHypothesis
332 _pyComplexParamHypo(const Handle(_pyCommand)& theCreationCmd): _pyHypothesis(theCreationCmd) {}
333 void Process( const Handle(_pyCommand)& theCommand);
335 DEFINE_STANDARD_RTTI (_pyComplexParamHypo)
337 DEFINE_STANDARD_HANDLE (_pyComplexParamHypo, _pyHypothesis);
339 // -------------------------------------------------------------------------------------
341 * \brief Class for LayerDistribution hypothesis conversion
343 // -------------------------------------------------------------------------------------
344 class _pyLayerDistributionHypo: public _pyHypothesis
346 Handle(_pyHypothesis) my1dHyp;
348 _pyLayerDistributionHypo(const Handle(_pyCommand)& theCreationCmd):
349 _pyHypothesis(theCreationCmd) {}
350 void Process( const Handle(_pyCommand)& theCommand);
352 bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
353 const _pyID& theMesh);
355 DEFINE_STANDARD_RTTI (_pyLayerDistributionHypo)
357 DEFINE_STANDARD_HANDLE (_pyLayerDistributionHypo, _pyHypothesis);
359 // -------------------------------------------------------------------------------------
361 * \brief Class representing NumberOfSegments hypothesis
363 // -------------------------------------------------------------------------------------
364 class _pyNumberOfSegmentsHyp: public _pyHypothesis
367 _pyNumberOfSegmentsHyp(const Handle(_pyCommand)& theCrCmd): _pyHypothesis(theCrCmd) {}
368 virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
369 const _pyID& theMesh);
372 DEFINE_STANDARD_RTTI (_pyNumberOfSegmentsHyp)
374 DEFINE_STANDARD_HANDLE (_pyNumberOfSegmentsHyp, _pyHypothesis);
376 // -------------------------------------------------------------------------------------
378 * \brief Class representing SegmentLengthAroundVertex hypothesis
380 // -------------------------------------------------------------------------------------
381 class _pySegmentLengthAroundVertexHyp: public _pyHypothesis
384 _pySegmentLengthAroundVertexHyp(const Handle(_pyCommand)& theCrCmd): _pyHypothesis(theCrCmd) {}
385 virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
386 const _pyID& theMesh);
387 DEFINE_STANDARD_RTTI (_pySegmentLengthAroundVertexHyp)
389 DEFINE_STANDARD_HANDLE (_pySegmentLengthAroundVertexHyp, _pyHypothesis);