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