0031431: Visualization, PrsMgr_PresentableObject - simplify HLR computing interface
[occt.git] / samples / mfc / standard / 04_Viewer3d / src / DlgAttributes.cpp
CommitLineData
7fd59977 1// DlgAttributes.cpp : implementation file
2//
3
4#include "stdafx.h"
5
6#include "DlgAttributes.h"
7
8#include "AISDisplayModeApp.h"
9
10#include <AISDialogs.h>
11#include <OCC_3dView.h>
12
13#include <Graphic3d_MaterialAspect.hxx>
14
15#ifdef _DEBUG
16#define new DEBUG_NEW
17#undef THIS_FILE
18static char THIS_FILE[] = __FILE__;
19#endif
20
21/////////////////////////////////////////////////////////////////////////////
22// DlgAttributes dialog
23
24
25DlgAttributes::DlgAttributes(CWnd* pParent)
26 : CDialog(DlgAttributes::IDD, pParent)
27{
28 //{{AFX_DATA_INIT(DlgAttributes)
29 // NOTE: the ClassWizard will add member initialization here
30 //}}AFX_DATA_INIT
31}
32
33
34void DlgAttributes::DoDataExchange(CDataExchange* pDX)
35{
36 CDialog::DoDataExchange(pDX);
37 //{{AFX_DATA_MAP(DlgAttributes)
38 // NOTE: the ClassWizard will add DDX and DDV calls here
39 //}}AFX_DATA_MAP
40}
41
42
43BEGIN_MESSAGE_MAP(DlgAttributes, CDialog)
44 //{{AFX_MSG_MAP(DlgAttributes)
45 ON_BN_CLICKED(ID_OBJECT_MATERIAL_ALUMINIUM, OnObjectMaterialAluminium)
46 ON_BN_CLICKED(ID_OBJECT_MATERIAL_BRASS, OnObjectMaterialBrass)
47 ON_BN_CLICKED(ID_OBJECT_MATERIAL_BRONZE, OnObjectMaterialBronze)
48 ON_BN_CLICKED(ID_OBJECT_MATERIAL_CHROME, OnObjectMaterialChrome)
49 ON_BN_CLICKED(ID_OBJECT_MATERIAL_COPPER, OnObjectMaterialCopper)
50 ON_BN_CLICKED(ID_OBJECT_MATERIAL_GOLD, OnObjectMaterialGold)
51 ON_BN_CLICKED(ID_OBJECT_MATERIAL_JADE, OnObjectMaterialJade)
52 ON_BN_CLICKED(ID_OBJECT_MATERIAL_METALIZED, OnObjectMaterialMetalized)
53 ON_BN_CLICKED(ID_OBJECT_MATERIAL_NEON_GNC, OnObjectMaterialNeonGNC)
54 ON_BN_CLICKED(ID_OBJECT_MATERIAL_NEON_PHC, OnObjectMaterialNeonPHC)
55 ON_BN_CLICKED(ID_OBJECT_MATERIAL_OBSIDIAN, OnObjectMaterialObsidian)
56 ON_BN_CLICKED(ID_OBJECT_MATERIAL_PEWTER, OnObjectMaterialPewter)
57 ON_BN_CLICKED(ID_OBJECT_MATERIAL_PLASTER, OnObjectMaterialPlaster)
58 ON_BN_CLICKED(ID_OBJECT_MATERIAL_PLASTIC, OnObjectMaterialPlastic)
59 ON_BN_CLICKED(ID_OBJECT_MATERIAL_SATIN, OnObjectMaterialSatin)
60 ON_BN_CLICKED(ID_OBJECT_MATERIAL_SHINY_PLASTIC, OnObjectMaterialShinyPlastic)
61 ON_BN_CLICKED(ID_OBJECT_MATERIAL_SILVER, OnObjectMaterialSilver)
62 ON_BN_CLICKED(ID_OBJECT_MATERIAL_STEEL, OnObjectMaterialSteel)
63 ON_BN_CLICKED(ID_OBJECT_MATERIAL_STONE, OnObjectMaterialStone)
64 ON_BN_CLICKED(ID_OBJECT_MATERIAL_DEFAULT, OnObjectMaterialDefault)
65 ON_BN_CLICKED(ID_OBJECT_COLOR, OnColor)
66 ON_BN_CLICKED(ID_OBJECT_SHADING, OnShading)
67 ON_BN_CLICKED(ID_OBJECT_WIREFRAME, OnWireframe)
68 ON_COMMAND(ID_OBJECT_TRANSPARENCY, OnTransparency)
69 ON_UPDATE_COMMAND_UI(ID_OBJECT_TRANSPARENCY, OnUpdateObjectTransparency)
70//}}AFX_MSG_MAP
71END_MESSAGE_MAP()
72
73/////////////////////////////////////////////////////////////////////////////
74// DlgAttributes message handlers
75
76
77void DlgAttributes::OnColor()
78{
92efcf78 79 Handle(AIS_InteractiveObject) Current ;
7fd59977 80 Quantity_Color CSFColor ;
81 COLORREF MSColor ;
82
83 myAISContext->InitCurrent();
84 if (myAISContext->MoreCurrent()) {
85 Current = myAISContext->Current() ;
86 if ( Current->HasColor () ) {
87 CSFColor = Current->Color () ;
88 MSColor = RGB (CSFColor.Red()*255.,
89 CSFColor.Green()*255.,
90 CSFColor.Blue()*255.);
91 }
92 else {
93 MSColor = RGB (255,255,255) ;
94 }
95
96 CColorDialog dlgColor(MSColor);
97 if (dlgColor.DoModal() == IDOK) {
98 MSColor = dlgColor.GetColor();
99 CSFColor = Quantity_Color (GetRValue(MSColor)/255.,
100 GetGValue(MSColor)/255.,
101 GetBValue(MSColor)/255.,Quantity_TOC_RGB);
102 for (myAISContext->InitCurrent();
103 myAISContext->MoreCurrent ();
104 myAISContext->NextCurrent ())
105 myAISContext->SetColor (myAISContext->Current(),
106 CSFColor.Name());
107 }
108 }
109
110TCollection_AsciiString Message ("\
111\n\
112for (myAISContext->InitCurrent(); myAISContext->MoreCurrent (); \n\
113 myAISContext->NextCurrent ()) \n\
114 myAISContext->SetColor (myAISContext->Current(), CSFColor.Name()); \n\
115\n");
116
117 CString text(Message.ToCString());
118 (*myCResultDialog).SetTitle(CString("Setting Color"));
119 (*myCResultDialog).SetText(text);
120}
121
122
123void DlgAttributes::OnWireframe()
124{
125 for(myAISContext->InitCurrent(); myAISContext->MoreCurrent();
126 myAISContext->NextCurrent())
127 myAISContext->SetDisplayMode(myAISContext->Current(), 0);
128
129TCollection_AsciiString Message ("\
130\n\
131for (myAISContext->InitCurrent(); myAISContext->MoreCurrent (); \n\
132 myAISContext->NextCurrent ()) \n\
133 myAISContext->SetDisplayMode(myAISContext->Current(), 0); \n\
134\n");
135
136 CString text(Message.ToCString());
137 (*myCResultDialog).SetTitle(CString("Wireframe"));
138 (*myCResultDialog).SetText(text);
139}
140
141void DlgAttributes::Set(Handle ( AIS_InteractiveContext ) & acontext, CResultDialog& aResultDialog)
142{
143 myAISContext = acontext;
144 myCResultDialog=&aResultDialog;
145}
146
147void DlgAttributes::OnTransparency()
148{
149/*
150 for (myAISContext->InitCurrent(); myAISContext->MoreCurrent ();
151 myAISContext->NextCurrent ()) {
152
153
154 int ival = (int) ((double) myAISContext->Current()->Transparency()*10.) ;
155 double rval = ((double) ival)/10.;
156 CDialogTransparency Dlg(NULL, rval);
157 if(Dlg.DoModal()== IDOK)
158 myAISContext->SetTransparency (myAISContext->Current(),Dlg.m_transvalue);
159
160 }
161*/
162 /*
163 CDialogTransparency DialBox(myAISContext);
164 DialBox.DoModal();
165 CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
166 CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame();
167 OCC_3dView *pView = (OCC_3dView *) pChild->GetActiveView();
168 pView->Redraw();
169 */
170 myAISContext->InitCurrent();
171 if(myAISContext->NbCurrents() > 0){
172 CDialogTransparency DialBox(myAISContext, AfxGetMainWnd());
173 DialBox.DoModal();
174 CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
175 CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame();
176 OCC_3dView *pView = (OCC_3dView *) pChild->GetActiveView();
177 pView->Redraw();
178 }
179
180TCollection_AsciiString Message ("\
181\n\
182for (myAISContext->InitCurrent(); myAISContext->MoreCurrent (); \n\
183 myAISContext->NextCurrent ()) \n\
184 myAISContext->SetTransparency (myAISContext->Current(),Dlg.m_transvalue); \n\
185\n");
186
187 CString text(Message.ToCString());
188 (*myCResultDialog).SetTitle(CString("Setting Transparency"));
189 (*myCResultDialog).SetText(text);
190}
191
192
193
194void DlgAttributes::OnObjectMaterialAluminium () { SetMaterial ( Graphic3d_NOM_ALUMINIUM ) ; }
195void DlgAttributes::OnObjectMaterialBrass () { SetMaterial ( Graphic3d_NOM_BRASS ) ; }
196void DlgAttributes::OnObjectMaterialBronze () { SetMaterial ( Graphic3d_NOM_BRONZE ) ; }
197void DlgAttributes::OnObjectMaterialChrome () { SetMaterial ( Graphic3d_NOM_CHROME ) ; }
198void DlgAttributes::OnObjectMaterialCopper () { SetMaterial ( Graphic3d_NOM_COPPER ) ; }
199void DlgAttributes::OnObjectMaterialGold () { SetMaterial ( Graphic3d_NOM_GOLD ) ; }
200void DlgAttributes::OnObjectMaterialJade () { SetMaterial ( Graphic3d_NOM_JADE ) ; }
201void DlgAttributes::OnObjectMaterialMetalized () { SetMaterial ( Graphic3d_NOM_METALIZED ) ; }
202void DlgAttributes::OnObjectMaterialNeonGNC () { SetMaterial ( Graphic3d_NOM_NEON_GNC ) ; }
203void DlgAttributes::OnObjectMaterialNeonPHC () { SetMaterial ( Graphic3d_NOM_NEON_PHC ) ; }
204void DlgAttributes::OnObjectMaterialObsidian () { SetMaterial ( Graphic3d_NOM_OBSIDIAN ) ; }
205void DlgAttributes::OnObjectMaterialPewter () { SetMaterial ( Graphic3d_NOM_PEWTER ) ; }
206void DlgAttributes::OnObjectMaterialPlaster () { SetMaterial ( Graphic3d_NOM_PLASTER ) ; }
207void DlgAttributes::OnObjectMaterialPlastic () { SetMaterial ( Graphic3d_NOM_PLASTIC ) ; }
208void DlgAttributes::OnObjectMaterialSatin () { SetMaterial ( Graphic3d_NOM_SATIN ) ; }
209void DlgAttributes::OnObjectMaterialShinyPlastic () { SetMaterial ( Graphic3d_NOM_SHINY_PLASTIC ) ; }
210void DlgAttributes::OnObjectMaterialSilver () { SetMaterial ( Graphic3d_NOM_SILVER ) ; }
211void DlgAttributes::OnObjectMaterialSteel () { SetMaterial ( Graphic3d_NOM_STEEL ) ; }
212void DlgAttributes::OnObjectMaterialStone () { SetMaterial ( Graphic3d_NOM_STONE ) ; }
213void DlgAttributes::OnObjectMaterialDefault () { SetMaterial ( Graphic3d_NOM_DEFAULT ) ; }
214
215void DlgAttributes::SetMaterial(Graphic3d_NameOfMaterial Material)
216{
217 for (myAISContext->InitCurrent();myAISContext->MoreCurrent ();myAISContext->NextCurrent ())
218 myAISContext->SetMaterial (myAISContext->Current(),
219 (Graphic3d_NameOfMaterial)(Material));
220
221 TCollection_AsciiString aString;
222 TCollection_AsciiString Message1 ("\
223\n\
224for (myAISContext->InitCurrent(); myAISContext->MoreCurrent (); \n\
225 myAISContext->NextCurrent ()) \n\
226 myAISContext->SetMaterial (myAISContext->Current(), ");
227
228 TCollection_AsciiString Message2("); \n\
229\n");
230 switch (Material){
231 case 0:
232 aString = "Graphic3d_NOM_BRASS";
233 break;
234 case 1:
235 aString = "Graphic3d_NOM_BRONZE";
236 break;
237 case 2:
238 aString = "Graphic3d_NOM_COPPER";
239 break;
240 case 3:
241 aString = "Graphic3d_NOM_GOLD";
242 break;
243 case 4:
244 aString = "Graphic3d_NOM_PEWTER";
245 break;
246 case 5:
247 aString = "Graphic3d_NOM_PLASTER";
248 break;
249 case 6:
250 aString = "Graphic3d_NOM_PLASTIC";
251 break;
252 case 7:
253 aString = "Graphic3d_NOM_SILVER";
254 break;
255 case 8:
256 aString = "Graphic3d_NOM_STEEL";
257 break;
258 case 9:
259 aString = "Graphic3d_NOM_STONE";
260 break;
261 case 10:
262 aString = "Graphic3d_NOM_SHINY_PLASTIC";
263 break;
264 case 11:
265 aString = "Graphic3d_NOM_SATIN";
266 break;
267 case 12:
268 aString = "Graphic3d_NOM_METALIZED";
269 break;
270 case 13:
271 aString = "Graphic3d_NOM_NEON_GNC";
272 break;
273 case 14:
274 aString = "Graphic3d_NOM_CHROME";
275 break;
276 case 15:
277 aString = "Graphic3d_NOM_ALUMINIUM";
278 break;
279 case 16:
280 aString = "Graphic3d_NOM_OBSIDIAN";
281 break;
282 case 17:
283 aString = "Graphic3d_NOM_NEON_PHC";
284 break;
285 case 18:
286 aString = "Graphic3d_NOM_JADE";
287 break;
288 case 19:
289 aString = "Graphic3d_NOM_DEFAULT";
290 break;
291 default:
292 break;
293 }
294
295 Message1 = Message1 +aString +Message2;
296 //Graphic3d_MaterialAspect aAspect (Material);
297 //Standard_CString aString = aAspect.MaterialName();
298
299 CString text(Message1.ToCString());
300 (*myCResultDialog).SetTitle(CString("Setting Material"));
301 (*myCResultDialog).SetText(text);
302
303}
304
305void DlgAttributes::OnUpdateObjectTransparency(CCmdUI* pCmdUI)
306{
307 bool OneOrMoreInShading = false;
308 for (myAISContext->InitCurrent();myAISContext->MoreCurrent ();myAISContext->NextCurrent ())
309 if (myAISContext->IsDisplayed(myAISContext->Current(),1)) OneOrMoreInShading=true;
310 pCmdUI->Enable (OneOrMoreInShading);
311}
312
313
314
315void DlgAttributes::OnShading()
316{
317 for(myAISContext->InitCurrent(); myAISContext->MoreCurrent();
318 myAISContext->NextCurrent())
319 myAISContext->SetDisplayMode(myAISContext->Current(), 1);
320
321
322TCollection_AsciiString Message ("\
323\n\
324for (myAISContext->InitCurrent(); myAISContext->MoreCurrent (); \n\
325 myAISContext->NextCurrent ()) \n\
326 myAISContext->SetDisplayMode(myAISContext->Current(), 1); \n\
327\n");
328
329 CString text(Message.ToCString());
330 (*myCResultDialog).SetTitle(CString("Shading"));
331 (*myCResultDialog).SetText(text);
332}