7fd59977 |
1 | // OCC_2dView.cpp: implementation of the OCC_2dView class. |
2 | // |
3 | ////////////////////////////////////////////////////////////////////// |
4 | #include "stdafx.h" |
5 | |
6 | #include "OCC_2dView.h" |
7 | |
8 | #include "OCC_2dApp.h" |
9 | #include "OCC_2dDoc.h" |
10 | #include "resource2d\RectangularGrid.h" |
11 | #include "resource2d\CircularGrid.h" |
12 | |
13 | #include "Quantity_Color.hxx" |
14 | #include "Quantity_NameOfColor.hxx" |
15 | |
16 | #define ValZWMin 1 |
17 | |
18 | // the key for multi selection : |
19 | #define MULTISELECTIONKEY MK_SHIFT |
20 | |
21 | // the key for shortcut ( use to activate dynamic rotation, panning ) |
22 | #define CASCADESHORTCUTKEY MK_CONTROL |
23 | |
24 | // define in witch case you want to display the popup |
25 | #define POPUPONBUTTONDOWN |
26 | |
27 | ///////////////////////////////////////////////////////////////////////////// |
28 | // OCC_2dView |
29 | |
30 | IMPLEMENT_DYNCREATE(OCC_2dView, CView) |
31 | |
32 | BEGIN_MESSAGE_MAP(OCC_2dView, CView) |
33 | //{{AFX_MSG_MAP(OCC_2dView) |
34 | // NOTE - the ClassWizard will add and remove mapping macros here. |
35 | // DO NOT EDIT what you see in these blocks of generated code! |
36 | ON_COMMAND(ID_FILE_EXPORT_IMAGE, OnFileExportImage) |
37 | ON_COMMAND(ID_BUTTON2DGridRectLines, OnBUTTONGridRectLines) |
38 | ON_COMMAND(ID_BUTTON2DGridRectPoints, OnBUTTONGridRectPoints) |
39 | ON_COMMAND(ID_BUTTON2DGridCircLines, OnBUTTONGridCircLines) |
40 | ON_COMMAND(ID_BUTTON2DGridCircPoints, OnBUTTONGridCircPoints) |
41 | ON_COMMAND(ID_BUTTON2DGridValues, OnBUTTONGridValues) |
42 | ON_UPDATE_COMMAND_UI(ID_BUTTON2DGridValues, OnUpdateBUTTONGridValues) |
43 | ON_COMMAND(ID_BUTTON2DGridCancel, OnBUTTONGridCancel) |
44 | ON_UPDATE_COMMAND_UI(ID_BUTTON2DGridCancel, OnUpdateBUTTONGridCancel) |
45 | ON_WM_LBUTTONDOWN() |
46 | ON_WM_LBUTTONUP() |
47 | ON_WM_MBUTTONDOWN() |
48 | ON_WM_MBUTTONUP() |
49 | ON_WM_RBUTTONDOWN() |
50 | ON_WM_RBUTTONUP() |
51 | ON_WM_MOUSEMOVE() |
52 | ON_WM_SIZE() |
53 | ON_COMMAND(ID_BUTTON2DFitAll, OnBUTTONFitAll) |
54 | ON_COMMAND(ID_BUTTON2DGlobPanning, OnBUTTONGlobPanning) |
55 | ON_COMMAND(ID_BUTTON2DPanning, OnBUTTONPanning) |
56 | ON_COMMAND(ID_BUTTON2DZoomProg, OnBUTTONZoomProg) |
57 | ON_COMMAND(ID_BUTTON2DZoomWin, OnBUTTONZoomWin) |
58 | ON_UPDATE_COMMAND_UI(ID_BUTTON2DGlobPanning, OnUpdateBUTTON2DGlobPanning) |
59 | ON_UPDATE_COMMAND_UI(ID_BUTTON2DPanning, OnUpdateBUTTON2DPanning) |
60 | ON_UPDATE_COMMAND_UI(ID_BUTTON2DZoomProg, OnUpdateBUTTON2DZoomProg) |
61 | ON_UPDATE_COMMAND_UI(ID_BUTTON2DZoomWin, OnUpdateBUTTON2DZoomWin) |
62 | ON_COMMAND(ID_Modify_ChangeBackground ,OnChangeBackground) |
63 | //}}AFX_MSG_MAP |
64 | END_MESSAGE_MAP() |
65 | |
66 | ///////////////////////////////////////////////////////////////////////////// |
67 | // OCC_2dView construction/destruction |
68 | |
69 | OCC_2dView::OCC_2dView() |
70 | { |
71 | // TODO: add construction code here |
72 | myCurrentMode = CurAction2d_Nothing; |
73 | m_Pen = NULL; |
74 | } |
75 | |
76 | OCC_2dView::~OCC_2dView() |
77 | { |
78 | Handle(V2d_Viewer) aViewer = myV2dView->Viewer(); |
79 | aViewer->RemoveView(myV2dView); |
80 | if (m_Pen) delete m_Pen; |
81 | |
82 | } |
83 | |
84 | BOOL OCC_2dView::PreCreateWindow(CREATESTRUCT& cs) |
85 | { |
86 | // TODO: Modify the Window class or styles here by modifying |
87 | // the CREATESTRUCT cs |
88 | |
89 | return CView::PreCreateWindow(cs); |
90 | } |
91 | |
92 | ///////////////////////////////////////////////////////////////////////////// |
93 | // OCC_2dView drawing |
94 | |
95 | void OCC_2dView::OnDraw(CDC* pDC) |
96 | { |
97 | if (!myV2dView.IsNull()) |
98 | myV2dView->Update(); |
99 | } |
100 | |
101 | void OCC_2dView::OnInitialUpdate() |
102 | { |
103 | CView::OnInitialUpdate(); |
104 | |
105 | Handle(WNT_Window) aWNTWindow; |
106 | aWNTWindow = new WNT_Window(((OCC_2dApp*)AfxGetApp())->GetGraphicDevice(),GetSafeHwnd()); |
107 | aWNTWindow->SetBackground(Quantity_NOC_MATRAGRAY); |
108 | |
109 | Handle(WNT_WDriver) aDriver= new WNT_WDriver(aWNTWindow); |
110 | myV2dView = new V2d_View(aDriver, ((OCC_2dDoc*)GetDocument())->GetViewer2D(),0,0,50); |
111 | |
112 | // initialyse the grids dialogs |
113 | TheRectangularGridDialog.Create(CRectangularGrid::IDD, NULL); |
114 | TheCircularGridDialog.Create(CCircularGrid::IDD, NULL); |
115 | TheRectangularGridDialog.SetViewer (((OCC_2dDoc*)GetDocument())->GetViewer2D()); |
116 | TheCircularGridDialog.SetViewer (((OCC_2dDoc*)GetDocument())->GetViewer2D()); |
117 | |
118 | Standard_Integer w=100 , h=100 ; /* Debug Matrox */ |
119 | aWNTWindow->Size (w,h) ; /* Keeps me unsatisfied (rlb)..... */ |
120 | /* Resize is not supposed to be done on */ |
121 | /* Matrox */ |
122 | /* I suspect another problem elsewhere */ |
123 | ::PostMessage ( GetSafeHwnd () , WM_SIZE , SIZE_RESTORED , w + h*65536 ) ; |
124 | |
125 | } |
126 | |
127 | void OCC_2dView::OnFileExportImage() |
128 | { |
129 | CFileDialog dlg(FALSE,_T("*.BMP"),NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, |
130 | _T("BMP Files (*.BMP)|*.bmp |GIF Files (*.GIF)|*.gif | XWD Files (*.XWD)|*.xwd||"), |
131 | NULL ); |
132 | |
133 | if (dlg.DoModal() == IDOK) |
134 | { |
135 | SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT)); |
136 | CString filename = dlg.GetPathName(); |
137 | Handle(WNT_Window) aWNTWindow= |
138 | Handle(WNT_Window)::DownCast(myV2dView->Driver()->Window()); |
139 | CString ext = dlg.GetFileExt(); |
140 | if (ext == "bmp") aWNTWindow->SetOutputFormat ( WNT_TOI_BMP ); |
141 | if (ext == "gif") aWNTWindow->SetOutputFormat ( WNT_TOI_GIF ); |
142 | if (ext == "xwd") aWNTWindow->SetOutputFormat ( WNT_TOI_XWD ); |
143 | aWNTWindow->Dump ((Standard_CString)(LPCTSTR)filename); |
144 | SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW)); |
145 | } |
146 | } |
147 | |
148 | ///////////////////////////////////////////////////////////////////////////// |
149 | // OCC_2dView diagnostics |
150 | |
151 | #ifdef _DEBUG |
152 | void OCC_2dView::AssertValid() const |
153 | { |
154 | CView::AssertValid(); |
155 | } |
156 | |
157 | void OCC_2dView::Dump(CDumpContext& dc) const |
158 | { |
159 | CView::Dump(dc); |
160 | } |
161 | |
162 | CDocument* OCC_2dView::GetDocument() // non-debug version is inline |
163 | { |
164 | //ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(OCC_2dDoc))); |
165 | return m_pDocument; |
166 | } |
167 | #endif //_DEBUG |
168 | #include <V2d_RectangularGrid.hxx> |
169 | void OCC_2dView::OnBUTTONGridRectLines() |
170 | { |
171 | Handle(V2d_Viewer) aViewer = myV2dView->Viewer(); |
172 | aViewer->SetGridColor(Quantity_Color(Quantity_NOC_WHITE), Quantity_Color(Quantity_NOC_WHITE)); |
173 | aViewer->ActivateGrid(Aspect_GT_Rectangular, |
174 | Aspect_GDM_Lines); |
175 | |
176 | if (TheCircularGridDialog.IsWindowVisible()) |
177 | { |
178 | TheCircularGridDialog.ShowWindow(SW_HIDE); |
179 | TheRectangularGridDialog.UpdateValues(); |
180 | TheRectangularGridDialog.ShowWindow(SW_SHOW); |
181 | } |
182 | } |
183 | |
184 | void OCC_2dView::OnBUTTONGridRectPoints() |
185 | { |
186 | Handle(V2d_Viewer) aViewer = myV2dView->Viewer(); |
187 | aViewer->ActivateGrid(Aspect_GT_Rectangular, |
188 | Aspect_GDM_Points); |
189 | aViewer->SetGridColor(Quantity_Color(Quantity_NOC_WHITE), Quantity_Color(Quantity_NOC_WHITE)); |
190 | if (TheCircularGridDialog.IsWindowVisible()) |
191 | { |
192 | TheCircularGridDialog.ShowWindow(SW_HIDE); |
193 | TheRectangularGridDialog.UpdateValues(); |
194 | TheRectangularGridDialog.ShowWindow(SW_SHOW); |
195 | } |
196 | } |
197 | |
198 | void OCC_2dView::OnBUTTONGridCircLines() |
199 | { |
200 | Handle(V2d_Viewer) aViewer = myV2dView->Viewer(); |
201 | aViewer->SetGridColor(Quantity_Color(Quantity_NOC_WHITE), Quantity_Color(Quantity_NOC_WHITE)); |
202 | aViewer->ActivateGrid(Aspect_GT_Circular, |
203 | Aspect_GDM_Lines); |
204 | |
205 | |
206 | if (TheRectangularGridDialog.IsWindowVisible()) |
207 | { |
208 | TheRectangularGridDialog.ShowWindow(SW_HIDE); |
209 | TheCircularGridDialog.UpdateValues(); |
210 | TheCircularGridDialog.ShowWindow(SW_SHOW); |
211 | } |
212 | } |
213 | |
214 | void OCC_2dView::OnBUTTONGridCircPoints() |
215 | { |
216 | Handle(V2d_Viewer) aViewer = myV2dView->Viewer(); |
217 | aViewer->SetGridColor(Quantity_Color(Quantity_NOC_WHITE), Quantity_Color(Quantity_NOC_WHITE)); |
218 | aViewer->ActivateGrid(Aspect_GT_Circular, |
219 | Aspect_GDM_Points); |
220 | if (TheRectangularGridDialog.IsWindowVisible()) |
221 | { |
222 | TheRectangularGridDialog.ShowWindow(SW_HIDE); |
223 | TheCircularGridDialog.UpdateValues(); |
224 | TheCircularGridDialog.ShowWindow(SW_SHOW); |
225 | } |
226 | } |
227 | |
228 | void OCC_2dView::OnBUTTONGridValues() |
229 | { |
230 | Handle(V2d_Viewer) aViewer = myV2dView->Viewer(); |
231 | Aspect_GridType TheGridtype = aViewer->GridType(); |
232 | |
233 | switch( TheGridtype ) |
234 | { |
235 | case Aspect_GT_Rectangular: |
236 | TheRectangularGridDialog.UpdateValues(); |
237 | TheRectangularGridDialog.ShowWindow(SW_SHOW); |
238 | break; |
239 | case Aspect_GT_Circular: |
240 | TheCircularGridDialog.UpdateValues(); |
241 | TheCircularGridDialog.ShowWindow(SW_SHOW); |
242 | break; |
243 | default : |
244 | Standard_Failure::Raise("invalid Aspect_GridType"); |
245 | } |
246 | } |
247 | void OCC_2dView::OnUpdateBUTTONGridValues(CCmdUI* pCmdUI) |
248 | { |
249 | Handle(V2d_Viewer) aViewer = myV2dView->Viewer(); |
250 | pCmdUI-> Enable( aViewer->IsActive() ); |
251 | } |
252 | |
253 | void OCC_2dView::OnBUTTONGridCancel() |
254 | { |
255 | Handle(V2d_Viewer) aViewer = myV2dView->Viewer(); |
256 | aViewer->DeactivateGrid(); |
257 | TheRectangularGridDialog.ShowWindow(SW_HIDE); |
258 | TheCircularGridDialog.ShowWindow(SW_HIDE); |
259 | aViewer->Update(); |
260 | } |
261 | void OCC_2dView::OnUpdateBUTTONGridCancel(CCmdUI* pCmdUI) |
262 | { |
263 | Handle(V2d_Viewer) aViewer = myV2dView->Viewer(); |
264 | pCmdUI-> Enable( aViewer->IsActive() ); |
265 | } |
266 | |
267 | void OCC_2dView::OnLButtonDown(UINT nFlags, CPoint point) |
268 | { |
269 | // save the current mouse coordinate in min |
270 | myXmin=point.x; myYmin=point.y; |
271 | myXmax=point.x; myYmax=point.y; |
272 | |
273 | if ( nFlags & CASCADESHORTCUTKEY ) |
274 | { |
275 | // Button MB1 down Control :start zomming |
276 | // |
277 | } |
278 | else // if ( MULTISELECTIONKEY ) |
279 | { |
280 | switch (myCurrentMode) |
281 | { |
282 | case CurAction2d_Nothing : // start a drag |
283 | DragEvent2D(point.x,point.y,-1); |
284 | break; |
285 | case CurAction2d_DynamicZooming : // nothing |
286 | break; |
287 | case CurAction2d_WindowZooming : // nothing |
288 | break; |
289 | case CurAction2d_DynamicPanning :// nothing |
290 | break; |
291 | case CurAction2d_GlobalPanning :// nothing |
292 | break; |
293 | default : |
294 | Standard_Failure::Raise(" incompatible Current Mode "); |
295 | break; |
296 | } |
297 | } |
298 | } |
299 | |
300 | |
301 | void OCC_2dView::OnLButtonUp(UINT nFlags, CPoint point) |
302 | { |
303 | // TODO: Add your message handler code here and/or call default |
304 | if ( nFlags & CASCADESHORTCUTKEY ) |
305 | { |
306 | return; |
307 | } |
308 | else // if ( Ctrl ) |
309 | { |
310 | switch (myCurrentMode) |
311 | { |
312 | case CurAction2d_Nothing : |
313 | if (point.x == myXmin && point.y == myYmin) |
314 | { // no offset between down and up --> selectEvent |
315 | myXmax=point.x; |
316 | myYmax=point.y; |
317 | if (nFlags & MULTISELECTIONKEY ) |
318 | MultiInputEvent2D(point.x,point.y); |
319 | else |
320 | InputEvent2D (point.x,point.y); |
321 | } else |
322 | { |
323 | DrawRectangle2D(myXmin,myYmin,myXmax,myYmax,Standard_False); |
324 | myXmax=point.x; |
325 | myYmax=point.y; |
326 | if (nFlags & MULTISELECTIONKEY) |
327 | MultiDragEvent2D(point.x,point.y,1); |
328 | else |
329 | DragEvent2D(point.x,point.y,1); |
330 | } |
331 | break; |
332 | case CurAction2d_DynamicZooming : |
333 | // |
334 | myCurrentMode = CurAction2d_Nothing; |
335 | break; |
336 | case CurAction2d_WindowZooming : |
337 | myXmax=point.x; myYmax=point.y; |
338 | DrawRectangle2D(myXmin,myYmin,myXmax,myYmax,Standard_False,LongDash); |
339 | if ((abs(myXmin-myXmax)>ValZWMin) || (abs(myYmin-myYmax)>ValZWMin)) |
340 | // Test if the zoom window is greater than a minimale window. |
341 | { |
342 | // Do the zoom window between Pmin and Pmax |
343 | myV2dView->WindowFit(myXmin,myYmin,myXmax,myYmax); |
344 | } |
345 | myCurrentMode = CurAction2d_Nothing; |
346 | break; |
347 | case CurAction2d_DynamicPanning : |
348 | myCurrentMode = CurAction2d_Nothing; |
349 | break; |
350 | case CurAction2d_GlobalPanning : |
351 | myV2dView->Place(point.x,point.y,myCurZoom); |
352 | myCurrentMode = CurAction2d_Nothing; |
353 | break; |
354 | default : |
355 | Standard_Failure::Raise(" incompatible Current Mode "); |
356 | break; |
357 | } //switch (myCurrentMode) |
358 | } // else // if ( CASCADESHORTCUTKEY ) |
359 | } |
360 | |
361 | void OCC_2dView::OnMButtonDown(UINT nFlags, CPoint point) |
362 | { |
363 | if ( nFlags & CASCADESHORTCUTKEY ) |
364 | { |
365 | // Button MB2 down + CASCADESHORTCUTKEY : panning init |
366 | // |
367 | } |
368 | |
369 | } |
370 | |
371 | void OCC_2dView::OnMButtonUp(UINT nFlags, CPoint point) |
372 | { |
373 | if ( nFlags & CASCADESHORTCUTKEY ) |
374 | { |
375 | // Button MB2 up + CASCADESHORTCUTKEY : panning stop |
376 | // |
377 | } |
378 | |
379 | } |
380 | |
381 | void OCC_2dView::OnRButtonDown(UINT nFlags, CPoint point) |
382 | { |
383 | #ifdef POPUPONBUTTONDOWN |
384 | if ( !(nFlags & CASCADESHORTCUTKEY) ) |
385 | Popup2D(point.x,point.y); |
386 | #endif |
387 | } |
388 | |
389 | void OCC_2dView::OnRButtonUp(UINT nFlags, CPoint point) |
390 | { |
391 | #ifndef POPUPONBUTTONDOWN |
392 | if ( !(nFlags & CASCADESHORTCUTKEY) ) |
393 | Popup2D(point.x,point.y); |
394 | #endif |
395 | } |
396 | |
397 | void OCC_2dView::OnMouseMove(UINT nFlags, CPoint point) |
398 | { |
399 | // ============================ LEFT BUTTON ======================= |
400 | if ( (nFlags & MK_LBUTTON) &! (nFlags & MK_RBUTTON) ) // Left + Right is specific |
401 | { |
402 | if ( nFlags & CASCADESHORTCUTKEY ) |
403 | { |
404 | // move with MB1 and CASCADESHORTCUTKEY : on the dynamic zooming |
405 | // Do the zoom in function of mouse's coordinates |
406 | myV2dView->Zoom(myXmax,myYmax,point.x,point.y); |
407 | // save the current mouse coordinate in min |
408 | myXmax = point.x; |
409 | myYmax = point.y; |
410 | } |
411 | else // if ( CASCADESHORTCUTKEY ) |
412 | { |
413 | switch (myCurrentMode) |
414 | { |
415 | case CurAction2d_Nothing : |
416 | myXmax = point.x; myYmax = point.y; |
417 | DrawRectangle2D(myXmin,myYmin,myXmax,myYmax,Standard_False); |
418 | DragEvent2D(myXmax,myYmax,0); |
419 | DrawRectangle2D(myXmin,myYmin,myXmax,myYmax,Standard_True); |
420 | break; |
421 | case CurAction2d_DynamicZooming : |
422 | myV2dView->Zoom(myXmax,myYmax,point.x,point.y); |
423 | // save the current mouse coordinate in min \n"; |
424 | myXmax=point.x; myYmax=point.y; |
425 | break; |
426 | case CurAction2d_WindowZooming : |
427 | myXmax = point.x; myYmax = point.y; |
428 | DrawRectangle2D(myXmin,myYmin,myXmax,myYmax,Standard_False,LongDash); |
429 | DrawRectangle2D(myXmin,myYmin,myXmax,myYmax,Standard_True,LongDash); |
430 | break; |
431 | case CurAction2d_DynamicPanning : |
432 | myV2dView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning |
433 | myXmax = point.x; myYmax = point.y; |
434 | break; |
435 | case CurAction2d_GlobalPanning : // nothing |
436 | break; |
437 | default : |
438 | Standard_Failure::Raise(" incompatible Current Mode "); |
439 | break; |
440 | }// switch (myCurrentMode) |
441 | }// if ( nFlags & CASCADESHORTCUTKEY ) else |
442 | } else // if ( nFlags & MK_LBUTTON) |
443 | // ============================ MIDDLE BUTTON ======================= |
444 | if ( nFlags & MK_MBUTTON) |
445 | { |
446 | if ( nFlags & CASCADESHORTCUTKEY ) |
447 | { |
448 | myV2dView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning |
449 | myXmax = point.x; myYmax = point.y; |
450 | |
451 | } |
452 | } else // if ( nFlags & MK_MBUTTON) |
453 | // ============================ RIGHT BUTTON ======================= |
454 | if ( (nFlags & MK_RBUTTON) &! (nFlags & MK_LBUTTON) ) // Left + Right is specific |
455 | { |
456 | }else //if ( nFlags & MK_RBUTTON) |
457 | if ( (nFlags & MK_RBUTTON) && (nFlags & MK_LBUTTON) ) |
458 | { |
459 | // in case of Left + Right : same as Middle |
460 | if ( nFlags & CASCADESHORTCUTKEY ) |
461 | { |
462 | myV2dView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning |
463 | myXmax = point.x; myYmax = point.y; |
464 | } |
465 | }else //if ( nFlags & MK_RBUTTON)&& (nFlags & MK_LBUTTON) |
466 | // ============================ NO BUTTON ======================= |
467 | { // No buttons |
468 | myXmax = point.x; myYmax = point.y; |
469 | if (nFlags & MULTISELECTIONKEY) |
470 | MultiMoveEvent2D(point.x,point.y); |
471 | else |
472 | MoveEvent2D(point.x,point.y); |
473 | } |
474 | } |
475 | |
476 | |
477 | void OCC_2dView::OnSize(UINT nType, int cx, int cy) |
478 | { |
479 | // Take care : This fonction is call before OnInitialUpdate |
480 | if (!myV2dView.IsNull()) |
481 | myV2dView->MustBeResized(V2d_TOWRE_ENLARGE_OBJECTS); |
482 | |
483 | } |
484 | |
485 | void OCC_2dView::OnBUTTONFitAll() |
486 | { |
487 | myV2dView->Fitall(); |
488 | } |
489 | |
490 | void OCC_2dView::OnBUTTONGlobPanning() |
491 | { |
492 | //save the current zoom value |
493 | myCurZoom = myV2dView->Zoom(); |
494 | |
495 | // Do a Global Zoom |
496 | //myV2dView->Fitall(); |
497 | |
498 | // Set the mode |
499 | myCurrentMode = CurAction2d_GlobalPanning; |
500 | } |
501 | void OCC_2dView::OnBUTTONPanning() |
502 | { |
503 | myCurrentMode = CurAction2d_DynamicPanning; |
504 | } |
505 | void OCC_2dView::OnBUTTONZoomProg() |
506 | { |
507 | myCurrentMode = CurAction2d_DynamicZooming; |
508 | } |
509 | void OCC_2dView::OnBUTTONZoomWin() |
510 | { |
511 | myCurrentMode = CurAction2d_WindowZooming; |
512 | } |
513 | void OCC_2dView::OnChangeBackground() |
514 | { |
515 | Standard_Real R1, G1, B1; |
516 | Handle(Aspect_WindowDriver) aWindowDriver = myV2dView->Driver(); |
517 | Handle(Aspect_Window) aWindow = aWindowDriver->Window(); |
518 | Aspect_Background ABack = aWindow->Background(); |
519 | Quantity_Color aColor = ABack.Color(); |
520 | aColor.Values(R1,G1,B1,Quantity_TOC_RGB); |
521 | COLORREF m_clr ; |
522 | m_clr = RGB(R1*255,G1*255,B1*255); |
523 | |
524 | CColorDialog dlgColor(m_clr); |
525 | if (dlgColor.DoModal() == IDOK) |
526 | { |
527 | m_clr = dlgColor.GetColor(); |
528 | R1 = GetRValue(m_clr)/255.; |
529 | G1 = GetGValue(m_clr)/255.; |
530 | B1 = GetBValue(m_clr)/255.; |
531 | aColor.SetValues(R1,G1,B1,Quantity_TOC_RGB); |
532 | ABack.SetColor(aColor); |
533 | aWindow->SetBackground(ABack); |
534 | myV2dView->Update(); |
535 | } |
536 | } |
537 | |
538 | |
539 | void OCC_2dView::OnUpdateBUTTON2DGlobPanning(CCmdUI* pCmdUI) |
540 | { |
541 | pCmdUI->SetCheck (myCurrentMode == CurAction2d_GlobalPanning); |
542 | pCmdUI->Enable (myCurrentMode != CurAction2d_GlobalPanning); |
543 | } |
544 | |
545 | void OCC_2dView::OnUpdateBUTTON2DPanning(CCmdUI* pCmdUI) |
546 | { |
547 | pCmdUI->SetCheck (myCurrentMode == CurAction2d_DynamicPanning); |
548 | pCmdUI->Enable (myCurrentMode != CurAction2d_DynamicPanning); |
549 | } |
550 | |
551 | void OCC_2dView::OnUpdateBUTTON2DZoomProg(CCmdUI* pCmdUI) |
552 | { |
553 | pCmdUI->SetCheck (myCurrentMode == CurAction2d_DynamicZooming); |
554 | pCmdUI->Enable (myCurrentMode != CurAction2d_DynamicZooming); |
555 | } |
556 | |
557 | void OCC_2dView::OnUpdateBUTTON2DZoomWin(CCmdUI* pCmdUI) |
558 | { |
559 | pCmdUI->SetCheck (myCurrentMode == CurAction2d_WindowZooming); |
560 | pCmdUI->Enable (myCurrentMode != CurAction2d_WindowZooming); |
561 | } |
562 | |
563 | |
564 | void OCC_2dView::DrawRectangle2D(const Standard_Integer MinX , |
565 | const Standard_Integer MinY , |
566 | const Standard_Integer MaxX , |
567 | const Standard_Integer MaxY , |
568 | const Standard_Boolean Draw , |
569 | const LineStyle aLineStyle) |
570 | { |
571 | static int m_DrawMode; |
572 | if (!m_Pen && aLineStyle ==Solid ) |
573 | {m_Pen = new CPen(PS_SOLID, 1, RGB(0,0,0)); m_DrawMode = R2_MERGEPENNOT;} |
574 | else if (!m_Pen && aLineStyle ==Dot ) |
575 | {m_Pen = new CPen(PS_DOT, 1, RGB(0,0,0)); m_DrawMode = R2_XORPEN;} |
576 | else if (!m_Pen && aLineStyle == ShortDash) |
577 | {m_Pen = new CPen(PS_DASH, 1, RGB(255,0,0)); m_DrawMode = R2_XORPEN;} |
578 | else if (!m_Pen && aLineStyle == LongDash) |
579 | {m_Pen = new CPen(PS_DASH, 1, RGB(0,0,0)); m_DrawMode = R2_NOTXORPEN;} |
580 | else if (aLineStyle == Default) |
581 | { m_Pen = NULL; m_DrawMode = R2_MERGEPENNOT;} |
582 | |
583 | CPen* aOldPen; |
584 | CClientDC clientDC(this); |
585 | if (m_Pen) aOldPen = clientDC.SelectObject(m_Pen); |
586 | clientDC.SetROP2(m_DrawMode); |
587 | |
588 | static Standard_Integer StoredMinX, StoredMaxX, StoredMinY, StoredMaxY; |
589 | static Standard_Boolean m_IsVisible; |
590 | |
591 | if ( m_IsVisible && !Draw) // move or up : erase at the old position |
592 | { |
593 | clientDC.MoveTo(StoredMinX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMaxY); |
594 | clientDC.LineTo(StoredMaxX,StoredMaxY); |
595 | clientDC.LineTo(StoredMaxX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMinY); |
596 | m_IsVisible = false; |
597 | } |
598 | |
599 | StoredMinX = min ( MinX, MaxX ); |
600 | StoredMinY = min ( MinY, MaxY ); |
601 | StoredMaxX = max ( MinX, MaxX ); |
602 | StoredMaxY = max ( MinY, MaxY); |
603 | |
604 | if (Draw) // move : draw |
605 | { |
606 | clientDC.MoveTo(StoredMinX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMaxY); |
607 | clientDC.LineTo(StoredMaxX,StoredMaxY); |
608 | clientDC.LineTo(StoredMaxX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMinY); |
609 | m_IsVisible = true; |
610 | } |
611 | |
612 | if (m_Pen) clientDC.SelectObject(aOldPen); |
613 | } |
614 | |
615 | |
616 | |
617 | // ===================================================================== |
618 | |
619 | //----------------------------------------------------------------------------------------- |
620 | // |
621 | //----------------------------------------------------------------------------------------- |
622 | void OCC_2dView::DragEvent2D(const Standard_Integer x , |
623 | const Standard_Integer y , |
624 | const Standard_Integer TheState ) |
625 | { |
626 | // TheState == -1 button down |
627 | // TheState == 0 move |
628 | // TheState == 1 button up |
629 | |
630 | static Standard_Integer theButtonDownX=0; |
631 | static Standard_Integer theButtonDownY=0; |
632 | |
633 | if (TheState == -1) |
634 | { |
635 | theButtonDownX=x; |
636 | theButtonDownY=y; |
637 | } |
638 | |
639 | if (TheState == 0) |
640 | { |
641 | ((OCC_2dDoc*)GetDocument())->GetInteractiveContext2D()->MoveTo(theButtonDownX,theButtonDownY,x,y,myV2dView); |
642 | } |
643 | |
644 | if (TheState == 1) |
645 | { |
646 | ((OCC_2dDoc*)GetDocument())->GetInteractiveContext2D()->Select(true); |
647 | } |
648 | |
649 | } |
650 | |
651 | |
652 | //----------------------------------------------------------------------------------------- |
653 | // |
654 | //----------------------------------------------------------------------------------------- |
655 | void OCC_2dView::InputEvent2D(const Standard_Integer x , |
656 | const Standard_Integer y ) |
657 | { |
658 | ((OCC_2dDoc*)GetDocument())->GetInteractiveContext2D()->Select(true); |
659 | |
660 | } |
661 | |
662 | //----------------------------------------------------------------------------------------- |
663 | // |
664 | //----------------------------------------------------------------------------------------- |
665 | void OCC_2dView::MoveEvent2D(const Standard_Integer x , |
666 | const Standard_Integer y ) |
667 | { |
668 | static bool LastIsGridActiveStatus = Standard_True; |
669 | if (myV2dView->Viewer()->IsActive() ) // about the grid |
670 | { myV2dView->ShowHit(x,y); LastIsGridActiveStatus = Standard_True;} |
671 | if (!myV2dView->Viewer()->IsActive() && LastIsGridActiveStatus ) // about the grid |
672 | {myV2dView->EraseHit(); LastIsGridActiveStatus = Standard_False;} |
673 | |
674 | ((OCC_2dDoc*)GetDocument())->GetInteractiveContext2D()->MoveTo(x,y,myV2dView); |
675 | |
676 | |
677 | } |
678 | |
679 | //----------------------------------------------------------------------------------------- |
680 | // |
681 | //----------------------------------------------------------------------------------------- |
682 | void OCC_2dView::MultiMoveEvent2D(const Standard_Integer x , |
683 | const Standard_Integer y ) |
684 | { |
685 | // MultiMoveEvent2D means we move the mouse in a multi selection mode |
686 | ((OCC_2dDoc*)GetDocument())->GetInteractiveContext2D()->MoveTo(x,y,myV2dView); |
687 | |
688 | } |
689 | |
690 | //----------------------------------------------------------------------------------------- |
691 | // |
692 | //----------------------------------------------------------------------------------------- |
693 | void OCC_2dView::MultiDragEvent2D(const Standard_Integer x , |
694 | const Standard_Integer y , |
695 | const Standard_Integer TheState) |
696 | { |
697 | static Standard_Integer theButtonDownX=0; |
698 | static Standard_Integer theButtonDownY=0; |
699 | |
700 | if (TheState == -1) |
701 | { |
702 | theButtonDownX=x; |
703 | theButtonDownY=y; |
704 | } |
705 | |
706 | if (TheState == 0) |
707 | { |
708 | ((OCC_2dDoc*)GetDocument())->GetInteractiveContext2D()->MoveTo(theButtonDownX,theButtonDownY,x,y,myV2dView); |
709 | } |
710 | |
711 | if (TheState == 1) |
712 | { |
713 | ((OCC_2dDoc*)GetDocument())->GetInteractiveContext2D()->ShiftSelect(true); |
714 | } |
715 | } |
716 | |
717 | |
718 | //----------------------------------------------------------------------------------------- |
719 | // |
720 | //----------------------------------------------------------------------------------------- |
721 | void OCC_2dView::MultiInputEvent2D(const Standard_Integer x , |
722 | const Standard_Integer y ) |
723 | { |
724 | ((OCC_2dDoc*)GetDocument())->GetInteractiveContext2D()->ShiftSelect(true); |
725 | } |
726 | |
727 | //----------------------------------------------------------------------------------------- |
728 | // |
729 | //----------------------------------------------------------------------------------------- |
730 | void OCC_2dView::Popup2D(const Standard_Integer x, |
731 | const Standard_Integer y ) |
732 | { |
733 | CMenu menu; |
734 | CMenu* pPopup ; |
735 | |
736 | // load the 'normal' popup |
737 | VERIFY(menu.LoadMenu(IDR_Popup2D)); |
738 | // activate the sub menu '0' |
739 | pPopup= menu.GetSubMenu(0); |
740 | ASSERT(pPopup != NULL); |
741 | |
742 | // display the popup |
743 | POINT winCoord = { x , y }; |
744 | |
745 | |
746 | ClientToScreen ( &winCoord); |
747 | pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON , winCoord.x, winCoord.y , AfxGetMainWnd()); |
748 | |
749 | } |
750 | |
751 | void OCC_2dView::FitAll() |
752 | { |
753 | myV2dView->Fitall(); |
754 | } |