Salome HOME
[SALOME platform 0013410]: SubMesh not taken into account with Netgen 1D-2D et 1D...
[plugins/netgenplugin.git] / src / NETGENPlugin / NETGENPlugin_SimpleHypothesis_3D.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_SimpleHypothesis_3D.cxx
23 // Author    : Edward AGAPOV
24 // Project   : SALOME
25 //=============================================================================
26
27 #include "NETGENPlugin_SimpleHypothesis_3D.hxx"
28 #include "NETGENPlugin_Hypothesis.hxx"
29
30 #include <SMESH_ControlsDef.hxx>
31 #include <SMESH_Mesh.hxx>
32 #include <SMESH_subMesh.hxx>
33
34 #include <TopExp_Explorer.hxx>
35
36 #include <utilities.h>
37
38 using namespace std;
39
40 //=============================================================================
41 /*!
42  *  
43  */
44 //=============================================================================
45 NETGENPlugin_SimpleHypothesis_3D::NETGENPlugin_SimpleHypothesis_3D (int         hypId,
46                                                                     int         studyId,
47                                                                     SMESH_Gen * gen)
48   : NETGENPlugin_SimpleHypothesis_2D(hypId, studyId, gen),
49   _volume(0)
50 {
51   _name = "NETGEN_SimpleParameters_3D";
52   _param_algo_dim = 3;
53 }
54
55 //=============================================================================
56 /*!
57  *  
58  */
59 //=============================================================================
60 void NETGENPlugin_SimpleHypothesis_3D::LengthFromFaces()
61 {
62   if (_volume > DBL_MIN )
63   {
64     _volume = 0;
65     NotifySubMeshesHypothesisModification();
66   }
67 }
68
69 //=============================================================================
70 /*!
71  *  
72  */
73 //=============================================================================
74 void NETGENPlugin_SimpleHypothesis_3D::SetMaxElementVolume(double value)
75 {
76   if ( value < DBL_MIN )
77     value = 0.;
78   if (_volume != value)
79   {
80     _volume = value;
81     NotifySubMeshesHypothesisModification();
82   }
83 }
84
85 //=============================================================================
86 /*!
87  *  
88  */
89 //=============================================================================
90 ostream & NETGENPlugin_SimpleHypothesis_3D::SaveTo(ostream & save)
91 {
92   NETGENPlugin_SimpleHypothesis_2D::SaveTo( save );
93   save << " " << _volume;
94
95   return save;
96 }
97
98 //=============================================================================
99 /*!
100  *  
101  */
102 //=============================================================================
103 istream & NETGENPlugin_SimpleHypothesis_3D::LoadFrom(istream & load)
104 {
105   NETGENPlugin_SimpleHypothesis_2D::LoadFrom(load);
106
107   bool isOK = true;
108   double val;
109
110   isOK = (load >> val);
111   if (isOK)
112     _volume = val;
113   else
114     load.clear(ios::badbit | load.rdstate());
115
116   return load;
117 }
118
119 //================================================================================
120 /*!
121  * \brief Does nothing
122  * \param theMesh - the built mesh
123  * \param theShape - the geometry of interest
124  * \retval bool - always false
125  */
126 //================================================================================
127 bool NETGENPlugin_SimpleHypothesis_3D::SetParametersByMesh(const SMESH_Mesh*   theMesh,
128                                                            const TopoDS_Shape& theShape)
129 {
130   if ( NETGENPlugin_SimpleHypothesis_2D::SetParametersByMesh(theMesh, theShape) )
131   {
132     // Find out max volume
133     _volume = 0;
134     SMESH::Controls::Volume volControl;
135     volControl.SetMesh( ((SMESH_Mesh*)theMesh)->GetMeshDS() );
136     const int nbElemToCheck = 100;
137     for ( TopExp_Explorer exp( theShape, TopAbs_SOLID ); exp.More(); exp.Next() ) {
138       SMESH_subMesh* sm = theMesh->GetSubMeshContaining( exp.Current() );
139       if ( sm && !sm->IsEmpty() ) {
140         SMDS_ElemIteratorPtr fIt = sm->GetSubMeshDS()->GetElements();
141         int nbCheckedElems = 0;
142         while ( fIt->more() && nbCheckedElems++ < nbElemToCheck ) {
143           const SMDS_MeshElement* elem = fIt->next();
144           _volume = max( _volume, volControl.GetValue( elem->GetID() ));
145         }
146       }
147     }
148     return int( _volume );
149   }
150   return false;
151 }