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;
35 m_HlrModeIsOn = FALSE;
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);
126 Handle(Graphic3d_GraphicDriver) aGraphicDriver = ((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);
148 myActiveView->ZFitAll();
149 myActiveView->FitAll();
151 myActiveView->Redraw();
152 myDisplay = Standard_True;
153 GetDlgItem(IDC_DUMMYBUTTON)->SetRedraw(false);
157 void CSelectionDialog::SetTitle(CString & aTitle)
159 SetWindowText(aTitle);
162 void CSelectionDialog::OnGetShape()
165 myDoc->GetInteractiveContext2D()->EraseAll();
166 myDisplayableShape = new ISession2D_Shape( );
168 myDisplayableShape->SetNbIsos(m_NbIsos);
170 myInteractiveContext->EraseAll(Standard_False);
171 myInteractiveContext->Display(myTrihedron);
173 Standard_Boolean OneOrMoreFound = Standard_False;
174 for (myDoc->GetAISContext()->InitCurrent();
175 myDoc->GetAISContext()->MoreCurrent ();
176 myDoc->GetAISContext()->NextCurrent ())
178 Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(myDoc->GetAISContext()->Current());
180 if (!anAISShape.IsNull())
182 OneOrMoreFound = Standard_True;
183 TopoDS_Shape aShape = anAISShape->Shape();
184 myDisplayableShape->Add( aShape );
185 myInteractiveContext->Display(anAISShape);
189 Standard_Integer DisplayMode = m_DisplayMode;
190 if (m_Algo == 1) DisplayMode+=100;
191 if (!m_DrawHiddenLine) DisplayMode+=1000;
193 myDoc->GetInteractiveContext2D()->Display(myDisplayableShape, // object
194 DisplayMode, // display mode
195 DisplayMode, // selection mode
196 Standard_True); // Redraw
198 myDoc->FitAll2DViews(Standard_False); // Update Viewer
201 // check the selection :
202 // if no object : disable all possiblity!!
203 ShowHideButton(OneOrMoreFound);
207 void CSelectionDialog::Apply()
209 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
210 myDoc->GetInteractiveContext2D()->EraseAll(/*Standard_False*/);
213 Standard_Integer DisplayMode = m_DisplayMode;
214 if (m_Algo == 1) DisplayMode+=100;
216 if (!m_DrawHiddenLine) DisplayMode+=1000;
218 myDoc->GetInteractiveContext2D()->Display(myDisplayableShape, // object
221 Standard_True); // Redraw
223 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
226 void CSelectionDialog::UpdateProjector()
228 V3d_Coordinate DX,DY,DZ,XAt,YAt,ZAt, Vx,Vy,Vz ;
229 myActiveView->Proj(DX,DY,DZ);
230 myActiveView->At(XAt,YAt,ZAt);
231 myActiveView->Up( Vx,Vy,Vz );
233 Standard_Boolean IsPerspective = (myActiveView->Type() == V3d_PERSPECTIVE);
234 Quantity_Length aFocus = 1;
235 Prs3d_Projector aPrs3dProjector(IsPerspective,aFocus,DX,DY,DZ,XAt,YAt,ZAt,Vx,Vy,Vz);
236 HLRAlgo_Projector aProjector = aPrs3dProjector.Projector();
238 if (myDisplayableShape.IsNull()) return;
239 myDisplayableShape->SetProjector(aProjector);
242 void CSelectionDialog::ShowHideButton(Standard_Boolean EnableButton)
246 GetDlgItem(ID_Update2D )->EnableWindow(EnableButton);
247 GetDlgItem(IDC_DisplayDefault )->EnableWindow(EnableButton);
248 GetDlgItem(IDC_PolyAlgo )->EnableWindow(EnableButton);
249 GetDlgItem(IDC_Algo )->EnableWindow(EnableButton);
251 GetDlgItem(IDC_VsharpEdges )->EnableWindow(EnableButton);
252 GetDlgItem(IDC_VsmoothEdges )->EnableWindow(EnableButton);
253 GetDlgItem(IDC_VSewingEdges )->EnableWindow(EnableButton);
254 GetDlgItem(IDC_VApparentContour )->EnableWindow(EnableButton);
255 GetDlgItem(IDC_VIsoParametrics )->EnableWindow(EnableButton);
257 GetDlgItem(IDC_DrawHiddenLine )->EnableWindow(EnableButton);
259 GetDlgItem(IDC_HsmoothEdges )->EnableWindow(EnableButton && m_DrawHiddenLine);
260 GetDlgItem(IDC_HSewingEdges )->EnableWindow(EnableButton && m_DrawHiddenLine);
261 GetDlgItem(IDC_HApparentContour )->EnableWindow(EnableButton && m_DrawHiddenLine);
262 GetDlgItem(IDC_HsharpEdges )->EnableWindow(EnableButton && m_DrawHiddenLine);
263 GetDlgItem(IDC_HIsoParametrics )->EnableWindow(EnableButton && m_DrawHiddenLine);
265 GetDlgItem(IDC_EDIT_NBIsos )->EnableWindow(EnableButton);
266 GetDlgItem(IDC_STATIC_NbIsos )->EnableWindow(EnableButton);
270 if (m_DisplayMode == 5) m_DisplayMode=0;
271 if (m_DisplayMode == 10) m_DisplayMode=0;
273 GetDlgItem(IDC_VIsoParametrics)->EnableWindow(false);
274 GetDlgItem(IDC_HIsoParametrics)->EnableWindow(false);
275 GetDlgItem(IDC_STATIC_NbIsos) ->EnableWindow(false);
276 GetDlgItem(IDC_EDIT_NBIsos) ->EnableWindow(false);
280 GetDlgItem(IDC_VIsoParametrics)->EnableWindow(true);
281 GetDlgItem(IDC_HIsoParametrics)->EnableWindow(m_DrawHiddenLine);
282 GetDlgItem(IDC_STATIC_NbIsos) ->EnableWindow(true);
283 GetDlgItem(IDC_EDIT_NBIsos) ->EnableWindow(true);
288 void CSelectionDialog::OnDisplayDefault()
290 void CSelectionDialog::OnVIsoParametrics()
292 void CSelectionDialog::OnVApparentContour()
294 void CSelectionDialog::OnVSewingEdges()
296 void CSelectionDialog::OnVsharpEdges()
298 void CSelectionDialog::OnVsmoothEdges()
300 void CSelectionDialog::OnHsharpEdges()
302 void CSelectionDialog::OnHsmoothEdges()
304 void CSelectionDialog::OnHSewingEdges()
306 void CSelectionDialog::OnHIsoParametrics()
308 void CSelectionDialog::OnHApparentContour()
311 void CSelectionDialog::OnChangeEDITNBIsos()
314 myDisplayableShape->SetNbIsos(m_NbIsos);
317 void CSelectionDialog::OnAlgo()
323 void CSelectionDialog::OnPolyAlgo()
329 void CSelectionDialog::OnDrawHiddenLine()
332 if(m_DisplayMode >=6 )
341 void CSelectionDialog::OnUpdate2D()
343 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
344 myDoc->ActivateFrame(RUNTIME_CLASS(OCC_2dView),SW_NORMAL);
347 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
350 void CSelectionDialog::OnTopView()
352 myActiveView->SetProj(V3d_Zpos);
356 void CSelectionDialog::OnBottomView()
358 myActiveView->SetProj(V3d_Zneg);
362 void CSelectionDialog::OnLeftView()
364 myActiveView->SetProj(V3d_Ypos);
368 void CSelectionDialog::OnRightView()
370 myActiveView->SetProj(V3d_Yneg);
374 void CSelectionDialog::OnFrontView()
376 myActiveView->SetProj(V3d_Xpos);
380 void CSelectionDialog::OnBackView()
382 myActiveView->SetProj(V3d_Xneg);
386 void CSelectionDialog::OnAxoView()
388 myActiveView->SetProj(V3d_XposYnegZpos);
392 void CSelectionDialog::OnHlrMode()
398 myActiveView->SetComputedMode (m_HlrModeIsOn);
402 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
403 myActiveView->SetComputedMode (m_HlrModeIsOn);
404 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
409 void CSelectionDialog::OnLButtonDown(UINT nFlags, CPoint point)
411 CDialog::OnLButtonDown(nFlags, point);
413 if ((myPosMinX > point.x)||(myPosMaxX < point.x) ||
414 (myPosMinY > point.y) ||(myPosMaxY < point.y))
417 // save the current mouse coordinate
418 myXmax=point.x; myYmax=point.y;
421 void CSelectionDialog::OnLButtonUp(UINT nFlags, CPoint point)
423 CDialog::OnLButtonUp(nFlags, point);
425 if ((myPosMinX > point.x)||(myPosMaxX < point.x) ||
426 (myPosMinY > point.y) ||(myPosMaxY < point.y))
430 void CSelectionDialog::OnRButtonDown(UINT nFlags, CPoint point)
432 CDialog::OnRButtonDown(nFlags, point);
434 if ((myPosMinX > point.x) || (myPosMaxX < point.x) ||
435 (myPosMinY > point.y) || (myPosMaxY < point.y))
440 if ( nFlags & CASCADESHORTCUTKEY )
444 myActiveView->SetComputedMode (Standard_False);
446 myActiveView->StartRotation (point.x, point.y);
451 void CSelectionDialog::OnRButtonUp(UINT nFlags, CPoint point)
453 CDialog::OnRButtonUp(nFlags, point);
455 if ((myPosMinX > point.x) || (myPosMaxX < point.x) ||
456 (myPosMinY > point.y) || (myPosMaxY < point.y))
461 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
462 // reset tyhe good HLR mode according to the strored one
463 // --> dynamic rotation may have change it
464 myActiveView->SetComputedMode (m_HlrModeIsOn);
466 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
469 void CSelectionDialog::OnMouseMove(UINT nFlags, CPoint point)
471 CDialog::OnMouseMove(nFlags, point);
473 if ((myPosMinX > point.x)||(myPosMaxX < point.x) ||
474 (myPosMinY > point.y) ||(myPosMaxY < point.y))
477 if ( nFlags & MK_LBUTTON)
479 if ( nFlags & CASCADESHORTCUTKEY )
481 // move with MB1 and Control : on the dynamic zooming
482 // Do the zoom in function of mouse's coordinates
483 myActiveView->Zoom(myXmax,myYmax,point.x,point.y);
484 // save the current mouse coordinate
485 myXmax = point.x; myYmax = point.y;
486 }// if ( nFlags & CASCADESHORTCUTKEY ) else
488 else if ( nFlags & MK_MBUTTON)
490 if ( nFlags & CASCADESHORTCUTKEY )
492 myActiveView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
493 myXmax = point.x; myYmax = point.y;
496 else if ( nFlags & MK_RBUTTON)
498 if ( nFlags & CASCADESHORTCUTKEY )
500 myActiveView->Rotation(point.x,point.y);
505 myXmax = point.x; myYmax = point.y;
510 void CSelectionDialog::OnOK()
515 void CSelectionDialog::OnPaint()
517 CPaintDC dc(this); // device context for painting