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)
29 myIsDisplayed = false;
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, OnGetSelectedShapes)
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_HlrDlgView);
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 unless you set the focus to a control
118 // EXCEPTION: OCX Property Pages should return FALSE
122 void CSelectionDialog::OnDisplay (bool isFit)
124 // GetDlgItem(IDC_HlrDlgView)->SetRedraw() wrapping of this method makes view blinking,
125 // but displaying of big models may be faster.
126 //GetDlgItem(IDC_HlrDlgView)->SetRedraw(true);
129 Handle(Graphic3d_GraphicDriver) aGraphicDriver =
130 ((CHLRApp*)AfxGetApp())->GetGraphicDriver();
132 myActiveViewer = new V3d_Viewer (aGraphicDriver, (short *) "Visu3D");
133 myActiveViewer->SetDefaultLights();
134 myActiveViewer->SetLightOn();
135 myActiveView = myActiveViewer->CreateView();
137 Handle(WNT_Window) aWNTWindow = new WNT_Window (GetDlgItem (IDC_HlrDlgView)->GetSafeHwnd(),
139 myActiveView->SetComputedMode (m_HlrModeIsOn);
140 myActiveView->SetWindow(aWNTWindow);
142 myInteractiveContext = new AIS_InteractiveContext (myActiveViewer);
145 Handle(Geom_Axis2Placement) aTrihedronAxis = new Geom_Axis2Placement (gp::XOY());
146 myTrihedron = new AIS_Trihedron (aTrihedronAxis);
148 myInteractiveContext->Display (myTrihedron);
149 myIsDisplayed = Standard_True;
153 myActiveView->ZFitAll();
154 myActiveView->FitAll();
157 myActiveView->Redraw();
158 //GetDlgItem (IDC_HlrDlgView)->SetRedraw (false);
162 void CSelectionDialog::SetTitle (const CString & aTitle)
164 SetWindowText (aTitle);
167 void CSelectionDialog::UpdateViews()
169 // Clear HLR dialog view
170 myInteractiveContext->RemoveAll();
171 myInteractiveContext->Display (myTrihedron);
175 // Display chosen shapes in the HLR dialog view.
176 Standard_Boolean OneOrMoreFound = Standard_False;
177 for (myDoc->GetAISContext()->InitCurrent();
178 myDoc->GetAISContext()->MoreCurrent();
179 myDoc->GetAISContext()->NextCurrent())
181 Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast (myDoc->GetAISContext()->Current());
182 if (!anAISShape.IsNull())
184 OneOrMoreFound = Standard_True;
185 myInteractiveContext->Display (anAISShape);
189 // Apply HLR to chosen shapes and display result into the 2d view.
192 myDoc->FitAll2DViews (Standard_False);
193 // Check the selection: if no object : disable all possiblity.
194 ShowHideButton (OneOrMoreFound);
198 void CSelectionDialog::OnGetSelectedShapes()
200 // Create new displayable shape.
201 myDisplayableShape = new ISession2D_Shape();
203 myDisplayableShape->SetNbIsos (m_NbIsos);
205 // Clear HLR dialog view
206 myInteractiveContext->RemoveAll();
207 myInteractiveContext->Display (myTrihedron);
209 Standard_Boolean OneOrMoreFound = Standard_False;
210 for (myDoc->GetAISContext()->InitCurrent();
211 myDoc->GetAISContext()->MoreCurrent();
212 myDoc->GetAISContext()->NextCurrent())
214 Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast (myDoc->GetAISContext()->Current());
216 if (!anAISShape.IsNull())
218 OneOrMoreFound = Standard_True;
219 TopoDS_Shape aShape = anAISShape->Shape();
220 myDisplayableShape->Add (aShape);
221 Handle(AIS_Shape) aSelectedShape = new AIS_Shape (aShape);
222 myInteractiveContext->Display (aSelectedShape);
226 // Apply HLR to chosen shapes and display result into the 2d view.
229 myDoc->FitAll2DViews (Standard_False);
231 // Check the selection: if no object : disable all possiblity.
232 ShowHideButton (OneOrMoreFound);
236 void CSelectionDialog::Apply()
238 SetCursor(AfxGetApp()->LoadStandardCursor (IDC_WAIT));
239 myDoc->GetInteractiveContext2D()->RemoveAll();
242 Standard_Integer aDisplayMode = m_DisplayMode;
249 if (!m_DrawHiddenLine)
251 aDisplayMode += 1000;
254 myDoc->GetInteractiveContext2D()->Display (myDisplayableShape, // object
257 Standard_True); // Redraw
259 SetCursor(AfxGetApp()->LoadStandardCursor (IDC_ARROW));
262 void CSelectionDialog::UpdateProjector()
264 V3d_Coordinate DX,DY,DZ,XAt,YAt,ZAt, Vx,Vy,Vz ;
265 myActiveView->Proj(DX,DY,DZ);
266 myActiveView->At(XAt,YAt,ZAt);
267 myActiveView->Up( Vx,Vy,Vz );
269 Standard_Boolean IsPerspective = (myActiveView->Type() == V3d_PERSPECTIVE);
270 Quantity_Length aFocus = 1;
271 Prs3d_Projector aPrs3dProjector(IsPerspective,aFocus,DX,DY,DZ,XAt,YAt,ZAt,Vx,Vy,Vz);
272 HLRAlgo_Projector aProjector = aPrs3dProjector.Projector();
274 if (myDisplayableShape.IsNull()) return;
275 myDisplayableShape->SetProjector(aProjector);
278 void CSelectionDialog::ShowHideButton(Standard_Boolean EnableButton)
282 GetDlgItem(ID_Update2D )->EnableWindow(EnableButton);
283 GetDlgItem(IDC_DisplayDefault )->EnableWindow(EnableButton);
284 GetDlgItem(IDC_PolyAlgo )->EnableWindow(EnableButton);
285 GetDlgItem(IDC_Algo )->EnableWindow(EnableButton);
287 GetDlgItem(IDC_VsharpEdges )->EnableWindow(EnableButton);
288 GetDlgItem(IDC_VsmoothEdges )->EnableWindow(EnableButton);
289 GetDlgItem(IDC_VSewingEdges )->EnableWindow(EnableButton);
290 GetDlgItem(IDC_VApparentContour )->EnableWindow(EnableButton);
291 GetDlgItem(IDC_VIsoParametrics )->EnableWindow(EnableButton);
293 GetDlgItem(IDC_DrawHiddenLine )->EnableWindow(EnableButton);
295 GetDlgItem(IDC_HsmoothEdges )->EnableWindow(EnableButton && m_DrawHiddenLine);
296 GetDlgItem(IDC_HSewingEdges )->EnableWindow(EnableButton && m_DrawHiddenLine);
297 GetDlgItem(IDC_HApparentContour )->EnableWindow(EnableButton && m_DrawHiddenLine);
298 GetDlgItem(IDC_HsharpEdges )->EnableWindow(EnableButton && m_DrawHiddenLine);
299 GetDlgItem(IDC_HIsoParametrics )->EnableWindow(EnableButton && m_DrawHiddenLine);
301 GetDlgItem(IDC_EDIT_NBIsos )->EnableWindow(EnableButton);
302 GetDlgItem(IDC_STATIC_NbIsos )->EnableWindow(EnableButton);
306 if (m_DisplayMode == 5 || m_DisplayMode == 10)
311 GetDlgItem(IDC_VIsoParametrics)->EnableWindow(false);
312 GetDlgItem(IDC_HIsoParametrics)->EnableWindow(false);
313 GetDlgItem(IDC_STATIC_NbIsos) ->EnableWindow(false);
314 GetDlgItem(IDC_EDIT_NBIsos) ->EnableWindow(false);
318 GetDlgItem(IDC_VIsoParametrics)->EnableWindow(true);
319 GetDlgItem(IDC_HIsoParametrics)->EnableWindow(m_DrawHiddenLine);
320 GetDlgItem(IDC_STATIC_NbIsos) ->EnableWindow(true);
321 GetDlgItem(IDC_EDIT_NBIsos) ->EnableWindow(true);
326 void CSelectionDialog::OnDisplayDefault()
328 void CSelectionDialog::OnVIsoParametrics()
330 void CSelectionDialog::OnVApparentContour()
332 void CSelectionDialog::OnVSewingEdges()
334 void CSelectionDialog::OnVsharpEdges()
336 void CSelectionDialog::OnVsmoothEdges()
338 void CSelectionDialog::OnHsharpEdges()
340 void CSelectionDialog::OnHsmoothEdges()
342 void CSelectionDialog::OnHSewingEdges()
344 void CSelectionDialog::OnHIsoParametrics()
346 void CSelectionDialog::OnHApparentContour()
349 void CSelectionDialog::OnChangeEDITNBIsos()
352 myDisplayableShape->SetNbIsos(m_NbIsos);
355 void CSelectionDialog::OnAlgo()
361 void CSelectionDialog::OnPolyAlgo()
367 void CSelectionDialog::OnDrawHiddenLine()
370 if(m_DisplayMode >=6 )
379 void CSelectionDialog::OnUpdate2D()
381 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
382 myDoc->ActivateFrame(RUNTIME_CLASS(OCC_2dView),SW_NORMAL);
385 myDoc->FitAll2DViews(Standard_False);
386 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
389 void CSelectionDialog::OnTopView()
391 myActiveView->SetProj(V3d_Zpos);
395 void CSelectionDialog::OnBottomView()
397 myActiveView->SetProj(V3d_Zneg);
401 void CSelectionDialog::OnLeftView()
403 myActiveView->SetProj(V3d_Xneg);
407 void CSelectionDialog::OnRightView()
409 myActiveView->SetProj(V3d_Xpos);
413 void CSelectionDialog::OnFrontView()
415 myActiveView->SetProj(V3d_Yneg);
419 void CSelectionDialog::OnBackView()
421 myActiveView->SetProj(V3d_Ypos);
425 void CSelectionDialog::OnAxoView()
427 myActiveView->SetProj(V3d_XposYnegZpos);
431 void CSelectionDialog::OnHlrMode()
437 myActiveView->SetComputedMode (m_HlrModeIsOn);
441 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
442 myActiveView->SetComputedMode (m_HlrModeIsOn);
443 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
448 void CSelectionDialog::OnLButtonDown(UINT nFlags, CPoint point)
450 CDialog::OnLButtonDown(nFlags, point);
452 if ((myPosMinX > point.x)||(myPosMaxX < point.x) ||
453 (myPosMinY > point.y) ||(myPosMaxY < point.y))
456 // save the current mouse coordinate
457 myXmax=point.x; myYmax=point.y;
460 void CSelectionDialog::OnLButtonUp(UINT nFlags, CPoint point)
462 CDialog::OnLButtonUp(nFlags, point);
464 if ((myPosMinX > point.x)||(myPosMaxX < point.x) ||
465 (myPosMinY > point.y) ||(myPosMaxY < point.y))
469 void CSelectionDialog::OnRButtonDown(UINT nFlags, CPoint point)
471 CDialog::OnRButtonDown(nFlags, point);
473 if ((myPosMinX > point.x) || (myPosMaxX < point.x) ||
474 (myPosMinY > point.y) || (myPosMaxY < point.y))
479 if ( nFlags & CASCADESHORTCUTKEY )
483 myActiveView->SetComputedMode (Standard_False);
485 myActiveView->StartRotation (point.x, point.y);
490 void CSelectionDialog::OnRButtonUp(UINT nFlags, CPoint point)
492 CDialog::OnRButtonUp(nFlags, point);
494 if ((myPosMinX > point.x) || (myPosMaxX < point.x) ||
495 (myPosMinY > point.y) || (myPosMaxY < point.y))
500 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
501 // reset the good HLR mode according to the stored one
502 // --> dynamic rotation may have change it
503 myActiveView->SetComputedMode (m_HlrModeIsOn);
505 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
508 void CSelectionDialog::OnMouseMove(UINT nFlags, CPoint point)
510 CDialog::OnMouseMove(nFlags, point);
512 if ((myPosMinX > point.x)||(myPosMaxX < point.x) ||
513 (myPosMinY > point.y) ||(myPosMaxY < point.y))
516 if ( nFlags & MK_LBUTTON)
518 if ( nFlags & CASCADESHORTCUTKEY )
520 // move with MB1 and Control : on the dynamic zooming
521 // Do the zoom in function of mouse's coordinates
522 myActiveView->Zoom(myXmax,myYmax,point.x,point.y);
523 // save the current mouse coordinate
524 myXmax = point.x; myYmax = point.y;
525 }// if ( nFlags & CASCADESHORTCUTKEY ) else
527 else if ( nFlags & MK_MBUTTON)
529 if ( nFlags & CASCADESHORTCUTKEY )
531 myActiveView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
532 myXmax = point.x; myYmax = point.y;
535 else if ( nFlags & MK_RBUTTON)
537 if ( nFlags & CASCADESHORTCUTKEY )
539 myActiveView->Rotation(point.x,point.y);
544 myXmax = point.x; myYmax = point.y;
549 void CSelectionDialog::OnOK()
554 void CSelectionDialog::OnPaint()