1 // Copyright (C) 2007-2011 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
62 SMESH_subMesh(int Id, SMESH_Mesh * father, SMESHDS_Mesh * meshDS,
63 const TopoDS_Shape & aSubShape);
64 virtual ~ SMESH_subMesh();
68 SMESH_Mesh* GetFather() { return _father; }
70 SMESHDS_SubMesh * GetSubMeshDS();
72 SMESHDS_SubMesh* CreateSubMeshDS();
73 // Explicit SMESHDS_SubMesh creation method, required for persistence mechanism
75 SMESH_subMesh *GetFirstToCompute();
77 SMESH_Algo* GetAlgo() const;
79 const std::map < int, SMESH_subMesh * >& DependsOn();
80 //const map < int, SMESH_subMesh * >&Dependants();
82 * \brief Return iterator on the submeshes this one depends on
84 SMESH_subMeshIteratorPtr getDependsOnIterator(const bool includeSelf,
85 const bool complexShapeFirst);
87 const TopoDS_Shape & GetSubShape() const;
91 NOT_READY, READY_TO_COMPUTE,
92 COMPUTE_OK, FAILED_TO_COMPUTE
96 NO_ALGO, MISSING_HYP, HYP_OK
101 REMOVE_HYP , REMOVE_ALGO,
102 ADD_FATHER_HYP , ADD_FATHER_ALGO,
103 REMOVE_FATHER_HYP, REMOVE_FATHER_ALGO,
108 MODIF_ALGO_STATE, COMPUTE,
109 #ifdef WITH_SMESH_CANCEL_COMPUTE
112 CLEAN, SUBMESH_COMPUTED, SUBMESH_RESTORED,
113 MESH_ENTITY_REMOVED, CHECK_COMPUTE_STATE
117 ALGO_EVENT, COMPUTE_EVENT
120 // ==================================================================
121 // Members to track non hierarchical dependencies between submeshes
122 // ==================================================================
125 * \brief Sets an event listener and its data to a submesh
126 * \param listener - the listener to store
127 * \param data - the listener data to store
128 * \param where - the submesh to store the listener and it's data
130 * The method remembers the submesh \awhere it puts the listener in order to delete
131 * it when HYP_OK algo_state is lost
132 * After being set, event listener is notified on each event of \awhere submesh.
134 void SetEventListener(EventListener* listener,
135 EventListenerData* data,
136 SMESH_subMesh* where);
139 * \brief Return an event listener data
140 * \param listener - the listener whose data is
141 * \retval EventListenerData* - found data, maybe NULL
143 EventListenerData* GetEventListenerData(EventListener* listener) const;
146 * \brief Unregister the listener and delete it and it's data
147 * \param listener - the event listener to delete
149 void DeleteEventListener(EventListener* listener);
153 //!< event listeners to notify
154 std::map< EventListener*, EventListenerData* > myEventListeners;
155 //!< event listeners to delete when HYP_OK algo_state is lost
156 struct OwnListenerData {
157 SMESH_subMesh* mySubMesh;
158 int myMeshID; // id of mySubMesh->GetFather()
160 EventListener* myListener;
161 OwnListenerData( SMESH_subMesh* sm=0, EventListener* el=0);
163 std::list< OwnListenerData > myOwnListeners;
166 * \brief Sets an event listener and its data to a submesh
167 * \param listener - the listener to store
168 * \param data - the listener data to store
170 * After being set, event listener is notified on each event of a submesh.
172 void SetEventListener(EventListener* listener, EventListenerData* data);
175 * \brief Notify stored event listeners on the occured event
176 * \param event - algo_event or compute_event itself
177 * \param eventType - algo_event or compute_event
178 * \param hyp - hypothesis, if eventType is algo_event
180 void NotifyListenersOnEvent( const int event,
181 const event_type eventType,
182 SMESH_Hypothesis* hyp = 0);
185 * \brief Delete event listeners depending on algo of this submesh
187 void DeleteOwnListeners();
189 // ==================================================================
193 SMESH_Hypothesis::Hypothesis_Status
194 AlgoStateEngine(int event, SMESH_Hypothesis * anHyp);
196 SMESH_Hypothesis::Hypothesis_Status
197 SubMeshesAlgoStateEngine(int event, SMESH_Hypothesis * anHyp);
199 int GetAlgoState() const { return _algoState; }
200 int GetComputeState() const { return _computeState; };
201 SMESH_ComputeErrorPtr& GetComputeError() { return _computeError; }
203 void DumpAlgoState(bool isMain);
205 bool ComputeStateEngine(int event);
206 void ComputeSubMeshStateEngine(int event);
208 bool Evaluate(MapShapeNbElems& aResMap);
210 bool IsConform(const SMESH_Algo* theAlgo);
211 // check if a conform mesh will be produced by the Algo
213 bool CanAddHypothesis(const SMESH_Hypothesis* theHypothesis) const;
214 // return true if theHypothesis can be attached to me:
215 // its dimention is checked
217 static bool IsApplicableHypotesis(const SMESH_Hypothesis* theHypothesis,
218 const TopAbs_ShapeEnum theShapeType);
220 bool IsApplicableHypotesis(const SMESH_Hypothesis* theHypothesis) const
221 { return IsApplicableHypotesis( theHypothesis, _subShape.ShapeType() ); }
222 // return true if theHypothesis can be used to mesh me:
223 // its shape type is checked
225 SMESH_Hypothesis::Hypothesis_Status CheckConcurentHypothesis (const int theHypType);
226 // check if there are several applicable hypothesis on fathers
229 * \brief Return true if no mesh entities is bound to the submesh
231 bool IsEmpty() const;
233 bool IsMeshComputed() const;
234 // check if _subMeshDS contains mesh elements
237 * \brief Allow algo->Compute() if a subshape of lower dim is meshed but
238 * none mesh entity is bound to it
240 void SetIsAlwaysComputed(bool isAlCo);
241 bool IsAlwaysComputed() { return _alwaysComputed; }
245 * \brief Find common submeshes (based on shared subshapes with other
246 * \param theOther submesh to check
247 * \param theCommonIds set of common submesh IDs
248 * NOTE: this method does not cleat set before collect common IDs
250 bool FindIntersection( const SMESH_subMesh * theOther,
251 std::set<const SMESH_subMesh*>& theSetOfCommon ) const;
254 // ==================================================================
255 void InsertDependence(const TopoDS_Shape aSubShape);
257 bool SubMeshesComputed();
259 bool SubMeshesReady();
261 void RemoveSubMeshElementsAndNodes();
262 void UpdateDependantsState(const compute_event theEvent);
263 void UpdateSubMeshState(const compute_state theState);
264 void CleanDependants();
265 void CleanDependsOn();
266 void SetAlgoState(int state);
269 * \brief Return a shape containing all sub-shapes of the MainShape that can be
270 * meshed at once along with _subShape
272 TopoDS_Shape GetCollection(SMESH_Gen * theGen,
274 bool & theSubComputed);
277 * \brief Update compute_state by _computeError
278 * \retval bool - false if there are errors
280 bool CheckComputeError(SMESH_Algo* theAlgo, const TopoDS_Shape& theShape=TopoDS_Shape());
283 * \brief Return a hypothesis attached to theShape.
285 * If theHyp is provided, similar but not same hypotheses
286 * is returned; else an applicable ones having theHypType
289 const SMESH_Hypothesis* GetSimilarAttached(const TopoDS_Shape& theShape,
290 const SMESH_Hypothesis * theHyp,
291 const int theHypType = 0);
296 TopoDS_Shape _subShape;
297 SMESHDS_SubMesh * _subMeshDS;
298 SMESH_Mesh * _father;
301 std::map < int, SMESH_subMesh * >_mapDepend;
302 bool _dependenceAnalysed;
306 SMESH_ComputeErrorPtr _computeError;
308 // allow algo->Compute() if a subshape of lower dim is meshed but
309 // none mesh entity is bound to it. Eg StdMeshers_CompositeSegment_1D can
310 // mesh several edges as a whole and leave some of them without mesh entities
311 bool _alwaysComputed;