1 // Copyright (C) 2007-2008 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"
34 #include <TColStd_HSequenceOfTransient.hxx>
36 //=============================================================================
40 //=============================================================================
42 GEOM_IHealingOperations_i::GEOM_IHealingOperations_i (PortableServer::POA_ptr thePOA,
43 GEOM::GEOM_Gen_ptr theEngine,
44 ::GEOMImpl_IHealingOperations* theImpl)
45 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
47 MESSAGE("GEOM_IHealingOperations_i::GEOM_IHealingOperations_i");
50 //=============================================================================
54 //=============================================================================
56 GEOM_IHealingOperations_i::~GEOM_IHealingOperations_i()
58 MESSAGE("GEOM_IHealingOperations_i::~GEOM_IHealingOperations_i");
61 //=============================================================================
65 //=============================================================================
66 Handle(TColStd_HArray1OfInteger) GEOM_IHealingOperations_i::Convert
67 (const GEOM::short_array& theInArray)
69 Handle(TColStd_HArray1OfInteger) anOutArray;
70 int n = theInArray.length();
73 anOutArray = new TColStd_HArray1OfInteger( 1, n );
74 for (int i = 0; i < n; i++)
75 anOutArray->SetValue( i+1, theInArray[i] );
79 //=============================================================================
83 //=============================================================================
84 Handle(TColStd_HArray1OfExtendedString) GEOM_IHealingOperations_i::Convert
85 (const GEOM::string_array& theInArray)
87 Handle(TColStd_HArray1OfExtendedString) anOutArray;
88 int n = theInArray.length();
91 anOutArray = new TColStd_HArray1OfExtendedString( 1, n );
93 for ( int i = 0; i < n; i++ )
95 str = CORBA::string_dup( theInArray[i] );
96 anOutArray->SetValue( i+1, TCollection_ExtendedString( str ) );
101 //=============================================================================
105 //=============================================================================
106 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::ProcessShape (GEOM::GEOM_Object_ptr theObject,
107 const GEOM::string_array& theOperations,
108 const GEOM::string_array& theParams,
109 const GEOM::string_array& theValues)
111 GEOM::GEOM_Object_var aGEOMObject;
113 // Set a not done flag
114 GetOperations()->SetNotDone();
117 if ( CORBA::is_nil(theObject) )
118 return aGEOMObject._retn();
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 =
126 GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry());
127 if ( anObject.IsNull() )
128 return aGEOMObject._retn();
131 Handle(GEOM_Object) aNewObject = GetOperations()->ShapeProcess( anObject,
132 Convert( theOperations ), Convert( theParams ), Convert( theValues ) );
133 if ( !GetOperations()->IsDone() || aNewObject.IsNull() )
134 return aGEOMObject._retn();
136 return GetObject( aNewObject );
139 //=============================================================================
141 * GetShapeProcessParameters
143 //=============================================================================
144 void GEOM_IHealingOperations_i::GetShapeProcessParameters(GEOM::string_array_out theOperations,
145 GEOM::string_array_out theParams,
146 GEOM::string_array_out theValues)
148 GEOM::string_array_var anOpArray = new GEOM::string_array();
149 GEOM::string_array_var aParArray = new GEOM::string_array();
150 GEOM::string_array_var aValArray = new GEOM::string_array();
152 // retrieve the values as stl-lists
153 list<string> operationsList, paramsList, valuesList;
154 GetOperations()->GetShapeProcessParameters( operationsList, paramsList, valuesList );
155 const int opSize = operationsList.size(),
156 parSize = paramsList.size(),
157 valSize = valuesList.size();
159 if ( opSize >= 0 && parSize >= 0 && parSize == valSize ) {
160 // allocate the CORBA arrays, sizes == returned lists' sizes
161 anOpArray->length(opSize);
162 aParArray->length(parSize);
163 aValArray->length(valSize);
165 // fill the local CORBA arrays with values from lists
166 list<string>::iterator opIt, parIt, valIt;
168 for ( opIt = operationsList.begin(); opIt != operationsList.end(); i++,++opIt )
169 anOpArray[i] = CORBA::string_dup( (*opIt).c_str() );
171 for ( i = 0, parIt = paramsList.begin(), valIt = valuesList.begin();
172 parIt != paramsList.end(); i++, ++parIt,++valIt ) {
173 aParArray[i] = CORBA::string_dup( (*parIt).c_str() );
174 aValArray[i] = CORBA::string_dup( (*valIt).c_str() );
178 // initialize out-parameters with local arrays
179 theOperations = anOpArray._retn();
180 theParams = aParArray._retn();
181 theValues = aValArray._retn();
184 //=============================================================================
186 * GetOperatorParameters
188 //=============================================================================
189 void GEOM_IHealingOperations_i::GetOperatorParameters (const char* theOperator,
190 GEOM::string_array_out theParams,
191 GEOM::string_array_out theValues)
193 GEOM::string_array_var aParArray = new GEOM::string_array();
194 GEOM::string_array_var aValArray = new GEOM::string_array();
196 // retrieve the values as stl-lists
197 list<string> paramsList, valuesList;
198 if ( GetOperations()->GetOperatorParameters( theOperator, paramsList, valuesList ) ) {
199 const int parSize = paramsList.size(), valSize = valuesList.size();
201 if ( parSize == valSize ) {
202 aParArray->length(parSize);
203 aValArray->length(valSize);
205 // fill the local CORBA arrays with values from lists
206 list<string>::iterator parIt, valIt;
208 for ( i = 0, parIt = paramsList.begin(), valIt = valuesList.begin();
209 parIt != paramsList.end(); i++, ++parIt,++valIt ) {
210 aParArray[i] = CORBA::string_dup( (*parIt).c_str() );
211 aValArray[i] = CORBA::string_dup( (*valIt).c_str() );
216 // initialize out-parameters with local arrays
217 theParams = aParArray._retn();
218 theValues = aValArray._retn();
221 //=============================================================================
225 //=============================================================================
226 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::SuppressFaces (GEOM::GEOM_Object_ptr theObject,
227 const GEOM::short_array& theFaces)
229 GEOM::GEOM_Object_var aGEOMObject;
231 // Set a not done flag
232 GetOperations()->SetNotDone();
235 if ( CORBA::is_nil(theObject) ) // if theFaces is empty - it's OK, it means that ALL faces must be removed
236 return aGEOMObject._retn();
238 // Get the object itself
239 Handle(GEOM_Object) anObject =
240 GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry());
241 if (anObject.IsNull())
242 return aGEOMObject._retn();
245 Handle(GEOM_Object) aNewObject =
246 GetOperations()->SuppressFaces( anObject, Convert( theFaces ) );
247 if (!GetOperations()->IsDone() || aNewObject.IsNull())
248 return aGEOMObject._retn();
250 return GetObject( aNewObject );
253 //=============================================================================
257 //=============================================================================
258 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::CloseContour (GEOM::GEOM_Object_ptr theObject,
259 const GEOM::short_array& theWires,
260 CORBA::Boolean isCommonVertex)
262 GEOM::GEOM_Object_var aGEOMObject;
264 // Set a not done flag
265 GetOperations()->SetNotDone();
268 if ( CORBA::is_nil(theObject) )
269 return aGEOMObject._retn();
271 // Get the object itself
272 Handle(GEOM_Object) anObject =
273 GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry());
274 if (anObject.IsNull())
275 return aGEOMObject._retn();
278 Handle(GEOM_Object) aNewObject =
279 GetOperations()->CloseContour( anObject, Convert( theWires ), isCommonVertex );
280 if (!GetOperations()->IsDone() || aNewObject.IsNull())
281 return aGEOMObject._retn();
283 return GetObject(aNewObject);
286 //=============================================================================
290 //=============================================================================
291 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::RemoveIntWires (GEOM::GEOM_Object_ptr theObject,
292 const GEOM::short_array& theWires)
294 GEOM::GEOM_Object_var aGEOMObject;
296 // Set a not done flag
297 GetOperations()->SetNotDone();
300 if ( CORBA::is_nil(theObject) ) // if theWires is empty - it's OK, it means that ALL wires should be removed
301 return aGEOMObject._retn();
303 // Get the object itself
304 Handle(GEOM_Object) anObject =
305 GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry());
306 if (anObject.IsNull())
307 return aGEOMObject._retn();
310 Handle(GEOM_Object) aNewObject =
311 GetOperations()->RemoveIntWires( anObject, Convert( theWires ) );
312 if (!GetOperations()->IsDone() || aNewObject.IsNull())
313 return aGEOMObject._retn();
315 return GetObject(aNewObject);
318 //=============================================================================
322 //=============================================================================
323 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::FillHoles (GEOM::GEOM_Object_ptr theObject,
324 const GEOM::short_array& theWires)
326 GEOM::GEOM_Object_var aGEOMObject;
328 // Set a not done flag
329 GetOperations()->SetNotDone();
332 if ( CORBA::is_nil(theObject) ) // if theWires is empty - it's OK, it means that ALL wires should be removed
333 return aGEOMObject._retn();
335 // Get the object itself
336 Handle(GEOM_Object) anObject =
337 GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry());
338 if (anObject.IsNull())
339 return aGEOMObject._retn();
342 Handle(GEOM_Object) aNewObject =
343 GetOperations()->FillHoles( anObject, Convert( theWires ) );
344 if (!GetOperations()->IsDone() || aNewObject.IsNull())
345 return aGEOMObject._retn();
347 return GetObject(aNewObject);
350 //=============================================================================
354 //=============================================================================
355 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::Sew (GEOM::GEOM_Object_ptr theObject,
356 CORBA::Double theTolerance)
358 GEOM::GEOM_Object_var aGEOMObject;
360 // Set a not done flag
361 GetOperations()->SetNotDone();
364 if ( CORBA::is_nil(theObject) || theTolerance < 0 )
365 return aGEOMObject._retn();
367 // Get the object itself
368 Handle(GEOM_Object) anObject =
369 GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry());
370 if (anObject.IsNull())
371 return aGEOMObject._retn();
374 Handle(GEOM_Object) aNewObject =
375 GetOperations()->Sew( anObject, theTolerance );
376 if (!GetOperations()->IsDone() || aNewObject.IsNull())
377 return aGEOMObject._retn();
379 return GetObject(aNewObject);
382 //=============================================================================
386 //=============================================================================
387 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::DivideEdge (GEOM::GEOM_Object_ptr theObject,
388 CORBA::Short theIndex,
389 CORBA::Double theValue,
390 CORBA::Boolean isByParameter)
392 GEOM::GEOM_Object_var aGEOMObject;
394 // Set a not done flag
395 GetOperations()->SetNotDone();
398 if ( CORBA::is_nil(theObject) || theValue < 0 || theValue > 1 )
399 return aGEOMObject._retn();
401 // Get the object itself
402 Handle(GEOM_Object) anObject =
403 GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry());
404 if (anObject.IsNull())
405 return aGEOMObject._retn();
408 Handle(GEOM_Object) aNewObject =
409 GetOperations()->DivideEdge( anObject, theIndex, theValue, isByParameter );
410 if (!GetOperations()->IsDone() || aNewObject.IsNull())
411 return aGEOMObject._retn();
413 return GetObject(aNewObject);
416 //=============================================================================
420 //=============================================================================
421 CORBA::Boolean GEOM_IHealingOperations_i::GetFreeBoundary ( GEOM::GEOM_Object_ptr theObject,
422 GEOM::ListOfGO_out theClosedWires,
423 GEOM::ListOfGO_out theOpenWires )
425 theClosedWires = new GEOM::ListOfGO;
426 theOpenWires = new GEOM::ListOfGO;
428 // Set a not done flag
429 GetOperations()->SetNotDone();
431 if ( CORBA::is_nil(theObject) )
434 // Get the object itself
435 Handle(GEOM_Object) anObject =
436 GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry());
437 if (anObject.IsNull())
440 Handle(TColStd_HSequenceOfTransient) aClosed = new TColStd_HSequenceOfTransient();
441 Handle(TColStd_HSequenceOfTransient) anOpen = new TColStd_HSequenceOfTransient();
442 bool res = GetOperations()->GetFreeBoundary( anObject, aClosed, anOpen );
444 if ( !GetOperations()->IsDone() || !res )
447 int i, n = aClosed->Length();
448 theClosedWires->length( n );
449 for ( i = 1; i <= n; i++ )
450 (*theClosedWires)[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aClosed->Value(i)));
452 n = anOpen->Length();
453 theOpenWires->length( n );
454 for ( i = 1, n = anOpen->Length(); i <= n; i++ )
455 (*theOpenWires)[i-1] = GetObject(Handle(GEOM_Object)::DownCast(anOpen->Value(i)));
461 //=============================================================================
465 //=============================================================================
466 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::ChangeOrientation (GEOM::GEOM_Object_ptr theObject)
468 GEOM::GEOM_Object_var aGEOMObject;
470 // Set a not done flag
471 GetOperations()->SetNotDone();
474 if ( CORBA::is_nil(theObject) )
475 return aGEOMObject._retn();
477 aGEOMObject = GEOM::GEOM_Object::_duplicate(theObject);
479 // Get the object itself
480 Handle(GEOM_Object) anObject =
481 GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry());
482 if (anObject.IsNull())
483 return aGEOMObject._retn();
486 // Handle(GEOM_Object) aNewObject =
487 GetOperations()->ChangeOrientation( anObject );
488 // if (!GetOperations()->IsDone() || aNewObject.IsNull())
489 // return aGEOMObject._retn();
491 //return GetObject(aNewObject);
492 return aGEOMObject._retn();
496 //=============================================================================
498 * ChangeOrientationCopy
500 //=============================================================================
501 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::ChangeOrientationCopy (GEOM::GEOM_Object_ptr theObject)
503 GEOM::GEOM_Object_var aGEOMObject;
505 // Set a not done flag
506 GetOperations()->SetNotDone();
509 if ( CORBA::is_nil(theObject) )
510 return aGEOMObject._retn();
512 // Get the object itself
513 Handle(GEOM_Object) anObject =
514 GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry());
515 if (anObject.IsNull())
516 return aGEOMObject._retn();
519 Handle(GEOM_Object) aNewObject =
520 GetOperations()->ChangeOrientationCopy( anObject );
521 if (!GetOperations()->IsDone() || aNewObject.IsNull())
522 return aGEOMObject._retn();
524 return GetObject(aNewObject);