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"
12 /////////////////////////////////////////////////////////////////////////////
15 IMPLEMENT_DYNCREATE(CGeometryView2D, CView)
16 BEGIN_MESSAGE_MAP(CGeometryView2D, OCC_2dView)
17 //{{AFX_MSG_MAP(CGeometryView2D)
29 /////////////////////////////////////////////////////////////////////////////
30 // CNSGView construction/destruction
32 CGeometryView2D::CGeometryView2D()
36 CGeometryView2D::~CGeometryView2D()
42 void CGeometryView2D::OnDraw(CDC* pDC)
44 CGeometryDoc* pDoc = GetDocument();
47 if (!myV2dView.IsNull())
51 /////////////////////////////////////////////////////////////////////////////
52 // CGeometryView2D diagnostics
55 void CGeometryView2D::AssertValid() const
60 void CGeometryView2D::Dump(CDumpContext& dc) const
65 CGeometryDoc* CGeometryView2D::GetDocument() // non-debug version is inline
67 ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGeometryDoc)));
68 return (CGeometryDoc*)m_pDocument;
72 /////////////////////////////////////////////////////////////////////////////
73 // CNSGView message handlers
77 //=================================================================
79 void CGeometryView2D::OnLButtonDown(UINT nFlags, CPoint point)
81 // save the current mouse coordinate in min
82 myXmin=point.x; myYmin=point.y;
83 myXmax=point.x; myYmax=point.y;
85 if ( nFlags & MK_CONTROL )
87 // Button MB1 down Control :start zomming
88 // SetCursor(AfxGetApp()->LoadStandardCursor());
92 switch (myCurrentMode)
94 case CurAction2d_Nothing : // start a drag
95 GetDocument()->DragEvent2D(point.x,point.y,-1,myV2dView);
97 case CurAction2d_DynamicZooming : // noting
99 case CurAction2d_WindowZooming :
101 case CurAction2d_DynamicPanning :// noting
103 case CurAction2d_GlobalPanning :// noting
106 Standard_Failure::Raise(" incompatible Current Mode ");
112 void CGeometryView2D::OnLButtonUp(UINT nFlags, CPoint point)
114 // TODO: Add your message handler code here and/or call default
115 if ( nFlags & MK_CONTROL )
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 DrawRectangle2D(myXmin,myYmin,myXmax,myYmax,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 DrawRectangle2D(myXmin,myYmin,myXmax,myYmax,Standard_False,LongDash);
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 switch (myCurrentMode)
227 case CurAction2d_Nothing :
228 DrawRectangle2D(myXmin,myYmin,myXmax,myYmax,Standard_False);
231 GetDocument()->DragEvent2D(myXmax,myYmax,0,myV2dView);
232 DrawRectangle2D(myXmin,myYmin,myXmax,myYmax,Standard_True);
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 DrawRectangle2D(myXmin,myYmin,myXmax,myYmax,Standard_False,LongDash);
242 DrawRectangle2D(myXmin,myYmin,myXmax,myYmax,Standard_True,LongDash);
244 case CurAction2d_DynamicPanning :
245 myV2dView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
246 myXmax = point.x; myYmax = point.y;
248 case CurAction2d_GlobalPanning : // nothing
251 Standard_Failure::Raise(" incompatible Current Mode ");
253 }// switch (myCurrentMode)
254 }// if ( nFlags & MK_CONTROL ) else
255 } else // if ( nFlags & MK_LBUTTON)
256 // ============================ MIDDLE BUTTON =======================
257 if ( nFlags & MK_MBUTTON)
259 if ( nFlags & MK_CONTROL )
261 myV2dView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
262 myXmax = point.x; myYmax = point.y;
265 } else // if ( nFlags & MK_MBUTTON)
266 // ============================ RIGHT BUTTON =======================
267 if ( nFlags & MK_RBUTTON)
269 }else //if ( nFlags & MK_RBUTTON)
270 // ============================ NO BUTTON =======================
272 myXmax = point.x; myYmax = point.y;
273 if (nFlags & MK_SHIFT)
274 GetDocument()->ShiftMoveEvent2D(point.x,point.y,myV2dView);
276 GetDocument()->MoveEvent2D(point.x,point.y,myV2dView);
280 void CGeometryView2D::OnSize(UINT nType, int cx, int cy)
282 if (!myV2dView.IsNull())
284 myV2dView->MustBeResized(); // added sro
288 void CGeometryView2D::OnInitialUpdate()
290 Handle(WNT_Window) aWNTWindow;
291 aWNTWindow = new WNT_Window(GetSafeHwnd());
293 myV2dView = GetDocument()->GetViewer2D()->CreateView();
294 myV2dView->SetWindow(aWNTWindow);
295 myV2dView->SetBackgroundColor(Quantity_NOC_BLACK);
297 // initialyse the grids dialogs
298 TheRectangularGridDialog.Create(CRectangularGrid::IDD, NULL);
299 TheCircularGridDialog.Create(CCircularGrid::IDD, NULL);
300 TheRectangularGridDialog.SetViewer (GetDocument()->GetViewer2D());
301 TheCircularGridDialog.SetViewer (GetDocument()->GetViewer2D());
303 Standard_Integer w=100 , h=100 ; /* Debug Matrox */
304 aWNTWindow->Size (w,h) ; /* Keeps me unsatisfied (rlb)..... */
305 /* Resize is not supposed to be done on */
307 /* I suspect another problem elsewhere */
308 ::PostMessage ( GetSafeHwnd () , WM_SIZE , SIZE_RESTORED , w + h*65536 ) ;