Salome HOME
e1b99a50edd28ca61f3c98eec7266b12d7d7353e
[plugins/hexoticplugin.git] / src / HexoticPlugin / HexoticPlugin_Hypothesis_i.cxx
1 // Copyright (C) 2007-2014  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 // ---
21 // File   : HexoticPlugin_Hypothesis_i.cxx
22 // Author : Lioka RAZAFINDRAZAKA (CEA)
23 // ---
24 //
25 #include "HexoticPlugin_Hypothesis_i.hxx"
26 #include "SMESH_Mesh_i.hxx"
27 #include "SMESH_Gen.hxx"
28 #include "SMESH_PythonDump.hxx"
29
30 #include "Utils_CorbaException.hxx"
31 #include "utilities.h"
32
33 //=============================================================================
34 /*!
35  *  HexoticPlugin_Hypothesis_i::HexoticPlugin_Hypothesis_i
36  *
37  *  Constructor
38  */
39 //=============================================================================
40 HexoticPlugin_Hypothesis_i::
41 HexoticPlugin_Hypothesis_i (PortableServer::POA_ptr thePOA,
42                            int                     theStudyId,
43                            ::SMESH_Gen*            theGenImpl)
44   : SALOME::GenericObj_i( thePOA ), 
45     SMESH_Hypothesis_i( thePOA )
46 {
47   MESSAGE( "HexoticPlugin_Hypothesis_i::HexoticPlugin_Hypothesis_i" );
48   myBaseImpl = new ::HexoticPlugin_Hypothesis (theGenImpl->GetANewId(),
49                                               theStudyId,
50                                               theGenImpl);
51 }
52
53 //=============================================================================
54 /*!
55  *  HexoticPlugin_Hypothesis_i::~HexoticPlugin_Hypothesis_i
56  *
57  *  Destructor
58  */
59 //=============================================================================
60 HexoticPlugin_Hypothesis_i::~HexoticPlugin_Hypothesis_i()
61 {
62   MESSAGE( "HexoticPlugin_Hypothesis_i::~HexoticPlugin_Hypothesis_i" );
63 }
64
65 //=============================================================================
66 /*!
67  *  HexoticPlugin_Hypothesis_i::SetHexesMinLevel
68  *  HexoticPlugin_Hypothesis_i::SetHexesMaxLevel
69  *  HexoticPlugin_Hypothesis_i::SetMinSize
70  *  HexoticPlugin_Hypothesis_i::SetMaxSize
71  *  HexoticPlugin_Hypothesis_i::SetHexoticIgnoreRidges
72  *  HexoticPlugin_Hypothesis_i::SetHexoticInvalidElements
73  *  HexoticPlugin_Hypothesis_i::SetHexoticSharpAngleThreshold
74  *  HexoticPlugin_Hypothesis_i::SetHexoticNbProc 
75  *  HexoticPlugin_Hypothesis_i::SetHexoticWorkingDirectory 
76  *  HexoticPlugin_Hypothesis_i::SetHexoticSdMode
77  *  HexoticPlugin_Hypothesis_i::SetVerbosity
78  *  HexoticPlugin_Hypothesis_i::SetHexoticMaxMemory
79  */
80 //=============================================================================
81
82 void HexoticPlugin_Hypothesis_i::SetHexesMinLevel (CORBA::Long theValue)
83 {
84   // MESSAGE("HexoticPlugin_Hypothesis_i::SetHexesMinLevel");
85   ASSERT(myBaseImpl);
86   CORBA::Long oldValue = GetHexesMinLevel();
87   this->GetImpl()->SetHexesMinLevel(theValue);
88   if (theValue != oldValue)
89     SMESH::TPythonDump() << _this() << ".SetHexesMinLevel( " << theValue << " )";
90 }
91
92 void HexoticPlugin_Hypothesis_i::SetHexesMaxLevel (CORBA::Long theValue)
93 {
94   // MESSAGE("HexoticPlugin_Hypothesis_i::SetHexesMaxLevel");
95   ASSERT(myBaseImpl);
96   CORBA::Long oldValue = GetHexesMaxLevel();
97   this->GetImpl()->SetHexesMaxLevel(theValue);
98   if (theValue != oldValue)
99     SMESH::TPythonDump() << _this() << ".SetHexesMaxLevel( " << theValue << " )";
100 }
101
102 void HexoticPlugin_Hypothesis_i::SetMinSize (CORBA::Double theValue)
103 {
104   // MESSAGE("HexoticPlugin_Hypothesis_i::SetHexesMaxLevel");
105   ASSERT(myBaseImpl);
106   CORBA::Double oldValue = GetMinSize();
107   this->GetImpl()->SetMinSize(theValue);
108   if (theValue != oldValue)
109     SMESH::TPythonDump() << _this() << ".SetMinSize( " << theValue << " )";
110 }
111
112 void HexoticPlugin_Hypothesis_i::SetMaxSize (CORBA::Double theValue)
113 {
114   // MESSAGE("HexoticPlugin_Hypothesis_i::SetHexesMaxLevel");
115   ASSERT(myBaseImpl);
116   CORBA::Double oldValue = GetMaxSize();
117   this->GetImpl()->SetMaxSize(theValue);
118   if (theValue != oldValue)
119     SMESH::TPythonDump() << _this() << ".SetMaxSize( " << theValue << " )";
120 }
121
122 void HexoticPlugin_Hypothesis_i::SetHexoticIgnoreRidges (CORBA::Boolean theValue)
123 {
124   // MESSAGE("HexoticPlugin_Hypothesis_i::SetHexoticIgnoreRidges");
125   ASSERT(myBaseImpl);
126   CORBA::Boolean oldValue = GetHexoticIgnoreRidges();
127   this->GetImpl()->SetHexoticIgnoreRidges(theValue);
128   if (theValue != oldValue)
129     SMESH::TPythonDump() << _this() << ".SetHexoticIgnoreRidges( " << theValue << " )";
130 }
131
132 void HexoticPlugin_Hypothesis_i::SetHexoticInvalidElements (CORBA::Boolean theValue)
133 {
134   // MESSAGE("HexoticPlugin_Hypothesis_i::SetHexoticInvalidElements");
135   ASSERT(myBaseImpl);
136   CORBA::Boolean oldValue = GetHexoticInvalidElements();
137   this->GetImpl()->SetHexoticInvalidElements(theValue);
138   if (theValue != oldValue)
139     SMESH::TPythonDump() << _this() << ".SetHexoticInvalidElements( " << theValue << " )";
140 }
141
142 void HexoticPlugin_Hypothesis_i::SetHexoticSharpAngleThreshold (CORBA::Double theValue)
143 {
144   // MESSAGE("HexoticPlugin_Hypothesis_i::SetHexoticSharpAngleThreshold");
145   ASSERT(myBaseImpl);
146   CORBA::Double oldValue = GetHexoticSharpAngleThreshold();
147   this->GetImpl()->SetHexoticSharpAngleThreshold(theValue);
148   if (theValue != oldValue)
149     SMESH::TPythonDump() << _this() << ".SetHexoticSharpAngleThreshold( " << theValue << " )";
150 }
151
152 void HexoticPlugin_Hypothesis_i::SetHexoticNbProc (CORBA::Long theValue)
153 {
154   // MESSAGE("HexoticPlugin_Hypothesis_i::SetHexoticNbProc");
155   ASSERT(myBaseImpl);
156   CORBA::Long oldValue = GetHexoticNbProc();
157   this->GetImpl()->SetHexoticNbProc(theValue);
158   if (theValue != oldValue)
159     SMESH::TPythonDump() << _this() << ".SetHexoticNbProc( " << theValue << " )";
160 }
161
162 void HexoticPlugin_Hypothesis_i::SetHexoticWorkingDirectory(const char* path) throw ( SALOME::SALOME_Exception )
163 {
164   if (!path )
165     THROW_SALOME_CORBA_EXCEPTION( "Null working directory",SALOME::BAD_PARAM );
166
167   ASSERT(myBaseImpl);
168   string file(path);
169   string oldValue(GetHexoticWorkingDirectory());
170   bool doDump = false;
171   if (oldValue != file)
172     doDump = true;
173
174   const char lastChar = *file.rbegin();
175 #ifdef WIN32
176   if ( lastChar != '\\' ) file += '\\';
177 #else
178   if ( lastChar != '/' ) file += '/';
179 #endif
180   file += "Hexotic_In.mesh";
181   SMESH_Mesh_i::PrepareForWriting (file.c_str());
182
183   this->GetImpl()->SetHexoticWorkingDirectory(path);
184   if (doDump)
185     SMESH::TPythonDump() << _this() << ".SetHexoticWorkingDirectory( '" << path << "' )";
186 }
187
188 void HexoticPlugin_Hypothesis_i::SetHexoticSdMode (CORBA::Long theValue)
189 {
190   // MESSAGE("HexoticPlugin_Hypothesis_i::SetHexoticSdMode");
191   ASSERT(myBaseImpl);
192   CORBA::Long oldValue = GetHexoticSdMode();
193   this->GetImpl()->SetHexoticSdMode(theValue);
194   if (theValue != oldValue)
195     SMESH::TPythonDump() << _this() << ".SetHexoticSdMode( " << theValue << " )";
196 }
197
198 void HexoticPlugin_Hypothesis_i::SetHexoticVerbosity (CORBA::Long theValue)
199 {
200   // MESSAGE("HexoticPlugin_Hypothesis_i::SetVerbosity");
201   ASSERT(myBaseImpl);
202   CORBA::Long oldValue = GetHexoticVerbosity();
203   this->GetImpl()->SetHexoticVerbosity(theValue);
204   if (theValue != oldValue)
205     SMESH::TPythonDump() << _this() << ".SetHexoticVerbosity( " << theValue << " )";
206 }
207
208 void HexoticPlugin_Hypothesis_i::SetHexoticMaxMemory (CORBA::Long theValue)
209 {
210   // MESSAGE("HexoticPlugin_Hypothesis_i::SetHexoticMaxMemory");
211   ASSERT(myBaseImpl);
212   CORBA::Long oldValue = GetHexoticMaxMemory();
213   this->GetImpl()->SetHexoticMaxMemory(theValue);
214   if (theValue != oldValue)
215     SMESH::TPythonDump() << _this() << ".SetHexoticMaxMemory( " << theValue << " )";
216 }
217
218 HexoticPlugin::HexoticPluginSizeMapsList* HexoticPlugin_Hypothesis_i::GetSizeMaps ()
219 {
220   // Get the std::map < string entry, double size >
221   HexoticPlugin::HexoticPluginSizeMapsList_var result = new HexoticPlugin::HexoticPluginSizeMapsList();
222   const ::HexoticPlugin_Hypothesis::THexoticSizeMaps sizeMaps = this->GetImpl()->GetSizeMaps();
223   result->length( sizeMaps.size() );
224   
225   // Write the content into a CORBA sequence of struct{ entry=anEntry; size=aSize; }
226   ::HexoticPlugin_Hypothesis::THexoticSizeMaps::const_iterator it = sizeMaps.begin(); 
227   for ( int i = 0; it != sizeMaps.end(); i++, it++ )
228   {
229     HexoticPlugin::HexoticPluginSizeMap_var aSizeMap = new HexoticPlugin::HexoticPluginSizeMap();
230     aSizeMap->entry = CORBA::string_dup( it->first.c_str() );
231     aSizeMap->size = it->second;
232     result[i] = aSizeMap;
233   }
234   return result._retn();
235 }
236
237 void HexoticPlugin_Hypothesis_i::SetSizeMapEntry ( const char* theEntry, CORBA::Double theSize )
238 {
239 //   MESSAGE("HexoticPlugin_Hypothesis_i::SetSizeMapEntry");
240   bool valueChanged = this->GetImpl()->AddSizeMap(theEntry, theSize);
241   if (valueChanged)
242     SMESH::TPythonDump() << _this() << ".SetSizeMap( "<< theEntry << ", " << theSize << " )";
243 }
244
245 void HexoticPlugin_Hypothesis_i::UnsetSizeMapEntry ( const char* theEntry )
246 {
247 //   MESSAGE("HexoticPlugin_Hypothesis_i::UnsetSizeMapEntry");
248   bool entryRemoved = this->GetImpl()->UnsetSizeMap(theEntry);
249   if (entryRemoved)
250     SMESH::TPythonDump() << _this() << ".UnsetSizeMap( "<< theEntry << " )";
251 }
252
253 void HexoticPlugin_Hypothesis_i::SetSizeMap (const GEOM::GEOM_Object_ptr theGeomObj, const double theSize)
254 {
255 //   MESSAGE("HexoticPlugin_Hypothesis_i::SetSizeMap");
256   ASSERT(myBaseImpl);
257   std::string entry = theGeomObj->GetStudyEntry();
258   SetSizeMapEntry( entry.c_str(), theSize);
259 }
260
261 void HexoticPlugin_Hypothesis_i::UnsetSizeMap (const GEOM::GEOM_Object_ptr theGeomObj)
262 {
263 //   MESSAGE("HexoticPlugin_Hypothesis_i::UnsetSizeMap");
264   ASSERT(myBaseImpl);
265   std::string entry = theGeomObj->GetStudyEntry();
266   UnsetSizeMapEntry( entry.c_str());
267 }
268
269 //=============================================================================
270 /*!
271  *  HexoticPlugin_Hypothesis_i::GetHexesMinLevel
272  *  HexoticPlugin_Hypothesis_i::GetHexesMaxLevel
273  *  HexoticPlugin_Hypothesis_i::GetMinSize
274  *  HexoticPlugin_Hypothesis_i::GetMaxSize
275  *  HexoticPlugin_Hypothesis_i::GetHexoticIgnoreRidges
276  *  HexoticPlugin_Hypothesis_i::GetHexoticInvalidElements
277  *  HexoticPlugin_Hypothesis_i::GetHexoticSharpAngleThreshold 
278  *  HexoticPlugin_Hypothesis_i::GetHexoticNbProc 
279  *  HexoticPlugin_Hypothesis_i::GetHexoticWorkingDirectory 
280  *  HexoticPlugin_Hypothesis_i::GetHexoticSdMode
281  *  HexoticPlugin_Hypothesis_i::GetVerbosity
282  *  HexoticPlugin_Hypothesis_i::GetHexoticMaxMemory
283  */
284 //=============================================================================
285
286 CORBA::Long HexoticPlugin_Hypothesis_i::GetHexesMinLevel()
287 {
288   // MESSAGE("HexoticPlugin_Hypothesis_i::GetHexesMinLevel");
289   ASSERT(myBaseImpl);
290   return this->GetImpl()->GetHexesMinLevel();
291 }
292
293 CORBA::Long HexoticPlugin_Hypothesis_i::GetHexesMaxLevel()
294 {
295   // MESSAGE("HexoticPlugin_Hypothesis_i::GetHexesMaxLevel");
296   ASSERT(myBaseImpl);
297   return this->GetImpl()->GetHexesMaxLevel();
298 }
299
300 CORBA::Double HexoticPlugin_Hypothesis_i::GetMinSize()
301 {
302   // MESSAGE("HexoticPlugin_Hypothesis_i::GetMinSize");
303   ASSERT(myBaseImpl);
304   return this->GetImpl()->GetMinSize();
305 }
306
307 CORBA::Double HexoticPlugin_Hypothesis_i::GetMaxSize()
308 {
309   // MESSAGE("HexoticPlugin_Hypothesis_i::GetMaxSize");
310   ASSERT(myBaseImpl);
311   return this->GetImpl()->GetMaxSize();
312 }
313
314 CORBA::Boolean HexoticPlugin_Hypothesis_i::GetHexoticIgnoreRidges()
315 {
316   // MESSAGE("HexoticPlugin_Hypothesis_i::GetHexoticIgnoreRidges");
317   ASSERT(myBaseImpl);
318   return this->GetImpl()->GetHexoticIgnoreRidges();
319 }
320
321 CORBA::Boolean HexoticPlugin_Hypothesis_i::GetHexoticInvalidElements()
322 {
323   // MESSAGE("HexoticPlugin_Hypothesis_i::GetHexoticInvalidElements");
324   ASSERT(myBaseImpl);
325   return this->GetImpl()->GetHexoticInvalidElements();
326 }
327
328 CORBA::Double HexoticPlugin_Hypothesis_i::GetHexoticSharpAngleThreshold()
329 {
330   // MESSAGE("HexoticPlugin_Hypothesis_i::GetHexoticSharpAngleThreshold");
331   ASSERT(myBaseImpl);
332   return this->GetImpl()->GetHexoticSharpAngleThreshold();
333 }
334
335 CORBA::Long HexoticPlugin_Hypothesis_i::GetHexoticNbProc()
336 {
337   // MESSAGE("HexoticPlugin_Hypothesis_i::GetHexoticNbProc");
338   ASSERT(myBaseImpl);
339   return this->GetImpl()->GetHexoticNbProc();
340 }
341
342 char* HexoticPlugin_Hypothesis_i::GetHexoticWorkingDirectory()
343 {
344   ASSERT(myBaseImpl);
345   return CORBA::string_dup( this->GetImpl()->GetHexoticWorkingDirectory().c_str() );
346 }
347
348 CORBA::Long HexoticPlugin_Hypothesis_i::GetHexoticSdMode ()
349 {
350   // MESSAGE("HexoticPlugin_Hypothesis_i::GetHexoticSdMode");
351   ASSERT(myBaseImpl);
352   return this->GetImpl()->GetHexoticSdMode();
353 }
354
355 CORBA::Long HexoticPlugin_Hypothesis_i::GetHexoticVerbosity()
356 {
357   // MESSAGE("HexoticPlugin_Hypothesis_i::GetVerbosity");
358   ASSERT(myBaseImpl);
359   return this->GetImpl()->GetHexoticVerbosity();
360 }
361
362 CORBA::Long HexoticPlugin_Hypothesis_i::GetHexoticMaxMemory()
363 {
364   // MESSAGE("HexoticPlugin_Hypothesis_i::GetHexoticMaxMemory");
365   ASSERT(myBaseImpl);
366   return this->GetImpl()->GetHexoticMaxMemory();
367 }
368
369 //=============================================================================
370 /*!
371  *  HexoticPlugin_Hypothesis_i::GetImpl
372  *
373  *  Get implementation
374  */
375 //=============================================================================
376 ::HexoticPlugin_Hypothesis* HexoticPlugin_Hypothesis_i::GetImpl()
377 {
378   // MESSAGE("HexoticPlugin_Hypothesis_i::GetImpl");
379   return (::HexoticPlugin_Hypothesis*)myBaseImpl;
380 }
381
382 //================================================================================
383 /*!
384  * \brief Verify whether hypothesis supports given entity type 
385   * \param type - dimension (see SMESH::Dimension enumeration)
386   * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
387  * 
388  * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
389  */
390 //================================================================================  
391 CORBA::Boolean HexoticPlugin_Hypothesis_i::IsDimSupported( SMESH::Dimension type )
392 {
393   return type == SMESH::DIM_3D;
394 }