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