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