1 // SelectionDialog.cpp : implementation file
6 #include "SelectionDialog.h"
9 #include "OCC_2dView.h"
10 #include <ISession2D/ISession2D_Shape.h>
11 #include "Prs3d_Projector.hxx"
14 //#define new DEBUG_NEW
16 static char THIS_FILE[] = __FILE__;
19 // the key for shortcut ( use to activate dynamic rotation, panning )
20 #define CASCADESHORTCUTKEY MK_CONTROL
22 /////////////////////////////////////////////////////////////////////////////
23 // CSelectionDialog dialog
25 CSelectionDialog::CSelectionDialog(CHLRDoc* aDoc,CWnd* pParent /*=NULL*/)
26 : CDialog(CSelectionDialog::IDD, pParent)
30 //{{AFX_DATA_INIT(CSelectionDialog)
34 m_DrawHiddenLine = TRUE;
39 void CSelectionDialog::DoDataExchange(CDataExchange* pDX)
41 CDialog::DoDataExchange(pDX);
42 //{{AFX_DATA_MAP(CSelectionDialog)
43 DDX_Radio(pDX, IDC_PolyAlgo, m_Algo);
44 DDX_Radio(pDX, IDC_DisplayDefault, m_DisplayMode);
45 DDX_Text(pDX, IDC_EDIT_NBIsos, m_NbIsos);
46 DDX_Check(pDX, IDC_DrawHiddenLine, m_DrawHiddenLine);
47 DDX_Check(pDX, IDC_HlrModeIsOn, m_HlrModeIsOn);
52 BEGIN_MESSAGE_MAP(CSelectionDialog, CDialog)
53 //{{AFX_MSG_MAP(CSelectionDialog)
54 ON_BN_CLICKED(ID_GetShape, OnGetShape)
55 ON_BN_CLICKED(IDC_DisplayDefault, OnDisplayDefault)
56 ON_BN_CLICKED(IDC_VIsoParametrics, OnVIsoParametrics)
57 ON_BN_CLICKED(IDC_VApparentContour, OnVApparentContour)
58 ON_BN_CLICKED(IDC_VSewingEdges, OnVSewingEdges)
59 ON_BN_CLICKED(IDC_VsharpEdges, OnVsharpEdges)
60 ON_BN_CLICKED(IDC_VsmoothEdges, OnVsmoothEdges)
61 ON_BN_CLICKED(IDC_HsharpEdges, OnHsharpEdges)
62 ON_BN_CLICKED(IDC_HsmoothEdges, OnHsmoothEdges)
63 ON_BN_CLICKED(IDC_HSewingEdges, OnHSewingEdges)
64 ON_BN_CLICKED(IDC_HIsoParametrics, OnHIsoParametrics)
65 ON_BN_CLICKED(IDC_HApparentContour, OnHApparentContour)
66 ON_EN_CHANGE(IDC_EDIT_NBIsos, OnChangeEDITNBIsos)
67 ON_BN_CLICKED(IDC_Algo, OnAlgo)
68 ON_BN_CLICKED(IDC_PolyAlgo, OnPolyAlgo)
69 ON_BN_CLICKED(ID_Update2D, OnUpdate2D)
70 ON_BN_CLICKED(IDC_TopView, OnTopView)
71 ON_BN_CLICKED(IDC_BottomView, OnBottomView)
72 ON_BN_CLICKED(IDC_LeftView, OnLeftView)
73 ON_BN_CLICKED(IDC_RightView, OnRightView)
74 ON_BN_CLICKED(IDC_FrontView, OnFrontView)
75 ON_BN_CLICKED(IDC_BackView, OnBackView)
76 ON_BN_CLICKED(IDC_AxoView, OnAxoView)
82 ON_BN_CLICKED(IDC_DrawHiddenLine, OnDrawHiddenLine)
83 ON_BN_CLICKED(IDC_HlrModeIsOn, OnHlrMode)
89 /////////////////////////////////////////////////////////////////////////////
90 // CSelectionDialog message handlers
92 BOOL CSelectionDialog::OnInitDialog()
94 CDialog::OnInitDialog();
96 VERIFY(TopView.AutoLoad(IDC_TopView, this));
97 VERIFY(BottomView.AutoLoad(IDC_BottomView, this)) ;
98 VERIFY(LeftView .AutoLoad(IDC_LeftView , this)) ;
99 VERIFY(RightView .AutoLoad(IDC_RightView , this)) ;
100 VERIFY(FrontView .AutoLoad(IDC_FrontView , this)) ;
101 VERIFY(BackView .AutoLoad(IDC_BackView , this)) ;
102 VERIFY(AxoView .AutoLoad(IDC_AxoView , this)) ;
104 // get the View Window position to managed mouse move
105 CRect BoxRect,ViewRect;
106 GetWindowRect(BoxRect);
107 CWnd * TheViewerWindow = GetDlgItem(IDC_DUMMYBUTTON);
108 TheViewerWindow->GetWindowRect(ViewRect);
109 myPosMinX = ViewRect.TopLeft().x - BoxRect.TopLeft().x;
110 myPosMaxX = ViewRect.Width()+myPosMinX;
111 myPosMinY = ViewRect.TopLeft().y - BoxRect.TopLeft().y;
112 myPosMaxY = myPosMinY + ViewRect.Height();
114 ShowHideButton(Standard_False);
117 return TRUE; // return TRUE unless you set the focus to a control
118 // EXCEPTION: OCX Property Pages should return FALSE
121 void CSelectionDialog::OnDisplay(bool isFit)
123 GetDlgItem(IDC_DUMMYBUTTON)->SetRedraw(true);
125 Handle(Graphic3d_GraphicDriver) aGraphicDriver =
126 ((CHLRApp*)AfxGetApp())->GetGraphicDriver();
128 myActiveViewer = new V3d_Viewer(aGraphicDriver,(short *) "Visu3D");
129 myActiveViewer->SetDefaultLights();
130 myActiveViewer->SetLightOn();
131 myActiveView = myActiveViewer->CreateView();
133 Handle(WNT_Window) aWNTWindow = new WNT_Window (GetDlgItem(IDC_DUMMYBUTTON)->GetSafeHwnd(),
135 myActiveView->SetComputedMode (m_HlrModeIsOn);
136 myActiveView->SetWindow(aWNTWindow);
138 myInteractiveContext = new AIS_InteractiveContext(myActiveViewer);
141 Handle(Geom_Axis2Placement) aTrihedronAxis=new Geom_Axis2Placement(gp::XOY());
142 myTrihedron=new AIS_Trihedron(aTrihedronAxis);
144 myInteractiveContext->Display(myTrihedron);
147 myActiveView->ZFitAll();
148 myActiveView->FitAll();
150 myActiveView->Redraw();
151 myDisplay = Standard_True;
152 GetDlgItem(IDC_DUMMYBUTTON)->SetRedraw(false);
156 void CSelectionDialog::SetTitle(CString & aTitle)
158 SetWindowText(aTitle);
161 void CSelectionDialog::OnGetShape()
164 myDoc->GetInteractiveContext2D()->RemoveAll();
165 myDisplayableShape = new ISession2D_Shape( );
167 myDisplayableShape->SetNbIsos(m_NbIsos);
169 myInteractiveContext->EraseAll(Standard_False);
170 myInteractiveContext->Display(myTrihedron);
172 Standard_Boolean OneOrMoreFound = Standard_False;
173 for (myDoc->GetAISContext()->InitCurrent();
174 myDoc->GetAISContext()->MoreCurrent ();
175 myDoc->GetAISContext()->NextCurrent ())
177 Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(myDoc->GetAISContext()->Current());
179 if (!anAISShape.IsNull())
181 OneOrMoreFound = Standard_True;
182 TopoDS_Shape aShape = anAISShape->Shape();
183 myDisplayableShape->Add( aShape );
184 myInteractiveContext->Display(anAISShape);
188 Standard_Integer DisplayMode = m_DisplayMode;
189 if (m_Algo == 1) DisplayMode+=100;
190 if (!m_DrawHiddenLine) DisplayMode+=1000;
192 myDoc->GetInteractiveContext2D()->Display(myDisplayableShape, // object
193 DisplayMode, // display mode
194 DisplayMode, // selection mode
195 Standard_True); // Redraw
197 myDoc->FitAll2DViews(Standard_False); // Update Viewer
199 // check the selection :
200 // if no object : disable all possiblity!!
201 ShowHideButton(OneOrMoreFound);
205 void CSelectionDialog::Apply()
207 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
208 myDoc->GetInteractiveContext2D()->RemoveAll();
211 Standard_Integer DisplayMode = m_DisplayMode;
212 if (m_Algo == 1) DisplayMode+=100;
214 if (!m_DrawHiddenLine) DisplayMode+=1000;
216 myDoc->GetInteractiveContext2D()->Display(myDisplayableShape, // object
219 Standard_True); // Redraw
221 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
224 void CSelectionDialog::UpdateProjector()
226 V3d_Coordinate DX,DY,DZ,XAt,YAt,ZAt, Vx,Vy,Vz ;
227 myActiveView->Proj(DX,DY,DZ);
228 myActiveView->At(XAt,YAt,ZAt);
229 myActiveView->Up( Vx,Vy,Vz );
231 Standard_Boolean IsPerspective = (myActiveView->Type() == V3d_PERSPECTIVE);
232 Quantity_Length aFocus = 1;
233 Prs3d_Projector aPrs3dProjector(IsPerspective,aFocus,DX,DY,DZ,XAt,YAt,ZAt,Vx,Vy,Vz);
234 HLRAlgo_Projector aProjector = aPrs3dProjector.Projector();
236 if (myDisplayableShape.IsNull()) return;
237 myDisplayableShape->SetProjector(aProjector);
240 void CSelectionDialog::ShowHideButton(Standard_Boolean EnableButton)
244 GetDlgItem(ID_Update2D )->EnableWindow(EnableButton);
245 GetDlgItem(IDC_DisplayDefault )->EnableWindow(EnableButton);
246 GetDlgItem(IDC_PolyAlgo )->EnableWindow(EnableButton);
247 GetDlgItem(IDC_Algo )->EnableWindow(EnableButton);
249 GetDlgItem(IDC_VsharpEdges )->EnableWindow(EnableButton);
250 GetDlgItem(IDC_VsmoothEdges )->EnableWindow(EnableButton);
251 GetDlgItem(IDC_VSewingEdges )->EnableWindow(EnableButton);
252 GetDlgItem(IDC_VApparentContour )->EnableWindow(EnableButton);
253 GetDlgItem(IDC_VIsoParametrics )->EnableWindow(EnableButton);
255 GetDlgItem(IDC_DrawHiddenLine )->EnableWindow(EnableButton);
257 GetDlgItem(IDC_HsmoothEdges )->EnableWindow(EnableButton && m_DrawHiddenLine);
258 GetDlgItem(IDC_HSewingEdges )->EnableWindow(EnableButton && m_DrawHiddenLine);
259 GetDlgItem(IDC_HApparentContour )->EnableWindow(EnableButton && m_DrawHiddenLine);
260 GetDlgItem(IDC_HsharpEdges )->EnableWindow(EnableButton && m_DrawHiddenLine);
261 GetDlgItem(IDC_HIsoParametrics )->EnableWindow(EnableButton && m_DrawHiddenLine);
263 GetDlgItem(IDC_EDIT_NBIsos )->EnableWindow(EnableButton);
264 GetDlgItem(IDC_STATIC_NbIsos )->EnableWindow(EnableButton);
268 if (m_DisplayMode == 5) m_DisplayMode=0;
269 if (m_DisplayMode == 10) m_DisplayMode=0;
271 GetDlgItem(IDC_VIsoParametrics)->EnableWindow(false);
272 GetDlgItem(IDC_HIsoParametrics)->EnableWindow(false);
273 GetDlgItem(IDC_STATIC_NbIsos) ->EnableWindow(false);
274 GetDlgItem(IDC_EDIT_NBIsos) ->EnableWindow(false);
278 GetDlgItem(IDC_VIsoParametrics)->EnableWindow(true);
279 GetDlgItem(IDC_HIsoParametrics)->EnableWindow(m_DrawHiddenLine);
280 GetDlgItem(IDC_STATIC_NbIsos) ->EnableWindow(true);
281 GetDlgItem(IDC_EDIT_NBIsos) ->EnableWindow(true);
286 void CSelectionDialog::OnDisplayDefault()
288 void CSelectionDialog::OnVIsoParametrics()
290 void CSelectionDialog::OnVApparentContour()
292 void CSelectionDialog::OnVSewingEdges()
294 void CSelectionDialog::OnVsharpEdges()
296 void CSelectionDialog::OnVsmoothEdges()
298 void CSelectionDialog::OnHsharpEdges()
300 void CSelectionDialog::OnHsmoothEdges()
302 void CSelectionDialog::OnHSewingEdges()
304 void CSelectionDialog::OnHIsoParametrics()
306 void CSelectionDialog::OnHApparentContour()
309 void CSelectionDialog::OnChangeEDITNBIsos()
312 myDisplayableShape->SetNbIsos(m_NbIsos);
315 void CSelectionDialog::OnAlgo()
321 void CSelectionDialog::OnPolyAlgo()
327 void CSelectionDialog::OnDrawHiddenLine()
330 if(m_DisplayMode >=6 )
339 void CSelectionDialog::OnUpdate2D()
341 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
342 myDoc->ActivateFrame(RUNTIME_CLASS(OCC_2dView),SW_NORMAL);
345 myDoc->FitAll2DViews(Standard_False);
346 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
349 void CSelectionDialog::OnTopView()
351 myActiveView->SetProj(V3d_Zpos);
355 void CSelectionDialog::OnBottomView()
357 myActiveView->SetProj(V3d_Zneg);
361 void CSelectionDialog::OnLeftView()
363 myActiveView->SetProj(V3d_Ypos);
367 void CSelectionDialog::OnRightView()
369 myActiveView->SetProj(V3d_Yneg);
373 void CSelectionDialog::OnFrontView()
375 myActiveView->SetProj(V3d_Xpos);
379 void CSelectionDialog::OnBackView()
381 myActiveView->SetProj(V3d_Xneg);
385 void CSelectionDialog::OnAxoView()
387 myActiveView->SetProj(V3d_XposYnegZpos);
391 void CSelectionDialog::OnHlrMode()
397 myActiveView->SetComputedMode (m_HlrModeIsOn);
401 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
402 myActiveView->SetComputedMode (m_HlrModeIsOn);
403 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
408 void CSelectionDialog::OnLButtonDown(UINT nFlags, CPoint point)
410 CDialog::OnLButtonDown(nFlags, point);
412 if ((myPosMinX > point.x)||(myPosMaxX < point.x) ||
413 (myPosMinY > point.y) ||(myPosMaxY < point.y))
416 // save the current mouse coordinate
417 myXmax=point.x; myYmax=point.y;
420 void CSelectionDialog::OnLButtonUp(UINT nFlags, CPoint point)
422 CDialog::OnLButtonUp(nFlags, point);
424 if ((myPosMinX > point.x)||(myPosMaxX < point.x) ||
425 (myPosMinY > point.y) ||(myPosMaxY < point.y))
429 void CSelectionDialog::OnRButtonDown(UINT nFlags, CPoint point)
431 CDialog::OnRButtonDown(nFlags, point);
433 if ((myPosMinX > point.x) || (myPosMaxX < point.x) ||
434 (myPosMinY > point.y) || (myPosMaxY < point.y))
439 if ( nFlags & CASCADESHORTCUTKEY )
443 myActiveView->SetComputedMode (Standard_False);
445 myActiveView->StartRotation (point.x, point.y);
450 void CSelectionDialog::OnRButtonUp(UINT nFlags, CPoint point)
452 CDialog::OnRButtonUp(nFlags, point);
454 if ((myPosMinX > point.x) || (myPosMaxX < point.x) ||
455 (myPosMinY > point.y) || (myPosMaxY < point.y))
460 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
461 // reset tyhe good HLR mode according to the strored one
462 // --> dynamic rotation may have change it
463 myActiveView->SetComputedMode (m_HlrModeIsOn);
465 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
468 void CSelectionDialog::OnMouseMove(UINT nFlags, CPoint point)
470 CDialog::OnMouseMove(nFlags, point);
472 if ((myPosMinX > point.x)||(myPosMaxX < point.x) ||
473 (myPosMinY > point.y) ||(myPosMaxY < point.y))
476 if ( nFlags & MK_LBUTTON)
478 if ( nFlags & CASCADESHORTCUTKEY )
480 // move with MB1 and Control : on the dynamic zooming
481 // Do the zoom in function of mouse's coordinates
482 myActiveView->Zoom(myXmax,myYmax,point.x,point.y);
483 // save the current mouse coordinate
484 myXmax = point.x; myYmax = point.y;
485 }// if ( nFlags & CASCADESHORTCUTKEY ) else
487 else if ( nFlags & MK_MBUTTON)
489 if ( nFlags & CASCADESHORTCUTKEY )
491 myActiveView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
492 myXmax = point.x; myYmax = point.y;
495 else if ( nFlags & MK_RBUTTON)
497 if ( nFlags & CASCADESHORTCUTKEY )
499 myActiveView->Rotation(point.x,point.y);
504 myXmax = point.x; myYmax = point.y;
509 void CSelectionDialog::OnOK()
514 void CSelectionDialog::OnPaint()
516 CPaintDC dc(this); // device context for painting