1 // Copyright (C) 2007-2008 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
22 // File : SMESH_smesh.hxx
23 // Created : Fri Nov 18 12:05:18 2005
24 // Author : Edward AGAPOV (eap)
26 #ifndef SMESH_smesh_HeaderFile
27 #define SMESH_smesh_HeaderFile
29 #include <Standard_DefineHandle.hxx>
30 #include <Standard_Type.hxx>
31 #include <Standard_Transient.hxx>
32 #include <TCollection_AsciiString.hxx>
33 #include <TColStd_SequenceOfAsciiString.hxx>
34 #include <TColStd_SequenceOfInteger.hxx>
39 // ===========================================================================================
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 corresponding SMESH IDL interfaces.
48 * Everything here is for internal usage by SMESH_2smeshpy::ConvertScript()
49 * declared in SMESH_PythonDump.hxx
51 * See comments to _pyHypothesis class to know how to assure convertion of a new
54 // ===========================================================================================
56 class Resource_DataMapOfAsciiStringAsciiString;
58 // ===========================================================================================
59 // =====================
61 // =====================
62 // ===========================================================================================
71 class _pyFilterManager;
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 (_pyFilterManager,_pyObject);
81 DEFINE_STANDARD_HANDLE (_pyAlgorithm ,_pyHypothesis);
83 typedef TCollection_AsciiString _pyID;
85 // ===========================================================
87 * \brief Class operating on a command string looking like
88 * ResultValue = Object.Method( Arg1, Arg2,...)
90 // ===========================================================
92 class _pyCommand: public Standard_Transient
94 int myOrderNb; //!< position within the script
95 TCollection_AsciiString myString; //!< command text
96 TCollection_AsciiString myRes, myObj, myMeth; //!< found parts of command
97 TColStd_SequenceOfAsciiString myArgs; //!< found arguments
98 TColStd_SequenceOfInteger myBegPos; //!< where myRes, myObj, ... begin
99 std::list< Handle(_pyCommand) > myDependentCmds; //!< commands that sould follow me in the script
101 enum { UNKNOWN=-1, EMPTY=0, RESULT_IND, OBJECT_IND, METHOD_IND, ARG1_IND };
102 int GetBegPos( int thePartIndex );
103 void SetBegPos( int thePartIndex, int thePosition );
104 void SetPart( int thePartIndex, const TCollection_AsciiString& theNewPart,
105 TCollection_AsciiString& theOldPart);
106 void FindAllArgs() { GetArg(1); }
110 _pyCommand( const TCollection_AsciiString& theString, int theNb )
111 : myString( theString ), myOrderNb( theNb ) {};
112 TCollection_AsciiString & GetString() { return myString; }
113 int GetOrderNb() const { return myOrderNb; }
114 void SetOrderNb( int theNb ) { myOrderNb = theNb; }
115 int Length() { return myString.Length(); }
116 void Clear() { myString.Clear(); myBegPos.Clear(); myArgs.Clear(); }
117 bool IsEmpty() const { return myString.IsEmpty(); }
118 TCollection_AsciiString GetIndentation();
119 const TCollection_AsciiString & GetResultValue();
120 const int GetNbResultValues();
121 const TCollection_AsciiString & GetResultValue(int res);
122 const TCollection_AsciiString & GetObject();
123 const TCollection_AsciiString & GetMethod();
124 const TCollection_AsciiString & GetArg( int index );
125 int GetNbArgs() { FindAllArgs(); return myArgs.Length(); }
126 //Handle(TColStd_HSequenceOfAsciiString) GetArgs();
127 void SetResultValue( const TCollection_AsciiString& theResult )
128 { GetResultValue(); SetPart( RESULT_IND, theResult, myRes ); }
129 void SetObject(const TCollection_AsciiString& theObject)
130 { GetObject(); SetPart( OBJECT_IND, theObject, myObj ); }
131 void SetMethod(const TCollection_AsciiString& theMethod)
132 { GetMethod(); SetPart( METHOD_IND, theMethod, myMeth ); }
133 void SetArg( int index, const TCollection_AsciiString& theArg);
135 static bool SkipSpaces( const TCollection_AsciiString & theSring, int & thePos );
136 static TCollection_AsciiString GetWord( const TCollection_AsciiString & theSring,
137 int & theStartPos, const bool theForward,
138 const bool dotIsWord = false);
139 void AddDependantCmd( Handle(_pyCommand) cmd, bool prepend = false)
140 { if (prepend) myDependentCmds.push_front( cmd ); else myDependentCmds.push_back( cmd ); }
141 bool SetDependentCmdsAfter() const;
143 bool AddAccessorMethod( _pyID theObjectID, const char* theAcsMethod );
145 DEFINE_STANDARD_RTTI (_pyCommand)
148 // -------------------------------------------------------------------------------------
150 * \brief Root of all objects. It counts calls of Process()
152 // -------------------------------------------------------------------------------------
154 class _pyObject: public Standard_Transient
156 Handle(_pyCommand) myCreationCmd;
159 _pyObject(const Handle(_pyCommand)& theCreationCmd)
160 : myCreationCmd(theCreationCmd), myNbCalls(0) {}
161 const _pyID& GetID() { return myCreationCmd->GetResultValue(); }
162 static _pyID FatherID(const _pyID & childID);
163 const Handle(_pyCommand)& GetCreationCmd() { return myCreationCmd; }
164 int GetNbCalls() const { return myNbCalls; }
165 void SetCreationCmd( Handle(_pyCommand) cmd ) { myCreationCmd = cmd; }
166 int GetCommandNb() { return myCreationCmd->GetOrderNb(); }
167 virtual void Process(const Handle(_pyCommand) & theCommand) { myNbCalls++; }
168 virtual void Flush() = 0;
169 virtual const char* AccessorMethod() const;
171 DEFINE_STANDARD_RTTI (_pyObject)
174 // -------------------------------------------------------------------------------------
176 * \brief Class corresponding to SMESH_Gen. It holds info on existing
177 * meshes and hypotheses
179 // -------------------------------------------------------------------------------------
180 class _pyGen: public _pyObject
183 _pyGen(Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod,
184 Resource_DataMapOfAsciiStringAsciiString& theObjectNames);
186 Handle(_pyCommand) 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 Handle(_pyHypothesis)& theHypothesis);
192 Handle(_pySubMesh) FindSubMesh( const _pyID& theSubMeshID );
193 void ExchangeCommands( Handle(_pyCommand) theCmd1, Handle(_pyCommand) theCmd2 );
194 void SetCommandAfter( Handle(_pyCommand) theCmd, Handle(_pyCommand) theAfterCmd );
195 void SetCommandBefore( Handle(_pyCommand) theCmd, Handle(_pyCommand) theBeforeCmd );
196 Handle(_pyCommand)& GetLastCommand();
197 std::list< Handle(_pyCommand) >& GetCommands() { return myCommands; }
198 void SetAccessorMethod(const _pyID& theID, const char* theMethod );
199 bool AddMeshAccessorMethod( Handle(_pyCommand) theCmd ) const;
200 bool AddAlgoAccessorMethod( Handle(_pyCommand) theCmd ) const;
201 const char* AccessorMethod() const;
202 _pyID GenerateNewID( const _pyID& theID );
205 void setNeighbourCommand( Handle(_pyCommand)& theCmd,
206 Handle(_pyCommand)& theOtherCmd,
207 const bool theIsAfter );
210 std::map< _pyID, Handle(_pyMesh) > myMeshes;
211 //std::map< _pyID, Handle(_pySubMesh) > mySubMeshes;
212 std::map< _pyID, Handle(_pyMeshEditor) > myMeshEditors;
213 std::map< _pyID, Handle(_pyObject) > myObjects;
214 std::list< Handle(_pyHypothesis) > myHypos;
215 std::list< Handle(_pyCommand) > myCommands;
217 Resource_DataMapOfAsciiStringAsciiString& myID2AccessorMethod;
218 Resource_DataMapOfAsciiStringAsciiString& myObjectNames;
219 Handle(_pyCommand) myLastCommand;
221 DEFINE_STANDARD_RTTI (_pyGen)
224 // -------------------------------------------------------------------------------------
226 * \brief Contains commands concerning mesh substructures
228 // -------------------------------------------------------------------------------------
229 #define _pyMesh_ACCESS_METHOD "GetMesh()"
230 class _pyMesh: public _pyObject
232 std::list< Handle(_pyHypothesis) > myHypos;
233 std::list< Handle(_pyCommand) > myAddHypCmds;
234 std::list< Handle(_pySubMesh) > mySubmeshes;
237 _pyMesh(const Handle(_pyCommand) creationCmd);
238 _pyMesh(const Handle(_pyCommand) theCreationCmd, const TCollection_AsciiString & id);
239 const _pyID& GetGeom() { return GetCreationCmd()->GetArg(1); }
240 void Process( const Handle(_pyCommand)& theCommand);
242 const char* AccessorMethod() const { return _pyMesh_ACCESS_METHOD; }
244 static bool NeedMeshAccess( const Handle(_pyCommand)& theCommand );
245 static void AddMeshAccess( const Handle(_pyCommand)& theCommand )
246 { theCommand->SetObject( theCommand->GetObject() + "." _pyMesh_ACCESS_METHOD ); }
248 //friend class _pyMeshEditor;
249 DEFINE_STANDARD_RTTI (_pyMesh)
251 #undef _pyMesh_ACCESS_METHOD
253 // -------------------------------------------------------------------------------------
255 * \brief MeshEditor convert its commands to ones of mesh
257 // -------------------------------------------------------------------------------------
258 class _pyMeshEditor: public _pyObject
261 TCollection_AsciiString myCreationCmdStr;
263 _pyMeshEditor(const Handle(_pyCommand)& theCreationCmd);
264 void Process( const Handle(_pyCommand)& theCommand);
265 virtual void Flush() {}
267 DEFINE_STANDARD_RTTI (_pyMesh)
270 // -------------------------------------------------------------------------------------
272 * \brief Root class for hypothesis
274 * HOWTO assure convertion of a new type of hypothesis
275 * In _pyHypothesis::NewHypothesis():
276 * 1. add a case for the name of the new hypothesis
277 * 2. use SetConvMethodAndType() to set
278 * . for algo: algorithm name and method of Mesh creating the algo
279 * . for hypo: name of the algorithm and method creating the hypothesis
280 * 3. append to myArgMethods interface methods setting param values in the
281 * order they are used when creation method is called. If arguments of
282 * the creation method can't be easily got from calls of hypothesis methods, you are
283 * to derive a specific class from _pyHypothesis that would redefine Process(),
284 * see _pyComplexParamHypo for example
286 // -------------------------------------------------------------------------------------
287 class _pyHypothesis: public _pyObject
290 bool myIsAlgo, myIsWrapped;
291 _pyID myGeom, myMesh;
292 // a hypothesis can be used and created by different algos by different methods
293 std::map<TCollection_AsciiString, TCollection_AsciiString > myType2CreationMethod;
294 //TCollection_AsciiString myCreationMethod, myType;
295 TColStd_SequenceOfAsciiString myArgs; // creation arguments
296 TColStd_SequenceOfAsciiString myArgMethods; // hypo methods setting myArgs
297 TColStd_SequenceOfInteger myNbArgsByMethod; // nb args set by each method
298 std::list<Handle(_pyCommand)> myArgCommands;
299 std::list<Handle(_pyCommand)> myUnknownCommands;
301 _pyHypothesis(const Handle(_pyCommand)& theCreationCmd);
302 void SetConvMethodAndType(const char* creationMethod, const char* type)
303 { myType2CreationMethod[ (char*)type ] = (char*)creationMethod; }
304 void AddArgMethod(const char* method, const int nbArgs = 1)
305 { myArgMethods.Append( (char*)method ); myNbArgsByMethod.Append( nbArgs ); }
306 const TColStd_SequenceOfAsciiString& GetArgs() const { return myArgs; }
307 const std::list<Handle(_pyCommand)>& GetArgCommands() const { return myArgCommands; }
308 void ClearAllCommands();
309 virtual bool IsAlgo() const { return myIsAlgo; }
310 bool IsValid() const { return !myType2CreationMethod.empty(); }
311 bool IsWrapped() const { return myIsWrapped; }
312 const _pyID & GetGeom() const { return myGeom; }
313 void SetMesh( const _pyID& theMeshId) { if ( myMesh.IsEmpty() ) myMesh = theMeshId; }
314 const _pyID & GetMesh() const { return myMesh; }
315 const TCollection_AsciiString& GetAlgoType() const
316 { return myType2CreationMethod.begin()->first; }
317 const TCollection_AsciiString& GetAlgoCreationMethod() const
318 { return myType2CreationMethod.begin()->second; }
319 bool CanBeCreatedBy(const TCollection_AsciiString& algoType ) const
320 { return myType2CreationMethod.find( algoType ) != myType2CreationMethod.end(); }
321 const TCollection_AsciiString& GetCreationMethod(const TCollection_AsciiString& algoType) const
322 { return myType2CreationMethod.find( algoType )->second; }
323 virtual bool IsWrappable(const _pyID& theMesh) { return !myIsWrapped && myMesh == theMesh; }
324 virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
325 const _pyID& theMesh);
326 static Handle(_pyHypothesis) NewHypothesis( const Handle(_pyCommand)& theCreationCmd);
327 void Process( const Handle(_pyCommand)& theCommand);
329 virtual void Assign( const Handle(_pyHypothesis)& theOther,
330 const _pyID& theMesh );
332 DEFINE_STANDARD_RTTI (_pyHypothesis)
335 // -------------------------------------------------------------------------------------
337 * \brief Class representing smesh.Mesh_Algorithm
339 // -------------------------------------------------------------------------------------
340 class _pyAlgorithm: public _pyHypothesis
343 _pyAlgorithm(const Handle(_pyCommand)& theCreationCmd);
344 virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
345 const _pyID& theMesh);
346 const char* AccessorMethod() const { return "GetAlgorithm()"; }
347 virtual bool IsWrappable(const _pyID& theMesh) { return !myIsWrapped; }
349 DEFINE_STANDARD_RTTI (_pyAlgorithm)
352 // -------------------------------------------------------------------------------------
354 * \brief Class for hypotheses having several parameters modified by one method
356 // -------------------------------------------------------------------------------------
357 class _pyComplexParamHypo: public _pyHypothesis
360 _pyComplexParamHypo(const Handle(_pyCommand)& theCreationCmd): _pyHypothesis(theCreationCmd) {}
361 void Process( const Handle(_pyCommand)& theCommand);
364 DEFINE_STANDARD_RTTI (_pyComplexParamHypo)
366 DEFINE_STANDARD_HANDLE (_pyComplexParamHypo, _pyHypothesis);
368 // -------------------------------------------------------------------------------------
370 * \brief Class for LayerDistribution hypothesis conversion
372 // -------------------------------------------------------------------------------------
373 class _pyLayerDistributionHypo: public _pyHypothesis
375 Handle(_pyHypothesis) my1dHyp;
376 TCollection_AsciiString myAlgoMethod;
378 _pyLayerDistributionHypo(const Handle(_pyCommand)& theCreationCmd, const char* algoMethod):
379 _pyHypothesis(theCreationCmd), myAlgoMethod((char*)algoMethod) {}
380 void Process( const Handle(_pyCommand)& theCommand);
382 bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
383 const _pyID& theMesh);
385 DEFINE_STANDARD_RTTI (_pyLayerDistributionHypo)
387 DEFINE_STANDARD_HANDLE (_pyLayerDistributionHypo, _pyHypothesis);
389 // -------------------------------------------------------------------------------------
391 * \brief Class representing NumberOfSegments hypothesis
393 // -------------------------------------------------------------------------------------
394 class _pyNumberOfSegmentsHyp: public _pyHypothesis
397 _pyNumberOfSegmentsHyp(const Handle(_pyCommand)& theCrCmd): _pyHypothesis(theCrCmd) {}
398 virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
399 const _pyID& theMesh);
402 DEFINE_STANDARD_RTTI (_pyNumberOfSegmentsHyp)
404 DEFINE_STANDARD_HANDLE (_pyNumberOfSegmentsHyp, _pyHypothesis);
406 // -------------------------------------------------------------------------------------
408 * \brief Class representing SegmentLengthAroundVertex hypothesis
410 // -------------------------------------------------------------------------------------
411 class _pySegmentLengthAroundVertexHyp: public _pyHypothesis
414 _pySegmentLengthAroundVertexHyp(const Handle(_pyCommand)& theCrCmd): _pyHypothesis(theCrCmd) {}
415 virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
416 const _pyID& theMesh);
417 DEFINE_STANDARD_RTTI (_pySegmentLengthAroundVertexHyp)
419 DEFINE_STANDARD_HANDLE (_pySegmentLengthAroundVertexHyp, _pyHypothesis);
421 // -------------------------------------------------------------------------------------
423 * \brief SelfEraser erases creation command if no more it's commands invoked
425 // -------------------------------------------------------------------------------------
426 class _pySelfEraser: public _pyObject
429 _pySelfEraser(const Handle(_pyCommand)& theCreationCmd):_pyObject(theCreationCmd) {}
430 virtual void Flush();
432 DEFINE_STANDARD_RTTI (_pySelfEraser)
434 DEFINE_STANDARD_HANDLE (_pySelfEraser, _pyObject);
436 // -------------------------------------------------------------------------------------
438 * \brief SubMesh creation can be moved to the end of engine commands
440 // -------------------------------------------------------------------------------------
441 class _pySubMesh: public _pyObject
444 _pySubMesh(const Handle(_pyCommand)& theCreationCmd):_pyObject(theCreationCmd) {}
445 void Process( const Handle(_pyCommand)& theCommand);
446 virtual void Flush();
447 void SetCreator( const Handle(_pyObject)& theCreator ) { myCreator = theCreator; }
449 DEFINE_STANDARD_RTTI (_pySubMesh)
451 Handle(_pyObject) myCreator;