| 1 |
// Copyright (C) 2007-2015 CEA/DEN, EDF R&D, 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 : [email protected] |
| 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 "SMESHDS_Mesh.hxx" |
| 33 |
#include "SMESHDS_SubMesh.hxx" |
| 34 |
#include "SMESH_Hypothesis.hxx" |
| 35 |
#include "SMESH_ComputeError.hxx" |
| 36 |
#include "SMESH_Algo.hxx" |
| 37 |
|
| 38 |
#include "Utils_SALOME_Exception.hxx" |
| 39 |
|
| 40 |
#include <TopoDS_Shape.hxx> |
| 41 |
|
| 42 |
#include <list> |
| 43 |
#include <map> |
| 44 |
|
| 45 |
class SMESH_Mesh; |
| 46 |
class SMESH_Hypothesis; |
| 47 |
class SMESH_Algo; |
| 48 |
class SMESH_Gen; |
| 49 |
class SMESH_subMeshEventListener; |
| 50 |
struct SMESH_subMeshEventListenerData; |
| 51 |
class SMESH_subMesh; |
| 52 |
|
| 53 |
typedef SMESH_subMeshEventListener EventListener; |
| 54 |
typedef SMESH_subMeshEventListenerData EventListenerData; |
| 55 |
|
| 56 |
typedef boost::shared_ptr< SMDS_Iterator<SMESH_subMesh*> > SMESH_subMeshIteratorPtr; |
| 57 |
|
| 58 |
|
| 59 |
class SMESH_EXPORT SMESH_subMesh |
| 60 |
{ |
| 61 |
public: |
| 62 |
SMESH_subMesh(int Id, |
| 63 |
SMESH_Mesh * father, |
| 64 |
SMESHDS_Mesh * meshDS, |
| 65 |
const TopoDS_Shape & aSubShape); |
| 66 |
virtual ~ SMESH_subMesh(); |
| 67 |
|
| 68 |
int GetId() const; // == meshDS->ShapeToIndex( aSubShape ) |
| 69 |
|
| 70 |
SMESH_Mesh* GetFather() { return _father; } |
| 71 |
|
| 72 |
SMESHDS_SubMesh * GetSubMeshDS(); |
| 73 |
const SMESHDS_SubMesh * GetSubMeshDS() const; |
| 74 |
|
| 75 |
SMESHDS_SubMesh* CreateSubMeshDS(); |
| 76 |
// Explicit SMESHDS_SubMesh creation method, required for persistence mechanism |
| 77 |
|
| 78 |
SMESH_subMesh *GetFirstToCompute(); |
| 79 |
|
| 80 |
SMESH_Algo* GetAlgo() const; |
| 81 |
|
| 82 |
const std::map < int, SMESH_subMesh * >& DependsOn(); |
| 83 |
bool DependsOn( const SMESH_subMesh* other ) const; |
| 84 |
/*! |
| 85 |
* \brief Return iterator on the sub-meshes this one depends on. By default |
| 86 |
* most simple sub-meshes go first. |
| 87 |
*/ |
| 88 |
SMESH_subMeshIteratorPtr getDependsOnIterator(const bool includeSelf, |
| 89 |
const bool complexShapeFirst=false) const; |
| 90 |
|
| 91 |
const std::vector< SMESH_subMesh * > & GetAncestors() const; |
| 92 |
void ClearAncestors(); |
| 93 |
|
| 94 |
const TopoDS_Shape & GetSubShape() const; |
| 95 |
|
| 96 |
enum compute_state |
| 97 |
{ |
| 98 |
NOT_READY, READY_TO_COMPUTE, |
| 99 |
COMPUTE_OK, FAILED_TO_COMPUTE |
| 100 |
}; |
| 101 |
enum algo_state |
| 102 |
{ |
| 103 |
NO_ALGO, MISSING_HYP, HYP_OK |
| 104 |
}; |
| 105 |
enum algo_event |
| 106 |
{ |
| 107 |
ADD_HYP , ADD_ALGO, |
| 108 |
REMOVE_HYP , REMOVE_ALGO, |
| 109 |
ADD_FATHER_HYP , ADD_FATHER_ALGO, |
| 110 |
REMOVE_FATHER_HYP, REMOVE_FATHER_ALGO, |
| 111 |
MODIF_HYP |
| 112 |
}; |
| 113 |
enum compute_event |
| 114 |
{ |
| 115 |
MODIF_ALGO_STATE, COMPUTE, COMPUTE_SUBMESH, COMPUTE_CANCELED, |
| 116 |
CLEAN, SUBMESH_COMPUTED, SUBMESH_RESTORED, SUBMESH_LOADED, |
| 117 |
MESH_ENTITY_REMOVED, CHECK_COMPUTE_STATE |
| 118 |
}; |
| 119 |
enum event_type |
| 120 |
{ |
| 121 |
ALGO_EVENT, COMPUTE_EVENT |
| 122 |
}; |
| 123 |
|
| 124 |
// ================================================================== |
| 125 |
// Members to track non hierarchical dependencies between submeshes |
| 126 |
// ================================================================== |
| 127 |
|
| 128 |
/*! |
| 129 |
* \brief Sets an event listener and its data to a submesh |
| 130 |
* \param listener - the listener to store |
| 131 |
* \param data - the listener data to store |
| 132 |
* \param where - the submesh to store the listener and it's data |
| 133 |
* |
| 134 |
* The method remembers the submesh \awhere it puts the listener in order to delete |
| 135 |
* it when HYP_OK algo_state is lost |
| 136 |
* After being set, event listener is notified on each event of \awhere submesh. |
| 137 |
*/ |
| 138 |
void SetEventListener(EventListener* listener, |
| 139 |
EventListenerData* data, |
| 140 |
SMESH_subMesh* where); |
| 141 |
|
| 142 |
/*! |
| 143 |
* \brief Return an event listener data |
| 144 |
* \param listener - the listener whose data is |
| 145 |
* \param myOwn - if \c true, returns a listener set by this sub-mesh, |
| 146 |
* else returns a listener listening to events of this sub-mesh |
| 147 |
* \retval EventListenerData* - found data, maybe NULL |
| 148 |
*/ |
| 149 |
EventListenerData* GetEventListenerData(EventListener* listener, |
| 150 |
const bool myOwn=false) const; |
| 151 |
|
| 152 |
/*! |
| 153 |
* \brief Return an event listener data |
| 154 |
* \param listenerName - the listener name |
| 155 |
* \param myOwn - if \c true, returns a listener set by this sub-mesh, |
| 156 |
* else returns a listener listening to events of this sub-mesh |
| 157 |
* \retval EventListenerData* - found data, maybe NULL |
| 158 |
*/ |
| 159 |
EventListenerData* GetEventListenerData(const std::string& listenerName, |
| 160 |
const bool myOwn=false) const; |
| 161 |
|
| 162 |
/*! |
| 163 |
* \brief Unregister the listener and delete it and it's data |
| 164 |
* \param listener - the event listener to delete |
| 165 |
*/ |
| 166 |
void DeleteEventListener(EventListener* listener); |
| 167 |
|
| 168 |
protected: |
| 169 |
|
| 170 |
//!< event listeners to notify |
| 171 |
std::map< EventListener*, EventListenerData* > _eventListeners; |
| 172 |
|
| 173 |
//!< event listeners to delete when HYP_OK algo_state is lost |
| 174 |
struct OwnListenerData { |
| 175 |
SMESH_subMesh* mySubMesh; |
| 176 |
int myMeshID; // id of mySubMesh->GetFather() |
| 177 |
int mySubMeshID; |
| 178 |
EventListener* myListener; |
| 179 |
OwnListenerData( SMESH_subMesh* sm=0, EventListener* el=0); |
| 180 |
}; |
| 181 |
std::list< OwnListenerData > _ownListeners; |
| 182 |
|
| 183 |
/*! |
| 184 |
* \brief Sets an event listener and its data to a submesh |
| 185 |
* \param listener - the listener to store |
| 186 |
* \param data - the listener data to store |
| 187 |
* |
| 188 |
* After being set, event listener is notified on each event of a submesh. |
| 189 |
*/ |
| 190 |
void setEventListener(EventListener* listener, EventListenerData* data); |
| 191 |
|
| 192 |
/*! |
| 193 |
* \brief Notify stored event listeners on the occurred event |
| 194 |
* \param event - algo_event or compute_event itself |
| 195 |
* \param eventType - algo_event or compute_event |
| 196 |
* \param hyp - hypothesis, if eventType is algo_event |
| 197 |
*/ |
| 198 |
void notifyListenersOnEvent( const int event, |
| 199 |
const event_type eventType, |
| 200 |
SMESH_Hypothesis* hyp = 0); |
| 201 |
|
| 202 |
/*! |
| 203 |
* \brief Delete event listeners depending on algo of this submesh |
| 204 |
*/ |
| 205 |
void deleteOwnListeners(); |
| 206 |
|
| 207 |
/*! |
| 208 |
* \brief loads dependent meshes on SUBMESH_LOADED event |
| 209 |
*/ |
| 210 |
void loadDependentMeshes(); |
| 211 |
|
| 212 |
// END: Members to track non hierarchical dependencies between submeshes |
| 213 |
// ===================================================================== |
| 214 |
|
| 215 |
public: |
| 216 |
|
| 217 |
SMESH_Hypothesis::Hypothesis_Status |
| 218 |
AlgoStateEngine(int event, SMESH_Hypothesis * anHyp); |
| 219 |
|
| 220 |
SMESH_Hypothesis::Hypothesis_Status |
| 221 |
SubMeshesAlgoStateEngine(int event, SMESH_Hypothesis * anHyp, bool exitOnFatal=false); |
| 222 |
|
| 223 |
algo_state GetAlgoState() const { return _algoState; } |
| 224 |
compute_state GetComputeState() const { return _computeState; } |
| 225 |
SMESH_ComputeErrorPtr& GetComputeError() { return _computeError; } |
| 226 |
|
| 227 |
void DumpAlgoState(bool isMain); |
| 228 |
|
| 229 |
bool ComputeStateEngine(int event); |
| 230 |
void ComputeSubMeshStateEngine(int event, const bool includeSelf=false); |
| 231 |
|
| 232 |
bool Evaluate(MapShapeNbElems& aResMap); |
| 233 |
|
| 234 |
bool IsConform(const SMESH_Algo* theAlgo); |
| 235 |
// check if a conform mesh will be produced by the Algo |
| 236 |
|
| 237 |
bool CanAddHypothesis(const SMESH_Hypothesis* theHypothesis) const; |
| 238 |
// return true if theHypothesis can be attached to me: |
| 239 |
// its dimension is checked |
| 240 |
|
| 241 |
static bool IsApplicableHypotesis(const SMESH_Hypothesis* theHypothesis, |
| 242 |
const TopAbs_ShapeEnum theShapeType); |
| 243 |
|
| 244 |
bool IsApplicableHypotesis(const SMESH_Hypothesis* theHypothesis) const |
| 245 |
{ return IsApplicableHypotesis( theHypothesis, _subShape.ShapeType() ); } |
| 246 |
// return true if theHypothesis can be used to mesh me: |
| 247 |
// its shape type is checked |
| 248 |
|
| 249 |
SMESH_Hypothesis::Hypothesis_Status CheckConcurentHypothesis (const int theHypType); |
| 250 |
// check if there are several applicable hypothesis on fathers |
| 251 |
|
| 252 |
/*! |
| 253 |
* \brief Return true if no mesh entities is bound to the submesh |
| 254 |
*/ |
| 255 |
bool IsEmpty() const; |
| 256 |
|
| 257 |
bool IsMeshComputed() const; |
| 258 |
// check if _subMeshDS contains mesh elements unless _alwaysComputed==true |
| 259 |
|
| 260 |
/*! |
| 261 |
* \brief Allow algo->Compute() if a subshape of lower dim is meshed but |
| 262 |
* none mesh entity is bound to it |
| 263 |
*/ |
| 264 |
void SetIsAlwaysComputed(bool isAlCo); |
| 265 |
bool IsAlwaysComputed() { return _alwaysComputed; } |
| 266 |
|
| 267 |
bool SubMeshesComputed(bool * isFailedToCompute=0) const; |
| 268 |
|
| 269 |
int GetComputeCost() const; |
| 270 |
// how costly is to compute this sub-mesh |
| 271 |
|
| 272 |
/*! |
| 273 |
* \brief Find common submeshes (based on shared subshapes with other |
| 274 |
* \param theOther submesh to check |
| 275 |
* \param theCommonIds set of common submesh IDs |
| 276 |
* NOTE: this method does not cleat set before collect common IDs |
| 277 |
*/ |
| 278 |
bool FindIntersection( const SMESH_subMesh * theOther, |
| 279 |
std::set<const SMESH_subMesh*>& theSetOfCommon ) const; |
| 280 |
|
| 281 |
protected: |
| 282 |
// ================================================================== |
| 283 |
void insertDependence(const TopoDS_Shape aShape, TopAbs_ShapeEnum aSubType ); |
| 284 |
|
| 285 |
void removeSubMeshElementsAndNodes(); |
| 286 |
void updateDependantsState(const compute_event theEvent); |
| 287 |
void updateSubMeshState(const compute_state theState); |
| 288 |
void cleanDependants(); |
| 289 |
void cleanDependsOn( SMESH_Algo* algoRequiringCleaning=0 ); |
| 290 |
void setAlgoState(algo_state state); |
| 291 |
|
| 292 |
/*! |
| 293 |
* \brief Return a shape containing all sub-shapes of the MainShape that can be |
| 294 |
* meshed at once along with _subShape |
| 295 |
*/ |
| 296 |
TopoDS_Shape getCollection(SMESH_Gen * theGen, |
| 297 |
SMESH_Algo* theAlgo, |
| 298 |
bool & theSubComputed, |
| 299 |
bool & theSubFailed, |
| 300 |
std::vector<SMESH_subMesh*>& theSubs); |
| 301 |
/*! |
| 302 |
* \brief Update compute_state by _computeError |
| 303 |
* \retval bool - false if there are errors |
| 304 |
*/ |
| 305 |
bool checkComputeError(SMESH_Algo* theAlgo, |
| 306 |
const bool theComputeOK, |
| 307 |
const TopoDS_Shape& theShape=TopoDS_Shape()); |
| 308 |
|
| 309 |
/*! |
| 310 |
* \brief Return a hypothesis attached to theShape. |
| 311 |
* |
| 312 |
* If theHyp is provided, similar but not same hypotheses |
| 313 |
* is returned; else an applicable ones having theHypType |
| 314 |
* is returned |
| 315 |
*/ |
| 316 |
const SMESH_Hypothesis* getSimilarAttached(const TopoDS_Shape& theShape, |
| 317 |
const SMESH_Hypothesis * theHyp, |
| 318 |
const int theHypType = 0); |
| 319 |
// |
| 320 |
int computeCost() const; |
| 321 |
|
| 322 |
protected: |
| 323 |
|
| 324 |
TopoDS_Shape _subShape; |
| 325 |
SMESHDS_SubMesh * _subMeshDS; |
| 326 |
SMESH_Mesh * _father; |
| 327 |
int _Id; |
| 328 |
|
| 329 |
std::map < int, SMESH_subMesh * >_mapDepend; |
| 330 |
bool _dependenceAnalysed; |
| 331 |
std::vector< SMESH_subMesh * > _ancestors; |
| 332 |
|
| 333 |
SMESH_Algo * _algo; // the algorithm found by last *StateEngine() call |
| 334 |
algo_state _algoState; |
| 335 |
compute_state _computeState; |
| 336 |
SMESH_ComputeErrorPtr _computeError; |
| 337 |
int _computeCost; // how costly is to compute this sub-mesh |
| 338 |
int _realComputeCost; // _computeCost depending on presence of needed hypotheses |
| 339 |
|
| 340 |
// allow algo->Compute() if a sub-shape of lower dim is meshed but |
| 341 |
// none mesh entity is bound to it. Eg StdMeshers_CompositeSegment_1D can |
| 342 |
// mesh several edges as a whole and leave some of them without mesh entities |
| 343 |
bool _alwaysComputed; |
| 344 |
|
| 345 |
}; |
| 346 |
|
| 347 |
#endif |