1 #include <Standard_Stream.hxx>
5 #include "GEOM_IHealingOperations_i.hh"
6 #include "GEOM_Engine.hxx"
7 #include "GEOM_Object.hxx"
11 #include "Utils_ExceptHandlers.hxx"
13 #include <TColStd_HSequenceOfTransient.hxx>
15 //=============================================================================
19 //=============================================================================
21 GEOM_IHealingOperations_i::GEOM_IHealingOperations_i (PortableServer::POA_ptr thePOA,
22 GEOM::GEOM_Gen_ptr theEngine,
23 ::GEOMImpl_IHealingOperations* theImpl)
24 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
26 MESSAGE("GEOM_IHealingOperations_i::GEOM_IHealingOperations_i");
29 //=============================================================================
33 //=============================================================================
35 GEOM_IHealingOperations_i::~GEOM_IHealingOperations_i()
37 MESSAGE("GEOM_IHealingOperations_i::~GEOM_IHealingOperations_i");
40 //=============================================================================
44 //=============================================================================
45 Handle(TColStd_HArray1OfInteger) GEOM_IHealingOperations_i::Convert
46 (const GEOM::short_array& theInArray)
48 Handle(TColStd_HArray1OfInteger) anOutArray;
49 int n = theInArray.length();
52 anOutArray = new TColStd_HArray1OfInteger( 1, n );
53 for (int i = 0; i < n; i++)
54 anOutArray->SetValue( i+1, theInArray[i] );
58 //=============================================================================
62 //=============================================================================
63 Handle(TColStd_HArray1OfExtendedString) GEOM_IHealingOperations_i::Convert
64 (const GEOM::string_array& theInArray)
66 Handle(TColStd_HArray1OfExtendedString) anOutArray;
67 int n = theInArray.length();
70 anOutArray = new TColStd_HArray1OfExtendedString( 1, n );
72 for ( int i = 0; i < n; i++ )
74 str = CORBA::string_dup( theInArray[i] );
75 anOutArray->SetValue( i+1, TCollection_ExtendedString( str ) );
80 //=============================================================================
84 //=============================================================================
85 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::ProcessShape (GEOM::GEOM_Object_ptr theObject,
86 const GEOM::string_array& theOperations,
87 const GEOM::string_array& theParams,
88 const GEOM::string_array& theValues)
90 GEOM::GEOM_Object_var aGEOMObject;
92 // Set a not done flag
93 GetOperations()->SetNotDone();
96 if ( CORBA::is_nil(theObject) )
97 return aGEOMObject._retn();
99 // Check if theOperations has more than 0 elements and theParams and theValues have the same length
100 // if ( theOperations.length() <= 0 || theParams.length() != theValues.length() )
101 // return aGEOMObject._retn();
103 // Get the object itself
104 Handle(GEOM_Object) anObject =
105 GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry());
106 if ( anObject.IsNull() )
107 return aGEOMObject._retn();
110 Handle(GEOM_Object) aNewObject = GetOperations()->ShapeProcess( anObject,
111 Convert( theOperations ), Convert( theParams ), Convert( theValues ) );
112 if ( !GetOperations()->IsDone() || aNewObject.IsNull() )
113 return aGEOMObject._retn();
115 return GetObject( aNewObject );
118 //=============================================================================
120 * GetShapeProcessParameters
122 //=============================================================================
123 void GEOM_IHealingOperations_i::GetShapeProcessParameters(GEOM::string_array_out theOperations,
124 GEOM::string_array_out theParams,
125 GEOM::string_array_out theValues)
127 GEOM::string_array_var anOpArray = new GEOM::string_array();
128 GEOM::string_array_var aParArray = new GEOM::string_array();
129 GEOM::string_array_var aValArray = new GEOM::string_array();
131 // retrieve the values as stl-lists
132 list<string> operationsList, paramsList, valuesList;
133 GetOperations()->GetShapeProcessParameters( operationsList, paramsList, valuesList );
134 const int opSize = operationsList.size(),
135 parSize = paramsList.size(),
136 valSize = valuesList.size();
138 if ( opSize >= 0 && parSize >= 0 && parSize == valSize ) {
139 // allocate the CORBA arrays, sizes == returned lists' sizes
140 anOpArray->length(opSize);
141 aParArray->length(parSize);
142 aValArray->length(valSize);
144 // fill the local CORBA arrays with values from lists
145 list<string>::iterator opIt, parIt, valIt;
147 for ( opIt = operationsList.begin(); opIt != operationsList.end(); i++,++opIt )
148 anOpArray[i] = CORBA::string_dup( (*opIt).c_str() );
150 for ( i = 0, parIt = paramsList.begin(), valIt = valuesList.begin();
151 parIt != paramsList.end(); i++, ++parIt,++valIt ) {
152 aParArray[i] = CORBA::string_dup( (*parIt).c_str() );
153 aValArray[i] = CORBA::string_dup( (*valIt).c_str() );
157 // initialize out-parameters with local arrays
158 theOperations = anOpArray._retn();
159 theParams = aParArray._retn();
160 theValues = aValArray._retn();
163 //=============================================================================
165 * GetOperatorParameters
167 //=============================================================================
168 void GEOM_IHealingOperations_i::GetOperatorParameters (const char* theOperator,
169 GEOM::string_array_out theParams,
170 GEOM::string_array_out theValues)
172 GEOM::string_array_var aParArray = new GEOM::string_array();
173 GEOM::string_array_var aValArray = new GEOM::string_array();
175 // retrieve the values as stl-lists
176 list<string> paramsList, valuesList;
177 if ( GetOperations()->GetOperatorParameters( theOperator, paramsList, valuesList ) ) {
178 const int parSize = paramsList.size(), valSize = valuesList.size();
180 if ( parSize == valSize ) {
181 aParArray->length(parSize);
182 aValArray->length(valSize);
184 // fill the local CORBA arrays with values from lists
185 list<string>::iterator parIt, valIt;
187 for ( i = 0, parIt = paramsList.begin(), valIt = valuesList.begin();
188 parIt != paramsList.end(); i++, ++parIt,++valIt ) {
189 aParArray[i] = CORBA::string_dup( (*parIt).c_str() );
190 aValArray[i] = CORBA::string_dup( (*valIt).c_str() );
195 // initialize out-parameters with local arrays
196 theParams = aParArray._retn();
197 theValues = aValArray._retn();
200 //=============================================================================
204 //=============================================================================
205 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::SuppressFaces (GEOM::GEOM_Object_ptr theObject,
206 const GEOM::short_array& theFaces)
208 GEOM::GEOM_Object_var aGEOMObject;
210 // Set a not done flag
211 GetOperations()->SetNotDone();
214 if ( CORBA::is_nil(theObject) ) // if theFaces is empty - it's OK, it means that ALL faces must be removed
215 return aGEOMObject._retn();
217 // Get the object itself
218 Handle(GEOM_Object) anObject =
219 GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry());
220 if (anObject.IsNull())
221 return aGEOMObject._retn();
224 Handle(GEOM_Object) aNewObject =
225 GetOperations()->SuppressFaces( anObject, Convert( theFaces ) );
226 if (!GetOperations()->IsDone() || aNewObject.IsNull())
227 return aGEOMObject._retn();
229 return GetObject( aNewObject );
232 //=============================================================================
236 //=============================================================================
237 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::CloseContour (GEOM::GEOM_Object_ptr theObject,
238 const GEOM::short_array& theWires,
239 CORBA::Boolean isCommonVertex)
241 GEOM::GEOM_Object_var aGEOMObject;
243 // Set a not done flag
244 GetOperations()->SetNotDone();
247 if ( CORBA::is_nil(theObject) )
248 return aGEOMObject._retn();
250 // Get the object itself
251 Handle(GEOM_Object) anObject =
252 GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry());
253 if (anObject.IsNull())
254 return aGEOMObject._retn();
257 Handle(GEOM_Object) aNewObject =
258 GetOperations()->CloseContour( anObject, Convert( theWires ), isCommonVertex );
259 if (!GetOperations()->IsDone() || aNewObject.IsNull())
260 return aGEOMObject._retn();
262 return GetObject(aNewObject);
265 //=============================================================================
269 //=============================================================================
270 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::RemoveIntWires (GEOM::GEOM_Object_ptr theObject,
271 const GEOM::short_array& theWires)
273 GEOM::GEOM_Object_var aGEOMObject;
275 // Set a not done flag
276 GetOperations()->SetNotDone();
279 if ( CORBA::is_nil(theObject) ) // if theWires is empty - it's OK, it means that ALL wires should be removed
280 return aGEOMObject._retn();
282 // Get the object itself
283 Handle(GEOM_Object) anObject =
284 GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry());
285 if (anObject.IsNull())
286 return aGEOMObject._retn();
289 Handle(GEOM_Object) aNewObject =
290 GetOperations()->RemoveIntWires( anObject, Convert( theWires ) );
291 if (!GetOperations()->IsDone() || aNewObject.IsNull())
292 return aGEOMObject._retn();
294 return GetObject(aNewObject);
297 //=============================================================================
301 //=============================================================================
302 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::FillHoles (GEOM::GEOM_Object_ptr theObject,
303 const GEOM::short_array& theWires)
305 GEOM::GEOM_Object_var aGEOMObject;
307 // Set a not done flag
308 GetOperations()->SetNotDone();
311 if ( CORBA::is_nil(theObject) ) // if theWires is empty - it's OK, it means that ALL wires should be removed
312 return aGEOMObject._retn();
314 // Get the object itself
315 Handle(GEOM_Object) anObject =
316 GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry());
317 if (anObject.IsNull())
318 return aGEOMObject._retn();
321 Handle(GEOM_Object) aNewObject =
322 GetOperations()->FillHoles( anObject, Convert( theWires ) );
323 if (!GetOperations()->IsDone() || aNewObject.IsNull())
324 return aGEOMObject._retn();
326 return GetObject(aNewObject);
329 //=============================================================================
333 //=============================================================================
334 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::Sew (GEOM::GEOM_Object_ptr theObject,
335 CORBA::Double theTolerance)
337 GEOM::GEOM_Object_var aGEOMObject;
339 // Set a not done flag
340 GetOperations()->SetNotDone();
343 if ( CORBA::is_nil(theObject) || theTolerance < 0 )
344 return aGEOMObject._retn();
346 // Get the object itself
347 Handle(GEOM_Object) anObject =
348 GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry());
349 if (anObject.IsNull())
350 return aGEOMObject._retn();
353 Handle(GEOM_Object) aNewObject =
354 GetOperations()->Sew( anObject, theTolerance );
355 if (!GetOperations()->IsDone() || aNewObject.IsNull())
356 return aGEOMObject._retn();
358 return GetObject(aNewObject);
361 //=============================================================================
365 //=============================================================================
366 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::DivideEdge (GEOM::GEOM_Object_ptr theObject,
367 CORBA::Short theIndex,
368 CORBA::Double theValue,
369 CORBA::Boolean isByParameter)
371 GEOM::GEOM_Object_var aGEOMObject;
373 // Set a not done flag
374 GetOperations()->SetNotDone();
377 if ( CORBA::is_nil(theObject) || theValue < 0 || theValue > 1 )
378 return aGEOMObject._retn();
380 // Get the object itself
381 Handle(GEOM_Object) anObject =
382 GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry());
383 if (anObject.IsNull())
384 return aGEOMObject._retn();
387 Handle(GEOM_Object) aNewObject =
388 GetOperations()->DivideEdge( anObject, theIndex, theValue, isByParameter );
389 if (!GetOperations()->IsDone() || aNewObject.IsNull())
390 return aGEOMObject._retn();
392 return GetObject(aNewObject);
395 //=============================================================================
399 //=============================================================================
400 CORBA::Boolean GEOM_IHealingOperations_i::GetFreeBoundary ( GEOM::GEOM_Object_ptr theObject,
401 GEOM::ListOfGO_out theClosedWires,
402 GEOM::ListOfGO_out theOpenWires )
404 theClosedWires = new GEOM::ListOfGO;
405 theOpenWires = new GEOM::ListOfGO;
407 // Set a not done flag
408 GetOperations()->SetNotDone();
410 if ( CORBA::is_nil(theObject) )
413 // Get the object itself
414 Handle(GEOM_Object) anObject =
415 GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry());
416 if (anObject.IsNull())
419 Handle(TColStd_HSequenceOfTransient) aClosed = new TColStd_HSequenceOfTransient();
420 Handle(TColStd_HSequenceOfTransient) anOpen = new TColStd_HSequenceOfTransient();
421 bool res = GetOperations()->GetFreeBoundary( anObject, aClosed, anOpen );
423 if ( !GetOperations()->IsDone() || !res )
426 int i, n = aClosed->Length();
427 theClosedWires->length( n );
428 for ( i = 1; i <= n; i++ )
429 (*theClosedWires)[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aClosed->Value(i)));
431 n = anOpen->Length();
432 theOpenWires->length( n );
433 for ( i = 1, n = anOpen->Length(); i <= n; i++ )
434 (*theOpenWires)[i-1] = GetObject(Handle(GEOM_Object)::DownCast(anOpen->Value(i)));