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