Salome HOME
Remove useless MESSAGEs
[plugins/netgenplugin.git] / src / NETGENPlugin / NETGENPlugin_NETGEN_2D3D.cxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  NETGENPlugin : C++ implementation
24 // File   : NETGENPlugin_NETGEN_2D3D.cxx
25 // Author : Michael Sazonov (OCN)
26 // Date   : 20/03/2006
27 // Project   : SALOME
28 //=============================================================================
29 //
30 #include "NETGENPlugin_NETGEN_2D3D.hxx"
31 #include "NETGENPlugin_Hypothesis.hxx"
32 #include "NETGENPlugin_SimpleHypothesis_3D.hxx"
33 #include "NETGENPlugin_Mesher.hxx"
34
35 #include <SMESH_Gen.hxx>
36 #include <SMESH_Mesh.hxx>
37 #include <SMESH_ControlsDef.hxx>
38 #include <SMESHDS_Mesh.hxx>
39 #include <utilities.h>
40
41 #include <list>
42
43 namespace nglib {
44 #include <nglib.h>
45 }
46 #include <meshing.hpp>
47
48 using namespace std;
49
50 //=============================================================================
51 /*!
52  *  
53  */
54 //=============================================================================
55
56 NETGENPlugin_NETGEN_2D3D::NETGENPlugin_NETGEN_2D3D(int hypId, int studyId,
57                                                    SMESH_Gen* gen)
58   : SMESH_3D_Algo(hypId, studyId, gen)
59 {
60   //MESSAGE("NETGENPlugin_NETGEN_2D3D::NETGENPlugin_NETGEN_2D3D");
61   _name = "NETGEN_2D3D";
62   _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID);// 1 bit /shape type
63   _compatibleHypothesis.push_back("NETGEN_Parameters");
64   _compatibleHypothesis.push_back("NETGEN_SimpleParameters_3D");
65   _requireDiscreteBoundary = false;
66   _onlyUnaryInput = false;
67   _hypothesis = NULL;
68   _supportSubmeshes = true;
69 }
70
71 //=============================================================================
72 /*!
73  *  
74  */
75 //=============================================================================
76
77 NETGENPlugin_NETGEN_2D3D::~NETGENPlugin_NETGEN_2D3D()
78 {
79   //MESSAGE("NETGENPlugin_NETGEN_2D3D::~NETGENPlugin_NETGEN_2D3D");
80 }
81
82 //=============================================================================
83 /*!
84  *  
85  */
86 //=============================================================================
87
88 bool NETGENPlugin_NETGEN_2D3D::CheckHypothesis
89                          (SMESH_Mesh& aMesh,
90                           const TopoDS_Shape& aShape,
91                           SMESH_Hypothesis::Hypothesis_Status& aStatus)
92 {
93   _hypothesis = NULL;
94   _mesher     = NULL;
95
96   const list<const SMESHDS_Hypothesis*>& hyps = GetUsedHypothesis(aMesh, aShape);
97   int nbHyp = hyps.size();
98   if (!nbHyp)
99   {
100     aStatus = SMESH_Hypothesis::HYP_OK;
101     return true;  // can work with no hypothesis
102   }
103
104   const SMESHDS_Hypothesis* theHyp = hyps.front(); // use only the first hypothesis
105
106   string hypName = theHyp->GetName();
107
108   if ( find( _compatibleHypothesis.begin(), _compatibleHypothesis.end(),
109              hypName ) != _compatibleHypothesis.end() )
110   {
111     _hypothesis = theHyp;
112     aStatus = SMESH_Hypothesis::HYP_OK;
113   }
114   else
115   {
116     aStatus = SMESH_Hypothesis::HYP_INCOMPATIBLE;
117   }
118
119   return aStatus == SMESH_Hypothesis::HYP_OK;
120 }
121
122 //=============================================================================
123 /*!
124  *  Here we are going to use the NETGEN mesher
125  */
126 //=============================================================================
127
128 bool NETGENPlugin_NETGEN_2D3D::Compute(SMESH_Mesh&         aMesh,
129                                        const TopoDS_Shape& aShape)
130 {
131   netgen::multithread.terminate = 0;
132
133   NETGENPlugin_Mesher mesher(&aMesh, aShape, true);
134   mesher.SetParameters(dynamic_cast<const NETGENPlugin_Hypothesis*>(_hypothesis));
135   mesher.SetParameters(dynamic_cast<const NETGENPlugin_SimpleHypothesis_3D*>(_hypothesis));
136   mesher.SetSelfPointer( &_mesher );
137   return mesher.Compute();
138 }
139
140 //=============================================================================
141 /*!
142  *
143  */
144 //=============================================================================
145
146 void NETGENPlugin_NETGEN_2D3D::CancelCompute()
147 {
148   SMESH_Algo::CancelCompute();
149   netgen::multithread.terminate = 1;
150 }
151
152 //================================================================================
153 /*!
154  * \brief Return progress of Compute() [0.,1]
155  */
156 //================================================================================
157
158 double NETGENPlugin_NETGEN_2D3D::GetProgress() const
159 {
160   double & progress = (double &)_progress;
161   if ( _mesher )
162     progress = _mesher->GetProgress(this, &_progressTic, &_progress);
163   else if ( _progress > 0.001 )
164     progress = 0.99;
165
166   return _progress;
167 }
168
169 //=============================================================================
170 /*!
171  *
172  */
173 //=============================================================================
174
175 bool NETGENPlugin_NETGEN_2D3D::Evaluate(SMESH_Mesh&         aMesh,
176                                         const TopoDS_Shape& aShape,
177                                         MapShapeNbElems& aResMap)
178 {
179   NETGENPlugin_Mesher mesher(&aMesh, aShape, true);
180   mesher.SetParameters(dynamic_cast<const NETGENPlugin_Hypothesis*>(_hypothesis));
181   mesher.SetParameters(dynamic_cast<const NETGENPlugin_SimpleHypothesis_2D*>(_hypothesis));
182   return mesher.Evaluate(aResMap);
183 }