Version: 8.3.0
SMESH_subMesh.hxx
Go to the documentation of this file.
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_subMesh.hxx
24 // Author : Paul RASCLE, EDF
25 // Module : SMESH
26 //
27 #ifndef _SMESH_SUBMESH_HXX_
28 #define _SMESH_SUBMESH_HXX_
29 
30 #include "SMESH_SMESH.hxx"
31 
32 #include "SMDS_Iterator.hxx"
33 #include "SMESH_ComputeError.hxx"
34 #include "SMESH_Algo.hxx"
35 
36 #include "Utils_SALOME_Exception.hxx"
37 
38 #include <TopoDS_Shape.hxx>
39 
40 #include <list>
41 #include <map>
42 
43 class SMESHDS_Mesh;
44 class SMESHDS_SubMesh;
45 class SMESH_Algo;
46 class SMESH_Gen;
47 class SMESH_Hypothesis;
48 class SMESH_Mesh;
49 class SMESH_subMesh;
52 
55 
56 typedef boost::shared_ptr< SMDS_Iterator<SMESH_subMesh*> > SMESH_subMeshIteratorPtr;
57 
58 
60 {
61  public:
62  SMESH_subMesh(int Id,
63  SMESH_Mesh * father,
64  SMESHDS_Mesh * meshDS,
65  const TopoDS_Shape & aSubShape);
66  virtual ~ SMESH_subMesh();
67 
68  int GetId() const; // == meshDS->ShapeToIndex( aSubShape )
69 
70  SMESH_Mesh* GetFather() { return _father; }
71 
72  SMESHDS_SubMesh * GetSubMeshDS();
73  const SMESHDS_SubMesh * GetSubMeshDS() const;
74 
75  SMESHDS_SubMesh* CreateSubMeshDS();
76  // Explicit SMESHDS_SubMesh creation method, required for persistence mechanism
77 
78  SMESH_subMesh *GetFirstToCompute();
79 
80  SMESH_Algo* GetAlgo() const;
81 
82  const std::map < int, SMESH_subMesh * >& DependsOn();
83  bool DependsOn( const SMESH_subMesh* other ) const;
84  bool DependsOn( const int shapeID ) const;
89  SMESH_subMeshIteratorPtr getDependsOnIterator(const bool includeSelf,
90  const bool complexShapeFirst=false) const;
91 
92  const std::vector< SMESH_subMesh * > & GetAncestors() const;
93  void ClearAncestors();
94 
95  const TopoDS_Shape & GetSubShape() const;
96 
98  {
99  NOT_READY, READY_TO_COMPUTE, COMPUTE_OK, FAILED_TO_COMPUTE
100  };
102  {
103  NO_ALGO, MISSING_HYP, HYP_OK
104  };
106  {
107  ADD_HYP , ADD_ALGO,
108  REMOVE_HYP , REMOVE_ALGO,
109  ADD_FATHER_HYP , ADD_FATHER_ALGO,
110  REMOVE_FATHER_HYP, REMOVE_FATHER_ALGO,
111  MODIF_HYP
112  };
114  {
115  MODIF_ALGO_STATE, COMPUTE, COMPUTE_SUBMESH, COMPUTE_NOGEOM, COMPUTE_CANCELED,
116  CLEAN, SUBMESH_COMPUTED, SUBMESH_RESTORED, SUBMESH_LOADED,
117  MESH_ENTITY_REMOVED, CHECK_COMPUTE_STATE
118  };
120  {
121  ALGO_EVENT, COMPUTE_EVENT
122  };
123 
124  // ==================================================================
125  // Members to track non hierarchical dependencies between sub-meshes
126  // ==================================================================
127 
138  void SetEventListener(EventListener* listener,
139  EventListenerData* data,
140  SMESH_subMesh* where);
141 
149  EventListenerData* GetEventListenerData(EventListener* listener,
150  const bool myOwn=false) const;
151 
159  EventListenerData* GetEventListenerData(const std::string& listenerName,
160  const bool myOwn=false) const;
161 
166  void DeleteEventListener(EventListener* listener);
167 
168 protected:
169 
171  std::map< EventListener*, EventListenerData* > _eventListeners;
172 
176  int myMeshID; // id of mySubMesh->GetFather()
180  };
181  std::list< OwnListenerData > _ownListeners;
182 
190  void setEventListener(EventListener* listener, EventListenerData* data);
191 
198  void notifyListenersOnEvent( const int event,
199  const event_type eventType,
200  SMESH_Hypothesis* hyp = 0);
201 
205  void deleteOwnListeners();
206 
210  void loadDependentMeshes();
211 
212  // END: Members to track non hierarchical dependencies between submeshes
213  // =====================================================================
214 
215 public:
216 
218  AlgoStateEngine(algo_event event, SMESH_Hypothesis * anHyp);
219 
221  SubMeshesAlgoStateEngine(algo_event event, SMESH_Hypothesis * anHyp, bool exitOnFatal=false);
222 
223  algo_state GetAlgoState() const { return _algoState; }
224  compute_state GetComputeState() const { return _computeState; }
225  SMESH_ComputeErrorPtr& GetComputeError() { return _computeError; }
226 
227  void DumpAlgoState(bool isMain);
228 
229  bool ComputeStateEngine(compute_event event);
230  void ComputeSubMeshStateEngine(compute_event event, const bool includeSelf=false);
231 
232  bool Evaluate(MapShapeNbElems& aResMap);
233 
234  bool IsConform(const SMESH_Algo* theAlgo);
235  // check if a conform mesh will be produced by the Algo
236 
237  bool CanAddHypothesis(const SMESH_Hypothesis* theHypothesis) const;
238  // return true if theHypothesis can be attached to me:
239  // its dimension is checked
240 
241  static bool IsApplicableHypotesis(const SMESH_Hypothesis* theHypothesis,
242  const TopAbs_ShapeEnum theShapeType);
243 
244  bool IsApplicableHypotesis(const SMESH_Hypothesis* theHypothesis) const;
245  // return true if theHypothesis can be used to mesh me:
246  // its shape type is checked
247 
248  SMESH_Hypothesis::Hypothesis_Status CheckConcurentHypothesis (const int theHypType);
249  // check if there are several applicable hypothesis on fathers
250 
254  bool IsEmpty() const;
255 
256  bool IsMeshComputed() const;
257  // check if _subMeshDS contains mesh elements unless _alwaysComputed==true
258 
263  void SetIsAlwaysComputed(bool isAlCo);
264  bool IsAlwaysComputed() { return _alwaysComputed; }
265 
266  bool SubMeshesComputed(bool * isFailedToCompute=0) const;
267 
268  int GetComputeCost() const;
269  // how costly is to compute this sub-mesh
270 
277  bool FindIntersection( const SMESH_subMesh * theOther,
278  std::set<const SMESH_subMesh*>& theSetOfCommon ) const;
279 
280 protected:
281  // ==================================================================
282  void insertDependence(const TopoDS_Shape aShape,
283  TopAbs_ShapeEnum aSubType,
284  TopAbs_ShapeEnum avoidType=TopAbs_SHAPE);
285 
286  void removeSubMeshElementsAndNodes();
287  void updateDependantsState(const compute_event theEvent);
288  void updateSubMeshState(const compute_state theState);
289  void cleanDependants();
290  void cleanDependsOn( SMESH_Algo* algoRequiringCleaning=0 );
291  void setAlgoState(algo_state state);
292 
297  TopoDS_Shape getCollection(SMESH_Gen * theGen,
298  SMESH_Algo* theAlgo,
299  bool & theSubComputed,
300  bool & theSubFailed,
301  std::vector<SMESH_subMesh*>& theSubs);
306  bool checkComputeError(SMESH_Algo* theAlgo,
307  const bool theComputeOK,
308  const TopoDS_Shape& theShape=TopoDS_Shape());
309 
317  const SMESH_Hypothesis* getSimilarAttached(const TopoDS_Shape& theShape,
318  const SMESH_Hypothesis * theHyp,
319  const int theHypType = 0);
320  //
321  int computeCost() const;
322 
323 protected:
324 
325  TopoDS_Shape _subShape;
328  int _Id;
329 
330  std::map < int, SMESH_subMesh * >_mapDepend;
332  std::vector< SMESH_subMesh * > _ancestors;
333 
334  SMESH_Algo * _algo; // the algorithm found by last *StateEngine() call
338  int _computeCost; // how costly is to compute this sub-mesh
339  int _realComputeCost; // _computeCost depending on presence of needed hypotheses
340 
341  // allow algo->Compute() if a sub-shape of lower dim is meshed but
342  // none mesh entity is bound to it. Eg StdMeshers_CompositeSegment_1D can
343  // mesh several edges as a whole and leave some of them without mesh entities
345 
346 };
347 
348 #endif