0023712: Remove dependency on Aspect_GraphicDevice from Aspect_Window
[occt.git] / samples / mfc / standard / 09_Animation / src / AnimationView3D.cpp
CommitLineData
7fd59977 1// AnimationView3D.cpp : implementation of the CAnimationView3D class
2//
3
4#include "stdafx.h"
5
6#include "AnimationView3D.h"
7
8#include "AnimationApp.h"
9#include "ShadingDialog.h"
10#include "AnimationDoc.h"
11
12#include "Sensitivity.h"
13
14#ifdef _DEBUG
15//#define new DEBUG_NEW by CasCade
16#undef THIS_FILE
17static char THIS_FILE[] = __FILE__;
18#endif
19static int rotCount = 0;
20
21// for elastic bean selection
22#define ValZWMin 1
23
24
25/////////////////////////////////////////////////////////////////////////////
26// CAnimationView3D
27
28IMPLEMENT_DYNCREATE(CAnimationView3D, CView)
29
30BEGIN_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)
47 ON_WM_SIZE()
48 ON_COMMAND(ID_BUTTONZoomProg, OnBUTTONZoomProg)
49 ON_COMMAND(ID_BUTTONZoomWin, OnBUTTONZoomWin)
50 ON_WM_LBUTTONDOWN()
51 ON_WM_LBUTTONUP()
52 ON_WM_MBUTTONDOWN()
53 ON_WM_MBUTTONUP()
54 ON_WM_MOUSEMOVE()
55 ON_WM_RBUTTONDOWN()
56 ON_WM_RBUTTONUP()
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)
64
65 ON_COMMAND(ID_Modify_ChangeBackground , OnChangeBackground)
66 ON_WM_TIMER()
67 ON_COMMAND(ID_STOP, OnStop)
68 ON_COMMAND(ID_RESTART, OnRestart)
69
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)
77 //}}AFX_MSG_MAP
78// CasCade
79
80END_MESSAGE_MAP()
81
82/////////////////////////////////////////////////////////////////////////////
83// CAnimationView3D construction/destruction
84
85CAnimationView3D::CAnimationView3D()
86{
87 // TODO: add construction code here
88
89 myXmin=0;
90 myYmin=0;
91 myXmax=0;
92 myYmax=0;
93 myCurZoom=0;
94 // will be set in OnInitial update, but, for more security :
95 myCurrentMode = CurrentAction3d_Nothing;
96 myDegenerateModeIsOn=Standard_True;
97 m_Pen = NULL;
98
99 myXmin=0;
100 myYmin=0;
101 myXmax=0;
102 myYmax=0;
103 myCurZoom=0;
104
105 // will be set in OnInitial update, but, for more security :
106 m_FlySens = 500. ;
42e4630c 107 m_TurnSens = M_PI / 40. ;
7fd59977 108}
109
110CAnimationView3D::~CAnimationView3D()
111{
112 myView->Remove();
113 if (m_Pen) delete m_Pen;
114}
115
116BOOL CAnimationView3D::PreCreateWindow(CREATESTRUCT& cs)
117{
118 // TODO: Modify the Window class or styles here by modifying
119 // the CREATESTRUCT cs
120
121 return CView::PreCreateWindow(cs);
122}
123
124/////////////////////////////////////////////////////////////////////////////
125// CAnimationView3D drawing
126
127void CAnimationView3D::OnDraw(CDC* pDC)
128{
129 CAnimationDoc* pDoc = GetDocument();
130 ASSERT_VALID(pDoc);
131
132 // TODO: add draw code for native data here
133
134 myView->Redraw();
135
136}
137void CAnimationView3D::OnInitialUpdate()
138{
139 CView::OnInitialUpdate();
140
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();
144
145 Handle(V3d_Viewer) aViewer ;
146
147 aViewer = GetDocument()->GetViewer() ;
148 aViewer->DefaultPerspectiveView () ;
149 aViewer->SetDefaultTypeOfView ( V3d_PERSPECTIVE ) ;
150 myView = aViewer->CreateView();
151
152 // store for restore state after rotation (witch is in Degenerated mode)
153 myDegenerateModeIsOn = myView->DegenerateModeIsOn();
154
dc3fe572 155 Handle(WNT_Window) aWNTWindow = new WNT_Window(GetSafeHwnd ());
7fd59977 156 myView->SetWindow(aWNTWindow);
157 if (!aWNTWindow->IsMapped()) aWNTWindow->Map();
158
159 // store the mode ( nothing , dynamic zooming, dynamic ... )
160 myCurrentMode = CurrentAction3d_Nothing;
161 CFrameWnd* pParentFrm = GetParentFrame();
162 pParentFrm->ActivateFrame(SW_SHOWMAXIMIZED);
163
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 */
167 /* Matrox */
168 /* I suspect another problem elsewhere */
169 ::PostMessage ( GetSafeHwnd () , WM_SIZE , SIZE_RESTORED , w + h*65536 ) ;
170
171 myPView = Handle(V3d_PerspectiveView)::DownCast (myView);
172
173 m_Tune.Create ( IDD_TUNE , NULL ) ;
174
175 RECT dlgrect;
176 m_Tune.GetWindowRect(&dlgrect);
177 LONG width = dlgrect.right-dlgrect.left;
178 LONG height = dlgrect.bottom-dlgrect.top;
179 RECT MainWndRect;
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);
184
185 m_Tune.m_pView = this ;
186
187 m_Tune.ShowWindow ( SW_HIDE );
188
189 // store the mode ( nothing , dynamic zooming, dynamic ... )
190
191 myCurrentMode = CurrentAction3d_Nothing;
192
193 ReloadData () ;
194
195}
196
197void CAnimationView3D::DisplayTuneDialog()
198{
199 m_Tune.Create ( IDD_TUNE , NULL ) ;
200
201 RECT dlgrect;
202 m_Tune.GetWindowRect(&dlgrect);
203 LONG width = dlgrect.right-dlgrect.left;
204 LONG height = dlgrect.bottom-dlgrect.top;
205 RECT MainWndRect;
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);
210
211 m_Tune.m_pView = this ;
212}
213
214
215/////////////////////////////////////////////////////////////////////////////
216// CAnimationView3D diagnostics
217
218#ifdef _DEBUG
219void CAnimationView3D::AssertValid() const
220{
221 CView::AssertValid();
222}
223
224void CAnimationView3D::Dump(CDumpContext& dc) const
225{
226 CView::Dump(dc);
227}
228
229CAnimationDoc* CAnimationView3D::GetDocument() // non-debug version is inline
230{
231 ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CAnimationDoc)));
232 return (CAnimationDoc*)m_pDocument;
233}
234#endif //_DEBUG
235
236/////////////////////////////////////////////////////////////////////////////
237// CAnimationView3D message handlers
238void CAnimationView3D::OnFileExportImage()
239{
240 CFileDialog dlg(FALSE,_T("*.BMP"),NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
3994ec41 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||"),
7fd59977 244 NULL );
245
246 if (dlg.DoModal() == IDOK)
247 {
248 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
3994ec41 249 CString aFileName = dlg.GetPathName();
250 myView->Dump(aFileName);
7fd59977 251 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
252 }
253}
254
255void CAnimationView3D::OnSize(UINT nType, int cx, int cy)
256{
257 m_cx = cx ;
258 m_cy = cy ;
259 if (!myView.IsNull())
260 myView->MustBeResized();
261}
262
263void CAnimationView3D::OnBUTTONBack()
264{ myView->SetProj(V3d_Xneg); } // See the back View
265void CAnimationView3D::OnBUTTONFront()
266{ myView->SetProj(V3d_Xpos); } // See the front View
267
268void CAnimationView3D::OnBUTTONBottom()
269{ myView->SetProj(V3d_Zneg); } // See the bottom View
270void CAnimationView3D::OnBUTTONTop()
271{ myView->SetProj(V3d_Zpos); } // See the top View
272
273void CAnimationView3D::OnBUTTONLeft()
274{ myView->SetProj(V3d_Ypos); } // See the left View
275void CAnimationView3D::OnBUTTONRight()
276{ myView->SetProj(V3d_Yneg); } // See the right View
277
278void CAnimationView3D::OnBUTTONAxo()
279{ myView->SetProj(V3d_XposYnegZpos); } // See the axonometric View
280
281void CAnimationView3D::OnBUTTONHlrOff()
282{
283 myView->SetDegenerateModeOn();
284 myDegenerateModeIsOn = Standard_True;
285}
286
287void CAnimationView3D::OnBUTTONHlrOn()
288{
289 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
290 myView->SetDegenerateModeOff();
291 myDegenerateModeIsOn = Standard_False;
292 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
293}
294
295void CAnimationView3D::OnBUTTONPan()
296{
297 myCurrentMode = CurrentAction3d_DynamicPanning;
298}
299
300void CAnimationView3D::OnBUTTONPanGlo()
301{
302 // save the current zoom value
303 myCurZoom = myView->Scale();
304 // Do a Global Zoom
305 myView->FitAll();
306 // Set the mode
307 myCurrentMode = CurrentAction3d_GlobalPanning;
308}
309
310void CAnimationView3D::OnBUTTONReset()
311{ myView->Reset();
312 ReloadData();
313}
314
315void CAnimationView3D::OnBUTTONRot()
316{ myCurrentMode = CurrentAction3d_DynamicRotation; }
317
318
319void CAnimationView3D::OnBUTTONZoomAll()
320{
321 SetDimensions();
322 myView->FitAll();
323 myView->ZFitAll();
324}
325
326void CAnimationView3D::OnBUTTONZoomProg()
327{ myCurrentMode = CurrentAction3d_DynamicZooming; }
328
329void CAnimationView3D::OnBUTTONZoomWin()
330{ myCurrentMode = CurrentAction3d_WindowZooming; }
331
332void CAnimationView3D::OnBUTTONFly()
333{ myCurrentMode = CurrentAction3d_Fly; }
334
335void CAnimationView3D::OnBUTTONTurn()
336{ myCurrentMode = CurrentAction3d_Turn; }
337
338
339void CAnimationView3D::OnLButtonDown(UINT nFlags, CPoint point)
340{
341 // save the current mouse coordinate in min
342 myXmin=point.x; myYmin=point.y;
343 myXmax=point.x; myYmax=point.y;
344
345 if ( nFlags & MK_CONTROL )
346 {
347 // Button MB1 down Control :start zomming
348 // SetCursor(AfxGetApp()->LoadStandardCursor());
349 }
350 else // if ( Ctrl )
351 {
352 switch (myCurrentMode)
353 {
354 case CurrentAction3d_Nothing : // start a drag
355 if (nFlags & MK_SHIFT)
356 GetDocument()->ShiftDragEvent(myXmax,myYmax,-1,myView);
357 else
358 GetDocument()->DragEvent(myXmax,myYmax,-1,myView);
359 break;
360 break;
361 case CurrentAction3d_DynamicZooming : // noting
362 // SetCursor(AfxGetApp()->LoadStandardCursor());
363 break;
364 case CurrentAction3d_WindowZooming : // noting
365 break;
366 case CurrentAction3d_DynamicPanning :// noting
367 break;
368 case CurrentAction3d_GlobalPanning :// noting
369 break;
370 case CurrentAction3d_DynamicRotation :
371 if (!myDegenerateModeIsOn)
372 myView->SetDegenerateModeOn();
373 myView->StartRotation(point.x,point.y);
374 break;
375 case CurrentAction3d_Fly :
376 KillTimer (1) ;
377 SetTimer ( 1 , 100 , NULL ) ;
378 break ;
379 case CurrentAction3d_Turn :
380 KillTimer (1) ;
381 SetTimer ( 1 , 100 , NULL ) ;
382 break ;
383 default :
384 Standard_Failure::Raise(" incompatible Current Mode ");
385 break;
386 }
387 }
388}
389
390void CAnimationView3D::OnLButtonUp(UINT nFlags, CPoint point)
391{
392 if ( nFlags & MK_CONTROL )
393 {
394 return;
395 }
396 else // if ( Ctrl )
397 {
398 switch (myCurrentMode)
399 {
400 case CurrentAction3d_Nothing :
401 if (point.x == myXmin && point.y == myYmin)
402 { // no offset between down and up --> selectEvent
403 myXmax=point.x;
404 myYmax=point.y;
405 if (nFlags & MK_SHIFT )
406 GetDocument()->ShiftInputEvent(point.x,point.y,myView);
407 else
408 GetDocument()->InputEvent (point.x,point.y,myView);
409 } else
410 {
411 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False);
412 myXmax=point.x;
413 myYmax=point.y;
414 if (nFlags & MK_SHIFT)
415 GetDocument()->ShiftDragEvent(point.x,point.y,1,myView);
416 else
417 GetDocument()->DragEvent(point.x,point.y,1,myView);
418 }
419 break;
420 case CurrentAction3d_DynamicZooming :
421 // SetCursor(AfxGetApp()->LoadStandardCursor());
422 myCurrentMode = CurrentAction3d_Nothing;
423 break;
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.
429 {
430 // Do the zoom window between Pmin and Pmax
431 myView->WindowFitAll(myXmin,myYmin,myXmax,myYmax);
432 }
433 myCurrentMode = CurrentAction3d_Nothing;
434 break;
435 case CurrentAction3d_DynamicPanning :
436 myCurrentMode = CurrentAction3d_Nothing;
437 break;
438 case CurrentAction3d_GlobalPanning :
439 myView->Place(point.x,point.y,myCurZoom);
440 myCurrentMode = CurrentAction3d_Nothing;
441 break;
442 case CurrentAction3d_DynamicRotation :
443 myCurrentMode = CurrentAction3d_Nothing;
444 break;
445 case CurrentAction3d_Fly :
446 KillTimer ( 1 ) ;
447 case CurrentAction3d_Turn :
448 KillTimer ( 1 ) ;
449 break;
450 default :
451 Standard_Failure::Raise(" incompatible Current Mode ");
452 break;
453 } //switch (myCurrentMode)
454 } // else // if ( Ctrl )
455}
456
457void CAnimationView3D::OnMButtonDown(UINT nFlags, CPoint point)
458{
459 if ( nFlags & MK_CONTROL )
460 {
461 // Button MB2 down Control : panning init
462 // SetCursor(AfxGetApp()->LoadStandardCursor());
463 }
464}
465
466void CAnimationView3D::OnMButtonUp(UINT nFlags, CPoint point)
467{
468 if ( nFlags & MK_CONTROL )
469 {
470 // Button MB2 down Control : panning init
471 // SetCursor(AfxGetApp()->LoadStandardCursor());
472 }
473}
474
475void CAnimationView3D::OnRButtonDown(UINT nFlags, CPoint point)
476{
477 if ( nFlags & MK_CONTROL )
478 {
479 // SetCursor(AfxGetApp()->LoadStandardCursor());
480 if (!myDegenerateModeIsOn)
481 myView->SetDegenerateModeOn();
482 myView->StartRotation(point.x,point.y);
483 }
484 else // if ( Ctrl )
485 {
486 GetDocument()->Popup(point.x,point.y,myView);
487 }
488}
489
490void CAnimationView3D::OnRButtonUp(UINT nFlags, CPoint point)
491{
492 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
493 if (!myDegenerateModeIsOn)
494 {
495 myView->SetDegenerateModeOff();
496 myDegenerateModeIsOn = Standard_False;
497 } else
498 {
499 myView->SetDegenerateModeOn();
500 myDegenerateModeIsOn = Standard_True;
501 }
502 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
503}
504
505void CAnimationView3D::OnMouseMove(UINT nFlags, CPoint point)
506{
507 // ============================ LEFT BUTTON =======================
508 m_curx = point.x ;
509 m_cury = point.y ;
510
511 if ( nFlags & MK_LBUTTON)
512 {
513 if ( nFlags & MK_CONTROL )
514 {
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
519 myXmax = point.x;
520 myYmax = point.y;
521 }
522 else // if ( Ctrl )
523 {
524 switch (myCurrentMode)
525 {
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);
531 else
532 GetDocument()->DragEvent(myXmax,myYmax,0,myView);
533 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_True);
534 break;
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;
539 break;
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);
544 break;
545 case CurrentAction3d_DynamicPanning :
546 myView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
547 myXmax = point.x; myYmax = point.y;
548 break;
549 case CurrentAction3d_GlobalPanning : // nothing
550 break;
551 case CurrentAction3d_DynamicRotation :
552 myView->Rotation(point.x,point.y);
553 myView->Redraw();
554 break;
555 case CurrentAction3d_Fly :
556 break ;
557 case CurrentAction3d_Turn :
558 break ;
559 default :
560 Standard_Failure::Raise(" incompatible Current Mode ");
561 break;
562 }// switch (myCurrentMode)
563 }// if ( nFlags & MK_CONTROL ) else
564 } else // if ( nFlags & MK_LBUTTON)
565 // ============================ MIDDLE BUTTON =======================
566 if ( nFlags & MK_MBUTTON)
567 {
568 if ( nFlags & MK_CONTROL )
569 {
570 myView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
571 myXmax = point.x; myYmax = point.y;
572
573 }
574 } else // if ( nFlags & MK_MBUTTON)
575 // ============================ RIGHT BUTTON =======================
576 if ( nFlags & MK_RBUTTON)
577 {
578 if ( nFlags & MK_CONTROL )
579 {
580 rotCount++;
581 myView->Rotation(point.x,point.y);
582 }
583 }else //if ( nFlags & MK_RBUTTON)
584 // ============================ NO BUTTON =======================
585 { // No buttons
586 myXmax = point.x; myYmax = point.y;
587 if (nFlags & MK_SHIFT)
588 GetDocument()->ShiftMoveEvent(point.x,point.y,myView);
589 else
590 GetDocument()->MoveEvent(point.x,point.y,myView);
591 }
592}
593
594void CAnimationView3D::OnUpdateBUTTONHlrOff(CCmdUI* pCmdUI)
595{
596 pCmdUI->SetCheck (myDegenerateModeIsOn);
597 pCmdUI->Enable (!myDegenerateModeIsOn);
598}
599
600void CAnimationView3D::OnUpdateBUTTONHlrOn(CCmdUI* pCmdUI)
601{
602 pCmdUI->SetCheck (!myDegenerateModeIsOn);
603 pCmdUI->Enable (myDegenerateModeIsOn);
604}
605
606void CAnimationView3D::OnUpdateBUTTONPanGlo(CCmdUI* pCmdUI)
607{
608 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_GlobalPanning);
609 pCmdUI->Enable (myCurrentMode != CurrentAction3d_GlobalPanning);
610
611}
612
613void CAnimationView3D::OnUpdateBUTTONPan(CCmdUI* pCmdUI)
614{
615 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_DynamicPanning);
616 pCmdUI->Enable (myCurrentMode != CurrentAction3d_DynamicPanning );
617}
618
619void CAnimationView3D::OnUpdateBUTTONZoomProg(CCmdUI* pCmdUI)
620{
621 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_DynamicZooming );
622 pCmdUI->Enable (myCurrentMode != CurrentAction3d_DynamicZooming);
623}
624
625void CAnimationView3D::OnUpdateBUTTONZoomWin(CCmdUI* pCmdUI)
626{
627 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_WindowZooming);
628 pCmdUI->Enable (myCurrentMode != CurrentAction3d_WindowZooming);
629}
630
631void CAnimationView3D::OnUpdateBUTTONRot(CCmdUI* pCmdUI)
632{
633 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_DynamicRotation);
634 pCmdUI->Enable (myCurrentMode != CurrentAction3d_DynamicRotation);
635}
636
637void CAnimationView3D::OnUpdateBUTTONFly(CCmdUI* pCmdUI)
638{
639 pCmdUI->Enable(GetDocument()->m_bIsGridLoaded);
640 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_Fly);
641}
642
643void CAnimationView3D::OnUpdateBUTTONTurn(CCmdUI* pCmdUI)
644{
645 pCmdUI->Enable(GetDocument()->m_bIsGridLoaded);
646 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_Turn);
647}
648
649void CAnimationView3D::OnChangeBackground()
650{
651 Standard_Real R1;
652 Standard_Real G1;
653 Standard_Real B1;
654 myView->BackgroundColor(Quantity_TOC_RGB,R1,G1,B1);
655 COLORREF m_clr ;
656 m_clr = RGB(R1*255,G1*255,B1*255);
657
658 CColorDialog dlgColor(m_clr);
659 if (dlgColor.DoModal() == IDOK)
660 {
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);
666 }
667 myView->Redraw();
668}
669
670//==========================================================================================
671//==========================================================================================
672//==========================================================================================
673
674//-----------------------------------------------------------------------------------------
675//
676//-----------------------------------------------------------------------------------------
677void 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)
683{
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;}
695
696 CPen* aOldPen;
697 CClientDC clientDC(this);
698 if (m_Pen) aOldPen = clientDC.SelectObject(m_Pen);
699 clientDC.SetROP2(m_DrawMode);
700
701 static Standard_Integer StoredMinX, StoredMaxX, StoredMinY, StoredMaxY;
702 static Standard_Boolean m_IsVisible;
703
704 if ( m_IsVisible && !Draw) // move or up : erase at the old position
705 {
706 clientDC.MoveTo(StoredMinX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMaxY);
707 clientDC.LineTo(StoredMaxX,StoredMaxY);
708 clientDC.LineTo(StoredMaxX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMinY);
709 m_IsVisible = false;
710 }
711
712 StoredMinX = min ( MinX, MaxX );
713 StoredMinY = min ( MinY, MaxY );
714 StoredMaxX = max ( MinX, MaxX );
715 StoredMaxY = max ( MinY, MaxY);
716
717 if (Draw) // move : draw
718 {
719 clientDC.MoveTo(StoredMinX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMaxY);
720 clientDC.LineTo(StoredMaxX,StoredMaxY);
721 clientDC.LineTo(StoredMaxX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMinY);
722 m_IsVisible = true;
723 }
724
725 if (m_Pen)
726 clientDC.SelectObject(aOldPen);
727}
728void CAnimationView3D::OnStop()
729{
730 KillTimer(GetDocument()->myCount);
731}
732
733void CAnimationView3D::OnRestart()
734{
735 KillTimer(GetDocument()->myCount);
736 SetTimer(GetDocument()->myCount, 1 , NULL);
737}
738
739/*
740void CAnimationView3D::OnTimer(UINT nIDEvent)
741{
742 // TODO: Add your message handler code here and/or call default
743 GetDocument()->OnMyTimer();
744 CView::OnTimer(nIDEvent);
745}
746*/
747
748
749/*********************************************************************************
750************** W A L K T H R O U G H ******************************************
751/********************************************************************************/
752
753void CAnimationView3D::OnTimer(UINT_PTR nIDEvent)
754{
755 if ( !GetDocument()->m_bIsGridLoaded )
756 {
757 // TODO: Add your message handler code here and/or call default
758 GetDocument()->OnMyTimer();
759 CView::OnTimer(nIDEvent);
760 }
761 else
762 {
763 CView::OnTimer(nIDEvent);
764 if ( nIDEvent == 1 ) {
765 myView->SetImmediateUpdate ( Standard_False ) ;
766 if ( myCurrentMode == CurrentAction3d_Fly ) {
767
768 Fly ( m_curx , m_cury ) ;
769 if ( m_bShift )
770 Roll ( m_curx , m_cury ) ;
771 else
772 Turn ( m_curx , m_cury ) ;
773
774 myView->SetAt ( m_Atx , m_Aty , m_Atz ) ;
775 myView->SetEye ( m_Eyex , m_Eyey , m_Eyez ) ;
776
777 }
778 else if ( myCurrentMode == CurrentAction3d_Turn ) {
779 Twist ( m_curx , m_cury ) ;
780 }
781 else
782 KillTimer (1) ;
783
784
785 myView->SetImmediateUpdate ( Standard_True ) ;
786
787 myView->Update ();
788 }
789
790 ReloadData () ;
791 }
792}
793
794void CAnimationView3D::OnSensitivity()
795{
796 CSensitivity dial ;
797
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 ;
803 }
804}
805
806void CAnimationView3D::Fly (int x , int y)
807{
808 double v [3] ;
809 double l ;
810 double sens ;
811 int i ;
812
813 sens = (double) myYmin - (double) y ;
814 sens /= (double) m_cy ;
815 sens *= m_FlySens ;
816
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] ) ;
821 if ( l > 1.e-3 ) {
822 for ( i=0 ; i<3 ; i++ )
823 v [i] = v [i] / l * sens ;
824
825 m_Atx += v [0] ;
826 m_Aty += v [1] ;
827 m_Atz += v [2] ;
828
829 m_Eyex += v [0] ;
830 m_Eyey += v [1] ;
831 m_Eyez += v [2] ;
832
833 }
834}
835
836/* Rotation */
837
838void CAnimationView3D::Turn (int x , int y)
839{
840 gp_Vec z (0.,0.,1.) ;
841
842 double v [3] ;
843 double sens ;
844 double aX , aY , aZ ;
845
846 sens = (double) x - (double) myXmin ;
847 sens /= (double) m_cx ;
848 sens *= m_TurnSens ;
849
850 v [0] = m_Atx - m_Eyex ;
851 v [1] = m_Aty - m_Eyey ;
852 v [2] = m_Atz - m_Eyez ;
853
854 gp_Pnt eye ( m_Eyex , m_Eyey , m_Eyez ) ;
855
856 gp_Vec reg (v[0],v[1],v[2] );
857
858 gp_Vec vert = reg ^ z ;
859 gp_Vec haut = vert ^ reg ;
860
861 gp_Dir dh (haut) ;
862 gp_Ax1 rot (eye,dh);
863
864 reg.Rotate (rot,sens) ;
865
866 reg.Coord ( aX , aY , aZ ) ;
867
868 m_Atx = m_Eyex + aX ;
869 m_Aty = m_Eyey + aY ;
870 m_Atz = m_Eyez + aZ ;
871}
872
873void CAnimationView3D::Roll (int x , int y)
874{
875 gp_Vec z (0.,0.,1.) ;
876
877 double v [3] ;
878 double sens ;
879 double aX , aY , aZ ;
880
881 sens = (double) x - (double) myXmin ;
882 sens /= (double) m_cx ;
883 sens *= m_TurnSens ;
884
885 v [0] = m_Atx - m_Eyex ;
886 v [1] = m_Aty - m_Eyey ;
887 v [2] = m_Atz - m_Eyez ;
888
889 gp_Pnt eye ( m_Eyex , m_Eyey , m_Eyez ) ;
890
891 gp_Vec reg (v[0],v[1],v[2] );
892
893 gp_Vec vert = reg ^ z ;
894
895 gp_Dir dh (vert) ;
896 gp_Ax1 rot (eye,dh);
897
898 reg.Rotate (rot,sens) ;
899
900 reg.Coord ( aX , aY , aZ ) ;
901
902 m_Atx = m_Eyex + aX ;
903 m_Aty = m_Eyey + aY ;
904 m_Atz = m_Eyez + aZ ;
905}
906
907void CAnimationView3D::Twist (int x , int y)
908{
909 double sens ;
910 double a ;
911
912 a = myView->Twist () ;
913
914 sens = (double) x - (double) myXmin ;
915 sens /= (double) m_cx ;
916 sens *= m_TurnSens ;
917
918 a += sens ;
919
920 myView->SetTwist (a) ;
921}
922
923void CAnimationView3D::SetFocal(double dFocus,double dAngle)
924{
925 double v [3] ;
926 double l ;
927 int i ;
928
929 v [0] = m_Atx - m_Eyex ;
930 v [1] = m_Aty - m_Eyey ;
931 v [2] = m_Atz - m_Eyez ;
932
933 l = sqrt ( v[0]*v[0] + v[1]*v[1] + v[2]*v[2] ) ;
934 if ( l > 1.e-3 ) {
935 for ( i=0 ; i<3 ; i++ )
936 v [i] = v [i] / l * dFocus ;
937
938 m_Focus = dFocus ;
939
940 m_Atx = v [0] + m_Eyex ;
941 m_Aty = v [1] + m_Eyey ;
942 m_Atz = v [2] + m_Eyez ;
943
944 myView->SetImmediateUpdate ( Standard_False ) ;
945 myView->SetAt ( m_Atx , m_Aty , m_Atz ) ;
946 m_dAngle = dAngle ;
42e4630c 947 dAngle = dAngle * M_PI / 180. ;
7fd59977 948 myPView->SetAngle ( dAngle ) ;
949 dAngle = myPView->Angle () ;
950
951 myView->SetImmediateUpdate ( Standard_True ) ;
952 myView->Update ();
953 }
954}
955
956void CAnimationView3D::ReloadData()
957{
958 char szMsg [128] ;
959 double dTwist ;
960
961 myView->At ( m_Atx , m_Aty , m_Atz ) ;
962 myView->Eye ( m_Eyex , m_Eyey , m_Eyez ) ;
963
964 dTwist = myView->Twist () ;
42e4630c 965 dTwist = dTwist * 180. / M_PI ;
7fd59977 966
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 ) ;
973
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 ) ;
980
981 sprintf_s ( szMsg , "%lf" , dTwist ) ;
982 (m_Tune.GetDlgItem ( IDC_TWIST ))->SetWindowText ( szMsg ) ;
983
984 double dx,dy,dz ;
985 dx = m_Atx - m_Eyex ;
986 dy = m_Aty - m_Eyey ;
987 dz = m_Atz - m_Eyez ;
988
989 m_Focus = sqrt ( dx * dx + dy * dy + dz * dz ) ;
990 m_dAngle = myPView->Angle () ;
42e4630c 991 m_dAngle = m_dAngle * 180. / M_PI ;
7fd59977 992
993 m_Tune.m_dAngle = m_dAngle ;
994 m_Tune.m_dFocus = m_Focus ;
995 m_Tune.UpdateData ( FALSE ) ;
996}
997
998void CAnimationView3D::SetDimensions()
999{
1000
1001 CAnimationDoc* pDoc = GetDocument();
1002
1003 myView->SetImmediateUpdate ( Standard_False ) ;
1004
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 ;
1011
1012 myView->SetAt ( m_Atx , m_Aty , m_Atz ) ;
1013 myView->SetEye ( m_Eyex , m_Eyey , m_Eyez ) ;
1014 myView->SetTwist (0.) ;
1015
1016 myView->SetImmediateUpdate ( Standard_False ) ;
1017 myView->FitAll();
1018 myView->SetImmediateUpdate ( Standard_False ) ;
1019 myView->ZFitAll();
1020
1021 myView->SetImmediateUpdate ( Standard_True ) ;
1022
1023 ReloadData () ;
1024 myView->Update ();
1025}
1026
1027void CAnimationView3D::OnViewDisplaystatus()
1028{
1029 // TODO: Add your command handler code here
1030
1031 if ( m_Tune.IsWindowVisible () ) {
1032
1033 }
1034 else {
1035 m_Tune.ShowWindow ( SW_SHOWNORMAL ) ;
1036 }
1037}
1038
1039void CAnimationView3D::OnUpdateViewDisplaystatus(CCmdUI* pCmdUI)
1040{
1041 // TODO: Add your command update UI handler code here
1042
1043 if ( m_Tune.IsWindowVisible () ) {
1044 pCmdUI->SetCheck ( 1 ) ;
1045 }
1046 else {
1047 pCmdUI->SetCheck ( 0 ) ;
1048 }
42e4630c 1049}