Version: 9.16.0
SMESH_subMesh.hxx
Go to the documentation of this file.
1// Copyright (C) 2007-2026 CEA, EDF, 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"
34#include "SMESH_Algo.hxx"
35
36#include "Utils_SALOME_Exception.hxx"
37
38#include <TopoDS_Shape.hxx>
39#include <TopTools_IndexedMapOfShape.hxx>
40
41#include <list>
42#include <map>
43
44class SMESHDS_Mesh;
45class SMESHDS_SubMesh;
46class SMESH_Algo;
47class SMESH_Gen;
49class SMESH_Mesh;
50class SMESH_subMesh;
53
56
57typedef boost::shared_ptr< SMDS_Iterator<SMESH_subMesh*> > SMESH_subMeshIteratorPtr;
58
59
61{
62 public:
63 SMESH_subMesh(int Id,
64 SMESH_Mesh * father,
65 SMESHDS_Mesh * meshDS,
66 const TopoDS_Shape & aSubShape);
67 virtual ~ SMESH_subMesh();
68
69 int GetId() const; // == meshDS->ShapeToIndex( aSubShape )
70
71 SMESH_Mesh* GetFather() { return _father; }
72
73 SMESHDS_SubMesh * GetSubMeshDS();
74 const SMESHDS_SubMesh * GetSubMeshDS() const;
75
76 SMESHDS_SubMesh* CreateSubMeshDS();
77 // Explicit SMESHDS_SubMesh creation method, required for persistence mechanism
78
79 SMESH_subMesh *GetFirstToCompute();
80
81 SMESH_Algo* GetAlgo() const;
83
84 const std::map < int, SMESH_subMesh * >& DependsOn();
85 bool DependsOn( const SMESH_subMesh* other ) const;
86 bool DependsOn( const int shapeID ) const;
91 SMESH_subMeshIteratorPtr getDependsOnIterator(const bool includeSelf,
92 const bool complexShapeFirst=false) const;
93
94 const std::vector< SMESH_subMesh * > & GetAncestors() const;
95 void ClearAncestors();
96
97 const TopoDS_Shape & GetSubShape() const;
98
100 {
101 NOT_READY, READY_TO_COMPUTE, COMPUTE_OK, FAILED_TO_COMPUTE
102 };
104 {
106 };
108 {
109 ADD_HYP , ADD_ALGO,
110 REMOVE_HYP , REMOVE_ALGO,
111 ADD_FATHER_HYP , ADD_FATHER_ALGO,
112 REMOVE_FATHER_HYP, REMOVE_FATHER_ALGO,
113 MODIF_HYP
114 };
116 {
117 MODIF_ALGO_STATE, COMPUTE, COMPUTE_SUBMESH, COMPUTE_NOGEOM, COMPUTE_CANCELED,
118 CLEAN, SUBMESH_COMPUTED, SUBMESH_RESTORED, SUBMESH_LOADED,
119 MESH_ENTITY_REMOVED, CHECK_COMPUTE_STATE
120 };
122 {
123 ALGO_EVENT, COMPUTE_EVENT
124 };
125
126 // ==================================================================
127 // Members to track non hierarchical dependencies between sub-meshes
128 // ==================================================================
129
140 void SetEventListener(EventListener* listener,
141 EventListenerData* data,
142 SMESH_subMesh* where);
143
150 void AddOwnListener(EventListener* listener);
151
159 EventListenerData* GetEventListenerData(EventListener* listener,
160 const bool myOwn=false) const;
161
169 EventListenerData* GetEventListenerData(const std::string& listenerName,
170 const bool myOwn=false) const;
171
176 void DeleteEventListener(EventListener* listener);
177
178protected:
179
181 std::map< EventListener*, EventListenerData* > _eventListeners;
182
186 int myMeshID; // id of mySubMesh->GetFather()
190 };
191 std::list< OwnListenerData > _ownListeners;
192
200 void setEventListener(EventListener* listener, EventListenerData* data);
201
208 void notifyListenersOnEvent( const int event,
209 const event_type eventType,
210 SMESH_Hypothesis* hyp = 0);
211
215 void deleteOwnListeners();
216
220 void loadDependentMeshes();
221
222 // END: Members to track non hierarchical dependencies between submeshes
223 // =====================================================================
224
225public:
226
228 AlgoStateEngine(algo_event event, SMESH_Hypothesis * anHyp);
229
231 SubMeshesAlgoStateEngine(algo_event event, SMESH_Hypothesis * anHyp, bool exitOnFatal=false);
232
233 algo_state GetAlgoState() const { return _algoState; }
234 compute_state GetComputeState() const { return _computeState; }
235 SMESH_ComputeErrorPtr& GetComputeError() { return _computeError; }
236
237 void DumpAlgoState(bool isMain);
238
239 bool ComputeStateEngine(compute_event event);
240 void ComputeSubMeshStateEngine(compute_event event, const bool includeSelf=false);
241
242 bool Evaluate(MapShapeNbElems& aResMap);
243
244 bool IsConform(const SMESH_Algo* theAlgo);
245 // check if a conform mesh will be produced by the Algo
246
247 bool CanAddHypothesis(const SMESH_Hypothesis* theHypothesis) const;
248 // return true if theHypothesis can be attached to me:
249 // its dimension is checked
250
251 static bool IsApplicableHypothesis(const SMESH_Hypothesis* theHypothesis,
252 const TopAbs_ShapeEnum theShapeType);
253
254 bool IsApplicableHypothesis(const SMESH_Hypothesis* theHypothesis) const;
255 // return true if theHypothesis can be used to mesh me:
256 // its shape type is checked
257
258 SMESH_Hypothesis::Hypothesis_Status CheckConcurrentHypothesis (SMESH_Hypothesis* theHypothesis);
259 // check if there are several applicable hypothesis on fathers
260
264 bool IsEmpty() const;
265
266 bool IsMeshComputed() const;
267 // check if _subMeshDS contains mesh elements unless _alwaysComputed==true
268
269 bool IsComputedPartially() const;
270 // check if any upper level sub-shape is not computed
271
275 void SetAllowedSubShapes( const TopTools_IndexedMapOfShape* subShapes )
276 { _allowedSubShapes = subShapes; }
277
282 void SetIsAlwaysComputed(bool isAlCo);
283 bool IsAlwaysComputed() const { return _alwaysComputed; }
284
285 bool SubMeshesComputed(bool * isFailedToCompute=0) const;
286
287 int GetComputeCost() const;
288 // how costly is to compute this sub-mesh
289
296 bool FindIntersection( const SMESH_subMesh * theOther,
297 std::set<const SMESH_subMesh*>& theSetOfCommon ) const;
298
299protected:
300 // ==================================================================
301 void insertDependence(const TopoDS_Shape aShape,
302 TopAbs_ShapeEnum aSubType,
303 TopAbs_ShapeEnum avoidType=TopAbs_SHAPE);
304
305 void removeSubMeshElementsAndNodes();
306 void updateDependantsState(const compute_event theEvent);
307 void updateSubMeshState(const compute_state theState);
308 void cleanDependants();
309 void cleanDependsOn( SMESH_Algo* algoRequiringCleaning=0 );
310 void setAlgoState(algo_state state);
311
316 TopoDS_Shape getCollection(SMESH_Gen * theGen,
317 SMESH_Algo* theAlgo,
318 bool & theSubComputed,
319 bool & theSubFailed,
320 std::vector<SMESH_subMesh*>& theSubs);
325 bool checkComputeError(SMESH_Algo* theAlgo,
326 const bool theComputeOK,
327 const TopoDS_Shape& theShape=TopoDS_Shape());
328
336 const SMESH_Hypothesis* getSimilarAttached(const TopoDS_Shape& theShape,
337 const SMESH_Hypothesis * theHyp,
338 const int theHypType = 0);
339 //
340 int computeCost() const;
341
342protected:
343
344 TopoDS_Shape _subShape;
347 int _Id;
348
349 std::map < int, SMESH_subMesh * >_mapDepend;
351 std::vector< SMESH_subMesh * > _ancestors;
352
353 SMESH_Algo * _algo; // the algorithm found by last *StateEngine() call
354 TopoDS_Shape _algoShape; // shape the algorithm is assigned to
358 int _computeCost; // how costly is to compute this sub-mesh
359 int _realComputeCost; // _computeCost depending on presence of needed hypotheses
360
361 // allow algo->Compute() if a sub-shape of lower dim is meshed but
362 // none mesh entity is bound to it. Eg StdMeshers_CompositeSegment_1D can
363 // mesh several edges as a whole and leave some of them without mesh entities
365
366 const TopTools_IndexedMapOfShape* _allowedSubShapes; // allowed to be returned by getCollection()
367
368};
369
370#endif
std::map< SMESH_subMesh *, std::vector< smIdType > > MapShapeNbElems
Definition: SMESH_Algo.hxx:63
boost::shared_ptr< SMESH_ComputeError > SMESH_ComputeErrorPtr
Definition: SMESH_ComputeError.hxx:38
#define SMESH_EXPORT
Definition: SMESH_SMESH.hxx:37
boost::shared_ptr< SMDS_Iterator< SMESH_subMesh * > > SMESH_subMeshIteratorPtr
Definition: SMESH_subMesh.hxx:57
SMESH_subMeshEventListenerData EventListenerData
Definition: SMESH_subMesh.hxx:55
SMESH_subMeshEventListener EventListener
Definition: SMESH_subMesh.hxx:54
Definition: SMESHDS_Mesh.hxx:98
Definition: SMESHDS_SubMesh.hxx:48
Root of all algorithms.
Definition: SMESH_Algo.hxx:79
Definition: SMESH_Gen.hxx:68
Definition: SMESH_Hypothesis.hxx:48
Hypothesis_Status
Definition: SMESH_Hypothesis.hxx:51
Definition: SMESH_Mesh.hxx:80
A base for objects reacting on submesh events.
Definition: SMESH_subMeshEventListener.hxx:46
Definition: SMESH_subMesh.hxx:61
std::list< OwnListenerData > _ownListeners
Definition: SMESH_subMesh.hxx:191
algo_state
Definition: SMESH_subMesh.hxx:104
@ MISSING_HYP
Definition: SMESH_subMesh.hxx:105
SMESH_Algo * _algo
Definition: SMESH_subMesh.hxx:353
compute_event
Definition: SMESH_subMesh.hxx:116
@ MESH_ENTITY_REMOVED
Definition: SMESH_subMesh.hxx:119
@ COMPUTE
Definition: SMESH_subMesh.hxx:117
@ CLEAN
Definition: SMESH_subMesh.hxx:118
int _realComputeCost
Definition: SMESH_subMesh.hxx:359
SMESH_Mesh * _father
Definition: SMESH_subMesh.hxx:346
algo_state GetAlgoState() const
Definition: SMESH_subMesh.hxx:233
void SetAllowedSubShapes(const TopTools_IndexedMapOfShape *subShapes)
Set sub-shapes that are allowed to compute at once by a multidimensional algo.
Definition: SMESH_subMesh.hxx:275
algo_state _algoState
Definition: SMESH_subMesh.hxx:355
std::vector< SMESH_subMesh * > _ancestors
Definition: SMESH_subMesh.hxx:351
std::map< int, SMESH_subMesh * > _mapDepend
Definition: SMESH_subMesh.hxx:349
SMESH_ComputeErrorPtr _computeError
Definition: SMESH_subMesh.hxx:357
algo_event
Definition: SMESH_subMesh.hxx:108
@ ADD_ALGO
Definition: SMESH_subMesh.hxx:109
@ REMOVE_ALGO
Definition: SMESH_subMesh.hxx:110
@ REMOVE_FATHER_ALGO
Definition: SMESH_subMesh.hxx:112
@ ADD_FATHER_ALGO
Definition: SMESH_subMesh.hxx:111
bool _alwaysComputed
Definition: SMESH_subMesh.hxx:364
bool IsAlwaysComputed() const
Definition: SMESH_subMesh.hxx:283
event_type
Definition: SMESH_subMesh.hxx:122
@ ALGO_EVENT
Definition: SMESH_subMesh.hxx:123
compute_state GetComputeState() const
Definition: SMESH_subMesh.hxx:234
int _computeCost
Definition: SMESH_subMesh.hxx:358
TopoDS_Shape _subShape
Definition: SMESH_subMesh.hxx:344
SMESH_Mesh * GetFather()
Definition: SMESH_subMesh.hxx:71
SMESHDS_SubMesh * _subMeshDS
Definition: SMESH_subMesh.hxx:345
TopoDS_Shape _algoShape
Definition: SMESH_subMesh.hxx:354
const TopTools_IndexedMapOfShape * _allowedSubShapes
Definition: SMESH_subMesh.hxx:366
bool _dependenceAnalysed
Definition: SMESH_subMesh.hxx:350
SMESH_ComputeErrorPtr & GetComputeError()
Definition: SMESH_subMesh.hxx:235
int _Id
Definition: SMESH_subMesh.hxx:347
compute_state _computeState
Definition: SMESH_subMesh.hxx:356
SMESH_Algo * CopyAlgo() const
compute_state
Definition: SMESH_subMesh.hxx:100
@ COMPUTE_OK
Definition: SMESH_subMesh.hxx:101
std::map< EventListener *, EventListenerData * > _eventListeners
< event listeners to notify
Definition: SMESH_subMesh.hxx:181
@ HYP_OK
Definition: SMESH_Mesh.idl:209
GEOM::GEOM_Object_ptr GetSubShape(GEOM::GEOM_Object_ptr theMainShape, long theID)
Definition: SMESHGUI_GEOMGenUtils.cxx:156
void SetEventListener(SMESH_subMesh *subMesh, TopoDS_Shape srcShape, SMESH_Mesh *srcMesh)
Set event listeners to submesh with projection algo.
Definition: StdMeshers_ProjectionUtils.cxx:2546
Data specific for EventListener and to be stored in a submesh.
Definition: SMESH_subMeshEventListener.hxx:87
Definition: SMESH_subMesh.hxx:184
int mySubMeshID
Definition: SMESH_subMesh.hxx:187
EventListener * myListener
Definition: SMESH_subMesh.hxx:188
SMESH_subMesh * mySubMesh
Definition: SMESH_subMesh.hxx:185
int myMeshID
Definition: SMESH_subMesh.hxx:186