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
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"
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 GEOM::GEOM_Object_var aGEOMObject;
114 // Set a not done flag
115 GetOperations()->SetNotDone();
117 // Check if theOperations has more than 0 elements and theParams and theValues have the same length
118 //if (theOperations.length() <= 0 || theParams.length() != theValues.length())
119 // return aGEOMObject._retn();
121 // Get the object itself
122 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
123 if (anObject.IsNull())
124 return aGEOMObject._retn();
127 Handle(GEOM_Object) aNewObject = GetOperations()->ShapeProcess( anObject,
128 Convert( theOperations ), Convert( theParams ), Convert( theValues ) );
129 if ( !GetOperations()->IsDone() || aNewObject.IsNull() )
130 return aGEOMObject._retn();
132 return GetObject( aNewObject );
135 //=============================================================================
137 * GetShapeProcessParameters
139 //=============================================================================
140 void GEOM_IHealingOperations_i::GetShapeProcessParameters(GEOM::string_array_out theOperations,
141 GEOM::string_array_out theParams,
142 GEOM::string_array_out theValues)
144 GEOM::string_array_var anOpArray = new GEOM::string_array();
145 GEOM::string_array_var aParArray = new GEOM::string_array();
146 GEOM::string_array_var aValArray = new GEOM::string_array();
148 // retrieve the values as stl-lists
149 std::list<std::string> operationsList, paramsList, valuesList;
150 GetOperations()->GetShapeProcessParameters( operationsList, paramsList, valuesList );
151 const int opSize = operationsList.size(),
152 parSize = paramsList.size(),
153 valSize = valuesList.size();
155 if ( opSize >= 0 && parSize >= 0 && parSize == valSize ) {
156 // allocate the CORBA arrays, sizes == returned lists' sizes
157 anOpArray->length(opSize);
158 aParArray->length(parSize);
159 aValArray->length(valSize);
161 // fill the local CORBA arrays with values from lists
162 std::list<std::string>::iterator opIt, parIt, valIt;
164 for ( opIt = operationsList.begin(); opIt != operationsList.end(); i++,++opIt )
165 anOpArray[i] = CORBA::string_dup( (*opIt).c_str() );
167 for ( i = 0, parIt = paramsList.begin(), valIt = valuesList.begin();
168 parIt != paramsList.end(); i++, ++parIt,++valIt ) {
169 aParArray[i] = CORBA::string_dup( (*parIt).c_str() );
170 aValArray[i] = CORBA::string_dup( (*valIt).c_str() );
174 // initialize out-parameters with local arrays
175 theOperations = anOpArray._retn();
176 theParams = aParArray._retn();
177 theValues = aValArray._retn();
180 //=============================================================================
182 * GetOperatorParameters
184 //=============================================================================
185 void GEOM_IHealingOperations_i::GetOperatorParameters (const char* theOperator,
186 GEOM::string_array_out theParams,
187 GEOM::string_array_out theValues)
189 GEOM::string_array_var aParArray = new GEOM::string_array();
190 GEOM::string_array_var aValArray = new GEOM::string_array();
192 // retrieve the values as stl-lists
193 std::list<std::string> paramsList, valuesList;
194 if ( GetOperations()->GetOperatorParameters( theOperator, paramsList, valuesList ) ) {
195 const int parSize = paramsList.size(), valSize = valuesList.size();
197 if ( parSize == valSize ) {
198 aParArray->length(parSize);
199 aValArray->length(valSize);
201 // fill the local CORBA arrays with values from lists
202 std::list<std::string>::iterator parIt, valIt;
204 for ( i = 0, parIt = paramsList.begin(), valIt = valuesList.begin();
205 parIt != paramsList.end(); i++, ++parIt,++valIt ) {
206 aParArray[i] = CORBA::string_dup( (*parIt).c_str() );
207 aValArray[i] = CORBA::string_dup( (*valIt).c_str() );
212 // initialize out-parameters with local arrays
213 theParams = aParArray._retn();
214 theValues = aValArray._retn();
217 //=============================================================================
221 //=============================================================================
222 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::SuppressFaces (GEOM::GEOM_Object_ptr theObject,
223 const GEOM::short_array& theFaces)
225 GEOM::GEOM_Object_var aGEOMObject;
227 // Set a not done flag
228 GetOperations()->SetNotDone();
230 // Get the object itself
231 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
232 if (anObject.IsNull())
233 return aGEOMObject._retn();
235 // if theFaces is empty - it's OK, it means that ALL faces must be removed
238 Handle(GEOM_Object) aNewObject =
239 GetOperations()->SuppressFaces( anObject, Convert( theFaces ) );
240 if (!GetOperations()->IsDone() || aNewObject.IsNull())
241 return aGEOMObject._retn();
243 return GetObject( aNewObject );
246 //=============================================================================
250 //=============================================================================
251 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::CloseContour (GEOM::GEOM_Object_ptr theObject,
252 const GEOM::short_array& theWires,
253 CORBA::Boolean isCommonVertex)
255 GEOM::GEOM_Object_var aGEOMObject;
257 // Set a not done flag
258 GetOperations()->SetNotDone();
260 // Get the object itself
261 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
262 if (anObject.IsNull())
263 return aGEOMObject._retn();
266 Handle(GEOM_Object) aNewObject =
267 GetOperations()->CloseContour( anObject, Convert( theWires ), isCommonVertex );
268 if (!GetOperations()->IsDone() || aNewObject.IsNull())
269 return aGEOMObject._retn();
271 return GetObject(aNewObject);
274 //=============================================================================
278 //=============================================================================
279 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::RemoveIntWires (GEOM::GEOM_Object_ptr theObject,
280 const GEOM::short_array& theWires)
282 GEOM::GEOM_Object_var aGEOMObject;
284 // Set a not done flag
285 GetOperations()->SetNotDone();
287 // Get the object itself
288 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
289 if (anObject.IsNull())
290 return aGEOMObject._retn();
292 // if theWires is empty - it's OK, it means that ALL wires should be removed
295 Handle(GEOM_Object) aNewObject =
296 GetOperations()->RemoveIntWires( anObject, Convert( theWires ) );
297 if (!GetOperations()->IsDone() || aNewObject.IsNull())
298 return aGEOMObject._retn();
300 return GetObject(aNewObject);
303 //=============================================================================
307 //=============================================================================
308 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::FillHoles (GEOM::GEOM_Object_ptr theObject,
309 const GEOM::short_array& theWires)
311 GEOM::GEOM_Object_var aGEOMObject;
313 // Set a not done flag
314 GetOperations()->SetNotDone();
316 // Get the object itself
317 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
318 if (anObject.IsNull())
319 return aGEOMObject._retn();
321 // if theWires is empty - it's OK, it means that ALL wires should be removed
324 Handle(GEOM_Object) aNewObject =
325 GetOperations()->FillHoles( anObject, Convert( theWires ) );
326 if (!GetOperations()->IsDone() || aNewObject.IsNull())
327 return aGEOMObject._retn();
329 return GetObject(aNewObject);
332 //=============================================================================
336 //=============================================================================
337 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::Sew (GEOM::GEOM_Object_ptr theObject,
338 CORBA::Double theTolerance)
340 GEOM::GEOM_Object_var aGEOMObject;
342 // Set a not done flag
343 GetOperations()->SetNotDone();
346 if (theTolerance < 0)
347 return aGEOMObject._retn();
349 // Get the object itself
350 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
351 if (anObject.IsNull())
352 return aGEOMObject._retn();
355 Handle(GEOM_Object) aNewObject =
356 GetOperations()->Sew( anObject, theTolerance );
357 if (!GetOperations()->IsDone() || aNewObject.IsNull())
358 return aGEOMObject._retn();
360 return GetObject(aNewObject);
363 //=============================================================================
367 //=============================================================================
368 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::DivideEdge (GEOM::GEOM_Object_ptr theObject,
369 CORBA::Short theIndex,
370 CORBA::Double theValue,
371 CORBA::Boolean isByParameter)
373 GEOM::GEOM_Object_var aGEOMObject;
375 // Set a not done flag
376 GetOperations()->SetNotDone();
379 if (theValue < 0 || theValue > 1)
380 return aGEOMObject._retn();
382 // Get the object itself
383 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
384 if (anObject.IsNull())
385 return aGEOMObject._retn();
388 Handle(GEOM_Object) aNewObject =
389 GetOperations()->DivideEdge( anObject, theIndex, theValue, isByParameter );
390 if (!GetOperations()->IsDone() || aNewObject.IsNull())
391 return aGEOMObject._retn();
393 return GetObject(aNewObject);
396 //=============================================================================
400 //=============================================================================
401 CORBA::Boolean GEOM_IHealingOperations_i::GetFreeBoundary ( GEOM::GEOM_Object_ptr theObject,
402 GEOM::ListOfGO_out theClosedWires,
403 GEOM::ListOfGO_out theOpenWires )
405 theClosedWires = new GEOM::ListOfGO;
406 theOpenWires = new GEOM::ListOfGO;
408 // Set a not done flag
409 GetOperations()->SetNotDone();
411 // Get the object itself
412 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
413 if (anObject.IsNull())
416 Handle(TColStd_HSequenceOfTransient) aClosed = new TColStd_HSequenceOfTransient();
417 Handle(TColStd_HSequenceOfTransient) anOpen = new TColStd_HSequenceOfTransient();
418 bool res = GetOperations()->GetFreeBoundary( anObject, aClosed, anOpen );
420 if ( !GetOperations()->IsDone() || !res )
423 int i, n = aClosed->Length();
424 theClosedWires->length( n );
425 for ( i = 1; i <= n; i++ )
426 (*theClosedWires)[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aClosed->Value(i)));
428 n = anOpen->Length();
429 theOpenWires->length( n );
430 for ( i = 1, n = anOpen->Length(); i <= n; i++ )
431 (*theOpenWires)[i-1] = GetObject(Handle(GEOM_Object)::DownCast(anOpen->Value(i)));
437 //=============================================================================
441 //=============================================================================
442 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::ChangeOrientation (GEOM::GEOM_Object_ptr theObject)
444 GEOM::GEOM_Object_var aGEOMObject;
446 // Set a not done flag
447 GetOperations()->SetNotDone();
450 if ( CORBA::is_nil(theObject) )
451 return aGEOMObject._retn();
453 aGEOMObject = GEOM::GEOM_Object::_duplicate(theObject);
455 // Get the object itself
456 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
457 if (anObject.IsNull())
458 return aGEOMObject._retn();
461 // Handle(GEOM_Object) aNewObject =
462 GetOperations()->ChangeOrientation( anObject );
463 // if (!GetOperations()->IsDone() || aNewObject.IsNull())
464 // return aGEOMObject._retn();
466 //return GetObject(aNewObject);
467 return aGEOMObject._retn();
471 //=============================================================================
473 * ChangeOrientationCopy
475 //=============================================================================
476 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::ChangeOrientationCopy (GEOM::GEOM_Object_ptr theObject)
478 GEOM::GEOM_Object_var aGEOMObject;
480 // Set a not done flag
481 GetOperations()->SetNotDone();
483 // Get the object itself
484 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
485 if (anObject.IsNull())
486 return aGEOMObject._retn();
489 Handle(GEOM_Object) aNewObject =
490 GetOperations()->ChangeOrientationCopy( anObject );
491 if (!GetOperations()->IsDone() || aNewObject.IsNull())
492 return aGEOMObject._retn();
494 return GetObject(aNewObject);