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