1 // Copyright (C) 2007-2012 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
23 #include <Standard_Stream.hxx>
27 #include "GEOM_IHealingOperations_i.hh"
28 #include "GEOM_Engine.hxx"
29 #include "GEOM_Object.hxx"
31 #include "utilities.h"
33 #include "Utils_ExceptHandlers.hxx"
34 #include <Basics_Utils.hxx>
36 #include <TColStd_HSequenceOfTransient.hxx>
38 //=============================================================================
42 //=============================================================================
44 GEOM_IHealingOperations_i::GEOM_IHealingOperations_i (PortableServer::POA_ptr thePOA,
45 GEOM::GEOM_Gen_ptr theEngine,
46 ::GEOMImpl_IHealingOperations* theImpl)
47 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
49 MESSAGE("GEOM_IHealingOperations_i::GEOM_IHealingOperations_i");
52 //=============================================================================
56 //=============================================================================
58 GEOM_IHealingOperations_i::~GEOM_IHealingOperations_i()
60 MESSAGE("GEOM_IHealingOperations_i::~GEOM_IHealingOperations_i");
63 //=============================================================================
67 //=============================================================================
68 Handle(TColStd_HArray1OfInteger) GEOM_IHealingOperations_i::Convert
69 (const GEOM::short_array& theInArray)
71 Handle(TColStd_HArray1OfInteger) anOutArray;
72 int n = theInArray.length();
75 anOutArray = new TColStd_HArray1OfInteger( 1, n );
76 for (int i = 0; i < n; i++)
77 anOutArray->SetValue( i+1, theInArray[i] );
81 //=============================================================================
85 //=============================================================================
86 Handle(TColStd_HArray1OfExtendedString) GEOM_IHealingOperations_i::Convert
87 (const GEOM::string_array& theInArray)
89 Handle(TColStd_HArray1OfExtendedString) anOutArray;
90 int n = theInArray.length();
93 anOutArray = new TColStd_HArray1OfExtendedString( 1, n );
95 for ( int i = 0; i < n; i++ )
97 str = CORBA::string_dup( theInArray[i] );
98 anOutArray->SetValue( i+1, TCollection_ExtendedString( str ) );
103 //=============================================================================
107 //=============================================================================
108 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::ProcessShape (GEOM::GEOM_Object_ptr theObject,
109 const GEOM::string_array& theOperations,
110 const GEOM::string_array& theParams,
111 const GEOM::string_array& theValues)
113 Kernel_Utils::Localizer loc;
115 GEOM::GEOM_Object_var aGEOMObject;
117 // Set a not done flag
118 GetOperations()->SetNotDone();
120 // Check if theOperations has more than 0 elements and theParams and theValues have the same length
121 //if (theOperations.length() <= 0 || theParams.length() != theValues.length())
122 // return aGEOMObject._retn();
124 // Get the object itself
125 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
126 if (anObject.IsNull())
127 return aGEOMObject._retn();
130 Handle(GEOM_Object) aNewObject = GetOperations()->ShapeProcess( anObject,
131 Convert( theOperations ), Convert( theParams ), Convert( theValues ) );
132 if ( !GetOperations()->IsDone() || aNewObject.IsNull() )
133 return aGEOMObject._retn();
135 return GetObject( aNewObject );
138 //=============================================================================
140 * GetShapeProcessParameters
142 //=============================================================================
143 void GEOM_IHealingOperations_i::GetShapeProcessParameters(GEOM::string_array_out theOperations,
144 GEOM::string_array_out theParams,
145 GEOM::string_array_out theValues)
147 GEOM::string_array_var anOpArray = new GEOM::string_array();
148 GEOM::string_array_var aParArray = new GEOM::string_array();
149 GEOM::string_array_var aValArray = new GEOM::string_array();
151 // retrieve the values as stl-lists
152 std::list<std::string> operationsList, paramsList, valuesList;
153 GetOperations()->GetShapeProcessParameters( operationsList, paramsList, valuesList );
154 const int opSize = operationsList.size(),
155 parSize = paramsList.size(),
156 valSize = valuesList.size();
158 if ( opSize >= 0 && parSize >= 0 && parSize == valSize ) {
159 // allocate the CORBA arrays, sizes == returned lists' sizes
160 anOpArray->length(opSize);
161 aParArray->length(parSize);
162 aValArray->length(valSize);
164 // fill the local CORBA arrays with values from lists
165 std::list<std::string>::iterator opIt, parIt, valIt;
167 for ( opIt = operationsList.begin(); opIt != operationsList.end(); i++,++opIt )
168 anOpArray[i] = CORBA::string_dup( (*opIt).c_str() );
170 for ( i = 0, parIt = paramsList.begin(), valIt = valuesList.begin();
171 parIt != paramsList.end(); i++, ++parIt,++valIt ) {
172 aParArray[i] = CORBA::string_dup( (*parIt).c_str() );
173 aValArray[i] = CORBA::string_dup( (*valIt).c_str() );
177 // initialize out-parameters with local arrays
178 theOperations = anOpArray._retn();
179 theParams = aParArray._retn();
180 theValues = aValArray._retn();
183 //=============================================================================
185 * GetOperatorParameters
187 //=============================================================================
188 void GEOM_IHealingOperations_i::GetOperatorParameters (const char* theOperator,
189 GEOM::string_array_out theParams,
190 GEOM::string_array_out theValues)
192 GEOM::string_array_var aParArray = new GEOM::string_array();
193 GEOM::string_array_var aValArray = new GEOM::string_array();
195 // retrieve the values as stl-lists
196 std::list<std::string> paramsList, valuesList;
197 if ( GetOperations()->GetOperatorParameters( theOperator, paramsList, valuesList ) ) {
198 const int parSize = paramsList.size(), valSize = valuesList.size();
200 if ( parSize == valSize ) {
201 aParArray->length(parSize);
202 aValArray->length(valSize);
204 // fill the local CORBA arrays with values from lists
205 std::list<std::string>::iterator parIt, valIt;
207 for ( i = 0, parIt = paramsList.begin(), valIt = valuesList.begin();
208 parIt != paramsList.end(); i++, ++parIt,++valIt ) {
209 aParArray[i] = CORBA::string_dup( (*parIt).c_str() );
210 aValArray[i] = CORBA::string_dup( (*valIt).c_str() );
215 // initialize out-parameters with local arrays
216 theParams = aParArray._retn();
217 theValues = aValArray._retn();
220 //=============================================================================
224 //=============================================================================
225 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::SuppressFaces (GEOM::GEOM_Object_ptr theObject,
226 const GEOM::short_array& theFaces)
228 GEOM::GEOM_Object_var aGEOMObject;
230 // Set a not done flag
231 GetOperations()->SetNotDone();
233 // Get the object itself
234 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
235 if (anObject.IsNull())
236 return aGEOMObject._retn();
238 // if theFaces is empty - it's OK, it means that ALL faces must be removed
241 Handle(GEOM_Object) aNewObject =
242 GetOperations()->SuppressFaces( anObject, Convert( theFaces ) );
243 if (!GetOperations()->IsDone() || aNewObject.IsNull())
244 return aGEOMObject._retn();
246 return GetObject( aNewObject );
249 //=============================================================================
253 //=============================================================================
254 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::CloseContour (GEOM::GEOM_Object_ptr theObject,
255 const GEOM::short_array& theWires,
256 CORBA::Boolean isCommonVertex)
258 GEOM::GEOM_Object_var aGEOMObject;
260 // Set a not done flag
261 GetOperations()->SetNotDone();
263 // Get the object itself
264 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
265 if (anObject.IsNull())
266 return aGEOMObject._retn();
269 Handle(GEOM_Object) aNewObject =
270 GetOperations()->CloseContour( anObject, Convert( theWires ), isCommonVertex );
271 if (!GetOperations()->IsDone() || aNewObject.IsNull())
272 return aGEOMObject._retn();
274 return GetObject(aNewObject);
277 //=============================================================================
281 //=============================================================================
282 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::RemoveIntWires (GEOM::GEOM_Object_ptr theObject,
283 const GEOM::short_array& theWires)
285 GEOM::GEOM_Object_var aGEOMObject;
287 // Set a not done flag
288 GetOperations()->SetNotDone();
290 // Get the object itself
291 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
292 if (anObject.IsNull())
293 return aGEOMObject._retn();
295 // if theWires is empty - it's OK, it means that ALL wires should be removed
298 Handle(GEOM_Object) aNewObject =
299 GetOperations()->RemoveIntWires( anObject, Convert( theWires ) );
300 if (!GetOperations()->IsDone() || aNewObject.IsNull())
301 return aGEOMObject._retn();
303 return GetObject(aNewObject);
306 //=============================================================================
310 //=============================================================================
311 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::FillHoles (GEOM::GEOM_Object_ptr theObject,
312 const GEOM::short_array& theWires)
314 GEOM::GEOM_Object_var aGEOMObject;
316 // Set a not done flag
317 GetOperations()->SetNotDone();
319 // Get the object itself
320 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
321 if (anObject.IsNull())
322 return aGEOMObject._retn();
324 // if theWires is empty - it's OK, it means that ALL wires should be removed
327 Handle(GEOM_Object) aNewObject =
328 GetOperations()->FillHoles( anObject, Convert( theWires ) );
329 if (!GetOperations()->IsDone() || aNewObject.IsNull())
330 return aGEOMObject._retn();
332 return GetObject(aNewObject);
335 //=============================================================================
339 //=============================================================================
340 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::Sew (GEOM::GEOM_Object_ptr theObject,
341 CORBA::Double theTolerance)
343 GEOM::GEOM_Object_var aGEOMObject;
345 // Set a not done flag
346 GetOperations()->SetNotDone();
349 if (theTolerance < 0)
350 return aGEOMObject._retn();
352 // Get the object itself
353 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
354 if (anObject.IsNull())
355 return aGEOMObject._retn();
358 Handle(GEOM_Object) aNewObject =
359 GetOperations()->Sew( anObject, theTolerance );
360 if (!GetOperations()->IsDone() || aNewObject.IsNull())
361 return aGEOMObject._retn();
363 return GetObject(aNewObject);
366 //=============================================================================
370 //=============================================================================
371 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::DivideEdge (GEOM::GEOM_Object_ptr theObject,
372 CORBA::Short theIndex,
373 CORBA::Double theValue,
374 CORBA::Boolean isByParameter)
376 GEOM::GEOM_Object_var aGEOMObject;
378 // Set a not done flag
379 GetOperations()->SetNotDone();
382 if (theValue < 0 || theValue > 1)
383 return aGEOMObject._retn();
385 // Get the object itself
386 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
387 if (anObject.IsNull())
388 return aGEOMObject._retn();
391 Handle(GEOM_Object) aNewObject =
392 GetOperations()->DivideEdge( anObject, theIndex, theValue, isByParameter );
393 if (!GetOperations()->IsDone() || aNewObject.IsNull())
394 return aGEOMObject._retn();
396 return GetObject(aNewObject);
399 //=============================================================================
403 //=============================================================================
404 CORBA::Boolean GEOM_IHealingOperations_i::GetFreeBoundary ( GEOM::GEOM_Object_ptr theObject,
405 GEOM::ListOfGO_out theClosedWires,
406 GEOM::ListOfGO_out theOpenWires )
408 theClosedWires = new GEOM::ListOfGO;
409 theOpenWires = new GEOM::ListOfGO;
411 // Set a not done flag
412 GetOperations()->SetNotDone();
414 // Get the object itself
415 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
416 if (anObject.IsNull())
419 Handle(TColStd_HSequenceOfTransient) aClosed = new TColStd_HSequenceOfTransient();
420 Handle(TColStd_HSequenceOfTransient) anOpen = new TColStd_HSequenceOfTransient();
421 bool res = GetOperations()->GetFreeBoundary( anObject, aClosed, anOpen );
423 if ( !GetOperations()->IsDone() || !res )
426 int i, n = aClosed->Length();
427 theClosedWires->length( n );
428 for ( i = 1; i <= n; i++ )
429 (*theClosedWires)[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aClosed->Value(i)));
431 n = anOpen->Length();
432 theOpenWires->length( n );
433 for ( i = 1, n = anOpen->Length(); i <= n; i++ )
434 (*theOpenWires)[i-1] = GetObject(Handle(GEOM_Object)::DownCast(anOpen->Value(i)));
440 //=============================================================================
444 //=============================================================================
445 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::ChangeOrientation (GEOM::GEOM_Object_ptr theObject)
447 GEOM::GEOM_Object_var aGEOMObject;
449 // Set a not done flag
450 GetOperations()->SetNotDone();
453 if ( CORBA::is_nil(theObject) )
454 return aGEOMObject._retn();
456 aGEOMObject = GEOM::GEOM_Object::_duplicate(theObject);
458 // Get the object itself
459 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
460 if (anObject.IsNull())
461 return aGEOMObject._retn();
464 // Handle(GEOM_Object) aNewObject =
465 GetOperations()->ChangeOrientation( anObject );
466 // if (!GetOperations()->IsDone() || aNewObject.IsNull())
467 // return aGEOMObject._retn();
469 //return GetObject(aNewObject);
470 return aGEOMObject._retn();
474 //=============================================================================
476 * ChangeOrientationCopy
478 //=============================================================================
479 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::ChangeOrientationCopy (GEOM::GEOM_Object_ptr theObject)
481 GEOM::GEOM_Object_var aGEOMObject;
483 // Set a not done flag
484 GetOperations()->SetNotDone();
486 // Get the object itself
487 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
488 if (anObject.IsNull())
489 return aGEOMObject._retn();
492 Handle(GEOM_Object) aNewObject =
493 GetOperations()->ChangeOrientationCopy( anObject );
494 if (!GetOperations()->IsDone() || aNewObject.IsNull())
495 return aGEOMObject._retn();
497 return GetObject(aNewObject);
500 //=============================================================================
504 //=============================================================================
505 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::LimitTolerance (GEOM::GEOM_Object_ptr theObject,
506 CORBA::Double theTolerance)
508 GEOM::GEOM_Object_var aGEOMObject;
510 // Set a not done flag
511 GetOperations()->SetNotDone();
513 // Get the object itself
514 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
515 if (anObject.IsNull())
516 return aGEOMObject._retn();
519 Handle(GEOM_Object) aNewObject =
520 GetOperations()->LimitTolerance(anObject, theTolerance);
521 if (!GetOperations()->IsDone() || aNewObject.IsNull())
522 return aGEOMObject._retn();
524 return GetObject(aNewObject);