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 "SMESHDS_Mesh.hxx"
33 #include "SMESHDS_SubMesh.hxx"
34 #include "SMESH_Hypothesis.hxx"
35 #include "Utils_SALOME_Exception.hxx"
36 #include <TopoDS_Shape.hxx>
37 #include <TColStd_IndexedMapOfTransient.hxx>
38 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
45 class SMESH_Hypothesis;
48 class SMESH_subMeshEventListener;
49 class SMESH_subMeshEventListenerData;
51 typedef SMESH_subMeshEventListener EventListener;
52 typedef SMESH_subMeshEventListenerData EventListenerData;
57 SMESH_subMesh(int Id, SMESH_Mesh * father, SMESHDS_Mesh * meshDS,
58 const TopoDS_Shape & aSubShape);
59 virtual ~ SMESH_subMesh();
63 // bool Contains(const TopoDS_Shape & aSubShape)
64 // throw (SALOME_Exception);
66 SMESH_Mesh* GetFather() { return _father; }
68 SMESHDS_SubMesh * GetSubMeshDS();
70 SMESHDS_SubMesh* CreateSubMeshDS();
71 // Explicit SMESHDS_SubMesh creation method, required for persistence mechanism
73 SMESH_subMesh *GetFirstToCompute();
75 const map < int, SMESH_subMesh * >&DependsOn();
76 //const map < int, SMESH_subMesh * >&Dependants();
78 const TopoDS_Shape & GetSubShape() const;
82 NOT_READY, READY_TO_COMPUTE,
83 COMPUTE_OK, FAILED_TO_COMPUTE
87 NO_ALGO, MISSING_HYP, HYP_OK
92 REMOVE_HYP, REMOVE_ALGO,
93 ADD_FATHER_HYP, ADD_FATHER_ALGO,
94 REMOVE_FATHER_HYP, REMOVE_FATHER_ALGO
98 MODIF_HYP, MODIF_ALGO_STATE, COMPUTE,
99 CLEAN, SUBMESH_COMPUTED, SUBMESH_RESTORED,
100 MESH_ENTITY_REMOVED, CHECK_COMPUTE_STATE
104 ALGO_EVENT, COMPUTE_EVENT
107 // ==================================================================
108 // Members to track non hierarchical dependencies between submeshes
109 // ==================================================================
112 * \brief Sets an event listener and its data to a submesh
113 * \param listener - the listener to store
114 * \param data - the listener data to store
115 * \param where - the submesh to store the listener and it's data
116 * \param deleteListener - if true then the listener will be deleted as
117 * it is removed from where submesh
119 * It remembers the submesh where it puts the listener in order to delete
120 * them when HYP_OK algo_state is lost
121 * After being set, event listener is notified on each event of where submesh.
123 void SetEventListener(EventListener* listener,
124 EventListenerData* data,
125 SMESH_subMesh* where);
128 * \brief Return an event listener data
129 * \param listener - the listener whose data is
130 * \retval EventListenerData* - found data, maybe NULL
132 EventListenerData* GetEventListenerData(EventListener* listener) const;
135 * \brief Unregister the listener and delete it and it's data
136 * \param listener - the event listener to delete
138 void DeleteEventListener(EventListener* listener);
142 //!< event listeners to notify
143 std::map< EventListener*, EventListenerData* > myEventListeners;
144 //!< event listeners to delete when HYP_OK algo_state is lost
145 std::list< std::pair< SMESH_subMesh*, EventListener* > > myOwnListeners;
148 * \brief Sets an event listener and its data to a submesh
149 * \param listener - the listener to store
150 * \param data - the listener data to store
152 * After being set, event listener is notified on each event of a submesh.
154 void SetEventListener(EventListener* listener, EventListenerData* data);
157 * \brief Notify stored event listeners on the occured event
158 * \param event - algo_event or compute_event itself
159 * \param eventType - algo_event or compute_event
160 * \param hyp - hypothesis, if eventType is algo_event
162 void NotifyListenersOnEvent( const int event,
163 const event_type eventType,
164 SMESH_Hypothesis* hyp = 0);
167 * \brief Delete event listeners depending on algo of this submesh
169 void DeleteOwnListeners();
171 // ==================================================================
175 SMESH_Hypothesis::Hypothesis_Status
176 AlgoStateEngine(int event, SMESH_Hypothesis * anHyp);
178 SMESH_Hypothesis::Hypothesis_Status
179 SubMeshesAlgoStateEngine(int event, SMESH_Hypothesis * anHyp);
181 int GetAlgoState() const { return _algoState; }
182 int GetComputeState() const { return _computeState; };
184 void DumpAlgoState(bool isMain);
186 bool ComputeStateEngine(int event);
188 bool IsConform(const SMESH_Algo* theAlgo);
189 // check if a conform mesh will be produced by the Algo
191 bool CanAddHypothesis(const SMESH_Hypothesis* theHypothesis) const;
192 // return true if theHypothesis can be attached to me:
193 // its dimention is checked
195 static bool IsApplicableHypotesis(const SMESH_Hypothesis* theHypothesis,
196 const TopAbs_ShapeEnum theShapeType);
198 bool IsApplicableHypotesis(const SMESH_Hypothesis* theHypothesis) const
199 { return IsApplicableHypotesis( theHypothesis, _subShape.ShapeType() ); }
200 // return true if theHypothesis can be used to mesh me:
201 // its shape type is checked
203 SMESH_Hypothesis::Hypothesis_Status CheckConcurentHypothesis (const int theHypType);
204 // check if there are several applicable hypothesis on fathers
206 bool IsMeshComputed() const;
207 // check if _subMeshDS contains mesh elements
210 // ==================================================================
211 void InsertDependence(const TopoDS_Shape aSubShape);
213 bool SubMeshesComputed();
215 bool SubMeshesReady();
217 void RemoveSubMeshElementsAndNodes();
218 void UpdateDependantsState(const compute_event theEvent);
219 void UpdateSubMeshState(const compute_state theState);
220 void ComputeSubMeshStateEngine(int event);
221 void CleanDependants();
222 void CleanDependsOn();
223 void SetAlgoState(int state);
225 TopoDS_Shape GetCollection(SMESH_Gen * theGen, SMESH_Algo* theAlgo);
226 // return a shape containing all sub-shapes of the MainShape that can be
227 // meshed at once along with _subShape
229 bool ApplyToCollection (SMESH_Algo* theAlgo,
230 const TopoDS_Shape& theCollection);
231 // Apply theAlgo to all subshapes in theCollection
233 const SMESH_Hypothesis* GetSimilarAttached(const TopoDS_Shape& theShape,
234 const SMESH_Hypothesis * theHyp,
235 const int theHypType = 0);
236 // return a hypothesis attached to theShape.
237 // If theHyp is provided, similar but not same hypotheses
238 // is returned; else an applicable ones having theHypType
241 TopoDS_Shape _subShape;
242 SMESHDS_Mesh * _meshDS;
243 SMESHDS_SubMesh * _subMeshDS;
246 map < int, SMESH_subMesh * >_mapDepend;
247 bool _dependenceAnalysed;