Salome HOME
f9bf94baac5e277142b55d6f24976959051c77ad
[plugins/ghs3dplugin.git] / src / GHS3DPlugin / GHS3DPlugin_Hypothesis_i.cxx
1 // Copyright (C) 2004-2022  CEA/DEN, EDF R&D
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 // File      : GHS3DPlugin_Hypothesis_i.cxx
21 // Created   : Wed Apr  2 13:53:01 2008
22 // Author    : Edward AGAPOV (eap)
23 //
24 #include "GHS3DPlugin_Hypothesis_i.hxx"
25
26 #include <SMESH_Gen.hxx>
27 #include <SMESH_PythonDump.hxx>
28
29 #include <Utils_CorbaException.hxx>
30 #include <utilities.h>
31 #include <SMESH_Mesh_i.hxx>
32 #include <SMESH_Group_i.hxx>
33 #include <SMESH_Gen_i.hxx>
34 #include <SMESHDS_GroupBase.hxx>
35
36
37 using namespace std;
38
39 //=======================================================================
40 //function : GHS3DPlugin_Hypothesis_i
41 //=======================================================================
42
43 GHS3DPlugin_Hypothesis_i::GHS3DPlugin_Hypothesis_i (PortableServer::POA_ptr thePOA,
44                                                     ::SMESH_Gen*            theGenImpl)
45   : SALOME::GenericObj_i( thePOA ), 
46     SMESH_Hypothesis_i( thePOA )
47 {
48   myBaseImpl = new ::GHS3DPlugin_Hypothesis (theGenImpl->GetANewId(),
49                                              theGenImpl);
50 }
51
52 //=======================================================================
53 //function : ~GHS3DPlugin_Hypothesis_i
54 //=======================================================================
55
56 GHS3DPlugin_Hypothesis_i::~GHS3DPlugin_Hypothesis_i()
57 {
58 }
59
60 //=======================================================================
61 //function : SetToMeshHoles
62 //=======================================================================
63
64 void GHS3DPlugin_Hypothesis_i::SetToMeshHoles(CORBA::Boolean toMesh)
65 {
66   ASSERT(myBaseImpl);
67   this->GetImpl()->SetToMeshHoles(toMesh);
68   SMESH::TPythonDump() << _this() << ".SetToMeshHoles( " << toMesh << " )";
69 }
70
71 //=======================================================================
72 //function : GetToMeshHoles
73 //=======================================================================
74
75 CORBA::Boolean GHS3DPlugin_Hypothesis_i::GetToMeshHoles()
76 {
77   ASSERT(myBaseImpl);
78   return this->GetImpl()->GetToMeshHoles();
79 }
80
81 //=============================================================================
82 void GHS3DPlugin_Hypothesis_i::SetMinSize(CORBA::Double theMinSize)
83 {
84   if ( GetMinSize() != theMinSize ) {
85     this->GetImpl()->SetMinSize( theMinSize );
86     SMESH::TPythonDump() << _this() << ".SetMinSize( " << theMinSize << " )";
87   }
88 }
89
90 //=============================================================================
91 CORBA::Double GHS3DPlugin_Hypothesis_i::GetMinSize()
92 {
93   return this->GetImpl()->GetMinSize();
94 }
95
96 //=============================================================================
97 CORBA::Double GHS3DPlugin_Hypothesis_i::GetMinSizeDefault()
98 {
99   return this->GetImpl()->GetMinSizeDefault();
100 }
101
102 //=============================================================================
103 void GHS3DPlugin_Hypothesis_i::SetMaxSize(CORBA::Double theMaxSize)
104 {
105   if ( GetMaxSize() != theMaxSize ) {
106     this->GetImpl()->SetMaxSize( theMaxSize );
107     SMESH::TPythonDump() << _this() << ".SetMaxSize( " << theMaxSize << " )";
108   }
109 }
110
111 //=============================================================================
112 CORBA::Double GHS3DPlugin_Hypothesis_i::GetMaxSize()
113 {
114   return this->GetImpl()->GetMaxSize();
115 }
116
117 //=============================================================================
118 CORBA::Double GHS3DPlugin_Hypothesis_i::GetMaxSizeDefault()
119 {
120   return this->GetImpl()->GetMaxSizeDefault();
121 }
122
123 //=============================================================================
124 void GHS3DPlugin_Hypothesis_i::SetMinMaxSizeDefault( CORBA::Double theMinSize,
125                                                      CORBA::Double theMaxSize )
126 {
127   this->GetImpl()->SetMinMaxSizeDefault( theMinSize, theMaxSize );
128 }
129
130 //=============================================================================
131 /*!
132  *  Activate/deactivate volume proximity computation
133  */
134 void GHS3DPlugin_Hypothesis_i::SetVolumeProximity( CORBA::Boolean toUse )
135 {
136   if ( GetVolumeProximity() != toUse )
137   {
138     this->GetImpl()->SetUseVolumeProximity( toUse );
139     SMESH::TPythonDump() << _this() << ".SetVolumeProximity( " << toUse << " )";
140   }
141 }
142
143 CORBA::Boolean GHS3DPlugin_Hypothesis_i::GetVolumeProximity()
144 {
145   return this->GetImpl()->GetUseVolumeProximity();
146 }
147
148
149 //=============================================================================
150 /*!
151  * Set number of surface element layers to be generated due to volume proximity
152  */
153 void GHS3DPlugin_Hypothesis_i::SetNbVolumeProximityLayers( CORBA::Short nbLayers )
154 {
155   if ( GetNbVolumeProximityLayers() != nbLayers )
156   {
157     this->GetImpl()->SetNbVolumeProximityLayers( nbLayers );
158     SMESH::TPythonDump() << _this() << ".SetNbVolumeProximityLayers( " << nbLayers << " )";
159   }
160 }
161
162 CORBA::Short GHS3DPlugin_Hypothesis_i::GetNbVolumeProximityLayers()
163 {
164   return (CORBA::Short) this->GetImpl()->GetNbVolumeProximityLayers();
165 }
166
167 //=======================================================================
168 //function : SetToMakeGroupsOfDomains
169 //=======================================================================
170
171 void GHS3DPlugin_Hypothesis_i::SetToMakeGroupsOfDomains(CORBA::Boolean toMakeGroups)
172 {
173   ASSERT(myBaseImpl);
174   this->GetImpl()->SetToMakeGroupsOfDomains(toMakeGroups);
175   SMESH::TPythonDump() << _this() << ".SetToMakeGroupsOfDomains( " << toMakeGroups << " )";
176 }
177
178 //=======================================================================
179 //function : GetToMakeGroupsOfDomains
180 //=======================================================================
181
182 CORBA::Boolean GHS3DPlugin_Hypothesis_i::GetToMakeGroupsOfDomains()
183 {
184   ASSERT(myBaseImpl);
185   return this->GetImpl()->GetToMakeGroupsOfDomains();
186 }
187
188 //=======================================================================
189 //function : SetMaximumMemory
190 //=======================================================================
191
192 void GHS3DPlugin_Hypothesis_i::SetMaximumMemory(CORBA::Float MB)
193 {
194   if ( MB == 0 )
195     THROW_SALOME_CORBA_EXCEPTION( "Invalid memory size",SALOME::BAD_PARAM );
196   ASSERT(myBaseImpl);
197   this->GetImpl()->SetMaximumMemory(MB);
198   SMESH::TPythonDump() << _this() << ".SetMaximumMemory( " << MB << " )";
199 }
200
201 //=======================================================================
202 //function : GetMaximumMemory
203 //=======================================================================
204
205 CORBA::Float GHS3DPlugin_Hypothesis_i::GetMaximumMemory()
206 {
207   ASSERT(myBaseImpl);
208   return this->GetImpl()->GetMaximumMemory();
209 }
210
211 //=======================================================================
212 //function : SetInitialMemory
213 //=======================================================================
214
215 void GHS3DPlugin_Hypothesis_i::SetInitialMemory(CORBA::Float MB)
216 {
217   if ( MB == 0 )
218     THROW_SALOME_CORBA_EXCEPTION( "Invalid memory size",SALOME::BAD_PARAM );
219   ASSERT(myBaseImpl);
220   this->GetImpl()->SetInitialMemory(MB);
221   SMESH::TPythonDump() << _this() << ".SetInitialMemory( " << MB << " )";
222 }
223
224 //=======================================================================
225 //function : GetInitialMemory
226 //=======================================================================
227
228 CORBA::Float GHS3DPlugin_Hypothesis_i::GetInitialMemory()
229 {
230   ASSERT(myBaseImpl);
231   return this->GetImpl()->GetInitialMemory();
232 }
233
234 //=======================================================================
235 //function : SetOptimizationLevel
236 //=======================================================================
237
238 void GHS3DPlugin_Hypothesis_i::SetOptimizationLevel(CORBA::Short level)
239 {
240   ::GHS3DPlugin_Hypothesis::OptimizationLevel l =
241     (::GHS3DPlugin_Hypothesis::OptimizationLevel) level;
242   if ( l < ::GHS3DPlugin_Hypothesis::None ||
243        l > ::GHS3DPlugin_Hypothesis::Strong )
244     THROW_SALOME_CORBA_EXCEPTION( "Invalid optimization level", SALOME::BAD_PARAM );
245     
246   ASSERT(myBaseImpl);
247   this->GetImpl()->SetOptimizationLevel(l);
248   SMESH::TPythonDump() << _this() << ".SetOptimizationLevel( " << level << " )";
249 }
250
251 //=======================================================================
252 //function : GetOptimizationLevel
253 //=======================================================================
254
255 CORBA::Short GHS3DPlugin_Hypothesis_i::GetOptimizationLevel()
256 {
257   ASSERT(myBaseImpl);
258   return this->GetImpl()->GetOptimizationLevel();
259 }
260
261 //=======================================================================
262 //function : SetAlgorithm
263 //=======================================================================
264 void GHS3DPlugin_Hypothesis_i::SetAlgorithm(CORBA::Short algoId)
265
266   ::GHS3DPlugin_Hypothesis::ImplementedAlgorithms algo =
267     (::GHS3DPlugin_Hypothesis::ImplementedAlgorithms) algoId;
268   if ( algo != ::GHS3DPlugin_Hypothesis::MGTetra && algo != ::GHS3DPlugin_Hypothesis::MGTetraHPC )
269     THROW_SALOME_CORBA_EXCEPTION( "Invalid algorithm type", SALOME::BAD_PARAM );
270
271   ASSERT(myBaseImpl);
272   this->GetImpl()->SetAlgorithm(algo);
273   SMESH::TPythonDump() << _this() << ".SetAlgorithm( " << algoId << " )";
274 }
275
276 //=======================================================================
277 //function : GetAlgorithm
278 //=======================================================================
279 CORBA::Short GHS3DPlugin_Hypothesis_i::GetAlgorithm()
280 {
281   ASSERT(myBaseImpl);
282   return this->GetImpl()->GetAlgorithm();
283 }
284
285 //=======================================================================
286 //function : SetUseNumOfThreads
287 //=======================================================================
288 void GHS3DPlugin_Hypothesis_i::SetUseNumOfThreads(CORBA::Boolean setThread)
289
290   ASSERT(myBaseImpl);
291   this->GetImpl()->SetUseNumOfThreads(setThread);
292   SMESH::TPythonDump() << _this() << ".SetUseNumOfThreads( " << setThread << " )";
293 }
294
295 //=======================================================================
296 //function : GetUseNumOfThreads
297 //=======================================================================
298 CORBA::Boolean GHS3DPlugin_Hypothesis_i::GetUseNumOfThreads()
299 {
300   ASSERT(myBaseImpl);
301   return this->GetImpl()->GetUseNumOfThreads();
302 }
303
304 //=======================================================================
305 //function : SetNumOfThreads
306 //=======================================================================
307 void GHS3DPlugin_Hypothesis_i::SetNumOfThreads(CORBA::Short numOfThreads)
308
309   ASSERT(myBaseImpl);
310   this->GetImpl()->SetNumOfThreads(numOfThreads);
311   SMESH::TPythonDump() << _this() << ".SetNumOfThreads( " << numOfThreads << " )";
312 }
313
314 //=======================================================================
315 //function : GetNumOfThreads
316 //=======================================================================
317 CORBA::Short GHS3DPlugin_Hypothesis_i::GetNumOfThreads()
318 {
319   ASSERT(myBaseImpl);
320   return this->GetImpl()->GetNumOfThreads();
321 }
322
323 //=======================================================================
324 //function : SetNumOfThreads
325 //=======================================================================
326 void GHS3DPlugin_Hypothesis_i::SetPthreadMode(CORBA::Short pThreadMode)
327
328   ::GHS3DPlugin_Hypothesis::PThreadMode mode =
329     (::GHS3DPlugin_Hypothesis::PThreadMode) pThreadMode;
330   
331    if ( mode < ::GHS3DPlugin_Hypothesis::PThreadNone ||
332        mode > ::GHS3DPlugin_Hypothesis::Safe )
333     THROW_SALOME_CORBA_EXCEPTION( "Invalid pthreadMode type", SALOME::BAD_PARAM );
334
335
336   ASSERT(myBaseImpl);
337   this->GetImpl()->SetPthreadMode(mode);
338   SMESH::TPythonDump() << _this() << ".SetPthreadMode( " << pThreadMode << " )";
339 }
340
341 //=======================================================================
342 //function : GetNumOfThreads
343 //=======================================================================
344 CORBA::Short GHS3DPlugin_Hypothesis_i::GetPthreadMode()
345 {
346   ASSERT(myBaseImpl);
347   return this->GetImpl()->GetPthreadMode();
348 }
349
350 //=======================================================================
351 //function : SetNumOfThreads
352 //=======================================================================
353 void GHS3DPlugin_Hypothesis_i::SetParallelMode(CORBA::Short parallelMode)
354
355     ::GHS3DPlugin_Hypothesis::ParallelMode mode =
356     (::GHS3DPlugin_Hypothesis::ParallelMode) parallelMode;
357   
358    if ( mode < ::GHS3DPlugin_Hypothesis::ParallelNone ||
359        mode > ::GHS3DPlugin_Hypothesis::ParallelAggressive )
360     THROW_SALOME_CORBA_EXCEPTION( "Invalid parallelMode type", SALOME::BAD_PARAM );
361
362   ASSERT(myBaseImpl);
363   this->GetImpl()->SetParallelMode(mode);
364   SMESH::TPythonDump() << _this() << ".SetParallelMode( " << parallelMode << " )";
365 }
366
367 //=======================================================================
368 //function : GetNumOfThreads
369 //=======================================================================
370 CORBA::Short GHS3DPlugin_Hypothesis_i::GetParallelMode()
371 {
372   ASSERT(myBaseImpl);
373   return this->GetImpl()->GetParallelMode();
374 }
375
376 //=======================================================================
377 //function : SetWorkingDirectory
378 //=======================================================================
379
380 void GHS3DPlugin_Hypothesis_i::SetWorkingDirectory(const char* path)
381 {
382   if (!path )
383     THROW_SALOME_CORBA_EXCEPTION( "Null working directory",SALOME::BAD_PARAM );
384
385   string file(path);
386   const char lastChar = *file.rbegin();
387 #ifdef WIN32
388   if ( lastChar != '\\' ) file += '\\';
389 #else
390   if ( lastChar != '/' ) file += '/';
391 #endif
392   file += "GHS3D.log";
393   SMESH_Mesh_i::PrepareForWriting (file.c_str());
394
395   ASSERT(myBaseImpl);
396   this->GetImpl()->SetWorkingDirectory(path);
397   SMESH::TPythonDump() << _this() << ".SetWorkingDirectory( '" << path << "' )";
398 }
399
400 //=======================================================================
401 //function : GetWorkingDirectory
402 //=======================================================================
403
404 char* GHS3DPlugin_Hypothesis_i::GetWorkingDirectory()
405 {
406   ASSERT(myBaseImpl);
407   return CORBA::string_dup( this->GetImpl()->GetWorkingDirectory().c_str() );
408 }
409
410 //=======================================================================
411 //function : SetKeepFiles
412 //=======================================================================
413
414 void GHS3DPlugin_Hypothesis_i::SetKeepFiles(CORBA::Boolean toKeep)
415 {
416   ASSERT(myBaseImpl);
417   this->GetImpl()->SetKeepFiles(toKeep);
418   SMESH::TPythonDump() << _this() << ".SetKeepFiles( " << toKeep << " )";
419 }
420
421 //=======================================================================
422 //function : GetKeepFiles
423 //=======================================================================
424
425 CORBA::Boolean GHS3DPlugin_Hypothesis_i::GetKeepFiles()
426 {
427   ASSERT(myBaseImpl);
428   return this->GetImpl()->GetKeepFiles();
429 }
430
431 //=======================================================================
432 //function : SetVerboseLevel
433 //=======================================================================
434
435 void GHS3DPlugin_Hypothesis_i::SetVerboseLevel(CORBA::Short level)
436 {
437   if (level < 0 || level > 10 )
438     THROW_SALOME_CORBA_EXCEPTION( "Invalid verbose level, valid range is [0-10]",
439                                   SALOME::BAD_PARAM );
440   ASSERT(myBaseImpl);
441   this->GetImpl()->SetVerboseLevel(level);
442   SMESH::TPythonDump() << _this() << ".SetVerboseLevel( " << level << " )";
443 }
444
445 //=======================================================================
446 //function : GetVerboseLevel
447 //=======================================================================
448
449 CORBA::Short GHS3DPlugin_Hypothesis_i::GetVerboseLevel()
450 {
451   ASSERT(myBaseImpl);
452   return this->GetImpl()->GetVerboseLevel();
453 }
454
455 //=======================================================================
456 //function : SetToCreateNewNodes
457 //=======================================================================
458
459 void GHS3DPlugin_Hypothesis_i::SetToCreateNewNodes(CORBA::Boolean toCreate)
460 {
461   ASSERT(myBaseImpl);
462   this->GetImpl()->SetToCreateNewNodes(toCreate);
463   SMESH::TPythonDump() << _this() << ".SetToCreateNewNodes( " << toCreate << " )";
464 }
465
466 //=======================================================================
467 //function : GetToCreateNewNodes
468 //=======================================================================
469
470 CORBA::Boolean GHS3DPlugin_Hypothesis_i::GetToCreateNewNodes()
471 {
472   ASSERT(myBaseImpl);
473   return this->GetImpl()->GetToCreateNewNodes();
474 }
475
476 //=======================================================================
477 //function : SetToUseBoundaryRecoveryVersion
478 //=======================================================================
479
480 void GHS3DPlugin_Hypothesis_i::SetToUseBoundaryRecoveryVersion(CORBA::Boolean toUse)
481 {
482   ASSERT(myBaseImpl);
483   this->GetImpl()->SetToUseBoundaryRecoveryVersion(toUse);
484   SMESH::TPythonDump() << _this() << ".SetToUseBoundaryRecoveryVersion( " << toUse << " )";
485 }
486
487 //=======================================================================
488 //function : GetToUseBoundaryRecoveryVersion
489 //=======================================================================
490
491 CORBA::Boolean GHS3DPlugin_Hypothesis_i::GetToUseBoundaryRecoveryVersion()
492 {
493   ASSERT(myBaseImpl);
494   return this->GetImpl()->GetToUseBoundaryRecoveryVersion();
495 }
496
497 //=======================================================================
498 //function : SetFEMCorrection
499 //=======================================================================
500
501 void GHS3DPlugin_Hypothesis_i::SetFEMCorrection(CORBA::Boolean toUseFem)
502 {
503   ASSERT(myBaseImpl);
504   this->GetImpl()->SetFEMCorrection(toUseFem);
505   SMESH::TPythonDump() << _this() << ".SetFEMCorrection( " << toUseFem << " )";
506 }
507
508 //=======================================================================
509 //function : GetFEMCorrection
510 //=======================================================================
511
512 CORBA::Boolean GHS3DPlugin_Hypothesis_i::GetFEMCorrection()
513 {
514   ASSERT(myBaseImpl);
515   return this->GetImpl()->GetFEMCorrection();
516 }
517
518 //=======================================================================
519 //function : SetToRemoveCentralPoint
520 //=======================================================================
521
522 void GHS3DPlugin_Hypothesis_i::SetToRemoveCentralPoint(CORBA::Boolean toRemove)
523 {
524   ASSERT(myBaseImpl);
525   this->GetImpl()->SetToRemoveCentralPoint(toRemove);
526   SMESH::TPythonDump() << _this() << ".SetToRemoveCentralPoint( " << toRemove << " )";
527 }
528
529 //=======================================================================
530 //function : GetToRemoveCentralPoint
531 //=======================================================================
532
533 CORBA::Boolean GHS3DPlugin_Hypothesis_i::GetToRemoveCentralPoint()
534 {
535   ASSERT(myBaseImpl);
536   return this->GetImpl()->GetToRemoveCentralPoint();
537 }
538
539 //=======================================================================
540 //function : SetTextOption
541 //=======================================================================
542
543 void GHS3DPlugin_Hypothesis_i::SetTextOption(const char* option)
544 {
545   SetAdvancedOption(option);
546 }
547
548 //=======================================================================
549 //function : GetTextOption
550 //=======================================================================
551
552 char* GHS3DPlugin_Hypothesis_i::GetTextOption()
553 {
554   return GetAdvancedOption();
555 }
556
557 //=======================================================================
558 //function : SetAdvancedOption
559 //=======================================================================
560
561 // void GHS3DPlugin_Hypothesis_i::SetAdvancedOption(const char* option)
562 // {
563 //   ASSERT(myBaseImpl);
564 //   this->GetImpl()->SetAdvancedOption(option);
565 //   SMESH::TPythonDump() << _this() << ".SetAdvancedOption( '" << option << "' )";
566 // }
567
568 //=======================================================================
569 //function : GetAdvancedOption
570 //=======================================================================
571
572 char* GHS3DPlugin_Hypothesis_i::GetAdvancedOption()
573 {
574   ASSERT(myBaseImpl);
575   return CORBA::string_dup( this->GetImpl()->GetAdvancedOption().c_str() );
576 }
577
578 //=============================================================================
579
580 void GHS3DPlugin_Hypothesis_i::SetOptionValue(const char* optionName, const char* optionValue)
581 {
582   ASSERT(myBaseImpl);
583   try {
584     std::string name( optionName );
585     if ( !optionValue || !optionValue[0] )
586       UnsetOption( optionName );
587
588     // basic options (visible in Advanced table)
589
590     else if ( name == "verbose" )
591       SetVerboseLevel((CORBA::Short) GetImpl()->ToInt( optionValue ));
592
593     else if ( name == "max_memory" )
594       SetMaximumMemory((CORBA::Short) GetImpl()->ToInt( optionValue ));
595
596     else if ( name == "automatic_memory" )
597       SetInitialMemory((CORBA::Short) GetImpl()->ToInt( optionValue ));
598
599     else if ( name == "no_initial_central_point" && // optimizer
600               strcmp( GetImpl()->GetName(), ::GHS3DPlugin_Hypothesis::GetHypType() ) != 0 )
601     {
602       //if ( strcmp( optionValue, ::GHS3DPlugin_Hypothesis::NoValue() ) == 0 )
603       if ( !optionValue[0] )
604         SetToRemoveCentralPoint( true );
605       else
606         SetToRemoveCentralPoint( GetImpl()->ToBool( optionValue ));
607     }
608     else if ( name == "no_internal_points"  && // optimizer
609               strcmp( GetImpl()->GetName(), ::GHS3DPlugin_Hypothesis::GetHypType() ) != 0)
610     {
611       //if ( strcmp( optionValue, ::GHS3DPlugin_Hypothesis::NoValue() ) == 0 )
612       if ( !optionValue[0] )
613         SetToRemoveCentralPoint( true );
614       else
615         SetToCreateNewNodes( GetImpl()->ToBool( optionValue ));
616     }
617     else if ( name == "min_size" )
618       SetMinSize( GetImpl()->ToDbl( optionValue ));
619
620     else if ( name == "max_size" )
621       SetMaxSize( GetImpl()->ToDbl( optionValue ));
622
623     else if ( name == "gradation" )
624       SetGradation( GetImpl()->ToDbl( optionValue ));
625
626     else if ( name == "volume_proximity_layers" )
627       SetNbVolumeProximityLayers((CORBA::Short) GetImpl()->ToInt( optionValue ));
628
629     else if ( name == "components" )
630       SetToMeshHoles( strncmp( "all", optionValue, 3 ) == 0 );
631
632     // advanced options (for backward compatibility)
633     // else if ( name == "create_tag_on_collision" ||
634     //           name == "tiny_edge_respect_geometry" )
635     //   AddOption( optionName, optionValue );
636
637     else {
638       bool valueChanged = true;
639       try {
640         valueChanged = ( this->GetImpl()->GetOptionValue( name ) != optionValue );
641       }
642       catch ( std::invalid_argument& ) {
643       }
644       if ( valueChanged )
645       {
646         this->GetImpl()->SetOptionValue(optionName, optionValue);
647         SMESH::TPythonDump() << _this() << ".SetOptionValue( '" << optionName << "', '" << optionValue << "' )";
648       }
649     }
650   } catch (const std::invalid_argument& ex) {
651     THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM );
652   } catch (SALOME_Exception& ex) {
653     THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM );
654   }
655 }
656
657 //=============================================================================
658
659 char* GHS3DPlugin_Hypothesis_i::GetOptionValue(const char* optionName)
660 {
661   ASSERT(myBaseImpl);
662   try {
663     bool isDefault;
664     return CORBA::string_dup(this->GetImpl()->GetOptionValue(optionName,&isDefault).c_str());
665   } catch (const std::invalid_argument& ex) {
666     THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM );
667   } catch (SALOME_Exception& ex) {
668     THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM );
669   }
670   return 0;
671 }
672
673 //=============================================================================
674
675 void GHS3DPlugin_Hypothesis_i::UnsetOption(const char* optionName) {
676   ASSERT(myBaseImpl);
677   if ( !GetImpl()->GetOptionValue( optionName ).empty() )
678   {
679     this->GetImpl()->ClearOption(optionName);
680     SMESH::TPythonDump() << _this() << ".UnsetOption( '" << optionName << "' )";
681   }
682 }
683
684 //=============================================================================
685
686 GHS3DPlugin::string_array* GHS3DPlugin_Hypothesis_i::GetOptionValues()
687 {
688   GHS3DPlugin::string_array_var result = new GHS3DPlugin::string_array();
689
690   const ::GHS3DPlugin_Hypothesis::TOptionValues & opts = this->GetImpl()->GetOptionValues();
691   result->length((CORBA::ULong) opts.size());
692   int i=0;
693
694   bool isDefault;
695   ::GHS3DPlugin_Hypothesis::TOptionValues::const_iterator opIt = opts.begin();
696   for (; opIt != opts.end(); ++opIt, ++i)
697   {
698     string name_value_type = opIt->first;
699     //if (!opIt->second.empty())
700     {
701       name_value_type += ":";
702       name_value_type += GetImpl()->GetOptionValue( opIt->first, &isDefault );
703       name_value_type += isDefault ? ":0" : ":1";
704     }
705     result[i] = CORBA::string_dup(name_value_type.c_str());
706   }
707
708   return result._retn();
709 }
710
711 //=============================================================================
712
713 GHS3DPlugin::string_array* GHS3DPlugin_Hypothesis_i::GetAdvancedOptionValues()
714 {
715   GHS3DPlugin::string_array_var result = new GHS3DPlugin::string_array();
716
717   const ::GHS3DPlugin_Hypothesis::TOptionValues & custom_opts = this->GetImpl()->GetCustomOptionValues();
718   result->length((CORBA::ULong) custom_opts.size());
719   int i=0;
720
721   ::GHS3DPlugin_Hypothesis::TOptionValues::const_iterator opIt = custom_opts.begin();
722   for (; opIt != custom_opts.end(); ++opIt, ++i) {
723     string name_value_type = opIt->first;
724     if (!opIt->second.empty()) {
725       name_value_type += ":";
726       name_value_type += opIt->second;
727       name_value_type += ":1"; // user defined
728     }
729     result[i] = CORBA::string_dup(name_value_type.c_str());
730   }
731   return result._retn();
732 }
733
734 //=============================================================================
735
736 void GHS3DPlugin_Hypothesis_i::SetOptionValues(const GHS3DPlugin::string_array& options)
737 {
738   for (CORBA::ULong i = 0; i < options.length(); ++i)
739   {
740     string name_value_type = options[i].in();
741     if(name_value_type.empty())
742       continue;
743     size_t colonPos = name_value_type.find(':');
744     string name, value;
745     if (colonPos == string::npos) // ':' not found
746       name = name_value_type;
747     else {
748       name = name_value_type.substr(0, colonPos);
749       if (colonPos < name_value_type.size() - 1 && name_value_type[colonPos] != ' ') {
750         string value_type = name_value_type.substr(colonPos + 1);
751         colonPos = value_type.find(':');
752         value = value_type.substr(0, colonPos);
753         if (colonPos < value_type.size() - 1 && value_type[colonPos] != ' ')
754           if ( value_type.substr(colonPos + 1) == "0" ) // is default
755             value.clear();
756       }
757     }
758     SetOptionValue(name.c_str(), value.c_str());
759   }
760 }
761
762 //=============================================================================
763
764 void GHS3DPlugin_Hypothesis_i::SetAdvancedOptionValues(const GHS3DPlugin::string_array& options)
765 {
766   SMESH::TPythonDump dump;
767
768   string optionsAndValues;
769   for ( CORBA::ULong i = 0; i < options.length(); ++i) {
770     string name_value_type = options[i].in();
771     if(name_value_type.empty())
772       continue;
773     size_t colonPos = name_value_type.find(':');
774     string name, value;
775     if (colonPos == string::npos) // ':' not found
776       name = name_value_type;
777     else {
778       name = name_value_type.substr(0, colonPos);
779       if (colonPos < name_value_type.size() - 1 && name_value_type[colonPos] != ' ') {
780         string value_type = name_value_type.substr(colonPos + 1);
781         colonPos = value_type.find(':');
782         value = value_type.substr(0, colonPos);
783       }
784     }
785     AddOption(name.c_str(), value.c_str());
786
787     optionsAndValues += name + " " + value + " ";
788   }
789
790   if ( !optionsAndValues.empty() )
791     dump << _this() << ".SetAdvancedOptions( '" << optionsAndValues.c_str() << "' )";
792 }
793
794 //=============================================================================
795
796 void GHS3DPlugin_Hypothesis_i::SetAdvancedOption(const char* optionsAndValues)
797 {
798   if ( !optionsAndValues ) return;
799
800   SMESH::TPythonDump dump;
801
802   std::istringstream strm( optionsAndValues );
803   std::istream_iterator<std::string> sIt( strm ), sEnd;
804   for ( int nbPairs = 0; sIt != sEnd; ++nbPairs )
805   {
806     std::string option = *sIt;
807     if ( ++sIt != sEnd )
808     {
809       std::string value = *sIt;
810       ++sIt;
811       AddOption( option.c_str(), value.c_str() );
812     }
813     else
814     {
815       if ( nbPairs > 0 )
816         THROW_SALOME_CORBA_EXCEPTION( "Uneven number of options and values" ,SALOME::BAD_PARAM );
817       AddOption( option.c_str(), "" );
818     }
819   }
820   dump << _this() << ".SetAdvancedOption( '" << optionsAndValues << "' )";
821 }
822
823 //=============================================================================
824
825 void GHS3DPlugin_Hypothesis_i::AddOption(const char* optionName, const char* optionValue)
826 {
827   ASSERT(myBaseImpl);
828   bool valueChanged = ( !this->GetImpl()->HasOptionDefined(optionName) ||
829                         this->GetImpl()->GetOptionValue(optionName) != optionValue );
830   if (valueChanged) {
831     this->GetImpl()->SetOptionValue(optionName, optionValue);
832     SMESH::TPythonDump() << _this() << ".SetOptionValue( '" << optionName << "', '" << optionValue << "' )";
833   }
834 }
835
836 //=============================================================================
837
838 char* GHS3DPlugin_Hypothesis_i::GetOption(const char* optionName)
839 {
840   ASSERT(myBaseImpl);
841   return CORBA::string_dup(this->GetImpl()->GetOptionValue(optionName).c_str());
842 }
843
844 //=======================================================================
845 //function : SetGradation
846 //=======================================================================
847
848 void GHS3DPlugin_Hypothesis_i::SetGradation(CORBA::Double gradation)
849 {
850   ASSERT(myBaseImpl);
851   if (gradation != GetGradation()) {
852     this->GetImpl()->SetGradation(gradation);
853     SMESH::TPythonDump() << _this() << ".SetGradation( " << gradation << " )";
854   }
855 }
856
857 //=======================================================================
858 //function : GetGradation
859 //=======================================================================
860
861 CORBA::Double GHS3DPlugin_Hypothesis_i::GetGradation()
862 {
863   ASSERT(myBaseImpl);
864   return this->GetImpl()->GetGradation();
865 }
866
867 //=======================================================================
868 //function : SetStandardOutputLog
869 //=======================================================================
870
871 void GHS3DPlugin_Hypothesis_i::SetStandardOutputLog(CORBA::Boolean logInStandardOutput)
872 {
873   ASSERT(myBaseImpl);
874   this->GetImpl()->SetStandardOutputLog(logInStandardOutput);
875   SMESH::TPythonDump() << _this() << ".SetStandardOutputLog( " << logInStandardOutput << " )";
876 }
877
878 //=======================================================================
879 //function : GetStandardOutputLog
880 //=======================================================================
881
882 CORBA::Boolean GHS3DPlugin_Hypothesis_i::GetStandardOutputLog()
883 {
884   ASSERT(myBaseImpl);
885   return this->GetImpl()->GetStandardOutputLog();
886 }
887
888 //=======================================================================
889 //function : SetRemoveLogOnSuccess
890 //=======================================================================
891
892 void GHS3DPlugin_Hypothesis_i::SetRemoveLogOnSuccess(CORBA::Boolean removeLogOnSuccess)
893 {
894   ASSERT(myBaseImpl);
895   this->GetImpl()->SetRemoveLogOnSuccess(removeLogOnSuccess);
896   SMESH::TPythonDump() << _this() << ".SetRemoveLogOnSuccess( " << removeLogOnSuccess << " )";
897 }
898
899 //=======================================================================
900 //function : GetRemoveLogOnSuccess
901 //=======================================================================
902
903 CORBA::Boolean GHS3DPlugin_Hypothesis_i::GetRemoveLogOnSuccess()
904 {
905   ASSERT(myBaseImpl);
906   return this->GetImpl()->GetRemoveLogOnSuccess();
907 }
908
909 //=======================================================================
910 //function : SetEnforcedVertex
911 //=======================================================================
912
913 bool GHS3DPlugin_Hypothesis_i::SetEnforcedVertex(CORBA::Double x, CORBA::Double y, CORBA::Double z, CORBA::Double size)
914 {
915   ASSERT(myBaseImpl);
916   return p_SetEnforcedVertex(size, x, y, z);
917 }
918
919 bool GHS3DPlugin_Hypothesis_i::SetEnforcedVertexNamed(CORBA::Double x, CORBA::Double y, CORBA::Double z, CORBA::Double size, const char* theVertexName)
920 {
921   ASSERT(myBaseImpl);
922   return p_SetEnforcedVertex(size, x, y, z, theVertexName, "", "");
923 }
924
925 bool GHS3DPlugin_Hypothesis_i::SetEnforcedVertexWithGroup(CORBA::Double x, CORBA::Double y, CORBA::Double z, CORBA::Double size, const char* theGroupName)
926 {
927   ASSERT(myBaseImpl);
928   return p_SetEnforcedVertex(size, x, y, z, "", "", theGroupName);
929 }
930
931 bool GHS3DPlugin_Hypothesis_i::SetEnforcedVertexNamedWithGroup(CORBA::Double x, CORBA::Double y, CORBA::Double z, CORBA::Double size, const char* theVertexName, const char* theGroupName)
932 {
933   ASSERT(myBaseImpl);
934   return p_SetEnforcedVertex(size, x, y, z, theVertexName, "", theGroupName);
935 }
936
937 bool GHS3DPlugin_Hypothesis_i::SetEnforcedVertexGeom(GEOM::GEOM_Object_ptr theVertex, CORBA::Double size)
938 {
939   ASSERT(myBaseImpl);
940   
941   if ((theVertex->GetShapeType() != GEOM::VERTEX) && (theVertex->GetShapeType() != GEOM::COMPOUND)) {
942     THROW_SALOME_CORBA_EXCEPTION("theVertex shape type is not VERTEX or COMPOUND", SALOME::BAD_PARAM);
943   }
944   
945   string theVertexEntry = theVertex->GetStudyEntry();
946   CORBA::Double x = 0, y = 0, z = 0;
947   CORBA::Boolean isCompound = false;
948   GEOM::GEOM_Gen_ptr geomGen = SMESH_Gen_i::GetGeomEngine( theVertex );
949   if (theVertexEntry.empty()) {
950     string aName;
951     if (theVertex->GetShapeType() == GEOM::VERTEX) {
952       aName = "Vertex_";
953     }
954     if (theVertex->GetShapeType() == GEOM::COMPOUND) {
955       aName = "Compound_";
956       isCompound = true;
957     }
958     aName += theVertex->GetEntry();
959     SALOMEDS::SObject_ptr theSVertex = geomGen->PublishInStudy(NULL, theVertex, aName.c_str());
960     if (!theSVertex->_is_nil())
961       theVertexEntry = theSVertex->GetID();
962   }
963   if (theVertexEntry.empty())
964     THROW_SALOME_CORBA_EXCEPTION( "Geom object is not published in study" ,SALOME::BAD_PARAM );
965
966   if (theVertex->GetShapeType() == GEOM::VERTEX) {
967     GEOM::GEOM_IMeasureOperations_var measureOp = geomGen->GetIMeasureOperations();
968     if (CORBA::is_nil(measureOp))
969       return false;
970     
971     measureOp->PointCoordinates (theVertex, x, y, z);
972   }
973
974   string theVertexName = theVertex->GetName();
975   
976   return p_SetEnforcedVertex(size, x, y, z, theVertexName.c_str(), theVertexEntry.c_str(), "", isCompound);
977 }
978
979 bool GHS3DPlugin_Hypothesis_i::SetEnforcedVertexGeomWithGroup(GEOM::GEOM_Object_ptr theVertex, CORBA::Double size, const char* theGroupName)
980 {
981   ASSERT(myBaseImpl);
982   
983   if ((theVertex->GetShapeType() != GEOM::VERTEX) && (theVertex->GetShapeType() != GEOM::COMPOUND)) {
984     THROW_SALOME_CORBA_EXCEPTION("theVertex shape type is not VERTEX or COMPOUND", SALOME::BAD_PARAM);
985   }
986   
987   string theVertexEntry = theVertex->GetStudyEntry();
988   CORBA::Double x = 0, y = 0, z = 0;
989   CORBA::Boolean isCompound = false;
990   GEOM::GEOM_Gen_ptr geomGen = SMESH_Gen_i::GetGeomEngine( theVertex );
991   if (theVertexEntry.empty()) {
992     string aName;
993     if (theVertex->GetShapeType() == GEOM::VERTEX) {
994       aName = "Vertex_";
995     }
996     if (theVertex->GetShapeType() == GEOM::COMPOUND) {
997       aName = "Compound_";
998       isCompound = true;
999     }
1000     aName += theVertex->GetEntry();
1001     SALOMEDS::SObject_ptr theSVertex = geomGen->PublishInStudy(NULL, theVertex, aName.c_str());
1002     if (!theSVertex->_is_nil())
1003       theVertexEntry = theSVertex->GetID();
1004   }
1005   if (theVertexEntry.empty())
1006     THROW_SALOME_CORBA_EXCEPTION( "Geom object is not published in study" ,SALOME::BAD_PARAM );
1007
1008   if (theVertex->GetShapeType() == GEOM::VERTEX) {
1009     GEOM::GEOM_IMeasureOperations_var measureOp = geomGen->GetIMeasureOperations();
1010     if (CORBA::is_nil(measureOp))
1011       return false;
1012     
1013     measureOp->PointCoordinates (theVertex, x, y, z);
1014   }
1015     
1016   string theVertexName = theVertex->GetName();
1017   
1018   return p_SetEnforcedVertex(size, x, y, z, theVertexName.c_str(), theVertexEntry.c_str(), theGroupName, isCompound);
1019 }
1020
1021 bool GHS3DPlugin_Hypothesis_i:: p_SetEnforcedVertex(CORBA::Double size, CORBA::Double x, CORBA::Double y, CORBA::Double z,
1022                                                     const char* theVertexName, const char* theVertexEntry, const char* theGroupName,
1023                                                     CORBA::Boolean isCompound)
1024 {
1025   ASSERT(myBaseImpl);
1026   bool newValue = false;
1027
1028   ::GHS3DPlugin_Hypothesis::TCoordsGHS3DEnforcedVertexMap coordsList;
1029   ::GHS3DPlugin_Hypothesis::TGeomEntryGHS3DEnforcedVertexMap enfVertexEntryList;
1030   if (string(theVertexEntry).empty()) {
1031     coordsList = this->GetImpl()->_GetEnforcedVerticesByCoords();
1032     std::vector<double> coords;
1033     coords.push_back(x);
1034     coords.push_back(y);
1035     coords.push_back(z);
1036     if (coordsList.find(coords) == coordsList.end()) {
1037       newValue = true;
1038     }
1039     else {
1040       ::GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertex *enfVertex = this->GetImpl()->GetEnforcedVertex(x, y, z);
1041       if ((enfVertex->name != theVertexName) || (enfVertex->groupName != theGroupName) || (enfVertex->size != size)) {
1042         newValue = true;
1043       }
1044     }
1045
1046     if (newValue) {
1047       if (string(theVertexName).empty()) {
1048         if (string(theGroupName).empty())
1049           SMESH::TPythonDump() << "isDone = " << _this() << ".SetEnforcedVertex(" << x << ", " << y << ", " << z << ", " << size << ")";
1050         else
1051           SMESH::TPythonDump() << "isDone = " << _this() << ".SetEnforcedVertexWithGroup(" << x << ", " << y << ", " << z << ", " << size << ", \"" << theGroupName << "\")";
1052       }
1053       else {
1054         if (string(theGroupName).empty())
1055           SMESH::TPythonDump() << "isDone = " << _this() << ".SetEnforcedVertexNamed(" << x << ", " << y << ", " << z << ", " << size  << ", \"" << theVertexName << "\")";
1056         else
1057           SMESH::TPythonDump() << "isDone = " << _this() << ".SetEnforcedVertexNamedWithGroup(" << x << ", " << y << ", " << z << ", " << size  << ", \"" << theVertexName << "\", \"" << theGroupName << "\")";
1058       }
1059     }
1060   } 
1061   else {
1062     enfVertexEntryList = this->GetImpl()->_GetEnforcedVerticesByEntry();
1063     if ( enfVertexEntryList.find(theVertexEntry) == enfVertexEntryList.end()) {
1064       newValue = true;
1065     }
1066     else {
1067       ::GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertex *enfVertex = this->GetImpl()->GetEnforcedVertex(theVertexEntry);
1068       if ((enfVertex->name != theVertexName) || (enfVertex->groupName != theGroupName) || (enfVertex->size != size)) {
1069         newValue = true;
1070       }
1071     }
1072
1073     if (newValue) {
1074       if (string(theGroupName).empty())
1075         SMESH::TPythonDump() << "isDone = " << _this() << ".SetEnforcedVertexGeom(" << theVertexEntry << ", " << size << ")";
1076       else
1077         SMESH::TPythonDump() << "isDone = " << _this() << ".SetEnforcedVertexGeomWithGroup(" << theVertexEntry << ", " << size << ", \"" << theGroupName << "\")";
1078     }
1079   }
1080
1081   if (newValue)
1082     this->GetImpl()->SetEnforcedVertex(theVertexName, theVertexEntry, theGroupName, size, x, y, z, isCompound);
1083
1084   return newValue;
1085 }
1086
1087 //=======================================================================
1088 //function : GetEnforcedVertex
1089 //=======================================================================
1090
1091 CORBA::Double GHS3DPlugin_Hypothesis_i::GetEnforcedVertex(CORBA::Double x, CORBA::Double y, CORBA::Double z)
1092 {
1093   ASSERT(myBaseImpl);
1094   try {
1095     bool isDone = this->GetImpl()->GetEnforcedVertex(x,y,z)->size;
1096     SMESH::TPythonDump() << "aSize = " << _this() << ".GetEnforcedVertex(" << x << ", " << y << ", " << z << ")";
1097     return isDone;
1098   }
1099   catch (const std::invalid_argument& ex) {
1100     THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM );
1101   }
1102   catch (SALOME_Exception& ex) {
1103     THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM );
1104   }
1105 }
1106
1107 //=======================================================================
1108 //function : GetEnforcedVertex
1109 //=======================================================================
1110
1111 CORBA::Double GHS3DPlugin_Hypothesis_i::GetEnforcedVertexGeom(GEOM::GEOM_Object_ptr theVertex)
1112 {
1113   ASSERT(myBaseImpl);
1114   
1115   if ((theVertex->GetShapeType() != GEOM::VERTEX) && (theVertex->GetShapeType() != GEOM::COMPOUND)) {
1116     THROW_SALOME_CORBA_EXCEPTION("theVertex shape type is not VERTEX or COMPOUND", SALOME::BAD_PARAM);
1117   }
1118   
1119   string theVertexEntry = theVertex->GetStudyEntry();
1120   if (theVertexEntry.empty()) {
1121     GEOM::GEOM_Gen_ptr geomGen = SMESH_Gen_i::GetGeomEngine( theVertex );
1122     string aName;
1123     if (theVertex->GetShapeType() == GEOM::VERTEX)
1124       aName = "Vertex_";
1125     if (theVertex->GetShapeType() == GEOM::COMPOUND)
1126       aName = "Compound_";
1127     aName += theVertex->GetEntry();
1128     SALOMEDS::SObject_ptr theSVertex = geomGen->PublishInStudy(NULL, theVertex, aName.c_str());
1129     if (!theSVertex->_is_nil())
1130       theVertexEntry = theSVertex->GetID();
1131   }
1132   if (theVertexEntry.empty())
1133     THROW_SALOME_CORBA_EXCEPTION( "Geom object is not published in study" ,SALOME::BAD_PARAM );
1134
1135   string theVertexName = theVertex->GetName();
1136   
1137   try {
1138     bool isDone = this->GetImpl()->GetEnforcedVertex(theVertexName)->size;
1139     SMESH::TPythonDump() << "aSize = " << _this() << ".GetEnforcedVertexGeom(" << theVertex << ")";
1140     return isDone;
1141   }
1142   catch (const std::invalid_argument& ex) {
1143     THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM );
1144   }
1145   catch (SALOME_Exception& ex) {
1146     THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM );
1147   }
1148 }
1149
1150 //=======================================================================
1151 //function : GetEnforcedVertices
1152 //=======================================================================
1153
1154 GHS3DPlugin::GHS3DEnforcedVertexList* GHS3DPlugin_Hypothesis_i::GetEnforcedVertices()
1155 {
1156   ASSERT(myBaseImpl);
1157   GHS3DPlugin::GHS3DEnforcedVertexList_var result = new GHS3DPlugin::GHS3DEnforcedVertexList();
1158
1159   const ::GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexList enfVertexList = this->GetImpl()->_GetEnforcedVertices();
1160   result->length((CORBA::ULong) enfVertexList.size() );
1161
1162   ::GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexList::const_iterator it = enfVertexList.begin();
1163
1164   for (int i = 0 ; it != enfVertexList.end(); ++it, ++i ) {
1165     ::GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertex* currentVertex = (*it);
1166     GHS3DPlugin::GHS3DEnforcedVertex_var enfVertex = new GHS3DPlugin::GHS3DEnforcedVertex();
1167     // Name
1168     enfVertex->name = CORBA::string_dup(currentVertex->name.c_str());
1169     // Geom Vertex Entry
1170     enfVertex->geomEntry = CORBA::string_dup(currentVertex->geomEntry.c_str());
1171     // Coords
1172     GHS3DPlugin::TCoords_var coords = new GHS3DPlugin::TCoords();
1173     coords->length((CORBA::ULong) currentVertex->coords.size());
1174     for ( CORBA::ULong ind = 0; ind < currentVertex->coords.size(); ind++)
1175       coords[ind] = currentVertex->coords[ind];
1176     enfVertex->coords = coords;
1177     // Group Name
1178     enfVertex->groupName = CORBA::string_dup(currentVertex->groupName.c_str());
1179     // Size
1180     enfVertex->size = currentVertex->size;
1181     // isCompound
1182     enfVertex->isCompound = currentVertex->isCompound;
1183     
1184     result[i]=enfVertex;
1185   }
1186   
1187   //   SMESH::TPythonDump() << "allEnforcedVertices = " << _this() << ".GetEnforcedVertices()";
1188
1189   return result._retn();
1190 }
1191
1192 //=======================================================================
1193 //function : RemoveEnforcedVertex
1194 //=======================================================================
1195
1196 bool GHS3DPlugin_Hypothesis_i::RemoveEnforcedVertex(CORBA::Double x, CORBA::Double y, CORBA::Double z)
1197 {
1198   ASSERT(myBaseImpl);
1199   try {
1200     bool res = this->GetImpl()->RemoveEnforcedVertex(x,y,z);
1201     SMESH::TPythonDump() << " isDone = " << _this() << ".RemoveEnforcedVertex( " << x << ", " << y << ", " << z << " )";
1202     return res;
1203   }
1204   catch (const std::invalid_argument& ex) {
1205     THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM );
1206   }
1207   catch (SALOME_Exception& ex) {
1208     THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM );
1209   }
1210 }
1211
1212 bool GHS3DPlugin_Hypothesis_i::RemoveEnforcedVertexGeom(GEOM::GEOM_Object_ptr theVertex)
1213 {
1214   ASSERT(myBaseImpl);
1215   
1216   if ((theVertex->GetShapeType() != GEOM::VERTEX) && (theVertex->GetShapeType() != GEOM::COMPOUND)) {
1217     THROW_SALOME_CORBA_EXCEPTION("theVertex shape type is not VERTEX or COMPOUND", SALOME::BAD_PARAM);
1218   }
1219   
1220   string theVertexEntry = theVertex->GetStudyEntry();
1221   if (theVertexEntry.empty()) {
1222     GEOM::GEOM_Gen_ptr geomGen = SMESH_Gen_i::GetGeomEngine( theVertex );
1223     string aName;
1224     if (theVertex->GetShapeType() == GEOM::VERTEX)
1225       aName = "Vertex_";
1226     if (theVertex->GetShapeType() == GEOM::COMPOUND)
1227       aName = "Compound_";
1228     aName += theVertex->GetEntry();
1229     SALOMEDS::SObject_ptr theSVertex = geomGen->PublishInStudy(NULL, theVertex, aName.c_str());
1230     if (!theSVertex->_is_nil())
1231       theVertexEntry = theSVertex->GetID();
1232   }
1233   if (theVertexEntry.empty())
1234     THROW_SALOME_CORBA_EXCEPTION( "Geom object is not published in study" ,SALOME::BAD_PARAM );
1235   
1236   try {
1237     bool res = this->GetImpl()->RemoveEnforcedVertex(0,0,0, theVertexEntry.c_str());
1238     SMESH::TPythonDump() << "isDone = " << _this() << ".RemoveEnforcedVertexGeom( " << theVertexEntry.c_str() << " )";
1239     return res;
1240   }
1241   catch (const std::invalid_argument& ex) {
1242     THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM );
1243   }
1244   catch (SALOME_Exception& ex) {
1245     THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM );
1246   }
1247 }
1248
1249 //=======================================================================
1250 //function : ClearEnforcedVertices
1251 //=======================================================================
1252
1253 void GHS3DPlugin_Hypothesis_i::ClearEnforcedVertices()
1254 {
1255   ASSERT(myBaseImpl);
1256   this->GetImpl()->ClearEnforcedVertices();
1257   SMESH::TPythonDump () << _this() << ".ClearEnforcedVertices() ";
1258 }
1259
1260 //=======================================================================
1261 //function : ClearEnforcedMeshes
1262 //=======================================================================
1263
1264 void GHS3DPlugin_Hypothesis_i::ClearEnforcedMeshes()
1265 {
1266   ASSERT(myBaseImpl);
1267   this->GetImpl()->ClearEnforcedMeshes();
1268   SMESH::TPythonDump () << _this() << ".ClearEnforcedMeshes() ";
1269 }
1270
1271 //=======================================================================
1272 //function : GetEnforcedMeshes
1273 //=======================================================================
1274
1275 GHS3DPlugin::GHS3DEnforcedMeshList* GHS3DPlugin_Hypothesis_i::GetEnforcedMeshes()
1276 {
1277   ASSERT(myBaseImpl);
1278   GHS3DPlugin::GHS3DEnforcedMeshList_var result = new GHS3DPlugin::GHS3DEnforcedMeshList();
1279
1280   const ::GHS3DPlugin_Hypothesis::TGHS3DEnforcedMeshList enfMeshList = this->GetImpl()->_GetEnforcedMeshes();
1281   result->length((CORBA::ULong) enfMeshList.size() );
1282
1283   ::GHS3DPlugin_Hypothesis::TGHS3DEnforcedMeshList::const_iterator it = enfMeshList.begin();
1284
1285   for (int i = 0 ; it != enfMeshList.end(); ++it, ++i ) {
1286     ::GHS3DPlugin_Hypothesis::TGHS3DEnforcedMesh* currentMesh = (*it);
1287     GHS3DPlugin::GHS3DEnforcedMesh_var enfMesh = new GHS3DPlugin::GHS3DEnforcedMesh();
1288     // Name
1289     enfMesh->name = CORBA::string_dup(currentMesh->name.c_str());
1290     // Mesh Entry
1291     enfMesh->entry = CORBA::string_dup(currentMesh->entry.c_str());
1292     // isCompound
1293     enfMesh->elementType = currentMesh->elementType;
1294     // Group Name
1295     enfMesh->groupName = CORBA::string_dup(currentMesh->groupName.c_str());
1296     
1297     result[i]=enfMesh;
1298   }
1299   
1300   //   SMESH::TPythonDump() << "allEnforcedVertices = " << _this() << ".GetEnforcedVertices()";
1301
1302   return result._retn();
1303 }
1304
1305 /*!
1306  * \brief Adds enforced elements of type elementType using another mesh/sub-mesh/mesh group theSource. The elements will be grouped in theGroupName.
1307  */
1308 bool GHS3DPlugin_Hypothesis_i::SetEnforcedMeshWithGroup(SMESH::SMESH_IDSource_ptr theSource, SMESH::ElementType theType, const char* theGroupName)
1309 {
1310   return p_SetEnforcedMesh(theSource, theType, "", theGroupName);
1311 }
1312
1313 /*!
1314  * \brief Adds enforced elements of type elementType using another mesh/sub-mesh/mesh group theSource.
1315  */
1316 bool GHS3DPlugin_Hypothesis_i::SetEnforcedMesh(SMESH::SMESH_IDSource_ptr theSource, SMESH::ElementType theType)
1317 {
1318   return p_SetEnforcedMesh(theSource, theType);
1319 }
1320
1321 /*!
1322  * \brief OBSOLETE FUNCTION - Adds enforced elements of type elementType using another mesh/sub-mesh/mesh group theSource and a size. The elements will be grouped in theGroupName.
1323  */
1324 bool GHS3DPlugin_Hypothesis_i::SetEnforcedMeshSizeWithGroup(SMESH::SMESH_IDSource_ptr theSource, SMESH::ElementType theType, double /*theSize*/, const char* theGroupName)
1325 {
1326   return p_SetEnforcedMesh(theSource, theType, "", theGroupName);
1327 }
1328
1329 /*!
1330  * \brief OBSOLETE FUNCTION - Adds enforced elements of type elementType using another mesh/sub-mesh/mesh group theSource and a size.
1331  */
1332 bool GHS3DPlugin_Hypothesis_i::SetEnforcedMeshSize(SMESH::SMESH_IDSource_ptr theSource, SMESH::ElementType theType, double /*theSize*/)
1333 {
1334   return p_SetEnforcedMesh(theSource, theType);
1335 }
1336
1337 bool GHS3DPlugin_Hypothesis_i::p_SetEnforcedMesh(SMESH::SMESH_IDSource_ptr theSource,
1338                                                  SMESH::ElementType        theType,
1339                                                  const char*               theName,
1340                                                  const char*               theGroupName)
1341 {
1342   ASSERT(myBaseImpl);
1343
1344   if (CORBA::is_nil( theSource ))
1345     THROW_SALOME_CORBA_EXCEPTION( "The source mesh CORBA object is NULL" ,SALOME::BAD_PARAM );
1346
1347   switch (theType) {
1348   case SMESH::NODE:
1349   case SMESH::EDGE:
1350   case SMESH::FACE: break;
1351   default:
1352     return false;
1353   }
1354   SMESH::array_of_ElementType_var types = theSource->GetTypes();
1355   if ( types->length() >= 1 && types[types->length()-1] <  theType)
1356   {
1357     return false;
1358   }
1359
1360   SMESH_Gen_i *smeshGen = SMESH_Gen_i::GetSMESHGen();
1361   SALOMEDS::SObject_ptr SObj = smeshGen->ObjectToSObject(theSource);
1362
1363   SMESH_Mesh_i* theMesh_i = SMESH::DownCast<SMESH_Mesh_i*>( theSource);
1364   SMESH_Group_i* theGroup_i = SMESH::DownCast<SMESH_Group_i*>( theSource);
1365   SMESH_GroupOnGeom_i* theGroupOnGeom_i = SMESH::DownCast<SMESH_GroupOnGeom_i*>( theSource);
1366
1367   string enfMeshName = theName;
1368   if (enfMeshName.empty())
1369     enfMeshName = SObj->GetName();
1370
1371   if (theMesh_i)
1372   {
1373     try {
1374       bool res = this->GetImpl()->SetEnforcedMesh(theMesh_i->GetImpl(), theType, enfMeshName , SObj->GetID(), theGroupName);
1375       if (theGroupName && theGroupName[0] ) {
1376         SMESH::TPythonDump () << "isDone = " << _this() << ".SetEnforcedMeshWithGroup( "
1377                               << theSource << ".GetMesh(), " << theType << ", \"" << theGroupName << "\" )";
1378       }
1379       else {
1380         SMESH::TPythonDump () << "isDone = " << _this() << ".SetEnforcedMesh( "
1381                               << theSource << ".GetMesh(), " << theType << " )";
1382       }
1383
1384       return res;
1385     }
1386     catch (const std::invalid_argument& ex) {
1387       SALOME::ExceptionStruct ExDescription;
1388       ExDescription.text = ex.what();
1389       ExDescription.type = SALOME::BAD_PARAM;
1390       ExDescription.sourceFile = "GHS3DPlugin_Hypothesis_i.cxx";
1391       ExDescription.lineNumber = 840;
1392       throw SALOME::SALOME_Exception(ExDescription);
1393     }
1394     catch (SALOME_Exception& ex) {
1395       THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM );
1396     }
1397   }
1398   else if (theGroup_i)// && types->length() == 1 && types[0] == theType)
1399   {
1400     try {
1401       bool res = this->GetImpl()->SetEnforcedGroup(theGroup_i->GetGroupDS()->GetMesh(), theGroup_i->GetListOfID(), theType, enfMeshName , SObj->GetID(), theGroupName);
1402       if ( theGroupName && theGroupName[0] ) {
1403         SMESH::TPythonDump () << "isDone = " << _this() << ".SetEnforcedMeshWithGroup( "
1404                               << theSource << ", " << theType << ", \"" << theGroupName << "\" )";
1405       }
1406       else {
1407         SMESH::TPythonDump () << "isDone = " << _this() << ".SetEnforcedMesh( "
1408                               << theSource << ", " << theType << " )";
1409       }
1410       return res;
1411     }
1412     catch (const std::invalid_argument& ex) {
1413       SALOME::ExceptionStruct ExDescription;
1414       ExDescription.text = ex.what();
1415       ExDescription.type = SALOME::BAD_PARAM;
1416       ExDescription.sourceFile = "GHS3DPlugin_Hypothesis_i.cxx";
1417       ExDescription.lineNumber = 840;
1418       throw SALOME::SALOME_Exception(ExDescription);
1419     }
1420     catch (SALOME_Exception& ex) {
1421       THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM );
1422     }
1423   }
1424   else if (theGroupOnGeom_i)// && types->length() == 1 && types[0] == theType)
1425   {
1426     try {
1427       bool res = this->GetImpl()->SetEnforcedGroup(theGroupOnGeom_i->GetGroupDS()->GetMesh(),theGroupOnGeom_i->GetListOfID(), theType, enfMeshName , SObj->GetID(), theGroupName);
1428       if ( theGroupName && theGroupName[0] ) {
1429         SMESH::TPythonDump () << "isDone = " << _this() << ".SetEnforcedMeshWithGroup( "
1430                               << theSource << ", " << theType << ", \"" << theGroupName << "\" )";
1431       }
1432       else {
1433         SMESH::TPythonDump () << "isDone = " << _this() << ".SetEnforcedMesh( "
1434                               << theSource << ", " << theType << " )";
1435       }
1436       return res;
1437     }
1438     catch (const std::invalid_argument& ex) {
1439       SALOME::ExceptionStruct ExDescription;
1440       ExDescription.text = ex.what();
1441       ExDescription.type = SALOME::BAD_PARAM;
1442       ExDescription.sourceFile = "GHS3DPlugin_Hypothesis_i.cxx";
1443       ExDescription.lineNumber = 840;
1444       throw SALOME::SALOME_Exception(ExDescription);
1445     }
1446     catch (SALOME_Exception& ex) {
1447       THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM );
1448     }
1449   }
1450   return false;
1451 }
1452 //=============================================================================
1453 /*!
1454  *  Get implementation
1455  */
1456 //=============================================================================
1457
1458 ::GHS3DPlugin_Hypothesis* GHS3DPlugin_Hypothesis_i::GetImpl()
1459 {
1460   return (::GHS3DPlugin_Hypothesis*)myBaseImpl;
1461 }
1462
1463 //================================================================================
1464 /*!
1465  * \brief Verify whether hypothesis supports given entity type 
1466  */
1467 //================================================================================  
1468
1469 CORBA::Boolean GHS3DPlugin_Hypothesis_i::IsDimSupported( SMESH::Dimension type )
1470 {
1471   return type == SMESH::DIM_3D;
1472 }
1473
1474
1475 //================================================================================
1476 /*!
1477  * \brief Return geometry this hypothesis depends on. Return false if there is no geometry parameter
1478  */
1479 //================================================================================
1480
1481 bool
1482 GHS3DPlugin_Hypothesis_i::getObjectsDependOn( std::vector< std::string > & entryArray,
1483                                               std::vector< int >         & /*subIDArray*/ ) const
1484 {
1485   typedef ::GHS3DPlugin_Hypothesis THyp;
1486   const THyp* h = static_cast< const THyp*>( myBaseImpl );
1487
1488   {
1489     const THyp::TGHS3DEnforcedVertexList& enfVertexList = h->_GetEnforcedVertices();
1490     THyp::TGHS3DEnforcedVertexList::const_iterator evIt = enfVertexList.begin();
1491     for ( ; evIt != enfVertexList.end(); ++evIt )
1492     {
1493       const THyp::TGHS3DEnforcedVertex* ev = *evIt;
1494       entryArray.push_back( ev->geomEntry );
1495     }
1496   }
1497   {
1498     const THyp::TGHS3DEnforcedVertexEntryValues&
1499       enfVertexEntrySizeList = h->_GetEnforcedVerticesEntrySize();
1500     THyp::TGHS3DEnforcedVertexEntryValues::const_iterator entry2size;
1501     for ( entry2size =  enfVertexEntrySizeList.cbegin();
1502           entry2size != enfVertexEntrySizeList.cend();
1503           entry2size++ )
1504     {
1505       entryArray.push_back( entry2size->first );
1506     }
1507   }
1508   {
1509     const THyp::TCoordsGHS3DEnforcedVertexMap&
1510       coordsEnfVertexMap = h->_GetEnforcedVerticesByCoords();
1511     THyp::TCoordsGHS3DEnforcedVertexMap::const_iterator size2ev = coordsEnfVertexMap.cbegin();
1512     for ( ; size2ev != coordsEnfVertexMap.cend(); ++size2ev )
1513     {
1514       const THyp::TGHS3DEnforcedVertex* ev = size2ev->second;
1515       entryArray.push_back( ev->geomEntry );
1516     }
1517   }
1518   {
1519     const THyp::TGeomEntryGHS3DEnforcedVertexMap&
1520       geomEntryEnfVertexMap = h->_GetEnforcedVerticesByEntry();
1521     THyp::TGeomEntryGHS3DEnforcedVertexMap::const_iterator entry2ev;
1522     for ( entry2ev =  geomEntryEnfVertexMap.cbegin();
1523           entry2ev != geomEntryEnfVertexMap.cend();
1524           entry2ev++ )
1525     {
1526       entryArray.push_back( entry2ev->first );
1527
1528       const THyp::TGHS3DEnforcedVertex* ev = entry2ev->second;
1529       entryArray.push_back( ev->geomEntry );
1530     }
1531   }
1532
1533   return entryArray.size() > 0;
1534 }
1535
1536 //================================================================================
1537 /*!
1538  * \brief Set new geometry instead of that returned by getObjectsDependOn()
1539  */
1540 //================================================================================
1541
1542 bool
1543 GHS3DPlugin_Hypothesis_i::setObjectsDependOn( std::vector< std::string > & entryArray,
1544                                               std::vector< int >         & /*subIDArray*/ )
1545 {
1546   typedef ::GHS3DPlugin_Hypothesis THyp;
1547   THyp* h = static_cast< THyp*>( myBaseImpl );
1548
1549   size_t iEnt = 0;
1550   {
1551     THyp::TGHS3DEnforcedVertexList& enfVertexList =
1552       const_cast<THyp::TGHS3DEnforcedVertexList& >( h->_GetEnforcedVertices() );
1553     THyp::TGHS3DEnforcedVertexList::iterator evIt = enfVertexList.begin();
1554     for ( ; evIt != enfVertexList.end(); ++evIt )
1555     {
1556       THyp::TGHS3DEnforcedVertex* ev = *evIt;
1557       ev->geomEntry = entryArray[ iEnt++ ];
1558     }
1559   }
1560   {
1561     THyp::TGHS3DEnforcedVertexEntryValues& enfVertexEntrySizeListNew =
1562       const_cast< THyp::TGHS3DEnforcedVertexEntryValues& > ( h->_GetEnforcedVerticesEntrySize() );
1563     THyp::TGHS3DEnforcedVertexEntryValues enfVertexEntrySizeList;
1564     enfVertexEntrySizeList.swap( enfVertexEntrySizeListNew );
1565     THyp::TGHS3DEnforcedVertexEntryValues::const_iterator entry2size;
1566     for ( entry2size =  enfVertexEntrySizeList.cbegin();
1567           entry2size != enfVertexEntrySizeList.cend();
1568           entry2size++, ++iEnt )
1569     {
1570       if ( entry2size->first.empty() == entryArray[ iEnt ].empty() )
1571         enfVertexEntrySizeListNew[ entryArray[ iEnt ]] = entry2size->second;
1572     }
1573   }
1574   {
1575     THyp::TCoordsGHS3DEnforcedVertexMap& coordsEnfVertexMap =
1576       const_cast< THyp::TCoordsGHS3DEnforcedVertexMap& > ( h->_GetEnforcedVerticesByCoords() );
1577     THyp::TCoordsGHS3DEnforcedVertexMap::iterator size2ev = coordsEnfVertexMap.begin();
1578     for ( ; size2ev != coordsEnfVertexMap.end(); ++size2ev )
1579     {
1580       THyp::TGHS3DEnforcedVertex* ev = size2ev->second;
1581       ev->geomEntry = entryArray[ iEnt++ ];
1582     }
1583   }
1584   {
1585     THyp::TGeomEntryGHS3DEnforcedVertexMap& geomEntryEnfVertexMapNew =
1586       const_cast< THyp::TGeomEntryGHS3DEnforcedVertexMap& > ( h->_GetEnforcedVerticesByEntry() );
1587     THyp::TGeomEntryGHS3DEnforcedVertexMap geomEntryEnfVertexMap;
1588     geomEntryEnfVertexMap.swap( geomEntryEnfVertexMapNew );
1589     THyp::TGeomEntryGHS3DEnforcedVertexMap::iterator entry2ev;
1590     for ( entry2ev =  geomEntryEnfVertexMap.begin();
1591           entry2ev != geomEntryEnfVertexMap.end();
1592           entry2ev++ )
1593     {
1594       const std::string& entry = entryArray[ iEnt++ ];
1595       THyp::TGHS3DEnforcedVertex* ev = entry2ev->second;
1596       ev->geomEntry = entryArray[ iEnt++ ];
1597
1598       geomEntryEnfVertexMapNew[ entry ] = ev;
1599     }
1600   }
1601
1602   return iEnt == entryArray.size();
1603 }