1 // Created on: 2000-02-01
2 // Created by: Peter KURNEV
3 // Copyright (c) 2000-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <TopOpeBRepBuild_Builder1.ixx>
19 #include <TopExp_Explorer.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>
30 #include <BRep_Builder.hxx>
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>
38 //=======================================================================
39 //function : TopOpeBRepBuild_Builder1::CorrectResult2d
40 //purpose : Change the Result (after CorrectFace2d)
41 //=======================================================================
42 Standard_Integer TopOpeBRepBuild_Builder1::CorrectResult2d(TopoDS_Shape& aResult)
45 Standard_Integer aNb=myMapOfCorrect2dEdges.Extent();
49 if (aResult.ShapeType()!=TopAbs_SOLID)
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);
59 TopTools_IndexedDataMapOfShapeShape EdMap;
61 TopoDS_Shape aLocalShape = aResult.EmptyCopied();
62 TopoDS_Solid aSolid=TopoDS::Solid(aLocalShape);
63 // TopoDS_Solid aSolid=TopoDS::Solid(aResult.EmptyCopied());
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());
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());
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();
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());
95 TopExp_Explorer anExpEdges(W, TopAbs_EDGE);
96 for (; anExpEdges.More(); anExpEdges.Next()) {
97 TopoDS_Edge E = TopoDS::Edge(anExpEdges.Current());
99 if (EdMap.Contains(E)) {
100 TopoDS_Shape anEdge = EdMap.ChangeFromKey(E);
102 anEdge.Orientation(E.Orientation());
103 BB.Add (aWire, anEdge);
108 if (myMapOfCorrect2dEdges.Contains(E)) {
109 TopoDS_Shape anEdge=myMapOfCorrect2dEdges.ChangeFromKey(E);
111 anEdge.Orientation(E.Orientation());
112 BB.Add (aWire, anEdge);
113 EdMap.Add(E, 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());
125 EdMap.Add(E, anEdge);
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());
138 anEdge.Orientation(E.Orientation());
139 BB.Add (aWire, anEdge);
142 aWire.Orientation(Wori);
143 BB.Add (aFace, aWire);
146 aFace.Orientation(Fori);
147 BB.Add (aShell, aFace);
150 aShell.Orientation(S.Orientation());
151 BB.Add (aSolid, aShell);
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);
176 //update section edges
177 const TopOpeBRepDS_DataStructure& BDS = myDataStructure->DS();
178 Standard_Integer i,nes = BDS.NbSectionEdges();
180 for(i = 1; i <= nes; i++) {
181 const TopoDS_Shape& es = BDS.SectionEdge(i);
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);