OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [host/] [tools/] [configtool/] [common/] [win32/] [FailingRulesDialog.cpp] - Blame information for rev 790

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
// ####ECOSHOSTGPLCOPYRIGHTBEGIN####                                        
2
// -------------------------------------------                              
3
// This file is part of the eCos host tools.                                
4
// Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.            
5
//
6
// This program is free software; you can redistribute it and/or modify     
7
// it under the terms of the GNU General Public License as published by     
8
// the Free Software Foundation; either version 2 or (at your option) any   
9
// later version.                                                           
10
//
11
// This program is distributed in the hope that it will be useful, but      
12
// WITHOUT ANY WARRANTY; without even the implied warranty of               
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        
14
// General Public License for more details.                                 
15
//
16
// You should have received a copy of the GNU General Public License        
17
// along with this program; if not, write to the                            
18
// Free Software Foundation, Inc., 51 Franklin Street,                      
19
// Fifth Floor, Boston, MA  02110-1301, USA.                                
20
// -------------------------------------------                              
21
// ####ECOSHOSTGPLCOPYRIGHTEND####                                          
22
// FailingRulesDialog.cpp : implementation file
23
//
24
 
25
#include "stdafx.h"
26
#ifndef PLUGIN
27
#include "BCMenu.h"
28
#endif
29
#include "FailingRulesDialog.h"
30
#include "ConfigItem.h"
31
#include "ConfigTool.h"
32
#include "ConfigToolDoc.h"
33
#include "ControlView.h"
34
#include "CTUtils.h"
35
 
36
#ifdef _DEBUG
37
#define new DEBUG_NEW
38
#undef THIS_FILE
39
static char THIS_FILE[] = __FILE__;
40
#endif
41
 
42
/////////////////////////////////////////////////////////////////////////////
43
// CFailingRulesDialog dialog
44
 
45
 
46
CFailingRulesDialog::CFailingRulesDialog(std::list<CdlConflict> conflicts,CdlTransaction transaction/*=NULL*/,CPtrArray *parConflictsOfInterest/*=NULL*/)
47
        : CeCosDialog(CFailingRulesDialog::IDD, NULL),
48
        m_conflicts(conflicts),
49
  m_Transaction(transaction),
50
  m_parConflictsOfInterest(parConflictsOfInterest)
51
{
52
  for (std::list<CdlConflict>::const_iterator conf_i= m_conflicts.begin (); conf_i != m_conflicts.end (); conf_i++) { // for each conflict
53
    int nSolutions=(*conf_i)->get_solution().size();
54
    SolutionInfo *pInfo=(SolutionInfo *)malloc(sizeof(SolutionInfo)+(nSolutions-1)*sizeof(int));
55
    pInfo->nCount=nSolutions;
56
    for(int i=0;i<nSolutions;i++){
57
      pInfo->arItem[i]=SolutionInfo::CHECKED;
58
    }
59
    m_Map.SetAt(*conf_i,pInfo);
60
  }
61
 
62
        //{{AFX_DATA_INIT(CFailingRulesDialog)
63
                // NOTE: the ClassWizard will add member initialization here
64
        //}}AFX_DATA_INIT
65
}
66
 
67
CFailingRulesDialog::~CFailingRulesDialog()
68
{
69
  for(POSITION pos = m_Map.GetStartPosition(); pos != NULL; ){
70
    CdlConflict conflict;
71
    SolutionInfo *pInfo=NULL;
72
    m_Map.GetNextAssoc(pos, (void *&)conflict, (void *&)pInfo);
73
    free(pInfo);
74
  }
75
}
76
 
77
void CFailingRulesDialog::DoDataExchange(CDataExchange* pDX)
78
{
79
        CeCosDialog::DoDataExchange(pDX);
80
        //{{AFX_DATA_MAP(CFailingRulesDialog)
81
        DDX_Control(pDX, IDC_LIST2, m_List);
82
        //}}AFX_DATA_MAP
83
}
84
 
85
 
86
BEGIN_MESSAGE_MAP(CFailingRulesDialog, CeCosDialog)
87
        //{{AFX_MSG_MAP(CFailingRulesDialog)
88
        ON_BN_CLICKED(IDC_RESET, OnReset)
