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 aDlg (FALSE, "*.BMP", NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
241 "BMP Files (*.BMP)|*.bmp|"
242 "GIF Files (*.GIF)|*.gif|"
243 "PNG Files (*.PNG)|*.png|"
244 "JPEG Files (*.JPEG)|*.jpeg|"
245 "PPM Files (*.PPM)|*.ppm|"
246 "TIFF Files (*.TIFF)|*.tiff|"
247 "TGA Files (*.TGA)|*.tga|"
248 "EXR Files (*.EXR)|*.exr||",
250 if (aDlg.DoModal() != IDOK)
255 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
256 myView->Dump (aDlg.GetPathName());
257 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
260 void CAnimationView3D::OnSize(UINT nType, int cx, int cy)
264 if (!myView.IsNull())
265 myView->MustBeResized();
268 void CAnimationView3D::OnBUTTONBack()
269 { myView->SetProj(V3d_Xneg); } // See the back View
270 void CAnimationView3D::OnBUTTONFront()
271 { myView->SetProj(V3d_Xpos); } // See the front View
273 void CAnimationView3D::OnBUTTONBottom()
274 { myView->SetProj(V3d_Zneg); } // See the bottom View
275 void CAnimationView3D::OnBUTTONTop()
276 { myView->SetProj(V3d_Zpos); } // See the top View
278 void CAnimationView3D::OnBUTTONLeft()
279 { myView->SetProj(V3d_Ypos); } // See the left View
280 void CAnimationView3D::OnBUTTONRight()
281 { myView->SetProj(V3d_Yneg); } // See the right View
283 void CAnimationView3D::OnBUTTONAxo()
284 { myView->SetProj(V3d_XposYnegZpos); } // See the axonometric View
286 void CAnimationView3D::OnBUTTONHlrOff()
288 myView->SetDegenerateModeOn();
289 myDegenerateModeIsOn = Standard_True;
292 void CAnimationView3D::OnBUTTONHlrOn()
294 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
295 myView->SetDegenerateModeOff();
296 myDegenerateModeIsOn = Standard_False;
297 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
300 void CAnimationView3D::OnBUTTONPan()
302 myCurrentMode = CurrentAction3d_DynamicPanning;
305 void CAnimationView3D::OnBUTTONPanGlo()
307 // save the current zoom value
308 myCurZoom = myView->Scale();
312 myCurrentMode = CurrentAction3d_GlobalPanning;
315 void CAnimationView3D::OnBUTTONReset()
320 void CAnimationView3D::OnBUTTONRot()
321 { myCurrentMode = CurrentAction3d_DynamicRotation; }
324 void CAnimationView3D::OnBUTTONZoomAll()
331 void CAnimationView3D::OnBUTTONZoomProg()
332 { myCurrentMode = CurrentAction3d_DynamicZooming; }
334 void CAnimationView3D::OnBUTTONZoomWin()
335 { myCurrentMode = CurrentAction3d_WindowZooming; }
337 void CAnimationView3D::OnBUTTONFly()
338 { myCurrentMode = CurrentAction3d_Fly; }
340 void CAnimationView3D::OnBUTTONTurn()
341 { myCurrentMode = CurrentAction3d_Turn; }
344 void CAnimationView3D::OnLButtonDown(UINT nFlags, CPoint point)
346 // save the current mouse coordinate in min
347 myXmin=point.x; myYmin=point.y;
348 myXmax=point.x; myYmax=point.y;
350 if ( nFlags & MK_CONTROL )
352 // Button MB1 down Control :start zomming
353 // SetCursor(AfxGetApp()->LoadStandardCursor());
357 switch (myCurrentMode)
359 case CurrentAction3d_Nothing : // start a drag
360 if (nFlags & MK_SHIFT)
361 GetDocument()->ShiftDragEvent(myXmax,myYmax,-1,myView);
363 GetDocument()->DragEvent(myXmax,myYmax,-1,myView);
366 case CurrentAction3d_DynamicZooming : // noting
367 // SetCursor(AfxGetApp()->LoadStandardCursor());
369 case CurrentAction3d_WindowZooming : // noting
371 case CurrentAction3d_DynamicPanning :// noting
373 case CurrentAction3d_GlobalPanning :// noting
375 case CurrentAction3d_DynamicRotation :
376 if (!myDegenerateModeIsOn)
377 myView->SetDegenerateModeOn();
378 myView->StartRotation(point.x,point.y);
380 case CurrentAction3d_Fly :
382 SetTimer ( 1 , 100 , NULL ) ;
384 case CurrentAction3d_Turn :
386 SetTimer ( 1 , 100 , NULL ) ;
389 Standard_Failure::Raise(" incompatible Current Mode ");
395 void CAnimationView3D::OnLButtonUp(UINT nFlags, CPoint point)
397 if ( nFlags & MK_CONTROL )
403 switch (myCurrentMode)
405 case CurrentAction3d_Nothing :
406 if (point.x == myXmin && point.y == myYmin)
407 { // no offset between down and up --> selectEvent
410 if (nFlags & MK_SHIFT )
411 GetDocument()->ShiftInputEvent(point.x,point.y,myView);
413 GetDocument()->InputEvent (point.x,point.y,myView);
416 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False);
419 if (nFlags & MK_SHIFT)
420 GetDocument()->ShiftDragEvent(point.x,point.y,1,myView);
422 GetDocument()->DragEvent(point.x,point.y,1,myView);
425 case CurrentAction3d_DynamicZooming :
426 // SetCursor(AfxGetApp()->LoadStandardCursor());
427 myCurrentMode = CurrentAction3d_Nothing;
429 case CurrentAction3d_WindowZooming :
430 myXmax=point.x; myYmax=point.y;
431 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False,LongDash);
432 if ((abs(myXmin-myXmax)>ValZWMin) || (abs(myYmin-myYmax)>ValZWMin))
433 // Test if the zoom window is greater than a minimale window.
435 // Do the zoom window between Pmin and Pmax
436 myView->WindowFitAll(myXmin,myYmin,myXmax,myYmax);
438 myCurrentMode = CurrentAction3d_Nothing;
440 case CurrentAction3d_DynamicPanning :
441 myCurrentMode = CurrentAction3d_Nothing;
443 case CurrentAction3d_GlobalPanning :
444 myView->Place(point.x,point.y,myCurZoom);
445 myCurrentMode = CurrentAction3d_Nothing;
447 case CurrentAction3d_DynamicRotation :
448 myCurrentMode = CurrentAction3d_Nothing;
450 case CurrentAction3d_Fly :
452 case CurrentAction3d_Turn :
456 Standard_Failure::Raise(" incompatible Current Mode ");
458 } //switch (myCurrentMode)
459 } // else // if ( Ctrl )
462 void CAnimationView3D::OnMButtonDown(UINT nFlags, CPoint point)
464 if ( nFlags & MK_CONTROL )
466 // Button MB2 down Control : panning init
467 // SetCursor(AfxGetApp()->LoadStandardCursor());
471 void CAnimationView3D::OnMButtonUp(UINT nFlags, CPoint point)
473 if ( nFlags & MK_CONTROL )
475 // Button MB2 down Control : panning init
476 // SetCursor(AfxGetApp()->LoadStandardCursor());
480 void CAnimationView3D::OnRButtonDown(UINT nFlags, CPoint point)
482 if ( nFlags & MK_CONTROL )
484 // SetCursor(AfxGetApp()->LoadStandardCursor());
485 if (!myDegenerateModeIsOn)
486 myView->SetDegenerateModeOn();
487 myView->StartRotation(point.x,point.y);
491 GetDocument()->Popup(point.x,point.y,myView);
495 void CAnimationView3D::OnRButtonUp(UINT nFlags, CPoint point)
497 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
498 if (!myDegenerateModeIsOn)
500 myView->SetDegenerateModeOff();
501 myDegenerateModeIsOn = Standard_False;
504 myView->SetDegenerateModeOn();
505 myDegenerateModeIsOn = Standard_True;
507 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
510 void CAnimationView3D::OnMouseMove(UINT nFlags, CPoint point)
512 // ============================ LEFT BUTTON =======================
516 if ( nFlags & MK_LBUTTON)
518 if ( nFlags & MK_CONTROL )
520 // move with MB1 and Control : on the dynamic zooming
521 // Do the zoom in function of mouse's coordinates
522 myView->Zoom(myXmax,myYmax,point.x,point.y);
523 // save the current mouse coordinate in min
529 switch (myCurrentMode)
531 case CurrentAction3d_Nothing :
532 myXmax = point.x; myYmax = point.y;
533 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False);
534 if (nFlags & MK_SHIFT)
535 GetDocument()->ShiftDragEvent(myXmax,myYmax,0,myView);
537 GetDocument()->DragEvent(myXmax,myYmax,0,myView);
538 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_True);
540 case CurrentAction3d_DynamicZooming :
541 myView->Zoom(myXmax,myYmax,point.x,point.y);
542 // save the current mouse coordinate in min \n";
543 myXmax=point.x; myYmax=point.y;
545 case CurrentAction3d_WindowZooming :
546 myXmax = point.x; myYmax = point.y;
547 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False,LongDash);
548 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_True,LongDash);
550 case CurrentAction3d_DynamicPanning :
551 myView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
552 myXmax = point.x; myYmax = point.y;
554 case CurrentAction3d_GlobalPanning : // nothing
556 case CurrentAction3d_DynamicRotation :
557 myView->Rotation(point.x,point.y);
560 case CurrentAction3d_Fly :
562 case CurrentAction3d_Turn :
565 Standard_Failure::Raise(" incompatible Current Mode ");
567 }// switch (myCurrentMode)
568 }// if ( nFlags & MK_CONTROL ) else
569 } else // if ( nFlags & MK_LBUTTON)
570 // ============================ MIDDLE BUTTON =======================
571 if ( nFlags & MK_MBUTTON)
573 if ( nFlags & MK_CONTROL )
575 myView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
576 myXmax = point.x; myYmax = point.y;
579 } else // if ( nFlags & MK_MBUTTON)
580 // ============================ RIGHT BUTTON =======================
581 if ( nFlags & MK_RBUTTON)
583 if ( nFlags & MK_CONTROL )
586 myView->Rotation(point.x,point.y);
588 }else //if ( nFlags & MK_RBUTTON)
589 // ============================ NO BUTTON =======================
591 myXmax = point.x; myYmax = point.y;
592 if (nFlags & MK_SHIFT)
593 GetDocument()->ShiftMoveEvent(point.x,point.y,myView);
595 GetDocument()->MoveEvent(point.x,point.y,myView);
599 void CAnimationView3D::OnUpdateBUTTONHlrOff(CCmdUI* pCmdUI)
601 pCmdUI->SetCheck (myDegenerateModeIsOn);
602 pCmdUI->Enable (!myDegenerateModeIsOn);
605 void CAnimationView3D::OnUpdateBUTTONHlrOn(CCmdUI* pCmdUI)
607 pCmdUI->SetCheck (!myDegenerateModeIsOn);
608 pCmdUI->Enable (myDegenerateModeIsOn);
611 void CAnimationView3D::OnUpdateBUTTONPanGlo(CCmdUI* pCmdUI)
613 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_GlobalPanning);
614 pCmdUI->Enable (myCurrentMode != CurrentAction3d_GlobalPanning);
618 void CAnimationView3D::OnUpdateBUTTONPan(CCmdUI* pCmdUI)
620 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_DynamicPanning);
621 pCmdUI->Enable (myCurrentMode != CurrentAction3d_DynamicPanning );
624 void CAnimationView3D::OnUpdateBUTTONZoomProg(CCmdUI* pCmdUI)
626 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_DynamicZooming );
627 pCmdUI->Enable (myCurrentMode != CurrentAction3d_DynamicZooming);
630 void CAnimationView3D::OnUpdateBUTTONZoomWin(CCmdUI* pCmdUI)
632 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_WindowZooming);
633 pCmdUI->Enable (myCurrentMode != CurrentAction3d_WindowZooming);
636 void CAnimationView3D::OnUpdateBUTTONRot(CCmdUI* pCmdUI)
638 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_DynamicRotation);
639 pCmdUI->Enable (myCurrentMode != CurrentAction3d_DynamicRotation);
642 void CAnimationView3D::OnUpdateBUTTONFly(CCmdUI* pCmdUI)
644 pCmdUI->Enable(GetDocument()->m_bIsGridLoaded);
645 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_Fly);
648 void CAnimationView3D::OnUpdateBUTTONTurn(CCmdUI* pCmdUI)
650 pCmdUI->Enable(GetDocument()->m_bIsGridLoaded);
651 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_Turn);
654 void CAnimationView3D::OnChangeBackground()
659 myView->BackgroundColor(Quantity_TOC_RGB,R1,G1,B1);
661 m_clr = RGB(R1*255,G1*255,B1*255);
663 CColorDialog dlgColor(m_clr);
664 if (dlgColor.DoModal() == IDOK)
666 m_clr = dlgColor.GetColor();
667 R1 = GetRValue(m_clr)/255.;
668 G1 = GetGValue(m_clr)/255.;
669 B1 = GetBValue(m_clr)/255.;
670 myView->SetBackgroundColor(Quantity_TOC_RGB,R1,G1,B1);
675 //==========================================================================================
676 //==========================================================================================
677 //==========================================================================================
679 //-----------------------------------------------------------------------------------------
681 //-----------------------------------------------------------------------------------------
682 void CAnimationView3D::DrawRectangle(const Standard_Integer MinX ,
683 const Standard_Integer MinY ,
684 const Standard_Integer MaxX ,
685 const Standard_Integer MaxY ,
686 const Standard_Boolean Draw ,
687 const LineStyle aLineStyle)
689 static int m_DrawMode;
690 if (!m_Pen && aLineStyle ==Solid )
691 {m_Pen = new CPen(PS_SOLID, 1, RGB(0,0,0)); m_DrawMode = R2_MERGEPENNOT;}
692 else if (!m_Pen && aLineStyle ==Dot )
693 {m_Pen = new CPen(PS_DOT, 1, RGB(0,0,0)); m_DrawMode = R2_XORPEN;}
694 else if (!m_Pen && aLineStyle == ShortDash)
695 {m_Pen = new CPen(PS_DASH, 1, RGB(255,0,0)); m_DrawMode = R2_XORPEN;}
696 else if (!m_Pen && aLineStyle == LongDash)
697 {m_Pen = new CPen(PS_DASH, 1, RGB(0,0,0)); m_DrawMode = R2_NOTXORPEN;}
698 else if (aLineStyle == Default)
699 { m_Pen = NULL; m_DrawMode = R2_MERGEPENNOT;}
702 CClientDC clientDC(this);
703 if (m_Pen) aOldPen = clientDC.SelectObject(m_Pen);
704 clientDC.SetROP2(m_DrawMode);
706 static Standard_Integer StoredMinX, StoredMaxX, StoredMinY, StoredMaxY;
707 static Standard_Boolean m_IsVisible;
709 if ( m_IsVisible && !Draw) // move or up : erase at the old position
711 clientDC.MoveTo(StoredMinX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMaxY);
712 clientDC.LineTo(StoredMaxX,StoredMaxY);
713 clientDC.LineTo(StoredMaxX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMinY);
717 StoredMinX = min ( MinX, MaxX );
718 StoredMinY = min ( MinY, MaxY );
719 StoredMaxX = max ( MinX, MaxX );
720 StoredMaxY = max ( MinY, MaxY);
722 if (Draw) // move : draw
724 clientDC.MoveTo(StoredMinX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMaxY);
725 clientDC.LineTo(StoredMaxX,StoredMaxY);
726 clientDC.LineTo(StoredMaxX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMinY);
731 clientDC.SelectObject(aOldPen);
733 void CAnimationView3D::OnStop()
735 KillTimer(GetDocument()->myCount);
738 void CAnimationView3D::OnRestart()
740 KillTimer(GetDocument()->myCount);
741 SetTimer(GetDocument()->myCount, 1 , NULL);
745 void CAnimationView3D::OnTimer(UINT nIDEvent)
747 // TODO: Add your message handler code here and/or call default
748 GetDocument()->OnMyTimer();
749 CView::OnTimer(nIDEvent);
754 /*********************************************************************************
755 ************** W A L K T H R O U G H ******************************************
756 /********************************************************************************/
758 void CAnimationView3D::OnTimer(UINT_PTR nIDEvent)
760 if ( !GetDocument()->m_bIsGridLoaded )
762 // TODO: Add your message handler code here and/or call default
763 GetDocument()->OnMyTimer();
764 CView::OnTimer(nIDEvent);
768 CView::OnTimer(nIDEvent);
769 if ( nIDEvent == 1 ) {
770 myView->SetImmediateUpdate ( Standard_False ) ;
771 if ( myCurrentMode == CurrentAction3d_Fly ) {
773 Fly ( m_curx , m_cury ) ;
775 Roll ( m_curx , m_cury ) ;
777 Turn ( m_curx , m_cury ) ;
779 myView->SetAt ( m_Atx , m_Aty , m_Atz ) ;
780 myView->SetEye ( m_Eyex , m_Eyey , m_Eyez ) ;
783 else if ( myCurrentMode == CurrentAction3d_Turn ) {
784 Twist ( m_curx , m_cury ) ;
790 myView->SetImmediateUpdate ( Standard_True ) ;
799 void CAnimationView3D::OnSensitivity()
803 dial.m_SensFly = m_FlySens ;
804 dial.m_SensTurn = m_TurnSens ;
805 if ( dial.DoModal () ) {
806 m_FlySens = dial.m_SensFly ;
807 m_TurnSens = dial.m_SensTurn ;
811 void CAnimationView3D::Fly (int x , int y)
818 sens = (double) myYmin - (double) y ;
819 sens /= (double) m_cy ;
822 v [0] = m_Atx - m_Eyex ;
823 v [1] = m_Aty - m_Eyey ;
824 v [2] = m_Atz - m_Eyez ;
825 l = sqrt ( v[0]*v[0] + v[1]*v[1] + v[2]*v[2] ) ;
827 for ( i=0 ; i<3 ; i++ )
828 v [i] = v [i] / l * sens ;
843 void CAnimationView3D::Turn (int x , int y)
845 gp_Vec z (0.,0.,1.) ;
849 double aX , aY , aZ ;
851 sens = (double) x - (double) myXmin ;
852 sens /= (double) m_cx ;
855 v [0] = m_Atx - m_Eyex ;
856 v [1] = m_Aty - m_Eyey ;
857 v [2] = m_Atz - m_Eyez ;
859 gp_Pnt eye ( m_Eyex , m_Eyey , m_Eyez ) ;
861 gp_Vec reg (v[0],v[1],v[2] );
863 gp_Vec vert = reg ^ z ;
864 gp_Vec haut = vert ^ reg ;
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::Roll (int x , int y)
880 gp_Vec z (0.,0.,1.) ;
884 double aX , aY , aZ ;
886 sens = (double) x - (double) myXmin ;
887 sens /= (double) m_cx ;
890 v [0] = m_Atx - m_Eyex ;
891 v [1] = m_Aty - m_Eyey ;
892 v [2] = m_Atz - m_Eyez ;
894 gp_Pnt eye ( m_Eyex , m_Eyey , m_Eyez ) ;
896 gp_Vec reg (v[0],v[1],v[2] );
898 gp_Vec vert = reg ^ z ;
903 reg.Rotate (rot,sens) ;
905 reg.Coord ( aX , aY , aZ ) ;
907 m_Atx = m_Eyex + aX ;
908 m_Aty = m_Eyey + aY ;
909 m_Atz = m_Eyez + aZ ;
912 void CAnimationView3D::Twist (int x , int y)
917 a = myView->Twist () ;
919 sens = (double) x - (double) myXmin ;
920 sens /= (double) m_cx ;
925 myView->SetTwist (a) ;
928 void CAnimationView3D::SetFocal(double dFocus,double dAngle)
934 v [0] = m_Atx - m_Eyex ;
935 v [1] = m_Aty - m_Eyey ;
936 v [2] = m_Atz - m_Eyez ;
938 l = sqrt ( v[0]*v[0] + v[1]*v[1] + v[2]*v[2] ) ;
940 for ( i=0 ; i<3 ; i++ )
941 v [i] = v [i] / l * dFocus ;
945 m_Atx = v [0] + m_Eyex ;
946 m_Aty = v [1] + m_Eyey ;
947 m_Atz = v [2] + m_Eyez ;
949 myView->SetImmediateUpdate ( Standard_False ) ;
950 myView->SetAt ( m_Atx , m_Aty , m_Atz ) ;
952 dAngle = dAngle * M_PI / 180. ;
953 myPView->SetAngle ( dAngle ) ;
954 dAngle = myPView->Angle () ;
956 myView->SetImmediateUpdate ( Standard_True ) ;
961 void CAnimationView3D::ReloadData()
966 myView->At ( m_Atx , m_Aty , m_Atz ) ;
967 myView->Eye ( m_Eyex , m_Eyey , m_Eyez ) ;
969 dTwist = myView->Twist () ;
970 dTwist = dTwist * 180. / M_PI ;
972 sprintf_s ( szMsg , "%lf" , m_Atx ) ;
973 (m_Tune.GetDlgItem ( IDC_XAT ))->SetWindowText ( szMsg ) ;
974 sprintf_s ( szMsg , "%lf" , m_Aty ) ;
975 (m_Tune.GetDlgItem ( IDC_YAT ))->SetWindowText ( szMsg ) ;
976 sprintf_s ( szMsg , "%lf" , m_Atz ) ;
977 (m_Tune.GetDlgItem ( IDC_ZAT ))->SetWindowText ( szMsg ) ;
979 sprintf_s ( szMsg , "%lf" , m_Eyex ) ;
980 (m_Tune.GetDlgItem ( IDC_XEYE ))->SetWindowText ( szMsg ) ;
981 sprintf_s ( szMsg , "%lf" , m_Eyey ) ;
982 (m_Tune.GetDlgItem ( IDC_YEYE ))->SetWindowText ( szMsg ) ;
983 sprintf_s ( szMsg , "%lf" , m_Eyez ) ;
984 (m_Tune.GetDlgItem ( IDC_ZEYE ))->SetWindowText ( szMsg ) ;
986 sprintf_s ( szMsg , "%lf" , dTwist ) ;
987 (m_Tune.GetDlgItem ( IDC_TWIST ))->SetWindowText ( szMsg ) ;
990 dx = m_Atx - m_Eyex ;
991 dy = m_Aty - m_Eyey ;
992 dz = m_Atz - m_Eyez ;
994 m_Focus = sqrt ( dx * dx + dy * dy + dz * dz ) ;
995 m_dAngle = myPView->Angle () ;
996 m_dAngle = m_dAngle * 180. / M_PI ;
998 m_Tune.m_dAngle = m_dAngle ;
999 m_Tune.m_dFocus = m_Focus ;
1000 m_Tune.UpdateData ( FALSE ) ;
1003 void CAnimationView3D::SetDimensions()
1006 CAnimationDoc* pDoc = GetDocument();
1008 myView->SetImmediateUpdate ( Standard_False ) ;
1010 m_Atx = ( pDoc->m_Xmin + pDoc->m_Xmax ) / 2. ;
1011 m_Aty = ( pDoc->m_Ymin + pDoc->m_Ymax ) / 2. ;
1012 m_Atz = ( pDoc->m_Zmin + pDoc->m_Zmax ) / 2. ;
1013 m_Eyex = pDoc->m_Xmax ;
1014 m_Eyey = pDoc->m_Ymax ;
1015 m_Eyez = pDoc->m_Zmax ;
1017 myView->SetAt ( m_Atx , m_Aty , m_Atz ) ;
1018 myView->SetEye ( m_Eyex , m_Eyey , m_Eyez ) ;
1019 myView->SetTwist (0.) ;
1021 myView->SetImmediateUpdate ( Standard_False ) ;
1023 myView->SetImmediateUpdate ( Standard_False ) ;
1026 myView->SetImmediateUpdate ( Standard_True ) ;
1032 void CAnimationView3D::OnViewDisplaystatus()
1034 // TODO: Add your command handler code here
1036 if ( m_Tune.IsWindowVisible () ) {
1040 m_Tune.ShowWindow ( SW_SHOWNORMAL ) ;
1044 void CAnimationView3D::OnUpdateViewDisplaystatus(CCmdUI* pCmdUI)
1046 // TODO: Add your command update UI handler code here
1048 if ( m_Tune.IsWindowVisible () ) {
1049 pCmdUI->SetCheck ( 1 ) ;
1052 pCmdUI->SetCheck ( 0 ) ;