1 // AnimationView3D.cpp : implementation of the CAnimationView3D class
6 #include "AnimationView3D.h"
8 #include "AnimationApp.h"
9 #include "ShadingDialog.h"
10 #include "AnimationDoc.h"
12 #include "Sensitivity.h"
15 //#define new DEBUG_NEW by CasCade
17 static char THIS_FILE[] = __FILE__;
19 static int rotCount = 0;
21 // for elastic bean selection
25 /////////////////////////////////////////////////////////////////////////////
28 IMPLEMENT_DYNCREATE(CAnimationView3D, CView)
30 BEGIN_MESSAGE_MAP(CAnimationView3D, CView)
31 //{{AFX_MSG_MAP(CAnimationView3D)
32 ON_COMMAND(ID_BUTTONAxo, OnBUTTONAxo)
33 ON_COMMAND(ID_BUTTONBack, OnBUTTONBack)
34 ON_COMMAND(ID_BUTTONBottom, OnBUTTONBottom)
35 ON_COMMAND(ID_BUTTONFront, OnBUTTONFront)
36 ON_COMMAND(ID_BUTTONHlrOff, OnBUTTONHlrOff)
37 ON_COMMAND(ID_BUTTONHlrOn, OnBUTTONHlrOn)
38 ON_COMMAND(ID_BUTTONLeft, OnBUTTONLeft)
39 ON_COMMAND(ID_BUTTONPan, OnBUTTONPan)
40 ON_COMMAND(ID_BUTTONPanGlo, OnBUTTONPanGlo)
41 ON_COMMAND(ID_BUTTONReset, OnBUTTONReset)
42 ON_COMMAND(ID_BUTTONRight, OnBUTTONRight)
43 ON_COMMAND(ID_BUTTONRot, OnBUTTONRot)
44 ON_COMMAND(ID_BUTTONTop, OnBUTTONTop)
45 ON_COMMAND(ID_BUTTONZoomAll, OnBUTTONZoomAll)
46 ON_COMMAND(ID_FILE_EXPORT_IMAGE, OnFileExportImage)
48 ON_COMMAND(ID_BUTTONZoomProg, OnBUTTONZoomProg)
49 ON_COMMAND(ID_BUTTONZoomWin, OnBUTTONZoomWin)
57 ON_UPDATE_COMMAND_UI(ID_BUTTONHlrOff, OnUpdateBUTTONHlrOff)
58 ON_UPDATE_COMMAND_UI(ID_BUTTONHlrOn, OnUpdateBUTTONHlrOn)
59 ON_UPDATE_COMMAND_UI(ID_BUTTONPanGlo, OnUpdateBUTTONPanGlo)
60 ON_UPDATE_COMMAND_UI(ID_BUTTONPan, OnUpdateBUTTONPan)
61 ON_UPDATE_COMMAND_UI(ID_BUTTONZoomProg, OnUpdateBUTTONZoomProg)
62 ON_UPDATE_COMMAND_UI(ID_BUTTONZoomWin, OnUpdateBUTTONZoomWin)
63 ON_UPDATE_COMMAND_UI(ID_BUTTONRot, OnUpdateBUTTONRot)
65 ON_COMMAND(ID_Modify_ChangeBackground , OnChangeBackground)
67 ON_COMMAND(ID_STOP, OnStop)
68 ON_COMMAND(ID_RESTART, OnRestart)
70 ON_COMMAND(ID_SENSITIVITY, OnSensitivity)
71 ON_COMMAND(ID_BUTTONFly, OnBUTTONFly)
72 ON_COMMAND(ID_BUTTONTurn, OnBUTTONTurn)
73 ON_UPDATE_COMMAND_UI(ID_BUTTONFly, OnUpdateBUTTONFly)
74 ON_UPDATE_COMMAND_UI(ID_BUTTONTurn, OnUpdateBUTTONTurn)
75 ON_COMMAND(ID_VIEW_DISPLAYSTATUS, OnViewDisplaystatus)
76 ON_UPDATE_COMMAND_UI(ID_VIEW_DISPLAYSTATUS, OnUpdateViewDisplaystatus)
82 /////////////////////////////////////////////////////////////////////////////
83 // CAnimationView3D construction/destruction
85 CAnimationView3D::CAnimationView3D()
91 myHlrModeIsOn (Standard_False),
92 myCurrentMode (CurrentAction3d_Nothing),
94 m_TurnSens (M_PI / 40.0),
97 // TODO: add construction code here
100 CAnimationView3D::~CAnimationView3D()
103 if (m_Pen) delete m_Pen;
106 BOOL CAnimationView3D::PreCreateWindow(CREATESTRUCT& cs)
108 // TODO: Modify the Window class or styles here by modifying
109 // the CREATESTRUCT cs
111 return CView::PreCreateWindow(cs);
114 /////////////////////////////////////////////////////////////////////////////
115 // CAnimationView3D drawing
117 void CAnimationView3D::OnDraw(CDC* /*pDC*/)
119 CAnimationDoc* pDoc = GetDocument();
122 // TODO: add draw code for native data here
127 void CAnimationView3D::OnInitialUpdate()
129 CView::OnInitialUpdate();
131 // TODO: Add your specialized code here and/or call the base class
132 // myView = GetDocument()->GetViewer()->CreateView();
134 Handle(V3d_Viewer) aViewer;
136 aViewer = GetDocument()->GetViewer();
137 aViewer->SetDefaultTypeOfView (V3d_PERSPECTIVE);
139 myView = aViewer->CreateView();
141 // store for restore state after rotation (witch is in Degenerated mode)
142 myHlrModeIsOn = myView->ComputedMode();
144 Handle(WNT_Window) aWNTWindow = new WNT_Window (GetSafeHwnd());
145 myView->SetWindow(aWNTWindow);
146 if (!aWNTWindow->IsMapped()) aWNTWindow->Map();
148 // store the mode ( nothing , dynamic zooming, dynamic ... )
149 myCurrentMode = CurrentAction3d_Nothing;
150 CFrameWnd* pParentFrm = GetParentFrame();
151 pParentFrm->ActivateFrame(SW_SHOWMAXIMIZED);
153 Standard_Integer w=100 , h=100 ; /* Debug Matrox */
154 aWNTWindow->Size (w,h) ; /* Keeps me unsatisfied (rlb)..... */
155 /* Resize is not supposed to be done on */
157 /* I suspect another problem elsewhere */
158 ::PostMessage ( GetSafeHwnd () , WM_SIZE , SIZE_RESTORED , w + h*65536 ) ;
160 m_Tune.Create ( IDD_TUNE , NULL ) ;
163 m_Tune.GetWindowRect(&dlgrect);
164 LONG width = dlgrect.right-dlgrect.left;
165 LONG height = dlgrect.bottom-dlgrect.top;
167 AfxGetApp()->m_pMainWnd->GetWindowRect(&MainWndRect);
168 LONG left = MainWndRect.left+3;
169 LONG top = MainWndRect.top + 112;
170 m_Tune.MoveWindow(left,top,width,height);
172 m_Tune.m_pView = this ;
174 m_Tune.ShowWindow ( SW_HIDE );
176 // store the mode ( nothing , dynamic zooming, dynamic ... )
178 myCurrentMode = CurrentAction3d_Nothing;
184 void CAnimationView3D::DisplayTuneDialog()
186 m_Tune.Create ( IDD_TUNE , NULL ) ;
189 m_Tune.GetWindowRect(&dlgrect);
190 LONG width = dlgrect.right-dlgrect.left;
191 LONG height = dlgrect.bottom-dlgrect.top;
193 AfxGetApp()->m_pMainWnd->GetWindowRect(&MainWndRect);
194 LONG left = MainWndRect.left+3;
195 LONG top = MainWndRect.top + 112;
196 m_Tune.MoveWindow(left,top,width,height);
198 m_Tune.m_pView = this ;
202 /////////////////////////////////////////////////////////////////////////////
203 // CAnimationView3D diagnostics
206 void CAnimationView3D::AssertValid() const
208 CView::AssertValid();
211 void CAnimationView3D::Dump(CDumpContext& dc) const
216 CAnimationDoc* CAnimationView3D::GetDocument() // non-debug version is inline
218 ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CAnimationDoc)));
219 return (CAnimationDoc*)m_pDocument;
223 /////////////////////////////////////////////////////////////////////////////
224 // CAnimationView3D message handlers
225 void CAnimationView3D::OnFileExportImage()
227 GetDocument()->ExportView (myView);
230 void CAnimationView3D::OnSize(UINT /*nType*/, int cx, int cy)
234 if (!myView.IsNull())
235 myView->MustBeResized();
238 void CAnimationView3D::OnBUTTONBack()
239 { myView->SetProj(V3d_Ypos); } // See the back View
240 void CAnimationView3D::OnBUTTONFront()
241 { myView->SetProj(V3d_Yneg); } // See the front View
243 void CAnimationView3D::OnBUTTONBottom()
244 { myView->SetProj(V3d_Zneg); } // See the bottom View
245 void CAnimationView3D::OnBUTTONTop()
246 { myView->SetProj(V3d_Zpos); } // See the top View
248 void CAnimationView3D::OnBUTTONLeft()
249 { myView->SetProj(V3d_Xneg); } // See the left View
250 void CAnimationView3D::OnBUTTONRight()
251 { myView->SetProj(V3d_Xpos); } // See the right View
253 void CAnimationView3D::OnBUTTONAxo()
254 { myView->SetProj(V3d_XposYnegZpos); } // See the axonometric View
256 void CAnimationView3D::OnBUTTONHlrOff()
258 myHlrModeIsOn = Standard_False;
259 myView->SetComputedMode (myHlrModeIsOn);
262 void CAnimationView3D::OnBUTTONHlrOn()
264 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
265 myHlrModeIsOn = Standard_True;
266 myView->SetComputedMode (myHlrModeIsOn);
267 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
270 void CAnimationView3D::OnBUTTONPan()
272 myCurrentMode = CurrentAction3d_DynamicPanning;
275 void CAnimationView3D::OnBUTTONPanGlo()
277 // save the current zoom value
278 myCurZoom = myView->Scale();
282 myCurrentMode = CurrentAction3d_GlobalPanning;
285 void CAnimationView3D::OnBUTTONReset()
290 void CAnimationView3D::OnBUTTONRot()
291 { myCurrentMode = CurrentAction3d_DynamicRotation; }
294 void CAnimationView3D::OnBUTTONZoomAll()
301 void CAnimationView3D::OnBUTTONZoomProg()
302 { myCurrentMode = CurrentAction3d_DynamicZooming; }
304 void CAnimationView3D::OnBUTTONZoomWin()
305 { myCurrentMode = CurrentAction3d_WindowZooming; }
307 void CAnimationView3D::OnBUTTONFly()
308 { myCurrentMode = CurrentAction3d_Fly; }
310 void CAnimationView3D::OnBUTTONTurn()
311 { myCurrentMode = CurrentAction3d_Turn; }
314 void CAnimationView3D::OnLButtonDown(UINT nFlags, CPoint point)
316 // save the current mouse coordinate in min
317 myXmin=point.x; myYmin=point.y;
318 myXmax=point.x; myYmax=point.y;
320 if ( nFlags & MK_CONTROL )
322 // Button MB1 down Control :start zomming
323 // SetCursor(AfxGetApp()->LoadStandardCursor());
327 switch (myCurrentMode)
329 case CurrentAction3d_Nothing : // start a drag
330 if (nFlags & MK_SHIFT)
331 GetDocument()->ShiftDragEvent(myXmax,myYmax,-1,myView);
333 GetDocument()->DragEvent(myXmax,myYmax,-1,myView);
336 case CurrentAction3d_DynamicZooming : // noting
337 // SetCursor(AfxGetApp()->LoadStandardCursor());
339 case CurrentAction3d_WindowZooming : // noting
341 case CurrentAction3d_DynamicPanning :// noting
343 case CurrentAction3d_GlobalPanning :// noting
345 case CurrentAction3d_DynamicRotation :
348 myView->SetComputedMode (Standard_False);
350 myView->StartRotation (point.x, point.y);
352 case CurrentAction3d_Fly :
354 SetTimer ( 1 , 100 , NULL ) ;
356 case CurrentAction3d_Turn :
358 SetTimer ( 1 , 100 , NULL ) ;
361 Standard_Failure::Raise(" incompatible Current Mode ");
367 void CAnimationView3D::OnLButtonUp(UINT nFlags, CPoint point)
369 if ( nFlags & MK_CONTROL )
375 switch (myCurrentMode)
377 case CurrentAction3d_Nothing :
378 if (point.x == myXmin && point.y == myYmin)
379 { // no offset between down and up --> selectEvent
382 if (nFlags & MK_SHIFT )
383 GetDocument()->ShiftInputEvent(point.x,point.y,myView);
385 GetDocument()->InputEvent (point.x,point.y,myView);
388 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False);
391 if (nFlags & MK_SHIFT)
392 GetDocument()->ShiftDragEvent(point.x,point.y,1,myView);
394 GetDocument()->DragEvent(point.x,point.y,1,myView);
397 case CurrentAction3d_DynamicZooming :
398 // SetCursor(AfxGetApp()->LoadStandardCursor());
399 myCurrentMode = CurrentAction3d_Nothing;
401 case CurrentAction3d_WindowZooming :
402 myXmax=point.x; myYmax=point.y;
403 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False,LongDash);
404 if ((abs(myXmin-myXmax)>ValZWMin) || (abs(myYmin-myYmax)>ValZWMin))
405 // Test if the zoom window is greater than a minimale window.
407 // Do the zoom window between Pmin and Pmax
408 myView->WindowFitAll(myXmin,myYmin,myXmax,myYmax);
410 myCurrentMode = CurrentAction3d_Nothing;
412 case CurrentAction3d_DynamicPanning :
413 myCurrentMode = CurrentAction3d_Nothing;
415 case CurrentAction3d_GlobalPanning :
416 myView->Place(point.x,point.y,myCurZoom);
417 myCurrentMode = CurrentAction3d_Nothing;
419 case CurrentAction3d_DynamicRotation :
420 myCurrentMode = CurrentAction3d_Nothing;
422 case CurrentAction3d_Fly :
424 case CurrentAction3d_Turn :
428 Standard_Failure::Raise(" incompatible Current Mode ");
430 } //switch (myCurrentMode)
431 } // else // if ( Ctrl )
434 void CAnimationView3D::OnMButtonDown(UINT nFlags, CPoint /*point*/)
436 if ( nFlags & MK_CONTROL )
438 // Button MB2 down Control : panning init
439 // SetCursor(AfxGetApp()->LoadStandardCursor());
443 void CAnimationView3D::OnMButtonUp(UINT nFlags, CPoint /*point*/)
445 if ( nFlags & MK_CONTROL )
447 // Button MB2 down Control : panning init
448 // SetCursor(AfxGetApp()->LoadStandardCursor());
452 void CAnimationView3D::OnRButtonDown(UINT nFlags, CPoint point)
454 if ( nFlags & MK_CONTROL )
456 // SetCursor(AfxGetApp()->LoadStandardCursor());
459 myView->SetComputedMode (Standard_False);
461 myView->StartRotation (point.x, point.y);
465 GetDocument()->Popup(point.x,point.y,myView);
469 void CAnimationView3D::OnRButtonUp(UINT /*nFlags*/, CPoint /*point*/)
471 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
472 myView->SetComputedMode (myHlrModeIsOn);
473 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
476 void CAnimationView3D::OnMouseMove(UINT nFlags, CPoint point)
478 // ============================ LEFT BUTTON =======================
482 if ( nFlags & MK_LBUTTON)
484 if ( nFlags & MK_CONTROL )
486 // move with MB1 and Control : on the dynamic zooming
487 // Do the zoom in function of mouse's coordinates
488 myView->Zoom(myXmax,myYmax,point.x,point.y);
489 // save the current mouse coordinate in min
495 switch (myCurrentMode)
497 case CurrentAction3d_Nothing :
498 myXmax = point.x; myYmax = point.y;
499 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False);
500 if (nFlags & MK_SHIFT)
501 GetDocument()->ShiftDragEvent(myXmax,myYmax,0,myView);
503 GetDocument()->DragEvent(myXmax,myYmax,0,myView);
504 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_True);
506 case CurrentAction3d_DynamicZooming :
507 myView->Zoom(myXmax,myYmax,point.x,point.y);
508 // save the current mouse coordinate in min \n";
509 myXmax=point.x; myYmax=point.y;
511 case CurrentAction3d_WindowZooming :
512 myXmax = point.x; myYmax = point.y;
513 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False,LongDash);
514 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_True,LongDash);
516 case CurrentAction3d_DynamicPanning :
517 myView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
518 myXmax = point.x; myYmax = point.y;
520 case CurrentAction3d_GlobalPanning : // nothing
522 case CurrentAction3d_DynamicRotation :
523 myView->Rotation(point.x,point.y);
526 case CurrentAction3d_Fly :
528 case CurrentAction3d_Turn :
531 Standard_Failure::Raise(" incompatible Current Mode ");
533 }// switch (myCurrentMode)
534 }// if ( nFlags & MK_CONTROL ) else
535 } else // if ( nFlags & MK_LBUTTON)
536 // ============================ MIDDLE BUTTON =======================
537 if ( nFlags & MK_MBUTTON)
539 if ( nFlags & MK_CONTROL )
541 myView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
542 myXmax = point.x; myYmax = point.y;
545 } else // if ( nFlags & MK_MBUTTON)
546 // ============================ RIGHT BUTTON =======================
547 if ( nFlags & MK_RBUTTON)
549 if ( nFlags & MK_CONTROL )
552 myView->Rotation(point.x,point.y);
554 }else //if ( nFlags & MK_RBUTTON)
555 // ============================ NO BUTTON =======================
557 myXmax = point.x; myYmax = point.y;
558 if (nFlags & MK_SHIFT)
559 GetDocument()->ShiftMoveEvent(point.x,point.y,myView);
561 GetDocument()->MoveEvent(point.x,point.y,myView);
565 void CAnimationView3D::OnUpdateBUTTONHlrOff(CCmdUI* pCmdUI)
567 pCmdUI->SetCheck (!myHlrModeIsOn);
568 pCmdUI->Enable (myHlrModeIsOn);
571 void CAnimationView3D::OnUpdateBUTTONHlrOn(CCmdUI* pCmdUI)
573 pCmdUI->SetCheck (myHlrModeIsOn);
574 pCmdUI->Enable (!myHlrModeIsOn);
577 void CAnimationView3D::OnUpdateBUTTONPanGlo(CCmdUI* pCmdUI)
579 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_GlobalPanning);
580 pCmdUI->Enable (myCurrentMode != CurrentAction3d_GlobalPanning);
584 void CAnimationView3D::OnUpdateBUTTONPan(CCmdUI* pCmdUI)
586 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_DynamicPanning);
587 pCmdUI->Enable (myCurrentMode != CurrentAction3d_DynamicPanning );
590 void CAnimationView3D::OnUpdateBUTTONZoomProg(CCmdUI* pCmdUI)
592 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_DynamicZooming );
593 pCmdUI->Enable (myCurrentMode != CurrentAction3d_DynamicZooming);
596 void CAnimationView3D::OnUpdateBUTTONZoomWin(CCmdUI* pCmdUI)
598 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_WindowZooming);
599 pCmdUI->Enable (myCurrentMode != CurrentAction3d_WindowZooming);
602 void CAnimationView3D::OnUpdateBUTTONRot(CCmdUI* pCmdUI)
604 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_DynamicRotation);
605 pCmdUI->Enable (myCurrentMode != CurrentAction3d_DynamicRotation);
608 void CAnimationView3D::OnUpdateBUTTONFly(CCmdUI* pCmdUI)
610 pCmdUI->Enable(GetDocument()->m_bIsGridLoaded);
611 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_Fly);
614 void CAnimationView3D::OnUpdateBUTTONTurn(CCmdUI* pCmdUI)
616 pCmdUI->Enable(GetDocument()->m_bIsGridLoaded);
617 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_Turn);
620 void CAnimationView3D::OnChangeBackground()
625 myView->BackgroundColor(Quantity_TOC_RGB,R1,G1,B1);
627 m_clr = RGB(R1*255,G1*255,B1*255);
629 CColorDialog dlgColor(m_clr);
630 if (dlgColor.DoModal() == IDOK)
632 m_clr = dlgColor.GetColor();
633 R1 = GetRValue(m_clr)/255.;
634 G1 = GetGValue(m_clr)/255.;
635 B1 = GetBValue(m_clr)/255.;
636 myView->SetBackgroundColor(Quantity_TOC_RGB,R1,G1,B1);
641 //==========================================================================================
642 //==========================================================================================
643 //==========================================================================================
645 //-----------------------------------------------------------------------------------------
647 //-----------------------------------------------------------------------------------------
648 void CAnimationView3D::DrawRectangle(const Standard_Integer MinX ,
649 const Standard_Integer MinY ,
650 const Standard_Integer MaxX ,
651 const Standard_Integer MaxY ,
652 const Standard_Boolean Draw ,
653 const LineStyle aLineStyle)
655 static int m_DrawMode;
656 if (!m_Pen && aLineStyle ==Solid )
657 {m_Pen = new CPen(PS_SOLID, 1, RGB(0,0,0)); m_DrawMode = R2_MERGEPENNOT;}
658 else if (!m_Pen && aLineStyle ==Dot )
659 {m_Pen = new CPen(PS_DOT, 1, RGB(0,0,0)); m_DrawMode = R2_XORPEN;}
660 else if (!m_Pen && aLineStyle == ShortDash)
661 {m_Pen = new CPen(PS_DASH, 1, RGB(255,0,0)); m_DrawMode = R2_XORPEN;}
662 else if (!m_Pen && aLineStyle == LongDash)
663 {m_Pen = new CPen(PS_DASH, 1, RGB(0,0,0)); m_DrawMode = R2_NOTXORPEN;}
664 else if (aLineStyle == Default)
665 { m_Pen = NULL; m_DrawMode = R2_MERGEPENNOT;}
667 CPen* aOldPen = NULL;
668 CClientDC clientDC(this);
669 if (m_Pen) aOldPen = clientDC.SelectObject(m_Pen);
670 clientDC.SetROP2(m_DrawMode);
672 static Standard_Integer StoredMinX, StoredMaxX, StoredMinY, StoredMaxY;
673 static Standard_Boolean m_IsVisible;
675 if ( m_IsVisible && !Draw) // move or up : erase at the old position
677 clientDC.MoveTo(StoredMinX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMaxY);
678 clientDC.LineTo(StoredMaxX,StoredMaxY);
679 clientDC.LineTo(StoredMaxX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMinY);
683 StoredMinX = Min ( MinX, MaxX );
684 StoredMinY = Min ( MinY, MaxY );
685 StoredMaxX = Max ( MinX, MaxX );
686 StoredMaxY = Max ( MinY, MaxY);
688 if (Draw) // move : draw
690 clientDC.MoveTo(StoredMinX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMaxY);
691 clientDC.LineTo(StoredMaxX,StoredMaxY);
692 clientDC.LineTo(StoredMaxX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMinY);
697 clientDC.SelectObject(aOldPen);
699 void CAnimationView3D::OnStop()
701 KillTimer(GetDocument()->myCount);
704 void CAnimationView3D::OnRestart()
706 KillTimer(GetDocument()->myCount);
707 SetTimer(GetDocument()->myCount, 1 , NULL);
711 void CAnimationView3D::OnTimer(UINT nIDEvent)
713 // TODO: Add your message handler code here and/or call default
714 GetDocument()->OnMyTimer();
715 CView::OnTimer(nIDEvent);
720 /*********************************************************************************
721 ************** W A L K T H R O U G H ******************************************
722 /********************************************************************************/
724 void CAnimationView3D::OnTimer(UINT_PTR nIDEvent)
726 if ( !GetDocument()->m_bIsGridLoaded )
728 // TODO: Add your message handler code here and/or call default
729 GetDocument()->OnMyTimer();
730 CView::OnTimer(nIDEvent);
734 CView::OnTimer(nIDEvent);
735 if ( nIDEvent == 1 ) {
736 myView->SetImmediateUpdate ( Standard_False ) ;
737 if ( myCurrentMode == CurrentAction3d_Fly ) {
739 Fly ( m_curx , m_cury ) ;
741 Roll ( m_curx , m_cury ) ;
743 Turn ( m_curx , m_cury ) ;
745 myView->SetAt ( m_Atx , m_Aty , m_Atz ) ;
746 myView->SetEye ( m_Eyex , m_Eyey , m_Eyez ) ;
749 else if ( myCurrentMode == CurrentAction3d_Turn ) {
750 Twist ( m_curx , m_cury ) ;
756 myView->SetImmediateUpdate ( Standard_True ) ;
765 void CAnimationView3D::OnSensitivity()
769 dial.m_SensFly = m_FlySens ;
770 dial.m_SensTurn = m_TurnSens ;
771 if ( dial.DoModal () ) {
772 m_FlySens = dial.m_SensFly ;
773 m_TurnSens = dial.m_SensTurn ;
777 void CAnimationView3D::Fly (int /*x*/ , int y)
784 sens = (double) myYmin - (double) y ;
785 sens /= (double) m_cy ;
788 v [0] = m_Atx - m_Eyex ;
789 v [1] = m_Aty - m_Eyey ;
790 v [2] = m_Atz - m_Eyez ;
791 l = sqrt ( v[0]*v[0] + v[1]*v[1] + v[2]*v[2] ) ;
793 for ( i=0 ; i<3 ; i++ )
794 v [i] = v [i] / l * sens ;
809 void CAnimationView3D::Turn (int x , int /*y*/)
811 gp_Vec z (0.,0.,1.) ;
815 double aX , aY , aZ ;
817 sens = (double) x - (double) myXmin ;
818 sens /= (double) m_cx ;
821 v [0] = m_Atx - m_Eyex ;
822 v [1] = m_Aty - m_Eyey ;
823 v [2] = m_Atz - m_Eyez ;
825 gp_Pnt eye ( m_Eyex , m_Eyey , m_Eyez ) ;
827 gp_Vec reg (v[0],v[1],v[2] );
829 gp_Vec vert = reg ^ z ;
830 gp_Vec haut = vert ^ reg ;
835 reg.Rotate (rot,sens) ;
837 reg.Coord ( aX , aY , aZ ) ;
839 m_Atx = m_Eyex + aX ;
840 m_Aty = m_Eyey + aY ;
841 m_Atz = m_Eyez + aZ ;
844 void CAnimationView3D::Roll (int x , int /*y*/)
846 gp_Vec z (0.,0.,1.) ;
850 double aX , aY , aZ ;
852 sens = (double) x - (double) myXmin ;
853 sens /= (double) m_cx ;
856 v [0] = m_Atx - m_Eyex ;
857 v [1] = m_Aty - m_Eyey ;
858 v [2] = m_Atz - m_Eyez ;
860 gp_Pnt eye ( m_Eyex , m_Eyey , m_Eyez ) ;
862 gp_Vec reg (v[0],v[1],v[2] );
864 gp_Vec vert = reg ^ z ;
869 reg.Rotate (rot,sens) ;
871 reg.Coord ( aX , aY , aZ ) ;
873 m_Atx = m_Eyex + aX ;
874 m_Aty = m_Eyey + aY ;
875 m_Atz = m_Eyez + aZ ;
878 void CAnimationView3D::Twist (int x , int /*y*/)
883 a = myView->Twist () ;
885 sens = (double) x - (double) myXmin ;
886 sens /= (double) m_cx ;
891 myView->SetTwist (a) ;
894 //=============================================================================
895 // function: SetFocal
897 //=============================================================================
898 void CAnimationView3D::SetFocal (double theFocus, double theAngle)
901 Handle(Graphic3d_Camera) aCamera = myView->Camera();
903 gp_Pnt anAt = aCamera->Center();
904 gp_Pnt anEye = aCamera->Eye();
906 gp_Vec aLook (anAt, anEye);
908 if (aCamera->Distance() > 1.e-3)
910 aLook = aLook / aCamera->Distance() * theFocus;
914 anAt.SetX (aLook.X() + anEye.X());
915 anAt.SetY (aLook.Y() + anEye.Y());
916 anAt.SetZ (aLook.Z() + anEye.Z());
920 aCamera->SetCenter (anAt);
921 aCamera->SetFOVy (theAngle);
927 void CAnimationView3D::ReloadData()
929 myView->At ( m_Atx , m_Aty , m_Atz ) ;
930 myView->Eye ( m_Eyex , m_Eyey , m_Eyez ) ;
931 double dTwist = myView->Twist() * 180. / M_PI;
934 aMsg.Format (L"%lf", m_Atx);
935 m_Tune.GetDlgItem (IDC_XAT)->SetWindowText (aMsg);
936 aMsg.Format (L"%lf", m_Aty);
937 m_Tune.GetDlgItem (IDC_YAT)->SetWindowText (aMsg);
938 aMsg.Format (L"%lf", m_Atz);
939 m_Tune.GetDlgItem (IDC_ZAT)->SetWindowText (aMsg);
941 aMsg.Format (L"%lf", m_Eyex);
942 m_Tune.GetDlgItem (IDC_XEYE)->SetWindowText (aMsg);
943 aMsg.Format (L"%lf", m_Eyey);
944 m_Tune.GetDlgItem (IDC_YEYE)->SetWindowText (aMsg);
945 aMsg.Format (L"%lf", m_Eyez);
946 m_Tune.GetDlgItem (IDC_ZEYE)->SetWindowText (aMsg);
948 aMsg.Format (L"%lf", dTwist);
949 m_Tune.GetDlgItem (IDC_TWIST)->SetWindowText (aMsg);
952 dx = m_Atx - m_Eyex ;
953 dy = m_Aty - m_Eyey ;
954 dz = m_Atz - m_Eyez ;
956 m_Focus = sqrt (dx * dx + dy * dy + dz * dz);
958 m_dAngle = myView->Camera()->FOVy();
960 m_Tune.m_dAngle = m_dAngle ;
961 m_Tune.m_dFocus = m_Focus ;
962 m_Tune.UpdateData ( FALSE ) ;
965 void CAnimationView3D::SetDimensions()
968 CAnimationDoc* pDoc = GetDocument();
970 myView->SetImmediateUpdate ( Standard_False ) ;
972 m_Atx = ( pDoc->m_Xmin + pDoc->m_Xmax ) / 2. ;
973 m_Aty = ( pDoc->m_Ymin + pDoc->m_Ymax ) / 2. ;
974 m_Atz = ( pDoc->m_Zmin + pDoc->m_Zmax ) / 2. ;
975 m_Eyex = pDoc->m_Xmax ;
976 m_Eyey = pDoc->m_Ymax ;
977 m_Eyez = pDoc->m_Zmax ;
979 myView->SetAt ( m_Atx , m_Aty , m_Atz ) ;
980 myView->SetEye ( m_Eyex , m_Eyey , m_Eyez ) ;
981 myView->SetTwist (0.) ;
983 myView->SetImmediateUpdate ( Standard_False ) ;
985 myView->SetImmediateUpdate ( Standard_False ) ;
988 myView->SetImmediateUpdate ( Standard_True ) ;
994 void CAnimationView3D::OnViewDisplaystatus()
996 // TODO: Add your command handler code here
998 if ( m_Tune.IsWindowVisible () ) {
1002 m_Tune.ShowWindow ( SW_SHOWNORMAL ) ;
1006 void CAnimationView3D::OnUpdateViewDisplaystatus(CCmdUI* pCmdUI)
1008 // TODO: Add your command update UI handler code here
1010 if ( m_Tune.IsWindowVisible () ) {
1011 pCmdUI->SetCheck ( 1 ) ;
1014 pCmdUI->SetCheck ( 0 ) ;