Integration of OCCT 6.5.0 from SVN
[occt.git] / samples / mfc / standard / 08_HLR / src / Properties / ColorNewColorRampColorMapDialog.cpp
1 // ColorNewColorRampColorMapDialog.cpp : implementation file
2 //
3
4 #include "stdafx.h"
5
6 #include "ColorNewColorRampColorMapDialog.h"
7
8 #include "HLRApp.h"
9 #include "Quantity_Color.hxx"
10 #include "Aspect_ColorRampColorMap.hxx"
11
12 #ifdef _DEBUG
13 //#define new DEBUG_NEW
14 #undef THIS_FILE
15 static char THIS_FILE[] = __FILE__;
16 #endif
17
18 /////////////////////////////////////////////////////////////////////////////
19 // CColorNewColorRampColorMapDialog dialog
20
21 CColorNewColorRampColorMapDialog::CColorNewColorRampColorMapDialog(CWnd* pParent /*=NULL*/)
22         : CDialog(CColorNewColorRampColorMapDialog::IDD, pParent)
23 {
24         //{{AFX_DATA_INIT(CColorNewColorRampColorMapDialog)
25         m_base_pixel = 0;
26         m_dimension = 16;
27         m_Red       = 1.0;
28         m_Green     = 0.0;
29         m_Blue      = 0.0;
30         //}}AFX_DATA_INIT
31 }
32
33 void CColorNewColorRampColorMapDialog::DoDataExchange(CDataExchange* pDX)
34 {
35         CDialog::DoDataExchange(pDX);
36         //{{AFX_DATA_MAP(CColorNewColorRampColorMapDialog)
37         DDX_Control(pDX, IDC_NewColorMap_COMBO_NewEntryColorName, m_ColorList);
38         DDX_Text(pDX, IDC_NewColorRamp_EDIT_base_pixel, m_base_pixel);
39         DDX_Text(pDX, IDC_NewColorramp_EDIT_dimension, m_dimension);
40         DDX_Text(pDX, IDC_NewColorMapRamp_EDIT_ColorRed, m_Red);
41         DDX_Text(pDX, IDC_NewColorMapRamp_EDIT_ColorGreen, m_Green);
42         DDX_Text(pDX, IDC_NewColorMapRamp_EDIT_ColorBlue, m_Blue);
43         //}}AFX_DATA_MAP
44 }
45
46
47 BEGIN_MESSAGE_MAP(CColorNewColorRampColorMapDialog, CDialog)
48         //{{AFX_MSG_MAP(CColorNewColorRampColorMapDialog)
49         ON_BN_CLICKED(IDC_NewColorMapRamp_BUTTON_EditColor, OnColorMapRampBUTTONEditColor)
50         ON_EN_CHANGE(IDC_NewColorMapRamp_EDIT_ColorRed, OnChangeColorMapRampEDITColorRed)
51         ON_EN_CHANGE(IDC_NewColorMapRamp_EDIT_ColorGreen, OnChangeColorMapRampEDITColorGreen)
52         ON_EN_CHANGE(IDC_NewColorMapRamp_EDIT_ColorBlue, OnChangeColorMapRampEDITColorBlue)
53         ON_CBN_SELCHANGE(IDC_NewColorMap_COMBO_NewEntryColorName, OnSelchangeColorMapCOMBONewEntryColorName)
54         //}}AFX_MSG_MAP
55 END_MESSAGE_MAP()
56
57 /////////////////////////////////////////////////////////////////////////////
58 // CColorNewColorRampColorMapDialog message handlers
59 BOOL CColorNewColorRampColorMapDialog::OnInitDialog() 
60 {
61         CDialog::OnInitDialog();
62     for (int i = 0 ;i< 517 ;  i++)
63     {
64       Standard_CString TheColorName = Quantity_Color::StringName((Quantity_NameOfColor)i);
65       // update the CComboBox to add the enumeration possibilities.
66       m_ColorList.AddString( TheColorName );
67     }
68     Quantity_Color aColor(m_Red,m_Green,m_Blue,Quantity_TOC_RGB);
69     m_ColorList.SetCurSel(aColor.Name());
70         
71         return TRUE;  // return TRUE unless you set the focus to a control
72                       // EXCEPTION: OCX Property Pages should return FALSE
73 }
74
75
76 void CColorNewColorRampColorMapDialog::OnColorMapRampBUTTONEditColor() 
77 {
78     UpdateData(true);
79     COLORREF m_clr ;
80         m_clr = RGB(m_Red*255,m_Green*255,m_Blue*255);
81         CColorDialog dlgColor(m_clr);
82         if (dlgColor.DoModal() == IDOK)
83         {
84                 m_clr = dlgColor.GetColor();
85                 m_Red    = GetRValue(m_clr)/255.;
86                 m_Green  = GetGValue(m_clr)/255.;
87                 m_Blue   = GetBValue(m_clr)/255.;
88     }
89     Quantity_Color aColor(m_Red,m_Green,m_Blue,Quantity_TOC_RGB);
90     m_ColorList.SetCurSel(aColor.Name());
91     UpdateData(false);
92 }
93
94
95 void CColorNewColorRampColorMapDialog::OnChangeColorMapRampEDITColorRed() 
96 {
97     UpdateData(true);
98     if (m_Red<0) m_Red=0;
99     if (m_Red>1) m_Red=1;
100     
101     Quantity_Color aColor(m_Red,m_Green,m_Blue,Quantity_TOC_RGB);
102     m_ColorList.SetCurSel(aColor.Name());
103     UpdateData(false);
104 }
105
106 void CColorNewColorRampColorMapDialog::OnChangeColorMapRampEDITColorGreen() 
107 {
108     UpdateData(true);
109     if (m_Green<0) m_Green=0;
110     if (m_Green>1) m_Green=1;
111     Quantity_Color aColor(m_Red,m_Green,m_Blue,Quantity_TOC_RGB);
112     m_ColorList.SetCurSel(aColor.Name());
113     UpdateData(false);  
114 }
115 void CColorNewColorRampColorMapDialog::OnChangeColorMapRampEDITColorBlue() 
116 {
117     UpdateData(true);
118     if (m_Blue<0) m_Blue=0;
119     if (m_Blue>1) m_Blue=1;
120     Quantity_Color aColor(m_Red,m_Green,m_Blue,Quantity_TOC_RGB);
121     m_ColorList.SetCurSel(aColor.Name());
122     UpdateData(false);  
123 }
124
125 void CColorNewColorRampColorMapDialog::OnSelchangeColorMapCOMBONewEntryColorName() 
126 {
127         // TODO: Add your control notification handler code here
128         UpdateData(true);       
129     int CurSel = m_ColorList.GetCurSel();
130     Quantity_NameOfColor SelectedNameOfColor = (Quantity_NameOfColor)CurSel;
131     Quantity_Color TheSelectedEquivalentColor(SelectedNameOfColor);
132
133     Quantity_Parameter Red,Green,Blue;
134     TheSelectedEquivalentColor.Values(Red,Green,Blue,Quantity_TOC_RGB);
135     m_Red         = Red;
136     m_Green       = Green;
137     m_Blue        = Blue; 
138     UpdateData(false);  
139 }
140
141
142 void CColorNewColorRampColorMapDialog::OnOK() 
143 {
144         UpdateData(true);
145     Quantity_Color TheColor(m_Red,m_Green,m_Blue,Quantity_TOC_RGB);
146     myColorMap = 
147         new Aspect_ColorRampColorMap(m_base_pixel,
148                                          m_dimension,
149                                      TheColor );
150         CDialog::OnOK();
151 }