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