Salome HOME
updated copyright message
[plugins/netgenplugin.git] / src / NETGENPlugin / NETGENPlugin_Hypothesis_2D.cxx
1 // Copyright (C) 2007-2023  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  NETGENPlugin : C++ implementation
24 // File      : NETGENPlugin_Hypothesis_2D.cxx
25 // Author    : Michael Sazonov (OCN)
26 // Date      : 28/03/2006
27 // Project   : SALOME
28 //=============================================================================
29 //
30 #include "NETGENPlugin_Hypothesis_2D.hxx"
31
32 #include <SMESH_Mesh.hxx>
33 #include <SMESH_Group.hxx>
34 #include <SMESHDS_GroupBase.hxx>
35
36 using namespace std;
37
38 //=============================================================================
39 /*!
40  *  
41  */
42 //=============================================================================
43 NETGENPlugin_Hypothesis_2D::NETGENPlugin_Hypothesis_2D (int hypId,
44                                                         SMESH_Gen * gen)
45   : NETGENPlugin_Hypothesis(hypId, gen)/*,
46     _quadAllowed (GetDefaultQuadAllowed())*/
47 {
48   _name = "NETGEN_Parameters_2D";
49   _param_algo_dim = 2;
50 }
51
52 //=============================================================================
53 /*!
54  *
55  */
56 //=============================================================================
57 NETGENPlugin_RemesherHypothesis_2D::
58 NETGENPlugin_RemesherHypothesis_2D (int hypId, SMESH_Gen * gen)
59   : NETGENPlugin_Hypothesis(hypId, gen),
60     _ridgeAngle             ( DefaultRidgeAngle()             ),
61     _edgeCornerAngle        ( DefaultEdgeCornerAngle()        ),
62     _chartAngle             ( DefaultChartAngle()             ),
63     _outerChartAngle        ( DefaultOuterChartAngle()        ),
64     _restHChartDistFactor   ( DefaultRestHChartDistFactor()   ),
65     _restHChartDistEnable   ( DefaultRestHChartDistEnable()   ),
66     _restHLineLengthFactor  ( DefaultRestHLineLengthFactor()  ),
67     _restHLineLengthEnable  ( DefaultRestHLineLengthEnable()  ),
68     _restHCloseEdgeFactor   ( DefaultRestHCloseEdgeFactor()   ),
69     _restHCloseEdgeEnable   ( DefaultRestHCloseEdgeEnable()   ),
70     _restHSurfCurvFactor    ( DefaultRestHSurfCurvFactor()    ),
71     _restHSurfCurvEnable    ( DefaultRestHSurfCurvEnable()    ),
72     _restHEdgeAngleFactor   ( DefaultRestHEdgeAngleFactor()   ),
73     _restHEdgeAngleEnable   ( DefaultRestHEdgeAngleEnable()   ),
74     _restHSurfMeshCurvFactor( DefaultRestHSurfMeshCurvFactor()),
75     _restHSurfMeshCurvEnable( DefaultRestHSurfMeshCurvEnable()),
76     _keepExistingEdges      ( DefaultKeepExistingEdges()      ),
77     _makeGroupsOfSurfaces   ( DefaultMakeGroupsOfSurfaces()   ),
78     _fixedEdgeGroupID       ( -1                              ),
79     _loadOnCancel           ( false                           )
80 {
81   _name = "NETGEN_RemesherParameters_2D";
82   _param_algo_dim = 2;
83 }
84
85 //=============================================================================
86 /*!
87  *
88  */
89 //=============================================================================
90
91 void NETGENPlugin_RemesherHypothesis_2D::SetRidgeAngle( double angle )
92 {
93   if ( _ridgeAngle != angle )
94   {
95     _ridgeAngle = angle;
96     NotifySubMeshesHypothesisModification();
97   }
98 }
99
100 //=======================================================================
101 //function : SetEdgeCornerAngle
102 //purpose  : 
103 //=======================================================================
104
105 void NETGENPlugin_RemesherHypothesis_2D::SetEdgeCornerAngle( double angle )
106 {
107   if ( _edgeCornerAngle != angle )
108   {
109     _edgeCornerAngle = angle;
110     NotifySubMeshesHypothesisModification();
111   }
112 }
113
114 //=======================================================================
115 //function : SetChartAngle
116 //purpose  : 
117 //=======================================================================
118
119 void NETGENPlugin_RemesherHypothesis_2D::SetChartAngle( double angle )
120 {
121   if ( _chartAngle != angle )
122   {
123     _chartAngle = angle;
124     NotifySubMeshesHypothesisModification();
125   }
126 }
127
128 //=======================================================================
129 //function : SetOuterChartAngle
130 //purpose  : 
131 //=======================================================================
132
133 void NETGENPlugin_RemesherHypothesis_2D::SetOuterChartAngle( double angle )
134 {
135   if ( _outerChartAngle != angle )
136   {
137     _outerChartAngle = angle;
138     NotifySubMeshesHypothesisModification();
139   }
140 }
141
142 //=======================================================================
143 //function : SetRestHChartDistFactor
144 //purpose  : 
145 //=======================================================================
146
147 void NETGENPlugin_RemesherHypothesis_2D::SetRestHChartDistFactor( double f )
148 {
149   if ( _restHChartDistFactor != f )
150   {
151     _restHChartDistFactor = f;
152     NotifySubMeshesHypothesisModification();
153   }
154 }
155
156 //=======================================================================
157 //function : SetRestHChartDistEnable
158 //purpose  : 
159 //=======================================================================
160
161 void NETGENPlugin_RemesherHypothesis_2D::SetRestHChartDistEnable( bool enable )
162 {
163   if ( _restHChartDistEnable != enable )
164   {
165     _restHChartDistEnable = enable;
166     NotifySubMeshesHypothesisModification();
167   }
168 }
169
170 //=======================================================================
171 //function : SetRestHLineLengthFactor
172 //purpose  : 
173 //=======================================================================
174
175 void NETGENPlugin_RemesherHypothesis_2D::SetRestHLineLengthFactor( double f )
176 {
177   if ( _restHLineLengthFactor != f )
178   {
179     _restHLineLengthFactor = f;
180     NotifySubMeshesHypothesisModification();
181   }
182 }
183
184 //=======================================================================
185 //function : SetRestHLineLengthEnable
186 //purpose  : 
187 //=======================================================================
188
189 void NETGENPlugin_RemesherHypothesis_2D::SetRestHLineLengthEnable( bool enable )
190 {
191   if ( _restHLineLengthEnable != enable )
192   {
193     _restHLineLengthEnable = enable;
194     NotifySubMeshesHypothesisModification();
195   }
196 }
197
198 //=======================================================================
199 //function : SetRestHCloseEdgeFactor
200 //purpose  : 
201 //=======================================================================
202
203 void NETGENPlugin_RemesherHypothesis_2D::SetRestHCloseEdgeFactor( double f )
204 {
205   if ( _restHCloseEdgeFactor != f )
206   {
207     _restHCloseEdgeFactor = f;
208     NotifySubMeshesHypothesisModification();
209   }
210 }
211
212 //=======================================================================
213 //function : SetRestHCloseEdgeEnable
214 //purpose  : 
215 //=======================================================================
216
217 void NETGENPlugin_RemesherHypothesis_2D::SetRestHCloseEdgeEnable( bool enable )
218 {
219   if ( _restHCloseEdgeEnable != enable )
220   {
221     _restHCloseEdgeEnable = enable;
222     NotifySubMeshesHypothesisModification();
223   }
224 }
225
226 //=======================================================================
227 //function : SetRestHSurfCurvFactor
228 //purpose  : 
229 //=======================================================================
230
231 void NETGENPlugin_RemesherHypothesis_2D::SetRestHSurfCurvFactor( double f )
232 {
233   if ( _restHSurfCurvFactor != f )
234   {
235     _restHSurfCurvFactor = f;
236     NotifySubMeshesHypothesisModification();
237   }
238 }
239
240 //=======================================================================
241 //function : SetRestHSurfCurvEnable
242 //purpose  : 
243 //=======================================================================
244
245 void NETGENPlugin_RemesherHypothesis_2D::SetRestHSurfCurvEnable( bool enable )
246 {
247   if ( _restHSurfCurvEnable != enable )
248   {
249     _restHSurfCurvEnable = enable;
250     NotifySubMeshesHypothesisModification();
251   }
252 }
253
254 //=======================================================================
255 //function : SetRestHEdgeAngleFactor
256 //purpose  : 
257 //=======================================================================
258
259 void NETGENPlugin_RemesherHypothesis_2D::SetRestHEdgeAngleFactor( double f )
260 {
261   if ( _restHEdgeAngleFactor != f )
262   {
263     _restHEdgeAngleFactor = f;
264     NotifySubMeshesHypothesisModification();
265   }
266 }
267
268 //=======================================================================
269 //function : SetRestHEdgeAngleEnable
270 //purpose  : 
271 //=======================================================================
272
273 void NETGENPlugin_RemesherHypothesis_2D::SetRestHEdgeAngleEnable( bool enable )
274 {
275   if ( _restHEdgeAngleEnable != enable )
276   {
277     _restHEdgeAngleEnable = enable;
278     NotifySubMeshesHypothesisModification();
279   }
280 }
281
282 //=======================================================================
283 //function : SetRestHSurfMeshCurvFactor
284 //purpose  :
285 //=======================================================================
286
287 void NETGENPlugin_RemesherHypothesis_2D::SetRestHSurfMeshCurvFactor( double f )
288 {
289   if ( _restHSurfMeshCurvFactor != f )
290   {
291     _restHSurfMeshCurvFactor = f;
292     NotifySubMeshesHypothesisModification();
293   }
294 }
295
296 //=======================================================================
297 //function : SetRestHSurfMeshCurvEnable
298 //purpose  :
299 //=======================================================================
300
301 void NETGENPlugin_RemesherHypothesis_2D::SetRestHSurfMeshCurvEnable( bool enable )
302 {
303   if ( _restHSurfMeshCurvEnable != enable )
304   {
305     _restHSurfMeshCurvEnable = enable;
306     NotifySubMeshesHypothesisModification();
307   }
308 }
309
310 //=======================================================================
311 //function : SetKeepExistingEdges
312 //purpose  :
313 //=======================================================================
314
315 void NETGENPlugin_RemesherHypothesis_2D::SetKeepExistingEdges( bool toKeep )
316 {
317   if ( _keepExistingEdges != toKeep )
318   {
319     _keepExistingEdges = toKeep;
320     NotifySubMeshesHypothesisModification();
321   }
322 }
323
324 //=======================================================================
325 //function : SetMakeGroupsOfSurfaces
326 //purpose  :
327 //=======================================================================
328
329 void NETGENPlugin_RemesherHypothesis_2D::SetMakeGroupsOfSurfaces( bool toMake )
330 {
331   if ( _makeGroupsOfSurfaces != toMake )
332   {
333     _makeGroupsOfSurfaces = toMake;
334     NotifySubMeshesHypothesisModification();
335   }
336 }
337
338 //=======================================================================
339 //function : SetFixedEdgeGroup
340 //purpose  : Set a group of edges whose nodes must not be moved
341 //=======================================================================
342
343 void NETGENPlugin_RemesherHypothesis_2D::SetFixedEdgeGroup( const SMESH_Group* edgeGroup )
344 {
345   int id = edgeGroup ? edgeGroup->GetID() : -1;
346   if ( id != _fixedEdgeGroupID )
347   {
348     _fixedEdgeGroupID = id;
349     NotifySubMeshesHypothesisModification();
350   }
351 }
352
353 //=======================================================================
354 //function : SetLoadMeshOnCancel
355 //purpose  : allow getting a current mesh existing upon CancelCompute()
356 //=======================================================================
357
358 void NETGENPlugin_RemesherHypothesis_2D::SetLoadMeshOnCancel( bool toLoad )
359 {
360   if ( toLoad != _loadOnCancel )
361   {
362     _loadOnCancel = toLoad;
363     NotifySubMeshesHypothesisModification();
364   }
365 }
366
367 //=======================================================================
368 //function : GetFixedEdgeGroup
369 //purpose  : Return a group of edges whose nodes must not be moved
370 //=======================================================================
371
372 SMESH_Group*
373 NETGENPlugin_RemesherHypothesis_2D::GetFixedEdgeGroup( const SMESH_Mesh& mesh ) const
374 {
375   SMESH_Group* group = mesh.GetGroup( _fixedEdgeGroupID );
376   if ( group && group->GetGroupDS()->GetType() != SMDSAbs_Edge )
377     group = NULL;
378
379   return group;
380 }
381
382 //=============================================================================
383 /*!
384  *
385  */
386 //=============================================================================
387
388 std::ostream & NETGENPlugin_RemesherHypothesis_2D::SaveTo(std::ostream & save)
389 {
390   NETGENPlugin_Hypothesis::SaveTo( save );
391   save << " " << _ridgeAngle;
392
393   save << " " << _edgeCornerAngle        ;
394   save << " " << _chartAngle             ;
395   save << " " << _outerChartAngle        ;
396   save << " " << _restHChartDistFactor   ;
397   save << " " << _restHChartDistEnable   ;
398   save << " " << _restHLineLengthFactor  ;
399   save << " " << _restHLineLengthEnable  ;
400   save << " " << _restHCloseEdgeFactor   ;
401   save << " " << _restHCloseEdgeEnable   ;
402   save << " " << _restHSurfCurvFactor    ;
403   save << " " << _restHSurfCurvEnable    ;
404   save << " " << _restHEdgeAngleFactor   ;
405   save << " " << _restHEdgeAngleEnable   ;
406   save << " " << _restHSurfMeshCurvFactor;
407   save << " " << _restHSurfMeshCurvEnable;
408   save << " " << _keepExistingEdges      ;
409   save << " " << _makeGroupsOfSurfaces   ;
410   save << " " << _fixedEdgeGroupID       ;
411   save << " " << _loadOnCancel           ;
412
413   return save;
414 }
415
416 //=============================================================================
417 /*!
418  *
419  */
420 //=============================================================================
421
422 std::istream & NETGENPlugin_RemesherHypothesis_2D::LoadFrom(std::istream & load)
423 {
424   NETGENPlugin_Hypothesis::LoadFrom( load );
425   if ( !load )
426     load.clear(ios::badbit | load.rdstate());
427
428   load >> _ridgeAngle;
429
430   if ( !load )
431     _ridgeAngle = DefaultRidgeAngle();
432
433   load >> _edgeCornerAngle;
434   if ( !load )
435     _edgeCornerAngle = DefaultEdgeCornerAngle();
436
437   load >> _chartAngle;
438   if ( !load )
439     _chartAngle = DefaultChartAngle();
440
441   load >> _outerChartAngle;
442   if ( !load )
443     _outerChartAngle = DefaultOuterChartAngle();
444
445   load >> _restHChartDistFactor;
446   if ( !load )
447     _restHChartDistFactor = DefaultRestHChartDistFactor();
448
449   load >> _restHChartDistEnable;
450   if ( !load )
451     _restHChartDistEnable = DefaultRestHChartDistEnable();
452
453   load >> _restHLineLengthFactor;
454   if ( !load )
455     _restHLineLengthFactor = DefaultRestHLineLengthFactor();
456
457   load >> _restHLineLengthEnable;
458   if ( !load )
459     _restHLineLengthEnable = DefaultRestHLineLengthEnable();
460
461   load >> _restHCloseEdgeFactor;
462   if ( !load )
463     _restHCloseEdgeFactor = DefaultRestHCloseEdgeFactor();
464
465   load >> _restHCloseEdgeEnable;
466   if ( !load )
467     _restHCloseEdgeEnable = DefaultRestHCloseEdgeEnable();
468
469   load >> _restHSurfCurvFactor;
470   if ( !load )
471     _restHSurfCurvFactor = DefaultRestHSurfCurvFactor();
472
473   load >> _restHSurfCurvEnable;
474   if ( !load )
475     _restHSurfCurvEnable = DefaultRestHSurfCurvEnable();
476
477   load >> _restHEdgeAngleFactor;
478   if ( !load )
479     _restHEdgeAngleFactor = DefaultRestHEdgeAngleFactor();
480
481   load >> _restHEdgeAngleEnable;
482   if ( !load )
483     _restHEdgeAngleEnable = DefaultRestHEdgeAngleEnable();
484
485   load >> _restHSurfMeshCurvFactor;
486   if ( !load )
487     _restHSurfMeshCurvFactor = DefaultRestHSurfMeshCurvFactor();
488
489   load >> _restHSurfMeshCurvEnable;
490   if ( !load )
491     _restHSurfMeshCurvEnable = DefaultRestHSurfMeshCurvEnable();
492
493   load >> _keepExistingEdges;
494   if ( !load )
495     _keepExistingEdges = DefaultKeepExistingEdges();
496
497   load >> _makeGroupsOfSurfaces;
498   if ( !load )
499     _makeGroupsOfSurfaces = DefaultMakeGroupsOfSurfaces();
500
501   load >> _fixedEdgeGroupID;
502   if ( !load )
503     _fixedEdgeGroupID = -1;
504
505   load >> _loadOnCancel;
506   if ( !load )
507     _loadOnCancel = false;
508
509   return load;
510 }