Back to index

salome-smesh  6.5.0
SMESH_subMesh.hxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  File   : SMESH_subMesh.hxx
00024 //  Author : Paul RASCLE, EDF
00025 //  Module : SMESH
00026 //
00027 #ifndef _SMESH_SUBMESH_HXX_
00028 #define _SMESH_SUBMESH_HXX_
00029 
00030 #include "SMESH_SMESH.hxx"
00031 
00032 #include "SMESHDS_Mesh.hxx"
00033 #include "SMESHDS_SubMesh.hxx"
00034 #include "SMESH_Hypothesis.hxx"
00035 #include "SMESH_ComputeError.hxx"
00036 #include "SMESH_Algo.hxx"
00037 
00038 #include "Utils_SALOME_Exception.hxx"
00039 
00040 #include <TopoDS_Shape.hxx>
00041 
00042 #include <list>
00043 #include <map>
00044 
00045 class SMESH_Mesh;
00046 class SMESH_Hypothesis;
00047 class SMESH_Algo;
00048 class SMESH_Gen;
00049 class SMESH_subMeshEventListener;
00050 class SMESH_subMeshEventListenerData;
00051 class SMESH_subMesh;
00052 
00053 typedef SMESH_subMeshEventListener     EventListener;
00054 typedef SMESH_subMeshEventListenerData EventListenerData;
00055 
00056 typedef boost::shared_ptr< SMDS_Iterator<SMESH_subMesh*> > SMESH_subMeshIteratorPtr;
00057 
00058 
00059 class SMESH_EXPORT SMESH_subMesh
00060 {
00061  public:
00062   SMESH_subMesh(int Id, SMESH_Mesh * father, SMESHDS_Mesh * meshDS,
00063                 const TopoDS_Shape & aSubShape);
00064   virtual ~ SMESH_subMesh();
00065 
00066   int GetId() const;
00067 
00068   SMESH_Mesh* GetFather() { return _father; }
00069   
00070   SMESHDS_SubMesh * GetSubMeshDS();
00071 
00072   SMESHDS_SubMesh* CreateSubMeshDS();
00073   // Explicit SMESHDS_SubMesh creation method, required for persistence mechanism
00074 
00075   SMESH_subMesh *GetFirstToCompute();
00076 
00077   SMESH_Algo* GetAlgo() const;
00078 
00079   const std::map < int, SMESH_subMesh * >& DependsOn();
00080   //const map < int, SMESH_subMesh * >&Dependants();
00084   SMESH_subMeshIteratorPtr getDependsOnIterator(const bool includeSelf,
00085                                                 const bool complexShapeFirst);
00086 
00087   const TopoDS_Shape & GetSubShape() const;
00088 
00089   enum compute_state
00090   {
00091     NOT_READY, READY_TO_COMPUTE,
00092     COMPUTE_OK, FAILED_TO_COMPUTE
00093     };
00094   enum algo_state
00095   {
00096     NO_ALGO, MISSING_HYP, HYP_OK
00097     };
00098   enum algo_event
00099   {
00100     ADD_HYP          , ADD_ALGO,
00101     REMOVE_HYP       , REMOVE_ALGO,
00102     ADD_FATHER_HYP   , ADD_FATHER_ALGO,
00103     REMOVE_FATHER_HYP, REMOVE_FATHER_ALGO,
00104     MODIF_HYP
00105     };
00106   enum compute_event
00107   {
00108     MODIF_ALGO_STATE, COMPUTE,
00109 #ifdef WITH_SMESH_CANCEL_COMPUTE
00110     COMPUTE_CANCELED,
00111 #endif
00112     CLEAN, SUBMESH_COMPUTED, SUBMESH_RESTORED, SUBMESH_LOADED,
00113     MESH_ENTITY_REMOVED, CHECK_COMPUTE_STATE
00114     };
00115   enum event_type
00116   {
00117     ALGO_EVENT, COMPUTE_EVENT
00118   };
00119 
00120   // ==================================================================
00121   // Members to track non hierarchical dependencies between submeshes 
00122   // ==================================================================
00123 
00134   void SetEventListener(EventListener*     listener,
00135                         EventListenerData* data,
00136                         SMESH_subMesh*     where);
00137 
00143   EventListenerData* GetEventListenerData(EventListener* listener) const;
00144 
00149   void DeleteEventListener(EventListener* listener);
00150 
00151 protected:
00152 
00154   std::map< EventListener*, EventListenerData* > _eventListeners;
00155 
00157   struct OwnListenerData {
00158     SMESH_subMesh* mySubMesh;
00159     int            myMeshID; // id of mySubMesh->GetFather()
00160     int            mySubMeshID;
00161     EventListener* myListener;
00162     OwnListenerData( SMESH_subMesh* sm=0, EventListener* el=0);
00163   };
00164   std::list< OwnListenerData >                    _ownListeners;
00165 
00173   void setEventListener(EventListener* listener, EventListenerData* data);
00174 
00181   void notifyListenersOnEvent( const int         event,
00182                                const event_type  eventType,
00183                                SMESH_Hypothesis* hyp = 0);
00184 
00188   void deleteOwnListeners();
00189 
00193   void loadDependentMeshes();
00194 
00195   // END: Members to track non hierarchical dependencies between submeshes
00196   // =====================================================================
00197 
00198 public:
00199 
00200   SMESH_Hypothesis::Hypothesis_Status
00201     AlgoStateEngine(int event, SMESH_Hypothesis * anHyp);
00202 
00203   SMESH_Hypothesis::Hypothesis_Status
00204     SubMeshesAlgoStateEngine(int event, SMESH_Hypothesis * anHyp);
00205 
00206   int GetAlgoState() const { return _algoState; }
00207   int GetComputeState() const { return _computeState; };
00208   SMESH_ComputeErrorPtr& GetComputeError() { return _computeError; }
00209 
00210   void DumpAlgoState(bool isMain);
00211 
00212   bool ComputeStateEngine(int event);
00213   void ComputeSubMeshStateEngine(int event, const bool includeSelf=false);
00214 
00215   bool Evaluate(MapShapeNbElems& aResMap);
00216 
00217   bool IsConform(const SMESH_Algo* theAlgo);
00218   // check if a conform mesh will be produced by the Algo
00219 
00220   bool CanAddHypothesis(const SMESH_Hypothesis* theHypothesis) const;
00221   // return true if theHypothesis can be attached to me:
00222   // its dimention is checked
00223 
00224   static bool IsApplicableHypotesis(const SMESH_Hypothesis* theHypothesis,
00225                                     const TopAbs_ShapeEnum  theShapeType);
00226 
00227   bool IsApplicableHypotesis(const SMESH_Hypothesis* theHypothesis) const
00228   { return IsApplicableHypotesis( theHypothesis, _subShape.ShapeType() ); }
00229   // return true if theHypothesis can be used to mesh me:
00230   // its shape type is checked
00231   
00232   SMESH_Hypothesis::Hypothesis_Status CheckConcurentHypothesis (const int theHypType);
00233   // check if there are several applicable hypothesis on fathers
00234 
00238   bool IsEmpty() const;
00239 
00240   bool IsMeshComputed() const;
00241   // check if _subMeshDS contains mesh elements
00242 
00247   void SetIsAlwaysComputed(bool isAlCo);
00248   bool IsAlwaysComputed() { return _alwaysComputed; }
00249 
00250   
00257   bool FindIntersection( const SMESH_subMesh *           theOther,
00258                          std::set<const SMESH_subMesh*>& theSetOfCommon ) const;
00259 
00260 protected:
00261   // ==================================================================
00262   void insertDependence(const TopoDS_Shape aSubShape);
00263 
00264   bool subMeshesComputed();
00265   //bool SubMeshesReady();
00266 
00267   void removeSubMeshElementsAndNodes();
00268   void updateDependantsState(const compute_event theEvent);
00269   void updateSubMeshState(const compute_state theState);
00270   void cleanDependants();
00271   void cleanDependsOn();
00272   void setAlgoState(int state);
00273 
00278   TopoDS_Shape getCollection(SMESH_Gen * theGen,
00279                              SMESH_Algo* theAlgo,
00280                              bool &      theSubComputed);
00285   bool checkComputeError(SMESH_Algo* theAlgo, const TopoDS_Shape& theShape=TopoDS_Shape());
00286 
00294   const SMESH_Hypothesis* getSimilarAttached(const TopoDS_Shape&      theShape,
00295                                              const SMESH_Hypothesis * theHyp,
00296                                              const int                theHypType = 0);
00297   // 
00298 
00299 protected:
00300 
00301   TopoDS_Shape          _subShape;
00302   SMESHDS_SubMesh *     _subMeshDS;
00303   SMESH_Mesh *          _father;
00304   int                   _Id;
00305 
00306   std::map < int, SMESH_subMesh * >_mapDepend;
00307   bool                  _dependenceAnalysed;
00308 
00309   int                   _algoState;
00310   int                   _computeState;
00311   SMESH_ComputeErrorPtr _computeError;
00312 
00313   // allow algo->Compute() if a subshape of lower dim is meshed but
00314   // none mesh entity is bound to it. Eg StdMeshers_CompositeSegment_1D can
00315   // mesh several edges as a whole and leave some of them  without mesh entities
00316   bool                  _alwaysComputed;
00317 
00318 };
00319 
00320 #endif