1 // TypePropertyPage.cpp : implementation file
6 #include "TypePropertyPage.h"
11 //#define new DEBUG_NEW
13 static char THIS_FILE[] = __FILE__;
16 #include "Aspect_TypeMap.hxx"
17 #include "Aspect_TypeMapEntry.hxx"
18 #include "TColQuantity_Array1OfLength.hxx"
19 #include "TColStd_SequenceOfReal.hxx"
21 /////////////////////////////////////////////////////////////////////////////
22 // CTypePropertyPage property page
24 IMPLEMENT_DYNCREATE(CTypePropertyPage, CPropertyPage)
26 CTypePropertyPage::CTypePropertyPage() : CPropertyPage(CTypePropertyPage::IDD)
28 //{{AFX_DATA_INIT(CTypePropertyPage)
29 m_TypeMapSize = _T("Computing...");
30 m_CurrentEntryStyle = _T("Computing...");
31 m_CurrentEntryValue = _T("Computing...");
32 m_NewEntryValue = _T("");
36 BOOL CTypePropertyPage::OnInitDialog()
38 CPropertyPage::OnInitDialog();
40 // TODO: Add extra initialization here
42 m_NewEntryControl.AddString("SOLID");
43 m_NewEntryControl.AddString("DASH");
44 m_NewEntryControl.AddString("DOT");
45 m_NewEntryControl.AddString("DOTDASH");
46 m_NewEntryControl.AddString("USERDEFINED");
47 m_NewEntryControl.SetCurSel(1);
53 return TRUE; // return TRUE unless you set the focus to a control
54 // EXCEPTION: OCX Property Pages should return FALSE
57 CTypePropertyPage::~CTypePropertyPage()
61 void CTypePropertyPage::DoDataExchange(CDataExchange* pDX)
63 CPropertyPage::DoDataExchange(pDX);
64 //{{AFX_DATA_MAP(CTypePropertyPage)
65 DDX_Control(pDX, IDC_TypeMap_TAB, m_TabCtrl);
66 DDX_Control(pDX, IDC_TypeMap_COMBO_NewEntryStyle, m_NewEntryControl);
67 DDX_Control(pDX, IDC_TypeMap_EDIT_NewEntryValue, m_NewEntryValueControl);
68 DDX_Text(pDX, IDC_TypeMap_STATIC_Size, m_TypeMapSize);
69 DDX_Text(pDX, IDC_TypeMap_STATIC_CurrentEntryStyle, m_CurrentEntryStyle);
70 DDX_Text(pDX, IDC_TypeMap_STATIC_CurrentEntryValue, m_CurrentEntryValue);
71 DDX_Text(pDX, IDC_TypeMap_EDIT_NewEntryValue, m_NewEntryValue);
77 BEGIN_MESSAGE_MAP(CTypePropertyPage, CPropertyPage)
78 //{{AFX_MSG_MAP(CTypePropertyPage)
79 ON_BN_CLICKED(IDC_FontMap_BUTTON_NewEntry, OnFontMapBUTTONNewEntry)
80 ON_BN_CLICKED(IDC_FontMap_BUTTON_UpdateCurrent, OnFontMapBUTTONUpdateCurrent)
81 ON_EN_CHANGE(IDC_TypeMap_EDIT_NewEntryValue, OnChangeTypeMapEDITNewEntryValue)
82 ON_NOTIFY(TCN_SELCHANGE, IDC_TypeMap_TAB, OnSelchangeTypeMapTAB)
83 ON_CBN_SELCHANGE(IDC_TypeMap_COMBO_NewEntryStyle, OnSelchangeTypeMapCOMBONewEntryStyle)
87 /////////////////////////////////////////////////////////////////////////////
88 // CTypePropertyPage message handlers
89 void CTypePropertyPage::UpdateDisplay(int CurrentSelectionIndex)
91 TCollection_AsciiString SizeMessage(myTypeMap->Size());
92 m_TypeMapSize = _T(SizeMessage.ToCString());
94 m_TabCtrl.DeleteAllItems();
97 TabCtrlItem.mask = TCIF_TEXT;
99 for(int i =1;i<=myTypeMap->Size();i++)
101 Aspect_TypeMapEntry aTypeMapEntry = myTypeMap->Entry(i);
102 TCollection_AsciiString EntryNumerMessage(aTypeMapEntry.Index());
103 TabCtrlItem.pszText = (LPSTR) EntryNumerMessage.ToCString();
104 m_TabCtrl.InsertItem( aTypeMapEntry.Index(), &TabCtrlItem );
106 m_TabCtrl.SetCurSel(CurrentSelectionIndex-1);
108 // update The Current Selected entry
109 Aspect_TypeMapEntry aTypeMapEntry = myTypeMap->Entry(CurrentSelectionIndex);
110 if (aTypeMapEntry. IsAllocated () )
112 Aspect_LineStyle TypeMapEntryType = aTypeMapEntry.Type() ;
114 switch (TypeMapEntryType.Style()) {
115 case Aspect_TOL_SOLID : m_CurrentEntryStyle = _T("SOLID"); break;
116 case Aspect_TOL_DASH : m_CurrentEntryStyle = _T("DASH"); break;
117 case Aspect_TOL_DOT : m_CurrentEntryStyle = _T("DOT"); break;
118 case Aspect_TOL_DOTDASH : m_CurrentEntryStyle = _T("DOTDASH"); break;
119 case Aspect_TOL_USERDEFINED : m_CurrentEntryStyle = _T("USERDEFINED"); break;
120 default : m_CurrentEntryStyle = _T("Underknown");
122 int NbValue = TypeMapEntryType.Length();
123 TCollection_AsciiString Message = BuildValuesAscii(TypeMapEntryType.Values());
125 m_CurrentEntryValue = _T(Message.ToCString());
127 m_NewEntryControl.SetCurSel(TypeMapEntryType.Style());
128 m_NewEntryValue = _T(Message.ToCString());
129 if (TypeMapEntryType.Style() == Aspect_TOL_USERDEFINED)
130 m_NewEntryValueControl.SetReadOnly( false );
132 m_NewEntryValueControl.SetReadOnly( true );
136 m_CurrentEntryStyle = _T("Not Allocated");
137 m_CurrentEntryValue = _T("");
138 m_NewEntryValue = _T("No value");
139 GetDlgItem(IDC_FontMap_BUTTON_UpdateCurrent)->ShowWindow(SW_HIDE);
143 void CTypePropertyPage::OnSelchangeTypeMapTAB(NMHDR* pNMHDR, LRESULT* pResult)
145 UpdateDisplay(m_TabCtrl.GetCurSel()+1);
149 void CTypePropertyPage::OnSelchangeTypeMapCOMBONewEntryStyle()
152 // the Type Map entry change in the edit part
153 if (m_NewEntryControl.GetCurSel() == Aspect_TOL_USERDEFINED)
154 m_NewEntryValueControl.SetReadOnly( false );
157 m_NewEntryValueControl.SetReadOnly( true );
159 // create a dummy map to extract the default values
160 Aspect_TypeMapEntry aTypeMapEntry(99,(Aspect_TypeOfLine)m_NewEntryControl.GetCurSel());
161 Aspect_LineStyle TypeMapEntryType = aTypeMapEntry.Type() ;
162 TCollection_AsciiString Message = BuildValuesAscii(TypeMapEntryType.Values());
164 m_NewEntryValue = _T(Message.ToCString());
169 void CTypePropertyPage::OnChangeTypeMapEDITNewEntryValue()
172 Handle(TColQuantity_HArray1OfLength) anArray;
173 Standard_Boolean IsDone = ExtractValues(TCollection_AsciiString((char *)(LPCSTR)m_NewEntryValue),anArray);
176 GetDlgItem(IDC_FontMap_BUTTON_UpdateCurrent)->ShowWindow(SW_SHOW);
177 GetDlgItem(IDC_FontMap_BUTTON_NewEntry)->ShowWindow(SW_SHOW);
181 GetDlgItem(IDC_FontMap_BUTTON_UpdateCurrent)->ShowWindow(SW_HIDE);
182 GetDlgItem(IDC_FontMap_BUTTON_NewEntry)->ShowWindow(SW_HIDE);
186 void CTypePropertyPage::OnFontMapBUTTONNewEntry()
191 if (m_NewEntryControl.GetCurSel() == Aspect_TOL_USERDEFINED)
193 Handle(TColQuantity_HArray1OfLength) anArray;
194 if (ExtractValues(TCollection_AsciiString((char *)(LPCSTR)m_NewEntryValue),anArray))
196 Aspect_LineStyle aLineStyle(anArray->Array1());
197 NewEntry = myTypeMap->AddEntry( aLineStyle );
199 else Standard_Failure::Raise(" The String is not Valid ");
203 Aspect_LineStyle aLineStyle((Aspect_TypeOfLine)m_NewEntryControl.GetCurSel());
204 NewEntry = myTypeMap->AddEntry( aLineStyle );
208 UpdateDisplay(NewEntry);
212 void CTypePropertyPage::OnFontMapBUTTONUpdateCurrent()
215 Aspect_TypeMapEntry aTypeMapEntry = myTypeMap->Entry( m_TabCtrl.GetCurSel()+1);
217 if (m_NewEntryControl.GetCurSel() == Aspect_TOL_USERDEFINED)
219 Handle(TColQuantity_HArray1OfLength) anArray;
220 if (ExtractValues(TCollection_AsciiString((char *)(LPCSTR)m_NewEntryValue),anArray))
222 Aspect_LineStyle aLineStyle(anArray->Array1());
223 aTypeMapEntry.SetType( aLineStyle );
225 else Standard_Failure::Raise(" The String is not Valid ");
229 Aspect_LineStyle aLineStyle((Aspect_TypeOfLine)m_NewEntryControl.GetCurSel());
230 aTypeMapEntry.SetType( aLineStyle );
233 myTypeMap->AddEntry(aTypeMapEntry); // in fact just update
236 UpdateDisplay(m_TabCtrl.GetCurSel()+1);
240 BOOL CTypePropertyPage::OnApply()
242 myViewer->SetTypeMap(myTypeMap);
244 return CPropertyPage::OnApply();
247 Standard_Boolean CTypePropertyPage::ExtractValues(TCollection_AsciiString aMessage,
248 Handle(TColQuantity_HArray1OfLength)& anArray) // out
250 TColStd_SequenceOfReal aSequenceOfReal;
251 Standard_Integer CurrentStartValue=1;
252 bool NotFinish = true;
255 CurrentStartValue = aMessage.SearchFromEnd(";");
256 if ( CurrentStartValue == aMessage.Length()) return Standard_False;
257 if (CurrentStartValue != -1)
259 TCollection_AsciiString aNewMessage = aMessage.Split(CurrentStartValue);
260 aMessage.Remove(aMessage.Length());
261 if (aNewMessage.IsRealValue())
262 aSequenceOfReal.Append(aNewMessage.RealValue());
263 else return Standard_False;
267 if (aMessage.IsRealValue())
268 aSequenceOfReal.Append(aMessage.RealValue());
269 else return Standard_False;
274 anArray = new TColQuantity_HArray1OfLength(1,aSequenceOfReal.Length());
275 for (int i=1;i<=aSequenceOfReal.Length();i++)
276 anArray->SetValue(i,aSequenceOfReal(aSequenceOfReal.Length()-i+1));
278 return Standard_True;
281 TCollection_AsciiString CTypePropertyPage::BuildValuesAscii(const TColQuantity_Array1OfLength& anArray)
283 TCollection_AsciiString Message;
284 int NbValue = anArray.Length();
285 for (int j=1;j<NbValue;j++)
287 Message += anArray(j);
290 Quantity_Length Length = anArray(NbValue);
291 if (Length > Precision::Confusion()) Message += Length;
292 else Message += "No value";