Back to index

salome-smesh  6.5.0
SMESH_Gen.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 //  SMESH SMESH : implementaion of SMESH idl descriptions
00024 //  File   : SMESH_Gen.hxx
00025 //  Author : Paul RASCLE, EDF
00026 //  Module : SMESH
00027 //
00028 #ifndef _SMESH_GEN_HXX_
00029 #define _SMESH_GEN_HXX_
00030 
00031 #include "SMESH_SMESH.hxx"
00032 
00033 #include "Utils_SALOME_Exception.hxx"
00034 
00035 #include "SMESH_Hypothesis.hxx"
00036 #include "SMESH_ComputeError.hxx"
00037 #include "SMESH_Algo.hxx"
00038 #include "SMESH_0D_Algo.hxx"
00039 #include "SMESH_1D_Algo.hxx"
00040 #include "SMESH_2D_Algo.hxx"
00041 #include "SMESH_3D_Algo.hxx"
00042 #include "SMESH_Mesh.hxx"
00043 
00044 #include "chrono.hxx"
00045 
00046 #include <TopoDS_Shape.hxx>
00047 
00048 #include <map>
00049 #include <list>
00050 
00051 class SMESHDS_Document;
00052 
00053 typedef SMESH_Hypothesis::Hypothesis_Status TAlgoStateErrorName;
00054 
00055 typedef struct studyContextStruct
00056 {
00057   std::map < int, SMESH_Hypothesis * >mapHypothesis;
00058   std::map < int, SMESH_Mesh * >mapMesh;
00059   SMESHDS_Document * myDocument;
00060 } StudyContextStruct;
00061 
00062 typedef std::set<int> TSetOfInt;
00063 
00064 class SMESH_EXPORT  SMESH_Gen
00065 {
00066 public:
00067   SMESH_Gen();
00068   ~SMESH_Gen();
00069 
00070   SMESH_Mesh* CreateMesh(int theStudyId, bool theIsEmbeddedMode)
00071     throw(SALOME_Exception);
00072 
00080   bool Compute(::SMESH_Mesh &        aMesh,
00081                const TopoDS_Shape &  aShape,
00082                const bool            anUpward=false,
00083                const ::MeshDimension aDim=::MeshDim_3D,
00084                TSetOfInt*            aShapesId=0);
00085 
00086 #ifdef WITH_SMESH_CANCEL_COMPUTE
00087   void PrepareCompute(::SMESH_Mesh &        aMesh,
00088                       const TopoDS_Shape &  aShape);
00089   void CancelCompute(::SMESH_Mesh &        aMesh,
00090                      const TopoDS_Shape &  aShape);
00091 #endif
00092 
00100   bool Evaluate(::SMESH_Mesh &        aMesh,
00101                 const TopoDS_Shape &  aShape,
00102                 MapShapeNbElems&      aResMap,
00103                 const bool            anUpward=false,
00104                 TSetOfInt*            aShapesId=0);
00105 
00106   bool CheckAlgoState(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape);
00107   // notify on bad state of attached algos, return false
00108   // if Compute() would fail because of some algo bad state
00109 
00114   void SetBoundaryBoxSegmentation( int theNbSegments ) { _segmentation = theNbSegments; }
00115   int  GetBoundaryBoxSegmentation() const { return _segmentation; }
00119   void SetDefaultNbSegments(int nb) { _nbSegments = nb; }
00120   int GetDefaultNbSegments() const { return _nbSegments; }
00121 
00122   struct TAlgoStateError
00123   {
00124     TAlgoStateErrorName _name;
00125     const SMESH_Algo*   _algo;
00126     int                 _algoDim;
00127     bool                _isGlobalAlgo;
00128 
00129     TAlgoStateError(): _algoDim(0),_algo(0),_name(SMESH_Hypothesis::HYP_OK) {}
00130     void Set(TAlgoStateErrorName name, const SMESH_Algo* algo, bool isGlobal)
00131     { _name = name; _algo = algo; _algoDim = algo->GetDim(); _isGlobalAlgo = isGlobal; }
00132     void Set(TAlgoStateErrorName name, const int algoDim,      bool isGlobal)
00133     { _name = name; _algo = 0;    _algoDim = algoDim;        _isGlobalAlgo = isGlobal; }
00134   };
00135 
00136   bool GetAlgoState(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape,
00137                     std::list< SMESH_Gen::TAlgoStateError > & theErrors);
00138   // notify on bad state of attached algos, return false
00139   // if Compute() would fail because of some algo bad state
00140   // theErrors list contains problems description
00141 
00142   StudyContextStruct *GetStudyContext(int studyId);
00143 
00144   static int GetShapeDim(const TopAbs_ShapeEnum & aShapeType);
00145   static int GetShapeDim(const TopoDS_Shape & aShape)
00146   { return GetShapeDim( aShape.ShapeType() ); }
00147   SMESH_Algo* GetAlgo(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape, TopoDS_Shape* assignedTo=0);
00148   static bool IsGlobalHypothesis(const SMESH_Hypothesis* theHyp, SMESH_Mesh& aMesh);
00149 
00150   int GetANewId();
00151 
00152   std::map < int, SMESH_Algo * >_mapAlgo;
00153   std::map < int, SMESH_0D_Algo * >_map0D_Algo;
00154   std::map < int, SMESH_1D_Algo * >_map1D_Algo;
00155   std::map < int, SMESH_2D_Algo * >_map2D_Algo;
00156   std::map < int, SMESH_3D_Algo * >_map3D_Algo;
00157 
00158 private:
00159 
00160   int _localId;                         // unique Id of created objects, within SMESH_Gen entity
00161   std::map < int, StudyContextStruct * >_mapStudyContext;
00162 
00163   // hypotheses managing
00164   int _hypId;
00165 
00166   // number of segments per diagonal of boundary box of geometry by which
00167   // default segment length of appropriate 1D hypotheses is defined
00168   int _segmentation;
00169   // default of segments
00170   int _nbSegments;
00171   counters *_counters;
00172 
00173 #ifdef WITH_SMESH_CANCEL_COMPUTE
00174   volatile bool _compute_canceled;
00175   SMESH_subMesh* _sm_current;
00176 #endif
00177 };
00178 
00179 #endif