1 // OCC_BaseView.cpp: implementation of the OCC_BaseView class.
3 //////////////////////////////////////////////////////////////////////
6 #include "OCC_BaseView.h"
8 BEGIN_MESSAGE_MAP(OCC_BaseView, CView)
22 //=======================================================================
23 //function : Constructor
25 //=======================================================================
26 OCC_BaseView::OCC_BaseView()
27 : myUpdateRequests (0),
29 myCurrentMode (CurAction3d_Nothing)
31 myDefaultGestures = myMouseGestureMap;
34 //=======================================================================
35 //function : Destructor
37 //=======================================================================
38 OCC_BaseView::~OCC_BaseView()
43 //=======================================================================
44 //function : GetDocument
46 //=======================================================================
47 OCC_BaseDoc* OCC_BaseView::GetDocument() // non-debug version is inline
49 return (OCC_BaseDoc*)m_pDocument;
52 // =======================================================================
53 // function : PostNcDestroy
55 // =======================================================================
56 void OCC_BaseView::PostNcDestroy()
63 CView::PostNcDestroy();
66 // =======================================================================
67 // function : PreCreateWindow
69 // =======================================================================
70 BOOL OCC_BaseView::PreCreateWindow (CREATESTRUCT& cs)
72 cs.lpszClass = ::AfxRegisterWndClass (CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | CS_OWNDC, ::LoadCursor(NULL, IDC_ARROW), NULL, NULL);
73 return CView::PreCreateWindow (cs);
76 // =======================================================================
77 // function : OnInitialUpdate
79 // =======================================================================
80 void OCC_BaseView::OnInitialUpdate()
82 myCurrentMode = CurAction3d_Nothing;
83 CView::OnInitialUpdate();
89 myView = GetAISContext()->CurrentViewer()->CreateView();
90 myView->SetImmediateUpdate (false);
91 myView->SetComputedMode (Standard_False);
93 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (myView->Viewer()->Driver());
94 myView->Camera()->SetProjectionType (aDriver->Options().contextStereo
95 ? Graphic3d_Camera::Projection_Stereo
96 : Graphic3d_Camera::Projection_Orthographic);
98 Handle(WNT_Window) aWNTWindow = new WNT_Window (GetSafeHwnd());
99 myView->SetWindow (aWNTWindow);
100 if (!aWNTWindow->IsMapped()) aWNTWindow->Map();
103 myView->Invalidate();
106 // ================================================================
107 // Function : GetAISContext
109 // ================================================================
110 const Handle(AIS_InteractiveContext)& OCC_BaseView::GetAISContext() const
112 return ((OCC_BaseDoc*)m_pDocument)->GetInteractiveContext();
115 // ================================================================
116 // Function : update3dView
118 // ================================================================
119 void OCC_BaseView::update3dView()
121 if (!myView.IsNull())
123 if (++myUpdateRequests == 1)
131 // ================================================================
132 // Function : redraw3dView
134 // ================================================================
135 void OCC_BaseView::redraw3dView()
137 if (!myView.IsNull())
139 FlushViewEvents (GetAISContext(), myView, true);
143 // ================================================================
144 // Function : handleViewRedraw
146 // ================================================================
147 void OCC_BaseView::handleViewRedraw (const Handle(AIS_InteractiveContext)& theCtx,
148 const Handle(V3d_View)& theView)
150 myUpdateRequests = 0;
151 AIS_ViewController::handleViewRedraw (theCtx, theView);
154 // ================================================================
155 // Function : OnSelectionChanged
157 // ================================================================
158 void OCC_BaseView::OnSelectionChanged (const Handle(AIS_InteractiveContext)& theCtx,
159 const Handle(V3d_View)& theView)
161 AIS_ViewController::OnSelectionChanged (theCtx, theView);
162 GetDocument()->OnSelectionChanged (theCtx, theView);
165 // =======================================================================
168 // =======================================================================
169 void OCC_BaseView::OnDraw (CDC* )
171 // always redraw immediate layer (dynamic highlighting) on Paint event,
172 // and redraw entire view content only when it is explicitly invalidated (V3d_View::Invalidate())
173 myView->InvalidateImmediate();
174 FlushViewEvents (GetAISContext(), myView, true);
177 // =======================================================================
178 // function : defineMouseGestures
180 // =======================================================================
181 void OCC_BaseView::defineMouseGestures()
183 myMouseGestureMap.Clear();
184 AIS_MouseGesture aRot = AIS_MouseGesture_RotateOrbit;
185 switch (myCurrentMode)
187 case CurAction3d_Nothing:
189 myMouseGestureMap = myDefaultGestures;
192 case CurAction3d_DynamicZooming:
194 myMouseGestureMap.Bind (Aspect_VKeyMouse_LeftButton, AIS_MouseGesture_Zoom);
197 case CurAction3d_GlobalPanning:
201 case CurAction3d_WindowZooming:
203 myMouseGestureMap.Bind (Aspect_VKeyMouse_LeftButton, AIS_MouseGesture_ZoomWindow);
206 case CurAction3d_DynamicPanning:
208 myMouseGestureMap.Bind (Aspect_VKeyMouse_LeftButton, AIS_MouseGesture_Pan);
211 case CurAction3d_DynamicRotation:
213 myMouseGestureMap.Bind (Aspect_VKeyMouse_LeftButton, aRot);
219 // =======================================================================
220 // function : OnMouseMove
222 // =======================================================================
223 void OCC_BaseView::OnMouseMove (UINT theFlags, CPoint thePoint)
225 TRACKMOUSEEVENT aMouseEvent; // for WM_MOUSELEAVE
226 aMouseEvent.cbSize = sizeof(aMouseEvent);
227 aMouseEvent.dwFlags = TME_LEAVE;
228 aMouseEvent.hwndTrack = m_hWnd;
229 aMouseEvent.dwHoverTime = HOVER_DEFAULT;
230 if (!::_TrackMouseEvent (&aMouseEvent)) { TRACE("Track ERROR!\n"); }
232 const Aspect_VKeyFlags aFlags = WNT_Window::MouseKeyFlagsFromEvent (theFlags);
233 if (UpdateMousePosition (Graphic3d_Vec2i (thePoint.x, thePoint.y), PressedMouseButtons(), aFlags, false))
239 // =======================================================================
240 // function : OnLButtonDown
242 // =======================================================================
243 void OCC_BaseView::OnLButtonDown (UINT theFlags, CPoint thePoint)
245 const Aspect_VKeyFlags aFlags = WNT_Window::MouseKeyFlagsFromEvent (theFlags);
246 PressMouseButton (Graphic3d_Vec2i (thePoint.x, thePoint.y), Aspect_VKeyMouse_LeftButton, aFlags, false);
250 // =======================================================================
251 // function : OnLButtonUp
253 // =======================================================================
254 void OCC_BaseView::OnLButtonUp (UINT theFlags, CPoint thePoint)
256 const Aspect_VKeyFlags aFlags = WNT_Window::MouseKeyFlagsFromEvent (theFlags);
257 ReleaseMouseButton (Graphic3d_Vec2i (thePoint.x, thePoint.y), Aspect_VKeyMouse_LeftButton, aFlags, false);
258 if (myCurrentMode == CurAction3d_GlobalPanning)
260 myView->Place (thePoint.x, thePoint.y, myCurZoom);
261 myView->Invalidate();
263 if (myCurrentMode != CurAction3d_Nothing)
265 setCurrentAction (CurAction3d_Nothing);
270 // =======================================================================
271 // function : OnMButtonDown
273 // =======================================================================
274 void OCC_BaseView::OnMButtonDown (UINT theFlags, CPoint thePoint)
276 const Aspect_VKeyFlags aFlags = WNT_Window::MouseKeyFlagsFromEvent (theFlags);
277 PressMouseButton (Graphic3d_Vec2i (thePoint.x, thePoint.y), Aspect_VKeyMouse_MiddleButton, aFlags, false);
281 // =======================================================================
282 // function : OnMButtonUp
284 // =======================================================================
285 void OCC_BaseView::OnMButtonUp (UINT theFlags, CPoint thePoint)
287 const Aspect_VKeyFlags aFlags = WNT_Window::MouseKeyFlagsFromEvent (theFlags);
288 ReleaseMouseButton (Graphic3d_Vec2i (thePoint.x, thePoint.y), Aspect_VKeyMouse_MiddleButton, aFlags, false);
290 if (myCurrentMode != CurAction3d_Nothing)
292 setCurrentAction (CurAction3d_Nothing);
296 // =======================================================================
297 // function : OnRButtonDown
299 // =======================================================================
300 void OCC_BaseView::OnRButtonDown (UINT theFlags, CPoint thePoint)
302 const Aspect_VKeyFlags aFlags = WNT_Window::MouseKeyFlagsFromEvent (theFlags);
303 PressMouseButton (Graphic3d_Vec2i (thePoint.x, thePoint.y), Aspect_VKeyMouse_RightButton, aFlags, false);
305 myClickPos.SetValues (thePoint.x, thePoint.y);
308 // =======================================================================
309 // function : OnRButtonUp
311 // =======================================================================
312 void OCC_BaseView::OnRButtonUp (UINT theFlags, CPoint thePoint)
314 const Aspect_VKeyFlags aFlags = WNT_Window::MouseKeyFlagsFromEvent (theFlags);
315 ReleaseMouseButton (Graphic3d_Vec2i (thePoint.x, thePoint.y), Aspect_VKeyMouse_RightButton, aFlags, false);
317 if (myCurrentMode != CurAction3d_Nothing)
319 setCurrentAction (CurAction3d_Nothing);
321 if (aFlags == Aspect_VKeyFlags_NONE
322 && (myClickPos - Graphic3d_Vec2i (thePoint.x, thePoint.y)).cwiseAbs().maxComp() <= 4)
324 GetDocument()->Popup (thePoint.x, thePoint.y, myView);
328 // =======================================================================
329 // function : OnMouseWheel
331 // =======================================================================
332 BOOL OCC_BaseView::OnMouseWheel (UINT theFlags, short theDelta, CPoint thePoint)
334 const Standard_Real aDeltaF = Standard_Real(theDelta) / Standard_Real(WHEEL_DELTA);
335 CPoint aCursorPnt = thePoint;
336 ScreenToClient (&aCursorPnt);
337 const Graphic3d_Vec2i aPos (aCursorPnt.x, aCursorPnt.y);
338 const Aspect_VKeyFlags aFlags = WNT_Window::MouseKeyFlagsFromEvent (theFlags);
339 if (UpdateMouseScroll (Aspect_ScrollDelta (aPos, aDeltaF, aFlags)))
346 // =======================================================================
349 // =======================================================================
350 void OCC_BaseView::OnSize (UINT nType, int cx, int cy)
352 CView::OnSize (nType, cx, cy);
357 myView->Window()->DoResize();
358 myView->MustBeResized();
359 myView->Invalidate();
364 // =======================================================================
365 // function : OnMouseLeave
367 // =======================================================================
368 void OCC_BaseView::OnMouseLeave()
371 if (GetCursorPos (&aCursorPos))
373 ReleaseMouseButton (Graphic3d_Vec2i (aCursorPos.x, aCursorPos.y),
374 PressedMouseButtons(),
375 Aspect_VKeyMouse_NONE,