1 // Created on: 2000-02-01
2 // Created by: Peter KURNEV
3 // Copyright (c) 2000-2012 OPEN CASCADE SAS
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.
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.
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.
21 #include <TopOpeBRepBuild_Builder1.ixx>
24 #include <TopExp_Explorer.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>
35 #include <BRep_Builder.hxx>
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>
43 //=======================================================================
44 //function : TopOpeBRepBuild_Builder1::CorrectResult2d
45 //purpose : Change the Result (after CorrectFace2d)
46 //=======================================================================
47 Standard_Integer TopOpeBRepBuild_Builder1::CorrectResult2d(TopoDS_Shape& aResult)
50 Standard_Integer aNb=myMapOfCorrect2dEdges.Extent();
54 if (aResult.ShapeType()!=TopAbs_SOLID)
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);
64 TopTools_IndexedDataMapOfShapeShape EdMap;
66 TopoDS_Shape aLocalShape = aResult.EmptyCopied();
67 TopoDS_Solid aSolid=TopoDS::Solid(aLocalShape);
68 // TopoDS_Solid aSolid=TopoDS::Solid(aResult.EmptyCopied());
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());
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());
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();
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());
100 TopExp_Explorer anExpEdges(W, TopAbs_EDGE);
101 for (; anExpEdges.More(); anExpEdges.Next()) {
102 TopoDS_Edge E = TopoDS::Edge(anExpEdges.Current());
104 if (EdMap.Contains(E)) {
105 TopoDS_Shape anEdge = EdMap.ChangeFromKey(E);
107 anEdge.Orientation(E.Orientation());
108 BB.Add (aWire, anEdge);
113 if (myMapOfCorrect2dEdges.Contains(E)) {
114 TopoDS_Shape anEdge=myMapOfCorrect2dEdges.ChangeFromKey(E);
116 anEdge.Orientation(E.Orientation());
117 BB.Add (aWire, anEdge);
118 EdMap.Add(E, 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());
130 EdMap.Add(E, anEdge);
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());
143 anEdge.Orientation(E.Orientation());
144 BB.Add (aWire, anEdge);
147 aWire.Orientation(Wori);
148 BB.Add (aFace, aWire);
151 aFace.Orientation(Fori);
152 BB.Add (aShell, aFace);
155 aShell.Orientation(S.Orientation());
156 BB.Add (aSolid, aShell);
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);
181 //update section edges
182 const TopOpeBRepDS_DataStructure& BDS = myDataStructure->DS();
183 Standard_Integer i,nes = BDS.NbSectionEdges();
185 for(i = 1; i <= nes; i++) {
186 const TopoDS_Shape& es = BDS.SectionEdge(i);
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);