Salome HOME
Merge from V6_main 01/04/2013
[plugins/netgenplugin.git] / src / NETGENPlugin / NETGENPlugin_SimpleHypothesis_3D.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 //  NETGENPlugin : C++ implementation
21 // File      : NETGENPlugin_SimpleHypothesis_3D.cxx
22 // Author    : Edward AGAPOV
23 // Project   : SALOME
24 //=============================================================================
25 //
26 #include "NETGENPlugin_SimpleHypothesis_3D.hxx"
27 #include "NETGENPlugin_Hypothesis.hxx"
28
29 #include <SMESH_ControlsDef.hxx>
30 #include <SMESH_Mesh.hxx>
31 #include <SMESH_subMesh.hxx>
32
33 #include <TopExp_Explorer.hxx>
34
35 #include <utilities.h>
36
37 using namespace std;
38
39 //=============================================================================
40 /*!
41  *  
42  */
43 //=============================================================================
44 NETGENPlugin_SimpleHypothesis_3D::NETGENPlugin_SimpleHypothesis_3D (int         hypId,
45                                                                     int         studyId,
46                                                                     SMESH_Gen * gen)
47   : NETGENPlugin_SimpleHypothesis_2D(hypId, studyId, gen),
48   _volume(0)
49 {
50   _name = "NETGEN_SimpleParameters_3D";
51   _param_algo_dim = 3;
52 }
53
54 //=============================================================================
55 /*!
56  *  
57  */
58 //=============================================================================
59 void NETGENPlugin_SimpleHypothesis_3D::LengthFromFaces()
60 {
61   if (_volume > DBL_MIN )
62   {
63     _volume = 0;
64     NotifySubMeshesHypothesisModification();
65   }
66 }
67
68 //=============================================================================
69 /*!
70  *  
71  */
72 //=============================================================================
73 void NETGENPlugin_SimpleHypothesis_3D::SetMaxElementVolume(double value)
74 {
75   if ( value < DBL_MIN )
76     value = 0.;
77   if (_volume != value)
78   {
79     _volume = value;
80     NotifySubMeshesHypothesisModification();
81   }
82 }
83
84 //=============================================================================
85 /*!
86  *  
87  */
88 //=============================================================================
89 ostream & NETGENPlugin_SimpleHypothesis_3D::SaveTo(ostream & save)
90 {
91   NETGENPlugin_SimpleHypothesis_2D::SaveTo( save );
92   save << " " << _volume;
93
94   return save;
95 }
96
97 //=============================================================================
98 /*!
99  *  
100  */
101 //=============================================================================
102 istream & NETGENPlugin_SimpleHypothesis_3D::LoadFrom(istream & load)
103 {
104   NETGENPlugin_SimpleHypothesis_2D::LoadFrom(load);
105
106   bool isOK = true;
107   double val;
108
109   isOK = (load >> val);
110   if (isOK)
111     _volume = val;
112   else
113     load.clear(ios::badbit | load.rdstate());
114
115   return load;
116 }
117
118 //================================================================================
119 /*!
120  * \brief Does nothing
121  * \param theMesh - the built mesh
122  * \param theShape - the geometry of interest
123  * \retval bool - always false
124  */
125 //================================================================================
126 bool NETGENPlugin_SimpleHypothesis_3D::SetParametersByMesh(const SMESH_Mesh*   theMesh,
127                                                            const TopoDS_Shape& theShape)
128 {
129   if ( NETGENPlugin_SimpleHypothesis_2D::SetParametersByMesh(theMesh, theShape) )
130   {
131     // Find out max volume
132     _volume = 0;
133     SMESH::Controls::Volume volControl;
134     volControl.SetMesh( ((SMESH_Mesh*)theMesh)->GetMeshDS() );
135     const int nbElemToCheck = 100;
136     for ( TopExp_Explorer exp( theShape, TopAbs_SOLID ); exp.More(); exp.Next() ) {
137       SMESH_subMesh* sm = theMesh->GetSubMeshContaining( exp.Current() );
138       if ( sm && !sm->IsEmpty() ) {
139         SMDS_ElemIteratorPtr fIt = sm->GetSubMeshDS()->GetElements();
140         int nbCheckedElems = 0;
141         while ( fIt->more() && nbCheckedElems++ < nbElemToCheck ) {
142           const SMDS_MeshElement* elem = fIt->next();
143           _volume = max( _volume, volControl.GetValue( elem->GetID() ));
144         }
145       }
146     }
147     return int( _volume );
148   }
149   return false;
150 }