Salome HOME
updated copyright message
[plugins/hexoticplugin.git] / src / HexoticPlugin / HexoticPlugin_Hypothesis_i.cxx
1 // Copyright (C) 2007-2023  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)
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 {
267   ASSERT(myBaseImpl);
268   try {
269     std::string name( optionName );
270     if ( !optionValue || !optionValue[0] )
271       UnsetOption( optionName );
272
273     // options having corresponding methods
274
275     else if ( name == "max_memory" )
276       SetHexoticMaxMemory( GetImpl()->ToInt( optionValue ));
277
278     else if ( name == "min_level" )
279       SetHexesMinLevel( GetImpl()->ToInt( optionValue ));
280
281     else if ( name == "max_level" )
282       SetHexesMaxLevel( GetImpl()->ToInt( optionValue ));
283
284     else if ( name == "min_size" )
285       SetMinSize( GetImpl()->ToDbl( optionValue ));
286
287     else if ( name == "max_size" )
288       SetMaxSize( GetImpl()->ToDbl( optionValue ));
289
290     else if ( name == "ridge_angle" )
291       SetHexoticSharpAngleThreshold( GetImpl()->ToDbl( optionValue ));
292
293     else if ( name == "compute_ridges" )
294       SetHexoticIgnoreRidges( ! GetImpl()->ToBool( optionValue ));
295
296     else if ( name == "allow_invalid_elements" )
297       SetHexoticInvalidElements( GetImpl()->ToBool( optionValue ));
298
299     else if ( name == "max_number_of_threads" )
300       SetHexoticNbProc( GetImpl()->ToInt( optionValue ));
301
302     else if ( name == "verbose" )
303       SetHexoticVerbosity( GetImpl()->ToInt( optionValue ));
304
305     // advanced options (for backward compatibility)
306     // else if ( name == "create_tag_on_collision" ||
307     //           name == "tiny_edge_respect_geometry" )
308     //   AddOption( optionName, optionValue );
309
310     else {
311       bool valueChanged = true, isDefault;
312       try {
313         valueChanged = ( this->GetImpl()->GetOptionValue( name, &isDefault ) != optionValue );
314       }
315       catch ( std::invalid_argument& ) {
316       }
317       if ( valueChanged )
318       {
319         this->GetImpl()->SetOptionValue(optionName, optionValue);
320         SMESH::TPythonDump() << _this() << ".SetOptionValue( '" << optionName << "', '" << optionValue << "' )";
321       }
322     }
323   } catch (const std::invalid_argument& ex) {
324     THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM );
325   } catch (SALOME_Exception& ex) {
326     THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM );
327   }
328 }
329
330 //=============================================================================
331
332 char* HexoticPlugin_Hypothesis_i::GetOptionValue(const char* optionName)
333 {
334   ASSERT(myBaseImpl);
335   try {
336     bool isDefault;
337     return CORBA::string_dup(this->GetImpl()->GetOptionValue(optionName,&isDefault).c_str());
338   } catch (const std::invalid_argument& ex) {
339     THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM );
340   } catch (SALOME_Exception& ex) {
341     THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM );
342   }
343   return 0;
344 }
345
346 //=============================================================================
347
348 void HexoticPlugin_Hypothesis_i::UnsetOption(const char* optionName) {
349   ASSERT(myBaseImpl);
350   if ( !GetImpl()->GetOptionValue( optionName ).empty() )
351   {
352     this->GetImpl()->ClearOption(optionName);
353     SMESH::TPythonDump() << _this() << ".UnsetOption( '" << optionName << "' )";
354   }
355 }
356
357 //=============================================================================
358
359 HexoticPlugin::string_array* HexoticPlugin_Hypothesis_i::GetOptionValues()
360 {
361   HexoticPlugin::string_array_var result = new HexoticPlugin::string_array();
362
363   const ::HexoticPlugin_Hypothesis::TOptionValues & opts = this->GetImpl()->GetOptionValues();
364   result->length(opts.size());
365   int i=0;
366
367   bool isDefault;
368   ::HexoticPlugin_Hypothesis::TOptionValues::const_iterator opIt = opts.begin();
369   for (; opIt != opts.end(); ++opIt, ++i)
370   {
371     std::string name_value_type = opIt->first;
372     //if (!opIt->second.empty())
373     {
374       name_value_type += ":";
375       name_value_type += GetImpl()->GetOptionValue( opIt->first, &isDefault );
376       name_value_type += isDefault ? ":0" : ":1";
377     }
378     result[i] = CORBA::string_dup(name_value_type.c_str());
379   }
380
381   return result._retn();
382 }
383
384 //=============================================================================
385
386 HexoticPlugin::string_array* HexoticPlugin_Hypothesis_i::GetAdvancedOptionValues()
387 {
388   HexoticPlugin::string_array_var result = new HexoticPlugin::string_array();
389
390   const ::HexoticPlugin_Hypothesis::TOptionValues & custom_opts = this->GetImpl()->GetCustomOptionValues();
391   result->length(custom_opts.size());
392   int i=0;
393
394   ::HexoticPlugin_Hypothesis::TOptionValues::const_iterator opIt = custom_opts.begin();
395   for (; opIt != custom_opts.end(); ++opIt, ++i) {
396     std::string name_value_type = opIt->first;
397     if (!opIt->second.empty()) {
398       name_value_type += ":";
399       name_value_type += opIt->second;
400       name_value_type += ":1"; // user defined
401     }
402     result[i] = CORBA::string_dup(name_value_type.c_str());
403   }
404   return result._retn();
405 }
406
407 //=============================================================================
408
409 void HexoticPlugin_Hypothesis_i::SetOptionValues(const HexoticPlugin::string_array& options)
410 {
411   for (CORBA::ULong i = 0; i < options.length(); ++i)
412   {
413     std::string name_value_type = options[i].in();
414     if(name_value_type.empty())
415       continue;
416     size_t colonPos = name_value_type.find(':');
417     std::string name, value;
418     if (colonPos == std::string::npos) // ':' not found
419       name = name_value_type;
420     else {
421       name = name_value_type.substr(0, colonPos);
422       if (colonPos < name_value_type.size() - 1 && name_value_type[colonPos] != ' ') {
423         std::string value_type = name_value_type.substr(colonPos + 1);
424         colonPos = value_type.find(':');
425         value = value_type.substr(0, colonPos);
426         if (colonPos < value_type.size() - 1 && value_type[colonPos] != ' ')
427           if ( value_type.substr(colonPos + 1) == "0" ) // is default
428             value.clear();
429       }
430     }
431     SetOptionValue(name.c_str(), value.c_str());
432   }
433 }
434
435 //=============================================================================
436
437 void HexoticPlugin_Hypothesis_i::SetAdvancedOptionValues(const HexoticPlugin::string_array& options)
438 {
439   SMESH::TPythonDump dump;
440
441   std::string optionsAndValues;
442   for ( CORBA::ULong i = 0; i < options.length(); ++i) {
443     std::string name_value_type = options[i].in();
444     if(name_value_type.empty())
445       continue;
446     size_t colonPos = name_value_type.find(':');
447     std::string name, value;
448     if (colonPos == std::string::npos) // ':' not found
449       name = name_value_type;
450     else {
451       name = name_value_type.substr(0, colonPos);
452       if (colonPos < name_value_type.size() - 1 && name_value_type[colonPos] != ' ') {
453         std::string value_type = name_value_type.substr(colonPos + 1);
454         colonPos = value_type.find(':');
455         value = value_type.substr(0, colonPos);
456       }
457     }
458     AddOption(name.c_str(), value.c_str());
459
460     optionsAndValues += name + " " + value + " ";
461   }
462
463   if ( !optionsAndValues.empty() )
464     dump << _this() << ".SetAdvancedOptions( '" << optionsAndValues.c_str() << "' )";
465 }
466
467 //=============================================================================
468
469 void HexoticPlugin_Hypothesis_i::SetAdvancedOption(const char* optionsAndValues)
470 {
471   if ( !optionsAndValues ) return;
472
473   SMESH::TPythonDump dump;
474
475   std::istringstream strm( optionsAndValues );
476   std::istream_iterator<std::string> sIt( strm ), sEnd;
477   for ( int nbPairs = 0; sIt != sEnd; ++nbPairs )
478   {
479     std::string option = *sIt;
480     if ( ++sIt != sEnd )
481     {
482       std::string value = *sIt;
483       ++sIt;
484       AddOption( option.c_str(), value.c_str() );
485     }
486     else
487     {
488       if ( nbPairs > 0 )
489         THROW_SALOME_CORBA_EXCEPTION( "Uneven number of options and values" ,SALOME::BAD_PARAM );
490       AddOption( option.c_str(), "" );
491     }
492   }
493   dump << _this() << ".SetAdvancedOption( '" << optionsAndValues << "' )";
494 }
495
496 //=============================================================================
497
498 void HexoticPlugin_Hypothesis_i::AddOption(const char* optionName, const char* optionValue)
499 {
500   ASSERT(myBaseImpl);
501   bool valueChanged = ( !this->GetImpl()->HasOptionDefined(optionName) ||
502                         this->GetImpl()->GetOptionValue(optionName) != optionValue );
503   if (valueChanged) {
504     this->GetImpl()->SetOptionValue(optionName, optionValue);
505     SMESH::TPythonDump() << _this() << ".SetOptionValue( '" << optionName << "', '" << optionValue << "' )";
506   }
507 }
508
509 //=============================================================================
510
511 char* HexoticPlugin_Hypothesis_i::GetOption(const char* optionName)
512 {
513   ASSERT(myBaseImpl);
514   return CORBA::string_dup(this->GetImpl()->GetOptionValue(optionName).c_str());
515 }
516
517 void HexoticPlugin_Hypothesis_i::SetTextOptions(const char* theOptions)
518 {
519   ASSERT(myBaseImpl);
520   std::string oldValue(GetAdvancedOption());
521   this->GetImpl()->SetAdvancedOption(theOptions);
522   if (theOptions != oldValue)
523     SMESH::TPythonDump() << _this() << ".SetAdvancedOption( '" << theOptions << "' )";
524 }
525
526 HexoticPlugin::HexoticPluginSizeMapsList* HexoticPlugin_Hypothesis_i::GetSizeMaps ()
527 {
528   // Get the std::map < std::string entry, double size >
529   HexoticPlugin::HexoticPluginSizeMapsList_var result = new HexoticPlugin::HexoticPluginSizeMapsList();
530   const ::HexoticPlugin_Hypothesis::THexoticSizeMaps sizeMaps = this->GetImpl()->GetSizeMaps();
531   result->length( sizeMaps.size() );
532   
533   // Write the content into a CORBA sequence of struct{ entry=anEntry; size=aSize; }
534   ::HexoticPlugin_Hypothesis::THexoticSizeMaps::const_iterator it = sizeMaps.begin(); 
535   for ( int i = 0; it != sizeMaps.end(); i++, it++ )
536   {
537     HexoticPlugin::HexoticPluginSizeMap_var aSizeMap = new HexoticPlugin::HexoticPluginSizeMap();
538     aSizeMap->entry = CORBA::string_dup( it->first.c_str() );
539     aSizeMap->size = it->second;
540     result[i] = aSizeMap;
541   }
542   return result._retn();
543 }
544
545 void HexoticPlugin_Hypothesis_i::SetSizeMapEntry ( const char* theEntry, CORBA::Double theSize )
546 {
547   bool valueChanged = this->GetImpl()->AddSizeMap(theEntry, theSize);
548   if (valueChanged)
549     SMESH::TPythonDump() << _this() << ".SetSizeMap( "<< theEntry << ", " << theSize << " )";
550 }
551
552 void HexoticPlugin_Hypothesis_i::UnsetSizeMapEntry ( const char* theEntry )
553 {
554   bool entryRemoved = this->GetImpl()->UnsetSizeMap(theEntry);
555   if (entryRemoved)
556     SMESH::TPythonDump() << _this() << ".UnsetSizeMap( "<< theEntry << " )";
557 }
558
559 void HexoticPlugin_Hypothesis_i::SetSizeMap (const GEOM::GEOM_Object_ptr theGeomObj, const double theSize)
560 {
561   ASSERT(myBaseImpl);
562   std::string entry = theGeomObj->GetStudyEntry();
563   SetSizeMapEntry( entry.c_str(), theSize);
564 }
565
566 void HexoticPlugin_Hypothesis_i::UnsetSizeMap (const GEOM::GEOM_Object_ptr theGeomObj)
567 {
568   ASSERT(myBaseImpl);
569   std::string entry = theGeomObj->GetStudyEntry();
570   UnsetSizeMapEntry( entry.c_str());
571 }
572
573 void HexoticPlugin_Hypothesis_i::SetNbLayers(CORBA::Long theVal)
574 {
575   ASSERT(myBaseImpl);
576   CORBA::Long oldValue = GetNbLayers();
577   this->GetImpl()->SetNbLayers(theVal);
578   if (theVal != oldValue)
579     SMESH::TPythonDump() << _this() << ".SetNbLayers( " << theVal << " )";
580 }
581
582 void HexoticPlugin_Hypothesis_i::SetFirstLayerSize(CORBA::Double theVal)
583 {
584   ASSERT(myBaseImpl);
585   CORBA::Double oldValue = GetFirstLayerSize();
586   this->GetImpl()->SetFirstLayerSize(theVal);
587   if (theVal != oldValue)
588     SMESH::TPythonDump() << _this() << ".SetFirstLayerSize( " << theVal << " )";
589 }
590
591 void HexoticPlugin_Hypothesis_i::SetDirection(CORBA::Boolean theVal)
592 {
593   ASSERT(myBaseImpl);
594   CORBA::Boolean oldValue = GetDirection();
595   this->GetImpl()->SetDirection(theVal);
596   if (theVal != oldValue)
597     SMESH::TPythonDump() << _this() << ".SetDirection( " << theVal << " )";
598 }
599
600 void HexoticPlugin_Hypothesis_i::SetGrowth(CORBA::Double theVal)
601 {
602   ASSERT(myBaseImpl);
603   CORBA::Double oldValue = GetGrowth();
604   this->GetImpl()->SetGrowth(theVal);
605   if (theVal != oldValue)
606     SMESH::TPythonDump() << _this() << ".SetGrowth( " << theVal << " )";
607 }
608
609 void HexoticPlugin_Hypothesis_i::SetFacesWithLayers(const ::SMESH::long_array& theVal)
610 {
611   std::vector<int> ids( theVal.length() );
612   for ( unsigned i = 0; i < ids.size(); ++i )
613    ids[i] = theVal[i];
614
615   bool valueChanged = this->GetImpl()->SetFacesWithLayers(ids);
616   if (valueChanged)
617     SMESH::TPythonDump() << _this() << ".SetFacesWithLayers( "<< theVal << " )";
618 }
619
620 void HexoticPlugin_Hypothesis_i::SetImprintedFaces(const ::SMESH::long_array& theVal)
621 {
622   std::vector<int> ids( theVal.length() );
623   for ( unsigned i = 0; i < ids.size(); ++i )
624    ids[i] = theVal[i];
625
626   bool valueChanged = this->GetImpl()->SetImprintedFaces(ids);
627   if (valueChanged)
628     SMESH::TPythonDump() << _this() << ".SetImprintedFaces( "<< theVal << " )";
629 }
630
631 //=============================================================================
632 /*!
633  *  HexoticPlugin_Hypothesis_i::GetHexesMinLevel
634  *  HexoticPlugin_Hypothesis_i::GetHexesMaxLevel
635  *  HexoticPlugin_Hypothesis_i::GetMinSize
636  *  HexoticPlugin_Hypothesis_i::GetMaxSize
637  *  HexoticPlugin_Hypothesis_i::GetHexoticIgnoreRidges
638  *  HexoticPlugin_Hypothesis_i::GetHexoticInvalidElements
639  *  HexoticPlugin_Hypothesis_i::GetHexoticSharpAngleThreshold 
640  *  HexoticPlugin_Hypothesis_i::GetHexoticNbProc 
641  *  HexoticPlugin_Hypothesis_i::GetHexoticWorkingDirectory 
642  *  HexoticPlugin_Hypothesis_i::GetHexoticSdMode
643  *  HexoticPlugin_Hypothesis_i::GetVerbosity
644  *  HexoticPlugin_Hypothesis_i::GetHexoticMaxMemory
645  *  HexoticPlugin_Hypothesis_i::GetTextOptions
646  *  HexoticPlugin_Hypothesis_i::GetNbLayers
647  *  HexoticPlugin_Hypothesis_i::GetFirstLayerSize
648  *  HexoticPlugin_Hypothesis_i::GetDirection
649  *  HexoticPlugin_Hypothesis_i::GetGrowth
650  *  HexoticPlugin_Hypothesis_i::GetFacesWithLayers
651  *  HexoticPlugin_Hypothesis_i::GetImprintedFaces
652  */
653 //=============================================================================
654
655 CORBA::Long HexoticPlugin_Hypothesis_i::GetHexesMinLevel()
656 {
657   ASSERT(myBaseImpl);
658   return this->GetImpl()->GetHexesMinLevel();
659 }
660
661 CORBA::Long HexoticPlugin_Hypothesis_i::GetHexesMaxLevel()
662 {
663   ASSERT(myBaseImpl);
664   return this->GetImpl()->GetHexesMaxLevel();
665 }
666
667 CORBA::Double HexoticPlugin_Hypothesis_i::GetMinSize()
668 {
669   ASSERT(myBaseImpl);
670   return this->GetImpl()->GetMinSize();
671 }
672
673 CORBA::Double HexoticPlugin_Hypothesis_i::GetMaxSize()
674 {
675   ASSERT(myBaseImpl);
676   return this->GetImpl()->GetMaxSize();
677 }
678
679 CORBA::Boolean HexoticPlugin_Hypothesis_i::GetHexoticIgnoreRidges()
680 {
681   ASSERT(myBaseImpl);
682   return this->GetImpl()->GetHexoticIgnoreRidges();
683 }
684
685 CORBA::Boolean HexoticPlugin_Hypothesis_i::GetHexoticInvalidElements()
686 {
687   ASSERT(myBaseImpl);
688   return this->GetImpl()->GetHexoticInvalidElements();
689 }
690
691 CORBA::Double HexoticPlugin_Hypothesis_i::GetHexoticSharpAngleThreshold()
692 {
693   ASSERT(myBaseImpl);
694   return this->GetImpl()->GetHexoticSharpAngleThreshold();
695 }
696
697 CORBA::Long HexoticPlugin_Hypothesis_i::GetHexoticNbProc()
698 {
699   ASSERT(myBaseImpl);
700   return this->GetImpl()->GetHexoticNbProc();
701 }
702
703 char* HexoticPlugin_Hypothesis_i::GetHexoticWorkingDirectory()
704 {
705   ASSERT(myBaseImpl);
706   return CORBA::string_dup( this->GetImpl()->GetHexoticWorkingDirectory().c_str() );
707 }
708
709 CORBA::Long HexoticPlugin_Hypothesis_i::GetHexoticSdMode ()
710 {
711   ASSERT(myBaseImpl);
712   return this->GetImpl()->GetHexoticSdMode();
713 }
714
715 CORBA::Long HexoticPlugin_Hypothesis_i::GetHexoticVerbosity()
716 {
717   ASSERT(myBaseImpl);
718   return this->GetImpl()->GetHexoticVerbosity();
719 }
720
721 CORBA::Long HexoticPlugin_Hypothesis_i::GetHexoticMaxMemory()
722 {
723   ASSERT(myBaseImpl);
724   return this->GetImpl()->GetHexoticMaxMemory();
725 }
726
727 char* HexoticPlugin_Hypothesis_i::GetAdvancedOption()
728 {
729   ASSERT(myBaseImpl);
730   return CORBA::string_dup( this->GetImpl()->GetAdvancedOption( /*customOnly=*/true ).c_str() );
731 }
732 char* HexoticPlugin_Hypothesis_i::GetTextOptions()
733 {
734   ASSERT(myBaseImpl);
735   return CORBA::string_dup( this->GetImpl()->GetAdvancedOption().c_str() );
736 }
737
738 CORBA::Long HexoticPlugin_Hypothesis_i::GetNbLayers()
739 {
740   ASSERT(myBaseImpl);
741   return this->GetImpl()->GetNbLayers();
742 }
743
744 CORBA::Double HexoticPlugin_Hypothesis_i::GetFirstLayerSize()
745 {
746   ASSERT(myBaseImpl);
747   return this->GetImpl()->GetFirstLayerSize();
748 }
749
750 CORBA::Boolean HexoticPlugin_Hypothesis_i::GetDirection()
751 {
752   ASSERT(myBaseImpl);
753   return this->GetImpl()->GetDirection();
754 }
755
756 CORBA::Double HexoticPlugin_Hypothesis_i::GetGrowth()
757 {
758   ASSERT(myBaseImpl);
759   return this->GetImpl()->GetGrowth();
760 }
761
762 SMESH::long_array* HexoticPlugin_Hypothesis_i::GetFacesWithLayers()
763 {
764   ASSERT(myBaseImpl);
765   std::vector<int> idsVec = this->GetImpl()->GetFacesWithLayers();
766   SMESH::long_array_var ids = new SMESH::long_array;
767   ids->length( idsVec.size() );
768   for ( unsigned i = 0; i < idsVec.size(); ++i )
769     ids[i] = idsVec[i];
770   return ids._retn();
771 }
772
773 SMESH::long_array* HexoticPlugin_Hypothesis_i::GetImprintedFaces()
774 {
775   ASSERT(myBaseImpl);
776   std::vector<int> idsVec = this->GetImpl()->GetImprintedFaces();
777   SMESH::long_array_var ids = new SMESH::long_array;
778   ids->length( idsVec.size() );
779   for ( unsigned i = 0; i < idsVec.size(); ++i )
780     ids[i] = idsVec[i];
781   return ids._retn();
782 }
783 //=============================================================================
784 /*!
785  *  HexoticPlugin_Hypothesis_i::GetImpl
786  *
787  *  Get implementation
788  */
789 //=============================================================================
790 ::HexoticPlugin_Hypothesis* HexoticPlugin_Hypothesis_i::GetImpl()
791 {
792   return (::HexoticPlugin_Hypothesis*)myBaseImpl;
793 }
794
795 //================================================================================
796 /*!
797  * \brief Verify whether hypothesis supports given entity type
798  * \param type - dimension (see SMESH::Dimension enumeration)
799  * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
800  *
801  * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
802  */
803 //================================================================================
804 CORBA::Boolean HexoticPlugin_Hypothesis_i::IsDimSupported( SMESH::Dimension type )
805 {
806   return type == SMESH::DIM_3D;
807 }
808
809 //================================================================================
810 /*!
811  * \brief Return geometry this hypothesis depends on. Return false if there is no geometry parameter
812  */
813 //================================================================================
814
815 bool
816 HexoticPlugin_Hypothesis_i::getObjectsDependOn( std::vector< std::string > & entryArray,
817                                                 std::vector< int >         & subIDArray ) const
818 {
819   typedef ::HexoticPlugin_Hypothesis THyp;
820   const THyp* h = static_cast< const THyp*> ( myBaseImpl );
821
822   const THyp::THexoticSizeMaps& sizeMaps = h->GetSizeMaps();
823   THyp::THexoticSizeMaps::const_iterator entry2size = sizeMaps.cbegin();
824   for ( ; entry2size != sizeMaps.cend(); ++entry2size )
825     entryArray.push_back( entry2size->first );
826
827   subIDArray = h->GetFacesWithLayers();
828   subIDArray.insert( subIDArray.end(),
829                      h->GetImprintedFaces().begin(),
830                      h->GetImprintedFaces().end());
831
832   return true;
833 }
834
835 //================================================================================
836 /*!
837  * \brief Set new geometry instead of that returned by getObjectsDependOn()
838  */
839 //================================================================================
840
841 bool
842 HexoticPlugin_Hypothesis_i::setObjectsDependOn( std::vector< std::string > & entryArray,
843                                                 std::vector< int >         & subIDArray )
844 {
845   typedef ::HexoticPlugin_Hypothesis THyp;
846   THyp* h = static_cast< THyp*> ( myBaseImpl );
847
848   size_t iEnt = 0;
849
850   THyp::THexoticSizeMaps& sizeMapsNew = const_cast< THyp::THexoticSizeMaps& > ( h->GetSizeMaps() );
851   THyp::THexoticSizeMaps sizeMaps;
852   sizeMaps.swap( sizeMapsNew );
853   THyp::THexoticSizeMaps::const_iterator entry2size = sizeMaps.cbegin();
854   for ( ; entry2size != sizeMaps.cend(); ++entry2size )
855   {
856     const std::string& entry = entryArray[ iEnt++ ];
857     if ( entry.empty() == entry2size->first.empty() )
858       sizeMapsNew[ entry ] = entry2size->second;
859   }
860
861   size_t nbFacesWL = h->GetFacesWithLayers().size();
862   std::vector<int> facesWithLayers;
863   size_t iID = 0;
864   for ( ; iID < nbFacesWL; ++iID )
865     if ( subIDArray[ iID ] > 0 )
866       facesWithLayers.push_back( subIDArray[ iID ]);
867   h->SetFacesWithLayers( facesWithLayers );
868
869   std::vector<int> imprintedFaces;
870   for ( ; iID < subIDArray.size(); ++iID )
871     if ( subIDArray[ iID ] > 0 )
872       imprintedFaces.push_back( subIDArray[ iID ]);
873   h->SetImprintedFaces( imprintedFaces );
874
875   return iID == subIDArray.size() && iEnt == entryArray.size();
876 }