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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [host/] [tools/] [configtool/] [standalone/] [wxwin/] [conflictwin.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, 2009 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
// configtree.cpp :
23
//
24
//===========================================================================
25
//#####DESCRIPTIONBEGIN####
26
//
27
// Author(s):   julians, jld
28
// Contact(s):  julians
29
// Date:        2000/09/04
30
// Version:     $Id: conflictwin.cpp,v 1.3 2001/04/24 14:39:13 julians Exp $
31
// Purpose:
32
// Description: Implementation file for ecConflictListCtrl
33
// Requires:
34
// Provides:
35
// See also:
36
// Known bugs:
37
// Usage:
38
//
39
//####DESCRIPTIONEND####
40
//
41
//===========================================================================
42
 
43
// ============================================================================
44
// declarations
45
// ============================================================================
46
 
47
// ----------------------------------------------------------------------------
48
// headers
49
// ----------------------------------------------------------------------------
50
#ifdef __GNUG__
51
    #pragma implementation "conflictwin.h"
52
#endif
53
 
54
// Includes other headers for precompiled compilation
55
#include "ecpch.h"
56
 
57
#ifdef __BORLANDC__
58
    #pragma hdrstop
59
#endif
60
 
61
#include "conflictwin.h"
62
#include "configtool.h"
63
#include "configtooldoc.h"
64
#include "configtree.h"
65
 
66
/*
67
 * ecConflictListCtrl
68
 */
69
 
70
IMPLEMENT_CLASS(ecConflictListCtrl, wxListCtrl)
71
 
72
BEGIN_EVENT_TABLE(ecConflictListCtrl, wxListCtrl)
73
    EVT_RIGHT_DOWN(ecConflictListCtrl::OnRightClick)
74
    EVT_LEFT_DCLICK(ecConflictListCtrl::OnLeftDClick)
75
 
76
    EVT_MENU(ecID_LOCATE_ITEM, ecConflictListCtrl::OnLocate)
77
    EVT_MENU(ecID_RESOLVE_ITEM, ecConflictListCtrl::OnResolve)
78
END_EVENT_TABLE()
79
 
80
ecConflictListCtrl::ecConflictListCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pt,
81
        const wxSize& sz, long style):
82
        wxListCtrl(parent, id, pt, sz, style)
83
{
84
    if (!wxGetApp().GetSettings().GetWindowSettings().GetUseDefaults() &&
85
         wxGetApp().GetSettings().GetWindowSettings().GetFont(wxT("Conflicts")).Ok())
86
    {
87
        SetFont(wxGetApp().GetSettings().GetWindowSettings().GetFont(wxT("Conflicts")));
88
    }
89
 
90
    InsertColumn(0, "Item", wxLIST_FORMAT_LEFT, 200);
91
    InsertColumn(1, "Conflict", wxLIST_FORMAT_LEFT, 80);
92
    InsertColumn(2, "Property", wxLIST_FORMAT_LEFT, 100);
93
 
94
    m_contextMenu = new wxMenu;
95
    m_contextMenu->Append(ecID_WHATS_THIS, _("&What's This?"));
96
    m_contextMenu->AppendSeparator();
97
    m_contextMenu->Append(ecID_LOCATE_ITEM, _("&Locate"));
98
    m_contextMenu->Append(ecID_RESOLVE_ITEM, _("&Resolve"));
99
 
100
    m_contextItem = -1;
101
    m_contextCol = 0;
102
}
103
 
104
ecConflictListCtrl::~ecConflictListCtrl()
105
{
106
    delete m_contextMenu;
107
}
108
 
109
void ecConflictListCtrl::OnRightClick(wxMouseEvent& event)
110
{
111
    int flags = 0;
112
    long item = HitTest(wxPoint(event.GetX(), event.GetY()), flags);
113
 
114
    if (item >= 0 && !GetParent ()->IsKindOf (CLASSINFO(wxDialog)))  // this menu for conflicts view only
115
    {
116
        m_contextItem = item;
117
 
118
        // Find which column we're on
119
        m_contextCol = wxListCtrlFindColumn(*this, 3, event.GetX());
120
 
121
        // GetContextMenu()->SetClientData((void*) TRUE);
122
        PopupMenu(GetContextMenu(), event.GetX(), event.GetY());
123
    }
124
    else
125
    {
126
        m_contextItem = -1;
127
 
128
        PopupMenu(wxGetApp().GetWhatsThisMenu(), event.GetX(), event.GetY());
129
    }
130
}
131
 
