1 // OCC_2dView.cpp: implementation of the OCC_2dView class.
3 //////////////////////////////////////////////////////////////////////
6 #include "OCC_2dView.h"
10 #include "resource2d\RectangularGrid.h"
11 #include "resource2d\CircularGrid.h"
13 #include "Quantity_Color.hxx"
14 #include "Quantity_NameOfColor.hxx"
16 /////////////////////////////////////////////////////////////////////////////
19 IMPLEMENT_DYNCREATE(OCC_2dView, OCC_BaseView)
21 BEGIN_MESSAGE_MAP(OCC_2dView, OCC_BaseView)
22 //{{AFX_MSG_MAP(OCC_2dView)
23 // NOTE - the ClassWizard will add and remove mapping macros here.
24 // DO NOT EDIT what you see in these blocks of generated code!
25 ON_COMMAND(ID_FILE_EXPORT_IMAGE, OnFileExportImage)
26 ON_COMMAND(ID_BUTTON2DGridRectLines, OnBUTTONGridRectLines)
27 ON_COMMAND(ID_BUTTON2DGridRectPoints, OnBUTTONGridRectPoints)
28 ON_COMMAND(ID_BUTTON2DGridCircLines, OnBUTTONGridCircLines)
29 ON_COMMAND(ID_BUTTON2DGridCircPoints, OnBUTTONGridCircPoints)
30 ON_COMMAND(ID_BUTTON2DGridValues, OnBUTTONGridValues)
31 ON_UPDATE_COMMAND_UI(ID_BUTTON2DGridValues, OnUpdateBUTTONGridValues)
32 ON_COMMAND(ID_BUTTON2DGridCancel, OnBUTTONGridCancel)
33 ON_UPDATE_COMMAND_UI(ID_BUTTON2DGridCancel, OnUpdateBUTTONGridCancel)
35 ON_COMMAND(ID_BUTTON2DFitAll, OnBUTTONFitAll)
36 ON_COMMAND(ID_BUTTON2DGlobPanning, OnBUTTONGlobPanning)
37 ON_COMMAND(ID_BUTTON2DPanning, OnBUTTONPanning)
38 ON_COMMAND(ID_BUTTON2DZoomProg, OnBUTTONZoomProg)
39 ON_COMMAND(ID_BUTTON2DZoomWin, OnBUTTONZoomWin)
40 ON_UPDATE_COMMAND_UI(ID_BUTTON2DGlobPanning, OnUpdateBUTTON2DGlobPanning)
41 ON_UPDATE_COMMAND_UI(ID_BUTTON2DPanning, OnUpdateBUTTON2DPanning)
42 ON_UPDATE_COMMAND_UI(ID_BUTTON2DZoomProg, OnUpdateBUTTON2DZoomProg)
43 ON_UPDATE_COMMAND_UI(ID_BUTTON2DZoomWin, OnUpdateBUTTON2DZoomWin)
44 ON_COMMAND(ID_Modify_ChangeBackground ,OnChangeBackground)
48 /////////////////////////////////////////////////////////////////////////////
49 // OCC_2dView construction/destruction
51 OCC_2dView::OCC_2dView()
53 myToAllowRotation = false;
54 myDefaultGestures.Bind (Aspect_VKeyMouse_LeftButton, AIS_MouseGesture_SelectRectangle);
55 myMouseGestureMap = myDefaultGestures;
58 OCC_2dView::~OCC_2dView()
63 /////////////////////////////////////////////////////////////////////////////
66 void OCC_2dView::OnInitialUpdate()
68 OCC_BaseView::OnInitialUpdate();
70 // initialize the grids dialogs
71 TheRectangularGridDialog.Create(CRectangularGrid::IDD, NULL);
72 TheCircularGridDialog.Create(CCircularGrid::IDD, NULL);
73 TheRectangularGridDialog.SetViewer (myView->Viewer());
74 TheCircularGridDialog.SetViewer (myView->Viewer());
77 void OCC_2dView::OnFileExportImage()
79 GetDocument()->ExportView (myView);
82 /////////////////////////////////////////////////////////////////////////////
83 // OCC_2dView diagnostics
86 void OCC_2dView::AssertValid() const
91 void OCC_2dView::Dump(CDumpContext& dc) const
96 OCC_2dDoc* OCC_2dView::GetDocument() // non-debug version is inline
98 //ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(OCC_2dDoc)));
99 return (OCC_2dDoc*)m_pDocument;
102 void OCC_2dView::OnBUTTONGridRectLines()
104 Handle(V3d_Viewer) aViewer = myView->Viewer();
105 Handle(Graphic3d_AspectMarker3d) aGridAspect = new Graphic3d_AspectMarker3d(Aspect_TOM_RING1,Quantity_NOC_WHITE,2);
106 aViewer->SetGridEcho(aGridAspect);
107 Standard_Integer aWidth=0, aHeight=0, anOffset=0;
108 myView->Window()->Size(aWidth,aHeight);
109 aViewer->SetRectangularGridGraphicValues(aWidth,aHeight,anOffset);
110 aViewer->ActivateGrid(Aspect_GT_Rectangular, Aspect_GDM_Lines);
113 if (TheCircularGridDialog.IsWindowVisible())
115 TheCircularGridDialog.ShowWindow(SW_HIDE);
116 TheRectangularGridDialog.UpdateValues();
117 TheRectangularGridDialog.ShowWindow(SW_SHOW);
121 void OCC_2dView::OnBUTTONGridRectPoints()
123 Handle(V3d_Viewer) aViewer = myView->Viewer();
124 Handle(Graphic3d_AspectMarker3d) aGridAspect = new Graphic3d_AspectMarker3d(Aspect_TOM_RING1,Quantity_NOC_WHITE,2);
125 aViewer->SetGridEcho(aGridAspect);
126 Standard_Integer aWidth=0, aHeight=0, anOffset=0;
127 myView->Window()->Size(aWidth,aHeight);
128 aViewer->SetRectangularGridGraphicValues(aWidth,aHeight,anOffset);
129 aViewer->ActivateGrid(Aspect_GT_Rectangular, Aspect_GDM_Points);
132 if (TheCircularGridDialog.IsWindowVisible())
134 TheCircularGridDialog.ShowWindow(SW_HIDE);
135 TheRectangularGridDialog.UpdateValues();
136 TheRectangularGridDialog.ShowWindow(SW_SHOW);
140 void OCC_2dView::OnBUTTONGridCircLines()
142 Handle(V3d_Viewer) aViewer = myView->Viewer();
143 Handle(Graphic3d_AspectMarker3d) aGridAspect = new Graphic3d_AspectMarker3d(Aspect_TOM_RING1,Quantity_NOC_WHITE,2);
144 aViewer->SetGridEcho(aGridAspect);
145 Standard_Integer aWidth=0, aHeight=0, anOffset=0;
146 myView->Window()->Size(aWidth,aHeight);
147 aViewer->SetCircularGridGraphicValues(aWidth>aHeight?aWidth:aHeight,anOffset);
148 aViewer->ActivateGrid(Aspect_GT_Circular, Aspect_GDM_Lines);
152 if (TheRectangularGridDialog.IsWindowVisible())
154 TheRectangularGridDialog.ShowWindow(SW_HIDE);
155 TheCircularGridDialog.UpdateValues();
156 TheCircularGridDialog.ShowWindow(SW_SHOW);
160 void OCC_2dView::OnBUTTONGridCircPoints()
162 Handle(V3d_Viewer) aViewer = myView->Viewer();
163 Handle(Graphic3d_AspectMarker3d) aGridAspect = new Graphic3d_AspectMarker3d(Aspect_TOM_RING1,Quantity_NOC_WHITE,2);
164 aViewer->SetGridEcho(aGridAspect);
165 Standard_Integer aWidth=0, aHeight=0, anOffset=0;
166 myView->Window()->Size(aWidth,aHeight);
167 aViewer->SetCircularGridGraphicValues(aWidth>aHeight?aWidth:aHeight,anOffset);
168 aViewer->ActivateGrid(Aspect_GT_Circular, Aspect_GDM_Points);
170 if (TheRectangularGridDialog.IsWindowVisible())
172 TheRectangularGridDialog.ShowWindow(SW_HIDE);
173 TheCircularGridDialog.UpdateValues();
174 TheCircularGridDialog.ShowWindow(SW_SHOW);
178 void OCC_2dView::OnBUTTONGridValues()
180 Handle(V3d_Viewer) aViewer = myView->Viewer();
181 Aspect_GridType TheGridtype = aViewer->GridType();
183 switch( TheGridtype )
185 case Aspect_GT_Rectangular:
186 TheRectangularGridDialog.UpdateValues();
187 TheRectangularGridDialog.ShowWindow(SW_SHOW);
189 case Aspect_GT_Circular:
190 TheCircularGridDialog.UpdateValues();
191 TheCircularGridDialog.ShowWindow(SW_SHOW);
194 throw Standard_Failure("invalid Aspect_GridType");
197 void OCC_2dView::OnUpdateBUTTONGridValues(CCmdUI* pCmdUI)
199 Handle(V3d_Viewer) aViewer = myView->Viewer();
200 pCmdUI-> Enable( aViewer->IsActive() );
203 void OCC_2dView::OnBUTTONGridCancel()
205 Handle(V3d_Viewer) aViewer = myView->Viewer();
206 aViewer->DeactivateGrid();
207 TheRectangularGridDialog.ShowWindow(SW_HIDE);
208 TheCircularGridDialog.ShowWindow(SW_HIDE);
211 void OCC_2dView::OnUpdateBUTTONGridCancel(CCmdUI* pCmdUI)
213 Handle(V3d_Viewer) aViewer = myView->Viewer();
214 pCmdUI-> Enable( aViewer->IsActive() );
217 void OCC_2dView::OnSize(UINT nType, int cx, int cy)
219 OCC_BaseView::OnSize (nType, cx, cy);
220 // Take care : This fonction is call before OnInitialUpdate
221 if (!myView.IsNull())
222 myView->MustBeResized();
225 void OCC_2dView::OnBUTTONFitAll()
230 void OCC_2dView::OnBUTTONGlobPanning()
232 //save the current zoom value
233 myCurZoom = myView->Scale();
239 setCurrentAction (CurAction3d_GlobalPanning);
241 void OCC_2dView::OnBUTTONPanning()
243 setCurrentAction (CurAction3d_DynamicPanning);
245 void OCC_2dView::OnBUTTONZoomProg()
247 setCurrentAction (CurAction3d_DynamicZooming);
249 void OCC_2dView::OnBUTTONZoomWin()
251 setCurrentAction (CurAction3d_WindowZooming);
253 void OCC_2dView::OnChangeBackground()
255 Standard_Real R1, G1, B1;
256 Handle(Aspect_Window) aWindow = myView->Window();
257 Aspect_Background ABack = aWindow->Background();
258 Quantity_Color aColor = ABack.Color();
259 aColor.Values(R1,G1,B1,Quantity_TOC_RGB);
261 m_clr = RGB(R1*255,G1*255,B1*255);
263 CColorDialog dlgColor(m_clr);
264 if (dlgColor.DoModal() == IDOK)
266 m_clr = dlgColor.GetColor();
267 R1 = GetRValue(m_clr)/255.;
268 G1 = GetGValue(m_clr)/255.;
269 B1 = GetBValue(m_clr)/255.;
270 aColor.SetValues(R1,G1,B1,Quantity_TOC_RGB);
271 myView->SetBackgroundColor(aColor);
277 void OCC_2dView::OnUpdateBUTTON2DGlobPanning(CCmdUI* pCmdUI)
279 pCmdUI->SetCheck (getCurrentAction() == CurAction3d_GlobalPanning);
280 pCmdUI->Enable (getCurrentAction() != CurAction3d_GlobalPanning);
283 void OCC_2dView::OnUpdateBUTTON2DPanning(CCmdUI* pCmdUI)
285 pCmdUI->SetCheck (getCurrentAction() == CurAction3d_DynamicPanning);
286 pCmdUI->Enable (getCurrentAction() != CurAction3d_DynamicPanning);
289 void OCC_2dView::OnUpdateBUTTON2DZoomProg(CCmdUI* pCmdUI)
291 pCmdUI->SetCheck (getCurrentAction() == CurAction3d_DynamicZooming);
292 pCmdUI->Enable (getCurrentAction() != CurAction3d_DynamicZooming);
295 void OCC_2dView::OnUpdateBUTTON2DZoomWin(CCmdUI* pCmdUI)
297 pCmdUI->SetCheck (getCurrentAction() == CurAction3d_WindowZooming);
298 pCmdUI->Enable (getCurrentAction() != CurAction3d_WindowZooming);