Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[plugins/netgenplugin.git] / src / NETGENPlugin / NETGENPlugin_NETGEN_2D3D.cxx
1 //  NETGENPlugin : C++ implementation
2 //
3 //  Copyright (C) 2006  OPEN CASCADE, CEA/DEN, EDF R&D
4 // 
5 //  This library is free software; you can redistribute it and/or 
6 //  modify it under the terms of the GNU Lesser General Public 
7 //  License as published by the Free Software Foundation; either 
8 //  version 2.1 of the License. 
9 // 
10 //  This library is distributed in the hope that it will be useful, 
11 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
12 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
13 //  Lesser General Public License for more details. 
14 // 
15 //  You should have received a copy of the GNU Lesser General Public 
16 //  License along with this library; if not, write to the Free Software 
17 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
18 // 
19 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 //
21 //
22 // File   : NETGENPlugin_NETGEN_2D3D.cxx
23 // Author : Michael Sazonov (OCN)
24 // Date   : 20/03/2006
25 // Project   : SALOME
26 // $Header$
27 //=============================================================================
28 using namespace std;
29
30 #include "NETGENPlugin_NETGEN_2D3D.hxx"
31 #include "NETGENPlugin_Hypothesis.hxx"
32 #include "NETGENPlugin_Mesher.hxx"
33
34 #include <SMESH_Gen.hxx>
35 #include <SMESH_Mesh.hxx>
36 #include <SMESH_ControlsDef.hxx>
37 #include <SMESHDS_Mesh.hxx>
38 #include <utilities.h>
39
40 #include <list>
41
42 //=============================================================================
43 /*!
44  *  
45  */
46 //=============================================================================
47
48 NETGENPlugin_NETGEN_2D3D::NETGENPlugin_NETGEN_2D3D(int hypId, int studyId,
49                                                    SMESH_Gen* gen)
50   : SMESH_3D_Algo(hypId, studyId, gen)
51 {
52   MESSAGE("NETGENPlugin_NETGEN_2D3D::NETGENPlugin_NETGEN_2D3D");
53   _name = "NETGEN_2D3D";
54   _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID);// 1 bit /shape type
55   _compatibleHypothesis.push_back("NETGEN_Parameters");
56   _requireDescretBoundary = false;
57   _onlyUnaryInput = false;
58   _hypothesis = NULL;
59 }
60
61 //=============================================================================
62 /*!
63  *  
64  */
65 //=============================================================================
66
67 NETGENPlugin_NETGEN_2D3D::~NETGENPlugin_NETGEN_2D3D()
68 {
69   MESSAGE("NETGENPlugin_NETGEN_2D3D::~NETGENPlugin_NETGEN_2D3D");
70 }
71
72 //=============================================================================
73 /*!
74  *  
75  */
76 //=============================================================================
77
78 bool NETGENPlugin_NETGEN_2D3D::CheckHypothesis
79                          (SMESH_Mesh& aMesh,
80                           const TopoDS_Shape& aShape,
81                           SMESH_Hypothesis::Hypothesis_Status& aStatus)
82 {
83   MESSAGE("NETGENPlugin_NETGEN_2D3D::CheckHypothesis");
84
85   _hypothesis = NULL;
86
87   list<const SMESHDS_Hypothesis*>::const_iterator itl;
88   const SMESHDS_Hypothesis* theHyp;
89
90   const list<const SMESHDS_Hypothesis*>& hyps = GetUsedHypothesis(aMesh, aShape);
91   int nbHyp = hyps.size();
92   if (!nbHyp)
93   {
94     aStatus = SMESH_Hypothesis::HYP_OK;
95     return true;  // can work with no hypothesis
96   }
97
98   itl = hyps.begin();
99   theHyp = (*itl); // use only the first hypothesis
100
101   string hypName = theHyp->GetName();
102
103   if (hypName == "NETGEN_Parameters")
104   {
105     _hypothesis = static_cast<const NETGENPlugin_Hypothesis*> (theHyp);
106     ASSERT(_hypothesis);
107     aStatus = SMESH_Hypothesis::HYP_OK;
108   }
109   else
110     aStatus = SMESH_Hypothesis::HYP_INCOMPATIBLE;
111
112   return aStatus == SMESH_Hypothesis::HYP_OK;
113 }
114
115 //=============================================================================
116 /*!
117  *Here we are going to use the NETGEN mesher
118  */
119 //=============================================================================
120
121 bool NETGENPlugin_NETGEN_2D3D::Compute(SMESH_Mesh&         aMesh,
122                                        const TopoDS_Shape& aShape)
123 {
124   SMESHDS_Mesh* meshDS = aMesh.GetMeshDS();
125
126   NETGENPlugin_Mesher mesher(meshDS, aShape, true);
127   mesher.SetParameters(_hypothesis);
128   return mesher.Compute();
129 }
130
131 //=============================================================================
132 /*!
133  *  
134  */
135 //=============================================================================
136
137 ostream & NETGENPlugin_NETGEN_2D3D::SaveTo(ostream & save)
138 {
139   return save;
140 }
141
142 //=============================================================================
143 /*!
144  *  
145  */
146 //=============================================================================
147
148 istream & NETGENPlugin_NETGEN_2D3D::LoadFrom(istream & load)
149 {
150   return load;
151 }
152
153 //=============================================================================
154 /*!
155  *  
156  */
157 //=============================================================================
158
159 ostream & operator << (ostream & save, NETGENPlugin_NETGEN_2D3D & hyp)
160 {
161   return hyp.SaveTo( save );
162 }
163
164 //=============================================================================
165 /*!
166  *  
167  */
168 //=============================================================================
169
170 istream & operator >> (istream & load, NETGENPlugin_NETGEN_2D3D & hyp)
171 {
172   return hyp.LoadFrom( load );
173 }