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