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