Salome HOME
Merge remote branch 'origin/V8_5_asterstudy'
[modules/smesh.git] / src / SMESH_I / SMESH_2smeshpy.hxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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, or (at your option) any later version.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // File      : SMESH_smesh.hxx
24 // Created   : Fri Nov 18 12:05:18 2005
25 // Author    : Edward AGAPOV (eap)
26 //
27 #ifndef SMESH_smesh_HeaderFile
28 #define SMESH_smesh_HeaderFile
29
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>
36 #include <Resource_DataMapOfAsciiStringAsciiString.hxx>
37
38 #include <list>
39 #include <map>
40 #include <vector>
41 #include <set>
42
43 #include <SALOMEconfig.h>
44 #include CORBA_CLIENT_HEADER(SALOMEDS)
45
46 #define USE_STRING_FAMILY
47
48 // ===========================================================================================
49 /*!
50  * This file was created in order to respond to requirement of bug PAL10494:
51  * SMESH python dump uses idl interface.
52  *
53  * The creation reason is that smeshBuilder.py commands defining hypotheses encapsulate
54  * several SMESH engine method calls. As well, the dependencies between smeshBuilder.py
55  * classes differ from ones between corresponding SMESH IDL interfaces.
56  * 
57  * Everything here is for internal usage by SMESH_2smeshpy::ConvertScript()
58  * declared in SMESH_PythonDump.hxx
59  */
60 // ===========================================================================================
61
62 // ===========================================================================================
63 // =====================
64 //    INTERNAL STUFF
65 // =====================
66 // ===========================================================================================
67
68 class _pyCommand;
69 class _pyObject;
70 class _pyGen;
71 class _pyMesh;
72 class _pySubMesh;
73 class _pyHypothesis;
74 class _pyAlgorithm;
75 class _pyHypothesisReader;
76
77 DEFINE_STANDARD_HANDLE (_pyCommand         ,Standard_Transient);
78 DEFINE_STANDARD_HANDLE (_pyObject          ,Standard_Transient);
79 DEFINE_STANDARD_HANDLE (_pyHypothesisReader,Standard_Transient);
80 DEFINE_STANDARD_HANDLE (_pyGen             ,_pyObject);
81 DEFINE_STANDARD_HANDLE (_pyMesh            ,_pyObject);
82 DEFINE_STANDARD_HANDLE (_pySubMesh         ,_pyObject);
83 DEFINE_STANDARD_HANDLE (_pyGroup           ,_pySubMesh);
84 DEFINE_STANDARD_HANDLE (_pyMeshEditor      ,_pyObject);
85 DEFINE_STANDARD_HANDLE (_pyHypothesis      ,_pyObject);
86 DEFINE_STANDARD_HANDLE (_pyAlgorithm       ,_pyHypothesis);
87
88 typedef TCollection_AsciiString _pyID;
89 typedef TCollection_AsciiString _AString;
90
91 // ===========================================================
92 /*!
93  * \brief Class operating on a command string looking like
94  *        ResultValue = Object.Method( Arg1, Arg2,...)
95  */
96 // ===========================================================
97
98 class _pyCommand: public Standard_Transient
99 {
100   int                             myOrderNb;            //!< position within the script
101   _AString                        myString;             //!< command text
102   _AString                        myRes, myObj, myMeth; //!< found parts of command
103   TColStd_SequenceOfAsciiString   myArgs;               //!< found arguments
104   TColStd_SequenceOfAsciiString   myResults;            //!< found results
105   TColStd_SequenceOfInteger       myBegPos;             //!< where myRes, myObj, ... begin
106   std::list< Handle(_pyCommand) > myDependentCmds; //!< commands that should follow me in the script
107
108   enum { UNKNOWN=-1, EMPTY=0, RESULT_IND, OBJECT_IND, METHOD_IND, ARG1_IND };
109   int  GetBegPos( int thePartIndex ) const;
110   void SetBegPos( int thePartIndex, int thePosition );
111   void SetPart( int thePartIndex, const _AString& theNewPart, _AString& theOldPart);
112   void FindAllArgs() { GetArg(1); }
113
114 public:
115   _pyCommand() {};
116   _pyCommand( const _AString& theString, int theNb=-1 )
117     : myOrderNb( theNb ), myString( theString ) {};
118   _AString & GetString() { return myString; }
119   int  GetOrderNb() const { return myOrderNb; }
120   void SetOrderNb( int theNb ) { myOrderNb = theNb; }
121   typedef void* TAddr;
122   TAddr GetAddress() const { return (void*) this; }
123   int  Length() const { return myString.Length(); }
124   void Clear() { myString.Clear(); myBegPos.Clear(); myArgs.Clear(); }
125   bool IsEmpty() const { return myString.IsEmpty(); }
126   _AString GetIndentation();
127   const _AString & GetResultValue();
128   int GetNbResultValues();
129   const _AString & GetResultValue(int res);
130   const _AString & GetObject();
131   const _AString & GetMethod();
132   const _AString & GetArg( int index );
133   int GetNbArgs() { FindAllArgs(); return myArgs.Length(); }
134   int GetArgBeginning() const;
135   bool IsMethodCall();
136   bool MethodStartsFrom(const _AString& beg)
137   { GetMethod(); return ( myMeth.Location( beg, 1, myMeth.Length() ) == 1 ); }
138   void SetResultValue( const _AString& theResult )
139   { GetResultValue(); SetPart( RESULT_IND, theResult, myRes ); }
140   void SetObject(const _AString& theObject)
141   { GetObject(); SetPart( OBJECT_IND, theObject, myObj ); }
142   void SetMethod(const _AString& theMethod)
143   { GetMethod(); SetPart( METHOD_IND, theMethod, myMeth ); }
144   void SetArg( int index, const _AString& theArg);
145   void RemoveArgs();
146   void Comment();
147   static bool SkipSpaces( const _AString & theSring, int & thePos );
148   static _AString GetWord( const _AString & theSring, int & theStartPos,
149                            const bool theForward, const bool dotIsWord = false);
150   static bool IsStudyEntry( const _AString& str );
151   static bool IsID( const _AString& str );
152   static bool IsIDChar( char c )
153   { return ( isalnum( c ) || c == '_' || c == ':' ); }
154   static std::list< _pyID > GetStudyEntries( const _AString& str );
155   void AddDependantCmd( Handle(_pyCommand) cmd, bool prepend = false)
156   { if (prepend) myDependentCmds.push_front( cmd ); else myDependentCmds.push_back( cmd ); }
157   bool SetDependentCmdsAfter() const;
158
159   bool AddAccessorMethod( _pyID theObjectID, const char* theAcsMethod );
160
161   DEFINE_STANDARD_RTTIEXT(_pyCommand,Standard_Transient)
162 };
163
164 // -------------------------------------------------------------------------------------
165 /*!
166  * \brief Root of all objects. It counts calls of Process()
167  */
168 // -------------------------------------------------------------------------------------
169
170 class _pyObject: public Standard_Transient
171 {
172 protected:
173   _pyID                           myID;
174   Handle(_pyCommand)              myCreationCmd;
175   std::list< Handle(_pyCommand) > myProcessedCmds;
176   std::list< Handle(_pyCommand) > myArgCmds; // where this obj is used as an argument
177   bool                            myIsPublished;
178
179   void setID(const _pyID& theID);
180 public:
181   _pyObject(const Handle(_pyCommand)& theCreationCmd, const _pyID& theID=_pyID());
182   const _pyID& GetID() { return myID.IsEmpty() ? myCreationCmd->GetResultValue() : myID; }
183   static _pyID FatherID(const _pyID & childID);
184   const Handle(_pyCommand)& GetCreationCmd() { return myCreationCmd; }
185   int  GetNbCalls() const { return myProcessedCmds.size(); }
186   bool IsInStudy() const { return myIsPublished; }
187   virtual void SetRemovedFromStudy(const bool isRemoved) { myIsPublished = !isRemoved; }
188   void SetCreationCmd( Handle(_pyCommand) cmd ) { myCreationCmd = cmd; }
189   int  GetCommandNb() { return myCreationCmd->GetOrderNb(); }
190   void AddProcessedCmd( const Handle(_pyCommand) & cmd )
191   { if (myProcessedCmds.empty() || myProcessedCmds.back()!=cmd) myProcessedCmds.push_back( cmd );}
192   std::list< Handle(_pyCommand) >& GetProcessedCmds() { return myProcessedCmds; }
193   void AddArgCmd( const Handle(_pyCommand) & cmd ) { myArgCmds.push_back( cmd ); }
194   virtual void Process(const Handle(_pyCommand) & cmd) { AddProcessedCmd(cmd); }
195   virtual void Flush() = 0;
196   virtual const char* AccessorMethod() const;
197   virtual bool CanClear();
198   virtual void ClearCommands();
199   virtual void Free() {}
200
201   DEFINE_STANDARD_RTTIEXT(_pyObject,Standard_Transient)
202 };
203
204 // -------------------------------------------------------------------------------------
205 /*!
206  * \brief Data used to restore cleared Compute() command of an exported mesh
207  * when an imported mesh is created
208  */
209 // -------------------------------------------------------------------------------------
210 struct ExportedMeshData
211 {
212   Handle(_pyMesh)    myMesh;
213   Handle(_pyCommand) myLastComputeCmd;
214   _AString           myLastComputeCmdString;
215   ExportedMeshData() {}
216   ExportedMeshData( const Handle(_pyMesh)& mesh, Handle(_pyCommand) computeCmd):
217     myMesh( mesh ), myLastComputeCmd( computeCmd )
218   {
219     if ( !myLastComputeCmd.IsNull())
220       myLastComputeCmdString = myLastComputeCmd->GetString();
221   }
222 };
223
224 // -------------------------------------------------------------------------------------
225 /*!
226  * \brief A container of strings groupped by prefix. It is used for a faster search of
227  *        objects requiring to KeepAgrCmds() in commands. A speed up is gained because
228  *        only a common prefix (e.g. "aArea") of many object IDs is searched in a command
229  *        and not every object ID
230  */
231 // -------------------------------------------------------------------------------------
232 class _pyStringFamily
233 {
234   _AString                     _prefix;
235   std::list< _pyStringFamily > _subFams;
236   std::list< _AString >        _strings;
237   int isIn( const char* str );
238 public:
239   bool Add( const char* str );
240   bool IsInArgs( Handle( _pyCommand)& cmd, std::list<_AString>& subStr );
241   void Print( int level = 0 );
242 };
243
244 // -------------------------------------------------------------------------------------
245 /*!
246  * \brief Class corresponding to SMESH_Gen. It holds info on existing
247  *        meshes and hypotheses
248  */
249 // -------------------------------------------------------------------------------------
250 class _pyGen: public _pyObject
251 {
252 public:
253   _pyGen(Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod,
254          Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
255          std::set< TCollection_AsciiString >&      theRemovedObjIDs,
256          const bool                                theToKeepAllCommands);
257   Handle(_pyCommand) AddCommand( const _AString& theCommand );
258   void ExchangeCommands( Handle(_pyCommand) theCmd1, Handle(_pyCommand) theCmd2 );
259   void SetCommandAfter ( Handle(_pyCommand) theCmd,  Handle(_pyCommand) theAfterCmd );
260   void SetCommandBefore( Handle(_pyCommand) theCmd,  Handle(_pyCommand) theBeforeCmd );
261   Handle(_pyCommand)& GetLastCommand();
262   std::list< Handle(_pyCommand) >& GetCommands() { return myCommands; }
263   void PlaceSubmeshAfterItsCreation( Handle(_pyCommand) theCmdUsingSubmesh ) const;
264
265   _pyID GenerateNewID( const _pyID& theID );
266   bool AddObject( Handle(_pyObject)& theObj );
267   void CheckObjectIsReCreated( Handle(_pyObject)& theObj );
268   void SetProxyObject( const _pyID& theID, Handle(_pyObject)& theObj );
269   Handle(_pyObject)     FindObject( const _pyID& theObjID ) const;
270   Handle(_pySubMesh)    FindSubMesh( const _pyID& theSubMeshID );
271   Handle(_pyHypothesis) FindHyp( const _pyID& theHypID );
272   Handle(_pyHypothesis) FindAlgo( const _pyID& theGeom, const _pyID& theMesh,
273                                   const Handle(_pyHypothesis)& theHypothesis);
274
275   void SetAccessorMethod(const _pyID& theID, const char* theMethod );
276   bool AddMeshAccessorMethod( Handle(_pyCommand) theCmd ) const;
277   bool AddAlgoAccessorMethod( Handle(_pyCommand) theCmd ) const;
278   virtual const char* AccessorMethod() const;
279
280   bool IsGeomObject(const _pyID& theObjID) const;
281   bool IsNotPublished(const _pyID& theObjID) const;
282   void ObjectCreationRemoved(const _pyID& theObjID);
283 #ifdef USE_STRING_FAMILY
284   void KeepAgrCmds(const _pyID& theObjID) { myKeepAgrCmdsIDs.Add( theObjID.ToCString() ); }
285 #else
286   void KeepAgrCmds(const _pyID& theObjID) { myKeepAgrCmdsIDs.push_back( theObjID ); }
287 #endif
288   bool IsToKeepAllCommands() const { return myToKeepAllCommands; }
289   void AddExportedMesh(const _AString& file, const ExportedMeshData& mesh )
290   { myFile2ExportedMesh[ file ] = mesh; }
291   ExportedMeshData& FindExportedMesh( const _AString& file )
292   { return myFile2ExportedMesh[ file ]; }
293
294   virtual void Process( const Handle(_pyCommand)& theCommand );
295   virtual void Flush();
296   virtual void ClearCommands();
297   virtual void Free();
298
299   Handle( _pyHypothesisReader ) GetHypothesisReader() const;
300
301 private:
302   void setNeighbourCommand( Handle(_pyCommand)& theCmd,
303                             Handle(_pyCommand)& theOtherCmd,
304                             const bool theIsAfter );
305   //void addFilterUser( Handle(_pyCommand)& theCmd, const Handle(_pyObject)& user );
306
307 private:
308   std::map< _pyID, Handle(_pyMesh) >        myMeshes;
309   std::map< _pyID, Handle(_pyMeshEditor) >  myMeshEditors;
310   std::map< _pyID, Handle(_pyHypothesis) >  myHypos;
311   std::map< _pyID, Handle(_pyObject) >      myObjects;
312   std::list< Handle(_pyObject) >            myOrderedObjects; // to know order of myObjects creation
313 #ifdef USE_STRING_FAMILY
314   _pyStringFamily                           myKeepAgrCmdsIDs;
315 #else
316   std::list< _pyID >                        myKeepAgrCmdsIDs;
317 #endif
318   std::list< Handle(_pyCommand) >           myCommands;
319   int                                       myNbCommands;
320   Resource_DataMapOfAsciiStringAsciiString& myID2AccessorMethod;
321   Resource_DataMapOfAsciiStringAsciiString& myObjectNames;
322   std::set< TCollection_AsciiString >&      myRemovedObjIDs;
323   Handle(_pyCommand)                        myLastCommand;
324   int                                       myNbFilters;
325   bool                                      myToKeepAllCommands;
326   int                                       myGeomIDNb, myGeomIDIndex;
327   std::map< _AString, ExportedMeshData >    myFile2ExportedMesh;
328   Handle( _pyHypothesisReader )             myHypReader;
329
330   DEFINE_STANDARD_RTTIEXT(_pyGen,_pyObject)
331 };
332
333 // -------------------------------------------------------------------------------------
334 /*!
335  * \brief Contains commands concerning mesh substructures
336  */
337 // -------------------------------------------------------------------------------------
338 #define _pyMesh_ACCESS_METHOD "GetMesh()"
339 class _pyMesh: public _pyObject
340 {
341   std::list< Handle(_pyHypothesis) > myHypos;
342   std::list< Handle(_pyCommand) >    myAddHypCmds, myNotConvertedAddHypCmds;
343   std::list< Handle(_pySubMesh) >    mySubmeshes;
344   std::list< Handle(_pyGroup) >      myGroups;
345   std::list< Handle(_pyMeshEditor)>  myEditors;
346   //d::list< Handle(_pyMesh) >       myFatherMeshes; // this mesh depends on
347   std::list< Handle(_pyMesh) >       myChildMeshes; // depending on me
348   bool                               myGeomNotInStudy;
349   Handle(_pyCommand)                 myLastComputeCmd;
350 public:
351   _pyMesh(const Handle(_pyCommand) creationCmd);
352   _pyMesh(const Handle(_pyCommand) theCreationCmd, const _pyID & id);
353   const _pyID& GetGeom() { return GetCreationCmd()->GetArg(1); }
354   void AddGroup( const Handle(_pyGroup)& g ) { myGroups.push_back( g ); }
355   void AddEditor( const Handle(_pyMeshEditor)& e ) { myEditors.push_back( e ); }
356   bool IsNotGeomPublished() { return myGeomNotInStudy; }
357   virtual void Process( const Handle(_pyCommand)& theCommand);
358   virtual void Flush();
359   virtual void SetRemovedFromStudy(const bool isRemoved);
360   virtual bool CanClear();
361   virtual void ClearCommands();
362   virtual void Free() { /*myFatherMeshes.clear();*/ myChildMeshes.clear(); }
363   virtual const char* AccessorMethod() const { return _pyMesh_ACCESS_METHOD; }
364 private:
365   void addFatherMesh( const Handle(_pyMesh)& mesh );
366   void addFatherMesh( const _pyID& meshID );
367   static bool NeedMeshAccess( const Handle(_pyCommand)& theCommand );
368   static void AddMeshAccess( const Handle(_pyCommand)& theCommand )
369   { theCommand->SetObject( theCommand->GetObject() + "." _pyMesh_ACCESS_METHOD ); }
370
371   DEFINE_STANDARD_RTTIEXT(_pyMesh,_pyObject)
372 };
373 #undef _pyMesh_ACCESS_METHOD 
374
375 // -------------------------------------------------------------------------------------
376 /*!
377  * \brief MeshEditor convert its commands to ones of mesh
378  */
379 // -------------------------------------------------------------------------------------
380 class _pyMeshEditor: public _pyObject
381 {
382   _pyID    myMesh;
383   _AString myCreationCmdStr;
384 public:
385   _pyMeshEditor(const Handle(_pyCommand)& theCreationCmd);
386   _pyID GetMesh() const { return myMesh; }
387   virtual void Process( const Handle(_pyCommand)& theCommand);
388   virtual void Flush() {}
389   virtual bool CanClear();
390
391   DEFINE_STANDARD_RTTIEXT(_pyMeshEditor,_pyObject)
392 };
393
394 // -------------------------------------------------------------------------------------
395 /*!
396  * \brief Root class for hypothesis
397  */
398 // -------------------------------------------------------------------------------------
399 class _pyHypothesis: public _pyObject
400 {
401   friend class _pyHypothesisReader;
402 protected:
403   bool    myIsAlgo, myIsWrapped;
404   _pyID   myGeom,   myMesh;
405   struct CreationMethod {
406     _AString              myMethod; // method of algo or mesh creating a hyp
407     // myArgNb(i)-th arg of myArgMethods(i) of hyp becomes an i-th arg of myMethod
408     std::vector<_AString> myArgMethods;
409     std::vector<int>      myArgNb; // arg nb countered from 1
410     std::vector<_AString> myArgs; // creation arguments
411   };
412   void setCreationArg( const int argNb, const _AString& arg );
413   // a hypothesis can be created by different algos by different methods
414   typedef std::map<_AString, CreationMethod > TType2CrMethod;
415   TType2CrMethod                myAlgoType2CreationMethod;
416   std::set< _AString >          myAccumulativeMethods;
417   CreationMethod*               myCurCrMethod; // used for adding to myAlgoType2CreationMethod
418   std::list<Handle(_pyCommand)> myArgCommands;
419   std::list<Handle(_pyCommand)> myUnusedCommands;
420   std::list<Handle(_pyObject) > myReferredObjs;
421   // maps used to clear commands setting parameters if result of setting is
422   // discared (e.g. by mesh.Clear())
423   std::map<_AString, std::list<Handle(_pyCommand)> >            myMeth2Commands;
424   std::map< _pyCommand::TAddr, std::list<Handle(_pyCommand) > > myComputeAddr2Cmds;
425   std::list<Handle(_pyCommand) >                                myComputeCmds;
426   void rememberCmdOfParameter( const Handle(_pyCommand) & cmd );
427   bool isCmdUsedForCompute( const Handle(_pyCommand) & cmd,
428                             _pyCommand::TAddr avoidComputeAddr=NULL ) const;
429 public:
430   _pyHypothesis(const Handle(_pyCommand)& theCreationCmd);
431   void SetConvMethodAndType(const _AString& creationMethod, const _AString& type)
432   { myCurCrMethod = &myAlgoType2CreationMethod[ type ];
433     myCurCrMethod->myMethod = creationMethod; }
434   void AddArgMethod(const _AString& method, const int argNb = 1)
435   { myCurCrMethod->myArgMethods.push_back( method );
436     myCurCrMethod->myArgNb.push_back( argNb ); }
437   void AddAccumulativeMethod( const _AString& method)
438   { myAccumulativeMethods.insert( method ); }
439   //const TColStd_SequenceOfAsciiString& GetArgs() const { return myArgs; }
440   const std::list<Handle(_pyCommand)>& GetArgCommands() const { return myArgCommands; }
441   void ClearAllCommands();
442   virtual bool IsAlgo() const { return myIsAlgo; }
443   bool IsValid() const { return !myAlgoType2CreationMethod.empty(); }
444   bool IsWrapped() const { return myIsWrapped; }
445   const _pyID & GetGeom() const { return myGeom; }
446   void SetMesh( const _pyID& theMeshId) { if ( myMesh.IsEmpty() ) myMesh = theMeshId; }
447   const _pyID & GetMesh() const { return myMesh; }
448   const _AString& GetAlgoType() const
449   { return myAlgoType2CreationMethod.begin()->first; }
450   const _AString& GetAlgoCreationMethod() const
451   { return myAlgoType2CreationMethod.begin()->second.myMethod; }
452   bool CanBeCreatedBy(const _AString& algoType ) const
453   { return myAlgoType2CreationMethod.find( algoType ) != myAlgoType2CreationMethod.end(); }
454   const _AString& GetCreationMethod(const _AString& algoType)
455   { return ( myCurCrMethod = & myAlgoType2CreationMethod[ algoType ])->myMethod; }
456   static Handle(_pyHypothesis) NewHypothesis( const Handle(_pyCommand)& theCreationCmd);
457
458   virtual bool IsWrappable(const _pyID& theMesh) const;
459   virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
460                                   const _pyID&              theMesh);
461   virtual void Process( const Handle(_pyCommand)& theCommand);
462   virtual void Flush();
463   virtual void Free() { myReferredObjs.clear(); }
464   virtual void Assign( const Handle(_pyHypothesis)& theOther,
465                        const _pyID&                 theMesh );
466   virtual bool CanClear();
467   virtual void ClearCommands();
468   virtual bool GetReferredMeshesAndGeom( std::list< Handle(_pyMesh) >& meshes );
469
470   void MeshComputed    ( const Handle(_pyCommand)& theComputeCommand );
471   void ComputeDiscarded( const Handle(_pyCommand)& theComputeCommand );
472   //void ComputeSaved    ( const Handle(_pyCommand)& theComputeCommand );
473
474
475   DEFINE_STANDARD_RTTIEXT(_pyHypothesis,_pyObject)
476 };
477
478 // -------------------------------------------------------------------------------------
479 /*!
480  * \brief Class representing smesh.Mesh_Algorithm
481  */
482 // -------------------------------------------------------------------------------------
483 class _pyAlgorithm: public _pyHypothesis
484 {
485 public:
486   _pyAlgorithm(const Handle(_pyCommand)& theCreationCmd);
487   virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
488                                   const _pyID&              theMesh);
489   virtual const char* AccessorMethod() const { return "GetAlgorithm()"; }
490   virtual bool IsWrappable(const _pyID& theMesh) { return !myIsWrapped; }
491
492   DEFINE_STANDARD_RTTIEXT(_pyAlgorithm,_pyHypothesis)
493 };
494
495 // -------------------------------------------------------------------------------------
496 /*!
497  * \brief Class for hypotheses having several parameters modified by one method
498  */
499 // -------------------------------------------------------------------------------------
500 class _pyComplexParamHypo: public _pyHypothesis
501 {
502 public:
503   _pyComplexParamHypo(const Handle(_pyCommand)& theCreationCmd): _pyHypothesis(theCreationCmd) {}
504   virtual void Process( const Handle(_pyCommand)& theCommand);
505   virtual void Flush();
506
507   DEFINE_STANDARD_RTTIEXT(_pyComplexParamHypo,_pyHypothesis)
508 };
509 DEFINE_STANDARD_HANDLE (_pyComplexParamHypo, _pyHypothesis);
510
511 // -------------------------------------------------------------------------------------
512 /*!
513  * \brief Class for LayerDistribution hypothesis conversion
514  */
515 // -------------------------------------------------------------------------------------
516 class _pyLayerDistributionHypo: public _pyHypothesis
517 {
518   Handle(_pyHypothesis) my1dHyp;
519   _AString              myAlgoMethod;
520 public:
521   _pyLayerDistributionHypo(const Handle(_pyCommand)& theCreationCmd, const char* algoMethod):
522     _pyHypothesis(theCreationCmd), myAlgoMethod((char*)algoMethod) {}
523   virtual void Process( const Handle(_pyCommand)& theCommand);
524   virtual void Flush();
525   virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
526                                   const _pyID&              theMesh);
527   virtual void Free() { my1dHyp.Nullify(); }
528
529   DEFINE_STANDARD_RTTIEXT(_pyLayerDistributionHypo,_pyHypothesis)
530 };
531 DEFINE_STANDARD_HANDLE (_pyLayerDistributionHypo, _pyHypothesis);
532
533 // -------------------------------------------------------------------------------------
534 /*!
535  * \brief Class representing NumberOfSegments hypothesis
536  */
537 // -------------------------------------------------------------------------------------
538 class _pyNumberOfSegmentsHyp: public _pyHypothesis
539 {
540 public:
541   _pyNumberOfSegmentsHyp(const Handle(_pyCommand)& theCrCmd): _pyHypothesis(theCrCmd) {}
542   virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
543                                   const _pyID&              theMesh);
544   void Flush();
545
546   DEFINE_STANDARD_RTTIEXT(_pyNumberOfSegmentsHyp,_pyHypothesis)
547 };
548 DEFINE_STANDARD_HANDLE (_pyNumberOfSegmentsHyp, _pyHypothesis);
549
550 // -------------------------------------------------------------------------------------
551 /*!
552  * \brief Class representing SegmentLengthAroundVertex hypothesis
553  */
554 // -------------------------------------------------------------------------------------
555 class _pySegmentLengthAroundVertexHyp: public _pyHypothesis
556 {
557 public:
558   _pySegmentLengthAroundVertexHyp(const Handle(_pyCommand)& theCrCmd): _pyHypothesis(theCrCmd) {}
559   virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
560                                   const _pyID&              theMesh);
561   DEFINE_STANDARD_RTTIEXT(_pySegmentLengthAroundVertexHyp,_pyHypothesis)
562 };
563 DEFINE_STANDARD_HANDLE (_pySegmentLengthAroundVertexHyp, _pyHypothesis);
564
565 // -------------------------------------------------------------------------------------
566 /*!
567  * \brief SelfEraser erases creation command if no more it's commands invoked
568  */
569 // -------------------------------------------------------------------------------------
570 class _pySelfEraser: public _pyObject
571 {
572   bool myIgnoreOwnCalls; // not to erase only if this obj is used as argument
573 public:
574   _pySelfEraser(const Handle(_pyCommand)& theCreationCmd);
575   void IgnoreOwnCalls() { myIgnoreOwnCalls = true; }
576   virtual void Flush();
577   virtual bool CanClear();
578   static bool IsAliveCmd( const Handle(_pyCommand)& theCmd );
579
580   DEFINE_STANDARD_RTTIEXT(_pySelfEraser,_pyObject)
581 };
582 DEFINE_STANDARD_HANDLE (_pySelfEraser, _pyObject);
583
584 // -------------------------------------------------------------------------------------
585 /*!
586  * \brief SubMesh creation can be moved to the end of engine commands
587  */
588 // -------------------------------------------------------------------------------------
589 class _pySubMesh:  public _pyObject
590 {
591   Handle(_pyObject) myCreator;
592   Handle(_pyMesh) myMesh;
593 public:
594   _pySubMesh(const Handle(_pyCommand)& theCreationCmd, bool toKeepAgrCmds=true);
595   virtual void Process( const Handle(_pyCommand)& theCommand);
596   virtual void Flush();
597   virtual Handle(_pyMesh) GetMesh() { return myMesh; }
598   virtual void Free() { myCreator.Nullify(); myMesh.Nullify(); }
599   void SetCreator( const Handle(_pyObject)& theCreator ) { myCreator = theCreator; }
600   static bool CanBeArgOfMethod(const _AString& theMethodName);
601
602   DEFINE_STANDARD_RTTIEXT(_pySubMesh,_pyObject)
603 };
604 // -------------------------------------------------------------------------------------
605 /*!
606  * \brief A filter sets a human readable name to self
607  */
608 // -------------------------------------------------------------------------------------
609 class _pyFilter:  public _pyObject
610 {
611   _pyID myNewID, myMesh;
612   //std::list< Handle(_pyObject) > myUsers;
613 public:
614   _pyFilter(const Handle(_pyCommand)& theCreationCmd, const _pyID& newID="");
615   //void AddUser( const Handle(_pyObject)& user) { myUsers.push_back( user ); }
616   virtual void Process( const Handle(_pyCommand)& theCommand);
617   virtual void Flush();
618   //virtual bool CanClear();
619   //virtual void Free() { myUsers.clear(); }
620   const _pyID& GetNewID() const { return myNewID; }
621
622   DEFINE_STANDARD_RTTIEXT(_pyFilter,_pyObject)
623 };
624 DEFINE_STANDARD_HANDLE (_pyFilter, _pyObject);
625
626 // -------------------------------------------------------------------------------------
627 /*!
628  * \brief To convert creation of a group by filter
629  */
630 // -------------------------------------------------------------------------------------
631 class _pyGroup:  public _pySubMesh // use myMesh of _pySubMesh
632 {
633   Handle(_pyFilter) myFilter;
634   bool              myCanClearCreationCmd;
635 public:
636   _pyGroup(const Handle(_pyCommand)& theCreationCmd, const _pyID & id=_pyID());
637   virtual void Process( const Handle(_pyCommand)& theCommand);
638   virtual void Flush();
639   virtual void Free() { myFilter.Nullify(); }
640   virtual bool CanClear();
641   void RemovedWithContents();
642
643   DEFINE_STANDARD_RTTIEXT(_pyGroup,_pySubMesh)
644 };
645
646 // -------------------------------------------------------------------------------------
647 /*!
648  * \brief Class reading _pyHypothesis'es from resource files of mesher Plugins
649  */
650 // -------------------------------------------------------------------------------------
651 class _pyHypothesisReader: public Standard_Transient
652 {
653   std::map<_AString, Handle(_pyHypothesis)> myType2Hyp;
654 public:
655   _pyHypothesisReader();
656   Handle(_pyHypothesis) GetHypothesis(const _AString&           hypType,
657                                       const Handle(_pyCommand)& creationCmd) const;
658   DEFINE_STANDARD_RTTIEXT(_pyHypothesisReader,Standard_Transient)
659 };
660
661 #endif