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 // retrieve the values as stl-lists
127 list<string> operationsList, paramsList, valuesList;
128 GetOperations()->GetShapeProcessParameters( operationsList, paramsList, valuesList );
129 const int opSize = operationsList.size(),
130 parSize = paramsList.size(),
131 valSize = valuesList.size();
133 // returns in case of an error
134 if ( opSize < 0 || parSize < 0 || parSize != valSize )
137 // allocate the CORBA arrays, sizes == returned lists' sizes
138 GEOM::string_array_var anOpArray = new GEOM::string_array();
139 GEOM::string_array_var aParArray = new GEOM::string_array();
140 GEOM::string_array_var aValArray = new GEOM::string_array();
141 anOpArray->length(opSize);
142 aParArray->length(parSize);
143 aValArray->length(valSize);
145 // fill the local CORBA arrays with values from lists
146 list<string>::iterator opIt, parIt, valIt;
148 for ( opIt = operationsList.begin(); opIt != operationsList.end(); i++,++opIt )
149 anOpArray[i] = CORBA::string_dup( (*opIt).c_str() );
151 for ( i = 0, parIt = paramsList.begin(), valIt = valuesList.begin();
152 parIt != paramsList.end(); i++, ++parIt,++valIt )
154 aParArray[i] = CORBA::string_dup( (*parIt).c_str() );
155 aValArray[i] = CORBA::string_dup( (*valIt).c_str() );
158 // initialize out-parameters with local arrays
159 theOperations = anOpArray._retn();
160 theParams = aParArray._retn();
161 theValues = aValArray._retn();
164 //=============================================================================
168 //=============================================================================
169 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::SuppressFaces (GEOM::GEOM_Object_ptr theObject,
170 const GEOM::short_array& theFaces)
172 GEOM::GEOM_Object_var aGEOMObject;
174 // Set a not done flag
175 GetOperations()->SetNotDone();
178 if ( CORBA::is_nil(theObject) ) // if theFaces is empty - it's OK, it means that ALL faces must be removed
179 return aGEOMObject._retn();
181 // Get the object itself
182 Handle(GEOM_Object) anObject =
183 GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry());
184 if (anObject.IsNull())
185 return aGEOMObject._retn();
188 Handle(GEOM_Object) aNewObject =
189 GetOperations()->SuppressFaces( anObject, Convert( theFaces ) );
190 if (!GetOperations()->IsDone() || aNewObject.IsNull())
191 return aGEOMObject._retn();
193 return GetObject( aNewObject );
196 //=============================================================================
200 //=============================================================================
201 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::CloseContour (GEOM::GEOM_Object_ptr theObject,
202 const GEOM::short_array& theWires,
203 CORBA::Boolean isCommonVertex)
205 GEOM::GEOM_Object_var aGEOMObject;
207 // Set a not done flag
208 GetOperations()->SetNotDone();
211 if ( CORBA::is_nil(theObject) )
212 return aGEOMObject._retn();
214 // Get the object itself
215 Handle(GEOM_Object) anObject =
216 GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry());
217 if (anObject.IsNull())
218 return aGEOMObject._retn();
221 Handle(GEOM_Object) aNewObject =
222 GetOperations()->CloseContour( anObject, Convert( theWires ), isCommonVertex );
223 if (!GetOperations()->IsDone() || aNewObject.IsNull())
224 return aGEOMObject._retn();
226 return GetObject(aNewObject);
229 //=============================================================================
233 //=============================================================================
234 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::RemoveIntWires (GEOM::GEOM_Object_ptr theObject,
235 const GEOM::short_array& theWires)
237 GEOM::GEOM_Object_var aGEOMObject;
239 // Set a not done flag
240 GetOperations()->SetNotDone();
243 if ( CORBA::is_nil(theObject) ) // if theWires is empty - it's OK, it means that ALL wires should be removed
244 return aGEOMObject._retn();
246 // Get the object itself
247 Handle(GEOM_Object) anObject =
248 GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry());
249 if (anObject.IsNull())
250 return aGEOMObject._retn();
253 Handle(GEOM_Object) aNewObject =
254 GetOperations()->RemoveIntWires( anObject, Convert( theWires ) );
255 if (!GetOperations()->IsDone() || aNewObject.IsNull())
256 return aGEOMObject._retn();
258 return GetObject(aNewObject);
261 //=============================================================================
265 //=============================================================================
266 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::FillHoles (GEOM::GEOM_Object_ptr theObject,
267 const GEOM::short_array& theWires)
269 GEOM::GEOM_Object_var aGEOMObject;
271 // Set a not done flag
272 GetOperations()->SetNotDone();
275 if ( CORBA::is_nil(theObject) ) // if theWires is empty - it's OK, it means that ALL wires should be removed
276 return aGEOMObject._retn();
278 // Get the object itself
279 Handle(GEOM_Object) anObject =
280 GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry());
281 if (anObject.IsNull())
282 return aGEOMObject._retn();
285 Handle(GEOM_Object) aNewObject =
286 GetOperations()->FillHoles( anObject, Convert( theWires ) );
287 if (!GetOperations()->IsDone() || aNewObject.IsNull())
288 return aGEOMObject._retn();
290 return GetObject(aNewObject);
293 //=============================================================================
297 //=============================================================================
298 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::Sew (GEOM::GEOM_Object_ptr theObject,
299 CORBA::Double theTolerance)
301 GEOM::GEOM_Object_var aGEOMObject;
303 // Set a not done flag
304 GetOperations()->SetNotDone();
307 if ( CORBA::is_nil(theObject) || theTolerance < 0 )
308 return aGEOMObject._retn();
310 // Get the object itself
311 Handle(GEOM_Object) anObject =
312 GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry());
313 if (anObject.IsNull())
314 return aGEOMObject._retn();
317 Handle(GEOM_Object) aNewObject =
318 GetOperations()->Sew( anObject, theTolerance );
319 if (!GetOperations()->IsDone() || aNewObject.IsNull())
320 return aGEOMObject._retn();
322 return GetObject(aNewObject);
325 //=============================================================================
329 //=============================================================================
330 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::DivideEdge (GEOM::GEOM_Object_ptr theObject,
331 CORBA::Short theIndex,
332 CORBA::Double theValue,
333 CORBA::Boolean isByParameter)
335 GEOM::GEOM_Object_var aGEOMObject;
337 // Set a not done flag
338 GetOperations()->SetNotDone();
341 if ( CORBA::is_nil(theObject) || theValue < 0 || theValue > 1 )
342 return aGEOMObject._retn();
344 // Get the object itself
345 Handle(GEOM_Object) anObject =
346 GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry());
347 if (anObject.IsNull())
348 return aGEOMObject._retn();
351 Handle(GEOM_Object) aNewObject =
352 GetOperations()->DivideEdge( anObject, theIndex, theValue, isByParameter );
353 if (!GetOperations()->IsDone() || aNewObject.IsNull())
354 return aGEOMObject._retn();
356 return GetObject(aNewObject);
359 //=============================================================================
363 //=============================================================================
364 CORBA::Boolean GEOM_IHealingOperations_i::GetFreeBoundary ( GEOM::GEOM_Object_ptr theObject,
365 GEOM::ListOfGO_out theClosedWires,
366 GEOM::ListOfGO_out theOpenWires )
368 theClosedWires = new GEOM::ListOfGO;
369 theOpenWires = new GEOM::ListOfGO;
371 // Set a not done flag
372 GetOperations()->SetNotDone();
374 if ( CORBA::is_nil(theObject) )
377 // Get the object itself
378 Handle(GEOM_Object) anObject =
379 GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry());
380 if (anObject.IsNull())
383 Handle(TColStd_HSequenceOfTransient) aClosed = new TColStd_HSequenceOfTransient();
384 Handle(TColStd_HSequenceOfTransient) anOpen = new TColStd_HSequenceOfTransient();
385 bool res = GetOperations()->GetFreeBoundary( anObject, aClosed, anOpen );
387 if ( !GetOperations()->IsDone() || !res )
390 int i, n = aClosed->Length();
391 theClosedWires->length( n );
392 for ( i = 1; i <= n; i++ )
393 (*theClosedWires)[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aClosed->Value(i)));
395 n = anOpen->Length();
396 theOpenWires->length( n );
397 for ( i = 1, n = anOpen->Length(); i <= n; i++ )
398 (*theOpenWires)[i-1] = GetObject(Handle(GEOM_Object)::DownCast(anOpen->Value(i)));