1 // Copyright (C) 2007-2013 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, false );
360 if (!GetOperations()->IsDone() || aNewObject.IsNull())
361 return aGEOMObject._retn();
363 return GetObject(aNewObject);
366 //=============================================================================
368 * SewAllowNonManifold
370 //=============================================================================
371 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::SewAllowNonManifold (GEOM::GEOM_Object_ptr theObject,
372 CORBA::Double theTolerance)
374 GEOM::GEOM_Object_var aGEOMObject;
376 // Set a not done flag
377 GetOperations()->SetNotDone();
380 if (theTolerance < 0)
381 return aGEOMObject._retn();
383 // Get the object itself
384 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
385 if (anObject.IsNull())
386 return aGEOMObject._retn();
389 Handle(GEOM_Object) aNewObject =
390 GetOperations()->Sew( anObject, theTolerance, true );
391 if (!GetOperations()->IsDone() || aNewObject.IsNull())
392 return aGEOMObject._retn();
394 return GetObject(aNewObject);
397 //=============================================================================
401 //=============================================================================
402 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::DivideEdge (GEOM::GEOM_Object_ptr theObject,
403 CORBA::Short theIndex,
404 CORBA::Double theValue,
405 CORBA::Boolean isByParameter)
407 GEOM::GEOM_Object_var aGEOMObject;
409 // Set a not done flag
410 GetOperations()->SetNotDone();
413 if (theValue < 0 || theValue > 1)
414 return aGEOMObject._retn();
416 // Get the object itself
417 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
418 if (anObject.IsNull())
419 return aGEOMObject._retn();
422 Handle(GEOM_Object) aNewObject =
423 GetOperations()->DivideEdge( anObject, theIndex, theValue, isByParameter );
424 if (!GetOperations()->IsDone() || aNewObject.IsNull())
425 return aGEOMObject._retn();
427 return GetObject(aNewObject);
430 //=============================================================================
432 * FuseCollinearEdgesWithinWire
434 //=============================================================================
435 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::FuseCollinearEdgesWithinWire
436 (GEOM::GEOM_Object_ptr theWire,
437 const GEOM::ListOfGO& theVertices)
439 GEOM::GEOM_Object_var aGEOMObject;
441 //Set a not done flag
442 GetOperations()->SetNotDone();
444 //Get the reference objects
445 Handle(GEOM_Object) aWire = GetObjectImpl(theWire);
446 if (aWire.IsNull()) return aGEOMObject._retn();
449 std::list<Handle(GEOM_Object)> aVerts;
451 aLen = theVertices.length();
452 for (ind = 0; ind < aLen; ind++) {
453 Handle(GEOM_Object) aSh = GetObjectImpl(theVertices[ind]);
454 if (aSh.IsNull()) return aGEOMObject._retn();
455 aVerts.push_back(aSh);
459 Handle(GEOM_Object) anObject =
460 GetOperations()->FuseCollinearEdgesWithinWire(aWire, aVerts);
461 if (!GetOperations()->IsDone() || anObject.IsNull())
462 return aGEOMObject._retn();
464 return GetObject(anObject);
467 //=============================================================================
471 //=============================================================================
472 CORBA::Boolean GEOM_IHealingOperations_i::GetFreeBoundary ( GEOM::GEOM_Object_ptr theObject,
473 GEOM::ListOfGO_out theClosedWires,
474 GEOM::ListOfGO_out theOpenWires )
476 theClosedWires = new GEOM::ListOfGO;
477 theOpenWires = new GEOM::ListOfGO;
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())
487 Handle(TColStd_HSequenceOfTransient) aClosed = new TColStd_HSequenceOfTransient();
488 Handle(TColStd_HSequenceOfTransient) anOpen = new TColStd_HSequenceOfTransient();
489 bool res = GetOperations()->GetFreeBoundary( anObject, aClosed, anOpen );
491 if ( !GetOperations()->IsDone() || !res )
494 int i, n = aClosed->Length();
495 theClosedWires->length( n );
496 for ( i = 1; i <= n; i++ )
497 (*theClosedWires)[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aClosed->Value(i)));
499 n = anOpen->Length();
500 theOpenWires->length( n );
501 for ( i = 1, n = anOpen->Length(); i <= n; i++ )
502 (*theOpenWires)[i-1] = GetObject(Handle(GEOM_Object)::DownCast(anOpen->Value(i)));
508 //=============================================================================
512 //=============================================================================
513 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::ChangeOrientation (GEOM::GEOM_Object_ptr theObject)
515 GEOM::GEOM_Object_var aGEOMObject;
517 // Set a not done flag
518 GetOperations()->SetNotDone();
521 if ( CORBA::is_nil(theObject) )
522 return aGEOMObject._retn();
524 aGEOMObject = GEOM::GEOM_Object::_duplicate(theObject);
526 // Get the object itself
527 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
528 if (anObject.IsNull())
529 return aGEOMObject._retn();
532 // Handle(GEOM_Object) aNewObject =
533 GetOperations()->ChangeOrientation( anObject );
534 // if (!GetOperations()->IsDone() || aNewObject.IsNull())
535 // return aGEOMObject._retn();
537 //return GetObject(aNewObject);
538 return aGEOMObject._retn();
542 //=============================================================================
544 * ChangeOrientationCopy
546 //=============================================================================
547 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::ChangeOrientationCopy (GEOM::GEOM_Object_ptr theObject)
549 GEOM::GEOM_Object_var aGEOMObject;
551 // Set a not done flag
552 GetOperations()->SetNotDone();
554 // Get the object itself
555 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
556 if (anObject.IsNull())
557 return aGEOMObject._retn();
560 Handle(GEOM_Object) aNewObject =
561 GetOperations()->ChangeOrientationCopy( anObject );
562 if (!GetOperations()->IsDone() || aNewObject.IsNull())
563 return aGEOMObject._retn();
565 return GetObject(aNewObject);
568 //=============================================================================
572 //=============================================================================
573 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::LimitTolerance (GEOM::GEOM_Object_ptr theObject,
574 CORBA::Double theTolerance)
576 GEOM::GEOM_Object_var aGEOMObject;
578 // Set a not done flag
579 GetOperations()->SetNotDone();
581 // Get the object itself
582 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
583 if (anObject.IsNull())
584 return aGEOMObject._retn();
587 Handle(GEOM_Object) aNewObject =
588 GetOperations()->LimitTolerance(anObject, theTolerance);
589 if (!GetOperations()->IsDone() || aNewObject.IsNull())
590 return aGEOMObject._retn();
592 return GetObject(aNewObject);