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 * This file was created in order to respond to requirement of bug PAL10494:
40 * SMESH python dump uses idl interface.
42 * The creation reason is that smesh.py commands defining hypotheses encapsulate
43 * several SMESH engine method calls. As well, the dependencies between smesh.py
44 * classes differ from ones between corresponding SMESH IDL interfaces.
46 * Everything here is for internal usage by SMESH_2smeshpy::ConvertScript()
47 * declared in SMESH_PythonDump.hxx
49 * See comments to _pyHypothesis class to know how to assure convertion of a new
52 // ===========================================================================================
54 class Resource_DataMapOfAsciiStringAsciiString;
56 // ===========================================================================================
57 // =====================
59 // =====================
60 // ===========================================================================================
69 class _pyFilterManager;
71 DEFINE_STANDARD_HANDLE (_pyCommand ,Standard_Transient);
72 DEFINE_STANDARD_HANDLE (_pyObject ,Standard_Transient);
73 DEFINE_STANDARD_HANDLE (_pyGen ,_pyObject);
74 DEFINE_STANDARD_HANDLE (_pyMesh ,_pyObject);
75 DEFINE_STANDARD_HANDLE (_pySubMesh ,_pyObject);
76 DEFINE_STANDARD_HANDLE (_pyMeshEditor,_pyObject);
77 DEFINE_STANDARD_HANDLE (_pyHypothesis,_pyObject);
78 DEFINE_STANDARD_HANDLE (_pyFilterManager,_pyObject);
79 DEFINE_STANDARD_HANDLE (_pyAlgorithm ,_pyHypothesis);
81 typedef TCollection_AsciiString _pyID;
83 // ===========================================================
85 * \brief Class operating on a command string looking like
86 * ResultValue = Object.Method( Arg1, Arg2,...)
88 // ===========================================================
90 class _pyCommand: public Standard_Transient
92 int myOrderNb; //!< position within the script
93 TCollection_AsciiString myString; //!< command text
94 TCollection_AsciiString myRes, myObj, myMeth; //!< found parts of command
95 TColStd_SequenceOfAsciiString myArgs; //!< found arguments
96 TColStd_SequenceOfInteger myBegPos; //!< where myRes, myObj, ... begin
97 std::list< Handle(_pyCommand) > myDependentCmds; //!< commands that sould follow me in the script
99 enum { UNKNOWN=-1, EMPTY=0, RESULT_IND, OBJECT_IND, METHOD_IND, ARG1_IND };
100 int GetBegPos( int thePartIndex );
101 void SetBegPos( int thePartIndex, int thePosition );
102 void SetPart( int thePartIndex, const TCollection_AsciiString& theNewPart,
103 TCollection_AsciiString& theOldPart);
104 void FindAllArgs() { GetArg(1); }
108 _pyCommand( const TCollection_AsciiString& theString, int theNb )
109 : myString( theString ), myOrderNb( theNb ) {};
110 TCollection_AsciiString & GetString() { return myString; }
111 int GetOrderNb() const { return myOrderNb; }
112 void SetOrderNb( int theNb ) { myOrderNb = theNb; }
113 int Length() { return myString.Length(); }
114 void Clear() { myString.Clear(); myBegPos.Clear(); }
115 bool IsEmpty() const { return myString.IsEmpty(); }
116 TCollection_AsciiString GetIndentation();
117 const TCollection_AsciiString & GetResultValue();
118 const int GetNbResultValues();
119 const TCollection_AsciiString & GetResultValue(int res);
120 const TCollection_AsciiString & GetObject();
121 const TCollection_AsciiString & GetMethod();
122 const TCollection_AsciiString & GetArg( int index );
123 int GetNbArgs() { FindAllArgs(); return myArgs.Length(); }
124 //Handle(TColStd_HSequenceOfAsciiString) GetArgs();
125 void SetResultValue( const TCollection_AsciiString& theResult )
126 { GetResultValue(); SetPart( RESULT_IND, theResult, myRes ); }
127 void SetObject(const TCollection_AsciiString& theObject)
128 { GetObject(); SetPart( OBJECT_IND, theObject, myObj ); }
129 void SetMethod(const TCollection_AsciiString& theMethod)
130 { GetMethod(); SetPart( METHOD_IND, theMethod, myMeth ); }
131 void SetArg( int index, const TCollection_AsciiString& theArg);
133 static bool SkipSpaces( const TCollection_AsciiString & theSring, int & thePos );
134 static TCollection_AsciiString GetWord( const TCollection_AsciiString & theSring,
135 int & theStartPos, const bool theForward,
136 const bool dotIsWord = false);
137 void AddDependantCmd( Handle(_pyCommand) cmd, bool prepend = false)
138 { if (prepend) myDependentCmds.push_front( cmd ); else myDependentCmds.push_back( cmd ); }
139 bool SetDependentCmdsAfter() const;
141 bool AddAccessorMethod( _pyID theObjectID, const char* theAcsMethod );
143 DEFINE_STANDARD_RTTI (_pyCommand)
146 // -------------------------------------------------------------------------------------
148 * \brief Root of all objects
150 // -------------------------------------------------------------------------------------
152 class _pyObject: public Standard_Transient
154 Handle(_pyCommand) myCreationCmd;
156 _pyObject(const Handle(_pyCommand)& theCreationCmd): myCreationCmd(theCreationCmd) {}
157 const _pyID& GetID() { return myCreationCmd->GetResultValue(); }
158 static _pyID FatherID(const _pyID & childID);
159 const Handle(_pyCommand)& GetCreationCmd() { return myCreationCmd; }
160 void SetCreationCmd( Handle(_pyCommand) cmd ) { myCreationCmd = cmd; }
161 int GetCommandNb() { return myCreationCmd->GetOrderNb(); }
162 virtual void Process(const Handle(_pyCommand) & theCommand) = 0;
163 virtual void Flush() = 0;
164 virtual const char* AccessorMethod() const;
166 DEFINE_STANDARD_RTTI (_pyObject)
169 // -------------------------------------------------------------------------------------
171 * \brief Class corresponding to SMESH_Gen. It holds info on existing
172 * meshes and hypotheses
174 // -------------------------------------------------------------------------------------
175 class _pyGen: public _pyObject
178 _pyGen(Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod,
179 Resource_DataMapOfAsciiStringAsciiString& theObjectNames);
181 Handle(_pyCommand) AddCommand( const TCollection_AsciiString& theCommand );
182 void Process( const Handle(_pyCommand)& theCommand );
184 Handle(_pyHypothesis) FindHyp( const _pyID& theHypID );
185 Handle(_pyHypothesis) FindAlgo( const _pyID& theGeom, const _pyID& theMesh,
186 const Handle(_pyHypothesis)& theHypothesis);
187 Handle(_pySubMesh) FindSubMesh( const _pyID& theSubMeshID );
188 void ExchangeCommands( Handle(_pyCommand) theCmd1, Handle(_pyCommand) theCmd2 );
189 void SetCommandAfter( Handle(_pyCommand) theCmd, Handle(_pyCommand) theAfterCmd );
190 void SetCommandBefore( Handle(_pyCommand) theCmd, Handle(_pyCommand) theBeforeCmd );
191 Handle(_pyCommand)& GetLastCommand();
192 std::list< Handle(_pyCommand) >& GetCommands() { return myCommands; }
193 void SetAccessorMethod(const _pyID& theID, const char* theMethod );
194 bool AddMeshAccessorMethod( Handle(_pyCommand) theCmd ) const;
195 bool AddAlgoAccessorMethod( Handle(_pyCommand) theCmd ) const;
196 const char* AccessorMethod() const;
197 _pyID GenerateNewID( const _pyID& theID );
200 void setNeighbourCommand( Handle(_pyCommand)& theCmd,
201 Handle(_pyCommand)& theOtherCmd,
202 const bool theIsAfter );
205 std::map< _pyID, Handle(_pyMesh) > myMeshes;
206 std::map< _pyID, Handle(_pySubMesh) > mySubMeshes;
207 std::map< _pyID, Handle(_pyMeshEditor) > myMeshEditors;
208 std::list< Handle(_pyHypothesis) > myHypos;
209 std::list< Handle(_pyCommand) > myCommands;
212 Resource_DataMapOfAsciiStringAsciiString& myID2AccessorMethod;
213 Resource_DataMapOfAsciiStringAsciiString& myObjectNames;
214 Handle(_pyCommand) myLastCommand;
215 Handle(_pyFilterManager) myFilterManager;
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(_pySubMesh) > mySubmeshes;
233 _pyMesh(const Handle(_pyCommand) creationCmd);
234 _pyMesh(const Handle(_pyCommand) theCreationCmd, const TCollection_AsciiString & id);
235 const _pyID& GetGeom() { return GetCreationCmd()->GetArg(1); }
236 void Process( const Handle(_pyCommand)& theCommand);
238 const char* AccessorMethod() const { return _pyMesh_ACCESS_METHOD; }
240 static bool NeedMeshAccess( const Handle(_pyCommand)& theCommand );
241 static void AddMeshAccess( const Handle(_pyCommand)& theCommand )
242 { theCommand->SetObject( theCommand->GetObject() + "." _pyMesh_ACCESS_METHOD ); }
244 //friend class _pyMeshEditor;
245 DEFINE_STANDARD_RTTI (_pyMesh)
247 #undef _pyMesh_ACCESS_METHOD
249 // -------------------------------------------------------------------------------------
251 * \brief MeshEditor convert its commands to ones of mesh
253 // -------------------------------------------------------------------------------------
254 class _pyMeshEditor: public _pyObject
257 TCollection_AsciiString myCreationCmdStr;
259 _pyMeshEditor(const Handle(_pyCommand)& theCreationCmd);
260 void Process( const Handle(_pyCommand)& theCommand);
261 virtual void Flush() {}
263 DEFINE_STANDARD_RTTI (_pyMesh)
266 // -------------------------------------------------------------------------------------
268 * \brief Root class for hypothesis
270 * HOWTO assure convertion of a new type of hypothesis
271 * In _pyHypothesis::NewHypothesis():
272 * 1. add a case for the name of the new hypothesis
273 * 2. use SetConvMethodAndType() to set
274 * . for algo: algorithm name and method of Mesh creating the algo
275 * . for hypo: name of the algorithm and method creating the hypothesis
276 * 3. append to myArgMethods interface methods setting param values in the
277 * order they are used when creation method is called. If arguments of
278 * the creation method can't be easily got from calls of hypothesis methods, you are
279 * to derive a specific class from _pyHypothesis that would redefine Process(),
280 * see _pyComplexParamHypo for example
282 // -------------------------------------------------------------------------------------
283 class _pyHypothesis: public _pyObject
286 bool myIsAlgo, myIsWrapped;
287 _pyID myGeom, myMesh;
288 // a hypothesis can be used and created by different algos by different methods
289 std::map<TCollection_AsciiString, TCollection_AsciiString > myType2CreationMethod;
290 //TCollection_AsciiString myCreationMethod, myType;
291 TColStd_SequenceOfAsciiString myArgs; // creation arguments
292 TColStd_SequenceOfAsciiString myArgMethods; // hypo methods setting myArgs
293 TColStd_SequenceOfInteger myNbArgsByMethod; // nb args set by each method
294 std::list<Handle(_pyCommand)> myArgCommands;
295 std::list<Handle(_pyCommand)> myUnknownCommands;
297 _pyHypothesis(const Handle(_pyCommand)& theCreationCmd);
298 void SetConvMethodAndType(const char* creationMethod, const char* type)
299 { myType2CreationMethod[ (char*)type ] = (char*)creationMethod; }
300 void AddArgMethod(const char* method, const int nbArgs = 1)
301 { myArgMethods.Append( (char*)method ); myNbArgsByMethod.Append( nbArgs ); }
302 const TColStd_SequenceOfAsciiString& GetArgs() const { return myArgs; }
303 const std::list<Handle(_pyCommand)>& GetArgCommands() const { return myArgCommands; }
304 void ClearAllCommands();
305 virtual bool IsAlgo() const { return myIsAlgo; }
306 bool IsValid() const { return !myType2CreationMethod.empty(); }
307 bool IsWrapped() const { return myIsWrapped; }
308 const _pyID & GetGeom() const { return myGeom; }
309 void SetMesh( const _pyID& theMeshId) { if ( myMesh.IsEmpty() ) myMesh = theMeshId; }
310 const _pyID & GetMesh() const { return myMesh; }
311 const TCollection_AsciiString& GetAlgoType() const
312 { return myType2CreationMethod.begin()->first; }
313 const TCollection_AsciiString& GetAlgoCreationMethod() const
314 { return myType2CreationMethod.begin()->second; }
315 bool CanBeCreatedBy(const TCollection_AsciiString& algoType ) const
316 { return myType2CreationMethod.find( algoType ) != myType2CreationMethod.end(); }
317 const TCollection_AsciiString& GetCreationMethod(const TCollection_AsciiString& algoType) const
318 { return myType2CreationMethod.find( algoType )->second; }
319 virtual bool IsWrappable(const _pyID& theMesh) { return !myIsWrapped && myMesh == theMesh; }
320 virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
321 const _pyID& theMesh);
322 static Handle(_pyHypothesis) NewHypothesis( const Handle(_pyCommand)& theCreationCmd);
323 void Process( const Handle(_pyCommand)& theCommand);
325 virtual void Assign( const Handle(_pyHypothesis)& theOther,
326 const _pyID& theMesh );
328 DEFINE_STANDARD_RTTI (_pyHypothesis)
331 // -------------------------------------------------------------------------------------
333 * \brief Class representing smesh.Mesh_Algorithm
335 // -------------------------------------------------------------------------------------
336 class _pyAlgorithm: public _pyHypothesis
339 _pyAlgorithm(const Handle(_pyCommand)& theCreationCmd);
340 virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
341 const _pyID& theMesh);
342 const char* AccessorMethod() const { return "GetAlgorithm()"; }
343 virtual bool IsWrappable(const _pyID& theMesh) { return !myIsWrapped; }
345 DEFINE_STANDARD_RTTI (_pyAlgorithm)
348 // -------------------------------------------------------------------------------------
350 * \brief Class for hypotheses having several parameters modified by one method
352 // -------------------------------------------------------------------------------------
353 class _pyComplexParamHypo: public _pyHypothesis
356 _pyComplexParamHypo(const Handle(_pyCommand)& theCreationCmd): _pyHypothesis(theCreationCmd) {}
357 void Process( const Handle(_pyCommand)& theCommand);
359 DEFINE_STANDARD_RTTI (_pyComplexParamHypo)
361 DEFINE_STANDARD_HANDLE (_pyComplexParamHypo, _pyHypothesis);
363 // -------------------------------------------------------------------------------------
365 * \brief Class for LayerDistribution hypothesis conversion
367 // -------------------------------------------------------------------------------------
368 class _pyLayerDistributionHypo: public _pyHypothesis
370 Handle(_pyHypothesis) my1dHyp;
372 _pyLayerDistributionHypo(const Handle(_pyCommand)& theCreationCmd):
373 _pyHypothesis(theCreationCmd) {}
374 void Process( const Handle(_pyCommand)& theCommand);
376 bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
377 const _pyID& theMesh);
379 DEFINE_STANDARD_RTTI (_pyLayerDistributionHypo)
381 DEFINE_STANDARD_HANDLE (_pyLayerDistributionHypo, _pyHypothesis);
383 // -------------------------------------------------------------------------------------
385 * \brief Class representing NumberOfSegments hypothesis
387 // -------------------------------------------------------------------------------------
388 class _pyNumberOfSegmentsHyp: public _pyHypothesis
391 _pyNumberOfSegmentsHyp(const Handle(_pyCommand)& theCrCmd): _pyHypothesis(theCrCmd) {}
392 virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
393 const _pyID& theMesh);
396 DEFINE_STANDARD_RTTI (_pyNumberOfSegmentsHyp)
398 DEFINE_STANDARD_HANDLE (_pyNumberOfSegmentsHyp, _pyHypothesis);
400 // -------------------------------------------------------------------------------------
402 * \brief Class representing SegmentLengthAroundVertex hypothesis
404 // -------------------------------------------------------------------------------------
405 class _pySegmentLengthAroundVertexHyp: public _pyHypothesis
408 _pySegmentLengthAroundVertexHyp(const Handle(_pyCommand)& theCrCmd): _pyHypothesis(theCrCmd) {}
409 virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
410 const _pyID& theMesh);
411 DEFINE_STANDARD_RTTI (_pySegmentLengthAroundVertexHyp)
413 DEFINE_STANDARD_HANDLE (_pySegmentLengthAroundVertexHyp, _pyHypothesis);
415 // -------------------------------------------------------------------------------------
417 * \brief FilterManager creates only if at least one command invoked
419 // -------------------------------------------------------------------------------------
420 class _pyFilterManager: public _pyObject
423 _pyFilterManager(const Handle(_pyCommand)& theCreationCmd);
424 void Process( const Handle(_pyCommand)& theCommand);
425 virtual void Flush();
427 DEFINE_STANDARD_RTTI (_pyFilterManager)
432 // -------------------------------------------------------------------------------------
434 * \brief SubMesh creation can be moved to the end of engine commands
436 // -------------------------------------------------------------------------------------
437 class _pySubMesh: public _pyObject
440 _pySubMesh(const Handle(_pyCommand)& theCreationCmd);
441 void Process( const Handle(_pyCommand)& theCommand);
442 virtual void Flush();
443 void SetCreator( const Handle(_pyObject)& theCreator ) { myCreator = theCreator; }
445 DEFINE_STANDARD_RTTI (_pyFilterManager)
448 Handle(_pyObject) myCreator;