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