]> SALOME platform Git repositories - plugins/gmshplugin.git/blob - src/GMSHPlugin/GMSHPlugin_GMSH_3D.cxx
Salome HOME
9588ed233d772ea8eb453d8a58614d8f036a4fc5
[plugins/gmshplugin.git] / src / GMSHPlugin / GMSHPlugin_GMSH_3D.cxx
1 // Copyright (C) 2012-2015  ALNEOS
2 // Copyright (C) 2016-2023  EDF R&D
3 //
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, or (at your option) any later version.
8 //
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.
13 //
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
17 //
18 // See http://www.alneos.com/ or email : contact@alneos.fr
19 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 //
21 #include "GMSHPlugin_GMSH_3D.hxx"
22 #include "GMSHPlugin_Hypothesis_2D.hxx"
23 #include "GMSHPlugin_Mesher.hxx"
24
25 #include <SMESH_Gen.hxx>
26 #include <SMESH_ControlsDef.hxx>
27 #include <SMESHDS_Mesh.hxx>
28 #include <utilities.h>
29
30 #include <list>
31
32 using namespace std;
33
34 //=============================================================================
35 /*!
36  *  
37  */
38 //=============================================================================
39
40 GMSHPlugin_GMSH_3D::GMSHPlugin_GMSH_3D(int hypId, SMESH_Gen* gen)
41   : SMESH_3D_Algo(hypId, gen)
42 {
43   MESSAGE("GMSHPlugin_GMSH_3D::GMSHPlugin_GMSH_3D");
44   _name = "GMSH_3D";
45   _shapeType = (1 << TopAbs_SOLID); // 1 bit /shape type
46   _compatibleHypothesis.push_back("GMSH_Parameters_3D");
47   _onlyUnaryInput = false;
48   _hypothesis = NULL;
49   _supportSubmeshes = true;
50
51   _requireShape = false; // can work without shape
52 }
53
54 //=============================================================================
55 /*!
56  *  
57  */
58 //=============================================================================
59
60 GMSHPlugin_GMSH_3D::~GMSHPlugin_GMSH_3D()
61 {
62   MESSAGE("GMSHPlugin_GMSH_3D::~GMSHPlugin_GMSH_3D");
63 }
64
65 //=============================================================================
66 /*!
67  *  
68  */
69 //=============================================================================
70
71 bool GMSHPlugin_GMSH_3D::CheckHypothesis
72                          (SMESH_Mesh& aMesh,
73                           const TopoDS_Shape& aShape,
74                           SMESH_Hypothesis::Hypothesis_Status& aStatus)
75 {
76   MESSAGE("GMSHPlugin_GMSH::CheckHypothesis");
77   
78   _hypothesis = NULL;
79   
80   const list<const SMESHDS_Hypothesis*>& hyps = GetUsedHypothesis(aMesh, aShape);
81   int nbHyp = hyps.size();
82   if (!nbHyp)
83   {
84     aStatus = SMESH_Hypothesis::HYP_OK;
85     return true;  // can work with no hypothesis
86   }
87   // use only the first hypothesis
88   const SMESHDS_Hypothesis* theHyp = hyps.front();
89   
90   string hypName = theHyp->GetName();
91   if ( find( _compatibleHypothesis.begin(), _compatibleHypothesis.end(),
92              hypName ) != _compatibleHypothesis.end() )
93   {
94     _hypothesis = theHyp;
95     aStatus = SMESH_Hypothesis::HYP_OK;
96   }
97   else
98   {
99     aStatus = SMESH_Hypothesis::HYP_INCOMPATIBLE;
100   }
101
102   return aStatus == SMESH_Hypothesis::HYP_OK;
103 }
104
105 //=============================================================================
106 /*!
107  *Here we are going to use the GMSH mesher
108  */
109 //=============================================================================
110
111 bool GMSHPlugin_GMSH_3D::Compute(SMESH_Mesh&         aMesh,
112                                  const TopoDS_Shape& aShape)
113 {
114   GMSHPlugin_Mesher mesher(&aMesh, aShape,/*2d=*/false, true);
115   mesher.SetParameters(dynamic_cast<const GMSHPlugin_Hypothesis*>(_hypothesis));
116
117   return mesher.Compute();
118 }
119
120 #ifdef WITH_SMESH_CANCEL_COMPUTE
121 void GMSHPlugin_GMSH_3D::CancelCompute()
122 {}
123 #endif
124
125 //=============================================================================
126 /*!
127  *
128  */
129 //=============================================================================
130
131 bool GMSHPlugin_GMSH_3D::Evaluate(SMESH_Mesh&         aMesh,
132                                   const TopoDS_Shape& aShape,
133                                   MapShapeNbElems& aResMap)
134 {
135   std::vector<smIdType> aResVec(SMDSEntity_Last);
136   for(smIdType i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aResVec[i] = 0;
137   SMESH_subMesh * sm = aMesh.GetSubMesh(aShape);
138   aResMap.insert(std::make_pair(sm,aResVec));
139   SMESH_ComputeErrorPtr& smError = sm->GetComputeError();
140   smError.reset( new SMESH_ComputeError(COMPERR_ALGO_FAILED,"Evaluation is not implemented",this));
141   
142   return true;
143 }