00001
00002
00003
00004 #include "stdafx.h"
00005 #include "SelConf.h"
00006 #include "Any.h"
00007 #include "FCO.h"
00008 #include ".\selconf.h"
00009
00010 #ifdef _DEBUG
00011 #define new DEBUG_NEW
00012 #undef THIS_FILE
00013 static char THIS_FILE[] = __FILE__;
00014 #endif
00015
00017
00018 int SelConf::m_lastId = 0;
00019 int SelConf::m_sortOrder = 1;
00020
00021 SelConf::SelConf( unsigned int no_of_configs, CWnd* pParent )
00022 : CDialog(SelConf::IDD, pParent),
00023 m_numberOfConfigs( no_of_configs)
00024 {
00025
00026
00027
00028 }
00029
00030 SelConf::~SelConf()
00031 {
00032 POSITION pos = m_entries.GetHeadPosition();
00033 while (pos) {
00034 delete m_entries.GetNext(pos);
00035 }
00036 m_entries.RemoveAll();
00037 }
00038
00039 void SelConf::DoDataExchange(CDataExchange* pDX)
00040 {
00041 CDialog::DoDataExchange(pDX);
00042
00043 DDX_Control(pDX, IDC_COMBO1, m_config);
00044
00045 }
00046
00047
00048 BEGIN_MESSAGE_MAP(SelConf, CDialog)
00049
00050 ON_CBN_EDITUPDATE(IDC_COMBO1, OnEditupdateCombo1)
00051 ON_CBN_CLOSEUP(IDC_COMBO1, OnCloseupCombo1)
00052 ON_BN_CLICKED(IDC_DESELECTALLBTN, OnBnClickedDeselectallbtn)
00053
00054 ON_BN_CLICKED(IDC_SELECTALLBTN, OnBnClickedSelectallbtn)
00055 END_MESSAGE_MAP()
00056
00058
00059
00060 void SelConf::addConfigs( std::vector< std::string >& configs)
00061 {
00062 ASSERT( configs.size() == m_numberOfConfigs);
00063 m_configStrings = configs;
00064 }
00065
00066 int SelConf::findAmongConfigs( std::string& config_name)
00067 {
00068 for( unsigned int i = 0; i < m_configStrings.size(); ++i)
00069 {
00070 if ( m_configStrings[i] == config_name)
00071 return (int) i;
00072 }
00073 return -1;
00074 }
00075
00076
00077 int SelConf::addEntry( const CString& role, char kind, int clique, bool in, const CString& repr, const void * ptr)
00078 {
00079 entry *f = new entry;
00080 f->id = m_lastId;
00081 f->s = role;
00082 f->kind = kind;
00083 f->cliqueId = clique;
00084 f->val = in;
00085 f->resp = repr;
00086 f->ptr = ptr;
00087
00088 m_entries.AddTail( f);
00089 return m_lastId++;
00090 }
00091
00092 bool SelConf::getEntry( int row, CString& role, bool & in, CString& repr, const void * &ptr)
00093 {
00094 bool retval = false;
00095
00096 POSITION pos = m_entries.GetHeadPosition();
00097 while (pos) {
00098 entry *e = m_entries.GetNext(pos);
00099 if (e->id == row) {
00100 role = e->s;
00101 in = e->val;
00102 ptr = e->ptr;
00103 repr = e->resp;
00104 retval = true;
00105 }
00106 }
00107 return retval;
00108
00109 }
00110
00111 BOOL SelConf::OnInitDialog()
00112 {
00113 CDialog::OnInitDialog();
00114
00115 CRect loc;
00116 this->GetClientRect(&loc);
00117 loc.DeflateRect(15, 50, 15, 50);
00118
00119 m_table.Create(WS_CHILD|WS_VISIBLE|WS_BORDER|LVS_REPORT|LVS_SINGLESEL, loc, this, 1);
00120 m_table.m_parent = this;
00121
00122 fillUpTable();
00123
00124 unsigned int len = m_configStrings.size();
00125 for( unsigned int i = 0; i < len; ++i)
00126 {
00127 m_config.AddString( m_configStrings[i].c_str());
00128 m_config.SetItemData( i, i);
00129 }
00130
00131 int nCount = m_config.GetCount();
00132 if (nCount > 0)
00133 {
00134
00135 m_config.SelectString( -1, "Default");
00136 m_currSelConfigStr = "Default";
00137 }
00138
00139
00140 return TRUE;
00141
00142 }
00143
00144 void SelConf::OnOK()
00145 {
00146
00147 if ( m_currSelConfigStr.empty() || m_currSelConfigStr.find_first_not_of(' ') == std::string::npos )
00148 {
00149 AfxMessageBox( "Please select a valid configuration name");
00150 return;
00151 }
00152
00153 getDataFromTable();
00154 saveUserPref( false);
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164 CDialog::OnOK();
00165 }
00166
00167 void SelConf::OnCloseupCombo1()
00168 {
00169
00170 int sel = m_config.GetCurSel();
00171 if ( sel != CB_ERR && sel < m_config.GetCount() && sel >= 0)
00172 {
00173 if( m_currSelConfigStr == m_configStrings[sel])
00174 return;
00175 else
00176 {
00177 getDataFromTable();
00178 saveUserPref( true);
00179 m_currSelConfigStr = m_configStrings[sel];
00180 refreshTable();
00181 }
00182 }
00183 }
00184
00185 void SelConf::OnEditupdateCombo1()
00186 {
00187
00188 CString temp_text;
00189 m_config.GetWindowText( temp_text);
00190 m_currSelConfigStr = (LPCTSTR) temp_text;
00191 }
00192
00193
00194 void SelConf::refreshTable()
00195 {
00196 std::string regPath = "/Configs/" + m_currSelConfigStr, regVal;
00197 int k = findAmongConfigs (m_currSelConfigStr);
00198 if ( k != -1)
00199 {
00200 m_table.DeleteAllItems();
00201
00202 POSITION pos = m_entries.GetHeadPosition();
00203 while (pos)
00204 {
00205 entry *e = m_entries.GetNext(pos);
00206 Any * any_ptr = const_cast<Any *>( static_cast<const Any *>(e->ptr));
00207 if ( any_ptr)
00208 {
00209 regVal = any_ptr->getMyRegistry()->getValueByPath( regPath);
00210 if ( regVal == "false")
00211 e->val = false;
00212 else
00213 e->val = true;
00214 }
00215
00216
00217 }
00218 fillUpTable();
00219 UpdateWindow();
00220 }
00221 }
00222
00223
00224
00225
00226
00227 void SelConf::saveUserPref( bool check)
00228 {
00229 int k = findAmongConfigs( m_currSelConfigStr);
00230 if ( check && k == -1) return;
00231
00232 std::string regVal, regPath = "/Configs/" + m_currSelConfigStr;
00233 POSITION pos = m_entries.GetHeadPosition();
00234 while (pos)
00235 {
00236 entry *e = m_entries.GetNext(pos);
00237 Any * any_ptr = const_cast<Any *>( static_cast<const Any *>(e->ptr));
00238 if ( any_ptr)
00239 {
00240 if ( !check)
00241 {
00242 any_ptr->toBeEx( e->val);
00243 FCO * fco_ptr = dynamic_cast<FCO*>( any_ptr);
00244 if( any_ptr->isFCO() && fco_ptr)
00245 {
00246
00247 fco_ptr->setExtedAnc( fco_ptr->findRspPtr( (LPCTSTR) e->resp));
00248 }
00249 }
00250 if (e->val) regVal = "true"; else regVal = "false";
00251 any_ptr->getMyRegistry()->setValueByPath( regPath, regVal);
00252 any_ptr->getMyRegistry()->setValueByPath( regPath + "/Resp", (LPCTSTR) e->resp);
00253 }
00254 }
00255 }
00256
00257 void SelConf::fillUpTable()
00258 {
00259 POSITION pos = m_entries.GetHeadPosition();
00260 while (pos) {
00261 entry *e = m_entries.GetNext(pos);
00262 m_table.addRow(e->id, e->s, e->kind, e->cliqueId, e->val, e->resp);
00263 }
00264 }
00265
00266 void SelConf::getDataFromTable()
00267 {
00268 POSITION pos = m_entries.GetHeadPosition();
00269 while (pos) {
00270 entry *e = m_entries.GetNext(pos);
00271 m_table.getRow( e->id, e->s, e->val, e->resp);
00272 }
00273 }
00274
00275
00276
00277 bool SelConf::addPossibleAncestors( CStringList& list, int changed)
00278 {
00279 POSITION pos = m_entries.GetHeadPosition();
00280 entry *e = 0;
00281 while (pos) {
00282 e = m_entries.GetNext(pos);
00283 if ( e->id == changed)
00284 break;
00285 }
00286
00287 if ( e && e->id == changed)
00288 {
00289 Any * any_ptr = const_cast<Any *>( static_cast<const Any *>(e->ptr));
00290 if ( any_ptr && any_ptr->isFCO())
00291 {
00292 FCO * fco_ptr = dynamic_cast<FCO*>( any_ptr);
00293 if( fco_ptr)
00294 {
00295 std::vector<FCO *> ancestor;
00296 bool found_same_kind_extd_anc = false;
00297 fco_ptr->getIntAncestors( ancestor);
00298
00299 for( unsigned int i = 0; i < ancestor.size(); ++i)
00300 {
00301
00302 POSITION pos_d = m_entries.GetHeadPosition();
00303 entry *e_d = 0;
00304 while (pos_d) {
00305 e_d = m_entries.GetNext(pos_d);
00306 if ( e_d->ptr == ancestor[i])
00307 {
00308 CString role, repr; bool extended = false;
00309 if( m_table.getRow( e_d->id, role, extended, repr))
00310 {
00311 if( extended
00312 && fco_ptr->getMyKind() == ancestor[i]->getMyKind()
00313 )
00314 {
00315 list.AddTail( ancestor[i]->getLStrictName().c_str());
00316 found_same_kind_extd_anc = true;
00317 }
00318 }
00319 break;
00320 }
00321 }
00322 }
00323
00324 return found_same_kind_extd_anc;
00325 }
00326 }
00327 }
00328 return false;
00329 }
00330
00331
00332 void SelConf::getDescsAncs( bool which, DWORD_PTR changed, std::vector< int > & res)
00333 {
00334 POSITION pos = m_entries.GetHeadPosition();
00335 entry *e = 0;
00336 while (pos) {
00337 e = m_entries.GetNext(pos);
00338 if ( e->id == changed)
00339 break;
00340 }
00341
00342 if ( e && e->id == changed)
00343 {
00344 Any * any_ptr = const_cast<Any *>( static_cast<const Any *>(e->ptr));
00345 if ( any_ptr && any_ptr->isFCO())
00346 {
00347 FCO * fco_ptr = dynamic_cast<FCO*>( any_ptr);
00348 if( fco_ptr)
00349 {
00350 std::vector<FCO *> family;
00351 if ( which)
00352 {
00353
00354
00355
00356 family = fco_ptr->getAllDescendants();
00357 }
00358 else
00359 {
00360 family = fco_ptr->getAllAncestors();
00361
00362 }
00363
00364 for( unsigned int i = 0; i < family.size(); ++i)
00365 {
00366 FCO * dep_ptr = family[i];
00367 POSITION pos_d = m_entries.GetHeadPosition();
00368 entry *e_d = 0;
00369 while (pos_d) {
00370 e_d = m_entries.GetNext(pos_d);
00371 if ( e_d->ptr == dep_ptr)
00372 {
00373 res.push_back( e_d->id);
00374 break;
00375 }
00376 }
00377 }
00378 }
00379 }
00380 }
00381 }
00382
00383 bool SelConf::getEntries( LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort, entry& e, entry& f)
00384 {
00385 SelConf * myDlg = reinterpret_cast<SelConf *>((void*)lParamSort);
00386 bool b1 = myDlg->getEntry( lParam1, e.s, e.val, e.resp, e.ptr);
00387 bool b2 = myDlg->getEntry( lParam2, f.s, f.val, f.resp, f.ptr);
00388
00389 return b1 && b2;
00390 }
00391
00392 int CALLBACK SelConf::MyNameCompare(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
00393 {
00394 entry e, f;
00395 if( !getEntries( lParam1, lParam2, lParamSort, e, f)) return 0;
00396
00397 return m_sortOrder * e.s.Compare( f.s);
00398 }
00399
00400 int CALLBACK SelConf::MyKindCompare(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
00401 {
00402 entry e, f;
00403 if( !getEntries( lParam1, lParam2, lParamSort, e, f)) return 0;
00404
00405 Any * any_ptr1 = reinterpret_cast<Any *>((void*)e.ptr);
00406 Any * any_ptr2 = reinterpret_cast<Any *>((void*)f.ptr);
00407
00408 std::string ks1 = any_ptr1->getMyKindStr();
00409 std::string ks2 = any_ptr2->getMyKindStr();
00410
00411 return m_sortOrder * ks1.compare( ks2);
00412 }
00413
00414 int CALLBACK SelConf::MyExtdCompare(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
00415 {
00416 entry e, f;
00417 if( !getEntries( lParam1, lParam2, lParamSort, e, f)) return 0;
00418
00419 if( e.val == f.val) return 0;
00420 else return m_sortOrder * (int)e.val < m_sortOrder * (int)f.val;
00421 }
00422
00423 int CALLBACK SelConf::MyReprCompare(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
00424 {
00425 entry e, f;
00426 if( !getEntries( lParam1, lParam2, lParamSort, e, f)) return 0;
00427
00428 return m_sortOrder * e.resp.Compare( f.resp);
00429 }
00430
00431
00432 void SelConf::selectAll( bool pVal)
00433 {
00434 m_table.DeleteAllItems();
00435
00436 POSITION pos = m_entries.GetHeadPosition();
00437 while( pos) {
00438 entry *e = m_entries.GetNext(pos);
00439 e->val = pVal;
00440 e->resp = "";
00441 }
00442 fillUpTable();
00443 }
00444
00445 void SelConf::OnBnClickedDeselectallbtn()
00446 {
00447 selectAll( false);
00448 }
00449
00450 void SelConf::OnBnClickedSelectallbtn()
00451 {
00452 selectAll( true);
00453 }