0031682: Visualization - Prs3d_ShadingAspect::SetTransparency() has no effect with...
[occt.git] / src / HLRBRep / HLRBRep_HLRToShape.cxx
CommitLineData
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.
7fd59977 16
42cf5bc1 17
7fd59977 18#include <BRep_Builder.hxx>
42cf5bc1 19#include <HLRAlgo_EdgeIterator.hxx>
7fd59977 20#include <HLRBRep.hxx>
42cf5bc1 21#include <HLRBRep_Algo.hxx>
7fd59977 22#include <HLRBRep_Data.hxx>
42cf5bc1 23#include <HLRBRep_EdgeData.hxx>
24#include <HLRBRep_HLRToShape.hxx>
7fd59977 25#include <HLRBRep_ShapeBounds.hxx>
42cf5bc1 26#include <TopExp_Explorer.hxx>
27#include <TopoDS.hxx>
28#include <TopoDS_Shape.hxx>
29#include <TopTools_IndexedMapOfShape.hxx>
7fd59977 30
31//=======================================================================
32//function : HLRBRep_HLRToShape
33//purpose :
34//=======================================================================
7fd59977 35HLRBRep_HLRToShape::HLRBRep_HLRToShape (const Handle(HLRBRep_Algo)& A) :
36myAlgo(A)
37{}
38
39//=======================================================================
40//function : InternalCompound
41//purpose :
42//=======================================================================
43
44TopoDS_Shape
45HLRBRep_HLRToShape::InternalCompound (const Standard_Integer typ,
46 const Standard_Boolean visible,
bda83605 47 const TopoDS_Shape& S,
48 const Standard_Boolean In3d)
7fd59977 49{
50 Standard_Boolean added = Standard_False;
51 TopoDS_Shape Result;
52 Handle(HLRBRep_Data) DS = myAlgo->DataStructure();
53
54 if (!DS.IsNull()) {
55 DS->Projector().Scaled(Standard_True);
56 Standard_Integer e1 = 1;
57 Standard_Integer e2 = DS->NbEdges();
58 Standard_Integer f1 = 1;
59 Standard_Integer f2 = DS->NbFaces();
60 Standard_Boolean explor = Standard_False;
61// Standard_Boolean todraw;
62 if (!S.IsNull()) {
63 Standard_Integer v1,v2;
64 Standard_Integer index = myAlgo->Index(S);
65 if (index == 0) explor = Standard_True;
66 else myAlgo->ShapeBounds(index).Bounds(v1,v2,e1,e2,f1,f2);
67 }
68 BRep_Builder B;
69 B.MakeCompound(TopoDS::Compound(Result));
70 HLRBRep_EdgeData* ed = &(DS->EDataArray().ChangeValue(e1 - 1));
71
72 for (Standard_Integer ie = e1; ie <= e2; ie++) {
73 ed++;
74 if (ed->Selected() && !ed->Vertical()) {
75 ed->Used(Standard_False);
76 ed->HideCount(0);
77 }
78 else ed->Used(Standard_True);
79 }
80 if (explor) {
81 TopTools_IndexedMapOfShape& Edges = DS->EdgeMap();
82 TopTools_IndexedMapOfShape& Faces = DS->FaceMap();
83 TopExp_Explorer Exp;
84
85 for (Exp.Init (S, TopAbs_FACE);
86 Exp.More();
87 Exp.Next()) {
88 Standard_Integer iface = Faces.FindIndex(Exp.Current());
bda83605 89 if (iface != 0)
90 DrawFace(visible,typ,iface,DS,Result,added,In3d);
7fd59977 91 }
92 if (typ >= 3) {
93
94 for (Exp.Init (S, TopAbs_EDGE, TopAbs_FACE);
95 Exp.More();
96 Exp.Next()) {
97 Standard_Integer ie = Edges.FindIndex(Exp.Current());
98 if (ie != 0) {
51740958 99 HLRBRep_EdgeData& EDataIE = DS->EDataArray().ChangeValue(ie);
100 if (!EDataIE.Used()) {
101 DrawEdge(visible,Standard_False,typ, EDataIE,Result,added,In3d);
102 EDataIE.Used(Standard_True);
7fd59977 103 }
104 }
105 }
106 }
107 }
108 else {
109
110 for (Standard_Integer iface = f1; iface <= f2; iface++)
bda83605 111 DrawFace(visible,typ,iface,DS,Result,added,In3d);
7fd59977 112
113 if (typ >= 3) {
51740958 114 HLRBRep_EdgeData* EDataE11 = &(DS->EDataArray().ChangeValue(e1 - 1));
7fd59977 115
116 for (Standard_Integer ie = e1; ie <= e2; ie++) {
51740958 117 EDataE11++;
118 if (!EDataE11->Used()) {
119 DrawEdge(visible,Standard_False,typ,*EDataE11,Result,added,In3d);
120 EDataE11->Used(Standard_True);
7fd59977 121 }
122 }
123 }
124 }
125 DS->Projector().Scaled(Standard_False);
126 }
127 if (!added) Result = TopoDS_Shape();
128 return Result;
129}
130
131//=======================================================================
132//function : DrawFace
133//purpose :
134//=======================================================================
135
136void
137HLRBRep_HLRToShape::DrawFace (const Standard_Boolean visible,
138 const Standard_Integer typ,
139 const Standard_Integer iface,
140 Handle(HLRBRep_Data)& DS,
141 TopoDS_Shape& Result,
bda83605 142 Standard_Boolean& added,
143 const Standard_Boolean In3d) const
7fd59977 144{
145 HLRBRep_FaceIterator Itf;
146
147 for (Itf.InitEdge(DS->FDataArray().ChangeValue(iface));
148 Itf.MoreEdge();
149 Itf.NextEdge()) {
150 Standard_Integer ie = Itf.Edge();
151 HLRBRep_EdgeData& edf = DS->EDataArray().ChangeValue(ie);
152 if (!edf.Used()) {
153 Standard_Boolean todraw;
154 if (typ == 1) todraw = Itf.IsoLine();
bda83605 155 else if (typ == 2) //outlines
156 {
157 if (In3d)
158 todraw = Itf.Internal() || Itf.OutLine();
159 else
160 todraw = Itf.Internal();
161 }
7fd59977 162 else if (typ == 3) todraw = edf.Rg1Line() &&
163 !edf.RgNLine() && !Itf.OutLine();
164 else if (typ == 4) todraw = edf.RgNLine() && !Itf.OutLine();
165 else todraw =
166 !(Itf.IsoLine() ||
167 Itf.Internal() ||
168 (edf.Rg1Line() && !Itf.OutLine()));
169
170 if (todraw) {
bda83605 171 DrawEdge(visible,Standard_True,typ,edf,Result,added,In3d);
7fd59977 172 edf.Used(Standard_True);
173 }
174 else {
bda83605 175 if((typ > 4 || typ == 2) && //sharp or outlines
176 (edf.Rg1Line() && !Itf.OutLine()))
177 {
7fd59977 178 Standard_Integer hc = edf.HideCount();
179 if(hc > 0) {
180 edf.Used(Standard_True);
181 }
182 else {
183 ++hc;
184 edf.HideCount(hc); //to try with another face
185 }
186 }
187 else {
188 edf.Used(Standard_True);
189 }
190 }
191 }
192 }
193}
194
195//=======================================================================
196//function : DrawEdge
197//purpose :
198//=======================================================================
199
200void
201HLRBRep_HLRToShape::DrawEdge (const Standard_Boolean visible,
202 const Standard_Boolean inFace,
203 const Standard_Integer typ,
204 HLRBRep_EdgeData& ed,
205 TopoDS_Shape& Result,
bda83605 206 Standard_Boolean& added,
207 const Standard_Boolean In3d) const
7fd59977 208{
5c953701 209 Standard_Boolean todraw = Standard_False;
7fd59977 210 if (inFace) todraw = Standard_True;
211 else if (typ == 3) todraw = ed.Rg1Line() && !ed.RgNLine();
212 else if (typ == 4) todraw = ed.RgNLine();
213 else todraw =!ed.Rg1Line();
5c953701 214
7fd59977 215 if (todraw) {
216 Standard_Real sta,end;
217 Standard_ShortReal tolsta,tolend;
218 BRep_Builder B;
5c953701 219 TopoDS_Edge E;
7fd59977 220 HLRAlgo_EdgeIterator It;
5c953701 221 if (visible)
222 {
223 for (It.InitVisible(ed.Status()); It.MoreVisible(); It.NextVisible()) {
224 It.Visible(sta,tolsta,end,tolend);
bda83605 225 if (!In3d)
226 E = HLRBRep::MakeEdge(ed.Geometry(),sta,end);
227 else
228 E = HLRBRep::MakeEdge3d(ed.Geometry(),sta,end);
5c953701 229 if (!E.IsNull())
230 {
231 B.Add(Result,E);
232 added = Standard_True;
233 }
7fd59977 234 }
235 }
5c953701 236 else
237 {
238 for (It.InitHidden(ed.Status()); It.MoreHidden(); It.NextHidden()) {
239 It.Hidden(sta,tolsta,end,tolend);
bda83605 240 if (!In3d)
241 E = HLRBRep::MakeEdge(ed.Geometry(),sta,end);
242 else
243 E = HLRBRep::MakeEdge3d(ed.Geometry(),sta,end);
5c953701 244 if (!E.IsNull())
245 {
246 B.Add(Result,E);
247 added = Standard_True;
248 }
7fd59977 249 }
250 }
251 }
252}