Salome HOME
0020682: EDF 1222 SMESH: 3D mesh from a skin mesh and with volumic cells
[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   return 1024;
421 }
422
423 //=======================================================================
424 //function : DefaultInitialMemory
425 //=======================================================================
426
427 short  GHS3DPlugin_Hypothesis::DefaultInitialMemory()
428 {
429   return DefaultMaximumMemory();
430 }
431
432 //=======================================================================
433 //function : DefaultOptimizationLevel
434 //=======================================================================
435
436 short  GHS3DPlugin_Hypothesis::DefaultOptimizationLevel()
437 {
438   return Medium;
439 }
440
441 //=======================================================================
442 //function : DefaultWorkingDirectory
443 //=======================================================================
444
445 std::string GHS3DPlugin_Hypothesis::DefaultWorkingDirectory()
446 {
447   TCollection_AsciiString aTmpDir;
448
449   char *Tmp_dir = getenv("SALOME_TMP_DIR");
450   if(Tmp_dir != NULL) {
451     aTmpDir = Tmp_dir;
452   }
453   else {
454 #ifdef WIN32
455     aTmpDir = TCollection_AsciiString("C:\\");
456 #else
457     aTmpDir = TCollection_AsciiString("/tmp/");
458 #endif
459   }
460   return aTmpDir.ToCString();
461 }
462
463 //=======================================================================
464 //function : DefaultKeepFiles
465 //=======================================================================
466
467 bool   GHS3DPlugin_Hypothesis::DefaultKeepFiles()
468 {
469   return false;
470 }
471
472 //=======================================================================
473 //function : DefaultVerboseLevel
474 //=======================================================================
475
476 short  GHS3DPlugin_Hypothesis::DefaultVerboseLevel()
477 {
478   return 10;
479 }
480
481 //=======================================================================
482 //function : DefaultToCreateNewNodes
483 //=======================================================================
484
485 bool GHS3DPlugin_Hypothesis::DefaultToCreateNewNodes()
486 {
487   return true;
488 }
489
490 //=======================================================================
491 //function : DefaultToUseBoundaryRecoveryVersion
492 //=======================================================================
493
494 bool GHS3DPlugin_Hypothesis::DefaultToUseBoundaryRecoveryVersion()
495 {
496   return false;
497 }
498
499 //=======================================================================
500 //function : DefaultToUseFEMCorrection
501 //=======================================================================
502
503 bool GHS3DPlugin_Hypothesis::DefaultToUseFEMCorrection()
504 {
505   return false;
506 }
507
508 //=======================================================================
509 //function : DefaultToRemoveCentralPoint
510 //=======================================================================
511
512 bool GHS3DPlugin_Hypothesis::DefaultToRemoveCentralPoint()
513 {
514   return false;
515 }
516
517 //=======================================================================
518 //function : DefaultEnforcedVertices
519 //=======================================================================
520
521 GHS3DPlugin_Hypothesis::TEnforcedVertexValues GHS3DPlugin_Hypothesis::DefaultEnforcedVertices()
522 {
523   return GHS3DPlugin_Hypothesis::TEnforcedVertexValues();
524 }
525
526
527 //=======================================================================
528 //function : SaveTo
529 //=======================================================================
530
531 std::ostream & GHS3DPlugin_Hypothesis::SaveTo(std::ostream & save)
532 {
533   save << (int) myToMeshHoles                 << " ";
534   save << myMaximumMemory                     << " ";
535   save << myInitialMemory                     << " ";
536   save << myOptimizationLevel                 << " ";
537   save << myWorkingDirectory                  << " ";
538   save << (int)myKeepFiles                    << " ";
539   save << myVerboseLevel                      << " ";
540   save << (int)myToCreateNewNodes             << " ";
541   save << (int)myToUseBoundaryRecoveryVersion << " ";
542   save << (int)myToUseFemCorrection           << " ";
543   save << (int)myToRemoveCentralPoint         << " ";
544   if (!myTextOption.empty()) {
545     save << "__OPTIONS_BEGIN__ ";
546     save << myTextOption                      << " ";
547     save << "__OPTIONS_END__ ";
548   }
549   
550
551   TEnforcedVertexValues::iterator it  = myEnforcedVertices.begin();
552   if (it != myEnforcedVertices.end()) {
553     save << "__ENFORCED_VERTICES_BEGIN__ ";
554     for ( ; it != myEnforcedVertices.end(); ++it ) {
555         save << it->first[0] << " "
556              << it->first[1] << " "
557              << it->first[2] << " "
558              << it->second << " ";
559     }
560     save << "__ENFORCED_VERTICES_END__ ";
561   }
562
563   return save;
564 }
565
566 //=======================================================================
567 //function : LoadFrom
568 //=======================================================================
569
570 std::istream & GHS3DPlugin_Hypothesis::LoadFrom(std::istream & load)
571 {
572     bool isOK = true;
573     int i;
574     
575     isOK = (load >> i);
576     if (isOK)
577         myToMeshHoles = i;
578     else
579         load.clear(ios::badbit | load.rdstate());
580     
581     isOK = (load >> i);
582     if (isOK)
583         myMaximumMemory = i;
584     else
585         load.clear(ios::badbit | load.rdstate());
586     
587     isOK = (load >> i);
588     if (isOK)
589         myInitialMemory = i;
590     else
591         load.clear(ios::badbit | load.rdstate());
592     
593     isOK = (load >> i);
594     if (isOK)
595         myOptimizationLevel = i;
596     else
597         load.clear(ios::badbit | load.rdstate());
598     
599     isOK = (load >> myWorkingDirectory);
600     if (isOK) {
601         if ( myWorkingDirectory == "0") { // myWorkingDirectory was empty
602             myKeepFiles = false;
603             myWorkingDirectory.clear();
604         }
605         else if ( myWorkingDirectory == "1" ) {
606             myKeepFiles = true;
607             myWorkingDirectory.clear();
608         }
609     }
610     else
611         load.clear(ios::badbit | load.rdstate());
612     
613     if ( !myWorkingDirectory.empty() ) {
614         isOK = (load >> i);
615         if (isOK)
616             myKeepFiles = i;
617         else
618             load.clear(ios::badbit | load.rdstate());
619     }
620     
621     isOK = (load >> i);
622     if (isOK)
623         myVerboseLevel = (short) i;
624     else
625         load.clear(ios::badbit | load.rdstate());
626     
627     isOK = (load >> i);
628     if (isOK)
629         myToCreateNewNodes = (bool) i;
630     else
631         load.clear(ios::badbit | load.rdstate());
632     
633     isOK = (load >> i);
634     if (isOK)
635         myToUseBoundaryRecoveryVersion = (bool) i;
636     else
637         load.clear(ios::badbit | load.rdstate());
638     
639     isOK = (load >> i);
640     if (isOK)
641         myToUseFemCorrection = (bool) i;
642     else
643         load.clear(ios::badbit | load.rdstate());
644     
645     isOK = (load >> i);
646     if (isOK)
647         myToRemoveCentralPoint = (bool) i;
648     else
649         load.clear(ios::badbit | load.rdstate());
650     
651     std::string separator;
652     bool hasOptions = false;
653     bool hasEnforcedVertices = false;
654     isOK = (load >> separator);
655
656     if (isOK)
657         if (separator == "__OPTIONS_BEGIN__")
658             hasOptions = true;
659         else if (separator == "__ENFORCED_VERTICES_BEGIN__")
660             hasEnforcedVertices = true;
661
662     if (hasOptions) {
663         std::string txt;
664         while (isOK) {
665             isOK = (load >> txt);
666             if (isOK) {
667                 if (txt == "__OPTIONS_END__") {
668                     if (!myTextOption.empty()) {
669                         // Remove last space
670                         myTextOption.erase(myTextOption.end()-1);
671                     }
672                     isOK = false;
673                     break;
674                 }
675                 myTextOption += txt;
676                 myTextOption += " ";
677             }
678         }
679     }
680
681     if (hasOptions) {
682         isOK = (load >> separator);
683         if (isOK)
684             if (separator == "__ENFORCED_VERTICES_BEGIN__")
685                 hasEnforcedVertices = true;
686     }
687
688     if (hasEnforcedVertices) {
689         std::string txt;
690         double x,y,z,size;
691         while (isOK) {
692             isOK = (load >> txt);
693             if (isOK) {
694                 if (txt == "__ENFORCED_VERTICES_END__") {
695                     isOK = false;
696                     break;
697                 }
698                 x = atof(txt.c_str());
699                 isOK = (load >> y >> z >> size);
700             }
701             if (isOK) {
702                 std::vector<double> coord;
703                 coord.push_back(x);
704                 coord.push_back(y);
705                 coord.push_back(z);
706                 myEnforcedVertices[ coord ] = size;
707             }
708         }
709     }
710
711   return load;
712 }
713
714 //=======================================================================
715 //function : SetParametersByMesh
716 //=======================================================================
717
718 bool GHS3DPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* ,const TopoDS_Shape&)
719 {
720   return false;
721 }
722
723
724 //================================================================================
725 /*!
726  * \brief Return false
727  */
728 //================================================================================
729
730 bool GHS3DPlugin_Hypothesis::SetParametersByDefaults(const TDefaults&  /*dflts*/,
731                                                      const SMESH_Mesh* /*theMesh*/)
732 {
733   return false;
734 }
735
736 //================================================================================
737 /*!
738  * \brief Return command to run ghs3d mesher excluding file prefix (-f)
739  */
740 //================================================================================
741
742 std::string GHS3DPlugin_Hypothesis::CommandToRun(const GHS3DPlugin_Hypothesis* hyp,
743                                             const bool                    hasShapeToMesh)
744 {
745   TCollection_AsciiString cmd( "ghs3d" );
746   // check if any option is overridden by hyp->myTextOption
747   bool m   = hyp ? ( hyp->myTextOption.find("-m")  == std::string::npos ) : true;
748   bool M   = hyp ? ( hyp->myTextOption.find("-M")  == std::string::npos ) : true;
749   bool c   = hyp ? ( hyp->myTextOption.find("-c")  == std::string::npos ) : true;
750   bool o   = hyp ? ( hyp->myTextOption.find("-o")  == std::string::npos ) : true;
751   bool p0  = hyp ? ( hyp->myTextOption.find("-p0") == std::string::npos ) : true;
752   bool C   = hyp ? ( hyp->myTextOption.find("-C")  == std::string::npos ) : true;
753   bool v   = hyp ? ( hyp->myTextOption.find("-v")  == std::string::npos ) : true;
754   bool fem = hyp ? ( hyp->myTextOption.find("-FEM")== std::string::npos ) : true;
755   bool rem = hyp ? ( hyp->myTextOption.find("-no_initial_central_point")== std::string::npos ) : true;
756
757   // if use boundary recovery version, few options are allowed
758   bool useBndRecovery = !C;
759   if ( !useBndRecovery && hyp )
760     useBndRecovery = hyp->myToUseBoundaryRecoveryVersion;
761
762   // ghs3d needs to know amount of memory it may use (MB).
763   // Default memory is defined at ghs3d installation but it may be not enough,
764   // so allow to use about all available memory
765   if ( m ) {
766     short aMaximumMemory = hyp ? hyp->myMaximumMemory : -1;
767     cmd += " -m ";
768     if ( aMaximumMemory < 0 )
769       cmd += DefaultMaximumMemory();
770     else
771       cmd += aMaximumMemory;
772   }
773   if ( M && !useBndRecovery ) {
774     short aInitialMemory = hyp ? hyp->myInitialMemory : -1;
775     cmd += " -M ";
776     if ( aInitialMemory > 0 )
777       cmd += aInitialMemory;
778     else
779       cmd += "100";
780   }
781   // component to mesh
782   // 0 , all components to be meshed
783   // 1 , only the main ( outermost ) component to be meshed
784   if ( c && !useBndRecovery ) {
785     // We always run GHS3D with "to mesh holes'==TRUE (see PAL19680)
786     if ( hasShapeToMesh )
787       cmd += " -c 0";
788     else {
789       bool aToMeshHoles = hyp ? hyp->myToMeshHoles : DefaultMeshHoles();
790       if ( aToMeshHoles )
791         cmd += " -c 0";
792       else
793         cmd += " -c 1";
794     }
795   }
796
797   // optimization level
798   if ( o && hyp && !useBndRecovery ) {
799     if ( hyp->myOptimizationLevel >= 0 && hyp->myOptimizationLevel < 5 ) {
800       char* level[] = { "none" , "light" , "standard" , "standard+" , "strong" };
801       cmd += " -o ";
802       cmd += level[ hyp->myOptimizationLevel ];
803     }
804   }
805
806   // to create internal nodes
807   if ( p0 && hyp && !hyp->myToCreateNewNodes ) {
808     cmd += " -p0";
809   }
810
811   // verbose mode
812   if ( v && hyp ) {
813     cmd += " -v ";
814     cmd += hyp->myVerboseLevel;
815   }
816
817   // boundary recovery version
818   if ( useBndRecovery ) {
819     cmd += " -C";
820   }
821
822   // to use FEM correction
823   if ( fem && hyp && hyp->myToUseFemCorrection) {
824     cmd += " -FEM";
825   }
826
827   // to remove initial central point.
828   if ( rem && hyp && hyp->myToRemoveCentralPoint) {
829     cmd += " -no_initial_central_point";
830   }
831
832   // options as text
833   if ( hyp && !hyp->myTextOption.empty() ) {
834     cmd += " ";
835     cmd += (char*) hyp->myTextOption.c_str();
836   }
837
838 #ifdef WNT
839   cmd += " < NUL";
840 #endif
841
842   return cmd.ToCString();
843 }
844
845 //================================================================================
846 /*!
847  * \brief Return a unique file name
848  */
849 //================================================================================
850
851 std::string GHS3DPlugin_Hypothesis::GetFileName(const GHS3DPlugin_Hypothesis* hyp)
852 {
853   std::string aTmpDir = hyp ? hyp->GetWorkingDirectory() : DefaultWorkingDirectory();
854   const char lastChar = *aTmpDir.rbegin();
855 #ifdef WIN32
856     if(lastChar != '\\') aTmpDir+='\\';
857 #else
858     if(lastChar != '/') aTmpDir+='/';
859 #endif      
860
861   TCollection_AsciiString aGenericName = (char*)aTmpDir.c_str();
862   aGenericName += "GHS3D_";
863   aGenericName += getpid();
864   aGenericName += "_";
865   aGenericName += Abs((Standard_Integer)(long) aGenericName.ToCString());
866
867   return aGenericName.ToCString();
868 }
869
870
871 //================================================================================
872 /*!
873 * \brief Return the enforced vertices
874 */
875 //================================================================================
876
877 GHS3DPlugin_Hypothesis::TEnforcedVertexValues GHS3DPlugin_Hypothesis::GetEnforcedVertices(const GHS3DPlugin_Hypothesis* hyp)
878 {
879     return hyp ? hyp->_GetEnforcedVertices():DefaultEnforcedVertices();
880 }
881