SALOME - SMESH
SMESH_subMesh.hxx
Go to the documentation of this file.
00001 //  Copyright (C) 2007-2008  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 //  SMESH SMESH : implementaion of SMESH idl descriptions
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 struct 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   const std::map < int, SMESH_subMesh * >& DependsOn();
00078   //const map < int, SMESH_subMesh * >&Dependants();
00082   SMESH_subMeshIteratorPtr getDependsOnIterator(const bool includeSelf,
00083                                                 const bool complexShapeFirst);
00084 
00085   const TopoDS_Shape & GetSubShape() const;
00086 
00087   enum compute_state
00088   {
00089     NOT_READY, READY_TO_COMPUTE,
00090     COMPUTE_OK, FAILED_TO_COMPUTE
00091     };
00092   enum algo_state
00093   {
00094     NO_ALGO, MISSING_HYP, HYP_OK
00095     };
00096   enum algo_event
00097   {
00098     ADD_HYP          , ADD_ALGO,
00099     REMOVE_HYP       , REMOVE_ALGO,
00100     ADD_FATHER_HYP   , ADD_FATHER_ALGO,
00101     REMOVE_FATHER_HYP, REMOVE_FATHER_ALGO,
00102     MODIF_HYP
00103     };
00104   enum compute_event
00105   {
00106     MODIF_ALGO_STATE, COMPUTE,
00107     CLEAN, SUBMESH_COMPUTED, SUBMESH_RESTORED,
00108     MESH_ENTITY_REMOVED, CHECK_COMPUTE_STATE
00109     };
00110   enum event_type
00111   {
00112     ALGO_EVENT, COMPUTE_EVENT
00113   };
00114 
00115   // ==================================================================
00116   // Members to track non hierarchical dependencies between submeshes 
00117   // ==================================================================
00118 
00129   void SetEventListener(EventListener*     listener,
00130                         EventListenerData* data,
00131                         SMESH_subMesh*     where);
00132 
00138   EventListenerData* GetEventListenerData(EventListener* listener) const;
00139 
00144   void DeleteEventListener(EventListener* listener);
00145 
00146 protected:
00147 
00149   std::map< EventListener*, EventListenerData* >           myEventListeners;
00151   std::list< std::pair< SMESH_subMesh*, EventListener* > > myOwnListeners;
00152 
00160   void SetEventListener(EventListener* listener, EventListenerData* data);
00161 
00168   void NotifyListenersOnEvent( const int         event,
00169                                const event_type  eventType,
00170                                SMESH_Hypothesis* hyp = 0);
00171 
00175   void DeleteOwnListeners();
00176 
00177   // ==================================================================
00178 
00179 public:
00180 
00181   SMESH_Hypothesis::Hypothesis_Status
00182     AlgoStateEngine(int event, SMESH_Hypothesis * anHyp);
00183 
00184   SMESH_Hypothesis::Hypothesis_Status
00185     SubMeshesAlgoStateEngine(int event, SMESH_Hypothesis * anHyp);
00186 
00187   int GetAlgoState() const { return _algoState; }
00188   int GetComputeState() const { return _computeState; };
00189   SMESH_ComputeErrorPtr& GetComputeError() { return _computeError; }
00190 
00191   void DumpAlgoState(bool isMain);
00192 
00193   bool ComputeStateEngine(int event);
00194 
00195   bool Evaluate(MapShapeNbElems& aResMap);
00196 
00197   bool IsConform(const SMESH_Algo* theAlgo);
00198   // check if a conform mesh will be produced by the Algo
00199 
00200   bool CanAddHypothesis(const SMESH_Hypothesis* theHypothesis) const;
00201   // return true if theHypothesis can be attached to me:
00202   // its dimention is checked
00203 
00204   static bool IsApplicableHypotesis(const SMESH_Hypothesis* theHypothesis,
00205                                     const TopAbs_ShapeEnum  theShapeType);
00206 
00207   bool IsApplicableHypotesis(const SMESH_Hypothesis* theHypothesis) const
00208   { return IsApplicableHypotesis( theHypothesis, _subShape.ShapeType() ); }
00209   // return true if theHypothesis can be used to mesh me:
00210   // its shape type is checked
00211   
00212   SMESH_Hypothesis::Hypothesis_Status CheckConcurentHypothesis (const int theHypType);
00213   // check if there are several applicable hypothesis on fathers
00214 
00218   bool IsEmpty() const;
00219 
00220   bool IsMeshComputed() const;
00221   // check if _subMeshDS contains mesh elements
00222 
00227   void SetIsAlwaysComputed(bool isAlCo);
00228   bool IsAlwaysComputed() { return _alwaysComputed; }
00229 
00230 
00231 protected:
00232   // ==================================================================
00233   void InsertDependence(const TopoDS_Shape aSubShape);
00234 
00235   bool SubMeshesComputed();
00236 
00237   bool SubMeshesReady();
00238 
00239   void RemoveSubMeshElementsAndNodes();
00240   void UpdateDependantsState(const compute_event theEvent);
00241   void UpdateSubMeshState(const compute_state theState);
00242   void ComputeSubMeshStateEngine(int event);
00243   void CleanDependants();
00244   void CleanDependsOn();
00245   void SetAlgoState(int state);
00246 
00251   TopoDS_Shape GetCollection(SMESH_Gen * theGen,
00252                              SMESH_Algo* theAlgo,
00253                              bool &      theSubComputed);
00254 
00258   bool ApplyToCollection (SMESH_Algo*         theAlgo,
00259                           const TopoDS_Shape& theCollection);
00260 
00265   bool CheckComputeError(SMESH_Algo* theAlgo, const TopoDS_Shape& theShape=TopoDS_Shape());
00266 
00274   const SMESH_Hypothesis* GetSimilarAttached(const TopoDS_Shape&      theShape,
00275                                              const SMESH_Hypothesis * theHyp,
00276                                              const int                theHypType = 0);
00277   // 
00278 
00279 protected:
00280 
00281   TopoDS_Shape          _subShape;
00282   SMESHDS_SubMesh *     _subMeshDS;
00283   SMESH_Mesh *          _father;
00284   int                   _Id;
00285 
00286   std::map < int, SMESH_subMesh * >_mapDepend;
00287   bool                  _dependenceAnalysed;
00288 
00289   int                   _algoState;
00290   int                   _computeState;
00291   SMESH_ComputeErrorPtr _computeError;
00292 
00293   // allow algo->Compute() if a subshape of lower dim is meshed but
00294   // none mesh entity is bound to it. Eg StdMeshers_CompositeSegment_1D can
00295   // mesh several edges as a whole and leave some of them  without mesh entities
00296   bool                  _alwaysComputed;
00297 
00298 };
00299 
00300 #endif
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines