0024943: Port MFC samples to UNICODE for compatibility with VS2013
[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,Standard_True);
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,Standard_True);
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,Standard_True);
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 = NULL;
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     CString aMsg;
896     aMsg.Format (L"You have reach the limit number of active lights (%d).\n Clear lights to create new ones.", myGraphicDriver->InquireLightLimit());
897                 MessageBox (aMsg, L"Light creation", MB_OK);
898                 return;
899         }
900
901         UpdateData(TRUE);
902         ((OCC_MainFrame*)AfxGetMainWnd())->SetStatusMessage("Pick a first point");
903         GetDocument()->GetAISContext()->OpenLocalContext();
904         myCurrentMode = CurAction3d_BeginDirectionalLight;
905
906 TCollection_AsciiString Message("\
907 myCurrent_DirectionalLight = new V3d_DirectionalLight(myView->Viewer(), Xt, Yt, Zt, Xp, Yp, Zp);\n\
908 \n\
909 myView->SetLightOn(myCurrent_DirectionalLight);\n\
910 \n\
911 ");
912 // Update The Result Message Dialog
913         GetDocument()->UpdateResultMessageDlg("V3d_DirectionalLight",Message);
914 }
915
916 void CViewer3dView::OnSpotLight() 
917 {
918 // Spot light source creation
919
920 // Checking if the Active lights limit number is not reached
921         if( NbActiveLights>=myGraphicDriver->InquireLightLimit() )
922         {
923     CString aMsg;
924     aMsg.Format(L"You have reach the limit number of active lights (%d).\n Clear lights to create new ones.", myGraphicDriver->InquireLightLimit());
925                 MessageBox (aMsg, L"Light creation", MB_OK);
926                 return;
927         }
928
929         GetDocument()->GetAISContext()->OpenLocalContext();
930         ((OCC_MainFrame*)AfxGetMainWnd())->SetStatusMessage("Pick the light position");
931         myCurrentMode = CurAction3d_BeginSpotLight;
932
933 TCollection_AsciiString Message("\
934 myCurrent_SpotLight = new V3d_SpotLight(myView->Viewer(), Xt, Yt, Zt, Xp, Yp, Zp,Quantity_NOC_RED);\n\
935 \n\
936 myView->SetLightOn(myCurrent_SpotLight);\n\
937 \n\
938 ");
939 // Update The Result Message Dialog
940 GetDocument()->UpdateResultMessageDlg("V3d_SpotLight",Message);
941 }
942
943 void CViewer3dView::OnPositionalLight() 
944 {
945 // Positional 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         GetDocument()->GetAISContext()->OpenLocalContext();
957         myCurrent_PositionalLight=new V3d_PositionalLight(myView->Viewer(),0,0,0,Quantity_NOC_GREEN,1,0);
958         myView->SetLightOn(myCurrent_PositionalLight);
959         NbActiveLights++;
960         ((OCC_MainFrame*)AfxGetMainWnd())->SetStatusMessage("Pick the light position");
961         myCurrentMode = CurAction3d_BeginPositionalLight;
962
963 TCollection_AsciiString Message("\
964 myCurrent_PositionalLight=new V3d_PositionalLight(myView->Viewer(),Xp, Yp, Zp,Quantity_NOC_GREEN,1,0);\n\
965 \n\
966 myView->SetLightOn(myCurrent_PositionalLight) ;\n\
967   ");
968
969   // Update The Result Message Dialog
970 GetDocument()->UpdateResultMessageDlg("V3d_PositionalLight",Message);
971 }
972
973 void CViewer3dView::OnAmbientLight() 
974 {
975 // Ambiant light source creation
976
977 // Checking if the Active lights limit number is not reached
978         if( NbActiveLights>=myGraphicDriver->InquireLightLimit() )
979         {
980     CString aMsg;
981     aMsg.Format(L"You have reach the limit number of active lights (%d).\n Clear lights to create new ones.", myGraphicDriver->InquireLightLimit());
982     MessageBox(aMsg, L"Light creation", MB_OK);
983                 return;
984         }
985
986         GetDocument()->GetAISContext()->OpenLocalContext();
987         myCurrent_AmbientLight=new V3d_AmbientLight(myView->Viewer(), Quantity_NOC_GRAY);
988         myView->SetLightOn(myCurrent_AmbientLight) ;    
989         NbActiveLights++;
990         GetDocument()->GetAISContext()->CloseLocalContext();
991
992         myView->UpdateLights();
993
994 TCollection_AsciiString Message("\
995 myCurrent_AmbientLight=new V3d_AmbientLight(myView->Viewer(), Quantity_NOC_GRAY);\n\
996 \n\
997 myView->SetLightOn(myCurrent_AmbientLight) ;\n\
998   ");
999
1000   // Update The Result Message Dialog
1001 GetDocument()->UpdateResultMessageDlg("V3d_AmbientLight",Message);
1002 }
1003
1004
1005 void CViewer3dView::OnScale() 
1006 {
1007         ScaleDlg Dlg(myView, this);
1008         Dlg.DoModal();
1009         myView->Redraw();
1010 }
1011
1012 void CViewer3dView::OnZcueing() 
1013 {
1014         ZCueingDlg Dlg(myView, GetDocument());
1015         Dlg.DoModal();
1016         myView->Redraw();
1017 }
1018
1019 void CViewer3dView::OnZclipping() 
1020 {
1021         ZClippingDlg Dlg(myView, GetDocument());
1022         Dlg.DoModal();
1023         myView->Redraw();
1024 }
1025
1026 //V3d_View.hxx
1027
1028 void CViewer3dView::OnShadingmodel() 
1029 {
1030 TCollection_AsciiString Message("\
1031 myView->SetShadingModel(V3d_TypeOfShadingModel myTypeOfShadingModel);\n\
1032 \n\
1033 myCurrent_V3d_View->Update();\n\
1034   ");
1035
1036   // Update The Result Message Dialog
1037 GetDocument()->UpdateResultMessageDlg("SetShadingModel",Message);
1038
1039         CShadingModelDlg Dlg(myView);
1040         Dlg.DoModal();
1041         myView->Redraw();
1042 }
1043
1044
1045 void CViewer3dView::OnAntialiasingonoff() 
1046 {
1047         if(!myView->Antialiasing())
1048                 myView->SetAntialiasingOn();
1049         else
1050                 myView->SetAntialiasingOff();
1051
1052         myView->Update();
1053
1054 TCollection_AsciiString Message("\
1055 if(!myView->Antialiasing())\n\
1056         myView->SetAntialiasingOn();\n\
1057 else\n\
1058         myView->SetAntialiasingOff();\n\
1059   ");
1060
1061   // Update The Result Message Dialog
1062 GetDocument()->UpdateResultMessageDlg("SetAntialiasingOn/SetAntialiasingOff",Message);
1063 }
1064
1065 void CViewer3dView::OnClearLights() 
1066 {
1067 //      Setting Off all viewer active lights
1068     TColStd_ListOfTransient lights;
1069         for(myView->Viewer()->InitActiveLights(); myView->Viewer()->MoreActiveLights(); myView->Viewer()->NextActiveLights())
1070     {
1071         lights.Append(myView->Viewer()->ActiveLight());
1072     }
1073     TColStd_ListIteratorOfListOfTransient itrLights(lights);
1074     for (; itrLights.More(); itrLights.Next())
1075     {
1076         Handle(V3d_Light) light = Handle(V3d_Light)::DownCast(itrLights.Value());
1077         myView->Viewer()->SetLightOff(light);
1078     }
1079
1080 //      Setting Off all view active lights
1081     lights.Clear();
1082     for(myView->InitActiveLights(); myView->MoreActiveLights(); myView->NextActiveLights())
1083     {
1084         lights.Append(myView->ActiveLight());
1085     }
1086     itrLights.Initialize(lights);
1087     for (; itrLights.More(); itrLights.Next())
1088     {
1089         Handle(V3d_Light) light = Handle(V3d_Light)::DownCast(itrLights.Value());
1090         myView->SetLightOff(light);
1091     }
1092
1093         myView->Viewer()->SetDefaultLights();// Setting the default lights on
1094
1095         NbActiveLights = 2;// There are 2 default active lights
1096
1097         myView->Update();
1098
1099 TCollection_AsciiString Message("\
1100 //      Setting Off all viewer active lights\n\
1101 TColStd_ListOfTransient lights;\n\
1102 for(myView->Viewer()->InitActiveLights(); myView->Viewer()->MoreActiveLights(); myView->Viewer()->NextActiveLights())\n\
1103 {\n\
1104     lights.Append(myView->Viewer()->ActiveLight());\n\
1105 }\n\
1106 TColStd_ListIteratorOfListOfTransient itrLights(lights);\n\
1107 for (; itrLights.More(); itrLights.Next())\n\
1108 {\n\
1109     Handle(V3d_Light) light = Handle(V3d_Light)::DownCast(itrLights.Value());\n\
1110     myView->Viewer()->SetLightOff(light);\n\
1111 }\n\
1112 \n\
1113 //      Setting Off all view active lights\n\
1114 lights.Clear();\n\
1115 for(myView->InitActiveLights(); myView->MoreActiveLights(); myView->NextActiveLights())\n\
1116 {\n\
1117     lights.Append(myView->ActiveLight());\n\
1118 }\n\
1119 itrLights.Initialize(lights);\n\
1120 for (; itrLights.More(); itrLights.Next())\n\
1121 {\n\
1122     Handle(V3d_Light) light = Handle(V3d_Light)::DownCast(itrLights.Value());\n\
1123     myView->SetLightOff(light);\n\
1124 }\n\
1125 \n\
1126 myView->Viewer()->SetDefaultLights();// Setting the default lights on\n\
1127   ");
1128
1129   // Update The Result Message Dialog
1130 GetDocument()->UpdateResultMessageDlg("SetLightOff",Message);
1131 }
1132
1133 void CViewer3dView::OnModelclipping() 
1134 {
1135   if (myClippingPlane.IsNull())
1136   {
1137     gp_Pln aClipPlane (gp_Pnt (0.0, 0.0, 0.0), gp_Dir (1.0, 0.0, 0.0));
1138     gp_Pln aFacePlane (gp_Pnt (0.1, 0.0, 0.0), gp_Dir (1.0, 0.0, 0.0));
1139
1140     // create clipping plane and add to view
1141     myClippingPlane = new Graphic3d_ClipPlane (aClipPlane);
1142
1143     // shape to represent clipping plane
1144     BRepBuilderAPI_MakeFace aMakeFaceCommand (aFacePlane, 200.0, -200.0, 410.0, -410.0);
1145     TopoDS_Face aShape = aMakeFaceCommand.Face();
1146     myShape = new AIS_Shape (aShape);
1147     myShape->SetTransparency (0.5);
1148   }
1149
1150   CModelClippingDlg aClippingDlg (myView, myShape, myClippingPlane, GetDocument());
1151
1152   aClippingDlg.DoModal();
1153 }
1154
1155 void CViewer3dView::OnOptionsTrihedronStaticTrihedron() 
1156 {
1157         CTrihedronDlg Dlg(myView, GetDocument());
1158         Dlg.DoModal();
1159 }
1160
1161 void CViewer3dView::InitButtons()
1162 {
1163   myXmin=0;
1164   myYmin=0;  
1165   myXmax=0;
1166   myYmax=0;
1167   myCurZoom=0;
1168   myCurrentMode = CurAction3d_Nothing;
1169 }
1170
1171 void CViewer3dView::Reset()
1172 {
1173   InitButtons();
1174   myVisMode = VIS_SHADE;
1175   if (!myView.IsNull())
1176   {
1177     RedrawVisMode();
1178     myView->Reset();
1179   }
1180 }
1181
1182 void CViewer3dView::GetViewAt (V3d_Coordinate& theX, V3d_Coordinate& theY, V3d_Coordinate& theZ) const
1183 {
1184   myView->At (theX, theY, theZ);
1185 }
1186
1187 void CViewer3dView::SetViewAt (const V3d_Coordinate theX, const V3d_Coordinate theY, const V3d_Coordinate theZ)
1188 {
1189   myView->SetAt (theX, theY, theZ);
1190 }
1191
1192 void CViewer3dView::GetViewEye(V3d_Coordinate& X, V3d_Coordinate& Y, V3d_Coordinate& Z)
1193 {
1194         myView->Eye(X,Y,Z);
1195 }
1196
1197 void CViewer3dView::SetViewEye(V3d_Coordinate X, V3d_Coordinate Y, V3d_Coordinate Z)
1198 {
1199         myView->SetEye(X,Y,Z);
1200 }
1201
1202 Quantity_Factor CViewer3dView::GetViewScale()
1203 {
1204         return myView->Scale();
1205 }
1206
1207 void CViewer3dView::SetViewScale(Quantity_Factor Coef)
1208 {
1209         myView->SetScale(Coef);
1210 }
1211
1212 void CViewer3dView::RedrawVisMode()
1213 {
1214   switch (myVisMode)
1215   {
1216   case VIS_WIREFRAME:
1217     GetDocument()->GetAISContext()->SetDisplayMode(AIS_WireFrame);
1218     myView->SetComputedMode (Standard_False);
1219     break;
1220   case VIS_SHADE:
1221     GetDocument()->GetAISContext()->SetDisplayMode(AIS_Shaded);
1222     myView->SetComputedMode (Standard_False);
1223     break;
1224   case VIS_HLR:
1225     SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
1226     myView->SetComputedMode (Standard_True);
1227     SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
1228     GetDocument()->GetAISContext()->SetDisplayMode(AIS_WireFrame);
1229     break;
1230   }
1231 }