1 // Copyright (C) 2007-2022 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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, or (at your option) any later version.
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
23 // SMESH SMESH : implementation of SMESH idl descriptions
24 // File : SMESH_Gen.hxx
25 // Author : Paul RASCLE, EDF
28 #ifndef _SMESH_GEN_HXX_
29 #define _SMESH_GEN_HXX_
31 #include "SMESH_SMESH.hxx"
33 #include "Utils_SALOME_Exception.hxx"
35 #include "SMESH_Algo.hxx"
36 #include "SMESH_ComputeError.hxx"
37 #include "SMESH_subMesh.hxx"
46 #include <TopoDS_Shape.hxx>
47 #include <TopTools_IndexedMapOfShape.hxx>
49 class SMESHDS_Document;
55 typedef SMESH_Hypothesis::Hypothesis_Status TAlgoStateErrorName;
57 typedef struct studyContextStruct
59 std::map < int, SMESH_Hypothesis * >mapHypothesis;
60 std::map < int, SMESH_Mesh * >mapMesh;
61 SMESHDS_Document * myDocument;
64 typedef std::set<int> TSetOfInt;
66 class SMESH_EXPORT SMESH_Gen
72 SMESH_Mesh* CreateMesh(bool theIsEmbeddedMode);
76 SHAPE_ONLY = 1, // to ignore algo->OnlyUnaryInput() feature and to compute a given shape only.
77 UPWARD = 2, // to compute from vertices up to more complex shape (internal usage)
78 COMPACT_MESH = 4, // to compact the mesh at the end
79 SHAPE_ONLY_UPWARD = 3 // SHAPE_ONLY | UPWARD
82 * \brief Computes aMesh on aShape
83 * \param aMesh - the mesh.
84 * \param aShape - the shape.
85 * \param aFlags - ComputeFlags. By default compute the whole mesh and compact at the end.
86 * \param aDim - upper level dimension of the mesh computation (for preview)
87 * \param aShapesId - list of shapes with computed mesh entities (elements or nodes)
88 * \param anAllowedSubShapes - shapes to mesh only. Mesh all if empty or nullptr
89 * \retval bool - true if none sub-mesh failed to compute
91 bool Compute(::SMESH_Mesh & aMesh,
92 const TopoDS_Shape & aShape,
93 const int aFlags = COMPACT_MESH,
94 const ::MeshDimension aDim=::MeshDim_3D,
95 TSetOfInt* aShapesId=0,
96 TopTools_IndexedMapOfShape* anAllowedSubShapes=0);
98 void PrepareCompute(::SMESH_Mesh & aMesh,
99 const TopoDS_Shape & aShape);
100 void CancelCompute(::SMESH_Mesh & aMesh,
101 const TopoDS_Shape & aShape);
103 const SMESH_subMesh* GetCurrentSubMesh() const;
106 * \brief evaluates size of prospective mesh on a shape
107 * \param aMesh - the mesh
108 * \param aShape - the shape
109 * \param aResMap - map for prospective numbers of elements
110 * \retval bool - is a success
112 bool Evaluate(::SMESH_Mesh & aMesh,
113 const TopoDS_Shape & aShape,
114 MapShapeNbElems& aResMap,
115 const bool anUpward=false,
116 TSetOfInt* aShapesId=0);
118 bool CheckAlgoState(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape);
119 // notify on bad state of attached algos, return false
120 // if Compute() would fail because of some algo bad state
123 * \brief Sets number of segments per diagonal of boundary box of geometry by which
124 * default segment length of appropriate 1D hypotheses is defined
126 void SetBoundaryBoxSegmentation( int theNbSegments ) { _segmentation = theNbSegments; }
127 int GetBoundaryBoxSegmentation() const { return _segmentation; }
129 * \brief Sets default number of segments per edge
131 void SetDefaultNbSegments(int nb) { _nbSegments = nb; }
132 int GetDefaultNbSegments() const { return _nbSegments; }
134 struct TAlgoStateError
136 TAlgoStateErrorName _name;
137 const SMESH_Algo* _algo;
141 TAlgoStateError(): _name(SMESH_Hypothesis::HYP_OK), _algo(0), _algoDim(0) {}
142 void Set(TAlgoStateErrorName name, const SMESH_Algo* algo, bool isGlobal)
143 { _name = name; _algo = algo; _algoDim = algo->GetDim(); _isGlobalAlgo = isGlobal; }
144 void Set(TAlgoStateErrorName name, const int algoDim, bool isGlobal)
145 { _name = name; _algo = 0; _algoDim = algoDim; _isGlobalAlgo = isGlobal; }
148 bool GetAlgoState(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape,
149 std::list< SMESH_Gen::TAlgoStateError > & theErrors);
150 // notify on bad state of attached algos, return false
151 // if Compute() would fail because of some algo bad state
152 // theErrors list contains problems description
154 StudyContextStruct *GetStudyContext();
156 static int GetShapeDim(const TopAbs_ShapeEnum & aShapeType);
157 static int GetShapeDim(const TopoDS_Shape & aShape)
158 { return GetShapeDim( aShape.ShapeType() ); }
159 static int GetFlatShapeDim(const TopoDS_Shape &aShape);
161 SMESH_Algo* GetAlgo(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape, TopoDS_Shape* assignedTo=0);
162 SMESH_Algo* GetAlgo(SMESH_subMesh * aSubMesh, TopoDS_Shape* assignedTo=0);
164 static bool IsGlobalHypothesis(const SMESH_Hypothesis* theHyp, SMESH_Mesh& aMesh);
166 static std::vector< std::string > GetPluginXMLPaths();
173 bool parallelComputeSubMeshes(
175 const TopoDS_Shape & aShape,
176 const ::MeshDimension aDim,
177 TSetOfInt* aShapesId,
178 TopTools_IndexedMapOfShape* allowedSubShapes,
179 SMESH_subMesh::compute_event &computeEvent,
180 const bool includeSelf,
181 const bool complexShapeFirst,
182 const bool aShapeOnly);
184 bool sequentialComputeSubMeshes(
186 const TopoDS_Shape & aShape,
187 const ::MeshDimension aDim,
188 TSetOfInt* aShapesId /*=0*/,
189 TopTools_IndexedMapOfShape* allowedSubShapes,
190 SMESH_subMesh::compute_event &computeEvent,
191 const bool includeSelf,
192 const bool complexShapeFirst,
193 const bool aShapeOnly);
194 int _localId; // unique Id of created objects, within SMESH_Gen entity
195 StudyContextStruct* _studyContext;
197 // hypotheses managing
200 // number of segments per diagonal of boundary box of geometry by which
201 // default segment length of appropriate 1D hypotheses is defined
203 // default number of segments
206 void setCurrentSubMesh(SMESH_subMesh* sm);
207 void resetCurrentSubMesh();
209 volatile bool _compute_canceled;
210 std::list< SMESH_subMesh* > _sm_current;