b311480e |
1 | // Created on: 1995-09-22 |
2 | // Created by: Remi LEQUETTE |
3 | // Copyright (c) 1995-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. |
7fd59977 |
16 | |
42cf5bc1 |
17 | |
18 | #include <DBRep_HideData.hxx> |
19 | #include <Draw_Color.hxx> |
20 | #include <Draw_Display.hxx> |
21 | #include <gp_Trsf.hxx> |
7fd59977 |
22 | #include <HLRAlgo_EdgeIterator.hxx> |
23 | #include <HLRBRep_BiPoint.hxx> |
24 | #include <HLRBRep_ListIteratorOfListOfBPoint.hxx> |
42cf5bc1 |
25 | #include <HLRBRep_PolyAlgo.hxx> |
26 | #include <TopoDS_Shape.hxx> |
7fd59977 |
27 | |
28 | #define PntX1 ((Standard_Real*)Coordinates)[0] |
29 | #define PntY1 ((Standard_Real*)Coordinates)[1] |
30 | #define PntZ1 ((Standard_Real*)Coordinates)[2] |
31 | #define PntX2 ((Standard_Real*)Coordinates)[3] |
32 | #define PntY2 ((Standard_Real*)Coordinates)[4] |
33 | #define PntZ2 ((Standard_Real*)Coordinates)[5] |
34 | |
35 | //======================================================================= |
36 | //function : DBRep_HideData |
37 | //purpose : |
38 | //======================================================================= |
39 | |
40 | DBRep_HideData::DBRep_HideData() |
41 | {} |
42 | |
43 | //======================================================================= |
44 | //function : Set |
45 | //purpose : |
46 | //======================================================================= |
47 | |
48 | void DBRep_HideData::Set(const Standard_Integer viewID, |
49 | const gp_Trsf& TProj, |
50 | const Standard_Real focal, |
51 | const TopoDS_Shape& S, |
52 | const Standard_Real ang) |
53 | { |
54 | myView = viewID; |
55 | myTrsf = TProj; |
56 | myFocal = focal; |
57 | myAngle = ang; |
58 | |
59 | Handle(HLRBRep_PolyAlgo) hider = new HLRBRep_PolyAlgo(S); |
7fd59977 |
60 | hider->Projector(HLRAlgo_Projector(myTrsf,myFocal > 0.,myFocal)); |
61 | hider->Update(); |
62 | |
63 | Standard_Real sta,end,dx,dy,dz; |
64 | Standard_ShortReal tolsta,tolend; |
65 | HLRAlgo_EdgeIterator It; |
66 | myBiPntVis.Clear(); |
67 | myBiPntHid.Clear(); |
68 | TopoDS_Shape Sori; |
69 | Standard_Boolean reg1,regn,outl,intl; |
70 | Standard_Address Coordinates; |
71 | HLRAlgo_EdgeStatus status; |
72 | |
73 | for (hider->InitHide(); hider->MoreHide(); hider->NextHide()) { |
681f3919 |
74 | Coordinates = &hider->Hide(status,Sori,reg1,regn,outl,intl); |
7fd59977 |
75 | dx = PntX2 - PntX1; |
76 | dy = PntY2 - PntY1; |
77 | dz = PntZ2 - PntZ1; |
78 | |
79 | for (It.InitVisible(status); |
80 | It.MoreVisible(); |
81 | It.NextVisible()) { |
82 | It.Visible(sta,tolsta,end,tolend); |
83 | myBiPntVis.Append |
84 | (HLRBRep_BiPoint |
85 | (PntX1 + sta * dx,PntY1 + sta * dy,PntZ1 + sta * dz, |
86 | PntX1 + end * dx,PntY1 + end * dy,PntZ1 + end * dz, |
87 | Sori,reg1,regn,outl,intl)); |
88 | } |
89 | |
90 | for (It.InitHidden(status); |
91 | It.MoreHidden(); |
92 | It.NextHidden()) { |
93 | It.Hidden(sta,tolsta,end,tolend); |
94 | myBiPntHid.Append |
95 | (HLRBRep_BiPoint |
96 | (PntX1 + sta * dx,PntY1 + sta * dy,PntZ1 + sta * dz, |
97 | PntX1 + end * dx,PntY1 + end * dy,PntZ1 + end * dz, |
98 | Sori,reg1,regn,outl,intl)); |
99 | } |
100 | } |
101 | } |
102 | |
103 | //======================================================================= |
104 | //function : IsSame |
105 | //purpose : |
106 | //======================================================================= |
107 | |
108 | Standard_Boolean DBRep_HideData::IsSame(const gp_Trsf& TProj, |
109 | const Standard_Real focal) const |
110 | { |
111 | if (focal > 0) { |
112 | if (myFocal <= 0) return Standard_False; |
113 | if (myFocal != focal) return Standard_False; |
114 | const gp_XYZ& T1 = TProj .TranslationPart(); |
115 | const gp_XYZ& T2 = myTrsf.TranslationPart(); |
116 | |
117 | for (Standard_Integer i = 1; i <= 3; i++) { |
118 | if (T1.Coord(i) != T2.Coord(i)) |
119 | return Standard_False; |
120 | } |
121 | } |
122 | const gp_Mat& M1 = TProj .HVectorialPart(); |
123 | const gp_Mat& M2 = myTrsf.HVectorialPart(); |
124 | |
125 | for (Standard_Integer i = 1; i <= 3; i++) { |
126 | |
127 | for (Standard_Integer j = 1; j <= 3; j++) { |
128 | if (M1.Value(i,j) != M2.Value(i,j)) |
129 | return Standard_False; |
130 | } |
131 | } |
132 | return Standard_True; |
133 | } |
134 | |
135 | //======================================================================= |
136 | //function : DrawOn |
137 | //purpose : |
138 | //======================================================================= |
139 | |
140 | void DBRep_HideData::DrawOn(Draw_Display& D, |
141 | const Standard_Boolean withRg1, |
142 | const Standard_Boolean withRgN, |
143 | const Standard_Boolean withHid, |
144 | const Draw_Color& VisCol, |
145 | const Draw_Color& HidCol) |
146 | { |
147 | Standard_Boolean firstPick = Standard_True; |
148 | HLRBRep_ListIteratorOfListOfBPoint It; |
149 | // Standard_Boolean reg1,regn,outl; |
150 | |
151 | if (withHid) { |
152 | D.SetColor(HidCol); |
153 | |
154 | for (It.Initialize(myBiPntHid); |
155 | It.More(); |
156 | It.Next()) { |
157 | const HLRBRep_BiPoint& BP = It.Value(); |
158 | Standard_Boolean todraw = Standard_True; |
159 | if ((!withRg1 && BP.Rg1Line() && !BP.OutLine()) || |
160 | (!withRgN && BP.RgNLine() && !BP.OutLine())) |
161 | todraw = Standard_False; |
162 | if (todraw) { |
163 | D.MoveTo(BP.P1()); |
164 | D.DrawTo(BP.P2()); |
165 | if (firstPick && D.HasPicked()) { |
166 | firstPick = Standard_False; |
167 | myPickShap = BP.Shape(); |
168 | } |
169 | } |
170 | } |
171 | } |
172 | D.SetColor(VisCol); |
173 | |
174 | for (It.Initialize(myBiPntVis); |
175 | It.More(); |
176 | It.Next()) { |
177 | const HLRBRep_BiPoint& BP = It.Value(); |
178 | Standard_Boolean todraw = Standard_True; |
179 | if ((!withRg1 && BP.Rg1Line() && !BP.OutLine()) || |
180 | (!withRgN && BP.RgNLine() && !BP.OutLine())) |
181 | todraw = Standard_False; |
182 | if (todraw) { |
183 | D.MoveTo(BP.P1()); |
184 | D.DrawTo(BP.P2()); |
185 | if (firstPick && D.HasPicked()) { |
186 | firstPick = Standard_False; |
187 | myPickShap = BP.Shape(); |
188 | } |
189 | } |
190 | } |
191 | } |
192 | |
193 | //======================================================================= |
194 | //function : LastPick |
195 | //purpose : |
196 | //======================================================================= |
197 | |
198 | const TopoDS_Shape & DBRep_HideData::LastPick () const |
199 | { return myPickShap; } |