1 // GeometryView.cpp : implementation of the CGeometryView class
5 #include "GeometryApp.h"
7 #include <GeometryApp.h>
8 #include "GeometryDoc.h"
9 #include "GeometryView.h"
15 static char THIS_FILE[] = __FILE__;
18 /////////////////////////////////////////////////////////////////////////////
21 IMPLEMENT_DYNCREATE(CGeometryView, OCC_3dView)
23 BEGIN_MESSAGE_MAP(CGeometryView, OCC_3dView)
24 //{{AFX_MSG_MAP(CGeometryView)
25 ON_COMMAND(ID_FILE_EXPORT_IMAGE, OnFileExportImage)
34 ON_UPDATE_COMMAND_UI(ID_BUTTONHlrOff, OnUpdateBUTTONHlrOff)
35 ON_UPDATE_COMMAND_UI(ID_BUTTONHlrOn, OnUpdateBUTTONHlrOn)
36 ON_UPDATE_COMMAND_UI(ID_BUTTONPanGlo, OnUpdateBUTTONPanGlo)
37 ON_UPDATE_COMMAND_UI(ID_BUTTONPan, OnUpdateBUTTONPan)
38 ON_UPDATE_COMMAND_UI(ID_BUTTONZoomProg, OnUpdateBUTTONZoomProg)
39 ON_UPDATE_COMMAND_UI(ID_BUTTONZoomWin, OnUpdateBUTTONZoomWin)
40 ON_UPDATE_COMMAND_UI(ID_BUTTONRot, OnUpdateBUTTONRot)
44 /////////////////////////////////////////////////////////////////////////////
45 // CGeometryView construction/destruction
47 CGeometryView::CGeometryView()
51 CGeometryView::~CGeometryView()
55 /////////////////////////////////////////////////////////////////////////////
56 // CGeometryView diagnostics
59 void CGeometryView::AssertValid() const
64 void CGeometryView::Dump(CDumpContext& dc) const
69 CGeometryDoc* CGeometryView::GetDocument() // non-debug version is inline
71 ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGeometryDoc)));
72 return (CGeometryDoc*)m_pDocument;
76 /////////////////////////////////////////////////////////////////////////////
77 // CGeometryView message handlers
80 void CGeometryView::OnFileExportImage()
82 GetDocument()->ExportView (myView);
85 void CGeometryView::OnSize(UINT /*nType*/, int /*cx*/, int /*cy*/)
88 myView->MustBeResized();
91 void CGeometryView::OnLButtonDown(UINT nFlags, CPoint point)
93 // save the current mouse coordinate in min
94 myXmin=point.x; myYmin=point.y;
95 myXmax=point.x; myYmax=point.y;
97 if ( nFlags & MK_CONTROL )
99 // Button MB1 down Control :start zomming
100 // SetCursor(AfxGetApp()->LoadStandardCursor());
104 switch (myCurrentMode)
106 case CurAction3d_Nothing : // start a drag
107 if (nFlags & MK_SHIFT)
108 ShiftDragEvent(myXmax,myYmax,-1);
110 DragEvent(myXmax,myYmax,-1);
113 case CurAction3d_DynamicZooming : // noting
114 // SetCursor(AfxGetApp()->LoadStandardCursor());
116 case CurAction3d_WindowZooming :
118 case CurAction3d_DynamicPanning :// noting
119 // SetCursor(AfxGetApp()->LoadStandardCursor());
121 case CurAction3d_GlobalPanning :// noting
122 // SetCursor(AfxGetApp()->LoadStandardCursor());
124 case CurAction3d_DynamicRotation :
125 // SetCursor(AfxGetApp()->LoadStandardCursor());
128 myView->SetComputedMode (Standard_False);
130 myView->StartRotation (point.x, point.y);
133 Standard_Failure::Raise(" incompatible Current Mode ");
139 void CGeometryView::OnLButtonUp(UINT nFlags, CPoint point)
141 if ( nFlags & MK_CONTROL )
147 switch (myCurrentMode)
149 case CurAction3d_Nothing :
150 if (point.x == myXmin && point.y == myYmin)
151 { // no offset between down and up --> selectEvent
154 if (nFlags & MK_SHIFT )
155 ShiftInputEvent(point.x,point.y);
157 InputEvent (point.x,point.y);
160 myXmax=point.x; myYmax=point.y;
161 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False);
162 if (nFlags & MK_SHIFT)
163 ShiftDragEvent(point.x,point.y,1);
165 DragEvent(point.x,point.y,1);
168 case CurAction3d_DynamicZooming :
169 // SetCursor(AfxGetApp()->LoadStandardCursor());
170 myCurrentMode = CurAction3d_Nothing;
172 case CurAction3d_WindowZooming :
173 myXmax=point.x; myYmax=point.y;
174 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False,LongDash);
175 if ((abs(myXmin-myXmax)>ValZWMin) || (abs(myYmin-myYmax)>ValZWMin))
176 // Test if the zoom window is greater than a minimale window.
178 // Do the zoom window between Pmin and Pmax
179 myView->WindowFitAll(myXmin,myYmin,myXmax,myYmax);
181 myCurrentMode = CurAction3d_Nothing;
183 case CurAction3d_DynamicPanning :
184 myCurrentMode = CurAction3d_Nothing;
186 case CurAction3d_GlobalPanning :
187 myView->Place(point.x,point.y,myCurZoom);
188 myCurrentMode = CurAction3d_Nothing;
190 case CurAction3d_DynamicRotation :
191 myCurrentMode = CurAction3d_Nothing;
194 Standard_Failure::Raise(" incompatible Current Mode ");
196 } //switch (myCurrentMode)
197 } // else // if ( Ctrl )
200 void CGeometryView::OnMButtonDown(UINT nFlags, CPoint /*point*/)
202 if ( nFlags & MK_CONTROL )
204 // Button MB2 down Control : panning init
205 // SetCursor(AfxGetApp()->LoadStandardCursor());
209 void CGeometryView::OnMButtonUp(UINT nFlags, CPoint /*point*/)
211 if ( nFlags & MK_CONTROL )
213 // Button MB2 down Control : panning init
214 // SetCursor(AfxGetApp()->LoadStandardCursor());
218 void CGeometryView::OnRButtonDown(UINT nFlags, CPoint point)
220 if ( nFlags & MK_CONTROL )
222 // SetCursor(AfxGetApp()->LoadStandardCursor());
225 myView->SetComputedMode (Standard_False);
227 myView->StartRotation (point.x, point.y);
231 Popup (point.x, point.y);
235 void CGeometryView::OnRButtonUp(UINT /*nFlags*/, CPoint /*point*/)
237 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
238 myView->SetComputedMode (myHlrModeIsOn);
239 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
242 void CGeometryView::OnMouseMove(UINT nFlags, CPoint point)
244 // ============================ LEFT BUTTON =======================
245 if ( nFlags & MK_LBUTTON)
247 if ( nFlags & MK_CONTROL )
249 // move with MB1 and Control : on the dynamic zooming
250 // Do the zoom in function of mouse's coordinates
251 myView->Zoom(myXmax,myYmax,point.x,point.y);
252 // save the current mouse coordinate in min
258 switch (myCurrentMode)
260 case CurAction3d_Nothing :
261 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False);
264 if (nFlags & MK_SHIFT)
265 ShiftDragEvent(myXmax,myYmax,0);
267 DragEvent(myXmax,myYmax,0);
268 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_True);
270 case CurAction3d_DynamicZooming :
271 myView->Zoom(myXmax,myYmax,point.x,point.y);
272 // save the current mouse coordinate in min \n";
273 myXmax=point.x; myYmax=point.y;
275 case CurAction3d_WindowZooming :
276 myXmax = point.x; myYmax = point.y;
277 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False,LongDash);
278 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_True,LongDash);
280 case CurAction3d_DynamicPanning :
281 myView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
282 myXmax = point.x; myYmax = point.y;
284 case CurAction3d_GlobalPanning : // nothing
286 case CurAction3d_DynamicRotation :
287 myView->Rotation(point.x,point.y);
291 Standard_Failure::Raise(" incompatible Current Mode ");
293 }// switch (myCurrentMode)
294 }// if ( nFlags & MK_CONTROL ) else
295 } else // if ( nFlags & MK_LBUTTON)
296 // ============================ MIDDLE BUTTON =======================
297 if ( nFlags & MK_MBUTTON)
299 if ( nFlags & MK_CONTROL )
301 myView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
302 myXmax = point.x; myYmax = point.y;
305 } else // if ( nFlags & MK_MBUTTON)
306 // ============================ RIGHT BUTTON =======================
307 if ( nFlags & MK_RBUTTON)
309 if ( nFlags & MK_CONTROL )
311 myView->Rotation(point.x,point.y);
313 }else //if ( nFlags & MK_RBUTTON)
314 // ============================ NO BUTTON =======================
316 myXmax = point.x; myYmax = point.y;
317 if (nFlags & MK_SHIFT)
318 ShiftMoveEvent(point.x,point.y);
320 MoveEvent(point.x,point.y);
324 void CGeometryView::OnUpdateBUTTONHlrOff (CCmdUI* pCmdUI)
326 pCmdUI->SetCheck (!myHlrModeIsOn);
327 pCmdUI->Enable (myHlrModeIsOn);
330 void CGeometryView::OnUpdateBUTTONHlrOn (CCmdUI* pCmdUI)
332 pCmdUI->SetCheck (myHlrModeIsOn);
333 pCmdUI->Enable (!myHlrModeIsOn);
336 void CGeometryView::OnUpdateBUTTONPanGlo(CCmdUI* pCmdUI)
338 pCmdUI->SetCheck (myCurrentMode == CurAction3d_GlobalPanning);
339 pCmdUI->Enable (myCurrentMode != CurAction3d_GlobalPanning);
343 void CGeometryView::OnUpdateBUTTONPan(CCmdUI* pCmdUI)
345 pCmdUI->SetCheck (myCurrentMode == CurAction3d_DynamicPanning);
346 pCmdUI->Enable (myCurrentMode != CurAction3d_DynamicPanning );
349 void CGeometryView::OnUpdateBUTTONZoomProg(CCmdUI* pCmdUI)
351 pCmdUI->SetCheck (myCurrentMode == CurAction3d_DynamicZooming );
352 pCmdUI->Enable (myCurrentMode != CurAction3d_DynamicZooming);
355 void CGeometryView::OnUpdateBUTTONZoomWin(CCmdUI* pCmdUI)
357 pCmdUI->SetCheck (myCurrentMode == CurAction3d_WindowZooming);
358 pCmdUI->Enable (myCurrentMode != CurAction3d_WindowZooming);
361 void CGeometryView::OnUpdateBUTTONRot(CCmdUI* pCmdUI)
363 pCmdUI->SetCheck (myCurrentMode == CurAction3d_DynamicRotation);
364 pCmdUI->Enable (myCurrentMode != CurAction3d_DynamicRotation);
367 //==========================================================================================
368 //==========================================================================================
369 //==========================================================================================
371 //-----------------------------------------------------------------------------------------
373 //-----------------------------------------------------------------------------------------
374 void CGeometryView::DragEvent(const Standard_Integer x ,
375 const Standard_Integer y ,
376 const Standard_Integer TheState )
379 // TheState == -1 button down
380 // TheState == 0 move
381 // TheState == 1 button up
383 static Standard_Integer theButtonDownX=0;
384 static Standard_Integer theButtonDownY=0;
393 GetDocument()->GetAISContext()->Select(theButtonDownX,theButtonDownY,x,y,myView);
396 //-----------------------------------------------------------------------------------------
398 //-----------------------------------------------------------------------------------------
399 void CGeometryView::InputEvent(const Standard_Integer /*x*/,
400 const Standard_Integer /*y*/)
402 GetDocument()->GetAISContext()->Select();
405 //-----------------------------------------------------------------------------------------
407 //-----------------------------------------------------------------------------------------
408 void CGeometryView::MoveEvent(const Standard_Integer x,
409 const Standard_Integer y)
411 GetDocument()->GetAISContext()->MoveTo(x,y,myView);
414 //-----------------------------------------------------------------------------------------
416 //-----------------------------------------------------------------------------------------
417 void CGeometryView::ShiftMoveEvent(const Standard_Integer x ,
418 const Standard_Integer y )
420 GetDocument()->GetAISContext()->MoveTo(x,y,myView);
423 //-----------------------------------------------------------------------------------------
425 //-----------------------------------------------------------------------------------------
426 void CGeometryView::ShiftDragEvent(const Standard_Integer x ,
427 const Standard_Integer y ,
428 const Standard_Integer TheState )
430 static Standard_Integer theButtonDownX=0;
431 static Standard_Integer theButtonDownY=0;
440 GetDocument()->GetAISContext()->ShiftSelect(theButtonDownX,theButtonDownY,x,y,myView);
444 //-----------------------------------------------------------------------------------------
446 //-----------------------------------------------------------------------------------------
447 void CGeometryView::ShiftInputEvent(const Standard_Integer /*x*/,
448 const Standard_Integer /*y*/)
450 GetDocument()->GetAISContext()->ShiftSelect();
453 //-----------------------------------------------------------------------------------------
455 //-----------------------------------------------------------------------------------------
456 void CGeometryView::Popup(const Standard_Integer x,
457 const Standard_Integer y )
459 Standard_Integer PopupMenuNumber=0;
460 GetDocument()->GetAISContext()->InitCurrent();
461 if (GetDocument()->GetAISContext()->MoreCurrent())
465 VERIFY(menu.LoadMenu(IDR_Popup3D));
466 CMenu* pPopup = menu.GetSubMenu(PopupMenuNumber);
467 ASSERT(pPopup != NULL);
469 POINT winCoord = { x , y };
470 Handle(WNT_Window) aWNTWindow=
471 Handle(WNT_Window)::DownCast(myView->Window());
472 ClientToScreen ( &winCoord);
473 pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON , winCoord.x, winCoord.y ,