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