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