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(Graphic3d_WNTGraphicDevice) theGraphicDevice =
156 ((CAnimationApp*)AfxGetApp())->GetGraphicDevice();
158 Handle(WNT_Window) aWNTWindow = new WNT_Window(theGraphicDevice,GetSafeHwnd ());
159 myView->SetWindow(aWNTWindow);
160 if (!aWNTWindow->IsMapped()) aWNTWindow->Map();
162 // store the mode ( nothing , dynamic zooming, dynamic ... )
163 myCurrentMode = CurrentAction3d_Nothing;
164 CFrameWnd* pParentFrm = GetParentFrame();
165 pParentFrm->ActivateFrame(SW_SHOWMAXIMIZED);
167 Standard_Integer w=100 , h=100 ; /* Debug Matrox */
168 aWNTWindow->Size (w,h) ; /* Keeps me unsatisfied (rlb)..... */
169 /* Resize is not supposed to be done on */
171 /* I suspect another problem elsewhere */
172 ::PostMessage ( GetSafeHwnd () , WM_SIZE , SIZE_RESTORED , w + h*65536 ) ;
174 myPView = Handle(V3d_PerspectiveView)::DownCast (myView);
176 m_Tune.Create ( IDD_TUNE , NULL ) ;
179 m_Tune.GetWindowRect(&dlgrect);
180 LONG width = dlgrect.right-dlgrect.left;
181 LONG height = dlgrect.bottom-dlgrect.top;
183 AfxGetApp()->m_pMainWnd->GetWindowRect(&MainWndRect);
184 LONG left = MainWndRect.left+3;
185 LONG top = MainWndRect.top + 112;
186 m_Tune.MoveWindow(left,top,width,height);
188 m_Tune.m_pView = this ;
190 m_Tune.ShowWindow ( SW_HIDE );
192 // store the mode ( nothing , dynamic zooming, dynamic ... )
194 myCurrentMode = CurrentAction3d_Nothing;
200 void CAnimationView3D::DisplayTuneDialog()
202 m_Tune.Create ( IDD_TUNE , NULL ) ;
205 m_Tune.GetWindowRect(&dlgrect);
206 LONG width = dlgrect.right-dlgrect.left;
207 LONG height = dlgrect.bottom-dlgrect.top;
209 AfxGetApp()->m_pMainWnd->GetWindowRect(&MainWndRect);
210 LONG left = MainWndRect.left+3;
211 LONG top = MainWndRect.top + 112;
212 m_Tune.MoveWindow(left,top,width,height);
214 m_Tune.m_pView = this ;
218 /////////////////////////////////////////////////////////////////////////////
219 // CAnimationView3D diagnostics
222 void CAnimationView3D::AssertValid() const
224 CView::AssertValid();
227 void CAnimationView3D::Dump(CDumpContext& dc) const
232 CAnimationDoc* CAnimationView3D::GetDocument() // non-debug version is inline
234 ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CAnimationDoc)));
235 return (CAnimationDoc*)m_pDocument;
239 /////////////////////////////////////////////////////////////////////////////
240 // CAnimationView3D message handlers
241 void CAnimationView3D::OnFileExportImage()
243 CFileDialog dlg(FALSE,_T("*.BMP"),NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
244 _T("BMP Files (*.BMP)|*.bmp |GIF Files (*.GIF)|*.gif | XWD Files (*.XWD)|*.xwd||"),
247 if (dlg.DoModal() == IDOK)
249 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
250 CString filename = dlg.GetPathName();
251 Handle(Aspect_Window) anAspectWindow = myView->Window();
252 Handle(WNT_Window) aWNTWindow = Handle(WNT_Window)::DownCast(anAspectWindow);
253 CString ext = dlg.GetFileExt();
254 if (ext == "bmp") aWNTWindow->SetOutputFormat ( WNT_TOI_BMP );
255 if (ext == "gif") aWNTWindow->SetOutputFormat ( WNT_TOI_GIF );
256 if (ext == "xwd") aWNTWindow->SetOutputFormat ( WNT_TOI_XWD );
257 aWNTWindow->Dump ((Standard_CString)(LPCTSTR)filename);
258 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
262 void CAnimationView3D::OnSize(UINT nType, int cx, int cy)
266 if (!myView.IsNull())
267 myView->MustBeResized();
270 void CAnimationView3D::OnBUTTONBack()
271 { myView->SetProj(V3d_Xneg); } // See the back View
272 void CAnimationView3D::OnBUTTONFront()
273 { myView->SetProj(V3d_Xpos); } // See the front View
275 void CAnimationView3D::OnBUTTONBottom()
276 { myView->SetProj(V3d_Zneg); } // See the bottom View
277 void CAnimationView3D::OnBUTTONTop()
278 { myView->SetProj(V3d_Zpos); } // See the top View
280 void CAnimationView3D::OnBUTTONLeft()
281 { myView->SetProj(V3d_Ypos); } // See the left View
282 void CAnimationView3D::OnBUTTONRight()
283 { myView->SetProj(V3d_Yneg); } // See the right View
285 void CAnimationView3D::OnBUTTONAxo()
286 { myView->SetProj(V3d_XposYnegZpos); } // See the axonometric View
288 void CAnimationView3D::OnBUTTONHlrOff()
290 myView->SetDegenerateModeOn();
291 myDegenerateModeIsOn = Standard_True;
294 void CAnimationView3D::OnBUTTONHlrOn()
296 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
297 myView->SetDegenerateModeOff();
298 myDegenerateModeIsOn = Standard_False;
299 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
302 void CAnimationView3D::OnBUTTONPan()
304 myCurrentMode = CurrentAction3d_DynamicPanning;
307 void CAnimationView3D::OnBUTTONPanGlo()
309 // save the current zoom value
310 myCurZoom = myView->Scale();
314 myCurrentMode = CurrentAction3d_GlobalPanning;
317 void CAnimationView3D::OnBUTTONReset()
322 void CAnimationView3D::OnBUTTONRot()
323 { myCurrentMode = CurrentAction3d_DynamicRotation; }
326 void CAnimationView3D::OnBUTTONZoomAll()
333 void CAnimationView3D::OnBUTTONZoomProg()
334 { myCurrentMode = CurrentAction3d_DynamicZooming; }
336 void CAnimationView3D::OnBUTTONZoomWin()
337 { myCurrentMode = CurrentAction3d_WindowZooming; }
339 void CAnimationView3D::OnBUTTONFly()
340 { myCurrentMode = CurrentAction3d_Fly; }
342 void CAnimationView3D::OnBUTTONTurn()
343 { myCurrentMode = CurrentAction3d_Turn; }
346 void CAnimationView3D::OnLButtonDown(UINT nFlags, CPoint point)
348 // save the current mouse coordinate in min
349 myXmin=point.x; myYmin=point.y;
350 myXmax=point.x; myYmax=point.y;
352 if ( nFlags & MK_CONTROL )
354 // Button MB1 down Control :start zomming
355 // SetCursor(AfxGetApp()->LoadStandardCursor());
359 switch (myCurrentMode)
361 case CurrentAction3d_Nothing : // start a drag
362 if (nFlags & MK_SHIFT)
363 GetDocument()->ShiftDragEvent(myXmax,myYmax,-1,myView);
365 GetDocument()->DragEvent(myXmax,myYmax,-1,myView);
368 case CurrentAction3d_DynamicZooming : // noting
369 // SetCursor(AfxGetApp()->LoadStandardCursor());
371 case CurrentAction3d_WindowZooming : // noting
373 case CurrentAction3d_DynamicPanning :// noting
375 case CurrentAction3d_GlobalPanning :// noting
377 case CurrentAction3d_DynamicRotation :
378 if (!myDegenerateModeIsOn)
379 myView->SetDegenerateModeOn();
380 myView->StartRotation(point.x,point.y);
382 case CurrentAction3d_Fly :
384 SetTimer ( 1 , 100 , NULL ) ;
386 case CurrentAction3d_Turn :
388 SetTimer ( 1 , 100 , NULL ) ;
391 Standard_Failure::Raise(" incompatible Current Mode ");
397 void CAnimationView3D::OnLButtonUp(UINT nFlags, CPoint point)
399 if ( nFlags & MK_CONTROL )
405 switch (myCurrentMode)
407 case CurrentAction3d_Nothing :
408 if (point.x == myXmin && point.y == myYmin)
409 { // no offset between down and up --> selectEvent
412 if (nFlags & MK_SHIFT )
413 GetDocument()->ShiftInputEvent(point.x,point.y,myView);
415 GetDocument()->InputEvent (point.x,point.y,myView);
418 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False);
421 if (nFlags & MK_SHIFT)
422 GetDocument()->ShiftDragEvent(point.x,point.y,1,myView);
424 GetDocument()->DragEvent(point.x,point.y,1,myView);
427 case CurrentAction3d_DynamicZooming :
428 // SetCursor(AfxGetApp()->LoadStandardCursor());
429 myCurrentMode = CurrentAction3d_Nothing;
431 case CurrentAction3d_WindowZooming :
432 myXmax=point.x; myYmax=point.y;
433 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False,LongDash);
434 if ((abs(myXmin-myXmax)>ValZWMin) || (abs(myYmin-myYmax)>ValZWMin))
435 // Test if the zoom window is greater than a minimale window.
437 // Do the zoom window between Pmin and Pmax
438 myView->WindowFitAll(myXmin,myYmin,myXmax,myYmax);
440 myCurrentMode = CurrentAction3d_Nothing;
442 case CurrentAction3d_DynamicPanning :
443 myCurrentMode = CurrentAction3d_Nothing;
445 case CurrentAction3d_GlobalPanning :
446 myView->Place(point.x,point.y,myCurZoom);
447 myCurrentMode = CurrentAction3d_Nothing;
449 case CurrentAction3d_DynamicRotation :
450 myCurrentMode = CurrentAction3d_Nothing;
452 case CurrentAction3d_Fly :
454 case CurrentAction3d_Turn :
458 Standard_Failure::Raise(" incompatible Current Mode ");
460 } //switch (myCurrentMode)
461 } // else // if ( Ctrl )
464 void CAnimationView3D::OnMButtonDown(UINT nFlags, CPoint point)
466 if ( nFlags & MK_CONTROL )
468 // Button MB2 down Control : panning init
469 // SetCursor(AfxGetApp()->LoadStandardCursor());
473 void CAnimationView3D::OnMButtonUp(UINT nFlags, CPoint point)
475 if ( nFlags & MK_CONTROL )
477 // Button MB2 down Control : panning init
478 // SetCursor(AfxGetApp()->LoadStandardCursor());
482 void CAnimationView3D::OnRButtonDown(UINT nFlags, CPoint point)
484 if ( nFlags & MK_CONTROL )
486 // SetCursor(AfxGetApp()->LoadStandardCursor());
487 if (!myDegenerateModeIsOn)
488 myView->SetDegenerateModeOn();
489 myView->StartRotation(point.x,point.y);
493 GetDocument()->Popup(point.x,point.y,myView);
497 void CAnimationView3D::OnRButtonUp(UINT nFlags, CPoint point)
499 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
500 if (!myDegenerateModeIsOn)
502 myView->SetDegenerateModeOff();
503 myDegenerateModeIsOn = Standard_False;
506 myView->SetDegenerateModeOn();
507 myDegenerateModeIsOn = Standard_True;
509 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
512 void CAnimationView3D::OnMouseMove(UINT nFlags, CPoint point)
514 // ============================ LEFT BUTTON =======================
518 if ( nFlags & MK_LBUTTON)
520 if ( nFlags & MK_CONTROL )
522 // move with MB1 and Control : on the dynamic zooming
523 // Do the zoom in function of mouse's coordinates
524 myView->Zoom(myXmax,myYmax,point.x,point.y);
525 // save the current mouse coordinate in min
531 switch (myCurrentMode)
533 case CurrentAction3d_Nothing :
534 myXmax = point.x; myYmax = point.y;
535 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False);
536 if (nFlags & MK_SHIFT)
537 GetDocument()->ShiftDragEvent(myXmax,myYmax,0,myView);
539 GetDocument()->DragEvent(myXmax,myYmax,0,myView);
540 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_True);
542 case CurrentAction3d_DynamicZooming :
543 myView->Zoom(myXmax,myYmax,point.x,point.y);
544 // save the current mouse coordinate in min \n";
545 myXmax=point.x; myYmax=point.y;
547 case CurrentAction3d_WindowZooming :
548 myXmax = point.x; myYmax = point.y;
549 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False,LongDash);
550 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_True,LongDash);
552 case CurrentAction3d_DynamicPanning :
553 myView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
554 myXmax = point.x; myYmax = point.y;
556 case CurrentAction3d_GlobalPanning : // nothing
558 case CurrentAction3d_DynamicRotation :
559 myView->Rotation(point.x,point.y);
562 case CurrentAction3d_Fly :
564 case CurrentAction3d_Turn :
567 Standard_Failure::Raise(" incompatible Current Mode ");
569 }// switch (myCurrentMode)
570 }// if ( nFlags & MK_CONTROL ) else
571 } else // if ( nFlags & MK_LBUTTON)
572 // ============================ MIDDLE BUTTON =======================
573 if ( nFlags & MK_MBUTTON)
575 if ( nFlags & MK_CONTROL )
577 myView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
578 myXmax = point.x; myYmax = point.y;
581 } else // if ( nFlags & MK_MBUTTON)
582 // ============================ RIGHT BUTTON =======================
583 if ( nFlags & MK_RBUTTON)
585 if ( nFlags & MK_CONTROL )
588 myView->Rotation(point.x,point.y);
590 }else //if ( nFlags & MK_RBUTTON)
591 // ============================ NO BUTTON =======================
593 myXmax = point.x; myYmax = point.y;
594 if (nFlags & MK_SHIFT)
595 GetDocument()->ShiftMoveEvent(point.x,point.y,myView);
597 GetDocument()->MoveEvent(point.x,point.y,myView);
601 void CAnimationView3D::OnUpdateBUTTONHlrOff(CCmdUI* pCmdUI)
603 pCmdUI->SetCheck (myDegenerateModeIsOn);
604 pCmdUI->Enable (!myDegenerateModeIsOn);
607 void CAnimationView3D::OnUpdateBUTTONHlrOn(CCmdUI* pCmdUI)
609 pCmdUI->SetCheck (!myDegenerateModeIsOn);
610 pCmdUI->Enable (myDegenerateModeIsOn);
613 void CAnimationView3D::OnUpdateBUTTONPanGlo(CCmdUI* pCmdUI)
615 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_GlobalPanning);
616 pCmdUI->Enable (myCurrentMode != CurrentAction3d_GlobalPanning);
620 void CAnimationView3D::OnUpdateBUTTONPan(CCmdUI* pCmdUI)
622 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_DynamicPanning);
623 pCmdUI->Enable (myCurrentMode != CurrentAction3d_DynamicPanning );
626 void CAnimationView3D::OnUpdateBUTTONZoomProg(CCmdUI* pCmdUI)
628 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_DynamicZooming );
629 pCmdUI->Enable (myCurrentMode != CurrentAction3d_DynamicZooming);
632 void CAnimationView3D::OnUpdateBUTTONZoomWin(CCmdUI* pCmdUI)
634 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_WindowZooming);
635 pCmdUI->Enable (myCurrentMode != CurrentAction3d_WindowZooming);
638 void CAnimationView3D::OnUpdateBUTTONRot(CCmdUI* pCmdUI)
640 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_DynamicRotation);
641 pCmdUI->Enable (myCurrentMode != CurrentAction3d_DynamicRotation);
644 void CAnimationView3D::OnUpdateBUTTONFly(CCmdUI* pCmdUI)
646 pCmdUI->Enable(GetDocument()->m_bIsGridLoaded);
647 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_Fly);
650 void CAnimationView3D::OnUpdateBUTTONTurn(CCmdUI* pCmdUI)
652 pCmdUI->Enable(GetDocument()->m_bIsGridLoaded);
653 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_Turn);
656 void CAnimationView3D::OnChangeBackground()
661 myView->BackgroundColor(Quantity_TOC_RGB,R1,G1,B1);
663 m_clr = RGB(R1*255,G1*255,B1*255);
665 CColorDialog dlgColor(m_clr);
666 if (dlgColor.DoModal() == IDOK)
668 m_clr = dlgColor.GetColor();
669 R1 = GetRValue(m_clr)/255.;
670 G1 = GetGValue(m_clr)/255.;
671 B1 = GetBValue(m_clr)/255.;
672 myView->SetBackgroundColor(Quantity_TOC_RGB,R1,G1,B1);
677 //==========================================================================================
678 //==========================================================================================
679 //==========================================================================================
681 //-----------------------------------------------------------------------------------------
683 //-----------------------------------------------------------------------------------------
684 void CAnimationView3D::DrawRectangle(const Standard_Integer MinX ,
685 const Standard_Integer MinY ,
686 const Standard_Integer MaxX ,
687 const Standard_Integer MaxY ,
688 const Standard_Boolean Draw ,
689 const LineStyle aLineStyle)
691 static int m_DrawMode;
692 if (!m_Pen && aLineStyle ==Solid )
693 {m_Pen = new CPen(PS_SOLID, 1, RGB(0,0,0)); m_DrawMode = R2_MERGEPENNOT;}
694 else if (!m_Pen && aLineStyle ==Dot )
695 {m_Pen = new CPen(PS_DOT, 1, RGB(0,0,0)); m_DrawMode = R2_XORPEN;}
696 else if (!m_Pen && aLineStyle == ShortDash)
697 {m_Pen = new CPen(PS_DASH, 1, RGB(255,0,0)); m_DrawMode = R2_XORPEN;}
698 else if (!m_Pen && aLineStyle == LongDash)
699 {m_Pen = new CPen(PS_DASH, 1, RGB(0,0,0)); m_DrawMode = R2_NOTXORPEN;}
700 else if (aLineStyle == Default)
701 { m_Pen = NULL; m_DrawMode = R2_MERGEPENNOT;}
704 CClientDC clientDC(this);
705 if (m_Pen) aOldPen = clientDC.SelectObject(m_Pen);
706 clientDC.SetROP2(m_DrawMode);
708 static Standard_Integer StoredMinX, StoredMaxX, StoredMinY, StoredMaxY;
709 static Standard_Boolean m_IsVisible;
711 if ( m_IsVisible && !Draw) // move or up : erase at the old position
713 clientDC.MoveTo(StoredMinX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMaxY);
714 clientDC.LineTo(StoredMaxX,StoredMaxY);
715 clientDC.LineTo(StoredMaxX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMinY);
719 StoredMinX = min ( MinX, MaxX );
720 StoredMinY = min ( MinY, MaxY );
721 StoredMaxX = max ( MinX, MaxX );
722 StoredMaxY = max ( MinY, MaxY);
724 if (Draw) // move : draw
726 clientDC.MoveTo(StoredMinX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMaxY);
727 clientDC.LineTo(StoredMaxX,StoredMaxY);
728 clientDC.LineTo(StoredMaxX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMinY);
733 clientDC.SelectObject(aOldPen);
735 void CAnimationView3D::OnStop()
737 KillTimer(GetDocument()->myCount);
740 void CAnimationView3D::OnRestart()
742 KillTimer(GetDocument()->myCount);
743 SetTimer(GetDocument()->myCount, 1 , NULL);
747 void CAnimationView3D::OnTimer(UINT nIDEvent)
749 // TODO: Add your message handler code here and/or call default
750 GetDocument()->OnMyTimer();
751 CView::OnTimer(nIDEvent);
756 /*********************************************************************************
757 ************** W A L K T H R O U G H ******************************************
758 /********************************************************************************/
760 void CAnimationView3D::OnTimer(UINT_PTR nIDEvent)
762 if ( !GetDocument()->m_bIsGridLoaded )
764 // TODO: Add your message handler code here and/or call default
765 GetDocument()->OnMyTimer();
766 CView::OnTimer(nIDEvent);
770 CView::OnTimer(nIDEvent);
771 if ( nIDEvent == 1 ) {
772 myView->SetImmediateUpdate ( Standard_False ) ;
773 if ( myCurrentMode == CurrentAction3d_Fly ) {
775 Fly ( m_curx , m_cury ) ;
777 Roll ( m_curx , m_cury ) ;
779 Turn ( m_curx , m_cury ) ;
781 myView->SetAt ( m_Atx , m_Aty , m_Atz ) ;
782 myView->SetEye ( m_Eyex , m_Eyey , m_Eyez ) ;
785 else if ( myCurrentMode == CurrentAction3d_Turn ) {
786 Twist ( m_curx , m_cury ) ;
792 myView->SetImmediateUpdate ( Standard_True ) ;
801 void CAnimationView3D::OnSensitivity()
805 dial.m_SensFly = m_FlySens ;
806 dial.m_SensTurn = m_TurnSens ;
807 if ( dial.DoModal () ) {
808 m_FlySens = dial.m_SensFly ;
809 m_TurnSens = dial.m_SensTurn ;
813 void CAnimationView3D::Fly (int x , int y)
820 sens = (double) myYmin - (double) y ;
821 sens /= (double) m_cy ;
824 v [0] = m_Atx - m_Eyex ;
825 v [1] = m_Aty - m_Eyey ;
826 v [2] = m_Atz - m_Eyez ;
827 l = sqrt ( v[0]*v[0] + v[1]*v[1] + v[2]*v[2] ) ;
829 for ( i=0 ; i<3 ; i++ )
830 v [i] = v [i] / l * sens ;
845 void CAnimationView3D::Turn (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 ;
866 gp_Vec haut = vert ^ reg ;
871 reg.Rotate (rot,sens) ;
873 reg.Coord ( aX , aY , aZ ) ;
875 m_Atx = m_Eyex + aX ;
876 m_Aty = m_Eyey + aY ;
877 m_Atz = m_Eyez + aZ ;
880 void CAnimationView3D::Roll (int x , int y)
882 gp_Vec z (0.,0.,1.) ;
886 double aX , aY , aZ ;
888 sens = (double) x - (double) myXmin ;
889 sens /= (double) m_cx ;
892 v [0] = m_Atx - m_Eyex ;
893 v [1] = m_Aty - m_Eyey ;
894 v [2] = m_Atz - m_Eyez ;
896 gp_Pnt eye ( m_Eyex , m_Eyey , m_Eyez ) ;
898 gp_Vec reg (v[0],v[1],v[2] );
900 gp_Vec vert = reg ^ z ;
905 reg.Rotate (rot,sens) ;
907 reg.Coord ( aX , aY , aZ ) ;
909 m_Atx = m_Eyex + aX ;
910 m_Aty = m_Eyey + aY ;
911 m_Atz = m_Eyez + aZ ;
914 void CAnimationView3D::Twist (int x , int y)
919 a = myView->Twist () ;
921 sens = (double) x - (double) myXmin ;
922 sens /= (double) m_cx ;
927 myView->SetTwist (a) ;
930 void CAnimationView3D::SetFocal(double dFocus,double dAngle)
936 v [0] = m_Atx - m_Eyex ;
937 v [1] = m_Aty - m_Eyey ;
938 v [2] = m_Atz - m_Eyez ;
940 l = sqrt ( v[0]*v[0] + v[1]*v[1] + v[2]*v[2] ) ;
942 for ( i=0 ; i<3 ; i++ )
943 v [i] = v [i] / l * dFocus ;
947 m_Atx = v [0] + m_Eyex ;
948 m_Aty = v [1] + m_Eyey ;
949 m_Atz = v [2] + m_Eyez ;
951 myView->SetImmediateUpdate ( Standard_False ) ;
952 myView->SetAt ( m_Atx , m_Aty , m_Atz ) ;
954 dAngle = dAngle * M_PI / 180. ;
955 myPView->SetAngle ( dAngle ) ;
956 dAngle = myPView->Angle () ;
958 myView->SetImmediateUpdate ( Standard_True ) ;
963 void CAnimationView3D::ReloadData()
968 myView->At ( m_Atx , m_Aty , m_Atz ) ;
969 myView->Eye ( m_Eyex , m_Eyey , m_Eyez ) ;
971 dTwist = myView->Twist () ;
972 dTwist = dTwist * 180. / M_PI ;
974 sprintf_s ( szMsg , "%lf" , m_Atx ) ;
975 (m_Tune.GetDlgItem ( IDC_XAT ))->SetWindowText ( szMsg ) ;
976 sprintf_s ( szMsg , "%lf" , m_Aty ) ;
977 (m_Tune.GetDlgItem ( IDC_YAT ))->SetWindowText ( szMsg ) ;
978 sprintf_s ( szMsg , "%lf" , m_Atz ) ;
979 (m_Tune.GetDlgItem ( IDC_ZAT ))->SetWindowText ( szMsg ) ;
981 sprintf_s ( szMsg , "%lf" , m_Eyex ) ;
982 (m_Tune.GetDlgItem ( IDC_XEYE ))->SetWindowText ( szMsg ) ;
983 sprintf_s ( szMsg , "%lf" , m_Eyey ) ;
984 (m_Tune.GetDlgItem ( IDC_YEYE ))->SetWindowText ( szMsg ) ;
985 sprintf_s ( szMsg , "%lf" , m_Eyez ) ;
986 (m_Tune.GetDlgItem ( IDC_ZEYE ))->SetWindowText ( szMsg ) ;
988 sprintf_s ( szMsg , "%lf" , dTwist ) ;
989 (m_Tune.GetDlgItem ( IDC_TWIST ))->SetWindowText ( szMsg ) ;
992 dx = m_Atx - m_Eyex ;
993 dy = m_Aty - m_Eyey ;
994 dz = m_Atz - m_Eyez ;
996 m_Focus = sqrt ( dx * dx + dy * dy + dz * dz ) ;
997 m_dAngle = myPView->Angle () ;
998 m_dAngle = m_dAngle * 180. / M_PI ;
1000 m_Tune.m_dAngle = m_dAngle ;
1001 m_Tune.m_dFocus = m_Focus ;
1002 m_Tune.UpdateData ( FALSE ) ;
1005 void CAnimationView3D::SetDimensions()
1008 CAnimationDoc* pDoc = GetDocument();
1010 myView->SetImmediateUpdate ( Standard_False ) ;
1012 m_Atx = ( pDoc->m_Xmin + pDoc->m_Xmax ) / 2. ;
1013 m_Aty = ( pDoc->m_Ymin + pDoc->m_Ymax ) / 2. ;
1014 m_Atz = ( pDoc->m_Zmin + pDoc->m_Zmax ) / 2. ;
1015 m_Eyex = pDoc->m_Xmax ;
1016 m_Eyey = pDoc->m_Ymax ;
1017 m_Eyez = pDoc->m_Zmax ;
1019 myView->SetAt ( m_Atx , m_Aty , m_Atz ) ;
1020 myView->SetEye ( m_Eyex , m_Eyey , m_Eyez ) ;
1021 myView->SetTwist (0.) ;
1023 myView->SetImmediateUpdate ( Standard_False ) ;
1025 myView->SetImmediateUpdate ( Standard_False ) ;
1028 myView->SetImmediateUpdate ( Standard_True ) ;
1034 void CAnimationView3D::OnViewDisplaystatus()
1036 // TODO: Add your command handler code here
1038 if ( m_Tune.IsWindowVisible () ) {
1042 m_Tune.ShowWindow ( SW_SHOWNORMAL ) ;
1046 void CAnimationView3D::OnUpdateViewDisplaystatus(CCmdUI* pCmdUI)
1048 // TODO: Add your command update UI handler code here
1050 if ( m_Tune.IsWindowVisible () ) {
1051 pCmdUI->SetCheck ( 1 ) ;
1054 pCmdUI->SetCheck ( 0 ) ;