b311480e |
1 | // Created on: 2000-02-01 |
2 | // Created by: Peter KURNEV |
3 | // Copyright (c) 2000-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. |
19 | |
7fd59977 |
20 | |
21 | #include <TopOpeBRepBuild_Builder1.ixx> |
22 | |
23 | #include <TopExp.hxx> |
24 | #include <TopExp_Explorer.hxx> |
25 | |
26 | #include <TopoDS.hxx> |
27 | #include <TopoDS_Shape.hxx> |
28 | #include <TopoDS_Face.hxx> |
29 | #include <TopoDS_Solid.hxx> |
30 | #include <TopoDS_Shell.hxx> |
31 | #include <TopoDS_Wire.hxx> |
32 | #include <TopoDS_Edge.hxx> |
33 | #include <TopoDS_Vertex.hxx> |
34 | |
35 | #include <BRep_Builder.hxx> |
36 | |
37 | #include <TopTools_ListOfShape.hxx> |
38 | #include <TopTools_ListIteratorOfListOfShape.hxx> |
39 | #include <TopTools_IndexedMapOfShape.hxx> |
40 | #include <TopTools_IndexedDataMapOfShapeShape.hxx> |
41 | #include <TopOpeBRepDS_CurveExplorer.hxx> |
42 | |
43 | //======================================================================= |
44 | //function : TopOpeBRepBuild_Builder1::CorrectResult2d |
45 | //purpose : Change the Result (after CorrectFace2d) |
7fd59977 |
46 | //======================================================================= |
b311480e |
47 | Standard_Integer TopOpeBRepBuild_Builder1::CorrectResult2d(TopoDS_Shape& aResult) |
7fd59977 |
48 | |
49 | { |
50 | Standard_Integer aNb=myMapOfCorrect2dEdges.Extent(); |
51 | if(!aNb) |
52 | return 0; |
53 | |
54 | if (aResult.ShapeType()!=TopAbs_SOLID) |
55 | return 0; |
56 | |
57 | // |
58 | // 1. Map Of sources' subshapes . |
59 | // The map (aSourceShapeMap) is to prevent unnecessary coping |
60 | TopTools_IndexedMapOfShape aSourceShapeMap; |
61 | TopExp::MapShapes(myShape1, TopAbs_EDGE, aSourceShapeMap); |
62 | TopExp::MapShapes(myShape2, TopAbs_EDGE, aSourceShapeMap); |
63 | |
64 | TopTools_IndexedDataMapOfShapeShape EdMap; |
65 | BRep_Builder BB; |
66 | TopoDS_Shape aLocalShape = aResult.EmptyCopied(); |
67 | TopoDS_Solid aSolid=TopoDS::Solid(aLocalShape); |
68 | // TopoDS_Solid aSolid=TopoDS::Solid(aResult.EmptyCopied()); |
69 | |
70 | TopExp_Explorer anExpShells(aResult, TopAbs_SHELL); |
71 | for (; anExpShells.More(); anExpShells.Next()) { |
72 | const TopoDS_Shell& S=TopoDS::Shell(anExpShells.Current()); |
73 | aLocalShape = S.EmptyCopied(); |
74 | TopoDS_Shell aShell=TopoDS::Shell(aLocalShape); |
75 | // TopoDS_Shell aShell=TopoDS::Shell(S.EmptyCopied()); |
76 | |
77 | TopExp_Explorer anExpFaces(S, TopAbs_FACE); |
78 | for (; anExpFaces.More(); anExpFaces.Next()) { |
79 | TopoDS_Face F=TopoDS::Face(anExpFaces.Current()); |
80 | //modified by NIZHNY-MZV Mon Mar 27 09:51:59 2000 |
81 | TopAbs_Orientation Fori = F.Orientation(); |
82 | //we should explore FORWARD face |
83 | // F.Orientation(TopAbs_FORWARD); |
84 | aLocalShape = F.EmptyCopied(); |
85 | TopoDS_Face aFace=TopoDS::Face(aLocalShape); |
86 | // TopoDS_Face aFace=TopoDS::Face(F.EmptyCopied()); |
87 | |
88 | TopExp_Explorer anExpWires(F, TopAbs_WIRE); |
89 | for (; anExpWires.More(); anExpWires.Next()) { |
90 | TopoDS_Wire W=TopoDS::Wire(anExpWires.Current()); |
91 | //modified by NIZHNY-MZV Mon Mar 27 09:51:59 2000 |
92 | TopAbs_Orientation Wori = W.Orientation(); |
93 | |
94 | //we should explore FORWARD wire |
95 | // W.Orientation(TopAbs_FORWARD); |
96 | aLocalShape = W.EmptyCopied(); |
97 | TopoDS_Wire aWire = TopoDS::Wire(aLocalShape); |
98 | // TopoDS_Wire aWire = TopoDS::Wire(W.EmptyCopied()); |
99 | |
100 | TopExp_Explorer anExpEdges(W, TopAbs_EDGE); |
101 | for (; anExpEdges.More(); anExpEdges.Next()) { |
102 | TopoDS_Edge E = TopoDS::Edge(anExpEdges.Current()); |
103 | |
104 | if (EdMap.Contains(E)) { |
105 | TopoDS_Shape anEdge = EdMap.ChangeFromKey(E); |
106 | |
107 | anEdge.Orientation(E.Orientation()); |
108 | BB.Add (aWire, anEdge); |
109 | continue; |
110 | } |
111 | |
112 | |
113 | if (myMapOfCorrect2dEdges.Contains(E)) { |
114 | TopoDS_Shape anEdge=myMapOfCorrect2dEdges.ChangeFromKey(E); |
115 | |
116 | anEdge.Orientation(E.Orientation()); |
117 | BB.Add (aWire, anEdge); |
118 | EdMap.Add(E, anEdge); |
119 | continue; |
120 | } |
121 | |
122 | // add edges |
123 | TopoDS_Edge anEdge; |
124 | //we copy edge in order to not change it in source shapes |
125 | if(aSourceShapeMap.Contains(E)) { |
126 | TopoDS_Shape aLocalShape1 = E.EmptyCopied(); |
127 | anEdge = TopoDS::Edge(aLocalShape1); |
128 | // anEdge = TopoDS::Edge(E.EmptyCopied()); |
129 | |
130 | EdMap.Add(E, anEdge); |
131 | |
132 | TopExp_Explorer anExpVertices(E, TopAbs_VERTEX); |
133 | Standard_Boolean free = anEdge.Free(); |
134 | anEdge.Free(Standard_True); |
135 | for(; anExpVertices.More(); anExpVertices.Next()) |
136 | BB.Add(anEdge, anExpVertices.Current()); |
137 | |
138 | anEdge.Free(free); |
139 | } |
140 | else |
141 | anEdge = E; |
142 | |
143 | anEdge.Orientation(E.Orientation()); |
144 | BB.Add (aWire, anEdge); |
145 | } |
146 | // Add wires |
147 | aWire.Orientation(Wori); |
148 | BB.Add (aFace, aWire); |
149 | } |
150 | |
151 | aFace.Orientation(Fori); |
152 | BB.Add (aShell, aFace); |
153 | } |
154 | |
155 | aShell.Orientation(S.Orientation()); |
156 | BB.Add (aSolid, aShell); |
157 | } |
158 | aResult=aSolid; |
159 | |
160 | //update section curves |
161 | TopOpeBRepDS_CurveExplorer cex(myDataStructure->DS()); |
162 | for (; cex.More(); cex.Next()) { |
163 | Standard_Integer ic = cex.Index(); |
164 | TopTools_ListOfShape& LSE = ChangeNewEdges(ic); |
165 | TopTools_ListOfShape corrLSE; |
166 | TopTools_ListIteratorOfListOfShape it(LSE); |
167 | for(; it.More(); it.Next()) { |
168 | const TopoDS_Shape& E = it.Value(); |
169 | if(EdMap.Contains(E)) { |
170 | const TopoDS_Shape& newE = EdMap.FindFromKey(E); |
171 | corrLSE.Append(newE); |
172 | } |
173 | else |
174 | corrLSE.Append(E); |
175 | } |
176 | LSE.Clear(); |
177 | LSE.Append(corrLSE); |
178 | } |
179 | |
180 | |
181 | //update section edges |
182 | const TopOpeBRepDS_DataStructure& BDS = myDataStructure->DS(); |
183 | Standard_Integer i,nes = BDS.NbSectionEdges(); |
184 | |
185 | for(i = 1; i <= nes; i++) { |
186 | const TopoDS_Shape& es = BDS.SectionEdge(i); |
187 | if(es.IsNull()) |
188 | continue; |
189 | |
190 | for(Standard_Integer j = 0; j <= 2; j++) { |
191 | TopAbs_State staspl = TopAbs_State(j); // 0 - IN, 1 - OUT, 2 - ON |
192 | TopTools_ListOfShape& LSE = ChangeSplit(es,staspl); |
193 | TopTools_ListOfShape corrLSE; |
194 | TopTools_ListIteratorOfListOfShape it(LSE); |
195 | for(; it.More(); it.Next()) { |
196 | const TopoDS_Shape& E = it.Value(); |
197 | if(EdMap.Contains(E)) { |
198 | const TopoDS_Shape& newE = EdMap.FindFromKey(E); |
199 | corrLSE.Append(newE); |
200 | } |
201 | else |
202 | corrLSE.Append(E); |
203 | } |
204 | LSE.Clear(); |
205 | LSE.Append(corrLSE); |
206 | } |
207 | } |
208 | return 1; |
209 | } |