1 // SMESH SMESH : implementaion of SMESH idl descriptions
3 // Copyright (C) 2003 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
24 // File : SMESH_subMesh.hxx
25 // Author : Paul RASCLE, EDF
29 #ifndef _SMESH_SUBMESH_HXX_
30 #define _SMESH_SUBMESH_HXX_
32 #include "SMESH_SMESH.hxx"
34 #include "SMESHDS_Mesh.hxx"
35 #include "SMESHDS_SubMesh.hxx"
36 #include "SMESH_Hypothesis.hxx"
37 #include "Utils_SALOME_Exception.hxx"
38 #include <TopoDS_Shape.hxx>
39 #include <TColStd_IndexedMapOfTransient.hxx>
40 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
47 class SMESH_Hypothesis;
50 class SMESH_subMeshEventListener;
51 class SMESH_subMeshEventListenerData;
53 typedef SMESH_subMeshEventListener EventListener;
54 typedef SMESH_subMeshEventListenerData EventListenerData;
56 class SMESH_EXPORT SMESH_subMesh
59 SMESH_subMesh(int Id, SMESH_Mesh * father, SMESHDS_Mesh * meshDS,
60 const TopoDS_Shape & aSubShape);
61 virtual ~ SMESH_subMesh();
65 // bool Contains(const TopoDS_Shape & aSubShape)
66 // throw (SALOME_Exception);
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 const map < int, SMESH_subMesh * >&DependsOn();
78 //const map < int, SMESH_subMesh * >&Dependants();
80 const TopoDS_Shape & GetSubShape() const;
84 NOT_READY, READY_TO_COMPUTE,
85 COMPUTE_OK, FAILED_TO_COMPUTE
89 NO_ALGO, MISSING_HYP, HYP_OK
94 REMOVE_HYP, REMOVE_ALGO,
95 ADD_FATHER_HYP, ADD_FATHER_ALGO,
96 REMOVE_FATHER_HYP, REMOVE_FATHER_ALGO
100 MODIF_HYP, MODIF_ALGO_STATE, COMPUTE,
101 CLEAN, SUBMESH_COMPUTED, SUBMESH_RESTORED,
102 MESH_ENTITY_REMOVED, CHECK_COMPUTE_STATE
106 ALGO_EVENT, COMPUTE_EVENT
109 // ==================================================================
110 // Members to track non hierarchical dependencies between submeshes
111 // ==================================================================
114 * \brief Sets an event listener and its data to a submesh
115 * \param listener - the listener to store
116 * \param data - the listener data to store
117 * \param where - the submesh to store the listener and it's data
118 * \param deleteListener - if true then the listener will be deleted as
119 * it is removed from where submesh
121 * It remembers the submesh where it puts the listener in order to delete
122 * them when HYP_OK algo_state is lost
123 * After being set, event listener is notified on each event of where submesh.
125 void SetEventListener(EventListener* listener,
126 EventListenerData* data,
127 SMESH_subMesh* where);
130 * \brief Return an event listener data
131 * \param listener - the listener whose data is
132 * \retval EventListenerData* - found data, maybe NULL
134 EventListenerData* GetEventListenerData(EventListener* listener) const;
137 * \brief Unregister the listener and delete it and it's data
138 * \param listener - the event listener to delete
140 void DeleteEventListener(EventListener* listener);
144 //!< event listeners to notify
145 std::map< EventListener*, EventListenerData* > myEventListeners;
146 //!< event listeners to delete when HYP_OK algo_state is lost
147 std::list< std::pair< SMESH_subMesh*, EventListener* > > myOwnListeners;
150 * \brief Sets an event listener and its data to a submesh
151 * \param listener - the listener to store
152 * \param data - the listener data to store
154 * After being set, event listener is notified on each event of a submesh.
156 void SetEventListener(EventListener* listener, EventListenerData* data);
159 * \brief Notify stored event listeners on the occured event
160 * \param event - algo_event or compute_event itself
161 * \param eventType - algo_event or compute_event
162 * \param hyp - hypothesis, if eventType is algo_event
164 void NotifyListenersOnEvent( const int event,
165 const event_type eventType,
166 SMESH_Hypothesis* hyp = 0);
169 * \brief Delete event listeners depending on algo of this submesh
171 void DeleteOwnListeners();
173 // ==================================================================
177 SMESH_Hypothesis::Hypothesis_Status
178 AlgoStateEngine(int event, SMESH_Hypothesis * anHyp);
180 SMESH_Hypothesis::Hypothesis_Status
181 SubMeshesAlgoStateEngine(int event, SMESH_Hypothesis * anHyp);
183 int GetAlgoState() const { return _algoState; }
184 int GetComputeState() const { return _computeState; };
186 void DumpAlgoState(bool isMain);
188 bool ComputeStateEngine(int event);
190 bool IsConform(const SMESH_Algo* theAlgo);
191 // check if a conform mesh will be produced by the Algo
193 bool CanAddHypothesis(const SMESH_Hypothesis* theHypothesis) const;
194 // return true if theHypothesis can be attached to me:
195 // its dimention is checked
197 static bool IsApplicableHypotesis(const SMESH_Hypothesis* theHypothesis,
198 const TopAbs_ShapeEnum theShapeType);
200 bool IsApplicableHypotesis(const SMESH_Hypothesis* theHypothesis) const
201 { return IsApplicableHypotesis( theHypothesis, _subShape.ShapeType() ); }
202 // return true if theHypothesis can be used to mesh me:
203 // its shape type is checked
205 SMESH_Hypothesis::Hypothesis_Status CheckConcurentHypothesis (const int theHypType);
206 // check if there are several applicable hypothesis on fathers
208 bool IsMeshComputed() const;
209 // check if _subMeshDS contains mesh elements
212 // ==================================================================
213 void InsertDependence(const TopoDS_Shape aSubShape);
215 bool SubMeshesComputed();
217 bool SubMeshesReady();
219 void RemoveSubMeshElementsAndNodes();
220 void UpdateDependantsState(const compute_event theEvent);
221 void UpdateSubMeshState(const compute_state theState);
222 void ComputeSubMeshStateEngine(int event);
223 void CleanDependants();
224 void CleanDependsOn();
225 void SetAlgoState(int state);
227 TopoDS_Shape GetCollection(SMESH_Gen * theGen, SMESH_Algo* theAlgo);
228 // return a shape containing all sub-shapes of the MainShape that can be
229 // meshed at once along with _subShape
231 bool ApplyToCollection (SMESH_Algo* theAlgo,
232 const TopoDS_Shape& theCollection);
233 // Apply theAlgo to all subshapes in theCollection
235 const SMESH_Hypothesis* GetSimilarAttached(const TopoDS_Shape& theShape,
236 const SMESH_Hypothesis * theHyp,
237 const int theHypType = 0);
238 // return a hypothesis attached to theShape.
239 // If theHyp is provided, similar but not same hypotheses
240 // is returned; else an applicable ones having theHypType
243 TopoDS_Shape _subShape;
244 SMESHDS_Mesh * _meshDS;
245 SMESHDS_SubMesh * _subMeshDS;
248 map < int, SMESH_subMesh * >_mapDepend;
249 bool _dependenceAnalysed;