0030675: Visualization - remove redundant proxy classes in hierarchy of PrsMgr_Presen...
[occt.git] / src / TopOpeBRepBuild / TopOpeBRepBuild_Builder1_2.cxx
CommitLineData
b311480e 1// Created on: 2000-02-01
2// Created by: Peter KURNEV
973c2be1 3// Copyright (c) 2000-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
7fd59977 15
7fd59977 16
42cf5bc1 17#include <BRep_Builder.hxx>
7fd59977 18#include <TopExp.hxx>
19#include <TopExp_Explorer.hxx>
7fd59977 20#include <TopoDS.hxx>
42cf5bc1 21#include <TopoDS_Edge.hxx>
7fd59977 22#include <TopoDS_Face.hxx>
42cf5bc1 23#include <TopoDS_Shape.hxx>
7fd59977 24#include <TopoDS_Shell.hxx>
42cf5bc1 25#include <TopoDS_Solid.hxx>
7fd59977 26#include <TopoDS_Vertex.hxx>
42cf5bc1 27#include <TopoDS_Wire.hxx>
28#include <TopOpeBRepBuild_Builder1.hxx>
29#include <TopOpeBRepBuild_GTopo.hxx>
30#include <TopOpeBRepBuild_HBuilder.hxx>
31#include <TopOpeBRepBuild_PaveSet.hxx>
32#include <TopOpeBRepBuild_ShellFaceSet.hxx>
33#include <TopOpeBRepBuild_WireEdgeSet.hxx>
34#include <TopOpeBRepDS_BuildTool.hxx>
7fd59977 35#include <TopOpeBRepDS_CurveExplorer.hxx>
42cf5bc1 36#include <TopOpeBRepDS_HDataStructure.hxx>
37#include <TopTools_IndexedDataMapOfShapeShape.hxx>
38#include <TopTools_IndexedMapOfShape.hxx>
39#include <TopTools_ListIteratorOfListOfShape.hxx>
40#include <TopTools_ListOfShape.hxx>
7fd59977 41
42//=======================================================================
43//function : TopOpeBRepBuild_Builder1::CorrectResult2d
44//purpose : Change the Result (after CorrectFace2d)
7fd59977 45//=======================================================================
b311480e 46Standard_Integer TopOpeBRepBuild_Builder1::CorrectResult2d(TopoDS_Shape& aResult)
7fd59977 47
48{
49 Standard_Integer aNb=myMapOfCorrect2dEdges.Extent();
50 if(!aNb)
51 return 0;
52
53 if (aResult.ShapeType()!=TopAbs_SOLID)
54 return 0;
55
56 //
57 // 1. Map Of sources' subshapes .
58 // The map (aSourceShapeMap) is to prevent unnecessary coping
59 TopTools_IndexedMapOfShape aSourceShapeMap;
60 TopExp::MapShapes(myShape1, TopAbs_EDGE, aSourceShapeMap);
61 TopExp::MapShapes(myShape2, TopAbs_EDGE, aSourceShapeMap);
62
63 TopTools_IndexedDataMapOfShapeShape EdMap;
64 BRep_Builder BB;
65 TopoDS_Shape aLocalShape = aResult.EmptyCopied();
66 TopoDS_Solid aSolid=TopoDS::Solid(aLocalShape);
67 // TopoDS_Solid aSolid=TopoDS::Solid(aResult.EmptyCopied());
68
69 TopExp_Explorer anExpShells(aResult, TopAbs_SHELL);
70 for (; anExpShells.More(); anExpShells.Next()) {
71 const TopoDS_Shell& S=TopoDS::Shell(anExpShells.Current());
72 aLocalShape = S.EmptyCopied();
73 TopoDS_Shell aShell=TopoDS::Shell(aLocalShape);
74 // TopoDS_Shell aShell=TopoDS::Shell(S.EmptyCopied());
75
76 TopExp_Explorer anExpFaces(S, TopAbs_FACE);
77 for (; anExpFaces.More(); anExpFaces.Next()) {
78 TopoDS_Face F=TopoDS::Face(anExpFaces.Current());
79 //modified by NIZHNY-MZV Mon Mar 27 09:51:59 2000
80 TopAbs_Orientation Fori = F.Orientation();
81 //we should explore FORWARD face
82// F.Orientation(TopAbs_FORWARD);
83 aLocalShape = F.EmptyCopied();
84 TopoDS_Face aFace=TopoDS::Face(aLocalShape);
85 // TopoDS_Face aFace=TopoDS::Face(F.EmptyCopied());
86
87 TopExp_Explorer anExpWires(F, TopAbs_WIRE);
88 for (; anExpWires.More(); anExpWires.Next()) {
89 TopoDS_Wire W=TopoDS::Wire(anExpWires.Current());
90 //modified by NIZHNY-MZV Mon Mar 27 09:51:59 2000
91 TopAbs_Orientation Wori = W.Orientation();
92
93 //we should explore FORWARD wire
94// W.Orientation(TopAbs_FORWARD);
95 aLocalShape = W.EmptyCopied();
96 TopoDS_Wire aWire = TopoDS::Wire(aLocalShape);
97 // TopoDS_Wire aWire = TopoDS::Wire(W.EmptyCopied());
98
99 TopExp_Explorer anExpEdges(W, TopAbs_EDGE);
100 for (; anExpEdges.More(); anExpEdges.Next()) {
101 TopoDS_Edge E = TopoDS::Edge(anExpEdges.Current());
102
103 if (EdMap.Contains(E)) {
104 TopoDS_Shape anEdge = EdMap.ChangeFromKey(E);
105
106 anEdge.Orientation(E.Orientation());
107 BB.Add (aWire, anEdge);
108 continue;
109 }
110
111
112 if (myMapOfCorrect2dEdges.Contains(E)) {
113 TopoDS_Shape anEdge=myMapOfCorrect2dEdges.ChangeFromKey(E);
114
115 anEdge.Orientation(E.Orientation());
116 BB.Add (aWire, anEdge);
117 EdMap.Add(E, anEdge);
118 continue;
119 }
120
121 // add edges
122 TopoDS_Edge anEdge;
123 //we copy edge in order to not change it in source shapes
124 if(aSourceShapeMap.Contains(E)) {
125 TopoDS_Shape aLocalShape1 = E.EmptyCopied();
126 anEdge = TopoDS::Edge(aLocalShape1);
127 // anEdge = TopoDS::Edge(E.EmptyCopied());
128
129 EdMap.Add(E, anEdge);
130
131 TopExp_Explorer anExpVertices(E, TopAbs_VERTEX);
132 Standard_Boolean free = anEdge.Free();
133 anEdge.Free(Standard_True);
134 for(; anExpVertices.More(); anExpVertices.Next())
135 BB.Add(anEdge, anExpVertices.Current());
136
137 anEdge.Free(free);
138 }
139 else
140 anEdge = E;
141
142 anEdge.Orientation(E.Orientation());
143 BB.Add (aWire, anEdge);
144 }
145 // Add wires
146 aWire.Orientation(Wori);
ab860031 147 aWire.Closed (BRep_Tool::IsClosed (aWire));
7fd59977 148 BB.Add (aFace, aWire);
149 }
150
151 aFace.Orientation(Fori);
152 BB.Add (aShell, aFace);
153 }
154
155 aShell.Orientation(S.Orientation());
ab860031 156 aShell.Closed (BRep_Tool::IsClosed(aShell));
7fd59977 157 BB.Add (aSolid, aShell);
158 }
159 aResult=aSolid;
160
161 //update section curves
162 TopOpeBRepDS_CurveExplorer cex(myDataStructure->DS());
163 for (; cex.More(); cex.Next()) {
164 Standard_Integer ic = cex.Index();
165 TopTools_ListOfShape& LSE = ChangeNewEdges(ic);
166 TopTools_ListOfShape corrLSE;
167 TopTools_ListIteratorOfListOfShape it(LSE);
168 for(; it.More(); it.Next()) {
169 const TopoDS_Shape& E = it.Value();
170 if(EdMap.Contains(E)) {
171 const TopoDS_Shape& newE = EdMap.FindFromKey(E);
172 corrLSE.Append(newE);
173 }
174 else
175 corrLSE.Append(E);
176 }
177 LSE.Clear();
178 LSE.Append(corrLSE);
179 }
180
181
182 //update section edges
183 const TopOpeBRepDS_DataStructure& BDS = myDataStructure->DS();
184 Standard_Integer i,nes = BDS.NbSectionEdges();
185
186 for(i = 1; i <= nes; i++) {
187 const TopoDS_Shape& es = BDS.SectionEdge(i);
188 if(es.IsNull())
189 continue;
190
191 for(Standard_Integer j = 0; j <= 2; j++) {
192 TopAbs_State staspl = TopAbs_State(j); // 0 - IN, 1 - OUT, 2 - ON
193 TopTools_ListOfShape& LSE = ChangeSplit(es,staspl);
194 TopTools_ListOfShape corrLSE;
195 TopTools_ListIteratorOfListOfShape it(LSE);
196 for(; it.More(); it.Next()) {
197 const TopoDS_Shape& E = it.Value();
198 if(EdMap.Contains(E)) {
199 const TopoDS_Shape& newE = EdMap.FindFromKey(E);
200 corrLSE.Append(newE);
201 }
202 else
203 corrLSE.Append(E);
204 }
205 LSE.Clear();
206 LSE.Append(corrLSE);
207 }
208 }
209 return 1;
210}