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
110 cs.lpszClass = ::AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | CS_OWNDC, ::LoadCursor(NULL, IDC_ARROW), NULL, NULL);
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)
232 CView::OnSize (nType, cx, cy);
235 if (!myView.IsNull())
236 myView->MustBeResized();
239 void CAnimationView3D::OnBUTTONBack()
240 { myView->SetProj(V3d_Ypos); } // See the back View
241 void CAnimationView3D::OnBUTTONFront()
242 { myView->SetProj(V3d_Yneg); } // See the front View
244 void CAnimationView3D::OnBUTTONBottom()
245 { myView->SetProj(V3d_Zneg); } // See the bottom View
246 void CAnimationView3D::OnBUTTONTop()
247 { myView->SetProj(V3d_Zpos); } // See the top View
249 void CAnimationView3D::OnBUTTONLeft()
250 { myView->SetProj(V3d_Xneg); } // See the left View
251 void CAnimationView3D::OnBUTTONRight()
252 { myView->SetProj(V3d_Xpos); } // See the right View
254 void CAnimationView3D::OnBUTTONAxo()
255 { myView->SetProj(V3d_XposYnegZpos); } // See the axonometric View
257 void CAnimationView3D::OnBUTTONHlrOff()
259 myHlrModeIsOn = Standard_False;
260 myView->SetComputedMode (myHlrModeIsOn);
263 void CAnimationView3D::OnBUTTONHlrOn()
265 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
266 myHlrModeIsOn = Standard_True;
267 myView->SetComputedMode (myHlrModeIsOn);
268 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
271 void CAnimationView3D::OnBUTTONPan()
273 myCurrentMode = CurrentAction3d_DynamicPanning;
276 void CAnimationView3D::OnBUTTONPanGlo()
278 // save the current zoom value
279 myCurZoom = myView->Scale();
283 myCurrentMode = CurrentAction3d_GlobalPanning;
286 void CAnimationView3D::OnBUTTONReset()
291 void CAnimationView3D::OnBUTTONRot()
292 { myCurrentMode = CurrentAction3d_DynamicRotation; }
295 void CAnimationView3D::OnBUTTONZoomAll()
302 void CAnimationView3D::OnBUTTONZoomProg()
303 { myCurrentMode = CurrentAction3d_DynamicZooming; }
305 void CAnimationView3D::OnBUTTONZoomWin()
306 { myCurrentMode = CurrentAction3d_WindowZooming; }
308 void CAnimationView3D::OnBUTTONFly()
309 { myCurrentMode = CurrentAction3d_Fly; }
311 void CAnimationView3D::OnBUTTONTurn()
312 { myCurrentMode = CurrentAction3d_Turn; }
315 void CAnimationView3D::OnLButtonDown(UINT nFlags, CPoint point)
317 // save the current mouse coordinate in min
318 myXmin=point.x; myYmin=point.y;
319 myXmax=point.x; myYmax=point.y;
321 if ( nFlags & MK_CONTROL )
323 // Button MB1 down Control :start zomming
324 // SetCursor(AfxGetApp()->LoadStandardCursor());
328 switch (myCurrentMode)
330 case CurrentAction3d_Nothing : // start a drag
331 if (nFlags & MK_SHIFT)
332 GetDocument()->ShiftDragEvent(myXmax,myYmax,-1,myView);
334 GetDocument()->DragEvent(myXmax,myYmax,-1,myView);
337 case CurrentAction3d_DynamicZooming : // noting
338 // SetCursor(AfxGetApp()->LoadStandardCursor());
340 case CurrentAction3d_WindowZooming : // noting
342 case CurrentAction3d_DynamicPanning :// noting
344 case CurrentAction3d_GlobalPanning :// noting
346 case CurrentAction3d_DynamicRotation :
349 myView->SetComputedMode (Standard_False);
351 myView->StartRotation (point.x, point.y);
353 case CurrentAction3d_Fly :
355 SetTimer ( 1 , 100 , NULL ) ;
357 case CurrentAction3d_Turn :
359 SetTimer ( 1 , 100 , NULL ) ;
362 throw Standard_Failure(" incompatible Current Mode ");
368 void CAnimationView3D::OnLButtonUp(UINT nFlags, CPoint point)
370 if ( nFlags & MK_CONTROL )
376 switch (myCurrentMode)
378 case CurrentAction3d_Nothing :
379 if (point.x == myXmin && point.y == myYmin)
380 { // no offset between down and up --> selectEvent
383 if (nFlags & MK_SHIFT )
384 GetDocument()->ShiftInputEvent(point.x,point.y,myView);
386 GetDocument()->InputEvent (point.x,point.y,myView);
389 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False);
392 if (nFlags & MK_SHIFT)
393 GetDocument()->ShiftDragEvent(point.x,point.y,1,myView);
395 GetDocument()->DragEvent(point.x,point.y,1,myView);
398 case CurrentAction3d_DynamicZooming :
399 // SetCursor(AfxGetApp()->LoadStandardCursor());
400 myCurrentMode = CurrentAction3d_Nothing;
402 case CurrentAction3d_WindowZooming :
403 myXmax=point.x; myYmax=point.y;
404 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False,LongDash);
405 if ((abs(myXmin-myXmax)>ValZWMin) || (abs(myYmin-myYmax)>ValZWMin))
406 // Test if the zoom window is greater than a minimale window.
408 // Do the zoom window between Pmin and Pmax
409 myView->WindowFitAll(myXmin,myYmin,myXmax,myYmax);
411 myCurrentMode = CurrentAction3d_Nothing;
413 case CurrentAction3d_DynamicPanning :
414 myCurrentMode = CurrentAction3d_Nothing;
416 case CurrentAction3d_GlobalPanning :
417 myView->Place(point.x,point.y,myCurZoom);
418 myCurrentMode = CurrentAction3d_Nothing;
420 case CurrentAction3d_DynamicRotation :
421 myCurrentMode = CurrentAction3d_Nothing;
423 case CurrentAction3d_Fly :
425 case CurrentAction3d_Turn :
429 throw Standard_Failure(" incompatible Current Mode ");
431 } //switch (myCurrentMode)
432 } // else // if ( Ctrl )
435 void CAnimationView3D::OnMButtonDown(UINT nFlags, CPoint /*point*/)
437 if ( nFlags & MK_CONTROL )
439 // Button MB2 down Control : panning init
440 // SetCursor(AfxGetApp()->LoadStandardCursor());
444 void CAnimationView3D::OnMButtonUp(UINT nFlags, CPoint /*point*/)
446 if ( nFlags & MK_CONTROL )
448 // Button MB2 down Control : panning init
449 // SetCursor(AfxGetApp()->LoadStandardCursor());
453 void CAnimationView3D::OnRButtonDown(UINT nFlags, CPoint point)
455 if ( nFlags & MK_CONTROL )
457 // SetCursor(AfxGetApp()->LoadStandardCursor());
460 myView->SetComputedMode (Standard_False);
462 myView->StartRotation (point.x, point.y);
466 GetDocument()->Popup(point.x,point.y,myView);
470 void CAnimationView3D::OnRButtonUp(UINT /*nFlags*/, CPoint /*point*/)
472 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
473 myView->SetComputedMode (myHlrModeIsOn);
474 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
477 void CAnimationView3D::OnMouseMove(UINT nFlags, CPoint point)
479 // ============================ LEFT BUTTON =======================
483 if ( nFlags & MK_LBUTTON)
485 if ( nFlags & MK_CONTROL )
487 // move with MB1 and Control : on the dynamic zooming
488 // Do the zoom in function of mouse's coordinates
489 myView->Zoom(myXmax,myYmax,point.x,point.y);
490 // save the current mouse coordinate in min
496 switch (myCurrentMode)
498 case CurrentAction3d_Nothing :
499 myXmax = point.x; myYmax = point.y;
500 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False);
501 if (nFlags & MK_SHIFT)
502 GetDocument()->ShiftDragEvent(myXmax,myYmax,0,myView);
504 GetDocument()->DragEvent(myXmax,myYmax,0,myView);
505 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_True);
507 case CurrentAction3d_DynamicZooming :
508 myView->Zoom(myXmax,myYmax,point.x,point.y);
509 // save the current mouse coordinate in min \n";
510 myXmax=point.x; myYmax=point.y;
512 case CurrentAction3d_WindowZooming :
513 myXmax = point.x; myYmax = point.y;
514 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False,LongDash);
515 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_True,LongDash);
517 case CurrentAction3d_DynamicPanning :
518 myView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
519 myXmax = point.x; myYmax = point.y;
521 case CurrentAction3d_GlobalPanning : // nothing
523 case CurrentAction3d_DynamicRotation :
524 myView->Rotation(point.x,point.y);
527 case CurrentAction3d_Fly :
529 case CurrentAction3d_Turn :
532 throw Standard_Failure(" incompatible Current Mode ");
534 }// switch (myCurrentMode)
535 }// if ( nFlags & MK_CONTROL ) else
536 } else // if ( nFlags & MK_LBUTTON)
537 // ============================ MIDDLE BUTTON =======================
538 if ( nFlags & MK_MBUTTON)
540 if ( nFlags & MK_CONTROL )
542 myView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
543 myXmax = point.x; myYmax = point.y;
546 } else // if ( nFlags & MK_MBUTTON)
547 // ============================ RIGHT BUTTON =======================
548 if ( nFlags & MK_RBUTTON)
550 if ( nFlags & MK_CONTROL )
553 myView->Rotation(point.x,point.y);
555 }else //if ( nFlags & MK_RBUTTON)
556 // ============================ NO BUTTON =======================
558 myXmax = point.x; myYmax = point.y;
559 if (nFlags & MK_SHIFT)
560 GetDocument()->ShiftMoveEvent(point.x,point.y,myView);
562 GetDocument()->MoveEvent(point.x,point.y,myView);
566 void CAnimationView3D::OnUpdateBUTTONHlrOff(CCmdUI* pCmdUI)
568 pCmdUI->SetCheck (!myHlrModeIsOn);
569 pCmdUI->Enable (myHlrModeIsOn);
572 void CAnimationView3D::OnUpdateBUTTONHlrOn(CCmdUI* pCmdUI)
574 pCmdUI->SetCheck (myHlrModeIsOn);
575 pCmdUI->Enable (!myHlrModeIsOn);
578 void CAnimationView3D::OnUpdateBUTTONPanGlo(CCmdUI* pCmdUI)
580 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_GlobalPanning);
581 pCmdUI->Enable (myCurrentMode != CurrentAction3d_GlobalPanning);
585 void CAnimationView3D::OnUpdateBUTTONPan(CCmdUI* pCmdUI)
587 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_DynamicPanning);
588 pCmdUI->Enable (myCurrentMode != CurrentAction3d_DynamicPanning );
591 void CAnimationView3D::OnUpdateBUTTONZoomProg(CCmdUI* pCmdUI)
593 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_DynamicZooming );
594 pCmdUI->Enable (myCurrentMode != CurrentAction3d_DynamicZooming);
597 void CAnimationView3D::OnUpdateBUTTONZoomWin(CCmdUI* pCmdUI)
599 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_WindowZooming);
600 pCmdUI->Enable (myCurrentMode != CurrentAction3d_WindowZooming);
603 void CAnimationView3D::OnUpdateBUTTONRot(CCmdUI* pCmdUI)
605 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_DynamicRotation);
606 pCmdUI->Enable (myCurrentMode != CurrentAction3d_DynamicRotation);
609 void CAnimationView3D::OnUpdateBUTTONFly(CCmdUI* pCmdUI)
611 pCmdUI->Enable(GetDocument()->m_bIsGridLoaded);
612 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_Fly);
615 void CAnimationView3D::OnUpdateBUTTONTurn(CCmdUI* pCmdUI)
617 pCmdUI->Enable(GetDocument()->m_bIsGridLoaded);
618 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_Turn);
621 void CAnimationView3D::OnChangeBackground()
626 myView->BackgroundColor(Quantity_TOC_RGB,R1,G1,B1);
628 m_clr = RGB(R1*255,G1*255,B1*255);
630 CColorDialog dlgColor(m_clr);
631 if (dlgColor.DoModal() == IDOK)
633 m_clr = dlgColor.GetColor();
634 R1 = GetRValue(m_clr)/255.;
635 G1 = GetGValue(m_clr)/255.;
636 B1 = GetBValue(m_clr)/255.;
637 myView->SetBackgroundColor(Quantity_TOC_RGB,R1,G1,B1);
642 //==========================================================================================
643 //==========================================================================================
644 //==========================================================================================
646 //-----------------------------------------------------------------------------------------
648 //-----------------------------------------------------------------------------------------
649 void CAnimationView3D::DrawRectangle(const Standard_Integer MinX ,
650 const Standard_Integer MinY ,
651 const Standard_Integer MaxX ,
652 const Standard_Integer MaxY ,
653 const Standard_Boolean Draw ,
654 const LineStyle aLineStyle)
656 static int m_DrawMode;
657 if (!m_Pen && aLineStyle ==Solid )
658 {m_Pen = new CPen(PS_SOLID, 1, RGB(0,0,0)); m_DrawMode = R2_MERGEPENNOT;}
659 else if (!m_Pen && aLineStyle ==Dot )
660 {m_Pen = new CPen(PS_DOT, 1, RGB(0,0,0)); m_DrawMode = R2_XORPEN;}
661 else if (!m_Pen && aLineStyle == ShortDash)
662 {m_Pen = new CPen(PS_DASH, 1, RGB(255,0,0)); m_DrawMode = R2_XORPEN;}
663 else if (!m_Pen && aLineStyle == LongDash)
664 {m_Pen = new CPen(PS_DASH, 1, RGB(0,0,0)); m_DrawMode = R2_NOTXORPEN;}
665 else if (aLineStyle == Default)
666 { m_Pen = NULL; m_DrawMode = R2_MERGEPENNOT;}
668 CPen* aOldPen = NULL;
669 CClientDC clientDC(this);
670 if (m_Pen) aOldPen = clientDC.SelectObject(m_Pen);
671 clientDC.SetROP2(m_DrawMode);
673 static Standard_Integer StoredMinX, StoredMaxX, StoredMinY, StoredMaxY;
674 static Standard_Boolean m_IsVisible;
676 if ( m_IsVisible && !Draw) // move or up : erase at the old position
678 clientDC.MoveTo(StoredMinX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMaxY);
679 clientDC.LineTo(StoredMaxX,StoredMaxY);
680 clientDC.LineTo(StoredMaxX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMinY);
684 StoredMinX = Min ( MinX, MaxX );
685 StoredMinY = Min ( MinY, MaxY );
686 StoredMaxX = Max ( MinX, MaxX );
687 StoredMaxY = Max ( MinY, MaxY);
689 if (Draw) // move : draw
691 clientDC.MoveTo(StoredMinX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMaxY);
692 clientDC.LineTo(StoredMaxX,StoredMaxY);
693 clientDC.LineTo(StoredMaxX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMinY);
698 clientDC.SelectObject(aOldPen);
700 void CAnimationView3D::OnStop()
702 KillTimer(GetDocument()->myCount);
705 void CAnimationView3D::OnRestart()
707 KillTimer(GetDocument()->myCount);
708 SetTimer(GetDocument()->myCount, 1 , NULL);
712 void CAnimationView3D::OnTimer(UINT nIDEvent)
714 // TODO: Add your message handler code here and/or call default
715 GetDocument()->OnMyTimer();
716 CView::OnTimer(nIDEvent);
721 /*********************************************************************************
722 ************** W A L K T H R O U G H ******************************************
723 /********************************************************************************/
725 void CAnimationView3D::OnTimer(UINT_PTR nIDEvent)
727 if ( !GetDocument()->m_bIsGridLoaded )
729 // TODO: Add your message handler code here and/or call default
730 GetDocument()->OnMyTimer();
731 CView::OnTimer(nIDEvent);
735 CView::OnTimer(nIDEvent);
736 if ( nIDEvent == 1 ) {
737 myView->SetImmediateUpdate ( Standard_False ) ;
738 if ( myCurrentMode == CurrentAction3d_Fly ) {
740 Fly ( m_curx , m_cury ) ;
742 Roll ( m_curx , m_cury ) ;
744 Turn ( m_curx , m_cury ) ;
746 myView->SetAt ( m_Atx , m_Aty , m_Atz ) ;
747 myView->SetEye ( m_Eyex , m_Eyey , m_Eyez ) ;
750 else if ( myCurrentMode == CurrentAction3d_Turn ) {
751 Twist ( m_curx , m_cury ) ;
757 myView->SetImmediateUpdate ( Standard_True ) ;
766 void CAnimationView3D::OnSensitivity()
770 dial.m_SensFly = m_FlySens ;
771 dial.m_SensTurn = m_TurnSens ;
772 if ( dial.DoModal () ) {
773 m_FlySens = dial.m_SensFly ;
774 m_TurnSens = dial.m_SensTurn ;
778 void CAnimationView3D::Fly (int /*x*/ , int y)
785 sens = (double) myYmin - (double) y ;
786 sens /= (double) m_cy ;
789 v [0] = m_Atx - m_Eyex ;
790 v [1] = m_Aty - m_Eyey ;
791 v [2] = m_Atz - m_Eyez ;
792 l = sqrt ( v[0]*v[0] + v[1]*v[1] + v[2]*v[2] ) ;
794 for ( i=0 ; i<3 ; i++ )
795 v [i] = v [i] / l * sens ;
810 void CAnimationView3D::Turn (int x , int /*y*/)
812 gp_Vec z (0.,0.,1.) ;
816 double aX , aY , aZ ;
818 sens = (double) x - (double) myXmin ;
819 sens /= (double) m_cx ;
822 v [0] = m_Atx - m_Eyex ;
823 v [1] = m_Aty - m_Eyey ;
824 v [2] = m_Atz - m_Eyez ;
826 gp_Pnt eye ( m_Eyex , m_Eyey , m_Eyez ) ;
828 gp_Vec reg (v[0],v[1],v[2] );
830 gp_Vec vert = reg ^ z ;
831 gp_Vec haut = vert ^ reg ;
836 reg.Rotate (rot,sens) ;
838 reg.Coord ( aX , aY , aZ ) ;
840 m_Atx = m_Eyex + aX ;
841 m_Aty = m_Eyey + aY ;
842 m_Atz = m_Eyez + aZ ;
845 void CAnimationView3D::Roll (int x , int /*y*/)
847 gp_Vec z (0.,0.,1.) ;
851 double aX , aY , aZ ;
853 sens = (double) x - (double) myXmin ;
854 sens /= (double) m_cx ;
857 v [0] = m_Atx - m_Eyex ;
858 v [1] = m_Aty - m_Eyey ;
859 v [2] = m_Atz - m_Eyez ;
861 gp_Pnt eye ( m_Eyex , m_Eyey , m_Eyez ) ;
863 gp_Vec reg (v[0],v[1],v[2] );
865 gp_Vec vert = reg ^ z ;
870 reg.Rotate (rot,sens) ;
872 reg.Coord ( aX , aY , aZ ) ;
874 m_Atx = m_Eyex + aX ;
875 m_Aty = m_Eyey + aY ;
876 m_Atz = m_Eyez + aZ ;
879 void CAnimationView3D::Twist (int x , int /*y*/)
884 a = myView->Twist () ;
886 sens = (double) x - (double) myXmin ;
887 sens /= (double) m_cx ;
892 myView->SetTwist (a) ;
895 //=============================================================================
896 // function: SetFocal
898 //=============================================================================
899 void CAnimationView3D::SetFocal (double theFocus, double theAngle)
902 Handle(Graphic3d_Camera) aCamera = myView->Camera();
904 gp_Pnt anAt = aCamera->Center();
905 gp_Pnt anEye = aCamera->Eye();
907 gp_Vec aLook (anAt, anEye);
909 if (aCamera->Distance() > 1.e-3)
911 aLook = aLook / aCamera->Distance() * theFocus;
915 anAt.SetX (aLook.X() + anEye.X());
916 anAt.SetY (aLook.Y() + anEye.Y());
917 anAt.SetZ (aLook.Z() + anEye.Z());
921 aCamera->SetCenter (anAt);
922 aCamera->SetFOVy (theAngle);
928 void CAnimationView3D::ReloadData()
930 myView->At ( m_Atx , m_Aty , m_Atz ) ;
931 myView->Eye ( m_Eyex , m_Eyey , m_Eyez ) ;
932 double dTwist = myView->Twist() * 180. / M_PI;
935 aMsg.Format (L"%lf", m_Atx);
936 m_Tune.GetDlgItem (IDC_XAT)->SetWindowText (aMsg);
937 aMsg.Format (L"%lf", m_Aty);
938 m_Tune.GetDlgItem (IDC_YAT)->SetWindowText (aMsg);
939 aMsg.Format (L"%lf", m_Atz);
940 m_Tune.GetDlgItem (IDC_ZAT)->SetWindowText (aMsg);
942 aMsg.Format (L"%lf", m_Eyex);
943 m_Tune.GetDlgItem (IDC_XEYE)->SetWindowText (aMsg);
944 aMsg.Format (L"%lf", m_Eyey);
945 m_Tune.GetDlgItem (IDC_YEYE)->SetWindowText (aMsg);
946 aMsg.Format (L"%lf", m_Eyez);
947 m_Tune.GetDlgItem (IDC_ZEYE)->SetWindowText (aMsg);
949 aMsg.Format (L"%lf", dTwist);
950 m_Tune.GetDlgItem (IDC_TWIST)->SetWindowText (aMsg);
953 dx = m_Atx - m_Eyex ;
954 dy = m_Aty - m_Eyey ;
955 dz = m_Atz - m_Eyez ;
957 m_Focus = sqrt (dx * dx + dy * dy + dz * dz);
959 m_dAngle = myView->Camera()->FOVy();
961 m_Tune.m_dAngle = m_dAngle ;
962 m_Tune.m_dFocus = m_Focus ;
963 m_Tune.UpdateData ( FALSE ) ;
966 void CAnimationView3D::SetDimensions()
969 CAnimationDoc* pDoc = GetDocument();
971 myView->SetImmediateUpdate ( Standard_False ) ;
973 m_Atx = ( pDoc->m_Xmin + pDoc->m_Xmax ) / 2. ;
974 m_Aty = ( pDoc->m_Ymin + pDoc->m_Ymax ) / 2. ;
975 m_Atz = ( pDoc->m_Zmin + pDoc->m_Zmax ) / 2. ;
976 m_Eyex = pDoc->m_Xmax ;
977 m_Eyey = pDoc->m_Ymax ;
978 m_Eyez = pDoc->m_Zmax ;
980 myView->SetAt ( m_Atx , m_Aty , m_Atz ) ;
981 myView->SetEye ( m_Eyex , m_Eyey , m_Eyez ) ;
982 myView->SetTwist (0.) ;
984 myView->SetImmediateUpdate ( Standard_False ) ;
986 myView->SetImmediateUpdate ( Standard_False ) ;
989 myView->SetImmediateUpdate ( Standard_True ) ;
995 void CAnimationView3D::OnViewDisplaystatus()
997 // TODO: Add your command handler code here
999 if ( m_Tune.IsWindowVisible () ) {
1003 m_Tune.ShowWindow ( SW_SHOWNORMAL ) ;
1007 void CAnimationView3D::OnUpdateViewDisplaystatus(CCmdUI* pCmdUI)
1009 // TODO: Add your command update UI handler code here
1011 if ( m_Tune.IsWindowVisible () ) {
1012 pCmdUI->SetCheck ( 1 ) ;
1015 pCmdUI->SetCheck ( 0 ) ;