1 // Copyright (C) 2007-2014 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, or (at your option) any later version.
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 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::ProcessShape (GEOM::GEOM_Object_ptr theObject,
87 const GEOM::string_array& theOperations,
88 const GEOM::string_array& theParams,
89 const GEOM::string_array& theValues)
91 Kernel_Utils::Localizer loc;
93 GEOM::GEOM_Object_var aGEOMObject;
95 // Set a not done flag
96 GetOperations()->SetNotDone();
98 // Check if theOperations has more than 0 elements and theParams and theValues have the same length
99 //if (theOperations.length() <= 0 || theParams.length() != theValues.length())
100 // return aGEOMObject._retn();
102 // Get the object itself
103 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
104 if (anObject.IsNull())
105 return aGEOMObject._retn();
108 Handle(GEOM_Object) aNewObject = GetOperations()->ShapeProcess( anObject,
109 ConvertStringArray( theOperations ), ConvertStringArray( theParams ),
110 ConvertStringArray( theValues ) );
111 if ( !GetOperations()->IsDone() || aNewObject.IsNull() )
112 return aGEOMObject._retn();
114 return GetObject( aNewObject );
117 //=============================================================================
119 * GetShapeProcessParameters
121 //=============================================================================
122 void GEOM_IHealingOperations_i::GetShapeProcessParameters(GEOM::string_array_out theOperations,
123 GEOM::string_array_out theParams,
124 GEOM::string_array_out theValues)
126 GEOM::string_array_var anOpArray = new GEOM::string_array();
127 GEOM::string_array_var aParArray = new GEOM::string_array();
128 GEOM::string_array_var aValArray = new GEOM::string_array();
130 // retrieve the values as stl-lists
131 std::list<std::string> operationsList, paramsList, valuesList;
132 GetOperations()->GetShapeProcessParameters( operationsList, paramsList, valuesList );
133 const int opSize = operationsList.size(),
134 parSize = paramsList.size(),
135 valSize = valuesList.size();
137 if ( opSize >= 0 && parSize >= 0 && parSize == valSize ) {
138 // allocate the CORBA arrays, sizes == returned lists' sizes
139 anOpArray->length(opSize);
140 aParArray->length(parSize);
141 aValArray->length(valSize);
143 // fill the local CORBA arrays with values from lists
144 std::list<std::string>::iterator opIt, parIt, valIt;
146 for ( opIt = operationsList.begin(); opIt != operationsList.end(); i++,++opIt )
147 anOpArray[i] = CORBA::string_dup( (*opIt).c_str() );
149 for ( i = 0, parIt = paramsList.begin(), valIt = valuesList.begin();
150 parIt != paramsList.end(); i++, ++parIt,++valIt ) {
151 aParArray[i] = CORBA::string_dup( (*parIt).c_str() );
152 aValArray[i] = CORBA::string_dup( (*valIt).c_str() );
156 // initialize out-parameters with local arrays
157 theOperations = anOpArray._retn();
158 theParams = aParArray._retn();
159 theValues = aValArray._retn();
162 //=============================================================================
164 * GetOperatorParameters
166 //=============================================================================
167 void GEOM_IHealingOperations_i::GetOperatorParameters (const char* theOperator,
168 GEOM::string_array_out theParams,
169 GEOM::string_array_out theValues)
171 GEOM::string_array_var aParArray = new GEOM::string_array();
172 GEOM::string_array_var aValArray = new GEOM::string_array();
174 // retrieve the values as stl-lists
175 std::list<std::string> paramsList, valuesList;
176 if ( GetOperations()->GetOperatorParameters( theOperator, paramsList, valuesList ) ) {
177 const int parSize = paramsList.size(), valSize = valuesList.size();
179 if ( parSize == valSize ) {
180 aParArray->length(parSize);
181 aValArray->length(valSize);
183 // fill the local CORBA arrays with values from lists
184 std::list<std::string>::iterator parIt, valIt;
186 for ( i = 0, parIt = paramsList.begin(), valIt = valuesList.begin();
187 parIt != paramsList.end(); i++, ++parIt,++valIt ) {
188 aParArray[i] = CORBA::string_dup( (*parIt).c_str() );
189 aValArray[i] = CORBA::string_dup( (*valIt).c_str() );
194 // initialize out-parameters with local arrays
195 theParams = aParArray._retn();
196 theValues = aValArray._retn();
199 //=============================================================================
203 //=============================================================================
204 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::SuppressFaces (GEOM::GEOM_Object_ptr theObject,
205 const GEOM::short_array& theFaces)
207 GEOM::GEOM_Object_var aGEOMObject;
209 // Set a not done flag
210 GetOperations()->SetNotDone();
212 // Get the object itself
213 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
214 if (anObject.IsNull())
215 return aGEOMObject._retn();
217 // if theFaces is empty - it's OK, it means that ALL faces must be removed
220 Handle(GEOM_Object) aNewObject =
221 GetOperations()->SuppressFaces( anObject, Convert( theFaces ) );
222 if (!GetOperations()->IsDone() || aNewObject.IsNull())
223 return aGEOMObject._retn();
225 return GetObject( aNewObject );
228 //=============================================================================
232 //=============================================================================
233 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::CloseContour (GEOM::GEOM_Object_ptr theObject,
234 const GEOM::short_array& theWires,
235 CORBA::Boolean isCommonVertex)
237 GEOM::GEOM_Object_var aGEOMObject;
239 // Set a not done flag
240 GetOperations()->SetNotDone();
242 // Get the object itself
243 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
244 if (anObject.IsNull())
245 return aGEOMObject._retn();
248 Handle(GEOM_Object) aNewObject =
249 GetOperations()->CloseContour( anObject, Convert( theWires ), isCommonVertex );
250 if (!GetOperations()->IsDone() || aNewObject.IsNull())
251 return aGEOMObject._retn();
253 return GetObject(aNewObject);
256 //=============================================================================
260 //=============================================================================
261 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::RemoveIntWires (GEOM::GEOM_Object_ptr theObject,
262 const GEOM::short_array& theWires)
264 GEOM::GEOM_Object_var aGEOMObject;
266 // Set a not done flag
267 GetOperations()->SetNotDone();
269 // Get the object itself
270 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
271 if (anObject.IsNull())
272 return aGEOMObject._retn();
274 // if theWires is empty - it's OK, it means that ALL wires should be removed
277 Handle(GEOM_Object) aNewObject =
278 GetOperations()->RemoveIntWires( anObject, Convert( theWires ) );
279 if (!GetOperations()->IsDone() || aNewObject.IsNull())
280 return aGEOMObject._retn();
282 return GetObject(aNewObject);
285 //=============================================================================
289 //=============================================================================
290 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::FillHoles (GEOM::GEOM_Object_ptr theObject,
291 const GEOM::short_array& theWires)
293 GEOM::GEOM_Object_var aGEOMObject;
295 // Set a not done flag
296 GetOperations()->SetNotDone();
298 // Get the object itself
299 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
300 if (anObject.IsNull())
301 return aGEOMObject._retn();
303 // if theWires is empty - it's OK, it means that ALL wires should be removed
306 Handle(GEOM_Object) aNewObject =
307 GetOperations()->FillHoles( anObject, Convert( theWires ) );
308 if (!GetOperations()->IsDone() || aNewObject.IsNull())
309 return aGEOMObject._retn();
311 return GetObject(aNewObject);
314 //=============================================================================
318 //=============================================================================
319 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::Sew (GEOM::GEOM_Object_ptr theObject,
320 CORBA::Double theTolerance)
322 GEOM::GEOM_Object_var aGEOMObject;
324 // Set a not done flag
325 GetOperations()->SetNotDone();
328 if (theTolerance < 0)
329 return aGEOMObject._retn();
331 // Get the object itself
332 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
333 if (anObject.IsNull())
334 return aGEOMObject._retn();
337 Handle(GEOM_Object) aNewObject =
338 GetOperations()->Sew( anObject, theTolerance, false );
339 if (!GetOperations()->IsDone() || aNewObject.IsNull())
340 return aGEOMObject._retn();
342 return GetObject(aNewObject);
345 //=============================================================================
347 * SewAllowNonManifold
349 //=============================================================================
350 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::SewAllowNonManifold (GEOM::GEOM_Object_ptr theObject,
351 CORBA::Double theTolerance)
353 GEOM::GEOM_Object_var aGEOMObject;
355 // Set a not done flag
356 GetOperations()->SetNotDone();
359 if (theTolerance < 0)
360 return aGEOMObject._retn();
362 // Get the object itself
363 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
364 if (anObject.IsNull())
365 return aGEOMObject._retn();
368 Handle(GEOM_Object) aNewObject =
369 GetOperations()->Sew( anObject, theTolerance, true );
370 if (!GetOperations()->IsDone() || aNewObject.IsNull())
371 return aGEOMObject._retn();
373 return GetObject(aNewObject);
376 //=============================================================================
378 * RemoveInternalFaces
380 //=============================================================================
381 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::RemoveInternalFaces (GEOM::GEOM_Object_ptr theCompound)
383 GEOM::GEOM_Object_var aGEOMObject;
385 // Set a not done flag
386 GetOperations()->SetNotDone();
389 Handle(GEOM_Object) anObject = GetObjectImpl(theCompound);
390 if (anObject.IsNull())
391 return aGEOMObject._retn();
394 Handle(GEOM_Object) aNewObject = GetOperations()->RemoveInternalFaces(anObject);
395 if (!GetOperations()->IsDone() || aNewObject.IsNull())
396 return aGEOMObject._retn();
398 return GetObject(aNewObject);
401 //=============================================================================
405 //=============================================================================
406 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::DivideEdge (GEOM::GEOM_Object_ptr theObject,
407 CORBA::Short theIndex,
408 CORBA::Double theValue,
409 CORBA::Boolean isByParameter)
411 GEOM::GEOM_Object_var aGEOMObject;
413 // Set a not done flag
414 GetOperations()->SetNotDone();
417 if (theValue < 0 || theValue > 1)
418 return aGEOMObject._retn();
420 // Get the object itself
421 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
422 if (anObject.IsNull())
423 return aGEOMObject._retn();
426 Handle(GEOM_Object) aNewObject =
427 GetOperations()->DivideEdge( anObject, theIndex, theValue, isByParameter );
428 if (!GetOperations()->IsDone() || aNewObject.IsNull())
429 return aGEOMObject._retn();
431 return GetObject(aNewObject);
434 //=============================================================================
436 * FuseCollinearEdgesWithinWire
438 //=============================================================================
439 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::FuseCollinearEdgesWithinWire
440 (GEOM::GEOM_Object_ptr theWire,
441 const GEOM::ListOfGO& theVertices)
443 GEOM::GEOM_Object_var aGEOMObject;
445 //Set a not done flag
446 GetOperations()->SetNotDone();
448 //Get the reference objects
449 Handle(GEOM_Object) aWire = GetObjectImpl(theWire);
450 if (aWire.IsNull()) return aGEOMObject._retn();
453 std::list<Handle(GEOM_Object)> aVerts;
455 aLen = theVertices.length();
456 for (ind = 0; ind < aLen; ind++) {
457 Handle(GEOM_Object) aSh = GetObjectImpl(theVertices[ind]);
458 if (aSh.IsNull()) return aGEOMObject._retn();
459 aVerts.push_back(aSh);
463 Handle(GEOM_Object) anObject =
464 GetOperations()->FuseCollinearEdgesWithinWire(aWire, aVerts);
465 if (!GetOperations()->IsDone() || anObject.IsNull())
466 return aGEOMObject._retn();
468 return GetObject(anObject);
471 //=============================================================================
475 //=============================================================================
476 CORBA::Boolean GEOM_IHealingOperations_i::GetFreeBoundary ( GEOM::GEOM_Object_ptr theObject,
477 GEOM::ListOfGO_out theClosedWires,
478 GEOM::ListOfGO_out theOpenWires )
480 theClosedWires = new GEOM::ListOfGO;
481 theOpenWires = new GEOM::ListOfGO;
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())
491 Handle(TColStd_HSequenceOfTransient) aClosed = new TColStd_HSequenceOfTransient();
492 Handle(TColStd_HSequenceOfTransient) anOpen = new TColStd_HSequenceOfTransient();
493 bool res = GetOperations()->GetFreeBoundary( anObject, aClosed, anOpen );
495 if ( !GetOperations()->IsDone() || !res )
498 int i, n = aClosed->Length();
499 theClosedWires->length( n );
500 for ( i = 1; i <= n; i++ )
501 (*theClosedWires)[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aClosed->Value(i)));
503 n = anOpen->Length();
504 theOpenWires->length( n );
505 for ( i = 1, n = anOpen->Length(); i <= n; i++ )
506 (*theOpenWires)[i-1] = GetObject(Handle(GEOM_Object)::DownCast(anOpen->Value(i)));
512 //=============================================================================
516 //=============================================================================
517 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::ChangeOrientation (GEOM::GEOM_Object_ptr theObject)
519 GEOM::GEOM_Object_var aGEOMObject;
521 // Set a not done flag
522 GetOperations()->SetNotDone();
525 if ( CORBA::is_nil(theObject) )
526 return aGEOMObject._retn();
528 aGEOMObject = GEOM::GEOM_Object::_duplicate(theObject);
530 // Get the object itself
531 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
532 if (anObject.IsNull())
533 return aGEOMObject._retn();
536 // Handle(GEOM_Object) aNewObject =
537 GetOperations()->ChangeOrientation( anObject );
538 // if (!GetOperations()->IsDone() || aNewObject.IsNull())
539 // return aGEOMObject._retn();
541 //return GetObject(aNewObject);
542 return aGEOMObject._retn();
546 //=============================================================================
548 * ChangeOrientationCopy
550 //=============================================================================
551 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::ChangeOrientationCopy (GEOM::GEOM_Object_ptr theObject)
553 GEOM::GEOM_Object_var aGEOMObject;
555 // Set a not done flag
556 GetOperations()->SetNotDone();
558 // Get the object itself
559 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
560 if (anObject.IsNull())
561 return aGEOMObject._retn();
564 Handle(GEOM_Object) aNewObject =
565 GetOperations()->ChangeOrientationCopy( anObject );
566 if (!GetOperations()->IsDone() || aNewObject.IsNull())
567 return aGEOMObject._retn();
569 return GetObject(aNewObject);
572 //=============================================================================
576 //=============================================================================
577 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::LimitTolerance (GEOM::GEOM_Object_ptr theObject,
578 CORBA::Double theTolerance)
580 GEOM::GEOM_Object_var aGEOMObject;
582 // Set a not done flag
583 GetOperations()->SetNotDone();
585 // Get the object itself
586 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
587 if (anObject.IsNull())
588 return aGEOMObject._retn();
591 Handle(GEOM_Object) aNewObject =
592 GetOperations()->LimitTolerance(anObject, theTolerance);
593 if (!GetOperations()->IsDone() || aNewObject.IsNull())
594 return aGEOMObject._retn();
596 return GetObject(aNewObject);