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