0031682: Visualization - Prs3d_ShadingAspect::SetTransparency() has no effect with...
[occt.git] / src / ShapeFix / ShapeFix_FreeBounds.cxx
1 // Created on: 1998-09-16
2 // Created by: Roman LYGIN
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 // 25.12.98 pdn: renaming methods GetWires and GetEdges to GetClosedWires
18 //               and GetOpenWires respectively
19
20 #include <BRep_Builder.hxx>
21 #include <ShapeAnalysis_FreeBounds.hxx>
22 #include <ShapeExtend_Explorer.hxx>
23 #include <ShapeFix_FreeBounds.hxx>
24 #include <TopExp_Explorer.hxx>
25 #include <TopoDS.hxx>
26 #include <TopoDS_Compound.hxx>
27 #include <TopoDS_Edge.hxx>
28 #include <TopoDS_Iterator.hxx>
29 #include <TopoDS_Shape.hxx>
30 #include <TopoDS_Vertex.hxx>
31 #include <TopTools_DataMapOfShapeShape.hxx>
32
33 //=======================================================================
34 //function : ShapeFix_FreeBounds
35 //purpose  : 
36 //=======================================================================
37 ShapeFix_FreeBounds::ShapeFix_FreeBounds()
38 : myShared(Standard_False),
39   mySewToler(0.0),
40   myCloseToler(0.0),
41   mySplitClosed(Standard_False),
42   mySplitOpen(Standard_False)
43 {
44 }
45
46 //=======================================================================
47 //function : ShapeFix_FreeBounds
48 //purpose  : 
49 //=======================================================================
50
51 ShapeFix_FreeBounds::ShapeFix_FreeBounds(const TopoDS_Shape& shape,
52                                          const Standard_Real sewtoler,
53                                          const Standard_Real closetoler,
54                                          const Standard_Boolean splitclosed,
55                                          const Standard_Boolean splitopen) :
56        myShared (Standard_False), mySewToler (sewtoler), myCloseToler (closetoler),
57        mySplitClosed (splitclosed), mySplitOpen (splitopen)
58 {
59   myShape = shape;
60   Perform();
61 }
62
63 //=======================================================================
64 //function : ShapeFix_FreeBounds
65 //purpose  : 
66 //=======================================================================
67
68 ShapeFix_FreeBounds::ShapeFix_FreeBounds(const TopoDS_Shape& shape,
69                                          const Standard_Real closetoler,
70                                          const Standard_Boolean splitclosed,
71                                          const Standard_Boolean splitopen):
72        myShared (Standard_True), mySewToler (0.), myCloseToler (closetoler),
73        mySplitClosed (splitclosed), mySplitOpen (splitopen)
74 {
75   myShape = shape;
76   Perform();
77 }
78
79 //=======================================================================
80 //function : Perform
81 //purpose  : 
82 //=======================================================================
83
84 Standard_Boolean ShapeFix_FreeBounds::Perform() 
85 {
86   ShapeAnalysis_FreeBounds safb;
87   if (myShared)
88     safb = ShapeAnalysis_FreeBounds (myShape, mySplitClosed, mySplitOpen);
89   else
90     safb = ShapeAnalysis_FreeBounds (myShape, mySewToler, mySplitClosed, mySplitOpen);
91   
92   myWires = safb.GetClosedWires();
93   myEdges = safb.GetOpenWires();
94   
95   if (myCloseToler > mySewToler) {
96     ShapeExtend_Explorer see;
97     Handle(TopTools_HSequenceOfShape) newwires,
98                                       open = see.SeqFromCompound (myEdges,
99                                                                   Standard_False);
100     TopTools_DataMapOfShapeShape vertices;
101     ShapeAnalysis_FreeBounds::ConnectWiresToWires (open, myCloseToler, myShared,
102                                                    newwires, vertices);
103     myEdges.Nullify();
104     ShapeAnalysis_FreeBounds::DispatchWires (newwires, myWires, myEdges);
105     
106     for( TopExp_Explorer exp (myShape, TopAbs_EDGE); exp.More(); exp.Next()) {
107       TopoDS_Edge Edge = TopoDS::Edge(exp.Current());
108       for( TopoDS_Iterator iter (Edge); iter.More(); iter.Next()) {
109         TopoDS_Vertex V = TopoDS::Vertex (iter.Value());
110         BRep_Builder B;
111         TopoDS_Vertex newV;
112         if( vertices.IsBound(V)) {
113           newV = TopoDS::Vertex (vertices.Find(V));
114           newV.Orientation(V.Orientation());
115           B.Remove(Edge, V);
116           B.Add(Edge, newV);
117         }
118       }
119     }
120   }
121   return Standard_True;
122 }