1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include <Standard_Stream.hxx>
26 #include "GEOM_IHealingOperations_i.hh"
27 #include "GEOM_Engine.hxx"
28 #include "GEOM_Object.hxx"
30 #include "utilities.h"
32 #include "Utils_ExceptHandlers.hxx"
34 #include <TColStd_HSequenceOfTransient.hxx>
36 //=============================================================================
40 //=============================================================================
42 GEOM_IHealingOperations_i::GEOM_IHealingOperations_i (PortableServer::POA_ptr thePOA,
43 GEOM::GEOM_Gen_ptr theEngine,
44 ::GEOMImpl_IHealingOperations* theImpl)
45 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
47 MESSAGE("GEOM_IHealingOperations_i::GEOM_IHealingOperations_i");
50 //=============================================================================
54 //=============================================================================
56 GEOM_IHealingOperations_i::~GEOM_IHealingOperations_i()
58 MESSAGE("GEOM_IHealingOperations_i::~GEOM_IHealingOperations_i");
61 //=============================================================================
65 //=============================================================================
66 Handle(TColStd_HArray1OfInteger) GEOM_IHealingOperations_i::Convert
67 (const GEOM::short_array& theInArray)
69 Handle(TColStd_HArray1OfInteger) anOutArray;
70 int n = theInArray.length();
73 anOutArray = new TColStd_HArray1OfInteger( 1, n );
74 for (int i = 0; i < n; i++)
75 anOutArray->SetValue( i+1, theInArray[i] );
79 //=============================================================================
83 //=============================================================================
84 Handle(TColStd_HArray1OfExtendedString) GEOM_IHealingOperations_i::Convert
85 (const GEOM::string_array& theInArray)
87 Handle(TColStd_HArray1OfExtendedString) anOutArray;
88 int n = theInArray.length();
91 anOutArray = new TColStd_HArray1OfExtendedString( 1, n );
93 for ( int i = 0; i < n; i++ )
95 str = CORBA::string_dup( theInArray[i] );
96 anOutArray->SetValue( i+1, TCollection_ExtendedString( str ) );
101 //=============================================================================
105 //=============================================================================
106 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::ProcessShape (GEOM::GEOM_Object_ptr theObject,
107 const GEOM::string_array& theOperations,
108 const GEOM::string_array& theParams,
109 const GEOM::string_array& theValues)
111 GEOM::GEOM_Object_var aGEOMObject;
113 // Set a not done flag
114 GetOperations()->SetNotDone();
116 // Check if theOperations has more than 0 elements and theParams and theValues have the same length
117 //if (theOperations.length() <= 0 || theParams.length() != theValues.length())
118 // return aGEOMObject._retn();
120 // Get the object itself
121 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
122 if (anObject.IsNull())
123 return aGEOMObject._retn();
126 Handle(GEOM_Object) aNewObject = GetOperations()->ShapeProcess( anObject,
127 Convert( theOperations ), Convert( theParams ), Convert( theValues ) );
128 if ( !GetOperations()->IsDone() || aNewObject.IsNull() )
129 return aGEOMObject._retn();
131 return GetObject( aNewObject );
134 //=============================================================================
136 * GetShapeProcessParameters
138 //=============================================================================
139 void GEOM_IHealingOperations_i::GetShapeProcessParameters(GEOM::string_array_out theOperations,
140 GEOM::string_array_out theParams,
141 GEOM::string_array_out theValues)
143 GEOM::string_array_var anOpArray = new GEOM::string_array();
144 GEOM::string_array_var aParArray = new GEOM::string_array();
145 GEOM::string_array_var aValArray = new GEOM::string_array();
147 // retrieve the values as stl-lists
148 std::list<std::string> operationsList, paramsList, valuesList;
149 GetOperations()->GetShapeProcessParameters( operationsList, paramsList, valuesList );
150 const int opSize = operationsList.size(),
151 parSize = paramsList.size(),
152 valSize = valuesList.size();
154 if ( opSize >= 0 && parSize >= 0 && parSize == valSize ) {
155 // allocate the CORBA arrays, sizes == returned lists' sizes
156 anOpArray->length(opSize);
157 aParArray->length(parSize);
158 aValArray->length(valSize);
160 // fill the local CORBA arrays with values from lists
161 std::list<std::string>::iterator opIt, parIt, valIt;
163 for ( opIt = operationsList.begin(); opIt != operationsList.end(); i++,++opIt )
164 anOpArray[i] = CORBA::string_dup( (*opIt).c_str() );
166 for ( i = 0, parIt = paramsList.begin(), valIt = valuesList.begin();
167 parIt != paramsList.end(); i++, ++parIt,++valIt ) {
168 aParArray[i] = CORBA::string_dup( (*parIt).c_str() );
169 aValArray[i] = CORBA::string_dup( (*valIt).c_str() );
173 // initialize out-parameters with local arrays
174 theOperations = anOpArray._retn();
175 theParams = aParArray._retn();
176 theValues = aValArray._retn();
179 //=============================================================================
181 * GetOperatorParameters
183 //=============================================================================
184 void GEOM_IHealingOperations_i::GetOperatorParameters (const char* theOperator,
185 GEOM::string_array_out theParams,
186 GEOM::string_array_out theValues)
188 GEOM::string_array_var aParArray = new GEOM::string_array();
189 GEOM::string_array_var aValArray = new GEOM::string_array();
191 // retrieve the values as stl-lists
192 std::list<std::string> paramsList, valuesList;
193 if ( GetOperations()->GetOperatorParameters( theOperator, paramsList, valuesList ) ) {
194 const int parSize = paramsList.size(), valSize = valuesList.size();
196 if ( parSize == valSize ) {
197 aParArray->length(parSize);
198 aValArray->length(valSize);
200 // fill the local CORBA arrays with values from lists
201 std::list<std::string>::iterator parIt, valIt;
203 for ( i = 0, parIt = paramsList.begin(), valIt = valuesList.begin();
204 parIt != paramsList.end(); i++, ++parIt,++valIt ) {
205 aParArray[i] = CORBA::string_dup( (*parIt).c_str() );
206 aValArray[i] = CORBA::string_dup( (*valIt).c_str() );
211 // initialize out-parameters with local arrays
212 theParams = aParArray._retn();
213 theValues = aValArray._retn();
216 //=============================================================================
220 //=============================================================================
221 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::SuppressFaces (GEOM::GEOM_Object_ptr theObject,
222 const GEOM::short_array& theFaces)
224 GEOM::GEOM_Object_var aGEOMObject;
226 // Set a not done flag
227 GetOperations()->SetNotDone();
229 // Get the object itself
230 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
231 if (anObject.IsNull())
232 return aGEOMObject._retn();
234 // if theFaces is empty - it's OK, it means that ALL faces must be removed
237 Handle(GEOM_Object) aNewObject =
238 GetOperations()->SuppressFaces( anObject, Convert( theFaces ) );
239 if (!GetOperations()->IsDone() || aNewObject.IsNull())
240 return aGEOMObject._retn();
242 return GetObject( aNewObject );
245 //=============================================================================
249 //=============================================================================
250 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::CloseContour (GEOM::GEOM_Object_ptr theObject,
251 const GEOM::short_array& theWires,
252 CORBA::Boolean isCommonVertex)
254 GEOM::GEOM_Object_var aGEOMObject;
256 // Set a not done flag
257 GetOperations()->SetNotDone();
259 // Get the object itself
260 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
261 if (anObject.IsNull())
262 return aGEOMObject._retn();
265 Handle(GEOM_Object) aNewObject =
266 GetOperations()->CloseContour( anObject, Convert( theWires ), isCommonVertex );
267 if (!GetOperations()->IsDone() || aNewObject.IsNull())
268 return aGEOMObject._retn();
270 return GetObject(aNewObject);
273 //=============================================================================
277 //=============================================================================
278 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::RemoveIntWires (GEOM::GEOM_Object_ptr theObject,
279 const GEOM::short_array& theWires)
281 GEOM::GEOM_Object_var aGEOMObject;
283 // Set a not done flag
284 GetOperations()->SetNotDone();
286 // Get the object itself
287 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
288 if (anObject.IsNull())
289 return aGEOMObject._retn();
291 // if theWires is empty - it's OK, it means that ALL wires should be removed
294 Handle(GEOM_Object) aNewObject =
295 GetOperations()->RemoveIntWires( anObject, Convert( theWires ) );
296 if (!GetOperations()->IsDone() || aNewObject.IsNull())
297 return aGEOMObject._retn();
299 return GetObject(aNewObject);
302 //=============================================================================
306 //=============================================================================
307 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::FillHoles (GEOM::GEOM_Object_ptr theObject,
308 const GEOM::short_array& theWires)
310 GEOM::GEOM_Object_var aGEOMObject;
312 // Set a not done flag
313 GetOperations()->SetNotDone();
315 // Get the object itself
316 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
317 if (anObject.IsNull())
318 return aGEOMObject._retn();
320 // if theWires is empty - it's OK, it means that ALL wires should be removed
323 Handle(GEOM_Object) aNewObject =
324 GetOperations()->FillHoles( anObject, Convert( theWires ) );
325 if (!GetOperations()->IsDone() || aNewObject.IsNull())
326 return aGEOMObject._retn();
328 return GetObject(aNewObject);
331 //=============================================================================
335 //=============================================================================
336 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::Sew (GEOM::GEOM_Object_ptr theObject,
337 CORBA::Double theTolerance)
339 GEOM::GEOM_Object_var aGEOMObject;
341 // Set a not done flag
342 GetOperations()->SetNotDone();
345 if (theTolerance < 0)
346 return aGEOMObject._retn();
348 // Get the object itself
349 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
350 if (anObject.IsNull())
351 return aGEOMObject._retn();
354 Handle(GEOM_Object) aNewObject =
355 GetOperations()->Sew( anObject, theTolerance );
356 if (!GetOperations()->IsDone() || aNewObject.IsNull())
357 return aGEOMObject._retn();
359 return GetObject(aNewObject);
362 //=============================================================================
366 //=============================================================================
367 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::DivideEdge (GEOM::GEOM_Object_ptr theObject,
368 CORBA::Short theIndex,
369 CORBA::Double theValue,
370 CORBA::Boolean isByParameter)
372 GEOM::GEOM_Object_var aGEOMObject;
374 // Set a not done flag
375 GetOperations()->SetNotDone();
378 if (theValue < 0 || theValue > 1)
379 return aGEOMObject._retn();
381 // Get the object itself
382 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
383 if (anObject.IsNull())
384 return aGEOMObject._retn();
387 Handle(GEOM_Object) aNewObject =
388 GetOperations()->DivideEdge( anObject, theIndex, theValue, isByParameter );
389 if (!GetOperations()->IsDone() || aNewObject.IsNull())
390 return aGEOMObject._retn();
392 return GetObject(aNewObject);
395 //=============================================================================
399 //=============================================================================
400 CORBA::Boolean GEOM_IHealingOperations_i::GetFreeBoundary ( GEOM::GEOM_Object_ptr theObject,
401 GEOM::ListOfGO_out theClosedWires,
402 GEOM::ListOfGO_out theOpenWires )
404 theClosedWires = new GEOM::ListOfGO;
405 theOpenWires = new GEOM::ListOfGO;
407 // Set a not done flag
408 GetOperations()->SetNotDone();
410 // Get the object itself
411 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
412 if (anObject.IsNull())
415 Handle(TColStd_HSequenceOfTransient) aClosed = new TColStd_HSequenceOfTransient();
416 Handle(TColStd_HSequenceOfTransient) anOpen = new TColStd_HSequenceOfTransient();
417 bool res = GetOperations()->GetFreeBoundary( anObject, aClosed, anOpen );
419 if ( !GetOperations()->IsDone() || !res )
422 int i, n = aClosed->Length();
423 theClosedWires->length( n );
424 for ( i = 1; i <= n; i++ )
425 (*theClosedWires)[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aClosed->Value(i)));
427 n = anOpen->Length();
428 theOpenWires->length( n );
429 for ( i = 1, n = anOpen->Length(); i <= n; i++ )
430 (*theOpenWires)[i-1] = GetObject(Handle(GEOM_Object)::DownCast(anOpen->Value(i)));
436 //=============================================================================
440 //=============================================================================
441 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::ChangeOrientation (GEOM::GEOM_Object_ptr theObject)
443 GEOM::GEOM_Object_var aGEOMObject;
445 // Set a not done flag
446 GetOperations()->SetNotDone();
449 if ( CORBA::is_nil(theObject) )
450 return aGEOMObject._retn();
452 aGEOMObject = GEOM::GEOM_Object::_duplicate(theObject);
454 // Get the object itself
455 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
456 if (anObject.IsNull())
457 return aGEOMObject._retn();
460 // Handle(GEOM_Object) aNewObject =
461 GetOperations()->ChangeOrientation( anObject );
462 // if (!GetOperations()->IsDone() || aNewObject.IsNull())
463 // return aGEOMObject._retn();
465 //return GetObject(aNewObject);
466 return aGEOMObject._retn();
470 //=============================================================================
472 * ChangeOrientationCopy
474 //=============================================================================
475 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::ChangeOrientationCopy (GEOM::GEOM_Object_ptr theObject)
477 GEOM::GEOM_Object_var aGEOMObject;
479 // Set a not done flag
480 GetOperations()->SetNotDone();
482 // Get the object itself
483 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
484 if (anObject.IsNull())
485 return aGEOMObject._retn();
488 Handle(GEOM_Object) aNewObject =
489 GetOperations()->ChangeOrientationCopy( anObject );
490 if (!GetOperations()->IsDone() || aNewObject.IsNull())
491 return aGEOMObject._retn();
493 return GetObject(aNewObject);
496 //=============================================================================
500 //=============================================================================
501 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::LimitTolerance (GEOM::GEOM_Object_ptr theObject,
502 CORBA::Double theTolerance)
504 GEOM::GEOM_Object_var aGEOMObject;
506 // Set a not done flag
507 GetOperations()->SetNotDone();
509 // Get the object itself
510 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
511 if (anObject.IsNull())
512 return aGEOMObject._retn();
515 Handle(GEOM_Object) aNewObject =
516 GetOperations()->LimitTolerance(anObject, theTolerance);
517 if (!GetOperations()->IsDone() || aNewObject.IsNull())
518 return aGEOMObject._retn();
520 return GetObject(aNewObject);