1 // NSGViewBibliotheque.cpp : implementation of the CGeometryView2D class
5 #include "GeometryApp.h"
6 #include "GeometryDoc.h"
7 #include "GeometryView2D.h"
8 #include ".\Resource2d\RectangularGrid.h"
9 #include ".\Resource2d\CircularGrid.h"
11 /////////////////////////////////////////////////////////////////////////////
14 IMPLEMENT_DYNCREATE(CGeometryView2D, CView)
15 BEGIN_MESSAGE_MAP(CGeometryView2D, OCC_2dView)
16 //{{AFX_MSG_MAP(CGeometryView2D)
28 /////////////////////////////////////////////////////////////////////////////
29 // CNSGView construction/destruction
31 CGeometryView2D::CGeometryView2D()
35 CGeometryView2D::~CGeometryView2D()
41 void CGeometryView2D::OnDraw(CDC* /*pDC*/)
43 CGeometryDoc* pDoc = GetDocument();
46 if (!myV2dView.IsNull())
50 /////////////////////////////////////////////////////////////////////////////
51 // CGeometryView2D diagnostics
54 void CGeometryView2D::AssertValid() const
59 void CGeometryView2D::Dump(CDumpContext& dc) const
64 CGeometryDoc* CGeometryView2D::GetDocument() // non-debug version is inline
66 ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGeometryDoc)));
67 return (CGeometryDoc*)m_pDocument;
71 /////////////////////////////////////////////////////////////////////////////
72 // CNSGView message handlers
76 //=================================================================
78 void CGeometryView2D::OnLButtonDown(UINT nFlags, CPoint point)
80 // save the current mouse coordinate in min
81 myXmin=point.x; myYmin=point.y;
82 myXmax=point.x; myYmax=point.y;
84 if ( nFlags & MK_CONTROL )
86 // Button MB1 down Control :start zomming
87 // SetCursor(AfxGetApp()->LoadStandardCursor());
91 switch (myCurrentMode)
93 case CurAction2d_Nothing : // start a drag
94 GetDocument()->DragEvent2D(point.x,point.y,-1,myV2dView);
96 case CurAction2d_DynamicZooming : // noting
98 case CurAction2d_WindowZooming :
100 case CurAction2d_DynamicPanning :// noting
102 case CurAction2d_GlobalPanning :// noting
105 Standard_Failure::Raise(" incompatible Current Mode ");
111 void CGeometryView2D::OnLButtonUp(UINT nFlags, CPoint point)
113 // TODO: Add your message handler code here and/or call default
114 if ( nFlags & MK_CONTROL )
120 const Handle(AIS_InteractiveContext)& aContext = GetDocument()->GetISessionContext();
121 switch (myCurrentMode)
123 case CurAction2d_Nothing :
124 if (point.x == myXmin && point.y == myYmin)
125 { // no offset between down and up --> selectEvent
128 if (nFlags & MK_SHIFT )
129 GetDocument()->ShiftInputEvent2D(point.x,point.y,myV2dView);
131 GetDocument()->InputEvent2D (point.x,point.y,myV2dView);
134 drawRectangle (myXmin,myYmin,myXmax,myYmax,aContext,Standard_False);
137 if (nFlags & MK_SHIFT)
138 GetDocument()->ShiftDragEvent2D(point.x,point.y,1,myV2dView);
140 GetDocument()->DragEvent2D(point.x,point.y,1,myV2dView);
143 case CurAction2d_DynamicZooming :
144 // SetCursor(AfxGetApp()->LoadStandardCursor());
145 myCurrentMode = CurAction2d_Nothing;
147 case CurAction2d_WindowZooming :
148 myXmax=point.x; myYmax=point.y;
149 drawRectangle (myXmin,myYmin,myXmax,myYmax,aContext,Standard_False);
150 if ((abs(myXmin-myXmax)>ValZWMin) || (abs(myYmin-myYmax)>ValZWMin))
151 // Test if the zoom window is greater than a minimale window.
153 // Do the zoom window between Pmin and Pmax
154 myV2dView->WindowFit(myXmin,myYmin,myXmax,myYmax);
156 myCurrentMode = CurAction2d_Nothing;
158 case CurAction2d_DynamicPanning :
159 myCurrentMode = CurAction2d_Nothing;
161 case CurAction2d_GlobalPanning :
162 myV2dView->Place(point.x,point.y,myCurZoom);
163 myCurrentMode = CurAction2d_Nothing;
166 Standard_Failure::Raise(" incompatible Current Mode ");
168 } //switch (myCurrentMode)
169 } // else // if ( Ctrl )
173 void CGeometryView2D::OnMButtonDown(UINT nFlags, CPoint /*point*/)
175 if ( nFlags & MK_CONTROL )
177 // Button MB2 down Control : panning init
178 // SetCursor(AfxGetApp()->LoadStandardCursor());
182 void CGeometryView2D::OnMButtonUp(UINT nFlags, CPoint /*point*/)
184 if ( nFlags & MK_CONTROL )
186 // Button MB2 up Control : panning stop
187 // SetCursor(AfxGetApp()->LoadStandardCursor());
191 void CGeometryView2D::OnRButtonDown(UINT nFlags, CPoint point)
193 // TODO: Add your message handler code here and/or call default
194 if ( nFlags & MK_CONTROL )
196 // SetCursor(AfxGetApp()->LoadStandardCursor());
200 GetDocument()->Popup2D(point.x,point.y,myV2dView);
204 void CGeometryView2D::OnRButtonUp(UINT /*nFlags*/, CPoint point)
206 OCC_2dView::Popup2D(point.x,point.y);
209 void CGeometryView2D::OnMouseMove(UINT nFlags, CPoint point)
211 // ============================ LEFT BUTTON =======================
212 if ( nFlags & MK_LBUTTON)
214 if ( nFlags & MK_CONTROL )
216 // move with MB1 and Control : on the dynamic zooming
217 // Do the zoom in function of mouse's coordinates
218 myV2dView->Zoom(myXmax,myYmax,point.x,point.y);
219 // save the current mouse coordinate in min
225 const Handle(AIS_InteractiveContext)& aContext = GetDocument()->GetISessionContext();
226 switch (myCurrentMode)
228 case CurAction2d_Nothing :
231 GetDocument()->DragEvent2D(myXmax,myYmax,0,myV2dView);
232 drawRectangle (myXmin,myYmin,myXmax,myYmax, aContext);
234 case CurAction2d_DynamicZooming :
235 myV2dView->Zoom(myXmax,myYmax,point.x,point.y);
236 // save the current mouse coordinate in min \n";
237 myXmax=point.x; myYmax=point.y;
239 case CurAction2d_WindowZooming :
240 myXmax = point.x; myYmax = point.y;
241 drawRectangle (myXmin,myYmin,myXmax,myYmax, aContext);
243 case CurAction2d_DynamicPanning :
244 myV2dView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
245 myXmax = point.x; myYmax = point.y;
247 case CurAction2d_GlobalPanning : // nothing
250 Standard_Failure::Raise(" incompatible Current Mode ");
252 }// switch (myCurrentMode)
253 }// if ( nFlags & MK_CONTROL ) else
254 } else // if ( nFlags & MK_LBUTTON)
255 // ============================ MIDDLE BUTTON =======================
256 if ( nFlags & MK_MBUTTON)
258 if ( nFlags & MK_CONTROL )
260 myV2dView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
261 myXmax = point.x; myYmax = point.y;
264 } else // if ( nFlags & MK_MBUTTON)
265 // ============================ RIGHT BUTTON =======================
266 if ( nFlags & MK_RBUTTON)
268 }else //if ( nFlags & MK_RBUTTON)
269 // ============================ NO BUTTON =======================
271 myXmax = point.x; myYmax = point.y;
272 if (nFlags & MK_SHIFT)
273 GetDocument()->ShiftMoveEvent2D(point.x,point.y,myV2dView);
275 GetDocument()->MoveEvent2D(point.x,point.y,myV2dView);
279 void CGeometryView2D::OnSize(UINT /*nType*/, int /*cx*/, int /*cy*/)
281 if (!myV2dView.IsNull())
283 myV2dView->MustBeResized(); // added sro
287 void CGeometryView2D::OnInitialUpdate()
289 Handle(WNT_Window) aWNTWindow;
290 aWNTWindow = new WNT_Window(GetSafeHwnd());
292 myV2dView = GetDocument()->GetViewer2D()->CreateView();
293 myV2dView->SetWindow(aWNTWindow);
294 myV2dView->SetBackgroundColor(Quantity_NOC_BLACK);
296 // initialyse the grids dialogs
297 TheRectangularGridDialog.Create(CRectangularGrid::IDD, NULL);
298 TheCircularGridDialog.Create(CCircularGrid::IDD, NULL);
299 TheRectangularGridDialog.SetViewer (GetDocument()->GetViewer2D());
300 TheCircularGridDialog.SetViewer (GetDocument()->GetViewer2D());
302 Standard_Integer w=100 , h=100 ; /* Debug Matrox */
303 aWNTWindow->Size (w,h) ; /* Keeps me unsatisfied (rlb)..... */
304 /* Resize is not supposed to be done on */
306 /* I suspect another problem elsewhere */
307 ::PostMessage ( GetSafeHwnd () , WM_SIZE , SIZE_RESTORED , w + h*65536 ) ;