1 // OCCDemoView.cpp : implementation of the COCCDemoView class
7 #include "OCCDemoDoc.h"
8 #include "OCCDemoView.h"
10 #include <AIS_RubberBand.hxx>
11 #include <Graphic3d_GraphicDriver.hxx>
17 static char THIS_FILE[] = __FILE__;
20 /////////////////////////////////////////////////////////////////////////////
23 IMPLEMENT_DYNCREATE(COCCDemoView, CView)
25 BEGIN_MESSAGE_MAP(COCCDemoView, CView)
26 //{{AFX_MSG_MAP(COCCDemoView)
27 ON_COMMAND(ID_BUTTONAxo, OnBUTTONAxo)
28 ON_COMMAND(ID_BUTTONBack, OnBUTTONBack)
29 ON_COMMAND(ID_BUTTONBottom, OnBUTTONBottom)
30 ON_COMMAND(ID_BUTTONFront, OnBUTTONFront)
31 ON_COMMAND(ID_BUTTONHlrOn, OnBUTTONHlrOn)
32 ON_COMMAND(ID_BUTTONLeft, OnBUTTONLeft)
33 ON_COMMAND(ID_BUTTONPan, OnBUTTONPan)
34 ON_COMMAND(ID_BUTTONPanGlo, OnBUTTONPanGlo)
35 ON_COMMAND(ID_BUTTONReset, OnBUTTONReset)
36 ON_COMMAND(ID_BUTTONRight, OnBUTTONRight)
37 ON_COMMAND(ID_BUTTONRot, OnBUTTONRot)
38 ON_COMMAND(ID_BUTTONTop, OnBUTTONTop)
39 ON_COMMAND(ID_BUTTONZoomAll, OnBUTTONZoomAll)
41 ON_COMMAND(ID_BUTTONZoomProg, OnBUTTONZoomProg)
42 ON_COMMAND(ID_BUTTONZoomWin, OnBUTTONZoomWin)
48 ON_UPDATE_COMMAND_UI(ID_BUTTONPanGlo, OnUpdateBUTTONPanGlo)
49 ON_UPDATE_COMMAND_UI(ID_BUTTONPan, OnUpdateBUTTONPan)
50 ON_UPDATE_COMMAND_UI(ID_BUTTONZoomProg, OnUpdateBUTTONZoomProg)
51 ON_UPDATE_COMMAND_UI(ID_BUTTONZoomWin, OnUpdateBUTTONZoomWin)
52 ON_UPDATE_COMMAND_UI(ID_BUTTONRot, OnUpdateBUTTONRot)
53 ON_COMMAND(ID_BUTTONWire, OnBUTTONWire)
54 ON_COMMAND(ID_BUTTONShade, OnBUTTONShade)
55 ON_UPDATE_COMMAND_UI(ID_BUTTONHlrOn, OnUpdateBUTTONHlrOn)
56 ON_UPDATE_COMMAND_UI(ID_BUTTONShade, OnUpdateBUTTONShade)
57 ON_UPDATE_COMMAND_UI(ID_BUTTONWire, OnUpdateBUTTONWire)
61 /////////////////////////////////////////////////////////////////////////////
62 // COCCDemoView construction/destruction
64 COCCDemoView::COCCDemoView()
71 myCurrentMode = CurAction3d_Nothing;
72 myVisMode = VIS_SHADE;
73 myRect = new AIS_RubberBand (Quantity_NOC_WHITE, Aspect_TOL_SOLID, 1.0);
74 myGraphicDriver = ((COCCDemoApp*)AfxGetApp())->GetGraphicDriver();
77 COCCDemoView::~COCCDemoView()
83 BOOL COCCDemoView::PreCreateWindow(CREATESTRUCT& cs)
85 // TODO: Modify the Window class or styles here by modifying
86 // the CREATESTRUCT cs
87 cs.lpszClass = ::AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | CS_OWNDC, ::LoadCursor(NULL, IDC_ARROW), NULL, NULL);
88 return CView::PreCreateWindow(cs);
91 /////////////////////////////////////////////////////////////////////////////
92 // COCCDemoView drawing
94 void COCCDemoView::OnInitialUpdate()
96 CView::OnInitialUpdate();
98 myView = GetDocument()->GetViewer()->CreateView();
99 myView->SetViewMappingDefault();
100 myView->SetViewOrientationDefault();
102 Handle(WNT_Window) aWNTWindow = new WNT_Window(GetSafeHwnd ());
103 myView->SetWindow(aWNTWindow);
104 if (!aWNTWindow->IsMapped()) aWNTWindow->Map();
106 myCurrentMode = CurAction3d_Nothing;
107 myVisMode = VIS_SHADE;
111 void COCCDemoView::OnDraw(CDC* /*pDC*/)
113 COCCDemoDoc* pDoc = GetDocument();
115 // TODO: add draw code for native data here
119 /////////////////////////////////////////////////////////////////////////////
120 // COCCDemoView diagnostics
123 void COCCDemoView::AssertValid() const
125 CView::AssertValid();
128 void COCCDemoView::Dump(CDumpContext& dc) const
133 COCCDemoDoc* COCCDemoView::GetDocument() // non-debug version is inline
135 ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(COCCDemoDoc)));
136 return (COCCDemoDoc*)m_pDocument;
140 /////////////////////////////////////////////////////////////////////////////
141 // COCCDemoView message handlers
143 void COCCDemoView::OnSize(UINT nType, int cx, int cy)
145 CView::OnSize (nType, cx, cy);
146 if (!myView.IsNull())
147 myView->MustBeResized();
150 void COCCDemoView::OnBUTTONBack()
152 myView->SetProj(V3d_Ypos);
155 void COCCDemoView::OnBUTTONFront()
157 myView->SetProj(V3d_Yneg);
160 void COCCDemoView::OnBUTTONBottom()
162 myView->SetProj(V3d_Zneg);
165 void COCCDemoView::OnBUTTONTop()
167 myView->SetProj(V3d_Zpos);
170 void COCCDemoView::OnBUTTONLeft()
172 myView->SetProj(V3d_Xneg);
175 void COCCDemoView::OnBUTTONRight()
177 myView->SetProj(V3d_Xpos);
180 void COCCDemoView::OnBUTTONAxo()
182 myView->SetProj(V3d_XposYnegZpos);
185 void COCCDemoView::OnBUTTONPan()
187 myCurrentMode = CurAction3d_DynamicPanning;
190 void COCCDemoView::OnBUTTONPanGlo()
192 // save the current zoom value
193 myCurZoom = myView->Scale();
197 myCurrentMode = CurAction3d_GlobalPanning;
200 void COCCDemoView::OnBUTTONReset()
205 void COCCDemoView::OnBUTTONRot()
207 myCurrentMode = CurAction3d_DynamicRotation;
210 void COCCDemoView::OnBUTTONZoomAll()
216 void COCCDemoView::OnBUTTONZoomProg()
218 myCurrentMode = CurAction3d_DynamicZooming;
221 void COCCDemoView::OnBUTTONZoomWin()
223 myCurrentMode = CurAction3d_WindowZooming;
226 void COCCDemoView::OnLButtonDown(UINT nFlags, CPoint point)
228 // save the current mouse coordinate in min
229 myXmin=point.x; myYmin=point.y;
230 myXmax=point.x; myYmax=point.y;
232 if ( ! (nFlags & MK_CONTROL) )
234 if (myCurrentMode == CurAction3d_DynamicRotation)
236 myView->SetComputedMode(Standard_False);
237 myView->StartRotation(point.x,point.y);
242 void COCCDemoView::OnLButtonUp(UINT nFlags, CPoint point)
244 if ( !(nFlags & MK_CONTROL) )
246 switch (myCurrentMode)
248 case CurAction3d_Nothing :
252 case CurAction3d_DynamicZooming :
253 myCurrentMode = CurAction3d_Nothing;
255 case CurAction3d_WindowZooming :
256 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False);
259 if ((abs(myXmin-myXmax)>ValZWMin) || (abs(myYmin-myYmax)>ValZWMin))
260 // Test if the zoom window is greater than a minimale window.
262 // Do the zoom window between Pmin and Pmax
263 myView->WindowFitAll(myXmin,myYmin,myXmax,myYmax);
265 myCurrentMode = CurAction3d_Nothing;
267 case CurAction3d_DynamicPanning :
268 myCurrentMode = CurAction3d_Nothing;
270 case CurAction3d_GlobalPanning :
271 myView->Place(point.x,point.y,myCurZoom);
272 myCurrentMode = CurAction3d_Nothing;
274 case CurAction3d_DynamicRotation :
275 if (myVisMode == VIS_HLR)
277 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
278 myView->SetComputedMode(Standard_True);
280 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
282 myCurrentMode = CurAction3d_Nothing;
284 } //switch (myCurrentMode)
288 void COCCDemoView::OnRButtonDown(UINT nFlags, CPoint point)
290 if ( nFlags & MK_CONTROL )
292 myView->SetComputedMode(Standard_False);
293 myView->StartRotation(point.x,point.y);
297 void COCCDemoView::OnRButtonUp(UINT /*nFlags*/, CPoint /*point*/)
299 if (myVisMode == VIS_HLR)
301 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
302 myView->SetComputedMode(Standard_True);
304 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
308 void COCCDemoView::OnMouseMove(UINT nFlags, CPoint point)
310 // ============================ LEFT BUTTON =======================
311 if ( nFlags & MK_LBUTTON)
313 if ( nFlags & MK_CONTROL )
315 // move with MB1 and Control : on the dynamic zooming
316 // Do the zoom in function of mouse's coordinates
317 myView->Zoom(myXmax,myYmax,point.x,point.y);
318 // save the current mouse coordinate in max
324 switch (myCurrentMode)
326 case CurAction3d_Nothing :
330 case CurAction3d_DynamicZooming :
331 myView->Zoom(myXmax,myYmax,point.x,point.y);
332 // save the current mouse coordinate in max;
336 case CurAction3d_WindowZooming :
337 myXmax = point.x; myYmax = point.y;
338 DrawRectangle (myXmin, myYmin, myXmax, myYmax, Standard_True, Aspect_TOL_DASH);
340 case CurAction3d_DynamicPanning :
341 myView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
342 myXmax = point.x; myYmax = point.y;
344 case CurAction3d_GlobalPanning : // nothing
346 case CurAction3d_DynamicRotation :
347 myView->Rotation(point.x,point.y);
353 // ============================ MIDDLE BUTTON =======================
354 else if ( nFlags & MK_MBUTTON)
356 if ( nFlags & MK_CONTROL )
358 myView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
359 myXmax = point.x; myYmax = point.y;
362 // ============================ RIGHT BUTTON =======================
363 else if ( nFlags & MK_RBUTTON)
365 if ( nFlags & MK_CONTROL )
367 myView->Rotation(point.x,point.y);
370 // ============================ NO BUTTON =======================
378 void COCCDemoView::OnUpdateBUTTONPanGlo(CCmdUI* pCmdUI)
380 pCmdUI->SetCheck (myCurrentMode == CurAction3d_GlobalPanning);
381 pCmdUI->Enable (myCurrentMode != CurAction3d_GlobalPanning);
384 void COCCDemoView::OnUpdateBUTTONPan(CCmdUI* pCmdUI)
386 pCmdUI->SetCheck (myCurrentMode == CurAction3d_DynamicPanning);
387 pCmdUI->Enable (myCurrentMode != CurAction3d_DynamicPanning );
390 void COCCDemoView::OnUpdateBUTTONZoomProg(CCmdUI* pCmdUI)
392 pCmdUI->SetCheck (myCurrentMode == CurAction3d_DynamicZooming );
393 pCmdUI->Enable (myCurrentMode != CurAction3d_DynamicZooming);
396 void COCCDemoView::OnUpdateBUTTONZoomWin(CCmdUI* pCmdUI)
398 pCmdUI->SetCheck (myCurrentMode == CurAction3d_WindowZooming);
399 pCmdUI->Enable (myCurrentMode != CurAction3d_WindowZooming);
402 void COCCDemoView::OnUpdateBUTTONRot(CCmdUI* pCmdUI)
404 pCmdUI->SetCheck (myCurrentMode == CurAction3d_DynamicRotation);
405 pCmdUI->Enable (myCurrentMode != CurAction3d_DynamicRotation);
408 void COCCDemoView::DrawRectangle (Standard_Integer theMinX,
409 Standard_Integer theMinY,
410 Standard_Integer theMaxX,
411 Standard_Integer theMaxY,
412 Standard_Boolean theToDraw,
413 Aspect_TypeOfLine theLineType)
415 const Handle(AIS_InteractiveContext)& aCtx = GetDocument()->GetAISContext();
418 aCtx->Remove (myRect, false);
419 aCtx->CurrentViewer()->RedrawImmediate();
424 GetWindowRect (aRect);
425 myRect->SetLineType (theLineType);
426 myRect->SetRectangle (theMinX, aRect.Height() - theMinY, theMaxX, aRect.Height() - theMaxY);
427 if (!aCtx->IsDisplayed (myRect))
429 aCtx->Display (myRect, false);
433 aCtx->Redisplay (myRect, false);
435 aCtx->CurrentViewer()->RedrawImmediate();
438 void COCCDemoView::InitButtons()
445 myCurrentMode = CurAction3d_Nothing;
448 void COCCDemoView::Reset()
451 myVisMode = VIS_SHADE;
452 if (!myView.IsNull())
459 void COCCDemoView::RedrawVisMode()
464 GetDocument()->GetAISContext()->SetDisplayMode (AIS_WireFrame, Standard_True);
465 myView->SetComputedMode (Standard_False);
469 GetDocument()->GetAISContext()->SetDisplayMode (AIS_Shaded, Standard_True);
470 myView->SetComputedMode (Standard_False);
474 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
475 myView->SetComputedMode (Standard_True);
477 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
478 GetDocument()->GetAISContext()->SetDisplayMode (AIS_WireFrame, Standard_True);
483 void COCCDemoView::OnBUTTONWire()
485 myVisMode = VIS_WIREFRAME;
489 void COCCDemoView::OnBUTTONShade()
491 myVisMode = VIS_SHADE;
495 void COCCDemoView::OnBUTTONHlrOn()
501 void COCCDemoView::OnUpdateBUTTONWire(CCmdUI* pCmdUI)
503 pCmdUI->SetCheck (myVisMode == VIS_WIREFRAME);
504 pCmdUI->Enable (myVisMode != VIS_WIREFRAME);
507 void COCCDemoView::OnUpdateBUTTONShade(CCmdUI* pCmdUI)
509 pCmdUI->SetCheck (myVisMode == VIS_SHADE);
510 pCmdUI->Enable (myVisMode != VIS_SHADE);
513 void COCCDemoView::OnUpdateBUTTONHlrOn(CCmdUI* pCmdUI)
515 pCmdUI->SetCheck (myVisMode == VIS_HLR);
516 pCmdUI->Enable (myVisMode != VIS_HLR);
519 void COCCDemoView::GetViewAt (Standard_Real& theX, Standard_Real& theY, Standard_Real& theZ) const
521 myView->At (theX, theY, theZ);
524 void COCCDemoView::SetViewAt (const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ)
526 myView->SetAt (theX, theY, theZ);
529 void COCCDemoView::GetViewEye(Standard_Real& X, Standard_Real& Y, Standard_Real& Z)
534 void COCCDemoView::SetViewEye(Standard_Real X, Standard_Real Y, Standard_Real Z)
536 myView->SetEye(X,Y,Z);
539 Standard_Real COCCDemoView::GetViewScale()
541 return myView->Scale();
544 void COCCDemoView::SetViewScale(Standard_Real Coef)
546 myView->SetScale(Coef);
549 void COCCDemoView::Translate (const Standard_Real theX, const Standard_Real theY)
551 myView->Panning (theX, theY);