Salome HOME
IMP23373: [CEA 1170] Optimization of a 3D mesh using MG-Tetra
[plugins/ghs3dplugin.git] / src / GHS3DPlugin / GHS3DPlugin_Hypothesis_i.cxx
1 // Copyright (C) 2004-2016  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // File      : GHS3DPlugin_Hypothesis_i.cxx
21 // Created   : Wed Apr  2 13:53:01 2008
22 // Author    : Edward AGAPOV (eap)
23 //
24 #include "GHS3DPlugin_Hypothesis_i.hxx"
25
26 #include <SMESH_Gen.hxx>
27 #include <SMESH_PythonDump.hxx>
28
29 #include <Utils_CorbaException.hxx>
30 #include <utilities.h>
31 #include <SMESH_Mesh_i.hxx>
32 #include <SMESH_Group_i.hxx>
33 #include <SMESH_Gen_i.hxx>
34 //#include <SMESH_TypeDefs.hxx>
35 #include <SMESHDS_GroupBase.hxx>
36
37 // SALOME KERNEL includes
38 // #include <SALOMEDSClient.hxx>
39 // #include <SALOMEDSClient_definitions.hxx>
40
41 using namespace std;
42
43 //=======================================================================
44 //function : GHS3DPlugin_Hypothesis_i
45 //=======================================================================
46
47 GHS3DPlugin_Hypothesis_i::GHS3DPlugin_Hypothesis_i (PortableServer::POA_ptr thePOA,
48                                                     int                     theStudyId,
49                                                     ::SMESH_Gen*            theGenImpl)
50   : SALOME::GenericObj_i( thePOA ), 
51     SMESH_Hypothesis_i( thePOA )
52 {
53   myBaseImpl = new ::GHS3DPlugin_Hypothesis (theGenImpl->GetANewId(),
54                                              theStudyId,
55                                              theGenImpl);
56 }
57
58 //=======================================================================
59 //function : ~GHS3DPlugin_Hypothesis_i
60 //=======================================================================
61
62 GHS3DPlugin_Hypothesis_i::~GHS3DPlugin_Hypothesis_i()
63 {
64 }
65
66 //=======================================================================
67 //function : SetToMeshHoles
68 //=======================================================================
69
70 void GHS3DPlugin_Hypothesis_i::SetToMeshHoles(CORBA::Boolean toMesh)
71 {
72   ASSERT(myBaseImpl);
73   this->GetImpl()->SetToMeshHoles(toMesh);
74   SMESH::TPythonDump() << _this() << ".SetToMeshHoles( " << toMesh << " )";
75 }
76
77 //=======================================================================
78 //function : GetToMeshHoles
79 //=======================================================================
80
81 CORBA::Boolean GHS3DPlugin_Hypothesis_i::GetToMeshHoles()
82 {
83   ASSERT(myBaseImpl);
84   return this->GetImpl()->GetToMeshHoles();
85 }
86
87 //=======================================================================
88 //function : SetToMakeGroupsOfDomains
89 //=======================================================================
90
91 void GHS3DPlugin_Hypothesis_i::SetToMakeGroupsOfDomains(CORBA::Boolean toMakeGroups)
92 {
93   ASSERT(myBaseImpl);
94   this->GetImpl()->SetToMakeGroupsOfDomains(toMakeGroups);
95   SMESH::TPythonDump() << _this() << ".SetToMakeGroupsOfDomains( " << toMakeGroups << " )";
96 }
97
98 //=======================================================================
99 //function : GetToMakeGroupsOfDomains
100 //=======================================================================
101
102 CORBA::Boolean GHS3DPlugin_Hypothesis_i::GetToMakeGroupsOfDomains()
103 {
104   ASSERT(myBaseImpl);
105   return this->GetImpl()->GetToMakeGroupsOfDomains();
106 }
107
108 //=======================================================================
109 //function : SetMaximumMemory
110 //=======================================================================
111
112 void GHS3DPlugin_Hypothesis_i::SetMaximumMemory(CORBA::Long MB)
113   throw ( SALOME::SALOME_Exception )
114 {
115   if ( MB == 0 )
116     THROW_SALOME_CORBA_EXCEPTION( "Invalid memory size",SALOME::BAD_PARAM );
117   ASSERT(myBaseImpl);
118   this->GetImpl()->SetMaximumMemory(MB);
119   SMESH::TPythonDump() << _this() << ".SetMaximumMemory( " << MB << " )";
120 }
121
122 //=======================================================================
123 //function : GetMaximumMemory
124 //=======================================================================
125
126 CORBA::Long GHS3DPlugin_Hypothesis_i::GetMaximumMemory()
127 {
128   ASSERT(myBaseImpl);
129   return this->GetImpl()->GetMaximumMemory();
130 }
131
132 //=======================================================================
133 //function : SetInitialMemory
134 //=======================================================================
135
136 void GHS3DPlugin_Hypothesis_i::SetInitialMemory(CORBA::Long MB)
137   throw ( SALOME::SALOME_Exception )
138 {
139   if ( MB == 0 )
140     THROW_SALOME_CORBA_EXCEPTION( "Invalid memory size",SALOME::BAD_PARAM );
141   ASSERT(myBaseImpl);
142   this->GetImpl()->SetInitialMemory(MB);
143   SMESH::TPythonDump() << _this() << ".SetInitialMemory( " << MB << " )";
144 }
145
146 //=======================================================================
147 //function : GetInitialMemory
148 //=======================================================================
149
150 CORBA::Long GHS3DPlugin_Hypothesis_i::GetInitialMemory()
151 {
152   ASSERT(myBaseImpl);
153   return this->GetImpl()->GetInitialMemory();
154 }
155
156 //=======================================================================
157 //function : SetOptimizationLevel
158 //=======================================================================
159
160 void GHS3DPlugin_Hypothesis_i::SetOptimizationLevel(CORBA::Short level)
161   throw ( SALOME::SALOME_Exception )
162 {
163   ::GHS3DPlugin_Hypothesis::OptimizationLevel l =
164     (::GHS3DPlugin_Hypothesis::OptimizationLevel) level;
165   if ( l < ::GHS3DPlugin_Hypothesis::None ||
166        l > ::GHS3DPlugin_Hypothesis::Strong )
167     THROW_SALOME_CORBA_EXCEPTION( "Invalid optimization level",SALOME::BAD_PARAM );
168     
169   ASSERT(myBaseImpl);
170   this->GetImpl()->SetOptimizationLevel(l);
171   SMESH::TPythonDump() << _this() << ".SetOptimizationLevel( " << level << " )";
172 }
173
174 //=======================================================================
175 //function : GetOptimizationLevel
176 //=======================================================================
177
178 CORBA::Short GHS3DPlugin_Hypothesis_i::GetOptimizationLevel()
179 {
180   ASSERT(myBaseImpl);
181   return this->GetImpl()->GetOptimizationLevel();
182 }
183
184 //=======================================================================
185 //function : SetWorkingDirectory
186 //=======================================================================
187
188 void GHS3DPlugin_Hypothesis_i::SetWorkingDirectory(const char* path) throw ( SALOME::SALOME_Exception )
189 {
190   if (!path )
191     THROW_SALOME_CORBA_EXCEPTION( "Null working directory",SALOME::BAD_PARAM );
192
193   string file(path);
194   const char lastChar = *file.rbegin();
195 #ifdef WIN32
196   if ( lastChar != '\\' ) file += '\\';
197 #else
198   if ( lastChar != '/' ) file += '/';
199 #endif
200   file += "GHS3D.log";
201   SMESH_Mesh_i::PrepareForWriting (file.c_str());
202
203   ASSERT(myBaseImpl);
204   this->GetImpl()->SetWorkingDirectory(path);
205   SMESH::TPythonDump() << _this() << ".SetWorkingDirectory( '" << path << "' )";
206 }
207
208 //=======================================================================
209 //function : GetWorkingDirectory
210 //=======================================================================
211
212 char* GHS3DPlugin_Hypothesis_i::GetWorkingDirectory()
213 {
214   ASSERT(myBaseImpl);
215   return CORBA::string_dup( this->GetImpl()->GetWorkingDirectory().c_str() );
216 }
217
218 //=======================================================================
219 //function : SetKeepFiles
220 //=======================================================================
221
222 void GHS3DPlugin_Hypothesis_i::SetKeepFiles(CORBA::Boolean toKeep)
223 {
224   ASSERT(myBaseImpl);
225   this->GetImpl()->SetKeepFiles(toKeep);
226   SMESH::TPythonDump() << _this() << ".SetKeepFiles( " << toKeep << " )";
227 }
228
229 //=======================================================================
230 //function : GetKeepFiles
231 //=======================================================================
232
233 CORBA::Boolean GHS3DPlugin_Hypothesis_i::GetKeepFiles()
234 {
235   ASSERT(myBaseImpl);
236   return this->GetImpl()->GetKeepFiles();
237 }
238
239 //=======================================================================
240 //function : SetVerboseLevel
241 //=======================================================================
242
243 void GHS3DPlugin_Hypothesis_i::SetVerboseLevel(CORBA::Short level)
244   throw ( SALOME::SALOME_Exception )
245 {
246   if (level < 0 || level > 10 )
247     THROW_SALOME_CORBA_EXCEPTION( "Invalid verbose level, valid range is [0-10]",
248                                   SALOME::BAD_PARAM );
249   ASSERT(myBaseImpl);
250   this->GetImpl()->SetVerboseLevel(level);
251   SMESH::TPythonDump() << _this() << ".SetVerboseLevel( " << level << " )";
252 }
253
254 //=======================================================================
255 //function : GetVerboseLevel
256 //=======================================================================
257
258 CORBA::Short GHS3DPlugin_Hypothesis_i::GetVerboseLevel()
259 {
260   ASSERT(myBaseImpl);
261   return this->GetImpl()->GetVerboseLevel();
262 }
263
264 //=======================================================================
265 //function : SetToCreateNewNodes
266 //=======================================================================
267
268 void GHS3DPlugin_Hypothesis_i::SetToCreateNewNodes(CORBA::Boolean toCreate)
269 {
270   ASSERT(myBaseImpl);
271   this->GetImpl()->SetToCreateNewNodes(toCreate);
272   SMESH::TPythonDump() << _this() << ".SetToCreateNewNodes( " << toCreate << " )";
273 }
274
275 //=======================================================================
276 //function : GetToCreateNewNodes
277 //=======================================================================
278
279 CORBA::Boolean GHS3DPlugin_Hypothesis_i::GetToCreateNewNodes()
280 {
281   ASSERT(myBaseImpl);
282   return this->GetImpl()->GetToCreateNewNodes();
283 }
284
285 //=======================================================================
286 //function : SetToUseBoundaryRecoveryVersion
287 //=======================================================================
288
289 void GHS3DPlugin_Hypothesis_i::SetToUseBoundaryRecoveryVersion(CORBA::Boolean toUse)
290 {
291   ASSERT(myBaseImpl);
292   this->GetImpl()->SetToUseBoundaryRecoveryVersion(toUse);
293   SMESH::TPythonDump() << _this() << ".SetToUseBoundaryRecoveryVersion( " << toUse << " )";
294 }
295
296 //=======================================================================
297 //function : GetToUseBoundaryRecoveryVersion
298 //=======================================================================
299
300 CORBA::Boolean GHS3DPlugin_Hypothesis_i::GetToUseBoundaryRecoveryVersion()
301 {
302   ASSERT(myBaseImpl);
303   return this->GetImpl()->GetToUseBoundaryRecoveryVersion();
304 }
305
306 //=======================================================================
307 //function : SetFEMCorrection
308 //=======================================================================
309
310 void GHS3DPlugin_Hypothesis_i::SetFEMCorrection(CORBA::Boolean toUseFem)
311 {
312   ASSERT(myBaseImpl);
313   this->GetImpl()->SetFEMCorrection(toUseFem);
314   SMESH::TPythonDump() << _this() << ".SetFEMCorrection( " << toUseFem << " )";
315 }
316
317 //=======================================================================
318 //function : GetFEMCorrection
319 //=======================================================================
320
321 CORBA::Boolean GHS3DPlugin_Hypothesis_i::GetFEMCorrection()
322 {
323   ASSERT(myBaseImpl);
324   return this->GetImpl()->GetFEMCorrection();
325 }
326
327 //=======================================================================
328 //function : SetToRemoveCentralPoint
329 //=======================================================================
330
331 void GHS3DPlugin_Hypothesis_i::SetToRemoveCentralPoint(CORBA::Boolean toRemove)
332 {
333   ASSERT(myBaseImpl);
334   this->GetImpl()->SetToRemoveCentralPoint(toRemove);
335   SMESH::TPythonDump() << _this() << ".SetToRemoveCentralPoint( " << toRemove << " )";
336 }
337
338 //=======================================================================
339 //function : GetToRemoveCentralPoint
340 //=======================================================================
341
342 CORBA::Boolean GHS3DPlugin_Hypothesis_i::GetToRemoveCentralPoint()
343 {
344   ASSERT(myBaseImpl);
345   return this->GetImpl()->GetToRemoveCentralPoint();
346 }
347
348 //=======================================================================
349 //function : SetTextOption
350 //=======================================================================
351
352 void GHS3DPlugin_Hypothesis_i::SetTextOption(const char* option)
353 {
354   ASSERT(myBaseImpl);
355   this->GetImpl()->SetAdvancedOption(option);
356   SMESH::TPythonDump() << _this() << ".SetAdvancedOption( '" << option << "' )";
357 }
358
359 //=======================================================================
360 //function : GetTextOption
361 //=======================================================================
362
363 char* GHS3DPlugin_Hypothesis_i::GetTextOption()
364 {
365   ASSERT(myBaseImpl);
366   return CORBA::string_dup( this->GetImpl()->GetAdvancedOption().c_str() );
367 }
368
369 //=======================================================================
370 //function : SetAdvancedOption
371 //=======================================================================
372
373 void GHS3DPlugin_Hypothesis_i::SetAdvancedOption(const char* option)
374 {
375   ASSERT(myBaseImpl);
376   this->GetImpl()->SetAdvancedOption(option);
377   SMESH::TPythonDump() << _this() << ".SetAdvancedOption( '" << option << "' )";
378 }
379
380 //=======================================================================
381 //function : GetAdvancedOption
382 //=======================================================================
383
384 char* GHS3DPlugin_Hypothesis_i::GetAdvancedOption()
385 {
386   ASSERT(myBaseImpl);
387   return CORBA::string_dup( this->GetImpl()->GetAdvancedOption().c_str() );
388 }
389
390 //=======================================================================
391 //function : SetToRemoveCentralPoint
392 //=======================================================================
393
394 void GHS3DPlugin_Hypothesis_i::SetGradation(CORBA::Double gradation)
395 {
396   ASSERT(myBaseImpl);
397   if (gradation != GetGradation()) {
398     this->GetImpl()->SetGradation(gradation);
399     SMESH::TPythonDump() << _this() << ".SetGradation( " << gradation << " )";
400   }
401 }
402
403 //=======================================================================
404 //function : GetToRemoveCentralPoint
405 //=======================================================================
406
407 CORBA::Double GHS3DPlugin_Hypothesis_i::GetGradation()
408 {
409   ASSERT(myBaseImpl);
410   return this->GetImpl()->GetGradation();
411 }
412
413 //=======================================================================
414 //function : SetStandardOutputLog
415 //=======================================================================
416
417 void GHS3DPlugin_Hypothesis_i::SetStandardOutputLog(CORBA::Boolean logInStandardOutput)
418 {
419   ASSERT(myBaseImpl);
420   this->GetImpl()->SetStandardOutputLog(logInStandardOutput);
421   SMESH::TPythonDump() << _this() << ".SetPrintLogInFile( " << !logInStandardOutput << " )";
422 }
423
424 //=======================================================================
425 //function : GetStandardOutputLog
426 //=======================================================================
427
428 CORBA::Boolean GHS3DPlugin_Hypothesis_i::GetStandardOutputLog()
429 {
430   ASSERT(myBaseImpl);
431   return this->GetImpl()->GetStandardOutputLog();
432 }
433
434 //=======================================================================
435 //function : SetRemoveLogOnSuccess
436 //=======================================================================
437
438 void GHS3DPlugin_Hypothesis_i::SetRemoveLogOnSuccess(CORBA::Boolean removeLogOnSuccess)
439 {
440   ASSERT(myBaseImpl);
441   this->GetImpl()->SetRemoveLogOnSuccess(removeLogOnSuccess);
442   SMESH::TPythonDump() << _this() << ".SetRemoveLogOnSuccess( " << removeLogOnSuccess << " )";
443 }
444
445 //=======================================================================
446 //function : GetRemoveLogOnSuccess
447 //=======================================================================
448
449 CORBA::Boolean GHS3DPlugin_Hypothesis_i::GetRemoveLogOnSuccess()
450 {
451   ASSERT(myBaseImpl);
452   return this->GetImpl()->GetRemoveLogOnSuccess();
453 }
454
455 //=======================================================================
456 //function : SetEnforcedVertex
457 //=======================================================================
458
459 bool GHS3DPlugin_Hypothesis_i::SetEnforcedVertex(CORBA::Double x, CORBA::Double y, CORBA::Double z, CORBA::Double size)
460   throw (SALOME::SALOME_Exception) {
461   ASSERT(myBaseImpl);
462   return p_SetEnforcedVertex(size, x, y, z);
463 }
464
465 bool GHS3DPlugin_Hypothesis_i::SetEnforcedVertexNamed(CORBA::Double x, CORBA::Double y, CORBA::Double z, CORBA::Double size, const char* theVertexName)
466   throw (SALOME::SALOME_Exception) {
467   ASSERT(myBaseImpl);
468   return p_SetEnforcedVertex(size, x, y, z, theVertexName, "", "");
469 }
470
471 bool GHS3DPlugin_Hypothesis_i::SetEnforcedVertexWithGroup(CORBA::Double x, CORBA::Double y, CORBA::Double z, CORBA::Double size, const char* theGroupName)
472   throw (SALOME::SALOME_Exception) {
473   ASSERT(myBaseImpl);
474   return p_SetEnforcedVertex(size, x, y, z, "", "", theGroupName);
475 }
476
477 bool GHS3DPlugin_Hypothesis_i::SetEnforcedVertexNamedWithGroup(CORBA::Double x, CORBA::Double y, CORBA::Double z, CORBA::Double size, const char* theVertexName, const char* theGroupName)
478   throw (SALOME::SALOME_Exception) {
479   ASSERT(myBaseImpl);
480   return p_SetEnforcedVertex(size, x, y, z, theVertexName, "", theGroupName);
481 }
482
483 bool GHS3DPlugin_Hypothesis_i::SetEnforcedVertexGeom(GEOM::GEOM_Object_ptr theVertex, CORBA::Double size)
484   throw (SALOME::SALOME_Exception) {
485   ASSERT(myBaseImpl);
486   
487   if ((theVertex->GetShapeType() != GEOM::VERTEX) && (theVertex->GetShapeType() != GEOM::COMPOUND)) {
488     THROW_SALOME_CORBA_EXCEPTION("theVertex shape type is not VERTEX or COMPOUND", SALOME::BAD_PARAM);
489   }
490   
491   string theVertexEntry = theVertex->GetStudyEntry();
492   CORBA::Double x = 0, y = 0, z = 0;
493   CORBA::Boolean isCompound = false;
494   GEOM::GEOM_Gen_ptr geomGen = SMESH_Gen_i::GetGeomEngine();
495   SMESH_Gen_i *smeshGen = SMESH_Gen_i::GetSMESHGen();
496   if (theVertexEntry.empty()) {
497     string aName;
498     if (theVertex->GetShapeType() == GEOM::VERTEX) {
499       aName = "Vertex_";
500     }
501     if (theVertex->GetShapeType() == GEOM::COMPOUND) {
502       aName = "Compound_";
503       isCompound = true;
504     }
505     aName += theVertex->GetEntry();
506     SALOMEDS::SObject_ptr theSVertex = geomGen->PublishInStudy(smeshGen->GetCurrentStudy(), NULL, theVertex, aName.c_str());
507     if (!theSVertex->_is_nil())
508       theVertexEntry = theSVertex->GetID();
509   }
510   if (theVertexEntry.empty())
511     THROW_SALOME_CORBA_EXCEPTION( "Geom object is not published in study" ,SALOME::BAD_PARAM );
512
513   if (theVertex->GetShapeType() == GEOM::VERTEX) {
514     GEOM::GEOM_IMeasureOperations_var measureOp = geomGen->GetIMeasureOperations( smeshGen->GetCurrentStudy()->StudyId() );
515     if (CORBA::is_nil(measureOp))
516       return false;
517     
518     measureOp->PointCoordinates (theVertex, x, y, z);
519   }
520
521   string theVertexName = theVertex->GetName();
522   
523   return p_SetEnforcedVertex(size, x, y, z, theVertexName.c_str(), theVertexEntry.c_str(), "", isCompound);
524 }
525
526 bool GHS3DPlugin_Hypothesis_i::SetEnforcedVertexGeomWithGroup(GEOM::GEOM_Object_ptr theVertex, CORBA::Double size, const char* theGroupName)
527   throw (SALOME::SALOME_Exception) {
528   ASSERT(myBaseImpl);
529   
530   if ((theVertex->GetShapeType() != GEOM::VERTEX) && (theVertex->GetShapeType() != GEOM::COMPOUND)) {
531     THROW_SALOME_CORBA_EXCEPTION("theVertex shape type is not VERTEX or COMPOUND", SALOME::BAD_PARAM);
532   }
533   
534   string theVertexEntry = theVertex->GetStudyEntry();
535   CORBA::Double x = 0, y = 0, z = 0;
536   CORBA::Boolean isCompound = false;
537   GEOM::GEOM_Gen_ptr geomGen = SMESH_Gen_i::GetGeomEngine();
538   SMESH_Gen_i *smeshGen = SMESH_Gen_i::GetSMESHGen();
539   if (theVertexEntry.empty()) {
540     string aName;
541     if (theVertex->GetShapeType() == GEOM::VERTEX) {
542       aName = "Vertex_";
543     }
544     if (theVertex->GetShapeType() == GEOM::COMPOUND) {
545       aName = "Compound_";
546       isCompound = true;
547     }
548     aName += theVertex->GetEntry();
549     SALOMEDS::SObject_ptr theSVertex = geomGen->PublishInStudy(smeshGen->GetCurrentStudy(), NULL, theVertex, aName.c_str());
550     if (!theSVertex->_is_nil())
551       theVertexEntry = theSVertex->GetID();
552   }
553   if (theVertexEntry.empty())
554     THROW_SALOME_CORBA_EXCEPTION( "Geom object is not published in study" ,SALOME::BAD_PARAM );
555
556   if (theVertex->GetShapeType() == GEOM::VERTEX) {
557     GEOM::GEOM_IMeasureOperations_var measureOp = geomGen->GetIMeasureOperations( smeshGen->GetCurrentStudy()->StudyId() );
558     if (CORBA::is_nil(measureOp))
559       return false;
560     
561     measureOp->PointCoordinates (theVertex, x, y, z);
562   }
563     
564   string theVertexName = theVertex->GetName();
565   
566   return p_SetEnforcedVertex(size, x, y, z, theVertexName.c_str(), theVertexEntry.c_str(), theGroupName, isCompound);
567 }
568
569 bool GHS3DPlugin_Hypothesis_i:: p_SetEnforcedVertex(CORBA::Double size, CORBA::Double x, CORBA::Double y, CORBA::Double z,
570                                                     const char* theVertexName, const char* theVertexEntry, const char* theGroupName,
571                                                     CORBA::Boolean isCompound)
572   throw (SALOME::SALOME_Exception) {
573   ASSERT(myBaseImpl);
574   bool newValue = false;
575
576   ::GHS3DPlugin_Hypothesis::TCoordsGHS3DEnforcedVertexMap coordsList;
577   ::GHS3DPlugin_Hypothesis::TGeomEntryGHS3DEnforcedVertexMap enfVertexEntryList;
578   if (string(theVertexEntry).empty()) {
579     coordsList = this->GetImpl()->_GetEnforcedVerticesByCoords();
580     std::vector<double> coords;
581     coords.push_back(x);
582     coords.push_back(y);
583     coords.push_back(z);
584     if (coordsList.find(coords) == coordsList.end()) {
585       newValue = true;
586     }
587     else {
588       ::GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertex *enfVertex = this->GetImpl()->GetEnforcedVertex(x, y, z);
589       if ((enfVertex->name != theVertexName) || (enfVertex->groupName != theGroupName) || (enfVertex->size != size)) {
590         newValue = true;
591       }
592     }
593
594     if (newValue) {
595       if (string(theVertexName).empty()) {
596         if (string(theGroupName).empty())
597           SMESH::TPythonDump() << "isDone = " << _this() << ".SetEnforcedVertex(" << x << ", " << y << ", " << z << ", " << size << ")";
598         else
599           SMESH::TPythonDump() << "isDone = " << _this() << ".SetEnforcedVertexWithGroup(" << x << ", " << y << ", " << z << ", " << size << ", \"" << theGroupName << "\")";
600       }
601       else {
602         if (string(theGroupName).empty())
603           SMESH::TPythonDump() << "isDone = " << _this() << ".SetEnforcedVertexNamed(" << x << ", " << y << ", " << z << ", " << size  << ", \"" << theVertexName << "\")";
604         else
605           SMESH::TPythonDump() << "isDone = " << _this() << ".SetEnforcedVertexNamedWithGroup(" << x << ", " << y << ", " << z << ", " << size  << ", \"" << theVertexName << "\", \"" << theGroupName << "\")";
606       }
607     }
608   } 
609   else {
610     enfVertexEntryList = this->GetImpl()->_GetEnforcedVerticesByEntry();
611     if ( enfVertexEntryList.find(theVertexEntry) == enfVertexEntryList.end()) {
612       newValue = true;
613     }
614     else {
615       ::GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertex *enfVertex = this->GetImpl()->GetEnforcedVertex(theVertexEntry);
616       if ((enfVertex->name != theVertexName) || (enfVertex->groupName != theGroupName) || (enfVertex->size != size)) {
617         newValue = true;
618       }
619     }
620
621     if (newValue) {
622       if (string(theGroupName).empty())
623         SMESH::TPythonDump() << "isDone = " << _this() << ".SetEnforcedVertexGeom(" << theVertexEntry << ", " << size << ")";
624       else
625         SMESH::TPythonDump() << "isDone = " << _this() << ".SetEnforcedVertexGeomWithGroup(" << theVertexEntry << ", " << size << ", \"" << theGroupName << "\")";
626     }
627   }
628
629   if (newValue)
630     this->GetImpl()->SetEnforcedVertex(theVertexName, theVertexEntry, theGroupName, size, x, y, z, isCompound);
631
632   return newValue;
633 }
634
635 //=======================================================================
636 //function : GetEnforcedVertex
637 //=======================================================================
638
639 CORBA::Double GHS3DPlugin_Hypothesis_i::GetEnforcedVertex(CORBA::Double x, CORBA::Double y, CORBA::Double z)
640   throw (SALOME::SALOME_Exception)
641 {
642   ASSERT(myBaseImpl);
643   try {
644     bool isDone = this->GetImpl()->GetEnforcedVertex(x,y,z)->size;
645     SMESH::TPythonDump() << "aSize = " << _this() << ".GetEnforcedVertex(" << x << ", " << y << ", " << z << ")";
646     return isDone;
647   }
648   catch (const std::invalid_argument& ex) {
649     THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM );
650   }
651   catch (SALOME_Exception& ex) {
652     THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM );
653   }
654 }
655
656 //=======================================================================
657 //function : GetEnforcedVertex
658 //=======================================================================
659
660 CORBA::Double GHS3DPlugin_Hypothesis_i::GetEnforcedVertexGeom(GEOM::GEOM_Object_ptr theVertex)
661   throw (SALOME::SALOME_Exception)
662 {
663   ASSERT(myBaseImpl);
664   
665   if ((theVertex->GetShapeType() != GEOM::VERTEX) && (theVertex->GetShapeType() != GEOM::COMPOUND)) {
666     THROW_SALOME_CORBA_EXCEPTION("theVertex shape type is not VERTEX or COMPOUND", SALOME::BAD_PARAM);
667   }
668   
669   string theVertexEntry = theVertex->GetStudyEntry();
670   if (theVertexEntry.empty()) {
671     GEOM::GEOM_Gen_ptr geomGen = SMESH_Gen_i::GetGeomEngine();
672     SMESH_Gen_i *smeshGen = SMESH_Gen_i::GetSMESHGen();
673     string aName;
674     if (theVertex->GetShapeType() == GEOM::VERTEX)
675       aName = "Vertex_";
676     if (theVertex->GetShapeType() == GEOM::COMPOUND)
677       aName = "Compound_";
678     aName += theVertex->GetEntry();
679     SALOMEDS::SObject_ptr theSVertex = geomGen->PublishInStudy(smeshGen->GetCurrentStudy(), NULL, theVertex, aName.c_str());
680     if (!theSVertex->_is_nil())
681       theVertexEntry = theSVertex->GetID();
682   }
683   if (theVertexEntry.empty())
684     THROW_SALOME_CORBA_EXCEPTION( "Geom object is not published in study" ,SALOME::BAD_PARAM );
685
686   string theVertexName = theVertex->GetName();
687   
688   try {
689     bool isDone = this->GetImpl()->GetEnforcedVertex(theVertexName)->size;
690     SMESH::TPythonDump() << "aSize = " << _this() << ".GetEnforcedVertexGeom(" << theVertex << ")";
691     return isDone;
692   }
693   catch (const std::invalid_argument& ex) {
694     THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM );
695   }
696   catch (SALOME_Exception& ex) {
697     THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM );
698   }
699 }
700
701 //=======================================================================
702 //function : GetEnforcedVertices
703 //=======================================================================
704
705 GHS3DPlugin::GHS3DEnforcedVertexList* GHS3DPlugin_Hypothesis_i::GetEnforcedVertices()
706 {
707   ASSERT(myBaseImpl);
708   GHS3DPlugin::GHS3DEnforcedVertexList_var result = new GHS3DPlugin::GHS3DEnforcedVertexList();
709
710   const ::GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexList enfVertexList = this->GetImpl()->_GetEnforcedVertices();
711   result->length( enfVertexList.size() );
712
713   ::GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexList::const_iterator it = enfVertexList.begin();
714
715   for (int i = 0 ; it != enfVertexList.end(); ++it, ++i ) {
716     ::GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertex* currentVertex = (*it);
717     GHS3DPlugin::GHS3DEnforcedVertex_var enfVertex = new GHS3DPlugin::GHS3DEnforcedVertex();
718     // Name
719     enfVertex->name = CORBA::string_dup(currentVertex->name.c_str());
720     // Geom Vertex Entry
721     enfVertex->geomEntry = CORBA::string_dup(currentVertex->geomEntry.c_str());
722     // Coords
723     GHS3DPlugin::TCoords_var coords = new GHS3DPlugin::TCoords();
724     coords->length(currentVertex->coords.size());
725     for ( size_t ind = 0; ind < currentVertex->coords.size(); ind++)
726       coords[ind] = currentVertex->coords[ind];
727     enfVertex->coords = coords;
728     // Group Name
729     enfVertex->groupName = CORBA::string_dup(currentVertex->groupName.c_str());
730     // Size
731     enfVertex->size = currentVertex->size;
732     // isCompound
733     enfVertex->isCompound = currentVertex->isCompound;
734     
735     result[i]=enfVertex;
736   }
737   
738   //   SMESH::TPythonDump() << "allEnforcedVertices = " << _this() << ".GetEnforcedVertices()";
739
740   return result._retn();
741 }
742
743 //=======================================================================
744 //function : RemoveEnforcedVertex
745 //=======================================================================
746
747 bool GHS3DPlugin_Hypothesis_i::RemoveEnforcedVertex(CORBA::Double x, CORBA::Double y, CORBA::Double z)
748   throw (SALOME::SALOME_Exception)
749 {
750   ASSERT(myBaseImpl);
751   try {
752     bool res = this->GetImpl()->RemoveEnforcedVertex(x,y,z);
753     SMESH::TPythonDump() << " isDone = " << _this() << ".RemoveEnforcedVertex( " << x << ", " << y << ", " << z << " )";
754     return res;
755   }
756   catch (const std::invalid_argument& ex) {
757     THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM );
758   }
759   catch (SALOME_Exception& ex) {
760     THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM );
761   }
762 }
763
764 bool GHS3DPlugin_Hypothesis_i::RemoveEnforcedVertexGeom(GEOM::GEOM_Object_ptr theVertex)
765   throw (SALOME::SALOME_Exception)
766 {
767   ASSERT(myBaseImpl);
768   
769   if ((theVertex->GetShapeType() != GEOM::VERTEX) && (theVertex->GetShapeType() != GEOM::COMPOUND)) {
770     THROW_SALOME_CORBA_EXCEPTION("theVertex shape type is not VERTEX or COMPOUND", SALOME::BAD_PARAM);
771   }
772   
773   string theVertexEntry = theVertex->GetStudyEntry();
774   if (theVertexEntry.empty()) {
775     GEOM::GEOM_Gen_ptr geomGen = SMESH_Gen_i::GetGeomEngine();
776     SMESH_Gen_i *smeshGen = SMESH_Gen_i::GetSMESHGen();
777     string aName;
778     if (theVertex->GetShapeType() == GEOM::VERTEX)
779       aName = "Vertex_";
780     if (theVertex->GetShapeType() == GEOM::COMPOUND)
781       aName = "Compound_";
782     aName += theVertex->GetEntry();
783     SALOMEDS::SObject_ptr theSVertex = geomGen->PublishInStudy(smeshGen->GetCurrentStudy(), NULL, theVertex, aName.c_str());
784     if (!theSVertex->_is_nil())
785       theVertexEntry = theSVertex->GetID();
786   }
787   if (theVertexEntry.empty())
788     THROW_SALOME_CORBA_EXCEPTION( "Geom object is not published in study" ,SALOME::BAD_PARAM );
789   
790   try {
791     bool res = this->GetImpl()->RemoveEnforcedVertex(0,0,0, theVertexEntry.c_str());
792     SMESH::TPythonDump() << "isDone = " << _this() << ".RemoveEnforcedVertexGeom( " << theVertexEntry.c_str() << " )";
793     return res;
794   }
795   catch (const std::invalid_argument& ex) {
796     THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM );
797   }
798   catch (SALOME_Exception& ex) {
799     THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM );
800   }
801 }
802
803 //=======================================================================
804 //function : ClearEnforcedVertices
805 //=======================================================================
806
807 void GHS3DPlugin_Hypothesis_i::ClearEnforcedVertices()
808 {
809   ASSERT(myBaseImpl);
810   this->GetImpl()->ClearEnforcedVertices();
811   SMESH::TPythonDump () << _this() << ".ClearEnforcedVertices() ";
812 }
813
814 //=======================================================================
815 //function : ClearEnforcedMeshes
816 //=======================================================================
817
818 void GHS3DPlugin_Hypothesis_i::ClearEnforcedMeshes()
819 {
820   ASSERT(myBaseImpl);
821   this->GetImpl()->ClearEnforcedMeshes();
822   SMESH::TPythonDump () << _this() << ".ClearEnforcedMeshes() ";
823 }
824
825 //=======================================================================
826 //function : GetEnforcedMeshes
827 //=======================================================================
828
829 GHS3DPlugin::GHS3DEnforcedMeshList* GHS3DPlugin_Hypothesis_i::GetEnforcedMeshes()
830 {
831   ASSERT(myBaseImpl);
832   GHS3DPlugin::GHS3DEnforcedMeshList_var result = new GHS3DPlugin::GHS3DEnforcedMeshList();
833
834   const ::GHS3DPlugin_Hypothesis::TGHS3DEnforcedMeshList enfMeshList = this->GetImpl()->_GetEnforcedMeshes();
835   result->length( enfMeshList.size() );
836
837   ::GHS3DPlugin_Hypothesis::TGHS3DEnforcedMeshList::const_iterator it = enfMeshList.begin();
838
839   for (int i = 0 ; it != enfMeshList.end(); ++it, ++i ) {
840     ::GHS3DPlugin_Hypothesis::TGHS3DEnforcedMesh* currentMesh = (*it);
841     GHS3DPlugin::GHS3DEnforcedMesh_var enfMesh = new GHS3DPlugin::GHS3DEnforcedMesh();
842     // Name
843     enfMesh->name = CORBA::string_dup(currentMesh->name.c_str());
844     // Mesh Entry
845     enfMesh->entry = CORBA::string_dup(currentMesh->entry.c_str());
846     // isCompound
847     enfMesh->elementType = currentMesh->elementType;
848     // Group Name
849     enfMesh->groupName = CORBA::string_dup(currentMesh->groupName.c_str());
850     
851     result[i]=enfMesh;
852   }
853   
854   //   SMESH::TPythonDump() << "allEnforcedVertices = " << _this() << ".GetEnforcedVertices()";
855
856   return result._retn();
857 }
858
859 /*!
860  * \brief Adds enforced elements of type elementType using another mesh/sub-mesh/mesh group theSource. The elements will be grouped in theGroupName.
861  */
862 bool GHS3DPlugin_Hypothesis_i::SetEnforcedMeshWithGroup(SMESH::SMESH_IDSource_ptr theSource, SMESH::ElementType theType, const char* theGroupName)
863   throw (SALOME::SALOME_Exception)
864 {
865   return p_SetEnforcedMesh(theSource, theType, "", theGroupName);
866 }
867
868 /*!
869  * \brief Adds enforced elements of type elementType using another mesh/sub-mesh/mesh group theSource.
870  */
871 bool GHS3DPlugin_Hypothesis_i::SetEnforcedMesh(SMESH::SMESH_IDSource_ptr theSource, SMESH::ElementType theType)
872   throw (SALOME::SALOME_Exception)
873 {
874   return p_SetEnforcedMesh(theSource, theType);
875 }
876
877 /*!
878  * \brief OBSOLETE FUNCTION - Adds enforced elements of type elementType using another mesh/sub-mesh/mesh group theSource and a size. The elements will be grouped in theGroupName.
879  */
880 bool GHS3DPlugin_Hypothesis_i::SetEnforcedMeshSizeWithGroup(SMESH::SMESH_IDSource_ptr theSource, SMESH::ElementType theType, double theSize, const char* theGroupName)
881   throw (SALOME::SALOME_Exception)
882 {
883   return p_SetEnforcedMesh(theSource, theType, "", theGroupName);
884 }
885
886 /*!
887  * \brief OBSOLETE FUNCTION - Adds enforced elements of type elementType using another mesh/sub-mesh/mesh group theSource and a size.
888  */
889 bool GHS3DPlugin_Hypothesis_i::SetEnforcedMeshSize(SMESH::SMESH_IDSource_ptr theSource, SMESH::ElementType theType, double theSize)
890   throw (SALOME::SALOME_Exception)
891 {
892   return p_SetEnforcedMesh(theSource, theType);
893 }
894
895 bool GHS3DPlugin_Hypothesis_i::p_SetEnforcedMesh(SMESH::SMESH_IDSource_ptr theSource,
896                                                  SMESH::ElementType        theType,
897                                                  const char*               theName,
898                                                  const char*               theGroupName)
899   throw (SALOME::SALOME_Exception)
900 {
901   ASSERT(myBaseImpl);
902
903   if (CORBA::is_nil( theSource ))
904     THROW_SALOME_CORBA_EXCEPTION( "The source mesh CORBA object is NULL" ,SALOME::BAD_PARAM );
905
906   switch (theType) {
907   case SMESH::NODE:
908   case SMESH::EDGE:
909   case SMESH::FACE: break;
910   default:
911     return false;
912   }
913   SMESH::array_of_ElementType_var types = theSource->GetTypes();
914   if ( types->length() >= 1 && types[types->length()-1] <  theType)
915   {
916     return false;
917   }
918
919   SMESH_Gen_i *smeshGen = SMESH_Gen_i::GetSMESHGen();
920   SALOMEDS::SObject_ptr SObj = smeshGen->ObjectToSObject(smeshGen->GetCurrentStudy(),theSource);
921
922   SMESH_Mesh_i* theMesh_i = SMESH::DownCast<SMESH_Mesh_i*>( theSource);
923   SMESH_Group_i* theGroup_i = SMESH::DownCast<SMESH_Group_i*>( theSource);
924   SMESH_GroupOnGeom_i* theGroupOnGeom_i = SMESH::DownCast<SMESH_GroupOnGeom_i*>( theSource);
925
926   string enfMeshName = theName;
927   if (enfMeshName.empty())
928     enfMeshName = SObj->GetName();
929
930   if (theMesh_i)
931   {
932     try {
933       bool res = this->GetImpl()->SetEnforcedMesh(theMesh_i->GetImpl(), theType, enfMeshName , SObj->GetID(), theGroupName);
934       if (theGroupName && theGroupName[0] ) {
935         SMESH::TPythonDump () << "isDone = " << _this() << ".SetEnforcedMeshWithGroup( "
936                               << theSource << ".GetMesh(), " << theType << ", \"" << theGroupName << "\" )";
937       }
938       else {
939         SMESH::TPythonDump () << "isDone = " << _this() << ".SetEnforcedMesh( "
940                               << theSource << ".GetMesh(), " << theType << " )";
941       }
942
943       return res;
944     }
945     catch (const std::invalid_argument& ex) {
946       SALOME::ExceptionStruct ExDescription;
947       ExDescription.text = ex.what();
948       ExDescription.type = SALOME::BAD_PARAM;
949       ExDescription.sourceFile = "GHS3DPlugin_Hypothesis_i.cxx";
950       ExDescription.lineNumber = 840;
951       throw SALOME::SALOME_Exception(ExDescription);
952     }
953     catch (SALOME_Exception& ex) {
954       THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM );
955     }
956   }
957   else if (theGroup_i)// && types->length() == 1 && types[0] == theType)
958   {
959     try {
960       bool res = this->GetImpl()->SetEnforcedGroup(theGroup_i->GetGroupDS()->GetMesh(), theGroup_i->GetListOfID(), theType, enfMeshName , SObj->GetID(), theGroupName);
961       if ( theGroupName && theGroupName[0] ) {
962         SMESH::TPythonDump () << "isDone = " << _this() << ".SetEnforcedMeshWithGroup( "
963                               << theSource << ", " << theType << ", \"" << theGroupName << "\" )";
964       }
965       else {
966         SMESH::TPythonDump () << "isDone = " << _this() << ".SetEnforcedMesh( "
967                               << theSource << ", " << theType << " )";
968       }
969       return res;
970     }
971     catch (const std::invalid_argument& ex) {
972       SALOME::ExceptionStruct ExDescription;
973       ExDescription.text = ex.what();
974       ExDescription.type = SALOME::BAD_PARAM;
975       ExDescription.sourceFile = "GHS3DPlugin_Hypothesis_i.cxx";
976       ExDescription.lineNumber = 840;
977       throw SALOME::SALOME_Exception(ExDescription);
978     }
979     catch (SALOME_Exception& ex) {
980       THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM );
981     }
982   }
983   else if (theGroupOnGeom_i)// && types->length() == 1 && types[0] == theType)
984   {
985     try {
986       bool res = this->GetImpl()->SetEnforcedGroup(theGroupOnGeom_i->GetGroupDS()->GetMesh(),theGroupOnGeom_i->GetListOfID(), theType, enfMeshName , SObj->GetID(), theGroupName);
987       if ( theGroupName && theGroupName[0] ) {
988         SMESH::TPythonDump () << "isDone = " << _this() << ".SetEnforcedMeshWithGroup( "
989                               << theSource << ", " << theType << ", \"" << theGroupName << "\" )";
990       }
991       else {
992         SMESH::TPythonDump () << "isDone = " << _this() << ".SetEnforcedMesh( "
993                               << theSource << ", " << theType << " )";
994       }
995       return res;
996     }
997     catch (const std::invalid_argument& ex) {
998       SALOME::ExceptionStruct ExDescription;
999       ExDescription.text = ex.what();
1000       ExDescription.type = SALOME::BAD_PARAM;
1001       ExDescription.sourceFile = "GHS3DPlugin_Hypothesis_i.cxx";
1002       ExDescription.lineNumber = 840;
1003       throw SALOME::SALOME_Exception(ExDescription);
1004     }
1005     catch (SALOME_Exception& ex) {
1006       THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM );
1007     }
1008   }
1009   return false;
1010 }
1011 //=============================================================================
1012 /*!
1013  *  Get implementation
1014  */
1015 //=============================================================================
1016
1017 ::GHS3DPlugin_Hypothesis* GHS3DPlugin_Hypothesis_i::GetImpl()
1018 {
1019   return (::GHS3DPlugin_Hypothesis*)myBaseImpl;
1020 }
1021
1022 //================================================================================
1023 /*!
1024  * \brief Verify whether hypothesis supports given entity type 
1025  */
1026 //================================================================================  
1027
1028 CORBA::Boolean GHS3DPlugin_Hypothesis_i::IsDimSupported( SMESH::Dimension type )
1029 {
1030   return type == SMESH::DIM_3D;
1031 }