132
void ecConflictListCtrl::OnLeftDClick(wxMouseEvent& event)
133
{
134
    if (!GetParent ()->IsKindOf (CLASSINFO(wxDialog)))  // handle double click for conflicts view only
135
    {
136
        long sel = wxListCtrlGetSelection(* this);
137
        if (sel >= 0)
138
        {
139
            // Find which column we're on
140
            int col = wxListCtrlFindColumn(*this, 3, event.GetX());
141
 
142
            ecConfigItem * pItem = AssociatedItem (sel, col); // get the referenced item
143
 
144
            if (pItem) { // if a referenced item was found
145
                wxGetApp().GetTreeCtrl()->SelectItem (pItem->GetTreeItem()); // select the refreenced item
146
            }
147
        }
148
    }
149
}
150
 
151
void ecConflictListCtrl::OnLocate(wxCommandEvent& event)
152
{
153
    if (m_contextItem > -1)
154
    {
155
        ecConfigItem * pItem = AssociatedItem (m_contextItem, m_contextCol); // get the referenced item
156
 
157
        if (pItem) { // if a referenced item was found
158
            wxGetApp().GetTreeCtrl()->SelectItem (pItem->GetTreeItem()); // select the refreenced item
159
        }
160
    }
161
}
162
 
163
void ecConflictListCtrl::OnResolve(wxCommandEvent& event)
164
{
165
    ecConfigToolDoc *pDoc = wxGetApp().GetConfigToolDoc();
166
 
167
    wxList conflictsOfInterest;
168
 
169
    long n = GetItemCount();
170
    long i;
171
    for (i = 0; i < n; i++)
172
    {
173
        if (GetItemState(i, wxLIST_STATE_SELECTED) & wxLIST_STATE_SELECTED)
174
        {
175
            conflictsOfInterest.Append((wxObject*) (void*) GetItemData(i));
176
        }
177
    }
178
 
179
    pDoc->ResolveGlobalConflicts(& conflictsOfInterest);
180
}
181
 
182
 
183
void ecConflictListCtrl::AddConflict (const CdlConflict &conf)
184
{
185
    // set the item column string
186
    wxString strMacroName = (conf)->get_node ()->get_name ().c_str ();
187
    int nIndex = InsertItem (GetItemCount (), strMacroName);
188
 
189
    nIndex = GetItemCount() - 1;
190
 
191
    SetItemData (nIndex, (long) (conf));
192
 
193
    // set the conflict column string
194
    if (0 != dynamic_cast<CdlConflict_Unresolved> (conf)) {// a conflict of type 'unresolved'
195
        SetItem (nIndex, 1, wxT("Unresolved"));
196
    } else if (0 != dynamic_cast<CdlConflict_IllegalValue> (conf)) { // a conflict of type 'illegal value'
197
        SetItem (nIndex, 1, wxT("Illegal"));
198
    } else if (0 != dynamic_cast<CdlConflict_EvalException> (conf)) { // a conflict of type 'evaluation exception'
199
        SetItem (nIndex, 1, wxT("Exception"));
200
    } else if (0 != dynamic_cast<CdlConflict_Requires> (conf)) { // a conflict of type 'goal unsatisfied'
201
        SetItem (nIndex, 1, wxT("Unsatisfied"));
202
    } else if (0 != dynamic_cast<CdlConflict_Data> (conf)) { // a conflict of type 'bad data'
203
        SetItem (nIndex, 1, wxT("Bad data"));
204
    } else {
205
        wxASSERT (0);
206
    }
207
 
208
    // set the property column string
209
    wxString strProperty = conf->get_property ()->get_property_name ().c_str ();
210
    strProperty += wxT(" ");
211
    const std::vector<std::string> & argv = conf->get_property ()->get_argv ();
212
    std::vector<std::string>::const_iterator argv_i;
213
    for (argv_i = argv.begin (); argv_i != argv.end (); argv_i++) {// for each property argument...
214
        if (argv_i != argv.begin ())                              // ...except the first
215
        {
216
            strProperty += argv_i->c_str (); // add the argument to the string
217
            strProperty += wxT (" "); // separate arguments by a space character
218
        }
219
    }
220
    strProperty.Trim (TRUE); // remove the trailing space character
221
    SetItem (nIndex, 2, strProperty);
222
}
223
 
224
void ecConflictListCtrl::AddConflicts (const std::list<CdlConflict>& conflicts)
225
{
226
    for (std::list<CdlConflict>::const_iterator conf_i=conflicts.begin (); conf_i != conflicts.end (); conf_i++) {
227
        AddConflict(*conf_i);
228
    }
229
    SetColumnWidth(2, wxLIST_AUTOSIZE); // resize the property column for the longest item
230
    if (GetColumnWidth(2) < 100)        // but at least wide enough for the column heading
231
        SetColumnWidth(2, 100);
232
}
233
 
