Salome HOME
52566]: TC7.5.0: Empty group of Balls at Diameter Equal to filter
[modules/smesh.git] / src / SMESH_I / SMESH_2smeshpy.hxx
1 // Copyright (C) 2007-2014  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
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_SequenceOfAsciiString   myResults;            //!< found results
106   TColStd_SequenceOfInteger       myBegPos;             //!< where myRes, myObj, ... begin
107   std::list< Handle(_pyCommand) > myDependentCmds; //!< commands that sould follow me in the script
108
109   enum { UNKNOWN=-1, EMPTY=0, RESULT_IND, OBJECT_IND, METHOD_IND, ARG1_IND };
110   int  GetBegPos( int thePartIndex ) const;
111   void SetBegPos( int thePartIndex, int thePosition );
112   void SetPart( int thePartIndex, const _AString& theNewPart, _AString& theOldPart);
113   void FindAllArgs() { GetArg(1); }
114
115 public:
116   _pyCommand() {};
117   _pyCommand( const _AString& theString, int theNb=-1 )
118     : myString( theString ), myOrderNb( theNb ) {};
119   _AString & GetString() { return myString; }
120   int GetOrderNb() const { return myOrderNb; }
121   void SetOrderNb( int theNb ) { myOrderNb = theNb; }
122   typedef void* TAddr;
123   TAddr GetAddress() const { return (void*) this; }
124   int Length() const { return myString.Length(); }
125   void Clear() { myString.Clear(); myBegPos.Clear(); myArgs.Clear(); }
126   bool IsEmpty() const { return myString.IsEmpty(); }
127   _AString GetIndentation();
128   const _AString & GetResultValue();
129   int GetNbResultValues();
130   const _AString& GetResultValue(int res);
131   const _AString & GetObject();
132   const _AString & GetMethod();
133   const _AString & GetArg( int index );
134   int GetNbArgs() { FindAllArgs(); return myArgs.Length(); }
135   int GetArgBeginning() const;
136   bool IsMethodCall();
137   bool MethodStartsFrom(const _AString& beg)
138   { GetMethod(); return ( myMeth.Location( beg, 1, myMeth.Length() ) == 1 ); }
139   void SetResultValue( const _AString& theResult )
140   { GetResultValue(); SetPart( RESULT_IND, theResult, myRes ); }
141   void SetObject(const _AString& theObject)
142   { GetObject(); SetPart( OBJECT_IND, theObject, myObj ); }
143   void SetMethod(const _AString& theMethod)
144   { GetMethod(); SetPart( METHOD_IND, theMethod, myMeth ); }
145   void SetArg( int index, const _AString& theArg);
146   void RemoveArgs();
147   void Comment();
148   static bool SkipSpaces( const _AString & theSring, int & thePos );
149   static _AString GetWord( const _AString & theSring, int & theStartPos,
150                            const bool theForward, const bool dotIsWord = false);
151   static bool IsStudyEntry( const _AString& str );
152   static bool IsID( const _AString& str );
153   static bool IsIDChar( char c )
154   { return ( isalnum( c ) || c == '_' || c == ':' ); }
155   static std::list< _pyID > GetStudyEntries( const _AString& str );
156   void AddDependantCmd( Handle(_pyCommand) cmd, bool prepend = false)
157   { if (prepend) myDependentCmds.push_front( cmd ); else myDependentCmds.push_back( cmd ); }
158   bool SetDependentCmdsAfter() const;
159
160   bool AddAccessorMethod( _pyID theObjectID, const char* theAcsMethod );
161
162   DEFINE_STANDARD_RTTI (_pyCommand)
163 };
164
165 // -------------------------------------------------------------------------------------
166 /*!
167  * \brief Root of all objects. It counts calls of Process()
168  */
169 // -------------------------------------------------------------------------------------
170
171 class _pyObject: public Standard_Transient
172 {
173 protected:
174   _pyID                           myID;
175   Handle(_pyCommand)              myCreationCmd;
176   std::list< Handle(_pyCommand) > myProcessedCmds;
177   std::list< Handle(_pyCommand) > myArgCmds; // where this obj is used as an argument
178   bool                            myIsPublished;
179
180   void setID(const _pyID& theID);
181 public:
182   _pyObject(const Handle(_pyCommand)& theCreationCmd, const _pyID& theID=_pyID());
183   const _pyID& GetID() { return myID.IsEmpty() ? myCreationCmd->GetResultValue() : myID; }
184   static _pyID FatherID(const _pyID & childID);
185   const Handle(_pyCommand)& GetCreationCmd() { return myCreationCmd; }
186   int GetNbCalls() const { return myProcessedCmds.size(); }
187   bool IsInStudy() const { return myIsPublished; }
188   virtual void SetRemovedFromStudy(const bool isRemoved) { myIsPublished = !isRemoved; }
189   void SetCreationCmd( Handle(_pyCommand) cmd ) { myCreationCmd = cmd; }
190   int GetCommandNb() { return myCreationCmd->GetOrderNb(); }
191   void AddProcessedCmd( const Handle(_pyCommand) & cmd )
192   { if (myProcessedCmds.empty() || myProcessedCmds.back()!=cmd) myProcessedCmds.push_back( cmd );}
193   std::list< Handle(_pyCommand) >& GetProcessedCmds() { return myProcessedCmds; }
194   void AddArgCmd( const Handle(_pyCommand) & cmd ) { myArgCmds.push_back( cmd ); }
195   virtual void Process(const Handle(_pyCommand) & cmd) { AddProcessedCmd(cmd); }
196   virtual void Flush() = 0;
197   virtual const char* AccessorMethod() const;
198   virtual bool CanClear();
199   virtual void ClearCommands();
200   virtual void Free() {}
201
202   DEFINE_STANDARD_RTTI (_pyObject)
203 };
204
205 // -------------------------------------------------------------------------------------
206 /*!
207  * \brief Data used to restore cleared Compute() command of an exported mesh
208  * when an imported mesh is created
209  */
210 // -------------------------------------------------------------------------------------
211 struct ExportedMeshData
212 {
213   Handle(_pyMesh)    myMesh;
214   Handle(_pyCommand) myLastComputeCmd;
215   _AString           myLastComputeCmdString;
216   ExportedMeshData() {}
217   ExportedMeshData( const Handle(_pyMesh)& mesh, Handle(_pyCommand) computeCmd):
218     myMesh( mesh ), myLastComputeCmd( computeCmd )
219   {
220     if ( !myLastComputeCmd.IsNull())
221       myLastComputeCmdString = myLastComputeCmd->GetString();
222   }
223 };
224
225 // -------------------------------------------------------------------------------------
226 /*!
227  * \brief A container of strings groupped by prefix. It is used for a faster search of
228  *        objects requiring to KeepAgrCmds() in commands. A speed up is gained because
229  *        only a common prefix (e.g. "aArea") of many object IDs is searched in a command
230  *        and not every object ID
231  */
232 // -------------------------------------------------------------------------------------
233 class _pyStringFamily
234 {
235   _AString                     _prefix;
236   std::list< _pyStringFamily > _subFams;
237   std::list< _AString >        _strings;
238   int isIn( const char* str );
239 public:
240   bool Add( const char* str );
241   bool IsInArgs( Handle( _pyCommand)& cmd, std::list<_AString>& subStr );
242   void Print( int level = 0 );
243 };
244
245 // -------------------------------------------------------------------------------------
246 /*!
247  * \brief Class corresponding to SMESH_Gen. It holds info on existing
248  *        meshes and hypotheses
249  */
250 // -------------------------------------------------------------------------------------
251 class _pyGen: public _pyObject
252 {
253 public:
254   _pyGen(Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod,
255          Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
256          std::set< TCollection_AsciiString >&      theRemovedObjIDs,
257          SALOMEDS::Study_ptr&                      theStudy,
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   SALOMEDS::Study_var                       myStudy;
329   int                                       myGeomIDNb, myGeomIDIndex;
330   std::map< _AString, ExportedMeshData >    myFile2ExportedMesh;
331   Handle( _pyHypothesisReader )             myHypReader;
332
333   DEFINE_STANDARD_RTTI (_pyGen)
334 };
335
336 // -------------------------------------------------------------------------------------
337 /*!
338  * \brief Contains commands concerning mesh substructures
339  */
340 // -------------------------------------------------------------------------------------
341 #define _pyMesh_ACCESS_METHOD "GetMesh()"
342 class _pyMesh: public _pyObject
343 {
344   std::list< Handle(_pyHypothesis) > myHypos;
345   std::list< Handle(_pyCommand) >    myAddHypCmds, myNotConvertedAddHypCmds;
346   std::list< Handle(_pySubMesh) >    mySubmeshes;
347   std::list< Handle(_pyGroup) >      myGroups;
348   std::list< Handle(_pyMeshEditor)>  myEditors;
349   //d::list< Handle(_pyMesh) >       myFatherMeshes; // this mesh depends on
350   std::list< Handle(_pyMesh) >       myChildMeshes; // depending on me
351   bool                               myGeomNotInStudy;
352   Handle(_pyCommand)                 myLastComputeCmd;
353 public:
354   _pyMesh(const Handle(_pyCommand) creationCmd);
355   _pyMesh(const Handle(_pyCommand) theCreationCmd, const _pyID & id);
356   const _pyID& GetGeom() { return GetCreationCmd()->GetArg(1); }
357   void AddGroup( const Handle(_pyGroup)& g ) { myGroups.push_back( g ); }
358   void AddEditor( const Handle(_pyMeshEditor)& e ) { myEditors.push_back( e ); }
359   bool IsNotGeomPublished() { return myGeomNotInStudy; }
360   virtual void Process( const Handle(_pyCommand)& theCommand);
361   virtual void Flush();
362   virtual void SetRemovedFromStudy(const bool isRemoved);
363   virtual bool CanClear();
364   virtual void ClearCommands();
365   virtual void Free() { /*myFatherMeshes.clear();*/ myChildMeshes.clear(); }
366   virtual const char* AccessorMethod() const { return _pyMesh_ACCESS_METHOD; }
367 private:
368   void addFatherMesh( const Handle(_pyMesh)& mesh );
369   void addFatherMesh( const _pyID& meshID );
370   static bool NeedMeshAccess( const Handle(_pyCommand)& theCommand );
371   static void AddMeshAccess( const Handle(_pyCommand)& theCommand )
372   { theCommand->SetObject( theCommand->GetObject() + "." _pyMesh_ACCESS_METHOD ); }
373
374   DEFINE_STANDARD_RTTI (_pyMesh)
375 };
376 #undef _pyMesh_ACCESS_METHOD 
377
378 // -------------------------------------------------------------------------------------
379 /*!
380  * \brief MeshEditor convert its commands to ones of mesh
381  */
382 // -------------------------------------------------------------------------------------
383 class _pyMeshEditor: public _pyObject
384 {
385   _pyID    myMesh;
386   _AString myCreationCmdStr;
387 public:
388   _pyMeshEditor(const Handle(_pyCommand)& theCreationCmd);
389   _pyID GetMesh() const { return myMesh; }
390   virtual void Process( const Handle(_pyCommand)& theCommand);
391   virtual void Flush() {}
392   virtual bool CanClear();
393
394   DEFINE_STANDARD_RTTI (_pyMesh)
395 };
396
397 // -------------------------------------------------------------------------------------
398 /*!
399  * \brief Root class for hypothesis
400  */
401 // -------------------------------------------------------------------------------------
402 class _pyHypothesis: public _pyObject
403 {
404   friend class _pyHypothesisReader;
405 protected:
406   bool    myIsAlgo, myIsWrapped;
407   _pyID   myGeom,   myMesh;
408   struct CreationMethod {
409     _AString              myMethod; // method of algo or mesh creating a hyp
410     // myArgNb(i)-th arg of myArgMethods(i) of hyp becomes an i-th arg of myMethod
411     std::vector<_AString> myArgMethods;
412     std::vector<int>      myArgNb; // arg nb countered from 1
413     std::vector<_AString> myArgs; // creation arguments
414   };
415   void setCreationArg( const int argNb, const _AString& arg );
416   // a hypothesis can be created by different algos by different methods
417   typedef std::map<_AString, CreationMethod > TType2CrMethod;
418   TType2CrMethod                myAlgoType2CreationMethod;
419   std::set< _AString >          myAccumulativeMethods;
420   CreationMethod*               myCurCrMethod; // used for adding to myAlgoType2CreationMethod
421   std::list<Handle(_pyCommand)> myArgCommands;
422   std::list<Handle(_pyCommand)> myUnusedCommands;
423   std::list<Handle(_pyObject) > myReferredObjs;
424   // maps used to clear commands setting parameters if result of setting is
425   // discared (e.g. by mesh.Clear())
426   std::map<_AString, std::list<Handle(_pyCommand)> >            myMeth2Commands;
427   std::map< _pyCommand::TAddr, std::list<Handle(_pyCommand) > > myComputeAddr2Cmds;
428   std::list<Handle(_pyCommand) >                                myComputeCmds;
429   void rememberCmdOfParameter( const Handle(_pyCommand) & cmd );
430   bool isCmdUsedForCompute( const Handle(_pyCommand) & cmd,
431                             _pyCommand::TAddr avoidComputeAddr=NULL ) const;
432 public:
433   _pyHypothesis(const Handle(_pyCommand)& theCreationCmd);
434   void SetConvMethodAndType(const _AString& creationMethod, const _AString& type)
435   { myCurCrMethod = &myAlgoType2CreationMethod[ type ];
436     myCurCrMethod->myMethod = creationMethod; }
437   void AddArgMethod(const _AString& method, const int argNb = 1)
438   { myCurCrMethod->myArgMethods.push_back( method );
439     myCurCrMethod->myArgNb.push_back( argNb ); }
440   void AddAccumulativeMethod( const _AString& method)
441   { myAccumulativeMethods.insert( method ); }
442   //const TColStd_SequenceOfAsciiString& GetArgs() const { return myArgs; }
443   const std::list<Handle(_pyCommand)>& GetArgCommands() const { return myArgCommands; }
444   void ClearAllCommands();
445   virtual bool IsAlgo() const { return myIsAlgo; }
446   bool IsValid() const { return !myAlgoType2CreationMethod.empty(); }
447   bool IsWrapped() const { return myIsWrapped; }
448   const _pyID & GetGeom() const { return myGeom; }
449   void SetMesh( const _pyID& theMeshId) { if ( myMesh.IsEmpty() ) myMesh = theMeshId; }
450   const _pyID & GetMesh() const { return myMesh; }
451   const _AString& GetAlgoType() const
452   { return myAlgoType2CreationMethod.begin()->first; }
453   const _AString& GetAlgoCreationMethod() const
454   { return myAlgoType2CreationMethod.begin()->second.myMethod; }
455   bool CanBeCreatedBy(const _AString& algoType ) const
456   { return myAlgoType2CreationMethod.find( algoType ) != myAlgoType2CreationMethod.end(); }
457   const _AString& GetCreationMethod(const _AString& algoType)
458   { return ( myCurCrMethod = & myAlgoType2CreationMethod[ algoType ])->myMethod; }
459   static Handle(_pyHypothesis) NewHypothesis( const Handle(_pyCommand)& theCreationCmd);
460
461   virtual bool IsWrappable(const _pyID& theMesh) const;
462   virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
463                                   const _pyID&              theMesh);
464   virtual void Process( const Handle(_pyCommand)& theCommand);
465   virtual void Flush();
466   virtual void Free() { myReferredObjs.clear(); }
467   virtual void Assign( const Handle(_pyHypothesis)& theOther,
468                        const _pyID&                 theMesh );
469   virtual bool CanClear();
470   virtual void ClearCommands();
471   virtual bool GetReferredMeshesAndGeom( std::list< Handle(_pyMesh) >& meshes );
472
473   void MeshComputed    ( const Handle(_pyCommand)& theComputeCommand );
474   void ComputeDiscarded( const Handle(_pyCommand)& theComputeCommand );
475   //void ComputeSaved    ( const Handle(_pyCommand)& theComputeCommand );
476
477
478   DEFINE_STANDARD_RTTI (_pyHypothesis)
479 };
480
481 // -------------------------------------------------------------------------------------
482 /*!
483  * \brief Class representing smesh.Mesh_Algorithm
484  */
485 // -------------------------------------------------------------------------------------
486 class _pyAlgorithm: public _pyHypothesis
487 {
488 public:
489   _pyAlgorithm(const Handle(_pyCommand)& theCreationCmd);
490   virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
491                                   const _pyID&              theMesh);
492   virtual const char* AccessorMethod() const { return "GetAlgorithm()"; }
493   virtual bool IsWrappable(const _pyID& theMesh) { return !myIsWrapped; }
494
495   DEFINE_STANDARD_RTTI (_pyAlgorithm)
496 };
497
498 // -------------------------------------------------------------------------------------
499 /*!
500  * \brief Class for hypotheses having several parameters modified by one method
501  */
502 // -------------------------------------------------------------------------------------
503 class _pyComplexParamHypo: public _pyHypothesis
504 {
505 public:
506   _pyComplexParamHypo(const Handle(_pyCommand)& theCreationCmd): _pyHypothesis(theCreationCmd) {}
507   virtual void Process( const Handle(_pyCommand)& theCommand);
508   virtual void Flush();
509
510   DEFINE_STANDARD_RTTI (_pyComplexParamHypo)
511 };
512 DEFINE_STANDARD_HANDLE (_pyComplexParamHypo, _pyHypothesis);
513
514 // -------------------------------------------------------------------------------------
515 /*!
516  * \brief Class for LayerDistribution hypothesis conversion
517  */
518 // -------------------------------------------------------------------------------------
519 class _pyLayerDistributionHypo: public _pyHypothesis
520 {
521   Handle(_pyHypothesis) my1dHyp;
522   _AString              myAlgoMethod;
523 public:
524   _pyLayerDistributionHypo(const Handle(_pyCommand)& theCreationCmd, const char* algoMethod):
525     _pyHypothesis(theCreationCmd), myAlgoMethod((char*)algoMethod) {}
526   virtual void Process( const Handle(_pyCommand)& theCommand);
527   virtual void Flush();
528   virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
529                                   const _pyID&              theMesh);
530   virtual void Free() { my1dHyp.Nullify(); }
531
532   DEFINE_STANDARD_RTTI (_pyLayerDistributionHypo)
533 };
534 DEFINE_STANDARD_HANDLE (_pyLayerDistributionHypo, _pyHypothesis);
535
536 // -------------------------------------------------------------------------------------
537 /*!
538  * \brief Class representing NumberOfSegments hypothesis
539  */
540 // -------------------------------------------------------------------------------------
541 class _pyNumberOfSegmentsHyp: public _pyHypothesis
542 {
543 public:
544   _pyNumberOfSegmentsHyp(const Handle(_pyCommand)& theCrCmd): _pyHypothesis(theCrCmd) {}
545   virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
546                                   const _pyID&              theMesh);
547   void Flush();
548
549   DEFINE_STANDARD_RTTI (_pyNumberOfSegmentsHyp)
550 };
551 DEFINE_STANDARD_HANDLE (_pyNumberOfSegmentsHyp, _pyHypothesis);
552
553 // -------------------------------------------------------------------------------------
554 /*!
555  * \brief Class representing SegmentLengthAroundVertex hypothesis
556  */
557 // -------------------------------------------------------------------------------------
558 class _pySegmentLengthAroundVertexHyp: public _pyHypothesis
559 {
560 public:
561   _pySegmentLengthAroundVertexHyp(const Handle(_pyCommand)& theCrCmd): _pyHypothesis(theCrCmd) {}
562   virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
563                                   const _pyID&              theMesh);
564   DEFINE_STANDARD_RTTI (_pySegmentLengthAroundVertexHyp)
565 };
566 DEFINE_STANDARD_HANDLE (_pySegmentLengthAroundVertexHyp, _pyHypothesis);
567
568 // -------------------------------------------------------------------------------------
569 /*!
570  * \brief SelfEraser erases creation command if no more it's commands invoked
571  */
572 // -------------------------------------------------------------------------------------
573 class _pySelfEraser: public _pyObject
574 {
575   bool myIgnoreOwnCalls; // not to erase only if this obj is used as argument
576 public:
577   _pySelfEraser(const Handle(_pyCommand)& theCreationCmd);
578   void IgnoreOwnCalls() { myIgnoreOwnCalls = true; }
579   virtual void Flush();
580   virtual bool CanClear();
581   static bool IsAliveCmd( const Handle(_pyCommand)& theCmd );
582
583   DEFINE_STANDARD_RTTI (_pySelfEraser)
584 };
585 DEFINE_STANDARD_HANDLE (_pySelfEraser, _pyObject);
586
587 // -------------------------------------------------------------------------------------
588 /*!
589  * \brief SubMesh creation can be moved to the end of engine commands
590  */
591 // -------------------------------------------------------------------------------------
592 class _pySubMesh:  public _pyObject
593 {
594   Handle(_pyObject) myCreator;
595   Handle(_pyMesh) myMesh;
596 public:
597   _pySubMesh(const Handle(_pyCommand)& theCreationCmd, bool toKeepAgrCmds=true);
598   virtual void Process( const Handle(_pyCommand)& theCommand);
599   virtual void Flush();
600   virtual Handle(_pyMesh) GetMesh() { return myMesh; }
601   virtual void Free() { myCreator.Nullify(); myMesh.Nullify(); }
602   void SetCreator( const Handle(_pyObject)& theCreator ) { myCreator = theCreator; }
603   static bool CanBeArgOfMethod(const _AString& theMethodName);
604
605   DEFINE_STANDARD_RTTI (_pySubMesh)
606 };
607 // -------------------------------------------------------------------------------------
608 /*!
609  * \brief A filter sets a human readable name to self
610  */
611 // -------------------------------------------------------------------------------------
612 class _pyFilter:  public _pyObject
613 {
614   _pyID myNewID, myMesh;
615   //std::list< Handle(_pyObject) > myUsers;
616 public:
617   _pyFilter(const Handle(_pyCommand)& theCreationCmd, const _pyID& newID="");
618   //void AddUser( const Handle(_pyObject)& user) { myUsers.push_back( user ); }
619   virtual void Process( const Handle(_pyCommand)& theCommand);
620   virtual void Flush();
621   //virtual bool CanClear();
622   //virtual void Free() { myUsers.clear(); }
623   const _pyID& GetNewID() const { return myNewID; }
624
625   DEFINE_STANDARD_RTTI (_pyFilter)
626 };
627 DEFINE_STANDARD_HANDLE (_pyFilter, _pyObject);
628
629 // -------------------------------------------------------------------------------------
630 /*!
631  * \brief To convert creation of a group by filter
632  */
633 // -------------------------------------------------------------------------------------
634 class _pyGroup:  public _pySubMesh // use myMesh of _pySubMesh
635 {
636   Handle(_pyFilter) myFilter;
637   bool              myCanClearCreationCmd;
638 public:
639   _pyGroup(const Handle(_pyCommand)& theCreationCmd, const _pyID & id=_pyID());
640   virtual void Process( const Handle(_pyCommand)& theCommand);
641   virtual void Flush();
642   virtual void Free() { myFilter.Nullify(); }
643   virtual bool CanClear();
644   void RemovedWithContents();
645
646   DEFINE_STANDARD_RTTI (_pyGroup)
647 };
648
649 // -------------------------------------------------------------------------------------
650 /*!
651  * \brief Class reading _pyHypothesis'es from resource files of mesher Plugins
652  */
653 // -------------------------------------------------------------------------------------
654 class _pyHypothesisReader: public Standard_Transient
655 {
656   std::map<_AString, Handle(_pyHypothesis)> myType2Hyp;
657 public:
658   _pyHypothesisReader();
659   Handle(_pyHypothesis) GetHypothesis(const _AString&           hypType,
660                                       const Handle(_pyCommand)& creationCmd) const;
661   DEFINE_STANDARD_RTTI (_pyHypothesisReader)
662 };
663
664 #endif