7fd59977 |
1 | // OCC_2dView.cpp: implementation of the OCC_2dView class. |
2 | // |
3 | ////////////////////////////////////////////////////////////////////// |
4 | #include "stdafx.h" |
5 | |
6 | #include "OCC_2dView.h" |
7 | |
5c1f974e |
8 | #include "OCC_App.h" |
7fd59977 |
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() |
b12e1c7b |
70 | : myCurrentMode (CurAction2d_Nothing) |
7fd59977 |
71 | { |
7fd59977 |
72 | } |
73 | |
74 | OCC_2dView::~OCC_2dView() |
75 | { |
5c1f974e |
76 | myV2dView->Remove(); |
7fd59977 |
77 | } |
78 | |
79 | BOOL OCC_2dView::PreCreateWindow(CREATESTRUCT& cs) |
80 | { |
5c1f974e |
81 | // TODO: Modify the Window class or styles here by modifying |
82 | // the CREATESTRUCT cs |
83 | return CView::PreCreateWindow(cs); |
7fd59977 |
84 | } |
85 | |
86 | ///////////////////////////////////////////////////////////////////////////// |
87 | // OCC_2dView drawing |
88 | |
5c573e69 |
89 | void OCC_2dView::OnDraw(CDC* /*pDC*/) |
7fd59977 |
90 | { |
5c1f974e |
91 | if (!myV2dView.IsNull()) |
92 | myV2dView->Update(); |
7fd59977 |
93 | } |
94 | |
95 | void OCC_2dView::OnInitialUpdate() |
96 | { |
5c1f974e |
97 | CView::OnInitialUpdate(); |
7fd59977 |
98 | |
5c1f974e |
99 | Handle(WNT_Window) aWNTWindow = new WNT_Window(GetSafeHwnd(),Quantity_NOC_MATRAGRAY); |
100 | myV2dView =((OCC_2dDoc*)GetDocument())->GetViewer2D()->CreateView(); |
101 | myV2dView->SetWindow(aWNTWindow); |
102 | myV2dView->SetZClippingType(V3d_OFF); |
103 | myV2dView->SetSurfaceDetail(V3d_TEX_ALL); |
104 | // initialize the grids dialogs |
105 | TheRectangularGridDialog.Create(CRectangularGrid::IDD, NULL); |
106 | TheCircularGridDialog.Create(CCircularGrid::IDD, NULL); |
107 | TheRectangularGridDialog.SetViewer (((OCC_2dDoc*)GetDocument())->GetViewer2D()); |
108 | TheCircularGridDialog.SetViewer (((OCC_2dDoc*)GetDocument())->GetViewer2D()); |
7fd59977 |
109 | |
5c1f974e |
110 | Standard_Integer w=100 , h=100 ; /* Debug Matrox */ |
111 | aWNTWindow->Size (w,h) ; /* Keeps me unsatisfied (rlb)..... */ |
112 | /* Resize is not supposed to be done on */ |
113 | /* Matrox */ |
114 | /* I suspect another problem elsewhere */ |
115 | ::PostMessage ( GetSafeHwnd () , WM_SIZE , SIZE_RESTORED , w + h*65536 ) ; |
7fd59977 |
116 | |
117 | } |
118 | |
119 | void OCC_2dView::OnFileExportImage() |
120 | { |
12c76bee |
121 | GetDocument()->ExportView (myV2dView); |
7fd59977 |
122 | } |
123 | |
124 | ///////////////////////////////////////////////////////////////////////////// |
125 | // OCC_2dView diagnostics |
126 | |
127 | #ifdef _DEBUG |
128 | void OCC_2dView::AssertValid() const |
129 | { |
5c1f974e |
130 | CView::AssertValid(); |
7fd59977 |
131 | } |
132 | |
133 | void OCC_2dView::Dump(CDumpContext& dc) const |
134 | { |
5c1f974e |
135 | CView::Dump(dc); |
7fd59977 |
136 | } |
137 | |
5c1f974e |
138 | OCC_2dDoc* OCC_2dView::GetDocument() // non-debug version is inline |
7fd59977 |
139 | { |
5c1f974e |
140 | //ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(OCC_2dDoc))); |
141 | return (OCC_2dDoc*)m_pDocument; |
7fd59977 |
142 | } |
143 | #endif //_DEBUG |
7fd59977 |
144 | void OCC_2dView::OnBUTTONGridRectLines() |
145 | { |
5c1f974e |
146 | Handle(V3d_Viewer) aViewer = myV2dView->Viewer(); |
a577aaab |
147 | Handle(Graphic3d_AspectMarker3d) aGridAspect = new Graphic3d_AspectMarker3d(Aspect_TOM_RING1,Quantity_NOC_WHITE,2); |
5c1f974e |
148 | aViewer->SetGridEcho(aGridAspect); |
149 | Standard_Integer aWidth=0, aHeight=0, anOffset=0; |
150 | myV2dView->Window()->Size(aWidth,aHeight); |
151 | aViewer->SetRectangularGridGraphicValues(aWidth,aHeight,anOffset); |
152 | aViewer->ActivateGrid(Aspect_GT_Rectangular, Aspect_GDM_Lines); |
153 | FitAll(); |
b12e1c7b |
154 | |
7fd59977 |
155 | if (TheCircularGridDialog.IsWindowVisible()) |
156 | { |
157 | TheCircularGridDialog.ShowWindow(SW_HIDE); |
158 | TheRectangularGridDialog.UpdateValues(); |
159 | TheRectangularGridDialog.ShowWindow(SW_SHOW); |
160 | } |
161 | } |
162 | |
163 | void OCC_2dView::OnBUTTONGridRectPoints() |
164 | { |
5c1f974e |
165 | Handle(V3d_Viewer) aViewer = myV2dView->Viewer(); |
a577aaab |
166 | Handle(Graphic3d_AspectMarker3d) aGridAspect = new Graphic3d_AspectMarker3d(Aspect_TOM_RING1,Quantity_NOC_WHITE,2); |
5c1f974e |
167 | aViewer->SetGridEcho(aGridAspect); |
168 | Standard_Integer aWidth=0, aHeight=0, anOffset=0; |
169 | myV2dView->Window()->Size(aWidth,aHeight); |
170 | aViewer->SetRectangularGridGraphicValues(aWidth,aHeight,anOffset); |
171 | aViewer->ActivateGrid(Aspect_GT_Rectangular, Aspect_GDM_Points); |
172 | FitAll(); |
173 | |
7fd59977 |
174 | if (TheCircularGridDialog.IsWindowVisible()) |
175 | { |
176 | TheCircularGridDialog.ShowWindow(SW_HIDE); |
177 | TheRectangularGridDialog.UpdateValues(); |
178 | TheRectangularGridDialog.ShowWindow(SW_SHOW); |
179 | } |
180 | } |
181 | |
182 | void OCC_2dView::OnBUTTONGridCircLines() |
183 | { |
5c1f974e |
184 | Handle(V3d_Viewer) aViewer = myV2dView->Viewer(); |
a577aaab |
185 | Handle(Graphic3d_AspectMarker3d) aGridAspect = new Graphic3d_AspectMarker3d(Aspect_TOM_RING1,Quantity_NOC_WHITE,2); |
5c1f974e |
186 | aViewer->SetGridEcho(aGridAspect); |
187 | Standard_Integer aWidth=0, aHeight=0, anOffset=0; |
188 | myV2dView->Window()->Size(aWidth,aHeight); |
189 | aViewer->SetCircularGridGraphicValues(aWidth>aHeight?aWidth:aHeight,anOffset); |
190 | aViewer->ActivateGrid(Aspect_GT_Circular, Aspect_GDM_Lines); |
191 | FitAll(); |
7fd59977 |
192 | |
193 | |
194 | if (TheRectangularGridDialog.IsWindowVisible()) |
195 | { |
196 | TheRectangularGridDialog.ShowWindow(SW_HIDE); |
197 | TheCircularGridDialog.UpdateValues(); |
198 | TheCircularGridDialog.ShowWindow(SW_SHOW); |
199 | } |
200 | } |
201 | |
202 | void OCC_2dView::OnBUTTONGridCircPoints() |
203 | { |
5c1f974e |
204 | Handle(V3d_Viewer) aViewer = myV2dView->Viewer(); |
a577aaab |
205 | Handle(Graphic3d_AspectMarker3d) aGridAspect = new Graphic3d_AspectMarker3d(Aspect_TOM_RING1,Quantity_NOC_WHITE,2); |
5c1f974e |
206 | aViewer->SetGridEcho(aGridAspect); |
207 | Standard_Integer aWidth=0, aHeight=0, anOffset=0; |
208 | myV2dView->Window()->Size(aWidth,aHeight); |
209 | aViewer->SetCircularGridGraphicValues(aWidth>aHeight?aWidth:aHeight,anOffset); |
210 | aViewer->ActivateGrid(Aspect_GT_Circular, Aspect_GDM_Points); |
211 | FitAll(); |
7fd59977 |
212 | if (TheRectangularGridDialog.IsWindowVisible()) |
213 | { |
214 | TheRectangularGridDialog.ShowWindow(SW_HIDE); |
215 | TheCircularGridDialog.UpdateValues(); |
216 | TheCircularGridDialog.ShowWindow(SW_SHOW); |
217 | } |
218 | } |
219 | |
220 | void OCC_2dView::OnBUTTONGridValues() |
221 | { |
5c1f974e |
222 | Handle(V3d_Viewer) aViewer = myV2dView->Viewer(); |
7fd59977 |
223 | Aspect_GridType TheGridtype = aViewer->GridType(); |
224 | |
225 | switch( TheGridtype ) |
226 | { |
5c1f974e |
227 | case Aspect_GT_Rectangular: |
228 | TheRectangularGridDialog.UpdateValues(); |
229 | TheRectangularGridDialog.ShowWindow(SW_SHOW); |
230 | break; |
231 | case Aspect_GT_Circular: |
232 | TheCircularGridDialog.UpdateValues(); |
233 | TheCircularGridDialog.ShowWindow(SW_SHOW); |
234 | break; |
235 | default : |
236 | Standard_Failure::Raise("invalid Aspect_GridType"); |
7fd59977 |
237 | } |
238 | } |
239 | void OCC_2dView::OnUpdateBUTTONGridValues(CCmdUI* pCmdUI) |
240 | { |
5c1f974e |
241 | Handle(V3d_Viewer) aViewer = myV2dView->Viewer(); |
7fd59977 |
242 | pCmdUI-> Enable( aViewer->IsActive() ); |
243 | } |
244 | |
245 | void OCC_2dView::OnBUTTONGridCancel() |
5c1f974e |
246 | { |
247 | Handle(V3d_Viewer) aViewer = myV2dView->Viewer(); |
7fd59977 |
248 | aViewer->DeactivateGrid(); |
249 | TheRectangularGridDialog.ShowWindow(SW_HIDE); |
250 | TheCircularGridDialog.ShowWindow(SW_HIDE); |
251 | aViewer->Update(); |
252 | } |
253 | void OCC_2dView::OnUpdateBUTTONGridCancel(CCmdUI* pCmdUI) |
254 | { |
5c1f974e |
255 | Handle(V3d_Viewer) aViewer = myV2dView->Viewer(); |
7fd59977 |
256 | pCmdUI-> Enable( aViewer->IsActive() ); |
257 | } |
258 | |
259 | void OCC_2dView::OnLButtonDown(UINT nFlags, CPoint point) |
260 | { |
261 | // save the current mouse coordinate in min |
262 | myXmin=point.x; myYmin=point.y; |
263 | myXmax=point.x; myYmax=point.y; |
264 | |
265 | if ( nFlags & CASCADESHORTCUTKEY ) |
5c1f974e |
266 | { |
267 | // Button MB1 down Control :start zomming |
268 | // |
269 | } |
270 | else // if ( MULTISELECTIONKEY ) |
271 | { |
272 | switch (myCurrentMode) |
273 | { |
274 | case CurAction2d_Nothing : // start a drag |
275 | DragEvent2D(point.x,point.y,-1); |
276 | break; |
277 | case CurAction2d_DynamicZooming : // nothing |
278 | break; |
279 | case CurAction2d_WindowZooming : // nothing |
280 | break; |
281 | case CurAction2d_DynamicPanning :// nothing |
282 | break; |
283 | case CurAction2d_GlobalPanning :// nothing |
284 | break; |
285 | default : |
286 | Standard_Failure::Raise(" incompatible Current Mode "); |
287 | break; |
7fd59977 |
288 | } |
5c1f974e |
289 | } |
7fd59977 |
290 | } |
291 | |
292 | |
293 | void OCC_2dView::OnLButtonUp(UINT nFlags, CPoint point) |
294 | { |
5c1f974e |
295 | // TODO: Add your message handler code here and/or call default |
296 | if ( nFlags & CASCADESHORTCUTKEY ) |
297 | { |
298 | return; |
299 | } |
300 | else // if ( Ctrl ) |
301 | { |
b12e1c7b |
302 | const Handle(AIS_InteractiveContext)& aContext = GetDocument()->GetAISContext(); |
5c1f974e |
303 | switch (myCurrentMode) |
304 | { |
305 | case CurAction2d_Nothing : |
306 | if (point.x == myXmin && point.y == myYmin) |
307 | { // no offset between down and up --> selectEvent |
308 | myXmax=point.x; |
309 | myYmax=point.y; |
310 | if (nFlags & MULTISELECTIONKEY ) |
311 | MultiInputEvent2D(point.x,point.y); |
312 | else |
313 | InputEvent2D (point.x,point.y); |
314 | } else |
315 | { |
b12e1c7b |
316 | drawRectangle (myXmin, myYmin, myXmax, myYmax, aContext, Standard_False); |
5c1f974e |
317 | myXmax=point.x; |
318 | myYmax=point.y; |
319 | if (nFlags & MULTISELECTIONKEY) |
320 | MultiDragEvent2D(point.x,point.y,1); |
321 | else |
322 | DragEvent2D(point.x,point.y,1); |
323 | } |
324 | break; |
325 | case CurAction2d_DynamicZooming : |
326 | // |
327 | myCurrentMode = CurAction2d_Nothing; |
328 | break; |
329 | case CurAction2d_WindowZooming : |
330 | myXmax=point.x; myYmax=point.y; |
b12e1c7b |
331 | drawRectangle (myXmin, myYmin, myXmax, myYmax, aContext, Standard_False); |
5c1f974e |
332 | if ((abs(myXmin-myXmax)>ValZWMin) || (abs(myYmin-myYmax)>ValZWMin)) |
333 | // Test if the zoom window is greater than a minimale window. |
334 | { |
335 | // Do the zoom window between Pmin and Pmax |
336 | myV2dView->WindowFit(myXmin,myYmin,myXmax,myYmax); |
337 | } |
338 | myCurrentMode = CurAction2d_Nothing; |
339 | break; |
340 | case CurAction2d_DynamicPanning : |
341 | myCurrentMode = CurAction2d_Nothing; |
342 | break; |
343 | case CurAction2d_GlobalPanning : |
344 | myV2dView->Place(point.x,point.y,myCurZoom); |
345 | myCurrentMode = CurAction2d_Nothing; |
346 | break; |
347 | default : |
348 | Standard_Failure::Raise(" incompatible Current Mode "); |
349 | break; |
350 | } //switch (myCurrentMode) |
351 | } // else // if ( CASCADESHORTCUTKEY ) |
7fd59977 |
352 | } |
353 | |
5c573e69 |
354 | void OCC_2dView::OnMButtonDown(UINT nFlags, CPoint /*point*/) |
7fd59977 |
355 | { |
5c1f974e |
356 | if ( nFlags & CASCADESHORTCUTKEY ) |
357 | { |
358 | // Button MB2 down + CASCADESHORTCUTKEY : panning init |
359 | // |
360 | } |
7fd59977 |
361 | } |
362 | |
5c573e69 |
363 | void OCC_2dView::OnMButtonUp(UINT nFlags, CPoint /*point*/) |
7fd59977 |
364 | { |
5c1f974e |
365 | if ( nFlags & CASCADESHORTCUTKEY ) |
366 | { |
367 | // Button MB2 up + CASCADESHORTCUTKEY : panning stop |
368 | } |
7fd59977 |
369 | } |
370 | |
371 | void OCC_2dView::OnRButtonDown(UINT nFlags, CPoint point) |
372 | { |
373 | #ifdef POPUPONBUTTONDOWN |
374 | if ( !(nFlags & CASCADESHORTCUTKEY) ) |
5c1f974e |
375 | Popup2D(point.x,point.y); |
7fd59977 |
376 | #endif |
377 | } |
378 | |
5c573e69 |
379 | void OCC_2dView::OnRButtonUp(UINT |
380 | #ifndef POPUPONBUTTONDOWN |
381 | nFlags |
382 | #endif |
383 | , CPoint |
384 | #ifndef POPUPONBUTTONDOWN |
385 | point |
386 | #endif |
387 | ) |
7fd59977 |
388 | { |
389 | #ifndef POPUPONBUTTONDOWN |
5c573e69 |
390 | if ( !(nFlags & CASCADESHORTCUTKEY) ) |
5c1f974e |
391 | Popup2D(point.x,point.y); |
7fd59977 |
392 | #endif |
393 | } |
394 | |
395 | void OCC_2dView::OnMouseMove(UINT nFlags, CPoint point) |
396 | { |
5c1f974e |
397 | // ============================ LEFT BUTTON ======================= |
7fd59977 |
398 | if ( (nFlags & MK_LBUTTON) &! (nFlags & MK_RBUTTON) ) // Left + Right is specific |
5c1f974e |
399 | { |
400 | if ( nFlags & CASCADESHORTCUTKEY ) |
7fd59977 |
401 | { |
5c1f974e |
402 | // move with MB1 and CASCADESHORTCUTKEY : on the dynamic zooming |
403 | // Do the zoom in function of mouse's coordinates |
404 | myV2dView->Zoom(myXmax,myYmax,point.x,point.y); |
405 | // save the current mouse coordinate in min |
406 | myXmax = point.x; |
407 | myYmax = point.y; |
408 | } |
409 | else // if ( CASCADESHORTCUTKEY ) |
410 | { |
b12e1c7b |
411 | const Handle(AIS_InteractiveContext)& aContext = GetDocument()->GetAISContext(); |
5c1f974e |
412 | switch (myCurrentMode) |
413 | { |
414 | case CurAction2d_Nothing : |
415 | myXmax = point.x; myYmax = point.y; |
5c1f974e |
416 | DragEvent2D(myXmax,myYmax,0); |
b12e1c7b |
417 | drawRectangle (myXmin, myYmin, myXmax, myYmax, aContext); |
5c1f974e |
418 | break; |
419 | case CurAction2d_DynamicZooming : |
420 | myV2dView->Zoom(myXmax,myYmax,point.x,point.y); |
421 | // save the current mouse coordinate in min \n"; |
422 | myXmax=point.x; myYmax=point.y; |
7fd59977 |
423 | break; |
5c1f974e |
424 | case CurAction2d_WindowZooming : |
b12e1c7b |
425 | myXmax = point.x; |
426 | myYmax = point.y; |
427 | drawRectangle (myXmin, myYmin, myXmax, myYmax, aContext); |
7fd59977 |
428 | break; |
5c1f974e |
429 | case CurAction2d_DynamicPanning : |
430 | myV2dView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning |
431 | myXmax = point.x; myYmax = point.y; |
432 | break; |
b12e1c7b |
433 | case CurAction2d_GlobalPanning : // nothing |
5c1f974e |
434 | break; |
435 | default : |
436 | Standard_Failure::Raise(" incompatible Current Mode "); |
437 | break; |
438 | }// switch (myCurrentMode) |
439 | }// if ( nFlags & CASCADESHORTCUTKEY ) else |
440 | } else // if ( nFlags & MK_LBUTTON) |
7fd59977 |
441 | // ============================ MIDDLE BUTTON ======================= |
442 | if ( nFlags & MK_MBUTTON) |
443 | { |
5c1f974e |
444 | if ( nFlags & CASCADESHORTCUTKEY ) |
445 | { |
446 | myV2dView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning |
447 | myXmax = point.x; myYmax = point.y; |
7fd59977 |
448 | |
5c1f974e |
449 | } |
7fd59977 |
450 | } else // if ( nFlags & MK_MBUTTON) |
5c1f974e |
451 | // ============================ RIGHT BUTTON ======================= |
452 | if ( (nFlags & MK_RBUTTON) &! (nFlags & MK_LBUTTON) ) // Left + Right is specific |
453 | { |
454 | }else //if ( nFlags & MK_RBUTTON) |
455 | if ( (nFlags & MK_RBUTTON) && (nFlags & MK_LBUTTON) ) |
456 | { |
457 | // in case of Left + Right : same as Middle |
458 | if ( nFlags & CASCADESHORTCUTKEY ) |
459 | { |
460 | myV2dView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning |
461 | myXmax = point.x; myYmax = point.y; |
462 | } |
463 | }else //if ( nFlags & MK_RBUTTON)&& (nFlags & MK_LBUTTON) |
464 | // ============================ NO BUTTON ======================= |
465 | { // No buttons |
466 | myXmax = point.x; myYmax = point.y; |
467 | if (nFlags & MULTISELECTIONKEY) |
468 | MultiMoveEvent2D(point.x,point.y); |
469 | else |
470 | MoveEvent2D(point.x,point.y); |
471 | } |
7fd59977 |
472 | } |
473 | |
474 | |
5c573e69 |
475 | void OCC_2dView::OnSize(UINT /*nType*/, int /*cx*/, int /*cy*/) |
7fd59977 |
476 | { |
5c1f974e |
477 | // Take care : This fonction is call before OnInitialUpdate |
478 | if (!myV2dView.IsNull()) |
479 | myV2dView->MustBeResized(); |
7fd59977 |
480 | |
481 | } |
482 | |
483 | void OCC_2dView::OnBUTTONFitAll() |
484 | { |
5c1f974e |
485 | myV2dView->FitAll(); |
7fd59977 |
486 | } |
487 | |
488 | void OCC_2dView::OnBUTTONGlobPanning() |
489 | { |
490 | //save the current zoom value |
5c1f974e |
491 | myCurZoom = myV2dView->Scale(); |
7fd59977 |
492 | |
493 | // Do a Global Zoom |
5c1f974e |
494 | myV2dView->FitAll(); |
7fd59977 |
495 | |
496 | // Set the mode |
497 | myCurrentMode = CurAction2d_GlobalPanning; |
498 | } |
499 | void OCC_2dView::OnBUTTONPanning() |
500 | { |
501 | myCurrentMode = CurAction2d_DynamicPanning; |
502 | } |
503 | void OCC_2dView::OnBUTTONZoomProg() |
504 | { |
505 | myCurrentMode = CurAction2d_DynamicZooming; |
506 | } |
507 | void OCC_2dView::OnBUTTONZoomWin() |
508 | { |
509 | myCurrentMode = CurAction2d_WindowZooming; |
510 | } |
511 | void OCC_2dView::OnChangeBackground() |
512 | { |
5c1f974e |
513 | Standard_Real R1, G1, B1; |
514 | Handle(Aspect_Window) aWindow = myV2dView->Window(); |
515 | Aspect_Background ABack = aWindow->Background(); |
516 | Quantity_Color aColor = ABack.Color(); |
517 | aColor.Values(R1,G1,B1,Quantity_TOC_RGB); |
518 | COLORREF m_clr ; |
519 | m_clr = RGB(R1*255,G1*255,B1*255); |
520 | |
521 | CColorDialog dlgColor(m_clr); |
522 | if (dlgColor.DoModal() == IDOK) |
523 | { |
524 | m_clr = dlgColor.GetColor(); |
525 | R1 = GetRValue(m_clr)/255.; |
526 | G1 = GetGValue(m_clr)/255.; |
527 | B1 = GetBValue(m_clr)/255.; |
528 | aColor.SetValues(R1,G1,B1,Quantity_TOC_RGB); |
529 | myV2dView->SetBackgroundColor(aColor); |
530 | myV2dView->Update(); |
531 | } |
7fd59977 |
532 | } |
533 | |
534 | |
535 | void OCC_2dView::OnUpdateBUTTON2DGlobPanning(CCmdUI* pCmdUI) |
536 | { |
5c1f974e |
537 | pCmdUI->SetCheck (myCurrentMode == CurAction2d_GlobalPanning); |
538 | pCmdUI->Enable (myCurrentMode != CurAction2d_GlobalPanning); |
7fd59977 |
539 | } |
540 | |
541 | void OCC_2dView::OnUpdateBUTTON2DPanning(CCmdUI* pCmdUI) |
542 | { |
5c1f974e |
543 | pCmdUI->SetCheck (myCurrentMode == CurAction2d_DynamicPanning); |
544 | pCmdUI->Enable (myCurrentMode != CurAction2d_DynamicPanning); |
7fd59977 |
545 | } |
546 | |
547 | void OCC_2dView::OnUpdateBUTTON2DZoomProg(CCmdUI* pCmdUI) |
548 | { |
5c1f974e |
549 | pCmdUI->SetCheck (myCurrentMode == CurAction2d_DynamicZooming); |
550 | pCmdUI->Enable (myCurrentMode != CurAction2d_DynamicZooming); |
7fd59977 |
551 | } |
552 | |
553 | void OCC_2dView::OnUpdateBUTTON2DZoomWin(CCmdUI* pCmdUI) |
554 | { |
5c1f974e |
555 | pCmdUI->SetCheck (myCurrentMode == CurAction2d_WindowZooming); |
556 | pCmdUI->Enable (myCurrentMode != CurAction2d_WindowZooming); |
7fd59977 |
557 | } |
558 | |
7fd59977 |
559 | // ===================================================================== |
560 | |
561 | //----------------------------------------------------------------------------------------- |
562 | // |
563 | //----------------------------------------------------------------------------------------- |
5c1f974e |
564 | void OCC_2dView::DragEvent2D(const Standard_Integer x, |
565 | const Standard_Integer y, |
566 | const Standard_Integer TheState) |
7fd59977 |
567 | { |
568 | // TheState == -1 button down |
569 | // TheState == 0 move |
570 | // TheState == 1 button up |
571 | |
5c1f974e |
572 | static Standard_Integer theButtonDownX=0; |
573 | static Standard_Integer theButtonDownY=0; |
7fd59977 |
574 | |
5c1f974e |
575 | if (TheState == -1) |
576 | { |
577 | theButtonDownX=x; |
578 | theButtonDownY=y; |
579 | } |
7fd59977 |
580 | |
581 | if (TheState == 0) |
582 | { |
5c1f974e |
583 | ((OCC_2dDoc*)GetDocument())->GetInteractiveContext()->MoveTo(x,y,myV2dView); |
584 | ((OCC_2dDoc*)GetDocument())->GetInteractiveContext()->Select(theButtonDownX,theButtonDownY,x,y,myV2dView); |
7fd59977 |
585 | } |
586 | |
587 | if (TheState == 1) |
588 | { |
5c1f974e |
589 | ((OCC_2dDoc*)GetDocument())->GetInteractiveContext()->Select(true); |
7fd59977 |
590 | } |
7fd59977 |
591 | } |
592 | |
593 | |
594 | //----------------------------------------------------------------------------------------- |
595 | // |
596 | //----------------------------------------------------------------------------------------- |
5c573e69 |
597 | void OCC_2dView::InputEvent2D(const Standard_Integer /*x*/, |
598 | const Standard_Integer /*y*/) |
7fd59977 |
599 | { |
5c1f974e |
600 | ((OCC_2dDoc*)GetDocument())->GetInteractiveContext()->Select(true); |
7fd59977 |
601 | } |
602 | |
603 | //----------------------------------------------------------------------------------------- |
604 | // |
605 | //----------------------------------------------------------------------------------------- |
5c1f974e |
606 | void OCC_2dView::MoveEvent2D(const Standard_Integer x, |
607 | const Standard_Integer y) |
7fd59977 |
608 | { |
5c1f974e |
609 | if(myV2dView->Viewer()->Grid()->IsActive()) |
610 | { |
611 | Quantity_Length aGridX=0,aGridY=0,aGridZ=0; |
612 | myV2dView->ConvertToGrid(x,y,aGridX,aGridY,aGridZ); |
613 | //View is not updated automatically in ConvertToGrid |
614 | myV2dView->Update(); |
615 | } |
616 | ((OCC_2dDoc*)GetDocument())->GetInteractiveContext()->MoveTo(x,y,myV2dView); |
7fd59977 |
617 | } |
618 | |
619 | //----------------------------------------------------------------------------------------- |
620 | // |
621 | //----------------------------------------------------------------------------------------- |
5c1f974e |
622 | void OCC_2dView::MultiMoveEvent2D(const Standard_Integer x, |
623 | const Standard_Integer y) |
7fd59977 |
624 | { |
625 | // MultiMoveEvent2D means we move the mouse in a multi selection mode |
5c1f974e |
626 | ((OCC_2dDoc*)GetDocument())->GetInteractiveContext()->MoveTo(x,y,myV2dView); |
7fd59977 |
627 | } |
628 | |
629 | //----------------------------------------------------------------------------------------- |
630 | // |
631 | //----------------------------------------------------------------------------------------- |
632 | void OCC_2dView::MultiDragEvent2D(const Standard_Integer x , |
5c1f974e |
633 | const Standard_Integer y , |
634 | const Standard_Integer TheState) |
7fd59977 |
635 | { |
5c1f974e |
636 | static Standard_Integer theButtonDownX=0; |
637 | static Standard_Integer theButtonDownY=0; |
7fd59977 |
638 | |
5c1f974e |
639 | if (TheState == -1) |
640 | { |
641 | theButtonDownX=x; |
642 | theButtonDownY=y; |
643 | } |
7fd59977 |
644 | |
645 | if (TheState == 0) |
646 | { |
5c1f974e |
647 | ((OCC_2dDoc*)GetDocument())->GetInteractiveContext()->MoveTo(x,y,myV2dView); |
648 | ((OCC_2dDoc*)GetDocument())->GetInteractiveContext()->ShiftSelect(theButtonDownX,theButtonDownY,x,y,myV2dView);; |
7fd59977 |
649 | } |
650 | |
651 | if (TheState == 1) |
652 | { |
5c1f974e |
653 | ((OCC_2dDoc*)GetDocument())->GetInteractiveContext()->ShiftSelect(true); |
7fd59977 |
654 | } |
655 | } |
656 | |
657 | |
658 | //----------------------------------------------------------------------------------------- |
659 | // |
660 | //----------------------------------------------------------------------------------------- |
5c573e69 |
661 | void OCC_2dView::MultiInputEvent2D(const Standard_Integer /*x*/, |
662 | const Standard_Integer /*y*/) |
7fd59977 |
663 | { |
5c1f974e |
664 | ((OCC_2dDoc*)GetDocument())->GetInteractiveContext()->ShiftSelect(true); |
7fd59977 |
665 | } |
666 | |
667 | //----------------------------------------------------------------------------------------- |
668 | // |
669 | //----------------------------------------------------------------------------------------- |
670 | void OCC_2dView::Popup2D(const Standard_Integer x, |
5c1f974e |
671 | const Standard_Integer y ) |
7fd59977 |
672 | { |
673 | CMenu menu; |
674 | CMenu* pPopup ; |
675 | |
676 | // load the 'normal' popup |
677 | VERIFY(menu.LoadMenu(IDR_Popup2D)); |
678 | // activate the sub menu '0' |
679 | pPopup= menu.GetSubMenu(0); |
680 | ASSERT(pPopup != NULL); |
681 | |
682 | // display the popup |
683 | POINT winCoord = { x , y }; |
7fd59977 |
684 | ClientToScreen ( &winCoord); |
685 | pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON , winCoord.x, winCoord.y , AfxGetMainWnd()); |
7fd59977 |
686 | } |
687 | |
688 | void OCC_2dView::FitAll() |
689 | { |
5c1f974e |
690 | myV2dView->FitAll(); |
7fd59977 |
691 | } |