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