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