0023831: Ghosts appears in 2D viewer of HLR MFC sample
[occt.git] / samples / mfc / standard / Common / ISession2D / ISession2D_Shape.cpp
CommitLineData
7fd59977 1#include "stdafx.h"
2
3#include "ISession2D_Shape.h"
4#include <TopTools_ListIteratorOfListOfShape.hxx>
5#include <HLRBRep_PolyHLRToShape.hxx>
6#include <HLRBRep_HLRToShape.hxx>
7#include <TopExp.hxx>
8
9IMPLEMENT_STANDARD_HANDLE(ISession2D_Shape,AIS_InteractiveObject)
10IMPLEMENT_STANDARD_RTTIEXT(ISession2D_Shape,AIS_InteractiveObject)
11
12ISession2D_Shape::ISession2D_Shape ()
13 :AIS_InteractiveObject(PrsMgr_TOP_ProjectorDependant)
14{}
15
16void ISession2D_Shape::Add(const TopoDS_Shape& aShape)
17{
18 myListOfShape.Append(aShape);
19 myAlgo.Nullify();
20 myPolyAlgo.Nullify();
21 Update(); // protected method used to specify that the presentation are not up to date
22}
23
24void ISession2D_Shape::SetProjector(HLRAlgo_Projector& aProjector)
25{
26 myProjector= aProjector;
27 myAlgo.Nullify();
28 myPolyAlgo.Nullify();
29 Update(); // protected method used to specify that the presentation are not up to date
30};
31
32
33void ISession2D_Shape::SetNbIsos(Standard_Integer& aNbIsos)
34{
35 myNbIsos= aNbIsos;
36 myAlgo.Nullify();
37
38 // declare the mode 100 to 110 as non valid
39 for (int i=100;i<=110;i++)
40 Update(i,Standard_False); // protected method used to specify that the presentation are not up to date
41
42 // declare the mode 1100 to 1110 as non valid
43 for (int i=1100;i<=1110;i++)
44 Update(i,Standard_False); // protected method used to specify that the presentation are not up to date
45
46};
47
7fd59977 48void ISession2D_Shape::BuildAlgo()
49{
50 myAlgo = new HLRBRep_Algo();
51 TopTools_ListIteratorOfListOfShape anIterator(myListOfShape);
52 for (;anIterator.More();anIterator.Next()) myAlgo->Add(anIterator.Value(),myNbIsos);
53 myAlgo->Projector(myProjector);
54 myAlgo->Update();
55 myAlgo->Hide();
56
57}
58void ISession2D_Shape::BuildPolyAlgo()
59{
60 myPolyAlgo = new HLRBRep_PolyAlgo();
61 TopTools_ListIteratorOfListOfShape anIterator(myListOfShape);
62 for (;anIterator.More();anIterator.Next()) myPolyAlgo->Load(anIterator.Value());
63 myPolyAlgo->Projector(myProjector);
64 myPolyAlgo->Update();
65}
66
97319109 67void ISession2D_Shape::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
68 const Handle(Prs3d_Presentation)& thePresentation,
69 const Standard_Integer theMode)
7fd59977 70{
97319109 71
72 Standard_Integer aMode = theMode;
7fd59977 73 Standard_Boolean DrawHiddenLine= Standard_True;
97319109 74 thePresentation->Clear();
75 if (aMode >= 1000)
7fd59977 76 {
77 DrawHiddenLine = Standard_False;
97319109 78 aMode -= 1000;
7fd59977 79 }
80
81 Standard_Boolean UsePolyAlgo= Standard_True;
97319109 82 if (aMode >= 100)
7fd59977 83 {
84 UsePolyAlgo = Standard_False;
97319109 85 aMode -= 100;
7fd59977 86 }
87 TopoDS_Shape VCompound;
88 TopoDS_Shape Rg1LineVCompound;
89 TopoDS_Shape RgNLineVCompound;
90 TopoDS_Shape OutLineVCompound;
5c1f974e 91 TopoDS_Shape IsoLineVCompound; // only for Exact algo
7fd59977 92 TopoDS_Shape HCompound;
93 TopoDS_Shape Rg1LineHCompound;
94 TopoDS_Shape RgNLineHCompound;
95 TopoDS_Shape OutLineHCompound;
5c1f974e 96 TopoDS_Shape IsoLineHCompound; // only for Exact algo
7fd59977 97
98 if (UsePolyAlgo)
5c1f974e 99 {
100 if (myPolyAlgo.IsNull()) BuildPolyAlgo();
101 HLRBRep_PolyHLRToShape aPolyHLRToShape;
102 aPolyHLRToShape.Update(myPolyAlgo);
103
104 VCompound = aPolyHLRToShape.VCompound();
105 Rg1LineVCompound = aPolyHLRToShape.Rg1LineVCompound();
106 RgNLineVCompound = aPolyHLRToShape.RgNLineVCompound();
107 OutLineVCompound = aPolyHLRToShape.OutLineVCompound();
108 HCompound = aPolyHLRToShape.HCompound();
109 Rg1LineHCompound = aPolyHLRToShape.Rg1LineHCompound();
110 RgNLineHCompound = aPolyHLRToShape.RgNLineHCompound();
111 OutLineHCompound = aPolyHLRToShape.OutLineHCompound();
112 }
113 else
114 {
115 if (myAlgo.IsNull()) BuildAlgo();
116 HLRBRep_HLRToShape aHLRToShape(myAlgo);
117
118 VCompound = aHLRToShape.VCompound();
119 Rg1LineVCompound = aHLRToShape.Rg1LineVCompound();
120 RgNLineVCompound = aHLRToShape.RgNLineVCompound();
121 OutLineVCompound = aHLRToShape.OutLineVCompound();
122 IsoLineVCompound = aHLRToShape.IsoLineVCompound();
123 HCompound = aHLRToShape.HCompound();
124 Rg1LineHCompound = aHLRToShape.Rg1LineHCompound();
125 RgNLineHCompound = aHLRToShape.RgNLineHCompound();
126 OutLineHCompound = aHLRToShape.OutLineHCompound();
127 IsoLineHCompound = aHLRToShape.IsoLineHCompound();
128 }
7fd59977 129
5c1f974e 130 if (UsePolyAlgo)
131 {
132 Handle(Prs3d_LineAspect) aLineAspectHighlighted = new Prs3d_LineAspect(Quantity_NOC_ALICEBLUE,
133 Aspect_TOL_DOTDASH,1);
134 Handle(Prs3d_LineAspect) aLineAspect = new Prs3d_LineAspect(Quantity_NOC_WHITE,
135 Aspect_TOL_SOLID,1);
7fd59977 136
97319109 137
138 switch(aMode)
7fd59977 139 {
5c1f974e 140 case (1):
141 {
97319109 142 DrawCompound(thePresentation, VCompound, aLineAspectHighlighted);
5c1f974e 143 break;
144 }
145 case (2):
146 {
97319109 147 DrawCompound(thePresentation, Rg1LineVCompound, aLineAspectHighlighted);
5c1f974e 148 break;
149 }
150 case (3):
151 {
97319109 152 DrawCompound(thePresentation, RgNLineVCompound, aLineAspectHighlighted);
5c1f974e 153 break;
154 }
155 case (4):
156 {
97319109 157 DrawCompound(thePresentation, OutLineVCompound, aLineAspectHighlighted);
5c1f974e 158 break;
159 }
160 default:
161 {
97319109 162 DrawCompound(thePresentation,VCompound, aLineAspect);
163 DrawCompound(thePresentation,Rg1LineVCompound, aLineAspect);
164 DrawCompound(thePresentation,RgNLineVCompound, aLineAspect);
165 DrawCompound(thePresentation,OutLineVCompound, aLineAspect);
5c1f974e 166 }
167 }
7fd59977 168
5c1f974e 169 if (DrawHiddenLine)
170 {
171 Handle(Prs3d_LineAspect) aLineAspectHighlighted = new Prs3d_LineAspect(Quantity_NOC_RED,
172 Aspect_TOL_DOTDASH,2);
173 Handle(Prs3d_LineAspect) aLineAspect = new Prs3d_LineAspect(Quantity_NOC_BLUE1,
174 Aspect_TOL_DOTDASH,1);
7fd59977 175
97319109 176 switch(aMode)
7fd59977 177 {
5c1f974e 178 case (6):
179 {
97319109 180 DrawCompound(thePresentation, HCompound, aLineAspectHighlighted);
5c1f974e 181 break;
182 }
183 case (7):
184 {
97319109 185 DrawCompound(thePresentation, Rg1LineHCompound, aLineAspectHighlighted);
5c1f974e 186 break;
187 }
188 case (8):
189 {
97319109 190 DrawCompound(thePresentation, RgNLineHCompound, aLineAspectHighlighted);
5c1f974e 191 break;
192 }
193 case (9):
194 {
97319109 195 DrawCompound(thePresentation, OutLineHCompound, aLineAspectHighlighted);
5c1f974e 196 break;
197 }
198 default:
199 {
97319109 200 DrawCompound(thePresentation, HCompound, aLineAspect);
201 DrawCompound(thePresentation, Rg1LineHCompound, aLineAspect);
202 DrawCompound(thePresentation, RgNLineHCompound, aLineAspect);
203 DrawCompound(thePresentation, OutLineHCompound, aLineAspect);
5c1f974e 204 }
7fd59977 205 }
5c1f974e 206 }
7fd59977 207 }
208 else
209 {
5c1f974e 210 Handle(Prs3d_LineAspect) aLineAspectHighlighted = new Prs3d_LineAspect(Quantity_NOC_RED,
211 Aspect_TOL_SOLID,2);
212 Handle(Prs3d_LineAspect) aLineAspect = new Prs3d_LineAspect(Quantity_NOC_WHITE,
213 Aspect_TOL_SOLID,1);
7fd59977 214
97319109 215 switch (aMode)
5c1f974e 216 {
217 case (1):
7fd59977 218 {
97319109 219 DrawCompound(thePresentation, VCompound, aLineAspectHighlighted);
5c1f974e 220 break;
7fd59977 221 }
5c1f974e 222 case (2):
223 {
97319109 224 DrawCompound(thePresentation, Rg1LineVCompound, aLineAspectHighlighted);
5c1f974e 225 break;
226 }
227 case (3):
228 {
97319109 229 DrawCompound(thePresentation, RgNLineVCompound, aLineAspectHighlighted);
5c1f974e 230 break;
231 }
232 case (4):
233 {
97319109 234 DrawCompound(thePresentation, OutLineVCompound, aLineAspectHighlighted);
5c1f974e 235 break;
236 }
237 case (5):
238 {
97319109 239 DrawCompound(thePresentation, IsoLineVCompound, aLineAspectHighlighted);
5c1f974e 240 break;
241 }
242 default:
243 {
97319109 244 DrawCompound(thePresentation, VCompound, aLineAspect);
245 DrawCompound(thePresentation, Rg1LineVCompound, aLineAspect);
246 DrawCompound(thePresentation, RgNLineVCompound, aLineAspect);
247 DrawCompound(thePresentation, OutLineVCompound, aLineAspect);
248 DrawCompound(thePresentation, IsoLineVCompound , aLineAspect);
5c1f974e 249 }
250 }
7fd59977 251
5c1f974e 252 if (DrawHiddenLine)
253 {
254 Handle(Prs3d_LineAspect) aLineAspectHighlighted = new Prs3d_LineAspect(Quantity_NOC_RED,
255 Aspect_TOL_DOT,2);
256 Handle(Prs3d_LineAspect) aLineAspect = new Prs3d_LineAspect(Quantity_NOC_ALICEBLUE,
257 Aspect_TOL_DOT,1);
7fd59977 258
97319109 259 switch(aMode)
5c1f974e 260 {
261 case (6):
262 {
97319109 263 DrawCompound(thePresentation, HCompound, aLineAspectHighlighted);
5c1f974e 264 break;
265 }
266 case (7):
267 {
97319109 268 DrawCompound(thePresentation, Rg1LineHCompound, aLineAspectHighlighted);
5c1f974e 269 break;
270 }
271 case (8):
272 {
97319109 273 DrawCompound(thePresentation, RgNLineHCompound, aLineAspectHighlighted);
5c1f974e 274 break;
275 }
276 case (9):
277 {
97319109 278 DrawCompound(thePresentation, OutLineHCompound, aLineAspectHighlighted);
5c1f974e 279 break;
280 }
281 case (10):
282 {
97319109 283 DrawCompound(thePresentation, IsoLineHCompound, aLineAspectHighlighted);
5c1f974e 284 break;
285 }
286 default:
287 {
97319109 288 DrawCompound(thePresentation, HCompound, aLineAspect);
289 DrawCompound(thePresentation, Rg1LineHCompound, aLineAspect);
290 DrawCompound(thePresentation, RgNLineHCompound, aLineAspect);
291 DrawCompound(thePresentation, OutLineHCompound, aLineAspect);
292 DrawCompound(thePresentation, IsoLineHCompound, aLineAspect);
5c1f974e 293 }
294 }
295 }
7fd59977 296 }
297}
298
5c1f974e 299void ISession2D_Shape::DrawCompound(const Handle(Prs3d_Presentation)& thePresentation,
300 const TopoDS_Shape& theCompound,
301 const Handle(Prs3d_LineAspect) theAspect)
7fd59977 302{
5c1f974e 303 if (theCompound.IsNull())
7fd59977 304 return;
5c1f974e 305 myDrawer->SetWireAspect(theAspect);
306 StdPrs_WFDeflectionShape::Add(thePresentation,TopoDS_Shape(theCompound),myDrawer);
7fd59977 307}
308
309void ISession2D_Shape::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
310 const Standard_Integer aMode)
5c1f974e 311{
312
7fd59977 313}
314