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