b311480e |
1 | // Created on: 1992-10-14 |
2 | // Created by: Christophe MARION |
3 | // Copyright (c) 1992-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 | |
17 | #include <HLRTest_DrawableEdgeTool.ixx> |
18 | #include <HLRTest_ShapeData.hxx> |
19 | #include <HLRBRep_Data.hxx> |
20 | #include <HLRAlgo_EdgeIterator.hxx> |
21 | #include <HLRBRep_ShapeBounds.hxx> |
22 | |
23 | //======================================================================= |
24 | //function : HLRTest_DrawableEdgeTool |
25 | //purpose : |
26 | //======================================================================= |
27 | |
28 | HLRTest_DrawableEdgeTool::HLRTest_DrawableEdgeTool |
29 | (const Handle(HLRBRep_Algo)& Alg, |
30 | const Standard_Boolean Visible, |
31 | const Standard_Boolean IsoLine, |
32 | const Standard_Boolean Rg1Line, |
33 | const Standard_Boolean RgNLine, |
34 | const Standard_Integer ViewId) : |
35 | myAlgo(Alg), |
36 | myVisible(Visible), |
37 | myIsoLine(IsoLine), |
38 | myRg1Line(Rg1Line), |
39 | myRgNLine(RgNLine), |
40 | myViewId(ViewId) |
41 | {} |
42 | |
43 | //======================================================================= |
44 | //function : DrawOn |
45 | //purpose : |
46 | //======================================================================= |
47 | |
48 | void HLRTest_DrawableEdgeTool::DrawOn(Draw_Display& D) const |
49 | { |
50 | if (myViewId == D.ViewId()) { |
51 | if (myIsoLine) InternalDraw(D,1); |
52 | InternalDraw(D,2); |
53 | InternalDraw(D,3); |
54 | } |
55 | } |
56 | |
57 | //======================================================================= |
58 | //function : InternalDraw |
59 | //purpose : |
60 | //======================================================================= |
61 | |
62 | void |
63 | HLRTest_DrawableEdgeTool::InternalDraw (Draw_Display& D, |
64 | const Standard_Integer typ) const |
65 | { |
66 | Handle(HLRBRep_Data) DS = myAlgo->DataStructure(); |
67 | |
68 | if (!DS.IsNull()) { |
69 | // Standard_Real sta,end; |
70 | // Standard_ShortReal tolsta,tolend; |
71 | // Standard_Integer ie,v1,v2,e1,e2,f1,f2; |
72 | Standard_Integer ie,e2; |
73 | Standard_Integer iCB = 1; |
74 | Standard_Integer nCB = myAlgo->NbShapes(); |
75 | Standard_Integer ne = DS->NbEdges(); |
76 | Standard_Integer nf = DS->NbFaces(); |
77 | HLRBRep_EdgeData* ed = &(DS->EDataArray().ChangeValue(0)); |
78 | ed++; |
79 | e2 = 0; |
80 | |
81 | for (ie = 1; ie <= ne; ie++) { |
82 | if (ed->Selected() && !ed->Vertical()) ed->Used(Standard_False); |
83 | else ed->Used(Standard_True); |
84 | ed++; |
85 | } |
86 | |
87 | for (Standard_Integer iface = 1; iface <= nf; iface++) |
88 | DrawFace(D,typ,nCB,iface,e2,iCB,DS); |
89 | |
90 | if (typ >= 3) { |
91 | iCB = 1; |
92 | e2 = 0; |
93 | HLRBRep_EdgeData* ed = &(DS->EDataArray().ChangeValue(0)); |
94 | ed++; |
95 | |
96 | for (Standard_Integer ie = 1; ie <= ne; ie++) { |
97 | if (!ed->Used()) { |
98 | DrawEdge(D,Standard_False,typ,nCB,ie,e2,iCB,*ed); |
99 | ed->Used(Standard_True); |
100 | } |
101 | ed++; |
102 | } |
103 | } |
104 | } |
105 | } |
106 | |
107 | //======================================================================= |
108 | //function : DrawFace |
109 | //purpose : |
110 | //======================================================================= |
111 | |
112 | void |
113 | HLRTest_DrawableEdgeTool::DrawFace (Draw_Display& D, |
114 | const Standard_Integer typ, |
115 | const Standard_Integer nCB, |
116 | const Standard_Integer iface, |
117 | Standard_Integer& e2, |
118 | Standard_Integer& iCB, |
119 | Handle(HLRBRep_Data)& DS) const |
120 | { |
121 | HLRBRep_FaceIterator Itf; |
122 | |
123 | for (Itf.InitEdge(DS->FDataArray().ChangeValue(iface)); |
124 | Itf.MoreEdge(); |
125 | Itf.NextEdge()) { |
126 | Standard_Integer ie = Itf.Edge(); |
127 | HLRBRep_EdgeData& edf = DS->EDataArray().ChangeValue(ie); |
128 | if (!edf.Used()) { |
129 | Standard_Boolean todraw; |
130 | if ((!myRg1Line && |
131 | !Itf.OutLine() && |
132 | edf.Rg1Line()) || |
133 | (!myRgNLine && |
134 | !Itf.OutLine() && |
135 | edf.RgNLine())) todraw = Standard_False; |
136 | else if (typ == 1) todraw = Itf.IsoLine(); |
137 | else if (typ == 2) todraw = Itf.OutLine() || Itf.Internal(); |
138 | else todraw = !(Itf.IsoLine() || |
139 | (Itf.OutLine() || Itf.Internal())); |
140 | if (todraw) DrawEdge(D,Standard_True,typ,nCB,ie,e2,iCB,edf); |
141 | edf.Used(Standard_True); |
142 | } |
143 | } |
144 | } |
145 | |
146 | //======================================================================= |
147 | //function : DrawEdge |
148 | //purpose : |
149 | //======================================================================= |
150 | |
151 | void |
152 | HLRTest_DrawableEdgeTool::DrawEdge (Draw_Display& D, |
153 | const Standard_Boolean inFace, |
154 | const Standard_Integer typ, |
155 | const Standard_Integer nCB, |
156 | const Standard_Integer ie, |
157 | Standard_Integer& e2, |
158 | Standard_Integer& iCB, |
159 | HLRBRep_EdgeData& ed) const |
160 | { |
161 | Standard_Boolean todraw = Standard_True; |
162 | if (!inFace && |
163 | ((!myRg1Line && ed.Rg1Line()) || |
164 | (!myRgNLine && ed.RgNLine()))) todraw = Standard_False; |
165 | if (todraw) { |
166 | Standard_Real sta,end; |
167 | Standard_ShortReal tolsta,tolend; |
168 | Standard_Integer v1,v2,e1,f1,f2; |
169 | HLRAlgo_EdgeIterator It; |
170 | if (myVisible) { |
171 | |
172 | while (ie > e2 && iCB <= nCB) { |
173 | HLRBRep_ShapeBounds& ShB |
174 | = myAlgo->ShapeBounds(iCB); |
175 | ShB.Bounds(v1,v2,e1,e2,f1,f2); |
176 | Handle(HLRTest_ShapeData) ShData = |
177 | Handle(HLRTest_ShapeData)::DownCast(ShB.ShapeData()); |
178 | if (typ == 1) D.SetColor(ShData->VisibleIsoColor()); |
179 | else if (typ == 2) D.SetColor(ShData->VisibleOutLineColor()); |
180 | else D.SetColor(ShData->VisibleColor()); |
181 | iCB++; |
182 | } |
183 | |
184 | const HLRBRep_Curve& ec = ed.Geometry(); |
185 | |
186 | for (It.InitVisible(ed.Status()); |
187 | It.MoreVisible(); |
188 | It.NextVisible()) { |
189 | It.Visible(sta,tolsta,end,tolend); |
190 | D.MoveTo(ec.Value3D(sta)); |
c29a9290 |
191 | if (ec.GetType() != GeomAbs_Line) { |
7fd59977 |
192 | Standard_Integer nbPnt = 100; |
193 | Standard_Real step = (end-sta)/(nbPnt+1); |
194 | |
195 | for (Standard_Integer i = 1; i <= nbPnt; i++) { |
196 | sta += step; |
197 | D.DrawTo(ec.Value3D(sta)); |
198 | } |
199 | } |
200 | D.DrawTo(ec.Value3D(end)); |
201 | } |
202 | } |
203 | else { |
204 | |
205 | while (ie > e2 && iCB <= nCB) { |
206 | HLRBRep_ShapeBounds& ShB |
207 | = myAlgo->ShapeBounds(iCB); |
208 | ShB.Bounds(v1,v2,e1,e2,f1,f2); |
209 | Handle(HLRTest_ShapeData) ShData = |
210 | Handle(HLRTest_ShapeData)::DownCast(ShB.ShapeData()); |
211 | if (typ == 1) D.SetColor(ShData->HiddenIsoColor()); |
212 | else if (typ == 2) D.SetColor(ShData->HiddenOutLineColor()); |
213 | else D.SetColor(ShData->HiddenColor()); |
214 | iCB++; |
215 | } |
216 | |
217 | const HLRBRep_Curve& ec = ed.Geometry(); |
218 | |
219 | for (It.InitHidden(ed.Status()); |
220 | It.MoreHidden(); |
221 | It.NextHidden()) { |
222 | It.Hidden(sta,tolsta,end,tolend); |
223 | D.MoveTo(ec.Value3D(sta)); |
c29a9290 |
224 | if (ec.GetType() != GeomAbs_Line) { |
7fd59977 |
225 | Standard_Integer nbPnt = 100; |
226 | Standard_Real step = (end-sta)/(nbPnt+1); |
227 | |
228 | for (Standard_Integer i = 1; i <= nbPnt; i++) { |
229 | sta += step; |
230 | D.DrawTo(ec.Value3D(sta)); |
231 | } |
232 | } |
233 | D.DrawTo(ec.Value3D(end)); |
234 | } |
235 | } |
236 | } |
237 | } |
238 | |