7fd59977 |
1 | // NSGViewBibliotheque.cpp : implementation of the CGeometryView2D class |
2 | // |
3 | |
4 | #include "stdafx.h" |
5 | #include "GeometryApp.h" |
6 | #include "GeometryDoc.h" |
7 | #include "GeometryView2D.h" |
8 | #include ".\Resource2d\RectangularGrid.h" |
9 | #include ".\Resource2d\CircularGrid.h" |
10 | #include <Aspect.hxx> |
11 | |
12 | ///////////////////////////////////////////////////////////////////////////// |
13 | // CNSGView |
14 | |
15 | IMPLEMENT_DYNCREATE(CGeometryView2D, CView) |
16 | BEGIN_MESSAGE_MAP(CGeometryView2D, OCC_2dView) |
5c1f974e |
17 | //{{AFX_MSG_MAP(CGeometryView2D) |
18 | ON_WM_LBUTTONDOWN() |
19 | ON_WM_LBUTTONUP() |
20 | ON_WM_MBUTTONDOWN() |
21 | ON_WM_MBUTTONUP() |
22 | ON_WM_RBUTTONDOWN() |
23 | ON_WM_RBUTTONUP() |
24 | ON_WM_MOUSEMOVE() |
25 | ON_WM_SIZE() |
26 | //}}AFX_MSG_MAP |
7fd59977 |
27 | END_MESSAGE_MAP() |
28 | |
29 | ///////////////////////////////////////////////////////////////////////////// |
30 | // CNSGView construction/destruction |
31 | |
32 | CGeometryView2D::CGeometryView2D() |
33 | { |
34 | } |
35 | |
36 | CGeometryView2D::~CGeometryView2D() |
37 | { |
38 | } |
39 | |
40 | // CNSGView drawing |
41 | |
5c573e69 |
42 | void CGeometryView2D::OnDraw(CDC* /*pDC*/) |
7fd59977 |
43 | { |
5c1f974e |
44 | CGeometryDoc* pDoc = GetDocument(); |
45 | ASSERT_VALID(pDoc); |
7fd59977 |
46 | |
5c1f974e |
47 | if (!myV2dView.IsNull()) |
48 | myV2dView->Update(); |
7fd59977 |
49 | } |
50 | |
51 | ///////////////////////////////////////////////////////////////////////////// |
52 | // CGeometryView2D diagnostics |
53 | |
54 | #ifdef _DEBUG |
55 | void CGeometryView2D::AssertValid() const |
56 | { |
5c1f974e |
57 | CView::AssertValid(); |
7fd59977 |
58 | } |
59 | |
60 | void CGeometryView2D::Dump(CDumpContext& dc) const |
61 | { |
5c1f974e |
62 | CView::Dump(dc); |
7fd59977 |
63 | } |
64 | |
65 | CGeometryDoc* CGeometryView2D::GetDocument() // non-debug version is inline |
66 | { |
5c1f974e |
67 | ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGeometryDoc))); |
68 | return (CGeometryDoc*)m_pDocument; |
7fd59977 |
69 | } |
70 | #endif //_DEBUG |
71 | |
72 | ///////////////////////////////////////////////////////////////////////////// |
73 | // CNSGView message handlers |
74 | |
75 | |
76 | |
77 | //================================================================= |
78 | |
79 | void CGeometryView2D::OnLButtonDown(UINT nFlags, CPoint point) |
80 | { |
81 | // save the current mouse coordinate in min |
82 | myXmin=point.x; myYmin=point.y; |
83 | myXmax=point.x; myYmax=point.y; |
84 | |
85 | if ( nFlags & MK_CONTROL ) |
5c1f974e |
86 | { |
87 | // Button MB1 down Control :start zomming |
88 | // SetCursor(AfxGetApp()->LoadStandardCursor()); |
89 | } |
90 | else // if ( Ctrl ) |
91 | { |
92 | switch (myCurrentMode) |
93 | { |
94 | case CurAction2d_Nothing : // start a drag |
95 | GetDocument()->DragEvent2D(point.x,point.y,-1,myV2dView); |
96 | break; |
97 | case CurAction2d_DynamicZooming : // noting |
98 | break; |
99 | case CurAction2d_WindowZooming : |
100 | break; |
101 | case CurAction2d_DynamicPanning :// noting |
102 | break; |
103 | case CurAction2d_GlobalPanning :// noting |
104 | break; |
105 | default : |
106 | Standard_Failure::Raise(" incompatible Current Mode "); |
107 | break; |
7fd59977 |
108 | } |
5c1f974e |
109 | } |
7fd59977 |
110 | } |
111 | |
112 | void CGeometryView2D::OnLButtonUp(UINT nFlags, CPoint point) |
113 | { |
5c1f974e |
114 | // TODO: Add your message handler code here and/or call default |
115 | if ( nFlags & MK_CONTROL ) |
116 | { |
117 | return; |
118 | } |
119 | else // if ( Ctrl ) |
120 | { |
121 | switch (myCurrentMode) |
122 | { |
123 | case CurAction2d_Nothing : |
124 | if (point.x == myXmin && point.y == myYmin) |
125 | { // no offset between down and up --> selectEvent |
126 | myXmax=point.x; |
127 | myYmax=point.y; |
128 | if (nFlags & MK_SHIFT ) |
129 | GetDocument()->ShiftInputEvent2D(point.x,point.y,myV2dView); |
130 | else |
131 | GetDocument()->InputEvent2D (point.x,point.y,myV2dView); |
132 | } else |
133 | { |
134 | DrawRectangle2D(myXmin,myYmin,myXmax,myYmax,Standard_False); |
135 | myXmax=point.x; |
136 | myYmax=point.y; |
137 | if (nFlags & MK_SHIFT) |
138 | GetDocument()->ShiftDragEvent2D(point.x,point.y,1,myV2dView); |
139 | else |
140 | GetDocument()->DragEvent2D(point.x,point.y,1,myV2dView); |
141 | } |
142 | break; |
143 | case CurAction2d_DynamicZooming : |
144 | // SetCursor(AfxGetApp()->LoadStandardCursor()); |
145 | myCurrentMode = CurAction2d_Nothing; |
146 | break; |
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. |
152 | { |
153 | // Do the zoom window between Pmin and Pmax |
154 | myV2dView->WindowFit(myXmin,myYmin,myXmax,myYmax); |
155 | } |
156 | myCurrentMode = CurAction2d_Nothing; |
157 | break; |
158 | case CurAction2d_DynamicPanning : |
159 | myCurrentMode = CurAction2d_Nothing; |
160 | break; |
161 | case CurAction2d_GlobalPanning : |
162 | myV2dView->Place(point.x,point.y,myCurZoom); |
163 | myCurrentMode = CurAction2d_Nothing; |
164 | break; |
165 | default : |
166 | Standard_Failure::Raise(" incompatible Current Mode "); |
167 | break; |
168 | } //switch (myCurrentMode) |
169 | } // else // if ( Ctrl ) |
170 | |
7fd59977 |
171 | } |
172 | |
5c573e69 |
173 | void CGeometryView2D::OnMButtonDown(UINT nFlags, CPoint /*point*/) |
7fd59977 |
174 | { |
5c1f974e |
175 | if ( nFlags & MK_CONTROL ) |
176 | { |
177 | // Button MB2 down Control : panning init |
178 | // SetCursor(AfxGetApp()->LoadStandardCursor()); |
179 | } |
7fd59977 |
180 | } |
181 | |
5c573e69 |
182 | void CGeometryView2D::OnMButtonUp(UINT nFlags, CPoint /*point*/) |
7fd59977 |
183 | { |
5c1f974e |
184 | if ( nFlags & MK_CONTROL ) |
185 | { |
186 | // Button MB2 up Control : panning stop |
187 | // SetCursor(AfxGetApp()->LoadStandardCursor()); |
188 | } |
7fd59977 |
189 | } |
190 | |
191 | void CGeometryView2D::OnRButtonDown(UINT nFlags, CPoint point) |
192 | { |
5c1f974e |
193 | // TODO: Add your message handler code here and/or call default |
194 | if ( nFlags & MK_CONTROL ) |
195 | { |
196 | // SetCursor(AfxGetApp()->LoadStandardCursor()); |
197 | } |
198 | else // if ( Ctrl ) |
199 | { |
200 | GetDocument()->Popup2D(point.x,point.y,myV2dView); |
201 | } |
7fd59977 |
202 | } |
203 | |
5c573e69 |
204 | void CGeometryView2D::OnRButtonUp(UINT /*nFlags*/, CPoint point) |
7fd59977 |
205 | { |
5c1f974e |
206 | OCC_2dView::Popup2D(point.x,point.y); |
7fd59977 |
207 | } |
208 | |
209 | void CGeometryView2D::OnMouseMove(UINT nFlags, CPoint point) |
210 | { |
5c1f974e |
211 | // ============================ LEFT BUTTON ======================= |
7fd59977 |
212 | if ( nFlags & MK_LBUTTON) |
5c1f974e |
213 | { |
214 | if ( nFlags & MK_CONTROL ) |
215 | { |
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 |
220 | myXmax = point.x; |
221 | myYmax = point.y; |
222 | } |
223 | else // if ( Ctrl ) |
7fd59977 |
224 | { |
5c1f974e |
225 | switch (myCurrentMode) |
226 | { |
227 | case CurAction2d_Nothing : |
228 | DrawRectangle2D(myXmin,myYmin,myXmax,myYmax,Standard_False); |
229 | myXmax = point.x; |
7fd59977 |
230 | myYmax = point.y; |
5c1f974e |
231 | GetDocument()->DragEvent2D(myXmax,myYmax,0,myV2dView); |
232 | DrawRectangle2D(myXmin,myYmin,myXmax,myYmax,Standard_True); |
233 | break; |
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; |
238 | break; |
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); |
7fd59977 |
243 | break; |
5c1f974e |
244 | case CurAction2d_DynamicPanning : |
245 | myV2dView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning |
246 | myXmax = point.x; myYmax = point.y; |
7fd59977 |
247 | break; |
5c1f974e |
248 | case CurAction2d_GlobalPanning : // nothing |
249 | break; |
250 | default : |
251 | Standard_Failure::Raise(" incompatible Current Mode "); |
252 | break; |
253 | }// switch (myCurrentMode) |
254 | }// if ( nFlags & MK_CONTROL ) else |
255 | } else // if ( nFlags & MK_LBUTTON) |
7fd59977 |
256 | // ============================ MIDDLE BUTTON ======================= |
257 | if ( nFlags & MK_MBUTTON) |
258 | { |
5c1f974e |
259 | if ( nFlags & MK_CONTROL ) |
260 | { |
261 | myV2dView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning |
262 | myXmax = point.x; myYmax = point.y; |
7fd59977 |
263 | |
5c1f974e |
264 | } |
7fd59977 |
265 | } else // if ( nFlags & MK_MBUTTON) |
5c1f974e |
266 | // ============================ RIGHT BUTTON ======================= |
267 | if ( nFlags & MK_RBUTTON) |
268 | { |
269 | }else //if ( nFlags & MK_RBUTTON) |
270 | // ============================ NO BUTTON ======================= |
271 | { // No buttons |
272 | myXmax = point.x; myYmax = point.y; |
273 | if (nFlags & MK_SHIFT) |
274 | GetDocument()->ShiftMoveEvent2D(point.x,point.y,myV2dView); |
275 | else |
276 | GetDocument()->MoveEvent2D(point.x,point.y,myV2dView); |
277 | } |
7fd59977 |
278 | } |
279 | |
5c573e69 |
280 | void CGeometryView2D::OnSize(UINT /*nType*/, int /*cx*/, int /*cy*/) |
7fd59977 |
281 | { |
5c1f974e |
282 | if (!myV2dView.IsNull()) |
283 | { |
284 | myV2dView->MustBeResized(); // added sro |
285 | } |
7fd59977 |
286 | } |
287 | |
288 | void CGeometryView2D::OnInitialUpdate() |
7fd59977 |
289 | { |
5c1f974e |
290 | Handle(WNT_Window) aWNTWindow; |
291 | aWNTWindow = new WNT_Window(GetSafeHwnd()); |
292 | |
293 | myV2dView = GetDocument()->GetViewer2D()->CreateView(); |
294 | myV2dView->SetWindow(aWNTWindow); |
295 | myV2dView->SetBackgroundColor(Quantity_NOC_BLACK); |
296 | |
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()); |
302 | |
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 */ |
306 | /* Matrox */ |
307 | /* I suspect another problem elsewhere */ |
308 | ::PostMessage ( GetSafeHwnd () , WM_SIZE , SIZE_RESTORED , w + h*65536 ) ; |
7fd59977 |
309 | } |