89
        ON_BN_CLICKED(IDC_CONFLICTS_NONE, OnConflictsNone)
90
        ON_BN_CLICKED(ID_RESOLVE_CONFLICTS_CONTINUE, OnOK)
91
  ON_BN_CLICKED(ID_RESOLVE_CONFLICTS_CANCEL,OnCancel)
92
  ON_COMMAND(ID_LOCATE,OnLocate)
93
        //}}AFX_MSG_MAP
94
END_MESSAGE_MAP()
95
 
96
/////////////////////////////////////////////////////////////////////////////
97
// CFailingRulesDialog message handlers
98
 
99
BOOL CFailingRulesDialog::OnInitDialog()
100
{
101
  CeCosDialog::OnInitDialog();
102
  m_List.SetExtendedStyle(LVS_EX_CHECKBOXES);
103
  m_List.InsertColumn(0,_T("Item"));
104
  m_List.InsertColumn(1,_T("Value"));
105
 
106
  CRect rect;
107
  GetDlgItem(IDC_LIST1)->GetWindowRect(rect);
108
  ScreenToClient(rect);
109
 
110
  m_RulesList.CreateEx(WS_EX_CLIENTEDGE,WC_LISTVIEW,NULL,WS_VISIBLE|WS_CHILD|LVS_SHOWSELALWAYS,rect,this,IDC_LIST1);
111
  // Select the first item and fill the solution set
112
  m_RulesList.AddConflicts(m_conflicts);
113
 
114
  if(m_parConflictsOfInterest && m_parConflictsOfInterest->GetSize()>0){
115
    CPtrArray &arConflictsOfInterest=*m_parConflictsOfInterest;
116
    for(int i=m_RulesList.GetItemCount()-1;i>=0;--i){
117
      for(int j=arConflictsOfInterest.GetSize()-1;j>=0;--j){
118
        CdlConflict conflict=(CdlConflict)m_RulesList.GetItemData(i);
119
        if(arConflictsOfInterest[j]==conflict){
120
          m_RulesList.SetItemState(i,LVIS_SELECTED, LVIS_SELECTED);
121
          m_RulesList.EnsureVisible(i,false);
122
          arConflictsOfInterest.RemoveAt(j);
123
          break;
124
        }
125
      }
126
    }
127
  } else {
128
    for(int i=m_RulesList.GetItemCount()-1;i>=0;--i){
129
      m_RulesList.SetItemState(i,LVIS_SELECTED, LVIS_SELECTED);
130
    }
131
  }
132
  SetButtons();
133
        return false;  // return TRUE unless you set the focus to a control
134
                      // EXCEPTION: OCX Property Pages should return FALSE
135
}
136
 
137
void CFailingRulesDialog::OnCancel()
138
{
139
  CeCosDialog::OnCancel();
140
}
141
 
