0023821: Improve qmake project files for Qt samples
[occt.git] / samples / mfc / standard / 08_HLR / src / Properties / WidthPropertyPage.cpp
1 // WidthPropertyPage.cpp : implementation file
2 //
3
4 #include "stdafx.h"
5
6 #include "WidthPropertyPage.h"
7
8 #include "HLRApp.h"
9 #include "Aspect_WidthMapEntry.hxx"
10 #include "Aspect_LineStyle.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 // CWidthPropertyPage property page
20
21 IMPLEMENT_DYNCREATE(CWidthPropertyPage, CPropertyPage)
22
23 CWidthPropertyPage::CWidthPropertyPage() : CPropertyPage(CWidthPropertyPage::IDD)
24 {
25         //{{AFX_DATA_INIT(CWidthPropertyPage)
26         m_WidthMapSize  = _T("Computing...");
27     m_EntryType     = _T("Computing...");
28         m_EntryWidth    = _T("Computing...");
29         m_NewEntryWidth = 1;
30         //}}AFX_DATA_INIT
31 }
32
33 CWidthPropertyPage::~CWidthPropertyPage()
34 {
35 }
36
37 void CWidthPropertyPage::DoDataExchange(CDataExchange* pDX)
38 {
39         CPropertyPage::DoDataExchange(pDX);
40         //{{AFX_DATA_MAP(CWidthPropertyPage)
41         DDX_Text    (pDX, IDC_WidthMap_STATIC_Size,        m_WidthMapSize);
42         DDX_Control (pDX, IDC_WidthMap_TAB,                m_TabCtrl);
43         DDX_Text    (pDX, IDC_WidthMap_STATIC_EntryType,   m_EntryType);
44         DDX_Text    (pDX, IDC_WidthMap_STATIC_EntryWidth,  m_EntryWidth);
45         DDX_Control (pDX, IDC_WidthMap_COMBO_NewEntryType, m_NewEntryType);
46         DDX_Control (pDX, IDC_WidthMap_EDIT_NewEntryWidth, m_NewEntryWidthControl);
47         DDX_Text    (pDX, IDC_WidthMap_EDIT_NewEntryWidth, m_NewEntryWidth);
48         //}}AFX_DATA_MAP
49 }
50
51
52 BEGIN_MESSAGE_MAP(CWidthPropertyPage, CPropertyPage)
53         //{{AFX_MSG_MAP(CWidthPropertyPage)
54         ON_NOTIFY(TCN_SELCHANGE, IDC_WidthMap_TAB, OnSelchangeDialogWidthTAB)
55         ON_BN_CLICKED(IDC_WidthMap_BUTTON_AddNewEntry, OnWidthMapBUTTONAddNewEntry)
56         ON_CBN_SELCHANGE(IDC_WidthMap_COMBO_NewEntryType, OnSelchangeWidthMapCOMBONewEntryType)
57         ON_BN_CLICKED(IDC_WidthMap_BUTTON_UpdateCurrentEntry, OnWidthMapBUTTONUpdateCurrentEntry)
58         //}}AFX_MSG_MAP
59 END_MESSAGE_MAP()
60
61 /////////////////////////////////////////////////////////////////////////////
62 // CWidthPropertyPage message handlers
63
64 BOOL CWidthPropertyPage::OnInitDialog() 
65 {
66         CPropertyPage::OnInitDialog();
67
68     // update the CComboBox to add the enumeration possibilities.
69     m_NewEntryType.AddString( "THIN" );
70     m_NewEntryType.AddString( "MEDIUM" );
71     m_NewEntryType.AddString( "THICK" );
72     m_NewEntryType.AddString( "VERYTHICK" );
73     m_NewEntryType.AddString( "USERDEFINED" );
74     m_NewEntryType.SetCurSel(0);
75         
76     UpdateDisplay(1);
77     UpdateData(false);
78         return TRUE;  // return TRUE unless you set the focus to a control
79                       // EXCEPTION: OCX Property Pages should return FALSE
80 }
81
82
83 void CWidthPropertyPage::UpdateDisplay(int CurrentSelectionIndex)
84 {     
85     // Update the size of the Width map
86     TCollection_AsciiString SizeMessage(myWidthMap->Size());
87     m_WidthMapSize = _T(SizeMessage.ToCString());
88
89     // clear the Tab Ctrl
90     m_TabCtrl.DeleteAllItems();
91         TC_ITEM TabCtrlItem;
92         TabCtrlItem.mask = TCIF_TEXT;
93     for(int i =1;i<=myWidthMap->Size();i++) 
94     {
95     Aspect_WidthMapEntry aWidthMapEntry = myWidthMap->Entry(i);
96
97       TCollection_AsciiString EntryNumerMessage(aWidthMapEntry.Index());
98       TabCtrlItem.pszText = (LPSTR) EntryNumerMessage.ToCString();
99           m_TabCtrl.InsertItem( aWidthMapEntry.Index(), &TabCtrlItem );
100     }
101     m_TabCtrl.SetCurSel(CurrentSelectionIndex-1);
102     // update the current Entry informations
103     Aspect_WidthMapEntry aWidthMapEntry = myWidthMap->Entry(CurrentSelectionIndex);
104     
105     // update the current entry 
106     switch (aWidthMapEntry.Type()) {
107         case Aspect_WOL_THIN        : m_EntryType   = _T("Aspect_WOL_THIN")        ; break;
108         case Aspect_WOL_MEDIUM      : m_EntryType   = _T("Aspect_WOL_MEDIUM")      ; break;
109         case Aspect_WOL_THICK       : m_EntryType   = _T("Aspect_WOL_THICK")       ; break;
110         case Aspect_WOL_VERYTHICK   : m_EntryType   = _T("Aspect_WOL_VERYTHICK")   ; break;
111         case Aspect_WOL_USERDEFINED : m_EntryType   = _T("Aspect_WOL_USERDEFINED") ; break;
112         default : cout<<" Underknown";
113     }
114
115     TCollection_AsciiString WidthMessage(aWidthMapEntry.Width());
116     m_EntryWidth = _T(WidthMessage.ToCString());
117  
118     // update the edit / new part of the 
119     // also update the edit part
120     m_NewEntryType.SetCurSel(aWidthMapEntry.Type());
121     m_NewEntryWidth = aWidthMapEntry.Width();
122     if (aWidthMapEntry.Type() == Aspect_WOL_USERDEFINED)
123       m_NewEntryWidthControl.SetReadOnly( false);
124     else
125       m_NewEntryWidthControl.SetReadOnly( true);
126
127     if (CurrentSelectionIndex == 1) // the item 1 is not editable ( in the map by default )
128       GetDlgItem(IDC_WidthMap_BUTTON_UpdateCurrentEntry)->ShowWindow(SW_HIDE);
129     else
130       GetDlgItem(IDC_WidthMap_BUTTON_UpdateCurrentEntry)->ShowWindow(SW_SHOW);
131 }
132
133 void CWidthPropertyPage::OnSelchangeDialogWidthTAB(NMHDR* pNMHDR, LRESULT* pResult) 
134 {
135     UpdateDisplay( m_TabCtrl.GetCurSel()+1);
136     UpdateData(false);
137         *pResult = 0;
138 }
139
140 void CWidthPropertyPage::OnSelchangeWidthMapCOMBONewEntryType() 
141 {
142    UpdateData(true);
143    // the Width Map entry change in the edit part
144    if (m_NewEntryType.GetCurSel() == Aspect_WOL_USERDEFINED)
145      m_NewEntryWidthControl.SetReadOnly( false);
146    else
147    {
148       m_NewEntryWidthControl.SetReadOnly( true);
149      Aspect_WidthMapEntry aTmpWidthMapEntry (99,(Aspect_WidthOfLine)m_NewEntryType.GetCurSel());
150      m_NewEntryWidth = aTmpWidthMapEntry.Width();
151    }
152    UpdateData(false);
153 }
154
155 void CWidthPropertyPage::OnWidthMapBUTTONAddNewEntry() 
156 {
157    UpdateData(true);
158    int NewEntry;
159    if (m_NewEntryType.GetCurSel() == Aspect_WOL_USERDEFINED)
160      NewEntry =myWidthMap->AddEntry(m_NewEntryWidth);
161    else
162      NewEntry =myWidthMap->AddEntry( (Aspect_WidthOfLine)m_NewEntryType.GetCurSel());
163    SetModified(true);
164    UpdateDisplay(NewEntry);
165    UpdateData(false);
166 }
167
168 void CWidthPropertyPage::OnWidthMapBUTTONUpdateCurrentEntry() 
169 {
170    UpdateData(true);
171
172    Aspect_WidthMapEntry aWidthMapEntry = myWidthMap->Entry( m_TabCtrl.GetCurSel()+1);
173
174    if (m_NewEntryType.GetCurSel() == Aspect_WOL_USERDEFINED)
175       aWidthMapEntry.SetWidth(m_NewEntryWidth );
176    else
177       aWidthMapEntry.SetType((Aspect_WidthOfLine)m_NewEntryType.GetCurSel());
178
179     myWidthMap->AddEntry(aWidthMapEntry); // in fact just update
180     SetModified(true);
181     UpdateDisplay(m_TabCtrl.GetCurSel()+1);     
182     UpdateData(false);
183 }
184
185 BOOL CWidthPropertyPage::OnApply() 
186 {
187     //AfxGetMainWnd()->SendMessage(WM_USERAPPLY_InMapProperties);
188     myViewer->SetWidthMap(myWidthMap);
189     myViewer->Update();
190         return CPropertyPage::OnApply();
191 }