3 #include "GEOMImpl_IShapesOperations.hxx"
5 #include "GEOMImpl_Types.hxx"
7 #include "GEOMImpl_VectorDriver.hxx"
8 #include "GEOMImpl_ShapeDriver.hxx"
9 #include "GEOMImpl_CopyDriver.hxx"
10 #include "GEOMImpl_GlueDriver.hxx"
12 #include "GEOMImpl_IVector.hxx"
13 #include "GEOMImpl_IShapes.hxx"
14 #include "GEOMImpl_IGlue.hxx"
16 #include "GEOMImpl_Block6Explorer.hxx"
18 #include "GEOM_Function.hxx"
20 #include "GEOMAlgo_FinderShapeOn.hxx"
22 #include "utilities.h"
24 #include "Utils_ExceptHandlers.hxx"
26 #include <TFunction_DriverTable.hxx>
27 #include <TFunction_Driver.hxx>
28 #include <TFunction_Logbook.hxx>
29 #include <TDataStd_Integer.hxx>
30 #include <TDataStd_IntegerArray.hxx>
31 #include <TDF_Tool.hxx>
33 #include <BRepExtrema_ExtCF.hxx>
35 #include <BRep_Tool.hxx>
36 #include <BRepGProp.hxx>
37 #include <BRepAdaptor_Curve.hxx>
38 #include <BRepBuilderAPI_MakeFace.hxx>
43 #include <TopoDS_Shape.hxx>
44 #include <TopoDS_Face.hxx>
45 #include <TopoDS_Edge.hxx>
46 #include <TopoDS_Vertex.hxx>
47 #include <TopoDS_Iterator.hxx>
48 #include <TopExp_Explorer.hxx>
49 #include <TopLoc_Location.hxx>
50 #include <TopTools_MapOfShape.hxx>
51 #include <TopTools_Array1OfShape.hxx>
52 #include <TopTools_ListIteratorOfListOfShape.hxx>
53 #include <TopTools_IndexedMapOfShape.hxx>
55 #include <Geom_Surface.hxx>
56 #include <Geom_Plane.hxx>
57 #include <Geom_SphericalSurface.hxx>
58 #include <Geom_CylindricalSurface.hxx>
59 #include <GeomAdaptor_Surface.hxx>
61 #include <Geom2d_Curve.hxx>
63 #include <GProp_GProps.hxx>
66 #include <TColStd_Array1OfReal.hxx>
67 #include <TColStd_HArray1OfInteger.hxx>
68 #include <TColStd_ListOfInteger.hxx>
69 #include <TColStd_ListIteratorOfListOfInteger.hxx>
71 //#include <OSD_Timer.hxx>
73 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
75 //=============================================================================
79 //=============================================================================
80 GEOMImpl_IShapesOperations::GEOMImpl_IShapesOperations (GEOM_Engine* theEngine, int theDocID)
81 : GEOM_IOperations(theEngine, theDocID)
83 MESSAGE("GEOMImpl_IShapesOperations::GEOMImpl_IShapesOperations");
86 //=============================================================================
90 //=============================================================================
91 GEOMImpl_IShapesOperations::~GEOMImpl_IShapesOperations()
93 MESSAGE("GEOMImpl_IShapesOperations::~GEOMImpl_IShapesOperations");
97 //=============================================================================
101 //=============================================================================
102 Handle(GEOM_Object) GEOMImpl_IShapesOperations::MakeEdge
103 (Handle(GEOM_Object) thePnt1, Handle(GEOM_Object) thePnt2)
107 if (thePnt1.IsNull() || thePnt2.IsNull()) return NULL;
109 //Add a new Edge object
110 Handle(GEOM_Object) anEdge = GetEngine()->AddObject(GetDocID(), GEOM_EDGE);
112 //Add a new Vector function
113 Handle(GEOM_Function) aFunction =
114 anEdge->AddFunction(GEOMImpl_VectorDriver::GetID(), VECTOR_TWO_PNT);
116 //Check if the function is set correctly
117 if (aFunction->GetDriverGUID() != GEOMImpl_VectorDriver::GetID()) return NULL;
119 GEOMImpl_IVector aPI (aFunction);
121 Handle(GEOM_Function) aRef1 = thePnt1->GetLastFunction();
122 Handle(GEOM_Function) aRef2 = thePnt2->GetLastFunction();
123 if (aRef1.IsNull() || aRef2.IsNull()) return NULL;
125 aPI.SetPoint1(aRef1);
126 aPI.SetPoint2(aRef2);
128 //Compute the Edge value
130 if (!GetSolver()->ComputeFunction(aFunction)) {
131 SetErrorCode("Vector driver failed");
135 catch (Standard_Failure) {
136 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
137 SetErrorCode(aFail->GetMessageString());
141 //Make a Python command
142 TCollection_AsciiString anEntry, aDescr;
143 TDF_Tool::Entry(anEdge->GetEntry(), anEntry);
144 aDescr += (anEntry+" = IShapesOperations.MakeEdge(");
145 TDF_Tool::Entry(thePnt1->GetEntry(), anEntry);
146 aDescr += (anEntry+", ");
147 TDF_Tool::Entry(thePnt2->GetEntry(), anEntry);
148 aDescr += (anEntry+")");
150 aFunction->SetDescription(aDescr);
156 //=============================================================================
160 //=============================================================================
161 Handle(GEOM_Object) GEOMImpl_IShapesOperations::MakeWire
162 (list<Handle(GEOM_Object)> theShapes)
164 return MakeShape(theShapes, GEOM_WIRE, WIRE_EDGES, "MakeWire");
167 //=============================================================================
171 //=============================================================================
172 Handle(GEOM_Object) GEOMImpl_IShapesOperations::MakeFace (Handle(GEOM_Object) theWire,
173 const bool isPlanarWanted)
177 if (theWire.IsNull()) return NULL;
179 //Add a new Face object
180 Handle(GEOM_Object) aFace = GetEngine()->AddObject(GetDocID(), GEOM_FACE);
182 //Add a new Shape function for creation of a face from a wire
183 Handle(GEOM_Function) aFunction =
184 aFace->AddFunction(GEOMImpl_ShapeDriver::GetID(), FACE_WIRE);
185 if (aFunction.IsNull()) return NULL;
187 //Check if the function is set correctly
188 if (aFunction->GetDriverGUID() != GEOMImpl_ShapeDriver::GetID()) return NULL;
190 GEOMImpl_IShapes aCI (aFunction);
192 Handle(GEOM_Function) aRefWire = theWire->GetLastFunction();
194 if (aRefWire.IsNull()) return NULL;
196 aCI.SetBase(aRefWire);
197 aCI.SetIsPlanar(isPlanarWanted);
199 //Compute the Face value
201 if (!GetSolver()->ComputeFunction(aFunction)) {
202 SetErrorCode("Shape driver failed to compute a face");
206 catch (Standard_Failure) {
207 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
208 SetErrorCode(aFail->GetMessageString());
212 //Make a Python command
213 TCollection_AsciiString anEntry, aDescr;
214 TDF_Tool::Entry(aFace->GetEntry(), anEntry);
216 aDescr += " = IShapesOperations.MakeFace(";
217 TDF_Tool::Entry(theWire->GetEntry(), anEntry);
225 aFunction->SetDescription(aDescr);
231 //=============================================================================
235 //=============================================================================
236 Handle(GEOM_Object) GEOMImpl_IShapesOperations::MakeFaceWires
237 (list<Handle(GEOM_Object)> theShapes,
238 const bool isPlanarWanted)
243 Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_FACE);
246 Handle(GEOM_Function) aFunction =
247 aShape->AddFunction(GEOMImpl_ShapeDriver::GetID(), FACE_WIRES);
248 if (aFunction.IsNull()) return NULL;
250 //Check if the function is set correctly
251 if (aFunction->GetDriverGUID() != GEOMImpl_ShapeDriver::GetID()) return NULL;
253 GEOMImpl_IShapes aCI (aFunction);
255 Handle(TColStd_HSequenceOfTransient) aShapesSeq = new TColStd_HSequenceOfTransient;
258 list<Handle(GEOM_Object)>::iterator it = theShapes.begin();
259 for (; it != theShapes.end(); it++) {
260 Handle(GEOM_Function) aRefSh = (*it)->GetLastFunction();
261 if (aRefSh.IsNull()) {
262 SetErrorCode("NULL argument shape for the face construction");
265 aShapesSeq->Append(aRefSh);
267 aCI.SetShapes(aShapesSeq);
269 aCI.SetIsPlanar(isPlanarWanted);
273 if (!GetSolver()->ComputeFunction(aFunction)) {
274 SetErrorCode("Shape driver failed");
278 catch (Standard_Failure) {
279 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
280 SetErrorCode(aFail->GetMessageString());
284 //Make a Python command
285 TCollection_AsciiString anEntry, aDescr;
286 TDF_Tool::Entry(aShape->GetEntry(), anEntry);
287 aDescr += (anEntry + " = IShapesOperations.MakeFaceWires([");
289 it = theShapes.begin();
290 if (it != theShapes.end()) {
291 TDF_Tool::Entry((*it)->GetEntry(), anEntry);
293 aDescr += (anEntry+", ");
294 for (; it != theShapes.end(); it++) {
296 TDF_Tool::Entry((*it)->GetEntry(), anEntry);
306 aFunction->SetDescription(aDescr);
312 //=============================================================================
316 //=============================================================================
317 Handle(GEOM_Object) GEOMImpl_IShapesOperations::MakeShell
318 (list<Handle(GEOM_Object)> theShapes)
320 return MakeShape(theShapes, GEOM_SHELL, SHELL_FACES, "MakeShell");
323 //=============================================================================
327 //=============================================================================
328 Handle(GEOM_Object) GEOMImpl_IShapesOperations::MakeSolidShells
329 (list<Handle(GEOM_Object)> theShapes)
331 return MakeShape(theShapes, GEOM_SOLID, SOLID_SHELLS, "MakeSolidShells");
334 //=============================================================================
338 //=============================================================================
339 Handle(GEOM_Object) GEOMImpl_IShapesOperations::MakeSolidShell (Handle(GEOM_Object) theShell)
343 if (theShell.IsNull()) return NULL;
345 //Add a new Solid object
346 Handle(GEOM_Object) aSolid = GetEngine()->AddObject(GetDocID(), GEOM_SOLID);
348 //Add a new Solid function for creation of a solid from a shell
349 Handle(GEOM_Function) aFunction =
350 aSolid->AddFunction(GEOMImpl_ShapeDriver::GetID(), SOLID_SHELL);
351 if (aFunction.IsNull()) return NULL;
353 //Check if the function is set correctly
354 if (aFunction->GetDriverGUID() != GEOMImpl_ShapeDriver::GetID()) return NULL;
356 GEOMImpl_IShapes aCI (aFunction);
358 Handle(GEOM_Function) aRefShell = theShell->GetLastFunction();
360 if (aRefShell.IsNull()) return NULL;
362 aCI.SetBase(aRefShell);
364 //Compute the Solid value
366 if (!GetSolver()->ComputeFunction(aFunction)) {
367 SetErrorCode("Solid driver failed");
371 catch (Standard_Failure) {
372 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
373 SetErrorCode(aFail->GetMessageString());
377 //Make a Python command
378 TCollection_AsciiString anEntry, aDescr("");
379 TDF_Tool::Entry(aSolid->GetEntry(), anEntry);
381 aDescr += " = IShapesOperations.MakeSolidShell(";
382 TDF_Tool::Entry(theShell->GetEntry(), anEntry);
383 aDescr += (anEntry+")");
385 aFunction->SetDescription(aDescr);
391 //=============================================================================
395 //=============================================================================
396 Handle(GEOM_Object) GEOMImpl_IShapesOperations::MakeCompound
397 (list<Handle(GEOM_Object)> theShapes)
399 return MakeShape(theShapes, GEOM_COMPOUND, COMPOUND_SHAPES, "MakeCompound");
402 //=============================================================================
406 //=============================================================================
407 Handle(GEOM_Object) GEOMImpl_IShapesOperations::MakeShape
408 (list<Handle(GEOM_Object)> theShapes,
409 const Standard_Integer theObjectType,
410 const Standard_Integer theFunctionType,
411 const TCollection_AsciiString theMethodName)
416 Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), theObjectType);
419 Handle(GEOM_Function) aFunction =
420 aShape->AddFunction(GEOMImpl_ShapeDriver::GetID(), theFunctionType);
421 if (aFunction.IsNull()) return NULL;
423 //Check if the function is set correctly
424 if (aFunction->GetDriverGUID() != GEOMImpl_ShapeDriver::GetID()) return NULL;
426 GEOMImpl_IShapes aCI (aFunction);
428 Handle(TColStd_HSequenceOfTransient) aShapesSeq = new TColStd_HSequenceOfTransient;
431 list<Handle(GEOM_Object)>::iterator it = theShapes.begin();
432 for (; it != theShapes.end(); it++) {
433 Handle(GEOM_Function) aRefSh = (*it)->GetLastFunction();
434 if (aRefSh.IsNull()) {
435 SetErrorCode("NULL argument shape for the shape construction");
438 aShapesSeq->Append(aRefSh);
440 aCI.SetShapes(aShapesSeq);
444 if (!GetSolver()->ComputeFunction(aFunction)) {
445 SetErrorCode("Shape driver failed");
449 catch (Standard_Failure) {
450 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
451 SetErrorCode(aFail->GetMessageString());
455 //Make a Python command
456 TCollection_AsciiString anEntry, aDescr("");
457 TDF_Tool::Entry(aShape->GetEntry(), anEntry);
458 aDescr += (anEntry + " = IShapesOperations.");
459 aDescr += (theMethodName + "([");
461 it = theShapes.begin();
462 if (it != theShapes.end()) {
463 TDF_Tool::Entry((*it)->GetEntry(), anEntry);
465 aDescr += (anEntry+", ");
466 for (; it != theShapes.end(); it++) {
468 TDF_Tool::Entry((*it)->GetEntry(), anEntry);
474 aFunction->SetDescription(aDescr);
480 //=============================================================================
484 //=============================================================================
485 Handle(GEOM_Object) GEOMImpl_IShapesOperations::MakeGlueFaces
486 (Handle(GEOM_Object) theShape,
487 const Standard_Real theTolerance)
491 if (theShape.IsNull()) return NULL;
493 //Add a new Glued object
494 Handle(GEOM_Object) aGlued = GetEngine()->AddObject(GetDocID(), GEOM_GLUED);
496 //Add a new Glue function
497 Handle(GEOM_Function) aFunction;
498 aFunction = aGlued->AddFunction(GEOMImpl_GlueDriver::GetID(), GLUE_FACES);
499 if (aFunction.IsNull()) return NULL;
501 //Check if the function is set correctly
502 if (aFunction->GetDriverGUID() != GEOMImpl_GlueDriver::GetID()) return NULL;
504 GEOMImpl_IGlue aCI (aFunction);
506 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
507 if (aRefShape.IsNull()) return NULL;
509 aCI.SetBase(aRefShape);
510 aCI.SetTolerance(theTolerance);
512 //Compute the sub-shape value
513 Standard_Boolean isWarning = Standard_False;
515 if (!GetSolver()->ComputeFunction(aFunction)) {
516 SetErrorCode("Shape driver failed to glue faces");
520 catch (Standard_Failure) {
521 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
522 SetErrorCode(aFail->GetMessageString());
523 // to provide warning
524 if (!aFunction->GetValue().IsNull()) {
525 isWarning = Standard_True;
531 //Make a Python command
532 TCollection_AsciiString anEntry, aDescr;
533 TDF_Tool::Entry(aGlued->GetEntry(), anEntry);
535 aDescr += " = IShapesOperations.MakeGlueFaces(";
536 TDF_Tool::Entry(theShape->GetEntry(), anEntry);
537 aDescr += anEntry + ", ";
538 aDescr += TCollection_AsciiString(theTolerance) + ")";
540 aFunction->SetDescription(aDescr);
542 // to provide warning
543 if (!isWarning) SetErrorCode(OK);
547 //=============================================================================
551 //=============================================================================
552 Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::MakeExplode
553 (Handle(GEOM_Object) theShape,
554 const Standard_Integer theShapeType,
555 const Standard_Boolean isSorted)
557 // OSD_Timer timer1, timer2, timer3, timer4;
562 if (theShape.IsNull()) return NULL;
563 TopoDS_Shape aShape = theShape->GetValue();
564 if (aShape.IsNull()) return NULL;
566 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
567 Handle(GEOM_Object) anObj;
568 Handle(GEOM_Function) aFunction;
569 TopTools_MapOfShape mapShape;
570 TopTools_ListOfShape listShape;
572 if (aShape.ShapeType() == TopAbs_COMPOUND &&
573 (TopAbs_ShapeEnum(theShapeType) == TopAbs_SHAPE ||
574 TopAbs_ShapeEnum(theShapeType) == TopAbs_COMPSOLID ||
575 TopAbs_ShapeEnum(theShapeType) == TopAbs_COMPOUND)) {
576 TopoDS_Iterator It (aShape, Standard_True, Standard_True);
577 for (; It.More(); It.Next()) {
578 if (mapShape.Add(It.Value())) {
579 if (TopAbs_ShapeEnum(theShapeType) == TopAbs_SHAPE ||
580 TopAbs_ShapeEnum(theShapeType) == It.Value().ShapeType()) {
581 listShape.Append(It.Value());
586 TopExp_Explorer exp (aShape, TopAbs_ShapeEnum(theShapeType));
587 for (; exp.More(); exp.Next())
588 if (mapShape.Add(exp.Current()))
589 listShape.Append(exp.Current());
592 if (listShape.IsEmpty()) {
593 SetErrorCode("The given shape has no sub-shapes of the requested type");
601 SortShapes(listShape);
606 TopTools_IndexedMapOfShape anIndices;
607 TopExp::MapShapes(aShape, anIndices);
608 Handle(TColStd_HArray1OfInteger) anArray;
610 TopTools_ListIteratorOfListOfShape itSub (listShape);
611 TCollection_AsciiString anAsciiList = "[", anEntry;
612 for (int index = 1; itSub.More(); itSub.Next(), ++index) {
613 TopoDS_Shape aValue = itSub.Value();
614 anArray = new TColStd_HArray1OfInteger(1,1);
615 anArray->SetValue(1, anIndices.FindIndex(aValue));
616 anObj = GetEngine()->AddSubShape(theShape, anArray);
619 TDF_Tool::Entry(anObj->GetEntry(), anEntry);
620 anAsciiList += anEntry;
627 anAsciiList.Trunc(anAsciiList.Length() - 1);
630 anAsciiList = TCollection_AsciiString("\n") + anAsciiList;
632 //The explode doesn't change object so no new function is requiered.
633 aFunction = theShape->GetLastFunction();
635 //Make a Python command
636 TCollection_AsciiString aDescr(anAsciiList);
637 TDF_Tool::Entry(theShape->GetEntry(), anEntry);
638 aDescr += " = IShapesOperations.MakeExplode(";
639 aDescr += (anEntry + ",");
641 aDescr += (TCollection_AsciiString(theShapeType) + ", 1)");
643 aDescr += (TCollection_AsciiString(theShapeType) + ", 0)");
645 TCollection_AsciiString anOldDescr = aFunction->GetDescription();
646 anOldDescr = anOldDescr + aDescr;
647 aFunction->SetDescription(anOldDescr);
653 // cout << "Explosure takes:" << endl;
655 // cout << "Sorting takes:" << endl;
657 // cout << "Sub-shapes addition takes:" << endl;
659 // cout << "Update Description takes:" << endl;
665 //=============================================================================
669 //=============================================================================
670 Handle(TColStd_HSequenceOfInteger) GEOMImpl_IShapesOperations::SubShapeAllIDs
671 (Handle(GEOM_Object) theShape,
672 const Standard_Integer theShapeType,
673 const Standard_Boolean isSorted)
677 if (theShape.IsNull()) return NULL;
678 TopoDS_Shape aShape = theShape->GetValue();
679 if (aShape.IsNull()) return NULL;
681 Handle(TColStd_HSequenceOfInteger) aSeq = new TColStd_HSequenceOfInteger;
682 TopTools_MapOfShape mapShape;
683 TopTools_ListOfShape listShape;
685 if (aShape.ShapeType() == TopAbs_COMPOUND &&
686 (TopAbs_ShapeEnum(theShapeType) == TopAbs_SHAPE ||
687 TopAbs_ShapeEnum(theShapeType) == TopAbs_COMPSOLID ||
688 TopAbs_ShapeEnum(theShapeType) == TopAbs_COMPOUND)) {
689 TopoDS_Iterator It (aShape, Standard_True, Standard_True);
690 for (; It.More(); It.Next()) {
691 if (mapShape.Add(It.Value())) {
692 if (TopAbs_ShapeEnum(theShapeType) == TopAbs_SHAPE ||
693 TopAbs_ShapeEnum(theShapeType) == It.Value().ShapeType()) {
694 listShape.Append(It.Value());
699 TopExp_Explorer exp (aShape, TopAbs_ShapeEnum(theShapeType));
700 for (; exp.More(); exp.Next())
701 if (mapShape.Add(exp.Current()))
702 listShape.Append(exp.Current());
705 if (listShape.IsEmpty()) {
706 SetErrorCode("The given shape has no sub-shapes of the requested type");
711 SortShapes(listShape);
713 TopTools_IndexedMapOfShape anIndices;
714 TopExp::MapShapes(aShape, anIndices);
715 Handle(TColStd_HArray1OfInteger) anArray;
717 TopTools_ListIteratorOfListOfShape itSub (listShape);
718 for (int index = 1; itSub.More(); itSub.Next(), ++index) {
719 TopoDS_Shape aValue = itSub.Value();
720 aSeq->Append(anIndices.FindIndex(aValue));
723 //The explode doesn't change object so no new function is required.
724 Handle(GEOM_Function) aFunction = theShape->GetLastFunction();
726 //Make a Python command
727 TCollection_AsciiString aDescr
728 ("\nlistSubShapeAllIDs = IShapesOperations.SubShapeAllIDs(");
729 TCollection_AsciiString anEntry;
730 TDF_Tool::Entry(theShape->GetEntry(), anEntry);
731 aDescr += (anEntry + ",");
733 aDescr += (TCollection_AsciiString(theShapeType) + ", 1)");
735 aDescr += (TCollection_AsciiString(theShapeType) + ", 0)");
737 TCollection_AsciiString anOldDescr = aFunction->GetDescription();
738 anOldDescr = anOldDescr + aDescr;
739 aFunction->SetDescription(anOldDescr);
745 //=============================================================================
749 //=============================================================================
750 Handle(GEOM_Object) GEOMImpl_IShapesOperations::GetSubShape
751 (Handle(GEOM_Object) theMainShape,
752 const Standard_Integer theID)
756 if (theMainShape.IsNull()) return NULL;
758 Handle(TColStd_HArray1OfInteger) anArray = new TColStd_HArray1OfInteger(1,1);
759 anArray->SetValue(1, theID);
760 Handle(GEOM_Object) anObj = GetEngine()->AddSubShape(theMainShape, anArray);
761 if (anObj.IsNull()) {
762 SetErrorCode("Can not get a sub-shape with the given ID");
766 //The GetSubShape() doesn't change object so no new function is requiered.
767 Handle(GEOM_Function) aFunction = theMainShape->GetLastFunction();
769 //Make a Python command
770 TCollection_AsciiString aDescr ("\n");
771 TCollection_AsciiString anEntry;
772 TDF_Tool::Entry(anObj->GetEntry(), anEntry);
773 aDescr += anEntry + " = IShapesOperations.GetSubShape(";
774 TDF_Tool::Entry(theMainShape->GetEntry(), anEntry);
775 aDescr += anEntry + ", ";
776 aDescr += TCollection_AsciiString(theID) + ")";
778 TCollection_AsciiString anOldDescr = aFunction->GetDescription();
779 anOldDescr = anOldDescr + aDescr;
780 aFunction->SetDescription(anOldDescr);
787 //=============================================================================
791 //=============================================================================
792 Standard_Integer GEOMImpl_IShapesOperations::NumberOfFaces (Handle(GEOM_Object) theShape)
796 Standard_Integer nb = 0;
798 if (theShape.IsNull()) return -1;
799 TopoDS_Shape aShape = theShape->GetValue();
800 if (aShape.IsNull()) return -1;
802 TopTools_MapOfShape mapShape;
804 TopExp_Explorer exp (aShape, TopAbs_FACE);
805 for (; exp.More(); exp.Next())
806 if (mapShape.Add(exp.Current()))
813 //=============================================================================
817 //=============================================================================
818 Standard_Integer GEOMImpl_IShapesOperations::NumberOfEdges (Handle(GEOM_Object) theShape)
822 Standard_Integer nb = 0;
824 if (theShape.IsNull()) return -1;
825 TopoDS_Shape aShape = theShape->GetValue();
826 if (aShape.IsNull()) return -1;
828 TopTools_MapOfShape mapShape;
830 TopExp_Explorer exp (aShape, TopAbs_EDGE);
831 for (; exp.More(); exp.Next())
832 if (mapShape.Add(exp.Current()))
839 //=============================================================================
843 //=============================================================================
844 Handle(GEOM_Object) GEOMImpl_IShapesOperations::ReverseShape(Handle(GEOM_Object) theShape)
848 if (theShape.IsNull()) return NULL;
850 //Add a new reversed object
851 Handle(GEOM_Object) aReversed = GetEngine()->AddObject(GetDocID(), theShape->GetType());
853 //Add a new Revese function
854 Handle(GEOM_Function) aFunction;
855 aFunction = aReversed->AddFunction(GEOMImpl_ShapeDriver::GetID(), REVERSE_ORIENTATION);
856 if (aFunction.IsNull()) return NULL;
858 //Check if the function is set correctly
859 if (aFunction->GetDriverGUID() != GEOMImpl_ShapeDriver::GetID()) return NULL;
861 GEOMImpl_IShapes aSI (aFunction);
863 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
864 if (aRefShape.IsNull()) return NULL;
866 aSI.SetBase(aRefShape);
868 //Compute the sub-shape value
870 if (!GetSolver()->ComputeFunction(aFunction)) {
871 SetErrorCode("Shape driver failed to reverse shape");
875 catch (Standard_Failure) {
876 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
877 SetErrorCode(aFail->GetMessageString());
881 //Make a Python command
882 TCollection_AsciiString anEntry, aDescr;
883 TDF_Tool::Entry(aReversed->GetEntry(), anEntry);
885 aDescr += " = IShapesOperations.ReverseShape(";
886 TDF_Tool::Entry(theShape->GetEntry(), anEntry);
887 aDescr += anEntry + ")";
889 aFunction->SetDescription(aDescr);
895 //=============================================================================
899 //=============================================================================
900 Handle(TColStd_HSequenceOfInteger) GEOMImpl_IShapesOperations::GetFreeFacesIDs
901 (Handle(GEOM_Object) theShape)
905 if (theShape.IsNull()) return NULL;
906 TopoDS_Shape aShape = theShape->GetValue();
907 if (aShape.IsNull()) return NULL;
909 Handle(TColStd_HSequenceOfInteger) aSeq = new TColStd_HSequenceOfInteger;
911 TopTools_IndexedDataMapOfShapeListOfShape mapFaceBlocks;
912 GEOMImpl_Block6Explorer::MapShapesAndAncestors
913 (aShape, TopAbs_FACE, TopAbs_SOLID, mapFaceBlocks);
915 Standard_Integer ind = 1, nbFaces = mapFaceBlocks.Extent();
918 SetErrorCode("The given shape has no faces");
922 TopTools_IndexedMapOfShape anIndices;
923 TopExp::MapShapes(aShape, anIndices);
926 for (; ind <= nbFaces; ind++) {
927 if (mapFaceBlocks.FindFromIndex(ind).Extent() != 2) {
928 id = anIndices.FindIndex(mapFaceBlocks.FindKey(ind));
933 //The explode doesn't change object so no new function is required.
934 Handle(GEOM_Function) aFunction = theShape->GetLastFunction();
936 //Make a Python command
937 TCollection_AsciiString aDescr ("\nlistFreeFacesIDs = IShapesOperations.GetFreeFacesIDs(");
938 TCollection_AsciiString anEntry;
939 TDF_Tool::Entry(theShape->GetEntry(), anEntry);
940 aDescr += (anEntry + ")");
942 TCollection_AsciiString anOldDescr = aFunction->GetDescription();
943 anOldDescr = anOldDescr + aDescr;
944 aFunction->SetDescription(anOldDescr);
950 //=============================================================================
954 //=============================================================================
955 Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::GetSharedShapes
956 (Handle(GEOM_Object) theShape1,
957 Handle(GEOM_Object) theShape2,
958 const Standard_Integer theShapeType)
962 if (theShape1.IsNull() || theShape2.IsNull()) return NULL;
964 TopoDS_Shape aShape1 = theShape1->GetValue();
965 TopoDS_Shape aShape2 = theShape2->GetValue();
967 if (aShape1.IsNull() || aShape2.IsNull()) return NULL;
969 TopTools_IndexedMapOfShape anIndices;
970 TopExp::MapShapes(aShape1, anIndices);
971 Handle(TColStd_HArray1OfInteger) anArray;
973 TopTools_IndexedMapOfShape mapShape1;
974 TopExp::MapShapes(aShape1, TopAbs_ShapeEnum(theShapeType), mapShape1);
976 Handle(GEOM_Object) anObj;
977 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
979 TopTools_MapOfShape mapShape2;
980 TopExp_Explorer exp (aShape2, TopAbs_ShapeEnum(theShapeType));
981 for (; exp.More(); exp.Next()) {
982 TopoDS_Shape aSS = exp.Current();
983 if (mapShape2.Add(aSS) && mapShape1.Contains(aSS)) {
984 anArray = new TColStd_HArray1OfInteger(1,1);
985 anArray->SetValue(1, anIndices.FindIndex(aSS));
986 anObj = GetEngine()->AddSubShape(theShape1, anArray);
991 if (aSeq->IsEmpty()) {
992 SetErrorCode("The given shapes have no shared sub-shapes of the requested type");
996 //The explode doesn't change object so no new function is required.
997 Handle(GEOM_Function) aFunction = theShape1->GetLastFunction();
999 //Make a Python command
1000 TCollection_AsciiString aDescr
1001 ("\nlistSharedShapes = IShapesOperations.GetSharedShapes(");
1002 TCollection_AsciiString anEntry;
1003 TDF_Tool::Entry(theShape1->GetEntry(), anEntry);
1004 aDescr += (anEntry + ",");
1005 TDF_Tool::Entry(theShape2->GetEntry(), anEntry);
1006 aDescr += (anEntry + ",");
1007 aDescr += TCollection_AsciiString(theShapeType) + ")";
1009 TCollection_AsciiString anOldDescr = aFunction->GetDescription();
1010 anOldDescr = anOldDescr + aDescr;
1011 aFunction->SetDescription(anOldDescr);
1017 //=============================================================================
1021 //=============================================================================
1022 Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::GetShapesOnPlane
1023 (const Handle(GEOM_Object)& theShape,
1024 const Standard_Integer theShapeType,
1025 const Handle(GEOM_Object)& theAx1,
1026 const GEOMAlgo_State theState)
1030 if (theShape.IsNull() || theAx1.IsNull()) return NULL;
1032 TopoDS_Shape aShape = theShape->GetValue();
1033 TopoDS_Shape anAx1 = theAx1->GetValue();
1035 if (aShape.IsNull() || anAx1.IsNull()) return NULL;
1037 TopAbs_ShapeEnum aShapeType = TopAbs_ShapeEnum(theShapeType);
1038 if (aShapeType != TopAbs_VERTEX &&
1039 aShapeType != TopAbs_EDGE &&
1040 aShapeType != TopAbs_FACE) {
1041 SetErrorCode("Only vertices, edges or faces can be found by this method");
1046 if (anAx1.ShapeType() != TopAbs_EDGE) return NULL;
1047 TopoDS_Edge anEdge = TopoDS::Edge(anAx1);
1048 TopoDS_Vertex V1, V2;
1049 TopExp::Vertices(anEdge, V1, V2, Standard_True);
1050 if (V1.IsNull() || V2.IsNull()) {
1051 SetErrorCode("Bad edge given for the plane normal vector");
1054 gp_Pnt aLoc = BRep_Tool::Pnt(V1);
1055 gp_Vec aVec (aLoc, BRep_Tool::Pnt(V2));
1056 if (aVec.Magnitude() < Precision::Confusion()) {
1057 SetErrorCode("Vector with null magnitude given");
1061 Handle(Geom_Plane) aPlane = new Geom_Plane(aLoc, aVec);
1064 GEOMAlgo_FinderShapeOn aFinder;
1065 Standard_Real aTol = 0.0001; // default value
1067 aFinder.SetShape(aShape);
1068 aFinder.SetTolerance(aTol);
1069 aFinder.SetSurface(aPlane);
1070 aFinder.SetShapeType(aShapeType);
1071 aFinder.SetState(theState);
1075 // Interprete results
1076 Standard_Integer iErr = aFinder.ErrorStatus();
1077 // the detailed description of error codes is in GEOMAlgo_FinderShapeOn.cxx
1079 MESSAGE(" iErr : " << iErr);
1080 TCollection_AsciiString aMsg (" iErr : ");
1081 aMsg += TCollection_AsciiString(iErr);
1085 Standard_Integer iWrn = aFinder.WarningStatus();
1086 // the detailed description of warning codes is in GEOMAlgo_FinderShapeOn.cxx
1088 MESSAGE(" *** iWrn : " << iWrn);
1091 const TopTools_ListOfShape& listSS = aFinder.Shapes(); // the result
1093 if (listSS.Extent() < 1) {
1094 SetErrorCode("Not a single sub-shape of the requested type found on the given plane");
1098 // Fill sequence of objects
1099 TopTools_IndexedMapOfShape anIndices;
1100 TopExp::MapShapes(aShape, anIndices);
1102 Handle(GEOM_Object) anObj;
1103 Handle(TColStd_HArray1OfInteger) anArray;
1104 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
1106 TopTools_ListIteratorOfListOfShape itSub (listSS);
1107 for (int index = 1; itSub.More(); itSub.Next(), ++index) {
1108 int id = anIndices.FindIndex(itSub.Value());
1109 anArray = new TColStd_HArray1OfInteger(1,1);
1110 anArray->SetValue(1, id);
1111 anObj = GetEngine()->AddSubShape(theShape, anArray);
1112 aSeq->Append(anObj);
1115 // The GetShapesOnPlane() doesn't change object so no new function is required.
1116 Handle(GEOM_Function) aFunction = theShape->GetLastFunction();
1118 // Make a Python command
1119 TCollection_AsciiString anEntry, aDescr
1120 ("\nlistShapesOnPlane = IShapesOperations.GetShapesOnPlane(");
1121 TDF_Tool::Entry(theShape->GetEntry(), anEntry);
1122 aDescr += anEntry + TCollection_AsciiString(theShapeType) + ",";
1123 TDF_Tool::Entry(theAx1->GetEntry(), anEntry);
1124 aDescr += anEntry + ",";
1125 aDescr += TCollection_AsciiString(theState) + ")";
1127 TCollection_AsciiString anOldDescr = aFunction->GetDescription();
1128 anOldDescr += aDescr;
1129 aFunction->SetDescription(anOldDescr);
1135 //=============================================================================
1137 * GetShapesOnCylinder
1139 //=============================================================================
1140 Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::GetShapesOnCylinder
1141 (const Handle(GEOM_Object)& theShape,
1142 const Standard_Integer theShapeType,
1143 const Handle(GEOM_Object)& theAxis,
1144 const Standard_Real theRadius,
1145 const GEOMAlgo_State theState)
1149 if (theShape.IsNull() || theAxis.IsNull()) return NULL;
1151 TopoDS_Shape aShape = theShape->GetValue();
1152 TopoDS_Shape anAxis = theAxis->GetValue();
1154 if (aShape.IsNull() || anAxis.IsNull()) return NULL;
1156 TopAbs_ShapeEnum aShapeType = TopAbs_ShapeEnum(theShapeType);
1157 if (aShapeType != TopAbs_VERTEX &&
1158 aShapeType != TopAbs_EDGE &&
1159 aShapeType != TopAbs_FACE) {
1160 SetErrorCode("Only vertices, edges or faces can be found by this method");
1164 //Axis of the cylinder
1165 if (anAxis.ShapeType() != TopAbs_EDGE) {
1166 SetErrorCode("Not an edge given for the axis");
1169 TopoDS_Edge anEdge = TopoDS::Edge(anAxis);
1170 TopoDS_Vertex V1, V2;
1171 TopExp::Vertices(anEdge, V1, V2, Standard_True);
1172 if (V1.IsNull() || V2.IsNull()) {
1173 SetErrorCode("Bad edge given for the axis");
1176 gp_Pnt aLoc = BRep_Tool::Pnt(V1);
1177 gp_Vec aVec (aLoc, BRep_Tool::Pnt(V2));
1178 if (aVec.Magnitude() < Precision::Confusion()) {
1179 SetErrorCode("Vector with null magnitude given");
1183 gp_Ax3 anAx3 (aLoc, aVec);
1184 Handle(Geom_CylindricalSurface) aCylinder =
1185 new Geom_CylindricalSurface(anAx3, theRadius);
1188 GEOMAlgo_FinderShapeOn aFinder;
1189 Standard_Real aTol = 0.0001; // default value
1191 aFinder.SetShape(aShape);
1192 aFinder.SetTolerance(aTol);
1193 aFinder.SetSurface(aCylinder);
1194 aFinder.SetShapeType(aShapeType);
1195 aFinder.SetState(theState);
1199 // Interprete results
1200 Standard_Integer iErr = aFinder.ErrorStatus();
1201 // the detailed description of error codes is in GEOMAlgo_FinderShapeOn.cxx
1203 MESSAGE(" iErr : " << iErr);
1204 TCollection_AsciiString aMsg (" iErr : ");
1205 aMsg += TCollection_AsciiString(iErr);
1209 Standard_Integer iWrn = aFinder.WarningStatus();
1210 // the detailed description of warning codes is in GEOMAlgo_FinderShapeOn.cxx
1212 MESSAGE(" *** iWrn : " << iWrn);
1215 const TopTools_ListOfShape& listSS = aFinder.Shapes(); // the result
1217 if (listSS.Extent() < 1) {
1218 SetErrorCode("Not a single sub-shape of the requested type found on the given cylinder");
1222 // Fill sequence of objects
1223 TopTools_IndexedMapOfShape anIndices;
1224 TopExp::MapShapes(aShape, anIndices);
1226 Handle(GEOM_Object) anObj;
1227 Handle(TColStd_HArray1OfInteger) anArray;
1228 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
1230 TopTools_ListIteratorOfListOfShape itSub (listSS);
1231 for (int index = 1; itSub.More(); itSub.Next(), ++index) {
1232 int id = anIndices.FindIndex(itSub.Value());
1233 anArray = new TColStd_HArray1OfInteger(1,1);
1234 anArray->SetValue(1, id);
1235 anObj = GetEngine()->AddSubShape(theShape, anArray);
1236 aSeq->Append(anObj);
1239 // The GetShapesOnCylinder() doesn't change object so no new function is required.
1240 Handle(GEOM_Function) aFunction = theShape->GetLastFunction();
1242 // Make a Python command
1243 TCollection_AsciiString anEntry, aDescr
1244 ("\nlistShapesOnCylinder = IShapesOperations.GetShapesOnCylinder(");
1245 TDF_Tool::Entry(theShape->GetEntry(), anEntry);
1246 aDescr += anEntry + TCollection_AsciiString(theShapeType) + ",";
1247 TDF_Tool::Entry(theAxis->GetEntry(), anEntry);
1248 aDescr += anEntry + ",";
1249 aDescr += TCollection_AsciiString(theRadius) + ",";
1250 aDescr += TCollection_AsciiString(theState) + ")";
1252 TCollection_AsciiString anOldDescr = aFunction->GetDescription();
1253 anOldDescr += aDescr;
1254 aFunction->SetDescription(anOldDescr);
1260 //=============================================================================
1264 //=============================================================================
1265 Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::GetShapesOnSphere
1266 (const Handle(GEOM_Object)& theShape,
1267 const Standard_Integer theShapeType,
1268 const Handle(GEOM_Object)& theCenter,
1269 const Standard_Real theRadius,
1270 const GEOMAlgo_State theState)
1274 if (theShape.IsNull() || theCenter.IsNull()) return NULL;
1276 TopoDS_Shape aShape = theShape->GetValue();
1277 TopoDS_Shape aCenter = theCenter->GetValue();
1279 if (aShape.IsNull() || aCenter.IsNull()) return NULL;
1281 TopAbs_ShapeEnum aShapeType = TopAbs_ShapeEnum(theShapeType);
1282 if (aShapeType != TopAbs_VERTEX &&
1283 aShapeType != TopAbs_EDGE &&
1284 aShapeType != TopAbs_FACE) {
1285 SetErrorCode("Only vertices, edges or faces can be found by this method");
1289 // Center of the sphere
1290 if (aCenter.ShapeType() != TopAbs_VERTEX) return NULL;
1291 gp_Pnt aLoc = BRep_Tool::Pnt(TopoDS::Vertex(aCenter));
1293 gp_Ax3 anAx3 (aLoc, gp::DZ());
1294 Handle(Geom_SphericalSurface) aSphere =
1295 new Geom_SphericalSurface(anAx3, theRadius);
1298 GEOMAlgo_FinderShapeOn aFinder;
1299 Standard_Real aTol = 0.0001; // default value
1301 aFinder.SetShape(aShape);
1302 aFinder.SetTolerance(aTol);
1303 aFinder.SetSurface(aSphere);
1304 aFinder.SetShapeType(aShapeType);
1305 aFinder.SetState(theState);
1309 // Interprete results
1310 Standard_Integer iErr = aFinder.ErrorStatus();
1311 // the detailed description of error codes is in GEOMAlgo_FinderShapeOn.cxx
1313 MESSAGE(" iErr : " << iErr);
1314 TCollection_AsciiString aMsg (" iErr : ");
1315 aMsg += TCollection_AsciiString(iErr);
1319 Standard_Integer iWrn = aFinder.WarningStatus();
1320 // the detailed description of warning codes is in GEOMAlgo_FinderShapeOn.cxx
1322 MESSAGE(" *** iWrn : " << iWrn);
1325 const TopTools_ListOfShape& listSS = aFinder.Shapes(); // the result
1327 if (listSS.Extent() < 1) {
1328 SetErrorCode("Not a single sub-shape of the requested type found on the given sphere");
1332 // Fill sequence of objects
1333 TopTools_IndexedMapOfShape anIndices;
1334 TopExp::MapShapes(aShape, anIndices);
1336 Handle(GEOM_Object) anObj;
1337 Handle(TColStd_HArray1OfInteger) anArray;
1338 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
1340 TopTools_ListIteratorOfListOfShape itSub (listSS);
1341 for (int index = 1; itSub.More(); itSub.Next(), ++index) {
1342 int id = anIndices.FindIndex(itSub.Value());
1343 anArray = new TColStd_HArray1OfInteger(1,1);
1344 anArray->SetValue(1, id);
1345 anObj = GetEngine()->AddSubShape(theShape, anArray);
1346 aSeq->Append(anObj);
1349 // The GetShapesOnSphere() doesn't change object so no new function is required.
1350 Handle(GEOM_Function) aFunction = theShape->GetLastFunction();
1352 // Make a Python command
1353 TCollection_AsciiString anEntry, aDescr
1354 ("\nlistShapesOnSphere = IShapesOperations.GetShapesOnSphere(");
1355 TDF_Tool::Entry(theShape->GetEntry(), anEntry);
1356 aDescr += anEntry + TCollection_AsciiString(theShapeType) + ",";
1357 TDF_Tool::Entry(theCenter->GetEntry(), anEntry);
1358 aDescr += anEntry + ",";
1359 aDescr += TCollection_AsciiString(theRadius) + ",";
1360 aDescr += TCollection_AsciiString(theState) + ")";
1362 TCollection_AsciiString anOldDescr = aFunction->GetDescription();
1363 anOldDescr += aDescr;
1364 aFunction->SetDescription(anOldDescr);
1370 //=============================================================================
1374 //=============================================================================
1375 Handle(GEOM_Object) GEOMImpl_IShapesOperations::GetInPlace
1376 (Handle(GEOM_Object) theShapeWhere,
1377 Handle(GEOM_Object) theShapeWhat)
1381 if (theShapeWhere.IsNull() || theShapeWhat.IsNull()) return NULL;
1383 TopoDS_Shape aWhere = theShapeWhere->GetValue();
1384 TopoDS_Shape aWhat = theShapeWhat->GetValue();
1386 if (aWhere.IsNull() || aWhat.IsNull()) return NULL;
1388 //Fill array of indices
1389 Handle(TColStd_HArray1OfInteger) aModifiedArray;
1391 Handle(GEOM_Function) aWhereFunction = theShapeWhere->GetLastFunction();
1393 TopTools_IndexedMapOfShape aWhereIndices;
1394 TopExp::MapShapes(aWhere, aWhereIndices);
1396 if (aWhereIndices.Contains(aWhat)) {
1398 // entity was not changed by the operation
1399 Standard_Integer aWhatIndex = aWhereIndices.FindIndex(aWhat);
1400 aModifiedArray = new TColStd_HArray1OfInteger(1,1);
1401 aModifiedArray->SetValue(1, aWhatIndex);
1405 TDF_Label aHistoryLabel = aWhereFunction->GetHistoryEntry(Standard_False);
1406 if (aHistoryLabel.IsNull()) {
1407 SetErrorCode("History for an operation, produced the shape, does not exist.");
1411 // search in history for all argument shapes
1412 Standard_Boolean isFound = Standard_False;
1414 TDF_LabelSequence aLabelSeq;
1415 aWhereFunction->GetDependency(aLabelSeq);
1416 Standard_Integer nbArg = aLabelSeq.Length();
1418 for (Standard_Integer iarg = 1; iarg <= nbArg && !isFound; iarg++) {
1420 TDF_Label anArgumentRefLabel = aLabelSeq.Value(iarg);
1422 Handle(GEOM_Object) anArgumentObject = GEOM_Object::GetReferencedObject(anArgumentRefLabel);
1423 TopoDS_Shape anArgumentShape = anArgumentObject->GetValue();
1425 TopTools_IndexedMapOfShape anArgumentIndices;
1426 TopExp::MapShapes(anArgumentShape, anArgumentIndices);
1428 if (anArgumentIndices.Contains(aWhat)) {
1429 isFound = Standard_True;
1430 Standard_Integer aWhatIndex = anArgumentIndices.FindIndex(aWhat);
1432 // Find corresponding label in history
1433 TDF_Label anArgumentHistoryLabel =
1434 aWhereFunction->GetArgumentHistoryEntry(anArgumentRefLabel, Standard_False);
1435 if (anArgumentHistoryLabel.IsNull()) {
1436 SetErrorCode("History for this entity does not exist.");
1440 TDF_Label aWhatHistoryLabel = anArgumentHistoryLabel.FindChild(aWhatIndex, Standard_False);
1441 if (aWhatHistoryLabel.IsNull()) {
1442 SetErrorCode("History for this entity does not exist.");
1446 Handle(TDataStd_IntegerArray) anIntegerArray;
1447 if (!aWhatHistoryLabel.FindAttribute(TDataStd_IntegerArray::GetID(), anIntegerArray)) {
1448 SetErrorCode("Empty history. Possibly, this entity is absent in result.");
1452 aModifiedArray = anIntegerArray->Array();
1453 if (aModifiedArray->Length() == 0) {
1454 SetErrorCode("This entity is absent in result.");
1461 SetErrorCode("Not found in arguments.");
1467 Handle(GEOM_Object) aResult = GetEngine()->AddSubShape(theShapeWhere, aModifiedArray);
1469 if (aModifiedArray->Length() > 1) {
1471 aResult->SetType(GEOM_GROUP);
1473 //Set a sub shape type
1474 TDF_Label aFreeLabel = aResult->GetFreeLabel();
1475 TopAbs_ShapeEnum aShapeType = aWhat.ShapeType();
1476 TDataStd_Integer::Set(aFreeLabel, (Standard_Integer)aShapeType);
1479 //Make a Python command
1480 TCollection_AsciiString anEntry, aDescr;
1481 TDF_Tool::Entry(aResult->GetEntry(), anEntry);
1483 aDescr += " = IShapesOperations.GetInPlace(";
1484 TDF_Tool::Entry(theShapeWhere->GetEntry(), anEntry);
1485 aDescr += anEntry + ",";
1486 TDF_Tool::Entry(theShapeWhat->GetEntry(), anEntry);
1487 aDescr += anEntry + ")";
1489 Handle(GEOM_Function) aFunction = aResult->GetFunction(1);
1490 aFunction->SetDescription(aDescr);
1496 //=======================================================================
1497 //function : SortShapes
1499 //=======================================================================
1500 void GEOMImpl_IShapesOperations::SortShapes(TopTools_ListOfShape& SL)
1502 Standard_Integer MaxShapes = SL.Extent();
1503 TopTools_Array1OfShape aShapes (1,MaxShapes);
1504 TColStd_Array1OfInteger OrderInd(1,MaxShapes);
1505 TColStd_Array1OfReal MidXYZ (1,MaxShapes); //X,Y,Z;
1506 TColStd_Array1OfReal Length (1,MaxShapes); //X,Y,Z;
1508 // Computing of CentreOfMass
1509 Standard_Integer Index;
1512 TopTools_ListIteratorOfListOfShape it(SL);
1513 for (Index=1; it.More(); Index++)
1515 TopoDS_Shape S = it.Value();
1516 SL.Remove( it ); // == it.Next()
1518 OrderInd.SetValue (Index, Index);
1519 if (S.ShapeType() == TopAbs_VERTEX)
1521 GPoint = BRep_Tool::Pnt( TopoDS::Vertex( S ));
1522 Length.SetValue( Index, (Standard_Real) S.Orientation());
1526 BRepGProp::LinearProperties (S, GPr);
1527 GPoint = GPr.CentreOfMass();
1528 Length.SetValue( Index, GPr.Mass() );
1530 MidXYZ.SetValue(Index,
1531 GPoint.X()*999 + GPoint.Y()*99 + GPoint.Z()*0.9);
1534 Standard_Integer aTemp;
1535 Standard_Boolean exchange, Sort = Standard_True;
1538 Sort = Standard_False;
1539 for (Index=1; Index < MaxShapes; Index++)
1541 if (MidXYZ(OrderInd(Index)) > MidXYZ(OrderInd(Index+1)))
1542 exchange = Standard_True;
1543 else if (MidXYZ(OrderInd(Index)) == MidXYZ(OrderInd(Index+1)) &&
1544 Length(OrderInd(Index)) > Length(OrderInd(Index+1)) )
1545 exchange = Standard_True;
1547 exchange = Standard_False;
1550 aTemp = OrderInd(Index);
1551 OrderInd(Index) = OrderInd(Index+1);
1552 OrderInd(Index+1) = aTemp;
1553 Sort = Standard_True;
1557 for (Index=1; Index <= MaxShapes; Index++)
1558 SL.Append( aShapes( OrderInd(Index) ));