7fd59977 |
1 | // GeometryView.cpp : implementation of the CGeometryView class |
2 | // |
3 | |
4 | #include "stdafx.h" |
5 | #include "GeometryApp.h" |
6 | |
7 | #include <GeometryApp.h> |
8 | #include "GeometryDoc.h" |
9 | #include "GeometryView.h" |
10 | |
11 | #define ValZWMin 1 |
12 | |
13 | #ifdef _DEBUG |
14 | #undef THIS_FILE |
15 | static char THIS_FILE[] = __FILE__; |
16 | #endif |
17 | |
18 | ///////////////////////////////////////////////////////////////////////////// |
19 | // CGeometryView |
20 | |
21 | IMPLEMENT_DYNCREATE(CGeometryView, OCC_3dView) |
22 | |
23 | BEGIN_MESSAGE_MAP(CGeometryView, OCC_3dView) |
5c1f974e |
24 | //{{AFX_MSG_MAP(CGeometryView) |
25 | ON_COMMAND(ID_FILE_EXPORT_IMAGE, OnFileExportImage) |
26 | ON_WM_SIZE() |
27 | ON_WM_LBUTTONDOWN() |
28 | ON_WM_LBUTTONUP() |
29 | ON_WM_MBUTTONDOWN() |
30 | ON_WM_MBUTTONUP() |
31 | ON_WM_MOUSEMOVE() |
32 | ON_WM_RBUTTONDOWN() |
33 | ON_WM_RBUTTONUP() |
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) |
41 | //}}AFX_MSG_MAP |
7fd59977 |
42 | END_MESSAGE_MAP() |
43 | |
44 | ///////////////////////////////////////////////////////////////////////////// |
45 | // CGeometryView construction/destruction |
46 | |
47 | CGeometryView::CGeometryView() |
48 | { |
49 | } |
50 | |
51 | CGeometryView::~CGeometryView() |
52 | { |
53 | } |
54 | |
55 | ///////////////////////////////////////////////////////////////////////////// |
56 | // CGeometryView diagnostics |
57 | |
58 | #ifdef _DEBUG |
59 | void CGeometryView::AssertValid() const |
60 | { |
5c1f974e |
61 | CView::AssertValid(); |
7fd59977 |
62 | } |
63 | |
64 | void CGeometryView::Dump(CDumpContext& dc) const |
65 | { |
5c1f974e |
66 | CView::Dump(dc); |
7fd59977 |
67 | } |
68 | |
69 | CGeometryDoc* CGeometryView::GetDocument() // non-debug version is inline |
70 | { |
5c1f974e |
71 | ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGeometryDoc))); |
72 | return (CGeometryDoc*)m_pDocument; |
7fd59977 |
73 | } |
74 | #endif //_DEBUG |
75 | |
76 | ///////////////////////////////////////////////////////////////////////////// |
77 | // CGeometryView message handlers |
78 | |
79 | |
80 | void CGeometryView::OnFileExportImage() |
81 | { |
5c1f974e |
82 | CFileDialog aDlg (FALSE, "*.BMP", NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, |
83 | "BMP Files (*.BMP)|*.bmp|" |
84 | "GIF Files (*.GIF)|*.gif|" |
85 | "PNG Files (*.PNG)|*.png|" |
86 | "JPEG Files (*.JPG)|*.jpg|" |
87 | "PPM Files (*.PPM)|*.ppm|" |
88 | "TIFF Files (*.TIFF)|*.tiff|" |
89 | "TGA Files (*.TGA)|*.tga|" |
90 | "EXR Files (*.EXR)|*.exr||", NULL); |
91 | if (aDlg.DoModal() != IDOK) |
7fd59977 |
92 | { |
5c1f974e |
93 | return; |
7fd59977 |
94 | } |
5c1f974e |
95 | |
96 | SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT)); |
97 | myView->Dump (aDlg.GetPathName()); |
98 | SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW)); |
7fd59977 |
99 | } |
100 | |
5c573e69 |
101 | void CGeometryView::OnSize(UINT /*nType*/, int /*cx*/, int /*cy*/) |
7fd59977 |
102 | { |
103 | if (!myView.IsNull()) |
5c1f974e |
104 | myView->MustBeResized(); |
7fd59977 |
105 | } |
106 | |
107 | void CGeometryView::OnLButtonDown(UINT nFlags, CPoint point) |
108 | { |
109 | // save the current mouse coordinate in min |
110 | myXmin=point.x; myYmin=point.y; |
111 | myXmax=point.x; myYmax=point.y; |
112 | |
113 | if ( nFlags & MK_CONTROL ) |
5c1f974e |
114 | { |
115 | // Button MB1 down Control :start zomming |
116 | // SetCursor(AfxGetApp()->LoadStandardCursor()); |
117 | } |
118 | else // if ( Ctrl ) |
119 | { |
120 | switch (myCurrentMode) |
121 | { |
122 | case CurAction3d_Nothing : // start a drag |
123 | if (nFlags & MK_SHIFT) |
124 | ShiftDragEvent(myXmax,myYmax,-1); |
125 | else |
126 | DragEvent(myXmax,myYmax,-1); |
127 | break; |
128 | break; |
129 | case CurAction3d_DynamicZooming : // noting |
130 | // SetCursor(AfxGetApp()->LoadStandardCursor()); |
131 | break; |
132 | case CurAction3d_WindowZooming : |
133 | break; |
134 | case CurAction3d_DynamicPanning :// noting |
135 | // SetCursor(AfxGetApp()->LoadStandardCursor()); |
136 | break; |
137 | case CurAction3d_GlobalPanning :// noting |
138 | // SetCursor(AfxGetApp()->LoadStandardCursor()); |
139 | break; |
140 | case CurAction3d_DynamicRotation : |
141 | // SetCursor(AfxGetApp()->LoadStandardCursor()); |
de75ed09 |
142 | if (myHlrModeIsOn) |
143 | { |
144 | myView->SetComputedMode (Standard_False); |
145 | } |
146 | myView->StartRotation (point.x, point.y); |
5c1f974e |
147 | break; |
148 | default : |
149 | Standard_Failure::Raise(" incompatible Current Mode "); |
150 | break; |
7fd59977 |
151 | } |
5c1f974e |
152 | } |
7fd59977 |
153 | } |
154 | |
155 | void CGeometryView::OnLButtonUp(UINT nFlags, CPoint point) |
156 | { |
5c1f974e |
157 | if ( nFlags & MK_CONTROL ) |
158 | { |
159 | return; |
160 | } |
161 | else // if ( Ctrl ) |
162 | { |
163 | switch (myCurrentMode) |
164 | { |
165 | case CurAction3d_Nothing : |
166 | if (point.x == myXmin && point.y == myYmin) |
167 | { // no offset between down and up --> selectEvent |
168 | myXmax=point.x; |
169 | myYmax=point.y; |
170 | if (nFlags & MK_SHIFT ) |
171 | ShiftInputEvent(point.x,point.y); |
172 | else |
173 | InputEvent (point.x,point.y); |
174 | } else |
175 | { |
176 | myXmax=point.x; myYmax=point.y; |
177 | DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False); |
178 | if (nFlags & MK_SHIFT) |
179 | ShiftDragEvent(point.x,point.y,1); |
180 | else |
181 | DragEvent(point.x,point.y,1); |
182 | } |
183 | break; |
184 | case CurAction3d_DynamicZooming : |
185 | // SetCursor(AfxGetApp()->LoadStandardCursor()); |
186 | myCurrentMode = CurAction3d_Nothing; |
187 | break; |
188 | case CurAction3d_WindowZooming : |
189 | myXmax=point.x; myYmax=point.y; |
190 | DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False,LongDash); |
191 | if ((abs(myXmin-myXmax)>ValZWMin) || (abs(myYmin-myYmax)>ValZWMin)) |
192 | // Test if the zoom window is greater than a minimale window. |
193 | { |
194 | // Do the zoom window between Pmin and Pmax |
195 | myView->WindowFitAll(myXmin,myYmin,myXmax,myYmax); |
196 | } |
197 | myCurrentMode = CurAction3d_Nothing; |
198 | break; |
199 | case CurAction3d_DynamicPanning : |
200 | myCurrentMode = CurAction3d_Nothing; |
201 | break; |
202 | case CurAction3d_GlobalPanning : |
203 | myView->Place(point.x,point.y,myCurZoom); |
204 | myCurrentMode = CurAction3d_Nothing; |
205 | break; |
206 | case CurAction3d_DynamicRotation : |
207 | myCurrentMode = CurAction3d_Nothing; |
208 | break; |
209 | default : |
210 | Standard_Failure::Raise(" incompatible Current Mode "); |
211 | break; |
212 | } //switch (myCurrentMode) |
213 | } // else // if ( Ctrl ) |
7fd59977 |
214 | } |
215 | |
5c573e69 |
216 | void CGeometryView::OnMButtonDown(UINT nFlags, CPoint /*point*/) |
7fd59977 |
217 | { |
5c1f974e |
218 | if ( nFlags & MK_CONTROL ) |
219 | { |
220 | // Button MB2 down Control : panning init |
221 | // SetCursor(AfxGetApp()->LoadStandardCursor()); |
222 | } |
7fd59977 |
223 | } |
224 | |
5c573e69 |
225 | void CGeometryView::OnMButtonUp(UINT nFlags, CPoint /*point*/) |
7fd59977 |
226 | { |
5c1f974e |
227 | if ( nFlags & MK_CONTROL ) |
228 | { |
229 | // Button MB2 down Control : panning init |
230 | // SetCursor(AfxGetApp()->LoadStandardCursor()); |
231 | } |
7fd59977 |
232 | } |
233 | |
234 | void CGeometryView::OnRButtonDown(UINT nFlags, CPoint point) |
235 | { |
de75ed09 |
236 | if ( nFlags & MK_CONTROL ) |
5c1f974e |
237 | { |
de75ed09 |
238 | // SetCursor(AfxGetApp()->LoadStandardCursor()); |
239 | if (myHlrModeIsOn) |
240 | { |
241 | myView->SetComputedMode (Standard_False); |
242 | } |
243 | myView->StartRotation (point.x, point.y); |
5c1f974e |
244 | } |
245 | else // if ( Ctrl ) |
246 | { |
de75ed09 |
247 | Popup (point.x, point.y); |
248 | } |
7fd59977 |
249 | } |
250 | |
5c573e69 |
251 | void CGeometryView::OnRButtonUp(UINT /*nFlags*/, CPoint /*point*/) |
7fd59977 |
252 | { |
5c1f974e |
253 | SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT)); |
de75ed09 |
254 | myView->SetComputedMode (myHlrModeIsOn); |
5c1f974e |
255 | SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW)); |
7fd59977 |
256 | } |
257 | |
258 | void CGeometryView::OnMouseMove(UINT nFlags, CPoint point) |
259 | { |
5c1f974e |
260 | // ============================ LEFT BUTTON ======================= |
7fd59977 |
261 | if ( nFlags & MK_LBUTTON) |
5c1f974e |
262 | { |
263 | if ( nFlags & MK_CONTROL ) |
7fd59977 |
264 | { |
5c1f974e |
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 |
269 | myXmax = point.x; |
270 | myYmax = point.y; |
271 | } |
272 | else // if ( Ctrl ) |
273 | { |
274 | switch (myCurrentMode) |
275 | { |
276 | case CurAction3d_Nothing : |
277 | DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False); |
278 | myXmax = point.x; |
279 | myYmax = point.y; |
280 | if (nFlags & MK_SHIFT) |
281 | ShiftDragEvent(myXmax,myYmax,0); |
282 | else |
283 | DragEvent(myXmax,myYmax,0); |
284 | DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_True); |
7fd59977 |
285 | break; |
5c1f974e |
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; |
290 | break; |
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); |
295 | break; |
296 | case CurAction3d_DynamicPanning : |
297 | myView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning |
298 | myXmax = point.x; myYmax = point.y; |
299 | break; |
300 | case CurAction3d_GlobalPanning : // nothing |
7fd59977 |
301 | break; |
5c1f974e |
302 | case CurAction3d_DynamicRotation : |
303 | myView->Rotation(point.x,point.y); |
304 | myView->Redraw(); |
7fd59977 |
305 | break; |
5c1f974e |
306 | default : |
307 | Standard_Failure::Raise(" incompatible Current Mode "); |
308 | break; |
309 | }// switch (myCurrentMode) |
310 | }// if ( nFlags & MK_CONTROL ) else |
311 | } else // if ( nFlags & MK_LBUTTON) |
7fd59977 |
312 | // ============================ MIDDLE BUTTON ======================= |
313 | if ( nFlags & MK_MBUTTON) |
314 | { |
5c1f974e |
315 | if ( nFlags & MK_CONTROL ) |
316 | { |
317 | myView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning |
318 | myXmax = point.x; myYmax = point.y; |
7fd59977 |
319 | |
5c1f974e |
320 | } |
7fd59977 |
321 | } else // if ( nFlags & MK_MBUTTON) |
5c1f974e |
322 | // ============================ RIGHT BUTTON ======================= |
323 | if ( nFlags & MK_RBUTTON) |
324 | { |
325 | if ( nFlags & MK_CONTROL ) |
326 | { |
327 | myView->Rotation(point.x,point.y); |
328 | } |
329 | }else //if ( nFlags & MK_RBUTTON) |
330 | // ============================ NO BUTTON ======================= |
331 | { // No buttons |
332 | myXmax = point.x; myYmax = point.y; |
333 | if (nFlags & MK_SHIFT) |
334 | ShiftMoveEvent(point.x,point.y); |
335 | else |
336 | MoveEvent(point.x,point.y); |
337 | } |
7fd59977 |
338 | } |
339 | |
de75ed09 |
340 | void CGeometryView::OnUpdateBUTTONHlrOff (CCmdUI* pCmdUI) |
7fd59977 |
341 | { |
de75ed09 |
342 | pCmdUI->SetCheck (!myHlrModeIsOn); |
343 | pCmdUI->Enable (myHlrModeIsOn); |
7fd59977 |
344 | } |
345 | |
de75ed09 |
346 | void CGeometryView::OnUpdateBUTTONHlrOn (CCmdUI* pCmdUI) |
7fd59977 |
347 | { |
de75ed09 |
348 | pCmdUI->SetCheck (myHlrModeIsOn); |
349 | pCmdUI->Enable (!myHlrModeIsOn); |
7fd59977 |
350 | } |
351 | |
352 | void CGeometryView::OnUpdateBUTTONPanGlo(CCmdUI* pCmdUI) |
353 | { |
5c1f974e |
354 | pCmdUI->SetCheck (myCurrentMode == CurAction3d_GlobalPanning); |
355 | pCmdUI->Enable (myCurrentMode != CurAction3d_GlobalPanning); |
356 | |
7fd59977 |
357 | } |
358 | |
359 | void CGeometryView::OnUpdateBUTTONPan(CCmdUI* pCmdUI) |
360 | { |
5c1f974e |
361 | pCmdUI->SetCheck (myCurrentMode == CurAction3d_DynamicPanning); |
362 | pCmdUI->Enable (myCurrentMode != CurAction3d_DynamicPanning ); |
7fd59977 |
363 | } |
364 | |
365 | void CGeometryView::OnUpdateBUTTONZoomProg(CCmdUI* pCmdUI) |
366 | { |
5c1f974e |
367 | pCmdUI->SetCheck (myCurrentMode == CurAction3d_DynamicZooming ); |
368 | pCmdUI->Enable (myCurrentMode != CurAction3d_DynamicZooming); |
7fd59977 |
369 | } |
370 | |
371 | void CGeometryView::OnUpdateBUTTONZoomWin(CCmdUI* pCmdUI) |
372 | { |
5c1f974e |
373 | pCmdUI->SetCheck (myCurrentMode == CurAction3d_WindowZooming); |
374 | pCmdUI->Enable (myCurrentMode != CurAction3d_WindowZooming); |
7fd59977 |
375 | } |
376 | |
377 | void CGeometryView::OnUpdateBUTTONRot(CCmdUI* pCmdUI) |
378 | { |
5c1f974e |
379 | pCmdUI->SetCheck (myCurrentMode == CurAction3d_DynamicRotation); |
380 | pCmdUI->Enable (myCurrentMode != CurAction3d_DynamicRotation); |
7fd59977 |
381 | } |
382 | |
383 | //========================================================================================== |
384 | //========================================================================================== |
385 | //========================================================================================== |
386 | |
387 | //----------------------------------------------------------------------------------------- |
388 | // |
389 | //----------------------------------------------------------------------------------------- |
390 | void CGeometryView::DragEvent(const Standard_Integer x , |
5c1f974e |
391 | const Standard_Integer y , |
392 | const Standard_Integer TheState ) |
7fd59977 |
393 | { |
394 | |
5c1f974e |
395 | // TheState == -1 button down |
396 | // TheState == 0 move |
397 | // TheState == 1 button up |
7fd59977 |
398 | |
5c1f974e |
399 | static Standard_Integer theButtonDownX=0; |
400 | static Standard_Integer theButtonDownY=0; |
7fd59977 |
401 | |
5c1f974e |
402 | if (TheState == -1) |
403 | { |
404 | theButtonDownX=x; |
405 | theButtonDownY=y; |
406 | } |
7fd59977 |
407 | |
5c1f974e |
408 | if (TheState == 0) |
409 | GetDocument()->GetAISContext()->Select(theButtonDownX,theButtonDownY,x,y,myView); |
7fd59977 |
410 | } |
411 | |
412 | //----------------------------------------------------------------------------------------- |
413 | // |
414 | //----------------------------------------------------------------------------------------- |
5c573e69 |
415 | void CGeometryView::InputEvent(const Standard_Integer /*x*/, |
416 | const Standard_Integer /*y*/) |
7fd59977 |
417 | { |
5c1f974e |
418 | GetDocument()->GetAISContext()->Select(); |
7fd59977 |
419 | } |
420 | |
421 | //----------------------------------------------------------------------------------------- |
422 | // |
423 | //----------------------------------------------------------------------------------------- |
5c573e69 |
424 | void CGeometryView::MoveEvent(const Standard_Integer x, |
425 | const Standard_Integer y) |
7fd59977 |
426 | { |
5c1f974e |
427 | GetDocument()->GetAISContext()->MoveTo(x,y,myView); |
7fd59977 |
428 | } |
429 | |
430 | //----------------------------------------------------------------------------------------- |
431 | // |
432 | //----------------------------------------------------------------------------------------- |
433 | void CGeometryView::ShiftMoveEvent(const Standard_Integer x , |
5c1f974e |
434 | const Standard_Integer y ) |
7fd59977 |
435 | { |
5c1f974e |
436 | GetDocument()->GetAISContext()->MoveTo(x,y,myView); |
7fd59977 |
437 | } |
438 | |
439 | //----------------------------------------------------------------------------------------- |
440 | // |
441 | //----------------------------------------------------------------------------------------- |
442 | void CGeometryView::ShiftDragEvent(const Standard_Integer x , |
5c1f974e |
443 | const Standard_Integer y , |
444 | const Standard_Integer TheState ) |
7fd59977 |
445 | { |
5c1f974e |
446 | static Standard_Integer theButtonDownX=0; |
447 | static Standard_Integer theButtonDownY=0; |
7fd59977 |
448 | |
5c1f974e |
449 | if (TheState == -1) |
450 | { |
451 | theButtonDownX=x; |
452 | theButtonDownY=y; |
453 | } |
7fd59977 |
454 | |
5c1f974e |
455 | if (TheState == 0) |
456 | GetDocument()->GetAISContext()->ShiftSelect(theButtonDownX,theButtonDownY,x,y,myView); |
7fd59977 |
457 | } |
458 | |
459 | |
460 | //----------------------------------------------------------------------------------------- |
461 | // |
462 | //----------------------------------------------------------------------------------------- |
5c573e69 |
463 | void CGeometryView::ShiftInputEvent(const Standard_Integer /*x*/, |
464 | const Standard_Integer /*y*/) |
7fd59977 |
465 | { |
5c1f974e |
466 | GetDocument()->GetAISContext()->ShiftSelect(); |
7fd59977 |
467 | } |
468 | |
469 | //----------------------------------------------------------------------------------------- |
470 | // |
471 | //----------------------------------------------------------------------------------------- |
472 | void CGeometryView::Popup(const Standard_Integer x, |
5c1f974e |
473 | const Standard_Integer y ) |
7fd59977 |
474 | { |
475 | Standard_Integer PopupMenuNumber=0; |
476 | GetDocument()->GetAISContext()->InitCurrent(); |
477 | if (GetDocument()->GetAISContext()->MoreCurrent()) |
478 | PopupMenuNumber=1; |
479 | |
480 | CMenu menu; |
481 | VERIFY(menu.LoadMenu(IDR_Popup3D)); |
482 | CMenu* pPopup = menu.GetSubMenu(PopupMenuNumber); |
483 | ASSERT(pPopup != NULL); |
5c1f974e |
484 | |
7fd59977 |
485 | POINT winCoord = { x , y }; |
486 | Handle(WNT_Window) aWNTWindow= |
5c1f974e |
487 | Handle(WNT_Window)::DownCast(myView->Window()); |
7fd59977 |
488 | ClientToScreen ( &winCoord); |
489 | pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON , winCoord.x, winCoord.y , |
5c1f974e |
490 | AfxGetMainWnd()); |
7fd59977 |
491 | } |
492 | |
493 | |