]> SALOME platform Git repositories - plugins/ghs3dplugin.git/blob - src/GHS3DPlugin_Hypothesis_i.cxx
Salome HOME
0020682: EDF 1222 SMESH: 3D mesh from a skin mesh and with volumic cells
[plugins/ghs3dplugin.git] / src / GHS3DPlugin_Hypothesis_i.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 // File      : GHS3DPlugin_Hypothesis_i.cxx
20 // Created   : Wed Apr  2 13:53:01 2008
21 // Author    : Edward AGAPOV (eap)
22 //
23 #include "GHS3DPlugin_Hypothesis_i.hxx"
24
25 #include <SMESH_Gen.hxx>
26 #include <SMESH_PythonDump.hxx>
27
28 #include <Utils_CorbaException.hxx>
29 #include <utilities.h>
30 #include <SMESH_Mesh_i.hxx>
31
32 //=======================================================================
33 //function : GHS3DPlugin_Hypothesis_i
34 //=======================================================================
35
36 GHS3DPlugin_Hypothesis_i::GHS3DPlugin_Hypothesis_i (PortableServer::POA_ptr thePOA,
37                                                     int                     theStudyId,
38                                                     ::SMESH_Gen*            theGenImpl)
39   : SALOME::GenericObj_i( thePOA ), 
40     SMESH_Hypothesis_i( thePOA )
41 {
42   MESSAGE( "GHS3DPlugin_Hypothesis_i::GHS3DPlugin_Hypothesis_i" );
43   myBaseImpl = new ::GHS3DPlugin_Hypothesis (theGenImpl->GetANewId(),
44                                               theStudyId,
45                                               theGenImpl);
46 }
47
48 //=======================================================================
49 //function : ~GHS3DPlugin_Hypothesis_i
50 //=======================================================================
51
52 GHS3DPlugin_Hypothesis_i::~GHS3DPlugin_Hypothesis_i()
53 {
54   MESSAGE( "GHS3DPlugin_Hypothesis_i::~GHS3DPlugin_Hypothesis_i" );
55 }
56
57 //=======================================================================
58 //function : SetToMeshHoles
59 //=======================================================================
60
61 void GHS3DPlugin_Hypothesis_i::SetToMeshHoles(CORBA::Boolean toMesh)
62 {
63   ASSERT(myBaseImpl);
64   this->GetImpl()->SetToMeshHoles(toMesh);
65   SMESH::TPythonDump() << _this() << ".SetToMeshHoles( " << toMesh << " )";
66 }
67
68 //=======================================================================
69 //function : GetToMeshHoles
70 //=======================================================================
71
72 CORBA::Boolean GHS3DPlugin_Hypothesis_i::GetToMeshHoles()
73 {
74   ASSERT(myBaseImpl);
75   return this->GetImpl()->GetToMeshHoles();
76 }
77
78 //=======================================================================
79 //function : SetMaximumMemory
80 //=======================================================================
81
82 void GHS3DPlugin_Hypothesis_i::SetMaximumMemory(CORBA::Short MB)
83    throw ( SALOME::SALOME_Exception )
84 {
85   if ( MB == 0 )
86     THROW_SALOME_CORBA_EXCEPTION( "Invalid memory size",SALOME::BAD_PARAM );
87   ASSERT(myBaseImpl);
88   this->GetImpl()->SetMaximumMemory(MB);
89   SMESH::TPythonDump() << _this() << ".SetMaximumMemory( " << MB << " )";
90 }
91
92 //=======================================================================
93 //function : GetMaximumMemory
94 //=======================================================================
95
96 CORBA::Short GHS3DPlugin_Hypothesis_i::GetMaximumMemory()
97 {
98   ASSERT(myBaseImpl);
99   return this->GetImpl()->GetMaximumMemory();
100 }
101
102 //=======================================================================
103 //function : SetInitialMemory
104 //=======================================================================
105
106 void GHS3DPlugin_Hypothesis_i::SetInitialMemory(CORBA::Short MB)
107   throw ( SALOME::SALOME_Exception )
108 {
109   if ( MB == 0 )
110     THROW_SALOME_CORBA_EXCEPTION( "Invalid memory size",SALOME::BAD_PARAM );
111   ASSERT(myBaseImpl);
112   this->GetImpl()->SetInitialMemory(MB);
113   SMESH::TPythonDump() << _this() << ".SetInitialMemory( " << MB << " )";
114 }
115
116 //=======================================================================
117 //function : GetInitialMemory
118 //=======================================================================
119
120 CORBA::Short GHS3DPlugin_Hypothesis_i::GetInitialMemory()
121 {
122   ASSERT(myBaseImpl);
123   return this->GetImpl()->GetInitialMemory();
124 }
125
126 //=======================================================================
127 //function : SetOptimizationLevel
128 //=======================================================================
129
130 void GHS3DPlugin_Hypothesis_i::SetOptimizationLevel(CORBA::Short level)
131   throw ( SALOME::SALOME_Exception )
132 {
133   ::GHS3DPlugin_Hypothesis::OptimizationLevel l =
134       (::GHS3DPlugin_Hypothesis::OptimizationLevel) level;
135   if ( l < ::GHS3DPlugin_Hypothesis::None ||
136        l > ::GHS3DPlugin_Hypothesis::Strong )
137     THROW_SALOME_CORBA_EXCEPTION( "Invalid optimization level",SALOME::BAD_PARAM );
138     
139   ASSERT(myBaseImpl);
140   this->GetImpl()->SetOptimizationLevel(l);
141   SMESH::TPythonDump() << _this() << ".SetOptimizationLevel( " << level << " )";
142 }
143
144 //=======================================================================
145 //function : GetOptimizationLevel
146 //=======================================================================
147
148 CORBA::Short GHS3DPlugin_Hypothesis_i::GetOptimizationLevel()
149 {
150   ASSERT(myBaseImpl);
151   return this->GetImpl()->GetOptimizationLevel();
152 }
153
154 //=======================================================================
155 //function : SetWorkingDirectory
156 //=======================================================================
157
158 void GHS3DPlugin_Hypothesis_i::SetWorkingDirectory(const char* path) throw ( SALOME::SALOME_Exception )
159 {
160   if (!path )
161     THROW_SALOME_CORBA_EXCEPTION( "Null working directory",SALOME::BAD_PARAM );
162
163   string file(path);
164   const char lastChar = *file.rbegin();
165 #ifdef WIN32
166   if ( lastChar != '\\' ) file += '\\';
167 #else
168   if ( lastChar != '/' ) file += '/';
169 #endif
170   file += "GHS3D.log";
171   SMESH_Mesh_i::PrepareForWriting (file.c_str());
172
173   ASSERT(myBaseImpl);
174   this->GetImpl()->SetWorkingDirectory(path);
175   SMESH::TPythonDump() << _this() << ".SetWorkingDirectory( '" << path << "' )";
176 }
177
178 //=======================================================================
179 //function : GetWorkingDirectory
180 //=======================================================================
181
182 char* GHS3DPlugin_Hypothesis_i::GetWorkingDirectory()
183 {
184   ASSERT(myBaseImpl);
185   return CORBA::string_dup( this->GetImpl()->GetWorkingDirectory().c_str() );
186 }
187
188 //=======================================================================
189 //function : SetKeepFiles
190 //=======================================================================
191
192 void GHS3DPlugin_Hypothesis_i::SetKeepFiles(CORBA::Boolean toKeep)
193 {
194   ASSERT(myBaseImpl);
195   this->GetImpl()->SetKeepFiles(toKeep);
196   SMESH::TPythonDump() << _this() << ".SetKeepFiles( " << toKeep << " )";
197 }
198
199 //=======================================================================
200 //function : GetKeepFiles
201 //=======================================================================
202
203 CORBA::Boolean GHS3DPlugin_Hypothesis_i::GetKeepFiles()
204 {
205   ASSERT(myBaseImpl);
206   return this->GetImpl()->GetKeepFiles();
207 }
208
209 //=======================================================================
210 //function : SetVerboseLevel
211 //=======================================================================
212
213 void GHS3DPlugin_Hypothesis_i::SetVerboseLevel(CORBA::Short level)
214   throw ( SALOME::SALOME_Exception )
215 {
216   if (level < 0 || level > 10 )
217     THROW_SALOME_CORBA_EXCEPTION( "Invalid verbose level, valid range is [0-10]",
218                                   SALOME::BAD_PARAM );
219   ASSERT(myBaseImpl);
220   this->GetImpl()->SetVerboseLevel(level);
221   SMESH::TPythonDump() << _this() << ".SetVerboseLevel( " << level << " )";
222 }
223
224 //=======================================================================
225 //function : GetVerboseLevel
226 //=======================================================================
227
228 CORBA::Short GHS3DPlugin_Hypothesis_i::GetVerboseLevel()
229 {
230   ASSERT(myBaseImpl);
231   return this->GetImpl()->GetVerboseLevel();
232 }
233
234 //=======================================================================
235 //function : SetToCreateNewNodes
236 //=======================================================================
237
238 void GHS3DPlugin_Hypothesis_i::SetToCreateNewNodes(CORBA::Boolean toCreate)
239 {
240   ASSERT(myBaseImpl);
241   this->GetImpl()->SetToCreateNewNodes(toCreate);
242   SMESH::TPythonDump() << _this() << ".SetToCreateNewNodes( " << toCreate << " )";
243 }
244
245 //=======================================================================
246 //function : GetToCreateNewNodes
247 //=======================================================================
248
249 CORBA::Boolean GHS3DPlugin_Hypothesis_i::GetToCreateNewNodes()
250 {
251   ASSERT(myBaseImpl);
252   return this->GetImpl()->GetToCreateNewNodes();
253 }
254
255 //=======================================================================
256 //function : SetToUseBoundaryRecoveryVersion
257 //=======================================================================
258
259 void GHS3DPlugin_Hypothesis_i::SetToUseBoundaryRecoveryVersion(CORBA::Boolean toUse)
260 {
261   ASSERT(myBaseImpl);
262   this->GetImpl()->SetToUseBoundaryRecoveryVersion(toUse);
263   SMESH::TPythonDump() << _this() << ".SetToUseBoundaryRecoveryVersion( " << toUse << " )";
264 }
265
266 //=======================================================================
267 //function : GetToUseBoundaryRecoveryVersion
268 //=======================================================================
269
270 CORBA::Boolean GHS3DPlugin_Hypothesis_i::GetToUseBoundaryRecoveryVersion()
271 {
272   ASSERT(myBaseImpl);
273   return this->GetImpl()->GetToUseBoundaryRecoveryVersion();
274 }
275
276 //=======================================================================
277 //function : SetFEMCorrection
278 //=======================================================================
279
280 void GHS3DPlugin_Hypothesis_i::SetFEMCorrection(CORBA::Boolean toUseFem)
281 {
282   ASSERT(myBaseImpl);
283   this->GetImpl()->SetFEMCorrection(toUseFem);
284   SMESH::TPythonDump() << _this() << ".SetFEMCorrection( " << toUseFem << " )";
285 }
286
287 //=======================================================================
288 //function : GetFEMCorrection
289 //=======================================================================
290
291 CORBA::Boolean GHS3DPlugin_Hypothesis_i::GetFEMCorrection()
292 {
293   ASSERT(myBaseImpl);
294   return this->GetImpl()->GetFEMCorrection();
295 }
296
297 //=======================================================================
298 //function : SetToRemoveCentralPoint
299 //=======================================================================
300
301 void GHS3DPlugin_Hypothesis_i::SetToRemoveCentralPoint(CORBA::Boolean toRemove)
302 {
303   ASSERT(myBaseImpl);
304   this->GetImpl()->SetToRemoveCentralPoint(toRemove);
305   SMESH::TPythonDump() << _this() << ".SetToRemoveCentralPoint( " << toRemove << " )";
306 }
307
308 //=======================================================================
309 //function : GetToRemoveCentralPoint
310 //=======================================================================
311
312 CORBA::Boolean GHS3DPlugin_Hypothesis_i::GetToRemoveCentralPoint()
313 {
314   ASSERT(myBaseImpl);
315   return this->GetImpl()->GetToRemoveCentralPoint();
316 }
317
318 //=======================================================================
319 //function : SetTextOption
320 //=======================================================================
321
322 void GHS3DPlugin_Hypothesis_i::SetTextOption(const char* option)
323 {
324   ASSERT(myBaseImpl);
325   this->GetImpl()->SetTextOption(option);
326   SMESH::TPythonDump() << _this() << ".SetTextOption( '" << option << "' )";
327 }
328
329 //=======================================================================
330 //function : GetTextOption
331 //=======================================================================
332
333 char* GHS3DPlugin_Hypothesis_i::GetTextOption()
334 {
335   ASSERT(myBaseImpl);
336   return CORBA::string_dup( this->GetImpl()->GetTextOption().c_str() );
337 }
338
339 //=======================================================================
340 //function : SetEnforcedVertex
341 //=======================================================================
342
343 void GHS3DPlugin_Hypothesis_i::SetEnforcedVertex(CORBA::Double x, CORBA::Double y, CORBA::Double z, CORBA::Double size)
344 {
345   ASSERT(myBaseImpl);
346   this->GetImpl()->SetEnforcedVertex(x,y,z,size);
347   SMESH::TPythonDump() << _this() << ".SetEnforcedVertex( " << x << ", " << y << ", " << z << ", " << size  << " )";
348 }
349
350 //=======================================================================
351 //function : GetEnforcedVertex
352 //=======================================================================
353
354 CORBA::Double GHS3DPlugin_Hypothesis_i::GetEnforcedVertex(CORBA::Double x, CORBA::Double y, CORBA::Double z)
355   throw (SALOME::SALOME_Exception)
356 {
357   ASSERT(myBaseImpl);
358   try {
359     return this->GetImpl()->GetEnforcedVertex(x,y,z);
360   }
361   catch (const std::invalid_argument& ex) {
362     SALOME::ExceptionStruct ExDescription;
363     ExDescription.text = ex.what();
364     ExDescription.type = SALOME::BAD_PARAM;
365     ExDescription.sourceFile = "GHS3DPlugin_Hypothesis::GetEnforcedVertex(x,y,z)";
366     ExDescription.lineNumber = 0;
367     throw SALOME::SALOME_Exception(ExDescription);
368   }
369   catch (SALOME_Exception& ex) {
370     THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM );
371   }
372   return 0;
373 }
374
375 //=======================================================================
376 //function : GetEnforcedVertices
377 //=======================================================================
378
379 GHS3DPlugin::GHS3DEnforcedVertexList* GHS3DPlugin_Hypothesis_i::GetEnforcedVertices()
380 {
381   ASSERT(myBaseImpl);
382   GHS3DPlugin::GHS3DEnforcedVertexList_var result = new GHS3DPlugin::GHS3DEnforcedVertexList();
383
384   const ::GHS3DPlugin_Hypothesis::TEnforcedVertexValues sizeMaps = this->GetImpl()->_GetEnforcedVertices();
385   int size = sizeMaps.size();
386   result->length( size );
387
388   ::GHS3DPlugin_Hypothesis::TEnforcedVertexValues::const_iterator it;
389   int i = 0;
390   for (it = sizeMaps.begin() ; it != sizeMaps.end(); it++ ) {
391     GHS3DPlugin::GHS3DEnforcedVertex_var myVertex = new GHS3DPlugin::GHS3DEnforcedVertex();
392     myVertex->x = it->first[0];
393     myVertex->y = it->first[1];
394     myVertex->z = it->first[2];
395     myVertex->size = it->second;
396     result[i]=myVertex;
397     i++;
398     }
399
400   return result._retn();
401 }
402
403 //=======================================================================
404 //function : RemoveEnforcedVertex
405 //=======================================================================
406
407 void GHS3DPlugin_Hypothesis_i::RemoveEnforcedVertex(CORBA::Double x, CORBA::Double y, CORBA::Double z)
408   throw (SALOME::SALOME_Exception)
409 {
410   ASSERT(myBaseImpl);
411   try {
412     this->GetImpl()->RemoveEnforcedVertex(x,y,z);
413     SMESH::TPythonDump() << _this() << ".RemoveEnforcedVertex( " << x << ", " << y << ", " << z << " )";
414   }
415   catch (const std::invalid_argument& ex) {
416     SALOME::ExceptionStruct ExDescription;
417     ExDescription.text = ex.what();
418     ExDescription.type = SALOME::BAD_PARAM;
419     ExDescription.sourceFile = "GHS3DPlugin_Hypothesis::RemoveEnforcedVertex(x,y,z)";
420     ExDescription.lineNumber = 0;
421     throw SALOME::SALOME_Exception(ExDescription);
422   }
423   catch (SALOME_Exception& ex) {
424     THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM );
425   }
426 }
427
428 //=======================================================================
429 //function : ClearEnforcedVertices
430 //=======================================================================
431
432 void GHS3DPlugin_Hypothesis_i::ClearEnforcedVertices()
433 {
434   ASSERT(myBaseImpl);
435   this->GetImpl()->ClearEnforcedVertices();
436 }
437
438 //=============================================================================
439 /*!
440  *  Get implementation
441  */
442 //=============================================================================
443
444 ::GHS3DPlugin_Hypothesis* GHS3DPlugin_Hypothesis_i::GetImpl()
445 {
446   return (::GHS3DPlugin_Hypothesis*)myBaseImpl;
447 }
448
449 //================================================================================
450 /*!
451  * \brief Verify whether hypothesis supports given entity type 
452  */
453 //================================================================================  
454
455 CORBA::Boolean GHS3DPlugin_Hypothesis_i::IsDimSupported( SMESH::Dimension type )
456 {
457   return type == SMESH::DIM_3D;
458 }
459