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