1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : GEOMImpl_IShapesOperations.cxx
24 // Author : modified by Lioka RAZAFINDRAZAKA (CEA) 22/06/2007
28 #include <Standard_Stream.hxx>
30 #include "GEOMImpl_IShapesOperations.hxx"
32 #include "GEOMImpl_Types.hxx"
34 #include "GEOMImpl_VectorDriver.hxx"
35 #include "GEOMImpl_ShapeDriver.hxx"
36 #include "GEOMImpl_CopyDriver.hxx"
37 #include "GEOMImpl_GlueDriver.hxx"
39 #include "GEOMImpl_IVector.hxx"
40 #include "GEOMImpl_IShapes.hxx"
41 #include "GEOMImpl_IGlue.hxx"
43 #include "GEOMImpl_Block6Explorer.hxx"
45 #include "GEOM_Function.hxx"
46 #include "GEOM_ISubShape.hxx"
47 #include "GEOM_PythonDump.hxx"
49 #include "GEOMAlgo_FinderShapeOn1.hxx"
50 #include "GEOMAlgo_FinderShapeOnQuad.hxx"
51 #include "GEOMAlgo_FinderShapeOn2.hxx"
52 #include "GEOMAlgo_ClsfBox.hxx"
53 #include "GEOMAlgo_ClsfSolid.hxx"
54 #include "GEOMAlgo_Gluer1.hxx"
55 #include "GEOMAlgo_ListIteratorOfListOfCoupleOfShapes.hxx"
56 #include "GEOMAlgo_CoupleOfShapes.hxx"
57 #include "GEOMAlgo_ListOfCoupleOfShapes.hxx"
59 #include "utilities.h"
61 #include "Utils_ExceptHandlers.hxx"
63 #include <TFunction_DriverTable.hxx>
64 #include <TFunction_Driver.hxx>
65 #include <TFunction_Logbook.hxx>
66 #include <TDataStd_Integer.hxx>
67 #include <TDataStd_IntegerArray.hxx>
68 #include <TDataStd_ListIteratorOfListOfExtendedString.hxx>
69 #include <TDF_Tool.hxx>
71 #include <BRepExtrema_ExtCF.hxx>
72 #include <BRepExtrema_DistShapeShape.hxx>
74 #include <BRep_Tool.hxx>
75 #include <BRep_Builder.hxx>
76 #include <BRepTools.hxx>
77 #include <BRepGProp.hxx>
78 #include <BRepAdaptor_Curve.hxx>
79 #include <BRepAdaptor_Surface.hxx>
80 #include <BRepBndLib.hxx>
81 #include <BRepBuilderAPI_MakeFace.hxx>
82 #include <BRepMesh_IncrementalMesh.hxx>
87 #include <TopoDS_Shape.hxx>
88 #include <TopoDS_Solid.hxx>
89 #include <TopoDS_Face.hxx>
90 #include <TopoDS_Edge.hxx>
91 #include <TopoDS_Vertex.hxx>
92 #include <TopoDS_Compound.hxx>
93 #include <TopoDS_Iterator.hxx>
94 #include <TopExp_Explorer.hxx>
95 #include <TopLoc_Location.hxx>
96 #include <TopTools_MapOfShape.hxx>
97 #include <TopTools_MapOfOrientedShape.hxx>
98 #include <TopTools_Array1OfShape.hxx>
99 #include <TopTools_ListIteratorOfListOfShape.hxx>
100 #include <TopTools_IndexedMapOfShape.hxx>
102 #include <Geom_Surface.hxx>
103 #include <Geom_Plane.hxx>
104 #include <Geom_SphericalSurface.hxx>
105 #include <Geom_CylindricalSurface.hxx>
106 #include <GeomAdaptor_Surface.hxx>
108 #include <GeomLib_Tool.hxx>
109 #include <Geom2d_Curve.hxx>
111 #include <Bnd_Box.hxx>
112 #include <GProp_GProps.hxx>
113 #include <TColStd_Array1OfReal.hxx>
114 #include <TColStd_HArray1OfInteger.hxx>
115 #include <TColStd_ListIteratorOfListOfInteger.hxx>
116 #include <TColStd_ListOfInteger.hxx>
117 #include <gp_Cylinder.hxx>
118 #include <gp_Lin.hxx>
119 #include <gp_Pnt.hxx>
123 #include <Standard_NullObject.hxx>
124 #include <Standard_Failure.hxx>
125 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
127 // Includes added for GetInPlace algorithm improvement
129 #include <GEOMImpl_MeasureDriver.hxx>
130 #include <GEOMImpl_IMeasure.hxx>
131 #include <BRepBuilderAPI_MakeVertex.hxx>
133 #include <BRepClass_FaceClassifier.hxx>
134 #include <BRepClass3d_SolidClassifier.hxx>
135 #include <Precision.hxx>
137 //=============================================================================
141 //=============================================================================
142 GEOMImpl_IShapesOperations::GEOMImpl_IShapesOperations (GEOM_Engine* theEngine, int theDocID)
143 : GEOM_IOperations(theEngine, theDocID)
145 MESSAGE("GEOMImpl_IShapesOperations::GEOMImpl_IShapesOperations");
148 //=============================================================================
152 //=============================================================================
153 GEOMImpl_IShapesOperations::~GEOMImpl_IShapesOperations()
155 MESSAGE("GEOMImpl_IShapesOperations::~GEOMImpl_IShapesOperations");
158 //=============================================================================
162 //=============================================================================
163 Handle(GEOM_Object) GEOMImpl_IShapesOperations::MakeEdge
164 (Handle(GEOM_Object) thePnt1, Handle(GEOM_Object) thePnt2)
168 if (thePnt1.IsNull() || thePnt2.IsNull()) return NULL;
170 //Add a new Edge object
171 Handle(GEOM_Object) anEdge = GetEngine()->AddObject(GetDocID(), GEOM_EDGE);
173 //Add a new Vector function
174 Handle(GEOM_Function) aFunction =
175 anEdge->AddFunction(GEOMImpl_VectorDriver::GetID(), VECTOR_TWO_PNT);
177 //Check if the function is set correctly
178 if (aFunction->GetDriverGUID() != GEOMImpl_VectorDriver::GetID()) return NULL;
180 GEOMImpl_IVector aPI (aFunction);
182 Handle(GEOM_Function) aRef1 = thePnt1->GetLastFunction();
183 Handle(GEOM_Function) aRef2 = thePnt2->GetLastFunction();
184 if (aRef1.IsNull() || aRef2.IsNull()) return NULL;
186 aPI.SetPoint1(aRef1);
187 aPI.SetPoint2(aRef2);
189 //Compute the Edge value
191 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
194 if (!GetSolver()->ComputeFunction(aFunction)) {
195 SetErrorCode("Vector driver failed");
199 catch (Standard_Failure) {
200 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
201 SetErrorCode(aFail->GetMessageString());
205 //Make a Python command
206 GEOM::TPythonDump(aFunction) << anEdge << " = geompy.MakeEdge("
207 << thePnt1 << ", " << thePnt2 << ")";
213 //=============================================================================
217 //=============================================================================
218 Handle(GEOM_Object) GEOMImpl_IShapesOperations::MakeWire
219 (std::list<Handle(GEOM_Object)> theShapes,
220 const Standard_Real theTolerance)
225 Handle(GEOM_Object) aWire = GetEngine()->AddObject(GetDocID(), GEOM_WIRE);
228 Handle(GEOM_Function) aFunction =
229 aWire->AddFunction(GEOMImpl_ShapeDriver::GetID(), WIRE_EDGES);
230 if (aFunction.IsNull()) return NULL;
232 //Check if the function is set correctly
233 if (aFunction->GetDriverGUID() != GEOMImpl_ShapeDriver::GetID()) return NULL;
235 GEOMImpl_IShapes aCI (aFunction);
236 aCI.SetTolerance(theTolerance);
238 Handle(TColStd_HSequenceOfTransient) aShapesSeq = new TColStd_HSequenceOfTransient;
241 std::list<Handle(GEOM_Object)>::iterator it = theShapes.begin();
242 for (; it != theShapes.end(); it++) {
243 Handle(GEOM_Function) aRefSh = (*it)->GetLastFunction();
244 if (aRefSh.IsNull()) {
245 SetErrorCode("NULL argument shape for the shape construction");
248 aShapesSeq->Append(aRefSh);
250 aCI.SetShapes(aShapesSeq);
254 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
257 if (!GetSolver()->ComputeFunction(aFunction)) {
258 SetErrorCode("Shape driver failed");
262 catch (Standard_Failure) {
263 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
264 SetErrorCode(aFail->GetMessageString());
268 //Make a Python command
269 GEOM::TPythonDump pd (aFunction);
270 pd << aWire << " = geompy.MakeWire([";
273 it = theShapes.begin();
274 if (it != theShapes.end()) {
276 while (it != theShapes.end()) {
277 pd << ", " << (*it++);
280 pd << "], " << theTolerance << ")";
286 //=============================================================================
290 //=============================================================================
291 Handle(GEOM_Object) GEOMImpl_IShapesOperations::MakeFace (Handle(GEOM_Object) theWire,
292 const bool isPlanarWanted)
296 if (theWire.IsNull()) return NULL;
298 //Add a new Face object
299 Handle(GEOM_Object) aFace = GetEngine()->AddObject(GetDocID(), GEOM_FACE);
301 //Add a new Shape function for creation of a face from a wire
302 Handle(GEOM_Function) aFunction =
303 aFace->AddFunction(GEOMImpl_ShapeDriver::GetID(), FACE_WIRE);
304 if (aFunction.IsNull()) return NULL;
306 //Check if the function is set correctly
307 if (aFunction->GetDriverGUID() != GEOMImpl_ShapeDriver::GetID()) return NULL;
309 GEOMImpl_IShapes aCI (aFunction);
311 Handle(GEOM_Function) aRefWire = theWire->GetLastFunction();
313 if (aRefWire.IsNull()) return NULL;
315 aCI.SetBase(aRefWire);
316 aCI.SetIsPlanar(isPlanarWanted);
318 //Compute the Face value
320 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
323 if (!GetSolver()->ComputeFunction(aFunction)) {
324 SetErrorCode("Shape driver failed to compute a face");
328 catch (Standard_Failure) {
329 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
330 SetErrorCode(aFail->GetMessageString());
334 //Make a Python command
335 GEOM::TPythonDump(aFunction) << aFace << " = geompy.MakeFace("
336 << theWire << ", " << (int)isPlanarWanted << ")";
342 //=============================================================================
346 //=============================================================================
347 Handle(GEOM_Object) GEOMImpl_IShapesOperations::MakeFaceWires
348 (std::list<Handle(GEOM_Object)> theShapes,
349 const bool isPlanarWanted)
354 Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_FACE);
357 Handle(GEOM_Function) aFunction =
358 aShape->AddFunction(GEOMImpl_ShapeDriver::GetID(), FACE_WIRES);
359 if (aFunction.IsNull()) return NULL;
361 //Check if the function is set correctly
362 if (aFunction->GetDriverGUID() != GEOMImpl_ShapeDriver::GetID()) return NULL;
364 GEOMImpl_IShapes aCI (aFunction);
366 Handle(TColStd_HSequenceOfTransient) aShapesSeq = new TColStd_HSequenceOfTransient;
369 std::list<Handle(GEOM_Object)>::iterator it = theShapes.begin();
370 for (; it != theShapes.end(); it++) {
371 Handle(GEOM_Function) aRefSh = (*it)->GetLastFunction();
372 if (aRefSh.IsNull()) {
373 SetErrorCode("NULL argument shape for the face construction");
376 aShapesSeq->Append(aRefSh);
378 aCI.SetShapes(aShapesSeq);
380 aCI.SetIsPlanar(isPlanarWanted);
384 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
387 if (!GetSolver()->ComputeFunction(aFunction)) {
388 SetErrorCode("Shape driver failed");
392 catch (Standard_Failure) {
393 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
394 SetErrorCode(aFail->GetMessageString());
398 //Make a Python command
399 GEOM::TPythonDump pd (aFunction);
400 pd << aShape << " = geompy.MakeFaceWires([";
403 it = theShapes.begin();
404 if (it != theShapes.end()) {
406 while (it != theShapes.end()) {
407 pd << ", " << (*it++);
410 pd << "], " << (int)isPlanarWanted << ")";
416 //=============================================================================
420 //=============================================================================
421 Handle(GEOM_Object) GEOMImpl_IShapesOperations::MakeShell
422 (std::list<Handle(GEOM_Object)> theShapes)
424 return MakeShape(theShapes, GEOM_SHELL, SHELL_FACES, "MakeShell");
427 //=============================================================================
431 //=============================================================================
432 Handle(GEOM_Object) GEOMImpl_IShapesOperations::MakeSolidShells
433 (std::list<Handle(GEOM_Object)> theShapes)
435 return MakeShape(theShapes, GEOM_SOLID, SOLID_SHELLS, "MakeSolid");
438 //=============================================================================
442 //=============================================================================
443 Handle(GEOM_Object) GEOMImpl_IShapesOperations::MakeSolidShell (Handle(GEOM_Object) theShell)
447 if (theShell.IsNull()) return NULL;
449 //Add a new Solid object
450 Handle(GEOM_Object) aSolid = GetEngine()->AddObject(GetDocID(), GEOM_SOLID);
452 //Add a new Solid function for creation of a solid from a shell
453 Handle(GEOM_Function) aFunction =
454 aSolid->AddFunction(GEOMImpl_ShapeDriver::GetID(), SOLID_SHELL);
455 if (aFunction.IsNull()) return NULL;
457 //Check if the function is set correctly
458 if (aFunction->GetDriverGUID() != GEOMImpl_ShapeDriver::GetID()) return NULL;
460 GEOMImpl_IShapes aCI (aFunction);
462 Handle(GEOM_Function) aRefShell = theShell->GetLastFunction();
464 if (aRefShell.IsNull()) return NULL;
466 aCI.SetBase(aRefShell);
468 //Compute the Solid value
470 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
473 if (!GetSolver()->ComputeFunction(aFunction)) {
474 SetErrorCode("Solid driver failed");
478 catch (Standard_Failure) {
479 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
480 SetErrorCode(aFail->GetMessageString());
484 //Make a Python command
485 GEOM::TPythonDump(aFunction) << aSolid
486 << " = geompy.MakeSolid(" << theShell << ")";
492 //=============================================================================
496 //=============================================================================
497 Handle(GEOM_Object) GEOMImpl_IShapesOperations::MakeCompound
498 (std::list<Handle(GEOM_Object)> theShapes)
500 return MakeShape(theShapes, GEOM_COMPOUND, COMPOUND_SHAPES, "MakeCompound");
503 //=============================================================================
507 //=============================================================================
508 Handle(GEOM_Object) GEOMImpl_IShapesOperations::MakeShape
509 (std::list<Handle(GEOM_Object)> theShapes,
510 const Standard_Integer theObjectType,
511 const Standard_Integer theFunctionType,
512 const TCollection_AsciiString& theMethodName)
517 Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), theObjectType);
520 Handle(GEOM_Function) aFunction =
521 aShape->AddFunction(GEOMImpl_ShapeDriver::GetID(), theFunctionType);
522 if (aFunction.IsNull()) return NULL;
524 //Check if the function is set correctly
525 if (aFunction->GetDriverGUID() != GEOMImpl_ShapeDriver::GetID()) return NULL;
527 GEOMImpl_IShapes aCI (aFunction);
529 Handle(TColStd_HSequenceOfTransient) aShapesSeq = new TColStd_HSequenceOfTransient;
532 std::list<Handle(GEOM_Object)>::iterator it = theShapes.begin();
533 for (; it != theShapes.end(); it++) {
534 Handle(GEOM_Function) aRefSh = (*it)->GetLastFunction();
535 if (aRefSh.IsNull()) {
536 SetErrorCode("NULL argument shape for the shape construction");
539 aShapesSeq->Append(aRefSh);
541 aCI.SetShapes(aShapesSeq);
545 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
548 if (!GetSolver()->ComputeFunction(aFunction)) {
549 SetErrorCode("Shape driver failed");
553 catch (Standard_Failure) {
554 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
555 SetErrorCode(aFail->GetMessageString());
559 //Make a Python command
560 GEOM::TPythonDump pd (aFunction);
561 pd << aShape << " = geompy." << theMethodName.ToCString() << "([";
564 it = theShapes.begin();
565 if (it != theShapes.end()) {
567 while (it != theShapes.end()) {
568 pd << ", " << (*it++);
577 //=============================================================================
581 //=============================================================================
582 Handle(GEOM_Object) GEOMImpl_IShapesOperations::MakeGlueFaces
583 (Handle(GEOM_Object) theShape,
584 const Standard_Real theTolerance,
585 const Standard_Boolean doKeepNonSolids)
589 if (theShape.IsNull()) return NULL;
591 //Add a new Glued object
592 Handle(GEOM_Object) aGlued = GetEngine()->AddObject(GetDocID(), GEOM_GLUED);
594 //Add a new Glue function
595 Handle(GEOM_Function) aFunction;
596 aFunction = aGlued->AddFunction(GEOMImpl_GlueDriver::GetID(), GLUE_FACES);
597 if (aFunction.IsNull()) return NULL;
599 //Check if the function is set correctly
600 if (aFunction->GetDriverGUID() != GEOMImpl_GlueDriver::GetID()) return NULL;
602 GEOMImpl_IGlue aCI (aFunction);
604 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
605 if (aRefShape.IsNull()) return NULL;
607 aCI.SetBase(aRefShape);
608 aCI.SetTolerance(theTolerance);
609 aCI.SetKeepNonSolids(doKeepNonSolids);
611 //Compute the sub-shape value
612 Standard_Boolean isWarning = Standard_False;
614 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
617 if (!GetSolver()->ComputeFunction(aFunction)) {
618 SetErrorCode("Shape driver failed to glue faces");
622 catch (Standard_Failure) {
623 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
624 SetErrorCode(aFail->GetMessageString());
625 // to provide warning
626 if (!aFunction->GetValue().IsNull()) {
627 isWarning = Standard_True;
633 //Make a Python command
634 GEOM::TPythonDump(aFunction) << aGlued << " = geompy.MakeGlueFaces("
635 << theShape << ", " << theTolerance << ")";
637 // to provide warning
638 if (!isWarning) SetErrorCode(OK);
642 //=============================================================================
646 //=============================================================================
647 Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::GetGlueFaces
648 (Handle(GEOM_Object) theShape,
649 const Standard_Real theTolerance)
653 if (theShape.IsNull()) return NULL;
654 TopoDS_Shape aShape = theShape->GetValue();
655 if (aShape.IsNull()) return NULL;
657 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
659 Standard_Integer iErr;
661 GEOMAlgo_Gluer1 aGluer;
662 GEOMAlgo_ListIteratorOfListOfCoupleOfShapes aItCS;
663 GEOMAlgo_CoupleOfShapes aCS;
664 GEOMAlgo_ListOfCoupleOfShapes aLCS;
666 //aGluer = new GEOMAlgo_Gluer1;
667 aGluer.SetShape(aShape);
668 aGluer.SetTolerance(theTolerance);
670 iErr = aGluer.ErrorStatus();
671 if (iErr) return NULL;
673 TopTools_ListOfShape listShape;
674 const GEOMAlgo_ListOfCoupleOfShapes& aLCSG = aGluer.GluedFaces();
676 aItCS.Initialize(aLCSG);
677 for (; aItCS.More(); aItCS.Next()) {
678 const GEOMAlgo_CoupleOfShapes& aCSG = aItCS.Value();
679 listShape.Append(aCSG.Shape1());
682 TopTools_ListIteratorOfListOfShape itSub (listShape);
683 TCollection_AsciiString anAsciiList, anEntry;
684 TopTools_IndexedMapOfShape anIndices;
685 TopExp::MapShapes(aShape, anIndices);
686 Handle(TColStd_HArray1OfInteger) anArray;
687 Handle(GEOM_Object) anObj;
688 for (int index = 1; itSub.More(); itSub.Next(), ++index) {
689 TopoDS_Shape aValue = itSub.Value();
690 anArray = new TColStd_HArray1OfInteger(1,1);
691 anArray->SetValue(1, anIndices.FindIndex(aValue));
692 anObj = GetEngine()->AddSubShape(theShape, anArray);
693 if (!anObj.IsNull()) {
696 // for python command
697 TDF_Tool::Entry(anObj->GetEntry(), anEntry);
698 anAsciiList += anEntry;
703 //Make a Python command
704 if( anAsciiList.Length() > 0 ) {
705 anAsciiList.Trunc(anAsciiList.Length() - 1);
706 Handle(GEOM_Function) aFunction = theShape->GetLastFunction();
707 GEOM::TPythonDump pd (aFunction, /*append=*/true);
708 pd << "[" << anAsciiList.ToCString();
709 pd << "] = geompy.GetGlueFaces(" << theShape << ", " << theTolerance << ")";
717 //=============================================================================
719 * MakeGlueFacesByList
721 //=============================================================================
722 Handle(GEOM_Object) GEOMImpl_IShapesOperations::MakeGlueFacesByList
723 (Handle(GEOM_Object) theShape,
724 const Standard_Real theTolerance,
725 std::list<Handle(GEOM_Object)> theFaces,
726 const Standard_Boolean doKeepNonSolids)
730 if (theShape.IsNull()) return NULL;
732 //Add a new Glued object
733 Handle(GEOM_Object) aGlued = GetEngine()->AddObject(GetDocID(), GEOM_GLUED);
735 //Add a new Glue function
736 Handle(GEOM_Function) aFunction;
737 aFunction = aGlued->AddFunction(GEOMImpl_GlueDriver::GetID(), GLUE_FACES_BY_LIST);
738 if (aFunction.IsNull()) return NULL;
740 //Check if the function is set correctly
741 if (aFunction->GetDriverGUID() != GEOMImpl_GlueDriver::GetID()) return NULL;
743 GEOMImpl_IGlue aCI (aFunction);
745 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
746 if (aRefShape.IsNull()) return NULL;
748 aCI.SetBase(aRefShape);
749 aCI.SetTolerance(theTolerance);
750 aCI.SetKeepNonSolids(doKeepNonSolids);
752 Handle(TColStd_HSequenceOfTransient) aFaces = new TColStd_HSequenceOfTransient;
753 std::list<Handle(GEOM_Object)>::iterator it = theFaces.begin();
754 for (; it != theFaces.end(); it++) {
755 Handle(GEOM_Function) aRefSh = (*it)->GetLastFunction();
756 if (aRefSh.IsNull()) {
757 SetErrorCode("NULL argument shape for the shape construction");
760 aFaces->Append(aRefSh);
762 aCI.SetFaces(aFaces);
764 //Compute the sub-shape value
765 Standard_Boolean isWarning = Standard_False;
767 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
770 if (!GetSolver()->ComputeFunction(aFunction)) {
771 SetErrorCode("Shape driver failed to glue faces");
775 catch (Standard_Failure) {
776 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
777 SetErrorCode(aFail->GetMessageString());
778 // to provide warning
779 if (!aFunction->GetValue().IsNull()) {
780 isWarning = Standard_True;
786 //Make a Python command
788 GEOM::TPythonDump pd(aFunction);
789 pd << aGlued << " = geompy.MakeGlueFacesByList("
790 << theShape << ", " << theTolerance << ", [";
792 it = theFaces.begin();
793 if (it != theFaces.end()) {
795 while (it != theFaces.end()) {
796 pd << ", " << (*it++);
801 // to provide warning
802 if (!isWarning) SetErrorCode(OK);
806 //=============================================================================
808 * GetExistingSubObjects
810 //=============================================================================
811 Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::GetExistingSubObjects
812 (Handle(GEOM_Object) theShape,
813 const Standard_Boolean theGroupsOnly)
817 if (theShape.IsNull()) return NULL;
819 Handle(GEOM_Function) aMainShape = theShape->GetLastFunction();
820 if (aMainShape.IsNull()) return NULL;
822 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
823 SetErrorCode(NOT_FOUND_ANY);
825 if (!aMainShape->HasSubShapeReferences()) return aSeq;
826 const TDataStd_ListOfExtendedString& aListEntries = aMainShape->GetSubShapeReferences();
827 if (aListEntries.IsEmpty()) return aSeq;
831 TCollection_AsciiString anAsciiList;
833 TDataStd_ListIteratorOfListOfExtendedString anIt (aListEntries);
834 for (; anIt.More(); anIt.Next()) {
835 TCollection_ExtendedString anEntry = anIt.Value();
836 Standard_Integer aStrLen = anEntry.LengthOfCString();
837 char* anEntryStr = new char[aStrLen];
838 anEntry.ToUTF8CString(anEntryStr);
839 Handle(GEOM_Object) anObj = GetEngine()->GetObject(GetDocID(), anEntryStr, false);
840 if (!anObj.IsNull()) {
841 if (!theGroupsOnly || anObj->GetType() == GEOM_GROUP) {
844 // for python command
845 anAsciiList += anEntryStr;
849 delete [] anEntryStr;
852 if (aSeq->Length() == 0) {
853 SetErrorCode(NOT_FOUND_ANY);
857 //Make a Python command
858 anAsciiList.Trunc(anAsciiList.Length() - 1);
860 GEOM::TPythonDump pd (aMainShape, /*append=*/true);
861 pd << "[" << anAsciiList.ToCString();
862 pd << "] = geompy.GetExistingSubObjects(";
863 pd << theShape << ", " << (int)theGroupsOnly << ")";
870 //=============================================================================
874 //=============================================================================
875 Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::MakeExplode
876 (Handle(GEOM_Object) theShape,
877 const Standard_Integer theShapeType,
878 const Standard_Boolean isSorted)
882 if (theShape.IsNull()) return NULL;
883 TopoDS_Shape aShape = theShape->GetValue();
884 if (aShape.IsNull()) return NULL;
886 Handle(GEOM_Function) aMainShape = theShape->GetLastFunction();
888 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
889 Handle(GEOM_Object) anObj;
890 TopTools_MapOfShape mapShape;
891 TopTools_ListOfShape listShape;
893 if (aShape.ShapeType() == TopAbs_COMPOUND &&
894 (TopAbs_ShapeEnum(theShapeType) == TopAbs_SHAPE ||
895 TopAbs_ShapeEnum(theShapeType) == TopAbs_COMPSOLID ||
896 TopAbs_ShapeEnum(theShapeType) == TopAbs_COMPOUND)) {
897 TopoDS_Iterator It (aShape, Standard_True, Standard_True);
898 for (; It.More(); It.Next()) {
899 if (mapShape.Add(It.Value())) {
900 if (TopAbs_ShapeEnum(theShapeType) == TopAbs_SHAPE ||
901 TopAbs_ShapeEnum(theShapeType) == It.Value().ShapeType()) {
902 listShape.Append(It.Value());
907 TopExp_Explorer exp (aShape, TopAbs_ShapeEnum(theShapeType));
908 for (; exp.More(); exp.Next())
909 if (mapShape.Add(exp.Current()))
910 listShape.Append(exp.Current());
913 if (listShape.IsEmpty()) {
914 //SetErrorCode("The given shape has no sub-shapes of the requested type");
915 SetErrorCode(NOT_FOUND_ANY); // NPAL18017
920 SortShapes(listShape);
922 TopTools_IndexedMapOfShape anIndices;
923 TopExp::MapShapes(aShape, anIndices);
924 Handle(TColStd_HArray1OfInteger) anArray;
926 TopTools_ListIteratorOfListOfShape itSub (listShape);
927 TCollection_AsciiString anAsciiList, anEntry;
928 for (int index = 1; itSub.More(); itSub.Next(), ++index)
930 TopoDS_Shape aValue = itSub.Value();
931 anArray = new TColStd_HArray1OfInteger(1,1);
932 anArray->SetValue(1, anIndices.FindIndex(aValue));
934 //anObj = GetEngine()->AddSubShape(theShape, anArray);
936 anObj = GetEngine()->AddObject(GetDocID(), GEOM_SUBSHAPE);
937 Handle(GEOM_Function) aFunction = anObj->AddFunction(GEOM_Object::GetSubShapeID(), 1);
938 if (aFunction.IsNull()) return aSeq;
940 GEOM_ISubShape aSSI (aFunction);
941 aSSI.SetMainShape(aMainShape);
942 aSSI.SetIndices(anArray);
944 // Set function value directly, as we know it.
945 // Usage of Solver here would lead to significant loss of time,
946 // because GEOM_SubShapeDriver will build TopTools_IndexedMapOfShape
947 // on the main shape for each being calculated sub-shape separately.
948 aFunction->SetValue(aValue);
951 if (!anObj.IsNull()) {
954 // for python command
955 TDF_Tool::Entry(anObj->GetEntry(), anEntry);
956 anAsciiList += anEntry;
961 //Make a Python command
962 anAsciiList.Trunc(anAsciiList.Length() - 1);
964 GEOM::TPythonDump pd (aMainShape, /*append=*/true);
965 pd << "[" << anAsciiList.ToCString();
966 pd << "] = geompy.SubShapeAll" << (isSorted ? "Sorted(" : "(");
967 pd << theShape << ", " << TopAbs_ShapeEnum(theShapeType) << ")";
974 //=============================================================================
978 //=============================================================================
979 Handle(TColStd_HSequenceOfInteger) GEOMImpl_IShapesOperations::SubShapeAllIDs
980 (Handle(GEOM_Object) theShape,
981 const Standard_Integer theShapeType,
982 const Standard_Boolean isSorted)
986 if (theShape.IsNull()) return NULL;
987 TopoDS_Shape aShape = theShape->GetValue();
988 if (aShape.IsNull()) return NULL;
990 Handle(TColStd_HSequenceOfInteger) aSeq = new TColStd_HSequenceOfInteger;
991 TopTools_MapOfShape mapShape;
992 TopTools_ListOfShape listShape;
994 if (aShape.ShapeType() == TopAbs_COMPOUND &&
995 (TopAbs_ShapeEnum(theShapeType) == TopAbs_SHAPE ||
996 TopAbs_ShapeEnum(theShapeType) == TopAbs_COMPSOLID ||
997 TopAbs_ShapeEnum(theShapeType) == TopAbs_COMPOUND)) {
998 TopoDS_Iterator It (aShape, Standard_True, Standard_True);
999 for (; It.More(); It.Next()) {
1000 if (mapShape.Add(It.Value())) {
1001 if (TopAbs_ShapeEnum(theShapeType) == TopAbs_SHAPE ||
1002 TopAbs_ShapeEnum(theShapeType) == It.Value().ShapeType()) {
1003 listShape.Append(It.Value());
1008 TopExp_Explorer exp (aShape, TopAbs_ShapeEnum(theShapeType));
1009 for (; exp.More(); exp.Next())
1010 if (mapShape.Add(exp.Current()))
1011 listShape.Append(exp.Current());
1014 if (listShape.IsEmpty()) {
1015 //SetErrorCode("The given shape has no sub-shapes of the requested type");
1016 SetErrorCode(NOT_FOUND_ANY); // NPAL18017
1021 SortShapes(listShape);
1023 TopTools_IndexedMapOfShape anIndices;
1024 TopExp::MapShapes(aShape, anIndices);
1025 Handle(TColStd_HArray1OfInteger) anArray;
1027 TopTools_ListIteratorOfListOfShape itSub (listShape);
1028 for (int index = 1; itSub.More(); itSub.Next(), ++index) {
1029 TopoDS_Shape aValue = itSub.Value();
1030 aSeq->Append(anIndices.FindIndex(aValue));
1033 Handle(GEOM_Function) aFunction = theShape->GetLastFunction();
1035 //Make a Python command
1036 GEOM::TPythonDump pd (aFunction, /*append=*/true);
1037 pd << "listSubShapeIDs = geompy.SubShapeAll";
1038 pd << (isSorted ? "SortedIDs(" : "IDs(");
1039 pd << theShape << ", " << TopAbs_ShapeEnum(theShapeType) << ")";
1045 //=============================================================================
1049 //=============================================================================
1050 Handle(GEOM_Object) GEOMImpl_IShapesOperations::GetSubShape
1051 (Handle(GEOM_Object) theMainShape,
1052 const Standard_Integer theID)
1056 if (theMainShape.IsNull()) return NULL;
1058 Handle(TColStd_HArray1OfInteger) anArray = new TColStd_HArray1OfInteger(1,1);
1059 anArray->SetValue(1, theID);
1060 Handle(GEOM_Object) anObj = GetEngine()->AddSubShape(theMainShape, anArray,true);
1061 if (anObj.IsNull()) {
1062 SetErrorCode("Can not get a sub-shape with the given ID");
1066 Handle(GEOM_Function) aFunction = anObj->GetLastFunction();
1068 //Make a Python command
1069 GEOM::TPythonDump(aFunction) << anObj << " = geompy.GetSubShape("
1070 << theMainShape << ", [" << theID << "])";
1076 //=============================================================================
1080 //=============================================================================
1081 Standard_Integer GEOMImpl_IShapesOperations::GetSubShapeIndex (Handle(GEOM_Object) theMainShape,
1082 Handle(GEOM_Object) theSubShape)
1086 TopoDS_Shape aMainShape = theMainShape->GetValue();
1087 TopoDS_Shape aSubShape = theSubShape->GetValue();
1089 if (aMainShape.IsNull() || aSubShape.IsNull()) return -1;
1091 TopTools_IndexedMapOfShape anIndices;
1092 TopExp::MapShapes(aMainShape, anIndices);
1093 if (anIndices.Contains(aSubShape)) {
1095 return anIndices.FindIndex(aSubShape);
1101 //=============================================================================
1105 //=============================================================================
1106 Standard_Integer GEOMImpl_IShapesOperations::GetTopologyIndex (Handle(GEOM_Object) theMainShape,
1107 Handle(GEOM_Object) theSubShape)
1111 TopoDS_Shape aMainShape = theMainShape->GetValue();
1112 TopoDS_Shape aSubShape = theSubShape->GetValue();
1114 if (aMainShape.IsNull() || aSubShape.IsNull()) {
1115 SetErrorCode("Null argument shape given");
1120 if (aSubShape.ShapeType() == TopAbs_COMPOUND) {
1122 TopTools_ListOfShape CL;
1123 CL.Append(aMainShape);
1124 TopTools_ListIteratorOfListOfShape itC;
1125 for (itC.Initialize(CL); itC.More(); itC.Next()) {
1126 for (it.Initialize(itC.Value()); it.More(); it.Next()) {
1127 if (it.Value().ShapeType() == TopAbs_COMPOUND) {
1128 if (it.Value().IsSame(aSubShape))
1132 CL.Append(it.Value());
1137 TopExp_Explorer anExp (aMainShape, aSubShape.ShapeType());
1138 TopTools_MapOfShape M;
1139 for (; anExp.More(); anExp.Next()) {
1140 if (M.Add(anExp.Current())) {
1141 if (anExp.Current().IsSame(aSubShape))
1148 SetErrorCode("The sub-shape does not belong to the main shape");
1152 //=============================================================================
1154 * GetShapeTypeString
1156 //=============================================================================
1157 TCollection_AsciiString GEOMImpl_IShapesOperations::GetShapeTypeString (Handle(GEOM_Object) theShape)
1161 TCollection_AsciiString aTypeName ("Null Shape");
1163 TopoDS_Shape aShape = theShape->GetValue();
1164 if (aShape.IsNull())
1167 switch (aShape.ShapeType() )
1169 case TopAbs_COMPOUND:
1170 aTypeName = "Compound";
1172 case TopAbs_COMPSOLID:
1173 aTypeName = "Compound Solid";
1176 aTypeName = "Solid";
1179 aTypeName = "Shell";
1183 BRepAdaptor_Surface surf (TopoDS::Face(aShape));
1184 if (surf.GetType() == GeomAbs_Plane)
1185 aTypeName = "Plane";
1186 else if (surf.GetType() == GeomAbs_Cylinder)
1187 aTypeName = "Cylindrical Face";
1188 else if (surf.GetType() == GeomAbs_Sphere)
1189 aTypeName = "Spherical Face";
1190 else if (surf.GetType() == GeomAbs_Torus)
1191 aTypeName = "Toroidal Face";
1192 else if (surf.GetType() == GeomAbs_Cone)
1193 aTypeName = "Conical Face";
1195 aTypeName = "GEOM::FACE";
1203 BRepAdaptor_Curve curv (TopoDS::Edge(aShape));
1204 if (curv.GetType() == GeomAbs_Line) {
1205 if ((Abs(curv.FirstParameter()) >= 1E6) ||
1206 (Abs(curv.LastParameter()) >= 1E6))
1210 } else if (curv.GetType() == GeomAbs_Circle) {
1211 if (curv.IsClosed())
1212 aTypeName = "Circle";
1221 aTypeName = "Vertex";
1224 aTypeName = "Shape";
1227 aTypeName = "Shape of unknown type";
1233 //=============================================================================
1237 //=============================================================================
1238 Standard_Integer GEOMImpl_IShapesOperations::NumberOfSubShapes
1239 (Handle(GEOM_Object) theShape,
1240 const Standard_Integer theShapeType)
1243 Standard_Integer nbShapes = 0;
1245 if (theShape.IsNull()) return -1;
1246 TopoDS_Shape aShape = theShape->GetValue();
1247 if (aShape.IsNull()) return -1;
1250 TopTools_MapOfShape mapShape;
1252 if (aShape.ShapeType() == TopAbs_COMPOUND &&
1253 (TopAbs_ShapeEnum(theShapeType) == TopAbs_SHAPE ||
1254 TopAbs_ShapeEnum(theShapeType) == TopAbs_COMPSOLID ||
1255 TopAbs_ShapeEnum(theShapeType) == TopAbs_COMPOUND)) {
1256 TopoDS_Iterator It (aShape, Standard_True, Standard_True);
1257 for (; It.More(); It.Next()) {
1258 if (mapShape.Add(It.Value())) {
1259 if (TopAbs_ShapeEnum(theShapeType) == TopAbs_SHAPE ||
1260 TopAbs_ShapeEnum(theShapeType) == It.Value().ShapeType()) {
1266 TopExp_Explorer exp (aShape, TopAbs_ShapeEnum(theShapeType));
1267 for (; exp.More(); exp.Next())
1268 if (mapShape.Add(exp.Current()))
1274 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1277 int iType, nbTypes [TopAbs_SHAPE];
1278 for (iType = 0; iType < TopAbs_SHAPE; ++iType)
1280 nbTypes[aShape.ShapeType()]++;
1282 TopTools_MapOfShape aMapOfShape;
1283 aMapOfShape.Add(aShape);
1284 TopTools_ListOfShape aListOfShape;
1285 aListOfShape.Append(aShape);
1287 TopTools_ListIteratorOfListOfShape itL (aListOfShape);
1288 for (; itL.More(); itL.Next()) {
1289 TopoDS_Iterator it (itL.Value());
1290 for (; it.More(); it.Next()) {
1291 TopoDS_Shape s = it.Value();
1292 if (aMapOfShape.Add(s)) {
1293 aListOfShape.Append(s);
1294 nbTypes[s.ShapeType()]++;
1299 if (TopAbs_ShapeEnum(theShapeType) == TopAbs_SHAPE)
1300 nbShapes = aMapOfShape.Extent();
1302 nbShapes = nbTypes[theShapeType];
1304 catch (Standard_Failure) {
1305 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1306 SetErrorCode(aFail->GetMessageString());
1314 //=============================================================================
1318 //=============================================================================
1319 Handle(GEOM_Object) GEOMImpl_IShapesOperations::ReverseShape(Handle(GEOM_Object) theShape)
1323 if (theShape.IsNull()) return NULL;
1325 //Add a new reversed object
1326 Handle(GEOM_Object) aReversed = GetEngine()->AddObject(GetDocID(), theShape->GetType());
1328 //Add a new Revese function
1329 Handle(GEOM_Function) aFunction;
1330 aFunction = aReversed->AddFunction(GEOMImpl_ShapeDriver::GetID(), REVERSE_ORIENTATION);
1331 if (aFunction.IsNull()) return NULL;
1333 //Check if the function is set correctly
1334 if (aFunction->GetDriverGUID() != GEOMImpl_ShapeDriver::GetID()) return NULL;
1336 GEOMImpl_IShapes aSI (aFunction);
1338 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1339 if (aRefShape.IsNull()) return NULL;
1341 aSI.SetBase(aRefShape);
1343 //Compute the sub-shape value
1345 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1348 if (!GetSolver()->ComputeFunction(aFunction)) {
1349 SetErrorCode("Shape driver failed to reverse shape");
1353 catch (Standard_Failure) {
1354 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1355 SetErrorCode(aFail->GetMessageString());
1359 //Make a Python command
1360 GEOM::TPythonDump(aFunction) << aReversed
1361 << " = geompy.ChangeOrientation(" << theShape << ")";
1367 //=============================================================================
1371 //=============================================================================
1372 Handle(TColStd_HSequenceOfInteger) GEOMImpl_IShapesOperations::GetFreeFacesIDs
1373 (Handle(GEOM_Object) theShape)
1377 if (theShape.IsNull()) return NULL;
1378 TopoDS_Shape aShape = theShape->GetValue();
1379 if (aShape.IsNull()) return NULL;
1381 Handle(TColStd_HSequenceOfInteger) aSeq = new TColStd_HSequenceOfInteger;
1383 TopTools_IndexedDataMapOfShapeListOfShape mapFaceBlocks;
1384 GEOMImpl_Block6Explorer::MapShapesAndAncestors
1385 (aShape, TopAbs_FACE, TopAbs_SOLID, mapFaceBlocks);
1387 Standard_Integer ind = 1, nbFaces = mapFaceBlocks.Extent();
1390 SetErrorCode("The given shape has no faces");
1394 TopTools_IndexedMapOfShape anIndices;
1395 TopExp::MapShapes(aShape, anIndices);
1397 Standard_Integer id;
1398 for (; ind <= nbFaces; ind++) {
1399 if (mapFaceBlocks.FindFromIndex(ind).Extent() != 2) {
1400 id = anIndices.FindIndex(mapFaceBlocks.FindKey(ind));
1405 //The explode doesn't change object so no new function is required.
1406 Handle(GEOM_Function) aFunction = theShape->GetLastFunction();
1408 //Make a Python command
1409 GEOM::TPythonDump(aFunction, /*append=*/true)
1410 << "listFreeFacesIDs = geompy.GetFreeFacesIDs(" << theShape << ")";
1416 //=======================================================================
1417 //function : GetSharedShapes
1419 //=======================================================================
1420 Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::GetSharedShapes
1421 (Handle(GEOM_Object) theShape1,
1422 Handle(GEOM_Object) theShape2,
1423 const Standard_Integer theShapeType)
1427 if (theShape1.IsNull() || theShape2.IsNull()) return NULL;
1429 TopoDS_Shape aShape1 = theShape1->GetValue();
1430 TopoDS_Shape aShape2 = theShape2->GetValue();
1432 if (aShape1.IsNull() || aShape2.IsNull()) return NULL;
1434 TopTools_IndexedMapOfShape anIndices;
1435 TopExp::MapShapes(aShape1, anIndices);
1436 Handle(TColStd_HArray1OfInteger) anArray;
1438 TopTools_IndexedMapOfShape mapShape1;
1439 TopExp::MapShapes(aShape1, TopAbs_ShapeEnum(theShapeType), mapShape1);
1441 Handle(GEOM_Object) anObj;
1442 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
1443 TCollection_AsciiString anAsciiList, anEntry;
1445 TopTools_MapOfShape mapShape2;
1446 TopExp_Explorer exp (aShape2, TopAbs_ShapeEnum(theShapeType));
1447 for (; exp.More(); exp.Next()) {
1448 TopoDS_Shape aSS = exp.Current();
1449 if (mapShape2.Add(aSS) && mapShape1.Contains(aSS)) {
1450 anArray = new TColStd_HArray1OfInteger(1,1);
1451 anArray->SetValue(1, anIndices.FindIndex(aSS));
1452 anObj = GetEngine()->AddSubShape(theShape1, anArray);
1453 aSeq->Append(anObj);
1455 // for python command
1456 TDF_Tool::Entry(anObj->GetEntry(), anEntry);
1457 anAsciiList += anEntry;
1462 if (aSeq->IsEmpty()) {
1463 SetErrorCode("The given shapes have no shared sub-shapes of the requested type");
1467 //Make a Python command
1468 anAsciiList.Trunc(anAsciiList.Length() - 1);
1470 Handle(GEOM_Function) aFunction = anObj->GetLastFunction();
1472 GEOM::TPythonDump(aFunction) << "[" << anAsciiList.ToCString()
1473 << "] = geompy.GetSharedShapes(" << theShape1 << ", "
1474 << theShape2 << ", " << TopAbs_ShapeEnum(theShapeType) << ")";
1480 //=============================================================================
1484 //=============================================================================
1485 static GEOM::TPythonDump& operator<< (GEOM::TPythonDump& theDump,
1486 const GEOMAlgo_State theState)
1489 case GEOMAlgo_ST_IN:
1490 theDump << "geompy.GEOM.ST_IN";
1492 case GEOMAlgo_ST_OUT:
1493 theDump << "geompy.GEOM.ST_OUT";
1495 case GEOMAlgo_ST_ON:
1496 theDump << "geompy.GEOM.ST_ON";
1498 case GEOMAlgo_ST_ONIN:
1499 theDump << "geompy.GEOM.ST_ONIN";
1501 case GEOMAlgo_ST_ONOUT:
1502 theDump << "geompy.GEOM.ST_ONOUT";
1505 theDump << "geompy.GEOM.ST_UNKNOWN";
1511 //=======================================================================
1512 //function : checkTypeShapesOn
1514 * \brief Checks if theShapeType parameter of GetShapesOnXXX() is OK
1515 * \param theShapeType - the shape type to check
1516 * \retval bool - result of the check
1518 //=======================================================================
1519 bool GEOMImpl_IShapesOperations::checkTypeShapesOn(const Standard_Integer theShapeType)
1521 if (theShapeType != TopAbs_VERTEX &&
1522 theShapeType != TopAbs_EDGE &&
1523 theShapeType != TopAbs_FACE &&
1524 theShapeType != TopAbs_SOLID) {
1525 SetErrorCode("Only solids, vertices, edges or faces can be found by this method");
1531 //=======================================================================
1532 //function : makePlane
1534 * \brief Creates Geom_Plane
1535 * \param theAx1 - shape object defining plane parameters
1536 * \retval Handle(Geom_Surface) - resulting surface
1538 //=======================================================================
1539 Handle(Geom_Surface) GEOMImpl_IShapesOperations::makePlane(const TopoDS_Shape& anAx1)
1541 if (anAx1.ShapeType() != TopAbs_EDGE) return NULL;
1542 TopoDS_Edge anEdge = TopoDS::Edge(anAx1);
1543 TopoDS_Vertex V1, V2;
1544 TopExp::Vertices(anEdge, V1, V2, Standard_True);
1545 if (V1.IsNull() || V2.IsNull()) {
1546 SetErrorCode("Bad edge given for the plane normal vector");
1549 gp_Pnt aLoc = BRep_Tool::Pnt(V1);
1550 gp_Vec aVec (aLoc, BRep_Tool::Pnt(V2));
1551 if (aVec.Magnitude() < Precision::Confusion()) {
1552 SetErrorCode("Vector with null magnitude given");
1555 return new Geom_Plane(aLoc, aVec);
1558 //=======================================================================
1559 //function : makeCylinder
1561 * \brief Creates Geom_CylindricalSurface
1562 * \param theAx1 - edge defining cylinder axis
1563 * \param theRadius - cylinder radius
1564 * \retval Handle(Geom_Surface) - resulting surface
1566 //=======================================================================
1567 Handle(Geom_Surface) GEOMImpl_IShapesOperations::makeCylinder(const TopoDS_Shape& anAxis,
1568 const Standard_Real theRadius)
1570 //Axis of the cylinder
1571 if (anAxis.ShapeType() != TopAbs_EDGE) {
1572 SetErrorCode("Not an edge given for the axis");
1575 TopoDS_Edge anEdge = TopoDS::Edge(anAxis);
1576 TopoDS_Vertex V1, V2;
1577 TopExp::Vertices(anEdge, V1, V2, Standard_True);
1578 if (V1.IsNull() || V2.IsNull()) {
1579 SetErrorCode("Bad edge given for the axis");
1582 gp_Pnt aLoc = BRep_Tool::Pnt(V1);
1583 gp_Vec aVec (aLoc, BRep_Tool::Pnt(V2));
1584 if (aVec.Magnitude() < Precision::Confusion()) {
1585 SetErrorCode("Vector with null magnitude given");
1589 gp_Ax3 anAx3 (aLoc, aVec);
1590 return new Geom_CylindricalSurface(anAx3, theRadius);
1593 //=======================================================================
1594 //function : getShapesOnBoxIDs
1596 * \brief Find IDs of subshapes complying with given status about surface
1597 * \param theBox - the box to check state of subshapes against
1598 * \param theShape - the shape to explore
1599 * \param theShapeType - type of subshape of theShape
1600 * \param theState - required state
1601 * \retval Handle(TColStd_HSequenceOfInteger) - IDs of found subshapes
1603 //=======================================================================
1604 Handle(TColStd_HSequenceOfInteger)
1605 GEOMImpl_IShapesOperations::getShapesOnBoxIDs(const Handle(GEOM_Object)& theBox,
1606 const Handle(GEOM_Object)& theShape,
1607 const Standard_Integer theShapeType,
1608 GEOMAlgo_State theState)
1610 Handle(TColStd_HSequenceOfInteger) aSeqOfIDs;
1612 TopoDS_Shape aBox = theBox->GetValue();
1613 TopoDS_Shape aShape = theShape->GetValue();
1615 // Check presence of triangulation, build if need
1616 if (!CheckTriangulation(aShape)) {
1617 SetErrorCode("Cannot build triangulation on the shape");
1622 GEOMAlgo_FinderShapeOn2 aFinder;
1623 Standard_Real aTol = 0.0001; // default value
1625 Handle(GEOMAlgo_ClsfBox) aClsfBox = new GEOMAlgo_ClsfBox;
1626 aClsfBox->SetBox(aBox);
1628 aFinder.SetShape(aShape);
1629 aFinder.SetTolerance(aTol);
1630 aFinder.SetClsf(aClsfBox);
1631 aFinder.SetShapeType( (TopAbs_ShapeEnum)theShapeType );
1632 aFinder.SetState(theState);
1635 // Interprete results
1636 Standard_Integer iErr = aFinder.ErrorStatus();
1637 // the detailed description of error codes is in GEOMAlgo_FinderShapeOn1.cxx
1639 MESSAGE(" iErr : " << iErr);
1640 TCollection_AsciiString aMsg (" iErr : ");
1641 aMsg += TCollection_AsciiString(iErr);
1645 Standard_Integer iWrn = aFinder.WarningStatus();
1646 // the detailed description of warning codes is in GEOMAlgo_FinderShapeOn1.cxx
1648 MESSAGE(" *** iWrn : " << iWrn);
1651 const TopTools_ListOfShape& listSS = aFinder.Shapes(); // the result
1653 if (listSS.Extent() < 1) {
1654 //SetErrorCode("Not a single sub-shape of the requested type found on the given surface");
1655 SetErrorCode(NOT_FOUND_ANY); // NPAL18017
1659 // Fill sequence of object IDs
1660 aSeqOfIDs = new TColStd_HSequenceOfInteger;
1662 TopTools_IndexedMapOfShape anIndices;
1663 TopExp::MapShapes(aShape, anIndices);
1665 TopTools_ListIteratorOfListOfShape itSub (listSS);
1666 for (int index = 1; itSub.More(); itSub.Next(), ++index) {
1667 int id = anIndices.FindIndex(itSub.Value());
1668 aSeqOfIDs->Append(id);
1674 //=======================================================================
1675 //function : GetShapesOnBoxIDs
1677 * \brief Find subshapes complying with given status about surface
1678 * \param theBox - the box to check state of subshapes against
1679 * \param theShape - the shape to explore
1680 * \param theShapeType - type of subshape of theShape
1681 * \param theState - required state
1682 * \retval Handle(TColStd_HSequenceOfInteger) - IDs of found subshapes
1684 //=======================================================================
1685 Handle(TColStd_HSequenceOfInteger)
1686 GEOMImpl_IShapesOperations::GetShapesOnBoxIDs(const Handle(GEOM_Object)& theBox,
1687 const Handle(GEOM_Object)& theShape,
1688 const Standard_Integer theShapeType,
1689 GEOMAlgo_State theState)
1691 // Find subshapes ids
1692 Handle(TColStd_HSequenceOfInteger) aSeqOfIDs =
1693 getShapesOnBoxIDs (theBox, theShape, theShapeType, theState);
1694 if ( aSeqOfIDs.IsNull() || aSeqOfIDs->Length() == 0 )
1697 // The GetShapesOnBox() doesn't change object so no new function is required.
1698 Handle(GEOM_Function) aFunction = GEOM::GetCreatedLast(theShape,theBox)->GetLastFunction();
1700 // Make a Python command
1701 GEOM::TPythonDump(aFunction)
1702 << "listShapesOnBoxIDs = geompy.GetShapesOnBoxIDs("
1705 << TopAbs_ShapeEnum(theShapeType) << ", "
1712 //=======================================================================
1713 //function : GetShapesOnBox
1715 * \brief Find subshapes complying with given status about surface
1716 * \param theBox - the box to check state of subshapes against
1717 * \param theShape - the shape to explore
1718 * \param theShapeType - type of subshape of theShape
1719 * \param theState - required state
1720 * \retval Handle(TColStd_HSequenceOfTransient) - found subshapes
1722 //=======================================================================
1723 Handle(TColStd_HSequenceOfTransient)
1724 GEOMImpl_IShapesOperations::GetShapesOnBox(const Handle(GEOM_Object)& theBox,
1725 const Handle(GEOM_Object)& theShape,
1726 const Standard_Integer theShapeType,
1727 GEOMAlgo_State theState)
1729 // Find subshapes ids
1730 Handle(TColStd_HSequenceOfInteger) aSeqOfIDs =
1731 getShapesOnBoxIDs (theBox, theShape, theShapeType, theState);
1732 if ( aSeqOfIDs.IsNull() || aSeqOfIDs->Length() == 0 )
1735 // Find objects by indices
1736 TCollection_AsciiString anAsciiList;
1737 Handle(TColStd_HSequenceOfTransient) aSeq;
1738 aSeq = getObjectsShapesOn( theShape, aSeqOfIDs, anAsciiList );
1739 if ( aSeq.IsNull() || aSeq->IsEmpty() )
1742 // Make a Python command
1744 Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast( aSeq->Value( 1 ));
1745 Handle(GEOM_Function) aFunction = anObj->GetLastFunction();
1747 GEOM::TPythonDump(aFunction)
1748 << "[" << anAsciiList.ToCString() << "] = geompy.GetShapesOnBox("
1751 << TopAbs_ShapeEnum(theShapeType) << ", "
1758 //=======================================================================
1759 //function : getShapesOnShapeIDs
1761 * \brief Find IDs of subshapes complying with given status about surface
1762 * \param theCheckShape - the shape to check state of subshapes against
1763 * \param theShape - the shape to explore
1764 * \param theShapeType - type of subshape of theShape
1765 * \param theState - required state
1766 * \retval Handle(TColStd_HSequenceOfInteger) - IDs of found subshapes
1768 //=======================================================================
1769 Handle(TColStd_HSequenceOfInteger)
1770 GEOMImpl_IShapesOperations::getShapesOnShapeIDs
1771 (const Handle(GEOM_Object)& theCheckShape,
1772 const Handle(GEOM_Object)& theShape,
1773 const Standard_Integer theShapeType,
1774 GEOMAlgo_State theState)
1776 Handle(TColStd_HSequenceOfInteger) aSeqOfIDs;
1778 TopoDS_Shape aCheckShape = theCheckShape->GetValue();
1779 TopoDS_Shape aShape = theShape->GetValue();
1780 TopTools_ListOfShape res;
1782 // Check presence of triangulation, build if need
1783 if (!CheckTriangulation(aShape)) {
1784 SetErrorCode("Cannot build triangulation on the shape");
1789 GEOMAlgo_FinderShapeOn2 aFinder;
1790 Standard_Real aTol = 0.0001; // default value
1792 Handle(GEOMAlgo_ClsfSolid) aClsfSolid = new GEOMAlgo_ClsfSolid;
1793 aClsfSolid->SetShape(aCheckShape);
1795 aFinder.SetShape(aShape);
1796 aFinder.SetTolerance(aTol);
1797 aFinder.SetClsf(aClsfSolid);
1798 aFinder.SetShapeType( (TopAbs_ShapeEnum)theShapeType );
1799 aFinder.SetState(theState);
1802 // Interprete results
1803 Standard_Integer iErr = aFinder.ErrorStatus();
1804 // the detailed description of error codes is in GEOMAlgo_FinderShapeOn1.cxx
1807 SetErrorCode("theCheckShape must be a solid");
1810 MESSAGE(" iErr : " << iErr);
1811 TCollection_AsciiString aMsg (" iErr : ");
1812 aMsg += TCollection_AsciiString(iErr);
1817 Standard_Integer iWrn = aFinder.WarningStatus();
1818 // the detailed description of warning codes is in GEOMAlgo_FinderShapeOn1.cxx
1820 MESSAGE(" *** iWrn : " << iWrn);
1823 const TopTools_ListOfShape& listSS = aFinder.Shapes(); // the result
1825 if (listSS.Extent() < 1) {
1826 //SetErrorCode("Not a single sub-shape of the requested type found on the given surface");
1827 SetErrorCode(NOT_FOUND_ANY); // NPAL18017
1830 // Fill sequence of object IDs
1831 aSeqOfIDs = new TColStd_HSequenceOfInteger;
1833 TopTools_IndexedMapOfShape anIndices;
1834 TopExp::MapShapes(aShape, anIndices);
1836 TopTools_ListIteratorOfListOfShape itSub (listSS);
1837 for (int index = 1; itSub.More(); itSub.Next(), ++index) {
1838 int id = anIndices.FindIndex(itSub.Value());
1839 aSeqOfIDs->Append(id);
1845 //=======================================================================
1846 //function : GetShapesOnShapeIDs
1848 * \brief Find subshapes complying with given status about surface
1849 * \param theCheckShape - the shape to check state of subshapes against
1850 * \param theShape - the shape to explore
1851 * \param theShapeType - type of subshape of theShape
1852 * \param theState - required state
1853 * \retval Handle(TColStd_HSequenceOfInteger) - IDs of found subshapes
1855 //=======================================================================
1856 Handle(TColStd_HSequenceOfInteger)
1857 GEOMImpl_IShapesOperations::GetShapesOnShapeIDs
1858 (const Handle(GEOM_Object)& theCheckShape,
1859 const Handle(GEOM_Object)& theShape,
1860 const Standard_Integer theShapeType,
1861 GEOMAlgo_State theState)
1863 Handle(TColStd_HSequenceOfInteger) aSeqOfIDs =
1864 getShapesOnShapeIDs (theCheckShape, theShape, theShapeType, theState);
1866 if ( aSeqOfIDs.IsNull() || aSeqOfIDs->Length() == 0 )
1869 // The GetShapesOnShape() doesn't change object so no new function is required.
1870 Handle(GEOM_Function) aFunction =
1871 GEOM::GetCreatedLast(theShape,theCheckShape)->GetLastFunction();
1873 // Make a Python command
1874 GEOM::TPythonDump(aFunction)
1875 << "listShapesOnBoxIDs = geompy.GetShapesOnShapeIDs("
1876 << theCheckShape << ", "
1878 << TopAbs_ShapeEnum(theShapeType) << ", "
1885 //=======================================================================
1886 //function : GetShapesOnShape
1888 * \brief Find subshapes complying with given status about surface
1889 * \param theCheckShape - the shape to check state of subshapes against
1890 * \param theShape - the shape to explore
1891 * \param theShapeType - type of subshape of theShape
1892 * \param theState - required state
1893 * \retval Handle(TColStd_HSequenceOfTransient) - found subshapes
1895 //=======================================================================
1896 Handle(TColStd_HSequenceOfTransient)
1897 GEOMImpl_IShapesOperations::GetShapesOnShape
1898 (const Handle(GEOM_Object)& theCheckShape,
1899 const Handle(GEOM_Object)& theShape,
1900 const Standard_Integer theShapeType,
1901 GEOMAlgo_State theState)
1903 Handle(TColStd_HSequenceOfInteger) aSeqOfIDs =
1904 getShapesOnShapeIDs (theCheckShape, theShape, theShapeType, theState);
1905 if ( aSeqOfIDs.IsNull() || aSeqOfIDs->Length() == 0 )
1908 // Find objects by indices
1909 TCollection_AsciiString anAsciiList;
1910 Handle(TColStd_HSequenceOfTransient) aSeq;
1911 aSeq = getObjectsShapesOn( theShape, aSeqOfIDs, anAsciiList );
1913 if ( aSeq.IsNull() || aSeq->IsEmpty() )
1916 // Make a Python command
1918 Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast( aSeq->Value( 1 ));
1919 Handle(GEOM_Function) aFunction = anObj->GetLastFunction();
1921 GEOM::TPythonDump(aFunction)
1922 << "[" << anAsciiList.ToCString() << "] = geompy.GetShapesOnShape("
1923 << theCheckShape << ", "
1925 << TopAbs_ShapeEnum(theShapeType) << ", "
1932 //=======================================================================
1933 //function : GetShapesOnShapeAsCompound
1934 //=======================================================================
1935 Handle(GEOM_Object) GEOMImpl_IShapesOperations::GetShapesOnShapeAsCompound
1936 (const Handle(GEOM_Object)& theCheckShape,
1937 const Handle(GEOM_Object)& theShape,
1938 const Standard_Integer theShapeType,
1939 GEOMAlgo_State theState)
1941 Handle(TColStd_HSequenceOfInteger) aSeqOfIDs =
1942 getShapesOnShapeIDs (theCheckShape, theShape, theShapeType, theState);
1944 if ( aSeqOfIDs.IsNull() || aSeqOfIDs->Length() == 0 )
1947 // Find objects by indices
1948 TCollection_AsciiString anAsciiList;
1949 Handle(TColStd_HSequenceOfTransient) aSeq;
1950 aSeq = getObjectsShapesOn( theShape, aSeqOfIDs, anAsciiList );
1952 if ( aSeq.IsNull() || aSeq->IsEmpty() )
1955 TopoDS_Compound aCompound;
1957 B.MakeCompound(aCompound);
1959 for(; i<=aSeq->Length(); i++) {
1960 Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(aSeq->Value(i));
1961 TopoDS_Shape aShape_i = anObj->GetValue();
1962 B.Add(aCompound,aShape_i);
1965 //Add a new result object
1966 Handle(GEOM_Object) aRes = GetEngine()->AddObject(GetDocID(), GEOM_SHAPES_ON_SHAPE);
1967 Handle(GEOM_Function) aFunction =
1968 aRes->AddFunction(GEOMImpl_ShapeDriver::GetID(), SHAPES_ON_SHAPE);
1969 aFunction->SetValue(aCompound);
1971 GEOM::TPythonDump(aFunction)
1972 << aRes << " = geompy.GetShapesOnShapeAsCompound("
1973 << theCheckShape << ", "
1975 << TopAbs_ShapeEnum(theShapeType) << ", "
1983 //=======================================================================
1984 //function : getShapesOnSurfaceIDs
1986 * \brief Find IDs of subshapes complying with given status about surface
1987 * \param theSurface - the surface to check state of subshapes against
1988 * \param theShape - the shape to explore
1989 * \param theShapeType - type of subshape of theShape
1990 * \param theState - required state
1991 * \retval Handle(TColStd_HSequenceOfInteger) - IDs of found subshapes
1993 //=======================================================================
1994 Handle(TColStd_HSequenceOfInteger)
1995 GEOMImpl_IShapesOperations::getShapesOnSurfaceIDs(const Handle(Geom_Surface)& theSurface,
1996 const TopoDS_Shape& theShape,
1997 TopAbs_ShapeEnum theShapeType,
1998 GEOMAlgo_State theState)
2000 Handle(TColStd_HSequenceOfInteger) aSeqOfIDs;
2002 // Check presence of triangulation, build if need
2003 if (!CheckTriangulation(theShape)) {
2004 SetErrorCode("Cannot build triangulation on the shape");
2009 GEOMAlgo_FinderShapeOn1 aFinder;
2010 Standard_Real aTol = 0.0001; // default value
2012 aFinder.SetShape(theShape);
2013 aFinder.SetTolerance(aTol);
2014 aFinder.SetSurface(theSurface);
2015 aFinder.SetShapeType(theShapeType);
2016 aFinder.SetState(theState);
2018 // Sets the minimal number of inner points for the faces that do not have own
2019 // inner points at all (for e.g. rectangular planar faces have just 2 triangles).
2021 aFinder.SetNbPntsMin(3);
2022 // Sets the maximal number of inner points for edges or faces.
2023 // It is usefull for the cases when this number is very big (e.g =2000) to improve
2024 // the performance. If this value =0, all inner points will be taken into account.
2026 aFinder.SetNbPntsMax(100);
2030 // Interprete results
2031 Standard_Integer iErr = aFinder.ErrorStatus();
2032 // the detailed description of error codes is in GEOMAlgo_FinderShapeOn1.cxx
2034 MESSAGE(" iErr : " << iErr);
2035 TCollection_AsciiString aMsg (" iErr : ");
2036 aMsg += TCollection_AsciiString(iErr);
2040 Standard_Integer iWrn = aFinder.WarningStatus();
2041 // the detailed description of warning codes is in GEOMAlgo_FinderShapeOn1.cxx
2043 MESSAGE(" *** iWrn : " << iWrn);
2046 const TopTools_ListOfShape& listSS = aFinder.Shapes(); // the result
2048 if (listSS.Extent() < 1) {
2049 //SetErrorCode("Not a single sub-shape of the requested type found on the given surface");
2050 SetErrorCode(NOT_FOUND_ANY); // NPAL18017
2054 // Fill sequence of object IDs
2055 aSeqOfIDs = new TColStd_HSequenceOfInteger;
2057 TopTools_IndexedMapOfShape anIndices;
2058 TopExp::MapShapes(theShape, anIndices);
2060 TopTools_ListIteratorOfListOfShape itSub (listSS);
2061 for (int index = 1; itSub.More(); itSub.Next(), ++index) {
2062 int id = anIndices.FindIndex(itSub.Value());
2063 aSeqOfIDs->Append(id);
2069 //=======================================================================
2070 //function : getObjectsShapesOn
2072 * \brief Find shape objects and their entries by their ids
2073 * \param theShapeIDs - incoming shape ids
2074 * \param theShapeEntries - outgoing entries like "entry1, entry2, ..."
2075 * \retval Handle(TColStd_HSequenceOfTransient) - found shape objects
2077 //=======================================================================
2078 Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::
2079 getObjectsShapesOn(const Handle(GEOM_Object)& theShape,
2080 const Handle(TColStd_HSequenceOfInteger)& theShapeIDs,
2081 TCollection_AsciiString & theShapeEntries)
2083 Handle(TColStd_HSequenceOfTransient) aSeq;
2085 if ( !theShapeIDs.IsNull() && theShapeIDs->Length() > 0 )
2087 aSeq = new TColStd_HSequenceOfTransient;
2088 Handle(TColStd_HArray1OfInteger) anArray = new TColStd_HArray1OfInteger(1,1);
2089 TCollection_AsciiString anEntry;
2090 for ( int i = 1; i <= theShapeIDs->Length(); ++i )
2092 anArray->SetValue(1, theShapeIDs->Value( i ));
2093 Handle(GEOM_Object) anObj = GetEngine()->AddSubShape(theShape, anArray);
2094 aSeq->Append( anObj );
2096 TDF_Tool::Entry(anObj->GetEntry(), anEntry);
2097 if ( i != 1 ) theShapeEntries += ",";
2098 theShapeEntries += anEntry;
2104 //=======================================================================
2105 //function : getShapesOnSurface
2107 * \brief Find subshapes complying with given status about surface
2108 * \param theSurface - the surface to check state of subshapes against
2109 * \param theShape - the shape to explore
2110 * \param theShapeType - type of subshape of theShape
2111 * \param theState - required state
2112 * \param theShapeEntries - outgoing entries like "entry1, entry2, ..."
2113 * \retval Handle(TColStd_HSequenceOfInteger) - IDs of found subshapes
2115 //=======================================================================
2116 Handle(TColStd_HSequenceOfTransient)
2117 GEOMImpl_IShapesOperations::getShapesOnSurface(const Handle(Geom_Surface)& theSurface,
2118 const Handle(GEOM_Object)& theShape,
2119 TopAbs_ShapeEnum theShapeType,
2120 GEOMAlgo_State theState,
2121 TCollection_AsciiString & theShapeEntries)
2123 // Find subshapes ids
2124 Handle(TColStd_HSequenceOfInteger) aSeqOfIDs =
2125 getShapesOnSurfaceIDs (theSurface, theShape->GetValue(), theShapeType, theState);
2126 if ( aSeqOfIDs.IsNull() || aSeqOfIDs->Length() == 0 )
2129 return getObjectsShapesOn( theShape, aSeqOfIDs, theShapeEntries );
2132 //=============================================================================
2136 //=============================================================================
2137 Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::GetShapesOnPlane
2138 (const Handle(GEOM_Object)& theShape,
2139 const Standard_Integer theShapeType,
2140 const Handle(GEOM_Object)& theAx1,
2141 const GEOMAlgo_State theState)
2145 if (theShape.IsNull() || theAx1.IsNull()) return NULL;
2147 TopoDS_Shape aShape = theShape->GetValue();
2148 TopoDS_Shape anAx1 = theAx1->GetValue();
2150 if (aShape.IsNull() || anAx1.IsNull()) return NULL;
2152 TopAbs_ShapeEnum aShapeType = TopAbs_ShapeEnum(theShapeType);
2153 if ( !checkTypeShapesOn( theShapeType ))
2157 Handle(Geom_Surface) aPlane = makePlane( anAx1 );
2158 if ( aPlane.IsNull() )
2162 TCollection_AsciiString anAsciiList;
2163 Handle(TColStd_HSequenceOfTransient) aSeq;
2164 aSeq = getShapesOnSurface( aPlane, theShape, aShapeType, theState, anAsciiList );
2165 if ( aSeq.IsNull() || aSeq->Length() == 0 )
2168 // Make a Python command
2170 Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast( aSeq->Value( 1 ));
2171 Handle(GEOM_Function) aFunction = anObj->GetLastFunction();
2173 GEOM::TPythonDump(aFunction) << "[" << anAsciiList.ToCString()
2174 << "] = geompy.GetShapesOnPlane(" << theShape << ", "
2175 << aShapeType << ", " << theAx1 << ", " << theState << ")";
2181 //=============================================================================
2183 * GetShapesOnPlaneWithLocation
2185 //=============================================================================
2186 Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::GetShapesOnPlaneWithLocation
2187 (const Handle(GEOM_Object)& theShape,
2188 const Standard_Integer theShapeType,
2189 const Handle(GEOM_Object)& theAx1,
2190 const Handle(GEOM_Object)& thePnt,
2191 const GEOMAlgo_State theState)
2195 if (theShape.IsNull() || theAx1.IsNull() || thePnt.IsNull()) return NULL;
2197 TopoDS_Shape aShape = theShape->GetValue();
2198 TopoDS_Shape anAx1 = theAx1->GetValue();
2199 TopoDS_Shape anPnt = thePnt->GetValue();
2201 if (aShape.IsNull() || anAx1.IsNull() || anPnt.IsNull()) return NULL;
2203 TopAbs_ShapeEnum aShapeType = TopAbs_ShapeEnum(theShapeType);
2204 if ( !checkTypeShapesOn( theShapeType ))
2208 if ( anAx1.ShapeType() != TopAbs_EDGE || anPnt.ShapeType() != TopAbs_VERTEX ) return NULL;
2209 TopoDS_Vertex V1, V2, V3;
2210 TopoDS_Edge anEdge = TopoDS::Edge(anAx1);
2211 TopExp::Vertices(anEdge, V1, V2, Standard_True);
2213 if (V1.IsNull() || V2.IsNull()) {
2214 SetErrorCode("Bad edge given for the plane normal vector");
2217 V3 = TopoDS::Vertex(anPnt);
2220 SetErrorCode("Bad vertex given for the plane location");
2223 gp_Pnt aLoc = BRep_Tool::Pnt(V3);
2224 gp_Vec aVec(BRep_Tool::Pnt(V1),BRep_Tool::Pnt(V2));
2226 if (aVec.Magnitude() < Precision::Confusion()) {
2227 SetErrorCode("Vector with null magnitude given");
2230 Handle(Geom_Surface) aPlane = new Geom_Plane(aLoc, aVec);
2232 if ( aPlane.IsNull() )
2236 TCollection_AsciiString anAsciiList;
2237 Handle(TColStd_HSequenceOfTransient) aSeq;
2238 aSeq = getShapesOnSurface( aPlane, theShape, aShapeType, theState, anAsciiList );
2239 if ( aSeq.IsNull() || aSeq->Length() == 0 )
2242 // Make a Python command
2244 Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast( aSeq->Value( 1 ));
2245 Handle(GEOM_Function) aFunction = anObj->GetLastFunction();
2247 GEOM::TPythonDump(aFunction) << "[" << anAsciiList.ToCString()
2248 << "] = geompy.GetShapesOnPlaneWithLocation(" << theShape << ", "
2249 << aShapeType << ", " << theAx1 << ", "<< thePnt <<", " << theState << ")";
2255 //=============================================================================
2257 * GetShapesOnCylinder
2259 //=============================================================================
2260 Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::GetShapesOnCylinder
2261 (const Handle(GEOM_Object)& theShape,
2262 const Standard_Integer theShapeType,
2263 const Handle(GEOM_Object)& theAxis,
2264 const Standard_Real theRadius,
2265 const GEOMAlgo_State theState)
2269 if (theShape.IsNull() || theAxis.IsNull()) return NULL;
2271 TopoDS_Shape aShape = theShape->GetValue();
2272 TopoDS_Shape anAxis = theAxis->GetValue();
2274 if (aShape.IsNull() || anAxis.IsNull()) return NULL;
2276 TopAbs_ShapeEnum aShapeType = TopAbs_ShapeEnum(theShapeType);
2277 if ( !checkTypeShapesOn( aShapeType ))
2280 // Create a cylinder surface
2281 Handle(Geom_Surface) aCylinder = makeCylinder( anAxis, theRadius );
2282 if ( aCylinder.IsNull() )
2286 TCollection_AsciiString anAsciiList;
2287 Handle(TColStd_HSequenceOfTransient) aSeq;
2288 aSeq = getShapesOnSurface( aCylinder, theShape, aShapeType, theState, anAsciiList );
2289 if ( aSeq.IsNull() || aSeq->Length() == 0 )
2292 // Make a Python command
2294 Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast( aSeq->Value( 1 ));
2295 Handle(GEOM_Function) aFunction = anObj->GetLastFunction();
2297 GEOM::TPythonDump(aFunction) << "[" << anAsciiList.ToCString()
2298 << "] = geompy.GetShapesOnCylinder(" << theShape << ", " << aShapeType
2299 << ", " << theAxis << ", " << theRadius << ", " << theState << ")";
2305 //=============================================================================
2307 * GetShapesOnCylinderWithLocation
2309 //=============================================================================
2310 Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::GetShapesOnCylinderWithLocation
2311 (const Handle(GEOM_Object)& theShape,
2312 const Standard_Integer theShapeType,
2313 const Handle(GEOM_Object)& theAxis,
2314 const Handle(GEOM_Object)& thePnt,
2315 const Standard_Real theRadius,
2316 const GEOMAlgo_State theState)
2320 if (theShape.IsNull() || theAxis.IsNull() || thePnt.IsNull()) return NULL;
2322 TopoDS_Shape aShape = theShape->GetValue();
2323 TopoDS_Shape anAxis = theAxis->GetValue();
2324 TopoDS_Shape aPnt = thePnt->GetValue();
2326 if (aShape.IsNull() || anAxis.IsNull() || aPnt.IsNull()) return NULL;
2328 if (aPnt.ShapeType() != TopAbs_VERTEX )
2330 SetErrorCode("Bottom location point must be vertex");
2334 TopAbs_ShapeEnum aShapeType = TopAbs_ShapeEnum(theShapeType);
2335 if ( !checkTypeShapesOn( aShapeType ))
2338 // Create a cylinder surface
2339 Handle(Geom_Surface) aCylinder = makeCylinder( anAxis, theRadius );
2340 if ( aCylinder.IsNull() )
2343 // translate the surface
2344 Handle(Geom_CylindricalSurface) aCylSurface =
2345 Handle(Geom_CylindricalSurface)::DownCast( aCylinder );
2346 if ( aCylSurface.IsNull() )
2348 SetErrorCode("Unexpected surface type instead of Geom_CylindricalSurface");
2351 gp_Pnt fromLoc = aCylSurface->Cylinder().Location();
2352 gp_Pnt toLoc = BRep_Tool::Pnt( TopoDS::Vertex( aPnt ));
2353 aCylinder->Translate( fromLoc, toLoc );
2356 TCollection_AsciiString anAsciiList;
2357 Handle(TColStd_HSequenceOfTransient) aSeq;
2358 aSeq = getShapesOnSurface( aCylinder, theShape, aShapeType, theState, anAsciiList );
2359 if ( aSeq.IsNull() || aSeq->Length() == 0 )
2362 // Make a Python command
2364 Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast( aSeq->Value( 1 ));
2365 Handle(GEOM_Function) aFunction = anObj->GetLastFunction();
2367 GEOM::TPythonDump(aFunction)
2368 << "[" << anAsciiList.ToCString()
2369 << "] = geompy.GetShapesOnCylinderWithLocation(" << theShape << ", " << aShapeType << ", "
2370 << theAxis << ", " << thePnt << ", " << theRadius << ", " << theState << ")";
2376 //=============================================================================
2380 //=============================================================================
2381 Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::GetShapesOnSphere
2382 (const Handle(GEOM_Object)& theShape,
2383 const Standard_Integer theShapeType,
2384 const Handle(GEOM_Object)& theCenter,
2385 const Standard_Real theRadius,
2386 const GEOMAlgo_State theState)
2390 if (theShape.IsNull() || theCenter.IsNull()) return NULL;
2392 TopoDS_Shape aShape = theShape->GetValue();
2393 TopoDS_Shape aCenter = theCenter->GetValue();
2395 if (aShape.IsNull() || aCenter.IsNull()) return NULL;
2397 TopAbs_ShapeEnum aShapeType = TopAbs_ShapeEnum(theShapeType);
2398 if ( !checkTypeShapesOn( aShapeType ))
2401 // Center of the sphere
2402 if (aCenter.ShapeType() != TopAbs_VERTEX) return NULL;
2403 gp_Pnt aLoc = BRep_Tool::Pnt(TopoDS::Vertex(aCenter));
2405 gp_Ax3 anAx3 (aLoc, gp::DZ());
2406 Handle(Geom_SphericalSurface) aSphere =
2407 new Geom_SphericalSurface(anAx3, theRadius);
2410 TCollection_AsciiString anAsciiList;
2411 Handle(TColStd_HSequenceOfTransient) aSeq;
2412 aSeq = getShapesOnSurface( aSphere, theShape, aShapeType, theState, anAsciiList );
2413 if ( aSeq.IsNull() || aSeq->Length() == 0 )
2416 // Make a Python command
2418 Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast( aSeq->Value( 1 ));
2419 Handle(GEOM_Function) aFunction = anObj->GetLastFunction();
2421 GEOM::TPythonDump(aFunction) << "[" << anAsciiList.ToCString()
2422 << "] = geompy.GetShapesOnSphere(" << theShape << ", " << aShapeType
2423 << ", " << theCenter << ", " << theRadius << ", " << theState << ")";
2429 //=============================================================================
2431 * GetShapesOnPlaneIDs
2433 //=============================================================================
2434 Handle(TColStd_HSequenceOfInteger) GEOMImpl_IShapesOperations::GetShapesOnPlaneIDs
2435 (const Handle(GEOM_Object)& theShape,
2436 const Standard_Integer theShapeType,
2437 const Handle(GEOM_Object)& theAx1,
2438 const GEOMAlgo_State theState)
2442 if (theShape.IsNull() || theAx1.IsNull()) return NULL;
2444 TopoDS_Shape aShape = theShape->GetValue();
2445 TopoDS_Shape anAx1 = theAx1->GetValue();
2447 if (aShape.IsNull() || anAx1.IsNull()) return NULL;
2449 TopAbs_ShapeEnum aShapeType = TopAbs_ShapeEnum(theShapeType);
2450 if ( !checkTypeShapesOn( aShapeType ))
2454 Handle(Geom_Surface) aPlane = makePlane( anAx1 );
2455 if ( aPlane.IsNull() )
2459 Handle(TColStd_HSequenceOfInteger) aSeq;
2460 aSeq = getShapesOnSurfaceIDs( aPlane, aShape, aShapeType, theState );
2462 // The GetShapesOnPlaneIDs() doesn't change object so no new function is required.
2463 Handle(GEOM_Function) aFunction = GEOM::GetCreatedLast(theShape,theAx1)->GetLastFunction();
2465 // Make a Python command
2466 GEOM::TPythonDump(aFunction, /*append=*/true)
2467 << "listShapesOnPlane = geompy.GetShapesOnPlaneIDs"
2468 << "(" << theShape << "," << aShapeType << "," << theAx1 << "," << theState << ")";
2474 //=============================================================================
2476 * GetShapesOnPlaneWithLocationIDs
2478 //=============================================================================
2479 Handle(TColStd_HSequenceOfInteger) GEOMImpl_IShapesOperations::GetShapesOnPlaneWithLocationIDs
2480 (const Handle(GEOM_Object)& theShape,
2481 const Standard_Integer theShapeType,
2482 const Handle(GEOM_Object)& theAx1,
2483 const Handle(GEOM_Object)& thePnt,
2484 const GEOMAlgo_State theState)
2488 if (theShape.IsNull() || theAx1.IsNull() || thePnt.IsNull()) return NULL;
2490 TopoDS_Shape aShape = theShape->GetValue();
2491 TopoDS_Shape anAx1 = theAx1->GetValue();
2492 TopoDS_Shape anPnt = thePnt->GetValue();
2494 if (aShape.IsNull() || anAx1.IsNull() || anPnt.IsNull()) return NULL;
2496 TopAbs_ShapeEnum aShapeType = TopAbs_ShapeEnum(theShapeType);
2497 if ( !checkTypeShapesOn( aShapeType ))
2501 if (anAx1.ShapeType() != TopAbs_EDGE || anPnt.ShapeType() != TopAbs_VERTEX) return NULL;
2502 TopoDS_Edge anEdge = TopoDS::Edge(anAx1);
2503 TopoDS_Vertex V1, V2, V3;
2504 TopExp::Vertices(anEdge, V1, V2, Standard_True);
2505 if (V1.IsNull() || V2.IsNull()) {
2506 SetErrorCode("Bad edge given for the plane normal vector");
2509 V3 = TopoDS::Vertex(anPnt);
2511 SetErrorCode("Bad vertex given for the plane location");
2514 gp_Pnt aLoc = BRep_Tool::Pnt(V3);
2515 gp_Vec aVec(BRep_Tool::Pnt(V1),BRep_Tool::Pnt(V2));
2516 if (aVec.Magnitude() < Precision::Confusion()) {
2517 SetErrorCode("Vector with null magnitude given");
2521 Handle(Geom_Surface) aPlane = new Geom_Plane(aLoc, aVec);
2522 if ( aPlane.IsNull() )
2526 Handle(TColStd_HSequenceOfInteger) aSeq;
2527 aSeq = getShapesOnSurfaceIDs( aPlane, aShape, aShapeType, theState );
2529 // The GetShapesOnPlaneIDs() doesn't change object so no new function is required.
2530 Handle(GEOM_Function) aFunction = GEOM::GetCreatedLast(theShape,theAx1)->GetLastFunction();
2532 // Make a Python command
2533 GEOM::TPythonDump(aFunction, /*append=*/true)
2534 << "listShapesOnPlane = geompy.GetShapesOnPlaneWithLocationIDs"
2535 << "(" << theShape << ", " << aShapeType << ", " << theAx1 << ", "<< thePnt << ", " << theState << ")";
2541 //=============================================================================
2543 * GetShapesOnCylinderIDs
2545 //=============================================================================
2546 Handle(TColStd_HSequenceOfInteger) GEOMImpl_IShapesOperations::GetShapesOnCylinderIDs
2547 (const Handle(GEOM_Object)& theShape,
2548 const Standard_Integer theShapeType,
2549 const Handle(GEOM_Object)& theAxis,
2550 const Standard_Real theRadius,
2551 const GEOMAlgo_State theState)
2555 if (theShape.IsNull() || theAxis.IsNull()) return NULL;
2557 TopoDS_Shape aShape = theShape->GetValue();
2558 TopoDS_Shape anAxis = theAxis->GetValue();
2560 if (aShape.IsNull() || anAxis.IsNull()) return NULL;
2562 TopAbs_ShapeEnum aShapeType = TopAbs_ShapeEnum(theShapeType);
2563 if ( !checkTypeShapesOn( aShapeType ))
2566 // Create a cylinder surface
2567 Handle(Geom_Surface) aCylinder = makeCylinder( anAxis, theRadius );
2568 if ( aCylinder.IsNull() )
2572 Handle(TColStd_HSequenceOfInteger) aSeq;
2573 aSeq = getShapesOnSurfaceIDs( aCylinder, aShape, aShapeType, theState );
2575 // The GetShapesOnCylinder() doesn't change object so no new function is required.
2576 Handle(GEOM_Function) aFunction = GEOM::GetCreatedLast(theShape,theAxis)->GetLastFunction();
2578 // Make a Python command
2579 GEOM::TPythonDump(aFunction, /*append=*/true)
2580 << "listShapesOnCylinder = geompy.GetShapesOnCylinderIDs"
2581 << "(" << theShape << ", " << aShapeType << ", " << theAxis << ", "
2582 << theRadius << ", " << theState << ")";
2588 //=============================================================================
2590 * GetShapesOnCylinderWithLocationIDs
2592 //=============================================================================
2593 Handle(TColStd_HSequenceOfInteger) GEOMImpl_IShapesOperations::GetShapesOnCylinderWithLocationIDs
2594 (const Handle(GEOM_Object)& theShape,
2595 const Standard_Integer theShapeType,
2596 const Handle(GEOM_Object)& theAxis,
2597 const Handle(GEOM_Object)& thePnt,
2598 const Standard_Real theRadius,
2599 const GEOMAlgo_State theState)
2603 if (theShape.IsNull() || theAxis.IsNull() || thePnt.IsNull()) return NULL;
2605 TopoDS_Shape aShape = theShape->GetValue();
2606 TopoDS_Shape anAxis = theAxis->GetValue();
2607 TopoDS_Shape aPnt = thePnt->GetValue();
2609 if (aShape.IsNull() || anAxis.IsNull() || aPnt.IsNull()) return NULL;
2611 if (aPnt.ShapeType() != TopAbs_VERTEX )
2613 SetErrorCode("Bottom location point must be vertex");
2617 TopAbs_ShapeEnum aShapeType = TopAbs_ShapeEnum(theShapeType);
2618 if ( !checkTypeShapesOn( aShapeType ))
2621 // Create a cylinder surface
2622 Handle(Geom_Surface) aCylinder = makeCylinder( anAxis, theRadius );
2623 if ( aCylinder.IsNull() )
2626 // translate the surface
2627 Handle(Geom_CylindricalSurface) aCylSurface =
2628 Handle(Geom_CylindricalSurface)::DownCast( aCylinder );
2629 if ( aCylSurface.IsNull() )
2631 SetErrorCode("Unexpected surface type instead of Geom_CylindricalSurface");
2634 gp_Pnt fromLoc = aCylSurface->Cylinder().Location();
2635 gp_Pnt toLoc = BRep_Tool::Pnt( TopoDS::Vertex( aPnt ));
2636 aCylinder->Translate( fromLoc, toLoc );
2639 Handle(TColStd_HSequenceOfInteger) aSeq;
2640 aSeq = getShapesOnSurfaceIDs( aCylinder, aShape, aShapeType, theState );
2642 // The GetShapesOnCylinder() doesn't change object so no new function is required.
2643 Handle(GEOM_Function) aFunction =
2644 GEOM::GetCreatedLast(theShape, GEOM::GetCreatedLast(thePnt,theAxis))->GetLastFunction();
2646 // Make a Python command
2647 GEOM::TPythonDump(aFunction, /*append=*/true)
2648 << "listShapesOnCylinder = geompy.GetShapesOnCylinderWithLocationIDs"
2649 << "(" << theShape << ", " << aShapeType << ", " << theAxis << ", "
2650 << thePnt << ", " << theRadius << ", " << theState << ")";
2656 //=============================================================================
2658 * GetShapesOnSphereIDs
2660 //=============================================================================
2661 Handle(TColStd_HSequenceOfInteger) GEOMImpl_IShapesOperations::GetShapesOnSphereIDs
2662 (const Handle(GEOM_Object)& theShape,
2663 const Standard_Integer theShapeType,
2664 const Handle(GEOM_Object)& theCenter,
2665 const Standard_Real theRadius,
2666 const GEOMAlgo_State theState)
2670 if (theShape.IsNull() || theCenter.IsNull()) return NULL;
2672 TopoDS_Shape aShape = theShape->GetValue();
2673 TopoDS_Shape aCenter = theCenter->GetValue();
2675 if (aShape.IsNull() || aCenter.IsNull()) return NULL;
2677 TopAbs_ShapeEnum aShapeType = TopAbs_ShapeEnum(theShapeType);
2678 if ( !checkTypeShapesOn( aShapeType ))
2681 // Center of the sphere
2682 if (aCenter.ShapeType() != TopAbs_VERTEX) return NULL;
2683 gp_Pnt aLoc = BRep_Tool::Pnt(TopoDS::Vertex(aCenter));
2685 gp_Ax3 anAx3 (aLoc, gp::DZ());
2686 Handle(Geom_SphericalSurface) aSphere =
2687 new Geom_SphericalSurface(anAx3, theRadius);
2690 Handle(TColStd_HSequenceOfInteger) aSeq;
2691 aSeq = getShapesOnSurfaceIDs( aSphere, aShape, aShapeType, theState );
2693 // The GetShapesOnSphere() doesn't change object so no new function is required.
2694 Handle(GEOM_Function) aFunction = GEOM::GetCreatedLast(theShape,theCenter)->GetLastFunction();
2696 // Make a Python command
2697 GEOM::TPythonDump(aFunction, /*append=*/true)
2698 << "listShapesOnCylinder = geompy.GetShapesOnCylinderIDs"
2699 << "(" << theShape << ", " << aShapeType << ", " << theCenter << ", "
2700 << theRadius << ", " << theState << ")";
2706 //=======================================================================
2707 //function : getShapesOnQuadrangleIDs
2709 * \brief Find IDs of subshapes complying with given status about quadrangle
2710 * \param theShape - the shape to explore
2711 * \param theShapeType - type of subshape of theShape
2712 * \param theTopLeftPoint - top left quadrangle corner
2713 * \param theTopRigthPoint - top right quadrangle corner
2714 * \param theBottomLeftPoint - bottom left quadrangle corner
2715 * \param theBottomRigthPoint - bottom right quadrangle corner
2716 * \param theState - required state
2717 * \retval Handle(TColStd_HSequenceOfInteger) - IDs of found subshapes
2719 //=======================================================================
2720 Handle(TColStd_HSequenceOfInteger)
2721 GEOMImpl_IShapesOperations::getShapesOnQuadrangleIDs (const Handle(GEOM_Object)& theShape,
2722 const Standard_Integer theShapeType,
2723 const Handle(GEOM_Object)& theTopLeftPoint,
2724 const Handle(GEOM_Object)& theTopRigthPoint,
2725 const Handle(GEOM_Object)& theBottomLeftPoint,
2726 const Handle(GEOM_Object)& theBottomRigthPoint,
2727 const GEOMAlgo_State theState)
2731 if ( theShape.IsNull() ||
2732 theTopLeftPoint.IsNull() ||
2733 theTopRigthPoint.IsNull() ||
2734 theBottomLeftPoint.IsNull() ||
2735 theBottomRigthPoint.IsNull() )
2738 TopoDS_Shape aShape = theShape->GetValue();
2739 TopoDS_Shape aTL = theTopLeftPoint->GetValue();
2740 TopoDS_Shape aTR = theTopRigthPoint->GetValue();
2741 TopoDS_Shape aBL = theBottomLeftPoint->GetValue();
2742 TopoDS_Shape aBR = theBottomRigthPoint->GetValue();
2744 if (aShape.IsNull() ||
2749 aTL.ShapeType() != TopAbs_VERTEX ||
2750 aTR.ShapeType() != TopAbs_VERTEX ||
2751 aBL.ShapeType() != TopAbs_VERTEX ||
2752 aBR.ShapeType() != TopAbs_VERTEX )
2755 TopAbs_ShapeEnum aShapeType = TopAbs_ShapeEnum(theShapeType);
2756 if ( !checkTypeShapesOn( aShapeType ))
2759 Handle(TColStd_HSequenceOfInteger) aSeqOfIDs;
2761 // Check presence of triangulation, build if need
2762 if (!CheckTriangulation(aShape)) {
2763 SetErrorCode("Cannot build triangulation on the shape");
2768 gp_Pnt aPntTL = BRep_Tool::Pnt(TopoDS::Vertex(aTL));
2769 gp_Pnt aPntTR = BRep_Tool::Pnt(TopoDS::Vertex(aTR));
2770 gp_Pnt aPntBL = BRep_Tool::Pnt(TopoDS::Vertex(aBL));
2771 gp_Pnt aPntBR = BRep_Tool::Pnt(TopoDS::Vertex(aBR));
2773 GEOMAlgo_FinderShapeOnQuad aFinder( aPntTL, aPntTR, aPntBL, aPntBR );
2774 Standard_Real aTol = 0.0001; // default value
2776 aFinder.SetShape(aShape);
2777 aFinder.SetTolerance(aTol);
2778 //aFinder.SetSurface(theSurface);
2779 aFinder.SetShapeType(aShapeType);
2780 aFinder.SetState(theState);
2782 // Sets the minimal number of inner points for the faces that do not have own
2783 // inner points at all (for e.g. rectangular planar faces have just 2 triangles).
2785 aFinder.SetNbPntsMin(3);
2786 // Sets the maximal number of inner points for edges or faces.
2787 // It is usefull for the cases when this number is very big (e.g =2000) to improve
2788 // the performance. If this value =0, all inner points will be taken into account.
2790 aFinder.SetNbPntsMax(100);
2794 // Interprete results
2795 Standard_Integer iErr = aFinder.ErrorStatus();
2796 // the detailed description of error codes is in GEOMAlgo_FinderShapeOn1.cxx
2798 MESSAGE(" iErr : " << iErr);
2799 TCollection_AsciiString aMsg (" iErr : ");
2800 aMsg += TCollection_AsciiString(iErr);
2804 Standard_Integer iWrn = aFinder.WarningStatus();
2805 // the detailed description of warning codes is in GEOMAlgo_FinderShapeOn1.cxx
2807 MESSAGE(" *** iWrn : " << iWrn);
2810 const TopTools_ListOfShape& listSS = aFinder.Shapes(); // the result
2812 if (listSS.Extent() < 1) {
2813 //SetErrorCode("Not a single sub-shape of the requested type found on the given surface");
2814 SetErrorCode(NOT_FOUND_ANY); // NPAL18017
2818 // Fill sequence of object IDs
2819 aSeqOfIDs = new TColStd_HSequenceOfInteger;
2821 TopTools_IndexedMapOfShape anIndices;
2822 TopExp::MapShapes(aShape, anIndices);
2824 TopTools_ListIteratorOfListOfShape itSub (listSS);
2825 for (int index = 1; itSub.More(); itSub.Next(), ++index) {
2826 int id = anIndices.FindIndex(itSub.Value());
2827 aSeqOfIDs->Append(id);
2832 //=======================================================================
2833 //function : GetShapesOnQuadrangle
2835 * \brief Find subshapes complying with given status about quadrangle
2836 * \param theShape - the shape to explore
2837 * \param theShapeType - type of subshape of theShape
2838 * \param theTopLeftPoint - top left quadrangle corner
2839 * \param theTopRigthPoint - top right quadrangle corner
2840 * \param theBottomLeftPoint - bottom left quadrangle corner
2841 * \param theBottomRigthPoint - bottom right quadrangle corner
2842 * \param theState - required state
2843 * \retval Handle(TColStd_HSequenceOfInteger) - IDs of found subshapes
2845 //=======================================================================
2846 Handle(TColStd_HSequenceOfTransient)
2847 GEOMImpl_IShapesOperations::GetShapesOnQuadrangle (const Handle(GEOM_Object)& theShape,
2848 const Standard_Integer theShapeType,
2849 const Handle(GEOM_Object)& theTopLeftPoint,
2850 const Handle(GEOM_Object)& theTopRigthPoint,
2851 const Handle(GEOM_Object)& theBottomLeftPoint,
2852 const Handle(GEOM_Object)& theBottomRigthPoint,
2853 const GEOMAlgo_State theState)
2856 Handle(TColStd_HSequenceOfInteger) aSeqOfIDs =
2857 getShapesOnQuadrangleIDs( theShape,
2862 theBottomRigthPoint,
2864 if ( aSeqOfIDs.IsNull() || aSeqOfIDs->IsEmpty() )
2867 // Find objects by indices
2868 TCollection_AsciiString anAsciiList;
2869 Handle(TColStd_HSequenceOfTransient) aSeq;
2870 aSeq = getObjectsShapesOn( theShape, aSeqOfIDs, anAsciiList );
2871 if ( aSeq.IsNull() || aSeq->IsEmpty() )
2874 // Make a Python command
2876 Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast( aSeq->Value( 1 ));
2877 Handle(GEOM_Function) aFunction = anObj->GetLastFunction();
2879 GEOM::TPythonDump(aFunction)
2880 << "[" << anAsciiList.ToCString() << "] = geompy.GetShapesOnQuadrangle("
2882 << TopAbs_ShapeEnum(theShapeType) << ", "
2883 << theTopLeftPoint << ", "
2884 << theTopRigthPoint << ", "
2885 << theBottomLeftPoint << ", "
2886 << theBottomRigthPoint << ", "
2893 //=======================================================================
2894 //function : GetShapesOnQuadrangleIDs
2896 * \brief Find IDs of subshapes complying with given status about quadrangle
2897 * \param theShape - the shape to explore
2898 * \param theShapeType - type of subshape of theShape
2899 * \param theTopLeftPoint - top left quadrangle corner
2900 * \param theTopRigthPoint - top right quadrangle corner
2901 * \param theBottomLeftPoint - bottom left quadrangle corner
2902 * \param theBottomRigthPoint - bottom right quadrangle corner
2903 * \param theState - required state
2904 * \retval Handle(TColStd_HSequenceOfInteger) - IDs of found subshapes
2906 //=======================================================================
2907 Handle(TColStd_HSequenceOfInteger)
2908 GEOMImpl_IShapesOperations::GetShapesOnQuadrangleIDs (const Handle(GEOM_Object)& theShape,
2909 const Standard_Integer theShapeType,
2910 const Handle(GEOM_Object)& theTopLeftPoint,
2911 const Handle(GEOM_Object)& theTopRigthPoint,
2912 const Handle(GEOM_Object)& theBottomLeftPoint,
2913 const Handle(GEOM_Object)& theBottomRigthPoint,
2914 const GEOMAlgo_State theState)
2917 Handle(TColStd_HSequenceOfInteger) aSeqOfIDs =
2918 getShapesOnQuadrangleIDs( theShape,
2923 theBottomRigthPoint,
2925 if ( aSeqOfIDs.IsNull() || aSeqOfIDs->IsEmpty() )
2928 // Make a Python command
2930 // The GetShapesOnCylinder() doesn't change object so no new function is required.
2931 Handle(GEOM_Object) lastObj = GEOM::GetCreatedLast(theShape,theTopLeftPoint);
2932 lastObj = GEOM::GetCreatedLast(lastObj,theTopRigthPoint);
2933 lastObj = GEOM::GetCreatedLast(lastObj,theBottomRigthPoint);
2934 lastObj = GEOM::GetCreatedLast(lastObj,theBottomLeftPoint);
2935 Handle(GEOM_Function) aFunction = lastObj->GetLastFunction();
2937 GEOM::TPythonDump(aFunction, /*append=*/true)
2938 << "listShapesOnQuadrangle = geompy.GetShapesOnQuadrangleIDs("
2940 << TopAbs_ShapeEnum(theShapeType) << ", "
2941 << theTopLeftPoint << ", "
2942 << theTopRigthPoint << ", "
2943 << theBottomLeftPoint << ", "
2944 << theBottomRigthPoint << ", "
2951 //=============================================================================
2955 //=============================================================================
2956 static bool GetInPlaceOfShape (const Handle(GEOM_Function)& theWhereFunction,
2957 const TopTools_IndexedMapOfShape& theWhereIndices,
2958 const TopoDS_Shape& theWhat,
2959 TColStd_ListOfInteger& theModifiedList)
2961 if (theWhereFunction.IsNull() || theWhat.IsNull()) return false;
2963 if (theWhereIndices.Contains(theWhat)) {
2964 // entity was not changed by the operation
2965 Standard_Integer aWhatIndex = theWhereIndices.FindIndex(theWhat);
2966 theModifiedList.Append(aWhatIndex);
2970 // try to find in history
2971 TDF_Label aHistoryLabel = theWhereFunction->GetHistoryEntry(Standard_False);
2973 // search in history for all argument shapes
2974 Standard_Boolean isFound = Standard_False;
2975 Standard_Boolean isGood = Standard_False;
2977 TDF_LabelSequence aLabelSeq;
2978 theWhereFunction->GetDependency(aLabelSeq);
2979 Standard_Integer nbArg = aLabelSeq.Length();
2981 for (Standard_Integer iarg = 1; iarg <= nbArg && !isFound; iarg++) {
2983 TDF_Label anArgumentRefLabel = aLabelSeq.Value(iarg);
2985 Handle(GEOM_Object) anArgumentObject = GEOM_Object::GetReferencedObject(anArgumentRefLabel);
2986 TopoDS_Shape anArgumentShape = anArgumentObject->GetValue();
2988 TopTools_IndexedMapOfShape anArgumentIndices;
2989 TopExp::MapShapes(anArgumentShape, anArgumentIndices);
2991 if (anArgumentIndices.Contains(theWhat)) {
2992 isFound = Standard_True;
2993 Standard_Integer aWhatIndex = anArgumentIndices.FindIndex(theWhat);
2995 // Find corresponding label in history
2996 TDF_Label anArgumentHistoryLabel =
2997 theWhereFunction->GetArgumentHistoryEntry(anArgumentRefLabel, Standard_False);
2998 if (anArgumentHistoryLabel.IsNull()) {
2999 // Lost History of operation argument. Possibly, all its entities was removed.
3000 isGood = Standard_True;
3003 TDF_Label aWhatHistoryLabel = anArgumentHistoryLabel.FindChild(aWhatIndex, Standard_False);
3005 if (aWhatHistoryLabel.IsNull()) {
3006 // Removed entity ? Compound ? Compsolid ? Shell ? Wire
3007 isGood = Standard_False;
3009 Handle(TDataStd_IntegerArray) anIntegerArray;
3010 if (!aWhatHistoryLabel.FindAttribute(TDataStd_IntegerArray::GetID(), anIntegerArray)) {
3011 //Error: Empty modifications history for the sought shape.
3012 isGood = Standard_False;
3015 isGood = Standard_True;
3016 Standard_Integer imod, aModifLen = anIntegerArray->Array()->Length();
3017 for (imod = 1; imod <= aModifLen; imod++) {
3018 theModifiedList.Append(anIntegerArray->Array()->Value(imod));
3029 // try compound/compsolid/shell/wire element by element
3030 bool isFoundAny = false;
3031 TopTools_MapOfShape mapShape;
3033 if (theWhat.ShapeType() == TopAbs_COMPOUND ||
3034 theWhat.ShapeType() == TopAbs_COMPSOLID) {
3035 // recursive processing of compound/compsolid
3036 TopoDS_Iterator anIt (theWhat, Standard_True, Standard_True);
3037 for (; anIt.More(); anIt.Next()) {
3038 if (mapShape.Add(anIt.Value())) {
3039 TopoDS_Shape curWhat = anIt.Value();
3040 isFoundAny = GetInPlaceOfShape(theWhereFunction, theWhereIndices, curWhat, theModifiedList);
3041 if (isFoundAny) isFound = Standard_True;
3045 else if (theWhat.ShapeType() == TopAbs_SHELL) {
3046 // try to replace a shell by its faces images
3047 TopExp_Explorer anExp (theWhat, TopAbs_FACE);
3048 for (; anExp.More(); anExp.Next()) {
3049 if (mapShape.Add(anExp.Current())) {
3050 TopoDS_Shape curWhat = anExp.Current();
3051 isFoundAny = GetInPlaceOfShape(theWhereFunction, theWhereIndices, curWhat, theModifiedList);
3052 if (isFoundAny) isFound = Standard_True;
3056 else if (theWhat.ShapeType() == TopAbs_WIRE) {
3057 // try to replace a wire by its edges images
3058 TopExp_Explorer anExp (theWhat, TopAbs_EDGE);
3059 for (; anExp.More(); anExp.Next()) {
3060 if (mapShape.Add(anExp.Current())) {
3061 TopoDS_Shape curWhat = anExp.Current();
3062 isFoundAny = GetInPlaceOfShape(theWhereFunction, theWhereIndices, curWhat, theModifiedList);
3063 if (isFoundAny) isFound = Standard_True;
3075 //=============================================================================
3077 * GetShapeProperties
3079 //=============================================================================
3080 void GEOMImpl_IShapesOperations::GetShapeProperties( const TopoDS_Shape aShape, Standard_Real tab[],
3083 GProp_GProps theProps;
3085 //TopoDS_Shape aPntShape;
3086 Standard_Real aShapeSize;
3088 if (aShape.ShapeType() == TopAbs_VERTEX) aCenterMass = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
3089 else if (aShape.ShapeType() == TopAbs_EDGE) BRepGProp::LinearProperties(aShape, theProps);
3090 else if (aShape.ShapeType() == TopAbs_FACE) BRepGProp::SurfaceProperties(aShape, theProps);
3091 else BRepGProp::VolumeProperties(aShape, theProps);
3093 if (aShape.ShapeType() == TopAbs_VERTEX)
3096 aCenterMass = theProps.CentreOfMass();
3097 aShapeSize = theProps.Mass();
3100 // aPntShape = BRepBuilderAPI_MakeVertex(aCenterMass).Shape();
3101 // aVertex = BRep_Tool::Pnt( TopoDS::Vertex( aPntShape ) );
3102 aVertex = aCenterMass;
3103 tab[0] = aVertex.X();
3104 tab[1] = aVertex.Y();
3105 tab[2] = aVertex.Z();
3106 tab[3] = aShapeSize;
3112 //================================================================================
3114 * \brief Return normal to face at extrema point
3116 //================================================================================
3118 gp_Vec GetNormal(const TopoDS_Face& face, const BRepExtrema_DistShapeShape& extrema)
3120 gp_Vec defaultNorm(1,0,0); // to have same normals on different faces
3122 // get UV at extrema point
3123 Standard_Real u,v, f,l;
3124 switch ( extrema.SupportTypeShape2(1) ) {
3125 case BRepExtrema_IsInFace: {
3126 extrema.ParOnFaceS2(1, u, v );
3129 case BRepExtrema_IsOnEdge: {
3130 TopoDS_Edge edge = TopoDS::Edge( extrema.SupportOnShape2(1));
3131 Handle(Geom2d_Curve) pcurve = BRep_Tool::CurveOnSurface( edge, face, f,l );
3132 extrema.ParOnEdgeS2( 1, u );
3133 gp_Pnt2d uv = pcurve->Value( u );
3138 case BRepExtrema_IsVertex: return defaultNorm;
3141 BRepAdaptor_Surface surface( face, false );
3142 gp_Vec du, dv; gp_Pnt p;
3143 surface.D1( u, v, p, du, dv );
3147 } catch (Standard_Failure ) {
3153 //=============================================================================
3158 //=============================================================================
3159 Handle(GEOM_Object) GEOMImpl_IShapesOperations::GetInPlace (Handle(GEOM_Object) theShapeWhere,
3160 Handle(GEOM_Object) theShapeWhat)
3164 if (theShapeWhere.IsNull() || theShapeWhat.IsNull()) return NULL;
3166 TopoDS_Shape aWhere = theShapeWhere->GetValue();
3167 TopoDS_Shape aWhat = theShapeWhat->GetValue();
3168 TopoDS_Shape aPntShape;
3169 TopoDS_Vertex aVertex;
3171 if (aWhere.IsNull() || aWhat.IsNull()) {
3172 SetErrorCode("Error: aWhere and aWhat TopoDS_Shape are Null.");
3176 Handle(GEOM_Function) aWhereFunction = theShapeWhere->GetLastFunction();
3177 if (aWhereFunction.IsNull()) {
3178 SetErrorCode("Error: aWhereFunction is Null.");
3182 TopTools_IndexedMapOfShape aWhereIndices;
3183 TopExp::MapShapes(aWhere, aWhereIndices);
3185 TColStd_ListOfInteger aModifiedList;
3186 Standard_Integer aWhereIndex;
3187 Handle(TColStd_HArray1OfInteger) aModifiedArray;
3188 Handle(GEOM_Object) aResult;
3190 bool isFound = false;
3191 Standard_Integer iType = TopAbs_SOLID;
3192 Standard_Integer compType = TopAbs_SOLID;
3193 Standard_Real aWhat_Mass = 0., aWhere_Mass = 0.;
3194 Standard_Real tab_aWhat[4], tab_aWhere[4];
3195 Standard_Real dl_l = 1e-3;
3196 Standard_Real min_l, Tol_0D, Tol_1D, Tol_2D, Tol_3D, Tol_Mass;
3197 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
3198 Bnd_Box BoundingBox;
3199 gp_Pnt aPnt, aPnt_aWhat, tab_Pnt[2];
3200 GProp_GProps aProps;
3202 // Find the iType of the aWhat shape
3203 if ( aWhat.ShapeType() == TopAbs_VERTEX ) iType = TopAbs_VERTEX;
3204 else if ( aWhat.ShapeType() == TopAbs_EDGE || aWhat.ShapeType() == TopAbs_WIRE ) iType = TopAbs_EDGE;
3205 else if ( aWhat.ShapeType() == TopAbs_FACE || aWhat.ShapeType() == TopAbs_SHELL ) iType = TopAbs_FACE;
3206 else if ( aWhat.ShapeType() == TopAbs_SOLID || aWhat.ShapeType() == TopAbs_COMPSOLID ) iType = TopAbs_SOLID;
3207 else if ( aWhat.ShapeType() == TopAbs_COMPOUND ) {
3208 // Only the iType of the first shape in the compound is taken into account
3209 TopoDS_Iterator It (aWhat, Standard_False, Standard_False);
3211 SetErrorCode("Error: theShapeWhat is an empty COMPOUND.");
3214 compType = It.Value().ShapeType();
3215 if ( compType == TopAbs_VERTEX ) iType = TopAbs_VERTEX;
3216 else if ( compType == TopAbs_EDGE || compType == TopAbs_WIRE ) iType = TopAbs_EDGE;
3217 else if ( compType == TopAbs_FACE || compType == TopAbs_SHELL) iType = TopAbs_FACE;
3218 else if ( compType == TopAbs_SOLID || compType == TopAbs_COMPSOLID) iType = TopAbs_SOLID;
3221 SetErrorCode("Error: An attempt to extract a shape of not supported type.");
3225 TopExp_Explorer Exp_aWhat( aWhat, TopAbs_ShapeEnum( iType ) );
3226 TopExp_Explorer Exp_aWhere( aWhere, TopAbs_ShapeEnum( iType ) );
3227 TopExp_Explorer Exp_Edge( aWhere, TopAbs_EDGE );
3229 // Find the shortest edge in theShapeWhere shape
3230 BRepBndLib::Add(aWhere, BoundingBox);
3231 BoundingBox.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
3232 min_l = fabs(aXmax - aXmin);
3233 if( min_l < fabs(aYmax - aYmin) ) min_l = fabs(aYmax - aYmin);
3234 if( min_l < fabs(aZmax - aZmin) ) min_l = fabs(aZmax - aZmin);
3236 // Mantis issue 0020908 BEGIN
3237 if (!Exp_Edge.More()) {
3238 min_l = Precision::Confusion();
3240 // Mantis issue 0020908 END
3241 for ( Standard_Integer nbEdge = 0; Exp_Edge.More(); Exp_Edge.Next(), nbEdge++ ) {
3242 TopExp_Explorer Exp_Vertex( Exp_Edge.Current(), TopAbs_VERTEX);
3243 for ( Standard_Integer nbVertex = 0; Exp_Vertex.More(); Exp_Vertex.Next(), nbVertex++ ) {
3244 aPnt = BRep_Tool::Pnt( TopoDS::Vertex( Exp_Vertex.Current() ) );
3245 tab_Pnt[nbVertex] = aPnt;
3247 if ( ! tab_Pnt[0].IsEqual(tab_Pnt[1], dl_l) ) {
3248 BRepGProp::LinearProperties(Exp_Edge.Current(), aProps);
3249 if ( aProps.Mass() < min_l ) min_l = aProps.Mass();
3253 // Compute tolerances
3255 Tol_1D = dl_l * min_l;
3256 Tol_2D = dl_l * ( min_l * min_l) * ( 2. + dl_l);
3257 Tol_3D = dl_l * ( min_l * min_l * min_l ) * ( 3. + (3 * dl_l) + (dl_l * dl_l) );
3259 if (Tol_0D < Precision::Confusion()) Tol_0D = Precision::Confusion();
3260 if (Tol_1D < Precision::Confusion()) Tol_1D = Precision::Confusion();
3261 if (Tol_2D < Precision::Confusion()) Tol_2D = Precision::Confusion();
3262 if (Tol_3D < Precision::Confusion()) Tol_3D = Precision::Confusion();
3264 //if (Tol_1D > 1.0) Tol_1D = 1.0;
3265 //if (Tol_2D > 1.0) Tol_2D = 1.0;
3266 //if (Tol_3D > 1.0) Tol_3D = 1.0;
3269 if ( iType == TopAbs_VERTEX ) Tol_Mass = Tol_0D;
3270 else if ( iType == TopAbs_EDGE ) Tol_Mass = Tol_1D;
3271 else if ( iType == TopAbs_FACE ) Tol_Mass = Tol_2D;
3273 // Compute the ShapeWhat Mass
3274 for ( ; Exp_aWhat.More(); Exp_aWhat.Next() ) {
3275 if ( iType == TopAbs_VERTEX ) {
3279 else if ( iType == TopAbs_EDGE ) BRepGProp::LinearProperties(Exp_aWhat.Current(), aProps);
3280 else if ( iType == TopAbs_FACE ) BRepGProp::SurfaceProperties(Exp_aWhat.Current(), aProps);
3281 else BRepGProp::VolumeProperties(Exp_aWhat.Current(), aProps);
3282 aWhat_Mass += aProps.Mass();
3285 // Searching for the sub-shapes inside the ShapeWhere shape
3286 TopTools_MapOfShape map_aWhere;
3287 for ( Exp_aWhere.ReInit(); Exp_aWhere.More(); Exp_aWhere.Next() ) {
3288 if (!map_aWhere.Add(Exp_aWhere.Current()))
3289 continue; // skip repeated shape to avoid mass addition
3290 GetShapeProperties( Exp_aWhere.Current(), tab_aWhere, aPnt );
3291 for ( Exp_aWhat.ReInit(); Exp_aWhat.More(); Exp_aWhat.Next() ) {
3292 GetShapeProperties( Exp_aWhat.Current(), tab_aWhat, aPnt_aWhat );
3293 if ( fabs(tab_aWhat[3] - tab_aWhere[3]) <= Tol_Mass && aPnt_aWhat.Distance(aPnt) <= Tol_1D )
3296 if ( (tab_aWhat[3] - tab_aWhere[3]) > Tol_Mass ) {
3297 aPntShape = BRepBuilderAPI_MakeVertex( aPnt ).Shape();
3298 aVertex = TopoDS::Vertex( aPntShape );
3299 BRepExtrema_DistShapeShape aWhereDistance ( aVertex, Exp_aWhere.Current() );
3300 BRepExtrema_DistShapeShape aWhatDistance ( aVertex, Exp_aWhat.Current() );
3301 if ( aWhereDistance.IsDone() && aWhatDistance.IsDone() &&
3302 fabs(aWhereDistance.Value() - aWhatDistance.Value()) <= Tol_1D )
3304 // 0020162: "EDF 961 GEOM : Getinplace is getting additionnal orthogonal faces"
3305 // aVertex must be projected to the same point on Where and on What
3306 gp_Pnt pOnWhat = aWhatDistance.PointOnShape2(1);
3307 gp_Pnt pOnWhere = aWhereDistance.PointOnShape2(1);
3308 isFound = ( pOnWhat.Distance(pOnWhere) <= Tol_1D );
3309 if ( isFound && iType == TopAbs_FACE )
3311 // check normals at pOnWhat and pOnWhere
3312 const double angleTol = PI/180.;
3313 gp_Vec normToWhat = GetNormal( TopoDS::Face(Exp_aWhat.Current()), aWhatDistance);
3314 gp_Vec normToWhere = GetNormal( TopoDS::Face(Exp_aWhere.Current()), aWhereDistance);
3315 if ( normToWhat * normToWhere < 0 )
3316 normToWhat.Reverse();
3317 isFound = ( normToWhat.Angle( normToWhere ) < angleTol );
3323 aWhereIndex = aWhereIndices.FindIndex(Exp_aWhere.Current());
3324 aModifiedList.Append(aWhereIndex);
3325 aWhere_Mass += tab_aWhere[3];
3330 if ( fabs( aWhat_Mass - aWhere_Mass ) <= Tol_Mass ) break;
3333 if (aModifiedList.Extent() == 0) { // Not found any Results
3334 SetErrorCode(NOT_FOUND_ANY);
3338 aModifiedArray = new TColStd_HArray1OfInteger (1, aModifiedList.Extent());
3339 TColStd_ListIteratorOfListOfInteger anIterModif (aModifiedList);
3340 for (Standard_Integer imod = 1; anIterModif.More(); anIterModif.Next(), imod++)
3341 aModifiedArray->SetValue(imod, anIterModif.Value());
3344 aResult = GetEngine()->AddSubShape(theShapeWhere, aModifiedArray);
3345 if (aResult.IsNull()) {
3346 SetErrorCode("Error in algorithm: result found, but cannot be returned.");
3350 if (aModifiedArray->Length() > 1) {
3352 aResult->SetType(GEOM_GROUP);
3354 //Set a sub shape type
3355 TopoDS_Shape aFirstFound = aWhereIndices.FindKey(aModifiedArray->Value(1));
3356 TopAbs_ShapeEnum aShapeType = aFirstFound.ShapeType();
3358 TDF_Label aFreeLabel = aResult->GetFreeLabel();
3359 TDataStd_Integer::Set(aFreeLabel, (Standard_Integer)aShapeType);
3362 //Make a Python command
3363 Handle(GEOM_Function) aFunction = aResult->GetFunction(1);
3365 GEOM::TPythonDump(aFunction) << aResult << " = geompy.GetInPlace("
3366 << theShapeWhere << ", " << theShapeWhat << ")";
3372 //=======================================================================
3373 //function : GetInPlaceByHistory
3375 //=======================================================================
3376 Handle(GEOM_Object) GEOMImpl_IShapesOperations::GetInPlaceByHistory
3377 (Handle(GEOM_Object) theShapeWhere,
3378 Handle(GEOM_Object) theShapeWhat)
3382 if (theShapeWhere.IsNull() || theShapeWhat.IsNull()) return NULL;
3384 TopoDS_Shape aWhere = theShapeWhere->GetValue();
3385 TopoDS_Shape aWhat = theShapeWhat->GetValue();
3387 if (aWhere.IsNull() || aWhat.IsNull()) return NULL;
3389 Handle(GEOM_Function) aWhereFunction = theShapeWhere->GetLastFunction();
3390 if (aWhereFunction.IsNull()) return NULL;
3392 //Fill array of indices
3393 TopTools_IndexedMapOfShape aWhereIndices;
3394 TopExp::MapShapes(aWhere, aWhereIndices);
3397 TColStd_ListOfInteger aModifiedList;
3398 bool isFound = GetInPlaceOfShape(aWhereFunction, aWhereIndices, aWhat, aModifiedList);
3400 if (!isFound || aModifiedList.Extent() < 1) {
3401 SetErrorCode("Error: No history found for the sought shape or its sub-shapes.");
3405 Handle(TColStd_HArray1OfInteger) aModifiedArray =
3406 new TColStd_HArray1OfInteger (1, aModifiedList.Extent());
3407 TColStd_ListIteratorOfListOfInteger anIterModif (aModifiedList);
3408 for (Standard_Integer imod = 1; anIterModif.More(); anIterModif.Next(), imod++) {
3409 aModifiedArray->SetValue(imod, anIterModif.Value());
3413 Handle(GEOM_Object) aResult = GetEngine()->AddSubShape(theShapeWhere, aModifiedArray);
3414 if (aResult.IsNull()) {
3415 SetErrorCode("Error in algorithm: result found, but cannot be returned.");
3419 if (aModifiedArray->Length() > 1) {
3421 aResult->SetType(GEOM_GROUP);
3423 //Set a sub shape type
3424 TopoDS_Shape aFirstFound = aWhereIndices.FindKey(aModifiedArray->Value(1));
3425 TopAbs_ShapeEnum aShapeType = aFirstFound.ShapeType();
3427 TDF_Label aFreeLabel = aResult->GetFreeLabel();
3428 TDataStd_Integer::Set(aFreeLabel, (Standard_Integer)aShapeType);
3431 //Make a Python command
3432 Handle(GEOM_Function) aFunction = aResult->GetFunction(1);
3434 GEOM::TPythonDump(aFunction) << aResult << " = geompy.GetInPlaceByHistory("
3435 << theShapeWhere << ", " << theShapeWhat << ")";
3441 //=======================================================================
3442 //function : SortShapes
3444 //=======================================================================
3445 void GEOMImpl_IShapesOperations::SortShapes(TopTools_ListOfShape& SL)
3447 Standard_Integer MaxShapes = SL.Extent();
3448 TopTools_Array1OfShape aShapes (1,MaxShapes);
3449 TColStd_Array1OfInteger OrderInd(1,MaxShapes);
3450 TColStd_Array1OfReal MidXYZ (1,MaxShapes); //X,Y,Z;
3451 TColStd_Array1OfReal Length (1,MaxShapes); //X,Y,Z;
3453 // Computing of CentreOfMass
3454 Standard_Integer Index;
3457 TopTools_ListIteratorOfListOfShape it(SL);
3458 for (Index=1; it.More(); Index++)
3460 TopoDS_Shape S = it.Value();
3461 SL.Remove( it ); // == it.Next()
3463 OrderInd.SetValue (Index, Index);
3464 if (S.ShapeType() == TopAbs_VERTEX)
3466 GPoint = BRep_Tool::Pnt( TopoDS::Vertex( S ));
3467 Length.SetValue( Index, (Standard_Real) S.Orientation());
3471 BRepGProp::LinearProperties (S, GPr);
3472 GPoint = GPr.CentreOfMass();
3473 Length.SetValue( Index, GPr.Mass() );
3475 MidXYZ.SetValue(Index,
3476 GPoint.X()*999 + GPoint.Y()*99 + GPoint.Z()*0.9);
3477 //cout << Index << " L: " << Length(Index) << "CG: " << MidXYZ(Index) << endl;
3481 Standard_Integer aTemp;
3482 Standard_Boolean exchange, Sort = Standard_True;
3483 Standard_Real tol = Precision::Confusion();
3486 Sort = Standard_False;
3487 for (Index=1; Index < MaxShapes; Index++)
3489 exchange = Standard_False;
3490 Standard_Real dMidXYZ = MidXYZ(OrderInd(Index)) - MidXYZ(OrderInd(Index+1));
3491 Standard_Real dLength = Length(OrderInd(Index)) - Length(OrderInd(Index+1));
3492 if ( dMidXYZ >= tol ) {
3493 // cout << "MidXYZ: " << MidXYZ(OrderInd(Index))<< " > " <<MidXYZ(OrderInd(Index+1))
3494 // << " d: " << dMidXYZ << endl;
3495 exchange = Standard_True;
3497 else if ( Abs(dMidXYZ) < tol && dLength >= tol ) {
3498 // cout << "Length: " << Length(OrderInd(Index))<< " > " <<Length(OrderInd(Index+1))
3499 // << " d: " << dLength << endl;
3500 exchange = Standard_True;
3502 else if ( Abs(dMidXYZ) < tol && Abs(dLength) < tol &&
3503 aShapes(OrderInd(Index)).ShapeType() <= TopAbs_FACE) {
3505 // equal values possible on shapes such as two halves of a sphere and
3506 // a membrane inside the sphere
3508 BRepBndLib::Add( aShapes( OrderInd(Index) ), box1 );
3509 if ( box1.IsVoid() ) continue;
3510 BRepBndLib::Add( aShapes( OrderInd(Index+1) ), box2 );
3511 Standard_Real dSquareExtent = box1.SquareExtent() - box2.SquareExtent();
3512 if ( dSquareExtent >= tol ) {
3513 // cout << "SquareExtent: " << box1.SquareExtent()<<" > "<<box2.SquareExtent() << endl;
3514 exchange = Standard_True;
3516 else if ( Abs(dSquareExtent) < tol ) {
3517 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax, val1, val2;
3518 box1.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
3519 val1 = (aXmin+aXmax)*999 + (aYmin+aYmax)*99 + (aZmin+aZmax)*0.9;
3520 box2.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
3521 val2 = (aXmin+aXmax)*999 + (aYmin+aYmax)*99 + (aZmin+aZmax)*0.9;
3522 //exchange = val1 > val2;
3523 if ((val1 - val2) >= tol) {
3524 exchange = Standard_True;
3526 //cout << "box: " << val1<<" > "<<val2 << endl;
3532 // cout << "exchange " << Index << " & " << Index+1 << endl;
3533 aTemp = OrderInd(Index);
3534 OrderInd(Index) = OrderInd(Index+1);
3535 OrderInd(Index+1) = aTemp;
3536 Sort = Standard_True;
3541 for (Index=1; Index <= MaxShapes; Index++)
3542 SL.Append( aShapes( OrderInd(Index) ));
3545 //=======================================================================
3546 //function : CompsolidToCompound
3548 //=======================================================================
3549 TopoDS_Shape GEOMImpl_IShapesOperations::CompsolidToCompound (const TopoDS_Shape& theCompsolid)
3551 if (theCompsolid.ShapeType() != TopAbs_COMPSOLID) {
3552 return theCompsolid;
3555 TopoDS_Compound aCompound;
3557 B.MakeCompound(aCompound);
3559 TopTools_MapOfShape mapShape;
3560 TopoDS_Iterator It (theCompsolid, Standard_True, Standard_True);
3562 for (; It.More(); It.Next()) {
3563 TopoDS_Shape aShape_i = It.Value();
3564 if (mapShape.Add(aShape_i)) {
3565 B.Add(aCompound, aShape_i);
3572 //=======================================================================
3573 //function : CheckTriangulation
3575 //=======================================================================
3576 bool GEOMImpl_IShapesOperations::CheckTriangulation (const TopoDS_Shape& aShape)
3578 bool isTriangulation = true;
3580 TopExp_Explorer exp (aShape, TopAbs_FACE);
3583 TopLoc_Location aTopLoc;
3584 Handle(Poly_Triangulation) aTRF;
3585 aTRF = BRep_Tool::Triangulation(TopoDS::Face(exp.Current()), aTopLoc);
3586 if (aTRF.IsNull()) {
3587 isTriangulation = false;
3590 else // no faces, try edges
3592 TopExp_Explorer expe (aShape, TopAbs_EDGE);
3596 TopLoc_Location aLoc;
3597 Handle(Poly_Polygon3D) aPE = BRep_Tool::Polygon3D(TopoDS::Edge(expe.Current()), aLoc);
3599 isTriangulation = false;
3603 if (!isTriangulation) {
3604 // calculate deflection
3605 Standard_Real aDeviationCoefficient = 0.001;
3608 BRepBndLib::Add(aShape, B);
3609 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
3610 B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
3612 Standard_Real dx = aXmax - aXmin, dy = aYmax - aYmin, dz = aZmax - aZmin;
3613 Standard_Real aDeflection = Max(Max(dx, dy), dz) * aDeviationCoefficient * 4;
3614 Standard_Real aHLRAngle = 0.349066;
3616 BRepMesh_IncrementalMesh Inc (aShape, aDeflection, Standard_False, aHLRAngle);
3622 #define MAX_TOLERANCE 1.e-7
3624 //=======================================================================
3625 //function : isSameEdge
3626 //purpose : Returns True if two edges coincide
3627 //=======================================================================
3628 static bool isSameEdge(const TopoDS_Edge& theEdge1, const TopoDS_Edge& theEdge2)
3630 TopoDS_Vertex V11, V12, V21, V22;
3631 TopExp::Vertices(theEdge1, V11, V12);
3632 TopExp::Vertices(theEdge2, V21, V22);
3633 gp_Pnt P11 = BRep_Tool::Pnt(V11);
3634 gp_Pnt P12 = BRep_Tool::Pnt(V12);
3635 gp_Pnt P21 = BRep_Tool::Pnt(V21);
3636 gp_Pnt P22 = BRep_Tool::Pnt(V22);
3637 bool coincide = false;
3639 //Check that ends of edges coincide
3640 if(P11.Distance(P21) <= MAX_TOLERANCE) {
3641 if(P12.Distance(P22) <= MAX_TOLERANCE) coincide = true;
3643 else if(P11.Distance(P22) <= MAX_TOLERANCE) {
3644 if(P12.Distance(P21) <= MAX_TOLERANCE) coincide = true;
3647 if(!coincide) return false;
3649 if (BRep_Tool::Degenerated(theEdge1))
3650 if (BRep_Tool::Degenerated(theEdge2)) return true;
3653 if (BRep_Tool::Degenerated(theEdge2)) return false;
3655 double U11, U12, U21, U22;
3656 Handle(Geom_Curve) C1 = BRep_Tool::Curve(theEdge1, U11, U12);
3657 Handle(Geom_Curve) C2 = BRep_Tool::Curve(theEdge2, U21, U22);
3658 if(C1->DynamicType() == C2->DynamicType()) return true;
3660 //Check that both edges has the same geometry
3661 double range = U12-U11;
3662 double U = U11+ range/3.0;
3663 gp_Pnt P1 = C1->Value(U); //Compute a point on one third of the edge's length
3664 U = U11+range*2.0/3.0;
3665 gp_Pnt P2 = C1->Value(U); //Compute a point on two thirds of the edge's length
3667 if(!GeomLib_Tool::Parameter(C2, P1, MAX_TOLERANCE, U) || U < U21 || U > U22)
3670 if(P1.Distance(C2->Value(U)) > MAX_TOLERANCE) return false;
3672 if(!GeomLib_Tool::Parameter(C2, P2, MAX_TOLERANCE, U) || U < U21 || U > U22)
3675 if(P2.Distance(C2->Value(U)) > MAX_TOLERANCE) return false;
3680 #include <TopoDS_TShape.hxx>
3681 //=======================================================================
3682 //function : isSameFace
3683 //purpose : Returns True if two faces coincide
3684 //=======================================================================
3685 static bool isSameFace(const TopoDS_Face& theFace1, const TopoDS_Face& theFace2)
3687 TopExp_Explorer E(theFace1, TopAbs_EDGE);
3688 TopTools_ListOfShape LS1, LS2;
3689 for(; E.More(); E.Next()) LS1.Append(E.Current());
3691 E.Init(theFace2, TopAbs_EDGE);
3692 for(; E.More(); E.Next()) LS2.Append(E.Current());
3694 //Compare the number of edges in the faces
3695 if(LS1.Extent() != LS2.Extent()) return false;
3697 double aMin = RealFirst(), aMax = RealLast();
3698 double xminB1=aMax, yminB1=aMax, zminB1=aMax, xminB2=aMax, yminB2=aMax, zminB2=aMax;
3699 double xmaxB1=aMin, ymaxB1=aMin, zmaxB1=aMin, xmaxB2=aMin, ymaxB2=aMin, zmaxB2=aMin;
3701 for(E.Init(theFace1, TopAbs_VERTEX); E.More(); E.Next()) {
3702 gp_Pnt P = BRep_Tool::Pnt(TopoDS::Vertex(E.Current()));
3703 if(P.X() < xminB1) xminB1 = P.X();
3704 if(P.Y() < yminB1) yminB1 = P.Y();
3705 if(P.Z() < zminB1) zminB1 = P.Z();
3706 if(P.X() > xmaxB1) xmaxB1 = P.X();
3707 if(P.Y() > ymaxB1) ymaxB1 = P.Y();
3708 if(P.Z() > zmaxB1) zmaxB1 = P.Z();
3711 for(E.Init(theFace2, TopAbs_VERTEX); E.More(); E.Next()) {
3712 gp_Pnt P = BRep_Tool::Pnt(TopoDS::Vertex(E.Current()));
3713 if(P.X() < xminB2) xminB2 = P.X();
3714 if(P.Y() < yminB2) yminB2 = P.Y();
3715 if(P.Z() < zminB2) zminB2 = P.Z();
3716 if(P.X() > xmaxB2) xmaxB2 = P.X();
3717 if(P.Y() > ymaxB2) ymaxB2 = P.Y();
3718 if(P.Z() > zmaxB2) zmaxB2 = P.Z();
3721 //Compare the bounding boxes of both faces
3722 if(gp_Pnt(xminB1, yminB1, zminB1).Distance(gp_Pnt(xminB2, yminB2, zminB2)) > MAX_TOLERANCE)
3725 if(gp_Pnt(xmaxB1, ymaxB1, zmaxB1).Distance(gp_Pnt(xmaxB2, ymaxB2, zmaxB2)) > MAX_TOLERANCE)
3728 Handle(Geom_Surface) S1 = BRep_Tool::Surface(theFace1);
3729 Handle(Geom_Surface) S2 = BRep_Tool::Surface(theFace2);
3731 //Check if there a coincidence of two surfaces at least in two points
3732 double U11, U12, V11, V12, U21, U22, V21, V22;
3733 BRepTools::UVBounds(theFace1, U11, U12, V11, V12);
3734 BRepTools::UVBounds(theFace2, U21, U22, V21, V22);
3736 double rangeU = U12-U11;
3737 double rangeV = V12-V11;
3738 double U = U11 + rangeU/3.0;
3739 double V = V11 + rangeV/3.0;
3740 gp_Pnt P1 = S1->Value(U, V);
3741 U = U11+rangeU*2.0/3.0;
3742 V = V11+rangeV*2.0/3.0;
3743 gp_Pnt P2 = S1->Value(U, V);
3745 if (!GeomLib_Tool::Parameters(S2, P1, MAX_TOLERANCE, U, V) || U < U21 || U > U22 || V < V21 || V > V22)
3748 if (P1.Distance(S2->Value(U,V)) > MAX_TOLERANCE) return false;
3750 if (!GeomLib_Tool::Parameters(S2, P2, MAX_TOLERANCE, U, V) || U < U21 || U > U22 || V < V21 || V > V22)
3753 if (P2.Distance(S2->Value(U, V)) > MAX_TOLERANCE) return false;
3755 //Check that each edge of the Face1 has a counterpart in the Face2
3756 TopTools_MapOfOrientedShape aMap;
3757 TopTools_ListIteratorOfListOfShape LSI1(LS1);
3758 for(; LSI1.More(); LSI1.Next()) {
3759 TopoDS_Edge E = TopoDS::Edge(LSI1.Value());
3760 bool isFound = false;
3761 TopTools_ListIteratorOfListOfShape LSI2(LS2);
3762 for(; LSI2.More(); LSI2.Next()) {
3763 TopoDS_Shape aValue = LSI2.Value();
3764 if(aMap.Contains(aValue)) continue; //To avoid checking already found edge several times
3765 if(isSameEdge(E, TopoDS::Edge(aValue))) {
3771 if(!isFound) return false;
3777 //=======================================================================
3778 //function : isSameSolid
3779 //purpose : Returns True if two solids coincide
3780 //=======================================================================
3781 bool isSameSolid(const TopoDS_Solid& theSolid1, const TopoDS_Solid& theSolid2)
3783 TopExp_Explorer E(theSolid1, TopAbs_FACE);
3784 TopTools_ListOfShape LS1, LS2;
3785 for(; E.More(); E.Next()) LS1.Append(E.Current());
3786 E.Init(theSolid2, TopAbs_FACE);
3787 for(; E.More(); E.Next()) LS2.Append(E.Current());
3789 if(LS1.Extent() != LS2.Extent()) return false;
3791 double aMin = RealFirst(), aMax = RealLast();
3792 double xminB1=aMax, yminB1=aMax, zminB1=aMax, xminB2=aMax, yminB2=aMax, zminB2=aMax;
3793 double xmaxB1=aMin, ymaxB1=aMin, zmaxB1=aMin, xmaxB2=aMin, ymaxB2=aMin, zmaxB2=aMin;
3795 for(E.Init(theSolid1, TopAbs_VERTEX); E.More(); E.Next()) {
3796 gp_Pnt P = BRep_Tool::Pnt(TopoDS::Vertex(E.Current()));
3797 if(P.X() < xminB1) xminB1 = P.X();
3798 if(P.Y() < yminB1) yminB1 = P.Y();
3799 if(P.Z() < zminB1) zminB1 = P.Z();
3800 if(P.X() > xmaxB1) xmaxB1 = P.X();
3801 if(P.Y() > ymaxB1) ymaxB1 = P.Y();
3802 if(P.Z() > zmaxB1) zmaxB1 = P.Z();
3805 for(E.Init(theSolid2, TopAbs_VERTEX); E.More(); E.Next()) {
3806 gp_Pnt P = BRep_Tool::Pnt(TopoDS::Vertex(E.Current()));
3807 if(P.X() < xminB2) xminB2 = P.X();
3808 if(P.Y() < yminB2) yminB2 = P.Y();
3809 if(P.Z() < zminB2) zminB2 = P.Z();
3810 if(P.X() > xmaxB2) xmaxB2 = P.X();
3811 if(P.Y() > ymaxB2) ymaxB2 = P.Y();
3812 if(P.Z() > zmaxB2) zmaxB2 = P.Z();
3815 //Compare the bounding boxes of both solids
3816 if(gp_Pnt(xminB1, yminB1, zminB1).Distance(gp_Pnt(xminB2, yminB2, zminB2)) > MAX_TOLERANCE)
3819 if(gp_Pnt(xmaxB1, ymaxB1, zmaxB1).Distance(gp_Pnt(xmaxB2, ymaxB2, zmaxB2)) > MAX_TOLERANCE)
3822 //Check that each face of the Solid1 has a counterpart in the Solid2
3823 TopTools_MapOfOrientedShape aMap;
3824 TopTools_ListIteratorOfListOfShape LSI1(LS1);
3825 for(; LSI1.More(); LSI1.Next()) {
3826 TopoDS_Face F = TopoDS::Face(LSI1.Value());
3827 bool isFound = false;
3828 TopTools_ListIteratorOfListOfShape LSI2(LS2);
3829 for(; LSI2.More(); LSI2.Next()) {
3830 if(aMap.Contains(LSI2.Value())) continue; //To avoid checking already found faces several times
3831 if(isSameFace(F, TopoDS::Face(LSI2.Value()))) {
3832 aMap.Add(LSI2.Value());
3837 if(!isFound) return false;
3843 //=======================================================================
3844 //function : GetSame
3846 //=======================================================================
3847 Handle(GEOM_Object) GEOMImpl_IShapesOperations::GetSame(const Handle(GEOM_Object)& theShapeWhere,
3848 const Handle(GEOM_Object)& theShapeWhat)
3851 if (theShapeWhere.IsNull() || theShapeWhat.IsNull()) return NULL;
3853 TopoDS_Shape aWhere = theShapeWhere->GetValue();
3854 TopoDS_Shape aWhat = theShapeWhat->GetValue();
3856 if (aWhere.IsNull() || aWhat.IsNull()) return NULL;
3859 bool isFound = false;
3860 TopoDS_Shape aSubShape;
3861 TopTools_MapOfShape aMap;
3863 switch(aWhat.ShapeType()) {
3864 case TopAbs_VERTEX: {
3865 gp_Pnt P = BRep_Tool::Pnt(TopoDS::Vertex(aWhat));
3866 TopExp_Explorer E(aWhere, TopAbs_VERTEX);
3867 for(; E.More(); E.Next()) {
3868 if(!aMap.Add(E.Current())) continue;
3869 gp_Pnt P2 = BRep_Tool::Pnt(TopoDS::Vertex(E.Current()));
3870 if(P.Distance(P2) <= MAX_TOLERANCE) {
3872 aSubShape = E.Current();
3879 TopoDS_Face aFace = TopoDS::Face(aWhat);
3880 TopExp_Explorer E(aWhere, TopAbs_FACE);
3881 for(; E.More(); E.Next()) {
3882 if(!aMap.Add(E.Current())) continue;
3883 if(isSameFace(aFace, TopoDS::Face(E.Current()))) {
3884 aSubShape = E.Current();
3892 TopoDS_Edge anEdge = TopoDS::Edge(aWhat);
3893 TopExp_Explorer E(aWhere, TopAbs_EDGE);
3894 for(; E.More(); E.Next()) {
3895 if(!aMap.Add(E.Current())) continue;
3896 if(isSameEdge(anEdge, TopoDS::Edge(E.Current()))) {
3897 aSubShape = E.Current();
3904 case TopAbs_SOLID: {
3905 TopoDS_Solid aSolid = TopoDS::Solid(aWhat);
3906 TopExp_Explorer E(aWhere, TopAbs_SOLID);
3907 for(; E.More(); E.Next()) {
3908 if(!aMap.Add(E.Current())) continue;
3909 if(isSameSolid(aSolid, TopoDS::Solid(E.Current()))) {
3910 aSubShape = E.Current();
3922 TopTools_IndexedMapOfShape anIndices;
3923 TopExp::MapShapes(aWhere, anIndices);
3924 if (anIndices.Contains(aSubShape))
3925 anIndex = anIndices.FindIndex(aSubShape);
3928 if(anIndex < 0) return NULL;
3930 Handle(TColStd_HArray1OfInteger) anArray = new TColStd_HArray1OfInteger(1,1);
3932 anArray->SetValue(1, anIndex);
3934 Handle(GEOM_Object) aResult = GetEngine()->AddSubShape(theShapeWhere, anArray);
3935 Handle(GEOM_Function) aFunction = aResult->GetLastFunction();
3937 GEOM::TPythonDump(aFunction) << aResult << " = geompy.GetSame("
3938 << theShapeWhere << ", " << theShapeWhat << ")";