1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include <Standard_Stream.hxx>
24 #include "GEOM_IHealingOperations_i.hh"
25 #include "GEOM_Engine.hxx"
26 #include "GEOM_Object.hxx"
28 #include "utilities.h"
30 #include "Utils_ExceptHandlers.hxx"
32 #include <TColStd_HSequenceOfTransient.hxx>
34 //=============================================================================
38 //=============================================================================
40 GEOM_IHealingOperations_i::GEOM_IHealingOperations_i (PortableServer::POA_ptr thePOA,
41 GEOM::GEOM_Gen_ptr theEngine,
42 ::GEOMImpl_IHealingOperations* theImpl)
43 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
45 MESSAGE("GEOM_IHealingOperations_i::GEOM_IHealingOperations_i");
48 //=============================================================================
52 //=============================================================================
54 GEOM_IHealingOperations_i::~GEOM_IHealingOperations_i()
56 MESSAGE("GEOM_IHealingOperations_i::~GEOM_IHealingOperations_i");
59 //=============================================================================
63 //=============================================================================
64 Handle(TColStd_HArray1OfInteger) GEOM_IHealingOperations_i::Convert
65 (const GEOM::short_array& theInArray)
67 Handle(TColStd_HArray1OfInteger) anOutArray;
68 int n = theInArray.length();
71 anOutArray = new TColStd_HArray1OfInteger( 1, n );
72 for (int i = 0; i < n; i++)
73 anOutArray->SetValue( i+1, theInArray[i] );
77 //=============================================================================
81 //=============================================================================
82 Handle(TColStd_HArray1OfExtendedString) GEOM_IHealingOperations_i::Convert
83 (const GEOM::string_array& theInArray)
85 Handle(TColStd_HArray1OfExtendedString) anOutArray;
86 int n = theInArray.length();
89 anOutArray = new TColStd_HArray1OfExtendedString( 1, n );
91 for ( int i = 0; i < n; i++ )
93 str = CORBA::string_dup( theInArray[i] );
94 anOutArray->SetValue( i+1, TCollection_ExtendedString( str ) );
99 //=============================================================================
103 //=============================================================================
104 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::ProcessShape (GEOM::GEOM_Object_ptr theObject,
105 const GEOM::string_array& theOperations,
106 const GEOM::string_array& theParams,
107 const GEOM::string_array& theValues)
109 GEOM::GEOM_Object_var aGEOMObject;
111 // Set a not done flag
112 GetOperations()->SetNotDone();
115 if ( CORBA::is_nil(theObject) )
116 return aGEOMObject._retn();
118 // Check if theOperations has more than 0 elements and theParams and theValues have the same length
119 // if ( theOperations.length() <= 0 || theParams.length() != theValues.length() )
120 // return aGEOMObject._retn();
122 // Get the object itself
123 Handle(GEOM_Object) anObject =
124 GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry());
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 list<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 list<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 list<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 list<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();
233 if ( CORBA::is_nil(theObject) ) // if theFaces is empty - it's OK, it means that ALL faces must be removed
234 return aGEOMObject._retn();
236 // Get the object itself
237 Handle(GEOM_Object) anObject =
238 GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry());
239 if (anObject.IsNull())
240 return aGEOMObject._retn();
243 Handle(GEOM_Object) aNewObject =
244 GetOperations()->SuppressFaces( anObject, Convert( theFaces ) );
245 if (!GetOperations()->IsDone() || aNewObject.IsNull())
246 return aGEOMObject._retn();
248 return GetObject( aNewObject );
251 //=============================================================================
255 //=============================================================================
256 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::CloseContour (GEOM::GEOM_Object_ptr theObject,
257 const GEOM::short_array& theWires,
258 CORBA::Boolean isCommonVertex)
260 GEOM::GEOM_Object_var aGEOMObject;
262 // Set a not done flag
263 GetOperations()->SetNotDone();
266 if ( CORBA::is_nil(theObject) )
267 return aGEOMObject._retn();
269 // Get the object itself
270 Handle(GEOM_Object) anObject =
271 GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry());
272 if (anObject.IsNull())
273 return aGEOMObject._retn();
276 Handle(GEOM_Object) aNewObject =
277 GetOperations()->CloseContour( anObject, Convert( theWires ), isCommonVertex );
278 if (!GetOperations()->IsDone() || aNewObject.IsNull())
279 return aGEOMObject._retn();
281 return GetObject(aNewObject);
284 //=============================================================================
288 //=============================================================================
289 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::RemoveIntWires (GEOM::GEOM_Object_ptr theObject,
290 const GEOM::short_array& theWires)
292 GEOM::GEOM_Object_var aGEOMObject;
294 // Set a not done flag
295 GetOperations()->SetNotDone();
298 if ( CORBA::is_nil(theObject) ) // if theWires is empty - it's OK, it means that ALL wires should be removed
299 return aGEOMObject._retn();
301 // Get the object itself
302 Handle(GEOM_Object) anObject =
303 GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry());
304 if (anObject.IsNull())
305 return aGEOMObject._retn();
308 Handle(GEOM_Object) aNewObject =
309 GetOperations()->RemoveIntWires( anObject, Convert( theWires ) );
310 if (!GetOperations()->IsDone() || aNewObject.IsNull())
311 return aGEOMObject._retn();
313 return GetObject(aNewObject);
316 //=============================================================================
320 //=============================================================================
321 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::FillHoles (GEOM::GEOM_Object_ptr theObject,
322 const GEOM::short_array& theWires)
324 GEOM::GEOM_Object_var aGEOMObject;
326 // Set a not done flag
327 GetOperations()->SetNotDone();
330 if ( CORBA::is_nil(theObject) ) // if theWires is empty - it's OK, it means that ALL wires should be removed
331 return aGEOMObject._retn();
333 // Get the object itself
334 Handle(GEOM_Object) anObject =
335 GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry());
336 if (anObject.IsNull())
337 return aGEOMObject._retn();
340 Handle(GEOM_Object) aNewObject =
341 GetOperations()->FillHoles( anObject, Convert( theWires ) );
342 if (!GetOperations()->IsDone() || aNewObject.IsNull())
343 return aGEOMObject._retn();
345 return GetObject(aNewObject);
348 //=============================================================================
352 //=============================================================================
353 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::Sew (GEOM::GEOM_Object_ptr theObject,
354 CORBA::Double theTolerance)
356 GEOM::GEOM_Object_var aGEOMObject;
358 // Set a not done flag
359 GetOperations()->SetNotDone();
362 if ( CORBA::is_nil(theObject) || theTolerance < 0 )
363 return aGEOMObject._retn();
365 // Get the object itself
366 Handle(GEOM_Object) anObject =
367 GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry());
368 if (anObject.IsNull())
369 return aGEOMObject._retn();
372 Handle(GEOM_Object) aNewObject =
373 GetOperations()->Sew( anObject, theTolerance );
374 if (!GetOperations()->IsDone() || aNewObject.IsNull())
375 return aGEOMObject._retn();
377 return GetObject(aNewObject);
380 //=============================================================================
384 //=============================================================================
385 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::DivideEdge (GEOM::GEOM_Object_ptr theObject,
386 CORBA::Short theIndex,
387 CORBA::Double theValue,
388 CORBA::Boolean isByParameter)
390 GEOM::GEOM_Object_var aGEOMObject;
392 // Set a not done flag
393 GetOperations()->SetNotDone();
396 if ( CORBA::is_nil(theObject) || theValue < 0 || theValue > 1 )
397 return aGEOMObject._retn();
399 // Get the object itself
400 Handle(GEOM_Object) anObject =
401 GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry());
402 if (anObject.IsNull())
403 return aGEOMObject._retn();
406 Handle(GEOM_Object) aNewObject =
407 GetOperations()->DivideEdge( anObject, theIndex, theValue, isByParameter );
408 if (!GetOperations()->IsDone() || aNewObject.IsNull())
409 return aGEOMObject._retn();
411 return GetObject(aNewObject);
414 //=============================================================================
418 //=============================================================================
419 CORBA::Boolean GEOM_IHealingOperations_i::GetFreeBoundary ( GEOM::GEOM_Object_ptr theObject,
420 GEOM::ListOfGO_out theClosedWires,
421 GEOM::ListOfGO_out theOpenWires )
423 theClosedWires = new GEOM::ListOfGO;
424 theOpenWires = new GEOM::ListOfGO;
426 // Set a not done flag
427 GetOperations()->SetNotDone();
429 if ( CORBA::is_nil(theObject) )
432 // Get the object itself
433 Handle(GEOM_Object) anObject =
434 GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry());
435 if (anObject.IsNull())
438 Handle(TColStd_HSequenceOfTransient) aClosed = new TColStd_HSequenceOfTransient();
439 Handle(TColStd_HSequenceOfTransient) anOpen = new TColStd_HSequenceOfTransient();
440 bool res = GetOperations()->GetFreeBoundary( anObject, aClosed, anOpen );
442 if ( !GetOperations()->IsDone() || !res )
445 int i, n = aClosed->Length();
446 theClosedWires->length( n );
447 for ( i = 1; i <= n; i++ )
448 (*theClosedWires)[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aClosed->Value(i)));
450 n = anOpen->Length();
451 theOpenWires->length( n );
452 for ( i = 1, n = anOpen->Length(); i <= n; i++ )
453 (*theOpenWires)[i-1] = GetObject(Handle(GEOM_Object)::DownCast(anOpen->Value(i)));
459 //=============================================================================
463 //=============================================================================
464 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::ChangeOrientation (GEOM::GEOM_Object_ptr theObject)
466 GEOM::GEOM_Object_var aGEOMObject;
468 // Set a not done flag
469 GetOperations()->SetNotDone();
472 if ( CORBA::is_nil(theObject) )
473 return aGEOMObject._retn();
475 aGEOMObject = GEOM::GEOM_Object::_duplicate(theObject);
477 // Get the object itself
478 Handle(GEOM_Object) anObject =
479 GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry());
480 if (anObject.IsNull())
481 return aGEOMObject._retn();
484 // Handle(GEOM_Object) aNewObject =
485 GetOperations()->ChangeOrientation( anObject );
486 // if (!GetOperations()->IsDone() || aNewObject.IsNull())
487 // return aGEOMObject._retn();
489 //return GetObject(aNewObject);
490 return aGEOMObject._retn();
494 //=============================================================================
496 * ChangeOrientationCopy
498 //=============================================================================
499 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::ChangeOrientationCopy (GEOM::GEOM_Object_ptr theObject)
501 GEOM::GEOM_Object_var aGEOMObject;
503 // Set a not done flag
504 GetOperations()->SetNotDone();
507 if ( CORBA::is_nil(theObject) )
508 return aGEOMObject._retn();
510 // Get the object itself
511 Handle(GEOM_Object) anObject =
512 GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry());
513 if (anObject.IsNull())
514 return aGEOMObject._retn();
517 Handle(GEOM_Object) aNewObject =
518 GetOperations()->ChangeOrientationCopy( anObject );
519 if (!GetOperations()->IsDone() || aNewObject.IsNull())
520 return aGEOMObject._retn();
522 return GetObject(aNewObject);