1 // Copyright (C) 2007-2012 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
23 // File: GEOMAlgo_Gluer.cxx
24 // Created: Sat Dec 04 12:45:53 2004
25 // Author: Peter KURNEV
28 #include <GEOMAlgo_Gluer.hxx>
30 #include <NMTDS_BoxBndTree.hxx>
31 #include <NCollection_UBTreeFiller.hxx>
33 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
34 #include <TColStd_MapOfInteger.hxx>
35 #include <TColStd_ListOfInteger.hxx>
36 #include <TColStd_ListIteratorOfListOfInteger.hxx>
42 #include <Geom_Curve.hxx>
43 #include <Geom_Surface.hxx>
45 #include <Bnd_Box.hxx>
46 #include <Bnd_HArray1OfBox.hxx>
47 #include <Bnd_BoundSortBox.hxx>
49 #include <TopLoc_Location.hxx>
50 #include <TopAbs_ShapeEnum.hxx>
51 #include <TopAbs_Orientation.hxx>
54 #include <TopoDS_Edge.hxx>
55 #include <TopoDS_Vertex.hxx>
56 #include <TopoDS_Shape.hxx>
57 #include <TopoDS_Compound.hxx>
58 #include <TopoDS_Wire.hxx>
59 #include <TopoDS_Shell.hxx>
60 #include <TopoDS_Solid.hxx>
61 #include <TopoDS_Iterator.hxx>
63 #include <TopTools_IndexedMapOfShape.hxx>
64 #include <TopTools_ListOfShape.hxx>
65 #include <TopTools_ListIteratorOfListOfShape.hxx>
66 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
67 #include <TopTools_MapOfShape.hxx>
68 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
71 #include <TopExp_Explorer.hxx>
73 #include <BRep_Tool.hxx>
74 #include <BRep_Builder.hxx>
75 #include <BRepLib.hxx>
76 #include <BRepTools.hxx>
77 #include <BRepBndLib.hxx>
79 #include <IntTools_Context.hxx>
80 #include <BOPTools_Tools.hxx>
81 #include <BOPTools_Tools3D.hxx>
82 #include <BOPTools_Tools2D.hxx>
83 #include <BOP_CorrectTolerances.hxx>
85 #include <GEOMAlgo_IndexedDataMapOfIntegerShape.hxx>
86 #include <GEOMAlgo_IndexedDataMapOfShapeBox.hxx>
87 #include <GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape.hxx>
88 #include <GEOMAlgo_PassKeyShape.hxx>
89 #include <GEOMAlgo_Tools.hxx>
92 #include <NMTDS_BndSphereTree.hxx>
93 #include <NMTDS_BndSphere.hxx>
94 #include <NMTDS_IndexedDataMapOfShapeBndSphere.hxx>
98 void GetSubShapes(const TopoDS_Shape& aS,
99 TopTools_IndexedMapOfShape& aMSS);
101 //=======================================================================
102 //function : GEOMAlgo_Gluer
104 //=======================================================================
105 GEOMAlgo_Gluer::GEOMAlgo_Gluer()
111 myCheckGeometry=Standard_True;
112 myKeepNonSolids=Standard_False;
115 //=======================================================================
116 //function : ~GEOMAlgo_Gluer
118 //=======================================================================
119 GEOMAlgo_Gluer::~GEOMAlgo_Gluer()
122 //=======================================================================
123 //function : SetCheckGeometry
125 //=======================================================================
126 void GEOMAlgo_Gluer::SetCheckGeometry(const Standard_Boolean aFlag)
128 myCheckGeometry=aFlag;
130 //=======================================================================
131 //function : CheckGeometry
133 //=======================================================================
134 Standard_Boolean GEOMAlgo_Gluer::CheckGeometry() const
136 return myCheckGeometry;
138 //=======================================================================
139 //function : SetKeepNonSolids
141 //=======================================================================
142 void GEOMAlgo_Gluer::SetKeepNonSolids(const Standard_Boolean aFlag)
144 myKeepNonSolids=aFlag;
146 //=======================================================================
147 //function : KeepNonSolids
149 //=======================================================================
150 Standard_Boolean GEOMAlgo_Gluer::KeepNonSolids()const
152 return myKeepNonSolids;
154 //=======================================================================
155 //function : AloneShapes
157 //=======================================================================
158 Standard_Integer GEOMAlgo_Gluer::AloneShapes()const
162 //=======================================================================
165 //=======================================================================
166 const TopTools_DataMapOfShapeListOfShape& GEOMAlgo_Gluer::Images()const
170 //=======================================================================
173 //=======================================================================
174 const TopTools_DataMapOfShapeShape& GEOMAlgo_Gluer::Origins()const
178 //=======================================================================
181 //=======================================================================
182 void GEOMAlgo_Gluer::Perform()
184 const Standard_Integer aNb=8;
190 // Initialize the context
191 GEOMAlgo_ShapeAlgo::Perform();
193 void (GEOMAlgo_Gluer::* pF[aNb])()={
194 &GEOMAlgo_Gluer::CheckData, &GEOMAlgo_Gluer::InnerTolerance,
195 &GEOMAlgo_Gluer::MakeVertices, &GEOMAlgo_Gluer::MakeEdges,
196 &GEOMAlgo_Gluer::MakeFaces, &GEOMAlgo_Gluer::MakeShells,
197 &GEOMAlgo_Gluer::MakeSolids, &GEOMAlgo_Gluer::CheckResult
200 for (i=0; i<aNb; ++i) {
208 //=======================================================================
209 //function : MakeVertices
211 //=======================================================================
212 void GEOMAlgo_Gluer::MakeVertices()
216 Standard_Integer j, i, aNbV, aNbVSD;
219 TColStd_ListIteratorOfListOfInteger aIt;
222 TopTools_IndexedMapOfShape aMV, aMVProcessed;
223 TopTools_ListIteratorOfListOfShape aItS;
224 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItIm;
225 TopTools_DataMapOfShapeListOfShape aMVV;
226 GEOMAlgo_IndexedDataMapOfIntegerShape aMIS;
227 //modified by NIZNHY-PKV Thu Jan 21 10:03:07 2010f
228 //GEOMAlgo_IndexedDataMapOfShapeBox aMSB;
229 NMTDS_IndexedDataMapOfShapeBndSphere aMSB;
230 //modified by NIZNHY-PKV Thu Jan 21 10:03:10 2010t
232 NMTDS_BndSphereTreeSelector aSelector;
233 NMTDS_BndSphereTree aBBTree;
234 NCollection_UBTreeFiller <Standard_Integer, NMTDS_BndSphere> aTreeFiller(aBBTree);
236 TopExp::MapShapes(myShape, TopAbs_VERTEX, aMV);
239 myErrorStatus=2; // no vertices in source shape
243 for (i=1; i<=aNbV; ++i) {
244 NMTDS_BndSphere aBox;
246 const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&aMV(i));
247 aPV=BRep_Tool::Pnt(aV);
248 aTolV=BRep_Tool::Tolerance(aV);
252 aBox.SetRadius(aTolV);
254 aTreeFiller.Add(i, aBox);
262 //------------------------------
264 for (i=1; i<=aNbV; ++i) {
265 const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&aMV(i));
267 if (aMVProcessed.Contains(aV)) {
271 Standard_Integer aNbIP, aIP, aNbIP1, aIP1;
272 TopTools_ListOfShape aLVSD;
273 TColStd_MapOfInteger aMIP, aMIP1, aMIPC;
274 TColStd_MapIteratorOfMapOfInteger aIt1;
279 aIt1.Initialize(aMIP);
280 for(; aIt1.More(); aIt1.Next()) {
282 if (aMIPC.Contains(aIP)) {
286 const TopoDS_Shape& aVP=aMIS.FindFromKey(aIP);
287 //modified by NIZNHY-PKV Thu Jan 21 10:04:09 2010f
288 const NMTDS_BndSphere& aBoxVP=aMSB.FindFromKey(aVP);
289 //const Bnd_Box& aBoxVP=aMSB.FindFromKey(aVP);
290 //modified by NIZNHY-PKV Thu Jan 21 10:04:11 2010t
293 aSelector.SetBox(aBoxVP);
295 aNbVSD=aBBTree.Select(aSelector);
297 continue; // it must not be
300 const TColStd_ListOfInteger& aLI=aSelector.Indices();
303 for (; aIt.More(); aIt.Next()) {
305 if (aMIP.Contains(aIP1)) {
309 } //for (; aIt.More(); aIt.Next()) {
310 }//for(; aIt1.More(); aIt1.Next()) {
312 aNbIP1=aMIP1.Extent();
317 aIt1.Initialize(aMIP);
318 for(; aIt1.More(); aIt1.Next()) {
324 aIt1.Initialize(aMIP1);
325 for(; aIt1.More(); aIt1.Next()) {
333 aNbIP=aMIPC.Extent();
335 if (!aNbIP) {// no SD vertices founded
338 aMVProcessed.Add(aV);
340 else { // SD vertices founded [ aMIPC ]
341 aIt1.Initialize(aMIPC);
342 for(j=0; aIt1.More(); aIt1.Next(), ++j) {
344 const TopoDS_Shape& aVP=aMIS.FindFromKey(aIP);
349 aMVProcessed.Add(aVP);
352 myImages.Bind(aVF, aLVSD);
353 }// for (i=1; i<=aNbV; ++i) {
354 //------------------------------
358 aItIm.Initialize(myImages);
359 for (; aItIm.More(); aItIm.Next()) {
360 const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&aItIm.Key());
361 const TopTools_ListOfShape& aLVSD=aItIm.Value();
362 aNbVSD=aLVSD.Extent();
365 MakeVertex(aLVSD, aVnew);
366 aMVV.Bind(aVnew, aLVSD);
370 // UnBind old vertices
372 for (i=1; i<=aNbV; ++i) {
373 const TopoDS_Shape& aV=aMV(i);
378 aItIm.Initialize(aMVV);
379 for (; aItIm.More(); aItIm.Next()) {
380 const TopoDS_Shape& aV=aItIm.Key();
381 const TopTools_ListOfShape& aLVSD=aItIm.Value();
382 myImages.Bind(aV, aLVSD);
386 aItIm.Initialize(myImages);
387 for (; aItIm.More(); aItIm.Next()) {
388 const TopoDS_Shape& aV=aItIm.Key();
389 const TopTools_ListOfShape& aLVSD=aItIm.Value();
390 aItS.Initialize(aLVSD);
391 for (; aItS.More(); aItS.Next()) {
392 const TopoDS_Shape& aVSD=aItS.Value();
393 if (!myOrigins.IsBound(aVSD)) {
394 myOrigins.Bind(aVSD, aV);
399 //=======================================================================
400 //function : MakeSubShapes
402 //=======================================================================
403 void GEOMAlgo_Gluer::MakeSubShapes (const TopoDS_Shape& theShape,
404 TopTools_MapOfShape& theMS,
405 TopoDS_Compound& theResult)
407 if (theMS.Contains(theShape))
414 if (theShape.ShapeType() == TopAbs_COMPOUND ||
415 theShape.ShapeType() == TopAbs_COMPSOLID) {
416 TopoDS_Iterator It (theShape, Standard_True, Standard_True);
417 for (; It.More(); It.Next()) {
418 MakeSubShapes(It.Value(), theMS, theResult);
421 else if (theShape.ShapeType() == TopAbs_SOLID) {
423 TopoDS_Solid aNewSolid;
424 TopExp_Explorer aExpS, aExp;
426 const TopoDS_Solid& aSolid = TopoDS::Solid(theShape);
428 TopAbs_Orientation anOr = aSolid.Orientation();
430 aBB.MakeSolid(aNewSolid);
431 aNewSolid.Orientation(anOr);
433 aExp.Init(aSolid, TopAbs_SHELL);
434 for (; aExp.More(); aExp.Next())
436 const TopoDS_Shape& aShell=aExp.Current();
437 const TopoDS_Shape& aShellR=myOrigins.Find(aShell);
438 aBB.Add(aNewSolid, aShellR);
441 TopTools_ListOfShape aLS;
444 myImages.Bind(aNewSolid, aLS);
445 myOrigins.Bind(aSolid, aNewSolid);
447 aBB.Add(theResult, aNewSolid);
449 else if (theShape.ShapeType() == TopAbs_WIRE) {
450 if (myKeepNonSolids) {
452 if (!myOrigins.IsBound(theShape)) {
454 const TopoDS_Wire& aW=TopoDS::Wire(theShape);
457 aBB.MakeWire(newWire);
459 TopExp_Explorer aExpE (aW, TopAbs_EDGE);
460 for (; aExpE.More(); aExpE.Next()) {
461 const TopoDS_Edge& aE=TopoDS::Edge(aExpE.Current());
462 TopoDS_Edge aER=TopoDS::Edge(myOrigins.Find(aE));
464 aER.Orientation(TopAbs_FORWARD);
465 if (!BRep_Tool::Degenerated(aER)) {
467 //if (bIsUPeriodic) {
468 // GEOMAlgo_Tools::RefinePCurveForEdgeOnFace(aER, aFFWD, aUMin, aUMax);
470 //BOPTools_Tools2D::BuildPCurveForEdgeOnFace(aER, aFFWD);
473 Standard_Boolean bIsToReverse=BOPTools_Tools3D::IsSplitToReverse1(aER, aE, myContext);
479 aER.Orientation(aE.Orientation());
482 aBB.Add(newWire, aER);
485 TopTools_ListOfShape aLW;
488 myImages.Bind(newWire, aLW);
489 myOrigins.Bind(aW, newWire);
491 const TopoDS_Shape& aShapeR = myOrigins.Find(theShape);
492 aBB.Add(theResult, aShapeR);
497 if (myKeepNonSolids) {
499 const TopoDS_Shape& aShapeR = myOrigins.Find(theShape);
500 aBB.Add(theResult, aShapeR);
504 //=======================================================================
505 //function : MakeSolids
507 //=======================================================================
508 void GEOMAlgo_Gluer::MakeSolids()
513 TopoDS_Compound aCmp;
514 TopTools_MapOfShape aMS;
516 aBB.MakeCompound(aCmp);
518 // Add images of all initial sub-shapes in the result.
519 // If myKeepNonSolids==false, add only solids images.
520 MakeSubShapes(myShape, aMS, aCmp);
525 BOP_CorrectTolerances::CorrectCurveOnSurface(myResult);
528 //=======================================================================
529 //function : MakeShells
531 //=======================================================================
532 void GEOMAlgo_Gluer::MakeShells()
536 Standard_Boolean bIsToReverse;
537 Standard_Integer i, aNbS;
538 TopAbs_Orientation anOr;
539 TopoDS_Shell aNewShell;
541 TopTools_IndexedMapOfShape aMS;
542 TopExp_Explorer aExp;
545 TopExp::MapShapes(myShape, TopAbs_SHELL, aMS);
548 for (i=1; i<=aNbS; ++i) {
549 const TopoDS_Shell& aShell=TopoDS::Shell(aMS(i));
550 anOr=aShell.Orientation();
552 aBB.MakeShell(aNewShell);
553 aNewShell.Orientation(anOr);
554 aExp.Init(aShell, TopAbs_FACE);
555 for (; aExp.More(); aExp.Next()) {
556 const TopoDS_Face& aF=TopoDS::Face(aExp.Current());
557 aFR=TopoDS::Face(myOrigins.Find(aF));
558 if (aFR.IsSame(aF)) {
559 aBB.Add(aNewShell, aF);
562 bIsToReverse=IsToReverse(aFR, aF);
566 aBB.Add(aNewShell, aFR);
569 TopTools_ListOfShape aLS;
572 myImages.Bind(aNewShell, aLS);
573 myOrigins.Bind(aShell, aNewShell);
576 //=======================================================================
577 //function : MakeFaces
579 //=======================================================================
580 void GEOMAlgo_Gluer::MakeFaces()
582 MakeShapes(TopAbs_FACE);
584 //=======================================================================
585 //function : MakeEdges
587 //=======================================================================
588 void GEOMAlgo_Gluer::MakeEdges()
590 MakeShapes(TopAbs_EDGE);
592 //=======================================================================
593 //function : MakeShapes
595 //=======================================================================
596 void GEOMAlgo_Gluer::MakeShapes(const TopAbs_ShapeEnum aType)
600 Standard_Boolean bHasNewSubShape;
601 Standard_Integer i, aNbF, aNbSDF, iErr;
602 TopoDS_Shape aNewShape;
603 TopTools_IndexedMapOfShape aMF;
604 TopTools_ListIteratorOfListOfShape aItS;
605 GEOMAlgo_PassKeyShape aPKF;
606 GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape aMPKLF;
608 TopExp::MapShapes(myShape, aType, aMF);
611 for (i=1; i<=aNbF; ++i) {
612 const TopoDS_Shape& aS=aMF(i);
614 if (aType==TopAbs_FACE) {
615 const TopoDS_Face& aF=TopoDS::Face(aS);
616 FacePassKey(aF, aPKF);
618 else if (aType==TopAbs_EDGE) {
619 const TopoDS_Edge& aE=TopoDS::Edge(aS);
620 EdgePassKey(aE, aPKF);
627 if (aMPKLF.Contains(aPKF)) {
628 TopTools_ListOfShape& aLSDF=aMPKLF.ChangeFromKey(aPKF);
632 TopTools_ListOfShape aLSDF;
635 aMPKLF.Add(aPKF, aLSDF);
638 // check geometric coincidence
639 if (myCheckGeometry) {
640 iErr=GEOMAlgo_Tools::RefineSDShapes(aMPKLF, myTol, myContext);
649 aNbF=aMPKLF.Extent();
650 for (i=1; i<=aNbF; ++i) {
651 const TopTools_ListOfShape& aLSDF=aMPKLF(i);
652 aNbSDF=aLSDF.Extent();
654 myErrorStatus=4; // it must not be
657 const TopoDS_Shape& aS1=aLSDF.First();
659 bHasNewSubShape=Standard_True;
660 // prevent creation of a new shape if there are not
661 // new sub-shapes of aSS among the originals
663 bHasNewSubShape=HasNewSubShape(aS1);
664 if (!bHasNewSubShape) {
666 aNewShape.Orientation(TopAbs_FORWARD);
670 if (bHasNewSubShape) {
671 if (aType==TopAbs_FACE) {
672 TopoDS_Face aNewFace;
674 const TopoDS_Face& aF1=TopoDS::Face(aS1);
675 MakeFace(aF1, aNewFace);
678 else if (aType==TopAbs_EDGE) {
679 TopoDS_Edge aNewEdge;
681 const TopoDS_Edge& aE1=TopoDS::Edge(aS1);
682 MakeEdge(aE1, aNewEdge);
687 myImages.Bind(aNewShape, aLSDF);
689 aItS.Initialize(aLSDF);
690 for (; aItS.More(); aItS.Next()) {
691 const TopoDS_Shape& aFSD=aItS.Value();
692 if (!myOrigins.IsBound(aFSD)) {
693 myOrigins.Bind(aFSD, aNewShape);
698 //=======================================================================
699 //function : CheckResult
701 //=======================================================================
702 void GEOMAlgo_Gluer::CheckResult()
706 if (myResult.IsNull()) {
711 Standard_Boolean bFound;
712 Standard_Integer i, j, aNbS, aNbFS, aNbSx;
713 TopTools_IndexedMapOfShape aMS, aMFS;
714 TopTools_IndexedDataMapOfShapeListOfShape aMFR;
716 TopExp::MapShapesAndAncestors(myResult, TopAbs_FACE, TopAbs_SOLID, aMFR);
717 TopExp::MapShapes(myResult, TopAbs_SOLID, aMS);
722 for (i=1; i<=aNbS; ++i) {
723 const TopoDS_Shape& aSolid=aMS(i);
726 TopExp::MapShapes(aSolid, TopAbs_FACE, aMFS);
728 bFound=Standard_False;
730 for (j=1; j<=aNbFS; ++j) {
731 const TopoDS_Shape& aFS=aMFS(j);
732 if (aMFR.Contains(aFS)) {
733 const TopTools_ListOfShape& aLSx=aMFR.FindFromKey(aFS);
749 //=======================================================================
750 //function : CheckData
752 //=======================================================================
753 void GEOMAlgo_Gluer::CheckData()
757 if (myShape.IsNull()) {
762 //=======================================================================
763 //function : InnerTolerance
765 //=======================================================================
766 void GEOMAlgo_Gluer::InnerTolerance()
772 Standard_Real aX[3][2], dH, dHmin, aCoef, aTolTresh;
775 BRepBndLib::Add(myShape, aBox);
776 aBox.Get(aX[0][0], aX[1][0], aX[2][0], aX[0][1], aX[1][1], aX[2][1]);
778 dHmin=aX[0][1]-aX[0][0];
779 for (i=1; i<3; ++i) {
780 dH=aX[i][1]-aX[i][0];
788 aTolTresh=aCoef*dHmin;
789 if (myTol>aTolTresh) {
795 //=======================================================================
796 //function : FacePassKey
798 //=======================================================================
799 void GEOMAlgo_Gluer::FacePassKey(const TopoDS_Face& aF,
800 GEOMAlgo_PassKeyShape& aPK)
802 Standard_Integer i, aNbE;
803 TopTools_ListOfShape aLE;
804 TopTools_IndexedMapOfShape aME;
806 TopExp::MapShapes(aF, TopAbs_EDGE, aME);
809 for (i=1; i<=aNbE; ++i) {
810 const TopoDS_Shape& aE=aME(i);
811 if (!myOrigins.IsBound(aE)) {
815 const TopoDS_Shape& aER=myOrigins.Find(aE);
820 //=======================================================================
821 //function : EdgePassKey
823 //=======================================================================
824 void GEOMAlgo_Gluer::EdgePassKey(const TopoDS_Edge& aE,
825 GEOMAlgo_PassKeyShape& aPK)
827 TopoDS_Vertex aV1, aV2;
829 TopExp::Vertices(aE, aV1, aV2);
831 if (!myOrigins.IsBound(aV1) || !myOrigins.IsBound(aV2) ) {
835 const TopoDS_Shape& aVR1=myOrigins.Find(aV1);
836 const TopoDS_Shape& aVR2=myOrigins.Find(aV2);
837 aPK.SetShapes(aVR1, aVR2);
839 //=======================================================================
840 //function : MakeVertex
842 //=======================================================================
843 void GEOMAlgo_Gluer::MakeVertex(const TopTools_ListOfShape& aLV,
844 TopoDS_Vertex& aNewVertex)
846 Standard_Integer aNbV;
847 Standard_Real aTolV, aD, aDmax;
852 TopTools_ListIteratorOfListOfShape aIt;
860 aGC.SetCoord(0.,0.,0.);
862 for (; aIt.More(); aIt.Next()) {
863 aVx=TopoDS::Vertex(aIt.Value());
864 aP3D=BRep_Tool::Pnt(aVx);
867 aGC/=(Standard_Real)aNbV;
873 for (; aIt.More(); aIt.Next()) {
874 aVx=TopoDS::Vertex(aIt.Value());
875 aP3D=BRep_Tool::Pnt(aVx);
876 aTolV=BRep_Tool::Tolerance(aVx);
877 aD=aPGC.Distance(aP3D)+aTolV;
883 aBB.MakeVertex (aNewVertex, aPGC, aDmax);
885 //=======================================================================
886 //function : MakeEdge
888 //=======================================================================
889 void GEOMAlgo_Gluer::MakeEdge(const TopoDS_Edge& aE,
890 TopoDS_Edge& aNewEdge)
894 Standard_Boolean bIsDE;
895 Standard_Real aT1, aT2;
896 TopoDS_Vertex aV1, aV2, aVR1, aVR2;
899 bIsDE=BRep_Tool::Degenerated(aE);
902 aEx.Orientation(TopAbs_FORWARD);
904 TopExp::Vertices(aEx, aV1, aV2);
906 aT1=BRep_Tool::Parameter(aV1, aEx);
907 aT2=BRep_Tool::Parameter(aV2, aEx);
909 aVR1=TopoDS::Vertex(myOrigins.Find(aV1));
910 aVR1.Orientation(TopAbs_FORWARD);
911 aVR2=TopoDS::Vertex(myOrigins.Find(aV2));
912 aVR2.Orientation(TopAbs_REVERSED);
918 TopAbs_Orientation anOrE;
920 anOrE=aE.Orientation();
921 aTol=BRep_Tool::Tolerance(aE);
928 aBB.Range(E, aT1, aT2);
929 aBB.Degenerated(E, Standard_True);
930 aBB.UpdateEdge(E, aTol);
936 BOPTools_Tools::MakeSplitEdge(aEx, aVR1, aT1, aVR2, aT2, aNewEdge);
939 //=======================================================================
940 //function : MakeFace
942 //=======================================================================
943 void GEOMAlgo_Gluer::MakeFace(const TopoDS_Face& aF,
944 TopoDS_Face& aNewFace)
948 Standard_Boolean bIsToReverse, bIsUPeriodic;
949 Standard_Real aTol, aUMin, aUMax, aVMin, aVMax;
952 TopoDS_Face aFFWD, newFace;
953 TopLoc_Location aLoc;
954 Handle(Geom_Surface) aS;
955 Handle(Geom2d_Curve) aC2D;
956 TopExp_Explorer aExpW, aExpE;
960 aFFWD.Orientation(TopAbs_FORWARD);
962 aS=BRep_Tool::Surface(aFFWD, aLoc);
963 bIsUPeriodic=GEOMAlgo_Tools::IsUPeriodic(aS);
964 aTol=BRep_Tool::Tolerance(aFFWD);
965 BRepTools::UVBounds(aF, aUMin, aUMax, aVMin, aVMax);
967 aBB.MakeFace (newFace, aS, aLoc, aTol);
969 aExpW.Init(aFFWD, TopAbs_WIRE);
970 for (; aExpW.More(); aExpW.Next()) {
971 aBB.MakeWire(newWire);
972 const TopoDS_Wire& aW=TopoDS::Wire(aExpW.Current());
973 aExpE.Init(aW, TopAbs_EDGE);
974 for (; aExpE.More(); aExpE.Next()) {
975 const TopoDS_Edge& aE=TopoDS::Edge(aExpE.Current());
976 aER=TopoDS::Edge(myOrigins.Find(aE));
978 aER.Orientation(TopAbs_FORWARD);
979 if (!BRep_Tool::Degenerated(aER)) {
982 GEOMAlgo_Tools::RefinePCurveForEdgeOnFace(aER, aFFWD, aUMin, aUMax);
984 BOPTools_Tools2D::BuildPCurveForEdgeOnFace(aER, aFFWD);
987 bIsToReverse=BOPTools_Tools3D::IsSplitToReverse1(aER, aE, myContext);
993 aER.Orientation(aE.Orientation());
996 aBB.Add(newWire, aER);
999 TopTools_ListOfShape aLW;
1002 myImages.Bind(newWire, aLW);
1003 myOrigins.Bind(aW, newWire);
1005 aBB.Add(newFace, newWire);
1009 //=======================================================================
1010 //function : IsToReverse
1012 //=======================================================================
1013 Standard_Boolean GEOMAlgo_Gluer::IsToReverse(const TopoDS_Face& aFR,
1014 const TopoDS_Face& aF)
1016 Standard_Boolean bRet;
1017 Standard_Real aT, aT1, aT2, aTR, aScPr;
1018 TopExp_Explorer aExp;
1019 Handle(Geom_Curve)aC3D;
1023 bRet=Standard_False;
1025 aExp.Init(aF, TopAbs_EDGE);
1026 for (; aExp.More(); aExp.Next()) {
1027 const TopoDS_Edge& aE=TopoDS::Edge(aExp.Current());
1029 if (BRep_Tool::Degenerated(aE)) {
1033 const TopoDS_Edge& aER=TopoDS::Edge(myOrigins.Find(aE));
1035 aC3D=BRep_Tool::Curve(aE, aT1, aT2);
1036 aT=BOPTools_Tools2D::IntermediatePoint(aT1, aT2);
1038 myContext->ProjectPointOnEdge(aP, aER, aTR);
1040 BOPTools_Tools3D::GetNormalToFaceOnEdge (aE, aF, aT, aDNF);
1041 if (aF.Orientation()==TopAbs_REVERSED) {
1045 BOPTools_Tools3D::GetNormalToFaceOnEdge (aER, aFR, aTR, aDNFR);
1046 if (aFR.Orientation()==TopAbs_REVERSED) {
1055 //=======================================================================
1056 //function : HasNewSubShape
1058 //=======================================================================
1059 Standard_Boolean GEOMAlgo_Gluer::HasNewSubShape(const TopoDS_Shape& aS)const
1061 Standard_Boolean bRet;
1062 Standard_Integer i, aNbSS;
1063 TopTools_IndexedMapOfShape aMSS;
1065 GetSubShapes(aS, aMSS);
1067 bRet=Standard_False;
1068 aNbSS=aMSS.Extent();
1069 for (i=1; i<=aNbSS; ++i) {
1070 const TopoDS_Shape& aSS=aMSS(i);
1071 if (aSS.ShapeType()==TopAbs_WIRE) {
1075 bRet=!myOrigins.IsBound(aSS);
1080 const TopoDS_Shape& aSSIm=myOrigins.Find(aSS);
1081 bRet=!aSSIm.IsSame(aSS);
1088 //=======================================================================
1089 //function : GetSubShapes
1091 //=======================================================================
1092 void GetSubShapes(const TopoDS_Shape& aS,
1093 TopTools_IndexedMapOfShape& aMSS)
1095 Standard_Integer aR;
1096 TopAbs_ShapeEnum aType;
1097 TopoDS_Iterator aIt;
1099 aType=aS.ShapeType();
1100 aR=(Standard_Integer)aType+1;
1101 if (aR>TopAbs_VERTEX) {
1106 for (; aIt.More(); aIt.Next()) {
1107 const TopoDS_Shape& aSS=aIt.Value();
1109 GetSubShapes(aSS, aMSS);
1112 //=======================================================================
1113 //function : Modified
1115 //=======================================================================
1116 const TopTools_ListOfShape& GEOMAlgo_Gluer::Modified (const TopoDS_Shape& aS)
1118 TopAbs_ShapeEnum aType;
1120 myGenerated.Clear();
1122 aType=aS.ShapeType();
1123 if (aType==TopAbs_VERTEX ||
1124 aType==TopAbs_EDGE ||
1125 aType==TopAbs_WIRE ||
1126 aType==TopAbs_FACE ||
1127 aType==TopAbs_SHELL ||
1128 aType==TopAbs_SOLID) {
1129 if(myOrigins.IsBound(aS)) {
1130 const TopoDS_Shape& aSnew=myOrigins.Find(aS);
1131 if (!aSnew.IsSame(aS)) {
1132 myGenerated.Append(aSnew);
1139 //=======================================================================
1140 //function : Generated
1142 //=======================================================================
1143 const TopTools_ListOfShape& GEOMAlgo_Gluer::Generated(const TopoDS_Shape& )
1145 myGenerated.Clear();
1148 //=======================================================================
1149 //function : IsDeleted
1151 //=======================================================================
1152 Standard_Boolean GEOMAlgo_Gluer::IsDeleted (const TopoDS_Shape& aS)
1154 Standard_Boolean bRet=Standard_False;
1156 const TopTools_ListOfShape& aL=Modified(aS);
1165 // 1 - the object is just initialized
1166 // 2 - no vertices found in source shape
1167 // 3 - nb same domain vertices for the vertex Vi =0
1168 // 4 - nb same domain edges(faces) for the edge Ei(face Fi) =0
1169 // 5 - source shape is Null
1170 // 6 - result shape is Null
1171 // 101 - nb edges > PassKey.NbMax() in FacesPassKey()
1172 // 102 - the edge Ei can not be found in myOrigins Map
1173 // 100 - the vertex Vi can not be found in myOrigins Map
1177 // 1 - some shapes can not be glued by faces