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