0023776: Redesign of MFC samples after V2d viewer removing
[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_HANDLE(ISession2D_Shape,AIS_InteractiveObject)
10 IMPLEMENT_STANDARD_RTTIEXT(ISession2D_Shape,AIS_InteractiveObject)
11
12 ISession2D_Shape::ISession2D_Shape ()
13     :AIS_InteractiveObject(PrsMgr_TOP_ProjectorDependant)
14 {}
15
16 void 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
24 void 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
33 void 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
48 void 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 }
58 void 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
67 void ISession2D_Shape::Compute(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
68                              const Handle(Prs3d_Presentation)& aPresentation,
69                              const Standard_Integer aMode) 
70 {
71   Standard_Integer TheMode = aMode;
72   Standard_Boolean DrawHiddenLine= Standard_True;
73   if (TheMode >= 1000)
74   {
75     DrawHiddenLine = Standard_False;
76     TheMode -= 1000;
77   }
78
79   Standard_Boolean UsePolyAlgo= Standard_True;
80   if (TheMode >= 100)
81   {
82     UsePolyAlgo = Standard_False;
83     TheMode -= 100;
84   }
85   TopoDS_Shape VCompound;
86   TopoDS_Shape Rg1LineVCompound;
87   TopoDS_Shape RgNLineVCompound;
88   TopoDS_Shape OutLineVCompound;
89   TopoDS_Shape IsoLineVCompound;  // only for Exact algo
90   TopoDS_Shape HCompound;
91   TopoDS_Shape Rg1LineHCompound;
92   TopoDS_Shape RgNLineHCompound;
93   TopoDS_Shape OutLineHCompound;
94   TopoDS_Shape IsoLineHCompound;  // only for Exact algo
95
96   if (UsePolyAlgo)
97   {
98     if (myPolyAlgo.IsNull()) BuildPolyAlgo();
99     HLRBRep_PolyHLRToShape aPolyHLRToShape;
100     aPolyHLRToShape.Update(myPolyAlgo);
101
102     VCompound        = aPolyHLRToShape.VCompound();
103     Rg1LineVCompound = aPolyHLRToShape.Rg1LineVCompound();
104     RgNLineVCompound = aPolyHLRToShape.RgNLineVCompound();
105     OutLineVCompound = aPolyHLRToShape.OutLineVCompound();
106     HCompound        = aPolyHLRToShape.HCompound();
107     Rg1LineHCompound = aPolyHLRToShape.Rg1LineHCompound();
108     RgNLineHCompound = aPolyHLRToShape.RgNLineHCompound();
109     OutLineHCompound = aPolyHLRToShape.OutLineHCompound();
110   }
111   else
112   {
113     if (myAlgo.IsNull()) BuildAlgo();
114     HLRBRep_HLRToShape aHLRToShape(myAlgo);
115
116     VCompound        = aHLRToShape.VCompound();
117     Rg1LineVCompound = aHLRToShape.Rg1LineVCompound();
118     RgNLineVCompound = aHLRToShape.RgNLineVCompound();
119     OutLineVCompound = aHLRToShape.OutLineVCompound();
120     IsoLineVCompound = aHLRToShape.IsoLineVCompound();
121     HCompound        = aHLRToShape.HCompound();
122     Rg1LineHCompound = aHLRToShape.Rg1LineHCompound();
123     RgNLineHCompound = aHLRToShape.RgNLineHCompound();
124     OutLineHCompound = aHLRToShape.OutLineHCompound();
125     IsoLineHCompound = aHLRToShape.IsoLineHCompound();
126   }
127
128   if (UsePolyAlgo)
129   {
130     Handle(Prs3d_LineAspect) aLineAspectHighlighted = new Prs3d_LineAspect(Quantity_NOC_ALICEBLUE,
131       Aspect_TOL_DOTDASH,1);
132     Handle(Prs3d_LineAspect) aLineAspect = new Prs3d_LineAspect(Quantity_NOC_WHITE,
133       Aspect_TOL_SOLID,1);
134
135
136     switch(TheMode)
137     {
138     case (1):
139       {
140         DrawCompound(aPresentation, VCompound, aLineAspectHighlighted);
141         break;
142       }
143     case (2):
144       {
145         DrawCompound(aPresentation, Rg1LineVCompound, aLineAspectHighlighted);
146         break;
147       }
148     case (3):
149       {
150         DrawCompound(aPresentation, RgNLineVCompound, aLineAspectHighlighted);
151         break;
152       }
153     case (4):
154       {
155         DrawCompound(aPresentation, OutLineVCompound, aLineAspectHighlighted);
156         break;
157       }
158     default:
159       {
160         DrawCompound(aPresentation,VCompound, aLineAspect);
161         DrawCompound(aPresentation,Rg1LineVCompound, aLineAspect);
162         DrawCompound(aPresentation,RgNLineVCompound, aLineAspect);
163         DrawCompound(aPresentation,OutLineVCompound, aLineAspect);
164       }
165     }
166
167     if (DrawHiddenLine)
168     {
169       Handle(Prs3d_LineAspect) aLineAspectHighlighted = new Prs3d_LineAspect(Quantity_NOC_RED,
170         Aspect_TOL_DOTDASH,2);
171       Handle(Prs3d_LineAspect) aLineAspect = new Prs3d_LineAspect(Quantity_NOC_BLUE1,
172         Aspect_TOL_DOTDASH,1);
173
174       switch(TheMode)
175       {
176       case (6):
177         {
178           DrawCompound(aPresentation, HCompound, aLineAspectHighlighted);
179           break;
180         }
181       case (7):
182         {
183           DrawCompound(aPresentation, Rg1LineHCompound, aLineAspectHighlighted);
184           break;
185         }
186       case (8):
187         {
188           DrawCompound(aPresentation, RgNLineHCompound, aLineAspectHighlighted);
189           break;
190         }
191       case (9):
192         {
193           DrawCompound(aPresentation, OutLineHCompound, aLineAspectHighlighted);
194           break;
195         }
196       default:
197         {
198           DrawCompound(aPresentation, HCompound, aLineAspect);
199           DrawCompound(aPresentation, Rg1LineHCompound, aLineAspect);
200           DrawCompound(aPresentation, RgNLineHCompound, aLineAspect);
201           DrawCompound(aPresentation, OutLineHCompound, aLineAspect);
202         }
203       }
204     }
205   }
206   else
207   {
208     Handle(Prs3d_LineAspect) aLineAspectHighlighted = new Prs3d_LineAspect(Quantity_NOC_RED,
209       Aspect_TOL_SOLID,2);
210     Handle(Prs3d_LineAspect) aLineAspect = new Prs3d_LineAspect(Quantity_NOC_WHITE,
211       Aspect_TOL_SOLID,1);  
212
213     switch (TheMode)
214     {
215     case (1):
216       {
217         DrawCompound(aPresentation, VCompound, aLineAspectHighlighted);
218         break;
219       }
220     case (2):
221       {
222         DrawCompound(aPresentation, Rg1LineVCompound, aLineAspectHighlighted);
223         break;
224       }
225     case (3):
226       {
227         DrawCompound(aPresentation, RgNLineVCompound, aLineAspectHighlighted);
228         break;
229       }
230     case (4):
231       {
232         DrawCompound(aPresentation, OutLineVCompound, aLineAspectHighlighted);
233         break;
234       }
235     case (5):
236       {
237         DrawCompound(aPresentation, IsoLineVCompound, aLineAspectHighlighted);
238         break;
239       }
240     default:
241       {
242         DrawCompound(aPresentation, VCompound, aLineAspect);
243         DrawCompound(aPresentation, Rg1LineVCompound, aLineAspect);
244         DrawCompound(aPresentation, RgNLineVCompound, aLineAspect);
245         DrawCompound(aPresentation, OutLineVCompound, aLineAspect);
246         DrawCompound(aPresentation, IsoLineVCompound , aLineAspect);
247       }
248     }
249
250     if (DrawHiddenLine)
251     {
252       Handle(Prs3d_LineAspect) aLineAspectHighlighted = new Prs3d_LineAspect(Quantity_NOC_RED,
253         Aspect_TOL_DOT,2);
254       Handle(Prs3d_LineAspect) aLineAspect = new Prs3d_LineAspect(Quantity_NOC_ALICEBLUE,
255         Aspect_TOL_DOT,1);  
256
257             switch(TheMode)
258       {
259       case (6):
260         {
261           DrawCompound(aPresentation, HCompound, aLineAspectHighlighted);
262           break;
263         }
264       case (7):
265         {
266           DrawCompound(aPresentation, Rg1LineHCompound, aLineAspectHighlighted);
267           break;
268         }
269       case (8):
270         {
271           DrawCompound(aPresentation, RgNLineHCompound, aLineAspectHighlighted);
272           break;
273         }
274       case (9):
275         {
276           DrawCompound(aPresentation, OutLineHCompound, aLineAspectHighlighted);
277           break;
278         }
279       case (10):
280         {
281           DrawCompound(aPresentation, IsoLineHCompound, aLineAspectHighlighted);
282           break;
283         }
284       default:
285         {
286           DrawCompound(aPresentation, HCompound, aLineAspect);
287           DrawCompound(aPresentation, Rg1LineHCompound, aLineAspect);
288           DrawCompound(aPresentation, RgNLineHCompound, aLineAspect);
289           DrawCompound(aPresentation, OutLineHCompound, aLineAspect);
290           DrawCompound(aPresentation, IsoLineHCompound, aLineAspect);
291         }
292       }
293     }
294   }
295 }
296
297 void ISession2D_Shape::DrawCompound(const Handle(Prs3d_Presentation)& thePresentation,
298                                    const TopoDS_Shape& theCompound, 
299                                    const Handle(Prs3d_LineAspect) theAspect)
300 {
301   if (theCompound.IsNull())
302     return;
303   myDrawer->SetWireAspect(theAspect);
304   StdPrs_WFDeflectionShape::Add(thePresentation,TopoDS_Shape(theCompound),myDrawer);
305 }
306
307 void ISession2D_Shape::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
308                                       const Standard_Integer aMode) 
309 {
310
311 }
312