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