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