1 // Created on: 2001-01-16
2 // Created by: Michael SAZONOV
3 // Copyright (c) 2001-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
17 #include <BRep_Builder.hxx>
18 #include <BRep_Tool.hxx>
19 #include <BRepExtrema_DistShapeShape.hxx>
21 #include <QANewModTopOpe_Glue.hxx>
23 #include <TopExp_Explorer.hxx>
25 #include <TopoDS_Edge.hxx>
26 #include <TopoDS_Face.hxx>
27 #include <TopoDS_Iterator.hxx>
28 #include <TopoDS_Shape.hxx>
29 #include <TopoDS_Vertex.hxx>
30 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
31 #include <TopTools_ListIteratorOfListOfShape.hxx>
33 //=======================================================================
34 //function : PerformVertex
36 //=======================================================================
38 QANewModTopOpe_Glue::PerformVertex()
40 TopoDS_Shape& myS1=myArguments.First();
41 TopoDS_Shape& myS2=myTools.First();
43 BRepExtrema_DistShapeShape aExtrema (myS1, myS2);
44 if (!aExtrema.IsDone()) return;
45 if (aExtrema.InnerSolution()) {
46 if (myS2.ShapeType() != TopAbs_VERTEX) return;
47 TopoDS_Vertex aV = TopoDS::Vertex(myS2);
49 aBld.Add(myS1,aV.Oriented(TopAbs_INTERNAL));
51 TopTools_ListOfShape aList;
53 myMapGener.Bind(myS1, aList);
58 myShape.Orientation(myS1.Orientation());
63 Standard_Integer nbSol = aExtrema.NbSolution(), i;
64 Standard_Real aDist = aExtrema.Value();
65 TopoDS_Shape aDummy = myS2.Oriented(TopAbs_FORWARD);
66 TopoDS_Vertex aVer2 = TopoDS::Vertex (aDummy);
67 Standard_Real aTol2 = BRep_Tool::Tolerance(aVer2);
69 TopTools_MapOfShape aMapPassed;
70 aMapPassed.Add (myS2);
71 TopTools_IndexedDataMapOfShapeListOfShape aMapAnc;
72 TopExp::MapShapesAndAncestors (myS1, TopAbs_VERTEX, TopAbs_EDGE, aMapAnc);
73 TopExp::MapShapesAndAncestors (myS1, TopAbs_VERTEX, TopAbs_FACE, aMapAnc);
74 TopExp::MapShapesAndAncestors (myS1, TopAbs_EDGE, TopAbs_FACE, aMapAnc);
77 // pass 1: process contacted vertices
78 for (i=1; i <= nbSol; i++) {
79 TopoDS_Shape aShape = aExtrema.SupportOnShape1(i);
80 if (aShape.ShapeType() != TopAbs_VERTEX ||
81 aMapPassed.Contains(aShape)) continue;
83 const TopoDS_Vertex& aVer = TopoDS::Vertex (aShape);
85 if(aVer.IsSame(aVer2)) continue;
87 Standard_Real aTol1 = BRep_Tool::Tolerance(aVer);
88 if (aDist > aTol1 && aDist > aTol2) continue;
90 aTol2 = Max (aTol2, aTol1 + aDist);
91 aBld.UpdateVertex (aVer2, aTol2);
93 // substitute aVer2 instead of aVer
94 TopTools_ListOfShape aList;
96 mySubst.Substitute (aVer, aList);
98 TopTools_ListIteratorOfListOfShape aIter(aMapAnc.FindFromKey(aVer));
99 for (; aIter.More(); aIter.Next()) {
100 aMapPassed.Add(aIter.Value());
102 myMapModif.Bind(aVer, aList);
105 // pass 2: process contacted edges
106 for (i=1; i <= nbSol; i++) {
107 TopoDS_Shape aShape = aExtrema.SupportOnShape1(i);
108 if (aShape.ShapeType() != TopAbs_EDGE ||
109 aMapPassed.Contains(aShape)) continue;
111 const TopoDS_Edge& aEdge = TopoDS::Edge (aShape);
112 Standard_Real aTol1 = BRep_Tool::Tolerance(aEdge);
113 if (aDist > aTol1 && aDist > aTol2) continue;
115 aExtrema.ParOnEdgeS1(i, aPar);
117 // construct new edge
118 TopoDS_Edge aNewEdge;
119 InsertVertexInEdge (aEdge, aVer2, aPar, aNewEdge);
122 TopTools_ListOfShape aList;
123 aList.Append (aNewEdge.Oriented(TopAbs_FORWARD));
124 mySubst.Substitute (aEdge, aList);
125 aMapPassed.Add(aEdge);
126 TopTools_ListIteratorOfListOfShape aIter(aMapAnc.FindFromKey(aEdge));
127 for (; aIter.More(); aIter.Next()) {
128 aMapPassed.Add(aIter.Value());
130 // for Mandrake-10 - mkv,02.06.06 - myMapModif.Bind(aEdge, TopTools_ListOfShape());
131 TopTools_ListOfShape aList1;
132 myMapModif.Bind(aEdge, aList1);
133 myMapModif(aEdge).Append (aNewEdge);
134 // for Mandrake-10 - mkv,02.06.06 - myMapGener.Bind(aEdge, TopTools_ListOfShape());
135 TopTools_ListOfShape aList2;
136 myMapGener.Bind(aEdge, aList2);
137 myMapGener(aEdge).Append (aVer2);
140 // pass 3: process contacted faces
141 for (i=1; i <= nbSol; i++) {
142 TopoDS_Shape aShape = aExtrema.SupportOnShape1(i);
143 if (aShape.ShapeType() != TopAbs_FACE ||
144 aMapPassed.Contains(aShape)) continue;
146 const TopoDS_Face& aFace = TopoDS::Face (aShape);
147 Standard_Real aTol1 = BRep_Tool::Tolerance(aFace);
148 if (aDist > aTol1 && aDist > aTol2) continue;
149 Standard_Real aParU, aParV;
150 aExtrema.ParOnFaceS1(i, aParU, aParV);
152 // construct new face
153 TopoDS_Face aNewFace = aFace;
154 aNewFace.EmptyCopy();
155 aNewFace.Orientation (TopAbs_FORWARD);
156 aBld.NaturalRestriction (aNewFace, BRep_Tool::NaturalRestriction(aFace));
158 TopoDS_Iterator aIterF (aFace, Standard_False);
159 for (; aIterF.More(); aIterF.Next()) {
160 aBld.Add (aNewFace, aIterF.Value());
162 // add new internal vertex
163 aTol2 = Max (aTol2, aTol1);
164 aBld.Add (aNewFace, aVer2.Oriented(TopAbs_INTERNAL));
165 aBld.UpdateVertex (aVer2, aParU, aParV, aNewFace, aTol2);
168 TopTools_ListOfShape aList;
169 aList.Append (aNewFace);
170 mySubst.Substitute (aFace, aList);
171 aMapPassed.Add(aFace);
172 // for Mandrake-10 - mkv,02.06.06 - myMapModif.Bind(aFace, TopTools_ListOfShape());
173 TopTools_ListOfShape aList3;
174 myMapModif.Bind(aFace, aList3);
175 myMapModif(aFace).Append (aNewFace);
176 // for Mandrake-10 - mkv,02.06.06 - myMapGener.Bind(aFace, TopTools_ListOfShape());
177 TopTools_ListOfShape aList4;
178 myMapGener.Bind(aFace, aList4);
179 myMapGener(aFace).Append (aVer2);
184 TopExp_Explorer aExp (myS1, TopAbs_FACE);
185 for (; aExp.More(); aExp.Next()) {
186 const TopoDS_Shape& aFace = aExp.Current();
187 if(myMapModif.IsBound(aFace)) continue;
188 if (mySubst.IsCopied(aFace)) {
189 if (!mySubst.Copy(aFace).IsEmpty()) {
190 myMapModif.Bind(aFace,mySubst.Copy(aFace));
195 aExp.Init(myS1, TopAbs_EDGE);
196 for (; aExp.More(); aExp.Next()) {
197 const TopoDS_Shape& anEdge = aExp.Current();
198 if(myMapModif.IsBound(anEdge)) continue;
199 if (mySubst.IsCopied(anEdge)) {
200 if (!mySubst.Copy(anEdge).IsEmpty()) {
201 myMapModif.Bind(anEdge,mySubst.Copy(anEdge));
206 if (mySubst.IsCopied(myS1)) {
207 myShape = mySubst.Copy(myS1).First();
208 myShape.Orientation(myS1.Orientation());