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