1 // TypePropertyPage.cpp : implementation file
6 #include "TypePropertyPage.h"
8 #include "Aspect_TypeMap.hxx"
9 #include "Aspect_TypeMapEntry.hxx"
10 #include "TColQuantity_Array1OfLength.hxx"
11 #include "TColStd_SequenceOfReal.hxx"
13 /////////////////////////////////////////////////////////////////////////////
14 // CTypePropertyPage property page
16 IMPLEMENT_DYNCREATE(CTypePropertyPage, CPropertyPage)
18 CTypePropertyPage::CTypePropertyPage() : CPropertyPage(CTypePropertyPage::IDD)
20 //{{AFX_DATA_INIT(CTypePropertyPage)
21 m_TypeMapSize = _T("Computing...");
22 m_CurrentEntryStyle = _T("Computing...");
23 m_CurrentEntryValue = _T("Computing...");
24 m_NewEntryValue = _T("");
29 BOOL CTypePropertyPage::OnInitDialog()
31 CPropertyPage::OnInitDialog();
33 // TODO: Add extra initialization here
35 m_NewEntryControl.AddString("SOLID");
36 m_NewEntryControl.AddString("DASH");
37 m_NewEntryControl.AddString("DOT");
38 m_NewEntryControl.AddString("DOTDASH");
39 m_NewEntryControl.AddString("USERDEFINED");
40 m_NewEntryControl.SetCurSel(1);
46 return TRUE; // return TRUE unless you set the focus to a control
47 // EXCEPTION: OCX Property Pages should return FALSE
50 CTypePropertyPage::~CTypePropertyPage()
54 void CTypePropertyPage::DoDataExchange(CDataExchange* pDX)
56 CPropertyPage::DoDataExchange(pDX);
57 //{{AFX_DATA_MAP(CTypePropertyPage)
58 DDX_Control(pDX, IDC_TypeMap_TAB, m_TabCtrl);
59 DDX_Control(pDX, IDC_TypeMap_COMBO_NewEntryStyle, m_NewEntryControl);
60 DDX_Control(pDX, IDC_TypeMap_EDIT_NewEntryValue, m_NewEntryValueControl);
61 DDX_Text(pDX, IDC_TypeMap_STATIC_Size, m_TypeMapSize);
62 DDX_Text(pDX, IDC_TypeMap_STATIC_CurrentEntryStyle, m_CurrentEntryStyle);
63 DDX_Text(pDX, IDC_TypeMap_STATIC_CurrentEntryValue, m_CurrentEntryValue);
64 DDX_Text(pDX, IDC_TypeMap_EDIT_NewEntryValue, m_NewEntryValue);
70 BEGIN_MESSAGE_MAP(CTypePropertyPage, CPropertyPage)
71 //{{AFX_MSG_MAP(CTypePropertyPage)
72 ON_BN_CLICKED(IDC_FontMap_BUTTON_NewEntry, OnFontMapBUTTONNewEntry)
73 ON_BN_CLICKED(IDC_FontMap_BUTTON_UpdateCurrent, OnFontMapBUTTONUpdateCurrent)
74 ON_EN_CHANGE(IDC_TypeMap_EDIT_NewEntryValue, OnChangeTypeMapEDITNewEntryValue)
75 ON_NOTIFY(TCN_SELCHANGE, IDC_TypeMap_TAB, OnSelchangeTypeMapTAB)
76 ON_CBN_SELCHANGE(IDC_TypeMap_COMBO_NewEntryStyle, OnSelchangeTypeMapCOMBONewEntryStyle)
80 /////////////////////////////////////////////////////////////////////////////
81 // CTypePropertyPage message handlers
82 void CTypePropertyPage::UpdateDisplay(int CurrentSelectionIndex)
84 TCollection_AsciiString SizeMessage(myTypeMap->Size());
85 m_TypeMapSize = _T(SizeMessage.ToCString());
87 m_TabCtrl.DeleteAllItems();
90 TabCtrlItem.mask = TCIF_TEXT;
92 for(int i =1;i<=myTypeMap->Size();i++)
94 Aspect_TypeMapEntry aTypeMapEntry = myTypeMap->Entry(i);
95 TCollection_AsciiString EntryNumerMessage(aTypeMapEntry.Index());
96 TabCtrlItem.pszText = (LPSTR) EntryNumerMessage.ToCString();
97 m_TabCtrl.InsertItem( aTypeMapEntry.Index(), &TabCtrlItem );
99 m_TabCtrl.SetCurSel(CurrentSelectionIndex-1);
101 // update The Current Selected entry
102 Aspect_TypeMapEntry aTypeMapEntry = myTypeMap->Entry(CurrentSelectionIndex);
103 if (aTypeMapEntry. IsAllocated () )
105 Aspect_LineStyle TypeMapEntryType = aTypeMapEntry.Type() ;
107 switch (TypeMapEntryType.Style()) {
108 case Aspect_TOL_SOLID : m_CurrentEntryStyle = _T("SOLID"); break;
109 case Aspect_TOL_DASH : m_CurrentEntryStyle = _T("DASH"); break;
110 case Aspect_TOL_DOT : m_CurrentEntryStyle = _T("DOT"); break;
111 case Aspect_TOL_DOTDASH : m_CurrentEntryStyle = _T("DOTDASH"); break;
112 case Aspect_TOL_USERDEFINED : m_CurrentEntryStyle = _T("USERDEFINED"); break;
113 default : m_CurrentEntryStyle = _T("Underknown");
115 int NbValue = TypeMapEntryType.Length();
116 TCollection_AsciiString Message = BuildValuesAscii(TypeMapEntryType.Values());
118 m_CurrentEntryValue = _T(Message.ToCString());
120 m_NewEntryControl.SetCurSel(TypeMapEntryType.Style());
121 m_NewEntryValue = _T(Message.ToCString());
122 if (TypeMapEntryType.Style() == Aspect_TOL_USERDEFINED)
123 m_NewEntryValueControl.SetReadOnly( false );
125 m_NewEntryValueControl.SetReadOnly( true );
129 m_CurrentEntryStyle = _T("Not Allocated");
130 m_CurrentEntryValue = _T("");
131 m_NewEntryValue = _T("No value");
132 GetDlgItem(IDC_FontMap_BUTTON_UpdateCurrent)->ShowWindow(SW_HIDE);
136 void CTypePropertyPage::OnSelchangeTypeMapTAB(NMHDR* pNMHDR, LRESULT* pResult)
138 UpdateDisplay(m_TabCtrl.GetCurSel()+1);
142 void CTypePropertyPage::OnSelchangeTypeMapCOMBONewEntryStyle()
145 // the Type Map entry change in the edit part
146 if (m_NewEntryControl.GetCurSel() == Aspect_TOL_USERDEFINED)
147 m_NewEntryValueControl.SetReadOnly( false );
150 m_NewEntryValueControl.SetReadOnly( true );
152 // create a dummy map to extract the default values
153 Aspect_TypeMapEntry aTypeMapEntry(99,(Aspect_TypeOfLine)m_NewEntryControl.GetCurSel());
154 Aspect_LineStyle TypeMapEntryType = aTypeMapEntry.Type() ;
155 TCollection_AsciiString Message = BuildValuesAscii(TypeMapEntryType.Values());
157 m_NewEntryValue = _T(Message.ToCString());
162 void CTypePropertyPage::OnChangeTypeMapEDITNewEntryValue()
165 Handle(TColQuantity_HArray1OfLength) anArray;
166 Standard_Boolean IsDone = ExtractValues(TCollection_AsciiString((char *)(LPCSTR)m_NewEntryValue),anArray);
169 GetDlgItem(IDC_FontMap_BUTTON_UpdateCurrent)->ShowWindow(SW_SHOW);
170 GetDlgItem(IDC_FontMap_BUTTON_NewEntry)->ShowWindow(SW_SHOW);
174 GetDlgItem(IDC_FontMap_BUTTON_UpdateCurrent)->ShowWindow(SW_HIDE);
175 GetDlgItem(IDC_FontMap_BUTTON_NewEntry)->ShowWindow(SW_HIDE);
179 void CTypePropertyPage::OnFontMapBUTTONNewEntry()
184 if (m_NewEntryControl.GetCurSel() == Aspect_TOL_USERDEFINED)
186 Handle(TColQuantity_HArray1OfLength) anArray;
187 if (ExtractValues(TCollection_AsciiString((char *)(LPCSTR)m_NewEntryValue),anArray))
189 Aspect_LineStyle aLineStyle(anArray->Array1());
190 NewEntry = myTypeMap->AddEntry( aLineStyle );
192 else Standard_Failure::Raise(" The String is not Valid ");
196 Aspect_LineStyle aLineStyle((Aspect_TypeOfLine)m_NewEntryControl.GetCurSel());
197 NewEntry = myTypeMap->AddEntry( aLineStyle );
201 UpdateDisplay(NewEntry);
205 void CTypePropertyPage::OnFontMapBUTTONUpdateCurrent()
208 Aspect_TypeMapEntry aTypeMapEntry = myTypeMap->Entry( m_TabCtrl.GetCurSel()+1);
210 if (m_NewEntryControl.GetCurSel() == Aspect_TOL_USERDEFINED)
212 Handle(TColQuantity_HArray1OfLength) anArray;
213 if (ExtractValues(TCollection_AsciiString((char *)(LPCSTR)m_NewEntryValue),anArray))
215 Aspect_LineStyle aLineStyle(anArray->Array1());
216 aTypeMapEntry.SetType( aLineStyle );
218 else Standard_Failure::Raise(" The String is not Valid ");
222 Aspect_LineStyle aLineStyle((Aspect_TypeOfLine)m_NewEntryControl.GetCurSel());
223 aTypeMapEntry.SetType( aLineStyle );
226 myTypeMap->AddEntry(aTypeMapEntry); // in fact just update
229 UpdateDisplay(m_TabCtrl.GetCurSel()+1);
233 BOOL CTypePropertyPage::OnApply()
235 myViewer->SetTypeMap(myTypeMap);
237 return CPropertyPage::OnApply();
240 Standard_Boolean CTypePropertyPage::ExtractValues(TCollection_AsciiString aMessage,
241 Handle(TColQuantity_HArray1OfLength)& anArray) // out
243 TColStd_SequenceOfReal aSequenceOfReal;
244 Standard_Integer CurrentStartValue=1;
245 bool NotFinish = true;
248 CurrentStartValue = aMessage.SearchFromEnd(";");
249 if ( CurrentStartValue == aMessage.Length()) return Standard_False;
250 if (CurrentStartValue != -1)
252 TCollection_AsciiString aNewMessage = aMessage.Split(CurrentStartValue);
253 aMessage.Remove(aMessage.Length());
254 if (aNewMessage.IsRealValue())
255 aSequenceOfReal.Append(aNewMessage.RealValue());
256 else return Standard_False;
260 if (aMessage.IsRealValue())
261 aSequenceOfReal.Append(aMessage.RealValue());
262 else return Standard_False;
267 anArray = new TColQuantity_HArray1OfLength(1,aSequenceOfReal.Length());
268 for (int i=1;i<=aSequenceOfReal.Length();i++)
269 anArray->SetValue(i,aSequenceOfReal(aSequenceOfReal.Length()-i+1));
271 return Standard_True;
274 TCollection_AsciiString CTypePropertyPage::BuildValuesAscii(const TColQuantity_Array1OfLength& anArray)
276 TCollection_AsciiString Message;
277 int NbValue = anArray.Length();
278 for (int j=1;j<NbValue;j++)
280 Message += anArray(j);
283 Quantity_Length Length = anArray(NbValue);
284 if (Length > Precision::Confusion()) Message += Length;
285 else Message += "No value";