0028895: Visualization, V3d_View::SetComputedMode() - HLR calculation is performed...
[occt.git] / samples / mfc / standard / 09_Animation / src / AnimationView3D.cpp
index aa3ef38..0ffae37 100755 (executable)
@@ -105,10 +105,10 @@ CAnimationView3D::~CAnimationView3D()
 
 BOOL CAnimationView3D::PreCreateWindow(CREATESTRUCT& cs)
 {
-       // TODO: Modify the Window class or styles here by modifying
-       //  the CREATESTRUCT cs
-
-       return CView::PreCreateWindow(cs);
+  // TODO: Modify the Window class or styles here by modifying
+  //  the CREATESTRUCT cs
+  cs.lpszClass = ::AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | CS_OWNDC, ::LoadCursor(NULL, IDC_ARROW), NULL, NULL);
+  return CView::PreCreateWindow(cs);
 }
 
 /////////////////////////////////////////////////////////////////////////////
@@ -135,6 +135,7 @@ void CAnimationView3D::OnInitialUpdate()
 
   aViewer = GetDocument()->GetViewer();
   aViewer->SetDefaultTypeOfView (V3d_PERSPECTIVE);
+
   myView = aViewer->CreateView();
 
   // store for restore state after rotation (witch is in Degenerated mode)
@@ -156,8 +157,6 @@ void CAnimationView3D::OnInitialUpdate()
                                    /* I suspect another problem elsewhere  */
   ::PostMessage ( GetSafeHwnd () , WM_SIZE , SIZE_RESTORED , w + h*65536 ) ;
 
-  myPView = Handle(V3d_PerspectiveView)::DownCast (myView);
-
   m_Tune.Create ( IDD_TUNE , NULL ) ;
 
   RECT dlgrect;
@@ -225,38 +224,22 @@ CAnimationDoc* CAnimationView3D::GetDocument() // non-debug version is inline
 // CAnimationView3D message handlers
 void CAnimationView3D::OnFileExportImage()
 {
-  CFileDialog aDlg (FALSE, "*.BMP", NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
-    "BMP  Files (*.BMP)|*.bmp|"
-    "GIF  Files (*.GIF)|*.gif|"
-    "PNG  Files (*.PNG)|*.png|"
-    "JPEG Files (*.JPEG)|*.jpeg|"
-    "PPM  Files (*.PPM)|*.ppm|"
-    "TIFF Files (*.TIFF)|*.tiff|"
-    "TGA  Files (*.TGA)|*.tga|"
-    "EXR  Files (*.EXR)|*.exr||",
-    NULL);
-  if (aDlg.DoModal() != IDOK)
-  {
-    return;
-  }
-
-  SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
-  myView->Dump (aDlg.GetPathName());
-  SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
+  GetDocument()->ExportView (myView);
 }
 
-void CAnimationView3D::OnSize(UINT /*nType*/, int cx, int cy) 
+void CAnimationView3D::OnSize(UINT nType, int cx, int cy)
 {
-       m_cx = cx ;
-       m_cy = cy ;
-       if (!myView.IsNull())
-               myView->MustBeResized();
+  CView::OnSize (nType, cx, cy);
+  m_cx = cx ;
+  m_cy = cy ;
+  if (!myView.IsNull())
+    myView->MustBeResized();
 }
 
 void CAnimationView3D::OnBUTTONBack() 
-{ myView->SetProj(V3d_Xneg); } // See the back View
+{ myView->SetProj(V3d_Ypos); } // See the back View
 void CAnimationView3D::OnBUTTONFront() 
-{ myView->SetProj(V3d_Xpos); } // See the front View
+{ myView->SetProj(V3d_Yneg); } // See the front View
 
 void CAnimationView3D::OnBUTTONBottom() 
 { myView->SetProj(V3d_Zneg); } // See the bottom View
@@ -264,9 +247,9 @@ void CAnimationView3D::OnBUTTONTop()
 { myView->SetProj(V3d_Zpos); } // See the top View     
 
 void CAnimationView3D::OnBUTTONLeft() 
-{ myView->SetProj(V3d_Ypos); } // See the left View    
+{ myView->SetProj(V3d_Xneg); } // See the left View    
 void CAnimationView3D::OnBUTTONRight() 
-{ myView->SetProj(V3d_Yneg); } // See the right View
+{ myView->SetProj(V3d_Xpos); } // See the right View
 
 void CAnimationView3D::OnBUTTONAxo() 
 { myView->SetProj(V3d_XposYnegZpos); } // See the axonometric View
