7fd59977 |
1 | // Viewer3dView.cpp : implementation of the CViewer3dView class |
2 | // |
3 | |
4 | #include "stdafx.h" |
5 | |
6 | #include "Viewer3dView.h" |
7 | |
8 | #include "OCC_MainFrame.h" |
9 | #include "Viewer3dApp.h" |
10 | #include "Viewer3dDoc.h" |
11 | #include "ZClippingDlg.h" |
12 | #include "ZCueingDlg.h" |
13 | #include "ScaleDlg.h" |
14 | #include "ShadingModelDlg.h" |
15 | #include "ModelClippingDlg.h" |
16 | #include "TrihedronDlg.h" |
17 | |
18 | #include <V3d_AmbientLight.hxx> |
19 | #include <V3d_DirectionalLight.hxx> |
20 | #include <V3d_PositionalLight.hxx> |
21 | #include <V3d_PositionLight.hxx> |
22 | #include <V3d_SpotLight.hxx> |
23 | #include <TopoDS_Solid.hxx> |
24 | #include <Precision.hxx> |
25 | #include <Graphic3d_GraphicDriver.hxx> |
26 | |
27 | #define ValZWMin 1 |
28 | #define X_Key 0x58 |
29 | #define Y_Key 0x59 |
30 | #define Z_Key 0x5A |
31 | |
32 | #define ModelClipping |
33 | |
34 | #ifdef _DEBUG |
35 | #undef THIS_FILE |
36 | static char THIS_FILE[] = __FILE__; |
37 | #endif |
38 | |
39 | //gp_Pnt ConvertClickToPoint(Standard_Real x, Standard_Real y, Handle(V3d_View) aView); |
40 | |
41 | gp_Pnt p1,p2,p3; |
42 | Handle(AIS_Shape) spotConeShape=new AIS_Shape(TopoDS_Solid()); |
43 | Handle(AIS_Shape) directionalEdgeShape=new AIS_Shape(TopoDS_Edge()); |
44 | |
45 | ///////////////////////////////////////////////////////////////////////////// |
46 | // CViewer3dView |
47 | |
48 | IMPLEMENT_DYNCREATE(CViewer3dView, CView) |
49 | |
50 | BEGIN_MESSAGE_MAP(CViewer3dView, CView) |
51 | //{{AFX_MSG_MAP(CViewer3dView) |
52 | ON_COMMAND(ID_BUTTONAxo, OnBUTTONAxo) |
53 | ON_COMMAND(ID_BUTTONBack, OnBUTTONBack) |
54 | ON_COMMAND(ID_BUTTONBottom, OnBUTTONBottom) |
55 | ON_COMMAND(ID_BUTTONFront, OnBUTTONFront) |
56 | ON_COMMAND(ID_BUTTONHlrOff, OnBUTTONHlrOff) |
57 | ON_COMMAND(ID_BUTTONHlrOn, OnBUTTONHlrOn) |
58 | ON_COMMAND(ID_BUTTONLeft, OnBUTTONLeft) |
59 | ON_COMMAND(ID_BUTTONPan, OnBUTTONPan) |
60 | ON_COMMAND(ID_BUTTONPanGlo, OnBUTTONPanGlo) |
61 | ON_COMMAND(ID_BUTTONReset, OnBUTTONReset) |
62 | ON_COMMAND(ID_BUTTONRight, OnBUTTONRight) |
63 | ON_COMMAND(ID_BUTTONRot, OnBUTTONRot) |
64 | ON_COMMAND(ID_BUTTONTop, OnBUTTONTop) |
65 | ON_COMMAND(ID_BUTTONZoomAll, OnBUTTONZoomAll) |
66 | ON_WM_SIZE() |
67 | ON_COMMAND(ID_BUTTONZoomProg, OnBUTTONZoomProg) |
68 | ON_COMMAND(ID_BUTTONZoomWin, OnBUTTONZoomWin) |
69 | ON_WM_LBUTTONDOWN() |
70 | ON_WM_KEYDOWN() |
71 | ON_WM_LBUTTONUP() |
72 | ON_WM_MBUTTONDOWN() |
73 | ON_WM_MBUTTONUP() |
74 | ON_WM_MOUSEMOVE() |
75 | ON_WM_RBUTTONDOWN() |
76 | ON_WM_RBUTTONUP() |
77 | ON_UPDATE_COMMAND_UI(ID_BUTTONHlrOff, OnUpdateBUTTONHlrOff) |
78 | ON_UPDATE_COMMAND_UI(ID_BUTTONHlrOn, OnUpdateBUTTONHlrOn) |
79 | ON_UPDATE_COMMAND_UI(ID_BUTTONPanGlo, OnUpdateBUTTONPanGlo) |
80 | ON_UPDATE_COMMAND_UI(ID_BUTTONPan, OnUpdateBUTTONPan) |
81 | ON_UPDATE_COMMAND_UI(ID_BUTTONZoomProg, OnUpdateBUTTONZoomProg) |
82 | ON_UPDATE_COMMAND_UI(ID_BUTTONZoomWin, OnUpdateBUTTONZoomWin) |
83 | ON_UPDATE_COMMAND_UI(ID_BUTTONRot, OnUpdateBUTTONRot) |
84 | ON_COMMAND(ID_Modify_ChangeBackground , OnModifyChangeBackground) |
85 | ON_COMMAND(ID_DIRECTIONAL_LIGHT, OnDirectionalLight) |
86 | ON_COMMAND(ID_SPOT_LIGHT, OnSpotLight) |
87 | ON_COMMAND(ID_POSITIONAL_LIGHT, OnPositionalLight) |
88 | ON_COMMAND(ID_AMBIENT_LIGHT, OnAmbientLight) |
89 | ON_COMMAND(ID_ZCUEING, OnZcueing) |
90 | ON_COMMAND(ID_SCALE, OnScale) |
91 | ON_COMMAND(ID_ZCLIPPING, OnZclipping) |
92 | ON_COMMAND(ID_SHADINGMODEL, OnShadingmodel) |
93 | ON_COMMAND(ID_ANTIALIASINGONOFF, OnAntialiasingonoff) |
94 | ON_COMMAND(ID_CLEAR_LIGHTS, OnClearLights) |
95 | ON_COMMAND(ID_MODELCLIPPING, OnModelclipping) |
96 | ON_COMMAND(ID_OPTIONS_TRIHEDRON_STATIC_TRIHEDRON, OnOptionsTrihedronStaticTrihedron) |
97 | //}}AFX_MSG_MAP |
98 | END_MESSAGE_MAP() |
99 | |
100 | ///////////////////////////////////////////////////////////////////////////// |
101 | // CViewer3dView construction/destruction |
102 | |
103 | CViewer3dView::CViewer3dView() |
104 | { |
105 | // TODO: add construction code here |
106 | myXmin=0; |
107 | myYmin=0; |
108 | myXmax=0; |
109 | myYmax=0; |
110 | myCurZoom=0; |
111 | myWidth=0; |
112 | myHeight=0; |
113 | |
114 | scaleX = 1; |
115 | scaleY = 1; |
116 | scaleZ = 1; |
117 | |
118 | myAxisKey = 0; |
119 | myScaleDirection = 0; |
120 | |
121 | |
122 | myVisMode = VIS_SHADE; |
123 | |
124 | // will be set in OnInitial update, but, for more security : |
125 | myCurrentMode = CurAction3d_Nothing; |
126 | myDegenerateModeIsOn=Standard_True; |
127 | m_Pen = NULL; |
128 | NbActiveLights=2; // There are 2 default active lights |
129 | myGraphicDriver = Handle(Graphic3d_GraphicDriver)::DownCast( |
130 | ((CViewer3dApp*)AfxGetApp())->GetGraphicDevice()->GraphicDriver() ); |
131 | } |
132 | |
133 | CViewer3dView::~CViewer3dView() |
134 | { |
135 | myView->Remove(); |
136 | if (m_Pen) delete m_Pen; |
137 | } |
138 | |
139 | BOOL CViewer3dView::PreCreateWindow(CREATESTRUCT& cs) |
140 | { |
141 | // TODO: Modify the Window class or styles here by modifying |
142 | // the CREATESTRUCT cs |
143 | |
144 | return CView::PreCreateWindow(cs); |
145 | } |
146 | |
147 | ///////////////////////////////////////////////////////////////////////////// |
148 | // CViewer3dView drawing |
149 | void CViewer3dView::OnInitialUpdate() |
150 | { |
151 | CView::OnInitialUpdate(); |
152 | |
153 | |
154 | myView = GetDocument()->GetViewer()->CreateView(); |
155 | |
156 | // set the default mode in wireframe ( not hidden line ! ) |
157 | myView->SetDegenerateModeOn(); |
158 | // store for restore state after rotation (witch is in Degenerated mode) |
159 | myDegenerateModeIsOn = Standard_True; |
160 | |
161 | |
162 | Handle(Graphic3d_WNTGraphicDevice) theGraphicDevice = |
163 | ((CViewer3dApp*)AfxGetApp())->GetGraphicDevice(); |
164 | |
165 | Handle(WNT_Window) aWNTWindow = new WNT_Window(theGraphicDevice,GetSafeHwnd ()); |
166 | myView->SetWindow(aWNTWindow); |
167 | if (!aWNTWindow->IsMapped()) aWNTWindow->Map(); |
168 | |
169 | // Standard_Integer w=100 , h=100 ; /* Debug Matrox */ |
170 | // aWNTWindow->Size (w,h) ; /* Keeps me unsatisfied (rlb)..... */ |
171 | /* Resize is not supposed to be done on */ |
172 | /* Matrox */ |
173 | /* I suspect another problem elsewhere */ |
174 | // ::PostMessage ( GetSafeHwnd () , WM_SIZE , SIZE_RESTORED , w + h*65536 ) ; |
175 | |
176 | // store the mode ( nothing , dynamic zooming, dynamic ... ) |
177 | myCurrentMode = CurAction3d_Nothing; |
178 | myVisMode = VIS_SHADE; |
179 | RedrawVisMode(); |
180 | } |
181 | |
182 | void CViewer3dView::OnDraw(CDC* pDC) |
183 | { |
184 | CViewer3dDoc* pDoc = GetDocument(); |
185 | ASSERT_VALID(pDoc); |
186 | CRect aRect; |
187 | GetWindowRect(aRect); |
188 | if(myWidth != aRect.Width() || myHeight != aRect.Height()) { |
189 | myWidth = aRect.Width(); |
190 | myHeight = aRect.Height(); |
191 | ::PostMessage ( GetSafeHwnd () , WM_SIZE , SW_SHOW , myWidth + myHeight*65536 ); |
192 | } |
193 | myView->Redraw(); |
194 | |
195 | } |
196 | |
197 | ///////////////////////////////////////////////////////////////////////////// |
198 | // CViewer3dView diagnostics |
199 | |
200 | #ifdef _DEBUG |
201 | void CViewer3dView::AssertValid() const |
202 | { |
203 | CView::AssertValid(); |
204 | } |
205 | |
206 | void CViewer3dView::Dump(CDumpContext& dc) const |
207 | { |
208 | CView::Dump(dc); |
209 | } |
210 | |
211 | CViewer3dDoc* CViewer3dView::GetDocument() // non-debug version is inline |
212 | { |
213 | ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CViewer3dDoc))); |
214 | return (CViewer3dDoc*)m_pDocument; |
215 | } |
216 | #endif //_DEBUG |
217 | |
218 | ///////////////////////////////////////////////////////////////////////////// |
219 | // CViewer3dView message handlers |
220 | |
221 | gp_Pnt ConvertClickToPoint(Standard_Real x, Standard_Real y, Handle(V3d_View) aView) |
222 | { |
223 | V3d_Coordinate XEye,YEye,ZEye,XAt,YAt,ZAt; |
224 | aView->Eye(XEye,YEye,ZEye); |
225 | aView->At(XAt,YAt,ZAt); |
226 | gp_Pnt EyePoint(XEye,YEye,ZEye); |
227 | gp_Pnt AtPoint(XAt,YAt,ZAt); |
228 | |
229 | gp_Vec EyeVector(EyePoint,AtPoint); |
230 | gp_Dir EyeDir(EyeVector); |
231 | |
232 | gp_Pln PlaneOfTheView = gp_Pln(AtPoint,EyeDir); |
233 | Standard_Real X,Y,Z; |
234 | aView->Convert(int(x),int(y),X,Y,Z); |
235 | gp_Pnt ConvertedPoint(X,Y,Z); |
236 | gp_Pnt2d ConvertedPointOnPlane = ProjLib::Project(PlaneOfTheView,ConvertedPoint); |
237 | |
238 | gp_Pnt ResultPoint = ElSLib::Value(ConvertedPointOnPlane.X(), |
239 | ConvertedPointOnPlane.Y(), |
240 | PlaneOfTheView); |
241 | return ResultPoint; |
242 | } |
243 | |
244 | void CViewer3dView::OnSize(UINT nType, int cx, int cy) |
245 | { |
246 | if (!myView.IsNull()) |
247 | myView->MustBeResized(); |
248 | } |
249 | |
250 | void CViewer3dView::OnBUTTONBack() |
251 | { |
252 | myView->SetProj(V3d_Xneg); |
253 | |
254 | TCollection_AsciiString Message("\ |
255 | myView->SetProj(V3d_Xneg);\n\ |
256 | "); |
257 | |
258 | // Update The Result Message Dialog |
259 | GetDocument()->UpdateResultMessageDlg("SetProj",Message); |
260 | } // See the back View |
261 | void CViewer3dView::OnBUTTONFront() |
262 | { |
263 | myView->SetProj(V3d_Xpos); |
264 | |
265 | TCollection_AsciiString Message("\ |
266 | myView->SetProj(V3d_Xpos);\n\ |
267 | "); |
268 | |
269 | // Update The Result Message Dialog |
270 | GetDocument()->UpdateResultMessageDlg("SetProj",Message); |
271 | } // See the front View |
272 | |
273 | void CViewer3dView::OnBUTTONBottom() |
274 | { |
275 | myView->SetProj(V3d_Zneg); |
276 | |
277 | TCollection_AsciiString Message("\ |
278 | myView->SetProj(V3d_Zneg);\n\ |
279 | "); |
280 | |
281 | // Update The Result Message Dialog |
282 | GetDocument()->UpdateResultMessageDlg("SetProj",Message); |
283 | } // See the bottom View |
284 | void CViewer3dView::OnBUTTONTop() |
285 | { |
286 | myView->SetProj(V3d_Zpos); |
287 | |
288 | TCollection_AsciiString Message("\ |
289 | myView->SetProj(V3d_Zpos);\n\ |
290 | "); |
291 | |
292 | // Update The Result Message Dialog |
293 | GetDocument()->UpdateResultMessageDlg("SetProj",Message); |
294 | } // See the top View |
295 | |
296 | void CViewer3dView::OnBUTTONLeft() |
297 | { |
298 | myView->SetProj(V3d_Ypos); |
299 | |
300 | TCollection_AsciiString Message("\ |
301 | myView->SetProj(V3d_Ypos);\n\ |
302 | "); |
303 | |
304 | // Update The Result Message Dialog |
305 | GetDocument()->UpdateResultMessageDlg("SetProj",Message); |
306 | } // See the left View |
307 | void CViewer3dView::OnBUTTONRight() |
308 | { |
309 | myView->SetProj(V3d_Yneg); |
310 | |
311 | TCollection_AsciiString Message("\ |
312 | myView->SetProj(V3d_Yneg);\n\ |
313 | "); |
314 | |
315 | // Update The Result Message Dialog |
316 | GetDocument()->UpdateResultMessageDlg("SetProj",Message); |
317 | } // See the right View |
318 | |
319 | void CViewer3dView::OnBUTTONAxo() |
320 | { |
321 | myView->SetProj(V3d_XposYnegZpos); |
322 | |
323 | TCollection_AsciiString Message("\ |
324 | myView->SetProj(V3d_XposYnegZpos);\n\ |
325 | "); |
326 | |
327 | // Update The Result Message Dialog |
328 | GetDocument()->UpdateResultMessageDlg("SetProj",Message); |
329 | } // See the axonometric View |
330 | |
331 | void CViewer3dView::OnBUTTONHlrOff() |
332 | { |
333 | myView->SetDegenerateModeOn(); |
334 | myDegenerateModeIsOn = Standard_True; |
335 | |
336 | TCollection_AsciiString Message("\ |
337 | myView->SetDegenerateModeOn();\n\ |
338 | "); |
339 | |
340 | // Update The Result Message Dialog |
341 | GetDocument()->UpdateResultMessageDlg("SetDegenerateModeOn",Message); |
342 | } |
343 | |
344 | void CViewer3dView::OnBUTTONHlrOn() |
345 | { |
346 | SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT)); |
347 | myView->SetDegenerateModeOff(); |
348 | myDegenerateModeIsOn = Standard_False; |
349 | SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW)); |
350 | |
351 | TCollection_AsciiString Message("\ |
352 | myView->SetDegenerateModeOff();\n\ |
353 | "); |
354 | |
355 | // Update The Result Message Dialog |
356 | GetDocument()->UpdateResultMessageDlg("SetDegenerateModeOff",Message); |
357 | } |
358 | |
359 | void CViewer3dView::OnBUTTONPan() |
360 | { myCurrentMode = CurAction3d_DynamicPanning; } |
361 | |
362 | void CViewer3dView::OnBUTTONPanGlo() |
363 | { |
364 | // save the current zoom value |
365 | myCurZoom = myView->Scale(); |
366 | // Do a Global Zoom |
367 | myView->FitAll(); |
368 | // Set the mode |
369 | myCurrentMode = CurAction3d_GlobalPanning; |
370 | } |
371 | |
372 | void CViewer3dView::OnBUTTONReset() |
373 | { myView->Reset(); } |
374 | |
375 | void CViewer3dView::OnBUTTONRot() |
376 | { myCurrentMode = CurAction3d_DynamicRotation; } |
377 | |
378 | |
379 | void CViewer3dView::OnBUTTONZoomAll() |
380 | { |
381 | myView->FitAll(); |
382 | myView->ZFitAll(); |
383 | } |
384 | |
385 | void CViewer3dView::OnBUTTONZoomProg() |
386 | { myCurrentMode = CurAction3d_DynamicZooming; } |
387 | |
388 | void CViewer3dView::OnBUTTONZoomWin() |
389 | { myCurrentMode = CurAction3d_WindowZooming; } |
390 | |
391 | void CViewer3dView::OnLButtonDown(UINT nFlags, CPoint point) |
392 | { |
393 | // save the current mouse coordinate in min |
394 | myXmin=point.x; myYmin=point.y; |
395 | myXmax=point.x; myYmax=point.y; |
396 | |
397 | if ( nFlags & MK_CONTROL ) |
398 | { |
399 | // Button MB1 down Control :start zomming |
400 | // SetCursor(AfxGetApp()->LoadStandardCursor()); |
401 | } |
402 | else // if ( Ctrl ) |
403 | { |
404 | switch (myCurrentMode) |
405 | { |
406 | case CurAction3d_Nothing : // start a drag |
407 | if (nFlags & MK_SHIFT) |
408 | GetDocument()->ShiftDragEvent(myXmax,myYmax,-1,myView); |
409 | else |
410 | GetDocument()->DragEvent(myXmax,myYmax,-1,myView); |
411 | break; |
412 | break; |
413 | case CurAction3d_DynamicZooming : // noting |
414 | break; |
415 | case CurAction3d_WindowZooming : |
416 | break; |
417 | case CurAction3d_DynamicPanning :// noting |
418 | break; |
419 | case CurAction3d_GlobalPanning :// noting |
420 | break; |
421 | case CurAction3d_DynamicRotation : |
422 | if (!myDegenerateModeIsOn) |
423 | myView->SetDegenerateModeOn(); |
424 | myView->StartRotation(point.x,point.y); |
425 | break; |
426 | case CurAction3d_BeginPositionalLight : |
427 | { |
428 | p1 = ConvertClickToPoint(point.x,point.y,myView); |
429 | myCurrent_PositionalLight->SetPosition(p1.X(),p1.Y(),p1.Z()) ; |
430 | GetDocument()->GetAISContext()->CloseLocalContext(); |
431 | ((OCC_MainFrame*)AfxGetMainWnd())->SetStatusMessage("Ready"); |
432 | myCurrentMode = CurAction3d_Nothing; |
433 | |
434 | TCollection_AsciiString Message("\ |
435 | myCurrent_PositionalLight->SetPosition(Xp, Yp, Zp) ;\n\ |
436 | "); |
437 | // Update The Result Message Dialog |
438 | GetDocument()->UpdateResultMessageDlg("SetPosition",Message); |
439 | } |
440 | break; |
441 | case CurAction3d_BeginSpotLight : |
442 | { |
443 | p1 = ConvertClickToPoint(point.x,point.y,myView); |
444 | myCurrent_SpotLight = new V3d_SpotLight(myView->Viewer(),0.,0.,1., p1.X(),p1.Y(),p1.Z(),Quantity_NOC_RED); |
445 | myView->SetLightOn(myCurrent_SpotLight); |
446 | NbActiveLights++; |
447 | p2 = gp_Pnt(p1.X(),p1.Y(),p1.Z()+1.); |
448 | Standard_Real coneHeigth=p1.Distance(p2); |
449 | BRepPrimAPI_MakeCone MakeCone(gp_Ax2(p1, gp_Dir(gp_Vec(p1, p2))), |
450 | 0, (p1.Distance(p2))/tan(1.04), coneHeigth); |
451 | spotConeShape->Set(MakeCone.Solid()); |
452 | GetDocument()->GetAISContext()->Display(spotConeShape,0,-1); |
453 | ((OCC_MainFrame*)AfxGetMainWnd())->SetStatusMessage("Pick the target point"); |
454 | myCurrentMode = CurAction3d_TargetSpotLight; |
455 | |
456 | TCollection_AsciiString Message("\ |
457 | myCurrent_SpotLight->SetDirection(Xv, Yv, Zv);\n\ |
458 | "); |
459 | // Update The Result Message Dialog |
460 | GetDocument()->UpdateResultMessageDlg("SetDirection",Message); |
461 | } |
462 | break; |
463 | case CurAction3d_TargetSpotLight : |
464 | { |
465 | p2 = ConvertClickToPoint(point.x,point.y,myView); |
466 | ((OCC_MainFrame*)AfxGetMainWnd())->SetStatusMessage("Pick a third point (to define the angle)"); |
467 | myCurrentMode = CurAction3d_EndSpotLight; |
468 | |
469 | TCollection_AsciiString Message("\ |
470 | myCurrent_SpotLight->SetAngle(Angle) ;\n\ |
471 | "); |
472 | // Update The Result Message Dialog |
473 | GetDocument()->UpdateResultMessageDlg("SetAngle",Message); |
474 | } |
475 | break; |
476 | case CurAction3d_EndSpotLight : |
477 | GetDocument()->GetAISContext()->Erase(spotConeShape); |
478 | GetDocument()->GetAISContext()->CloseLocalContext(); |
479 | ((OCC_MainFrame*)AfxGetMainWnd())->SetStatusMessage("Ready"); |
480 | myCurrentMode = CurAction3d_Nothing; |
481 | break; |
482 | case CurAction3d_BeginDirectionalLight: |
483 | { |
484 | p1 = ConvertClickToPoint(point.x,point.y,myView); |
485 | p2 = gp_Pnt(p1.X(),p1.Y(),p1.Z()+1.); |
486 | BRepBuilderAPI_MakeEdge MakeEdge(p1, p2); |
487 | directionalEdgeShape->Set(MakeEdge.Edge()); |
488 | GetDocument()->GetAISContext()->Display(directionalEdgeShape,0,-1); |
489 | // Create a directional light |
490 | myCurrent_DirectionalLight = new V3d_DirectionalLight(myView->Viewer(), p1.X(),p1.Y(),p1.Z(),0.,0.,1.); |
491 | myView->SetLightOn(myCurrent_DirectionalLight); |
492 | NbActiveLights++; |
493 | ((OCC_MainFrame*)AfxGetMainWnd())->SetStatusMessage("Pick the target point"); |
494 | myCurrentMode = CurAction3d_EndDirectionalLight; |
495 | |
496 | |
497 | TCollection_AsciiString Message("\ |
498 | myCurrent_DirectionalLight->SetDirection(Xv, Yv, Zv);\n\ |
499 | "); |
500 | // Update The Result Message Dialog |
501 | GetDocument()->UpdateResultMessageDlg("SetDirection",Message); |
502 | } |
503 | break; |
504 | case CurAction3d_EndDirectionalLight: |
505 | GetDocument()->GetAISContext()->Erase(directionalEdgeShape); |
506 | GetDocument()->GetAISContext()->CloseLocalContext(); |
507 | ((OCC_MainFrame*)AfxGetMainWnd())->SetStatusMessage("Ready"); |
508 | myCurrentMode = CurAction3d_Nothing; |
509 | break; |
510 | } |
511 | } |
512 | } |
513 | |
514 | void CViewer3dView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) |
515 | { |
516 | |
517 | if( nChar == X_Key || nChar == Y_Key || nChar == Z_Key ) |
518 | myAxisKey = nChar; |
519 | else if( (nChar == VK_ADD || nChar == VK_SUBTRACT) && myAxisKey ) |
520 | { |
521 | myScaleDirection = nChar; |
522 | if( myAxisKey && myScaleDirection ) |
523 | { |
524 | switch( myAxisKey ) |
525 | { |
526 | case X_Key: |
527 | if( myScaleDirection == VK_ADD ) scaleX ++; |
528 | if( myScaleDirection == VK_SUBTRACT ) scaleX --; |
529 | break; |
530 | case Y_Key: |
531 | if( myScaleDirection == VK_ADD ) scaleY ++; |
532 | if( myScaleDirection == VK_SUBTRACT ) scaleY --; |
533 | break; |
534 | case Z_Key: |
535 | if( myScaleDirection == VK_ADD ) scaleZ ++; |
536 | if( myScaleDirection == VK_SUBTRACT ) scaleZ --; |
537 | break; |
538 | default: |
539 | break; |
540 | } |
541 | if( scaleX < 1 ) scaleX = 1; |
542 | if( scaleY < 1 ) scaleY = 1; |
543 | if( scaleZ < 1 ) scaleZ = 1; |
544 | |
545 | myView->SetAxialScale( scaleX, scaleY, scaleZ ); |
546 | } |
547 | } |
548 | } |
549 | |
550 | void CViewer3dView::OnLButtonUp(UINT nFlags, CPoint point) |
551 | { |
552 | if ( nFlags & MK_CONTROL ) |
553 | { |
554 | return; |
555 | } |
556 | else // if ( Ctrl ) |
557 | { |
558 | switch (myCurrentMode) |
559 | { |
560 | case CurAction3d_Nothing : |
561 | if (point.x == myXmin && point.y == myYmin) |
562 | { // no offset between down and up --> selectEvent |
563 | myXmax=point.x; |
564 | myYmax=point.y; |
565 | if (nFlags & MK_SHIFT ) |
566 | GetDocument()->ShiftInputEvent(point.x,point.y,myView); |
567 | else |
568 | GetDocument()->InputEvent (point.x,point.y,myView); |
569 | } else |
570 | { |
571 | DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False); |
572 | myXmax=point.x; |
573 | myYmax=point.y; |
574 | if (nFlags & MK_SHIFT) |
575 | GetDocument()->ShiftDragEvent(point.x,point.y,1,myView); |
576 | else |
577 | GetDocument()->DragEvent(point.x,point.y,1,myView); |
578 | } |
579 | break; |
580 | case CurAction3d_DynamicZooming : |
581 | // SetCursor(AfxGetApp()->LoadStandardCursor()); |
582 | myCurrentMode = CurAction3d_Nothing; |
583 | break; |
584 | case CurAction3d_WindowZooming : |
585 | DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False); |
586 | myXmax=point.x; |
587 | myYmax=point.y; |
588 | if ((abs(myXmin-myXmax)>ValZWMin) || (abs(myYmin-myYmax)>ValZWMin)) |
589 | // Test if the zoom window is greater than a minimale window. |
590 | { |
591 | // Do the zoom window between Pmin and Pmax |
592 | myView->WindowFitAll(myXmin,myYmin,myXmax,myYmax); |
593 | } |
594 | myCurrentMode = CurAction3d_Nothing; |
595 | break; |
596 | case CurAction3d_DynamicPanning : |
597 | myCurrentMode = CurAction3d_Nothing; |
598 | break; |
599 | case CurAction3d_GlobalPanning : |
600 | myView->Place(point.x,point.y,myCurZoom); |
601 | myCurrentMode = CurAction3d_Nothing; |
602 | break; |
603 | case CurAction3d_DynamicRotation : |
604 | myCurrentMode = CurAction3d_Nothing; |
605 | break; |
606 | } //switch (myCurrentMode) |
607 | } // else // if ( Ctrl ) |
608 | } |
609 | |
610 | void CViewer3dView::OnMButtonDown(UINT nFlags, CPoint point) |
611 | { |
612 | if ( nFlags & MK_CONTROL ) |
613 | { |
614 | // Button MB2 down Control : panning init |
615 | // SetCursor(AfxGetApp()->LoadStandardCursor()); |
616 | } |
617 | } |
618 | |
619 | void CViewer3dView::OnMButtonUp(UINT nFlags, CPoint point) |
620 | { |
621 | if ( nFlags & MK_CONTROL ) |
622 | { |
623 | // Button MB2 down Control : panning init |
624 | // SetCursor(AfxGetApp()->LoadStandardCursor()); |
625 | } |
626 | } |
627 | |
628 | void CViewer3dView::OnRButtonDown(UINT nFlags, CPoint point) |
629 | { |
630 | if ( nFlags & MK_CONTROL ) |
631 | { |
632 | // SetCursor(AfxGetApp()->LoadStandardCursor()); |
633 | if (!myDegenerateModeIsOn) |
634 | myView->SetDegenerateModeOn(); |
635 | myView->StartRotation(point.x,point.y); |
636 | } |
637 | else // if ( Ctrl ) |
638 | { |
639 | GetDocument()->Popup(point.x,point.y,myView); |
640 | } |
641 | } |
642 | |
643 | void CViewer3dView::OnRButtonUp(UINT nFlags, CPoint point) |
644 | { |
645 | SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT)); |
646 | if (!myDegenerateModeIsOn) |
647 | { |
648 | myView->SetDegenerateModeOff(); |
649 | myDegenerateModeIsOn = Standard_False; |
650 | } else |
651 | { |
652 | myView->SetDegenerateModeOn(); |
653 | myDegenerateModeIsOn = Standard_True; |
654 | } |
655 | SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW)); |
656 | } |
657 | |
658 | void CViewer3dView::OnMouseMove(UINT nFlags, CPoint point) |
659 | { |
660 | // ============================ LEFT BUTTON ======================= |
661 | if ( nFlags & MK_LBUTTON) |
662 | { |
663 | if ( nFlags & MK_CONTROL ) |
664 | { |
665 | // move with MB1 and Control : on the dynamic zooming |
666 | // Do the zoom in function of mouse's coordinates |
667 | myView->Zoom(myXmax,myYmax,point.x,point.y); |
668 | // save the current mouse coordinate in min |
669 | myXmax = point.x; |
670 | myYmax = point.y; |
671 | } |
672 | else // if ( Ctrl ) |
673 | { |
674 | switch (myCurrentMode) |
675 | { |
676 | case CurAction3d_Nothing : |
677 | myXmax = point.x; myYmax = point.y; |
678 | DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False); |
679 | if (nFlags & MK_SHIFT) |
680 | GetDocument()->ShiftDragEvent(myXmax,myYmax,0,myView); |
681 | else |
682 | GetDocument()->DragEvent(myXmax,myYmax,0,myView); |
683 | DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_True); |
684 | break; |
685 | case CurAction3d_DynamicZooming : |
686 | myView->Zoom(myXmax,myYmax,point.x,point.y); |
687 | // save the current mouse coordinate in min \n"; |
688 | myXmax=point.x; myYmax=point.y; |
689 | break; |
690 | case CurAction3d_WindowZooming : |
691 | myXmax = point.x; myYmax = point.y; |
692 | DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False,LongDash); |
693 | DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_True,LongDash); |
694 | |
695 | break; |
696 | case CurAction3d_DynamicPanning : |
697 | myView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning |
698 | myXmax = point.x; myYmax = point.y; |
699 | break; |
700 | case CurAction3d_GlobalPanning : // nothing |
701 | break; |
702 | case CurAction3d_DynamicRotation : |
703 | myView->Rotation(point.x,point.y); |
704 | myView->Redraw(); |
705 | break; |
706 | }// switch (myCurrentMode) |
707 | }// if ( nFlags & MK_CONTROL ) else |
708 | } else // if ( nFlags & MK_LBUTTON) |
709 | // ============================ MIDDLE BUTTON ======================= |
710 | if ( nFlags & MK_MBUTTON) |
711 | { |
712 | if ( nFlags & MK_CONTROL ) |
713 | { |
714 | myView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning |
715 | myXmax = point.x; myYmax = point.y; |
716 | |
717 | } |
718 | } else // if ( nFlags & MK_MBUTTON) |
719 | // ============================ RIGHT BUTTON ======================= |
720 | if ( nFlags & MK_RBUTTON) |
721 | { |
722 | if ( nFlags & MK_CONTROL ) |
723 | { |
724 | myView->Rotation(point.x,point.y); |
725 | } |
726 | }else //if ( nFlags & MK_RBUTTON) |
727 | // ============================ NO BUTTON ======================= |
728 | { // No buttons |
729 | myXmax = point.x; myYmax = point.y; |
730 | if (myCurrentMode == CurAction3d_EndDirectionalLight) |
731 | { |
732 | p2 = ConvertClickToPoint(point.x,point.y,myView); |
733 | //Update the light dynamically |
734 | if( p1.Distance(p2)>Precision::Confusion()) |
735 | { |
736 | BRepBuilderAPI_MakeEdge MakeEdge(p1, p2); |
737 | directionalEdgeShape->Set(MakeEdge.Edge()); |
738 | GetDocument()->GetAISContext()->Redisplay(directionalEdgeShape,0,-1); |
739 | myCurrent_DirectionalLight->SetDirection(p2.X()-p1.X(),p2.Y()-p1.Y(),p2.Z()-p1.Z()); |
740 | myView->UpdateLights(); |
741 | } |
742 | } |
743 | else if (myCurrentMode == CurAction3d_BeginPositionalLight) |
744 | { |
745 | p2 = ConvertClickToPoint(point.x,point.y,myView); |
746 | //Update the light dynamically |
747 | myCurrent_PositionalLight->SetPosition(p2.X(),p2.Y(),p2.Z()); |
748 | myView->UpdateLights(); |
749 | } |
750 | else if (myCurrentMode == CurAction3d_TargetSpotLight) |
751 | { |
752 | p2 = ConvertClickToPoint(point.x,point.y,myView); |
753 | //Update the light dynamically |
754 | Standard_Real coneHeigth=p1.Distance(p2); |
755 | if( coneHeigth>Precision::Confusion()) |
756 | { |
757 | BRepPrimAPI_MakeCone MakeCone(gp_Ax2(p1, gp_Dir(gp_Vec(p1, p2))), |
758 | 0, (p1.Distance(p2))/tan(1.04), coneHeigth); |
759 | spotConeShape->Set(MakeCone.Solid()); |
760 | GetDocument()->GetAISContext()->Redisplay(spotConeShape,0,-1); |
761 | myCurrent_SpotLight->SetDirection(p2.X()-p1.X(),p2.Y()-p1.Y(),p2.Z()-p1.Z()); |
762 | myView->UpdateLights(); |
763 | } |
764 | } |
765 | else if (myCurrentMode == CurAction3d_EndSpotLight) |
766 | { |
767 | p3 = ConvertClickToPoint(point.x,point.y,myView); |
768 | //Update the light dynamically |
769 | Standard_Real coneHeigth=p1.Distance(p2); |
770 | if( (p2.Distance(p3))>Precision::Confusion()) |
771 | { |
772 | BRepPrimAPI_MakeCone MakeCone(gp_Ax2(p1, gp_Dir(gp_Vec(p1, p2))), |
773 | 0, p2.Distance(p3), coneHeigth); |
774 | spotConeShape->Set(MakeCone.Solid()); |
775 | GetDocument()->GetAISContext()->Redisplay(spotConeShape,0,-1); |
776 | myCurrent_SpotLight->SetAngle(atan(p2.Distance(p3)/p1.Distance(p2))) ; |
777 | myView->UpdateLights(); |
778 | } |
779 | } |
780 | if (nFlags & MK_SHIFT) |
781 | GetDocument()->ShiftMoveEvent(point.x,point.y,myView); |
782 | else |
783 | GetDocument()->MoveEvent(point.x,point.y,myView); |
784 | } |
785 | } |
786 | |
787 | void CViewer3dView::OnUpdateBUTTONHlrOff(CCmdUI* pCmdUI) |
788 | { |
789 | pCmdUI->SetCheck (myDegenerateModeIsOn); |
790 | pCmdUI->Enable (!myDegenerateModeIsOn); |
791 | } |
792 | |
793 | void CViewer3dView::OnUpdateBUTTONHlrOn(CCmdUI* pCmdUI) |
794 | { |
795 | pCmdUI->SetCheck (!myDegenerateModeIsOn); |
796 | pCmdUI->Enable (myDegenerateModeIsOn); |
797 | } |
798 | |
799 | void CViewer3dView::OnUpdateBUTTONPanGlo(CCmdUI* pCmdUI) |
800 | { |
801 | pCmdUI->SetCheck (myCurrentMode == CurAction3d_GlobalPanning); |
802 | pCmdUI->Enable (myCurrentMode != CurAction3d_GlobalPanning); |
803 | |
804 | } |
805 | |
806 | void CViewer3dView::OnUpdateBUTTONPan(CCmdUI* pCmdUI) |
807 | { |
808 | pCmdUI->SetCheck (myCurrentMode == CurAction3d_DynamicPanning); |
809 | pCmdUI->Enable (myCurrentMode != CurAction3d_DynamicPanning ); |
810 | } |
811 | |
812 | void CViewer3dView::OnUpdateBUTTONZoomProg(CCmdUI* pCmdUI) |
813 | { |
814 | pCmdUI->SetCheck (myCurrentMode == CurAction3d_DynamicZooming ); |
815 | pCmdUI->Enable (myCurrentMode != CurAction3d_DynamicZooming); |
816 | } |
817 | |
818 | void CViewer3dView::OnUpdateBUTTONZoomWin(CCmdUI* pCmdUI) |
819 | { |
820 | pCmdUI->SetCheck (myCurrentMode == CurAction3d_WindowZooming); |
821 | pCmdUI->Enable (myCurrentMode != CurAction3d_WindowZooming); |
822 | } |
823 | |
824 | void CViewer3dView::OnUpdateBUTTONRot(CCmdUI* pCmdUI) |
825 | { |
826 | pCmdUI->SetCheck (myCurrentMode == CurAction3d_DynamicRotation); |
827 | pCmdUI->Enable (myCurrentMode != CurAction3d_DynamicRotation); |
828 | } |
829 | |
830 | void CViewer3dView::DrawRectangle(const Standard_Integer MinX , |
831 | const Standard_Integer MinY , |
832 | const Standard_Integer MaxX , |
833 | const Standard_Integer MaxY , |
834 | const Standard_Boolean Draw , |
835 | const LineStyle aLineStyle) |
836 | { |
837 | static int m_DrawMode; |
838 | if (!m_Pen && aLineStyle ==Solid ) |
839 | {m_Pen = new CPen(PS_SOLID, 1, RGB(0,0,0)); m_DrawMode = R2_MERGEPENNOT;} |
840 | else if (!m_Pen && aLineStyle ==Dot ) |
841 | {m_Pen = new CPen(PS_DOT, 1, RGB(0,0,0)); m_DrawMode = R2_XORPEN;} |
842 | else if (!m_Pen && aLineStyle == ShortDash) |
843 | {m_Pen = new CPen(PS_DASH, 1, RGB(255,0,0)); m_DrawMode = R2_XORPEN;} |
844 | else if (!m_Pen && aLineStyle == LongDash) |
845 | {m_Pen = new CPen(PS_DASH, 1, RGB(0,0,0)); m_DrawMode = R2_NOTXORPEN;} |
846 | else if (aLineStyle == Default) |
847 | { m_Pen = NULL; m_DrawMode = R2_MERGEPENNOT;} |
848 | |
849 | CPen* aOldPen; |
850 | CClientDC clientDC(this); |
851 | if (m_Pen) aOldPen = clientDC.SelectObject(m_Pen); |
852 | clientDC.SetROP2(m_DrawMode); |
853 | |
854 | static Standard_Integer StoredMinX, StoredMaxX, StoredMinY, StoredMaxY; |
855 | static Standard_Boolean m_IsVisible; |
856 | |
857 | if ( m_IsVisible && !Draw) // move or up : erase at the old position |
858 | { |
859 | clientDC.MoveTo(StoredMinX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMaxY); |
860 | clientDC.LineTo(StoredMaxX,StoredMaxY); |
861 | clientDC.LineTo(StoredMaxX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMinY); |
862 | m_IsVisible = false; |
863 | } |
864 | |
865 | StoredMinX = min ( MinX, MaxX ); |
866 | StoredMinY = min ( MinY, MaxY ); |
867 | StoredMaxX = max ( MinX, MaxX ); |
868 | StoredMaxY = max ( MinY, MaxY); |
869 | |
870 | if (Draw) // move : draw |
871 | { |
872 | clientDC.MoveTo(StoredMinX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMaxY); |
873 | clientDC.LineTo(StoredMaxX,StoredMaxY); |
874 | clientDC.LineTo(StoredMaxX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMinY); |
875 | m_IsVisible = true; |
876 | } |
877 | |
878 | if (m_Pen) clientDC.SelectObject(aOldPen); |
879 | } |
880 | |
881 | void CViewer3dView::OnModifyChangeBackground() |
882 | { |
883 | Standard_Real R1; |
884 | Standard_Real G1; |
885 | Standard_Real B1; |
886 | myView->BackgroundColor(Quantity_TOC_RGB,R1,G1,B1); |
887 | COLORREF m_clr ; |
888 | m_clr = RGB(R1*255,G1*255,B1*255); |
889 | |
890 | CColorDialog dlgColor(m_clr); |
891 | if (dlgColor.DoModal() == IDOK) |
892 | { |
893 | m_clr = dlgColor.GetColor(); |
894 | R1 = GetRValue(m_clr)/255.; |
895 | G1 = GetGValue(m_clr)/255.; |
896 | B1 = GetBValue(m_clr)/255.; |
897 | myView->SetBackgroundColor(Quantity_TOC_RGB,R1,G1,B1); |
898 | } |
899 | myView->Redraw(); |
900 | } |
901 | |
902 | void CViewer3dView::OnDirectionalLight() |
903 | { |
904 | // Directional light source creation |
905 | |
906 | // Checking if the Active lights limit number is not reached |
907 | if( NbActiveLights>=myGraphicDriver->InquireLightLimit() ) |
908 | { |
909 | char tmpStr[128]; |
910 | sprintf_s(tmpStr, "You have reach the limit number of active lights (%d).\n Clear lights to create new ones.", |
911 | myGraphicDriver->InquireLightLimit()); |
912 | MessageBox(tmpStr,"Light creation", MB_OK); |
913 | return; |
914 | } |
915 | |
916 | UpdateData(TRUE); |
917 | ((OCC_MainFrame*)AfxGetMainWnd())->SetStatusMessage("Pick a first point"); |
918 | GetDocument()->GetAISContext()->OpenLocalContext(); |
919 | myCurrentMode = CurAction3d_BeginDirectionalLight; |
920 | |
921 | TCollection_AsciiString Message("\ |
922 | myCurrent_DirectionalLight = new V3d_DirectionalLight(myView->Viewer(), Xt, Yt, Zt, Xp, Yp, Zp);\n\ |
923 | \n\ |
924 | myView->SetLightOn(myCurrent_DirectionalLight);\n\ |
925 | \n\ |
926 | "); |
927 | // Update The Result Message Dialog |
928 | GetDocument()->UpdateResultMessageDlg("V3d_DirectionalLight",Message); |
929 | } |
930 | |
931 | void CViewer3dView::OnSpotLight() |
932 | { |
933 | // Spot light source creation |
934 | |
935 | // Checking if the Active lights limit number is not reached |
936 | if( NbActiveLights>=myGraphicDriver->InquireLightLimit() ) |
937 | { |
938 | char tmpStr[128]; |
939 | sprintf_s(tmpStr, "You have reach the limit number of active lights (%d).\n Clear lights to create new ones.", |
940 | myGraphicDriver->InquireLightLimit()); |
941 | MessageBox(tmpStr,"Light creation", MB_OK); |
942 | return; |
943 | } |
944 | |
945 | GetDocument()->GetAISContext()->OpenLocalContext(); |
946 | ((OCC_MainFrame*)AfxGetMainWnd())->SetStatusMessage("Pick the light position"); |
947 | myCurrentMode = CurAction3d_BeginSpotLight; |
948 | |
949 | TCollection_AsciiString Message("\ |
950 | myCurrent_SpotLight = new V3d_SpotLight(myView->Viewer(), Xt, Yt, Zt, Xp, Yp, Zp,Quantity_NOC_RED);\n\ |
951 | \n\ |
952 | myView->SetLightOn(myCurrent_SpotLight);\n\ |
953 | \n\ |
954 | "); |
955 | // Update The Result Message Dialog |
956 | GetDocument()->UpdateResultMessageDlg("V3d_SpotLight",Message); |
957 | } |
958 | |
959 | void CViewer3dView::OnPositionalLight() |
960 | { |
961 | // Positional light source creation |
962 | |
963 | // Checking if the Active lights limit number is not reached |
964 | if( NbActiveLights>=myGraphicDriver->InquireLightLimit() ) |
965 | { |
966 | char tmpStr[128]; |
967 | sprintf_s(tmpStr, "You have reach the limit number of active lights (%d).\n Clear lights to create new ones.", |
968 | myGraphicDriver->InquireLightLimit()); |
969 | MessageBox(tmpStr,"Light creation", MB_OK); |
970 | return; |
971 | } |
972 | |
973 | GetDocument()->GetAISContext()->OpenLocalContext(); |
974 | myCurrent_PositionalLight=new V3d_PositionalLight(myView->Viewer(),0,0,0,Quantity_NOC_GREEN,1,0); |
975 | myView->SetLightOn(myCurrent_PositionalLight); |
976 | NbActiveLights++; |
977 | ((OCC_MainFrame*)AfxGetMainWnd())->SetStatusMessage("Pick the light position"); |
978 | myCurrentMode = CurAction3d_BeginPositionalLight; |
979 | |
980 | TCollection_AsciiString Message("\ |
981 | myCurrent_PositionalLight=new V3d_PositionalLight(myView->Viewer(),Xp, Yp, Zp,Quantity_NOC_GREEN,1,0);\n\ |
982 | \n\ |
983 | myView->SetLightOn(myCurrent_PositionalLight) ;\n\ |
984 | "); |
985 | |
986 | // Update The Result Message Dialog |
987 | GetDocument()->UpdateResultMessageDlg("V3d_PositionalLight",Message); |
988 | } |
989 | |
990 | void CViewer3dView::OnAmbientLight() |
991 | { |
992 | // Ambiant light source creation |
993 | |
994 | // Checking if the Active lights limit number is not reached |
995 | if( NbActiveLights>=myGraphicDriver->InquireLightLimit() ) |
996 | { |
997 | char tmpStr[128]; |
998 | sprintf_s(tmpStr, "You have reach the limit number of active lights (%d).\n Clear lights to create new ones.", |
999 | myGraphicDriver->InquireLightLimit()); |
1000 | MessageBox(tmpStr,"Light creation", MB_OK); |
1001 | return; |
1002 | } |
1003 | |
1004 | GetDocument()->GetAISContext()->OpenLocalContext(); |
1005 | myCurrent_AmbientLight=new V3d_AmbientLight(myView->Viewer(), Quantity_NOC_GRAY); |
1006 | myView->SetLightOn(myCurrent_AmbientLight) ; |
1007 | NbActiveLights++; |
1008 | GetDocument()->GetAISContext()->CloseLocalContext(); |
1009 | |
1010 | myView->UpdateLights(); |
1011 | |
1012 | TCollection_AsciiString Message("\ |
1013 | myCurrent_AmbientLight=new V3d_AmbientLight(myView->Viewer(), Quantity_NOC_GRAY);\n\ |
1014 | \n\ |
1015 | myView->SetLightOn(myCurrent_AmbientLight) ;\n\ |
1016 | "); |
1017 | |
1018 | // Update The Result Message Dialog |
1019 | GetDocument()->UpdateResultMessageDlg("V3d_AmbientLight",Message); |
1020 | } |
1021 | |
1022 | |
1023 | void CViewer3dView::OnScale() |
1024 | { |
1025 | ScaleDlg Dlg(myView, this); |
1026 | Dlg.DoModal(); |
1027 | myView->Redraw(); |
1028 | } |
1029 | |
1030 | void CViewer3dView::OnZcueing() |
1031 | { |
1032 | ZCueingDlg Dlg(myView, GetDocument()); |
1033 | Dlg.DoModal(); |
1034 | myView->Redraw(); |
1035 | } |
1036 | |
1037 | void CViewer3dView::OnZclipping() |
1038 | { |
1039 | ZClippingDlg Dlg(myView, GetDocument()); |
1040 | Dlg.DoModal(); |
1041 | myView->Redraw(); |
1042 | } |
1043 | |
1044 | //V3d_View.hxx |
1045 | |
1046 | void CViewer3dView::OnShadingmodel() |
1047 | { |
1048 | TCollection_AsciiString Message("\ |
1049 | myView->SetShadingModel(V3d_TypeOfShadingModel myTypeOfShadingModel);\n\ |
1050 | \n\ |
1051 | myCurrent_V3d_View->Update();\n\ |
1052 | "); |
1053 | |
1054 | // Update The Result Message Dialog |
1055 | GetDocument()->UpdateResultMessageDlg("SetShadingModel",Message); |
1056 | |
1057 | CShadingModelDlg Dlg(myView); |
1058 | Dlg.DoModal(); |
1059 | myView->Redraw(); |
1060 | } |
1061 | |
1062 | |
1063 | void CViewer3dView::OnAntialiasingonoff() |
1064 | { |
1065 | if(!myView->Antialiasing()) |
1066 | myView->SetAntialiasingOn(); |
1067 | else |
1068 | myView->SetAntialiasingOff(); |
1069 | |
1070 | myView->Update(); |
1071 | |
1072 | TCollection_AsciiString Message("\ |
1073 | if(!myView->Antialiasing())\n\ |
1074 | myView->SetAntialiasingOn();\n\ |
1075 | else\n\ |
1076 | myView->SetAntialiasingOff();\n\ |
1077 | "); |
1078 | |
1079 | // Update The Result Message Dialog |
1080 | GetDocument()->UpdateResultMessageDlg("SetAntialiasingOn/SetAntialiasingOff",Message); |
1081 | } |
1082 | |
1083 | void CViewer3dView::OnClearLights() |
1084 | { |
1085 | // Setting Off all viewer active lights |
1086 | for(myView->Viewer()->InitActiveLights(); myView->Viewer()->MoreActiveLights(); myView->Viewer()->NextActiveLights()) |
1087 | myView->Viewer()->SetLightOff(myView->Viewer()->ActiveLight()); |
1088 | // Setting Off all view active lights |
1089 | for(myView->InitActiveLights(); myView->MoreActiveLights(); myView->NextActiveLights()) |
1090 | myView->SetLightOff(myView->ActiveLight()); |
1091 | |
1092 | myView->Viewer()->SetDefaultLights();// Setting the default lights on |
1093 | |
1094 | NbActiveLights = 2;// There are 2 default active lights |
1095 | |
1096 | myView->Update(); |
1097 | |
1098 | TCollection_AsciiString Message("\ |
1099 | for(myView->Viewer()->InitActiveLights(); myView->Viewer()->MoreActiveLights(); myView->Viewer()->NextActiveLights())\n\ |
1100 | myView->Viewer()->SetLightOff(myView->Viewer()->ActiveLight()); //Setting Off all viewer active lights\n\ |
1101 | for(myView->InitActiveLights(); myView->MoreActiveLights(); myView->NextActiveLights())\n\ |
1102 | myView->SetLightOff(myView->ActiveLight()); //Setting Off all view active lights\n\ |
1103 | \n\ |
1104 | myView->Viewer()->SetDefaultLights();// Setting the default lights on\n\ |
1105 | "); |
1106 | |
1107 | // Update The Result Message Dialog |
1108 | GetDocument()->UpdateResultMessageDlg("SetLightOff",Message); |
1109 | } |
1110 | |
1111 | void CViewer3dView::OnModelclipping() |
1112 | { |
1113 | if( myPlane.IsNull() ) |
1114 | { |
1115 | //creates a plane defined : center of the box ( 50,50,50) and 1 direction |
1116 | gp_Pln tmpPln(gp_Pnt(0,0,0),gp_Dir(1,0,0)); |
1117 | //getting the coefficients of the gp_Pln ( ax+by+cz+d = 0 ) |
1118 | Standard_Real A,B,C,D; |
1119 | tmpPln.Coefficients(A,B,C,D); |
1120 | //with these coefficients, creating a V3d_Plane |
1121 | myPlane = new V3d_Plane( |
1122 | GetDocument()->GetViewer(),A,B,C,D); |
1123 | //creates the Face |
1124 | //NOTE : the face must be behind the clipping plane !! |
1125 | tmpPln = gp_Pln(gp_Pnt(0.1,0,0),gp_Dir(1,0,0)); |
1126 | BRepBuilderAPI_MakeFace MakeFace(tmpPln, 200, -200, 410, -410); |
1127 | TopoDS_Face S = MakeFace.Face(); |
1128 | //display the face |
1129 | myShape = new AIS_Shape(S); |
1130 | } |
1131 | |
1132 | CModelClippingDlg Dlg(myView, myPlane, myShape, GetDocument()); |
1133 | Dlg.DoModal(); |
1134 | } |
1135 | |
1136 | void CViewer3dView::OnOptionsTrihedronStaticTrihedron() |
1137 | { |
1138 | CTrihedronDlg Dlg(myView, GetDocument()); |
1139 | Dlg.DoModal(); |
1140 | } |
1141 | |
1142 | void CViewer3dView::InitButtons() |
1143 | { |
1144 | myXmin=0; |
1145 | myYmin=0; |
1146 | myXmax=0; |
1147 | myYmax=0; |
1148 | myCurZoom=0; |
1149 | myCurrentMode = CurAction3d_Nothing; |
1150 | } |
1151 | |
1152 | void CViewer3dView::Reset() |
1153 | { |
1154 | InitButtons(); |
1155 | myVisMode = VIS_SHADE; |
1156 | if (!myView.IsNull()) |
1157 | { |
1158 | RedrawVisMode(); |
1159 | myView->Reset(); |
1160 | } |
1161 | } |
1162 | |
1163 | void CViewer3dView::GetViewCenter(V3d_Coordinate& Xc, V3d_Coordinate& Yc) |
1164 | { |
1165 | myView->Center(Xc,Yc); |
1166 | } |
1167 | |
1168 | void CViewer3dView::SetViewCenter(V3d_Coordinate Xc, V3d_Coordinate Yc) |
1169 | { |
1170 | myView->SetCenter(Xc,Yc); |
1171 | } |
1172 | |
1173 | void CViewer3dView::GetViewEye(V3d_Coordinate& X, V3d_Coordinate& Y, V3d_Coordinate& Z) |
1174 | { |
1175 | myView->Eye(X,Y,Z); |
1176 | } |
1177 | |
1178 | void CViewer3dView::SetViewEye(V3d_Coordinate X, V3d_Coordinate Y, V3d_Coordinate Z) |
1179 | { |
1180 | myView->SetEye(X,Y,Z); |
1181 | } |
1182 | |
1183 | Quantity_Factor CViewer3dView::GetViewScale() |
1184 | { |
1185 | return myView->Scale(); |
1186 | } |
1187 | |
1188 | void CViewer3dView::SetViewScale(Quantity_Factor Coef) |
1189 | { |
1190 | myView->SetScale(Coef); |
1191 | } |
1192 | |
1193 | void CViewer3dView::RedrawVisMode() |
1194 | { |
1195 | switch (myVisMode) |
1196 | { |
1197 | case VIS_WIREFRAME: |
1198 | GetDocument()->GetAISContext()->SetDisplayMode(AIS_WireFrame); |
1199 | myView->SetComputedMode (Standard_False); |
1200 | break; |
1201 | case VIS_SHADE: |
1202 | GetDocument()->GetAISContext()->SetDisplayMode(AIS_Shaded); |
1203 | myView->SetComputedMode (Standard_False); |
1204 | break; |
1205 | case VIS_HLR: |
1206 | SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT)); |
1207 | myView->SetComputedMode (Standard_True); |
1208 | SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW)); |
1209 | GetDocument()->GetAISContext()->SetDisplayMode(AIS_WireFrame); |
1210 | break; |
1211 | } |
1212 | } |