0023821: Improve qmake project files for Qt samples
[occt.git] / samples / mfc / standard / 08_HLR / src / HLRView3D.cpp
CommitLineData
7fd59977 1// HLRView.cpp : implementation of the CHLRView3D3D class
2//
3
4#include "stdafx.h"
5#include "HLRApp.h"
6
7#include "HLRDoc.h"
8#include "HLRView3D.h"
9#include "..\..\Common\res\OCC_Resource.h"
10
11#ifdef _DEBUG
12//#define new DEBUG_NEW by CasCade
13#undef THIS_FILE
14static char THIS_FILE[] = __FILE__;
15#endif
16
17// for elastic bean selection
18#define ValZWMin 1
19
20// the key for multi selection :
21#define MULTISELECTIONKEY MK_SHIFT
22
23// the key for shortcut ( use to activate dynamic rotation, panning )
24#define CASCADESHORTCUTKEY MK_CONTROL
25
26// define in witch case you want to display the popup
27#define POPUPONBUTTONDOWN
28
29/////////////////////////////////////////////////////////////////////////////
30// CHLRView3D
31
32IMPLEMENT_DYNCREATE(CHLRView3D, OCC_3dView)
33
34BEGIN_MESSAGE_MAP(CHLRView3D, OCC_3dView)
35 //{{AFX_MSG_MAP(CHLRView3D)
36 // NOTE - the ClassWizard will add and remove mapping macros here.
37 // DO NOT EDIT what you see in these blocks of generated code!
38 //}}AFX_MSG_MAP
39// CasCade
40 ON_WM_LBUTTONDOWN()
41 ON_WM_LBUTTONUP()
42 ON_WM_MOUSEMOVE()
43 ON_WM_RBUTTONDOWN()
44END_MESSAGE_MAP()
45
46/////////////////////////////////////////////////////////////////////////////
47// CHLRView3D construction/destruction
48
49CHLRView3D::CHLRView3D()
50{
51}
52
53CHLRView3D::~CHLRView3D()
54{
55}
56
57void CHLRView3D::OnInitialUpdate()
58{
59
60 // TODO: Add your specialized code here and/or call the base class
61 // TODO: Add your specialized code here and/or call the base class
62 myView = GetDocument()->GetViewer()->CreateView();
63
64 // store for restore state after rotation (witch is in Degenerated mode)
65 myDegenerateModeIsOn = myView->DegenerateModeIsOn();
66
67 Handle(Graphic3d_WNTGraphicDevice) theGraphicDevice =
68 ((CHLRApp*)AfxGetApp())->GetGraphicDevice();
69
70 Handle(WNT_Window) aWNTWindow = new WNT_Window(theGraphicDevice,GetSafeHwnd ());
71 myView->SetWindow(aWNTWindow);
72 if (!aWNTWindow->IsMapped()) aWNTWindow->Map();
73
74 Standard_Integer w=100 , h=100 ; /* Debug Matrox */
75 aWNTWindow->Size (w,h) ; /* Keeps me unsatisfied (rlb)..... */
76 /* Resize is not supposed to be done on */
77 /* Matrox */
78 /* I suspect another problem elsewhere */
79 ::PostMessage ( GetSafeHwnd () , WM_SIZE , SIZE_RESTORED , w + h*65536 ) ;
80
81 // store the mode ( nothing , dynamic zooming, dynamic ... )
82 myCurrentMode = CurAction3d_Nothing;
83
84}
85
86/////////////////////////////////////////////////////////////////////////////
87// CHLRView3D diagnostics
88
89#ifdef _DEBUG
90void CHLRView3D::AssertValid() const
91{
92 CView::AssertValid();
93}
94
95void CHLRView3D::Dump(CDumpContext& dc) const
96{
97 CView::Dump(dc);
98}
99
100CHLRDoc* CHLRView3D::GetDocument() // non-debug version is inline
101{
102 ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CHLRDoc)));
103 return (CHLRDoc*)m_pDocument;
104}
105#endif //_DEBUG
106
107/////////////////////////////////////////////////////////////////////////////
108// CHLRView3D message handlers
109
110
111void CHLRView3D::OnLButtonDown(UINT nFlags, CPoint point)
112{
113 // save the current mouse coordinate in min
114 myXmin=point.x; myYmin=point.y;
115 myXmax=point.x; myYmax=point.y;
116
117 if ( nFlags & CASCADESHORTCUTKEY )
118 {
119 // Button MB1 down Control :start zomming
120 // SetCursor(AfxGetApp()->LoadStandardCursor());
121 }
122 else // if ( Ctrl )
123 {
124 switch (myCurrentMode)
125 {
126 case CurAction3d_Nothing : // start a drag
127 if (nFlags & MULTISELECTIONKEY)
128 MultiDragEvent(myXmax,myYmax,-1);
129 else
130 DragEvent(myXmax,myYmax,-1);
131 break;
132 break;
133 case CurAction3d_DynamicZooming : // noting
134 break;
135 case CurAction3d_WindowZooming : // noting
136 break;
137 case CurAction3d_DynamicPanning :// noting
138 break;
139 case CurAction3d_GlobalPanning :// noting
140 break;
141 case CurAction3d_DynamicRotation :
142 if (!myDegenerateModeIsOn)
143 myView->SetDegenerateModeOn();
144 myView->StartRotation(point.x,point.y);
145 break;
146 default :
147 Standard_Failure::Raise(" incompatible Current Mode ");
148 break;
149 }
150 }
151}
152
153void CHLRView3D::OnLButtonUp(UINT nFlags, CPoint point)
154{
155 if ( nFlags & CASCADESHORTCUTKEY )
156 {
157 return;
158 }
159 else // if ( Ctrl )
160 {
161 switch (myCurrentMode)
162 {
163 case CurAction3d_Nothing :
164 if (point.x == myXmin && point.y == myYmin)
165 { // no offset between down and up --> selectEvent
166 myXmax=point.x;
167 myYmax=point.y;
168 if (nFlags & MULTISELECTIONKEY )
169 MultiInputEvent(point.x,point.y);
170 else
171 InputEvent (point.x,point.y);
172 } else
173 {
174 myXmax=point.x; myYmax=point.y;
175 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False);
176 if (nFlags & MULTISELECTIONKEY)
177 MultiDragEvent(point.x,point.y,1);
178 else
179 DragEvent(point.x,point.y,1);
180 }
181 break;
182 case CurAction3d_DynamicZooming :
183 // SetCursor(AfxGetApp()->LoadStandardCursor());
184 myCurrentMode = CurAction3d_Nothing;
185 break;
186 case CurAction3d_WindowZooming :
187 myXmax=point.x; myYmax=point.y;
188 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False,LongDash);
189 if ((abs(myXmin-myXmax)>ValZWMin) || (abs(myYmin-myYmax)>ValZWMin))
190 // Test if the zoom window is greater than a minimale window.
191 {
192 // Do the zoom window between Pmin and Pmax
193 myView->WindowFitAll(myXmin,myYmin,myXmax,myYmax);
194 }
195 myCurrentMode = CurAction3d_Nothing;
196 break;
197 case CurAction3d_DynamicPanning :
198 myCurrentMode = CurAction3d_Nothing;
199 break;
200 case CurAction3d_GlobalPanning :
201 myView->Place(point.x,point.y,myCurZoom);
202 myCurrentMode = CurAction3d_Nothing;
203 break;
204 case CurAction3d_DynamicRotation :
205 myCurrentMode = CurAction3d_Nothing;
206 break;
207 default :
208 Standard_Failure::Raise(" incompatible Current Mode ");
209 break;
210 } //switch (myCurrentMode)
211 } // else // if ( Ctrl )
212}
213
214void CHLRView3D::OnRButtonDown(UINT nFlags, CPoint point)
215{
216 if ( nFlags & CASCADESHORTCUTKEY )
217 {
218 if (!myDegenerateModeIsOn)
219 myView->SetDegenerateModeOn();
220 myView->StartRotation(point.x,point.y);
221 }
222 else // if ( CASCADESHORTCUTKEY )
223 {
224#ifdef POPUPONBUTTONDOWN
225 GetDocument()->Popup(point.x,point.y, myView);
226#endif
227 }
228}
229
230void CHLRView3D::OnMouseMove(UINT nFlags, CPoint point)
231{
232 // ============================ LEFT BUTTON =======================
233 if ( nFlags & MK_LBUTTON)
234 {
235 if ( nFlags & CASCADESHORTCUTKEY )
236 {
237 // move with MB1 and Control : on the dynamic zooming
238 // Do the zoom in function of mouse's coordinates
239 myView->Zoom(myXmax,myYmax,point.x,point.y);
240 // save the current mouse coordinate in min
241 myXmax = point.x;
242 myYmax = point.y;
243 }
244 else // if ( Ctrl )
245 {
246 switch (myCurrentMode)
247 {
248 case CurAction3d_Nothing :
249 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False);
250 myXmax = point.x;
251 myYmax = point.y;
252 if (nFlags & MULTISELECTIONKEY)
253 MultiDragEvent(myXmax,myYmax,0);
254 else
255 DragEvent(myXmax,myYmax,0);
256 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_True);
257 break;
258 case CurAction3d_DynamicZooming :
259 myView->Zoom(myXmax,myYmax,point.x,point.y);
260 // save the current mouse coordinate in min \n";
261 myXmax=point.x; myYmax=point.y;
262 break;
263 case CurAction3d_WindowZooming :
264 myXmax = point.x; myYmax = point.y;
265 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False,LongDash);
266 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_True,LongDash);
267 break;
268 case CurAction3d_DynamicPanning :
269 myView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
270 myXmax = point.x; myYmax = point.y;
271 break;
272 case CurAction3d_GlobalPanning : // nothing
273 break;
274 case CurAction3d_DynamicRotation :
275 myView->Rotation(point.x,point.y);
276 myView->Redraw();
277 break;
278 default :
279 Standard_Failure::Raise(" incompatible Current Mode ");
280 break;
281 }// switch (myCurrentMode)
282 }// if ( nFlags & CASCADESHORTCUTKEY ) else
283 } else // if ( nFlags & MK_LBUTTON)
284 // ============================ MIDDLE BUTTON =======================
285 if ( nFlags & MK_MBUTTON)
286 {
287 if ( nFlags & CASCADESHORTCUTKEY )
288 {
289 myView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
290 myXmax = point.x; myYmax = point.y;
291
292 }
293 } else // if ( nFlags & MK_MBUTTON)
294 // ============================ RIGHT BUTTON =======================
295 if ( nFlags & MK_RBUTTON)
296 {
297 if ( nFlags & CASCADESHORTCUTKEY )
298 {
299 myView->Rotation(point.x,point.y);
300 }
301 }else //if ( nFlags & MK_RBUTTON)
302 // ============================ NO BUTTON =======================
303 { // No buttons
304 myXmax = point.x; myYmax = point.y;
305 if (nFlags & MULTISELECTIONKEY)
306 MultiMoveEvent(point.x,point.y);
307 else
308 MoveEvent(point.x,point.y);
309 }
310}
311
312void CHLRView3D::DragEvent(const Standard_Integer x ,
313 const Standard_Integer y ,
314 const Standard_Integer TheState )
315{
316
317 // TheState == -1 button down
318 // TheState == 0 move
319 // TheState == 1 button up
320
321 static Standard_Integer theButtonDownX=0;
322 static Standard_Integer theButtonDownY=0;
323
324 if (TheState == -1)
325 {
326 theButtonDownX=x;
327 theButtonDownY=y;
328 }
329
330 if (TheState == 0)
331 GetDocument()->GetAISContext()->Select(theButtonDownX,theButtonDownY,x,y,myView);
332}
333
334//-----------------------------------------------------------------------------------------
335//
336//-----------------------------------------------------------------------------------------
337void CHLRView3D::InputEvent(const Standard_Integer x ,
338 const Standard_Integer y )
339{
340 GetDocument()->GetAISContext()->Select();
341}
342
343//-----------------------------------------------------------------------------------------
344//
345//-----------------------------------------------------------------------------------------
346void CHLRView3D::MoveEvent(const Standard_Integer x ,
347 const Standard_Integer y )
348{
349 GetDocument()->GetAISContext()->MoveTo(x,y,myView);
350}
351
352//-----------------------------------------------------------------------------------------
353//
354//-----------------------------------------------------------------------------------------
355void CHLRView3D::MultiMoveEvent(const Standard_Integer x ,
356 const Standard_Integer y )
357{
358 GetDocument()->GetAISContext()->MoveTo(x,y,myView);
359}
360
361//-----------------------------------------------------------------------------------------
362//
363//-----------------------------------------------------------------------------------------
364void CHLRView3D::MultiDragEvent(const Standard_Integer x ,
365 const Standard_Integer y ,
366 const Standard_Integer TheState )
367{
368 static Standard_Integer theButtonDownX=0;
369 static Standard_Integer theButtonDownY=0;
370
371 if (TheState == -1)
372 {
373 theButtonDownX=x;
374 theButtonDownY=y;
375 }
376
377 if (TheState == 0)
378 GetDocument()->GetAISContext()->ShiftSelect(theButtonDownX,theButtonDownY,x,y,myView);
379}
380
381
382//-----------------------------------------------------------------------------------------
383//
384//-----------------------------------------------------------------------------------------
385void CHLRView3D::MultiInputEvent(const Standard_Integer x ,
386 const Standard_Integer y )
387{
388 GetDocument()->GetAISContext()->ShiftSelect();
389}
390