142
void CFailingRulesDialog::OnOK()
143
{
144
  // Ensure we have the current conflict check array
145
  for(POSITION pos = m_RulesList.GetFirstSelectedItemPosition();pos;){
146
    int nItem = m_RulesList.GetNextSelectedItem(pos);
147
    RemoveConflictSolutions((CdlConflict)m_RulesList.GetItemData(nItem));
148
  }
149
 
150
  // Dismiss the window
151
  CeCosDialog::OnOK();
152
 
153
  for (std::list<CdlConflict>::const_iterator conf_i= m_conflicts.begin (); conf_i != m_conflicts.end (); conf_i++) { // for each conflict
154
    CdlConflict conflict=*conf_i;
155
    //int nSolutions=conflict->get_solution().size();
156
    SolutionInfo &info=Info(conflict);
157
    int nIndex=0;
158
    const std::vector<std::pair<CdlValuable, CdlValue> >&Solution=conflict->get_solution();
159
    for (std::vector<std::pair<CdlValuable, CdlValue> >::const_iterator soln_i = Solution.begin();soln_i != Solution.end(); soln_i++) {
160
      if(SolutionInfo::CHECKED==info.arItem[nIndex++]){
161
        CdlValuable valuable  = soln_i->first;
162
        CdlValue value=soln_i->second;
163
        CdlValueFlavor flavor = valuable->get_flavor();
164
        const CString strName(valuable->get_name().c_str());
165
        const CString strValue(value.get_value().c_str());
166
        bool rc=true;
167
        CString str;
168
        try {
169
          switch(flavor) {
170
            case CdlValueFlavor_None :
171
              str=_T("set CdlValueFlavor_None");
172
              rc=false;
173
              break;
174
            case CdlValueFlavor_Bool :
175
              str.Format(_T("%s %s\n"),value.is_enabled()?_T("disable"):_T("enable"),strName);
176
              valuable->set_enabled (m_Transaction, value.is_enabled(), CdlValueSource_User);
177
              break;
178
            case CdlValueFlavor_BoolData :
179
              {
180
                bool bEnabled=value.is_enabled();
181
                str.Format(_T("%s %s and set value to %s\n"),bEnabled?_T("disable"):_T("enable"),strName,strValue);
182
                // This is wrong: it should set the NEW value. This is the cause of a long-standing bug...
183
                // CdlSimpleValue simple_value = valuable->get_simple_value ();
184
                //valuable->set_enabled_and_value (m_Transaction, bEnabled, simple_value, CdlValueSource_User);
185
                valuable->set_enabled_and_value (m_Transaction, bEnabled, CUtils::UnicodeToStdStr (strValue), CdlValueSource_User);
186
 
187
              }
188
              break;
189
            case CdlValueFlavor_Data :
190
              str.Format(_T("set %s to %s\n"),strName,strValue);
191
              valuable->set_value (m_Transaction, CUtils::UnicodeToStdStr (strValue), CdlValueSource_User);
192
              break;
193
          }
194
        }
195
        catch(...){
196
          rc=false;
197
        }
198
        if(rc){
199
          CConfigTool::GetConfigToolDoc()->SetModifiedFlag();
200
        } else {
201
          CUtils::MessageBoxF(_T("Failed to %s\n"),str);
202
        }
203
      }
204
    }
205
  }
206
}
207
 
208
void CFailingRulesDialog::SetAll(bool bOnOff)
209
{
210
  for(int i=m_List.GetItemCount()-1;i>=0;--i){
211
    m_List.SetCheck(i,bOnOff);
212
  }
213
}
214
 
215
void CFailingRulesDialog::OnReset()
216
{
217
  SetAll(true);
218
}
219
 
220
void CFailingRulesDialog::OnConflictsNone()
221
{
222
  SetAll(false);
223
}
224
 
225
BOOL CFailingRulesDialog::OnItemChanged(UINT, LPNMLISTVIEW pnmv, LRESULT* pResult)
226
{
227
  bool bWasSelected=(pnmv->uOldState & LVIS_SELECTED);
228
  bool bIsSelected =(pnmv->uNewState & LVIS_SELECTED);
229
 
230
  if(bWasSelected != bIsSelected) {
231
    CdlConflict conflict=(CdlConflict) m_RulesList.GetItemData(pnmv->iItem);
232
    if(bIsSelected){
233
      if(1==m_List.GetSelectedCount()){
234
        GetDlgItem(IDC_STATIC1)->ShowWindow(SW_HIDE);
235
        m_List.ShowWindow(SW_SHOW);
236
      }
237
      AddConflictSolutions(conflict);
238
    } else {
239
      RemoveConflictSolutions(conflict);
240
    }
241
  }
242
  *pResult = 0;
243
  return false;
244
}
245
 
246
// We need to use this because the OnItemChanged handler successive receives "not selected" followed by "selected"
247
// notifications.  The result is that the "Select one or more conflicts to display available solutions" message
248
// would be seen briefly when clicking from one selection to another.
249
BOOL CFailingRulesDialog::OnClick(UINT,LPNMLISTVIEW pnmv, LRESULT* pResult)
250
{
251
  if(-1==pnmv->iItem && 0==m_List.GetSelectedCount()){
252
    SetDlgItemText(IDC_STATIC1,_T("Select one or more conflicts to display available solutions"));
253
    m_List.ShowWindow(SW_HIDE);
254
    GetDlgItem(IDC_STATIC1)->ShowWindow(SW_SHOW);
255
    GetDlgItem(IDC_RESET)->EnableWindow(false);
256
    GetDlgItem(IDC_CONFLICTS_NONE)->EnableWindow(false);
257
  }
258
  *pResult = 0;
259
  return false; // not handled
260
}
261
 
