Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[plugins/netgenplugin.git] / src / NETGENPlugin / NETGENPlugin_NETGEN_2D.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_2D.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_2D.hxx"
31 #include "NETGENPlugin_Hypothesis_2D.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_2D::NETGENPlugin_NETGEN_2D(int hypId, int studyId,
49                                                SMESH_Gen* gen)
50   : SMESH_2D_Algo(hypId, studyId, gen)
51 {
52   MESSAGE("NETGENPlugin_NETGEN_2D::NETGENPlugin_NETGEN_2D");
53   _name = "NETGEN_2D";
54   _shapeType = (1 << TopAbs_FACE); // 1 bit /shape type
55   _compatibleHypothesis.push_back("NETGEN_Parameters_2D");
56   _requireDescretBoundary = false;
57   _onlyUnaryInput = false;
58   _hypothesis = NULL;
59 }
60
61 //=============================================================================
62 /*!
63  *  
64  */
65 //=============================================================================
66
67 NETGENPlugin_NETGEN_2D::~NETGENPlugin_NETGEN_2D()
68 {
69   MESSAGE("NETGENPlugin_NETGEN_2D::~NETGENPlugin_NETGEN_2D");
70 }
71
72 //=============================================================================
73 /*!
74  *  
75  */
76 //=============================================================================
77
78 bool NETGENPlugin_NETGEN_2D::CheckHypothesis
79                          (SMESH_Mesh& aMesh,
80                           const TopoDS_Shape& aShape,
81                           SMESH_Hypothesis::Hypothesis_Status& aStatus)
82 {
83   _hypothesis = NULL;
84
85   list<const SMESHDS_Hypothesis*>::const_iterator itl;
86   const SMESHDS_Hypothesis* theHyp;
87
88   const list<const SMESHDS_Hypothesis*>& hyps = GetUsedHypothesis(aMesh, aShape);
89   int nbHyp = hyps.size();
90   if (!nbHyp)
91   {
92     aStatus = SMESH_Hypothesis::HYP_OK;
93     return true;  // can work with no hypothesis
94   }
95
96   itl = hyps.begin();
97   theHyp = (*itl); // use only the first hypothesis
98
99   string hypName = theHyp->GetName();
100
101   if (hypName == "NETGEN_Parameters_2D")
102   {
103     _hypothesis = static_cast<const NETGENPlugin_Hypothesis_2D*> (theHyp);
104     ASSERT(_hypothesis);
105     aStatus = SMESH_Hypothesis::HYP_OK;
106   }
107   else
108     aStatus = SMESH_Hypothesis::HYP_INCOMPATIBLE;
109
110   return aStatus == SMESH_Hypothesis::HYP_OK;
111 }
112
113 //=============================================================================
114 /*!
115  *
116  */
117 //=============================================================================
118
119 bool NETGENPlugin_NETGEN_2D::Compute(SMESH_Mesh&         aMesh,
120                                      const TopoDS_Shape& aShape)
121 {
122   SMESHDS_Mesh* meshDS = aMesh.GetMeshDS();
123
124   NETGENPlugin_Mesher mesher(meshDS, aShape, false);
125   mesher.SetParameters(_hypothesis);
126   return mesher.Compute();
127 }
128
129 //=============================================================================
130 /*!
131  *  
132  */
133 //=============================================================================
134
135 ostream & NETGENPlugin_NETGEN_2D::SaveTo(ostream & save)
136 {
137   return save;
138 }
139
140 //=============================================================================
141 /*!
142  *  
143  */
144 //=============================================================================
145
146 istream & NETGENPlugin_NETGEN_2D::LoadFrom(istream & load)
147 {
148   return load;
149 }
150
151 //=============================================================================
152 /*!
153  *  
154  */
155 //=============================================================================
156
157 ostream & operator << (ostream & save, NETGENPlugin_NETGEN_2D & hyp)
158 {
159   return hyp.SaveTo( save );
160 }
161
162 //=============================================================================
163 /*!
164  *  
165  */
166 //=============================================================================
167
168 istream & operator >> (istream & load, NETGENPlugin_NETGEN_2D & hyp)
169 {
170   return hyp.LoadFrom( load );
171 }