1 // HLRView.cpp : implementation of the CHLRView3D3D class
9 #include "..\..\Common\res\OCC_Resource.h"
12 //#define new DEBUG_NEW by CasCade
14 static char THIS_FILE[] = __FILE__;
17 // for elastic bean selection
20 // the key for multi selection :
21 #define MULTISELECTIONKEY MK_SHIFT
23 // the key for shortcut ( use to activate dynamic rotation, panning )
24 #define CASCADESHORTCUTKEY MK_CONTROL
26 // define in witch case you want to display the popup
27 #define POPUPONBUTTONDOWN
29 /////////////////////////////////////////////////////////////////////////////
32 IMPLEMENT_DYNCREATE(CHLRView3D, OCC_3dView)
34 BEGIN_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!
46 /////////////////////////////////////////////////////////////////////////////
47 // CHLRView3D construction/destruction
49 CHLRView3D::CHLRView3D()
53 CHLRView3D::~CHLRView3D()
57 void CHLRView3D::OnInitialUpdate()
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();
64 // store for restore state after rotation (witch is in Degenerated mode)
65 myDegenerateModeIsOn = myView->DegenerateModeIsOn();
67 Handle(Graphic3d_WNTGraphicDevice) theGraphicDevice =
68 ((CHLRApp*)AfxGetApp())->GetGraphicDevice();
70 Handle(WNT_Window) aWNTWindow = new WNT_Window(theGraphicDevice,GetSafeHwnd ());
71 myView->SetWindow(aWNTWindow);
72 if (!aWNTWindow->IsMapped()) aWNTWindow->Map();
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 */
78 /* I suspect another problem elsewhere */
79 ::PostMessage ( GetSafeHwnd () , WM_SIZE , SIZE_RESTORED , w + h*65536 ) ;
81 // store the mode ( nothing , dynamic zooming, dynamic ... )
82 myCurrentMode = CurAction3d_Nothing;
86 /////////////////////////////////////////////////////////////////////////////
87 // CHLRView3D diagnostics
90 void CHLRView3D::AssertValid() const
95 void CHLRView3D::Dump(CDumpContext& dc) const
100 CHLRDoc* CHLRView3D::GetDocument() // non-debug version is inline
102 ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CHLRDoc)));
103 return (CHLRDoc*)m_pDocument;
107 /////////////////////////////////////////////////////////////////////////////
108 // CHLRView3D message handlers
111 void CHLRView3D::OnLButtonDown(UINT nFlags, CPoint point)
113 // save the current mouse coordinate in min
114 myXmin=point.x; myYmin=point.y;
115 myXmax=point.x; myYmax=point.y;
117 if ( nFlags & CASCADESHORTCUTKEY )
119 // Button MB1 down Control :start zomming
120 // SetCursor(AfxGetApp()->LoadStandardCursor());
124 switch (myCurrentMode)
126 case CurAction3d_Nothing : // start a drag
127 if (nFlags & MULTISELECTIONKEY)
128 MultiDragEvent(myXmax,myYmax,-1);
130 DragEvent(myXmax,myYmax,-1);
133 case CurAction3d_DynamicZooming : // noting
135 case CurAction3d_WindowZooming : // noting
137 case CurAction3d_DynamicPanning :// noting
139 case CurAction3d_GlobalPanning :// noting
141 case CurAction3d_DynamicRotation :
142 if (!myDegenerateModeIsOn)
143 myView->SetDegenerateModeOn();
144 myView->StartRotation(point.x,point.y);
147 Standard_Failure::Raise(" incompatible Current Mode ");
153 void CHLRView3D::OnLButtonUp(UINT nFlags, CPoint point)
155 if ( nFlags & CASCADESHORTCUTKEY )
161 switch (myCurrentMode)
163 case CurAction3d_Nothing :
164 if (point.x == myXmin && point.y == myYmin)
165 { // no offset between down and up --> selectEvent
168 if (nFlags & MULTISELECTIONKEY )
169 MultiInputEvent(point.x,point.y);
171 InputEvent (point.x,point.y);
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);
179 DragEvent(point.x,point.y,1);
182 case CurAction3d_DynamicZooming :
183 // SetCursor(AfxGetApp()->LoadStandardCursor());
184 myCurrentMode = CurAction3d_Nothing;
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.
192 // Do the zoom window between Pmin and Pmax
193 myView->WindowFitAll(myXmin,myYmin,myXmax,myYmax);
195 myCurrentMode = CurAction3d_Nothing;
197 case CurAction3d_DynamicPanning :
198 myCurrentMode = CurAction3d_Nothing;
200 case CurAction3d_GlobalPanning :
201 myView->Place(point.x,point.y,myCurZoom);
202 myCurrentMode = CurAction3d_Nothing;
204 case CurAction3d_DynamicRotation :
205 myCurrentMode = CurAction3d_Nothing;
208 Standard_Failure::Raise(" incompatible Current Mode ");
210 } //switch (myCurrentMode)
211 } // else // if ( Ctrl )
214 void CHLRView3D::OnRButtonDown(UINT nFlags, CPoint point)
216 if ( nFlags & CASCADESHORTCUTKEY )
218 if (!myDegenerateModeIsOn)
219 myView->SetDegenerateModeOn();
220 myView->StartRotation(point.x,point.y);
222 else // if ( CASCADESHORTCUTKEY )
224 #ifdef POPUPONBUTTONDOWN
225 GetDocument()->Popup(point.x,point.y, myView);
230 void CHLRView3D::OnMouseMove(UINT nFlags, CPoint point)
232 // ============================ LEFT BUTTON =======================
233 if ( nFlags & MK_LBUTTON)
235 if ( nFlags & CASCADESHORTCUTKEY )
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
246 switch (myCurrentMode)
248 case CurAction3d_Nothing :
249 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False);
252 if (nFlags & MULTISELECTIONKEY)
253 MultiDragEvent(myXmax,myYmax,0);
255 DragEvent(myXmax,myYmax,0);
256 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_True);
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;
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);
268 case CurAction3d_DynamicPanning :
269 myView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
270 myXmax = point.x; myYmax = point.y;
272 case CurAction3d_GlobalPanning : // nothing
274 case CurAction3d_DynamicRotation :
275 myView->Rotation(point.x,point.y);
279 Standard_Failure::Raise(" incompatible Current Mode ");
281 }// switch (myCurrentMode)
282 }// if ( nFlags & CASCADESHORTCUTKEY ) else
283 } else // if ( nFlags & MK_LBUTTON)
284 // ============================ MIDDLE BUTTON =======================
285 if ( nFlags & MK_MBUTTON)
287 if ( nFlags & CASCADESHORTCUTKEY )
289 myView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
290 myXmax = point.x; myYmax = point.y;
293 } else // if ( nFlags & MK_MBUTTON)
294 // ============================ RIGHT BUTTON =======================
295 if ( nFlags & MK_RBUTTON)
297 if ( nFlags & CASCADESHORTCUTKEY )
299 myView->Rotation(point.x,point.y);
301 }else //if ( nFlags & MK_RBUTTON)
302 // ============================ NO BUTTON =======================
304 myXmax = point.x; myYmax = point.y;
305 if (nFlags & MULTISELECTIONKEY)
306 MultiMoveEvent(point.x,point.y);
308 MoveEvent(point.x,point.y);
312 void CHLRView3D::DragEvent(const Standard_Integer x ,
313 const Standard_Integer y ,
314 const Standard_Integer TheState )
317 // TheState == -1 button down
318 // TheState == 0 move
319 // TheState == 1 button up
321 static Standard_Integer theButtonDownX=0;
322 static Standard_Integer theButtonDownY=0;
331 GetDocument()->GetAISContext()->Select(theButtonDownX,theButtonDownY,x,y,myView);
334 //-----------------------------------------------------------------------------------------
336 //-----------------------------------------------------------------------------------------
337 void CHLRView3D::InputEvent(const Standard_Integer x ,
338 const Standard_Integer y )
340 GetDocument()->GetAISContext()->Select();
343 //-----------------------------------------------------------------------------------------
345 //-----------------------------------------------------------------------------------------
346 void CHLRView3D::MoveEvent(const Standard_Integer x ,
347 const Standard_Integer y )
349 GetDocument()->GetAISContext()->MoveTo(x,y,myView);
352 //-----------------------------------------------------------------------------------------
354 //-----------------------------------------------------------------------------------------
355 void CHLRView3D::MultiMoveEvent(const Standard_Integer x ,
356 const Standard_Integer y )
358 GetDocument()->GetAISContext()->MoveTo(x,y,myView);
361 //-----------------------------------------------------------------------------------------
363 //-----------------------------------------------------------------------------------------
364 void CHLRView3D::MultiDragEvent(const Standard_Integer x ,
365 const Standard_Integer y ,
366 const Standard_Integer TheState )
368 static Standard_Integer theButtonDownX=0;
369 static Standard_Integer theButtonDownY=0;
378 GetDocument()->GetAISContext()->ShiftSelect(theButtonDownX,theButtonDownY,x,y,myView);
382 //-----------------------------------------------------------------------------------------
384 //-----------------------------------------------------------------------------------------
385 void CHLRView3D::MultiInputEvent(const Standard_Integer x ,
386 const Standard_Integer y )
388 GetDocument()->GetAISContext()->ShiftSelect();