]> SALOME platform Git repositories - plugins/ghs3dplugin.git/blob - src/GHS3DPlugin_Hypothesis.cxx
Salome HOME
04644bc75abb7f82136a78ba89dcf084bb0d7c8b
[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   save << "__OPTIONS_BEGIN__ ";
544   save << myTextOption                        << " ";
545   save << " __OPTIONS_END__ ";
546   
547
548   TEnforcedVertexValues::iterator it  = myEnforcedVertices.begin();
549   if (it != myEnforcedVertices.end()) {
550     save << "__ENFORCED_VERTICES_BEGIN__ ";
551     for ( ; it != myEnforcedVertices.end(); ++it ) {
552         save << it->first[0] << " "
553              << it->first[1] << " "
554              << it->first[2] << " "
555              << it->second << " ";
556     }
557     save << "__ENFORCED_VERTICES_END__ ";
558   }
559
560   return save;
561 }
562
563 //=======================================================================
564 //function : LoadFrom
565 //=======================================================================
566
567 std::istream & GHS3DPlugin_Hypothesis::LoadFrom(std::istream & load)
568 {
569     bool isOK = true;
570     int i;
571     
572     isOK = (load >> i);
573     if (isOK)
574         myToMeshHoles = i;
575     else
576         load.clear(ios::badbit | load.rdstate());
577     
578     isOK = (load >> i);
579     if (isOK)
580         myMaximumMemory = i;
581     else
582         load.clear(ios::badbit | load.rdstate());
583     
584     isOK = (load >> i);
585     if (isOK)
586         myInitialMemory = i;
587     else
588         load.clear(ios::badbit | load.rdstate());
589     
590     isOK = (load >> i);
591     if (isOK)
592         myOptimizationLevel = i;
593     else
594         load.clear(ios::badbit | load.rdstate());
595     
596     isOK = (load >> myWorkingDirectory);
597     if (isOK) {
598         if ( myWorkingDirectory == "0") { // myWorkingDirectory was empty
599             myKeepFiles = false;
600             myWorkingDirectory.clear();
601         }
602         else if ( myWorkingDirectory == "1" ) {
603             myKeepFiles = true;
604             myWorkingDirectory.clear();
605         }
606     }
607     else
608         load.clear(ios::badbit | load.rdstate());
609     
610     if ( !myWorkingDirectory.empty() ) {
611         isOK = (load >> i);
612         if (isOK)
613             myKeepFiles = i;
614         else
615             load.clear(ios::badbit | load.rdstate());
616     }
617     
618     isOK = (load >> i);
619     if (isOK)
620         myVerboseLevel = (short) i;
621     else
622         load.clear(ios::badbit | load.rdstate());
623     
624     isOK = (load >> i);
625     if (isOK)
626         myToCreateNewNodes = (bool) i;
627     else
628         load.clear(ios::badbit | load.rdstate());
629     
630     isOK = (load >> i);
631     if (isOK)
632         myToUseBoundaryRecoveryVersion = (bool) i;
633     else
634         load.clear(ios::badbit | load.rdstate());
635     
636     isOK = (load >> i);
637     if (isOK)
638         myToUseFemCorrection = (bool) i;
639     else
640         load.clear(ios::badbit | load.rdstate());
641     
642     isOK = (load >> i);
643     if (isOK)
644         myToRemoveCentralPoint = (bool) i;
645     else
646         load.clear(ios::badbit | load.rdstate());
647     
648 //     isOK = (load >> myTextOption);
649 //     while (isOK) {
650 //         std::string txt;
651 //         if (load >> txt) {
652 //             myTextOption += " ";
653 //             myTextOption += txt;
654 //         }
655 //         else
656 //             isOK = false;
657 //     }
658 //     //   else
659 //     //     load.clear(ios::badbit | load.rdstate());
660
661     
662     std::string separator;
663     bool hasOptions = false;
664     bool hasEnforcedVertices = false;
665     isOK = (load >> separator);
666
667     if (isOK)
668         if (separator == "__OPTIONS_BEGIN__")
669             hasOptions = true;
670         else if (separator == "__ENFORCED_VERTICES_BEGIN__")
671             hasEnforcedVertices = true;
672     
673     if (hasOptions) {
674         std::string txt;
675         isOK = (load >> myTextOption);
676         while (isOK) {
677             if (myTextOption == "__OPTIONS_END__") {
678                 isOK = false;
679                 break;
680             }
681             if (load >> txt) {
682                 if (txt == "__OPTIONS_END__") {
683                     isOK = false;
684                     break;
685                 }
686                 myTextOption += " ";
687                 myTextOption += txt;
688             }
689             else
690                 isOK = false;
691         }
692     }
693
694     if (hasOptions) {
695         isOK = (load >> separator);
696         if (isOK)
697             if (separator == "__ENFORCED_VERTICES_BEGIN__")
698                 hasEnforcedVertices = true;
699     }
700
701     if (hasEnforcedVertices) {
702         std::string txt;
703         double x,y,z,size;
704         while (isOK) {
705             isOK = (load >> txt);
706             if (isOK) {
707                 if (txt == "__ENFORCED_VERTICES_END__") {
708                     isOK = false;
709                     break;
710                 }
711                 x = atof(txt.c_str());
712                 isOK = (load >> y >> z >> size);
713             }
714             if (isOK) {
715                 std::vector<double> coord;
716                 coord.push_back(x);
717                 coord.push_back(y);
718                 coord.push_back(z);
719                 myEnforcedVertices[ coord ] = size;
720             }
721         }
722     }
723
724   return load;
725 }
726
727 //=======================================================================
728 //function : SetParametersByMesh
729 //=======================================================================
730
731 bool GHS3DPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* ,const TopoDS_Shape&)
732 {
733   return false;
734 }
735
736
737 //================================================================================
738 /*!
739  * \brief Return false
740  */
741 //================================================================================
742
743 bool GHS3DPlugin_Hypothesis::SetParametersByDefaults(const TDefaults&  /*dflts*/,
744                                                      const SMESH_Mesh* /*theMesh*/)
745 {
746   return false;
747 }
748
749 //================================================================================
750 /*!
751  * \brief Return command to run ghs3d mesher excluding file prefix (-f)
752  */
753 //================================================================================
754
755 std::string GHS3DPlugin_Hypothesis::CommandToRun(const GHS3DPlugin_Hypothesis* hyp,
756                                             const bool                    hasShapeToMesh)
757 {
758   TCollection_AsciiString cmd( "ghs3d" );
759   // check if any option is overridden by hyp->myTextOption
760   bool m   = hyp ? ( hyp->myTextOption.find("-m")  == std::string::npos ) : true;
761   bool M   = hyp ? ( hyp->myTextOption.find("-M")  == std::string::npos ) : true;
762   bool c   = hyp ? ( hyp->myTextOption.find("-c")  == std::string::npos ) : true;
763   bool o   = hyp ? ( hyp->myTextOption.find("-o")  == std::string::npos ) : true;
764   bool p0  = hyp ? ( hyp->myTextOption.find("-p0") == std::string::npos ) : true;
765   bool C   = hyp ? ( hyp->myTextOption.find("-C")  == std::string::npos ) : true;
766   bool v   = hyp ? ( hyp->myTextOption.find("-v")  == std::string::npos ) : true;
767   bool fem = hyp ? ( hyp->myTextOption.find("-FEM")== std::string::npos ) : true;
768   bool rem = hyp ? ( hyp->myTextOption.find("-no_initial_central_point")== std::string::npos ) : true;
769
770   // if use boundary recovery version, few options are allowed
771   bool useBndRecovery = !C;
772   if ( !useBndRecovery && hyp )
773     useBndRecovery = hyp->myToUseBoundaryRecoveryVersion;
774
775   // ghs3d needs to know amount of memory it may use (MB).
776   // Default memory is defined at ghs3d installation but it may be not enough,
777   // so allow to use about all available memory
778   if ( m ) {
779     short aMaximumMemory = hyp ? hyp->myMaximumMemory : -1;
780     cmd += " -m ";
781     if ( aMaximumMemory < 0 )
782       cmd += DefaultMaximumMemory();
783     else
784       cmd += aMaximumMemory;
785   }
786   if ( M && !useBndRecovery ) {
787     short aInitialMemory = hyp ? hyp->myInitialMemory : -1;
788     cmd += " -M ";
789     if ( aInitialMemory > 0 )
790       cmd += aInitialMemory;
791     else
792       cmd += "100";
793   }
794   // component to mesh
795   // 0 , all components to be meshed
796   // 1 , only the main ( outermost ) component to be meshed
797   if ( c && !useBndRecovery ) {
798     // We always run GHS3D with "to mesh holes'==TRUE (see PAL19680)
799     if ( hasShapeToMesh )
800       cmd += " -c 0";
801     else {
802       bool aToMeshHoles = hyp ? hyp->myToMeshHoles : DefaultMeshHoles();
803       if ( aToMeshHoles )
804         cmd += " -c 0";
805       else
806         cmd += " -c 1";
807     }
808   }
809
810   // optimization level
811   if ( o && hyp && !useBndRecovery ) {
812     if ( hyp->myOptimizationLevel >= 0 && hyp->myOptimizationLevel < 5 ) {
813       char* level[] = { "none" , "light" , "standard" , "standard+" , "strong" };
814       cmd += " -o ";
815       cmd += level[ hyp->myOptimizationLevel ];
816     }
817   }
818
819   // to create internal nodes
820   if ( p0 && hyp && !hyp->myToCreateNewNodes ) {
821     cmd += " -p0";
822   }
823
824   // verbose mode
825   if ( v && hyp ) {
826     cmd += " -v ";
827     cmd += hyp->myVerboseLevel;
828   }
829
830   // boundary recovery version
831   if ( useBndRecovery ) {
832     cmd += " -C";
833   }
834
835   // to use FEM correction
836   if ( fem && hyp && hyp->myToUseFemCorrection) {
837     cmd += " -FEM";
838   }
839
840   // to remove initial central point.
841   if ( rem && hyp && hyp->myToRemoveCentralPoint) {
842     cmd += " -no_initial_central_point";
843   }
844
845   // options as text
846   if ( hyp && !hyp->myTextOption.empty() ) {
847     cmd += " ";
848     cmd += (char*) hyp->myTextOption.c_str();
849   }
850
851 #ifdef WNT
852   cmd += " < NUL";
853 #endif
854
855   return cmd.ToCString();
856 }
857
858 //================================================================================
859 /*!
860  * \brief Return a unique file name
861  */
862 //================================================================================
863
864 std::string GHS3DPlugin_Hypothesis::GetFileName(const GHS3DPlugin_Hypothesis* hyp)
865 {
866   std::string aTmpDir = hyp ? hyp->GetWorkingDirectory() : DefaultWorkingDirectory();
867   const char lastChar = *aTmpDir.rbegin();
868 #ifdef WIN32
869     if(lastChar != '\\') aTmpDir+='\\';
870 #else
871     if(lastChar != '/') aTmpDir+='/';
872 #endif      
873
874   TCollection_AsciiString aGenericName = (char*)aTmpDir.c_str();
875   aGenericName += "GHS3D_";
876   aGenericName += getpid();
877   aGenericName += "_";
878   aGenericName += Abs((Standard_Integer)(long) aGenericName.ToCString());
879
880   return aGenericName.ToCString();
881 }
882
883
884 //================================================================================
885 /*!
886 * \brief Return the enforced vertices
887 */
888 //================================================================================
889
890 GHS3DPlugin_Hypothesis::TEnforcedVertexValues GHS3DPlugin_Hypothesis::GetEnforcedVertices(const GHS3DPlugin_Hypothesis* hyp)
891 {
892     return hyp ? hyp->_GetEnforcedVertices():DefaultEnforcedVertices();
893 }
894