Salome HOME
Merge from V6_main 01/04/2013
[plugins/netgenplugin.git] / src / NETGENPlugin / NETGENPlugin_NETGEN_2D3D.cxx
1 // Copyright (C) 2007-2013  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.
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_2D.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 #ifdef WITH_SMESH_CANCEL_COMPUTE
44 namespace nglib {
45 #include <nglib.h>
46 }
47 #include <meshing.hpp>
48 #endif
49
50 using namespace std;
51
52 //=============================================================================
53 /*!
54  *  
55  */
56 //=============================================================================
57
58 NETGENPlugin_NETGEN_2D3D::NETGENPlugin_NETGEN_2D3D(int hypId, int studyId,
59                                                    SMESH_Gen* gen)
60   : SMESH_3D_Algo(hypId, studyId, gen)
61 {
62   MESSAGE("NETGENPlugin_NETGEN_2D3D::NETGENPlugin_NETGEN_2D3D");
63   _name = "NETGEN_2D3D";
64   _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID);// 1 bit /shape type
65   _compatibleHypothesis.push_back("NETGEN_Parameters");
66   _compatibleHypothesis.push_back("NETGEN_SimpleParameters_3D");
67   _requireDiscreteBoundary = false;
68   _onlyUnaryInput = false;
69   _hypothesis = NULL;
70   _supportSubmeshes = true;
71 }
72
73 //=============================================================================
74 /*!
75  *  
76  */
77 //=============================================================================
78
79 NETGENPlugin_NETGEN_2D3D::~NETGENPlugin_NETGEN_2D3D()
80 {
81   MESSAGE("NETGENPlugin_NETGEN_2D3D::~NETGENPlugin_NETGEN_2D3D");
82 }
83
84 //=============================================================================
85 /*!
86  *  
87  */
88 //=============================================================================
89
90 bool NETGENPlugin_NETGEN_2D3D::CheckHypothesis
91                          (SMESH_Mesh& aMesh,
92                           const TopoDS_Shape& aShape,
93                           SMESH_Hypothesis::Hypothesis_Status& aStatus)
94 {
95   MESSAGE("NETGENPlugin_NETGEN_2D3D::CheckHypothesis");
96
97   _hypothesis = NULL;
98
99   const list<const SMESHDS_Hypothesis*>& hyps = GetUsedHypothesis(aMesh, aShape);
100   int nbHyp = hyps.size();
101   if (!nbHyp)
102   {
103     aStatus = SMESH_Hypothesis::HYP_OK;
104     return true;  // can work with no hypothesis
105   }
106
107   const SMESHDS_Hypothesis* theHyp = hyps.front(); // use only the first hypothesis
108
109   string hypName = theHyp->GetName();
110
111   if ( find( _compatibleHypothesis.begin(), _compatibleHypothesis.end(),
112              hypName ) != _compatibleHypothesis.end() )
113   {
114     _hypothesis = theHyp;
115     aStatus = SMESH_Hypothesis::HYP_OK;
116   }
117   else
118   {
119     aStatus = SMESH_Hypothesis::HYP_INCOMPATIBLE;
120   }
121
122   return aStatus == SMESH_Hypothesis::HYP_OK;
123 }
124
125 //=============================================================================
126 /*!
127  *  Here we are going to use the NETGEN mesher
128  */
129 //=============================================================================
130
131 bool NETGENPlugin_NETGEN_2D3D::Compute(SMESH_Mesh&         aMesh,
132                                        const TopoDS_Shape& aShape)
133 {
134 #ifdef WITH_SMESH_CANCEL_COMPUTE
135   netgen::multithread.terminate = 0;
136 #endif
137
138   NETGENPlugin_Mesher mesher(&aMesh, aShape, true);
139   mesher.SetParameters(dynamic_cast<const NETGENPlugin_Hypothesis*>(_hypothesis));
140   mesher.SetParameters(dynamic_cast<const NETGENPlugin_SimpleHypothesis_2D*>(_hypothesis));
141   return mesher.Compute();
142 }
143
144 //=============================================================================
145 /*!
146  *
147  */
148 //=============================================================================
149
150 #ifdef WITH_SMESH_CANCEL_COMPUTE
151 void NETGENPlugin_NETGEN_2D3D::CancelCompute()
152 {
153   SMESH_Algo::CancelCompute();
154   netgen::multithread.terminate = 1;
155 }
156 #endif
157
158 //=============================================================================
159 /*!
160  *
161  */
162 //=============================================================================
163
164 bool NETGENPlugin_NETGEN_2D3D::Evaluate(SMESH_Mesh&         aMesh,
165                                         const TopoDS_Shape& aShape,
166                                         MapShapeNbElems& aResMap)
167 {
168   NETGENPlugin_Mesher mesher(&aMesh, aShape, true);
169   mesher.SetParameters(dynamic_cast<const NETGENPlugin_Hypothesis*>(_hypothesis));
170   mesher.SetParameters(dynamic_cast<const NETGENPlugin_SimpleHypothesis_2D*>(_hypothesis));
171   return mesher.Evaluate(aResMap);
172 }