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