1 // Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : SMESH_smesh.hxx
24 // Created : Fri Nov 18 12:05:18 2005
25 // Author : Edward AGAPOV (eap)
27 #ifndef SMESH_smesh_HeaderFile
28 #define SMESH_smesh_HeaderFile
30 #include <Standard_DefineHandle.hxx>
31 #include <Standard_Type.hxx>
32 #include <Standard_Transient.hxx>
33 #include <TCollection_AsciiString.hxx>
34 #include <TColStd_SequenceOfAsciiString.hxx>
35 #include <TColStd_SequenceOfInteger.hxx>
40 // ===========================================================================================
42 * This file was created in order to respond to requirement of bug PAL10494:
43 * SMESH python dump uses idl interface.
45 * The creation reason is that smesh.py commands defining hypotheses encapsulate
46 * several SMESH engine method calls. As well, the dependencies between smesh.py
47 * classes differ from ones between corresponding SMESH IDL interfaces.
49 * Everything here is for internal usage by SMESH_2smeshpy::ConvertScript()
50 * declared in SMESH_PythonDump.hxx
52 * See comments to _pyHypothesis class to know how to assure convertion of a new
55 // ===========================================================================================
57 class Resource_DataMapOfAsciiStringAsciiString;
59 // ===========================================================================================
60 // =====================
62 // =====================
63 // ===========================================================================================
73 DEFINE_STANDARD_HANDLE (_pyCommand ,Standard_Transient);
74 DEFINE_STANDARD_HANDLE (_pyObject ,Standard_Transient);
75 DEFINE_STANDARD_HANDLE (_pyGen ,_pyObject);
76 DEFINE_STANDARD_HANDLE (_pyMesh ,_pyObject);
77 DEFINE_STANDARD_HANDLE (_pySubMesh ,_pyObject);
78 DEFINE_STANDARD_HANDLE (_pyMeshEditor,_pyObject);
79 DEFINE_STANDARD_HANDLE (_pyHypothesis,_pyObject);
80 DEFINE_STANDARD_HANDLE (_pyAlgorithm ,_pyHypothesis);
82 typedef TCollection_AsciiString _pyID;
84 // ===========================================================
86 * \brief Class operating on a command string looking like
87 * ResultValue = Object.Method( Arg1, Arg2,...)
89 // ===========================================================
91 class _pyCommand: public Standard_Transient
93 int myOrderNb; //!< position within the script
94 TCollection_AsciiString myString; //!< command text
95 TCollection_AsciiString myRes, myObj, myMeth; //!< found parts of command
96 TColStd_SequenceOfAsciiString myArgs; //!< found arguments
97 TColStd_SequenceOfInteger myBegPos; //!< where myRes, myObj, ... begin
98 std::list< Handle(_pyCommand) > myDependentCmds; //!< commands that sould follow me in the script
100 enum { UNKNOWN=-1, EMPTY=0, RESULT_IND, OBJECT_IND, METHOD_IND, ARG1_IND };
101 int GetBegPos( int thePartIndex );
102 void SetBegPos( int thePartIndex, int thePosition );
103 void SetPart( int thePartIndex, const TCollection_AsciiString& theNewPart,
104 TCollection_AsciiString& theOldPart);
105 void FindAllArgs() { GetArg(1); }
109 _pyCommand( const TCollection_AsciiString& theString, int theNb )
110 : myString( theString ), myOrderNb( theNb ) {};
111 TCollection_AsciiString & GetString() { return myString; }
112 int GetOrderNb() const { return myOrderNb; }
113 void SetOrderNb( int theNb ) { myOrderNb = theNb; }
114 int Length() { return myString.Length(); }
115 void Clear() { myString.Clear(); myBegPos.Clear(); myArgs.Clear(); }
116 bool IsEmpty() const { return myString.IsEmpty(); }
117 TCollection_AsciiString GetIndentation();
118 const TCollection_AsciiString & GetResultValue();
119 const int GetNbResultValues();
120 const TCollection_AsciiString & GetResultValue(int res);
121 const TCollection_AsciiString & GetObject();
122 const TCollection_AsciiString & GetMethod();
123 const TCollection_AsciiString & GetArg( int index );
124 int GetNbArgs() { FindAllArgs(); return myArgs.Length(); }
125 //Handle(TColStd_HSequenceOfAsciiString) GetArgs();
126 void SetResultValue( const TCollection_AsciiString& theResult )
127 { GetResultValue(); SetPart( RESULT_IND, theResult, myRes ); }
128 void SetObject(const TCollection_AsciiString& theObject)
129 { GetObject(); SetPart( OBJECT_IND, theObject, myObj ); }
130 void SetMethod(const TCollection_AsciiString& theMethod)
131 { GetMethod(); SetPart( METHOD_IND, theMethod, myMeth ); }
132 void SetArg( int index, const TCollection_AsciiString& theArg);
134 static bool SkipSpaces( const TCollection_AsciiString & theSring, int & thePos );
135 static TCollection_AsciiString GetWord( const TCollection_AsciiString & theSring,
136 int & theStartPos, const bool theForward,
137 const bool dotIsWord = false);
138 void AddDependantCmd( Handle(_pyCommand) cmd, bool prepend = false)
139 { if (prepend) myDependentCmds.push_front( cmd ); else myDependentCmds.push_back( cmd ); }
140 bool SetDependentCmdsAfter() const;
142 bool AddAccessorMethod( _pyID theObjectID, const char* theAcsMethod );
144 DEFINE_STANDARD_RTTI (_pyCommand)
147 // -------------------------------------------------------------------------------------
149 * \brief Root of all objects. It counts calls of Process()
151 // -------------------------------------------------------------------------------------
153 class _pyObject: public Standard_Transient
155 Handle(_pyCommand) myCreationCmd;
158 _pyObject(const Handle(_pyCommand)& theCreationCmd)
159 : myCreationCmd(theCreationCmd), myNbCalls(0) {}
160 const _pyID& GetID() { return myCreationCmd->GetResultValue(); }
161 static _pyID FatherID(const _pyID & childID);
162 const Handle(_pyCommand)& GetCreationCmd() { return myCreationCmd; }
163 int GetNbCalls() const { return myNbCalls; }
164 void SetCreationCmd( Handle(_pyCommand) cmd ) { myCreationCmd = cmd; }
165 int GetCommandNb() { return myCreationCmd->GetOrderNb(); }
166 virtual void Process(const Handle(_pyCommand) & theCommand) { myNbCalls++; }
167 virtual void Flush() = 0;
168 virtual const char* AccessorMethod() const;
170 DEFINE_STANDARD_RTTI (_pyObject)
173 // -------------------------------------------------------------------------------------
175 * \brief Class corresponding to SMESH_Gen. It holds info on existing
176 * meshes and hypotheses
178 // -------------------------------------------------------------------------------------
179 class _pyGen: public _pyObject
182 _pyGen(Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod,
183 Resource_DataMapOfAsciiStringAsciiString& theObjectNames);
184 Handle(_pyCommand) AddCommand( const TCollection_AsciiString& theCommand );
185 void Process( const Handle(_pyCommand)& theCommand );
187 Handle(_pyHypothesis) FindHyp( const _pyID& theHypID );
188 Handle(_pyHypothesis) FindAlgo( const _pyID& theGeom, const _pyID& theMesh,
189 const Handle(_pyHypothesis)& theHypothesis);
190 Handle(_pySubMesh) FindSubMesh( const _pyID& theSubMeshID );
191 void ExchangeCommands( Handle(_pyCommand) theCmd1, Handle(_pyCommand) theCmd2 );
192 void SetCommandAfter( Handle(_pyCommand) theCmd, Handle(_pyCommand) theAfterCmd );
193 void SetCommandBefore( Handle(_pyCommand) theCmd, Handle(_pyCommand) theBeforeCmd );
194 Handle(_pyCommand)& GetLastCommand();
195 std::list< Handle(_pyCommand) >& GetCommands() { return myCommands; }
196 void SetAccessorMethod(const _pyID& theID, const char* theMethod );
197 bool AddMeshAccessorMethod( Handle(_pyCommand) theCmd ) const;
198 bool AddAlgoAccessorMethod( Handle(_pyCommand) theCmd ) const;
199 const char* AccessorMethod() const;
200 _pyID GenerateNewID( const _pyID& theID );
201 void AddObject( Handle(_pyObject)& theObj );
204 void setNeighbourCommand( Handle(_pyCommand)& theCmd,
205 Handle(_pyCommand)& theOtherCmd,
206 const bool theIsAfter );
209 std::map< _pyID, Handle(_pyMesh) > myMeshes;
210 std::map< _pyID, Handle(_pyMeshEditor) > myMeshEditors;
211 std::map< _pyID, Handle(_pyObject) > myObjects;
212 std::list< Handle(_pyHypothesis) > myHypos;
213 std::list< Handle(_pyCommand) > myCommands;
215 Resource_DataMapOfAsciiStringAsciiString& myID2AccessorMethod;
216 Resource_DataMapOfAsciiStringAsciiString& myObjectNames;
217 Handle(_pyCommand) myLastCommand;
220 DEFINE_STANDARD_RTTI (_pyGen)
223 // -------------------------------------------------------------------------------------
225 * \brief Contains commands concerning mesh substructures
227 // -------------------------------------------------------------------------------------
228 #define _pyMesh_ACCESS_METHOD "GetMesh()"
229 class _pyMesh: public _pyObject
231 std::list< Handle(_pyHypothesis) > myHypos;
232 std::list< Handle(_pyCommand) > myAddHypCmds;
233 std::list< Handle(_pySubMesh) > mySubmeshes;
236 _pyMesh(const Handle(_pyCommand) creationCmd);
237 _pyMesh(const Handle(_pyCommand) theCreationCmd, const TCollection_AsciiString & id);
238 const _pyID& GetGeom() { return GetCreationCmd()->GetArg(1); }
239 void Process( const Handle(_pyCommand)& theCommand);
241 const char* AccessorMethod() const { return _pyMesh_ACCESS_METHOD; }
243 static bool NeedMeshAccess( const Handle(_pyCommand)& theCommand );
244 static void AddMeshAccess( const Handle(_pyCommand)& theCommand )
245 { theCommand->SetObject( theCommand->GetObject() + "." _pyMesh_ACCESS_METHOD ); }
247 DEFINE_STANDARD_RTTI (_pyMesh)
249 #undef _pyMesh_ACCESS_METHOD
251 // -------------------------------------------------------------------------------------
253 * \brief MeshEditor convert its commands to ones of mesh
255 // -------------------------------------------------------------------------------------
256 class _pyMeshEditor: public _pyObject
259 TCollection_AsciiString myCreationCmdStr;
261 _pyMeshEditor(const Handle(_pyCommand)& theCreationCmd);
262 void Process( const Handle(_pyCommand)& theCommand);
263 virtual void Flush() {}
265 DEFINE_STANDARD_RTTI (_pyMesh)
268 // -------------------------------------------------------------------------------------
270 * \brief Root class for hypothesis
272 * HOWTO assure convertion of a new type of hypothesis
273 * In _pyHypothesis::NewHypothesis():
274 * 1. add a case for the name of the new hypothesis
275 * 2. use SetConvMethodAndType() to set
276 * . for algo: algorithm name and method of Mesh creating the algo
277 * . for hypo: name of the algorithm and method creating the hypothesis
278 * 3. append to myArgMethods interface methods setting param values in the
279 * order they are used when creation method is called. If arguments of
280 * the creation method can't be easily got from calls of hypothesis methods, you are
281 * to derive a specific class from _pyHypothesis that would redefine Process(),
282 * see _pyComplexParamHypo for example
284 // -------------------------------------------------------------------------------------
285 class _pyHypothesis: public _pyObject
288 bool myIsAlgo, myIsWrapped;
289 _pyID myGeom, myMesh;
290 // a hypothesis can be used and created by different algos by different methods
291 std::map<TCollection_AsciiString, TCollection_AsciiString > myType2CreationMethod;
292 //TCollection_AsciiString myCreationMethod, myType;
293 TColStd_SequenceOfAsciiString myArgs; // creation arguments
294 TColStd_SequenceOfAsciiString myArgMethods; // hypo methods setting myArgs
295 TColStd_SequenceOfInteger myNbArgsByMethod; // nb args set by each method
296 std::list<Handle(_pyCommand)> myArgCommands;
297 std::list<Handle(_pyCommand)> myUnknownCommands;
299 _pyHypothesis(const Handle(_pyCommand)& theCreationCmd);
300 void SetConvMethodAndType(const char* creationMethod, const char* type)
301 { myType2CreationMethod[ (char*)type ] = (char*)creationMethod; }
302 void AddArgMethod(const char* method, const int nbArgs = 1)
303 { myArgMethods.Append( (char*)method ); myNbArgsByMethod.Append( nbArgs ); }
304 const TColStd_SequenceOfAsciiString& GetArgs() const { return myArgs; }
305 const std::list<Handle(_pyCommand)>& GetArgCommands() const { return myArgCommands; }
306 void ClearAllCommands();
307 virtual bool IsAlgo() const { return myIsAlgo; }
308 bool IsValid() const { return !myType2CreationMethod.empty(); }
309 bool IsWrapped() const { return myIsWrapped; }
310 const _pyID & GetGeom() const { return myGeom; }
311 void SetMesh( const _pyID& theMeshId) { if ( myMesh.IsEmpty() ) myMesh = theMeshId; }
312 const _pyID & GetMesh() const { return myMesh; }
313 const TCollection_AsciiString& GetAlgoType() const
314 { return myType2CreationMethod.begin()->first; }
315 const TCollection_AsciiString& GetAlgoCreationMethod() const
316 { return myType2CreationMethod.begin()->second; }
317 bool CanBeCreatedBy(const TCollection_AsciiString& algoType ) const
318 { return myType2CreationMethod.find( algoType ) != myType2CreationMethod.end(); }
319 const TCollection_AsciiString& GetCreationMethod(const TCollection_AsciiString& algoType) const
320 { return myType2CreationMethod.find( algoType )->second; }
321 virtual bool IsWrappable(const _pyID& theMesh) { return !myIsWrapped && myMesh == theMesh; }
322 virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
323 const _pyID& theMesh);
324 static Handle(_pyHypothesis) NewHypothesis( const Handle(_pyCommand)& theCreationCmd);
325 void Process( const Handle(_pyCommand)& theCommand);
327 virtual void Assign( const Handle(_pyHypothesis)& theOther,
328 const _pyID& theMesh );
330 DEFINE_STANDARD_RTTI (_pyHypothesis)
333 // -------------------------------------------------------------------------------------
335 * \brief Class representing smesh.Mesh_Algorithm
337 // -------------------------------------------------------------------------------------
338 class _pyAlgorithm: public _pyHypothesis
341 _pyAlgorithm(const Handle(_pyCommand)& theCreationCmd);
342 virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
343 const _pyID& theMesh);
344 const char* AccessorMethod() const { return "GetAlgorithm()"; }
345 virtual bool IsWrappable(const _pyID& theMesh) { return !myIsWrapped; }
347 DEFINE_STANDARD_RTTI (_pyAlgorithm)
350 // -------------------------------------------------------------------------------------
352 * \brief Class for hypotheses having several parameters modified by one method
354 // -------------------------------------------------------------------------------------
355 class _pyComplexParamHypo: public _pyHypothesis
358 _pyComplexParamHypo(const Handle(_pyCommand)& theCreationCmd): _pyHypothesis(theCreationCmd) {}
359 void Process( const Handle(_pyCommand)& theCommand);
362 DEFINE_STANDARD_RTTI (_pyComplexParamHypo)
364 DEFINE_STANDARD_HANDLE (_pyComplexParamHypo, _pyHypothesis);
366 // -------------------------------------------------------------------------------------
368 * \brief Class for LayerDistribution hypothesis conversion
370 // -------------------------------------------------------------------------------------
371 class _pyLayerDistributionHypo: public _pyHypothesis
373 Handle(_pyHypothesis) my1dHyp;
374 TCollection_AsciiString myAlgoMethod;
376 _pyLayerDistributionHypo(const Handle(_pyCommand)& theCreationCmd, const char* algoMethod):
377 _pyHypothesis(theCreationCmd), myAlgoMethod((char*)algoMethod) {}
378 void Process( const Handle(_pyCommand)& theCommand);
380 bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
381 const _pyID& theMesh);
383 DEFINE_STANDARD_RTTI (_pyLayerDistributionHypo)
385 DEFINE_STANDARD_HANDLE (_pyLayerDistributionHypo, _pyHypothesis);
387 // -------------------------------------------------------------------------------------
389 * \brief Class representing NumberOfSegments hypothesis
391 // -------------------------------------------------------------------------------------
392 class _pyNumberOfSegmentsHyp: public _pyHypothesis
395 _pyNumberOfSegmentsHyp(const Handle(_pyCommand)& theCrCmd): _pyHypothesis(theCrCmd) {}
396 virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
397 const _pyID& theMesh);
400 DEFINE_STANDARD_RTTI (_pyNumberOfSegmentsHyp)
402 DEFINE_STANDARD_HANDLE (_pyNumberOfSegmentsHyp, _pyHypothesis);
404 // -------------------------------------------------------------------------------------
406 * \brief Class representing SegmentLengthAroundVertex hypothesis
408 // -------------------------------------------------------------------------------------
409 class _pySegmentLengthAroundVertexHyp: public _pyHypothesis
412 _pySegmentLengthAroundVertexHyp(const Handle(_pyCommand)& theCrCmd): _pyHypothesis(theCrCmd) {}
413 virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
414 const _pyID& theMesh);
415 DEFINE_STANDARD_RTTI (_pySegmentLengthAroundVertexHyp)
417 DEFINE_STANDARD_HANDLE (_pySegmentLengthAroundVertexHyp, _pyHypothesis);
419 // -------------------------------------------------------------------------------------
421 * \brief SelfEraser erases creation command if no more it's commands invoked
423 // -------------------------------------------------------------------------------------
424 class _pySelfEraser: public _pyObject
427 _pySelfEraser(const Handle(_pyCommand)& theCreationCmd):_pyObject(theCreationCmd) {}
428 virtual void Flush();
430 DEFINE_STANDARD_RTTI (_pySelfEraser)
432 DEFINE_STANDARD_HANDLE (_pySelfEraser, _pyObject);
434 // -------------------------------------------------------------------------------------
436 * \brief SubMesh creation can be moved to the end of engine commands
438 // -------------------------------------------------------------------------------------
439 class _pySubMesh: public _pyObject
442 _pySubMesh(const Handle(_pyCommand)& theCreationCmd):_pyObject(theCreationCmd) {}
443 void Process( const Handle(_pyCommand)& theCommand);
444 virtual void Flush();
445 void SetCreator( const Handle(_pyObject)& theCreator ) { myCreator = theCreator; }
447 DEFINE_STANDARD_RTTI (_pySubMesh)
449 Handle(_pyObject) myCreator;
451 // -------------------------------------------------------------------------------------
453 * \brief To convert creation of a group by filter
455 // -------------------------------------------------------------------------------------
456 class _pyGroup: public _pyObject
459 _pyGroup(const Handle(_pyCommand)& theCreationCmd):_pyObject(theCreationCmd) {}
460 void Process( const Handle(_pyCommand)& theCommand);
461 virtual void Flush() {}
463 DEFINE_STANDARD_RTTI (_pyGroup)
465 DEFINE_STANDARD_HANDLE (_pyGroup, _pyObject);
467 // -------------------------------------------------------------------------------------
471 // -------------------------------------------------------------------------------------
472 class _pyFilter: public _pyObject
476 _pyFilter(const Handle(_pyCommand)& theCreationCmd, const _pyID& newID="");
477 void Process( const Handle(_pyCommand)& theCommand);
478 virtual void Flush();
480 DEFINE_STANDARD_RTTI (_pyFilter)
482 DEFINE_STANDARD_HANDLE (_pyFilter, _pyObject);