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