262
void CFailingRulesDialog::RemoveConflictSolutions(CdlConflict conflict)
263
{
264
  SolutionInfo &info=Info(conflict);
265
  for(int i=0;i<info.nCount;i++){
266
    int nItem=info.arItem[i];
267
    ASSERT(nItem>=0);
268
    info.arItem[i]=(1==m_List.GetCheck(nItem)?SolutionInfo::CHECKED:SolutionInfo::UNCHECKED);
269
    int nRefs=m_List.GetItemData(nItem);
270
    if(1==nRefs){
271
      m_List.DeleteItem(nItem);
272
      for(int i=0;i<m_RulesList.GetItemCount();i++){
273
        SolutionInfo &info=Info((CdlConflict)m_RulesList.GetItemData(i));
274
        for(int j=0;j<info.nCount;j++){
275
          if(info.arItem[j]>nItem){
276
            info.arItem[j]--;
277
          }
278
        }
279
      }
280
    } else {
281
      m_List.SetItemData(nItem,nRefs-1);
282
    }
283
  }
284
}
285
 
286
void CFailingRulesDialog::AddConflictSolutions(CdlConflict conflict)
287
{
288
  SolutionInfo &info=Info(conflict);
289
 
290
  const std::vector<std::pair<CdlValuable, CdlValue> >&Solution=conflict->get_solution();
291
 
292
  int i=0;
293
  for (std::vector<std::pair<CdlValuable, CdlValue> >::const_iterator soln_i = Solution.begin();
294
       soln_i != Solution.end(); soln_i++) {
295
    CdlValuable valuable  = soln_i->first;
296
    CdlValue value=soln_i->second;
297
    CdlValueFlavor flavor = valuable->get_flavor();
298
 
299
    CString strValue;
300
    switch(flavor) {
301
      case CdlValueFlavor_None :
302
        break;
303
      case CdlValueFlavor_Bool :
304
        strValue=value.is_enabled() ? _T("Enabled") : _T("Disabled");
305
        break;
306
      case CdlValueFlavor_BoolData :
307
        strValue.Format(_T("%s, %s"), value.is_enabled() ? _T("Enabled") : _T("Disabled"), CString(value.get_value().c_str()));
308
        break;
309
      case CdlValueFlavor_Data :
310
        strValue=value.get_value().c_str();
311
        break;
312
    }
313
 
314
    const CString strName(soln_i->first->get_name().c_str());
315
    LVFINDINFO fi;
316
    fi.flags=LVFI_STRING;
317
    fi.psz=strName;
318
    int nIndex=m_List.FindItem(&fi);
319
    if(-1==nIndex || strValue!=m_List.GetItemText(nIndex,1)){
320
      // We don't have an existing solution that matches this one
321
      nIndex=m_List.GetItemCount();
322
      m_List.InsertItem(nIndex,strName);
323
      m_List.SetItemData(nIndex,1);
324
      m_List.SetItemText(nIndex,1,strValue);
325
      ASSERT(info.arItem[i]<0);
326
      m_List.SetCheck(nIndex,SolutionInfo::CHECKED==info.arItem[i]);
327
    } else {
328
      // We do - to avoid duplicates, increment the "ref count"
329
      m_List.SetItemData(nIndex,m_List.GetItemData(nIndex)+1);
330
    }
331
    info.arItem[i++]=nIndex;
332
  }
333
  if(0==i){
334
    SetDlgItemText(IDC_STATIC1,_T("No solution is available for this conflict"));
335
    m_List.ShowWindow(SW_HIDE);
336
  } else {
337
    SetDlgItemText(IDC_STATIC1,_T("Proposed solution:"));
338
    m_List.ShowWindow(SW_SHOW);
339
    m_List.SetColumnWidth(0,LVSCW_AUTOSIZE);
340
    CRect rect;
341
    m_List.GetClientRect(rect);
342
    m_List.SetColumnWidth(1,rect.Width()-m_List.GetColumnWidth(0));
343
  }
344
}
345
 
