0031431: Visualization, PrsMgr_PresentableObject - simplify HLR computing interface
[occt.git] / samples / mfc / standard / Common / OCC_2dView.cpp
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_App.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 : myCurrentMode (CurAction2d_Nothing)
71 {
72 }
73
74 OCC_2dView::~OCC_2dView()
75 {
76   myV2dView->Remove();
77 }
78
79 BOOL OCC_2dView::PreCreateWindow(CREATESTRUCT& cs)
80 {
81   // TODO: Modify the Window class or styles here by modifying
82   //  the CREATESTRUCT cs
83   cs.lpszClass = ::AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | CS_OWNDC, ::LoadCursor(NULL, IDC_ARROW), NULL, NULL);
84   return CView::PreCreateWindow(cs);
85 }
86
87 /////////////////////////////////////////////////////////////////////////////
88 // OCC_2dView drawing
89
90 void OCC_2dView::OnDraw(CDC* /*pDC*/)
91 {
92   if (!myV2dView.IsNull())
93     myV2dView->Update();
94 }
95
96 void OCC_2dView::OnInitialUpdate()
97 {
98   CView::OnInitialUpdate();
99
100   Handle(WNT_Window) aWNTWindow = new WNT_Window(GetSafeHwnd(),Quantity_NOC_MATRAGRAY);   
101   myV2dView =((OCC_2dDoc*)GetDocument())->GetViewer2D()->CreateView();
102   myV2dView->SetWindow(aWNTWindow);
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());
108
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 ) ;
115
116 }
117
118 void OCC_2dView::OnFileExportImage()
119 {
120   GetDocument()->ExportView (myV2dView);
121 }
122
123 /////////////////////////////////////////////////////////////////////////////
124 // OCC_2dView diagnostics
125
126 #ifdef _DEBUG
127 void OCC_2dView::AssertValid() const
128 {
129   CView::AssertValid();
130 }
131
132 void OCC_2dView::Dump(CDumpContext& dc) const
133 {
134   CView::Dump(dc);
135 }
136
137 OCC_2dDoc* OCC_2dView::GetDocument() // non-debug version is inline
138 {
139   //ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(OCC_2dDoc)));
140   return (OCC_2dDoc*)m_pDocument;
141 }
142 #endif //_DEBUG
143 void OCC_2dView::OnBUTTONGridRectLines() 
144 {
145   Handle(V3d_Viewer) aViewer = myV2dView->Viewer();
146   Handle(Graphic3d_AspectMarker3d) aGridAspect = new Graphic3d_AspectMarker3d(Aspect_TOM_RING1,Quantity_NOC_WHITE,2);
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();
153
154   if (TheCircularGridDialog.IsWindowVisible())
155   {
156     TheCircularGridDialog.ShowWindow(SW_HIDE);
157     TheRectangularGridDialog.UpdateValues();
158     TheRectangularGridDialog.ShowWindow(SW_SHOW);
159   }
160 }
161
162 void OCC_2dView::OnBUTTONGridRectPoints() 
163 {
164   Handle(V3d_Viewer) aViewer = myV2dView->Viewer();
165   Handle(Graphic3d_AspectMarker3d) aGridAspect = new Graphic3d_AspectMarker3d(Aspect_TOM_RING1,Quantity_NOC_WHITE,2);
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
173   if (TheCircularGridDialog.IsWindowVisible())
174   {
175     TheCircularGridDialog.ShowWindow(SW_HIDE);
176     TheRectangularGridDialog.UpdateValues();
177     TheRectangularGridDialog.ShowWindow(SW_SHOW);
178   }
179 }
180
181 void OCC_2dView::OnBUTTONGridCircLines() 
182 {
183   Handle(V3d_Viewer) aViewer = myV2dView->Viewer();
184   Handle(Graphic3d_AspectMarker3d) aGridAspect = new Graphic3d_AspectMarker3d(Aspect_TOM_RING1,Quantity_NOC_WHITE,2);
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();
191  
192
193   if (TheRectangularGridDialog.IsWindowVisible())
194   {
195     TheRectangularGridDialog.ShowWindow(SW_HIDE);
196     TheCircularGridDialog.UpdateValues();
197     TheCircularGridDialog.ShowWindow(SW_SHOW);
198   }
199 }
200
201 void OCC_2dView::OnBUTTONGridCircPoints() 
202 {
203   Handle(V3d_Viewer) aViewer = myV2dView->Viewer();
204   Handle(Graphic3d_AspectMarker3d) aGridAspect = new Graphic3d_AspectMarker3d(Aspect_TOM_RING1,Quantity_NOC_WHITE,2);
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();
211   if (TheRectangularGridDialog.IsWindowVisible())
212   {
213     TheRectangularGridDialog.ShowWindow(SW_HIDE);
214     TheCircularGridDialog.UpdateValues();
215     TheCircularGridDialog.ShowWindow(SW_SHOW);
216   }
217 }
218
219 void OCC_2dView::OnBUTTONGridValues() 
220 {
221   Handle(V3d_Viewer) aViewer = myV2dView->Viewer();
222   Aspect_GridType  TheGridtype = aViewer->GridType();
223
224   switch( TheGridtype ) 
225   {
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     throw Standard_Failure("invalid Aspect_GridType");
236   }
237 }
238 void OCC_2dView::OnUpdateBUTTONGridValues(CCmdUI* pCmdUI) 
239 {
240   Handle(V3d_Viewer) aViewer = myV2dView->Viewer();
241   pCmdUI-> Enable( aViewer->IsActive() );
242 }
243
244 void OCC_2dView::OnBUTTONGridCancel() 
245 {
246   Handle(V3d_Viewer) aViewer = myV2dView->Viewer();
247   aViewer->DeactivateGrid();
248   TheRectangularGridDialog.ShowWindow(SW_HIDE);
249   TheCircularGridDialog.ShowWindow(SW_HIDE);
250   aViewer->Update();
251 }
252 void OCC_2dView::OnUpdateBUTTONGridCancel(CCmdUI* pCmdUI) 
253 {
254   Handle(V3d_Viewer) aViewer = myV2dView->Viewer();
255   pCmdUI-> Enable( aViewer->IsActive() );       
256 }
257
258 void 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 ) 
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       throw Standard_Failure(" incompatible Current Mode ");
286       break;
287     }
288   }
289 }
290
291
292 void OCC_2dView::OnLButtonUp(UINT nFlags, CPoint point) 
293 {
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   {
301     const Handle(AIS_InteractiveContext)& aContext = GetDocument()->GetAISContext();
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       {
315         drawRectangle (myXmin, myYmin, myXmax, myYmax, aContext, Standard_False);
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;
330       drawRectangle (myXmin, myYmin, myXmax, myYmax, aContext, Standard_False);
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       throw Standard_Failure(" incompatible Current Mode ");
348       break;
349     } //switch (myCurrentMode)
350   } //  else // if ( CASCADESHORTCUTKEY )       
351 }
352
353 void OCC_2dView::OnMButtonDown(UINT nFlags, CPoint /*point*/) 
354 {
355   if ( nFlags & CASCADESHORTCUTKEY ) 
356   {
357     // Button MB2 down + CASCADESHORTCUTKEY : panning init  
358     // 
359   }
360 }
361
362 void OCC_2dView::OnMButtonUp(UINT nFlags, CPoint /*point*/) 
363 {
364   if ( nFlags & CASCADESHORTCUTKEY ) 
365   {
366     // Button MB2 up + CASCADESHORTCUTKEY : panning stop 
367   }
368 }
369
370 void OCC_2dView::OnRButtonDown(UINT nFlags, CPoint point) 
371 {
372 #ifdef POPUPONBUTTONDOWN
373    if ( !(nFlags & CASCADESHORTCUTKEY) ) 
374      Popup2D(point.x,point.y);
375 #endif
376 }
377
378 void OCC_2dView::OnRButtonUp(UINT 
379 #ifndef POPUPONBUTTONDOWN
380                              nFlags
381 #endif
382                              , CPoint 
383 #ifndef POPUPONBUTTONDOWN
384                              point
385 #endif
386                              )
387 {
388 #ifndef POPUPONBUTTONDOWN
389    if ( !(nFlags & CASCADESHORTCUTKEY) )
390     Popup2D(point.x,point.y);
391 #endif
392 }
393
394 void OCC_2dView::OnMouseMove(UINT nFlags, CPoint point) 
395 {
396   //   ============================  LEFT BUTTON =======================
397   if ( (nFlags & MK_LBUTTON) &! (nFlags & MK_RBUTTON) ) // Left + Right is specific
398   {
399     if ( nFlags & CASCADESHORTCUTKEY ) 
400     {
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     {
410       const Handle(AIS_InteractiveContext)& aContext = GetDocument()->GetAISContext();
411       switch (myCurrentMode)
412       {
413       case CurAction2d_Nothing :
414         myXmax = point.x;     myYmax = point.y; 
415         DragEvent2D(myXmax,myYmax,0);  
416         drawRectangle (myXmin, myYmin, myXmax, myYmax, aContext);
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;
422         break;
423       case CurAction2d_WindowZooming :
424         myXmax = point.x;
425         myYmax = point.y;
426         drawRectangle (myXmin, myYmin, myXmax, myYmax, aContext);
427         break;
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;
432       case CurAction2d_GlobalPanning : // nothing
433         break;
434       default :
435         throw Standard_Failure(" incompatible Current Mode ");
436         break;
437       }//  switch (myCurrentMode)
438     }// if ( nFlags & CASCADESHORTCUTKEY )  else 
439   } else //   if ( nFlags & MK_LBUTTON) 
440     //   ============================  MIDDLE BUTTON =======================
441     if ( nFlags & MK_MBUTTON)
442     {
443       if ( nFlags & CASCADESHORTCUTKEY ) 
444       {
445         myV2dView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
446         myXmax = point.x; myYmax = point.y;     
447
448       }
449     } else //  if ( nFlags & MK_MBUTTON)
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         }
471 }
472
473
474 void OCC_2dView::OnSize(UINT nType, int cx, int cy)
475 {
476   OCC_BaseView::OnSize (nType, cx, cy);
477   // Take care : This fonction is call before OnInitialUpdate
478   if (!myV2dView.IsNull())
479     myV2dView->MustBeResized(); 
480 }
481
482 void OCC_2dView::OnBUTTONFitAll() 
483 {
484   myV2dView->FitAll();
485 }
486
487 void OCC_2dView::OnBUTTONGlobPanning() 
488 {
489   //save the current zoom value
490   myCurZoom = myV2dView->Scale();  
491
492   // Do a Global Zoom 
493   myV2dView->FitAll();
494
495   // Set the mode
496   myCurrentMode = CurAction2d_GlobalPanning;
497 }
498 void OCC_2dView::OnBUTTONPanning() 
499 {
500   myCurrentMode = CurAction2d_DynamicPanning;
501 }
502 void OCC_2dView::OnBUTTONZoomProg() 
503 {
504   myCurrentMode = CurAction2d_DynamicZooming;
505 }
506 void OCC_2dView::OnBUTTONZoomWin() 
507 {
508   myCurrentMode = CurAction2d_WindowZooming;
509 }
510 void OCC_2dView::OnChangeBackground() 
511 {
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   }     
531 }
532
533
534 void OCC_2dView::OnUpdateBUTTON2DGlobPanning(CCmdUI* pCmdUI) 
535 {
536   pCmdUI->SetCheck (myCurrentMode == CurAction2d_GlobalPanning);
537   pCmdUI->Enable   (myCurrentMode != CurAction2d_GlobalPanning);
538 }
539
540 void OCC_2dView::OnUpdateBUTTON2DPanning(CCmdUI* pCmdUI) 
541 {
542   pCmdUI->SetCheck (myCurrentMode == CurAction2d_DynamicPanning);
543   pCmdUI->Enable   (myCurrentMode != CurAction2d_DynamicPanning);
544 }
545
546 void OCC_2dView::OnUpdateBUTTON2DZoomProg(CCmdUI* pCmdUI) 
547 {
548   pCmdUI->SetCheck (myCurrentMode == CurAction2d_DynamicZooming);
549   pCmdUI->Enable   (myCurrentMode != CurAction2d_DynamicZooming);
550 }
551
552 void OCC_2dView::OnUpdateBUTTON2DZoomWin(CCmdUI* pCmdUI) 
553 {
554   pCmdUI->SetCheck (myCurrentMode == CurAction2d_WindowZooming);
555   pCmdUI->Enable   (myCurrentMode != CurAction2d_WindowZooming);                
556 }
557
558 // =====================================================================
559
560 //-----------------------------------------------------------------------------------------
561 //
562 //-----------------------------------------------------------------------------------------
563 void OCC_2dView::DragEvent2D(const Standard_Integer  x,
564                             const Standard_Integer  y,
565                             const Standard_Integer  TheState)
566 {
567   // TheState == -1  button down
568   // TheState ==  0  move
569   // TheState ==  1  button up
570
571   static Standard_Integer theButtonDownX=0;
572   static Standard_Integer theButtonDownY=0;
573
574   if (TheState == -1)
575   {
576     theButtonDownX=x;
577     theButtonDownY=y;
578   }
579
580   if (TheState == 0)
581   {
582     ((OCC_2dDoc*)GetDocument())->GetInteractiveContext()->MoveTo (x, y, myV2dView, Standard_False);
583     ((OCC_2dDoc*)GetDocument())->GetInteractiveContext()->Select (theButtonDownX, theButtonDownY, x, y, myV2dView, Standard_True);
584   }
585
586   if (TheState == 1)
587   {
588     ((OCC_2dDoc*)GetDocument())->GetInteractiveContext()->Select(true);
589   }
590 }
591
592
593 //-----------------------------------------------------------------------------------------
594 //
595 //-----------------------------------------------------------------------------------------
596 void OCC_2dView::InputEvent2D(const Standard_Integer /*x*/,
597                               const Standard_Integer /*y*/)
598 {
599   ((OCC_2dDoc*)GetDocument())->GetInteractiveContext()->Select(true);
600 }
601
602 //-----------------------------------------------------------------------------------------
603 //
604 //-----------------------------------------------------------------------------------------
605 void OCC_2dView::MoveEvent2D(const Standard_Integer  x,
606                             const Standard_Integer  y) 
607 {
608   if(myV2dView->Viewer()->Grid()->IsActive())
609   {
610     Standard_Real 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   }
615   ((OCC_2dDoc*)GetDocument())->GetInteractiveContext()->MoveTo (x, y, myV2dView, Standard_True);
616 }
617
618 //-----------------------------------------------------------------------------------------
619 //
620 //-----------------------------------------------------------------------------------------
621 void OCC_2dView::MultiMoveEvent2D(const Standard_Integer  x,
622                                   const Standard_Integer  y) 
623 {
624 // MultiMoveEvent2D means we move the mouse in a multi selection mode
625 ((OCC_2dDoc*)GetDocument())->GetInteractiveContext()->MoveTo (x, y, myV2dView, Standard_True);
626 }
627
628 //-----------------------------------------------------------------------------------------
629 //
630 //-----------------------------------------------------------------------------------------
631 void OCC_2dView::MultiDragEvent2D(const Standard_Integer  x        ,
632                                   const Standard_Integer  y        ,
633                                   const Standard_Integer  TheState) 
634 {
635   static Standard_Integer theButtonDownX=0;
636   static Standard_Integer theButtonDownY=0;
637
638   if (TheState == -1)
639   {
640     theButtonDownX=x;
641     theButtonDownY=y;
642   }
643
644   if (TheState == 0)
645   {
646     ((OCC_2dDoc*)GetDocument())->GetInteractiveContext()->MoveTo (x, y, myV2dView, Standard_False);
647     ((OCC_2dDoc*)GetDocument())->GetInteractiveContext()->ShiftSelect (theButtonDownX, theButtonDownY, x, y, myV2dView, Standard_True);
648   }
649
650   if (TheState == 1)
651   {
652     ((OCC_2dDoc*)GetDocument())->GetInteractiveContext()->ShiftSelect(true);
653   }
654 }
655
656
657 //-----------------------------------------------------------------------------------------
658 //
659 //-----------------------------------------------------------------------------------------
660 void OCC_2dView::MultiInputEvent2D(const Standard_Integer /*x*/,
661                                    const Standard_Integer /*y*/)
662 {
663   ((OCC_2dDoc*)GetDocument())->GetInteractiveContext()->ShiftSelect(true);
664 }
665
666 //-----------------------------------------------------------------------------------------
667 //
668 //-----------------------------------------------------------------------------------------
669 void  OCC_2dView::Popup2D(const Standard_Integer  x,
670                          const Standard_Integer  y ) 
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 };
683   ClientToScreen ( &winCoord);
684   pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON , winCoord.x, winCoord.y , AfxGetMainWnd());
685 }
686
687 void OCC_2dView::FitAll()
688 {
689   myV2dView->FitAll();
690 }