b311480e |
1 | // Created on: 1993-10-11 |
2 | // Created by: Christophe MARION |
3 | // Copyright (c) 1993-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
733a0e55 |
16 | |
7fd59977 |
17 | // Modified by cma, Fri Nov 10 17:36:13 1995 |
18 | |
7fd59977 |
19 | #include <BRep_Builder.hxx> |
20 | #include <BRepLib_MakeEdge2d.hxx> |
42cf5bc1 |
21 | #include <HLRAlgo_EdgeIterator.hxx> |
22 | #include <HLRAlgo_EdgeStatus.hxx> |
7fd59977 |
23 | #include <HLRBRep_BiPnt2D.hxx> |
24 | #include <HLRBRep_ListIteratorOfListOfBPnt2D.hxx> |
42cf5bc1 |
25 | #include <HLRBRep_PolyAlgo.hxx> |
26 | #include <HLRBRep_PolyHLRToShape.hxx> |
27 | #include <TopExp_Explorer.hxx> |
28 | #include <TopoDS.hxx> |
29 | #include <TopoDS_Shape.hxx> |
30 | #include <TopTools_MapOfShape.hxx> |
7fd59977 |
31 | |
7fd59977 |
32 | //======================================================================= |
33 | //function : HLRBRep_PolyHLRToShape |
34 | //purpose : |
35 | //======================================================================= |
36 | |
37 | HLRBRep_PolyHLRToShape::HLRBRep_PolyHLRToShape () |
38 | {} |
39 | |
40 | //======================================================================= |
41 | //function : Update |
42 | //purpose : |
43 | //======================================================================= |
44 | |
45 | void HLRBRep_PolyHLRToShape::Update (const Handle(HLRBRep_PolyAlgo)& A) |
46 | { |
47 | myAlgo = A; |
48 | myHideMode = Standard_True; |
681f3919 |
49 | Standard_Real sta,end; |
7fd59977 |
50 | Standard_ShortReal tolsta,tolend; |
51 | HLRAlgo_EdgeIterator It; |
52 | myBiPntVis.Clear(); |
53 | myBiPntHid.Clear(); |
54 | TopoDS_Shape S; |
55 | Standard_Boolean reg1,regn,outl,intl; |
56 | const gp_Trsf& T = myAlgo->Projector().Transformation(); |
57 | HLRAlgo_EdgeStatus status; |
7fd59977 |
58 | |
59 | for (myAlgo->InitHide(); myAlgo->MoreHide(); myAlgo->NextHide()) { |
681f3919 |
60 | HLRAlgo_BiPoint::PointsT& aPoints = myAlgo->Hide(status,S,reg1,regn,outl,intl); |
61 | gp_XYZ aSta = aPoints.Pnt1; |
62 | gp_XYZ aEnd = aPoints.Pnt2; |
63 | T.Transforms(aSta); |
64 | T.Transforms(aEnd); |
65 | const gp_XY aSta2D(aSta.X(), aSta.Y()); |
66 | const gp_XY aEnd2D(aEnd.X(), aEnd.Y()); |
67 | const gp_XY aD = aEnd2D - aSta2D; |
68 | if (aD.Modulus() > 1.e-10) { |
7fd59977 |
69 | |
70 | for (It.InitVisible(status); |
71 | It.MoreVisible(); |
72 | It.NextVisible()) { |
73 | It.Visible(sta,tolsta,end,tolend); |
74 | myBiPntVis.Append |
75 | (HLRBRep_BiPnt2D |
681f3919 |
76 | (aSta2D + sta * aD, aSta2D + end * aD, |
7fd59977 |
77 | S,reg1,regn,outl,intl)); |
78 | } |
79 | |
80 | for (It.InitHidden(status); |
81 | It.MoreHidden(); |
82 | It.NextHidden()) { |
83 | It.Hidden(sta,tolsta,end,tolend); |
84 | myBiPntHid.Append |
85 | (HLRBRep_BiPnt2D |
681f3919 |
86 | (aSta2D + sta * aD, aSta2D + end * aD, |
7fd59977 |
87 | S,reg1,regn,outl,intl)); |
88 | } |
89 | } |
90 | } |
91 | } |
92 | |
93 | //======================================================================= |
94 | //function : InternalCompound |
95 | //purpose : |
96 | //======================================================================= |
97 | |
98 | TopoDS_Shape |
99 | HLRBRep_PolyHLRToShape::InternalCompound (const Standard_Integer typ, |
100 | const Standard_Boolean visible, |
101 | const TopoDS_Shape& S) |
102 | { |
103 | TopTools_MapOfShape Map; |
104 | if (!S.IsNull()) { |
105 | TopExp_Explorer ex; |
106 | for (ex.Init(S,TopAbs_EDGE); ex.More(); ex.Next()) |
107 | Map.Add(ex.Current()); |
108 | for (ex.Init(S,TopAbs_FACE); ex.More(); ex.Next()) |
109 | Map.Add(ex.Current()); |
110 | } |
111 | Standard_Boolean todraw,reg1,regn,outl,intl; |
112 | Standard_Boolean added = Standard_False; |
113 | TopoDS_Shape Result; |
114 | BRep_Builder B; |
115 | B.MakeCompound(TopoDS::Compound(Result)); |
116 | |
117 | if (myHideMode) { |
118 | HLRBRep_ListIteratorOfListOfBPnt2D It; |
119 | if (visible) It.Initialize(myBiPntVis); |
120 | else It.Initialize(myBiPntHid); |
121 | |
122 | for (; It.More(); It.Next()) { |
123 | const HLRBRep_BiPnt2D& BP = It.Value(); |
124 | reg1 = BP.Rg1Line(); |
125 | regn = BP.RgNLine(); |
126 | outl = BP.OutLine(); |
127 | intl = BP.IntLine(); |
128 | if (typ == 1) todraw = intl; |
129 | else if (typ == 2) todraw = reg1 && !regn && !outl; |
130 | else if (typ == 3) todraw = regn && !outl; |
131 | else todraw = !(intl || (reg1 && !outl)); |
132 | if (todraw) |
133 | if (!S.IsNull()) todraw = Map.Contains(BP.Shape()); |
134 | if (todraw) { |
1fae7cda |
135 | const gp_Pnt2d& FirstP2d = BP.P1(); |
136 | const gp_Pnt2d& LastP2d = BP.P2(); |
137 | if (FirstP2d.SquareDistance(LastP2d) > 1.e-20) |
138 | { |
139 | B.Add(Result,BRepLib_MakeEdge2d(BP.P1(),BP.P2())); |
140 | added = Standard_True; |
141 | } |
7fd59977 |
142 | } |
143 | } |
144 | } |
145 | else { |
146 | const gp_Trsf& T = myAlgo->Projector().Transformation(); |
147 | TopoDS_Shape SBP; |
7fd59977 |
148 | |
149 | for (myAlgo->InitShow(); myAlgo->MoreShow(); myAlgo->NextShow()) { |
681f3919 |
150 | HLRAlgo_BiPoint::PointsT& aPoints = myAlgo->Show(SBP,reg1,regn,outl,intl); |
7fd59977 |
151 | if (typ == 1) todraw = intl; |
152 | else if (typ == 2) todraw = reg1 && !regn && !outl; |
153 | else if (typ == 3) todraw = regn && !outl; |
154 | else todraw = !(intl || (reg1 && !outl)); |
155 | if (todraw) |
156 | if (!S.IsNull()) todraw = Map.Contains(SBP); |
157 | if (todraw) { |
681f3919 |
158 | gp_XYZ aSta = aPoints.Pnt1, aEnd = aPoints.Pnt2; |
159 | T.Transforms(aSta); |
160 | T.Transforms(aEnd); |
161 | const gp_XY aSta2D(aSta.X(), aSta.Y()); |
162 | const gp_XY aEnd2D(aEnd.X(), aEnd.Y()); |
163 | const gp_XY aD = aEnd2D - aSta2D; |
1fae7cda |
164 | if (aD.SquareModulus() > 1.e-20) { |
681f3919 |
165 | B.Add(Result,BRepLib_MakeEdge2d(aSta2D, aEnd2D)); |
7fd59977 |
166 | added = Standard_True; |
167 | } |
168 | } |
169 | } |
170 | } |
171 | if (!added) Result = TopoDS_Shape(); |
172 | return Result; |
173 | } |