7fd59977 |
1 | // File: QANewModTopOpe_Glue_vertex.cxx |
2 | // Created: Tue Jan 16 10:00:32 2001 |
3 | // Author: Michael SAZONOV <msv@nnov.matra-dtv.fr> |
4 | // Copyright: SAMTECH S.A. 2001 |
5 | |
7fd59977 |
6 | // Lastly modified by : |
7 | // +---------------------------------------------------------------------------+ |
8 | // ! martin ! add glue : vertex+solid ! 07/25/03! 4.0-2! |
9 | // +---------------------------------------------------------------------------+ |
10 | |
11 | |
12 | #include <QANewModTopOpe_Glue.ixx> |
13 | #include <TopoDS.hxx> |
14 | #include <TopoDS_Iterator.hxx> |
15 | #include <BRep_Builder.hxx> |
16 | #include <BRep_Tool.hxx> |
17 | #include <TopExp.hxx> |
18 | #include <TopTools_ListIteratorOfListOfShape.hxx> |
19 | #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx> |
20 | #include <BRepExtrema_DistShapeShape.hxx> |
21 | #include <TopExp_Explorer.hxx> |
22 | |
23 | //======================================================================= |
24 | //function : PerformVertex |
25 | //purpose : |
26 | //======================================================================= |
27 | |
28 | void |
29 | QANewModTopOpe_Glue::PerformVertex() |
30 | { |
31 | BRepExtrema_DistShapeShape aExtrema (myS1, myS2); |
32 | if (!aExtrema.IsDone()) return; |
33 | if (aExtrema.InnerSolution()) { |
34 | if (myS2.ShapeType() != TopAbs_VERTEX) return; |
35 | TopoDS_Vertex aV = TopoDS::Vertex(myS2); |
36 | BRep_Builder aBld; |
37 | aBld.Add(myS1,aV.Oriented(TopAbs_INTERNAL)); |
38 | |
39 | TopTools_ListOfShape aList; |
40 | aList.Append (aV); |
41 | myMapGener.Bind(myS1, aList); |
42 | |
43 | myShape = myS1; |
44 | myShape.Orientation(myS1.Orientation()); |
45 | Done(); |
46 | |
47 | } |
48 | else { |
49 | Standard_Integer nbSol = aExtrema.NbSolution(), i; |
50 | Standard_Real aDist = aExtrema.Value(); |
51 | TopoDS_Shape aDummy = myS2.Oriented(TopAbs_FORWARD); |
52 | TopoDS_Vertex aVer2 = TopoDS::Vertex (aDummy); |
53 | Standard_Real aTol2 = BRep_Tool::Tolerance(aVer2); |
54 | |
55 | TopTools_MapOfShape aMapPassed; |
56 | aMapPassed.Add (myS2); |
57 | TopTools_IndexedDataMapOfShapeListOfShape aMapAnc; |
58 | TopExp::MapShapesAndAncestors (myS1, TopAbs_VERTEX, TopAbs_EDGE, aMapAnc); |
59 | TopExp::MapShapesAndAncestors (myS1, TopAbs_VERTEX, TopAbs_FACE, aMapAnc); |
60 | TopExp::MapShapesAndAncestors (myS1, TopAbs_EDGE, TopAbs_FACE, aMapAnc); |
61 | BRep_Builder aBld; |
62 | |
63 | // pass 1: process contacted vertices |
64 | for (i=1; i <= nbSol; i++) { |
65 | TopoDS_Shape aShape = aExtrema.SupportOnShape1(i); |
66 | if (aShape.ShapeType() != TopAbs_VERTEX || |
67 | aMapPassed.Contains(aShape)) continue; |
68 | |
69 | const TopoDS_Vertex& aVer = TopoDS::Vertex (aShape); |
70 | |
71 | if(aVer.IsSame(aVer2)) continue; |
72 | |
73 | Standard_Real aTol1 = BRep_Tool::Tolerance(aVer); |
74 | if (aDist > aTol1 && aDist > aTol2) continue; |
75 | |
76 | aTol2 = Max (aTol2, aTol1 + aDist); |
77 | aBld.UpdateVertex (aVer2, aTol2); |
78 | |
79 | // substitute aVer2 instead of aVer |
80 | TopTools_ListOfShape aList; |
81 | aList.Append (aVer2); |
82 | mySubst.Substitute (aVer, aList); |
83 | aMapPassed.Add(aVer); |
84 | TopTools_ListIteratorOfListOfShape aIter(aMapAnc.FindFromKey(aVer)); |
85 | for (; aIter.More(); aIter.Next()) { |
86 | aMapPassed.Add(aIter.Value()); |
87 | } |
88 | myMapModif.Bind(aVer, aList); |
89 | } |
90 | |
91 | // pass 2: process contacted edges |
92 | for (i=1; i <= nbSol; i++) { |
93 | TopoDS_Shape aShape = aExtrema.SupportOnShape1(i); |
94 | if (aShape.ShapeType() != TopAbs_EDGE || |
95 | aMapPassed.Contains(aShape)) continue; |
96 | |
97 | const TopoDS_Edge& aEdge = TopoDS::Edge (aShape); |
98 | Standard_Real aTol1 = BRep_Tool::Tolerance(aEdge); |
99 | if (aDist > aTol1 && aDist > aTol2) continue; |
100 | Standard_Real aPar; |
101 | aExtrema.ParOnEdgeS1(i, aPar); |
102 | |
103 | // construct new edge |
104 | TopoDS_Edge aNewEdge; |
105 | InsertVertexInEdge (aEdge, aVer2, aPar, aNewEdge); |
106 | |
107 | // substitute edge |
108 | TopTools_ListOfShape aList; |
109 | aList.Append (aNewEdge.Oriented(TopAbs_FORWARD)); |
110 | mySubst.Substitute (aEdge, aList); |
111 | aMapPassed.Add(aEdge); |
112 | TopTools_ListIteratorOfListOfShape aIter(aMapAnc.FindFromKey(aEdge)); |
113 | for (; aIter.More(); aIter.Next()) { |
114 | aMapPassed.Add(aIter.Value()); |
115 | } |
116 | // for Mandrake-10 - mkv,02.06.06 - myMapModif.Bind(aEdge, TopTools_ListOfShape()); |
117 | TopTools_ListOfShape aList1; |
118 | myMapModif.Bind(aEdge, aList1); |
119 | myMapModif(aEdge).Append (aNewEdge); |
120 | // for Mandrake-10 - mkv,02.06.06 - myMapGener.Bind(aEdge, TopTools_ListOfShape()); |
121 | TopTools_ListOfShape aList2; |
122 | myMapGener.Bind(aEdge, aList2); |
123 | myMapGener(aEdge).Append (aVer2); |
124 | } |
125 | |
126 | // pass 3: process contacted faces |
127 | for (i=1; i <= nbSol; i++) { |
128 | TopoDS_Shape aShape = aExtrema.SupportOnShape1(i); |
129 | if (aShape.ShapeType() != TopAbs_FACE || |
130 | aMapPassed.Contains(aShape)) continue; |
131 | |
132 | const TopoDS_Face& aFace = TopoDS::Face (aShape); |
133 | Standard_Real aTol1 = BRep_Tool::Tolerance(aFace); |
134 | if (aDist > aTol1 && aDist > aTol2) continue; |
135 | Standard_Real aParU, aParV; |
136 | aExtrema.ParOnFaceS1(i, aParU, aParV); |
137 | |
138 | // construct new face |
139 | TopoDS_Face aNewFace = aFace; |
140 | aNewFace.EmptyCopy(); |
141 | aNewFace.Orientation (TopAbs_FORWARD); |
142 | aBld.NaturalRestriction (aNewFace, BRep_Tool::NaturalRestriction(aFace)); |
143 | // add old subshapes |
144 | TopoDS_Iterator aIterF (aFace, Standard_False); |
145 | for (; aIterF.More(); aIterF.Next()) { |
146 | aBld.Add (aNewFace, aIterF.Value()); |
147 | } |
148 | // add new internal vertex |
149 | aTol2 = Max (aTol2, aTol1); |
150 | aBld.Add (aNewFace, aVer2.Oriented(TopAbs_INTERNAL)); |
151 | aBld.UpdateVertex (aVer2, aParU, aParV, aNewFace, aTol2); |
152 | |
153 | // substitute face |
154 | TopTools_ListOfShape aList; |
155 | aList.Append (aNewFace); |
156 | mySubst.Substitute (aFace, aList); |
157 | aMapPassed.Add(aFace); |
158 | // for Mandrake-10 - mkv,02.06.06 - myMapModif.Bind(aFace, TopTools_ListOfShape()); |
159 | TopTools_ListOfShape aList3; |
160 | myMapModif.Bind(aFace, aList3); |
161 | myMapModif(aFace).Append (aNewFace); |
162 | // for Mandrake-10 - mkv,02.06.06 - myMapGener.Bind(aFace, TopTools_ListOfShape()); |
163 | TopTools_ListOfShape aList4; |
164 | myMapGener.Bind(aFace, aList4); |
165 | myMapGener(aFace).Append (aVer2); |
166 | } |
167 | |
168 | mySubst.Build(myS1); |
169 | |
170 | TopExp_Explorer aExp (myS1, TopAbs_FACE); |
171 | for (; aExp.More(); aExp.Next()) { |
172 | const TopoDS_Shape& aFace = aExp.Current(); |
173 | if(myMapModif.IsBound(aFace)) continue; |
174 | if (mySubst.IsCopied(aFace)) { |
175 | if (!mySubst.Copy(aFace).IsEmpty()) { |
176 | myMapModif.Bind(aFace,mySubst.Copy(aFace)); |
177 | } |
178 | } |
179 | } |
180 | |
181 | aExp.Init(myS1, TopAbs_EDGE); |
182 | for (; aExp.More(); aExp.Next()) { |
183 | const TopoDS_Shape& anEdge = aExp.Current(); |
184 | if(myMapModif.IsBound(anEdge)) continue; |
185 | if (mySubst.IsCopied(anEdge)) { |
186 | if (!mySubst.Copy(anEdge).IsEmpty()) { |
187 | myMapModif.Bind(anEdge,mySubst.Copy(anEdge)); |
188 | } |
189 | } |
190 | } |
191 | |
192 | if (mySubst.IsCopied(myS1)) { |
193 | myShape = mySubst.Copy(myS1).First(); |
194 | myShape.Orientation(myS1.Orientation()); |
195 | Done(); |
196 | } |
197 | } |
198 | } |
199 | |
200 | // @@SDM: begin |
201 | |
202 | // Copyright SAMTECH ..........................................Version 3.0-00 |
203 | // Lastly modified by : martinbe Date : 07/25/03 |
204 | |
205 | // File history synopsis (creation,modification,correction) |
206 | // +---------------------------------------------------------------------------+ |
207 | // ! Developer ! Comments ! Date ! Version ! |
208 | // +-----------!-----------------------------------------!----------!----------+ |
209 | // ! msv ! Creation !16-01-2001! 3.0-00-2! |
210 | // ! martin ! add glue : vertex+solid ! 07/25/03! 4.0-2! |
211 | // +---------------------------------------------------------------------------+ |
212 | |
213 | // @@SDM: end |