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()
87 // TODO: add construction code here
94 // will be set in OnInitial update, but, for more security :
95 myCurrentMode = CurrentAction3d_Nothing;
96 myDegenerateModeIsOn=Standard_True;
105 // will be set in OnInitial update, but, for more security :
107 m_TurnSens = M_PI / 40. ;
110 CAnimationView3D::~CAnimationView3D()
113 if (m_Pen) delete m_Pen;
116 BOOL CAnimationView3D::PreCreateWindow(CREATESTRUCT& cs)
118 // TODO: Modify the Window class or styles here by modifying
119 // the CREATESTRUCT cs
121 return CView::PreCreateWindow(cs);
124 /////////////////////////////////////////////////////////////////////////////
125 // CAnimationView3D drawing
127 void CAnimationView3D::OnDraw(CDC* pDC)
129 CAnimationDoc* pDoc = GetDocument();
132 // TODO: add draw code for native data here
137 void CAnimationView3D::OnInitialUpdate()
139 CView::OnInitialUpdate();
141 // TODO: Add your specialized code here and/or call the base class
142 // TODO: Add your specialized code here and/or call the base class
143 // myView = GetDocument()->GetViewer()->CreateView();
145 Handle(V3d_Viewer) aViewer ;
147 aViewer = GetDocument()->GetViewer() ;
148 aViewer->DefaultPerspectiveView () ;
149 aViewer->SetDefaultTypeOfView ( V3d_PERSPECTIVE ) ;
150 myView = aViewer->CreateView();
152 // store for restore state after rotation (witch is in Degenerated mode)
153 myDegenerateModeIsOn = myView->DegenerateModeIsOn();
155 Handle(WNT_Window) aWNTWindow = new WNT_Window(GetSafeHwnd ());
156 myView->SetWindow(aWNTWindow);
157 if (!aWNTWindow->IsMapped()) aWNTWindow->Map();
159 // store the mode ( nothing , dynamic zooming, dynamic ... )
160 myCurrentMode = CurrentAction3d_Nothing;
161 CFrameWnd* pParentFrm = GetParentFrame();
162 pParentFrm->ActivateFrame(SW_SHOWMAXIMIZED);
164 Standard_Integer w=100 , h=100 ; /* Debug Matrox */
165 aWNTWindow->Size (w,h) ; /* Keeps me unsatisfied (rlb)..... */
166 /* Resize is not supposed to be done on */
168 /* I suspect another problem elsewhere */
169 ::PostMessage ( GetSafeHwnd () , WM_SIZE , SIZE_RESTORED , w + h*65536 ) ;
171 myPView = Handle(V3d_PerspectiveView)::DownCast (myView);
173 m_Tune.Create ( IDD_TUNE , NULL ) ;
176 m_Tune.GetWindowRect(&dlgrect);
177 LONG width = dlgrect.right-dlgrect.left;
178 LONG height = dlgrect.bottom-dlgrect.top;
180 AfxGetApp()->m_pMainWnd->GetWindowRect(&MainWndRect);
181 LONG left = MainWndRect.left+3;
182 LONG top = MainWndRect.top + 112;
183 m_Tune.MoveWindow(left,top,width,height);
185 m_Tune.m_pView = this ;
187 m_Tune.ShowWindow ( SW_HIDE );
189 // store the mode ( nothing , dynamic zooming, dynamic ... )
191 myCurrentMode = CurrentAction3d_Nothing;
197 void CAnimationView3D::DisplayTuneDialog()
199 m_Tune.Create ( IDD_TUNE , NULL ) ;
202 m_Tune.GetWindowRect(&dlgrect);
203 LONG width = dlgrect.right-dlgrect.left;
204 LONG height = dlgrect.bottom-dlgrect.top;
206 AfxGetApp()->m_pMainWnd->GetWindowRect(&MainWndRect);
207 LONG left = MainWndRect.left+3;
208 LONG top = MainWndRect.top + 112;
209 m_Tune.MoveWindow(left,top,width,height);
211 m_Tune.m_pView = this ;
215 /////////////////////////////////////////////////////////////////////////////
216 // CAnimationView3D diagnostics
219 void CAnimationView3D::AssertValid() const
221 CView::AssertValid();
224 void CAnimationView3D::Dump(CDumpContext& dc) const
229 CAnimationDoc* CAnimationView3D::GetDocument() // non-debug version is inline
231 ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CAnimationDoc)));
232 return (CAnimationDoc*)m_pDocument;
236 /////////////////////////////////////////////////////////////////////////////
237 // CAnimationView3D message handlers
238 void CAnimationView3D::OnFileExportImage()
240 CFileDialog dlg(FALSE,_T("*.BMP"),NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
241 _T("BMP Files (*.BMP)|*.bmp |GIF Files (*.GIF)|*.gif | PNG Files (*.PNG)|*.png"
242 "|JPEG Files (*.JPEG)|*.jpeg | PPM Files (*.PPM)|*.ppm | TIFF Files (*.TIFF)"
243 "|*.tiff | TGA Files (*.TGA)|*.tga | EXR Files (*.EXR)|*.exr||"),
246 if (dlg.DoModal() == IDOK)
248 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
249 CString aFileName = dlg.GetPathName();
250 myView->Dump(aFileName);
251 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
255 void CAnimationView3D::OnSize(UINT nType, int cx, int cy)
259 if (!myView.IsNull())
260 myView->MustBeResized();
263 void CAnimationView3D::OnBUTTONBack()
264 { myView->SetProj(V3d_Xneg); } // See the back View
265 void CAnimationView3D::OnBUTTONFront()
266 { myView->SetProj(V3d_Xpos); } // See the front View
268 void CAnimationView3D::OnBUTTONBottom()
269 { myView->SetProj(V3d_Zneg); } // See the bottom View
270 void CAnimationView3D::OnBUTTONTop()
271 { myView->SetProj(V3d_Zpos); } // See the top View
273 void CAnimationView3D::OnBUTTONLeft()
274 { myView->SetProj(V3d_Ypos); } // See the left View
275 void CAnimationView3D::OnBUTTONRight()
276 { myView->SetProj(V3d_Yneg); } // See the right View
278 void CAnimationView3D::OnBUTTONAxo()
279 { myView->SetProj(V3d_XposYnegZpos); } // See the axonometric View
281 void CAnimationView3D::OnBUTTONHlrOff()
283 myView->SetDegenerateModeOn();
284 myDegenerateModeIsOn = Standard_True;
287 void CAnimationView3D::OnBUTTONHlrOn()
289 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
290 myView->SetDegenerateModeOff();
291 myDegenerateModeIsOn = Standard_False;
292 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
295 void CAnimationView3D::OnBUTTONPan()
297 myCurrentMode = CurrentAction3d_DynamicPanning;
300 void CAnimationView3D::OnBUTTONPanGlo()
302 // save the current zoom value
303 myCurZoom = myView->Scale();
307 myCurrentMode = CurrentAction3d_GlobalPanning;
310 void CAnimationView3D::OnBUTTONReset()
315 void CAnimationView3D::OnBUTTONRot()
316 { myCurrentMode = CurrentAction3d_DynamicRotation; }
319 void CAnimationView3D::OnBUTTONZoomAll()
326 void CAnimationView3D::OnBUTTONZoomProg()
327 { myCurrentMode = CurrentAction3d_DynamicZooming; }
329 void CAnimationView3D::OnBUTTONZoomWin()
330 { myCurrentMode = CurrentAction3d_WindowZooming; }
332 void CAnimationView3D::OnBUTTONFly()
333 { myCurrentMode = CurrentAction3d_Fly; }
335 void CAnimationView3D::OnBUTTONTurn()
336 { myCurrentMode = CurrentAction3d_Turn; }
339 void CAnimationView3D::OnLButtonDown(UINT nFlags, CPoint point)
341 // save the current mouse coordinate in min
342 myXmin=point.x; myYmin=point.y;
343 myXmax=point.x; myYmax=point.y;
345 if ( nFlags & MK_CONTROL )
347 // Button MB1 down Control :start zomming
348 // SetCursor(AfxGetApp()->LoadStandardCursor());
352 switch (myCurrentMode)
354 case CurrentAction3d_Nothing : // start a drag
355 if (nFlags & MK_SHIFT)
356 GetDocument()->ShiftDragEvent(myXmax,myYmax,-1,myView);
358 GetDocument()->DragEvent(myXmax,myYmax,-1,myView);
361 case CurrentAction3d_DynamicZooming : // noting
362 // SetCursor(AfxGetApp()->LoadStandardCursor());
364 case CurrentAction3d_WindowZooming : // noting
366 case CurrentAction3d_DynamicPanning :// noting
368 case CurrentAction3d_GlobalPanning :// noting
370 case CurrentAction3d_DynamicRotation :
371 if (!myDegenerateModeIsOn)
372 myView->SetDegenerateModeOn();
373 myView->StartRotation(point.x,point.y);
375 case CurrentAction3d_Fly :
377 SetTimer ( 1 , 100 , NULL ) ;
379 case CurrentAction3d_Turn :
381 SetTimer ( 1 , 100 , NULL ) ;
384 Standard_Failure::Raise(" incompatible Current Mode ");
390 void CAnimationView3D::OnLButtonUp(UINT nFlags, CPoint point)
392 if ( nFlags & MK_CONTROL )
398 switch (myCurrentMode)
400 case CurrentAction3d_Nothing :
401 if (point.x == myXmin && point.y == myYmin)
402 { // no offset between down and up --> selectEvent
405 if (nFlags & MK_SHIFT )
406 GetDocument()->ShiftInputEvent(point.x,point.y,myView);
408 GetDocument()->InputEvent (point.x,point.y,myView);
411 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False);
414 if (nFlags & MK_SHIFT)
415 GetDocument()->ShiftDragEvent(point.x,point.y,1,myView);
417 GetDocument()->DragEvent(point.x,point.y,1,myView);
420 case CurrentAction3d_DynamicZooming :
421 // SetCursor(AfxGetApp()->LoadStandardCursor());
422 myCurrentMode = CurrentAction3d_Nothing;
424 case CurrentAction3d_WindowZooming :
425 myXmax=point.x; myYmax=point.y;
426 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False,LongDash);
427 if ((abs(myXmin-myXmax)>ValZWMin) || (abs(myYmin-myYmax)>ValZWMin))
428 // Test if the zoom window is greater than a minimale window.
430 // Do the zoom window between Pmin and Pmax
431 myView->WindowFitAll(myXmin,myYmin,myXmax,myYmax);
433 myCurrentMode = CurrentAction3d_Nothing;
435 case CurrentAction3d_DynamicPanning :
436 myCurrentMode = CurrentAction3d_Nothing;
438 case CurrentAction3d_GlobalPanning :
439 myView->Place(point.x,point.y,myCurZoom);
440 myCurrentMode = CurrentAction3d_Nothing;
442 case CurrentAction3d_DynamicRotation :
443 myCurrentMode = CurrentAction3d_Nothing;
445 case CurrentAction3d_Fly :
447 case CurrentAction3d_Turn :
451 Standard_Failure::Raise(" incompatible Current Mode ");
453 } //switch (myCurrentMode)
454 } // else // if ( Ctrl )
457 void CAnimationView3D::OnMButtonDown(UINT nFlags, CPoint point)
459 if ( nFlags & MK_CONTROL )
461 // Button MB2 down Control : panning init
462 // SetCursor(AfxGetApp()->LoadStandardCursor());
466 void CAnimationView3D::OnMButtonUp(UINT nFlags, CPoint point)
468 if ( nFlags & MK_CONTROL )
470 // Button MB2 down Control : panning init
471 // SetCursor(AfxGetApp()->LoadStandardCursor());
475 void CAnimationView3D::OnRButtonDown(UINT nFlags, CPoint point)
477 if ( nFlags & MK_CONTROL )
479 // SetCursor(AfxGetApp()->LoadStandardCursor());
480 if (!myDegenerateModeIsOn)
481 myView->SetDegenerateModeOn();
482 myView->StartRotation(point.x,point.y);
486 GetDocument()->Popup(point.x,point.y,myView);
490 void CAnimationView3D::OnRButtonUp(UINT nFlags, CPoint point)
492 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
493 if (!myDegenerateModeIsOn)
495 myView->SetDegenerateModeOff();
496 myDegenerateModeIsOn = Standard_False;
499 myView->SetDegenerateModeOn();
500 myDegenerateModeIsOn = Standard_True;
502 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
505 void CAnimationView3D::OnMouseMove(UINT nFlags, CPoint point)
507 // ============================ LEFT BUTTON =======================
511 if ( nFlags & MK_LBUTTON)
513 if ( nFlags & MK_CONTROL )
515 // move with MB1 and Control : on the dynamic zooming
516 // Do the zoom in function of mouse's coordinates
517 myView->Zoom(myXmax,myYmax,point.x,point.y);
518 // save the current mouse coordinate in min
524 switch (myCurrentMode)
526 case CurrentAction3d_Nothing :
527 myXmax = point.x; myYmax = point.y;
528 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False);
529 if (nFlags & MK_SHIFT)
530 GetDocument()->ShiftDragEvent(myXmax,myYmax,0,myView);
532 GetDocument()->DragEvent(myXmax,myYmax,0,myView);
533 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_True);
535 case CurrentAction3d_DynamicZooming :
536 myView->Zoom(myXmax,myYmax,point.x,point.y);
537 // save the current mouse coordinate in min \n";
538 myXmax=point.x; myYmax=point.y;
540 case CurrentAction3d_WindowZooming :
541 myXmax = point.x; myYmax = point.y;
542 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False,LongDash);
543 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_True,LongDash);
545 case CurrentAction3d_DynamicPanning :
546 myView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
547 myXmax = point.x; myYmax = point.y;
549 case CurrentAction3d_GlobalPanning : // nothing
551 case CurrentAction3d_DynamicRotation :
552 myView->Rotation(point.x,point.y);
555 case CurrentAction3d_Fly :
557 case CurrentAction3d_Turn :
560 Standard_Failure::Raise(" incompatible Current Mode ");
562 }// switch (myCurrentMode)
563 }// if ( nFlags & MK_CONTROL ) else
564 } else // if ( nFlags & MK_LBUTTON)
565 // ============================ MIDDLE BUTTON =======================
566 if ( nFlags & MK_MBUTTON)
568 if ( nFlags & MK_CONTROL )
570 myView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
571 myXmax = point.x; myYmax = point.y;
574 } else // if ( nFlags & MK_MBUTTON)
575 // ============================ RIGHT BUTTON =======================
576 if ( nFlags & MK_RBUTTON)
578 if ( nFlags & MK_CONTROL )
581 myView->Rotation(point.x,point.y);
583 }else //if ( nFlags & MK_RBUTTON)
584 // ============================ NO BUTTON =======================
586 myXmax = point.x; myYmax = point.y;
587 if (nFlags & MK_SHIFT)
588 GetDocument()->ShiftMoveEvent(point.x,point.y,myView);
590 GetDocument()->MoveEvent(point.x,point.y,myView);
594 void CAnimationView3D::OnUpdateBUTTONHlrOff(CCmdUI* pCmdUI)
596 pCmdUI->SetCheck (myDegenerateModeIsOn);
597 pCmdUI->Enable (!myDegenerateModeIsOn);
600 void CAnimationView3D::OnUpdateBUTTONHlrOn(CCmdUI* pCmdUI)
602 pCmdUI->SetCheck (!myDegenerateModeIsOn);
603 pCmdUI->Enable (myDegenerateModeIsOn);
606 void CAnimationView3D::OnUpdateBUTTONPanGlo(CCmdUI* pCmdUI)
608 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_GlobalPanning);
609 pCmdUI->Enable (myCurrentMode != CurrentAction3d_GlobalPanning);
613 void CAnimationView3D::OnUpdateBUTTONPan(CCmdUI* pCmdUI)
615 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_DynamicPanning);
616 pCmdUI->Enable (myCurrentMode != CurrentAction3d_DynamicPanning );
619 void CAnimationView3D::OnUpdateBUTTONZoomProg(CCmdUI* pCmdUI)
621 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_DynamicZooming );
622 pCmdUI->Enable (myCurrentMode != CurrentAction3d_DynamicZooming);
625 void CAnimationView3D::OnUpdateBUTTONZoomWin(CCmdUI* pCmdUI)
627 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_WindowZooming);
628 pCmdUI->Enable (myCurrentMode != CurrentAction3d_WindowZooming);
631 void CAnimationView3D::OnUpdateBUTTONRot(CCmdUI* pCmdUI)
633 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_DynamicRotation);
634 pCmdUI->Enable (myCurrentMode != CurrentAction3d_DynamicRotation);
637 void CAnimationView3D::OnUpdateBUTTONFly(CCmdUI* pCmdUI)
639 pCmdUI->Enable(GetDocument()->m_bIsGridLoaded);
640 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_Fly);
643 void CAnimationView3D::OnUpdateBUTTONTurn(CCmdUI* pCmdUI)
645 pCmdUI->Enable(GetDocument()->m_bIsGridLoaded);
646 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_Turn);
649 void CAnimationView3D::OnChangeBackground()
654 myView->BackgroundColor(Quantity_TOC_RGB,R1,G1,B1);
656 m_clr = RGB(R1*255,G1*255,B1*255);
658 CColorDialog dlgColor(m_clr);
659 if (dlgColor.DoModal() == IDOK)
661 m_clr = dlgColor.GetColor();
662 R1 = GetRValue(m_clr)/255.;
663 G1 = GetGValue(m_clr)/255.;
664 B1 = GetBValue(m_clr)/255.;
665 myView->SetBackgroundColor(Quantity_TOC_RGB,R1,G1,B1);
670 //==========================================================================================
671 //==========================================================================================
672 //==========================================================================================
674 //-----------------------------------------------------------------------------------------
676 //-----------------------------------------------------------------------------------------
677 void CAnimationView3D::DrawRectangle(const Standard_Integer MinX ,
678 const Standard_Integer MinY ,
679 const Standard_Integer MaxX ,
680 const Standard_Integer MaxY ,
681 const Standard_Boolean Draw ,
682 const LineStyle aLineStyle)
684 static int m_DrawMode;
685 if (!m_Pen && aLineStyle ==Solid )
686 {m_Pen = new CPen(PS_SOLID, 1, RGB(0,0,0)); m_DrawMode = R2_MERGEPENNOT;}
687 else if (!m_Pen && aLineStyle ==Dot )
688 {m_Pen = new CPen(PS_DOT, 1, RGB(0,0,0)); m_DrawMode = R2_XORPEN;}
689 else if (!m_Pen && aLineStyle == ShortDash)
690 {m_Pen = new CPen(PS_DASH, 1, RGB(255,0,0)); m_DrawMode = R2_XORPEN;}
691 else if (!m_Pen && aLineStyle == LongDash)
692 {m_Pen = new CPen(PS_DASH, 1, RGB(0,0,0)); m_DrawMode = R2_NOTXORPEN;}
693 else if (aLineStyle == Default)
694 { m_Pen = NULL; m_DrawMode = R2_MERGEPENNOT;}
697 CClientDC clientDC(this);
698 if (m_Pen) aOldPen = clientDC.SelectObject(m_Pen);
699 clientDC.SetROP2(m_DrawMode);
701 static Standard_Integer StoredMinX, StoredMaxX, StoredMinY, StoredMaxY;
702 static Standard_Boolean m_IsVisible;
704 if ( m_IsVisible && !Draw) // move or up : erase at the old position
706 clientDC.MoveTo(StoredMinX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMaxY);
707 clientDC.LineTo(StoredMaxX,StoredMaxY);
708 clientDC.LineTo(StoredMaxX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMinY);
712 StoredMinX = min ( MinX, MaxX );
713 StoredMinY = min ( MinY, MaxY );
714 StoredMaxX = max ( MinX, MaxX );
715 StoredMaxY = max ( MinY, MaxY);
717 if (Draw) // move : draw
719 clientDC.MoveTo(StoredMinX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMaxY);
720 clientDC.LineTo(StoredMaxX,StoredMaxY);
721 clientDC.LineTo(StoredMaxX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMinY);
726 clientDC.SelectObject(aOldPen);
728 void CAnimationView3D::OnStop()
730 KillTimer(GetDocument()->myCount);
733 void CAnimationView3D::OnRestart()
735 KillTimer(GetDocument()->myCount);
736 SetTimer(GetDocument()->myCount, 1 , NULL);
740 void CAnimationView3D::OnTimer(UINT nIDEvent)
742 // TODO: Add your message handler code here and/or call default
743 GetDocument()->OnMyTimer();
744 CView::OnTimer(nIDEvent);
749 /*********************************************************************************
750 ************** W A L K T H R O U G H ******************************************
751 /********************************************************************************/
753 void CAnimationView3D::OnTimer(UINT_PTR nIDEvent)
755 if ( !GetDocument()->m_bIsGridLoaded )
757 // TODO: Add your message handler code here and/or call default
758 GetDocument()->OnMyTimer();
759 CView::OnTimer(nIDEvent);
763 CView::OnTimer(nIDEvent);
764 if ( nIDEvent == 1 ) {
765 myView->SetImmediateUpdate ( Standard_False ) ;
766 if ( myCurrentMode == CurrentAction3d_Fly ) {
768 Fly ( m_curx , m_cury ) ;
770 Roll ( m_curx , m_cury ) ;
772 Turn ( m_curx , m_cury ) ;
774 myView->SetAt ( m_Atx , m_Aty , m_Atz ) ;
775 myView->SetEye ( m_Eyex , m_Eyey , m_Eyez ) ;
778 else if ( myCurrentMode == CurrentAction3d_Turn ) {
779 Twist ( m_curx , m_cury ) ;
785 myView->SetImmediateUpdate ( Standard_True ) ;
794 void CAnimationView3D::OnSensitivity()
798 dial.m_SensFly = m_FlySens ;
799 dial.m_SensTurn = m_TurnSens ;
800 if ( dial.DoModal () ) {
801 m_FlySens = dial.m_SensFly ;
802 m_TurnSens = dial.m_SensTurn ;
806 void CAnimationView3D::Fly (int x , int y)
813 sens = (double) myYmin - (double) y ;
814 sens /= (double) m_cy ;
817 v [0] = m_Atx - m_Eyex ;
818 v [1] = m_Aty - m_Eyey ;
819 v [2] = m_Atz - m_Eyez ;
820 l = sqrt ( v[0]*v[0] + v[1]*v[1] + v[2]*v[2] ) ;
822 for ( i=0 ; i<3 ; i++ )
823 v [i] = v [i] / l * sens ;
838 void CAnimationView3D::Turn (int x , int y)
840 gp_Vec z (0.,0.,1.) ;
844 double aX , aY , aZ ;
846 sens = (double) x - (double) myXmin ;
847 sens /= (double) m_cx ;
850 v [0] = m_Atx - m_Eyex ;
851 v [1] = m_Aty - m_Eyey ;
852 v [2] = m_Atz - m_Eyez ;
854 gp_Pnt eye ( m_Eyex , m_Eyey , m_Eyez ) ;
856 gp_Vec reg (v[0],v[1],v[2] );
858 gp_Vec vert = reg ^ z ;
859 gp_Vec haut = vert ^ reg ;
864 reg.Rotate (rot,sens) ;
866 reg.Coord ( aX , aY , aZ ) ;
868 m_Atx = m_Eyex + aX ;
869 m_Aty = m_Eyey + aY ;
870 m_Atz = m_Eyez + aZ ;
873 void CAnimationView3D::Roll (int x , int y)
875 gp_Vec z (0.,0.,1.) ;
879 double aX , aY , aZ ;
881 sens = (double) x - (double) myXmin ;
882 sens /= (double) m_cx ;
885 v [0] = m_Atx - m_Eyex ;
886 v [1] = m_Aty - m_Eyey ;
887 v [2] = m_Atz - m_Eyez ;
889 gp_Pnt eye ( m_Eyex , m_Eyey , m_Eyez ) ;
891 gp_Vec reg (v[0],v[1],v[2] );
893 gp_Vec vert = reg ^ z ;
898 reg.Rotate (rot,sens) ;
900 reg.Coord ( aX , aY , aZ ) ;
902 m_Atx = m_Eyex + aX ;
903 m_Aty = m_Eyey + aY ;
904 m_Atz = m_Eyez + aZ ;
907 void CAnimationView3D::Twist (int x , int y)
912 a = myView->Twist () ;
914 sens = (double) x - (double) myXmin ;
915 sens /= (double) m_cx ;
920 myView->SetTwist (a) ;
923 void CAnimationView3D::SetFocal(double dFocus,double dAngle)
929 v [0] = m_Atx - m_Eyex ;
930 v [1] = m_Aty - m_Eyey ;
931 v [2] = m_Atz - m_Eyez ;
933 l = sqrt ( v[0]*v[0] + v[1]*v[1] + v[2]*v[2] ) ;
935 for ( i=0 ; i<3 ; i++ )
936 v [i] = v [i] / l * dFocus ;
940 m_Atx = v [0] + m_Eyex ;
941 m_Aty = v [1] + m_Eyey ;
942 m_Atz = v [2] + m_Eyez ;
944 myView->SetImmediateUpdate ( Standard_False ) ;
945 myView->SetAt ( m_Atx , m_Aty , m_Atz ) ;
947 dAngle = dAngle * M_PI / 180. ;
948 myPView->SetAngle ( dAngle ) ;
949 dAngle = myPView->Angle () ;
951 myView->SetImmediateUpdate ( Standard_True ) ;
956 void CAnimationView3D::ReloadData()
961 myView->At ( m_Atx , m_Aty , m_Atz ) ;
962 myView->Eye ( m_Eyex , m_Eyey , m_Eyez ) ;
964 dTwist = myView->Twist () ;
965 dTwist = dTwist * 180. / M_PI ;
967 sprintf_s ( szMsg , "%lf" , m_Atx ) ;
968 (m_Tune.GetDlgItem ( IDC_XAT ))->SetWindowText ( szMsg ) ;
969 sprintf_s ( szMsg , "%lf" , m_Aty ) ;
970 (m_Tune.GetDlgItem ( IDC_YAT ))->SetWindowText ( szMsg ) ;
971 sprintf_s ( szMsg , "%lf" , m_Atz ) ;
972 (m_Tune.GetDlgItem ( IDC_ZAT ))->SetWindowText ( szMsg ) ;
974 sprintf_s ( szMsg , "%lf" , m_Eyex ) ;
975 (m_Tune.GetDlgItem ( IDC_XEYE ))->SetWindowText ( szMsg ) ;
976 sprintf_s ( szMsg , "%lf" , m_Eyey ) ;
977 (m_Tune.GetDlgItem ( IDC_YEYE ))->SetWindowText ( szMsg ) ;
978 sprintf_s ( szMsg , "%lf" , m_Eyez ) ;
979 (m_Tune.GetDlgItem ( IDC_ZEYE ))->SetWindowText ( szMsg ) ;
981 sprintf_s ( szMsg , "%lf" , dTwist ) ;
982 (m_Tune.GetDlgItem ( IDC_TWIST ))->SetWindowText ( szMsg ) ;
985 dx = m_Atx - m_Eyex ;
986 dy = m_Aty - m_Eyey ;
987 dz = m_Atz - m_Eyez ;
989 m_Focus = sqrt ( dx * dx + dy * dy + dz * dz ) ;
990 m_dAngle = myPView->Angle () ;
991 m_dAngle = m_dAngle * 180. / M_PI ;
993 m_Tune.m_dAngle = m_dAngle ;
994 m_Tune.m_dFocus = m_Focus ;
995 m_Tune.UpdateData ( FALSE ) ;
998 void CAnimationView3D::SetDimensions()
1001 CAnimationDoc* pDoc = GetDocument();
1003 myView->SetImmediateUpdate ( Standard_False ) ;
1005 m_Atx = ( pDoc->m_Xmin + pDoc->m_Xmax ) / 2. ;
1006 m_Aty = ( pDoc->m_Ymin + pDoc->m_Ymax ) / 2. ;
1007 m_Atz = ( pDoc->m_Zmin + pDoc->m_Zmax ) / 2. ;
1008 m_Eyex = pDoc->m_Xmax ;
1009 m_Eyey = pDoc->m_Ymax ;
1010 m_Eyez = pDoc->m_Zmax ;
1012 myView->SetAt ( m_Atx , m_Aty , m_Atz ) ;
1013 myView->SetEye ( m_Eyex , m_Eyey , m_Eyez ) ;
1014 myView->SetTwist (0.) ;
1016 myView->SetImmediateUpdate ( Standard_False ) ;
1018 myView->SetImmediateUpdate ( Standard_False ) ;
1021 myView->SetImmediateUpdate ( Standard_True ) ;
1027 void CAnimationView3D::OnViewDisplaystatus()
1029 // TODO: Add your command handler code here
1031 if ( m_Tune.IsWindowVisible () ) {
1035 m_Tune.ShowWindow ( SW_SHOWNORMAL ) ;
1039 void CAnimationView3D::OnUpdateViewDisplaystatus(CCmdUI* pCmdUI)
1041 // TODO: Add your command update UI handler code here
1043 if ( m_Tune.IsWindowVisible () ) {
1044 pCmdUI->SetCheck ( 1 ) ;
1047 pCmdUI->SetCheck ( 0 ) ;