0027736: Samples - rectangle selection issues within MFC sample Viewer3d
[occt.git] / samples / mfc / standard / 04_Viewer3d / src / Viewer3dView.cpp
1 // Viewer3dView.cpp : implementation of the CViewer3dView class
2 //
3
4 #include "stdafx.h"
5
6 #include "Viewer3dView.h"
7
8 #include "OCC_MainFrame.h"
9 #include "Viewer3dApp.h"
10 #include "Viewer3dDoc.h"
11 #include "ScaleDlg.h"
12 #include "ShadingModelDlg.h"
13 #include "ModelClippingDlg.h"
14 #include "TrihedronDlg.h"
15
16 #include <AIS_RubberBand.hxx>
17 #include <V3d_AmbientLight.hxx>
18 #include <V3d_DirectionalLight.hxx>
19 #include <V3d_PositionalLight.hxx>
20 #include <V3d_PositionLight.hxx>
21 #include <V3d_SpotLight.hxx>
22 #include <TopoDS_Solid.hxx>
23 #include <Precision.hxx>
24 #include <Graphic3d_GraphicDriver.hxx>
25
26 #define ValZWMin 1
27 #define X_Key 0x58
28 #define Y_Key 0x59
29 #define Z_Key 0x5A
30
31 #define ModelClipping
32
33 #ifdef _DEBUG
34 #undef THIS_FILE
35 static char THIS_FILE[] = __FILE__;
36 #endif
37
38 //gp_Pnt ConvertClickToPoint(Standard_Real x, Standard_Real y, Handle(V3d_View) aView);
39
40         gp_Pnt p1,p2,p3;
41         Handle(AIS_Shape) spotConeShape=new AIS_Shape(TopoDS_Solid());
42         Handle(AIS_Shape) directionalEdgeShape=new AIS_Shape(TopoDS_Edge());
43
44 /////////////////////////////////////////////////////////////////////////////
45 // CViewer3dView
46
47 IMPLEMENT_DYNCREATE(CViewer3dView, CView)
48
49 BEGIN_MESSAGE_MAP(CViewer3dView, CView)
50         //{{AFX_MSG_MAP(CViewer3dView)
51         ON_COMMAND(ID_BUTTONAxo, OnBUTTONAxo)
52         ON_COMMAND(ID_BUTTONBack, OnBUTTONBack)
53         ON_COMMAND(ID_BUTTONBottom, OnBUTTONBottom)
54         ON_COMMAND(ID_BUTTONFront, OnBUTTONFront)
55         ON_COMMAND(ID_BUTTONHlrOff, OnBUTTONHlrOff)
56         ON_COMMAND(ID_BUTTONHlrOn, OnBUTTONHlrOn)
57         ON_COMMAND(ID_BUTTONLeft, OnBUTTONLeft)
58         ON_COMMAND(ID_BUTTONPan, OnBUTTONPan)
59         ON_COMMAND(ID_BUTTONPanGlo, OnBUTTONPanGlo)
60         ON_COMMAND(ID_BUTTONReset, OnBUTTONReset)
61         ON_COMMAND(ID_BUTTONRight, OnBUTTONRight)
62         ON_COMMAND(ID_BUTTONRot, OnBUTTONRot)
63         ON_COMMAND(ID_BUTTONTop, OnBUTTONTop)
64         ON_COMMAND(ID_BUTTONZoomAll, OnBUTTONZoomAll)
65         ON_WM_SIZE()
66         ON_COMMAND(ID_BUTTONZoomProg, OnBUTTONZoomProg)
67         ON_COMMAND(ID_BUTTONZoomWin, OnBUTTONZoomWin)
68         ON_WM_LBUTTONDOWN()
69   ON_WM_KEYDOWN()
70         ON_WM_LBUTTONUP()
71         ON_WM_MBUTTONDOWN()
72         ON_WM_MBUTTONUP()
73         ON_WM_MOUSEMOVE()
74         ON_WM_RBUTTONDOWN()
75         ON_WM_RBUTTONUP()
76         ON_UPDATE_COMMAND_UI(ID_BUTTONHlrOff, OnUpdateBUTTONHlrOff)
77         ON_UPDATE_COMMAND_UI(ID_BUTTONHlrOn, OnUpdateBUTTONHlrOn)
78         ON_UPDATE_COMMAND_UI(ID_BUTTONPanGlo, OnUpdateBUTTONPanGlo)
79         ON_UPDATE_COMMAND_UI(ID_BUTTONPan, OnUpdateBUTTONPan)
80         ON_UPDATE_COMMAND_UI(ID_BUTTONZoomProg, OnUpdateBUTTONZoomProg)
81         ON_UPDATE_COMMAND_UI(ID_BUTTONZoomWin, OnUpdateBUTTONZoomWin)
82         ON_UPDATE_COMMAND_UI(ID_BUTTONRot, OnUpdateBUTTONRot)
83         ON_COMMAND(ID_Modify_ChangeBackground     , OnModifyChangeBackground)
84         ON_COMMAND(ID_DIRECTIONAL_LIGHT, OnDirectionalLight)
85         ON_COMMAND(ID_SPOT_LIGHT, OnSpotLight)
86         ON_COMMAND(ID_POSITIONAL_LIGHT, OnPositionalLight)
87         ON_COMMAND(ID_AMBIENT_LIGHT, OnAmbientLight)
88         ON_COMMAND(ID_SCALE, OnScale)
89         ON_COMMAND(ID_SHADINGMODEL, OnShadingmodel)
90         ON_COMMAND(ID_ANTIALIASINGONOFF, OnAntialiasingonoff)
91         ON_COMMAND(ID_CLEAR_LIGHTS, OnClearLights)
92         ON_COMMAND(ID_MODELCLIPPING, OnModelclipping)
93         ON_COMMAND(ID_OPTIONS_TRIHEDRON_STATIC_TRIHEDRON, OnOptionsTrihedronStaticTrihedron)
94         //}}AFX_MSG_MAP
95 END_MESSAGE_MAP()
96
97 /////////////////////////////////////////////////////////////////////////////
98 // CViewer3dView construction/destruction
99
100 CViewer3dView::CViewer3dView()
101 : scaleX (1),
102   scaleY (1),
103   scaleZ (1),
104   myVisMode (VIS_SHADE),
105   myCurrentMode (CurAction3d_Nothing),
106   myXmin (0),
107   myYmin (0),
108   myXmax (0),
109   myYmax (0),
110   myCurZoom (0.0),
111   NbActiveLights (2), // There are 2 default active lights
112   myHlrModeIsOn (Standard_False),
113   myRect (new AIS_RubberBand (Quantity_NOC_WHITE, Aspect_TOL_SOLID, 1.0)),
114   myAxisKey (0),
115   myScaleDirection (0)
116 {
117   // TODO: add construction code here
118   myGraphicDriver = ((CViewer3dApp*)AfxGetApp())->GetGraphicDriver();
119 }
120
121 CViewer3dView::~CViewer3dView()
122 {
123   myView->Remove();
124 }
125
126 BOOL CViewer3dView::PreCreateWindow(CREATESTRUCT& cs)
127 {
128   // TODO: Modify the Window class or styles here by modifying
129   //  the CREATESTRUCT cs
130   cs.lpszClass = ::AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | CS_OWNDC, ::LoadCursor(NULL, IDC_ARROW), NULL, NULL);
131   return CView::PreCreateWindow(cs);
132 }
133
134 /////////////////////////////////////////////////////////////////////////////
135 // CViewer3dView drawing
136 void CViewer3dView::OnInitialUpdate() 
137 {
138   CView::OnInitialUpdate();
139
140   myView = GetDocument()->GetViewer()->CreateView();
141
142   // store for restore state after rotation (witch is in Degenerated mode)
143   myHlrModeIsOn = Standard_False;
144   myView->SetComputedMode (myHlrModeIsOn);
145
146   Handle(WNT_Window) aWNTWindow = new WNT_Window (GetSafeHwnd());
147   myView->SetWindow(aWNTWindow);
148   if (!aWNTWindow->IsMapped()) aWNTWindow->Map();
149
150   //    Standard_Integer w=100 , h=100 ;   /* Debug Matrox                         */
151   //    aWNTWindow->Size (w,h) ;           /* Keeps me unsatisfied (rlb).....      */
152                                          /* Resize is not supposed to be done on */
153                                          /* Matrox                               */
154                                          /* I suspect another problem elsewhere  */
155   //    ::PostMessage ( GetSafeHwnd () , WM_SIZE , SIZE_RESTORED , w + h*65536 ) ;
156
157   // store the mode ( nothing , dynamic zooming, dynamic ... )
158   myCurrentMode = CurAction3d_Nothing;
159   myVisMode = VIS_SHADE;
160   RedrawVisMode();
161 }
162
163 void CViewer3dView::OnDraw(CDC* /*pDC*/)
164 {
165         CViewer3dDoc* pDoc = GetDocument();
166         ASSERT_VALID(pDoc);
167         myView->Redraw();
168 }
169
170 /////////////////////////////////////////////////////////////////////////////
171 // CViewer3dView diagnostics
172
173 #ifdef _DEBUG
174 void CViewer3dView::AssertValid() const
175 {
176         CView::AssertValid();
177 }
178
179 void CViewer3dView::Dump(CDumpContext& dc) const
180 {
181         CView::Dump(dc);
182 }
183
184 CViewer3dDoc* CViewer3dView::GetDocument() // non-debug version is inline
185 {
186         ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CViewer3dDoc)));
187         return (CViewer3dDoc*)m_pDocument;
188 }
189 #endif //_DEBUG
190
191 /////////////////////////////////////////////////////////////////////////////
192 // CViewer3dView message handlers
193
194 gp_Pnt ConvertClickToPoint(Standard_Real x, Standard_Real y, Handle(V3d_View) aView)
195 {
196         Standard_Real XEye,YEye,ZEye,XAt,YAt,ZAt;
197         aView->Eye(XEye,YEye,ZEye);
198         aView->At(XAt,YAt,ZAt);
199         gp_Pnt EyePoint(XEye,YEye,ZEye);
200         gp_Pnt AtPoint(XAt,YAt,ZAt);
201
202         gp_Vec EyeVector(EyePoint,AtPoint);
203         gp_Dir EyeDir(EyeVector);
204
205         gp_Pln PlaneOfTheView = gp_Pln(AtPoint,EyeDir);
206         Standard_Real X,Y,Z;
207         aView->Convert(int(x),int(y),X,Y,Z);
208         gp_Pnt ConvertedPoint(X,Y,Z);
209         gp_Pnt2d ConvertedPointOnPlane = ProjLib::Project(PlaneOfTheView,ConvertedPoint);
210         
211         gp_Pnt ResultPoint = ElSLib::Value(ConvertedPointOnPlane.X(),
212                                                                         ConvertedPointOnPlane.Y(),
213                                                                         PlaneOfTheView);
214         return ResultPoint;
215 }
216
217 void CViewer3dView::OnSize(UINT nType, int cx, int cy)
218 {
219   CView::OnSize (nType, cx, cy);
220   if (!myView.IsNull())
221    myView->MustBeResized();
222 }
223
224 void CViewer3dView::OnBUTTONBack() 
225
226         myView->SetProj(V3d_Ypos); 
227
228 TCollection_AsciiString Message("\
229 myView->SetProj(V3d_Ypos);\n\
230   ");
231
232   // Update The Result Message Dialog
233 GetDocument()->UpdateResultMessageDlg("SetProj",Message);
234 } // See the back View
235 void CViewer3dView::OnBUTTONFront() 
236
237         myView->SetProj(V3d_Yneg); 
238
239 TCollection_AsciiString Message("\
240 myView->SetProj(V3d_Yneg);\n\
241   ");
242
243   // Update The Result Message Dialog
244 GetDocument()->UpdateResultMessageDlg("SetProj",Message);
245 } // See the front View
246
247 void CViewer3dView::OnBUTTONBottom() 
248
249         myView->SetProj(V3d_Zneg); 
250
251 TCollection_AsciiString Message("\
252 myView->SetProj(V3d_Zneg);\n\
253   ");
254
255   // Update The Result Message Dialog
256 GetDocument()->UpdateResultMessageDlg("SetProj",Message);
257 } // See the bottom View
258 void CViewer3dView::OnBUTTONTop() 
259
260         myView->SetProj(V3d_Zpos); 
261
262 TCollection_AsciiString Message("\
263 myView->SetProj(V3d_Zpos);\n\
264   ");
265
266   // Update The Result Message Dialog
267 GetDocument()->UpdateResultMessageDlg("SetProj",Message);
268 } // See the top View   
269
270 void CViewer3dView::OnBUTTONLeft() 
271
272         myView->SetProj(V3d_Xneg); 
273
274 TCollection_AsciiString Message("\
275 myView->SetProj(V3d_Xneg);\n\
276   ");
277
278   // Update The Result Message Dialog
279 GetDocument()->UpdateResultMessageDlg("SetProj",Message);
280 } // See the left View  
281 void CViewer3dView::OnBUTTONRight() 
282
283         myView->SetProj(V3d_Xpos); 
284
285 TCollection_AsciiString Message("\
286 myView->SetProj(V3d_Xpos);\n\
287   ");
288
289   // Update The Result Message Dialog
290 GetDocument()->UpdateResultMessageDlg("SetProj",Message);
291 } // See the right View
292
293 void CViewer3dView::OnBUTTONAxo() 
294
295         myView->SetProj(V3d_XposYnegZpos); 
296
297 TCollection_AsciiString Message("\
298 myView->SetProj(V3d_XposYnegZpos);\n\
299   ");
300
301   // Update The Result Message Dialog
302 GetDocument()->UpdateResultMessageDlg("SetProj",Message);
303 } // See the axonometric View
304
305 void CViewer3dView::OnBUTTONHlrOff() 
306 {
307   myHlrModeIsOn = Standard_False;
308   myView->SetComputedMode (myHlrModeIsOn);
309   myView->Redraw();
310
311   TCollection_AsciiString aMsg ("myView->SetComputedMode (Standard_False);\n"
312                                 "  ");
313
314   // Update The Result Message Dialog
315   GetDocument()->UpdateResultMessageDlg ("SetComputedMode", aMsg);
316 }
317
318 void CViewer3dView::OnBUTTONHlrOn() 
319 {
320   SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
321   myHlrModeIsOn = Standard_True;
322   myView->SetComputedMode (myHlrModeIsOn);
323   myView->Redraw();
324   SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
325
326   TCollection_AsciiString aMsg ("myView->SetComputedMode (Standard_True);\n"
327                                 "  ");
328
329   // Update The Result Message Dialog
330   GetDocument()->UpdateResultMessageDlg ("SetComputedMode", aMsg);
331 }
332
333 void CViewer3dView::OnBUTTONPan() 
334 {  myCurrentMode = CurAction3d_DynamicPanning; }
335
336 void CViewer3dView::OnBUTTONPanGlo() 
337 {
338   // save the current zoom value 
339   myCurZoom = myView->Scale();
340   // Do a Global Zoom 
341   myView->FitAll();
342   // Set the mode 
343   myCurrentMode = CurAction3d_GlobalPanning;
344 }
345
346 void CViewer3dView::OnBUTTONReset() 
347 {   myView->Reset(); }
348
349 void CViewer3dView::OnBUTTONRot() 
350 {   myCurrentMode = CurAction3d_DynamicRotation; }
351
352
353 void CViewer3dView::OnBUTTONZoomAll() 
354 {
355   myView->FitAll();
356   myView->ZFitAll();
357 }
358
359 void CViewer3dView::OnBUTTONZoomProg() 
360 {  myCurrentMode = CurAction3d_DynamicZooming; }
361
362 void CViewer3dView::OnBUTTONZoomWin() 
363 {  myCurrentMode = CurAction3d_WindowZooming; }
364
365 void CViewer3dView::OnLButtonDown(UINT nFlags, CPoint point) 
366 {
367   //  save the current mouse coordinate in min 
368   myXmin=point.x;  myYmin=point.y;
369   myXmax=point.x;  myYmax=point.y;
370
371   if ( nFlags & MK_CONTROL ) 
372           {
373             // Button MB1 down Control :start zomming 
374         // SetCursor(AfxGetApp()->LoadStandardCursor());
375           }
376         else // if ( Ctrl )
377           {
378         switch (myCurrentMode)
379         {
380          case CurAction3d_Nothing : // start a drag
381            if (nFlags & MK_SHIFT)
382                 GetDocument()->ShiftDragEvent(myXmax,myYmax,-1,myView);
383            else
384                 GetDocument()->DragEvent(myXmax,myYmax,-1,myView);
385         break;
386          break;
387          case CurAction3d_DynamicZooming : // noting
388          break;
389          case CurAction3d_WindowZooming : 
390          break;
391          case CurAction3d_DynamicPanning :// noting
392          break;
393          case CurAction3d_GlobalPanning :// noting
394         break;
395         case  CurAction3d_DynamicRotation :
396           if (myHlrModeIsOn)
397           {
398             myView->SetComputedMode (Standard_False);
399           }
400           myView->StartRotation (point.x, point.y);
401           break;
402         case  CurAction3d_BeginPositionalLight :
403                         {
404                         p1 = ConvertClickToPoint(point.x,point.y,myView);
405                         myCurrent_PositionalLight->SetPosition(p1.X(),p1.Y(),p1.Z()) ;
406                         ((OCC_MainFrame*)AfxGetMainWnd())->SetStatusMessage("Ready");
407                         myCurrentMode = CurAction3d_Nothing;
408
409 TCollection_AsciiString Message("\
410 myCurrent_PositionalLight->SetPosition(Xp, Yp, Zp) ;\n\
411 ");
412 // Update The Result Message Dialog
413 GetDocument()->UpdateResultMessageDlg("SetPosition",Message);
414                         }
415         break;
416         case  CurAction3d_BeginSpotLight :
417                         {
418                         p1 = ConvertClickToPoint(point.x,point.y,myView);
419                         myCurrent_SpotLight = new V3d_SpotLight (p1, gp_Dir (gp_XYZ (0.0, 0.0, 1.0) - p1.XYZ()), Quantity_NOC_RED);
420                         myView->SetLightOn(myCurrent_SpotLight);
421                         NbActiveLights++;
422                         p2 = gp_Pnt(p1.X(),p1.Y(),p1.Z()+1.);
423                         Standard_Real coneHeigth=p1.Distance(p2);
424                         BRepPrimAPI_MakeCone MakeCone(gp_Ax2(p1, gp_Dir(gp_Vec(p1, p2))), 
425                                 0, (p1.Distance(p2))/tan(1.04), coneHeigth);
426                         spotConeShape->Set(MakeCone.Solid());
427                         GetDocument()->GetAISContext()->Display (spotConeShape, 0, -1, Standard_True);
428                         ((OCC_MainFrame*)AfxGetMainWnd())->SetStatusMessage("Pick the target point");
429                         myCurrentMode = CurAction3d_TargetSpotLight;
430
431 TCollection_AsciiString Message("\
432 myCurrent_SpotLight->SetDirection(Xv, Yv, Zv);\n\
433 ");
434 // Update The Result Message Dialog
435 GetDocument()->UpdateResultMessageDlg("SetDirection",Message);
436                         }
437         break;
438         case  CurAction3d_TargetSpotLight :
439                         {
440                         p2 = ConvertClickToPoint(point.x,point.y,myView);
441                         ((OCC_MainFrame*)AfxGetMainWnd())->SetStatusMessage("Pick a third point (to define the angle)");
442                         myCurrentMode = CurAction3d_EndSpotLight;
443
444 TCollection_AsciiString Message("\
445 myCurrent_SpotLight->SetAngle(Angle) ;\n\
446 ");
447 // Update The Result Message Dialog
448 GetDocument()->UpdateResultMessageDlg("SetAngle",Message);
449                         }
450                 break;
451         case  CurAction3d_EndSpotLight :
452                         GetDocument()->GetAISContext()->Erase (spotConeShape, Standard_True);
453                         ((OCC_MainFrame*)AfxGetMainWnd())->SetStatusMessage("Ready");
454                         myCurrentMode = CurAction3d_Nothing;
455         break;
456                 case CurAction3d_BeginDirectionalLight:
457                         {
458                                 p1 = ConvertClickToPoint(point.x,point.y,myView);
459                                 p2 = gp_Pnt(p1.X(),p1.Y(),p1.Z()+1.);
460                                 BRepBuilderAPI_MakeEdge MakeEdge(p1, p2);
461                                 directionalEdgeShape->Set(MakeEdge.Edge());
462                                 GetDocument()->GetAISContext()->Display (directionalEdgeShape, 0, -1, Standard_True);
463                         // Create a directional light
464                                 myCurrent_DirectionalLight = new V3d_DirectionalLight (gp_Dir (p1.XYZ() - gp_XYZ (0.,0.,1.)));
465                                 myView->SetLightOn(myCurrent_DirectionalLight);
466                                 NbActiveLights++;
467                                 ((OCC_MainFrame*)AfxGetMainWnd())->SetStatusMessage("Pick the target point");
468                                 myCurrentMode = CurAction3d_EndDirectionalLight;
469
470
471 TCollection_AsciiString Message("\
472 myCurrent_DirectionalLight->SetDirection(Xv, Yv, Zv);\n\
473 ");
474 // Update The Result Message Dialog
475 GetDocument()->UpdateResultMessageDlg("SetDirection",Message);
476                         }
477                 break;
478                 case CurAction3d_EndDirectionalLight:
479                         GetDocument()->GetAISContext()->Erase (directionalEdgeShape, Standard_True);
480                         ((OCC_MainFrame*)AfxGetMainWnd())->SetStatusMessage("Ready");
481                         myCurrentMode = CurAction3d_Nothing;
482                 break;
483         }
484     }
485 }
486
487 void CViewer3dView::OnKeyDown(UINT nChar, UINT /*nRepCnt*/, UINT /*nFlags*/) 
488 {
489   
490   if( nChar == X_Key || nChar == Y_Key || nChar == Z_Key )
491     myAxisKey = nChar;
492   else if( (nChar == VK_ADD || nChar == VK_SUBTRACT) && myAxisKey )
493   {
494     myScaleDirection = nChar;
495     if( myAxisKey && myScaleDirection )
496     {
497       switch( myAxisKey )
498       {
499       case X_Key:
500         if( myScaleDirection == VK_ADD ) scaleX ++;
501         if( myScaleDirection == VK_SUBTRACT ) scaleX --;
502         break;
503       case Y_Key:
504         if( myScaleDirection == VK_ADD ) scaleY ++;
505         if( myScaleDirection == VK_SUBTRACT ) scaleY --;
506         break;
507       case Z_Key:
508         if( myScaleDirection == VK_ADD ) scaleZ ++;
509         if( myScaleDirection == VK_SUBTRACT ) scaleZ --;
510         break;
511       default:
512         break;
513       }
514       if( scaleX < 1 ) scaleX = 1;
515       if( scaleY < 1 ) scaleY = 1;
516       if( scaleZ < 1 ) scaleZ = 1;
517       
518       myView->SetAxialScale( scaleX, scaleY, scaleZ );
519     }
520   }
521 }
522
523 void CViewer3dView::OnLButtonUp(UINT nFlags, CPoint point) 
524 {
525    if ( nFlags & MK_CONTROL ) 
526           {
527         return;
528           }
529         else // if ( Ctrl )
530           {
531         switch (myCurrentMode)
532         {
533          case CurAction3d_Nothing :
534          if (point.x == myXmin && point.y == myYmin)
535          { // no offset between down and up --> selectEvent
536             myXmax=point.x;  
537             myYmax=point.y;
538             if (nFlags & MK_SHIFT )
539               GetDocument()->ShiftInputEvent(point.x,point.y,myView);
540             else
541               GetDocument()->InputEvent     (point.x,point.y,myView);
542          } else
543          {
544             DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False);
545             myXmax=point.x;  
546             myYmax=point.y;
547                     if (nFlags & MK_SHIFT)
548                                 GetDocument()->ShiftDragEvent(point.x,point.y,1,myView);
549                         else
550                                 GetDocument()->DragEvent(point.x,point.y,1,myView);
551          }
552          break;
553          case CurAction3d_DynamicZooming :
554              // SetCursor(AfxGetApp()->LoadStandardCursor());
555                myCurrentMode = CurAction3d_Nothing;
556          break;
557          case CurAction3d_WindowZooming :
558            DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False);
559            myXmax=point.x;  
560            myYmax=point.y;
561                if ((abs(myXmin-myXmax)>ValZWMin) || (abs(myYmin-myYmax)>ValZWMin))
562                                          // Test if the zoom window is greater than a minimale window.
563                         {
564                           // Do the zoom window between Pmin and Pmax
565                           myView->WindowFitAll(myXmin,myYmin,myXmax,myYmax);  
566                         }  
567                myCurrentMode = CurAction3d_Nothing;
568          break;
569          case CurAction3d_DynamicPanning :
570            myCurrentMode = CurAction3d_Nothing;
571          break;
572          case CurAction3d_GlobalPanning :
573                myView->Place(point.x,point.y,myCurZoom); 
574                myCurrentMode = CurAction3d_Nothing;
575         break;
576         case  CurAction3d_DynamicRotation :
577                myCurrentMode = CurAction3d_Nothing;
578         break;
579         } //switch (myCurrentMode)
580     } //        else // if ( Ctrl )
581 }
582
583 void CViewer3dView::OnMButtonDown(UINT nFlags, CPoint /*point*/) 
584 {
585    if ( nFlags & MK_CONTROL ) 
586           {
587         // Button MB2 down Control : panning init  
588         // SetCursor(AfxGetApp()->LoadStandardCursor());
589           }
590 }
591
592 void CViewer3dView::OnMButtonUp(UINT nFlags, CPoint /*point*/) 
593 {
594    if ( nFlags & MK_CONTROL ) 
595           {
596         // Button MB2 down Control : panning init  
597         // SetCursor(AfxGetApp()->LoadStandardCursor());
598           }
599 }
600
601 void CViewer3dView::OnRButtonDown(UINT nFlags, CPoint point) 
602 {
603   if ( nFlags & MK_CONTROL )
604   {
605     // SetCursor(AfxGetApp()->LoadStandardCursor());
606     if (myHlrModeIsOn)
607     {
608       myView->SetComputedMode (Standard_False);
609     }
610     myView->StartRotation (point.x, point.y);
611   }
612   else // if ( Ctrl )
613   {
614     GetDocument()->Popup (point.x, point.y, myView);
615   }
616 }
617
618 void CViewer3dView::OnRButtonUp(UINT /*nFlags*/, CPoint /*point*/) 
619 {
620   SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
621   if (myHlrModeIsOn)
622   {
623     myView->SetComputedMode (myHlrModeIsOn);
624     myView->Redraw();
625   }
626   SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
627 }
628
629 void CViewer3dView::OnMouseMove(UINT nFlags, CPoint point) 
630 {
631     //   ============================  LEFT BUTTON =======================
632   if ( nFlags & MK_LBUTTON)
633     {
634      if ( nFlags & MK_CONTROL ) 
635           {
636             // move with MB1 and Control : on the dynamic zooming  
637             // Do the zoom in function of mouse's coordinates  
638             myView->Zoom(myXmax,myYmax,point.x,point.y); 
639             // save the current mouse coordinate in min 
640                 myXmax = point.x; 
641         myYmax = point.y;       
642           }
643           else // if ( Ctrl )
644           {
645         switch (myCurrentMode)
646         {
647          case CurAction3d_Nothing :
648
649            myXmax = point.x;      myYmax = point.y;
650            if (nFlags & MK_SHIFT)               
651              GetDocument()->ShiftDragEvent(myXmax,myYmax,0,myView);
652            else
653              GetDocument()->DragEvent(myXmax,myYmax,0,myView);
654            DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_True);
655            break;
656          case CurAction3d_DynamicZooming :
657                myView->Zoom(myXmax,myYmax,point.x,point.y); 
658                // save the current mouse coordinate in min \n";
659                myXmax=point.x;  myYmax=point.y;
660          break;
661          case CurAction3d_WindowZooming :
662                    myXmax = point.x; myYmax = point.y;  
663            DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_True, Aspect_TOL_DASH);
664
665          break;
666          case CurAction3d_DynamicPanning :
667                    myView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
668                    myXmax = point.x; myYmax = point.y;  
669          break;
670          case CurAction3d_GlobalPanning : // nothing           
671         break;
672         case  CurAction3d_DynamicRotation :
673           myView->Rotation(point.x,point.y);
674               myView->Redraw();
675         break;
676         }//  switch (myCurrentMode)
677       }// if ( nFlags & MK_CONTROL )  else 
678     } else //   if ( nFlags & MK_LBUTTON) 
679     //   ============================  MIDDLE BUTTON =======================
680     if ( nFlags & MK_MBUTTON)
681     {
682      if ( nFlags & MK_CONTROL ) 
683           {
684                 myView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
685                 myXmax = point.x; myYmax = point.y;     
686
687           }
688     } else //  if ( nFlags & MK_MBUTTON)
689     //   ============================  RIGHT BUTTON =======================
690     if ( nFlags & MK_RBUTTON)
691     {
692      if ( nFlags & MK_CONTROL ) 
693           {
694          myView->Rotation(point.x,point.y);
695           }
696     }else //if ( nFlags & MK_RBUTTON)
697     //   ============================  NO BUTTON =======================
698     {  // No buttons 
699                 myXmax = point.x; myYmax = point.y;     
700                 if (myCurrentMode ==  CurAction3d_EndDirectionalLight) 
701                 {
702                         p2 = ConvertClickToPoint(point.x,point.y,myView);
703                         //Update the light dynamically
704                         if( p1.Distance(p2)>Precision::Confusion())
705                         {
706                                 BRepBuilderAPI_MakeEdge MakeEdge(p1, p2);
707                                 directionalEdgeShape->Set(MakeEdge.Edge());
708                                 GetDocument()->GetAISContext()->Redisplay(directionalEdgeShape,0,Standard_True);
709                                 myCurrent_DirectionalLight->SetDirection(p2.X()-p1.X(),p2.Y()-p1.Y(),p2.Z()-p1.Z());
710                                 myView->UpdateLights();
711                         }
712                 }
713                 else if (myCurrentMode ==  CurAction3d_BeginPositionalLight) 
714                 {
715                         p2 = ConvertClickToPoint(point.x,point.y,myView);
716                         //Update the light dynamically
717                         myCurrent_PositionalLight->SetPosition(p2.X(),p2.Y(),p2.Z());
718                         myView->UpdateLights();
719                 }
720                 else if (myCurrentMode ==  CurAction3d_TargetSpotLight) 
721                 {
722                         p2 = ConvertClickToPoint(point.x,point.y,myView);
723                         //Update the light dynamically
724                         Standard_Real coneHeigth=p1.Distance(p2);
725                         if( coneHeigth>Precision::Confusion())
726                         {
727                                 BRepPrimAPI_MakeCone MakeCone(gp_Ax2(p1, gp_Dir(gp_Vec(p1, p2))), 
728                                         0, (p1.Distance(p2))/tan(1.04), coneHeigth);
729                                 spotConeShape->Set(MakeCone.Solid());
730                                 GetDocument()->GetAISContext()->Redisplay(spotConeShape,0,Standard_True);
731                                 myCurrent_SpotLight->SetDirection(p2.X()-p1.X(),p2.Y()-p1.Y(),p2.Z()-p1.Z());
732                                 myView->UpdateLights();
733                         }
734                 }
735                 else if (myCurrentMode ==  CurAction3d_EndSpotLight) 
736                 {
737                         p3 = ConvertClickToPoint(point.x,point.y,myView);
738                         //Update the light dynamically
739                         Standard_Real coneHeigth=p1.Distance(p2);
740                         if( (p2.Distance(p3))>Precision::Confusion())
741                         {
742                                 BRepPrimAPI_MakeCone MakeCone(gp_Ax2(p1, gp_Dir(gp_Vec(p1, p2))), 
743                                         0, p2.Distance(p3), coneHeigth);
744                                 spotConeShape->Set(MakeCone.Solid());
745                                 GetDocument()->GetAISContext()->Redisplay(spotConeShape,0,Standard_True);
746                                 myCurrent_SpotLight->SetAngle((float )atan(p2.Distance(p3)/p1.Distance(p2))) ;
747                                 myView->UpdateLights();
748                         }
749                 }
750                 if (nFlags & MK_SHIFT)
751                         GetDocument()->ShiftMoveEvent(point.x,point.y,myView);
752                 else
753                         GetDocument()->MoveEvent(point.x,point.y,myView);
754         }
755 }
756
757 void CViewer3dView::OnUpdateBUTTONHlrOff (CCmdUI* pCmdUI)
758 {
759   pCmdUI->SetCheck (!myHlrModeIsOn);
760   pCmdUI->Enable   (myHlrModeIsOn);
761 }
762
763 void CViewer3dView::OnUpdateBUTTONHlrOn (CCmdUI* pCmdUI)
764 {
765   pCmdUI->SetCheck (myHlrModeIsOn);
766   pCmdUI->Enable   (!myHlrModeIsOn);
767 }
768
769 void CViewer3dView::OnUpdateBUTTONPanGlo(CCmdUI* pCmdUI) 
770 {
771     pCmdUI->SetCheck (myCurrentMode == CurAction3d_GlobalPanning);
772         pCmdUI->Enable   (myCurrentMode != CurAction3d_GlobalPanning);  
773         
774 }
775
776 void CViewer3dView::OnUpdateBUTTONPan(CCmdUI* pCmdUI) 
777 {
778     pCmdUI->SetCheck (myCurrentMode == CurAction3d_DynamicPanning);
779         pCmdUI->Enable   (myCurrentMode != CurAction3d_DynamicPanning );        
780 }
781
782 void CViewer3dView::OnUpdateBUTTONZoomProg(CCmdUI* pCmdUI) 
783 {
784     pCmdUI->SetCheck (myCurrentMode == CurAction3d_DynamicZooming );
785         pCmdUI->Enable   (myCurrentMode != CurAction3d_DynamicZooming); 
786 }
787
788 void CViewer3dView::OnUpdateBUTTONZoomWin(CCmdUI* pCmdUI) 
789 {
790     pCmdUI->SetCheck (myCurrentMode == CurAction3d_WindowZooming);
791         pCmdUI->Enable   (myCurrentMode != CurAction3d_WindowZooming);  
792 }
793
794 void CViewer3dView::OnUpdateBUTTONRot(CCmdUI* pCmdUI) 
795 {
796     pCmdUI->SetCheck (myCurrentMode == CurAction3d_DynamicRotation);
797         pCmdUI->Enable   (myCurrentMode != CurAction3d_DynamicRotation);        
798 }
799
800 void CViewer3dView::DrawRectangle (Standard_Integer theMinX,
801                                    Standard_Integer theMinY,
802                                    Standard_Integer theMaxX,
803                                    Standard_Integer theMaxY,
804                                    Standard_Boolean theToDraw,
805                                    Aspect_TypeOfLine theLineType)
806 {
807   const Handle(AIS_InteractiveContext)& aCtx = GetDocument()->GetAISContext();
808   if (!theToDraw)
809   {
810     aCtx->Remove (myRect, false);
811     aCtx->CurrentViewer()->RedrawImmediate();
812     return;
813   }
814
815   CRect aRect;
816   GetWindowRect (aRect);
817   myRect->SetLineType (theLineType);
818   myRect->SetRectangle (theMinX, aRect.Height() - theMinY, theMaxX, aRect.Height() - theMaxY);
819   if (!aCtx->IsDisplayed (myRect))
820   {
821     aCtx->Display (myRect, false);
822   }
823   else
824   {
825     aCtx->Redisplay (myRect, false);
826   }
827   aCtx->CurrentViewer()->RedrawImmediate();
828 }
829
830 void CViewer3dView::OnModifyChangeBackground() 
831 {
832         Standard_Real R1;
833         Standard_Real G1;
834         Standard_Real B1;
835     myView->BackgroundColor(Quantity_TOC_RGB,R1,G1,B1);
836         COLORREF m_clr ;
837         m_clr = RGB(R1*255,G1*255,B1*255);
838
839         CColorDialog dlgColor(m_clr);
840         if (dlgColor.DoModal() == IDOK)
841         {
842                 m_clr = dlgColor.GetColor();
843                 R1 = GetRValue(m_clr)/255.;
844                 G1 = GetGValue(m_clr)/255.;
845                 B1 = GetBValue(m_clr)/255.;
846         myView->SetBackgroundColor(Quantity_TOC_RGB,R1,G1,B1);
847         }
848     myView->Redraw();
849 }
850
851 void CViewer3dView::OnDirectionalLight() 
852 {
853 // Directional light source creation
854
855 // Checking if the Active lights limit number is not reached
856         if( NbActiveLights>=myGraphicDriver->InquireLightLimit() )
857         {
858     CString aMsg;
859     aMsg.Format (L"You have reach the limit number of active lights (%d).\n Clear lights to create new ones.", myGraphicDriver->InquireLightLimit());
860                 MessageBox (aMsg, L"Light creation", MB_OK);
861                 return;
862         }
863
864         UpdateData(TRUE);
865         ((OCC_MainFrame*)AfxGetMainWnd())->SetStatusMessage("Pick a first point");
866         myCurrentMode = CurAction3d_BeginDirectionalLight;
867
868 TCollection_AsciiString Message("\
869 myCurrent_DirectionalLight = new V3d_DirectionalLight (gp_Dir (theDirection));\n\
870 \n\
871 myView->SetLightOn(myCurrent_DirectionalLight);\n\
872 \n\
873 ");
874 // Update The Result Message Dialog
875         GetDocument()->UpdateResultMessageDlg("V3d_DirectionalLight",Message);
876 }
877
878 void CViewer3dView::OnSpotLight() 
879 {
880 // Spot light source creation
881
882 // Checking if the Active lights limit number is not reached
883         if( NbActiveLights>=myGraphicDriver->InquireLightLimit() )
884         {
885     CString aMsg;
886     aMsg.Format(L"You have reach the limit number of active lights (%d).\n Clear lights to create new ones.", myGraphicDriver->InquireLightLimit());
887                 MessageBox (aMsg, L"Light creation", MB_OK);
888                 return;
889         }
890
891         ((OCC_MainFrame*)AfxGetMainWnd())->SetStatusMessage("Pick the light position");
892         myCurrentMode = CurAction3d_BeginSpotLight;
893
894 TCollection_AsciiString Message("\
895 myCurrent_SpotLight = new V3d_SpotLight (gp_Pnt (thePosition), gp_Dir (theDirection), Quantity_NOC_RED);\n\
896 \n\
897 myView->SetLightOn(myCurrent_SpotLight);\n\
898 \n\
899 ");
900 // Update The Result Message Dialog
901 GetDocument()->UpdateResultMessageDlg("V3d_SpotLight",Message);
902 }
903
904 void CViewer3dView::OnPositionalLight() 
905 {
906 // Positional light source creation
907
908 // Checking if the Active lights limit number is not reached
909         if( NbActiveLights>=myGraphicDriver->InquireLightLimit() )
910         {
911     CString aMsg;
912     aMsg.Format(L"You have reach the limit number of active lights (%d).\n Clear lights to create new ones.", myGraphicDriver->InquireLightLimit());
913     MessageBox(aMsg, L"Light creation", MB_OK);
914                 return;
915         }
916
917         myCurrent_PositionalLight=new V3d_PositionalLight (gp_Pnt (0,0,0), Quantity_NOC_GREEN);
918     myCurrent_PositionalLight->SetAttenuation (1, 0);
919         myView->SetLightOn(myCurrent_PositionalLight);
920         NbActiveLights++;
921         ((OCC_MainFrame*)AfxGetMainWnd())->SetStatusMessage("Pick the light position");
922         myCurrentMode = CurAction3d_BeginPositionalLight;
923
924 TCollection_AsciiString Message("\
925 myCurrent_PositionalLight=new V3d_PositionalLight (gp_Pnt(thePosition),Quantity_NOC_GREEN);\n\
926 myCurrent_PositionalLight->SetAttenuation (1, 0);\n\
927 \n\
928 myView->SetLightOn(myCurrent_PositionalLight) ;\n\
929   ");
930
931   // Update The Result Message Dialog
932 GetDocument()->UpdateResultMessageDlg("V3d_PositionalLight",Message);
933 }
934
935 void CViewer3dView::OnAmbientLight() 
936 {
937 // Ambiant light source creation
938
939 // Checking if the Active lights limit number is not reached
940         if( NbActiveLights>=myGraphicDriver->InquireLightLimit() )
941         {
942     CString aMsg;
943     aMsg.Format(L"You have reach the limit number of active lights (%d).\n Clear lights to create new ones.", myGraphicDriver->InquireLightLimit());
944     MessageBox(aMsg, L"Light creation", MB_OK);
945                 return;
946         }
947
948         myCurrent_AmbientLight=new V3d_AmbientLight (Quantity_NOC_GRAY);
949         myView->SetLightOn(myCurrent_AmbientLight) ;    
950         NbActiveLights++;
951
952         myView->UpdateLights();
953
954 TCollection_AsciiString Message("\
955 myCurrent_AmbientLight=new V3d_AmbientLight(Quantity_NOC_GRAY);\n\
956 \n\
957 myView->SetLightOn(myCurrent_AmbientLight) ;\n\
958   ");
959
960   // Update The Result Message Dialog
961 GetDocument()->UpdateResultMessageDlg("V3d_AmbientLight",Message);
962 }
963
964
965 void CViewer3dView::OnScale() 
966 {
967         ScaleDlg Dlg(myView, this);
968         Dlg.DoModal();
969         myView->Redraw();
970 }
971
972 //V3d_View.hxx
973
974 void CViewer3dView::OnShadingmodel() 
975 {
976 TCollection_AsciiString Message("\
977 myView->SetShadingModel(V3d_TypeOfShadingModel myTypeOfShadingModel);\n\
978 \n\
979 myCurrent_V3d_View->Update();\n\
980   ");
981
982   // Update The Result Message Dialog
983 GetDocument()->UpdateResultMessageDlg("SetShadingModel",Message);
984
985         CShadingModelDlg Dlg(myView);
986         Dlg.DoModal();
987         myView->Redraw();
988 }
989
990
991 void CViewer3dView::OnAntialiasingonoff() 
992 {
993   Graphic3d_RenderingParams& aParams = myView->ChangeRenderingParams();
994   aParams.NbMsaaSamples = aParams.NbMsaaSamples == 0 ? 8 : 0;
995         myView->Update();
996
997 TCollection_AsciiString Message("\
998 Graphic3d_RenderingParams& aParams = myView->ChangeRenderingParams();\n\
999 aParams.NbMsaaSamples = aParams.NbMsaaSamples == 0 ? 8 : 0;\n\
1000   ");
1001
1002   // Update The Result Message Dialog
1003 GetDocument()->UpdateResultMessageDlg("SetAntialiasingOn/SetAntialiasingOff",Message);
1004 }
1005
1006 void CViewer3dView::OnClearLights() 
1007 {
1008 //      Setting Off all viewer active lights
1009     TColStd_ListOfTransient lights;
1010         for(myView->Viewer()->InitActiveLights(); myView->Viewer()->MoreActiveLights(); myView->Viewer()->NextActiveLights())
1011     {
1012         lights.Append(myView->Viewer()->ActiveLight());
1013     }
1014     TColStd_ListIteratorOfListOfTransient itrLights(lights);
1015     for (; itrLights.More(); itrLights.Next())
1016     {
1017         Handle(V3d_Light) light = Handle(V3d_Light)::DownCast(itrLights.Value());
1018         myView->Viewer()->SetLightOff(light);
1019     }
1020
1021 //      Setting Off all view active lights
1022     lights.Clear();
1023     for(myView->InitActiveLights(); myView->MoreActiveLights(); myView->NextActiveLights())
1024     {
1025         lights.Append(myView->ActiveLight());
1026     }
1027     itrLights.Initialize(lights);
1028     for (; itrLights.More(); itrLights.Next())
1029     {
1030         Handle(V3d_Light) light = Handle(V3d_Light)::DownCast(itrLights.Value());
1031         myView->SetLightOff(light);
1032     }
1033
1034         myView->Viewer()->SetDefaultLights();// Setting the default lights on
1035
1036         NbActiveLights = 2;// There are 2 default active lights
1037
1038         myView->Update();
1039
1040 TCollection_AsciiString Message("\
1041 //      Setting Off all viewer active lights\n\
1042 TColStd_ListOfTransient lights;\n\
1043 for(myView->Viewer()->InitActiveLights(); myView->Viewer()->MoreActiveLights(); myView->Viewer()->NextActiveLights())\n\
1044 {\n\
1045     lights.Append(myView->Viewer()->ActiveLight());\n\
1046 }\n\
1047 TColStd_ListIteratorOfListOfTransient itrLights(lights);\n\
1048 for (; itrLights.More(); itrLights.Next())\n\
1049 {\n\
1050     Handle(V3d_Light) light = Handle(V3d_Light)::DownCast(itrLights.Value());\n\
1051     myView->Viewer()->SetLightOff(light);\n\
1052 }\n\
1053 \n\
1054 //      Setting Off all view active lights\n\
1055 lights.Clear();\n\
1056 for(myView->InitActiveLights(); myView->MoreActiveLights(); myView->NextActiveLights())\n\
1057 {\n\
1058     lights.Append(myView->ActiveLight());\n\
1059 }\n\
1060 itrLights.Initialize(lights);\n\
1061 for (; itrLights.More(); itrLights.Next())\n\
1062 {\n\
1063     Handle(V3d_Light) light = Handle(V3d_Light)::DownCast(itrLights.Value());\n\
1064     myView->SetLightOff(light);\n\
1065 }\n\
1066 \n\
1067 myView->Viewer()->SetDefaultLights();// Setting the default lights on\n\
1068   ");
1069
1070   // Update The Result Message Dialog
1071 GetDocument()->UpdateResultMessageDlg("SetLightOff",Message);
1072 }
1073
1074 void CViewer3dView::OnModelclipping() 
1075 {
1076   if (myClippingPlane.IsNull())
1077   {
1078     gp_Pln aClipPlane (gp_Pnt (0.0, 0.0, 0.0), gp_Dir (1.0, 0.0, 0.0));
1079     gp_Pln aFacePlane (gp_Pnt (0.1, 0.0, 0.0), gp_Dir (1.0, 0.0, 0.0));
1080
1081     // create clipping plane and add to view
1082     myClippingPlane = new Graphic3d_ClipPlane (aClipPlane);
1083
1084     // shape to represent clipping plane
1085     BRepBuilderAPI_MakeFace aMakeFaceCommand (aFacePlane, 200.0, -200.0, 410.0, -410.0);
1086     TopoDS_Face aShape = aMakeFaceCommand.Face();
1087     myShape = new AIS_Shape (aShape);
1088     myShape->SetTransparency (0.5);
1089   }
1090
1091   CModelClippingDlg aClippingDlg (myView, myShape, myClippingPlane, GetDocument());
1092
1093   aClippingDlg.DoModal();
1094 }
1095
1096 void CViewer3dView::OnOptionsTrihedronStaticTrihedron() 
1097 {
1098         CTrihedronDlg Dlg(myView, GetDocument());
1099         Dlg.DoModal();
1100 }
1101
1102 void CViewer3dView::InitButtons()
1103 {
1104   myXmin=0;
1105   myYmin=0;  
1106   myXmax=0;
1107   myYmax=0;
1108   myCurZoom=0;
1109   myCurrentMode = CurAction3d_Nothing;
1110 }
1111
1112 void CViewer3dView::Reset()
1113 {
1114   InitButtons();
1115   myVisMode = VIS_SHADE;
1116   if (!myView.IsNull())
1117   {
1118     RedrawVisMode();
1119     myView->Reset();
1120   }
1121 }
1122
1123 void CViewer3dView::GetViewAt (Standard_Real& theX, Standard_Real& theY, Standard_Real& theZ) const
1124 {
1125   myView->At (theX, theY, theZ);
1126 }
1127
1128 void CViewer3dView::SetViewAt (const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ)
1129 {
1130   myView->SetAt (theX, theY, theZ);
1131 }
1132
1133 void CViewer3dView::GetViewEye(Standard_Real& X, Standard_Real& Y, Standard_Real& Z)
1134 {
1135         myView->Eye(X,Y,Z);
1136 }
1137
1138 void CViewer3dView::SetViewEye(Standard_Real X, Standard_Real Y, Standard_Real Z)
1139 {
1140         myView->SetEye(X,Y,Z);
1141 }
1142
1143 Standard_Real CViewer3dView::GetViewScale()
1144 {
1145         return myView->Scale();
1146 }
1147
1148 void CViewer3dView::SetViewScale(Standard_Real Coef)
1149 {
1150         myView->SetScale(Coef);
1151 }
1152
1153 void CViewer3dView::RedrawVisMode()
1154 {
1155   switch (myVisMode)
1156   {
1157   case VIS_WIREFRAME:
1158     GetDocument()->GetAISContext()->SetDisplayMode (AIS_WireFrame, Standard_True);
1159     myView->SetComputedMode (Standard_False);
1160     myView->Redraw();
1161     break;
1162   case VIS_SHADE:
1163     GetDocument()->GetAISContext()->SetDisplayMode (AIS_Shaded, Standard_True);
1164     myView->SetComputedMode (Standard_False);
1165     myView->Redraw();
1166     break;
1167   case VIS_HLR:
1168     SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
1169     myView->SetComputedMode (Standard_True);
1170     myView->Redraw();
1171     SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
1172     GetDocument()->GetAISContext()->SetDisplayMode (AIS_WireFrame, Standard_True);
1173     break;
1174   }
1175 }