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_DegeneratedModeOn = 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_DegeneratedMode, m_DegeneratedModeOn);
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_DegeneratedMode, OnDegeneratedMode)
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_WNTGraphicDevice) theGraphicDevice =
126 ((CHLRApp*)AfxGetApp())->GetGraphicDevice();
128 myActiveViewer = new V3d_Viewer(theGraphicDevice,(short *) "Visu3D");
129 myActiveViewer->SetDefaultLights();
130 myActiveViewer->SetLightOn();
131 myActiveView = myActiveViewer->CreateView();
133 Handle(WNT_Window) aWNTWindow = new WNT_Window(theGraphicDevice,
134 GetDlgItem(IDC_DUMMYBUTTON)->GetSafeHwnd(),
137 aWNTWindow->SetDoubleBuffer(Standard_False);
139 if (m_DegeneratedModeOn) myActiveView->SetDegenerateModeOn();
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);
151 myActiveView->ZFitAll();
152 myActiveView->FitAll();
154 myActiveView->Redraw();
155 myDisplay = Standard_True;
156 GetDlgItem(IDC_DUMMYBUTTON)->SetRedraw(false);
160 void CSelectionDialog::SetTitle(CString & aTitle)
162 SetWindowText(aTitle);
165 void CSelectionDialog::OnGetShape()
168 myDoc->GetInteractiveContext2D()->EraseAll();
169 myDisplayableShape = new ISession2D_Shape( );
171 myDisplayableShape->SetNbIsos(m_NbIsos);
173 myInteractiveContext->EraseAll(Standard_False);
174 myInteractiveContext->Display(myTrihedron);
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());
183 if (!anAISShape.IsNull())
185 OneOrMoreFound = Standard_True;
186 TopoDS_Shape aShape = anAISShape->Shape();
187 myDisplayableShape->Add( aShape );
188 myInteractiveContext->Display(anAISShape);
192 Standard_Integer DisplayMode = m_DisplayMode;
193 if (m_Algo == 1) DisplayMode+=100;
194 if (!m_DrawHiddenLine) DisplayMode+=1000;
196 myDoc->GetInteractiveContext2D()->Display(myDisplayableShape, // object
197 DisplayMode, // display mode
198 DisplayMode, // selection mode
199 Standard_True); // Redraw
201 myDoc->FitAll2DViews(Standard_False); // Update Viewer
204 // check the selection :
205 // if no object : disable all possiblity!!
206 ShowHideButton(OneOrMoreFound);
210 void CSelectionDialog::Apply()
212 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
213 myDoc->GetInteractiveContext2D()->EraseAll(Standard_False);
216 Standard_Integer DisplayMode = m_DisplayMode;
217 if (m_Algo == 1) DisplayMode+=100;
219 if (!m_DrawHiddenLine) DisplayMode+=1000;
221 myDoc->GetInteractiveContext2D()->Display(myDisplayableShape, // object
224 Standard_True); // Redraw
226 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
229 void CSelectionDialog::UpdateProjector()
231 V3d_Coordinate DX,DY,DZ,XAt,YAt,ZAt, Vx,Vy,Vz ;
232 myActiveView->Proj(DX,DY,DZ);
233 myActiveView->At(XAt,YAt,ZAt);
234 myActiveView->Up( Vx,Vy,Vz );
236 Standard_Boolean IsPerspective = (myActiveView->Type() == V3d_PERSPECTIVE);
237 Quantity_Length aFocus = 1;
238 Prs3d_Projector aPrs3dProjector(IsPerspective,aFocus,DX,DY,DZ,XAt,YAt,ZAt,Vx,Vy,Vz);
239 HLRAlgo_Projector aProjector = aPrs3dProjector.Projector();
241 if (myDisplayableShape.IsNull()) return;
242 myDisplayableShape->SetProjector(aProjector);
245 void CSelectionDialog::ShowHideButton(Standard_Boolean EnableButton)
249 GetDlgItem(ID_Update2D )->EnableWindow(EnableButton);
250 GetDlgItem(IDC_DisplayDefault )->EnableWindow(EnableButton);
251 GetDlgItem(IDC_PolyAlgo )->EnableWindow(EnableButton);
252 GetDlgItem(IDC_Algo )->EnableWindow(EnableButton);
254 GetDlgItem(IDC_VsharpEdges )->EnableWindow(EnableButton);
255 GetDlgItem(IDC_VsmoothEdges )->EnableWindow(EnableButton);
256 GetDlgItem(IDC_VSewingEdges )->EnableWindow(EnableButton);
257 GetDlgItem(IDC_VApparentContour )->EnableWindow(EnableButton);
258 GetDlgItem(IDC_VIsoParametrics )->EnableWindow(EnableButton);
260 GetDlgItem(IDC_DrawHiddenLine )->EnableWindow(EnableButton);
262 GetDlgItem(IDC_HsmoothEdges )->EnableWindow(EnableButton && m_DrawHiddenLine);
263 GetDlgItem(IDC_HSewingEdges )->EnableWindow(EnableButton && m_DrawHiddenLine);
264 GetDlgItem(IDC_HApparentContour )->EnableWindow(EnableButton && m_DrawHiddenLine);
265 GetDlgItem(IDC_HsharpEdges )->EnableWindow(EnableButton && m_DrawHiddenLine);
266 GetDlgItem(IDC_HIsoParametrics )->EnableWindow(EnableButton && m_DrawHiddenLine);
268 GetDlgItem(IDC_EDIT_NBIsos )->EnableWindow(EnableButton);
269 GetDlgItem(IDC_STATIC_NbIsos )->EnableWindow(EnableButton);
273 if (m_DisplayMode == 5) m_DisplayMode=0;
274 if (m_DisplayMode == 10) m_DisplayMode=0;
276 GetDlgItem(IDC_VIsoParametrics)->EnableWindow(false);
277 GetDlgItem(IDC_HIsoParametrics)->EnableWindow(false);
278 GetDlgItem(IDC_STATIC_NbIsos) ->EnableWindow(false);
279 GetDlgItem(IDC_EDIT_NBIsos) ->EnableWindow(false);
283 GetDlgItem(IDC_VIsoParametrics)->EnableWindow(true);
284 GetDlgItem(IDC_HIsoParametrics)->EnableWindow(m_DrawHiddenLine);
285 GetDlgItem(IDC_STATIC_NbIsos) ->EnableWindow(true);
286 GetDlgItem(IDC_EDIT_NBIsos) ->EnableWindow(true);
291 void CSelectionDialog::OnDisplayDefault()
293 void CSelectionDialog::OnVIsoParametrics()
295 void CSelectionDialog::OnVApparentContour()
297 void CSelectionDialog::OnVSewingEdges()
299 void CSelectionDialog::OnVsharpEdges()
301 void CSelectionDialog::OnVsmoothEdges()
303 void CSelectionDialog::OnHsharpEdges()
305 void CSelectionDialog::OnHsmoothEdges()
307 void CSelectionDialog::OnHSewingEdges()
309 void CSelectionDialog::OnHIsoParametrics()
311 void CSelectionDialog::OnHApparentContour()
314 void CSelectionDialog::OnChangeEDITNBIsos()
317 myDisplayableShape->SetNbIsos(m_NbIsos);
320 void CSelectionDialog::OnAlgo()
325 void CSelectionDialog::OnPolyAlgo()
330 void CSelectionDialog::OnDrawHiddenLine()
333 if (m_DisplayMode >=6 )
340 void CSelectionDialog::OnUpdate2D()
342 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
343 myDoc->ActivateFrame(RUNTIME_CLASS(OCC_2dView),SW_NORMAL);
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::OnDegeneratedMode()
395 if(m_DegeneratedModeOn)
397 myActiveView->SetDegenerateModeOn();
398 m_DegeneratedModeOn = Standard_True;
402 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
403 myActiveView->SetDegenerateModeOff();
404 m_DegeneratedModeOn = Standard_False;
405 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
410 void CSelectionDialog::OnLButtonDown(UINT nFlags, CPoint point)
412 CDialog::OnLButtonDown(nFlags, point);
414 if ((myPosMinX > point.x)||(myPosMaxX < point.x) ||
415 (myPosMinY > point.y) ||(myPosMaxY < point.y))
418 // save the current mouse coordinate
419 myXmax=point.x; myYmax=point.y;
422 void CSelectionDialog::OnLButtonUp(UINT nFlags, CPoint point)
424 CDialog::OnLButtonUp(nFlags, point);
426 if ((myPosMinX > point.x)||(myPosMaxX < point.x) ||
427 (myPosMinY > point.y) ||(myPosMaxY < point.y))
431 void CSelectionDialog::OnRButtonDown(UINT nFlags, CPoint point)
433 CDialog::OnRButtonDown(nFlags, point);
435 if ((myPosMinX > point.x)||(myPosMaxX < point.x) ||
436 (myPosMinY > point.y) ||(myPosMaxY < point.y))
439 if ( nFlags & CASCADESHORTCUTKEY )
441 if (!m_DegeneratedModeOn)
442 myActiveView->SetDegenerateModeOn();
443 myActiveView->StartRotation(point.x,point.y);
448 void CSelectionDialog::OnRButtonUp(UINT nFlags, CPoint point)
450 CDialog::OnRButtonUp(nFlags, point);
452 if ((myPosMinX > point.x)||(myPosMaxX < point.x) ||
453 (myPosMinY > point.y) ||(myPosMaxY < point.y))
456 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
457 // reset tyhe good Degenerated mode according to the strored one
458 // --> dynamic rotation may have change it
459 if (!m_DegeneratedModeOn)
460 myActiveView->SetDegenerateModeOff();
462 myActiveView->SetDegenerateModeOn();
464 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
467 void CSelectionDialog::OnMouseMove(UINT nFlags, CPoint point)
469 CDialog::OnMouseMove(nFlags, point);
471 if ((myPosMinX > point.x)||(myPosMaxX < point.x) ||
472 (myPosMinY > point.y) ||(myPosMaxY < point.y))
475 // ============================ LEFT BUTTON =======================
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
486 } else // if ( nFlags & MK_LBUTTON)
487 // ============================ MIDDLE BUTTON =======================
488 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;
495 } else // if ( nFlags & MK_MBUTTON)
496 // ============================ RIGHT BUTTON =======================
497 if ( nFlags & MK_RBUTTON)
499 if ( nFlags & CASCADESHORTCUTKEY )
501 myActiveView->Rotation(point.x,point.y);
503 } else //if ( nFlags & MK_RBUTTON)
504 // ============================ NO BUTTON =======================
506 myXmax = point.x; myYmax = point.y;
511 void CSelectionDialog::OnOK()
516 void CSelectionDialog::OnPaint()
518 CPaintDC dc(this); // device context for painting