7fd59977 |
1 | // HLRDoc.cpp : implementation of the CHLRDoc class |
2 | // |
3 | |
4 | |
5 | #include "stdafx.h" |
6 | |
7 | #include "HLRDoc.h" |
8 | |
9 | #include "HLRApp.h" |
10 | #include <OCC_2dView.h> |
11 | #include <OCC_3dView.h> |
12 | |
13 | |
14 | #include <ImportExport/ImportExport.h> |
15 | #include "AISDialogs.h" |
16 | #include "Properties/PropertiesSheet.h" |
17 | |
18 | #include <AIS_ListOfInteractive.hxx> |
19 | |
20 | #ifdef _DEBUG |
21 | //#define new DEBUG_NEW // by cascade |
22 | #undef THIS_FILE |
23 | static char THIS_FILE[] = __FILE__; |
24 | #endif |
25 | |
26 | ///////////////////////////////////////////////////////////////////////////// |
27 | // CHLRDoc |
28 | |
29 | IMPLEMENT_DYNCREATE(CHLRDoc, CDocument) |
30 | |
31 | |
32 | BEGIN_MESSAGE_MAP(CHLRDoc, OCC_3dBaseDoc) |
33 | //{{AFX_MSG_MAP(CHLRDoc) |
34 | ON_COMMAND(ID_WINDOW_NEW3D, OnWindowNew3d) |
35 | ON_COMMAND(ID_WINDOW_NEW2D, OnWindowNew2d) |
36 | ON_COMMAND(ID_FILE_IMPORT_BREP, OnFileImportBrep) |
37 | ON_COMMAND(ID_BUTTON_HLRDialog, OnBUTTONHLRDialog) |
38 | ON_COMMAND(ID_MENU_CASCADE_PROPERTIES, OnBUTTONTest2DProperties) |
39 | //}}AFX_MSG_MAP |
40 | |
41 | |
42 | END_MESSAGE_MAP() |
43 | |
44 | ///////////////////////////////////////////////////////////////////////////// |
45 | // CHLRDoc construction/destruction |
46 | |
47 | CHLRDoc::CHLRDoc() |
48 | { |
49 | // TODO: add one-time construction code here |
50 | |
51 | Handle(Graphic3d_WNTGraphicDevice) theGraphicDevice = |
52 | ((CHLRApp*)AfxGetApp())->GetGraphicDevice(); |
53 | |
54 | TCollection_ExtendedString a3DName("Visu3D"); |
55 | myViewer = new V3d_Viewer(theGraphicDevice,a3DName.ToExtString(),"", 1000.0, |
56 | V3d_XposYnegZpos, Quantity_NOC_GRAY30, |
57 | V3d_ZBUFFER,V3d_GOURAUD,V3d_WAIT, |
58 | Standard_True, Standard_False); |
59 | /* |
60 | Handle(V3d_Viewer) myViewerCollector; |
61 | myViewerCollector = new V3d_Viewer(theGraphicDevice,a3DName.ToExtString(),"", 1000.0, |
62 | V3d_XposYnegZpos, Quantity_NOC_GRAY30, |
63 | V3d_ZBUFFER,V3d_GOURAUD,V3d_WAIT, |
64 | Standard_True, Standard_False); |
65 | */ |
66 | myViewer->SetDefaultLights(); |
67 | myViewer->SetLightOn(); |
68 | |
69 | //myAISContext =new AIS_InteractiveContext(myViewer,myViewerCollector); |
70 | |
71 | myAISContext =new AIS_InteractiveContext(myViewer); |
72 | |
73 | // VIEWER 2D |
74 | TCollection_ExtendedString a2DName("Visu2D"); |
75 | my2DViewer = new V2d_Viewer(theGraphicDevice,a2DName.ToExtString()); |
76 | my2DViewer->SetCircularGridValues(0,0,10,8,0); |
77 | my2DViewer->SetRectangularGridValues(0,0,10,10,0); |
78 | |
79 | myInteractiveContext2D= new ISession2D_InteractiveContext(my2DViewer); |
80 | |
81 | CFrameWnd* pFrame2d=((CHLRApp*)AfxGetApp())->CreateView2D(this); |
82 | pFrame2d->ShowWindow(SW_SHOWNORMAL/*SW_MINIMIZE*/); |
83 | |
84 | // update the Maps : |
85 | // entries are reserve for utilisation : |
86 | // - 1 for Visible edges HighLighted |
87 | // - 2 for Visible edges |
88 | // - 3 for Hidden edges HighLighted |
89 | // - 4 for Hidden edges |
90 | |
91 | Handle(Aspect_GenericColorMap) aColorMap= Handle(Aspect_GenericColorMap)::DownCast(my2DViewer->ColorMap()); |
92 | ASSERT(!aColorMap.IsNull()); |
93 | aColorMap->AddEntry(Aspect_ColorMapEntry (1,Quantity_Color(Quantity_NOC_RED ))); // in fact just update |
94 | aColorMap->AddEntry(Aspect_ColorMapEntry (2,Quantity_Color(Quantity_NOC_WHITE))); // in fact just update |
95 | aColorMap->AddEntry(Aspect_ColorMapEntry (3,Quantity_Color(Quantity_NOC_RED ))); // in fact just update |
96 | aColorMap->AddEntry(Aspect_ColorMapEntry (4,Quantity_Color(Quantity_NOC_BLUE1))); // in fact just update |
97 | my2DViewer->SetColorMap(aColorMap); |
98 | |
99 | Handle(Aspect_WidthMap) aWidthMap = my2DViewer->WidthMap(); |
100 | aWidthMap->AddEntry(Aspect_WidthMapEntry(1,0.8)); // in fact just update |
101 | aWidthMap->AddEntry(Aspect_WidthMapEntry(2,0.4)); // in fact just update |
102 | aWidthMap->AddEntry(Aspect_WidthMapEntry(3,0.6)); // in fact just update |
103 | aWidthMap->AddEntry(Aspect_WidthMapEntry(4,0.2)); // in fact just update |
104 | my2DViewer->SetWidthMap(aWidthMap); |
105 | |
106 | Handle(Aspect_TypeMap) aTypeMap = my2DViewer->TypeMap(); |
107 | aTypeMap->AddEntry(Aspect_TypeMapEntry(1,Aspect_LineStyle(Aspect_TOL_SOLID))); |
108 | aTypeMap->AddEntry(Aspect_TypeMapEntry(2,Aspect_LineStyle(Aspect_TOL_SOLID))); |
109 | TColQuantity_Array1OfLength anArray(1,2); |
110 | anArray(1) = 0.5; anArray(2) = 0.5; |
111 | aTypeMap->AddEntry(Aspect_TypeMapEntry(3,Aspect_LineStyle(anArray))); |
112 | aTypeMap->AddEntry(Aspect_TypeMapEntry(4,Aspect_LineStyle(anArray))); |
113 | my2DViewer->SetTypeMap(aTypeMap); |
114 | |
115 | myCSelectionDialogIsCreated=false; |
116 | } |
117 | |
118 | CHLRDoc::~CHLRDoc() |
119 | { |
120 | if (myCSelectionDialogIsCreated) |
121 | { |
122 | myCSelectionDialog->ShowWindow(SW_ERASE); |
123 | delete myCSelectionDialog; |
124 | } |
125 | } |
126 | |
127 | void CHLRDoc::OnWindowNew2d() |
128 | { |
129 | ((CHLRApp*)AfxGetApp())->CreateView2D(this); |
130 | } |
131 | |
132 | void CHLRDoc::OnWindowNew3d() |
133 | { |
134 | ((CHLRApp*)AfxGetApp())->CreateView3D(this); |
135 | } |
136 | |
137 | // nCmdShow could be : ( default is SW_RESTORE ) |
138 | // SW_HIDE SW_SHOWNORMAL SW_NORMAL |
139 | // SW_SHOWMINIMIZED SW_SHOWMAXIMIZED |
140 | // SW_MAXIMIZE SW_SHOWNOACTIVATE |
141 | // SW_SHOW SW_MINIMIZE |
142 | // SW_SHOWMINNOACTIVE SW_SHOWNA |
143 | // SW_RESTORE SW_SHOWDEFAULT |
144 | // SW_MAX |
145 | |
146 | // use pViewClass = RUNTIME_CLASS( CHLRView3D ) for 3D Views |
147 | // use pViewClass = RUNTIME_CLASS( CHLRView2D ) for 2D Views |
148 | |
149 | void CHLRDoc::ActivateFrame(CRuntimeClass* pViewClass,int nCmdShow) |
150 | { |
151 | POSITION position = GetFirstViewPosition(); |
152 | while (position != (POSITION)NULL) |
153 | { |
154 | CView* pCurrentView = (CView*)GetNextView(position); |
155 | if(pCurrentView->IsKindOf(pViewClass) ) |
156 | { |
157 | ASSERT_VALID(pCurrentView); |
158 | CFrameWnd* pParentFrm = pCurrentView->GetParentFrame(); |
159 | ASSERT(pParentFrm != (CFrameWnd *)NULL); |
160 | // simply make the frame window visible |
161 | pParentFrm->ActivateFrame(nCmdShow); |
162 | } |
163 | } |
164 | } |
165 | |
166 | void CHLRDoc::FitAll2DViews(Standard_Boolean UpdateViewer) |
167 | { |
168 | if (UpdateViewer) my2DViewer->Update(); |
169 | POSITION position = GetFirstViewPosition(); |
170 | while (position != (POSITION)NULL) |
171 | { |
172 | CView* pCurrentView = (CView*)GetNextView(position); |
173 | if(pCurrentView->IsKindOf(RUNTIME_CLASS(OCC_2dView)) ) |
174 | { |
175 | ASSERT_VALID(pCurrentView); |
176 | ((OCC_2dView*)pCurrentView)->GetV2dView()->Fitall(); |
177 | } |
178 | } |
179 | } |
180 | |
181 | void CHLRDoc::OnBUTTONTest2DProperties() |
182 | { |
183 | // TODO: Add your command handler code here |
184 | CPropertiesSheet aDial; |
185 | aDial.SetViewer(my2DViewer); |
186 | aDial.DoModal(); |
187 | } |
188 | |
189 | |
190 | ///////////////////////////////////////////////////////////////////////////// |
191 | // CHLRDoc diagnostics |
192 | |
193 | #ifdef _DEBUG |
194 | void CHLRDoc::AssertValid() const |
195 | { |
196 | CDocument::AssertValid(); |
197 | } |
198 | |
199 | void CHLRDoc::Dump(CDumpContext& dc) const |
200 | { |
201 | CDocument::Dump(dc); |
202 | } |
203 | #endif //_DEBUG |
204 | |
205 | ///////////////////////////////////////////////////////////////////////////// |
206 | // CHLRDoc commands |
207 | void CHLRDoc::OnBUTTONHLRDialog() |
208 | |
209 | { |
210 | if (!myCSelectionDialogIsCreated) |
211 | { |
212 | myCSelectionDialog = new CSelectionDialog(this,AfxGetMainWnd()); |
213 | myCSelectionDialog->Create(CSelectionDialog::IDD, AfxGetMainWnd()); |
214 | myCSelectionDialogIsCreated = true; |
215 | } |
216 | myCSelectionDialog->ShowWindow(SW_RESTORE); |
217 | } |
218 | |
219 | void CHLRDoc::OnFileImportBrep() |
220 | { CImportExport::ReadBREP(myAISContext); |
221 | Fit(); |
222 | } |
223 | void CHLRDoc::Fit() |
224 | { |
225 | POSITION position = GetFirstViewPosition(); |
226 | while (position != (POSITION)NULL) |
227 | { |
228 | CView* pCurrentView = (CView*)GetNextView(position); |
229 | if(pCurrentView->IsKindOf(RUNTIME_CLASS(OCC_3dView)) ) |
230 | { |
231 | ((OCC_3dView *) pCurrentView)->FitAll(); |
232 | } |
233 | } |
234 | } |