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 under
8 // the terms of the GNU Lesser General Public License 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.
19 #include <TopoDS_Shape.hxx>
20 #include <TopOpeBRepBuild_GTopo.hxx>
21 #include <TopOpeBRepBuild_HBuilder.hxx>
22 #include <TopOpeBRepBuild_PaveSet.hxx>
23 #include <TopOpeBRepBuild_WireEdgeSet.hxx>
24 #include <TopOpeBRepDS_CurveExplorer.hxx>
25 #include <TopOpeBRepDS_HDataStructure.hxx>
26 #include <TopTools_IndexedDataMapOfShapeShape.hxx>
27 #include <TopTools_IndexedMapOfShape.hxx>
28 #include <TopTools_ListOfShape.hxx>
30 //=======================================================================
31 //function : TopOpeBRepBuild_Builder1::CorrectResult2d
32 //purpose : Change the Result (after CorrectFace2d)
33 //=======================================================================
34 Standard_Integer TopOpeBRepBuild_Builder1::CorrectResult2d(TopoDS_Shape& aResult)
37 Standard_Integer aNb=myMapOfCorrect2dEdges.Extent();
41 if (aResult.ShapeType()!=TopAbs_SOLID)
45 // 1. Map Of sources' subshapes .
46 // The map (aSourceShapeMap) is to prevent unnecessary coping
47 TopTools_IndexedMapOfShape aSourceShapeMap;
48 TopExp::MapShapes(myShape1, TopAbs_EDGE, aSourceShapeMap);
49 TopExp::MapShapes(myShape2, TopAbs_EDGE, aSourceShapeMap);
51 TopTools_IndexedDataMapOfShapeShape EdMap;
53 TopoDS_Shape aLocalShape = aResult.EmptyCopied();
54 TopoDS_Solid aSolid=TopoDS::Solid(aLocalShape);
55 // TopoDS_Solid aSolid=TopoDS::Solid(aResult.EmptyCopied());
57 TopExp_Explorer anExpShells(aResult, TopAbs_SHELL);
58 for (; anExpShells.More(); anExpShells.Next()) {
59 const TopoDS_Shell& S=TopoDS::Shell(anExpShells.Current());
60 aLocalShape = S.EmptyCopied();
61 TopoDS_Shell aShell=TopoDS::Shell(aLocalShape);
62 // TopoDS_Shell aShell=TopoDS::Shell(S.EmptyCopied());
64 TopExp_Explorer anExpFaces(S, TopAbs_FACE);
65 for (; anExpFaces.More(); anExpFaces.Next()) {
66 TopoDS_Face F=TopoDS::Face(anExpFaces.Current());
67 //modified by NIZHNY-MZV Mon Mar 27 09:51:59 2000
68 TopAbs_Orientation Fori = F.Orientation();
69 //we should explore FORWARD face
70 // F.Orientation(TopAbs_FORWARD);
71 aLocalShape = F.EmptyCopied();
72 TopoDS_Face aFace=TopoDS::Face(aLocalShape);
73 // TopoDS_Face aFace=TopoDS::Face(F.EmptyCopied());
75 TopExp_Explorer anExpWires(F, TopAbs_WIRE);
76 for (; anExpWires.More(); anExpWires.Next()) {
77 TopoDS_Wire W=TopoDS::Wire(anExpWires.Current());
78 //modified by NIZHNY-MZV Mon Mar 27 09:51:59 2000
79 TopAbs_Orientation Wori = W.Orientation();
81 //we should explore FORWARD wire
82 // W.Orientation(TopAbs_FORWARD);
83 aLocalShape = W.EmptyCopied();
84 TopoDS_Wire aWire = TopoDS::Wire(aLocalShape);
85 // TopoDS_Wire aWire = TopoDS::Wire(W.EmptyCopied());
87 TopExp_Explorer anExpEdges(W, TopAbs_EDGE);
88 for (; anExpEdges.More(); anExpEdges.Next()) {
89 TopoDS_Edge E = TopoDS::Edge(anExpEdges.Current());
91 if (EdMap.Contains(E)) {
92 TopoDS_Shape anEdge = EdMap.ChangeFromKey(E);
94 anEdge.Orientation(E.Orientation());
95 BB.Add (aWire, anEdge);
100 if (myMapOfCorrect2dEdges.Contains(E)) {
101 TopoDS_Shape anEdge=myMapOfCorrect2dEdges.ChangeFromKey(E);
103 anEdge.Orientation(E.Orientation());
104 BB.Add (aWire, anEdge);
105 EdMap.Add(E, anEdge);
111 //we copy edge in order to not change it in source shapes
112 if(aSourceShapeMap.Contains(E)) {
113 TopoDS_Shape aLocalShape1 = E.EmptyCopied();
114 anEdge = TopoDS::Edge(aLocalShape1);
115 // anEdge = TopoDS::Edge(E.EmptyCopied());
117 EdMap.Add(E, anEdge);
119 TopExp_Explorer anExpVertices(E, TopAbs_VERTEX);
120 Standard_Boolean free = anEdge.Free();
121 anEdge.Free(Standard_True);
122 for(; anExpVertices.More(); anExpVertices.Next())
123 BB.Add(anEdge, anExpVertices.Current());
130 anEdge.Orientation(E.Orientation());
131 BB.Add (aWire, anEdge);
134 aWire.Orientation(Wori);
135 aWire.Closed (BRep_Tool::IsClosed (aWire));
136 BB.Add (aFace, aWire);
139 aFace.Orientation(Fori);
140 BB.Add (aShell, aFace);
143 aShell.Orientation(S.Orientation());
144 aShell.Closed (BRep_Tool::IsClosed(aShell));
145 BB.Add (aSolid, aShell);
149 //update section curves
150 TopOpeBRepDS_CurveExplorer cex(myDataStructure->DS());
151 for (; cex.More(); cex.Next()) {
152 Standard_Integer ic = cex.Index();
153 TopTools_ListOfShape& LSE = ChangeNewEdges(ic);
154 TopTools_ListOfShape corrLSE;
155 TopTools_ListIteratorOfListOfShape it(LSE);
156 for(; it.More(); it.Next()) {
157 const TopoDS_Shape& E = it.Value();
158 if(EdMap.Contains(E)) {
159 const TopoDS_Shape& newE = EdMap.FindFromKey(E);
160 corrLSE.Append(newE);
170 //update section edges
171 const TopOpeBRepDS_DataStructure& BDS = myDataStructure->DS();
172 Standard_Integer i,nes = BDS.NbSectionEdges();
174 for(i = 1; i <= nes; i++) {
175 const TopoDS_Shape& es = BDS.SectionEdge(i);
179 for(Standard_Integer j = 0; j <= 2; j++) {
180 TopAbs_State staspl = TopAbs_State(j); // 0 - IN, 1 - OUT, 2 - ON
181 TopTools_ListOfShape& LSE = ChangeSplit(es,staspl);
182 TopTools_ListOfShape corrLSE;
183 TopTools_ListIteratorOfListOfShape it(LSE);
184 for(; it.More(); it.Next()) {
185 const TopoDS_Shape& E = it.Value();
186 if(EdMap.Contains(E)) {
187 const TopoDS_Shape& newE = EdMap.FindFromKey(E);
188 corrLSE.Append(newE);