0029367: Visualization - simplify interface of V3d_View and V3d_Viewer
[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, false);
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                                 myView->Redraw();
712                         }
713                 }
714                 else if (myCurrentMode ==  CurAction3d_BeginPositionalLight) 
715                 {
716                         p2 = ConvertClickToPoint(point.x,point.y,myView);
717                         //Update the light dynamically
718                         myCurrent_PositionalLight->SetPosition(p2.X(),p2.Y(),p2.Z());
719                         myView->UpdateLights();
720                         myView->Redraw();
721                 }
722                 else if (myCurrentMode ==  CurAction3d_TargetSpotLight) 
723                 {
724                         p2 = ConvertClickToPoint(point.x,point.y,myView);
725                         //Update the light dynamically
726                         Standard_Real coneHeigth=p1.Distance(p2);
727                         if( coneHeigth>Precision::Confusion())
728                         {
729                                 BRepPrimAPI_MakeCone MakeCone(gp_Ax2(p1, gp_Dir(gp_Vec(p1, p2))), 
730                                         0, (p1.Distance(p2))/tan(1.04), coneHeigth);
731                                 spotConeShape->Set(MakeCone.Solid());
732                                 GetDocument()->GetAISContext()->Redisplay(spotConeShape,0,Standard_True);
733                                 myCurrent_SpotLight->SetDirection(p2.X()-p1.X(),p2.Y()-p1.Y(),p2.Z()-p1.Z());
734                                 myView->UpdateLights();
735                                 myView->Redraw();
736                         }
737                 }
738                 else if (myCurrentMode ==  CurAction3d_EndSpotLight) 
739                 {
740                         p3 = ConvertClickToPoint(point.x,point.y,myView);
741                         //Update the light dynamically
742                         Standard_Real coneHeigth=p1.Distance(p2);
743                         if( (p2.Distance(p3))>Precision::Confusion())
744                         {
745                                 BRepPrimAPI_MakeCone MakeCone(gp_Ax2(p1, gp_Dir(gp_Vec(p1, p2))), 
746                                         0, p2.Distance(p3), coneHeigth);
747                                 spotConeShape->Set(MakeCone.Solid());
748                                 GetDocument()->GetAISContext()->Redisplay(spotConeShape,0,Standard_True);
749                                 myCurrent_SpotLight->SetAngle((float )atan(p2.Distance(p3)/p1.Distance(p2))) ;
750                                 myView->UpdateLights();
751                                 myView->Redraw();
752                         }
753                 }
754                 else if (nFlags & MK_SHIFT)
755                 {
756                         GetDocument()->ShiftMoveEvent(point.x,point.y,myView);
757                 }
758                 else
759                 {
760                         GetDocument()->MoveEvent(point.x,point.y,myView);
761                 }
762         }
763 }
764
765 void CViewer3dView::OnUpdateBUTTONHlrOff (CCmdUI* pCmdUI)
766 {
767   pCmdUI->SetCheck (!myHlrModeIsOn);
768   pCmdUI->Enable   (myHlrModeIsOn);
769 }
770
771 void CViewer3dView::OnUpdateBUTTONHlrOn (CCmdUI* pCmdUI)
772 {
773   pCmdUI->SetCheck (myHlrModeIsOn);
774   pCmdUI->Enable   (!myHlrModeIsOn);
775 }
776
777 void CViewer3dView::OnUpdateBUTTONPanGlo(CCmdUI* pCmdUI) 
778 {
779     pCmdUI->SetCheck (myCurrentMode == CurAction3d_GlobalPanning);
780         pCmdUI->Enable   (myCurrentMode != CurAction3d_GlobalPanning);  
781         
782 }
783
784 void CViewer3dView::OnUpdateBUTTONPan(CCmdUI* pCmdUI) 
785 {
786     pCmdUI->SetCheck (myCurrentMode == CurAction3d_DynamicPanning);
787         pCmdUI->Enable   (myCurrentMode != CurAction3d_DynamicPanning );        
788 }
789
790 void CViewer3dView::OnUpdateBUTTONZoomProg(CCmdUI* pCmdUI) 
791 {
792     pCmdUI->SetCheck (myCurrentMode == CurAction3d_DynamicZooming );
793         pCmdUI->Enable   (myCurrentMode != CurAction3d_DynamicZooming); 
794 }
795
796 void CViewer3dView::OnUpdateBUTTONZoomWin(CCmdUI* pCmdUI) 
797 {
798     pCmdUI->SetCheck (myCurrentMode == CurAction3d_WindowZooming);
799         pCmdUI->Enable   (myCurrentMode != CurAction3d_WindowZooming);  
800 }
801
802 void CViewer3dView::OnUpdateBUTTONRot(CCmdUI* pCmdUI) 
803 {
804     pCmdUI->SetCheck (myCurrentMode == CurAction3d_DynamicRotation);
805         pCmdUI->Enable   (myCurrentMode != CurAction3d_DynamicRotation);        
806 }
807
808 void CViewer3dView::DrawRectangle (Standard_Integer theMinX,
809                                    Standard_Integer theMinY,
810                                    Standard_Integer theMaxX,
811                                    Standard_Integer theMaxY,
812                                    Standard_Boolean theToDraw,
813                                    Aspect_TypeOfLine theLineType)
814 {
815   const Handle(AIS_InteractiveContext)& aCtx = GetDocument()->GetAISContext();
816   if (!theToDraw)
817   {
818     aCtx->Remove (myRect, false);
819     aCtx->CurrentViewer()->RedrawImmediate();
820     return;
821   }
822
823   CRect aRect;
824   GetWindowRect (aRect);
825   myRect->SetLineType (theLineType);
826   myRect->SetRectangle (theMinX, aRect.Height() - theMinY, theMaxX, aRect.Height() - theMaxY);
827   if (!aCtx->IsDisplayed (myRect))
828   {
829     aCtx->Display (myRect, false);
830   }
831   else
832   {
833     aCtx->Redisplay (myRect, false);
834   }
835   aCtx->CurrentViewer()->RedrawImmediate();
836 }
837
838 void CViewer3dView::OnModifyChangeBackground() 
839 {
840         Standard_Real R1;
841         Standard_Real G1;
842         Standard_Real B1;
843     myView->BackgroundColor(Quantity_TOC_RGB,R1,G1,B1);
844         COLORREF m_clr ;
845         m_clr = RGB(R1*255,G1*255,B1*255);
846
847         CColorDialog dlgColor(m_clr);
848         if (dlgColor.DoModal() == IDOK)
849         {
850                 m_clr = dlgColor.GetColor();
851                 R1 = GetRValue(m_clr)/255.;
852                 G1 = GetGValue(m_clr)/255.;
853                 B1 = GetBValue(m_clr)/255.;
854         myView->SetBackgroundColor(Quantity_TOC_RGB,R1,G1,B1);
855         }
856     myView->Redraw();
857 }
858
859 void CViewer3dView::OnDirectionalLight() 
860 {
861 // Directional light source creation
862
863 // Checking if the Active lights limit number is not reached
864         if( NbActiveLights>=myGraphicDriver->InquireLightLimit() )
865         {
866     CString aMsg;
867     aMsg.Format (L"You have reach the limit number of active lights (%d).\n Clear lights to create new ones.", myGraphicDriver->InquireLightLimit());
868                 MessageBox (aMsg, L"Light creation", MB_OK);
869                 return;
870         }
871
872         UpdateData(TRUE);
873         ((OCC_MainFrame*)AfxGetMainWnd())->SetStatusMessage("Pick a first point");
874         myCurrentMode = CurAction3d_BeginDirectionalLight;
875
876 TCollection_AsciiString Message("\
877 myCurrent_DirectionalLight = new V3d_DirectionalLight (gp_Dir (theDirection));\n\
878 \n\
879 myView->SetLightOn(myCurrent_DirectionalLight);\n\
880 \n\
881 ");
882 // Update The Result Message Dialog
883         GetDocument()->UpdateResultMessageDlg("V3d_DirectionalLight",Message);
884 }
885
886 void CViewer3dView::OnSpotLight() 
887 {
888 // Spot light source creation
889
890 // Checking if the Active lights limit number is not reached
891         if( NbActiveLights>=myGraphicDriver->InquireLightLimit() )
892         {
893     CString aMsg;
894     aMsg.Format(L"You have reach the limit number of active lights (%d).\n Clear lights to create new ones.", myGraphicDriver->InquireLightLimit());
895                 MessageBox (aMsg, L"Light creation", MB_OK);
896                 return;
897         }
898
899         ((OCC_MainFrame*)AfxGetMainWnd())->SetStatusMessage("Pick the light position");
900         myCurrentMode = CurAction3d_BeginSpotLight;
901
902 TCollection_AsciiString Message("\
903 myCurrent_SpotLight = new V3d_SpotLight (gp_Pnt (thePosition), gp_Dir (theDirection), Quantity_NOC_RED);\n\
904 \n\
905 myView->SetLightOn(myCurrent_SpotLight);\n\
906 \n\
907 ");
908 // Update The Result Message Dialog
909 GetDocument()->UpdateResultMessageDlg("V3d_SpotLight",Message);
910 }
911
912 void CViewer3dView::OnPositionalLight() 
913 {
914 // Positional light source creation
915
916 // Checking if the Active lights limit number is not reached
917         if( NbActiveLights>=myGraphicDriver->InquireLightLimit() )
918         {
919     CString aMsg;
920     aMsg.Format(L"You have reach the limit number of active lights (%d).\n Clear lights to create new ones.", myGraphicDriver->InquireLightLimit());
921     MessageBox(aMsg, L"Light creation", MB_OK);
922                 return;
923         }
924
925         myCurrent_PositionalLight=new V3d_PositionalLight (gp_Pnt (0,0,0), Quantity_NOC_GREEN);
926     myCurrent_PositionalLight->SetAttenuation (1, 0);
927         myView->SetLightOn(myCurrent_PositionalLight);
928         NbActiveLights++;
929         ((OCC_MainFrame*)AfxGetMainWnd())->SetStatusMessage("Pick the light position");
930         myCurrentMode = CurAction3d_BeginPositionalLight;
931
932 TCollection_AsciiString Message("\
933 myCurrent_PositionalLight=new V3d_PositionalLight (gp_Pnt(thePosition),Quantity_NOC_GREEN);\n\
934 myCurrent_PositionalLight->SetAttenuation (1, 0);\n\
935 \n\
936 myView->SetLightOn(myCurrent_PositionalLight) ;\n\
937   ");
938
939   // Update The Result Message Dialog
940 GetDocument()->UpdateResultMessageDlg("V3d_PositionalLight",Message);
941 }
942
943 void CViewer3dView::OnAmbientLight() 
944 {
945 // Ambiant light source creation
946
947 // Checking if the Active lights limit number is not reached
948         if( NbActiveLights>=myGraphicDriver->InquireLightLimit() )
949         {
950     CString aMsg;
951     aMsg.Format(L"You have reach the limit number of active lights (%d).\n Clear lights to create new ones.", myGraphicDriver->InquireLightLimit());
952     MessageBox(aMsg, L"Light creation", MB_OK);
953                 return;
954         }
955
956         myCurrent_AmbientLight=new V3d_AmbientLight (Quantity_NOC_GRAY);
957         myView->SetLightOn(myCurrent_AmbientLight) ;    
958         NbActiveLights++;
959
960         myView->UpdateLights();
961         myView->Redraw();
962
963 TCollection_AsciiString Message("\
964 myCurrent_AmbientLight=new V3d_AmbientLight(Quantity_NOC_GRAY);\n\
965 \n\
966 myView->SetLightOn(myCurrent_AmbientLight) ;\n\
967   ");
968
969   // Update The Result Message Dialog
970 GetDocument()->UpdateResultMessageDlg("V3d_AmbientLight",Message);
971 }
972
973
974 void CViewer3dView::OnScale() 
975 {
976         ScaleDlg Dlg(myView, this);
977         Dlg.DoModal();
978         myView->Redraw();
979 }
980
981 //V3d_View.hxx
982
983 void CViewer3dView::OnShadingmodel() 
984 {
985 TCollection_AsciiString Message("\
986 myView->SetShadingModel(V3d_TypeOfShadingModel myTypeOfShadingModel);\n\
987 \n\
988 myCurrent_V3d_View->Update();\n\
989   ");
990
991   // Update The Result Message Dialog
992 GetDocument()->UpdateResultMessageDlg("SetShadingModel",Message);
993
994         CShadingModelDlg Dlg(myView);
995         Dlg.DoModal();
996         myView->Redraw();
997 }
998
999
1000 void CViewer3dView::OnAntialiasingonoff() 
1001 {
1002   Graphic3d_RenderingParams& aParams = myView->ChangeRenderingParams();
1003   aParams.NbMsaaSamples = aParams.NbMsaaSamples == 0 ? 8 : 0;
1004         myView->Update();
1005
1006 TCollection_AsciiString Message("\
1007 Graphic3d_RenderingParams& aParams = myView->ChangeRenderingParams();\n\
1008 aParams.NbMsaaSamples = aParams.NbMsaaSamples == 0 ? 8 : 0;\n\
1009   ");
1010
1011   // Update The Result Message Dialog
1012 GetDocument()->UpdateResultMessageDlg("SetAntialiasingOn/SetAntialiasingOff",Message);
1013 }
1014
1015 void CViewer3dView::OnClearLights()
1016 {
1017 // Setting Off all viewer active lights
1018     V3d_ListOfLight lights;
1019     for (V3d_ListOfLightIterator anIter = myView->Viewer()->ActiveLightIterator(); anIter.More(); anIter.Next())
1020     {
1021         lights.Append (anIter.Value());
1022     }
1023     V3d_ListOfLightIterator itrLights(lights);
1024     for (; itrLights.More(); itrLights.Next())
1025     {
1026         myView->Viewer()->SetLightOff (itrLights.Value());
1027     }
1028
1029 // Setting Off all view active lights
1030     lights.Clear();
1031     for (V3d_ListOfLightIterator anIter = myView->ActiveLightIterator(); anIter.More(); anIter.Next())
1032     {
1033         lights.Append (anIter.Value());
1034     }
1035     itrLights.Initialize (lights);
1036     for (; itrLights.More(); itrLights.Next())
1037     {
1038         myView->SetLightOff (itrLights.Value());
1039     }
1040
1041     myView->Viewer()->SetDefaultLights(); // Setting the default lights on
1042
1043     NbActiveLights = 2; // There are 2 default active lights
1044
1045     myView->Update();
1046
1047 TCollection_AsciiString Message("\
1048 // Setting Off all viewer active lights\n\
1049 V3d_ListOfLight lights;\n\
1050 for (V3d_ListOfLightIterator anIter = myView->Viewer()->ActiveLightIterator(); anIter.More(); anIter.Next())\n\
1051 {\n\
1052     lights.Append (anIter.Value());\n\
1053 }\n\
1054 V3d_ListOfLightIterator itrLights(lights);\n\
1055 for (; itrLights.More(); itrLights.Next())\n\
1056 {\n\
1057     myView->Viewer()->SetLightOff (itrLights.Value())\n\
1058 }\n\
1059 \n\
1060 // Setting Off all view active lights\n\
1061 lights.Clear();\n\
1062 for (V3d_ListOfLightIterator anIter = myView->ActiveLightIterator(); anIter.More(); anIter.Next())\n\
1063 {\n\
1064     lights.Append (anIter.Value());\n\
1065 }\n\
1066 itrLights.Initialize(lights);\n\
1067 for (; itrLights.More(); itrLights.Next())\n\
1068 {\n\
1069     myView->SetLightOff (itrLights.Value());\n\
1070 }\n\
1071 \n\
1072 myView->Viewer()->SetDefaultLights();// Setting the default lights on\n\
1073   ");
1074
1075   // Update The Result Message Dialog
1076 GetDocument()->UpdateResultMessageDlg("SetLightOff",Message);
1077 }
1078
1079 void CViewer3dView::OnModelclipping() 
1080 {
1081   if (myClippingPlane.IsNull())
1082   {
1083     gp_Pln aClipPlane (gp_Pnt (0.0, 0.0, 0.0), gp_Dir (1.0, 0.0, 0.0));
1084     gp_Pln aFacePlane (gp_Pnt (0.1, 0.0, 0.0), gp_Dir (1.0, 0.0, 0.0));
1085
1086     // create clipping plane and add to view
1087     myClippingPlane = new Graphic3d_ClipPlane (aClipPlane);
1088
1089     // shape to represent clipping plane
1090     BRepBuilderAPI_MakeFace aMakeFaceCommand (aFacePlane, 200.0, -200.0, 410.0, -410.0);
1091     TopoDS_Face aShape = aMakeFaceCommand.Face();
1092     myShape = new AIS_Shape (aShape);
1093     myShape->SetTransparency (0.5);
1094   }
1095
1096   CModelClippingDlg aClippingDlg (myView, myShape, myClippingPlane, GetDocument());
1097
1098   aClippingDlg.DoModal();
1099 }
1100
1101 void CViewer3dView::OnOptionsTrihedronStaticTrihedron() 
1102 {
1103         CTrihedronDlg Dlg(myView, GetDocument());
1104         Dlg.DoModal();
1105 }
1106
1107 void CViewer3dView::InitButtons()
1108 {
1109   myXmin=0;
1110   myYmin=0;  
1111   myXmax=0;
1112   myYmax=0;
1113   myCurZoom=0;
1114   myCurrentMode = CurAction3d_Nothing;
1115 }
1116
1117 void CViewer3dView::Reset()
1118 {
1119   InitButtons();
1120   myVisMode = VIS_SHADE;
1121   if (!myView.IsNull())
1122   {
1123     RedrawVisMode();
1124     myView->Reset();
1125   }
1126 }
1127
1128 void CViewer3dView::GetViewAt (Standard_Real& theX, Standard_Real& theY, Standard_Real& theZ) const
1129 {
1130   myView->At (theX, theY, theZ);
1131 }
1132
1133 void CViewer3dView::SetViewAt (const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ)
1134 {
1135   myView->SetAt (theX, theY, theZ);
1136 }
1137
1138 void CViewer3dView::GetViewEye(Standard_Real& X, Standard_Real& Y, Standard_Real& Z)
1139 {
1140         myView->Eye(X,Y,Z);
1141 }
1142
1143 void CViewer3dView::SetViewEye(Standard_Real X, Standard_Real Y, Standard_Real Z)
1144 {
1145         myView->SetEye(X,Y,Z);
1146 }
1147
1148 Standard_Real CViewer3dView::GetViewScale()
1149 {
1150         return myView->Scale();
1151 }
1152
1153 void CViewer3dView::SetViewScale(Standard_Real Coef)
1154 {
1155         myView->SetScale(Coef);
1156 }
1157
1158 void CViewer3dView::RedrawVisMode()
1159 {
1160   switch (myVisMode)
1161   {
1162   case VIS_WIREFRAME:
1163     GetDocument()->GetAISContext()->SetDisplayMode (AIS_WireFrame, Standard_True);
1164     myView->SetComputedMode (Standard_False);
1165     myView->Redraw();
1166     break;
1167   case VIS_SHADE:
1168     GetDocument()->GetAISContext()->SetDisplayMode (AIS_Shaded, Standard_True);
1169     myView->SetComputedMode (Standard_False);
1170     myView->Redraw();
1171     break;
1172   case VIS_HLR:
1173     SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
1174     myView->SetComputedMode (Standard_True);
1175     myView->Redraw();
1176     SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
1177     GetDocument()->GetAISContext()->SetDisplayMode (AIS_WireFrame, Standard_True);
1178     break;
1179   }
1180 }