Salome HOME
Fixed bad Save/Load of GHS3D hypothesis in hdf file
[plugins/ghs3dplugin.git] / src / GHS3DPlugin_Hypothesis.cxx
1 //  Copyright (C) 2004-2008  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.
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.cxx
21 // Created   : Wed Apr  2 12:36:29 2008
22 // Author    : Edward AGAPOV (eap)
23 //=============================================================================
24 //
25 #include "GHS3DPlugin_Hypothesis.hxx"
26
27 #include <TCollection_AsciiString.hxx>
28
29 #ifdef WNT
30 #include <process.h>
31 #define getpid _getpid
32 #endif
33
34 //=======================================================================
35 //function : GHS3DPlugin_Hypothesis
36 //=======================================================================
37
38 GHS3DPlugin_Hypothesis::GHS3DPlugin_Hypothesis(int hypId, int studyId, SMESH_Gen * gen)
39   : SMESH_Hypothesis(hypId, studyId, gen),
40   myToMeshHoles(DefaultMeshHoles()),
41   myMaximumMemory(-1),
42   myInitialMemory(-1),
43   myOptimizationLevel(DefaultOptimizationLevel()),
44   myWorkingDirectory(DefaultWorkingDirectory()),
45   myKeepFiles(DefaultKeepFiles()),
46   myVerboseLevel(DefaultVerboseLevel()),
47   myToCreateNewNodes(DefaultToCreateNewNodes()),
48   myToUseBoundaryRecoveryVersion(DefaultToUseBoundaryRecoveryVersion()),
49   myToUseFemCorrection(DefaultToUseFEMCorrection()),
50   myToRemoveCentralPoint(DefaultToRemoveCentralPoint()),
51   myEnforcedVertices(DefaultEnforcedVertices())
52 {
53   _name = "GHS3D_Parameters";
54   _param_algo_dim = 3;
55 }
56
57 //=======================================================================
58 //function : SetToMeshHoles
59 //=======================================================================
60
61 void GHS3DPlugin_Hypothesis::SetToMeshHoles(bool toMesh)
62 {
63   if ( myToMeshHoles != toMesh ) {
64     myToMeshHoles = toMesh;
65     NotifySubMeshesHypothesisModification();
66   }
67 }
68
69 //=======================================================================
70 //function : GetToMeshHoles
71 //=======================================================================
72
73 bool GHS3DPlugin_Hypothesis::GetToMeshHoles(bool checkFreeOption) const
74 {
75   if (checkFreeOption && !myTextOption.empty()) {
76     if ( myTextOption.find("-c 0"))
77       return true;
78     if ( myTextOption.find("-c 1"))
79       return false;
80   }
81   return myToMeshHoles;
82 }
83
84 //=======================================================================
85 //function : SetMaximumMemory
86 //=======================================================================
87
88 void GHS3DPlugin_Hypothesis::SetMaximumMemory(short MB)
89 {
90   if ( myMaximumMemory != MB ) {
91     myMaximumMemory = MB;
92     NotifySubMeshesHypothesisModification();
93   }
94 }
95
96 //=======================================================================
97 //function : GetMaximumMemory
98 //           * automatic memory adjustment mode. Default is zero
99 //=======================================================================
100
101 short GHS3DPlugin_Hypothesis::GetMaximumMemory() const
102 {
103   return myMaximumMemory;
104 }
105
106 //=======================================================================
107 //function : SetInitialMemory
108 //=======================================================================
109
110 void GHS3DPlugin_Hypothesis::SetInitialMemory(short MB)
111 {
112   if ( myInitialMemory != MB ) {
113     myInitialMemory = MB;
114     NotifySubMeshesHypothesisModification();
115   }
116 }
117
118 //=======================================================================
119 //function : GetInitialMemory
120 //=======================================================================
121
122 short GHS3DPlugin_Hypothesis::GetInitialMemory() const
123 {
124   return myInitialMemory;
125 }
126
127 //=======================================================================
128 //function : SetOptimizationLevel
129 //=======================================================================
130
131 void GHS3DPlugin_Hypothesis::SetOptimizationLevel(OptimizationLevel level)
132 {
133   if ( myOptimizationLevel != level ) {
134     myOptimizationLevel = level;
135     NotifySubMeshesHypothesisModification();
136   }
137 }
138
139 //=======================================================================
140 //function : GetOptimizationLevel
141 //=======================================================================
142
143 GHS3DPlugin_Hypothesis::OptimizationLevel GHS3DPlugin_Hypothesis::GetOptimizationLevel() const
144 {
145   return (OptimizationLevel) myOptimizationLevel;
146 }
147
148 //=======================================================================
149 //function : SetWorkingDirectory
150 //=======================================================================
151
152 void GHS3DPlugin_Hypothesis::SetWorkingDirectory(const std::string& path)
153 {
154   if ( myWorkingDirectory != path ) {
155     myWorkingDirectory = path;
156     NotifySubMeshesHypothesisModification();
157   }
158 }
159
160 //=======================================================================
161 //function : GetWorkingDirectory
162 //=======================================================================
163
164 std::string GHS3DPlugin_Hypothesis::GetWorkingDirectory() const
165 {
166   return myWorkingDirectory;
167 }
168
169 //=======================================================================
170 //function : SetKeepFiles
171 //=======================================================================
172
173 void GHS3DPlugin_Hypothesis::SetKeepFiles(bool toKeep)
174 {
175   if ( myKeepFiles != toKeep ) {
176     myKeepFiles = toKeep;
177     NotifySubMeshesHypothesisModification();
178   }
179 }
180
181 //=======================================================================
182 //function : GetKeepFiles
183 //=======================================================================
184
185 bool GHS3DPlugin_Hypothesis::GetKeepFiles() const
186 {
187   return myKeepFiles;
188 }
189
190 //=======================================================================
191 //function : SetVerboseLevel
192 //=======================================================================
193
194 void GHS3DPlugin_Hypothesis::SetVerboseLevel(short level)
195 {
196   if ( myVerboseLevel != level ) {
197     myVerboseLevel = level;
198     NotifySubMeshesHypothesisModification();
199   }
200 }
201
202 //=======================================================================
203 //function : GetVerboseLevel
204 //=======================================================================
205
206 short GHS3DPlugin_Hypothesis::GetVerboseLevel() const
207 {
208   return myVerboseLevel;
209 }
210
211 //=======================================================================
212 //function : SetToCreateNewNodes
213 //=======================================================================
214
215 void GHS3DPlugin_Hypothesis::SetToCreateNewNodes(bool toCreate)
216 {
217   if ( myToCreateNewNodes != toCreate ) {
218     myToCreateNewNodes = toCreate;
219     NotifySubMeshesHypothesisModification();
220   }
221 }
222
223 //=======================================================================
224 //function : GetToCreateNewNodes
225 //=======================================================================
226
227 bool GHS3DPlugin_Hypothesis::GetToCreateNewNodes() const
228 {
229   return myToCreateNewNodes;
230 }
231
232 //=======================================================================
233 //function : SetToUseBoundaryRecoveryVersion
234 //=======================================================================
235
236 void GHS3DPlugin_Hypothesis::SetToUseBoundaryRecoveryVersion(bool toUse)
237 {
238   if ( myToUseBoundaryRecoveryVersion != toUse ) {
239     myToUseBoundaryRecoveryVersion = toUse;
240     NotifySubMeshesHypothesisModification();
241   }
242 }
243
244 //=======================================================================
245 //function : GetToUseBoundaryRecoveryVersion
246 //=======================================================================
247
248 bool GHS3DPlugin_Hypothesis::GetToUseBoundaryRecoveryVersion() const
249 {
250   return myToUseBoundaryRecoveryVersion;
251 }
252
253 //=======================================================================
254 //function : SetFEMCorrection
255 //=======================================================================
256
257 void GHS3DPlugin_Hypothesis::SetFEMCorrection(bool toUseFem)
258 {
259   if ( myToUseFemCorrection != toUseFem ) {
260     myToUseFemCorrection = toUseFem;
261     NotifySubMeshesHypothesisModification();
262   }
263 }
264
265 //=======================================================================
266 //function : GetFEMCorrection
267 //=======================================================================
268
269 bool GHS3DPlugin_Hypothesis::GetFEMCorrection() const
270 {
271   return myToUseFemCorrection;
272 }
273
274 //=======================================================================
275 //function : SetToRemoveCentralPoint
276 //=======================================================================
277
278 void GHS3DPlugin_Hypothesis::SetToRemoveCentralPoint(bool toRemove)
279 {
280   if ( myToRemoveCentralPoint != toRemove ) {
281     myToRemoveCentralPoint = toRemove;
282     NotifySubMeshesHypothesisModification();
283   }
284 }
285
286 //=======================================================================
287 //function : GetToRemoveCentralPoint
288 //=======================================================================
289
290 bool GHS3DPlugin_Hypothesis::GetToRemoveCentralPoint() const
291 {
292   return myToRemoveCentralPoint;
293 }
294
295 //=======================================================================
296 //function : SetTextOption
297 //=======================================================================
298
299 void GHS3DPlugin_Hypothesis::SetTextOption(const std::string& option)
300 {
301   if ( myTextOption != option ) {
302     myTextOption = option;
303     NotifySubMeshesHypothesisModification();
304   }
305 }
306
307 //=======================================================================
308 //function : GetTextOption
309 //=======================================================================
310
311 std::string GHS3DPlugin_Hypothesis::GetTextOption() const
312 {
313   return myTextOption;
314 }
315
316 //=======================================================================
317 //function : SetEnforcedVertex
318 //=======================================================================
319
320 void GHS3DPlugin_Hypothesis::SetEnforcedVertex(double x, double y, double z, double size)
321 {
322   std::vector<double> coord(3);
323   coord[0] = x;
324   coord[1] = y;
325   coord[2] = z;
326   myEnforcedVertices[coord] = size;
327   NotifySubMeshesHypothesisModification();
328 }
329
330 //=======================================================================
331 //function : GetEnforcedVertex
332 //=======================================================================
333
334 double GHS3DPlugin_Hypothesis::GetEnforcedVertex(double x, double y, double z)
335   throw (std::invalid_argument)
336 {
337   std::vector<double> coord(3);
338   coord[0] = x;
339   coord[1] = y;
340   coord[2] = z;
341   if (myEnforcedVertices.count(coord)>0)
342     return myEnforcedVertices[coord];
343   std::ostringstream msg ;
344   msg << "No enforced vertex at " << x << ", " << y << ", " << z;
345   throw std::invalid_argument(msg.str());
346 }
347
348 //=======================================================================
349 //function : RemoveEnforcedVertex
350 //=======================================================================
351
352 void GHS3DPlugin_Hypothesis::RemoveEnforcedVertex(double x, double y, double z)
353   throw (std::invalid_argument)
354 {
355     std::vector<double> coord(3);
356     coord[0] = x;
357     coord[1] = y;
358     coord[2] = z;
359     TEnforcedVertexValues::iterator it = myEnforcedVertices.find(coord);
360     if (it != myEnforcedVertices.end()) {
361         myEnforcedVertices.erase(it);
362         NotifySubMeshesHypothesisModification();
363         return;
364     }
365     std::ostringstream msg ;
366     msg << "No enforced vertex at " << x << ", " << y << ", " << z;
367     throw std::invalid_argument(msg.str());
368 }
369
370 //=======================================================================
371 //function : ClearEnforcedVertices
372 //=======================================================================
373 void GHS3DPlugin_Hypothesis::ClearEnforcedVertices()
374 {
375     myEnforcedVertices.clear();
376     NotifySubMeshesHypothesisModification();
377 }
378
379 //=======================================================================
380 //function : DefaultMeshHoles
381 //=======================================================================
382
383 bool GHS3DPlugin_Hypothesis::DefaultMeshHoles()
384 {
385   return false; // PAL19680
386 }
387
388 //=======================================================================
389 //function : DefaultMaximumMemory
390 //=======================================================================
391
392 #ifndef WIN32
393 #include <sys/sysinfo.h>
394 #else
395 #include <windows.h>
396 #endif
397
398 short  GHS3DPlugin_Hypothesis::DefaultMaximumMemory()
399 {
400 #ifndef WIN32
401   struct sysinfo si;
402   int err = sysinfo( &si );
403   if ( err == 0 ) {
404     int ramMB = si.totalram * si.mem_unit / 1024 / 1024;
405     return (int) ( 0.7 * ramMB );
406   }
407 #else
408   // See http://msdn.microsoft.com/en-us/library/aa366589.aspx
409   MEMORYSTATUSEX statex;
410   statex.dwLength = sizeof (statex);
411   int err = GlobalMemoryStatusEx (&statex);
412   if (err != 0) {
413     int totMB = 
414       statex.ullTotalPhys / 1024 / 1024 +
415       statex.ullTotalPageFile / 1024 / 1024 +
416       statex.ullTotalVirtual / 1024 / 1024;
417     return (int) ( 0.7 * totMB );
418   }
419 #endif
420 }
421
422 //=======================================================================
423 //function : DefaultInitialMemory
424 //=======================================================================
425
426 short  GHS3DPlugin_Hypothesis::DefaultInitialMemory()
427 {
428   return DefaultMaximumMemory();
429 }
430
431 //=======================================================================
432 //function : DefaultOptimizationLevel
433 //=======================================================================
434
435 short  GHS3DPlugin_Hypothesis::DefaultOptimizationLevel()
436 {
437   return Medium;
438 }
439
440 //=======================================================================
441 //function : DefaultWorkingDirectory
442 //=======================================================================
443
444 std::string GHS3DPlugin_Hypothesis::DefaultWorkingDirectory()
445 {
446   TCollection_AsciiString aTmpDir;
447
448   char *Tmp_dir = getenv("SALOME_TMP_DIR");
449   if(Tmp_dir != NULL) {
450     aTmpDir = Tmp_dir;
451   }
452   else {
453 #ifdef WIN32
454     aTmpDir = TCollection_AsciiString("C:\\");
455 #else
456     aTmpDir = TCollection_AsciiString("/tmp/");
457 #endif
458   }
459   return aTmpDir.ToCString();
460 }
461
462 //=======================================================================
463 //function : DefaultKeepFiles
464 //=======================================================================
465
466 bool   GHS3DPlugin_Hypothesis::DefaultKeepFiles()
467 {
468   return false;
469 }
470
471 //=======================================================================
472 //function : DefaultVerboseLevel
473 //=======================================================================
474
475 short  GHS3DPlugin_Hypothesis::DefaultVerboseLevel()
476 {
477   return 10;
478 }
479
480 //=======================================================================
481 //function : DefaultToCreateNewNodes
482 //=======================================================================
483
484 bool GHS3DPlugin_Hypothesis::DefaultToCreateNewNodes()
485 {
486   return true;
487 }
488
489 //=======================================================================
490 //function : DefaultToUseBoundaryRecoveryVersion
491 //=======================================================================
492
493 bool GHS3DPlugin_Hypothesis::DefaultToUseBoundaryRecoveryVersion()
494 {
495   return false;
496 }
497
498 //=======================================================================
499 //function : DefaultToUseFEMCorrection
500 //=======================================================================
501
502 bool GHS3DPlugin_Hypothesis::DefaultToUseFEMCorrection()
503 {
504   return false;
505 }
506
507 //=======================================================================
508 //function : DefaultToRemoveCentralPoint
509 //=======================================================================
510
511 bool GHS3DPlugin_Hypothesis::DefaultToRemoveCentralPoint()
512 {
513   return false;
514 }
515
516 //=======================================================================
517 //function : DefaultEnforcedVertices
518 //=======================================================================
519
520 GHS3DPlugin_Hypothesis::TEnforcedVertexValues GHS3DPlugin_Hypothesis::DefaultEnforcedVertices()
521 {
522   return GHS3DPlugin_Hypothesis::TEnforcedVertexValues();
523 }
524
525
526 //=======================================================================
527 //function : SaveTo
528 //=======================================================================
529
530 std::ostream & GHS3DPlugin_Hypothesis::SaveTo(std::ostream & save)
531 {
532   save << (int) myToMeshHoles                 << " ";
533   save << myMaximumMemory                     << " ";
534   save << myInitialMemory                     << " ";
535   save << myOptimizationLevel                 << " ";
536   save << myWorkingDirectory                  << " ";
537   save << (int)myKeepFiles                    << " ";
538   save << myVerboseLevel                      << " ";
539   save << (int)myToCreateNewNodes             << " ";
540   save << (int)myToUseBoundaryRecoveryVersion << " ";
541   save << (int)myToUseFemCorrection           << " ";
542   save << (int)myToRemoveCentralPoint         << " ";
543   if (!myTextOption.empty()) {
544     save << "__OPTIONS_BEGIN__ ";
545     save << myTextOption                      << " ";
546     save << "__OPTIONS_END__ ";
547   }
548   
549
550   TEnforcedVertexValues::iterator it  = myEnforcedVertices.begin();
551   if (it != myEnforcedVertices.end()) {
552     save << "__ENFORCED_VERTICES_BEGIN__ ";
553     for ( ; it != myEnforcedVertices.end(); ++it ) {
554         save << it->first[0] << " "
555              << it->first[1] << " "
556              << it->first[2] << " "
557              << it->second << " ";
558     }
559     save << "__ENFORCED_VERTICES_END__ ";
560   }
561
562   return save;
563 }
564
565 //=======================================================================
566 //function : LoadFrom
567 //=======================================================================
568
569 std::istream & GHS3DPlugin_Hypothesis::LoadFrom(std::istream & load)
570 {
571     bool isOK = true;
572     int i;
573     
574     isOK = (load >> i);
575     if (isOK)
576         myToMeshHoles = i;
577     else
578         load.clear(ios::badbit | load.rdstate());
579     
580     isOK = (load >> i);
581     if (isOK)
582         myMaximumMemory = i;
583     else
584         load.clear(ios::badbit | load.rdstate());
585     
586     isOK = (load >> i);
587     if (isOK)
588         myInitialMemory = i;
589     else
590         load.clear(ios::badbit | load.rdstate());
591     
592     isOK = (load >> i);
593     if (isOK)
594         myOptimizationLevel = i;
595     else
596         load.clear(ios::badbit | load.rdstate());
597     
598     isOK = (load >> myWorkingDirectory);
599     if (isOK) {
600         if ( myWorkingDirectory == "0") { // myWorkingDirectory was empty
601             myKeepFiles = false;
602             myWorkingDirectory.clear();
603         }
604         else if ( myWorkingDirectory == "1" ) {
605             myKeepFiles = true;
606             myWorkingDirectory.clear();
607         }
608     }
609     else
610         load.clear(ios::badbit | load.rdstate());
611     
612     if ( !myWorkingDirectory.empty() ) {
613         isOK = (load >> i);
614         if (isOK)
615             myKeepFiles = i;
616         else
617             load.clear(ios::badbit | load.rdstate());
618     }
619     
620     isOK = (load >> i);
621     if (isOK)
622         myVerboseLevel = (short) i;
623     else
624         load.clear(ios::badbit | load.rdstate());
625     
626     isOK = (load >> i);
627     if (isOK)
628         myToCreateNewNodes = (bool) i;
629     else
630         load.clear(ios::badbit | load.rdstate());
631     
632     isOK = (load >> i);
633     if (isOK)
634         myToUseBoundaryRecoveryVersion = (bool) i;
635     else
636         load.clear(ios::badbit | load.rdstate());
637     
638     isOK = (load >> i);
639     if (isOK)
640         myToUseFemCorrection = (bool) i;
641     else
642         load.clear(ios::badbit | load.rdstate());
643     
644     isOK = (load >> i);
645     if (isOK)
646         myToRemoveCentralPoint = (bool) i;
647     else
648         load.clear(ios::badbit | load.rdstate());
649     
650     std::string separator;
651     bool hasOptions = false;
652     bool hasEnforcedVertices = false;
653     isOK = (load >> separator);
654
655     if (isOK)
656         if (separator == "__OPTIONS_BEGIN__")
657             hasOptions = true;
658         else if (separator == "__ENFORCED_VERTICES_BEGIN__")
659             hasEnforcedVertices = true;
660
661     if (hasOptions) {
662         std::string txt;
663         while (isOK) {
664             isOK = (load >> txt);
665             if (isOK) {
666                 if (txt == "__OPTIONS_END__") {
667                     if (!myTextOption.empty()) {
668                         // Remove last space
669                         myTextOption.erase(myTextOption.end()-1);
670                     }
671                     isOK = false;
672                     break;
673                 }
674                 myTextOption += txt;
675                 myTextOption += " ";
676             }
677         }
678     }
679
680     if (hasOptions) {
681         isOK = (load >> separator);
682         if (isOK)
683             if (separator == "__ENFORCED_VERTICES_BEGIN__")
684                 hasEnforcedVertices = true;
685     }
686
687     if (hasEnforcedVertices) {
688         std::string txt;
689         double x,y,z,size;
690         while (isOK) {
691             isOK = (load >> txt);
692             if (isOK) {
693                 if (txt == "__ENFORCED_VERTICES_END__") {
694                     isOK = false;
695                     break;
696                 }
697                 x = atof(txt.c_str());
698                 isOK = (load >> y >> z >> size);
699             }
700             if (isOK) {
701                 std::vector<double> coord;
702                 coord.push_back(x);
703                 coord.push_back(y);
704                 coord.push_back(z);
705                 myEnforcedVertices[ coord ] = size;
706             }
707         }
708     }
709
710   return load;
711 }
712
713 //=======================================================================
714 //function : SetParametersByMesh
715 //=======================================================================
716
717 bool GHS3DPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* ,const TopoDS_Shape&)
718 {
719   return false;
720 }
721
722
723 //================================================================================
724 /*!
725  * \brief Return false
726  */
727 //================================================================================
728
729 bool GHS3DPlugin_Hypothesis::SetParametersByDefaults(const TDefaults&  /*dflts*/,
730                                                      const SMESH_Mesh* /*theMesh*/)
731 {
732   return false;
733 }
734
735 //================================================================================
736 /*!
737  * \brief Return command to run ghs3d mesher excluding file prefix (-f)
738  */
739 //================================================================================
740
741 std::string GHS3DPlugin_Hypothesis::CommandToRun(const GHS3DPlugin_Hypothesis* hyp,
742                                             const bool                    hasShapeToMesh)
743 {
744   TCollection_AsciiString cmd( "ghs3d" );
745   // check if any option is overridden by hyp->myTextOption
746   bool m   = hyp ? ( hyp->myTextOption.find("-m")  == std::string::npos ) : true;
747   bool M   = hyp ? ( hyp->myTextOption.find("-M")  == std::string::npos ) : true;
748   bool c   = hyp ? ( hyp->myTextOption.find("-c")  == std::string::npos ) : true;
749   bool o   = hyp ? ( hyp->myTextOption.find("-o")  == std::string::npos ) : true;
750   bool p0  = hyp ? ( hyp->myTextOption.find("-p0") == std::string::npos ) : true;
751   bool C   = hyp ? ( hyp->myTextOption.find("-C")  == std::string::npos ) : true;
752   bool v   = hyp ? ( hyp->myTextOption.find("-v")  == std::string::npos ) : true;
753   bool fem = hyp ? ( hyp->myTextOption.find("-FEM")== std::string::npos ) : true;
754   bool rem = hyp ? ( hyp->myTextOption.find("-no_initial_central_point")== std::string::npos ) : true;
755
756   // if use boundary recovery version, few options are allowed
757   bool useBndRecovery = !C;
758   if ( !useBndRecovery && hyp )
759     useBndRecovery = hyp->myToUseBoundaryRecoveryVersion;
760
761   // ghs3d needs to know amount of memory it may use (MB).
762   // Default memory is defined at ghs3d installation but it may be not enough,
763   // so allow to use about all available memory
764   if ( m ) {
765     short aMaximumMemory = hyp ? hyp->myMaximumMemory : -1;
766     cmd += " -m ";
767     if ( aMaximumMemory < 0 )
768       cmd += DefaultMaximumMemory();
769     else
770       cmd += aMaximumMemory;
771   }
772   if ( M && !useBndRecovery ) {
773     short aInitialMemory = hyp ? hyp->myInitialMemory : -1;
774     cmd += " -M ";
775     if ( aInitialMemory > 0 )
776       cmd += aInitialMemory;
777     else
778       cmd += "100";
779   }
780   // component to mesh
781   // 0 , all components to be meshed
782   // 1 , only the main ( outermost ) component to be meshed
783   if ( c && !useBndRecovery ) {
784     // We always run GHS3D with "to mesh holes'==TRUE (see PAL19680)
785     if ( hasShapeToMesh )
786       cmd += " -c 0";
787     else {
788       bool aToMeshHoles = hyp ? hyp->myToMeshHoles : DefaultMeshHoles();
789       if ( aToMeshHoles )
790         cmd += " -c 0";
791       else
792         cmd += " -c 1";
793     }
794   }
795
796   // optimization level
797   if ( o && hyp && !useBndRecovery ) {
798     if ( hyp->myOptimizationLevel >= 0 && hyp->myOptimizationLevel < 5 ) {
799       char* level[] = { "none" , "light" , "standard" , "standard+" , "strong" };
800       cmd += " -o ";
801       cmd += level[ hyp->myOptimizationLevel ];
802     }
803   }
804
805   // to create internal nodes
806   if ( p0 && hyp && !hyp->myToCreateNewNodes ) {
807     cmd += " -p0";
808   }
809
810   // verbose mode
811   if ( v && hyp ) {
812     cmd += " -v ";
813     cmd += hyp->myVerboseLevel;
814   }
815
816   // boundary recovery version
817   if ( useBndRecovery ) {
818     cmd += " -C";
819   }
820
821   // to use FEM correction
822   if ( fem && hyp && hyp->myToUseFemCorrection) {
823     cmd += " -FEM";
824   }
825
826   // to remove initial central point.
827   if ( rem && hyp && hyp->myToRemoveCentralPoint) {
828     cmd += " -no_initial_central_point";
829   }
830
831   // options as text
832   if ( hyp && !hyp->myTextOption.empty() ) {
833     cmd += " ";
834     cmd += (char*) hyp->myTextOption.c_str();
835   }
836
837 #ifdef WNT
838   cmd += " < NUL";
839 #endif
840
841   return cmd.ToCString();
842 }
843
844 //================================================================================
845 /*!
846  * \brief Return a unique file name
847  */
848 //================================================================================
849
850 std::string GHS3DPlugin_Hypothesis::GetFileName(const GHS3DPlugin_Hypothesis* hyp)
851 {
852   std::string aTmpDir = hyp ? hyp->GetWorkingDirectory() : DefaultWorkingDirectory();
853   const char lastChar = *aTmpDir.rbegin();
854 #ifdef WIN32
855     if(lastChar != '\\') aTmpDir+='\\';
856 #else
857     if(lastChar != '/') aTmpDir+='/';
858 #endif      
859
860   TCollection_AsciiString aGenericName = (char*)aTmpDir.c_str();
861   aGenericName += "GHS3D_";
862   aGenericName += getpid();
863   aGenericName += "_";
864   aGenericName += Abs((Standard_Integer)(long) aGenericName.ToCString());
865
866   return aGenericName.ToCString();
867 }
868
869
870 //================================================================================
871 /*!
872 * \brief Return the enforced vertices
873 */
874 //================================================================================
875
876 GHS3DPlugin_Hypothesis::TEnforcedVertexValues GHS3DPlugin_Hypothesis::GetEnforcedVertices(const GHS3DPlugin_Hypothesis* hyp)
877 {
878     return hyp ? hyp->_GetEnforcedVertices():DefaultEnforcedVertices();
879 }
880