@@ -275,6 +258,7 @@ void CAnimationView3D::OnBUTTONHlrOff()
 {
   myHlrModeIsOn = Standard_False;
   myView->SetComputedMode (myHlrModeIsOn);
+  myView->Redraw();
 }
 
 void CAnimationView3D::OnBUTTONHlrOn() 
@@ -282,6 +266,7 @@ void CAnimationView3D::OnBUTTONHlrOn()
   SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
   myHlrModeIsOn = Standard_True;
   myView->SetComputedMode (myHlrModeIsOn);
+  myView->Redraw();
   SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
 }
 
@@ -376,7 +361,7 @@ void CAnimationView3D::OnLButtonDown(UINT nFlags, CPoint point)
                        SetTimer ( 1 , 100 , NULL ) ;
                break ;
         default :
-           Standard_Failure::Raise(" incompatible Current Mode ");
+           throw Standard_Failure(" incompatible Current Mode ");
         break;
         }
     }
@@ -443,7 +428,7 @@ void CAnimationView3D::OnLButtonUp(UINT nFlags, CPoint point)
                        KillTimer ( 1 ) ;
                break;
         default :
-           Standard_Failure::Raise(" incompatible Current Mode ");
+           throw Standard_Failure(" incompatible Current Mode ");
         break;
         } //switch (myCurrentMode)
     } //       else // if ( Ctrl )
@@ -487,7 +472,11 @@ void CAnimationView3D::OnRButtonDown(UINT nFlags, CPoint point)
 void CAnimationView3D::OnRButtonUp(UINT /*nFlags*/, CPoint /*point*/) 
 {
     SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
-    myView->SetComputedMode (myHlrModeIsOn);
+    if (myHlrModeIsOn)
+    {
+      myView->SetComputedMode (myHlrModeIsOn);
+      myView->Redraw();
+    }
     SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
 }
 
@@ -546,7 +535,7 @@ void CAnimationView3D::OnMouseMove(UINT nFlags, CPoint point)
                case CurrentAction3d_Turn :
                        break ;
         default :
-           Standard_Failure::Raise(" incompatible Current Mode ");
+           throw Standard_Failure(" incompatible Current Mode ");
         break;
         }//  switch (myCurrentMode)
       }// if ( nFlags & MK_CONTROL )  else 
@@ -698,10 +687,10 @@ void CAnimationView3D::DrawRectangle(const Standard_Integer  MinX    ,
      m_IsVisible = false;
     }
 
-    StoredMinX = min ( MinX, MaxX );
-    StoredMinY = min ( MinY, MaxY );
-    StoredMaxX = max ( MinX, MaxX );
-    StoredMaxY = max ( MinY, MaxY);
+    StoredMinX = Min ( MinX, MaxX );
+    StoredMinY = Min ( MinY, MaxY );
+    StoredMaxX = Max ( MinX, MaxX );
+    StoredMaxY = Max ( MinY, MaxY);
 
     if (Draw) // move : draw
     {
@@ -909,75 +898,71 @@ void CAnimationView3D::Twist (int x , int /*y*/)
        myView->SetTwist (a) ;
 }
 
