0028316: Coding Rules - Elimilate confusing aliases of Standard_Real type in V3d_View
[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
310   TCollection_AsciiString aMsg ("myView->SetComputedMode (Standard_False);\n"
311                                 "  ");
312
313   // Update The Result Message Dialog
314   GetDocument()->UpdateResultMessageDlg ("SetComputedMode", aMsg);
315 }
316
317 void CViewer3dView::OnBUTTONHlrOn() 
318 {
319   SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
320   myHlrModeIsOn = Standard_True;
321   myView->SetComputedMode (myHlrModeIsOn);
322   SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
323
324   TCollection_AsciiString aMsg ("myView->SetComputedMode (Standard_True);\n"
325                                 "  ");
326
327   // Update The Result Message Dialog
328   GetDocument()->UpdateResultMessageDlg ("SetComputedMode", aMsg);
329 }
330
331 void CViewer3dView::OnBUTTONPan() 
332 {  myCurrentMode = CurAction3d_DynamicPanning; }
333
334 void CViewer3dView::OnBUTTONPanGlo() 
335 {
336   // save the current zoom value 
337   myCurZoom = myView->Scale();
338   // Do a Global Zoom 
339   myView->FitAll();
340   // Set the mode 
341   myCurrentMode = CurAction3d_GlobalPanning;
342 }
343
344 void CViewer3dView::OnBUTTONReset() 
345 {   myView->Reset(); }
346
347 void CViewer3dView::OnBUTTONRot() 
348 {   myCurrentMode = CurAction3d_DynamicRotation; }
349
350
351 void CViewer3dView::OnBUTTONZoomAll() 
352 {
353   myView->FitAll();
354   myView->ZFitAll();
355 }
356
357 void CViewer3dView::OnBUTTONZoomProg() 
358 {  myCurrentMode = CurAction3d_DynamicZooming; }
359
360 void CViewer3dView::OnBUTTONZoomWin() 
361 {  myCurrentMode = CurAction3d_WindowZooming; }
362
363 void CViewer3dView::OnLButtonDown(UINT nFlags, CPoint point) 
364 {
365   //  save the current mouse coordinate in min 
366   myXmin=point.x;  myYmin=point.y;
367   myXmax=point.x;  myYmax=point.y;
368
369   if ( nFlags & MK_CONTROL ) 
370           {
371             // Button MB1 down Control :start zomming 
372         // SetCursor(AfxGetApp()->LoadStandardCursor());
373           }
374         else // if ( Ctrl )
375           {
376         switch (myCurrentMode)
377         {
378          case CurAction3d_Nothing : // start a drag
379            if (nFlags & MK_SHIFT)
380                 GetDocument()->ShiftDragEvent(myXmax,myYmax,-1,myView);
381            else
382                 GetDocument()->DragEvent(myXmax,myYmax,-1,myView);
383         break;
384          break;
385          case CurAction3d_DynamicZooming : // noting
386          break;
387          case CurAction3d_WindowZooming : 
388          break;
389          case CurAction3d_DynamicPanning :// noting
390          break;
391          case CurAction3d_GlobalPanning :// noting
392         break;
393         case  CurAction3d_DynamicRotation :
394           if (myHlrModeIsOn)
395           {
396             myView->SetComputedMode (Standard_False);
397           }
398           myView->StartRotation (point.x, point.y);
399           break;
400         case  CurAction3d_BeginPositionalLight :
401                         {
402                         p1 = ConvertClickToPoint(point.x,point.y,myView);
403                         myCurrent_PositionalLight->SetPosition(p1.X(),p1.Y(),p1.Z()) ;
404                         ((OCC_MainFrame*)AfxGetMainWnd())->SetStatusMessage("Ready");
405                         myCurrentMode = CurAction3d_Nothing;
406
407 TCollection_AsciiString Message("\
408 myCurrent_PositionalLight->SetPosition(Xp, Yp, Zp) ;\n\
409 ");
410 // Update The Result Message Dialog
411 GetDocument()->UpdateResultMessageDlg("SetPosition",Message);
412                         }
413         break;
414         case  CurAction3d_BeginSpotLight :
415                         {
416                         p1 = ConvertClickToPoint(point.x,point.y,myView);
417                         myCurrent_SpotLight = new V3d_SpotLight(myView->Viewer(),0.,0.,1., p1.X(),p1.Y(),p1.Z(),Quantity_NOC_RED);
418                         myView->SetLightOn(myCurrent_SpotLight);
419                         NbActiveLights++;
420                         p2 = gp_Pnt(p1.X(),p1.Y(),p1.Z()+1.);
421                         Standard_Real coneHeigth=p1.Distance(p2);
422                         BRepPrimAPI_MakeCone MakeCone(gp_Ax2(p1, gp_Dir(gp_Vec(p1, p2))), 
423                                 0, (p1.Distance(p2))/tan(1.04), coneHeigth);
424                         spotConeShape->Set(MakeCone.Solid());
425                         GetDocument()->GetAISContext()->Display (spotConeShape, 0, -1, Standard_True);
426                         ((OCC_MainFrame*)AfxGetMainWnd())->SetStatusMessage("Pick the target point");
427                         myCurrentMode = CurAction3d_TargetSpotLight;
428
429 TCollection_AsciiString Message("\
430 myCurrent_SpotLight->SetDirection(Xv, Yv, Zv);\n\
431 ");
432 // Update The Result Message Dialog
433 GetDocument()->UpdateResultMessageDlg("SetDirection",Message);
434                         }
435         break;
436         case  CurAction3d_TargetSpotLight :
437                         {
438                         p2 = ConvertClickToPoint(point.x,point.y,myView);
439                         ((OCC_MainFrame*)AfxGetMainWnd())->SetStatusMessage("Pick a third point (to define the angle)");
440                         myCurrentMode = CurAction3d_EndSpotLight;
441
442 TCollection_AsciiString Message("\
443 myCurrent_SpotLight->SetAngle(Angle) ;\n\
444 ");
445 // Update The Result Message Dialog
446 GetDocument()->UpdateResultMessageDlg("SetAngle",Message);
447                         }
448                 break;
449         case  CurAction3d_EndSpotLight :
450                         GetDocument()->GetAISContext()->Erase (spotConeShape, Standard_True);
451                         ((OCC_MainFrame*)AfxGetMainWnd())->SetStatusMessage("Ready");
452                         myCurrentMode = CurAction3d_Nothing;
453         break;
454                 case CurAction3d_BeginDirectionalLight:
455                         {
456                                 p1 = ConvertClickToPoint(point.x,point.y,myView);
457                                 p2 = gp_Pnt(p1.X(),p1.Y(),p1.Z()+1.);
458                                 BRepBuilderAPI_MakeEdge MakeEdge(p1, p2);
459                                 directionalEdgeShape->Set(MakeEdge.Edge());
460                                 GetDocument()->GetAISContext()->Display (directionalEdgeShape, 0, -1, Standard_True);
461                         // Create a directional light
462                                 myCurrent_DirectionalLight = new V3d_DirectionalLight(myView->Viewer(), p1.X(),p1.Y(),p1.Z(),0.,0.,1.);
463                                 myView->SetLightOn(myCurrent_DirectionalLight);
464                                 NbActiveLights++;
465                                 ((OCC_MainFrame*)AfxGetMainWnd())->SetStatusMessage("Pick the target point");
466                                 myCurrentMode = CurAction3d_EndDirectionalLight;
467
468
469 TCollection_AsciiString Message("\
470 myCurrent_DirectionalLight->SetDirection(Xv, Yv, Zv);\n\
471 ");
472 // Update The Result Message Dialog
473 GetDocument()->UpdateResultMessageDlg("SetDirection",Message);
474                         }
475                 break;
476                 case CurAction3d_EndDirectionalLight:
477                         GetDocument()->GetAISContext()->Erase (directionalEdgeShape, Standard_True);
478                         ((OCC_MainFrame*)AfxGetMainWnd())->SetStatusMessage("Ready");
479                         myCurrentMode = CurAction3d_Nothing;
480                 break;
481         }
482     }
483 }
484
485 void CViewer3dView::OnKeyDown(UINT nChar, UINT /*nRepCnt*/, UINT /*nFlags*/) 
486 {
487   
488   if( nChar == X_Key || nChar == Y_Key || nChar == Z_Key )
489     myAxisKey = nChar;
490   else if( (nChar == VK_ADD || nChar == VK_SUBTRACT) && myAxisKey )
491   {
492     myScaleDirection = nChar;
493     if( myAxisKey && myScaleDirection )
494     {
495       switch( myAxisKey )
496       {
497       case X_Key:
498         if( myScaleDirection == VK_ADD ) scaleX ++;
499         if( myScaleDirection == VK_SUBTRACT ) scaleX --;
500         break;
501       case Y_Key:
502         if( myScaleDirection == VK_ADD ) scaleY ++;
503         if( myScaleDirection == VK_SUBTRACT ) scaleY --;
504         break;
505       case Z_Key:
506         if( myScaleDirection == VK_ADD ) scaleZ ++;
507         if( myScaleDirection == VK_SUBTRACT ) scaleZ --;
508         break;
509       default:
510         break;
511       }
512       if( scaleX < 1 ) scaleX = 1;
513       if( scaleY < 1 ) scaleY = 1;
514       if( scaleZ < 1 ) scaleZ = 1;
515       
516       myView->SetAxialScale( scaleX, scaleY, scaleZ );
517     }
518   }
519 }
520
521 void CViewer3dView::OnLButtonUp(UINT nFlags, CPoint point) 
522 {
523    if ( nFlags & MK_CONTROL ) 
524           {
525         return;
526           }
527         else // if ( Ctrl )
528           {
529         switch (myCurrentMode)
530         {
531          case CurAction3d_Nothing :
532          if (point.x == myXmin && point.y == myYmin)
533          { // no offset between down and up --> selectEvent
534             myXmax=point.x;  
535             myYmax=point.y;
536             if (nFlags & MK_SHIFT )
537               GetDocument()->ShiftInputEvent(point.x,point.y,myView);
538             else
539               GetDocument()->InputEvent     (point.x,point.y,myView);
540          } else
541          {
542             DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False);
543             myXmax=point.x;  
544             myYmax=point.y;
545                     if (nFlags & MK_SHIFT)
546                                 GetDocument()->ShiftDragEvent(point.x,point.y,1,myView);
547                         else
548                                 GetDocument()->DragEvent(point.x,point.y,1,myView);
549          }
550          break;
551          case CurAction3d_DynamicZooming :
552              // SetCursor(AfxGetApp()->LoadStandardCursor());
553                myCurrentMode = CurAction3d_Nothing;
554          break;
555          case CurAction3d_WindowZooming :
556            DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False);
557            myXmax=point.x;  
558            myYmax=point.y;
559                if ((abs(myXmin-myXmax)>ValZWMin) || (abs(myYmin-myYmax)>ValZWMin))
560                                          // Test if the zoom window is greater than a minimale window.
561                         {
562                           // Do the zoom window between Pmin and Pmax
563                           myView->WindowFitAll(myXmin,myYmin,myXmax,myYmax);  
564                         }  
565                myCurrentMode = CurAction3d_Nothing;
566          break;
567          case CurAction3d_DynamicPanning :
568            myCurrentMode = CurAction3d_Nothing;
569          break;
570          case CurAction3d_GlobalPanning :
571                myView->Place(point.x,point.y,myCurZoom); 
572                myCurrentMode = CurAction3d_Nothing;
573         break;
574         case  CurAction3d_DynamicRotation :
575                myCurrentMode = CurAction3d_Nothing;
576         break;
577         } //switch (myCurrentMode)
578     } //        else // if ( Ctrl )
579 }
580
581 void CViewer3dView::OnMButtonDown(UINT nFlags, CPoint /*point*/) 
582 {
583    if ( nFlags & MK_CONTROL ) 
584           {
585         // Button MB2 down Control : panning init  
586         // SetCursor(AfxGetApp()->LoadStandardCursor());
587           }
588 }
589
590 void CViewer3dView::OnMButtonUp(UINT nFlags, CPoint /*point*/) 
591 {
592    if ( nFlags & MK_CONTROL ) 
593           {
594         // Button MB2 down Control : panning init  
595         // SetCursor(AfxGetApp()->LoadStandardCursor());
596           }
597 }
598
599 void CViewer3dView::OnRButtonDown(UINT nFlags, CPoint point) 
600 {
601   if ( nFlags & MK_CONTROL )
602   {
603     // SetCursor(AfxGetApp()->LoadStandardCursor());
604     if (myHlrModeIsOn)
605     {
606       myView->SetComputedMode (Standard_False);
607     }
608     myView->StartRotation (point.x, point.y);
609   }
610   else // if ( Ctrl )
611   {
612     GetDocument()->Popup (point.x, point.y, myView);
613   }
614 }
615
616 void CViewer3dView::OnRButtonUp(UINT /*nFlags*/, CPoint /*point*/) 
617 {
618   SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
619   myView->SetComputedMode (myHlrModeIsOn);
620   SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
621 }
622
623 void CViewer3dView::OnMouseMove(UINT nFlags, CPoint point) 
624 {
625     //   ============================  LEFT BUTTON =======================
626   if ( nFlags & MK_LBUTTON)
627     {
628      if ( nFlags & MK_CONTROL ) 
629           {
630             // move with MB1 and Control : on the dynamic zooming  
631             // Do the zoom in function of mouse's coordinates  
632             myView->Zoom(myXmax,myYmax,point.x,point.y); 
633             // save the current mouse coordinate in min 
634                 myXmax = point.x; 
635         myYmax = point.y;       
636           }
637           else // if ( Ctrl )
638           {
639         switch (myCurrentMode)
640         {
641          case CurAction3d_Nothing :
642
643            DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False);
644            myXmax = point.x;      myYmax = point.y;
645            if (nFlags & MK_SHIFT)               
646              GetDocument()->ShiftDragEvent(myXmax,myYmax,0,myView);
647            else
648              GetDocument()->DragEvent(myXmax,myYmax,0,myView);
649            DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_True);
650            break;
651          case CurAction3d_DynamicZooming :
652                myView->Zoom(myXmax,myYmax,point.x,point.y); 
653                // save the current mouse coordinate in min \n";
654                myXmax=point.x;  myYmax=point.y;
655          break;
656          case CurAction3d_WindowZooming :
657                    myXmax = point.x; myYmax = point.y;  
658            DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False,LongDash);
659            DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_True,LongDash);
660
661          break;
662          case CurAction3d_DynamicPanning :
663                    myView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
664                    myXmax = point.x; myYmax = point.y;  
665          break;
666          case CurAction3d_GlobalPanning : // nothing           
667         break;
668         case  CurAction3d_DynamicRotation :
669           myView->Rotation(point.x,point.y);
670               myView->Redraw();
671         break;
672         }//  switch (myCurrentMode)
673       }// if ( nFlags & MK_CONTROL )  else 
674     } else //   if ( nFlags & MK_LBUTTON) 
675     //   ============================  MIDDLE BUTTON =======================
676     if ( nFlags & MK_MBUTTON)
677     {
678      if ( nFlags & MK_CONTROL ) 
679           {
680                 myView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
681                 myXmax = point.x; myYmax = point.y;     
682
683           }
684     } else //  if ( nFlags & MK_MBUTTON)
685     //   ============================  RIGHT BUTTON =======================
686     if ( nFlags & MK_RBUTTON)
687     {
688      if ( nFlags & MK_CONTROL ) 
689           {
690          myView->Rotation(point.x,point.y);
691           }
692     }else //if ( nFlags & MK_RBUTTON)
693     //   ============================  NO BUTTON =======================
694     {  // No buttons 
695                 myXmax = point.x; myYmax = point.y;     
696                 if (myCurrentMode ==  CurAction3d_EndDirectionalLight) 
697                 {
698                         p2 = ConvertClickToPoint(point.x,point.y,myView);
699                         //Update the light dynamically
700                         if( p1.Distance(p2)>Precision::Confusion())
701                         {
702                                 BRepBuilderAPI_MakeEdge MakeEdge(p1, p2);
703                                 directionalEdgeShape->Set(MakeEdge.Edge());
704                                 GetDocument()->GetAISContext()->Redisplay(directionalEdgeShape,0,Standard_True);
705                                 myCurrent_DirectionalLight->SetDirection(p2.X()-p1.X(),p2.Y()-p1.Y(),p2.Z()-p1.Z());
706                                 myView->UpdateLights();
707                         }
708                 }
709                 else if (myCurrentMode ==  CurAction3d_BeginPositionalLight) 
710                 {
711                         p2 = ConvertClickToPoint(point.x,point.y,myView);
712                         //Update the light dynamically
713                         myCurrent_PositionalLight->SetPosition(p2.X(),p2.Y(),p2.Z());
714                         myView->UpdateLights();
715                 }
716                 else if (myCurrentMode ==  CurAction3d_TargetSpotLight) 
717                 {
718                         p2 = ConvertClickToPoint(point.x,point.y,myView);
719                         //Update the light dynamically
720                         Standard_Real coneHeigth=p1.Distance(p2);
721                         if( coneHeigth>Precision::Confusion())
722                         {
723                                 BRepPrimAPI_MakeCone MakeCone(gp_Ax2(p1, gp_Dir(gp_Vec(p1, p2))), 
724                                         0, (p1.Distance(p2))/tan(1.04), coneHeigth);
725                                 spotConeShape->Set(MakeCone.Solid());
726                                 GetDocument()->GetAISContext()->Redisplay(spotConeShape,0,Standard_True);
727                                 myCurrent_SpotLight->SetDirection(p2.X()-p1.X(),p2.Y()-p1.Y(),p2.Z()-p1.Z());
728                                 myView->UpdateLights();
729                         }
730                 }
731                 else if (myCurrentMode ==  CurAction3d_EndSpotLight) 
732                 {
733                         p3 = ConvertClickToPoint(point.x,point.y,myView);
734                         //Update the light dynamically
735                         Standard_Real coneHeigth=p1.Distance(p2);
736                         if( (p2.Distance(p3))>Precision::Confusion())
737                         {
738                                 BRepPrimAPI_MakeCone MakeCone(gp_Ax2(p1, gp_Dir(gp_Vec(p1, p2))), 
739                                         0, p2.Distance(p3), coneHeigth);
740                                 spotConeShape->Set(MakeCone.Solid());
741                                 GetDocument()->GetAISContext()->Redisplay(spotConeShape,0,Standard_True);
742                                 myCurrent_SpotLight->SetAngle(atan(p2.Distance(p3)/p1.Distance(p2))) ;
743                                 myView->UpdateLights();
744                         }
745                 }
746                 if (nFlags & MK_SHIFT)
747                         GetDocument()->ShiftMoveEvent(point.x,point.y,myView);
748                 else
749                         GetDocument()->MoveEvent(point.x,point.y,myView);
750         }
751 }
752
753 void CViewer3dView::OnUpdateBUTTONHlrOff (CCmdUI* pCmdUI)
754 {
755   pCmdUI->SetCheck (!myHlrModeIsOn);
756   pCmdUI->Enable   (myHlrModeIsOn);
757 }
758
759 void CViewer3dView::OnUpdateBUTTONHlrOn (CCmdUI* pCmdUI)
760 {
761   pCmdUI->SetCheck (myHlrModeIsOn);
762   pCmdUI->Enable   (!myHlrModeIsOn);
763 }
764
765 void CViewer3dView::OnUpdateBUTTONPanGlo(CCmdUI* pCmdUI) 
766 {
767     pCmdUI->SetCheck (myCurrentMode == CurAction3d_GlobalPanning);
768         pCmdUI->Enable   (myCurrentMode != CurAction3d_GlobalPanning);  
769         
770 }
771
772 void CViewer3dView::OnUpdateBUTTONPan(CCmdUI* pCmdUI) 
773 {
774     pCmdUI->SetCheck (myCurrentMode == CurAction3d_DynamicPanning);
775         pCmdUI->Enable   (myCurrentMode != CurAction3d_DynamicPanning );        
776 }
777
778 void CViewer3dView::OnUpdateBUTTONZoomProg(CCmdUI* pCmdUI) 
779 {
780     pCmdUI->SetCheck (myCurrentMode == CurAction3d_DynamicZooming );
781         pCmdUI->Enable   (myCurrentMode != CurAction3d_DynamicZooming); 
782 }
783
784 void CViewer3dView::OnUpdateBUTTONZoomWin(CCmdUI* pCmdUI) 
785 {
786     pCmdUI->SetCheck (myCurrentMode == CurAction3d_WindowZooming);
787         pCmdUI->Enable   (myCurrentMode != CurAction3d_WindowZooming);  
788 }
789
790 void CViewer3dView::OnUpdateBUTTONRot(CCmdUI* pCmdUI) 
791 {
792     pCmdUI->SetCheck (myCurrentMode == CurAction3d_DynamicRotation);
793         pCmdUI->Enable   (myCurrentMode != CurAction3d_DynamicRotation);        
794 }
795
796 void CViewer3dView::DrawRectangle(const Standard_Integer  MinX    ,
797                                                             const Standard_Integer  MinY    ,
798                                         const Standard_Integer  MaxX ,
799                                                             const Standard_Integer  MaxY ,
800                                                             const Standard_Boolean  Draw , 
801                                         const LineStyle aLineStyle)
802 {
803     static int m_DrawMode;
804     if  (!m_Pen && aLineStyle ==Solid )
805         {m_Pen = new CPen(PS_SOLID, 1, RGB(0,0,0)); m_DrawMode = R2_MERGEPENNOT;}
806     else if (!m_Pen && aLineStyle ==Dot )
807         {m_Pen = new CPen(PS_DOT, 1, RGB(0,0,0));   m_DrawMode = R2_XORPEN;}
808     else if (!m_Pen && aLineStyle == ShortDash)
809         {m_Pen = new CPen(PS_DASH, 1, RGB(255,0,0));    m_DrawMode = R2_XORPEN;}
810     else if (!m_Pen && aLineStyle == LongDash)
811         {m_Pen = new CPen(PS_DASH, 1, RGB(0,0,0));      m_DrawMode = R2_NOTXORPEN;}
812     else if (aLineStyle == Default) 
813         { m_Pen = NULL; m_DrawMode = R2_MERGEPENNOT;}
814
815     CPen* aOldPen = NULL;
816     CClientDC clientDC(this);
817     if (m_Pen) aOldPen = clientDC.SelectObject(m_Pen);
818     clientDC.SetROP2(m_DrawMode);
819
820     static              Standard_Integer StoredMinX, StoredMaxX, StoredMinY, StoredMaxY;
821     static              Standard_Boolean m_IsVisible;
822
823     if ( m_IsVisible && !Draw) // move or up  : erase at the old position 
824     {
825      clientDC.MoveTo(StoredMinX,StoredMinY); 
826      clientDC.LineTo(StoredMinX,StoredMaxY); 
827      clientDC.LineTo(StoredMaxX,StoredMaxY); 
828            clientDC.LineTo(StoredMaxX,StoredMinY); 
829      clientDC.LineTo(StoredMinX,StoredMinY);
830      m_IsVisible = false;
831     }
832
833     StoredMinX = Min ( MinX, MaxX );
834     StoredMinY = Min ( MinY, MaxY );
835     StoredMaxX = Max ( MinX, MaxX );
836     StoredMaxY = Max ( MinY, MaxY);
837
838     if (Draw) // move : draw
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 = true;
846    }
847
848     if (m_Pen) 
849       clientDC.SelectObject(aOldPen);
850 }
851
852 void CViewer3dView::OnModifyChangeBackground() 
853 {
854         Standard_Real R1;
855         Standard_Real G1;
856         Standard_Real B1;
857     myView->BackgroundColor(Quantity_TOC_RGB,R1,G1,B1);
858         COLORREF m_clr ;
859         m_clr = RGB(R1*255,G1*255,B1*255);
860
861         CColorDialog dlgColor(m_clr);
862         if (dlgColor.DoModal() == IDOK)
863         {
864                 m_clr = dlgColor.GetColor();
865                 R1 = GetRValue(m_clr)/255.;
866                 G1 = GetGValue(m_clr)/255.;
867                 B1 = GetBValue(m_clr)/255.;
868         myView->SetBackgroundColor(Quantity_TOC_RGB,R1,G1,B1);
869         }
870     myView->Redraw();
871 }
872
873 void CViewer3dView::OnDirectionalLight() 
874 {
875 // Directional light source creation
876
877 // Checking if the Active lights limit number is not reached
878         if( NbActiveLights>=myGraphicDriver->InquireLightLimit() )
879         {
880     CString aMsg;
881     aMsg.Format (L"You have reach the limit number of active lights (%d).\n Clear lights to create new ones.", myGraphicDriver->InquireLightLimit());
882                 MessageBox (aMsg, L"Light creation", MB_OK);
883                 return;
884         }
885
886         UpdateData(TRUE);
887         ((OCC_MainFrame*)AfxGetMainWnd())->SetStatusMessage("Pick a first point");
888         myCurrentMode = CurAction3d_BeginDirectionalLight;
889
890 TCollection_AsciiString Message("\
891 myCurrent_DirectionalLight = new V3d_DirectionalLight(myView->Viewer(), Xt, Yt, Zt, Xp, Yp, Zp);\n\
892 \n\
893 myView->SetLightOn(myCurrent_DirectionalLight);\n\
894 \n\
895 ");
896 // Update The Result Message Dialog
897         GetDocument()->UpdateResultMessageDlg("V3d_DirectionalLight",Message);
898 }
899
900 void CViewer3dView::OnSpotLight() 
901 {
902 // Spot light source creation
903
904 // Checking if the Active lights limit number is not reached
905         if( NbActiveLights>=myGraphicDriver->InquireLightLimit() )
906         {
907     CString aMsg;
908     aMsg.Format(L"You have reach the limit number of active lights (%d).\n Clear lights to create new ones.", myGraphicDriver->InquireLightLimit());
909                 MessageBox (aMsg, L"Light creation", MB_OK);
910                 return;
911         }
912
913         ((OCC_MainFrame*)AfxGetMainWnd())->SetStatusMessage("Pick the light position");
914         myCurrentMode = CurAction3d_BeginSpotLight;
915
916 TCollection_AsciiString Message("\
917 myCurrent_SpotLight = new V3d_SpotLight(myView->Viewer(), Xt, Yt, Zt, Xp, Yp, Zp,Quantity_NOC_RED);\n\
918 \n\
919 myView->SetLightOn(myCurrent_SpotLight);\n\
920 \n\
921 ");
922 // Update The Result Message Dialog
923 GetDocument()->UpdateResultMessageDlg("V3d_SpotLight",Message);
924 }
925
926 void CViewer3dView::OnPositionalLight() 
927 {
928 // Positional light source creation
929
930 // Checking if the Active lights limit number is not reached
931         if( NbActiveLights>=myGraphicDriver->InquireLightLimit() )
932         {
933     CString aMsg;
934     aMsg.Format(L"You have reach the limit number of active lights (%d).\n Clear lights to create new ones.", myGraphicDriver->InquireLightLimit());
935     MessageBox(aMsg, L"Light creation", MB_OK);
936                 return;
937         }
938
939         myCurrent_PositionalLight=new V3d_PositionalLight(myView->Viewer(),0,0,0,Quantity_NOC_GREEN,1,0);
940         myView->SetLightOn(myCurrent_PositionalLight);
941         NbActiveLights++;
942         ((OCC_MainFrame*)AfxGetMainWnd())->SetStatusMessage("Pick the light position");
943         myCurrentMode = CurAction3d_BeginPositionalLight;
944
945 TCollection_AsciiString Message("\
946 myCurrent_PositionalLight=new V3d_PositionalLight(myView->Viewer(),Xp, Yp, Zp,Quantity_NOC_GREEN,1,0);\n\
947 \n\
948 myView->SetLightOn(myCurrent_PositionalLight) ;\n\
949   ");
950
951   // Update The Result Message Dialog
952 GetDocument()->UpdateResultMessageDlg("V3d_PositionalLight",Message);
953 }
954
955 void CViewer3dView::OnAmbientLight() 
956 {
957 // Ambiant light source creation
958
959 // Checking if the Active lights limit number is not reached
960         if( NbActiveLights>=myGraphicDriver->InquireLightLimit() )
961         {
962     CString aMsg;
963     aMsg.Format(L"You have reach the limit number of active lights (%d).\n Clear lights to create new ones.", myGraphicDriver->InquireLightLimit());
964     MessageBox(aMsg, L"Light creation", MB_OK);
965                 return;
966         }
967
968         myCurrent_AmbientLight=new V3d_AmbientLight(myView->Viewer(), Quantity_NOC_GRAY);
969         myView->SetLightOn(myCurrent_AmbientLight) ;    
970         NbActiveLights++;
971
972         myView->UpdateLights();
973
974 TCollection_AsciiString Message("\
975 myCurrent_AmbientLight=new V3d_AmbientLight(myView->Viewer(), Quantity_NOC_GRAY);\n\
976 \n\
977 myView->SetLightOn(myCurrent_AmbientLight) ;\n\
978   ");
979
980   // Update The Result Message Dialog
981 GetDocument()->UpdateResultMessageDlg("V3d_AmbientLight",Message);
982 }
983
984
985 void CViewer3dView::OnScale() 
986 {
987         ScaleDlg Dlg(myView, this);
988         Dlg.DoModal();
989         myView->Redraw();
990 }
991
992 //V3d_View.hxx
993
994 void CViewer3dView::OnShadingmodel() 
995 {
996 TCollection_AsciiString Message("\
997 myView->SetShadingModel(V3d_TypeOfShadingModel myTypeOfShadingModel);\n\
998 \n\
999 myCurrent_V3d_View->Update();\n\
1000   ");
1001
1002   // Update The Result Message Dialog
1003 GetDocument()->UpdateResultMessageDlg("SetShadingModel",Message);
1004
1005         CShadingModelDlg Dlg(myView);
1006         Dlg.DoModal();
1007         myView->Redraw();
1008 }
1009
1010
1011 void CViewer3dView::OnAntialiasingonoff() 
1012 {
1013   Graphic3d_RenderingParams& aParams = myView->ChangeRenderingParams();
1014   aParams.NbMsaaSamples = aParams.NbMsaaSamples == 0 ? 8 : 0;
1015         myView->Update();
1016
1017 TCollection_AsciiString Message("\
1018 Graphic3d_RenderingParams& aParams = myView->ChangeRenderingParams();\n\
1019 aParams.NbMsaaSamples = aParams.NbMsaaSamples == 0 ? 8 : 0;\n\
1020   ");
1021
1022   // Update The Result Message Dialog
1023 GetDocument()->UpdateResultMessageDlg("SetAntialiasingOn/SetAntialiasingOff",Message);
1024 }
1025
1026 void CViewer3dView::OnClearLights() 
1027 {
1028 //      Setting Off all viewer active lights
1029     TColStd_ListOfTransient lights;
1030         for(myView->Viewer()->InitActiveLights(); myView->Viewer()->MoreActiveLights(); myView->Viewer()->NextActiveLights())
1031     {
1032         lights.Append(myView->Viewer()->ActiveLight());
1033     }
1034     TColStd_ListIteratorOfListOfTransient itrLights(lights);
1035     for (; itrLights.More(); itrLights.Next())
1036     {
1037         Handle(V3d_Light) light = Handle(V3d_Light)::DownCast(itrLights.Value());
1038         myView->Viewer()->SetLightOff(light);
1039     }
1040
1041 //      Setting Off all view active lights
1042     lights.Clear();
1043     for(myView->InitActiveLights(); myView->MoreActiveLights(); myView->NextActiveLights())
1044     {
1045         lights.Append(myView->ActiveLight());
1046     }
1047     itrLights.Initialize(lights);
1048     for (; itrLights.More(); itrLights.Next())
1049     {
1050         Handle(V3d_Light) light = Handle(V3d_Light)::DownCast(itrLights.Value());
1051         myView->SetLightOff(light);
1052     }
1053
1054         myView->Viewer()->SetDefaultLights();// Setting the default lights on
1055
1056         NbActiveLights = 2;// There are 2 default active lights
1057
1058         myView->Update();
1059
1060 TCollection_AsciiString Message("\
1061 //      Setting Off all viewer active lights\n\
1062 TColStd_ListOfTransient lights;\n\
1063 for(myView->Viewer()->InitActiveLights(); myView->Viewer()->MoreActiveLights(); myView->Viewer()->NextActiveLights())\n\
1064 {\n\
1065     lights.Append(myView->Viewer()->ActiveLight());\n\
1066 }\n\
1067 TColStd_ListIteratorOfListOfTransient itrLights(lights);\n\
1068 for (; itrLights.More(); itrLights.Next())\n\
1069 {\n\
1070     Handle(V3d_Light) light = Handle(V3d_Light)::DownCast(itrLights.Value());\n\
1071     myView->Viewer()->SetLightOff(light);\n\
1072 }\n\
1073 \n\
1074 //      Setting Off all view active lights\n\
1075 lights.Clear();\n\
1076 for(myView->InitActiveLights(); myView->MoreActiveLights(); myView->NextActiveLights())\n\
1077 {\n\
1078     lights.Append(myView->ActiveLight());\n\
1079 }\n\
1080 itrLights.Initialize(lights);\n\
1081 for (; itrLights.More(); itrLights.Next())\n\
1082 {\n\
1083     Handle(V3d_Light) light = Handle(V3d_Light)::DownCast(itrLights.Value());\n\
1084     myView->SetLightOff(light);\n\
1085 }\n\
1086 \n\
1087 myView->Viewer()->SetDefaultLights();// Setting the default lights on\n\
1088   ");
1089
1090   // Update The Result Message Dialog
1091 GetDocument()->UpdateResultMessageDlg("SetLightOff",Message);
1092 }
1093
1094 void CViewer3dView::OnModelclipping() 
1095 {
1096   if (myClippingPlane.IsNull())
1097   {
1098     gp_Pln aClipPlane (gp_Pnt (0.0, 0.0, 0.0), gp_Dir (1.0, 0.0, 0.0));
1099     gp_Pln aFacePlane (gp_Pnt (0.1, 0.0, 0.0), gp_Dir (1.0, 0.0, 0.0));
1100
1101     // create clipping plane and add to view
1102     myClippingPlane = new Graphic3d_ClipPlane (aClipPlane);
1103
1104     // shape to represent clipping plane
1105     BRepBuilderAPI_MakeFace aMakeFaceCommand (aFacePlane, 200.0, -200.0, 410.0, -410.0);
1106     TopoDS_Face aShape = aMakeFaceCommand.Face();
1107     myShape = new AIS_Shape (aShape);
1108     myShape->SetTransparency (0.5);
1109   }
1110
1111   CModelClippingDlg aClippingDlg (myView, myShape, myClippingPlane, GetDocument());
1112
1113   aClippingDlg.DoModal();
1114 }
1115
1116 void CViewer3dView::OnOptionsTrihedronStaticTrihedron() 
1117 {
1118         CTrihedronDlg Dlg(myView, GetDocument());
1119         Dlg.DoModal();
1120 }
1121
1122 void CViewer3dView::InitButtons()
1123 {
1124   myXmin=0;
1125   myYmin=0;  
1126   myXmax=0;
1127   myYmax=0;
1128   myCurZoom=0;
1129   myCurrentMode = CurAction3d_Nothing;
1130 }
1131
1132 void CViewer3dView::Reset()
1133 {
1134   InitButtons();
1135   myVisMode = VIS_SHADE;
1136   if (!myView.IsNull())
1137   {
1138     RedrawVisMode();
1139     myView->Reset();
1140   }
1141 }
1142
1143 void CViewer3dView::GetViewAt (Standard_Real& theX, Standard_Real& theY, Standard_Real& theZ) const
1144 {
1145   myView->At (theX, theY, theZ);
1146 }
1147
1148 void CViewer3dView::SetViewAt (const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ)
1149 {
1150   myView->SetAt (theX, theY, theZ);
1151 }
1152
1153 void CViewer3dView::GetViewEye(Standard_Real& X, Standard_Real& Y, Standard_Real& Z)
1154 {
1155         myView->Eye(X,Y,Z);
1156 }
1157
1158 void CViewer3dView::SetViewEye(Standard_Real X, Standard_Real Y, Standard_Real Z)
1159 {
1160         myView->SetEye(X,Y,Z);
1161 }
1162
1163 Standard_Real CViewer3dView::GetViewScale()
1164 {
1165         return myView->Scale();
1166 }
1167
1168 void CViewer3dView::SetViewScale(Standard_Real Coef)
1169 {
1170         myView->SetScale(Coef);
1171 }
1172
1173 void CViewer3dView::RedrawVisMode()
1174 {
1175   switch (myVisMode)
1176   {
1177   case VIS_WIREFRAME:
1178     GetDocument()->GetAISContext()->SetDisplayMode (AIS_WireFrame, Standard_True);
1179     myView->SetComputedMode (Standard_False);
1180     break;
1181   case VIS_SHADE:
1182     GetDocument()->GetAISContext()->SetDisplayMode (AIS_Shaded, Standard_True);
1183     myView->SetComputedMode (Standard_False);
1184     break;
1185   case VIS_HLR:
1186     SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
1187     myView->SetComputedMode (Standard_True);
1188     SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
1189     GetDocument()->GetAISContext()->SetDisplayMode (AIS_WireFrame, Standard_True);
1190     break;
1191   }
1192 }