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