Salome HOME
Copyright update 2020
[plugins/hexoticplugin.git] / src / HexoticPlugin / HexoticPlugin_Hypothesis_i.cxx
1 // Copyright (C) 2007-2020  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 // ---
21 // File   : HexoticPlugin_Hypothesis_i.cxx
22 // Author : Lioka RAZAFINDRAZAKA (CEA)
23 // ---
24 //
25 #include "HexoticPlugin_Hypothesis_i.hxx"
26 #include "SMESH_Mesh_i.hxx"
27 #include "SMESH_Gen.hxx"
28 #include "SMESH_PythonDump.hxx"
29
30 #include "Utils_CorbaException.hxx"
31 #include "utilities.h"
32
33 //=============================================================================
34 /*!
35  *  HexoticPlugin_Hypothesis_i::HexoticPlugin_Hypothesis_i
36  *
37  *  Constructor
38  */
39 //=============================================================================
40 HexoticPlugin_Hypothesis_i::
41 HexoticPlugin_Hypothesis_i (PortableServer::POA_ptr thePOA,
42                             ::SMESH_Gen*            theGenImpl)
43   : SALOME::GenericObj_i( thePOA ), 
44     SMESH_Hypothesis_i( thePOA )
45 {
46   myBaseImpl = new ::HexoticPlugin_Hypothesis (theGenImpl->GetANewId(),
47                                                theGenImpl);
48 }
49
50 //=============================================================================
51 /*!
52  *  HexoticPlugin_Hypothesis_i::~HexoticPlugin_Hypothesis_i
53  *
54  *  Destructor
55  */
56 //=============================================================================
57 HexoticPlugin_Hypothesis_i::~HexoticPlugin_Hypothesis_i()
58 {
59 }
60
61 //=============================================================================
62 /*!
63  *  HexoticPlugin_Hypothesis_i::SetHexesMinLevel
64  *  HexoticPlugin_Hypothesis_i::SetHexesMaxLevel
65  *  HexoticPlugin_Hypothesis_i::SetMinSize
66  *  HexoticPlugin_Hypothesis_i::SetMaxSize
67  *  HexoticPlugin_Hypothesis_i::SetHexoticIgnoreRidges
68  *  HexoticPlugin_Hypothesis_i::SetHexoticInvalidElements
69  *  HexoticPlugin_Hypothesis_i::SetHexoticSharpAngleThreshold
70  *  HexoticPlugin_Hypothesis_i::SetHexoticNbProc 
71  *  HexoticPlugin_Hypothesis_i::SetHexoticWorkingDirectory 
72  *  HexoticPlugin_Hypothesis_i::SetHexoticSdMode
73  *  HexoticPlugin_Hypothesis_i::SetVerbosity
74  *  HexoticPlugin_Hypothesis_i::SetHexoticMaxMemory
75  *  HexoticPlugin_Hypothesis_i::SetTextOptions
76  *  HexoticPlugin_Hypothesis_i::SetNbLayers
77  *  HexoticPlugin_Hypothesis_i::SetFirstLayerSize
78  *  HexoticPlugin_Hypothesis_i::SetDirection
79  *  HexoticPlugin_Hypothesis_i::SetGrowth
80  *  HexoticPlugin_Hypothesis_i::SetFacesWithLayers
81  *  HexoticPlugin_Hypothesis_i::SetImprintedFaces
82  */
83 //=============================================================================
84
85 void HexoticPlugin_Hypothesis_i::SetHexesMinLevel (CORBA::Long theValue)
86 {
87   ASSERT(myBaseImpl);
88   CORBA::Long oldValue = GetHexesMinLevel();
89   this->GetImpl()->SetHexesMinLevel(theValue);
90   if (theValue != oldValue)
91     SMESH::TPythonDump() << _this() << ".SetHexesMinLevel( " << theValue << " )";
92 }
93
94 void HexoticPlugin_Hypothesis_i::SetHexesMaxLevel (CORBA::Long theValue)
95 {
96   ASSERT(myBaseImpl);
97   CORBA::Long oldValue = GetHexesMaxLevel();
98   this->GetImpl()->SetHexesMaxLevel(theValue);
99   if (theValue != oldValue)
100     SMESH::TPythonDump() << _this() << ".SetHexesMaxLevel( " << theValue << " )";
101 }
102
103 void HexoticPlugin_Hypothesis_i::SetMinSize (CORBA::Double theValue)
104 {
105   ASSERT(myBaseImpl);
106   CORBA::Double oldValue = GetMinSize();
107   this->GetImpl()->SetMinSize(theValue);
108   if (theValue != oldValue)
109     SMESH::TPythonDump() << _this() << ".SetMinSize( " << theValue << " )";
110 }
111
112 void HexoticPlugin_Hypothesis_i::SetMaxSize (CORBA::Double theValue)
113 {
114   ASSERT(myBaseImpl);
115   CORBA::Double oldValue = GetMaxSize();
116   this->GetImpl()->SetMaxSize(theValue);
117   if (theValue != oldValue)
118     SMESH::TPythonDump() << _this() << ".SetMaxSize( " << theValue << " )";
119 }
120
121 void HexoticPlugin_Hypothesis_i::SetGeomApproxAngle(CORBA::Double angle)
122 {
123   CORBA::Double oldValue = GetGeomApproxAngle();
124   this->GetImpl()->SetGeomApproxAngle( angle );
125   if (angle != oldValue)
126     SMESH::TPythonDump() << _this() << ".SetGeomApproxAngle( " << angle << " )";
127 }
128
129 CORBA::Double HexoticPlugin_Hypothesis_i::GetGeomApproxAngle()
130 {
131   return this->GetImpl()->GetGeomApproxAngle();
132 }
133
134 void HexoticPlugin_Hypothesis_i::SetHexoticIgnoreRidges (CORBA::Boolean theValue)
135 {
136   ASSERT(myBaseImpl);
137   CORBA::Boolean oldValue = GetHexoticIgnoreRidges();
138   this->GetImpl()->SetHexoticIgnoreRidges(theValue);
139   if (theValue != oldValue)
140     SMESH::TPythonDump() << _this() << ".SetHexoticIgnoreRidges( " << theValue << " )";
141 }
142
143 void HexoticPlugin_Hypothesis_i::SetHexoticInvalidElements (CORBA::Boolean theValue)
144 {
145   ASSERT(myBaseImpl);
146   CORBA::Boolean oldValue = GetHexoticInvalidElements();
147   this->GetImpl()->SetHexoticInvalidElements(theValue);
148   if (theValue != oldValue)
149     SMESH::TPythonDump() << _this() << ".SetHexoticInvalidElements( " << theValue << " )";
150 }
151
152 void HexoticPlugin_Hypothesis_i::SetHexoticSharpAngleThreshold (CORBA::Double theValue)
153 {
154   ASSERT(myBaseImpl);
155   CORBA::Double oldValue = GetHexoticSharpAngleThreshold();
156   this->GetImpl()->SetHexoticSharpAngleThreshold(theValue);
157   if (theValue != oldValue)
158     SMESH::TPythonDump() << _this() << ".SetHexoticSharpAngleThreshold( " << theValue << " )";
159 }
160
161 void HexoticPlugin_Hypothesis_i::SetHexoticNbProc (CORBA::Long theValue)
162 {
163   ASSERT(myBaseImpl);
164   CORBA::Long oldValue = GetHexoticNbProc();
165   this->GetImpl()->SetHexoticNbProc(theValue);
166   if (theValue != oldValue)
167     SMESH::TPythonDump() << _this() << ".SetHexoticNbProc( " << theValue << " )";
168 }
169
170 void HexoticPlugin_Hypothesis_i::SetHexoticWorkingDirectory(const char* path) throw ( SALOME::SALOME_Exception )
171 {
172   if (!path )
173     THROW_SALOME_CORBA_EXCEPTION( "Null working directory",SALOME::BAD_PARAM );
174
175   ASSERT(myBaseImpl);
176   std::string file(path);
177   std::string oldValue(GetHexoticWorkingDirectory());
178   bool doDump = false;
179   if (oldValue != file)
180     doDump = true;
181
182   const char lastChar = *file.rbegin();
183 #ifdef WIN32
184   if ( lastChar != '\\' ) file += '\\';
185 #else
186   if ( lastChar != '/' ) file += '/';
187 #endif
188   file += "Hexotic_In.mesh";
189   SMESH_Mesh_i::PrepareForWriting (file.c_str());
190
191   this->GetImpl()->SetHexoticWorkingDirectory(path);
192   if (doDump)
193     SMESH::TPythonDump() << _this() << ".SetHexoticWorkingDirectory( '" << path << "' )";
194 }
195
196 void HexoticPlugin_Hypothesis_i::SetKeepFiles(::CORBA::Boolean toKeep)
197 {
198   if ( GetKeepFiles() != toKeep )
199   {
200     this->GetImpl()->SetKeepFiles(toKeep);
201     SMESH::TPythonDump() << _this() << ".SetKeepFiles( " << toKeep << " )";
202   }
203 }
204
205 ::CORBA::Boolean HexoticPlugin_Hypothesis_i::GetKeepFiles()
206 {
207   return this->GetImpl()->GetKeepFiles();
208 }
209
210 void HexoticPlugin_Hypothesis_i::SetStandardOutputLog(::CORBA::Boolean logInStandardOutput)
211 {
212   if ( GetStandardOutputLog() != logInStandardOutput )
213   {
214     this->GetImpl()->SetStandardOutputLog(logInStandardOutput);
215     SMESH::TPythonDump() << _this() << ".SetStandardOutputLog( " << logInStandardOutput << " )";
216   }
217 }
218
219 ::CORBA::Boolean HexoticPlugin_Hypothesis_i::GetStandardOutputLog()
220 {
221   return this->GetImpl()->GetStandardOutputLog();
222 }
223
224 void HexoticPlugin_Hypothesis_i::SetRemoveLogOnSuccess(::CORBA::Boolean removeLogOnSuccess)
225 {
226   if ( GetRemoveLogOnSuccess() != removeLogOnSuccess )
227   {
228     this->GetImpl()->SetRemoveLogOnSuccess(removeLogOnSuccess);
229     SMESH::TPythonDump() << _this() << ".SetRemoveLogOnSuccess( " << removeLogOnSuccess << " )";
230   }
231 }
232
233 ::CORBA::Boolean HexoticPlugin_Hypothesis_i::GetRemoveLogOnSuccess()
234 {
235   return this->GetImpl()->GetRemoveLogOnSuccess();
236 }
237
238 void HexoticPlugin_Hypothesis_i::SetHexoticSdMode (CORBA::Long theValue)
239 {
240   ASSERT(myBaseImpl);
241   CORBA::Long oldValue = GetHexoticSdMode();
242   this->GetImpl()->SetHexoticSdMode(theValue);
243   if (theValue != oldValue)
244     SMESH::TPythonDump() << _this() << ".SetHexoticSdMode( " << theValue << " )";
245 }
246
247 void HexoticPlugin_Hypothesis_i::SetHexoticVerbosity (CORBA::Long theValue)
248 {
249   ASSERT(myBaseImpl);
250   CORBA::Long oldValue = GetHexoticVerbosity();
251   this->GetImpl()->SetHexoticVerbosity(theValue);
252   if (theValue != oldValue)
253     SMESH::TPythonDump() << _this() << ".SetHexoticVerbosity( " << theValue << " )";
254 }
255
256 void HexoticPlugin_Hypothesis_i::SetHexoticMaxMemory (CORBA::Long theValue)
257 {
258   ASSERT(myBaseImpl);
259   CORBA::Long oldValue = GetHexoticMaxMemory();
260   this->GetImpl()->SetHexoticMaxMemory(theValue);
261   if (theValue != oldValue)
262     SMESH::TPythonDump() << _this() << ".SetHexoticMaxMemory( " << theValue << " )";
263 }
264
265 void HexoticPlugin_Hypothesis_i::SetOptionValue(const char* optionName, const char* optionValue)
266   throw (SALOME::SALOME_Exception)
267 {
268   ASSERT(myBaseImpl);
269   try {
270     std::string name( optionName );
271     if ( !optionValue || !optionValue[0] )
272       UnsetOption( optionName );
273
274     // options having corresponding methods
275
276     else if ( name == "max_memory" )
277       SetHexoticMaxMemory( GetImpl()->ToInt( optionValue ));
278
279     else if ( name == "min_level" )
280       SetHexesMinLevel( GetImpl()->ToInt( optionValue ));
281
282     else if ( name == "max_level" )
283       SetHexesMaxLevel( GetImpl()->ToInt( optionValue ));
284
285     else if ( name == "min_size" )
286       SetMinSize( GetImpl()->ToDbl( optionValue ));
287
288     else if ( name == "max_size" )
289       SetMaxSize( GetImpl()->ToDbl( optionValue ));
290
291     else if ( name == "ridge_angle" )
292       SetHexoticSharpAngleThreshold( GetImpl()->ToDbl( optionValue ));
293
294     else if ( name == "compute_ridges" )
295       SetHexoticIgnoreRidges( ! GetImpl()->ToBool( optionValue ));
296
297     else if ( name == "allow_invalid_elements" )
298       SetHexoticInvalidElements( GetImpl()->ToBool( optionValue ));
299
300     else if ( name == "max_number_of_threads" )
301       SetHexoticNbProc( GetImpl()->ToInt( optionValue ));
302
303     else if ( name == "verbose" )
304       SetHexoticVerbosity( GetImpl()->ToInt( optionValue ));
305
306     // advanced options (for backward compatibility)
307     // else if ( name == "create_tag_on_collision" ||
308     //           name == "tiny_edge_respect_geometry" )
309     //   AddOption( optionName, optionValue );
310
311     else {
312       bool valueChanged = true, isDefault;
313       try {
314         valueChanged = ( this->GetImpl()->GetOptionValue( name, &isDefault ) != optionValue );
315       }
316       catch ( std::invalid_argument ) {
317       }
318       if ( valueChanged )
319       {
320         this->GetImpl()->SetOptionValue(optionName, optionValue);
321         SMESH::TPythonDump() << _this() << ".SetOptionValue( '" << optionName << "', '" << optionValue << "' )";
322       }
323     }
324   } catch (const std::invalid_argument& ex) {
325     THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM );
326   } catch (SALOME_Exception& ex) {
327     THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM );
328   }
329 }
330
331 //=============================================================================
332
333 char* HexoticPlugin_Hypothesis_i::GetOptionValue(const char* optionName)
334   throw (SALOME::SALOME_Exception)
335 {
336   ASSERT(myBaseImpl);
337   try {
338     bool isDefault;
339     return CORBA::string_dup(this->GetImpl()->GetOptionValue(optionName,&isDefault).c_str());
340   } catch (const std::invalid_argument& ex) {
341     THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM );
342   } catch (SALOME_Exception& ex) {
343     THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM );
344   }
345   return 0;
346 }
347
348 //=============================================================================
349
350 void HexoticPlugin_Hypothesis_i::UnsetOption(const char* optionName) {
351   ASSERT(myBaseImpl);
352   if ( !GetImpl()->GetOptionValue( optionName ).empty() )
353   {
354     this->GetImpl()->ClearOption(optionName);
355     SMESH::TPythonDump() << _this() << ".UnsetOption( '" << optionName << "' )";
356   }
357 }
358
359 //=============================================================================
360
361 HexoticPlugin::string_array* HexoticPlugin_Hypothesis_i::GetOptionValues()
362 {
363   HexoticPlugin::string_array_var result = new HexoticPlugin::string_array();
364
365   const ::HexoticPlugin_Hypothesis::TOptionValues & opts = this->GetImpl()->GetOptionValues();
366   result->length(opts.size());
367   int i=0;
368
369   bool isDefault;
370   ::HexoticPlugin_Hypothesis::TOptionValues::const_iterator opIt = opts.begin();
371   for (; opIt != opts.end(); ++opIt, ++i)
372   {
373     std::string name_value_type = opIt->first;
374     //if (!opIt->second.empty())
375     {
376       name_value_type += ":";
377       name_value_type += GetImpl()->GetOptionValue( opIt->first, &isDefault );
378       name_value_type += isDefault ? ":0" : ":1";
379     }
380     result[i] = CORBA::string_dup(name_value_type.c_str());
381   }
382
383   return result._retn();
384 }
385
386 //=============================================================================
387
388 HexoticPlugin::string_array* HexoticPlugin_Hypothesis_i::GetAdvancedOptionValues()
389 {
390   HexoticPlugin::string_array_var result = new HexoticPlugin::string_array();
391
392   const ::HexoticPlugin_Hypothesis::TOptionValues & custom_opts = this->GetImpl()->GetCustomOptionValues();
393   result->length(custom_opts.size());
394   int i=0;
395
396   ::HexoticPlugin_Hypothesis::TOptionValues::const_iterator opIt = custom_opts.begin();
397   for (; opIt != custom_opts.end(); ++opIt, ++i) {
398     std::string name_value_type = opIt->first;
399     if (!opIt->second.empty()) {
400       name_value_type += ":";
401       name_value_type += opIt->second;
402       name_value_type += ":1"; // user defined
403     }
404     result[i] = CORBA::string_dup(name_value_type.c_str());
405   }
406   return result._retn();
407 }
408
409 //=============================================================================
410
411 void HexoticPlugin_Hypothesis_i::SetOptionValues(const HexoticPlugin::string_array& options)
412   throw (SALOME::SALOME_Exception)
413 {
414   for (CORBA::ULong i = 0; i < options.length(); ++i)
415   {
416     std::string name_value_type = options[i].in();
417     if(name_value_type.empty())
418       continue;
419     size_t colonPos = name_value_type.find(':');
420     std::string name, value;
421     if (colonPos == std::string::npos) // ':' not found
422       name = name_value_type;
423     else {
424       name = name_value_type.substr(0, colonPos);
425       if (colonPos < name_value_type.size() - 1 && name_value_type[colonPos] != ' ') {
426         std::string value_type = name_value_type.substr(colonPos + 1);
427         colonPos = value_type.find(':');
428         value = value_type.substr(0, colonPos);
429         if (colonPos < value_type.size() - 1 && value_type[colonPos] != ' ')
430           if ( value_type.substr(colonPos + 1) == "0" ) // is default
431             value.clear();
432       }
433     }
434     SetOptionValue(name.c_str(), value.c_str());
435   }
436 }
437
438 //=============================================================================
439
440 void HexoticPlugin_Hypothesis_i::SetAdvancedOptionValues(const HexoticPlugin::string_array& options)
441 {
442   SMESH::TPythonDump dump;
443
444   std::string optionsAndValues;
445   for ( CORBA::ULong i = 0; i < options.length(); ++i) {
446     std::string name_value_type = options[i].in();
447     if(name_value_type.empty())
448       continue;
449     size_t colonPos = name_value_type.find(':');
450     std::string name, value;
451     if (colonPos == std::string::npos) // ':' not found
452       name = name_value_type;
453     else {
454       name = name_value_type.substr(0, colonPos);
455       if (colonPos < name_value_type.size() - 1 && name_value_type[colonPos] != ' ') {
456         std::string value_type = name_value_type.substr(colonPos + 1);
457         colonPos = value_type.find(':');
458         value = value_type.substr(0, colonPos);
459       }
460     }
461     AddOption(name.c_str(), value.c_str());
462
463     optionsAndValues += name + " " + value + " ";
464   }
465
466   if ( !optionsAndValues.empty() )
467     dump << _this() << ".SetAdvancedOptions( '" << optionsAndValues.c_str() << "' )";
468 }
469
470 //=============================================================================
471
472 void HexoticPlugin_Hypothesis_i::SetAdvancedOption(const char* optionsAndValues)
473   throw (SALOME::SALOME_Exception)
474 {
475   if ( !optionsAndValues ) return;
476
477   SMESH::TPythonDump dump;
478
479   std::istringstream strm( optionsAndValues );
480   std::istream_iterator<std::string> sIt( strm ), sEnd;
481   for ( int nbPairs = 0; sIt != sEnd; ++nbPairs )
482   {
483     std::string option = *sIt;
484     if ( ++sIt != sEnd )
485     {
486       std::string value = *sIt;
487       ++sIt;
488       AddOption( option.c_str(), value.c_str() );
489     }
490     else
491     {
492       if ( nbPairs > 0 )
493         THROW_SALOME_CORBA_EXCEPTION( "Uneven number of options and values" ,SALOME::BAD_PARAM );
494       AddOption( option.c_str(), "" );
495     }
496   }
497   dump << _this() << ".SetAdvancedOption( '" << optionsAndValues << "' )";
498 }
499
500 //=============================================================================
501
502 void HexoticPlugin_Hypothesis_i::AddOption(const char* optionName, const char* optionValue)
503 {
504   ASSERT(myBaseImpl);
505   bool valueChanged = ( !this->GetImpl()->HasOptionDefined(optionName) ||
506                         this->GetImpl()->GetOptionValue(optionName) != optionValue );
507   if (valueChanged) {
508     this->GetImpl()->SetOptionValue(optionName, optionValue);
509     SMESH::TPythonDump() << _this() << ".SetOptionValue( '" << optionName << "', '" << optionValue << "' )";
510   }
511 }
512
513 //=============================================================================
514
515 char* HexoticPlugin_Hypothesis_i::GetOption(const char* optionName)
516 {
517   ASSERT(myBaseImpl);
518   return CORBA::string_dup(this->GetImpl()->GetOptionValue(optionName).c_str());
519 }
520
521 void HexoticPlugin_Hypothesis_i::SetTextOptions(const char* theOptions)
522 {
523   ASSERT(myBaseImpl);
524   std::string oldValue(GetAdvancedOption());
525   this->GetImpl()->SetAdvancedOption(theOptions);
526   if (theOptions != oldValue)
527     SMESH::TPythonDump() << _this() << ".SetAdvancedOption( '" << theOptions << "' )";
528 }
529
530 HexoticPlugin::HexoticPluginSizeMapsList* HexoticPlugin_Hypothesis_i::GetSizeMaps ()
531 {
532   // Get the std::map < std::string entry, double size >
533   HexoticPlugin::HexoticPluginSizeMapsList_var result = new HexoticPlugin::HexoticPluginSizeMapsList();
534   const ::HexoticPlugin_Hypothesis::THexoticSizeMaps sizeMaps = this->GetImpl()->GetSizeMaps();
535   result->length( sizeMaps.size() );
536   
537   // Write the content into a CORBA sequence of struct{ entry=anEntry; size=aSize; }
538   ::HexoticPlugin_Hypothesis::THexoticSizeMaps::const_iterator it = sizeMaps.begin(); 
539   for ( int i = 0; it != sizeMaps.end(); i++, it++ )
540   {
541     HexoticPlugin::HexoticPluginSizeMap_var aSizeMap = new HexoticPlugin::HexoticPluginSizeMap();
542     aSizeMap->entry = CORBA::string_dup( it->first.c_str() );
543     aSizeMap->size = it->second;
544     result[i] = aSizeMap;
545   }
546   return result._retn();
547 }
548
549 void HexoticPlugin_Hypothesis_i::SetSizeMapEntry ( const char* theEntry, CORBA::Double theSize )
550 {
551   bool valueChanged = this->GetImpl()->AddSizeMap(theEntry, theSize);
552   if (valueChanged)
553     SMESH::TPythonDump() << _this() << ".SetSizeMap( "<< theEntry << ", " << theSize << " )";
554 }
555
556 void HexoticPlugin_Hypothesis_i::UnsetSizeMapEntry ( const char* theEntry )
557 {
558   bool entryRemoved = this->GetImpl()->UnsetSizeMap(theEntry);
559   if (entryRemoved)
560     SMESH::TPythonDump() << _this() << ".UnsetSizeMap( "<< theEntry << " )";
561 }
562
563 void HexoticPlugin_Hypothesis_i::SetSizeMap (const GEOM::GEOM_Object_ptr theGeomObj, const double theSize)
564 {
565   ASSERT(myBaseImpl);
566   std::string entry = theGeomObj->GetStudyEntry();
567   SetSizeMapEntry( entry.c_str(), theSize);
568 }
569
570 void HexoticPlugin_Hypothesis_i::UnsetSizeMap (const GEOM::GEOM_Object_ptr theGeomObj)
571 {
572   ASSERT(myBaseImpl);
573   std::string entry = theGeomObj->GetStudyEntry();
574   UnsetSizeMapEntry( entry.c_str());
575 }
576
577 void HexoticPlugin_Hypothesis_i::SetNbLayers(CORBA::Long theVal)
578 {
579   ASSERT(myBaseImpl);
580   CORBA::Long oldValue = GetNbLayers();
581   this->GetImpl()->SetNbLayers(theVal);
582   if (theVal != oldValue)
583     SMESH::TPythonDump() << _this() << ".SetNbLayers( " << theVal << " )";
584 }
585
586 void HexoticPlugin_Hypothesis_i::SetFirstLayerSize(CORBA::Double theVal)
587 {
588   ASSERT(myBaseImpl);
589   CORBA::Double oldValue = GetFirstLayerSize();
590   this->GetImpl()->SetFirstLayerSize(theVal);
591   if (theVal != oldValue)
592     SMESH::TPythonDump() << _this() << ".SetFirstLayerSize( " << theVal << " )";
593 }
594
595 void HexoticPlugin_Hypothesis_i::SetDirection(CORBA::Boolean theVal)
596 {
597   ASSERT(myBaseImpl);
598   CORBA::Boolean oldValue = GetDirection();
599   this->GetImpl()->SetDirection(theVal);
600   if (theVal != oldValue)
601     SMESH::TPythonDump() << _this() << ".SetDirection( " << theVal << " )";
602 }
603
604 void HexoticPlugin_Hypothesis_i::SetGrowth(CORBA::Double theVal)
605 {
606   ASSERT(myBaseImpl);
607   CORBA::Double oldValue = GetGrowth();
608   this->GetImpl()->SetGrowth(theVal);
609   if (theVal != oldValue)
610     SMESH::TPythonDump() << _this() << ".SetGrowth( " << theVal << " )";
611 }
612
613 void HexoticPlugin_Hypothesis_i::SetFacesWithLayers(const ::SMESH::long_array& theVal)
614 {
615   std::vector<int> ids( theVal.length() );
616   for ( unsigned i = 0; i < ids.size(); ++i )
617    ids[i] = theVal[i];
618
619   bool valueChanged = this->GetImpl()->SetFacesWithLayers(ids);
620   if (valueChanged)
621     SMESH::TPythonDump() << _this() << ".SetFacesWithLayers( "<< theVal << " )";
622 }
623
624 void HexoticPlugin_Hypothesis_i::SetImprintedFaces(const ::SMESH::long_array& theVal)
625 {
626   std::vector<int> ids( theVal.length() );
627   for ( unsigned i = 0; i < ids.size(); ++i )
628    ids[i] = theVal[i];
629
630   bool valueChanged = this->GetImpl()->SetImprintedFaces(ids);
631   if (valueChanged)
632     SMESH::TPythonDump() << _this() << ".SetImprintedFaces( "<< theVal << " )";
633 }
634
635 //=============================================================================
636 /*!
637  *  HexoticPlugin_Hypothesis_i::GetHexesMinLevel
638  *  HexoticPlugin_Hypothesis_i::GetHexesMaxLevel
639  *  HexoticPlugin_Hypothesis_i::GetMinSize
640  *  HexoticPlugin_Hypothesis_i::GetMaxSize
641  *  HexoticPlugin_Hypothesis_i::GetHexoticIgnoreRidges
642  *  HexoticPlugin_Hypothesis_i::GetHexoticInvalidElements
643  *  HexoticPlugin_Hypothesis_i::GetHexoticSharpAngleThreshold 
644  *  HexoticPlugin_Hypothesis_i::GetHexoticNbProc 
645  *  HexoticPlugin_Hypothesis_i::GetHexoticWorkingDirectory 
646  *  HexoticPlugin_Hypothesis_i::GetHexoticSdMode
647  *  HexoticPlugin_Hypothesis_i::GetVerbosity
648  *  HexoticPlugin_Hypothesis_i::GetHexoticMaxMemory
649  *  HexoticPlugin_Hypothesis_i::GetTextOptions
650  *  HexoticPlugin_Hypothesis_i::GetNbLayers
651  *  HexoticPlugin_Hypothesis_i::GetFirstLayerSize
652  *  HexoticPlugin_Hypothesis_i::GetDirection
653  *  HexoticPlugin_Hypothesis_i::GetGrowth
654  *  HexoticPlugin_Hypothesis_i::GetFacesWithLayers
655  *  HexoticPlugin_Hypothesis_i::GetImprintedFaces
656  */
657 //=============================================================================
658
659 CORBA::Long HexoticPlugin_Hypothesis_i::GetHexesMinLevel()
660 {
661   ASSERT(myBaseImpl);
662   return this->GetImpl()->GetHexesMinLevel();
663 }
664
665 CORBA::Long HexoticPlugin_Hypothesis_i::GetHexesMaxLevel()
666 {
667   ASSERT(myBaseImpl);
668   return this->GetImpl()->GetHexesMaxLevel();
669 }
670
671 CORBA::Double HexoticPlugin_Hypothesis_i::GetMinSize()
672 {
673   ASSERT(myBaseImpl);
674   return this->GetImpl()->GetMinSize();
675 }
676
677 CORBA::Double HexoticPlugin_Hypothesis_i::GetMaxSize()
678 {
679   ASSERT(myBaseImpl);
680   return this->GetImpl()->GetMaxSize();
681 }
682
683 CORBA::Boolean HexoticPlugin_Hypothesis_i::GetHexoticIgnoreRidges()
684 {
685   ASSERT(myBaseImpl);
686   return this->GetImpl()->GetHexoticIgnoreRidges();
687 }
688
689 CORBA::Boolean HexoticPlugin_Hypothesis_i::GetHexoticInvalidElements()
690 {
691   ASSERT(myBaseImpl);
692   return this->GetImpl()->GetHexoticInvalidElements();
693 }
694
695 CORBA::Double HexoticPlugin_Hypothesis_i::GetHexoticSharpAngleThreshold()
696 {
697   ASSERT(myBaseImpl);
698   return this->GetImpl()->GetHexoticSharpAngleThreshold();
699 }
700
701 CORBA::Long HexoticPlugin_Hypothesis_i::GetHexoticNbProc()
702 {
703   ASSERT(myBaseImpl);
704   return this->GetImpl()->GetHexoticNbProc();
705 }
706
707 char* HexoticPlugin_Hypothesis_i::GetHexoticWorkingDirectory()
708 {
709   ASSERT(myBaseImpl);
710   return CORBA::string_dup( this->GetImpl()->GetHexoticWorkingDirectory().c_str() );
711 }
712
713 CORBA::Long HexoticPlugin_Hypothesis_i::GetHexoticSdMode ()
714 {
715   ASSERT(myBaseImpl);
716   return this->GetImpl()->GetHexoticSdMode();
717 }
718
719 CORBA::Long HexoticPlugin_Hypothesis_i::GetHexoticVerbosity()
720 {
721   ASSERT(myBaseImpl);
722   return this->GetImpl()->GetHexoticVerbosity();
723 }
724
725 CORBA::Long HexoticPlugin_Hypothesis_i::GetHexoticMaxMemory()
726 {
727   ASSERT(myBaseImpl);
728   return this->GetImpl()->GetHexoticMaxMemory();
729 }
730
731 char* HexoticPlugin_Hypothesis_i::GetAdvancedOption()
732 {
733   ASSERT(myBaseImpl);
734   return CORBA::string_dup( this->GetImpl()->GetAdvancedOption( /*customOnly=*/true ).c_str() );
735 }
736 char* HexoticPlugin_Hypothesis_i::GetTextOptions()
737 {
738   ASSERT(myBaseImpl);
739   return CORBA::string_dup( this->GetImpl()->GetAdvancedOption().c_str() );
740 }
741
742 CORBA::Long HexoticPlugin_Hypothesis_i::GetNbLayers()
743 {
744   ASSERT(myBaseImpl);
745   return this->GetImpl()->GetNbLayers();
746 }
747
748 CORBA::Double HexoticPlugin_Hypothesis_i::GetFirstLayerSize()
749 {
750   ASSERT(myBaseImpl);
751   return this->GetImpl()->GetFirstLayerSize();
752 }
753
754 CORBA::Boolean HexoticPlugin_Hypothesis_i::GetDirection()
755 {
756   ASSERT(myBaseImpl);
757   return this->GetImpl()->GetDirection();
758 }
759
760 CORBA::Double HexoticPlugin_Hypothesis_i::GetGrowth()
761 {
762   ASSERT(myBaseImpl);
763   return this->GetImpl()->GetGrowth();
764 }
765
766 SMESH::long_array* HexoticPlugin_Hypothesis_i::GetFacesWithLayers()
767 {
768   ASSERT(myBaseImpl);
769   std::vector<int> idsVec = this->GetImpl()->GetFacesWithLayers();
770   SMESH::long_array_var ids = new SMESH::long_array;
771   ids->length( idsVec.size() );
772   for ( unsigned i = 0; i < idsVec.size(); ++i )
773     ids[i] = idsVec[i];
774   return ids._retn();
775 }
776
777 SMESH::long_array* HexoticPlugin_Hypothesis_i::GetImprintedFaces()
778 {
779   ASSERT(myBaseImpl);
780   std::vector<int> idsVec = this->GetImpl()->GetImprintedFaces();
781   SMESH::long_array_var ids = new SMESH::long_array;
782   ids->length( idsVec.size() );
783   for ( unsigned i = 0; i < idsVec.size(); ++i )
784     ids[i] = idsVec[i];
785   return ids._retn();
786 }
787 //=============================================================================
788 /*!
789  *  HexoticPlugin_Hypothesis_i::GetImpl
790  *
791  *  Get implementation
792  */
793 //=============================================================================
794 ::HexoticPlugin_Hypothesis* HexoticPlugin_Hypothesis_i::GetImpl()
795 {
796   return (::HexoticPlugin_Hypothesis*)myBaseImpl;
797 }
798
799 //================================================================================
800 /*!
801  * \brief Verify whether hypothesis supports given entity type
802  * \param type - dimension (see SMESH::Dimension enumeration)
803  * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
804  *
805  * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
806  */
807 //================================================================================
808 CORBA::Boolean HexoticPlugin_Hypothesis_i::IsDimSupported( SMESH::Dimension type )
809 {
810   return type == SMESH::DIM_3D;
811 }
812
813 //================================================================================
814 /*!
815  * \brief Return geometry this hypothesis depends on. Return false if there is no geometry parameter
816  */
817 //================================================================================
818
819 bool
820 HexoticPlugin_Hypothesis_i::getObjectsDependOn( std::vector< std::string > & entryArray,
821                                                 std::vector< int >         & subIDArray ) const
822 {
823   typedef ::HexoticPlugin_Hypothesis THyp;
824   const THyp* h = static_cast< const THyp*> ( myBaseImpl );
825
826   const THyp::THexoticSizeMaps& sizeMaps = h->GetSizeMaps();
827   THyp::THexoticSizeMaps::const_iterator entry2size = sizeMaps.cbegin();
828   for ( ; entry2size != sizeMaps.cend(); ++entry2size )
829     entryArray.push_back( entry2size->first );
830
831   subIDArray = h->GetFacesWithLayers();
832   subIDArray.insert( subIDArray.end(),
833                      h->GetImprintedFaces().begin(),
834                      h->GetImprintedFaces().end());
835
836   return true;
837 }
838
839 //================================================================================
840 /*!
841  * \brief Set new geometry instead of that returned by getObjectsDependOn()
842  */
843 //================================================================================
844
845 bool
846 HexoticPlugin_Hypothesis_i::setObjectsDependOn( std::vector< std::string > & entryArray,
847                                                 std::vector< int >         & subIDArray )
848 {
849   typedef ::HexoticPlugin_Hypothesis THyp;
850   THyp* h = static_cast< THyp*> ( myBaseImpl );
851
852   size_t iEnt = 0;
853
854   THyp::THexoticSizeMaps& sizeMapsNew = const_cast< THyp::THexoticSizeMaps& > ( h->GetSizeMaps() );
855   THyp::THexoticSizeMaps sizeMaps;
856   sizeMaps.swap( sizeMapsNew );
857   THyp::THexoticSizeMaps::const_iterator entry2size = sizeMaps.cbegin();
858   for ( ; entry2size != sizeMaps.cend(); ++entry2size )
859   {
860     const std::string& entry = entryArray[ iEnt++ ];
861     if ( entry.empty() == entry2size->first.empty() )
862       sizeMapsNew[ entry ] = entry2size->second;
863   }
864
865   size_t nbFacesWL = h->GetFacesWithLayers().size();
866   std::vector<int> facesWithLayers;
867   size_t iID = 0;
868   for ( ; iID < nbFacesWL; ++iID )
869     if ( subIDArray[ iID ] > 0 )
870       facesWithLayers.push_back( subIDArray[ iID ]);
871   h->SetFacesWithLayers( facesWithLayers );
872
873   std::vector<int> imprintedFaces;
874   for ( ; iID < subIDArray.size(); ++iID )
875     if ( subIDArray[ iID ] > 0 )
876       imprintedFaces.push_back( subIDArray[ iID ]);
877   h->SetImprintedFaces( imprintedFaces );
878
879   return iID == subIDArray.size() && iEnt == entryArray.size();
880 }