1 // Copyright (C) 2012-2015 ALNEOS
2 // Copyright (C) 2016 EDF R&D
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.alneos.com/ or email : contact@alneos.fr
20 #include "GMSHPlugin_GMSH_2D.hxx"
21 #include "GMSHPlugin_Hypothesis_2D.hxx"
22 #include "GMSHPlugin_Mesher.hxx"
24 #include <SMESH_Gen.hxx>
25 #include <SMESH_Mesh.hxx>
26 #include <SMESH_ControlsDef.hxx>
27 #include <SMESHDS_Mesh.hxx>
28 #include <utilities.h>
34 //=============================================================================
38 //=============================================================================
40 GMSHPlugin_GMSH_2D::GMSHPlugin_GMSH_2D(int hypId, int studyId,
42 : SMESH_2D_Algo(hypId, studyId, gen)
44 MESSAGE("GMSHPlugin_GMSH_2D::GMSHPlugin_GMSH_2D");
46 _shapeType = (1 << TopAbs_FACE); // 1 bit /shape type
47 _compatibleHypothesis.push_back("GMSH_Parameters_2D");
48 _requireDiscreteBoundary = false;
49 _onlyUnaryInput = false;
51 _supportSubmeshes = true;
54 //=============================================================================
58 //=============================================================================
60 GMSHPlugin_GMSH_2D::~GMSHPlugin_GMSH_2D()
62 MESSAGE("GMSHPlugin_GMSH_2D::~GMSHPlugin_GMSH_2D");
65 //=============================================================================
69 //=============================================================================
71 bool GMSHPlugin_GMSH_2D::CheckHypothesis
73 const TopoDS_Shape& aShape,
74 SMESH_Hypothesis::Hypothesis_Status& aStatus)
76 MESSAGE("GMSHPlugin_GMSH::CheckHypothesis");
80 const list<const SMESHDS_Hypothesis*>& hyps = GetUsedHypothesis(aMesh, aShape);
81 int nbHyp = hyps.size();
84 aStatus = SMESH_Hypothesis::HYP_OK;
85 return true; // can work with no hypothesis
87 // use only the first hypothesis
88 const SMESHDS_Hypothesis* theHyp = hyps.front();
90 string hypName = theHyp->GetName();
91 if ( find( _compatibleHypothesis.begin(), _compatibleHypothesis.end(),
92 hypName ) != _compatibleHypothesis.end() )
95 aStatus = SMESH_Hypothesis::HYP_OK;
99 aStatus = SMESH_Hypothesis::HYP_INCOMPATIBLE;
102 return aStatus == SMESH_Hypothesis::HYP_OK;
105 //=============================================================================
107 *Here we are going to use the GMSH mesher
109 //=============================================================================
111 bool GMSHPlugin_GMSH_2D::Compute(SMESH_Mesh& aMesh,
112 const TopoDS_Shape& aShape)
114 GMSHPlugin_Mesher mesher(&aMesh, aShape);
115 mesher.SetParameters(dynamic_cast<const GMSHPlugin_Hypothesis*>(_hypothesis));
116 return mesher.Compute();
119 #ifdef WITH_SMESH_CANCEL_COMPUTE
120 void GMSHPlugin_GMSH_2D::CancelCompute()
124 //=============================================================================
128 //=============================================================================
130 bool GMSHPlugin_GMSH_2D::Evaluate(SMESH_Mesh& aMesh,
131 const TopoDS_Shape& aShape,
132 MapShapeNbElems& aResMap)
134 std::vector<int> aResVec(SMDSEntity_Last);
135 for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aResVec[i] = 0;
136 SMESH_subMesh * sm = aMesh.GetSubMesh(aShape);
137 aResMap.insert(std::make_pair(sm,aResVec));
138 SMESH_ComputeErrorPtr& smError = sm->GetComputeError();
139 smError.reset( new SMESH_ComputeError(COMPERR_ALGO_FAILED,"Evaluation is not implemented",this));