Salome HOME
Copyright update 2020
[modules/smesh.git] / src / StdMeshers / StdMeshers_QuadrangleParams.cxx
1 // Copyright (C) 2007-2020  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 //  File   : StdMeshers_QuadrangleParams.cxx
20 //  Author : Sergey KUUL, OCC
21 //  Module : SMESH
22
23 #include "StdMeshers_QuadrangleParams.hxx"
24
25 #include "SMESH_Algo.hxx"
26 #include "SMESH_Mesh.hxx"
27
28 #include <BRep_Tool.hxx>
29 #include <GCPnts_AbscissaPoint.hxx>
30 #include <GeomAdaptor_Curve.hxx>
31 #include <Geom_Curve.hxx>
32 #include <TopExp.hxx>
33 #include <TopLoc_Location.hxx>
34 #include <TopTools_IndexedMapOfShape.hxx>
35 #include <TopoDS.hxx>
36 #include <TopoDS_Edge.hxx>
37
38 using namespace std;
39
40 //=============================================================================
41 /*!
42  *
43  */
44 //=============================================================================
45 StdMeshers_QuadrangleParams::StdMeshers_QuadrangleParams(int hypId,
46                                                          SMESH_Gen * gen)
47   : SMESH_Hypothesis(hypId, gen)
48 {
49   _name = "QuadrangleParams";
50   _param_algo_dim = 2;
51   _triaVertexID = -1;
52   _quadType = QUAD_STANDARD;
53 }
54
55 //=============================================================================
56 /*!
57  *
58  */
59 //=============================================================================
60 StdMeshers_QuadrangleParams::~StdMeshers_QuadrangleParams()
61 {
62 }
63
64 //=============================================================================
65 /*!
66  *
67  */
68 //=============================================================================
69 void StdMeshers_QuadrangleParams::SetTriaVertex (int id)
70 {
71   if (id != _triaVertexID) {
72     _triaVertexID = id;
73     NotifySubMeshesHypothesisModification();
74   }
75 }
76
77 //=============================================================================
78 /*!
79  *
80  */
81 //=============================================================================
82 void StdMeshers_QuadrangleParams::SetQuadType (StdMeshers_QuadType type)
83 {
84   if (type != _quadType) {
85     _quadType = type;
86     NotifySubMeshesHypothesisModification();
87   }
88 }
89
90 //================================================================================
91 /*!
92  * \brief Set positions of enforced nodes
93  */
94 //================================================================================
95
96 void StdMeshers_QuadrangleParams::
97 SetEnforcedNodes( const std::vector< TopoDS_Shape >& shapes,
98                   const std::vector< gp_Pnt >&       points )
99 {
100   bool isChanged = ( shapes        != _enforcedVertices ||
101                      points.size() != _enforcedPoints.size() );
102   for ( size_t i = 0; i < points.size() && !isChanged; ++i )
103     isChanged = ( _enforcedPoints[ i ].SquareDistance( points[i] ) > 1e-100 );
104       
105   if ( isChanged )
106   {
107     _enforcedVertices = shapes;
108     _enforcedPoints   = points;
109     NotifySubMeshesHypothesisModification();
110   }
111 }
112
113 //================================================================================
114 /*!
115  * \brief Returns positions of enforced nodes
116  */
117 //================================================================================
118
119 void StdMeshers_QuadrangleParams::
120 GetEnforcedNodes( std::vector< TopoDS_Shape >& shapes,
121                   std::vector< gp_Pnt >&       points ) const
122 {
123   shapes = _enforcedVertices;
124   points = _enforcedPoints;
125 }
126
127 //=============================================================================
128 /*!
129  *
130  */
131 //=============================================================================
132 ostream & StdMeshers_QuadrangleParams::SaveTo(ostream & save)
133 {
134   if (_objEntry.size() == 0)
135     save << _triaVertexID << " UNDEFINED " << int(_quadType);
136   else
137     save << _triaVertexID << " " << _objEntry << " " << int(_quadType);
138
139   save << " " << _enforcedPoints.size();
140   for ( size_t i = 0; i < _enforcedPoints.size(); ++i )
141     save << " " << _enforcedPoints[i].X()
142          << " " << _enforcedPoints[i].Y()
143          << " " << _enforcedPoints[i].Z();
144
145   save << " " << _cornerVertices.size();
146   for ( size_t i = 0; i < _cornerVertices.size(); ++i )
147     save << " " << _cornerVertices[i];
148
149   return save;
150 }
151
152 //=============================================================================
153 /*!
154  *
155  */
156 //=============================================================================
157 istream & StdMeshers_QuadrangleParams::LoadFrom(istream & load)
158 {
159   bool isOK = true;
160   isOK = static_cast<bool>(load >> _triaVertexID);
161   if (!isOK)
162     load.clear(ios::badbit | load.rdstate());
163
164   isOK = static_cast<bool>(load >> _objEntry);
165   if (!isOK)
166     load.clear(ios::badbit | load.rdstate());
167
168   int type;
169   isOK = static_cast<bool>(load >> type);
170   if (isOK)
171     _quadType = StdMeshers_QuadType(type);
172
173   // _enforcedVertices are loaded at StdMeshers_I level
174   // because GEOM objects are referred by study entry.
175
176   int nbP = 0;
177   double x,y,z;
178   if ( load >> nbP && nbP > 0 )
179   {
180     _enforcedPoints.reserve( nbP );
181     while ( _enforcedPoints.size() < _enforcedPoints.capacity() )
182       if ( load >> x &&
183            load >> y &&
184            load >> z )
185         _enforcedPoints.push_back( gp_Pnt( x,y,z ));
186       else
187         break;
188   }
189
190   if ( load >> nbP && nbP > 0 )
191   {
192     int id;
193     _cornerVertices.reserve( nbP );
194     while ( _cornerVertices.size() < _cornerVertices.capacity() )
195       if ( load >> id )
196         _cornerVertices.push_back( id );
197       else
198         break;
199   }
200   return load;
201 }
202
203 //================================================================================
204 /*!
205  * \brief Redifined method
206  * \param theMesh - the built mesh
207  * \param theShape - the geometry of interest
208  * \retval bool - true if parameter values have been successfully defined
209  */
210 //================================================================================
211 bool StdMeshers_QuadrangleParams::SetParametersByMesh(const SMESH_Mesh* theMesh,
212                                                       const TopoDS_Shape& theShape)
213 {
214   if ( !theMesh || theShape.IsNull() )
215     return false;
216
217   return true;
218 }
219
220 //================================================================================
221 /*!
222  * \brief Initialize my parameter values by default parameters.
223  *  \retval bool - true if parameter values have been successfully defined
224  */
225 //================================================================================
226 bool StdMeshers_QuadrangleParams::SetParametersByDefaults(const TDefaults&  dflts,
227                                                           const SMESH_Mesh* /*mesh*/)
228 {
229   return true;
230 }