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_FinderShapeOn1.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 <BRepBndLib.hxx>
39 #include <BRepBuilderAPI_MakeFace.hxx>
40 #include <BRepMesh_IncrementalMesh.hxx>
45 #include <TopoDS_Shape.hxx>
46 #include <TopoDS_Face.hxx>
47 #include <TopoDS_Edge.hxx>
48 #include <TopoDS_Vertex.hxx>
49 #include <TopoDS_Iterator.hxx>
50 #include <TopExp_Explorer.hxx>
51 #include <TopLoc_Location.hxx>
52 #include <TopTools_MapOfShape.hxx>
53 #include <TopTools_Array1OfShape.hxx>
54 #include <TopTools_ListIteratorOfListOfShape.hxx>
55 #include <TopTools_IndexedMapOfShape.hxx>
57 #include <Geom_Surface.hxx>
58 #include <Geom_Plane.hxx>
59 #include <Geom_SphericalSurface.hxx>
60 #include <Geom_CylindricalSurface.hxx>
61 #include <GeomAdaptor_Surface.hxx>
63 #include <Geom2d_Curve.hxx>
65 #include <Bnd_Box.hxx>
66 #include <GProp_GProps.hxx>
69 #include <TColStd_Array1OfReal.hxx>
70 #include <TColStd_HArray1OfInteger.hxx>
71 #include <TColStd_ListOfInteger.hxx>
72 #include <TColStd_ListIteratorOfListOfInteger.hxx>
74 //#include <OSD_Timer.hxx>
76 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
78 //=============================================================================
82 //=============================================================================
83 GEOMImpl_IShapesOperations::GEOMImpl_IShapesOperations (GEOM_Engine* theEngine, int theDocID)
84 : GEOM_IOperations(theEngine, theDocID)
86 MESSAGE("GEOMImpl_IShapesOperations::GEOMImpl_IShapesOperations");
89 //=============================================================================
93 //=============================================================================
94 GEOMImpl_IShapesOperations::~GEOMImpl_IShapesOperations()
96 MESSAGE("GEOMImpl_IShapesOperations::~GEOMImpl_IShapesOperations");
100 //=============================================================================
104 //=============================================================================
105 Handle(GEOM_Object) GEOMImpl_IShapesOperations::MakeEdge
106 (Handle(GEOM_Object) thePnt1, Handle(GEOM_Object) thePnt2)
110 if (thePnt1.IsNull() || thePnt2.IsNull()) return NULL;
112 //Add a new Edge object
113 Handle(GEOM_Object) anEdge = GetEngine()->AddObject(GetDocID(), GEOM_EDGE);
115 //Add a new Vector function
116 Handle(GEOM_Function) aFunction =
117 anEdge->AddFunction(GEOMImpl_VectorDriver::GetID(), VECTOR_TWO_PNT);
119 //Check if the function is set correctly
120 if (aFunction->GetDriverGUID() != GEOMImpl_VectorDriver::GetID()) return NULL;
122 GEOMImpl_IVector aPI (aFunction);
124 Handle(GEOM_Function) aRef1 = thePnt1->GetLastFunction();
125 Handle(GEOM_Function) aRef2 = thePnt2->GetLastFunction();
126 if (aRef1.IsNull() || aRef2.IsNull()) return NULL;
128 aPI.SetPoint1(aRef1);
129 aPI.SetPoint2(aRef2);
131 //Compute the Edge value
133 if (!GetSolver()->ComputeFunction(aFunction)) {
134 SetErrorCode("Vector driver failed");
138 catch (Standard_Failure) {
139 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
140 SetErrorCode(aFail->GetMessageString());
144 //Make a Python command
145 TCollection_AsciiString anEntry, aDescr;
146 TDF_Tool::Entry(anEdge->GetEntry(), anEntry);
147 aDescr += (anEntry+" = IShapesOperations.MakeEdge(");
148 TDF_Tool::Entry(thePnt1->GetEntry(), anEntry);
149 aDescr += (anEntry+", ");
150 TDF_Tool::Entry(thePnt2->GetEntry(), anEntry);
151 aDescr += (anEntry+")");
153 aFunction->SetDescription(aDescr);
159 //=============================================================================
163 //=============================================================================
164 Handle(GEOM_Object) GEOMImpl_IShapesOperations::MakeWire
165 (list<Handle(GEOM_Object)> theShapes)
167 return MakeShape(theShapes, GEOM_WIRE, WIRE_EDGES, "MakeWire");
170 //=============================================================================
174 //=============================================================================
175 Handle(GEOM_Object) GEOMImpl_IShapesOperations::MakeFace (Handle(GEOM_Object) theWire,
176 const bool isPlanarWanted)
180 if (theWire.IsNull()) return NULL;
182 //Add a new Face object
183 Handle(GEOM_Object) aFace = GetEngine()->AddObject(GetDocID(), GEOM_FACE);
185 //Add a new Shape function for creation of a face from a wire
186 Handle(GEOM_Function) aFunction =
187 aFace->AddFunction(GEOMImpl_ShapeDriver::GetID(), FACE_WIRE);
188 if (aFunction.IsNull()) return NULL;
190 //Check if the function is set correctly
191 if (aFunction->GetDriverGUID() != GEOMImpl_ShapeDriver::GetID()) return NULL;
193 GEOMImpl_IShapes aCI (aFunction);
195 Handle(GEOM_Function) aRefWire = theWire->GetLastFunction();
197 if (aRefWire.IsNull()) return NULL;
199 aCI.SetBase(aRefWire);
200 aCI.SetIsPlanar(isPlanarWanted);
202 //Compute the Face value
204 if (!GetSolver()->ComputeFunction(aFunction)) {
205 SetErrorCode("Shape driver failed to compute a face");
209 catch (Standard_Failure) {
210 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
211 SetErrorCode(aFail->GetMessageString());
215 //Make a Python command
216 TCollection_AsciiString anEntry, aDescr;
217 TDF_Tool::Entry(aFace->GetEntry(), anEntry);
219 aDescr += " = IShapesOperations.MakeFace(";
220 TDF_Tool::Entry(theWire->GetEntry(), anEntry);
228 aFunction->SetDescription(aDescr);
234 //=============================================================================
238 //=============================================================================
239 Handle(GEOM_Object) GEOMImpl_IShapesOperations::MakeFaceWires
240 (list<Handle(GEOM_Object)> theShapes,
241 const bool isPlanarWanted)
246 Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_FACE);
249 Handle(GEOM_Function) aFunction =
250 aShape->AddFunction(GEOMImpl_ShapeDriver::GetID(), FACE_WIRES);
251 if (aFunction.IsNull()) return NULL;
253 //Check if the function is set correctly
254 if (aFunction->GetDriverGUID() != GEOMImpl_ShapeDriver::GetID()) return NULL;
256 GEOMImpl_IShapes aCI (aFunction);
258 Handle(TColStd_HSequenceOfTransient) aShapesSeq = new TColStd_HSequenceOfTransient;
261 list<Handle(GEOM_Object)>::iterator it = theShapes.begin();
262 for (; it != theShapes.end(); it++) {
263 Handle(GEOM_Function) aRefSh = (*it)->GetLastFunction();
264 if (aRefSh.IsNull()) {
265 SetErrorCode("NULL argument shape for the face construction");
268 aShapesSeq->Append(aRefSh);
270 aCI.SetShapes(aShapesSeq);
272 aCI.SetIsPlanar(isPlanarWanted);
276 if (!GetSolver()->ComputeFunction(aFunction)) {
277 SetErrorCode("Shape driver failed");
281 catch (Standard_Failure) {
282 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
283 SetErrorCode(aFail->GetMessageString());
287 //Make a Python command
288 TCollection_AsciiString anEntry, aDescr;
289 TDF_Tool::Entry(aShape->GetEntry(), anEntry);
290 aDescr += (anEntry + " = IShapesOperations.MakeFaceWires([");
292 it = theShapes.begin();
293 if (it != theShapes.end()) {
294 TDF_Tool::Entry((*it)->GetEntry(), anEntry);
296 aDescr += (anEntry+", ");
297 for (; it != theShapes.end(); it++) {
299 TDF_Tool::Entry((*it)->GetEntry(), anEntry);
309 aFunction->SetDescription(aDescr);
315 //=============================================================================
319 //=============================================================================
320 Handle(GEOM_Object) GEOMImpl_IShapesOperations::MakeShell
321 (list<Handle(GEOM_Object)> theShapes)
323 return MakeShape(theShapes, GEOM_SHELL, SHELL_FACES, "MakeShell");
326 //=============================================================================
330 //=============================================================================
331 Handle(GEOM_Object) GEOMImpl_IShapesOperations::MakeSolidShells
332 (list<Handle(GEOM_Object)> theShapes)
334 return MakeShape(theShapes, GEOM_SOLID, SOLID_SHELLS, "MakeSolidShells");
337 //=============================================================================
341 //=============================================================================
342 Handle(GEOM_Object) GEOMImpl_IShapesOperations::MakeSolidShell (Handle(GEOM_Object) theShell)
346 if (theShell.IsNull()) return NULL;
348 //Add a new Solid object
349 Handle(GEOM_Object) aSolid = GetEngine()->AddObject(GetDocID(), GEOM_SOLID);
351 //Add a new Solid function for creation of a solid from a shell
352 Handle(GEOM_Function) aFunction =
353 aSolid->AddFunction(GEOMImpl_ShapeDriver::GetID(), SOLID_SHELL);
354 if (aFunction.IsNull()) return NULL;
356 //Check if the function is set correctly
357 if (aFunction->GetDriverGUID() != GEOMImpl_ShapeDriver::GetID()) return NULL;
359 GEOMImpl_IShapes aCI (aFunction);
361 Handle(GEOM_Function) aRefShell = theShell->GetLastFunction();
363 if (aRefShell.IsNull()) return NULL;
365 aCI.SetBase(aRefShell);
367 //Compute the Solid value
369 if (!GetSolver()->ComputeFunction(aFunction)) {
370 SetErrorCode("Solid driver failed");
374 catch (Standard_Failure) {
375 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
376 SetErrorCode(aFail->GetMessageString());
380 //Make a Python command
381 TCollection_AsciiString anEntry, aDescr("");
382 TDF_Tool::Entry(aSolid->GetEntry(), anEntry);
384 aDescr += " = IShapesOperations.MakeSolidShell(";
385 TDF_Tool::Entry(theShell->GetEntry(), anEntry);
386 aDescr += (anEntry+")");
388 aFunction->SetDescription(aDescr);
394 //=============================================================================
398 //=============================================================================
399 Handle(GEOM_Object) GEOMImpl_IShapesOperations::MakeCompound
400 (list<Handle(GEOM_Object)> theShapes)
402 return MakeShape(theShapes, GEOM_COMPOUND, COMPOUND_SHAPES, "MakeCompound");
405 //=============================================================================
409 //=============================================================================
410 Handle(GEOM_Object) GEOMImpl_IShapesOperations::MakeShape
411 (list<Handle(GEOM_Object)> theShapes,
412 const Standard_Integer theObjectType,
413 const Standard_Integer theFunctionType,
414 const TCollection_AsciiString theMethodName)
419 Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), theObjectType);
422 Handle(GEOM_Function) aFunction =
423 aShape->AddFunction(GEOMImpl_ShapeDriver::GetID(), theFunctionType);
424 if (aFunction.IsNull()) return NULL;
426 //Check if the function is set correctly
427 if (aFunction->GetDriverGUID() != GEOMImpl_ShapeDriver::GetID()) return NULL;
429 GEOMImpl_IShapes aCI (aFunction);
431 Handle(TColStd_HSequenceOfTransient) aShapesSeq = new TColStd_HSequenceOfTransient;
434 list<Handle(GEOM_Object)>::iterator it = theShapes.begin();
435 for (; it != theShapes.end(); it++) {
436 Handle(GEOM_Function) aRefSh = (*it)->GetLastFunction();
437 if (aRefSh.IsNull()) {
438 SetErrorCode("NULL argument shape for the shape construction");
441 aShapesSeq->Append(aRefSh);
443 aCI.SetShapes(aShapesSeq);
447 if (!GetSolver()->ComputeFunction(aFunction)) {
448 SetErrorCode("Shape driver failed");
452 catch (Standard_Failure) {
453 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
454 SetErrorCode(aFail->GetMessageString());
458 //Make a Python command
459 TCollection_AsciiString anEntry, aDescr("");
460 TDF_Tool::Entry(aShape->GetEntry(), anEntry);
461 aDescr += (anEntry + " = IShapesOperations.");
462 aDescr += (theMethodName + "([");
464 it = theShapes.begin();
465 if (it != theShapes.end()) {
466 TDF_Tool::Entry((*it)->GetEntry(), anEntry);
468 aDescr += (anEntry+", ");
469 for (; it != theShapes.end(); it++) {
471 TDF_Tool::Entry((*it)->GetEntry(), anEntry);
477 aFunction->SetDescription(aDescr);
483 //=============================================================================
487 //=============================================================================
488 Handle(GEOM_Object) GEOMImpl_IShapesOperations::MakeGlueFaces
489 (Handle(GEOM_Object) theShape,
490 const Standard_Real theTolerance)
494 if (theShape.IsNull()) return NULL;
496 //Add a new Glued object
497 Handle(GEOM_Object) aGlued = GetEngine()->AddObject(GetDocID(), GEOM_GLUED);
499 //Add a new Glue function
500 Handle(GEOM_Function) aFunction;
501 aFunction = aGlued->AddFunction(GEOMImpl_GlueDriver::GetID(), GLUE_FACES);
502 if (aFunction.IsNull()) return NULL;
504 //Check if the function is set correctly
505 if (aFunction->GetDriverGUID() != GEOMImpl_GlueDriver::GetID()) return NULL;
507 GEOMImpl_IGlue aCI (aFunction);
509 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
510 if (aRefShape.IsNull()) return NULL;
512 aCI.SetBase(aRefShape);
513 aCI.SetTolerance(theTolerance);
515 //Compute the sub-shape value
516 Standard_Boolean isWarning = Standard_False;
518 if (!GetSolver()->ComputeFunction(aFunction)) {
519 SetErrorCode("Shape driver failed to glue faces");
523 catch (Standard_Failure) {
524 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
525 SetErrorCode(aFail->GetMessageString());
526 // to provide warning
527 if (!aFunction->GetValue().IsNull()) {
528 isWarning = Standard_True;
534 //Make a Python command
535 TCollection_AsciiString anEntry, aDescr;
536 TDF_Tool::Entry(aGlued->GetEntry(), anEntry);
538 aDescr += " = IShapesOperations.MakeGlueFaces(";
539 TDF_Tool::Entry(theShape->GetEntry(), anEntry);
540 aDescr += anEntry + ", ";
541 aDescr += TCollection_AsciiString(theTolerance) + ")";
543 aFunction->SetDescription(aDescr);
545 // to provide warning
546 if (!isWarning) SetErrorCode(OK);
550 //=============================================================================
554 //=============================================================================
555 Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::MakeExplode
556 (Handle(GEOM_Object) theShape,
557 const Standard_Integer theShapeType,
558 const Standard_Boolean isSorted)
560 // OSD_Timer timer1, timer2, timer3, timer4;
565 if (theShape.IsNull()) return NULL;
566 TopoDS_Shape aShape = theShape->GetValue();
567 if (aShape.IsNull()) return NULL;
569 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
570 Handle(GEOM_Object) anObj;
571 Handle(GEOM_Function) aFunction;
572 TopTools_MapOfShape mapShape;
573 TopTools_ListOfShape listShape;
575 if (aShape.ShapeType() == TopAbs_COMPOUND &&
576 (TopAbs_ShapeEnum(theShapeType) == TopAbs_SHAPE ||
577 TopAbs_ShapeEnum(theShapeType) == TopAbs_COMPSOLID ||
578 TopAbs_ShapeEnum(theShapeType) == TopAbs_COMPOUND)) {
579 TopoDS_Iterator It (aShape, Standard_True, Standard_True);
580 for (; It.More(); It.Next()) {
581 if (mapShape.Add(It.Value())) {
582 if (TopAbs_ShapeEnum(theShapeType) == TopAbs_SHAPE ||
583 TopAbs_ShapeEnum(theShapeType) == It.Value().ShapeType()) {
584 listShape.Append(It.Value());
589 TopExp_Explorer exp (aShape, TopAbs_ShapeEnum(theShapeType));
590 for (; exp.More(); exp.Next())
591 if (mapShape.Add(exp.Current()))
592 listShape.Append(exp.Current());
595 if (listShape.IsEmpty()) {
596 SetErrorCode("The given shape has no sub-shapes of the requested type");
604 SortShapes(listShape);
609 TopTools_IndexedMapOfShape anIndices;
610 TopExp::MapShapes(aShape, anIndices);
611 Handle(TColStd_HArray1OfInteger) anArray;
613 TopTools_ListIteratorOfListOfShape itSub (listShape);
614 TCollection_AsciiString anAsciiList = "[", anEntry;
615 for (int index = 1; itSub.More(); itSub.Next(), ++index) {
616 TopoDS_Shape aValue = itSub.Value();
617 anArray = new TColStd_HArray1OfInteger(1,1);
618 anArray->SetValue(1, anIndices.FindIndex(aValue));
619 anObj = GetEngine()->AddSubShape(theShape, anArray);
622 TDF_Tool::Entry(anObj->GetEntry(), anEntry);
623 anAsciiList += anEntry;
630 anAsciiList.Trunc(anAsciiList.Length() - 1);
633 anAsciiList = TCollection_AsciiString("\n") + anAsciiList;
635 //The explode doesn't change object so no new function is requiered.
636 aFunction = theShape->GetLastFunction();
638 //Make a Python command
639 TCollection_AsciiString aDescr(anAsciiList);
640 TDF_Tool::Entry(theShape->GetEntry(), anEntry);
641 aDescr += " = IShapesOperations.MakeExplode(";
642 aDescr += (anEntry + ",");
644 aDescr += (TCollection_AsciiString(theShapeType) + ", 1)");
646 aDescr += (TCollection_AsciiString(theShapeType) + ", 0)");
648 TCollection_AsciiString anOldDescr = aFunction->GetDescription();
649 anOldDescr = anOldDescr + aDescr;
650 aFunction->SetDescription(anOldDescr);
656 // cout << "Explosure takes:" << endl;
658 // cout << "Sorting takes:" << endl;
660 // cout << "Sub-shapes addition takes:" << endl;
662 // cout << "Update Description takes:" << endl;
668 //=============================================================================
672 //=============================================================================
673 Handle(TColStd_HSequenceOfInteger) GEOMImpl_IShapesOperations::SubShapeAllIDs
674 (Handle(GEOM_Object) theShape,
675 const Standard_Integer theShapeType,
676 const Standard_Boolean isSorted)
680 if (theShape.IsNull()) return NULL;
681 TopoDS_Shape aShape = theShape->GetValue();
682 if (aShape.IsNull()) return NULL;
684 Handle(TColStd_HSequenceOfInteger) aSeq = new TColStd_HSequenceOfInteger;
685 TopTools_MapOfShape mapShape;
686 TopTools_ListOfShape listShape;
688 if (aShape.ShapeType() == TopAbs_COMPOUND &&
689 (TopAbs_ShapeEnum(theShapeType) == TopAbs_SHAPE ||
690 TopAbs_ShapeEnum(theShapeType) == TopAbs_COMPSOLID ||
691 TopAbs_ShapeEnum(theShapeType) == TopAbs_COMPOUND)) {
692 TopoDS_Iterator It (aShape, Standard_True, Standard_True);
693 for (; It.More(); It.Next()) {
694 if (mapShape.Add(It.Value())) {
695 if (TopAbs_ShapeEnum(theShapeType) == TopAbs_SHAPE ||
696 TopAbs_ShapeEnum(theShapeType) == It.Value().ShapeType()) {
697 listShape.Append(It.Value());
702 TopExp_Explorer exp (aShape, TopAbs_ShapeEnum(theShapeType));
703 for (; exp.More(); exp.Next())
704 if (mapShape.Add(exp.Current()))
705 listShape.Append(exp.Current());
708 if (listShape.IsEmpty()) {
709 SetErrorCode("The given shape has no sub-shapes of the requested type");
714 SortShapes(listShape);
716 TopTools_IndexedMapOfShape anIndices;
717 TopExp::MapShapes(aShape, anIndices);
718 Handle(TColStd_HArray1OfInteger) anArray;
720 TopTools_ListIteratorOfListOfShape itSub (listShape);
721 for (int index = 1; itSub.More(); itSub.Next(), ++index) {
722 TopoDS_Shape aValue = itSub.Value();
723 aSeq->Append(anIndices.FindIndex(aValue));
726 //The explode doesn't change object so no new function is required.
727 Handle(GEOM_Function) aFunction = theShape->GetLastFunction();
729 //Make a Python command
730 TCollection_AsciiString aDescr
731 ("\nlistSubShapeAllIDs = IShapesOperations.SubShapeAllIDs(");
732 TCollection_AsciiString anEntry;
733 TDF_Tool::Entry(theShape->GetEntry(), anEntry);
734 aDescr += (anEntry + ",");
736 aDescr += (TCollection_AsciiString(theShapeType) + ", 1)");
738 aDescr += (TCollection_AsciiString(theShapeType) + ", 0)");
740 TCollection_AsciiString anOldDescr = aFunction->GetDescription();
741 anOldDescr = anOldDescr + aDescr;
742 aFunction->SetDescription(anOldDescr);
748 //=============================================================================
752 //=============================================================================
753 Handle(GEOM_Object) GEOMImpl_IShapesOperations::GetSubShape
754 (Handle(GEOM_Object) theMainShape,
755 const Standard_Integer theID)
759 if (theMainShape.IsNull()) return NULL;
761 Handle(TColStd_HArray1OfInteger) anArray = new TColStd_HArray1OfInteger(1,1);
762 anArray->SetValue(1, theID);
763 Handle(GEOM_Object) anObj = GetEngine()->AddSubShape(theMainShape, anArray);
764 if (anObj.IsNull()) {
765 SetErrorCode("Can not get a sub-shape with the given ID");
769 //The GetSubShape() doesn't change object so no new function is requiered.
770 Handle(GEOM_Function) aFunction = theMainShape->GetLastFunction();
772 //Make a Python command
773 TCollection_AsciiString aDescr ("\n");
774 TCollection_AsciiString anEntry;
775 TDF_Tool::Entry(anObj->GetEntry(), anEntry);
776 aDescr += anEntry + " = IShapesOperations.GetSubShape(";
777 TDF_Tool::Entry(theMainShape->GetEntry(), anEntry);
778 aDescr += anEntry + ", ";
779 aDescr += TCollection_AsciiString(theID) + ")";
781 TCollection_AsciiString anOldDescr = aFunction->GetDescription();
782 anOldDescr = anOldDescr + aDescr;
783 aFunction->SetDescription(anOldDescr);
790 //=============================================================================
794 //=============================================================================
795 Standard_Integer GEOMImpl_IShapesOperations::NumberOfFaces (Handle(GEOM_Object) theShape)
799 Standard_Integer nb = 0;
801 if (theShape.IsNull()) return -1;
802 TopoDS_Shape aShape = theShape->GetValue();
803 if (aShape.IsNull()) return -1;
805 TopTools_MapOfShape mapShape;
807 TopExp_Explorer exp (aShape, TopAbs_FACE);
808 for (; exp.More(); exp.Next())
809 if (mapShape.Add(exp.Current()))
816 //=============================================================================
820 //=============================================================================
821 Standard_Integer GEOMImpl_IShapesOperations::NumberOfEdges (Handle(GEOM_Object) theShape)
825 Standard_Integer nb = 0;
827 if (theShape.IsNull()) return -1;
828 TopoDS_Shape aShape = theShape->GetValue();
829 if (aShape.IsNull()) return -1;
831 TopTools_MapOfShape mapShape;
833 TopExp_Explorer exp (aShape, TopAbs_EDGE);
834 for (; exp.More(); exp.Next())
835 if (mapShape.Add(exp.Current()))
842 //=============================================================================
846 //=============================================================================
847 Handle(GEOM_Object) GEOMImpl_IShapesOperations::ReverseShape(Handle(GEOM_Object) theShape)
851 if (theShape.IsNull()) return NULL;
853 //Add a new reversed object
854 Handle(GEOM_Object) aReversed = GetEngine()->AddObject(GetDocID(), theShape->GetType());
856 //Add a new Revese function
857 Handle(GEOM_Function) aFunction;
858 aFunction = aReversed->AddFunction(GEOMImpl_ShapeDriver::GetID(), REVERSE_ORIENTATION);
859 if (aFunction.IsNull()) return NULL;
861 //Check if the function is set correctly
862 if (aFunction->GetDriverGUID() != GEOMImpl_ShapeDriver::GetID()) return NULL;
864 GEOMImpl_IShapes aSI (aFunction);
866 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
867 if (aRefShape.IsNull()) return NULL;
869 aSI.SetBase(aRefShape);
871 //Compute the sub-shape value
873 if (!GetSolver()->ComputeFunction(aFunction)) {
874 SetErrorCode("Shape driver failed to reverse shape");
878 catch (Standard_Failure) {
879 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
880 SetErrorCode(aFail->GetMessageString());
884 //Make a Python command
885 TCollection_AsciiString anEntry, aDescr;
886 TDF_Tool::Entry(aReversed->GetEntry(), anEntry);
888 aDescr += " = IShapesOperations.ReverseShape(";
889 TDF_Tool::Entry(theShape->GetEntry(), anEntry);
890 aDescr += anEntry + ")";
892 aFunction->SetDescription(aDescr);
898 //=============================================================================
902 //=============================================================================
903 Handle(TColStd_HSequenceOfInteger) GEOMImpl_IShapesOperations::GetFreeFacesIDs
904 (Handle(GEOM_Object) theShape)
908 if (theShape.IsNull()) return NULL;
909 TopoDS_Shape aShape = theShape->GetValue();
910 if (aShape.IsNull()) return NULL;
912 Handle(TColStd_HSequenceOfInteger) aSeq = new TColStd_HSequenceOfInteger;
914 TopTools_IndexedDataMapOfShapeListOfShape mapFaceBlocks;
915 GEOMImpl_Block6Explorer::MapShapesAndAncestors
916 (aShape, TopAbs_FACE, TopAbs_SOLID, mapFaceBlocks);
918 Standard_Integer ind = 1, nbFaces = mapFaceBlocks.Extent();
921 SetErrorCode("The given shape has no faces");
925 TopTools_IndexedMapOfShape anIndices;
926 TopExp::MapShapes(aShape, anIndices);
929 for (; ind <= nbFaces; ind++) {
930 if (mapFaceBlocks.FindFromIndex(ind).Extent() != 2) {
931 id = anIndices.FindIndex(mapFaceBlocks.FindKey(ind));
936 //The explode doesn't change object so no new function is required.
937 Handle(GEOM_Function) aFunction = theShape->GetLastFunction();
939 //Make a Python command
940 TCollection_AsciiString aDescr ("\nlistFreeFacesIDs = IShapesOperations.GetFreeFacesIDs(");
941 TCollection_AsciiString anEntry;
942 TDF_Tool::Entry(theShape->GetEntry(), anEntry);
943 aDescr += (anEntry + ")");
945 TCollection_AsciiString anOldDescr = aFunction->GetDescription();
946 anOldDescr = anOldDescr + aDescr;
947 aFunction->SetDescription(anOldDescr);
953 //=============================================================================
957 //=============================================================================
958 Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::GetSharedShapes
959 (Handle(GEOM_Object) theShape1,
960 Handle(GEOM_Object) theShape2,
961 const Standard_Integer theShapeType)
965 if (theShape1.IsNull() || theShape2.IsNull()) return NULL;
967 TopoDS_Shape aShape1 = theShape1->GetValue();
968 TopoDS_Shape aShape2 = theShape2->GetValue();
970 if (aShape1.IsNull() || aShape2.IsNull()) return NULL;
972 TopTools_IndexedMapOfShape anIndices;
973 TopExp::MapShapes(aShape1, anIndices);
974 Handle(TColStd_HArray1OfInteger) anArray;
976 TopTools_IndexedMapOfShape mapShape1;
977 TopExp::MapShapes(aShape1, TopAbs_ShapeEnum(theShapeType), mapShape1);
979 Handle(GEOM_Object) anObj;
980 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
982 TopTools_MapOfShape mapShape2;
983 TopExp_Explorer exp (aShape2, TopAbs_ShapeEnum(theShapeType));
984 for (; exp.More(); exp.Next()) {
985 TopoDS_Shape aSS = exp.Current();
986 if (mapShape2.Add(aSS) && mapShape1.Contains(aSS)) {
987 anArray = new TColStd_HArray1OfInteger(1,1);
988 anArray->SetValue(1, anIndices.FindIndex(aSS));
989 anObj = GetEngine()->AddSubShape(theShape1, anArray);
994 if (aSeq->IsEmpty()) {
995 SetErrorCode("The given shapes have no shared sub-shapes of the requested type");
999 //The explode doesn't change object so no new function is required.
1000 Handle(GEOM_Function) aFunction = theShape1->GetLastFunction();
1002 //Make a Python command
1003 TCollection_AsciiString aDescr
1004 ("\nlistSharedShapes = IShapesOperations.GetSharedShapes(");
1005 TCollection_AsciiString anEntry;
1006 TDF_Tool::Entry(theShape1->GetEntry(), anEntry);
1007 aDescr += (anEntry + ",");
1008 TDF_Tool::Entry(theShape2->GetEntry(), anEntry);
1009 aDescr += (anEntry + ",");
1010 aDescr += TCollection_AsciiString(theShapeType) + ")";
1012 TCollection_AsciiString anOldDescr = aFunction->GetDescription();
1013 anOldDescr = anOldDescr + aDescr;
1014 aFunction->SetDescription(anOldDescr);
1020 //=============================================================================
1024 //=============================================================================
1025 Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::GetShapesOnPlane
1026 (const Handle(GEOM_Object)& theShape,
1027 const Standard_Integer theShapeType,
1028 const Handle(GEOM_Object)& theAx1,
1029 const GEOMAlgo_State theState)
1033 // MESSAGE("--------------------------- GetShapesOnPlane phase 1 takes:");
1034 // OSD_Timer timer1;
1037 if (theShape.IsNull() || theAx1.IsNull()) return NULL;
1039 TopoDS_Shape aShape = theShape->GetValue();
1040 TopoDS_Shape anAx1 = theAx1->GetValue();
1042 if (aShape.IsNull() || anAx1.IsNull()) return NULL;
1044 TopAbs_ShapeEnum aShapeType = TopAbs_ShapeEnum(theShapeType);
1045 if (aShapeType != TopAbs_VERTEX &&
1046 aShapeType != TopAbs_EDGE &&
1047 aShapeType != TopAbs_FACE &&
1048 aShapeType != TopAbs_SOLID) {
1049 SetErrorCode("Only solids, vertices, edges or faces can be found by this method");
1054 if (anAx1.ShapeType() != TopAbs_EDGE) return NULL;
1055 TopoDS_Edge anEdge = TopoDS::Edge(anAx1);
1056 TopoDS_Vertex V1, V2;
1057 TopExp::Vertices(anEdge, V1, V2, Standard_True);
1058 if (V1.IsNull() || V2.IsNull()) {
1059 SetErrorCode("Bad edge given for the plane normal vector");
1062 gp_Pnt aLoc = BRep_Tool::Pnt(V1);
1063 gp_Vec aVec (aLoc, BRep_Tool::Pnt(V2));
1064 if (aVec.Magnitude() < Precision::Confusion()) {
1065 SetErrorCode("Vector with null magnitude given");
1069 Handle(Geom_Plane) aPlane = new Geom_Plane(aLoc, aVec);
1071 // Check presence of triangulation, build if need
1072 if (!CheckTriangulation(aShape))
1076 GEOMAlgo_FinderShapeOn1 aFinder;
1077 Standard_Real aTol = 0.0001; // default value
1079 aFinder.SetShape(aShape);
1080 aFinder.SetTolerance(aTol);
1081 aFinder.SetSurface(aPlane);
1082 aFinder.SetShapeType(aShapeType);
1083 aFinder.SetState(theState);
1085 // Sets the minimal number of inner points for the faces that do not have own
1086 // inner points at all (for e.g. rectangular planar faces have just 2 triangles).
1088 aFinder.SetNbPntsMin(3);
1089 // Sets the maximal number of inner points for edges or faces.
1090 // It is usefull for the cases when this number is very big (e.g =2000) to improve
1091 // the performance. If this value =0, all inner points will be taken into account.
1093 aFinder.SetNbPntsMax(100);
1098 // MESSAGE("--------------------------- Perform on Plane takes:");
1105 // MESSAGE("--------------------------- GetShapesOnPlane phase 3 takes:");
1109 // Interprete results
1110 Standard_Integer iErr = aFinder.ErrorStatus();
1111 // the detailed description of error codes is in GEOMAlgo_FinderShapeOn1.cxx
1113 MESSAGE(" iErr : " << iErr);
1114 TCollection_AsciiString aMsg (" iErr : ");
1115 aMsg += TCollection_AsciiString(iErr);
1119 Standard_Integer iWrn = aFinder.WarningStatus();
1120 // the detailed description of warning codes is in GEOMAlgo_FinderShapeOn1.cxx
1122 MESSAGE(" *** iWrn : " << iWrn);
1125 const TopTools_ListOfShape& listSS = aFinder.Shapes(); // the result
1127 if (listSS.Extent() < 1) {
1128 SetErrorCode("Not a single sub-shape of the requested type found on the given plane");
1135 // MESSAGE("--------------------------- GetShapesOnPlane phase 4 takes:");
1139 // Fill sequence of objects
1140 TopTools_IndexedMapOfShape anIndices;
1141 TopExp::MapShapes(aShape, anIndices);
1143 Handle(GEOM_Object) anObj;
1144 Handle(TColStd_HArray1OfInteger) anArray;
1145 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
1147 TopTools_ListIteratorOfListOfShape itSub (listSS);
1148 for (int index = 1; itSub.More(); itSub.Next(), ++index) {
1149 int id = anIndices.FindIndex(itSub.Value());
1150 anArray = new TColStd_HArray1OfInteger(1,1);
1151 anArray->SetValue(1, id);
1152 anObj = GetEngine()->AddSubShape(theShape, anArray);
1153 aSeq->Append(anObj);
1159 // MESSAGE("--------------------------- GetShapesOnPlane phase 5 takes:");
1163 // The GetShapesOnPlane() doesn't change object so no new function is required.
1164 Handle(GEOM_Function) aFunction = theShape->GetLastFunction();
1166 // Make a Python command
1167 TCollection_AsciiString anEntry, aDescr
1168 ("\nlistShapesOnPlane = IShapesOperations.GetShapesOnPlane(");
1169 TDF_Tool::Entry(theShape->GetEntry(), anEntry);
1170 aDescr += anEntry + TCollection_AsciiString(theShapeType) + ",";
1171 TDF_Tool::Entry(theAx1->GetEntry(), anEntry);
1172 aDescr += anEntry + ",";
1173 aDescr += TCollection_AsciiString(theState) + ")";
1175 TCollection_AsciiString anOldDescr = aFunction->GetDescription();
1176 anOldDescr += aDescr;
1177 aFunction->SetDescription(anOldDescr);
1186 //=============================================================================
1188 * GetShapesOnCylinder
1190 //=============================================================================
1191 Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::GetShapesOnCylinder
1192 (const Handle(GEOM_Object)& theShape,
1193 const Standard_Integer theShapeType,
1194 const Handle(GEOM_Object)& theAxis,
1195 const Standard_Real theRadius,
1196 const GEOMAlgo_State theState)
1200 if (theShape.IsNull() || theAxis.IsNull()) return NULL;
1202 TopoDS_Shape aShape = theShape->GetValue();
1203 TopoDS_Shape anAxis = theAxis->GetValue();
1205 if (aShape.IsNull() || anAxis.IsNull()) return NULL;
1207 TopAbs_ShapeEnum aShapeType = TopAbs_ShapeEnum(theShapeType);
1208 if (aShapeType != TopAbs_VERTEX &&
1209 aShapeType != TopAbs_EDGE &&
1210 aShapeType != TopAbs_FACE &&
1211 aShapeType != TopAbs_SOLID) {
1212 SetErrorCode("Only solids, vertices, edges or faces can be found by this method");
1216 //Axis of the cylinder
1217 if (anAxis.ShapeType() != TopAbs_EDGE) {
1218 SetErrorCode("Not an edge given for the axis");
1221 TopoDS_Edge anEdge = TopoDS::Edge(anAxis);
1222 TopoDS_Vertex V1, V2;
1223 TopExp::Vertices(anEdge, V1, V2, Standard_True);
1224 if (V1.IsNull() || V2.IsNull()) {
1225 SetErrorCode("Bad edge given for the axis");
1228 gp_Pnt aLoc = BRep_Tool::Pnt(V1);
1229 gp_Vec aVec (aLoc, BRep_Tool::Pnt(V2));
1230 if (aVec.Magnitude() < Precision::Confusion()) {
1231 SetErrorCode("Vector with null magnitude given");
1235 gp_Ax3 anAx3 (aLoc, aVec);
1236 Handle(Geom_CylindricalSurface) aCylinder =
1237 new Geom_CylindricalSurface(anAx3, theRadius);
1239 // Check presence of triangulation, build if need
1240 if (!CheckTriangulation(aShape))
1244 GEOMAlgo_FinderShapeOn1 aFinder;
1245 Standard_Real aTol = 0.0001; // default value
1247 aFinder.SetShape(aShape);
1248 aFinder.SetTolerance(aTol);
1249 aFinder.SetSurface(aCylinder);
1250 aFinder.SetShapeType(aShapeType);
1251 aFinder.SetState(theState);
1253 aFinder.SetNbPntsMin(3);
1254 aFinder.SetNbPntsMax(100);
1258 // Interprete results
1259 Standard_Integer iErr = aFinder.ErrorStatus();
1260 // the detailed description of error codes is in GEOMAlgo_FinderShapeOn1.cxx
1262 MESSAGE(" iErr : " << iErr);
1263 TCollection_AsciiString aMsg (" iErr : ");
1264 aMsg += TCollection_AsciiString(iErr);
1268 Standard_Integer iWrn = aFinder.WarningStatus();
1269 // the detailed description of warning codes is in GEOMAlgo_FinderShapeOn1.cxx
1271 MESSAGE(" *** iWrn : " << iWrn);
1274 const TopTools_ListOfShape& listSS = aFinder.Shapes(); // the result
1276 if (listSS.Extent() < 1) {
1277 SetErrorCode("Not a single sub-shape of the requested type found on the given cylinder");
1281 // Fill sequence of objects
1282 TopTools_IndexedMapOfShape anIndices;
1283 TopExp::MapShapes(aShape, anIndices);
1285 Handle(GEOM_Object) anObj;
1286 Handle(TColStd_HArray1OfInteger) anArray;
1287 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
1289 TopTools_ListIteratorOfListOfShape itSub (listSS);
1290 for (int index = 1; itSub.More(); itSub.Next(), ++index) {
1291 int id = anIndices.FindIndex(itSub.Value());
1292 anArray = new TColStd_HArray1OfInteger(1,1);
1293 anArray->SetValue(1, id);
1294 anObj = GetEngine()->AddSubShape(theShape, anArray);
1295 aSeq->Append(anObj);
1298 // The GetShapesOnCylinder() doesn't change object so no new function is required.
1299 Handle(GEOM_Function) aFunction = theShape->GetLastFunction();
1301 // Make a Python command
1302 TCollection_AsciiString anEntry, aDescr
1303 ("\nlistShapesOnCylinder = IShapesOperations.GetShapesOnCylinder(");
1304 TDF_Tool::Entry(theShape->GetEntry(), anEntry);
1305 aDescr += anEntry + TCollection_AsciiString(theShapeType) + ",";
1306 TDF_Tool::Entry(theAxis->GetEntry(), anEntry);
1307 aDescr += anEntry + ",";
1308 aDescr += TCollection_AsciiString(theRadius) + ",";
1309 aDescr += TCollection_AsciiString(theState) + ")";
1311 TCollection_AsciiString anOldDescr = aFunction->GetDescription();
1312 anOldDescr += aDescr;
1313 aFunction->SetDescription(anOldDescr);
1319 //=============================================================================
1323 //=============================================================================
1324 Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::GetShapesOnSphere
1325 (const Handle(GEOM_Object)& theShape,
1326 const Standard_Integer theShapeType,
1327 const Handle(GEOM_Object)& theCenter,
1328 const Standard_Real theRadius,
1329 const GEOMAlgo_State theState)
1333 if (theShape.IsNull() || theCenter.IsNull()) return NULL;
1335 TopoDS_Shape aShape = theShape->GetValue();
1336 TopoDS_Shape aCenter = theCenter->GetValue();
1338 if (aShape.IsNull() || aCenter.IsNull()) return NULL;
1340 TopAbs_ShapeEnum aShapeType = TopAbs_ShapeEnum(theShapeType);
1341 if (aShapeType != TopAbs_VERTEX &&
1342 aShapeType != TopAbs_EDGE &&
1343 aShapeType != TopAbs_FACE &&
1344 aShapeType != TopAbs_SOLID) {
1345 SetErrorCode("Only solids, vertices, edges or faces can be found by this method");
1349 // Center of the sphere
1350 if (aCenter.ShapeType() != TopAbs_VERTEX) return NULL;
1351 gp_Pnt aLoc = BRep_Tool::Pnt(TopoDS::Vertex(aCenter));
1353 gp_Ax3 anAx3 (aLoc, gp::DZ());
1354 Handle(Geom_SphericalSurface) aSphere =
1355 new Geom_SphericalSurface(anAx3, theRadius);
1357 // Check presence of triangulation, build if need
1358 if (!CheckTriangulation(aShape))
1362 GEOMAlgo_FinderShapeOn1 aFinder;
1363 Standard_Real aTol = 0.0001; // default value
1365 aFinder.SetShape(aShape);
1366 aFinder.SetTolerance(aTol);
1367 aFinder.SetSurface(aSphere);
1368 aFinder.SetShapeType(aShapeType);
1369 aFinder.SetState(theState);
1371 aFinder.SetNbPntsMin(3);
1372 aFinder.SetNbPntsMax(100);
1376 // Interprete results
1377 Standard_Integer iErr = aFinder.ErrorStatus();
1378 // the detailed description of error codes is in GEOMAlgo_FinderShapeOn1.cxx
1380 MESSAGE(" iErr : " << iErr);
1381 TCollection_AsciiString aMsg (" iErr : ");
1382 aMsg += TCollection_AsciiString(iErr);
1386 Standard_Integer iWrn = aFinder.WarningStatus();
1387 // the detailed description of warning codes is in GEOMAlgo_FinderShapeOn1.cxx
1389 MESSAGE(" *** iWrn : " << iWrn);
1392 const TopTools_ListOfShape& listSS = aFinder.Shapes(); // the result
1394 if (listSS.Extent() < 1) {
1395 SetErrorCode("Not a single sub-shape of the requested type found on the given sphere");
1399 // Fill sequence of objects
1400 TopTools_IndexedMapOfShape anIndices;
1401 TopExp::MapShapes(aShape, anIndices);
1403 Handle(GEOM_Object) anObj;
1404 Handle(TColStd_HArray1OfInteger) anArray;
1405 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
1407 TopTools_ListIteratorOfListOfShape itSub (listSS);
1408 for (int index = 1; itSub.More(); itSub.Next(), ++index) {
1409 int id = anIndices.FindIndex(itSub.Value());
1410 anArray = new TColStd_HArray1OfInteger(1,1);
1411 anArray->SetValue(1, id);
1412 anObj = GetEngine()->AddSubShape(theShape, anArray);
1413 aSeq->Append(anObj);
1416 // The GetShapesOnSphere() doesn't change object so no new function is required.
1417 Handle(GEOM_Function) aFunction = theShape->GetLastFunction();
1419 // Make a Python command
1420 TCollection_AsciiString anEntry, aDescr
1421 ("\nlistShapesOnSphere = IShapesOperations.GetShapesOnSphere(");
1422 TDF_Tool::Entry(theShape->GetEntry(), anEntry);
1423 aDescr += anEntry + TCollection_AsciiString(theShapeType) + ",";
1424 TDF_Tool::Entry(theCenter->GetEntry(), anEntry);
1425 aDescr += anEntry + ",";
1426 aDescr += TCollection_AsciiString(theRadius) + ",";
1427 aDescr += TCollection_AsciiString(theState) + ")";
1429 TCollection_AsciiString anOldDescr = aFunction->GetDescription();
1430 anOldDescr += aDescr;
1431 aFunction->SetDescription(anOldDescr);
1437 //=============================================================================
1439 * GetShapesOnPlaneIDs
1441 //=============================================================================
1442 Handle(TColStd_HSequenceOfInteger) GEOMImpl_IShapesOperations::GetShapesOnPlaneIDs
1443 (const Handle(GEOM_Object)& theShape,
1444 const Standard_Integer theShapeType,
1445 const Handle(GEOM_Object)& theAx1,
1446 const GEOMAlgo_State theState)
1450 if (theShape.IsNull() || theAx1.IsNull()) return NULL;
1452 TopoDS_Shape aShape = theShape->GetValue();
1453 TopoDS_Shape anAx1 = theAx1->GetValue();
1455 if (aShape.IsNull() || anAx1.IsNull()) return NULL;
1457 TopAbs_ShapeEnum aShapeType = TopAbs_ShapeEnum(theShapeType);
1458 if (aShapeType != TopAbs_VERTEX &&
1459 aShapeType != TopAbs_EDGE &&
1460 aShapeType != TopAbs_FACE &&
1461 aShapeType != TopAbs_SOLID) {
1462 SetErrorCode("Only solids, vertices, edges or faces can be found by this method");
1467 if (anAx1.ShapeType() != TopAbs_EDGE) return NULL;
1468 TopoDS_Edge anEdge = TopoDS::Edge(anAx1);
1469 TopoDS_Vertex V1, V2;
1470 TopExp::Vertices(anEdge, V1, V2, Standard_True);
1471 if (V1.IsNull() || V2.IsNull()) {
1472 SetErrorCode("Bad edge given for the plane normal vector");
1475 gp_Pnt aLoc = BRep_Tool::Pnt(V1);
1476 gp_Vec aVec (aLoc, BRep_Tool::Pnt(V2));
1477 if (aVec.Magnitude() < Precision::Confusion()) {
1478 SetErrorCode("Vector with null magnitude given");
1482 Handle(Geom_Plane) aPlane = new Geom_Plane(aLoc, aVec);
1484 // Check presence of triangulation, build if need
1485 if (!CheckTriangulation(aShape))
1489 GEOMAlgo_FinderShapeOn1 aFinder;
1490 Standard_Real aTol = 0.0001; // default value
1492 aFinder.SetShape(aShape);
1493 aFinder.SetTolerance(aTol);
1494 aFinder.SetSurface(aPlane);
1495 aFinder.SetShapeType(aShapeType);
1496 aFinder.SetState(theState);
1498 aFinder.SetNbPntsMin(3);
1499 aFinder.SetNbPntsMax(100);
1503 // Interprete results
1504 Standard_Integer iErr = aFinder.ErrorStatus();
1505 // the detailed description of error codes is in GEOMAlgo_FinderShapeOn1.cxx
1507 MESSAGE(" iErr : " << iErr);
1508 TCollection_AsciiString aMsg (" iErr : ");
1509 aMsg += TCollection_AsciiString(iErr);
1513 Standard_Integer iWrn = aFinder.WarningStatus();
1514 // the detailed description of warning codes is in GEOMAlgo_FinderShapeOn1.cxx
1516 MESSAGE(" *** iWrn : " << iWrn);
1519 const TopTools_ListOfShape& listSS = aFinder.Shapes(); // the result
1521 if (listSS.Extent() < 1) {
1522 SetErrorCode("Not a single sub-shape of the requested type found on the given plane");
1526 // Fill sequence of objects
1527 TopTools_IndexedMapOfShape anIndices;
1528 TopExp::MapShapes(aShape, anIndices);
1530 Handle(TColStd_HSequenceOfInteger) aSeq = new TColStd_HSequenceOfInteger;
1532 TopTools_ListIteratorOfListOfShape itSub (listSS);
1533 for (int index = 1; itSub.More(); itSub.Next(), ++index) {
1534 int id = anIndices.FindIndex(itSub.Value());
1538 // The GetShapesOnPlane() doesn't change object so no new function is required.
1539 Handle(GEOM_Function) aFunction = theShape->GetLastFunction();
1541 // Make a Python command
1542 TCollection_AsciiString anEntry, aDescr
1543 ("\nlistShapesOnPlane = IShapesOperations.GetShapesOnPlaneIDs(");
1544 TDF_Tool::Entry(theShape->GetEntry(), anEntry);
1545 aDescr += anEntry + TCollection_AsciiString(theShapeType) + ",";
1546 TDF_Tool::Entry(theAx1->GetEntry(), anEntry);
1547 aDescr += anEntry + ",";
1548 aDescr += TCollection_AsciiString(theState) + ")";
1550 TCollection_AsciiString anOldDescr = aFunction->GetDescription();
1551 anOldDescr += aDescr;
1552 aFunction->SetDescription(anOldDescr);
1558 //=============================================================================
1560 * GetShapesOnCylinderIDs
1562 //=============================================================================
1563 Handle(TColStd_HSequenceOfInteger) GEOMImpl_IShapesOperations::GetShapesOnCylinderIDs
1564 (const Handle(GEOM_Object)& theShape,
1565 const Standard_Integer theShapeType,
1566 const Handle(GEOM_Object)& theAxis,
1567 const Standard_Real theRadius,
1568 const GEOMAlgo_State theState)
1572 if (theShape.IsNull() || theAxis.IsNull()) return NULL;
1574 TopoDS_Shape aShape = theShape->GetValue();
1575 TopoDS_Shape anAxis = theAxis->GetValue();
1577 if (aShape.IsNull() || anAxis.IsNull()) return NULL;
1579 TopAbs_ShapeEnum aShapeType = TopAbs_ShapeEnum(theShapeType);
1580 if (aShapeType != TopAbs_VERTEX &&
1581 aShapeType != TopAbs_EDGE &&
1582 aShapeType != TopAbs_FACE &&
1583 aShapeType != TopAbs_SOLID) {
1584 SetErrorCode("Only solids, vertices, edges or faces can be found by this method");
1588 //Axis of the cylinder
1589 if (anAxis.ShapeType() != TopAbs_EDGE) {
1590 SetErrorCode("Not an edge given for the axis");
1593 TopoDS_Edge anEdge = TopoDS::Edge(anAxis);
1594 TopoDS_Vertex V1, V2;
1595 TopExp::Vertices(anEdge, V1, V2, Standard_True);
1596 if (V1.IsNull() || V2.IsNull()) {
1597 SetErrorCode("Bad edge given for the axis");
1600 gp_Pnt aLoc = BRep_Tool::Pnt(V1);
1601 gp_Vec aVec (aLoc, BRep_Tool::Pnt(V2));
1602 if (aVec.Magnitude() < Precision::Confusion()) {
1603 SetErrorCode("Vector with null magnitude given");
1607 gp_Ax3 anAx3 (aLoc, aVec);
1608 Handle(Geom_CylindricalSurface) aCylinder =
1609 new Geom_CylindricalSurface(anAx3, theRadius);
1611 // Check presence of triangulation, build if need
1612 if (!CheckTriangulation(aShape))
1616 GEOMAlgo_FinderShapeOn1 aFinder;
1617 Standard_Real aTol = 0.0001; // default value
1619 aFinder.SetShape(aShape);
1620 aFinder.SetTolerance(aTol);
1621 aFinder.SetSurface(aCylinder);
1622 aFinder.SetShapeType(aShapeType);
1623 aFinder.SetState(theState);
1625 aFinder.SetNbPntsMin(3);
1626 aFinder.SetNbPntsMax(100);
1630 // Interprete results
1631 Standard_Integer iErr = aFinder.ErrorStatus();
1632 // the detailed description of error codes is in GEOMAlgo_FinderShapeOn1.cxx
1634 MESSAGE(" iErr : " << iErr);
1635 TCollection_AsciiString aMsg (" iErr : ");
1636 aMsg += TCollection_AsciiString(iErr);
1640 Standard_Integer iWrn = aFinder.WarningStatus();
1641 // the detailed description of warning codes is in GEOMAlgo_FinderShapeOn1.cxx
1643 MESSAGE(" *** iWrn : " << iWrn);
1646 const TopTools_ListOfShape& listSS = aFinder.Shapes(); // the result
1648 if (listSS.Extent() < 1) {
1649 SetErrorCode("Not a single sub-shape of the requested type found on the given cylinder");
1653 // Fill sequence of objects
1654 TopTools_IndexedMapOfShape anIndices;
1655 TopExp::MapShapes(aShape, anIndices);
1657 Handle(TColStd_HSequenceOfInteger) aSeq = new TColStd_HSequenceOfInteger;
1659 TopTools_ListIteratorOfListOfShape itSub (listSS);
1660 for (int index = 1; itSub.More(); itSub.Next(), ++index) {
1661 int id = anIndices.FindIndex(itSub.Value());
1665 // The GetShapesOnCylinder() doesn't change object so no new function is required.
1666 Handle(GEOM_Function) aFunction = theShape->GetLastFunction();
1668 // Make a Python command
1669 TCollection_AsciiString anEntry, aDescr
1670 ("\nlistShapesOnCylinder = IShapesOperations.GetShapesOnCylinderIDs(");
1671 TDF_Tool::Entry(theShape->GetEntry(), anEntry);
1672 aDescr += anEntry + TCollection_AsciiString(theShapeType) + ",";
1673 TDF_Tool::Entry(theAxis->GetEntry(), anEntry);
1674 aDescr += anEntry + ",";
1675 aDescr += TCollection_AsciiString(theRadius) + ",";
1676 aDescr += TCollection_AsciiString(theState) + ")";
1678 TCollection_AsciiString anOldDescr = aFunction->GetDescription();
1679 anOldDescr += aDescr;
1680 aFunction->SetDescription(anOldDescr);
1686 //=============================================================================
1688 * GetShapesOnSphereIDs
1690 //=============================================================================
1691 Handle(TColStd_HSequenceOfInteger) GEOMImpl_IShapesOperations::GetShapesOnSphereIDs
1692 (const Handle(GEOM_Object)& theShape,
1693 const Standard_Integer theShapeType,
1694 const Handle(GEOM_Object)& theCenter,
1695 const Standard_Real theRadius,
1696 const GEOMAlgo_State theState)
1700 if (theShape.IsNull() || theCenter.IsNull()) return NULL;
1702 TopoDS_Shape aShape = theShape->GetValue();
1703 TopoDS_Shape aCenter = theCenter->GetValue();
1705 if (aShape.IsNull() || aCenter.IsNull()) return NULL;
1707 TopAbs_ShapeEnum aShapeType = TopAbs_ShapeEnum(theShapeType);
1708 if (aShapeType != TopAbs_VERTEX &&
1709 aShapeType != TopAbs_EDGE &&
1710 aShapeType != TopAbs_FACE &&
1711 aShapeType != TopAbs_SOLID) {
1712 SetErrorCode("Only solids, vertices, edges or faces can be found by this method");
1716 // Center of the sphere
1717 if (aCenter.ShapeType() != TopAbs_VERTEX) return NULL;
1718 gp_Pnt aLoc = BRep_Tool::Pnt(TopoDS::Vertex(aCenter));
1720 gp_Ax3 anAx3 (aLoc, gp::DZ());
1721 Handle(Geom_SphericalSurface) aSphere =
1722 new Geom_SphericalSurface(anAx3, theRadius);
1724 // Check presence of triangulation, build if need
1725 if (!CheckTriangulation(aShape))
1729 GEOMAlgo_FinderShapeOn1 aFinder;
1730 Standard_Real aTol = 0.0001; // default value
1732 aFinder.SetShape(aShape);
1733 aFinder.SetTolerance(aTol);
1734 aFinder.SetSurface(aSphere);
1735 aFinder.SetShapeType(aShapeType);
1736 aFinder.SetState(theState);
1738 aFinder.SetNbPntsMin(3);
1739 aFinder.SetNbPntsMax(100);
1743 // Interprete results
1744 Standard_Integer iErr = aFinder.ErrorStatus();
1745 // the detailed description of error codes is in GEOMAlgo_FinderShapeOn1.cxx
1747 MESSAGE(" iErr : " << iErr);
1748 TCollection_AsciiString aMsg (" iErr : ");
1749 aMsg += TCollection_AsciiString(iErr);
1753 Standard_Integer iWrn = aFinder.WarningStatus();
1754 // the detailed description of warning codes is in GEOMAlgo_FinderShapeOn1.cxx
1756 MESSAGE(" *** iWrn : " << iWrn);
1759 const TopTools_ListOfShape& listSS = aFinder.Shapes(); // the result
1761 if (listSS.Extent() < 1) {
1762 SetErrorCode("Not a single sub-shape of the requested type found on the given sphere");
1766 // Fill sequence of objects
1767 TopTools_IndexedMapOfShape anIndices;
1768 TopExp::MapShapes(aShape, anIndices);
1770 Handle(TColStd_HSequenceOfInteger) aSeq = new TColStd_HSequenceOfInteger;
1772 TopTools_ListIteratorOfListOfShape itSub (listSS);
1773 for (int index = 1; itSub.More(); itSub.Next(), ++index) {
1774 int id = anIndices.FindIndex(itSub.Value());
1778 // The GetShapesOnSphere() doesn't change object so no new function is required.
1779 Handle(GEOM_Function) aFunction = theShape->GetLastFunction();
1781 // Make a Python command
1782 TCollection_AsciiString anEntry, aDescr
1783 ("\nlistShapesOnSphere = IShapesOperations.GetShapesOnSphereIDs(");
1784 TDF_Tool::Entry(theShape->GetEntry(), anEntry);
1785 aDescr += anEntry + TCollection_AsciiString(theShapeType) + ",";
1786 TDF_Tool::Entry(theCenter->GetEntry(), anEntry);
1787 aDescr += anEntry + ",";
1788 aDescr += TCollection_AsciiString(theRadius) + ",";
1789 aDescr += TCollection_AsciiString(theState) + ")";
1791 TCollection_AsciiString anOldDescr = aFunction->GetDescription();
1792 anOldDescr += aDescr;
1793 aFunction->SetDescription(anOldDescr);
1799 //=============================================================================
1803 //=============================================================================
1804 Handle(GEOM_Object) GEOMImpl_IShapesOperations::GetInPlace
1805 (Handle(GEOM_Object) theShapeWhere,
1806 Handle(GEOM_Object) theShapeWhat)
1810 if (theShapeWhere.IsNull() || theShapeWhat.IsNull()) return NULL;
1812 TopoDS_Shape aWhere = theShapeWhere->GetValue();
1813 TopoDS_Shape aWhat = theShapeWhat->GetValue();
1815 if (aWhere.IsNull() || aWhat.IsNull()) return NULL;
1817 //Fill array of indices
1818 Handle(TColStd_HArray1OfInteger) aModifiedArray;
1820 Handle(GEOM_Function) aWhereFunction = theShapeWhere->GetLastFunction();
1822 TopTools_IndexedMapOfShape aWhereIndices;
1823 TopExp::MapShapes(aWhere, aWhereIndices);
1825 if (aWhereIndices.Contains(aWhat)) {
1827 // entity was not changed by the operation
1828 Standard_Integer aWhatIndex = aWhereIndices.FindIndex(aWhat);
1829 aModifiedArray = new TColStd_HArray1OfInteger(1,1);
1830 aModifiedArray->SetValue(1, aWhatIndex);
1834 TDF_Label aHistoryLabel = aWhereFunction->GetHistoryEntry(Standard_False);
1835 if (aHistoryLabel.IsNull()) {
1836 SetErrorCode("Modifications history does not exist for the shape under consideration.");
1840 // search in history for all argument shapes
1841 Standard_Boolean isFound = Standard_False;
1843 TDF_LabelSequence aLabelSeq;
1844 aWhereFunction->GetDependency(aLabelSeq);
1845 Standard_Integer nbArg = aLabelSeq.Length();
1847 for (Standard_Integer iarg = 1; iarg <= nbArg && !isFound; iarg++) {
1849 TDF_Label anArgumentRefLabel = aLabelSeq.Value(iarg);
1851 Handle(GEOM_Object) anArgumentObject = GEOM_Object::GetReferencedObject(anArgumentRefLabel);
1852 TopoDS_Shape anArgumentShape = anArgumentObject->GetValue();
1854 TopTools_IndexedMapOfShape anArgumentIndices;
1855 TopExp::MapShapes(anArgumentShape, anArgumentIndices);
1857 if (anArgumentIndices.Contains(aWhat)) {
1858 isFound = Standard_True;
1859 Standard_Integer aWhatIndex = anArgumentIndices.FindIndex(aWhat);
1861 // Find corresponding label in history
1862 TDF_Label anArgumentHistoryLabel =
1863 aWhereFunction->GetArgumentHistoryEntry(anArgumentRefLabel, Standard_False);
1864 if (anArgumentHistoryLabel.IsNull()) {
1865 // Lost History of operation argument. Possibly, all its entities was removed.
1870 TDF_Label aWhatHistoryLabel = anArgumentHistoryLabel.FindChild(aWhatIndex, Standard_False);
1871 if (aWhatHistoryLabel.IsNull()) {
1877 Handle(TDataStd_IntegerArray) anIntegerArray;
1878 if (!aWhatHistoryLabel.FindAttribute(TDataStd_IntegerArray::GetID(), anIntegerArray)) {
1879 SetErrorCode("Error: Empty modifications history for the sought shape.");
1883 aModifiedArray = anIntegerArray->Array();
1884 if (aModifiedArray->Length() == 0) {
1885 SetErrorCode("Error: Empty modifications history for the sought shape.");
1892 SetErrorCode("The sought shape does not belong to any operation argument.");
1898 Handle(GEOM_Object) aResult = GetEngine()->AddSubShape(theShapeWhere, aModifiedArray);
1900 if (aModifiedArray->Length() > 1) {
1902 aResult->SetType(GEOM_GROUP);
1904 //Set a sub shape type
1905 TDF_Label aFreeLabel = aResult->GetFreeLabel();
1906 TopAbs_ShapeEnum aShapeType = aWhat.ShapeType();
1907 TDataStd_Integer::Set(aFreeLabel, (Standard_Integer)aShapeType);
1910 //Make a Python command
1911 TCollection_AsciiString anEntry, aDescr;
1912 TDF_Tool::Entry(aResult->GetEntry(), anEntry);
1914 aDescr += " = IShapesOperations.GetInPlace(";
1915 TDF_Tool::Entry(theShapeWhere->GetEntry(), anEntry);
1916 aDescr += anEntry + ",";
1917 TDF_Tool::Entry(theShapeWhat->GetEntry(), anEntry);
1918 aDescr += anEntry + ")";
1920 Handle(GEOM_Function) aFunction = aResult->GetFunction(1);
1921 aFunction->SetDescription(aDescr);
1927 //=======================================================================
1928 //function : SortShapes
1930 //=======================================================================
1931 void GEOMImpl_IShapesOperations::SortShapes(TopTools_ListOfShape& SL)
1933 Standard_Integer MaxShapes = SL.Extent();
1934 TopTools_Array1OfShape aShapes (1,MaxShapes);
1935 TColStd_Array1OfInteger OrderInd(1,MaxShapes);
1936 TColStd_Array1OfReal MidXYZ (1,MaxShapes); //X,Y,Z;
1937 TColStd_Array1OfReal Length (1,MaxShapes); //X,Y,Z;
1939 // Computing of CentreOfMass
1940 Standard_Integer Index;
1943 TopTools_ListIteratorOfListOfShape it(SL);
1944 for (Index=1; it.More(); Index++)
1946 TopoDS_Shape S = it.Value();
1947 SL.Remove( it ); // == it.Next()
1949 OrderInd.SetValue (Index, Index);
1950 if (S.ShapeType() == TopAbs_VERTEX)
1952 GPoint = BRep_Tool::Pnt( TopoDS::Vertex( S ));
1953 Length.SetValue( Index, (Standard_Real) S.Orientation());
1957 BRepGProp::LinearProperties (S, GPr);
1958 GPoint = GPr.CentreOfMass();
1959 Length.SetValue( Index, GPr.Mass() );
1961 MidXYZ.SetValue(Index,
1962 GPoint.X()*999 + GPoint.Y()*99 + GPoint.Z()*0.9);
1965 Standard_Integer aTemp;
1966 Standard_Boolean exchange, Sort = Standard_True;
1969 Sort = Standard_False;
1970 for (Index=1; Index < MaxShapes; Index++)
1972 if (MidXYZ(OrderInd(Index)) > MidXYZ(OrderInd(Index+1)))
1973 exchange = Standard_True;
1974 else if (MidXYZ(OrderInd(Index)) == MidXYZ(OrderInd(Index+1)) &&
1975 Length(OrderInd(Index)) > Length(OrderInd(Index+1)) )
1976 exchange = Standard_True;
1978 exchange = Standard_False;
1981 aTemp = OrderInd(Index);
1982 OrderInd(Index) = OrderInd(Index+1);
1983 OrderInd(Index+1) = aTemp;
1984 Sort = Standard_True;
1988 for (Index=1; Index <= MaxShapes; Index++)
1989 SL.Append( aShapes( OrderInd(Index) ));
1992 //=======================================================================
1993 //function : CheckTriangulation
1995 //=======================================================================
1996 bool GEOMImpl_IShapesOperations::CheckTriangulation (const TopoDS_Shape& aShape)
1998 // MESSAGE("CheckTriangulation");
2000 // OSD_Timer timer1;
2003 TopExp_Explorer exp (aShape, TopAbs_FACE);
2005 SetErrorCode("Shape without faces given");
2009 TopLoc_Location aTopLoc;
2010 Handle(Poly_Triangulation) aTRF;
2011 aTRF = BRep_Tool::Triangulation(TopoDS::Face(exp.Current()), aTopLoc);
2012 if (aTRF.IsNull()) {
2013 // calculate deflection
2014 Standard_Real aDeviationCoefficient = 0.001;
2017 BRepBndLib::Add(aShape, B);
2018 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
2019 B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
2021 Standard_Real dx = aXmax - aXmin, dy = aYmax - aYmin, dz = aZmax - aZmin;
2022 Standard_Real aDeflection = Max(Max(dx, dy), dz) * aDeviationCoefficient * 4;
2024 // MESSAGE("Deflection = " << aDeflection);
2026 Standard_Real aHLRAngle = 0.349066;
2028 BRepMesh_IncrementalMesh Inc (aShape, aDeflection, Standard_False, aHLRAngle);