-void CAnimationView3D::SetFocal(double dFocus,double dAngle)
+//=============================================================================
+// function: SetFocal
+// purpose:
+//=============================================================================
+void CAnimationView3D::SetFocal (double theFocus, double theAngle)
 {
-       double v [3] ;
-       double l ;
-       int    i     ;
 
-       v [0] = m_Atx - m_Eyex ;
-       v [1] = m_Aty - m_Eyey ;
-       v [2] = m_Atz - m_Eyez ;
+  Handle(Graphic3d_Camera) aCamera = myView->Camera();
 
-       l = sqrt ( v[0]*v[0] + v[1]*v[1] + v[2]*v[2] ) ;
-       if ( l > 1.e-3 ) {
-               for ( i=0 ; i<3 ; i++ )
-          v [i] = v [i] / l * dFocus ;
+  gp_Pnt anAt  = aCamera->Center();
+  gp_Pnt anEye = aCamera->Eye();
 
-               m_Focus = dFocus ;
+  gp_Vec aLook (anAt, anEye);
 
-               m_Atx = v [0] + m_Eyex ;
-               m_Aty = v [1] + m_Eyey ;
-               m_Atz = v [2] + m_Eyez ;
+  if (aCamera->Distance() > 1.e-3)
+  {
+    aLook = aLook / aCamera->Distance() * theFocus;
 
-        myView->SetImmediateUpdate ( Standard_False ) ;
-               myView->SetAt  ( m_Atx  , m_Aty  , m_Atz  ) ;
-               m_dAngle = dAngle ;
-               dAngle = dAngle * M_PI / 180. ;
-        myPView->SetAngle ( dAngle ) ;
-               dAngle = myPView->Angle () ;
+    m_Focus = theFocus;
 
-        myView->SetImmediateUpdate ( Standard_True ) ;
-        myView->Update ();
-       }
+    anAt.SetX (aLook.X() + anEye.X());
+    anAt.SetY (aLook.Y() + anEye.Y());
+    anAt.SetZ (aLook.Z() + anEye.Z());
+
+    m_dAngle = theAngle;
+
+    aCamera->SetCenter (anAt);
+    aCamera->SetFOVy (theAngle);
+
+    myView->Update();
+  }
 }
 
 void CAnimationView3D::ReloadData()
 {
-       char szMsg [128] ;
-       double dTwist ;
-
        myView->At  ( m_Atx  , m_Aty  , m_Atz  ) ;
        myView->Eye ( m_Eyex , m_Eyey , m_Eyez ) ;
-
-       dTwist = myView->Twist () ;
-       dTwist = dTwist * 180. / M_PI ;
-
-       sprintf_s ( szMsg , "%lf" , m_Atx ) ;
-       (m_Tune.GetDlgItem ( IDC_XAT ))->SetWindowText ( szMsg ) ;
-       sprintf_s ( szMsg , "%lf" , m_Aty ) ;
-       (m_Tune.GetDlgItem ( IDC_YAT ))->SetWindowText ( szMsg ) ;
-       sprintf_s ( szMsg , "%lf" , m_Atz ) ;
-       (m_Tune.GetDlgItem ( IDC_ZAT ))->SetWindowText ( szMsg ) ;
-
-       sprintf_s ( szMsg , "%lf" , m_Eyex ) ;
-       (m_Tune.GetDlgItem ( IDC_XEYE ))->SetWindowText ( szMsg ) ;
-       sprintf_s ( szMsg , "%lf" , m_Eyey ) ;
-       (m_Tune.GetDlgItem ( IDC_YEYE ))->SetWindowText ( szMsg ) ;
-       sprintf_s ( szMsg , "%lf" , m_Eyez ) ;
-       (m_Tune.GetDlgItem ( IDC_ZEYE ))->SetWindowText ( szMsg ) ;
-
-       sprintf_s ( szMsg , "%lf" , dTwist ) ;
-       (m_Tune.GetDlgItem ( IDC_TWIST ))->SetWindowText ( szMsg ) ;
+  double dTwist = myView->Twist() * 180. / M_PI;
+
+  CString aMsg;
+  aMsg.Format (L"%lf", m_Atx);
+       m_Tune.GetDlgItem (IDC_XAT)->SetWindowText (aMsg);
+  aMsg.Format (L"%lf", m_Aty);
+       m_Tune.GetDlgItem (IDC_YAT)->SetWindowText (aMsg);
+       aMsg.Format (L"%lf", m_Atz);
+       m_Tune.GetDlgItem (IDC_ZAT)->SetWindowText (aMsg);
+
+  aMsg.Format (L"%lf", m_Eyex);
+       m_Tune.GetDlgItem (IDC_XEYE)->SetWindowText (aMsg);
+       aMsg.Format (L"%lf", m_Eyey);
+       m_Tune.GetDlgItem (IDC_YEYE)->SetWindowText (aMsg);
+       aMsg.Format (L"%lf", m_Eyez);
+       m_Tune.GetDlgItem (IDC_ZEYE)->SetWindowText (aMsg);
+
+  aMsg.Format (L"%lf", dTwist);
+       m_Tune.GetDlgItem (IDC_TWIST)->SetWindowText (aMsg);
 
        double dx,dy,dz ;
        dx = m_Atx - m_Eyex ;
        dy = m_Aty - m_Eyey ;
        dz = m_Atz - m_Eyez ;
 
-    m_Focus = sqrt ( dx * dx + dy * dy + dz * dz ) ;
-       m_dAngle = myPView->Angle () ;
-       m_dAngle = m_dAngle * 180. / M_PI ;
+  m_Focus = sqrt (dx * dx + dy * dy + dz * dz);
+
+  m_dAngle = myView->Camera()->FOVy();
 
        m_Tune.m_dAngle = m_dAngle ;
        m_Tune.m_dFocus = m_Focus  ;