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
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"
33 #include <Basics_Utils.hxx>
35 #include <TColStd_HSequenceOfTransient.hxx>
37 //=============================================================================
41 //=============================================================================
43 GEOM_IHealingOperations_i::GEOM_IHealingOperations_i (PortableServer::POA_ptr thePOA,
44 GEOM::GEOM_Gen_ptr theEngine,
45 ::GEOMImpl_IHealingOperations* theImpl)
46 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
48 MESSAGE("GEOM_IHealingOperations_i::GEOM_IHealingOperations_i");
51 //=============================================================================
55 //=============================================================================
57 GEOM_IHealingOperations_i::~GEOM_IHealingOperations_i()
59 MESSAGE("GEOM_IHealingOperations_i::~GEOM_IHealingOperations_i");
62 //=============================================================================
66 //=============================================================================
67 Handle(TColStd_HArray1OfInteger) GEOM_IHealingOperations_i::Convert
68 (const GEOM::short_array& theInArray)
70 Handle(TColStd_HArray1OfInteger) anOutArray;
71 int n = theInArray.length();
74 anOutArray = new TColStd_HArray1OfInteger( 1, n );
75 for (int i = 0; i < n; i++)
76 anOutArray->SetValue( i+1, theInArray[i] );
80 //=============================================================================
84 //=============================================================================
85 Handle(TColStd_HArray1OfExtendedString) GEOM_IHealingOperations_i::Convert
86 (const GEOM::string_array& theInArray)
88 Handle(TColStd_HArray1OfExtendedString) anOutArray;
89 int n = theInArray.length();
92 anOutArray = new TColStd_HArray1OfExtendedString( 1, n );
94 for ( int i = 0; i < n; i++ )
96 str = CORBA::string_dup( theInArray[i] );
97 anOutArray->SetValue( i+1, TCollection_ExtendedString( str ) );
102 //=============================================================================
106 //=============================================================================
107 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::ProcessShape (GEOM::GEOM_Object_ptr theObject,
108 const GEOM::string_array& theOperations,
109 const GEOM::string_array& theParams,
110 const GEOM::string_array& theValues)
112 Kernel_Utils::Localizer loc;
114 GEOM::GEOM_Object_var aGEOMObject;
116 // Set a not done flag
117 GetOperations()->SetNotDone();
119 // Check if theOperations has more than 0 elements and theParams and theValues have the same length
120 //if (theOperations.length() <= 0 || theParams.length() != theValues.length())
121 // return aGEOMObject._retn();
123 // Get the object itself
124 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
125 if (anObject.IsNull())
126 return aGEOMObject._retn();
129 Handle(GEOM_Object) aNewObject = GetOperations()->ShapeProcess( anObject,
130 Convert( theOperations ), Convert( theParams ), Convert( theValues ) );
131 if ( !GetOperations()->IsDone() || aNewObject.IsNull() )
132 return aGEOMObject._retn();
134 return GetObject( aNewObject );
137 //=============================================================================
139 * GetShapeProcessParameters
141 //=============================================================================
142 void GEOM_IHealingOperations_i::GetShapeProcessParameters(GEOM::string_array_out theOperations,
143 GEOM::string_array_out theParams,
144 GEOM::string_array_out theValues)
146 GEOM::string_array_var anOpArray = new GEOM::string_array();
147 GEOM::string_array_var aParArray = new GEOM::string_array();
148 GEOM::string_array_var aValArray = new GEOM::string_array();
150 // retrieve the values as stl-lists
151 std::list<std::string> operationsList, paramsList, valuesList;
152 GetOperations()->GetShapeProcessParameters( operationsList, paramsList, valuesList );
153 const int opSize = operationsList.size(),
154 parSize = paramsList.size(),
155 valSize = valuesList.size();
157 if ( opSize >= 0 && parSize >= 0 && parSize == valSize ) {
158 // allocate the CORBA arrays, sizes == returned lists' sizes
159 anOpArray->length(opSize);
160 aParArray->length(parSize);
161 aValArray->length(valSize);
163 // fill the local CORBA arrays with values from lists
164 std::list<std::string>::iterator opIt, parIt, valIt;
166 for ( opIt = operationsList.begin(); opIt != operationsList.end(); i++,++opIt )
167 anOpArray[i] = CORBA::string_dup( (*opIt).c_str() );
169 for ( i = 0, parIt = paramsList.begin(), valIt = valuesList.begin();
170 parIt != paramsList.end(); i++, ++parIt,++valIt ) {
171 aParArray[i] = CORBA::string_dup( (*parIt).c_str() );
172 aValArray[i] = CORBA::string_dup( (*valIt).c_str() );
176 // initialize out-parameters with local arrays
177 theOperations = anOpArray._retn();
178 theParams = aParArray._retn();
179 theValues = aValArray._retn();
182 //=============================================================================
184 * GetOperatorParameters
186 //=============================================================================
187 void GEOM_IHealingOperations_i::GetOperatorParameters (const char* theOperator,
188 GEOM::string_array_out theParams,
189 GEOM::string_array_out theValues)
191 GEOM::string_array_var aParArray = new GEOM::string_array();
192 GEOM::string_array_var aValArray = new GEOM::string_array();
194 // retrieve the values as stl-lists
195 std::list<std::string> paramsList, valuesList;
196 if ( GetOperations()->GetOperatorParameters( theOperator, paramsList, valuesList ) ) {
197 const int parSize = paramsList.size(), valSize = valuesList.size();
199 if ( parSize == valSize ) {
200 aParArray->length(parSize);
201 aValArray->length(valSize);
203 // fill the local CORBA arrays with values from lists
204 std::list<std::string>::iterator parIt, valIt;
206 for ( i = 0, parIt = paramsList.begin(), valIt = valuesList.begin();
207 parIt != paramsList.end(); i++, ++parIt,++valIt ) {
208 aParArray[i] = CORBA::string_dup( (*parIt).c_str() );
209 aValArray[i] = CORBA::string_dup( (*valIt).c_str() );
214 // initialize out-parameters with local arrays
215 theParams = aParArray._retn();
216 theValues = aValArray._retn();
219 //=============================================================================
223 //=============================================================================
224 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::SuppressFaces (GEOM::GEOM_Object_ptr theObject,
225 const GEOM::short_array& theFaces)
227 GEOM::GEOM_Object_var aGEOMObject;
229 // Set a not done flag
230 GetOperations()->SetNotDone();
232 // Get the object itself
233 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
234 if (anObject.IsNull())
235 return aGEOMObject._retn();
237 // if theFaces is empty - it's OK, it means that ALL faces must be removed
240 Handle(GEOM_Object) aNewObject =
241 GetOperations()->SuppressFaces( anObject, Convert( theFaces ) );
242 if (!GetOperations()->IsDone() || aNewObject.IsNull())
243 return aGEOMObject._retn();
245 return GetObject( aNewObject );
248 //=============================================================================
252 //=============================================================================
253 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::CloseContour (GEOM::GEOM_Object_ptr theObject,
254 const GEOM::short_array& theWires,
255 CORBA::Boolean isCommonVertex)
257 GEOM::GEOM_Object_var aGEOMObject;
259 // Set a not done flag
260 GetOperations()->SetNotDone();
262 // Get the object itself
263 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
264 if (anObject.IsNull())
265 return aGEOMObject._retn();
268 Handle(GEOM_Object) aNewObject =
269 GetOperations()->CloseContour( anObject, Convert( theWires ), isCommonVertex );
270 if (!GetOperations()->IsDone() || aNewObject.IsNull())
271 return aGEOMObject._retn();
273 return GetObject(aNewObject);
276 //=============================================================================
280 //=============================================================================
281 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::RemoveIntWires (GEOM::GEOM_Object_ptr theObject,
282 const GEOM::short_array& theWires)
284 GEOM::GEOM_Object_var aGEOMObject;
286 // Set a not done flag
287 GetOperations()->SetNotDone();
289 // Get the object itself
290 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
291 if (anObject.IsNull())
292 return aGEOMObject._retn();
294 // if theWires is empty - it's OK, it means that ALL wires should be removed
297 Handle(GEOM_Object) aNewObject =
298 GetOperations()->RemoveIntWires( anObject, Convert( theWires ) );
299 if (!GetOperations()->IsDone() || aNewObject.IsNull())
300 return aGEOMObject._retn();
302 return GetObject(aNewObject);
305 //=============================================================================
309 //=============================================================================
310 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::FillHoles (GEOM::GEOM_Object_ptr theObject,
311 const GEOM::short_array& theWires)
313 GEOM::GEOM_Object_var aGEOMObject;
315 // Set a not done flag
316 GetOperations()->SetNotDone();
318 // Get the object itself
319 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
320 if (anObject.IsNull())
321 return aGEOMObject._retn();
323 // if theWires is empty - it's OK, it means that ALL wires should be removed
326 Handle(GEOM_Object) aNewObject =
327 GetOperations()->FillHoles( anObject, Convert( theWires ) );
328 if (!GetOperations()->IsDone() || aNewObject.IsNull())
329 return aGEOMObject._retn();
331 return GetObject(aNewObject);
334 //=============================================================================
338 //=============================================================================
339 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::Sew (GEOM::GEOM_Object_ptr theObject,
340 CORBA::Double theTolerance)
342 GEOM::GEOM_Object_var aGEOMObject;
344 // Set a not done flag
345 GetOperations()->SetNotDone();
348 if (theTolerance < 0)
349 return aGEOMObject._retn();
351 // Get the object itself
352 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
353 if (anObject.IsNull())
354 return aGEOMObject._retn();
357 Handle(GEOM_Object) aNewObject =
358 GetOperations()->Sew( anObject, theTolerance );
359 if (!GetOperations()->IsDone() || aNewObject.IsNull())
360 return aGEOMObject._retn();
362 return GetObject(aNewObject);
365 //=============================================================================
369 //=============================================================================
370 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::DivideEdge (GEOM::GEOM_Object_ptr theObject,
371 CORBA::Short theIndex,
372 CORBA::Double theValue,
373 CORBA::Boolean isByParameter)
375 GEOM::GEOM_Object_var aGEOMObject;
377 // Set a not done flag
378 GetOperations()->SetNotDone();
381 if (theValue < 0 || theValue > 1)
382 return aGEOMObject._retn();
384 // Get the object itself
385 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
386 if (anObject.IsNull())
387 return aGEOMObject._retn();
390 Handle(GEOM_Object) aNewObject =
391 GetOperations()->DivideEdge( anObject, theIndex, theValue, isByParameter );
392 if (!GetOperations()->IsDone() || aNewObject.IsNull())
393 return aGEOMObject._retn();
395 return GetObject(aNewObject);
398 //=============================================================================
400 * FuseCollinearEdgesWithinWire
402 //=============================================================================
403 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::FuseCollinearEdgesWithinWire
404 (GEOM::GEOM_Object_ptr theWire,
405 const GEOM::ListOfGO& theVertices)
407 GEOM::GEOM_Object_var aGEOMObject;
409 //Set a not done flag
410 GetOperations()->SetNotDone();
412 //Get the reference objects
413 Handle(GEOM_Object) aWire = GetObjectImpl(theWire);
414 if (aWire.IsNull()) return aGEOMObject._retn();
417 std::list<Handle(GEOM_Object)> aVerts;
419 aLen = theVertices.length();
420 for (ind = 0; ind < aLen; ind++) {
421 Handle(GEOM_Object) aSh = GetObjectImpl(theVertices[ind]);
422 if (aSh.IsNull()) return aGEOMObject._retn();
423 aVerts.push_back(aSh);
427 Handle(GEOM_Object) anObject =
428 GetOperations()->FuseCollinearEdgesWithinWire(aWire, aVerts);
429 if (!GetOperations()->IsDone() || anObject.IsNull())
430 return aGEOMObject._retn();
432 return GetObject(anObject);
435 //=============================================================================
439 //=============================================================================
440 CORBA::Boolean GEOM_IHealingOperations_i::GetFreeBoundary ( GEOM::GEOM_Object_ptr theObject,
441 GEOM::ListOfGO_out theClosedWires,
442 GEOM::ListOfGO_out theOpenWires )
444 theClosedWires = new GEOM::ListOfGO;
445 theOpenWires = new GEOM::ListOfGO;
447 // Set a not done flag
448 GetOperations()->SetNotDone();
450 // Get the object itself
451 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
452 if (anObject.IsNull())
455 Handle(TColStd_HSequenceOfTransient) aClosed = new TColStd_HSequenceOfTransient();
456 Handle(TColStd_HSequenceOfTransient) anOpen = new TColStd_HSequenceOfTransient();
457 bool res = GetOperations()->GetFreeBoundary( anObject, aClosed, anOpen );
459 if ( !GetOperations()->IsDone() || !res )
462 int i, n = aClosed->Length();
463 theClosedWires->length( n );
464 for ( i = 1; i <= n; i++ )
465 (*theClosedWires)[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aClosed->Value(i)));
467 n = anOpen->Length();
468 theOpenWires->length( n );
469 for ( i = 1, n = anOpen->Length(); i <= n; i++ )
470 (*theOpenWires)[i-1] = GetObject(Handle(GEOM_Object)::DownCast(anOpen->Value(i)));
476 //=============================================================================
480 //=============================================================================
481 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::ChangeOrientation (GEOM::GEOM_Object_ptr theObject)
483 GEOM::GEOM_Object_var aGEOMObject;
485 // Set a not done flag
486 GetOperations()->SetNotDone();
489 if ( CORBA::is_nil(theObject) )
490 return aGEOMObject._retn();
492 aGEOMObject = GEOM::GEOM_Object::_duplicate(theObject);
494 // Get the object itself
495 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
496 if (anObject.IsNull())
497 return aGEOMObject._retn();
500 // Handle(GEOM_Object) aNewObject =
501 GetOperations()->ChangeOrientation( anObject );
502 // if (!GetOperations()->IsDone() || aNewObject.IsNull())
503 // return aGEOMObject._retn();
505 //return GetObject(aNewObject);
506 return aGEOMObject._retn();
510 //=============================================================================
512 * ChangeOrientationCopy
514 //=============================================================================
515 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::ChangeOrientationCopy (GEOM::GEOM_Object_ptr theObject)
517 GEOM::GEOM_Object_var aGEOMObject;
519 // Set a not done flag
520 GetOperations()->SetNotDone();
522 // Get the object itself
523 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
524 if (anObject.IsNull())
525 return aGEOMObject._retn();
528 Handle(GEOM_Object) aNewObject =
529 GetOperations()->ChangeOrientationCopy( anObject );
530 if (!GetOperations()->IsDone() || aNewObject.IsNull())
531 return aGEOMObject._retn();
533 return GetObject(aNewObject);
536 //=============================================================================
540 //=============================================================================
541 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::LimitTolerance (GEOM::GEOM_Object_ptr theObject,
542 CORBA::Double theTolerance)
544 GEOM::GEOM_Object_var aGEOMObject;
546 // Set a not done flag
547 GetOperations()->SetNotDone();
549 // Get the object itself
550 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
551 if (anObject.IsNull())
552 return aGEOMObject._retn();
555 Handle(GEOM_Object) aNewObject =
556 GetOperations()->LimitTolerance(anObject, theTolerance);
557 if (!GetOperations()->IsDone() || aNewObject.IsNull())
558 return aGEOMObject._retn();
560 return GetObject(aNewObject);