1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : SMESH_subMesh.hxx
24 // Author : Paul RASCLE, EDF
27 #ifndef _SMESH_SUBMESH_HXX_
28 #define _SMESH_SUBMESH_HXX_
30 #include "SMESH_SMESH.hxx"
32 #include "SMESHDS_Mesh.hxx"
33 #include "SMESHDS_SubMesh.hxx"
34 #include "SMESH_Hypothesis.hxx"
35 #include "SMESH_ComputeError.hxx"
36 #include "SMESH_Algo.hxx"
38 #include "Utils_SALOME_Exception.hxx"
40 #include <TopoDS_Shape.hxx>
46 class SMESH_Hypothesis;
49 class SMESH_subMeshEventListener;
50 class SMESH_subMeshEventListenerData;
53 typedef SMESH_subMeshEventListener EventListener;
54 typedef SMESH_subMeshEventListenerData EventListenerData;
56 typedef boost::shared_ptr< SMDS_Iterator<SMESH_subMesh*> > SMESH_subMeshIteratorPtr;
59 class SMESH_EXPORT SMESH_subMesh
64 SMESHDS_Mesh * meshDS,
65 const TopoDS_Shape & aSubShape);
66 virtual ~ SMESH_subMesh();
68 int GetId() const; // == meshDS->ShapeToIndex( aSubShape )
70 SMESH_Mesh* GetFather() { return _father; }
72 SMESHDS_SubMesh * GetSubMeshDS();
73 const SMESHDS_SubMesh * GetSubMeshDS() const;
75 SMESHDS_SubMesh* CreateSubMeshDS();
76 // Explicit SMESHDS_SubMesh creation method, required for persistence mechanism
78 SMESH_subMesh *GetFirstToCompute();
80 SMESH_Algo* GetAlgo() const;
82 const std::map < int, SMESH_subMesh * >& DependsOn();
83 bool DependsOn( const SMESH_subMesh* other ) const;
85 * \brief Return iterator on the sub-meshes this one depends on. By default
86 * most simple sub-meshes go first.
88 SMESH_subMeshIteratorPtr getDependsOnIterator(const bool includeSelf,
89 const bool complexShapeFirst=false) const;
91 const TopoDS_Shape & GetSubShape() const;
95 NOT_READY, READY_TO_COMPUTE,
96 COMPUTE_OK, FAILED_TO_COMPUTE
100 NO_ALGO, MISSING_HYP, HYP_OK
105 REMOVE_HYP , REMOVE_ALGO,
106 ADD_FATHER_HYP , ADD_FATHER_ALGO,
107 REMOVE_FATHER_HYP, REMOVE_FATHER_ALGO,
112 MODIF_ALGO_STATE, COMPUTE, COMPUTE_SUBMESH, COMPUTE_CANCELED,
113 CLEAN, SUBMESH_COMPUTED, SUBMESH_RESTORED, SUBMESH_LOADED,
114 MESH_ENTITY_REMOVED, CHECK_COMPUTE_STATE
118 ALGO_EVENT, COMPUTE_EVENT
121 // ==================================================================
122 // Members to track non hierarchical dependencies between submeshes
123 // ==================================================================
126 * \brief Sets an event listener and its data to a submesh
127 * \param listener - the listener to store
128 * \param data - the listener data to store
129 * \param where - the submesh to store the listener and it's data
131 * The method remembers the submesh \awhere it puts the listener in order to delete
132 * it when HYP_OK algo_state is lost
133 * After being set, event listener is notified on each event of \awhere submesh.
135 void SetEventListener(EventListener* listener,
136 EventListenerData* data,
137 SMESH_subMesh* where);
140 * \brief Return an event listener data
141 * \param listener - the listener whose data is
142 * \retval EventListenerData* - found data, maybe NULL
144 EventListenerData* GetEventListenerData(EventListener* listener) const;
147 * \brief Return an event listener data
148 * \param listenerName - the listener name
149 * \retval EventListenerData* - found data, maybe NULL
151 EventListenerData* GetEventListenerData(const std::string& listenerName) const;
154 * \brief Unregister the listener and delete it and it's data
155 * \param listener - the event listener to delete
157 void DeleteEventListener(EventListener* listener);
161 //!< event listeners to notify
162 std::map< EventListener*, EventListenerData* > _eventListeners;
164 //!< event listeners to delete when HYP_OK algo_state is lost
165 struct OwnListenerData {
166 SMESH_subMesh* mySubMesh;
167 int myMeshID; // id of mySubMesh->GetFather()
169 EventListener* myListener;
170 OwnListenerData( SMESH_subMesh* sm=0, EventListener* el=0);
172 std::list< OwnListenerData > _ownListeners;
175 * \brief Sets an event listener and its data to a submesh
176 * \param listener - the listener to store
177 * \param data - the listener data to store
179 * After being set, event listener is notified on each event of a submesh.
181 void setEventListener(EventListener* listener, EventListenerData* data);
184 * \brief Notify stored event listeners on the occured event
185 * \param event - algo_event or compute_event itself
186 * \param eventType - algo_event or compute_event
187 * \param hyp - hypothesis, if eventType is algo_event
189 void notifyListenersOnEvent( const int event,
190 const event_type eventType,
191 SMESH_Hypothesis* hyp = 0);
194 * \brief Delete event listeners depending on algo of this submesh
196 void deleteOwnListeners();
199 * \brief loads dependent meshes on SUBMESH_LOADED event
201 void loadDependentMeshes();
203 // END: Members to track non hierarchical dependencies between submeshes
204 // =====================================================================
208 SMESH_Hypothesis::Hypothesis_Status
209 AlgoStateEngine(int event, SMESH_Hypothesis * anHyp);
211 SMESH_Hypothesis::Hypothesis_Status
212 SubMeshesAlgoStateEngine(int event, SMESH_Hypothesis * anHyp);
214 algo_state GetAlgoState() const { return _algoState; }
215 compute_state GetComputeState() const { return _computeState; };
216 SMESH_ComputeErrorPtr& GetComputeError() { return _computeError; }
218 void DumpAlgoState(bool isMain);
220 bool ComputeStateEngine(int event);
221 void ComputeSubMeshStateEngine(int event, const bool includeSelf=false);
223 bool Evaluate(MapShapeNbElems& aResMap);
225 bool IsConform(const SMESH_Algo* theAlgo);
226 // check if a conform mesh will be produced by the Algo
228 bool CanAddHypothesis(const SMESH_Hypothesis* theHypothesis) const;
229 // return true if theHypothesis can be attached to me:
230 // its dimention is checked
232 static bool IsApplicableHypotesis(const SMESH_Hypothesis* theHypothesis,
233 const TopAbs_ShapeEnum theShapeType);
235 bool IsApplicableHypotesis(const SMESH_Hypothesis* theHypothesis) const
236 { return IsApplicableHypotesis( theHypothesis, _subShape.ShapeType() ); }
237 // return true if theHypothesis can be used to mesh me:
238 // its shape type is checked
240 SMESH_Hypothesis::Hypothesis_Status CheckConcurentHypothesis (const int theHypType);
241 // check if there are several applicable hypothesis on fathers
244 * \brief Return true if no mesh entities is bound to the submesh
246 bool IsEmpty() const;
248 bool IsMeshComputed() const;
249 // check if _subMeshDS contains mesh elements unless _alwaysComputed==true
252 * \brief Allow algo->Compute() if a subshape of lower dim is meshed but
253 * none mesh entity is bound to it
255 void SetIsAlwaysComputed(bool isAlCo);
256 bool IsAlwaysComputed() { return _alwaysComputed; }
258 bool SubMeshesComputed(bool * isFailedToCompute=0) const;
260 int GetComputeCost() const;
261 // how costly is to compute this sub-mesh
264 * \brief Find common submeshes (based on shared subshapes with other
265 * \param theOther submesh to check
266 * \param theCommonIds set of common submesh IDs
267 * NOTE: this method does not cleat set before collect common IDs
269 bool FindIntersection( const SMESH_subMesh * theOther,
270 std::set<const SMESH_subMesh*>& theSetOfCommon ) const;
273 // ==================================================================
274 void insertDependence(const TopoDS_Shape aSubShape);
276 void removeSubMeshElementsAndNodes();
277 void updateDependantsState(const compute_event theEvent);
278 void updateSubMeshState(const compute_state theState);
279 void cleanDependants();
280 void cleanDependsOn( SMESH_Algo* algoRequiringCleaning=0 );
281 void setAlgoState(algo_state state);
284 * \brief Return a shape containing all sub-shapes of the MainShape that can be
285 * meshed at once along with _subShape
287 TopoDS_Shape getCollection(SMESH_Gen * theGen,
289 bool & theSubComputed,
291 std::vector<SMESH_subMesh*>& theSubs);
293 * \brief Update compute_state by _computeError
294 * \retval bool - false if there are errors
296 bool checkComputeError(SMESH_Algo* theAlgo,
297 const bool theComputeOK,
298 const TopoDS_Shape& theShape=TopoDS_Shape());
301 * \brief Return a hypothesis attached to theShape.
303 * If theHyp is provided, similar but not same hypotheses
304 * is returned; else an applicable ones having theHypType
307 const SMESH_Hypothesis* getSimilarAttached(const TopoDS_Shape& theShape,
308 const SMESH_Hypothesis * theHyp,
309 const int theHypType = 0);
311 int computeCost() const;
315 TopoDS_Shape _subShape;
316 SMESHDS_SubMesh * _subMeshDS;
317 SMESH_Mesh * _father;
320 std::map < int, SMESH_subMesh * >_mapDepend;
321 bool _dependenceAnalysed;
323 SMESH_Algo * _algo; // the algorithm found by last *StateEngine() call
324 algo_state _algoState;
325 compute_state _computeState;
326 SMESH_ComputeErrorPtr _computeError;
327 int _computeCost; // how costly is to compute this sub-mesh
328 int _realComputeCost; // _computeCost depending on presence of needed hypotheses
330 // allow algo->Compute() if a sub-shape of lower dim is meshed but
331 // none mesh entity is bound to it. Eg StdMeshers_CompositeSegment_1D can
332 // mesh several edges as a whole and leave some of them without mesh entities
333 bool _alwaysComputed;