Salome HOME
Update copyright information
[plugins/netgenplugin.git] / src / NETGENPlugin / NETGENPlugin_NETGEN_2D.cxx
1 //  Copyright (C) 2007-2008  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 //  NETGENPlugin : C++ implementation
23 // File   : NETGENPlugin_NETGEN_2D.cxx
24 // Author : Michael Sazonov (OCN)
25 // Date   : 20/03/2006
26 // Project   : SALOME
27 // $Header$
28 //=============================================================================
29 //
30 #include "NETGENPlugin_NETGEN_2D.hxx"
31 #include "NETGENPlugin_Hypothesis_2D.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 using namespace std;
44
45 //=============================================================================
46 /*!
47  *  
48  */
49 //=============================================================================
50
51 NETGENPlugin_NETGEN_2D::NETGENPlugin_NETGEN_2D(int hypId, int studyId,
52                                                SMESH_Gen* gen)
53   : SMESH_2D_Algo(hypId, studyId, gen)
54 {
55   MESSAGE("NETGENPlugin_NETGEN_2D::NETGENPlugin_NETGEN_2D");
56   _name = "NETGEN_2D";
57   _shapeType = (1 << TopAbs_FACE); // 1 bit /shape type
58   _compatibleHypothesis.push_back("NETGEN_Parameters_2D");
59   _compatibleHypothesis.push_back("NETGEN_SimpleParameters_2D");
60   _requireDescretBoundary = false;
61   _onlyUnaryInput = false;
62   _hypothesis = NULL;
63   _supportSubmeshes = true;
64 }
65
66 //=============================================================================
67 /*!
68  *  
69  */
70 //=============================================================================
71
72 NETGENPlugin_NETGEN_2D::~NETGENPlugin_NETGEN_2D()
73 {
74   MESSAGE("NETGENPlugin_NETGEN_2D::~NETGENPlugin_NETGEN_2D");
75 }
76
77 //=============================================================================
78 /*!
79  *  
80  */
81 //=============================================================================
82
83 bool NETGENPlugin_NETGEN_2D::CheckHypothesis
84                          (SMESH_Mesh& aMesh,
85                           const TopoDS_Shape& aShape,
86                           SMESH_Hypothesis::Hypothesis_Status& aStatus)
87 {
88   _hypothesis = NULL;
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   // use only the first hypothesis
98   const SMESHDS_Hypothesis* theHyp = hyps.front();
99
100   string hypName = theHyp->GetName();
101   if ( find( _compatibleHypothesis.begin(), _compatibleHypothesis.end(),
102              hypName ) != _compatibleHypothesis.end() )
103   {
104     _hypothesis = theHyp;
105     aStatus = SMESH_Hypothesis::HYP_OK;
106   }
107   else
108   {
109     aStatus = SMESH_Hypothesis::HYP_INCOMPATIBLE;
110   }
111
112   return aStatus == SMESH_Hypothesis::HYP_OK;
113 }
114
115 //=============================================================================
116 /*!
117  *
118  */
119 //=============================================================================
120
121 bool NETGENPlugin_NETGEN_2D::Compute(SMESH_Mesh&         aMesh,
122                                      const TopoDS_Shape& aShape)
123 {
124   //SMESHDS_Mesh* meshDS = aMesh.GetMeshDS();
125
126   NETGENPlugin_Mesher mesher(&aMesh, aShape, false);
127 //   NETGENPlugin_Mesher mesher(meshDS, aShape, false);
128   mesher.SetParameters(dynamic_cast<const NETGENPlugin_Hypothesis*>(_hypothesis));
129   mesher.SetParameters(dynamic_cast<const NETGENPlugin_SimpleHypothesis_2D*>(_hypothesis));
130   return mesher.Compute();
131 }