1 // Created on: 2001-01-16
2 // Created by: Michael SAZONOV
3 // Copyright (c) 2001-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
20 #include <QANewModTopOpe_Glue.ixx>
22 #include <TopoDS_Iterator.hxx>
23 #include <BRep_Builder.hxx>
24 #include <BRep_Tool.hxx>
26 #include <TopTools_ListIteratorOfListOfShape.hxx>
27 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
28 #include <BRepExtrema_DistShapeShape.hxx>
29 #include <TopExp_Explorer.hxx>
31 //=======================================================================
32 //function : PerformVertex
34 //=======================================================================
37 QANewModTopOpe_Glue::PerformVertex()
39 BRepExtrema_DistShapeShape aExtrema (myS1, myS2);
40 if (!aExtrema.IsDone()) return;
41 if (aExtrema.InnerSolution()) {
42 if (myS2.ShapeType() != TopAbs_VERTEX) return;
43 TopoDS_Vertex aV = TopoDS::Vertex(myS2);
45 aBld.Add(myS1,aV.Oriented(TopAbs_INTERNAL));
47 TopTools_ListOfShape aList;
49 myMapGener.Bind(myS1, aList);
52 myShape.Orientation(myS1.Orientation());
57 Standard_Integer nbSol = aExtrema.NbSolution(), i;
58 Standard_Real aDist = aExtrema.Value();
59 TopoDS_Shape aDummy = myS2.Oriented(TopAbs_FORWARD);
60 TopoDS_Vertex aVer2 = TopoDS::Vertex (aDummy);
61 Standard_Real aTol2 = BRep_Tool::Tolerance(aVer2);
63 TopTools_MapOfShape aMapPassed;
64 aMapPassed.Add (myS2);
65 TopTools_IndexedDataMapOfShapeListOfShape aMapAnc;
66 TopExp::MapShapesAndAncestors (myS1, TopAbs_VERTEX, TopAbs_EDGE, aMapAnc);
67 TopExp::MapShapesAndAncestors (myS1, TopAbs_VERTEX, TopAbs_FACE, aMapAnc);
68 TopExp::MapShapesAndAncestors (myS1, TopAbs_EDGE, TopAbs_FACE, aMapAnc);
71 // pass 1: process contacted vertices
72 for (i=1; i <= nbSol; i++) {
73 TopoDS_Shape aShape = aExtrema.SupportOnShape1(i);
74 if (aShape.ShapeType() != TopAbs_VERTEX ||
75 aMapPassed.Contains(aShape)) continue;
77 const TopoDS_Vertex& aVer = TopoDS::Vertex (aShape);
79 if(aVer.IsSame(aVer2)) continue;
81 Standard_Real aTol1 = BRep_Tool::Tolerance(aVer);
82 if (aDist > aTol1 && aDist > aTol2) continue;
84 aTol2 = Max (aTol2, aTol1 + aDist);
85 aBld.UpdateVertex (aVer2, aTol2);
87 // substitute aVer2 instead of aVer
88 TopTools_ListOfShape aList;
90 mySubst.Substitute (aVer, aList);
92 TopTools_ListIteratorOfListOfShape aIter(aMapAnc.FindFromKey(aVer));
93 for (; aIter.More(); aIter.Next()) {
94 aMapPassed.Add(aIter.Value());
96 myMapModif.Bind(aVer, aList);
99 // pass 2: process contacted edges
100 for (i=1; i <= nbSol; i++) {
101 TopoDS_Shape aShape = aExtrema.SupportOnShape1(i);
102 if (aShape.ShapeType() != TopAbs_EDGE ||
103 aMapPassed.Contains(aShape)) continue;
105 const TopoDS_Edge& aEdge = TopoDS::Edge (aShape);
106 Standard_Real aTol1 = BRep_Tool::Tolerance(aEdge);
107 if (aDist > aTol1 && aDist > aTol2) continue;
109 aExtrema.ParOnEdgeS1(i, aPar);
111 // construct new edge
112 TopoDS_Edge aNewEdge;
113 InsertVertexInEdge (aEdge, aVer2, aPar, aNewEdge);
116 TopTools_ListOfShape aList;
117 aList.Append (aNewEdge.Oriented(TopAbs_FORWARD));
118 mySubst.Substitute (aEdge, aList);
119 aMapPassed.Add(aEdge);
120 TopTools_ListIteratorOfListOfShape aIter(aMapAnc.FindFromKey(aEdge));
121 for (; aIter.More(); aIter.Next()) {
122 aMapPassed.Add(aIter.Value());
124 // for Mandrake-10 - mkv,02.06.06 - myMapModif.Bind(aEdge, TopTools_ListOfShape());
125 TopTools_ListOfShape aList1;
126 myMapModif.Bind(aEdge, aList1);
127 myMapModif(aEdge).Append (aNewEdge);
128 // for Mandrake-10 - mkv,02.06.06 - myMapGener.Bind(aEdge, TopTools_ListOfShape());
129 TopTools_ListOfShape aList2;
130 myMapGener.Bind(aEdge, aList2);
131 myMapGener(aEdge).Append (aVer2);
134 // pass 3: process contacted faces
135 for (i=1; i <= nbSol; i++) {
136 TopoDS_Shape aShape = aExtrema.SupportOnShape1(i);
137 if (aShape.ShapeType() != TopAbs_FACE ||
138 aMapPassed.Contains(aShape)) continue;
140 const TopoDS_Face& aFace = TopoDS::Face (aShape);
141 Standard_Real aTol1 = BRep_Tool::Tolerance(aFace);
142 if (aDist > aTol1 && aDist > aTol2) continue;
143 Standard_Real aParU, aParV;
144 aExtrema.ParOnFaceS1(i, aParU, aParV);
146 // construct new face
147 TopoDS_Face aNewFace = aFace;
148 aNewFace.EmptyCopy();
149 aNewFace.Orientation (TopAbs_FORWARD);
150 aBld.NaturalRestriction (aNewFace, BRep_Tool::NaturalRestriction(aFace));
152 TopoDS_Iterator aIterF (aFace, Standard_False);
153 for (; aIterF.More(); aIterF.Next()) {
154 aBld.Add (aNewFace, aIterF.Value());
156 // add new internal vertex
157 aTol2 = Max (aTol2, aTol1);
158 aBld.Add (aNewFace, aVer2.Oriented(TopAbs_INTERNAL));
159 aBld.UpdateVertex (aVer2, aParU, aParV, aNewFace, aTol2);
162 TopTools_ListOfShape aList;
163 aList.Append (aNewFace);
164 mySubst.Substitute (aFace, aList);
165 aMapPassed.Add(aFace);
166 // for Mandrake-10 - mkv,02.06.06 - myMapModif.Bind(aFace, TopTools_ListOfShape());
167 TopTools_ListOfShape aList3;
168 myMapModif.Bind(aFace, aList3);
169 myMapModif(aFace).Append (aNewFace);
170 // for Mandrake-10 - mkv,02.06.06 - myMapGener.Bind(aFace, TopTools_ListOfShape());
171 TopTools_ListOfShape aList4;
172 myMapGener.Bind(aFace, aList4);
173 myMapGener(aFace).Append (aVer2);
178 TopExp_Explorer aExp (myS1, TopAbs_FACE);
179 for (; aExp.More(); aExp.Next()) {
180 const TopoDS_Shape& aFace = aExp.Current();
181 if(myMapModif.IsBound(aFace)) continue;
182 if (mySubst.IsCopied(aFace)) {
183 if (!mySubst.Copy(aFace).IsEmpty()) {
184 myMapModif.Bind(aFace,mySubst.Copy(aFace));
189 aExp.Init(myS1, TopAbs_EDGE);
190 for (; aExp.More(); aExp.Next()) {
191 const TopoDS_Shape& anEdge = aExp.Current();
192 if(myMapModif.IsBound(anEdge)) continue;
193 if (mySubst.IsCopied(anEdge)) {
194 if (!mySubst.Copy(anEdge).IsEmpty()) {
195 myMapModif.Bind(anEdge,mySubst.Copy(anEdge));
200 if (mySubst.IsCopied(myS1)) {
201 myShape = mySubst.Copy(myS1).First();
202 myShape.Orientation(myS1.Orientation());