b311480e |
1 | // Created on: 2001-01-16 |
2 | // Created by: Michael SAZONOV |
3 | // Copyright (c) 2001-2012 OPEN CASCADE SAS |
4 | // |
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. |
9 | // |
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. |
12 | // |
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. |
7fd59977 |
19 | |
20 | #include <QANewModTopOpe_Glue.ixx> |
21 | #include <TopoDS.hxx> |
22 | #include <TopoDS_Iterator.hxx> |
23 | #include <BRep_Builder.hxx> |
24 | #include <BRep_Tool.hxx> |
25 | #include <TopExp.hxx> |
26 | #include <TopTools_ListIteratorOfListOfShape.hxx> |
27 | #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx> |
28 | #include <BRepExtrema_DistShapeShape.hxx> |
29 | #include <TopExp_Explorer.hxx> |
30 | |
31 | //======================================================================= |
32 | //function : PerformVertex |
33 | //purpose : |
34 | //======================================================================= |
35 | |
36 | void |
37 | QANewModTopOpe_Glue::PerformVertex() |
38 | { |
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); |
44 | BRep_Builder aBld; |
45 | aBld.Add(myS1,aV.Oriented(TopAbs_INTERNAL)); |
46 | |
47 | TopTools_ListOfShape aList; |
48 | aList.Append (aV); |
49 | myMapGener.Bind(myS1, aList); |
50 | |
51 | myShape = myS1; |
52 | myShape.Orientation(myS1.Orientation()); |
53 | Done(); |
54 | |
55 | } |
56 | else { |
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); |
62 | |
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); |
69 | BRep_Builder aBld; |
70 | |
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; |
76 | |
77 | const TopoDS_Vertex& aVer = TopoDS::Vertex (aShape); |
78 | |
79 | if(aVer.IsSame(aVer2)) continue; |
80 | |
81 | Standard_Real aTol1 = BRep_Tool::Tolerance(aVer); |
82 | if (aDist > aTol1 && aDist > aTol2) continue; |
83 | |
84 | aTol2 = Max (aTol2, aTol1 + aDist); |
85 | aBld.UpdateVertex (aVer2, aTol2); |
86 | |
87 | // substitute aVer2 instead of aVer |
88 | TopTools_ListOfShape aList; |
89 | aList.Append (aVer2); |
90 | mySubst.Substitute (aVer, aList); |
91 | aMapPassed.Add(aVer); |
92 | TopTools_ListIteratorOfListOfShape aIter(aMapAnc.FindFromKey(aVer)); |
93 | for (; aIter.More(); aIter.Next()) { |
94 | aMapPassed.Add(aIter.Value()); |
95 | } |
96 | myMapModif.Bind(aVer, aList); |
97 | } |
98 | |
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; |
104 | |
105 | const TopoDS_Edge& aEdge = TopoDS::Edge (aShape); |
106 | Standard_Real aTol1 = BRep_Tool::Tolerance(aEdge); |
107 | if (aDist > aTol1 && aDist > aTol2) continue; |
108 | Standard_Real aPar; |
109 | aExtrema.ParOnEdgeS1(i, aPar); |
110 | |
111 | // construct new edge |
112 | TopoDS_Edge aNewEdge; |
113 | InsertVertexInEdge (aEdge, aVer2, aPar, aNewEdge); |
114 | |
115 | // substitute edge |
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()); |
123 | } |
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); |
132 | } |
133 | |
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; |
139 | |
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); |
145 | |
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)); |
151 | // add old subshapes |
152 | TopoDS_Iterator aIterF (aFace, Standard_False); |
153 | for (; aIterF.More(); aIterF.Next()) { |
154 | aBld.Add (aNewFace, aIterF.Value()); |
155 | } |
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); |
160 | |
161 | // substitute face |
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); |
174 | } |
175 | |
176 | mySubst.Build(myS1); |
177 | |
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)); |
185 | } |
186 | } |
187 | } |
188 | |
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)); |
196 | } |
197 | } |
198 | } |
199 | |
200 | if (mySubst.IsCopied(myS1)) { |
201 | myShape = mySubst.Copy(myS1).First(); |
202 | myShape.Orientation(myS1.Orientation()); |
203 | Done(); |
204 | } |
205 | } |
206 | } |