1 // HLRDoc.cpp : implementation of the CHLRDoc class
9 #include <OCC_2dView.h>
10 #include <OCC_3dView.h>
13 #include <ImportExport/ImportExport.h>
14 #include "AISDialogs.h"
15 #include <AIS_ListOfInteractive.hxx>
18 //#define new DEBUG_NEW // by cascade
20 static char THIS_FILE[] = __FILE__;
23 /////////////////////////////////////////////////////////////////////////////
26 IMPLEMENT_DYNCREATE(CHLRDoc, CDocument)
29 BEGIN_MESSAGE_MAP(CHLRDoc, OCC_3dBaseDoc)
30 //{{AFX_MSG_MAP(CHLRDoc)
31 ON_COMMAND(ID_WINDOW_NEW3D, OnWindowNew3d)
32 ON_COMMAND(ID_WINDOW_NEW2D, OnWindowNew2d)
33 ON_COMMAND(ID_FILE_HLR, OnBUTTONHLRDialog)
34 ON_COMMAND(ID_FILE_IMPORT_BREP, OnFileImportBrep)
35 ON_COMMAND(ID_BUTTON_HLRDialog, OnBUTTONHLRDialog)
36 ON_COMMAND(ID_OBJECT_ERASE, OnObjectErase)
42 /////////////////////////////////////////////////////////////////////////////
43 // CHLRDoc construction/destruction
47 // TODO: add one-time construction code here
48 Handle(Graphic3d_GraphicDriver) theGraphicDriver =
49 ((CHLRApp*)AfxGetApp())->GetGraphicDriver();
52 myViewer = new V3d_Viewer (theGraphicDriver);
53 myViewer->SetDefaultLights();
54 myViewer->SetLightOn();
56 myAISContext =new AIS_InteractiveContext (myViewer);
58 // 2D VIEWER: exploit V3d viewer for 2D visualization
59 my2DViewer = new V3d_Viewer (theGraphicDriver);
60 my2DViewer->SetCircularGridValues (0, 0, 10, 8, 0);
61 my2DViewer->SetRectangularGridValues (0, 0, 10, 10, 0);
63 //Set projection mode for 2D visualization
64 my2DViewer->SetDefaultViewProj (V3d_Zpos);
66 myInteractiveContext2D = new AIS_InteractiveContext (my2DViewer);
68 CFrameWnd* pFrame2d = ((CHLRApp*)AfxGetApp())->CreateView2D (this);
69 pFrame2d->ShowWindow (SW_SHOWNORMAL);
70 myCSelectionDialogIsCreated = false;
75 if (myCSelectionDialogIsCreated)
77 myCSelectionDialog->ShowWindow(SW_ERASE);
78 delete myCSelectionDialog;
82 void CHLRDoc::OnWindowNew2d()
84 ((CHLRApp*)AfxGetApp())->CreateView2D(this);
87 void CHLRDoc::OnWindowNew3d()
89 ((CHLRApp*)AfxGetApp())->CreateView3D(this);
92 // nCmdShow could be : ( default is SW_RESTORE )
93 // SW_HIDE SW_SHOWNORMAL SW_NORMAL
94 // SW_SHOWMINIMIZED SW_SHOWMAXIMIZED
95 // SW_MAXIMIZE SW_SHOWNOACTIVATE
96 // SW_SHOW SW_MINIMIZE
97 // SW_SHOWMINNOACTIVE SW_SHOWNA
98 // SW_RESTORE SW_SHOWDEFAULT
101 // use pViewClass = RUNTIME_CLASS( CHLRView3D ) for 3D Views
102 // use pViewClass = RUNTIME_CLASS( CHLRView2D ) for 2D Views
104 void CHLRDoc::ActivateFrame(CRuntimeClass* pViewClass,int nCmdShow)
106 POSITION position = GetFirstViewPosition();
107 while (position != (POSITION)NULL)
109 CView* pCurrentView = (CView*)GetNextView(position);
110 if(pCurrentView->IsKindOf(pViewClass) )
112 ASSERT_VALID(pCurrentView);
113 CFrameWnd* pParentFrm = pCurrentView->GetParentFrame();
114 ASSERT(pParentFrm != (CFrameWnd *)NULL);
115 // simply make the frame window visible
116 pParentFrm->ActivateFrame(nCmdShow);
121 void CHLRDoc::FitAll2DViews(Standard_Boolean UpdateViewer)
123 if (UpdateViewer) my2DViewer->Update();
124 POSITION position = GetFirstViewPosition();
125 while (position != (POSITION)NULL)
127 CView* pCurrentView = (CView*)GetNextView(position);
128 if(pCurrentView->IsKindOf(RUNTIME_CLASS(OCC_2dView)) )
130 ASSERT_VALID(pCurrentView);
131 ((OCC_2dView*)pCurrentView)->GetV2dView()->FitAll();
136 /////////////////////////////////////////////////////////////////////////////
137 // CHLRDoc diagnostics
140 void CHLRDoc::AssertValid() const
142 CDocument::AssertValid();
145 void CHLRDoc::Dump(CDumpContext& dc) const
151 /////////////////////////////////////////////////////////////////////////////
153 void CHLRDoc::OnBUTTONHLRDialog()
155 if (!myCSelectionDialogIsCreated)
157 myCSelectionDialog = new CSelectionDialog(this,AfxGetMainWnd());
158 myCSelectionDialog->Create(CSelectionDialog::IDD, AfxGetMainWnd());
159 myCSelectionDialogIsCreated = true;
161 myCSelectionDialog->ShowWindow(SW_RESTORE);
162 myCSelectionDialog->UpdateWindow();
165 void CHLRDoc::OnFileImportBrep()
166 { CImportExport::ReadBREP(myAISContext);
171 POSITION position = GetFirstViewPosition();
172 while (position != (POSITION)NULL)
174 CView* pCurrentView = (CView*)GetNextView(position);
175 if(pCurrentView->IsKindOf(RUNTIME_CLASS(OCC_3dView)) )
177 ((OCC_3dView *) pCurrentView)->FitAll();
182 void CHLRDoc::OnObjectErase()
184 Standard_Boolean toUpdateDisplayable = Standard_False;
185 myAISContext->InitSelected();
186 while (myAISContext->MoreSelected())
188 if (myAISContext->SelectedInteractive()->Type() == AIS_KOI_Shape && myCSelectionDialogIsCreated)
190 myCSelectionDialog->DiplayableShape()->Remove (Handle(AIS_Shape)::DownCast (myAISContext->SelectedInteractive())->Shape());
191 toUpdateDisplayable = Standard_True;
194 myAISContext->Erase (myAISContext->SelectedInteractive(), Standard_True);
195 myAISContext->InitSelected();
198 myAISContext->ClearSelected();
200 if (toUpdateDisplayable)
202 // Update view in the HLR dialog if list of displayable shapes has been changed.
203 myCSelectionDialog->UpdateViews();