1 // OCC_3dView.cpp: implementation of the OCC_3dView class.
6 #include "OCC_3dView.h"
8 #include "OCC_3dBaseDoc.h"
9 #include <res\OCC_Resource.h>
11 #include <Visual3d_View.hxx>
12 #include <Graphic3d_ExportFormat.hxx>
16 IMPLEMENT_DYNCREATE(OCC_3dView, CView)
18 BEGIN_MESSAGE_MAP(OCC_3dView, CView)
19 //{{AFX_MSG_MAP(OCC_3dView)
20 ON_COMMAND(ID_BUTTONAxo, OnBUTTONAxo)
21 ON_COMMAND(ID_BUTTONBack, OnBUTTONBack)
22 ON_COMMAND(ID_BUTTONBottom, OnBUTTONBottom)
23 ON_COMMAND(ID_BUTTONFront, OnBUTTONFront)
24 ON_COMMAND(ID_BUTTONHlrOff, OnBUTTONHlrOff)
25 ON_COMMAND(ID_BUTTONHlrOn, OnBUTTONHlrOn)
26 ON_COMMAND(ID_BUTTONLeft, OnBUTTONLeft)
27 ON_COMMAND(ID_BUTTONPan, OnBUTTONPan)
28 ON_COMMAND(ID_BUTTONPanGlo, OnBUTTONPanGlo)
29 ON_COMMAND(ID_BUTTONReset, OnBUTTONReset)
30 ON_COMMAND(ID_BUTTONRight, OnBUTTONRight)
31 ON_COMMAND(ID_BUTTONRot, OnBUTTONRot)
32 ON_COMMAND(ID_BUTTONTop, OnBUTTONTop)
33 ON_COMMAND(ID_BUTTONZoomAll, OnBUTTONZoomAll)
35 ON_COMMAND(ID_FILE_EXPORT_IMAGE, OnFileExportImage)
36 ON_COMMAND(ID_BUTTONZoomProg, OnBUTTONZoomProg)
37 ON_COMMAND(ID_BUTTONZoomWin, OnBUTTONZoomWin)
45 ON_UPDATE_COMMAND_UI(ID_BUTTONHlrOff, OnUpdateBUTTONHlrOff)
46 ON_UPDATE_COMMAND_UI(ID_BUTTONHlrOn, OnUpdateBUTTONHlrOn)
47 ON_UPDATE_COMMAND_UI(ID_BUTTONPanGlo, OnUpdateBUTTONPanGlo)
48 ON_UPDATE_COMMAND_UI(ID_BUTTONPan, OnUpdateBUTTONPan)
49 ON_UPDATE_COMMAND_UI(ID_BUTTONZoomProg, OnUpdateBUTTONZoomProg)
50 ON_UPDATE_COMMAND_UI(ID_BUTTONZoomWin, OnUpdateBUTTONZoomWin)
51 ON_UPDATE_COMMAND_UI(ID_BUTTONRot, OnUpdateBUTTONRot)
52 ON_COMMAND(ID_Modify_ChangeBackground , OnModifyChangeBackground)
56 /////////////////////////////////////////////////////////////////////////////
57 // OCC_3dView construction/destruction
59 OCC_3dView::OCC_3dView()
60 : myCurrentMode (CurAction3d_Nothing),
68 myHlrModeIsOn (Standard_False),
71 // TODO: add construction code here
74 OCC_3dView::~OCC_3dView()
78 if (m_Pen) delete m_Pen;
81 BOOL OCC_3dView::PreCreateWindow(CREATESTRUCT& cs)
83 // TODO: Modify the Window class or styles here by modifying
84 // the CREATESTRUCT cs
85 return CView::PreCreateWindow(cs);
88 /////////////////////////////////////////////////////////////////////////////
90 void OCC_3dView::OnInitialUpdate()
92 CView::OnInitialUpdate();
94 myView = GetDocument()->GetViewer()->CreateView();
96 // store for restore state after rotation (which is in Degenerated mode)
97 myHlrModeIsOn = Standard_False;
98 myView->SetComputedMode (myHlrModeIsOn);
100 Handle(Graphic3d_GraphicDriver) aGraphicDriver =
101 ((OCC_App*)AfxGetApp())->GetGraphicDriver();
103 Handle(WNT_Window) aWNTWindow = new WNT_Window(GetSafeHwnd());
104 myView->SetWindow(aWNTWindow);
105 if (!aWNTWindow->IsMapped()) aWNTWindow->Map();
107 // store the mode ( nothing , dynamic zooming, dynamic ... )
108 myCurrentMode = CurAction3d_Nothing;
111 void OCC_3dView::OnDraw(CDC* pDC)
114 GetWindowRect(aRect);
115 if(myWidth != aRect.Width() || myHeight != aRect.Height()) {
116 myWidth = aRect.Width();
117 myHeight = aRect.Height();
118 ::PostMessage ( GetSafeHwnd () , WM_SIZE , SW_SHOW , myWidth + myHeight*65536 );
124 /////////////////////////////////////////////////////////////////////////////
125 // OCC_3dView diagnostics
128 void OCC_3dView::AssertValid() const
130 CView::AssertValid();
133 void OCC_3dView::Dump(CDumpContext& dc) const
138 OCC_3dDoc* OCC_3dView::GetDocument() // non-debug version is inline
140 // ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(OCC_3dBaseDoc)));
141 return (OCC_3dDoc*)m_pDocument;
146 /////////////////////////////////////////////////////////////////////////////
147 // OCC_3dView message handlers
148 void OCC_3dView::OnFileExportImage()
151 filter = _T("EXR Files (*.EXR)|*.exr|TGA Files (*.TGA)|*.tga|TIFF Files (*.TIFF)|*.tiff|"
152 "PPM Files (*.PPM)|*.ppm|JPEG Files(*.JPEG)|*.jpeg|PNG Files (*.PNG)|*.png|"
153 "GIF Files (*.GIF)|*.gif|BMP Files (*.BMP)|*.bmp|PS Files (*.PS)|*.ps|"
154 "EPS Files (*.EPS)|*.eps|TEX Files (*.TEX)|*.tex|PDF Files (*.PDF)|*.pdf"
155 "|SVG Files (*.SVG)|*.svg|PGF Files (*.PGF)|*.pgf|EMF Files (*.EMF)|*.emf||");
156 CFileDialog dlg(FALSE,_T("*.BMP"),NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
160 if (dlg.DoModal() == IDOK)
162 CString aFileName = dlg.GetPathName();
163 CString ext = dlg.GetFileExt();
164 if (!(ext.CompareNoCase("ps")) || !(ext.CompareNoCase("emf"))
165 || !(ext.CompareNoCase("pdf")) || !(ext.CompareNoCase("eps"))
166 || !(ext.CompareNoCase("tex")) || !(ext.CompareNoCase("svg"))
167 || !(ext.CompareNoCase("pgf")))
169 Graphic3d_ExportFormat exFormat;
170 if (!(ext.CompareNoCase("ps"))) exFormat = Graphic3d_EF_PostScript;
171 else exFormat = Graphic3d_EF_EnhPostScript;
172 myView->View()->Export( aFileName, exFormat );
175 myView->Dump(aFileName);
179 void OCC_3dView::OnSize(UINT nType, int cx, int cy)
181 if (!myView.IsNull())
182 myView->MustBeResized();
186 void OCC_3dView::OnBUTTONBack()
188 myView->SetProj(V3d_Xneg);
191 // See the front View
192 void OCC_3dView::OnBUTTONFront()
194 myView->SetProj(V3d_Xpos);
197 // See the bottom View
198 void OCC_3dView::OnBUTTONBottom()
200 myView->SetProj(V3d_Zneg);
204 void OCC_3dView::OnBUTTONTop()
206 myView->SetProj(V3d_Zpos);
210 void OCC_3dView::OnBUTTONLeft()
212 myView->SetProj(V3d_Ypos);
215 // See the right View
216 void OCC_3dView::OnBUTTONRight()
218 myView->SetProj(V3d_Yneg);
221 // See the axonometric View
222 void OCC_3dView::OnBUTTONAxo()
224 myView->SetProj(V3d_XposYnegZpos);
227 void OCC_3dView::OnBUTTONHlrOff()
229 myHlrModeIsOn = Standard_False;
230 myView->SetComputedMode (myHlrModeIsOn);
233 void OCC_3dView::OnBUTTONHlrOn()
235 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
236 myHlrModeIsOn = Standard_True;
237 myView->SetComputedMode (myHlrModeIsOn);
238 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
241 void OCC_3dView::OnBUTTONPan()
243 myCurrentMode = CurAction3d_DynamicPanning;
246 void OCC_3dView::OnBUTTONPanGlo()
248 // save the current zoom value
249 myCurZoom = myView->Scale();
253 myCurrentMode = CurAction3d_GlobalPanning;
256 void OCC_3dView::OnBUTTONReset()
261 void OCC_3dView::OnBUTTONRot()
263 myCurrentMode = CurAction3d_DynamicRotation;
266 void OCC_3dView::OnBUTTONZoomAll()
272 void OCC_3dView::OnBUTTONZoomProg()
273 { myCurrentMode = CurAction3d_DynamicZooming; }
275 void OCC_3dView::OnBUTTONZoomWin()
276 { myCurrentMode = CurAction3d_WindowZooming; }
278 void OCC_3dView::OnLButtonDown(UINT nFlags, CPoint point)
280 // save the current mouse coordinate in min
281 myXmin=point.x; myYmin=point.y;
282 myXmax=point.x; myYmax=point.y;
284 if ( nFlags & MK_CONTROL )
286 // Button MB1 down Control :start zomming
287 // SetCursor(AfxGetApp()->LoadStandardCursor());
291 switch (myCurrentMode)
293 case CurAction3d_Nothing : // start a drag
294 if (nFlags & MK_SHIFT)
295 GetDocument()->ShiftDragEvent(myXmax,myYmax,-1,myView);
297 GetDocument()->DragEvent(myXmax,myYmax,-1,myView);
300 case CurAction3d_DynamicZooming : // noting
302 case CurAction3d_WindowZooming : // noting
304 case CurAction3d_DynamicPanning :// noting
306 case CurAction3d_GlobalPanning :// noting
308 case CurAction3d_DynamicRotation :
311 myView->SetComputedMode (Standard_False);
314 myView->StartRotation(point.x,point.y);
317 Standard_Failure::Raise(" incompatible Current Mode ");
323 void OCC_3dView::OnLButtonUp(UINT nFlags, CPoint point)
325 if ( nFlags & MK_CONTROL )
331 switch (myCurrentMode)
333 case CurAction3d_Nothing :
334 if (point.x == myXmin && point.y == myYmin)
335 { // no offset between down and up --> selectEvent
338 if (nFlags & MK_SHIFT )
339 GetDocument()->ShiftInputEvent(point.x,point.y,myView);
341 GetDocument()->InputEvent (point.x,point.y,myView);
344 myXmax=point.x; myYmax=point.y;
345 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False);
346 if (nFlags & MK_SHIFT)
347 GetDocument()->ShiftDragEvent(point.x,point.y,1,myView);
349 GetDocument()->DragEvent(point.x,point.y,1,myView);
352 case CurAction3d_DynamicZooming :
353 // SetCursor(AfxGetApp()->LoadStandardCursor());
354 myCurrentMode = CurAction3d_Nothing;
356 case CurAction3d_WindowZooming :
357 myXmax=point.x; myYmax=point.y;
358 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False);
359 if ((abs(myXmin-myXmax)>ValZWMin) || (abs(myYmin-myYmax)>ValZWMin))
360 // Test if the zoom window is greater than a minimale window.
362 // Do the zoom window between Pmin and Pmax
363 myView->WindowFitAll(myXmin,myYmin,myXmax,myYmax);
365 myCurrentMode = CurAction3d_Nothing;
367 case CurAction3d_DynamicPanning :
368 myCurrentMode = CurAction3d_Nothing;
370 case CurAction3d_GlobalPanning :
371 myView->Place(point.x,point.y,myCurZoom);
372 myCurrentMode = CurAction3d_Nothing;
374 case CurAction3d_DynamicRotation :
375 myCurrentMode = CurAction3d_Nothing;
378 CWaitCursor aWaitCursor;
379 myView->SetComputedMode (myHlrModeIsOn);
383 myView->SetComputedMode (myHlrModeIsOn);
387 Standard_Failure::Raise(" incompatible Current Mode ");
389 } //switch (myCurrentMode)
390 } // else // if ( Ctrl )
393 void OCC_3dView::OnMButtonDown(UINT nFlags, CPoint point)
395 if ( nFlags & MK_CONTROL )
397 // Button MB2 down Control : panning init
398 // SetCursor(AfxGetApp()->LoadStandardCursor());
402 void OCC_3dView::OnMButtonUp(UINT nFlags, CPoint point)
404 if ( nFlags & MK_CONTROL )
406 // Button MB2 down Control : panning init
407 // SetCursor(AfxGetApp()->LoadStandardCursor());
411 void OCC_3dView::OnRButtonDown(UINT nFlags, CPoint point)
413 if ( nFlags & MK_CONTROL )
417 myView->SetComputedMode (Standard_False);
419 myView->StartRotation(point.x,point.y);
423 GetDocument()->Popup(point.x,point.y,myView);
427 void OCC_3dView::OnRButtonUp(UINT nFlags, CPoint point)
429 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
430 myView->SetComputedMode (myHlrModeIsOn);
431 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
434 void OCC_3dView::OnMouseMove(UINT nFlags, CPoint point)
436 // ============================ LEFT BUTTON =======================
437 if ( nFlags & MK_LBUTTON)
439 if ( nFlags & MK_CONTROL )
441 // move with MB1 and Control : on the dynamic zooming
442 // Do the zoom in function of mouse's coordinates
443 myView->Zoom(myXmax,myYmax,point.x,point.y);
444 // save the current mouse coordinate in min
450 switch (myCurrentMode)
452 case CurAction3d_Nothing :
453 myXmax = point.x; myYmax = point.y;
454 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False);
455 if (nFlags & MK_SHIFT)
456 GetDocument()->ShiftDragEvent(myXmax,myYmax,0,myView);
458 GetDocument()->DragEvent(myXmax,myYmax,0,myView);
459 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_True);
462 case CurAction3d_DynamicZooming :
463 myView->Zoom(myXmax,myYmax,point.x,point.y);
464 // save the current mouse coordinate in min \n";
465 myXmax=point.x; myYmax=point.y;
467 case CurAction3d_WindowZooming :
468 myXmax = point.x; myYmax = point.y;
469 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False,LongDash);
470 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_True,LongDash);
472 case CurAction3d_DynamicPanning :
473 myView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
474 myXmax = point.x; myYmax = point.y;
476 case CurAction3d_GlobalPanning : // nothing
478 case CurAction3d_DynamicRotation :
479 myView->Rotation(point.x,point.y);
483 Standard_Failure::Raise(" incompatible Current Mode ");
485 }// switch (myCurrentMode)
486 }// if ( nFlags & MK_CONTROL ) else
488 else if ( nFlags & MK_MBUTTON)
490 if ( nFlags & MK_CONTROL )
492 myView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
493 myXmax = point.x; myYmax = point.y;
497 else if ( nFlags & MK_RBUTTON)
499 if ( nFlags & MK_CONTROL )
501 myView->Rotation(point.x,point.y);
506 myXmax = point.x; myYmax = point.y;
507 if (nFlags & MK_SHIFT)
508 GetDocument()->ShiftMoveEvent(point.x,point.y,myView);
510 GetDocument()->MoveEvent(point.x,point.y,myView);
514 void OCC_3dView::DrawRectangle(const Standard_Integer MinX ,
515 const Standard_Integer MinY ,
516 const Standard_Integer MaxX ,
517 const Standard_Integer MaxY ,
518 const Standard_Boolean Draw ,
519 const LineStyle aLineStyle)
521 static int m_DrawMode;
522 if (!m_Pen && aLineStyle ==Solid )
523 {m_Pen = new CPen(PS_SOLID, 1, RGB(0,0,0)); m_DrawMode = R2_MERGEPENNOT;}
524 else if (!m_Pen && aLineStyle ==Dot )
525 {m_Pen = new CPen(PS_DOT, 1, RGB(0,0,0)); m_DrawMode = R2_XORPEN;}
526 else if (!m_Pen && aLineStyle == ShortDash)
527 {m_Pen = new CPen(PS_DASH, 1, RGB(255,0,0)); m_DrawMode = R2_XORPEN;}
528 else if (!m_Pen && aLineStyle == LongDash)
529 {m_Pen = new CPen(PS_DASH, 1, RGB(0,0,0)); m_DrawMode = R2_NOTXORPEN;}
530 else if (aLineStyle == Default)
531 { m_Pen = NULL; m_DrawMode = R2_MERGEPENNOT;}
534 CClientDC clientDC(this);
535 if (m_Pen) aOldPen = clientDC.SelectObject(m_Pen);
536 clientDC.SetROP2(m_DrawMode);
538 static Standard_Integer StoredMinX, StoredMaxX, StoredMinY, StoredMaxY;
539 static Standard_Boolean m_IsVisible;
541 if ( m_IsVisible && !Draw) // move or up : erase at the old position
543 clientDC.MoveTo(StoredMinX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMaxY);
544 clientDC.LineTo(StoredMaxX,StoredMaxY);
545 clientDC.LineTo(StoredMaxX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMinY);
549 StoredMinX = min ( MinX, MaxX );
550 StoredMinY = min ( MinY, MaxY );
551 StoredMaxX = max ( MinX, MaxX );
552 StoredMaxY = max ( MinY, MaxY);
554 if (Draw) // move : draw
556 clientDC.MoveTo(StoredMinX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMaxY);
557 clientDC.LineTo(StoredMaxX,StoredMaxY);
558 clientDC.LineTo(StoredMaxX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMinY);
562 if (m_Pen) clientDC.SelectObject(aOldPen);
567 void OCC_3dView::OnUpdateBUTTONHlrOff(CCmdUI* pCmdUI)
569 pCmdUI->SetCheck (!myHlrModeIsOn);
570 pCmdUI->Enable (myHlrModeIsOn);
573 void OCC_3dView::OnUpdateBUTTONHlrOn(CCmdUI* pCmdUI)
575 pCmdUI->SetCheck (myHlrModeIsOn);
576 pCmdUI->Enable (!myHlrModeIsOn);
579 void OCC_3dView::OnUpdateBUTTONPanGlo(CCmdUI* pCmdUI)
581 pCmdUI->SetCheck (myCurrentMode == CurAction3d_GlobalPanning);
582 pCmdUI->Enable (myCurrentMode != CurAction3d_GlobalPanning);
586 void OCC_3dView::OnUpdateBUTTONPan(CCmdUI* pCmdUI)
588 pCmdUI->SetCheck (myCurrentMode == CurAction3d_DynamicPanning);
589 pCmdUI->Enable (myCurrentMode != CurAction3d_DynamicPanning );
592 void OCC_3dView::OnUpdateBUTTONZoomProg(CCmdUI* pCmdUI)
594 pCmdUI->SetCheck (myCurrentMode == CurAction3d_DynamicZooming );
595 pCmdUI->Enable (myCurrentMode != CurAction3d_DynamicZooming);
598 void OCC_3dView::OnUpdateBUTTONZoomWin(CCmdUI* pCmdUI)
600 pCmdUI->SetCheck (myCurrentMode == CurAction3d_WindowZooming);
601 pCmdUI->Enable (myCurrentMode != CurAction3d_WindowZooming);
604 void OCC_3dView::OnUpdateBUTTONRot(CCmdUI* pCmdUI)
606 pCmdUI->SetCheck (myCurrentMode == CurAction3d_DynamicRotation);
607 pCmdUI->Enable (myCurrentMode != CurAction3d_DynamicRotation);
610 void OCC_3dView::OnModifyChangeBackground()
615 myView->BackgroundColor(Quantity_TOC_RGB,R1,G1,B1);
617 m_clr = RGB(R1*255,G1*255,B1*255);
619 CColorDialog dlgColor(m_clr);
620 if (dlgColor.DoModal() == IDOK)
622 m_clr = dlgColor.GetColor();
623 R1 = GetRValue(m_clr)/255.;
624 G1 = GetGValue(m_clr)/255.;
625 B1 = GetBValue(m_clr)/255.;
626 myView->SetBackgroundColor(Quantity_TOC_RGB,R1,G1,B1);