3 #include "GEOM_IShapesOperations_i.hh"
7 #include "Utils_ExceptHandlers.hxx"
9 #include "GEOM_Engine.hxx"
10 #include "GEOM_Object.hxx"
12 #include <TColStd_HSequenceOfTransient.hxx>
13 #include <TColStd_HArray1OfInteger.hxx>
15 //=============================================================================
19 //=============================================================================
20 GEOM_IShapesOperations_i::GEOM_IShapesOperations_i (PortableServer::POA_ptr thePOA,
21 GEOM::GEOM_Gen_ptr theEngine,
22 ::GEOMImpl_IShapesOperations* theImpl)
23 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
25 MESSAGE("GEOM_IShapesOperations_i::GEOM_IShapesOperations_i");
28 //=============================================================================
32 //=============================================================================
33 GEOM_IShapesOperations_i::~GEOM_IShapesOperations_i()
35 MESSAGE("GEOM_IShapesOperations_i::~GEOM_IShapesOperations_i");
39 //=============================================================================
43 //=============================================================================
44 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::MakeEdge
45 (GEOM::GEOM_Object_ptr thePnt1, GEOM::GEOM_Object_ptr thePnt2)
47 GEOM::GEOM_Object_var aGEOMObject;
50 GetOperations()->SetNotDone();
52 if (thePnt1 == NULL || thePnt2 == NULL) return aGEOMObject._retn();
54 //Get the reference points
55 Handle(GEOM_Object) aPnt1 = GetOperations()->GetEngine()->GetObject
56 (thePnt1->GetStudyID(), thePnt1->GetEntry());
57 Handle(GEOM_Object) aPnt2 = GetOperations()->GetEngine()->GetObject
58 (thePnt2->GetStudyID(), thePnt2->GetEntry());
60 if (aPnt1.IsNull() || aPnt2.IsNull()) return aGEOMObject._retn();
63 Handle(GEOM_Object) anObject = GetOperations()->MakeEdge(aPnt1, aPnt2);
64 if (!GetOperations()->IsDone() || anObject.IsNull())
65 return aGEOMObject._retn();
67 return GetObject(anObject);
70 //=============================================================================
74 //=============================================================================
75 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::MakeWire
76 (const GEOM::ListOfGO& theEdgesAndWires)
78 GEOM::GEOM_Object_var aGEOMObject;
81 GetOperations()->SetNotDone();
84 list<Handle(GEOM_Object)> aShapes;
87 aLen = theEdgesAndWires.length();
88 for (ind = 0; ind < aLen; ind++) {
89 if (theEdgesAndWires[ind] == NULL) return aGEOMObject._retn();
90 Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
91 (theEdgesAndWires[ind]->GetStudyID(), theEdgesAndWires[ind]->GetEntry());
92 if (aSh.IsNull()) return aGEOMObject._retn();
93 aShapes.push_back(aSh);
97 Handle(GEOM_Object) anObject =
98 GetOperations()->MakeWire(aShapes);
99 if (!GetOperations()->IsDone() || anObject.IsNull())
100 return aGEOMObject._retn();
102 return GetObject(anObject);
105 //=============================================================================
109 //=============================================================================
110 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::MakeFace
111 (GEOM::GEOM_Object_ptr theWire,
112 const CORBA::Boolean isPlanarWanted)
114 GEOM::GEOM_Object_var aGEOMObject;
116 //Set a not done flag
117 GetOperations()->SetNotDone();
119 if (theWire == NULL) return aGEOMObject._retn();
121 //Get the reference wire
122 Handle(GEOM_Object) aWire = GetOperations()->GetEngine()->GetObject
123 (theWire->GetStudyID(), theWire->GetEntry());
125 if (aWire.IsNull()) return aGEOMObject._retn();
128 Handle(GEOM_Object) anObject = GetOperations()->MakeFace(aWire, isPlanarWanted);
129 if (!GetOperations()->IsDone() || anObject.IsNull())
130 return aGEOMObject._retn();
132 return GetObject(anObject);
135 //=============================================================================
139 //=============================================================================
140 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::MakeFaceWires
141 (const GEOM::ListOfGO& theWires,
142 const CORBA::Boolean isPlanarWanted)
144 GEOM::GEOM_Object_var aGEOMObject;
146 //Set a not done flag
147 GetOperations()->SetNotDone();
150 list<Handle(GEOM_Object)> aShapes;
153 aLen = theWires.length();
154 for (ind = 0; ind < aLen; ind++) {
155 if (theWires[ind] == NULL) return aGEOMObject._retn();
156 Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
157 (theWires[ind]->GetStudyID(), theWires[ind]->GetEntry());
158 if (aSh.IsNull()) return aGEOMObject._retn();
159 aShapes.push_back(aSh);
163 Handle(GEOM_Object) anObject =
164 GetOperations()->MakeFaceWires(aShapes, isPlanarWanted);
165 if (!GetOperations()->IsDone() || anObject.IsNull())
166 return aGEOMObject._retn();
168 return GetObject(anObject);
171 //=============================================================================
175 //=============================================================================
176 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::MakeShell
177 (const GEOM::ListOfGO& theFacesAndShells)
179 GEOM::GEOM_Object_var aGEOMObject;
181 //Set a not done flag
182 GetOperations()->SetNotDone();
185 list<Handle(GEOM_Object)> aShapes;
188 aLen = theFacesAndShells.length();
189 for (ind = 0; ind < aLen; ind++) {
190 if (theFacesAndShells[ind] == NULL) return aGEOMObject._retn();
191 Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
192 (theFacesAndShells[ind]->GetStudyID(), theFacesAndShells[ind]->GetEntry());
193 if (aSh.IsNull()) return aGEOMObject._retn();
194 aShapes.push_back(aSh);
198 Handle(GEOM_Object) anObject =
199 GetOperations()->MakeShell(aShapes);
200 if (!GetOperations()->IsDone() || anObject.IsNull())
201 return aGEOMObject._retn();
203 return GetObject(anObject);
206 //=============================================================================
210 //=============================================================================
211 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::MakeSolidShell
212 (GEOM::GEOM_Object_ptr theShell)
214 GEOM::GEOM_Object_var aGEOMObject;
216 //Set a not done flag
217 GetOperations()->SetNotDone();
219 if (theShell == NULL) return aGEOMObject._retn();
221 //Get the reference objects
222 Handle(GEOM_Object) aShell = GetOperations()->GetEngine()->GetObject
223 (theShell->GetStudyID(), theShell->GetEntry());
225 if (aShell.IsNull()) return aGEOMObject._retn();
228 Handle(GEOM_Object) anObject = GetOperations()->MakeSolidShell(aShell);
229 if (!GetOperations()->IsDone() || anObject.IsNull())
230 return aGEOMObject._retn();
232 return GetObject(anObject);
235 //=============================================================================
239 //=============================================================================
240 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::MakeSolidShells
241 (const GEOM::ListOfGO& theShells)
243 GEOM::GEOM_Object_var aGEOMObject;
245 //Set a not done flag
246 GetOperations()->SetNotDone();
249 list<Handle(GEOM_Object)> aShapes;
252 aLen = theShells.length();
253 for (ind = 0; ind < aLen; ind++) {
254 if (theShells[ind] == NULL) return aGEOMObject._retn();
255 Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
256 (theShells[ind]->GetStudyID(), theShells[ind]->GetEntry());
257 if (aSh.IsNull()) return aGEOMObject._retn();
258 aShapes.push_back(aSh);
262 Handle(GEOM_Object) anObject =
263 GetOperations()->MakeSolidShells(aShapes);
264 if (!GetOperations()->IsDone() || anObject.IsNull())
265 return aGEOMObject._retn();
267 return GetObject(anObject);
270 //=============================================================================
274 //=============================================================================
275 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::MakeCompound
276 (const GEOM::ListOfGO& theShapes)
278 GEOM::GEOM_Object_var aGEOMObject;
280 //Set a not done flag
281 GetOperations()->SetNotDone();
284 list<Handle(GEOM_Object)> aShapes;
287 aLen = theShapes.length();
288 for (ind = 0; ind < aLen; ind++) {
289 if (theShapes[ind] == NULL) return aGEOMObject._retn();
290 Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
291 (theShapes[ind]->GetStudyID(), theShapes[ind]->GetEntry());
292 if (aSh.IsNull()) return aGEOMObject._retn();
293 aShapes.push_back(aSh);
297 Handle(GEOM_Object) anObject =
298 GetOperations()->MakeCompound(aShapes);
299 if (!GetOperations()->IsDone() || anObject.IsNull())
300 return aGEOMObject._retn();
302 return GetObject(anObject);
305 //=============================================================================
309 //=============================================================================
310 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::MakeGlueFaces
311 (GEOM::GEOM_Object_ptr theShape,
312 const CORBA::Double theTolerance)
314 GEOM::GEOM_Object_var aGEOMObject;
316 //Set a not done flag
317 GetOperations()->SetNotDone();
319 if (theShape == NULL) return aGEOMObject._retn();
321 //Get the reference objects
322 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
323 (theShape->GetStudyID(), theShape->GetEntry());
325 if (aShape.IsNull()) return aGEOMObject._retn();
328 Handle(GEOM_Object) anObject =
329 GetOperations()->MakeGlueFaces(aShape, theTolerance);
330 //if (!GetOperations()->IsDone() || anObject.IsNull())
332 if (anObject.IsNull())
333 return aGEOMObject._retn();
335 return GetObject(anObject);
338 //=============================================================================
342 //=============================================================================
343 GEOM::ListOfGO* GEOM_IShapesOperations_i::MakeExplode (GEOM::GEOM_Object_ptr theShape,
344 const CORBA::Long theShapeType,
345 const CORBA::Boolean isSorted)
347 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
348 if (theShape == NULL) return aSeq._retn();
350 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
351 (theShape->GetStudyID(), theShape->GetEntry());
353 Handle(TColStd_HSequenceOfTransient) aHSeq =
354 GetOperations()->MakeExplode(aShape, theShapeType, isSorted);
355 if (!GetOperations()->IsDone() || aHSeq.IsNull())
358 Standard_Integer aLength = aHSeq->Length();
359 aSeq->length(aLength);
360 for (Standard_Integer i = 1; i <= aLength; i++)
361 aSeq[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aHSeq->Value(i)));
366 //=============================================================================
370 //=============================================================================
371 GEOM::ListOfLong* GEOM_IShapesOperations_i::SubShapeAllIDs (GEOM::GEOM_Object_ptr theShape,
372 const CORBA::Long theShapeType,
373 const CORBA::Boolean isSorted)
375 GEOM::ListOfLong_var aSeq = new GEOM::ListOfLong;
376 if (theShape == NULL) return aSeq._retn();
378 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
379 (theShape->GetStudyID(), theShape->GetEntry());
381 Handle(TColStd_HSequenceOfInteger) aHSeq =
382 GetOperations()->SubShapeAllIDs(aShape, theShapeType, isSorted);
383 if (!GetOperations()->IsDone() || aHSeq.IsNull()) return aSeq._retn();
385 Standard_Integer aLength = aHSeq->Length();
386 aSeq->length(aLength);
387 for (Standard_Integer i = 1; i <= aLength; i++)
388 aSeq[i-1] = aHSeq->Value(i);
393 //=============================================================================
397 //=============================================================================
398 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::GetSubShape
399 (GEOM::GEOM_Object_ptr theMainShape,
400 const CORBA::Long theID)
402 GEOM::GEOM_Object_var aGEOMObject;
404 //Set a not done flag
405 GetOperations()->SetNotDone();
407 if (theMainShape == NULL) return aGEOMObject._retn();
409 //Get the reference objects
410 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
411 (theMainShape->GetStudyID(), theMainShape->GetEntry());
413 if (aShape.IsNull()) return aGEOMObject._retn();
415 Handle(GEOM_Object) anObject = GetOperations()->GetSubShape(aShape, theID);
416 if (!GetOperations()->IsDone() || anObject.IsNull())
417 return aGEOMObject._retn();
419 return GetObject(anObject);
422 //=============================================================================
426 //=============================================================================
427 CORBA::Long GEOM_IShapesOperations_i::NumberOfFaces (GEOM::GEOM_Object_ptr theShape)
429 if (theShape == NULL) return -1;
431 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
432 (theShape->GetStudyID(), theShape->GetEntry());
434 CORBA::Long aNb = GetOperations()->NumberOfFaces(aShape);
435 if (!GetOperations()->IsDone()) return -1;
440 //=============================================================================
444 //=============================================================================
445 CORBA::Long GEOM_IShapesOperations_i::NumberOfEdges (GEOM::GEOM_Object_ptr theShape)
447 if (theShape == NULL) return -1;
449 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
450 (theShape->GetStudyID(), theShape->GetEntry());
452 CORBA::Long aNb = GetOperations()->NumberOfEdges(aShape);
453 if (!GetOperations()->IsDone()) return -1;
458 //=============================================================================
462 //=============================================================================
463 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::ChangeOrientation
464 (GEOM::GEOM_Object_ptr theShape)
466 GEOM::GEOM_Object_var aGEOMObject;
468 //Set a not done flag
469 GetOperations()->SetNotDone();
471 if (theShape == NULL) return aGEOMObject._retn();
473 //Get the reference objects
474 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
475 (theShape->GetStudyID(), theShape->GetEntry());
477 if (aShape.IsNull()) return aGEOMObject._retn();
480 Handle(GEOM_Object) anObject = GetOperations()->ReverseShape(aShape);
481 if (!GetOperations()->IsDone() || anObject.IsNull())
482 return aGEOMObject._retn();
484 return GetObject(anObject);
487 //=============================================================================
491 //=============================================================================
492 GEOM::ListOfLong* GEOM_IShapesOperations_i::GetFreeFacesIDs (GEOM::GEOM_Object_ptr theShape)
494 GEOM::ListOfLong_var aSeq = new GEOM::ListOfLong;
495 if (theShape == NULL) return aSeq._retn();
497 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
498 (theShape->GetStudyID(), theShape->GetEntry());
500 Handle(TColStd_HSequenceOfInteger) aHSeq =
501 GetOperations()->GetFreeFacesIDs(aShape);
502 if (!GetOperations()->IsDone() || aHSeq.IsNull()) return aSeq._retn();
504 Standard_Integer aLength = aHSeq->Length();
505 aSeq->length(aLength);
506 for (Standard_Integer i = 1; i <= aLength; i++)
507 aSeq[i-1] = aHSeq->Value(i);
512 //=============================================================================
516 //=============================================================================
517 GEOM::ListOfGO* GEOM_IShapesOperations_i::GetSharedShapes
518 (GEOM::GEOM_Object_ptr theShape1,
519 GEOM::GEOM_Object_ptr theShape2,
520 const CORBA::Long theShapeType)
522 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
523 if (theShape1 == NULL ||
524 theShape2 == NULL) return aSeq._retn();
526 Handle(GEOM_Object) aShape1 = GetOperations()->GetEngine()->GetObject
527 (theShape1->GetStudyID(), theShape1->GetEntry());
528 Handle(GEOM_Object) aShape2 = GetOperations()->GetEngine()->GetObject
529 (theShape2->GetStudyID(), theShape2->GetEntry());
531 if (aShape1.IsNull() ||
532 aShape2.IsNull()) return aSeq._retn();
534 Handle(TColStd_HSequenceOfTransient) aHSeq =
535 GetOperations()->GetSharedShapes(aShape1, aShape2, theShapeType);
536 if (!GetOperations()->IsDone() || aHSeq.IsNull())
539 Standard_Integer aLength = aHSeq->Length();
540 aSeq->length(aLength);
541 for (Standard_Integer i = 1; i <= aLength; i++)
542 aSeq[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aHSeq->Value(i)));
547 //=============================================================================
551 //=============================================================================
552 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::GetShapesOnPlane
553 (GEOM::GEOM_Object_ptr theShape,
554 const CORBA::Long theShapeType,
555 GEOM::GEOM_Object_ptr thePlane)
557 GEOM::GEOM_Object_var aGEOMObject;
559 //Set a not done flag
560 GetOperations()->SetNotDone();
562 if (theShape == NULL ||
563 thePlane == NULL) return aGEOMObject._retn();
565 //Get the reference objects
566 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
567 (theShape->GetStudyID(), theShape->GetEntry());
568 Handle(GEOM_Object) aPlane = GetOperations()->GetEngine()->GetObject
569 (thePlane->GetStudyID(), thePlane->GetEntry());
571 if (aShape.IsNull() ||
572 aPlane.IsNull()) return aGEOMObject._retn();
574 //Get Shapes On Plane
575 Handle(GEOM_Object) anObject =
576 GetOperations()->GetShapesOnPlane(aShape, theShapeType, aPlane);
577 if (!GetOperations()->IsDone() || anObject.IsNull())
578 return aGEOMObject._retn();
580 return GetObject(anObject);
583 //=============================================================================
585 * GetShapesOnCylinder
587 //=============================================================================
588 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::GetShapesOnCylinder
589 (GEOM::GEOM_Object_ptr theShape,
590 const CORBA::Long theShapeType,
591 GEOM::GEOM_Object_ptr theAxis,
592 const CORBA::Double theRadius)
594 GEOM::GEOM_Object_var aGEOMObject;
596 //Set a not done flag
597 GetOperations()->SetNotDone();
599 if (theShape == NULL ||
600 theAxis == NULL) return aGEOMObject._retn();
602 //Get the reference objects
603 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
604 (theShape->GetStudyID(), theShape->GetEntry());
605 Handle(GEOM_Object) anAxis = GetOperations()->GetEngine()->GetObject
606 (theAxis->GetStudyID(), theAxis->GetEntry());
608 if (aShape.IsNull() ||
609 anAxis.IsNull()) return aGEOMObject._retn();
611 //Get Shapes On Cylinder
612 Handle(GEOM_Object) anObject =
613 GetOperations()->GetShapesOnCylinder(aShape, theShapeType, anAxis, theRadius);
614 if (!GetOperations()->IsDone() || anObject.IsNull())
615 return aGEOMObject._retn();
617 return GetObject(anObject);
620 //=============================================================================
624 //=============================================================================
625 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::GetShapesOnSphere
626 (GEOM::GEOM_Object_ptr theShape,
627 const CORBA::Long theShapeType,
628 GEOM::GEOM_Object_ptr theCenter,
629 const CORBA::Double theRadius)
631 GEOM::GEOM_Object_var aGEOMObject;
633 //Set a not done flag
634 GetOperations()->SetNotDone();
636 if (theShape == NULL ||
637 theCenter == NULL) return aGEOMObject._retn();
639 //Get the reference objects
640 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
641 (theShape->GetStudyID(), theShape->GetEntry());
642 Handle(GEOM_Object) aCenter = GetOperations()->GetEngine()->GetObject
643 (theCenter->GetStudyID(), theCenter->GetEntry());
645 if (aShape.IsNull() ||
646 aCenter.IsNull()) return aGEOMObject._retn();
648 //Get Shapes On Sphere
649 Handle(GEOM_Object) anObject =
650 GetOperations()->GetShapesOnSphere(aShape, theShapeType, aCenter, theRadius);
651 if (!GetOperations()->IsDone() || anObject.IsNull())
652 return aGEOMObject._retn();
654 return GetObject(anObject);
657 //=============================================================================
661 //=============================================================================
662 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::GetInPlace
663 (GEOM::GEOM_Object_ptr theShapeWhere,
664 GEOM::GEOM_Object_ptr theShapeWhat)
666 GEOM::GEOM_Object_var aGEOMObject;
668 //Set a not done flag
669 GetOperations()->SetNotDone();
671 if (theShapeWhere == NULL ||
672 theShapeWhat == NULL) return aGEOMObject._retn();
674 //Get the reference objects
675 Handle(GEOM_Object) aShapeWhere = GetOperations()->GetEngine()->GetObject
676 (theShapeWhere->GetStudyID(), theShapeWhere->GetEntry());
677 Handle(GEOM_Object) aShapeWhat = GetOperations()->GetEngine()->GetObject
678 (theShapeWhat->GetStudyID(), theShapeWhat->GetEntry());
680 if (aShapeWhere.IsNull() ||
681 aShapeWhat.IsNull()) return aGEOMObject._retn();
683 //Get Shapes in place of aShapeWhat
684 Handle(GEOM_Object) anObject =
685 GetOperations()->GetInPlace(aShapeWhere, aShapeWhat);
686 if (!GetOperations()->IsDone() || anObject.IsNull())
687 return aGEOMObject._retn();
689 return GetObject(anObject);