Integration of OCCT 6.5.0 from SVN
[occt.git] / samples / mfc / standard / 08_HLR / src / Properties / MarkPropertyPage.cpp
1 // MarkPropertyPage.cpp : implementation file
2 //
3
4 #include "stdafx.h"
5
6 #include "MarkPropertyPage.h"
7
8 #include "HLRApp.h"
9
10 #include "Aspect_MarkMap.hxx"
11 #include "Aspect_MarkMapEntry.hxx"
12 #include "TColQuantity_Array1OfLength.hxx"
13 #include "TColStd_SequenceOfReal.hxx"
14 #include "TShort_Array1OfShortReal.hxx"
15 #include "TColStd_Array1OfBoolean.hxx"
16
17 #ifdef _DEBUG
18 //#define new DEBUG_NEW
19 #undef THIS_FILE
20 static char THIS_FILE[] = __FILE__;
21 #endif
22
23 /////////////////////////////////////////////////////////////////////////////
24 // CMarkPropertyPage property page
25
26 IMPLEMENT_DYNCREATE(CMarkPropertyPage, CPropertyPage)
27
28 CMarkPropertyPage::CMarkPropertyPage() : CPropertyPage(CMarkPropertyPage::IDD)
29 {
30         //{{AFX_DATA_INIT(CMarkPropertyPage)
31         m_MarkMapSize       = _T("Computing...");
32         m_CurrentEntryStyle = _T("Computing...");
33         m_CurrentEntryXValue = _T("Computing...");
34         m_CurrentEntryYValue = _T("Computing...");
35         m_CurrentEntrySValue = _T("Computing...");
36         //}}AFX_DATA_INIT
37
38
39 }
40 BOOL CMarkPropertyPage::OnInitDialog() 
41 {
42         CPropertyPage::OnInitDialog();
43
44     UpdateDisplay(1);
45
46     UpdateData(false);
47
48         return TRUE;  // return TRUE unless you set the focus to a control
49                       // EXCEPTION: OCX Property Pages should return FALSE
50 }
51
52 CMarkPropertyPage::~CMarkPropertyPage()
53 {
54 }
55
56 void CMarkPropertyPage::DoDataExchange(CDataExchange* pDX)
57 {
58         CPropertyPage::DoDataExchange(pDX);
59         //{{AFX_DATA_MAP(CMarkPropertyPage)
60         DDX_Control(pDX, IDC_MarkMap_TAB, m_TabCtrl);
61         DDX_Text(pDX, IDC_MarkMap_STATIC_Size, m_MarkMapSize);
62         DDX_Text(pDX, IDC_MarkMap_STATIC_CurrentEntryStyle, m_CurrentEntryStyle);
63         DDX_Text(pDX, IDC_MarkMap_STATIC_CurrentEntryXValue, m_CurrentEntryXValue);
64         DDX_Text(pDX, IDC_MarkMap_STATIC_CurrentEntryYValue, m_CurrentEntryYValue);
65         DDX_Text(pDX, IDC_MarkMap_STATIC_CurrentEntrySValue, m_CurrentEntrySValue);
66
67         //}}AFX_DATA_MAP
68 }
69
70
71 BEGIN_MESSAGE_MAP(CMarkPropertyPage, CPropertyPage)
72         //{{AFX_MSG_MAP(CMarkPropertyPage)
73         ON_NOTIFY(TCN_SELCHANGE, IDC_MarkMap_TAB, OnSelchangeMarkMapTAB)
74         //}}AFX_MSG_MAP
75 END_MESSAGE_MAP()
76
77 /////////////////////////////////////////////////////////////////////////////
78 // CMarkPropertyPage message handlers
79 void CMarkPropertyPage::UpdateDisplay(int CurrentSelectionIndex)
80 {
81     TCollection_AsciiString SizeMessage(myMarkMap->Size());
82     m_MarkMapSize = _T(SizeMessage.ToCString());
83         
84     m_TabCtrl.DeleteAllItems();
85
86         TC_ITEM TabCtrlItem;
87         TabCtrlItem.mask = TCIF_TEXT;
88
89     for(int i =1;i<=myMarkMap->Size();i++) 
90     {
91       Aspect_MarkMapEntry aMarkMapEntry = myMarkMap->Entry(i);
92       TCollection_AsciiString EntryNumerMessage(aMarkMapEntry.Index());
93       TabCtrlItem.pszText = (LPSTR) EntryNumerMessage.ToCString();
94           m_TabCtrl.InsertItem( aMarkMapEntry.Index(), &TabCtrlItem );
95     }
96     m_TabCtrl.SetCurSel(CurrentSelectionIndex-1);
97
98     // update The Current Selected entry
99     Aspect_MarkMapEntry aMarkMapEntry = myMarkMap->Entry(CurrentSelectionIndex);
100     if (aMarkMapEntry. IsAllocated () ) 
101       {
102         Aspect_MarkerStyle aMarkerStyle =  aMarkMapEntry.Style() ;
103         switch (aMarkerStyle.Type())  {
104           case Aspect_TOM_POINT       : m_CurrentEntryStyle = _T("Aspect_TOM_POINT");       break;
105           case Aspect_TOM_PLUS        : m_CurrentEntryStyle = _T("Aspect_TOM_PLUS");        break;
106           case Aspect_TOM_STAR        : m_CurrentEntryStyle = _T("Aspect_TOM_STAR");        break;
107           case Aspect_TOM_O           : m_CurrentEntryStyle = _T("Aspect_TOM_O");           break;
108           case Aspect_TOM_X           : m_CurrentEntryStyle = _T("Aspect_TOM_X");           break;
109           case Aspect_TOM_O_POINT     : m_CurrentEntryStyle = _T("Aspect_TOM_O_POINT");     break;
110           case Aspect_TOM_O_PLUS      : m_CurrentEntryStyle = _T("Aspect_TOM_O_PLUS");      break;
111           case Aspect_TOM_O_STAR      : m_CurrentEntryStyle = _T("Aspect_TOM_O_STAR");      break;
112           case Aspect_TOM_O_X         : m_CurrentEntryStyle = _T("Aspect_TOM_O_X");         break;
113           case Aspect_TOM_BALL        : m_CurrentEntryStyle = _T("Aspect_TOM_BALL");        break;
114           case Aspect_TOM_RING1       : m_CurrentEntryStyle = _T("Aspect_TOM_RING1");       break;
115           case Aspect_TOM_RING2       : m_CurrentEntryStyle = _T("Aspect_TOM_RING2");       break;
116           case Aspect_TOM_RING3       : m_CurrentEntryStyle = _T("Aspect_TOM_RING3");       break;
117           case Aspect_TOM_USERDEFINED : m_CurrentEntryStyle = _T("Aspect_TOM_USERDEFINED"); break;
118           default : m_CurrentEntryStyle = _T("Underknown");
119         }
120
121         cout<<" aMarkerStyle  Length: "<<aMarkerStyle.Length()<<endl;
122
123         const TShort_Array1OfShortReal& aMarkerStyleXValues = aMarkerStyle.XValues() ;
124         const TShort_Array1OfShortReal& aMarkerStyleYValues= aMarkerStyle.YValues() ;
125         const TColStd_Array1OfBoolean&  aMarkerStyleSValues= aMarkerStyle.SValues() ;
126
127         TCollection_AsciiString MessageX =BuildValuesAscii(aMarkerStyleXValues);
128         TCollection_AsciiString MessageY =BuildValuesAscii(aMarkerStyleYValues);
129         TCollection_AsciiString MessageS =BuildValuesAscii(aMarkerStyleSValues);
130
131         m_CurrentEntryXValue = _T(MessageX.ToCString());
132             m_CurrentEntryYValue = _T(MessageY.ToCString());
133             m_CurrentEntrySValue = _T(MessageS.ToCString());
134
135       }
136       else 
137       {
138             m_CurrentEntryStyle = _T("Not Allocated");
139             m_CurrentEntryXValue = _T("");
140             m_CurrentEntryYValue = _T("");
141             m_CurrentEntrySValue = _T("");
142         GetDlgItem(IDC_FontMap_BUTTON_UpdateCurrent)->ShowWindow(SW_HIDE);
143       }
144 }
145
146 void CMarkPropertyPage::OnSelchangeMarkMapTAB(NMHDR* pNMHDR, LRESULT* pResult) 
147 {
148     UpdateDisplay(m_TabCtrl.GetCurSel()+1);     
149     UpdateData(false);
150         *pResult = 0;
151 }
152
153 BOOL CMarkPropertyPage::OnApply() 
154 {
155 //    myViewer->SetMarkMap(myMarkMap);
156 //    myViewer->Update();
157         return CPropertyPage::OnApply();
158 }
159
160 TCollection_AsciiString CMarkPropertyPage::BuildValuesAscii(const TShort_Array1OfShortReal& anArray)
161 {
162   TCollection_AsciiString Message;
163   for(int i=1;i<=anArray.Length();i++)
164    {
165      Message += anArray.Value(i);
166      Message += "\t";
167    }
168   return Message;
169 }
170
171 TCollection_AsciiString CMarkPropertyPage::BuildValuesAscii(const TColStd_Array1OfBoolean& anArray)
172 {
173   TCollection_AsciiString Message;
174   for(int i=1;i<=anArray.Length();i++)
175    {
176      if (anArray(i)) Message += "True"; else Message += "False";
177      Message += "\t";    
178    }
179   return Message;
180 }