346
BOOL CFailingRulesDialog::OnSolutionItemChanged(UINT,LPNMLISTVIEW, LRESULT*)
347
{
348
  SetButtons();
349
  return false; // not handled
350
}
351
 
352
CFailingRulesDialog::SolutionInfo & CFailingRulesDialog::Info(const CdlConflict conflict)
353
{
354
  SolutionInfo *pInfo;
355
  VERIFY(m_Map.Lookup(conflict,(void *&)pInfo));
356
  return *pInfo;
357
}
358
 
359
BOOL CFailingRulesDialog::OnRClick(UINT, LPNMITEMACTIVATE pnmv, LRESULT* pResult)
360
{
361
  DWORD dwPos=GetMessagePos();
362
  CPoint pt(GET_X_LPARAM(dwPos),GET_Y_LPARAM(dwPos));
363
  m_nContextItem=pnmv->iItem;
364
  m_nContextRow=pnmv->iSubItem;
365
  if(-1!=m_nContextItem){
366
    //m_RulesList.SetItemState(m_nContextItem,LVIS_SELECTED,LVIS_SELECTED);
367
        Menu menu;
368
    menu.CreatePopupMenu();
369
    menu.AppendMenu(1==m_RulesList.GetSelectedCount() && m_RulesList.AssociatedItem(m_nContextItem,m_nContextRow)?MF_STRING:(MF_STRING|MF_GRAYED),ID_LOCATE,_T("&Locate"));
370
#ifndef PLUGIN
371
    SuppressNextContextMenuMessage();
372
#endif
373
    menu.TrackPopupMenu(TPM_LEFTALIGN|TPM_LEFTBUTTON|TPM_RIGHTBUTTON, pt.x,pt.y,this);
374
  }
375
 
376
  *pResult = 0;
377
  return TRUE; // handled
378
}
379
 
380
void CFailingRulesDialog::OnLocate()
381
{
382
  CConfigItem *pItem=m_RulesList.AssociatedItem(m_nContextItem,m_nContextRow);
383
  if (pItem) {
384
    CConfigTool::GetControlView()->SelectItem(pItem);
385
  }
386
}
387
 
388
 
389
void CFailingRulesDialog::SetButtons()
390
{
391
  int nCheckCount=0;
392
  int nItemCount=m_List.GetItemCount();
393
  for(int i=nItemCount-1;i>=0;--i){
394
    nCheckCount+=m_List.GetCheck(i);
395
  }
396
  GetDlgItem(IDC_RESET)->EnableWindow(nItemCount>0 && nCheckCount<nItemCount);
397
  GetDlgItem(IDC_CONFLICTS_NONE)->EnableWindow(nItemCount>0 && nCheckCount>0);
398
}
399
 
400
// We have to dispatch our own notify messages because the multiple inheritance of CCSHDialog prevents
401
// the message map from compiling properly for ON_NOTIFY messages.
402
BOOL CFailingRulesDialog::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult )
403
{
404
  LPNMHDR pHdr=(LPNMHDR)lParam;
405
  bool bHandled=false;
406
  switch(pHdr->idFrom){
407
    case IDC_LIST1:
408
      switch (pHdr->code) {
409
        case LVN_ITEMCHANGED:
410
          bHandled=OnItemChanged(wParam, (LPNMLISTVIEW)lParam, pResult);
411
          break;
412
        case NM_CLICK:
413
          bHandled=OnClick(wParam, (LPNMLISTVIEW)lParam, pResult);
414
          break;
415
        case NM_RCLICK:
416
          bHandled=OnRClick(wParam, (LPNMITEMACTIVATE)lParam, pResult);
417
          break;
418
        default:
419
          break;
420
      }
421
      break;
422
    case IDC_LIST2:
423
      switch (pHdr->code) {
424
        case LVN_ITEMCHANGED:
425
          bHandled=OnSolutionItemChanged(wParam,(LPNMLISTVIEW)lParam, pResult);
426
          break;
427
        default:
428
          break;
429
      }
430
      break;
431
  }
432
  return bHandled || CeCosDialog::OnNotify(wParam,lParam,pResult);
433
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.