Salome HOME
depot initial V7_2_0
[plugins/gmshplugin.git] / src / GMSHPlugin / GMSHPlugin_GMSH.cxx
1 // Copyright (C) 2012-2013  ALNEOS
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.alneos.com/ or email : contact@alneos.fr
18 //
19 #include "GMSHPlugin_GMSH.hxx"
20 #include "GMSHPlugin_Hypothesis.hxx"
21 #include "GMSHPlugin_Mesher.hxx"
22
23 #include <SMESH_Gen.hxx>
24 #include <SMESH_Mesh.hxx>
25 #include <SMESH_ControlsDef.hxx>
26 #include <SMESHDS_Mesh.hxx>
27 #include <utilities.h>
28
29 #include <list>
30
31 using namespace std;
32
33 //=============================================================================
34 /*!
35  *  
36  */
37 //=============================================================================
38
39 GMSHPlugin_GMSH::GMSHPlugin_GMSH(int hypId, int studyId,
40                                                    SMESH_Gen* gen)
41   : SMESH_3D_Algo(hypId, studyId, gen)
42 {
43   MESSAGE("GMSHPlugin_GMSH::GMSHPlugin_GMSH");
44   _name = "GMSH";
45   _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID);// 1 bit /shape type
46   _compatibleHypothesis.push_back("GMSH_Parameters");
47   _requireDiscreteBoundary = false;
48   _onlyUnaryInput = false;
49   _hypothesis = NULL;
50   _supportSubmeshes = true;
51 }
52
53 //=============================================================================
54 /*!
55  *  
56  */
57 //=============================================================================
58
59 GMSHPlugin_GMSH::~GMSHPlugin_GMSH()
60 {
61   MESSAGE("GMSHPlugin_GMSH::~GMSHPlugin_GMSH");
62 }
63
64 //=============================================================================
65 /*!
66  *  
67  */
68 //=============================================================================
69
70 bool GMSHPlugin_GMSH::CheckHypothesis
71                          (SMESH_Mesh& aMesh,
72                           const TopoDS_Shape& aShape,
73                           SMESH_Hypothesis::Hypothesis_Status& aStatus)
74 {
75   MESSAGE("GMSHPlugin_GMSH::CheckHypothesis");
76   
77   _hypothesis = NULL;
78   
79   const list<const SMESHDS_Hypothesis*>& hyps = GetUsedHypothesis(aMesh, aShape);
80   int nbHyp = hyps.size();
81   if (!nbHyp)
82   {
83     aStatus = SMESH_Hypothesis::HYP_OK;
84     return true;  // can work with no hypothesis
85   }
86   // use only the first hypothesis
87   const SMESHDS_Hypothesis* theHyp = hyps.front();
88   
89   string hypName = theHyp->GetName();
90   if ( find( _compatibleHypothesis.begin(), _compatibleHypothesis.end(),
91              hypName ) != _compatibleHypothesis.end() )
92   {
93     _hypothesis = theHyp;
94     aStatus = SMESH_Hypothesis::HYP_OK;
95   }
96   else
97   {
98     aStatus = SMESH_Hypothesis::HYP_INCOMPATIBLE;
99   }
100
101   return aStatus == SMESH_Hypothesis::HYP_OK;
102 }
103
104 //=============================================================================
105 /*!
106  *Here we are going to use the GMSH mesher
107  */
108 //=============================================================================
109
110 bool GMSHPlugin_GMSH::Compute(SMESH_Mesh&         aMesh,
111                                        const TopoDS_Shape& aShape)
112 {
113   GMSHPlugin_Mesher mesher(&aMesh, aShape);
114   mesher.SetParameters(dynamic_cast<const GMSHPlugin_Hypothesis*>(_hypothesis));
115   return mesher.Compute();
116 }
117
118 #ifdef WITH_SMESH_CANCEL_COMPUTE
119 void GMSHPlugin_GMSH::CancelCompute()
120 {}
121 #endif
122
123 //=============================================================================
124 /*!
125  *
126  */
127 //=============================================================================
128
129 bool GMSHPlugin_GMSH::Evaluate(SMESH_Mesh&         aMesh,
130                                         const TopoDS_Shape& aShape,
131                                         MapShapeNbElems& aResMap)
132 {
133   std::vector<int> aResVec(SMDSEntity_Last);
134   for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aResVec[i] = 0;
135   SMESH_subMesh * sm = aMesh.GetSubMesh(aShape);
136   aResMap.insert(std::make_pair(sm,aResVec));
137   SMESH_ComputeErrorPtr& smError = sm->GetComputeError();
138   smError.reset( new SMESH_ComputeError(COMPERR_ALGO_FAILED,"Evaluation is not implemented",this));
139   
140   return true;
141 }