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 CFileDialog dlg(FALSE,_T("*.BMP"),NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
83 _T("BMP Files (*.BMP)|*.bmp |GIF Files (*.GIF)|*.gif | PNG Files (*.PNG)|*.png"
84 "|JPEG Files (*.JPEG)|*.jpeg | PPM Files (*.PPM)|*.ppm | TIFF Files (*.TIFF)"
85 "|*.tiff | TGA Files (*.TGA)|*.tga | EXR Files (*.EXR)|*.exr||"),
88 if (dlg.DoModal() == IDOK)
90 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
91 CString aFileName = dlg.GetPathName();
92 myView->Dump(aFileName);
93 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
97 void CGeometryView::OnSize(UINT nType, int cx, int cy)
100 myView->MustBeResized();
103 void CGeometryView::OnLButtonDown(UINT nFlags, CPoint point)
105 // save the current mouse coordinate in min
106 myXmin=point.x; myYmin=point.y;
107 myXmax=point.x; myYmax=point.y;
109 if ( nFlags & MK_CONTROL )
111 // Button MB1 down Control :start zomming
112 // SetCursor(AfxGetApp()->LoadStandardCursor());
116 switch (myCurrentMode)
118 case CurAction3d_Nothing : // start a drag
119 if (nFlags & MK_SHIFT)
120 ShiftDragEvent(myXmax,myYmax,-1);
122 DragEvent(myXmax,myYmax,-1);
125 case CurAction3d_DynamicZooming : // noting
126 // SetCursor(AfxGetApp()->LoadStandardCursor());
128 case CurAction3d_WindowZooming :
130 case CurAction3d_DynamicPanning :// noting
131 // SetCursor(AfxGetApp()->LoadStandardCursor());
133 case CurAction3d_GlobalPanning :// noting
134 // SetCursor(AfxGetApp()->LoadStandardCursor());
136 case CurAction3d_DynamicRotation :
137 // SetCursor(AfxGetApp()->LoadStandardCursor());
138 if (!myDegenerateModeIsOn)
139 myView->SetDegenerateModeOn();
140 myView->StartRotation(point.x,point.y);
143 Standard_Failure::Raise(" incompatible Current Mode ");
149 void CGeometryView::OnLButtonUp(UINT nFlags, CPoint point)
151 if ( nFlags & MK_CONTROL )
157 switch (myCurrentMode)
159 case CurAction3d_Nothing :
160 if (point.x == myXmin && point.y == myYmin)
161 { // no offset between down and up --> selectEvent
164 if (nFlags & MK_SHIFT )
165 ShiftInputEvent(point.x,point.y);
167 InputEvent (point.x,point.y);
170 myXmax=point.x; myYmax=point.y;
171 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False);
172 if (nFlags & MK_SHIFT)
173 ShiftDragEvent(point.x,point.y,1);
175 DragEvent(point.x,point.y,1);
178 case CurAction3d_DynamicZooming :
179 // SetCursor(AfxGetApp()->LoadStandardCursor());
180 myCurrentMode = CurAction3d_Nothing;
182 case CurAction3d_WindowZooming :
183 myXmax=point.x; myYmax=point.y;
184 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False,LongDash);
185 if ((abs(myXmin-myXmax)>ValZWMin) || (abs(myYmin-myYmax)>ValZWMin))
186 // Test if the zoom window is greater than a minimale window.
188 // Do the zoom window between Pmin and Pmax
189 myView->WindowFitAll(myXmin,myYmin,myXmax,myYmax);
191 myCurrentMode = CurAction3d_Nothing;
193 case CurAction3d_DynamicPanning :
194 myCurrentMode = CurAction3d_Nothing;
196 case CurAction3d_GlobalPanning :
197 myView->Place(point.x,point.y,myCurZoom);
198 myCurrentMode = CurAction3d_Nothing;
200 case CurAction3d_DynamicRotation :
201 myCurrentMode = CurAction3d_Nothing;
204 Standard_Failure::Raise(" incompatible Current Mode ");
206 } //switch (myCurrentMode)
207 } // else // if ( Ctrl )
210 void CGeometryView::OnMButtonDown(UINT nFlags, CPoint point)
212 if ( nFlags & MK_CONTROL )
214 // Button MB2 down Control : panning init
215 // SetCursor(AfxGetApp()->LoadStandardCursor());
219 void CGeometryView::OnMButtonUp(UINT nFlags, CPoint point)
221 if ( nFlags & MK_CONTROL )
223 // Button MB2 down Control : panning init
224 // SetCursor(AfxGetApp()->LoadStandardCursor());
228 void CGeometryView::OnRButtonDown(UINT nFlags, CPoint point)
230 if ( nFlags & MK_CONTROL )
232 // SetCursor(AfxGetApp()->LoadStandardCursor());
233 if (!myDegenerateModeIsOn)
234 myView->SetDegenerateModeOn();
235 myView->StartRotation(point.x,point.y);
239 Popup(point.x,point.y);
243 void CGeometryView::OnRButtonUp(UINT nFlags, CPoint point)
245 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
246 if (!myDegenerateModeIsOn)
248 myView->SetDegenerateModeOff();
249 myDegenerateModeIsOn = Standard_False;
252 myView->SetDegenerateModeOn();
253 myDegenerateModeIsOn = Standard_True;
255 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
258 void CGeometryView::OnMouseMove(UINT nFlags, CPoint point)
260 // ============================ LEFT BUTTON =======================
261 if ( nFlags & MK_LBUTTON)
263 if ( nFlags & MK_CONTROL )
265 // move with MB1 and Control : on the dynamic zooming
266 // Do the zoom in function of mouse's coordinates
267 myView->Zoom(myXmax,myYmax,point.x,point.y);
268 // save the current mouse coordinate in min
274 switch (myCurrentMode)
276 case CurAction3d_Nothing :
277 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False);
280 if (nFlags & MK_SHIFT)
281 ShiftDragEvent(myXmax,myYmax,0);
283 DragEvent(myXmax,myYmax,0);
284 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_True);
286 case CurAction3d_DynamicZooming :
287 myView->Zoom(myXmax,myYmax,point.x,point.y);
288 // save the current mouse coordinate in min \n";
289 myXmax=point.x; myYmax=point.y;
291 case CurAction3d_WindowZooming :
292 myXmax = point.x; myYmax = point.y;
293 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False,LongDash);
294 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_True,LongDash);
296 case CurAction3d_DynamicPanning :
297 myView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
298 myXmax = point.x; myYmax = point.y;
300 case CurAction3d_GlobalPanning : // nothing
302 case CurAction3d_DynamicRotation :
303 myView->Rotation(point.x,point.y);
307 Standard_Failure::Raise(" incompatible Current Mode ");
309 }// switch (myCurrentMode)
310 }// if ( nFlags & MK_CONTROL ) else
311 } else // if ( nFlags & MK_LBUTTON)
312 // ============================ MIDDLE BUTTON =======================
313 if ( nFlags & MK_MBUTTON)
315 if ( nFlags & MK_CONTROL )
317 myView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
318 myXmax = point.x; myYmax = point.y;
321 } else // if ( nFlags & MK_MBUTTON)
322 // ============================ RIGHT BUTTON =======================
323 if ( nFlags & MK_RBUTTON)
325 if ( nFlags & MK_CONTROL )
327 myView->Rotation(point.x,point.y);
329 }else //if ( nFlags & MK_RBUTTON)
330 // ============================ NO BUTTON =======================
332 myXmax = point.x; myYmax = point.y;
333 if (nFlags & MK_SHIFT)
334 ShiftMoveEvent(point.x,point.y);
336 MoveEvent(point.x,point.y);
340 void CGeometryView::OnUpdateBUTTONHlrOff(CCmdUI* pCmdUI)
342 pCmdUI->SetCheck (myDegenerateModeIsOn);
343 pCmdUI->Enable (!myDegenerateModeIsOn);
346 void CGeometryView::OnUpdateBUTTONHlrOn(CCmdUI* pCmdUI)
348 pCmdUI->SetCheck (!myDegenerateModeIsOn);
349 pCmdUI->Enable (myDegenerateModeIsOn);
352 void CGeometryView::OnUpdateBUTTONPanGlo(CCmdUI* pCmdUI)
354 pCmdUI->SetCheck (myCurrentMode == CurAction3d_GlobalPanning);
355 pCmdUI->Enable (myCurrentMode != CurAction3d_GlobalPanning);
359 void CGeometryView::OnUpdateBUTTONPan(CCmdUI* pCmdUI)
361 pCmdUI->SetCheck (myCurrentMode == CurAction3d_DynamicPanning);
362 pCmdUI->Enable (myCurrentMode != CurAction3d_DynamicPanning );
365 void CGeometryView::OnUpdateBUTTONZoomProg(CCmdUI* pCmdUI)
367 pCmdUI->SetCheck (myCurrentMode == CurAction3d_DynamicZooming );
368 pCmdUI->Enable (myCurrentMode != CurAction3d_DynamicZooming);
371 void CGeometryView::OnUpdateBUTTONZoomWin(CCmdUI* pCmdUI)
373 pCmdUI->SetCheck (myCurrentMode == CurAction3d_WindowZooming);
374 pCmdUI->Enable (myCurrentMode != CurAction3d_WindowZooming);
377 void CGeometryView::OnUpdateBUTTONRot(CCmdUI* pCmdUI)
379 pCmdUI->SetCheck (myCurrentMode == CurAction3d_DynamicRotation);
380 pCmdUI->Enable (myCurrentMode != CurAction3d_DynamicRotation);
383 //==========================================================================================
384 //==========================================================================================
385 //==========================================================================================
387 //-----------------------------------------------------------------------------------------
389 //-----------------------------------------------------------------------------------------
390 void CGeometryView::DragEvent(const Standard_Integer x ,
391 const Standard_Integer y ,
392 const Standard_Integer TheState )
395 // TheState == -1 button down
396 // TheState == 0 move
397 // TheState == 1 button up
399 static Standard_Integer theButtonDownX=0;
400 static Standard_Integer theButtonDownY=0;
409 GetDocument()->GetAISContext()->Select(theButtonDownX,theButtonDownY,x,y,myView);
412 //-----------------------------------------------------------------------------------------
414 //-----------------------------------------------------------------------------------------
415 void CGeometryView::InputEvent(const Standard_Integer x ,
416 const Standard_Integer y )
418 GetDocument()->GetAISContext()->Select();
421 //-----------------------------------------------------------------------------------------
423 //-----------------------------------------------------------------------------------------
424 void CGeometryView::MoveEvent(const Standard_Integer x ,
425 const Standard_Integer y )
427 GetDocument()->GetAISContext()->MoveTo(x,y,myView);
430 //-----------------------------------------------------------------------------------------
432 //-----------------------------------------------------------------------------------------
433 void CGeometryView::ShiftMoveEvent(const Standard_Integer x ,
434 const Standard_Integer y )
436 GetDocument()->GetAISContext()->MoveTo(x,y,myView);
439 //-----------------------------------------------------------------------------------------
441 //-----------------------------------------------------------------------------------------
442 void CGeometryView::ShiftDragEvent(const Standard_Integer x ,
443 const Standard_Integer y ,
444 const Standard_Integer TheState )
446 static Standard_Integer theButtonDownX=0;
447 static Standard_Integer theButtonDownY=0;
456 GetDocument()->GetAISContext()->ShiftSelect(theButtonDownX,theButtonDownY,x,y,myView);
460 //-----------------------------------------------------------------------------------------
462 //-----------------------------------------------------------------------------------------
463 void CGeometryView::ShiftInputEvent(const Standard_Integer x ,
464 const Standard_Integer y )
466 GetDocument()->GetAISContext()->ShiftSelect();
469 //-----------------------------------------------------------------------------------------
471 //-----------------------------------------------------------------------------------------
472 void CGeometryView::Popup(const Standard_Integer x,
473 const Standard_Integer y )
475 Standard_Integer PopupMenuNumber=0;
476 GetDocument()->GetAISContext()->InitCurrent();
477 if (GetDocument()->GetAISContext()->MoreCurrent())
481 VERIFY(menu.LoadMenu(IDR_Popup3D));
482 CMenu* pPopup = menu.GetSubMenu(PopupMenuNumber);
483 ASSERT(pPopup != NULL);
485 POINT winCoord = { x , y };
486 Handle(WNT_Window) aWNTWindow=
487 Handle(WNT_Window)::DownCast(myView->Window());
488 ClientToScreen ( &winCoord);
489 pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON , winCoord.x, winCoord.y ,