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