4 #include "GEOM_IHealingOperations_i.hh"
5 #include "GEOM_Engine.hxx"
6 #include "GEOM_Object.hxx"
10 #include "Utils_ExceptHandlers.hxx"
12 #include <TColStd_HSequenceOfTransient.hxx>
14 //=============================================================================
18 //=============================================================================
20 GEOM_IHealingOperations_i::GEOM_IHealingOperations_i (PortableServer::POA_ptr thePOA,
21 GEOM::GEOM_Gen_ptr theEngine,
22 ::GEOMImpl_IHealingOperations* theImpl)
23 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
25 MESSAGE("GEOM_IHealingOperations_i::GEOM_IHealingOperations_i");
28 //=============================================================================
32 //=============================================================================
34 GEOM_IHealingOperations_i::~GEOM_IHealingOperations_i()
36 MESSAGE("GEOM_IHealingOperations_i::~GEOM_IHealingOperations_i");
39 //=============================================================================
43 //=============================================================================
44 Handle(TColStd_HArray1OfInteger) GEOM_IHealingOperations_i::Convert
45 (const GEOM::short_array& theInArray)
47 Handle(TColStd_HArray1OfInteger) anOutArray;
48 int n = theInArray.length();
51 anOutArray = new TColStd_HArray1OfInteger( 1, n );
52 for (int i = 0; i < n; i++)
53 anOutArray->SetValue( i+1, theInArray[i] );
57 //=============================================================================
61 //=============================================================================
62 Handle(TColStd_HArray1OfExtendedString) GEOM_IHealingOperations_i::Convert
63 (const GEOM::string_array& theInArray)
65 Handle(TColStd_HArray1OfExtendedString) anOutArray;
66 int n = theInArray.length();
69 anOutArray = new TColStd_HArray1OfExtendedString( 1, n );
71 for ( int i = 0; i < n; i++ )
73 str = CORBA::string_dup( theInArray[i] );
74 anOutArray->SetValue( i+1, TCollection_ExtendedString( str ) );
79 //=============================================================================
83 //=============================================================================
84 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::ProcessShape (GEOM::GEOM_Object_ptr theObject,
85 const GEOM::string_array& theOperations,
86 const GEOM::string_array& theParams,
87 const GEOM::string_array& theValues)
89 GEOM::GEOM_Object_var aGEOMObject;
91 // Set a not done flag
92 GetOperations()->SetNotDone();
95 if ( CORBA::is_nil(theObject) )
96 return aGEOMObject._retn();
98 // Check if theOperations has more than 0 elements and theParams and theValues have the same length
99 // if ( theOperations.length() <= 0 || theParams.length() != theValues.length() )
100 // return aGEOMObject._retn();
102 // Get the object itself
103 Handle(GEOM_Object) anObject =
104 GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry());
105 if ( anObject.IsNull() )
106 return aGEOMObject._retn();
109 Handle(GEOM_Object) aNewObject = GetOperations()->ShapeProcess( anObject,
110 Convert( theOperations ), Convert( theParams ), Convert( theValues ) );
111 if ( !GetOperations()->IsDone() || aNewObject.IsNull() )
112 return aGEOMObject._retn();
114 return GetObject( aNewObject );
117 //=============================================================================
119 * GetShapeProcessParameters
121 //=============================================================================
122 void GEOM_IHealingOperations_i::GetShapeProcessParameters(GEOM::string_array_out theOperations,
123 GEOM::string_array_out theParams,
124 GEOM::string_array_out theValues)
126 GEOM::string_array_var anOpArray = new GEOM::string_array();
127 GEOM::string_array_var aParArray = new GEOM::string_array();
128 GEOM::string_array_var aValArray = new GEOM::string_array();
130 // retrieve the values as stl-lists
131 list<string> operationsList, paramsList, valuesList;
132 GetOperations()->GetShapeProcessParameters( operationsList, paramsList, valuesList );
133 const int opSize = operationsList.size(),
134 parSize = paramsList.size(),
135 valSize = valuesList.size();
137 if ( opSize >= 0 && parSize >= 0 && parSize == valSize ) {
138 // allocate the CORBA arrays, sizes == returned lists' sizes
139 anOpArray->length(opSize);
140 aParArray->length(parSize);
141 aValArray->length(valSize);
143 // fill the local CORBA arrays with values from lists
144 list<string>::iterator opIt, parIt, valIt;
146 for ( opIt = operationsList.begin(); opIt != operationsList.end(); i++,++opIt )
147 anOpArray[i] = CORBA::string_dup( (*opIt).c_str() );
149 for ( i = 0, parIt = paramsList.begin(), valIt = valuesList.begin();
150 parIt != paramsList.end(); i++, ++parIt,++valIt ) {
151 aParArray[i] = CORBA::string_dup( (*parIt).c_str() );
152 aValArray[i] = CORBA::string_dup( (*valIt).c_str() );
156 // initialize out-parameters with local arrays
157 theOperations = anOpArray._retn();
158 theParams = aParArray._retn();
159 theValues = aValArray._retn();
162 //=============================================================================
164 * GetOperatorParameters
166 //=============================================================================
167 void GEOM_IHealingOperations_i::GetOperatorParameters (const char* theOperator,
168 GEOM::string_array_out theParams,
169 GEOM::string_array_out theValues)
171 GEOM::string_array_var aParArray = new GEOM::string_array();
172 GEOM::string_array_var aValArray = new GEOM::string_array();
174 // retrieve the values as stl-lists
175 list<string> paramsList, valuesList;
176 if ( GetOperations()->GetOperatorParameters( theOperator, paramsList, valuesList ) ) {
177 const int parSize = paramsList.size(), valSize = valuesList.size();
179 if ( parSize == valSize ) {
180 aParArray->length(parSize);
181 aValArray->length(valSize);
183 // fill the local CORBA arrays with values from lists
184 list<string>::iterator parIt, valIt;
186 for ( i = 0, parIt = paramsList.begin(), valIt = valuesList.begin();
187 parIt != paramsList.end(); i++, ++parIt,++valIt ) {
188 aParArray[i] = CORBA::string_dup( (*parIt).c_str() );
189 aValArray[i] = CORBA::string_dup( (*valIt).c_str() );
194 // initialize out-parameters with local arrays
195 theParams = aParArray._retn();
196 theValues = aValArray._retn();
199 //=============================================================================
203 //=============================================================================
204 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::SuppressFaces (GEOM::GEOM_Object_ptr theObject,
205 const GEOM::short_array& theFaces)
207 GEOM::GEOM_Object_var aGEOMObject;
209 // Set a not done flag
210 GetOperations()->SetNotDone();
213 if ( CORBA::is_nil(theObject) ) // if theFaces is empty - it's OK, it means that ALL faces must be removed
214 return aGEOMObject._retn();
216 // Get the object itself
217 Handle(GEOM_Object) anObject =
218 GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry());
219 if (anObject.IsNull())
220 return aGEOMObject._retn();
223 Handle(GEOM_Object) aNewObject =
224 GetOperations()->SuppressFaces( anObject, Convert( theFaces ) );
225 if (!GetOperations()->IsDone() || aNewObject.IsNull())
226 return aGEOMObject._retn();
228 return GetObject( aNewObject );
231 //=============================================================================
235 //=============================================================================
236 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::CloseContour (GEOM::GEOM_Object_ptr theObject,
237 const GEOM::short_array& theWires,
238 CORBA::Boolean isCommonVertex)
240 GEOM::GEOM_Object_var aGEOMObject;
242 // Set a not done flag
243 GetOperations()->SetNotDone();
246 if ( CORBA::is_nil(theObject) )
247 return aGEOMObject._retn();
249 // Get the object itself
250 Handle(GEOM_Object) anObject =
251 GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry());
252 if (anObject.IsNull())
253 return aGEOMObject._retn();
256 Handle(GEOM_Object) aNewObject =
257 GetOperations()->CloseContour( anObject, Convert( theWires ), isCommonVertex );
258 if (!GetOperations()->IsDone() || aNewObject.IsNull())
259 return aGEOMObject._retn();
261 return GetObject(aNewObject);
264 //=============================================================================
268 //=============================================================================
269 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::RemoveIntWires (GEOM::GEOM_Object_ptr theObject,
270 const GEOM::short_array& theWires)
272 GEOM::GEOM_Object_var aGEOMObject;
274 // Set a not done flag
275 GetOperations()->SetNotDone();
278 if ( CORBA::is_nil(theObject) ) // if theWires is empty - it's OK, it means that ALL wires should be removed
279 return aGEOMObject._retn();
281 // Get the object itself
282 Handle(GEOM_Object) anObject =
283 GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry());
284 if (anObject.IsNull())
285 return aGEOMObject._retn();
288 Handle(GEOM_Object) aNewObject =
289 GetOperations()->RemoveIntWires( anObject, Convert( theWires ) );
290 if (!GetOperations()->IsDone() || aNewObject.IsNull())
291 return aGEOMObject._retn();
293 return GetObject(aNewObject);
296 //=============================================================================
300 //=============================================================================
301 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::FillHoles (GEOM::GEOM_Object_ptr theObject,
302 const GEOM::short_array& theWires)
304 GEOM::GEOM_Object_var aGEOMObject;
306 // Set a not done flag
307 GetOperations()->SetNotDone();
310 if ( CORBA::is_nil(theObject) ) // if theWires is empty - it's OK, it means that ALL wires should be removed
311 return aGEOMObject._retn();
313 // Get the object itself
314 Handle(GEOM_Object) anObject =
315 GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry());
316 if (anObject.IsNull())
317 return aGEOMObject._retn();
320 Handle(GEOM_Object) aNewObject =
321 GetOperations()->FillHoles( anObject, Convert( theWires ) );
322 if (!GetOperations()->IsDone() || aNewObject.IsNull())
323 return aGEOMObject._retn();
325 return GetObject(aNewObject);
328 //=============================================================================
332 //=============================================================================
333 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::Sew (GEOM::GEOM_Object_ptr theObject,
334 CORBA::Double theTolerance)
336 GEOM::GEOM_Object_var aGEOMObject;
338 // Set a not done flag
339 GetOperations()->SetNotDone();
342 if ( CORBA::is_nil(theObject) || theTolerance < 0 )
343 return aGEOMObject._retn();
345 // Get the object itself
346 Handle(GEOM_Object) anObject =
347 GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry());
348 if (anObject.IsNull())
349 return aGEOMObject._retn();
352 Handle(GEOM_Object) aNewObject =
353 GetOperations()->Sew( anObject, theTolerance );
354 if (!GetOperations()->IsDone() || aNewObject.IsNull())
355 return aGEOMObject._retn();
357 return GetObject(aNewObject);
360 //=============================================================================
364 //=============================================================================
365 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::DivideEdge (GEOM::GEOM_Object_ptr theObject,
366 CORBA::Short theIndex,
367 CORBA::Double theValue,
368 CORBA::Boolean isByParameter)
370 GEOM::GEOM_Object_var aGEOMObject;
372 // Set a not done flag
373 GetOperations()->SetNotDone();
376 if ( CORBA::is_nil(theObject) || theValue < 0 || theValue > 1 )
377 return aGEOMObject._retn();
379 // Get the object itself
380 Handle(GEOM_Object) anObject =
381 GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry());
382 if (anObject.IsNull())
383 return aGEOMObject._retn();
386 Handle(GEOM_Object) aNewObject =
387 GetOperations()->DivideEdge( anObject, theIndex, theValue, isByParameter );
388 if (!GetOperations()->IsDone() || aNewObject.IsNull())
389 return aGEOMObject._retn();
391 return GetObject(aNewObject);
394 //=============================================================================
398 //=============================================================================
399 CORBA::Boolean GEOM_IHealingOperations_i::GetFreeBoundary ( GEOM::GEOM_Object_ptr theObject,
400 GEOM::ListOfGO_out theClosedWires,
401 GEOM::ListOfGO_out theOpenWires )
403 theClosedWires = new GEOM::ListOfGO;
404 theOpenWires = new GEOM::ListOfGO;
406 // Set a not done flag
407 GetOperations()->SetNotDone();
409 if ( CORBA::is_nil(theObject) )
412 // Get the object itself
413 Handle(GEOM_Object) anObject =
414 GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry());
415 if (anObject.IsNull())
418 Handle(TColStd_HSequenceOfTransient) aClosed = new TColStd_HSequenceOfTransient();
419 Handle(TColStd_HSequenceOfTransient) anOpen = new TColStd_HSequenceOfTransient();
420 bool res = GetOperations()->GetFreeBoundary( anObject, aClosed, anOpen );
422 if ( !GetOperations()->IsDone() || !res )
425 int i, n = aClosed->Length();
426 theClosedWires->length( n );
427 for ( i = 1; i <= n; i++ )
428 (*theClosedWires)[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aClosed->Value(i)));
430 n = anOpen->Length();
431 theOpenWires->length( n );
432 for ( i = 1, n = anOpen->Length(); i <= n; i++ )
433 (*theOpenWires)[i-1] = GetObject(Handle(GEOM_Object)::DownCast(anOpen->Value(i)));