234
ecConfigItem *ecConflictListCtrl::AssociatedItem(int nRow,int nCol)
235
{
236
    const CdlConflict conflict = (CdlConflict) GetItemData (nRow);
237
    wxASSERT (conflict != NULL);
238
 
239
    ecConfigItem *pItem=NULL;
240
    switch(nCol)
241
    {
242
    case 2:
243
        {
244
            const CdlGoalExpression goal = dynamic_cast<CdlGoalExpression> (conflict->get_property ());
245
            if (! goal) // if the item is not a goal expression
246
                break; // do nothing
247
            const CdlExpression expression = goal->get_expression ();
248
            if (1 == expression->references.size ()) // if the property contains a single reference
249
            {
250
                // assume that the reference is to another user visible node and try to find it
251
                const wxString strName(expression->references [0].get_destination_name ().c_str());
252
                pItem = wxGetApp().GetConfigToolDoc ()->Find(strName);
253
            }
254
        }
255
        break;
256
    case 0:
257
        pItem = wxGetApp().GetConfigToolDoc ()->Find(wxString(conflict->get_node ()->get_name ().c_str()));
258
        break;
259
    default:
260
        break;
261
    }
262
    return pItem;
263
}
264
 
265
// This is taken from CRulesView::FillRules in the MFC version
266
void ecConflictListCtrl::FillRules()
267
{
268
    CdlConfiguration CdlConfig = wxGetApp().GetConfigToolDoc()->GetCdlConfig ();
269
    if (CdlConfig)
270
    { // if configuration information
271
        int nCount=0;
272
        bool bRefill=false;
273
        wxHashTable arMap(wxKEY_INTEGER);
274
        int i;
275
        for ( i = 0 ; i < GetItemCount(); i++)
276
        {
277
            arMap.Put(GetItemData(i), (wxObject*) i);
278
        }
279
 
280
        std::list<CdlConflict>::const_iterator conf_i;
281
 
282
        const std::list<CdlConflict>& conflicts=CdlConfig->get_all_conflicts();
283
        for (conf_i = conflicts.begin (); conf_i != conflicts.end (); conf_i++) { // for each conflict
284
            nCount++;
285
            if (!arMap.Get((long) * conf_i))
286
            {
287
                bRefill=true;
288
                break;
289
            }
290
        }
291
        //for (conf_i = CdlConfig->get_structural_conflicts().begin (); conf_i != CdlConfig->get_structural_conflicts().end (); conf_i++) { // for each conflict
292
        //  nCount++;
293
        //  if(!arMap.Lookup(*conf_i,w)){
294
        //    bRefill=true;
295
        //    break;
296
        //  }
297
        //}
298
        if(bRefill || nCount != GetItemCount())
299
        {
300
            DeleteAllItems();
301
            //m_List.AddConflicts(CdlConfig->get_structural_conflicts());
302
            AddConflicts(CdlConfig->get_all_conflicts());
303
        }
304
    }
305
}
306
 
307
#if 0
308
int CRulesList::CompareFunc(LPARAM lParam1, LPARAM lParam2)
309
{
310
        LV_FINDINFO find1 = { LVFI_PARAM, NULL, lParam1, NULL, NULL };
311
        LV_FINDINFO find2 = { LVFI_PARAM, NULL, lParam2, NULL, NULL };
312
        const int nIndex1 = FindItem (&find1);
313
        const int nIndex2 = FindItem (&find2);
314
        const CString str1 = GetItemText (nIndex1, m_nLastCol & 0x7fffffff);
315
        const CString str2 = GetItemText (nIndex2, m_nLastCol & 0x7fffffff);
316
        return (m_nLastCol & 0x80000000) ^ str1.Compare (str2);
317
}
318
 
319
void CRulesList::OnColumnclick(NMHDR* pNMHDR, LRESULT* pResult)
320
{
321
        NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
322
        LPARAM nCol=pNMListView->iSubItem;
323
        if((nCol&0x7fffffff)==(0x7fffffff&m_nLastCol)){
324
                nCol=m_nLastCol^0x80000000;
325
        }
326
  m_nLastCol=nCol;
327
        SortItems(CompareFunc,(DWORD)this);
328
 
329
        *pResult = 0;
330
}
331
 
332
void CRulesList::OnDblclk(NMHDR* pNMHDR, LRESULT* pResult)
333
{
334
  if (GetParent ()->IsKindOf (RUNTIME_CLASS (CRulesView))) { // handle double click for conflicts view only
335
    NM_LISTVIEW * pNMListView = (NM_LISTVIEW *) pNMHDR;
336
    int nItem = pNMListView->iItem;
337
    if (-1 != nItem) { // if the double click was on a row of the list
338
      CConfigItem * pItem = AssociatedItem (nItem, pNMListView->iSubItem); // get the referenced item
339
      if (pItem) { // if a referenced item was found
340
        CConfigTool::GetControlView ()->SelectItem (pItem); // select the refreenced item
341
      }
342
    }
343
  }
344
 
345
  *pResult = 0;
346
  UNUSED_ALWAYS(pNMHDR);
347
}
348
 
349
#endif

powered by: WebSVN 2.1.0

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