1 // SelectionDialog.cpp : implementation file
6 #include "SelectionDialog.h"
9 #include "OCC_2dView.h"
10 #include <ISession2D/ISession2D_Shape.h>
13 //#define new DEBUG_NEW
15 static char THIS_FILE[] = __FILE__;
18 // the key for shortcut ( use to activate dynamic rotation, panning )
19 #define CASCADESHORTCUTKEY MK_CONTROL
21 /////////////////////////////////////////////////////////////////////////////
22 // CSelectionDialog dialog
24 CSelectionDialog::CSelectionDialog (CHLRDoc* aDoc,CWnd* pParent /*=NULL*/)
25 : CDialog(CSelectionDialog::IDD, pParent)
28 myIsDisplayed = false;
29 //{{AFX_DATA_INIT(CSelectionDialog)
33 m_DrawHiddenLine = TRUE;
38 void CSelectionDialog::DoDataExchange (CDataExchange* pDX)
40 CDialog::DoDataExchange(pDX);
41 //{{AFX_DATA_MAP(CSelectionDialog)
42 DDX_Radio(pDX, IDC_PolyAlgo, m_Algo);
43 DDX_Radio(pDX, IDC_DisplayDefault, m_DisplayMode);
44 DDX_Text(pDX, IDC_EDIT_NBIsos, m_NbIsos);
45 DDX_Check(pDX, IDC_DrawHiddenLine, m_DrawHiddenLine);
46 DDX_Check(pDX, IDC_HlrModeIsOn, m_HlrModeIsOn);
51 BEGIN_MESSAGE_MAP(CSelectionDialog, CDialog)
52 //{{AFX_MSG_MAP(CSelectionDialog)
53 ON_BN_CLICKED(ID_GetShape, OnGetSelectedShapes)
54 ON_BN_CLICKED(IDC_DisplayDefault, OnDisplayDefault)
55 ON_BN_CLICKED(IDC_VIsoParametrics, OnVIsoParametrics)
56 ON_BN_CLICKED(IDC_VApparentContour, OnVApparentContour)
57 ON_BN_CLICKED(IDC_VSewingEdges, OnVSewingEdges)
58 ON_BN_CLICKED(IDC_VsharpEdges, OnVsharpEdges)
59 ON_BN_CLICKED(IDC_VsmoothEdges, OnVsmoothEdges)
60 ON_BN_CLICKED(IDC_HsharpEdges, OnHsharpEdges)
61 ON_BN_CLICKED(IDC_HsmoothEdges, OnHsmoothEdges)
62 ON_BN_CLICKED(IDC_HSewingEdges, OnHSewingEdges)
63 ON_BN_CLICKED(IDC_HIsoParametrics, OnHIsoParametrics)
64 ON_BN_CLICKED(IDC_HApparentContour, OnHApparentContour)
65 ON_EN_CHANGE(IDC_EDIT_NBIsos, OnChangeEDITNBIsos)
66 ON_BN_CLICKED(IDC_Algo, OnAlgo)
67 ON_BN_CLICKED(IDC_PolyAlgo, OnPolyAlgo)
68 ON_BN_CLICKED(ID_Update2D, OnUpdate2D)
69 ON_BN_CLICKED(IDC_TopView, OnTopView)
70 ON_BN_CLICKED(IDC_BottomView, OnBottomView)
71 ON_BN_CLICKED(IDC_LeftView, OnLeftView)
72 ON_BN_CLICKED(IDC_RightView, OnRightView)
73 ON_BN_CLICKED(IDC_FrontView, OnFrontView)
74 ON_BN_CLICKED(IDC_BackView, OnBackView)
75 ON_BN_CLICKED(IDC_AxoView, OnAxoView)
81 ON_BN_CLICKED(IDC_DrawHiddenLine, OnDrawHiddenLine)
82 ON_BN_CLICKED(IDC_HlrModeIsOn, OnHlrMode)
88 /////////////////////////////////////////////////////////////////////////////
89 // CSelectionDialog message handlers
91 BOOL CSelectionDialog::OnInitDialog()
93 CDialog::OnInitDialog();
95 VERIFY(TopView.AutoLoad (IDC_TopView, this));
96 VERIFY(BottomView.AutoLoad (IDC_BottomView, this)) ;
97 VERIFY(LeftView .AutoLoad (IDC_LeftView , this)) ;
98 VERIFY(RightView .AutoLoad (IDC_RightView , this)) ;
99 VERIFY(FrontView .AutoLoad (IDC_FrontView , this)) ;
100 VERIFY(BackView .AutoLoad (IDC_BackView , this)) ;
101 VERIFY(AxoView .AutoLoad (IDC_AxoView , this)) ;
103 // get the View Window position to managed mouse move
104 CRect BoxRect,ViewRect;
105 GetWindowRect (BoxRect);
106 CWnd * TheViewerWindow = GetDlgItem (IDC_HlrDlgView);
107 TheViewerWindow->GetWindowRect (ViewRect);
108 myPosMinX = ViewRect.TopLeft().x - BoxRect.TopLeft().x;
109 myPosMaxX = ViewRect.Width() + myPosMinX;
110 myPosMinY = ViewRect.TopLeft().y - BoxRect.TopLeft().y;
111 myPosMaxY = myPosMinY + ViewRect.Height();
113 ShowHideButton (Standard_False);
116 // return TRUE unless you set the focus to a control
117 // EXCEPTION: OCX Property Pages should return FALSE
121 void CSelectionDialog::OnDisplay (bool isFit)
123 // GetDlgItem(IDC_HlrDlgView)->SetRedraw() wrapping of this method makes view blinking,
124 // but displaying of big models may be faster.
125 //GetDlgItem(IDC_HlrDlgView)->SetRedraw(true);
128 Handle(Graphic3d_GraphicDriver) aGraphicDriver =
129 ((CHLRApp*)AfxGetApp())->GetGraphicDriver();
131 myActiveViewer = new V3d_Viewer (aGraphicDriver);
132 myActiveViewer->SetDefaultLights();
133 myActiveViewer->SetLightOn();
134 myActiveView = myActiveViewer->CreateView();
136 Handle(WNT_Window) aWNTWindow = new WNT_Window (GetDlgItem (IDC_HlrDlgView)->GetSafeHwnd(),
138 myActiveView->SetComputedMode (m_HlrModeIsOn != 0);
139 myActiveView->SetWindow(aWNTWindow);
141 myInteractiveContext = new AIS_InteractiveContext (myActiveViewer);
144 Handle(Geom_Axis2Placement) aTrihedronAxis = new Geom_Axis2Placement (gp::XOY());
145 myTrihedron = new AIS_Trihedron (aTrihedronAxis);
147 myInteractiveContext->Display (myTrihedron, Standard_False);
148 myIsDisplayed = Standard_True;
152 myActiveView->ZFitAll();
153 myActiveView->FitAll();
156 myActiveView->Redraw();
157 //GetDlgItem (IDC_HlrDlgView)->SetRedraw (false);
161 void CSelectionDialog::SetTitle (const CString & aTitle)
163 SetWindowText (aTitle);
166 void CSelectionDialog::UpdateViews()
168 // Clear HLR dialog view
169 myInteractiveContext->RemoveAll (Standard_False);
170 myInteractiveContext->Display (myTrihedron, Standard_False);
174 // Display chosen shapes in the HLR dialog view.
175 Standard_Boolean OneOrMoreFound = Standard_False;
176 for (myDoc->GetAISContext()->InitSelected();
177 myDoc->GetAISContext()->MoreSelected();
178 myDoc->GetAISContext()->NextSelected())
180 Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast (myDoc->GetAISContext()->SelectedInteractive());
181 if (!anAISShape.IsNull())
183 OneOrMoreFound = Standard_True;
184 myInteractiveContext->Display (anAISShape, Standard_False);
187 myInteractiveContext->UpdateCurrentViewer();
188 // Apply HLR to chosen shapes and display result into the 2d view.
191 myDoc->FitAll2DViews (Standard_False);
192 // Check the selection: if no object : disable all possiblity.
193 ShowHideButton (OneOrMoreFound);
197 void CSelectionDialog::OnGetSelectedShapes()
199 // Create new displayable shape.
200 myDisplayableShape = new ISession2D_Shape();
202 myDisplayableShape->SetNbIsos (m_NbIsos);
204 // Clear HLR dialog view
205 myInteractiveContext->RemoveAll (Standard_False);
206 myInteractiveContext->Display (myTrihedron, Standard_False);
208 Standard_Boolean OneOrMoreFound = Standard_False;
209 for (myDoc->GetAISContext()->InitSelected();
210 myDoc->GetAISContext()->MoreSelected();
211 myDoc->GetAISContext()->NextSelected())
213 Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast (myDoc->GetAISContext()->SelectedInteractive());
215 if (!anAISShape.IsNull())
217 OneOrMoreFound = Standard_True;
218 TopoDS_Shape aShape = anAISShape->Shape();
219 myDisplayableShape->Add (aShape);
220 Handle(AIS_Shape) aSelectedShape = new AIS_Shape (aShape);
221 myInteractiveContext->Display (aSelectedShape, Standard_False);
224 myInteractiveContext->UpdateCurrentViewer();
225 // Apply HLR to chosen shapes and display result into the 2d view.
228 myDoc->FitAll2DViews (Standard_False);
230 // Check the selection: if no object : disable all possiblity.
231 ShowHideButton (OneOrMoreFound);
235 void CSelectionDialog::Apply()
237 SetCursor(AfxGetApp()->LoadStandardCursor (IDC_WAIT));
238 myDoc->GetInteractiveContext2D()->RemoveAll (Standard_False);
241 Standard_Integer aDisplayMode = m_DisplayMode;
248 if (!m_DrawHiddenLine)
250 aDisplayMode += 1000;
253 myDoc->GetInteractiveContext2D()->Display (myDisplayableShape, // object
256 Standard_True); // Redraw
258 SetCursor(AfxGetApp()->LoadStandardCursor (IDC_ARROW));
261 void CSelectionDialog::UpdateProjector()
263 const Handle(Graphic3d_Camera)& aCam = myActiveView->Camera();
264 gp_Dir aBackDir = -aCam->Direction();
265 gp_Dir aXpers = aCam->Up().Crossed (aBackDir);
266 gp_Ax3 anAx3 (aCam->Center(), aBackDir, aXpers);
268 aTrsf.SetTransformation (anAx3);
269 HLRAlgo_Projector aProjector (aTrsf, !aCam->IsOrthographic(), aCam->Scale());
273 if (myDisplayableShape.IsNull()) return;
274 myDisplayableShape->SetProjector(aProjector);
277 void CSelectionDialog::ShowHideButton(Standard_Boolean EnableButton)
281 GetDlgItem(ID_Update2D )->EnableWindow(EnableButton);
282 GetDlgItem(IDC_DisplayDefault )->EnableWindow(EnableButton);
283 GetDlgItem(IDC_PolyAlgo )->EnableWindow(EnableButton);
284 GetDlgItem(IDC_Algo )->EnableWindow(EnableButton);
286 GetDlgItem(IDC_VsharpEdges )->EnableWindow(EnableButton);
287 GetDlgItem(IDC_VsmoothEdges )->EnableWindow(EnableButton);
288 GetDlgItem(IDC_VSewingEdges )->EnableWindow(EnableButton);
289 GetDlgItem(IDC_VApparentContour )->EnableWindow(EnableButton);
290 GetDlgItem(IDC_VIsoParametrics )->EnableWindow(EnableButton);
292 GetDlgItem(IDC_DrawHiddenLine )->EnableWindow(EnableButton);
294 GetDlgItem(IDC_HsmoothEdges )->EnableWindow(EnableButton && m_DrawHiddenLine);
295 GetDlgItem(IDC_HSewingEdges )->EnableWindow(EnableButton && m_DrawHiddenLine);
296 GetDlgItem(IDC_HApparentContour )->EnableWindow(EnableButton && m_DrawHiddenLine);
297 GetDlgItem(IDC_HsharpEdges )->EnableWindow(EnableButton && m_DrawHiddenLine);
298 GetDlgItem(IDC_HIsoParametrics )->EnableWindow(EnableButton && m_DrawHiddenLine);
300 GetDlgItem(IDC_EDIT_NBIsos )->EnableWindow(EnableButton);
301 GetDlgItem(IDC_STATIC_NbIsos )->EnableWindow(EnableButton);
305 if (m_DisplayMode == 5 || m_DisplayMode == 10)
310 GetDlgItem(IDC_VIsoParametrics)->EnableWindow(false);
311 GetDlgItem(IDC_HIsoParametrics)->EnableWindow(false);
312 GetDlgItem(IDC_STATIC_NbIsos) ->EnableWindow(false);
313 GetDlgItem(IDC_EDIT_NBIsos) ->EnableWindow(false);
317 GetDlgItem(IDC_VIsoParametrics)->EnableWindow(true);
318 GetDlgItem(IDC_HIsoParametrics)->EnableWindow(m_DrawHiddenLine);
319 GetDlgItem(IDC_STATIC_NbIsos) ->EnableWindow(true);
320 GetDlgItem(IDC_EDIT_NBIsos) ->EnableWindow(true);
325 void CSelectionDialog::OnDisplayDefault()
327 void CSelectionDialog::OnVIsoParametrics()
329 void CSelectionDialog::OnVApparentContour()
331 void CSelectionDialog::OnVSewingEdges()
333 void CSelectionDialog::OnVsharpEdges()
335 void CSelectionDialog::OnVsmoothEdges()
337 void CSelectionDialog::OnHsharpEdges()
339 void CSelectionDialog::OnHsmoothEdges()
341 void CSelectionDialog::OnHSewingEdges()
343 void CSelectionDialog::OnHIsoParametrics()
345 void CSelectionDialog::OnHApparentContour()
348 void CSelectionDialog::OnChangeEDITNBIsos()
351 myDisplayableShape->SetNbIsos(m_NbIsos);
354 void CSelectionDialog::OnAlgo()
360 void CSelectionDialog::OnPolyAlgo()
366 void CSelectionDialog::OnDrawHiddenLine()
369 if(m_DisplayMode >=6 )
378 void CSelectionDialog::OnUpdate2D()
380 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
381 myDoc->ActivateFrame(RUNTIME_CLASS(OCC_2dView),SW_NORMAL);
384 myDoc->FitAll2DViews(Standard_False);
385 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
388 void CSelectionDialog::OnTopView()
390 myActiveView->SetProj(V3d_Zpos);
394 void CSelectionDialog::OnBottomView()
396 myActiveView->SetProj(V3d_Zneg);
400 void CSelectionDialog::OnLeftView()
402 myActiveView->SetProj(V3d_Xneg);
406 void CSelectionDialog::OnRightView()
408 myActiveView->SetProj(V3d_Xpos);
412 void CSelectionDialog::OnFrontView()
414 myActiveView->SetProj(V3d_Yneg);
418 void CSelectionDialog::OnBackView()
420 myActiveView->SetProj(V3d_Ypos);
424 void CSelectionDialog::OnAxoView()
426 myActiveView->SetProj(V3d_XposYnegZpos);
430 void CSelectionDialog::OnHlrMode()
436 myActiveView->SetComputedMode (m_HlrModeIsOn != 0);
437 myActiveView->Redraw();
441 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
442 myActiveView->SetComputedMode (m_HlrModeIsOn != 0);
443 myActiveView->Redraw();
444 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
449 void CSelectionDialog::OnLButtonDown(UINT nFlags, CPoint point)
451 CDialog::OnLButtonDown(nFlags, point);
453 if ((myPosMinX > point.x)||(myPosMaxX < point.x) ||
454 (myPosMinY > point.y) ||(myPosMaxY < point.y))
457 // save the current mouse coordinate
458 myXmax=point.x; myYmax=point.y;
461 void CSelectionDialog::OnLButtonUp(UINT nFlags, CPoint point)
463 CDialog::OnLButtonUp(nFlags, point);
465 if ((myPosMinX > point.x)||(myPosMaxX < point.x) ||
466 (myPosMinY > point.y) ||(myPosMaxY < point.y))
470 void CSelectionDialog::OnRButtonDown(UINT nFlags, CPoint point)
472 CDialog::OnRButtonDown(nFlags, point);
474 if ((myPosMinX > point.x) || (myPosMaxX < point.x) ||
475 (myPosMinY > point.y) || (myPosMaxY < point.y))
480 if ( nFlags & CASCADESHORTCUTKEY )
484 myActiveView->SetComputedMode (Standard_False);
486 myActiveView->StartRotation (point.x, point.y);
491 void CSelectionDialog::OnRButtonUp(UINT nFlags, CPoint point)
493 CDialog::OnRButtonUp(nFlags, point);
495 if ((myPosMinX > point.x) || (myPosMaxX < point.x) ||
496 (myPosMinY > point.y) || (myPosMaxY < point.y))
501 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
502 // reset the good HLR mode according to the stored one
503 // --> dynamic rotation may have change it
504 if (m_HlrModeIsOn != 0)
506 myActiveView->SetComputedMode (true);
507 myActiveView->Redraw();
510 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
513 void CSelectionDialog::OnMouseMove(UINT nFlags, CPoint point)
515 CDialog::OnMouseMove(nFlags, point);
517 if ((myPosMinX > point.x)||(myPosMaxX < point.x) ||
518 (myPosMinY > point.y) ||(myPosMaxY < point.y))
521 if ( nFlags & MK_LBUTTON)
523 if ( nFlags & CASCADESHORTCUTKEY )
525 // move with MB1 and Control : on the dynamic zooming
526 // Do the zoom in function of mouse's coordinates
527 myActiveView->Zoom(myXmax,myYmax,point.x,point.y);
528 // save the current mouse coordinate
529 myXmax = point.x; myYmax = point.y;
530 }// if ( nFlags & CASCADESHORTCUTKEY ) else
532 else if ( nFlags & MK_MBUTTON)
534 if ( nFlags & CASCADESHORTCUTKEY )
536 myActiveView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
537 myXmax = point.x; myYmax = point.y;
540 else if ( nFlags & MK_RBUTTON)
542 if ( nFlags & CASCADESHORTCUTKEY )
544 myActiveView->Rotation(point.x,point.y);
549 myXmax = point.x; myYmax = point.y;
554 void CSelectionDialog::OnOK()
559 void CSelectionDialog::OnPaint()