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