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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [host/] [tools/] [configtool/] [standalone/] [wxwin/] [configtooldoc.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, 2003, 2005, 2006, 2008, 2009, 2010 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
// configtooldoc.cpp :
23
//
24
//===========================================================================
25
//#####DESCRIPTIONBEGIN####
26
//
27
// Author(s):   julians, jld
28
// Contact(s):  julians, jld
29
// Date:        2000/10/05
30
// Version:     $Id: configtooldoc.cpp,v 1.43 2002/02/13 13:58:18 julians Exp $
31
// Purpose:
32
// Description: Implementation file for the ecConfigToolDoc class
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 "configtooldoc.h"
52
#endif
53
 
54
// Includes other headers for precompiled compilation
55
#include "ecpch.h"
56
 
57
#include "wx/config.h"
58
#include "wx/textfile.h"
59
#include "wx/process.h"
60
#include "wx/mimetype.h"
61
 
62
#ifdef __BORLANDC__
63
#pragma hdrstop
64
#endif
65
 
66
#ifdef __WXMSW__
67
#include <windows.h>
68
#ifndef __CYGWIN__
69
#include <shlobj.h>
70
#endif
71
#include "wx/msw/winundef.h"
72
#ifdef CreateDirectory
73
#undef CreateDirectory
74
#endif
75
#endif
76
 
77
#include "configtooldoc.h"
78
#include "configtoolview.h"
79
#include "configtree.h"
80
#include "mainwin.h"
81
#include "ecutils.h"
82
#include "filename.h"
83
#include "choosereposdlg.h"
84
#include "packagesdlg.h"
85
#include "conflictsdlg.h"
86
#include "conflictwin.h"
87
#include "mltwin.h"
88
#include "build.hxx"
89
#include "platformeditordlg.h"
90
#include "runtestsdlg.h"
91
#include "propertywin.h"
92
#include "docsystem.h"
93
 
94
IMPLEMENT_DYNAMIC_CLASS(ecConfigToolDoc, wxDocument)
95
 
96
ecConfigToolDoc::ecConfigToolDoc()
97
{
98
    m_bRepositoryOpen = FALSE;
99
    m_CdlPkgData = NULL;
100
    m_CdlInterp = NULL;
101
    m_CdlConfig = NULL;
102
    m_ConflictsOutcome = OK;
103
    m_strRepository = wxGetApp().GetSettings().m_strRepository;
104
}
105
 
106
ecConfigToolDoc::~ecConfigToolDoc()
107
{
108
    wxGetApp().m_currentDoc = NULL;
109
    wxGetApp().GetSettings().m_strRepository = m_strRepository;
110
 
111
    CloseRepository();
112
 
113
    // Delete remaining items -- most (if not all) should already
114
    // have been deleted via the tree item client data
115
    DeleteItems();
116
}
117
 
118
void ecConfigToolDoc::DeleteItems()
119
{
120
#if wxCHECK_VERSION(2, 6, 0)
121
    // Delete any remaining items
122
    wxNode* node = m_items.GetFirst();
123
    while (node)
124
    {
125
        ecConfigItem* item = wxDynamicCast(node->GetData(), ecConfigItem);
126
        wxNode* next = node->GetNext();
127
#else
128
    // Delete any remaining items
129
    wxNode* node = m_items.First();
130
    while (node)
131
    {
132
        ecConfigItem* item = wxDynamicCast(node->Data(), ecConfigItem);
133
        wxNode* next = node->Next();
134
#endif
135
 
136
        // Note: automatically removes itself from this list in ~ecConfigItem
137
        delete item;
138
        node = next;
139
    }
140
}
141
 
142
bool ecConfigToolDoc::OnCloseDocument()
143
{
144
    if (wxDocument::OnCloseDocument())
145
    {
146
        DeleteItems();
147
        return TRUE;
148
    }
149
    else
150
    {
151
        return FALSE;
152
    }
153
}
154
 
155
bool ecConfigToolDoc::Save()
156
{
157
    bool ret = FALSE;
158
 
159
    if (!IsModified() && m_savedYet) return TRUE;
160
    if (m_documentFile == wxT("") || !m_savedYet)
161
        ret = SaveAs();
162
    else
163
        ret = OnSaveDocument(m_documentFile);
164
    if ( ret )
165
        SetDocumentSaved(TRUE);
166
    return ret;
167
}
168
 
169
 
170
bool ecConfigToolDoc::OnCreate(const wxString& path, long flags)
171
{
172
    wxGetApp().m_currentDoc = this;
173
 
174
    if (flags & wxDOC_NEW)
175
    {
176
        m_bRepositoryOpen = FALSE;
177
 
178
        bool prompt = FALSE;
179
        if (flags & ecDOC_PROMPT_FOR_REPOSITORY)
180
            prompt = TRUE;
181
 
182
        if(!OpenRepository(wxEmptyString, prompt))
183
        {
184
            wxGetApp().m_currentDoc = NULL;
185
            return FALSE;
186
        }
187
 
188
        Modify(FALSE);
189
        SetDocumentSaved(FALSE);
190
 
191
        wxString rootName(wxT("untitled"));
192
        wxStripExtension(rootName);
193
        SetFilename(wxGetApp().GetSettings().GenerateFilename(rootName));
194
    }
195
 
196
    // Creates the view, so do any view updating after this
197
    bool success = wxDocument::OnCreate(path, flags);
198
 
199
    if (success)
200
    {
201
        if (flags & wxDOC_NEW)
202
        {
203
            wxBusyCursor wait;
204
 
205
            ecConfigToolHint hint(NULL, ecSelChanged);
206
            UpdateAllViews (NULL, & hint);
207
 
208
            SetFilename(GetFilename(), TRUE);
209
 
210
            // load the memory layout for the default target-platform-startup from the current repository
211
 
212
            // TODO
213
            // m_memoryMap.set_map_size (0xFFFFFFFF); // set the maximum memory map size
214
            // NewMemoryLayout (CFileName (m_strPackagesDir, m_strMemoryLayoutFolder, _T("include\\pkgconf")));
215
 
216
            // Why should we generate the names at this point, when we only have a temporary filename?
217
            // Don't do it!
218
#if 0
219
            wxGetApp().SetStatusText(wxT("Updating build information..."), FALSE);
220
            UpdateBuildInfo();
221
#endif
222
        }
223
    }
224
    return success;
225
}
226
 
227
bool ecConfigToolDoc::OnSaveDocument(const wxString& filename)
228
{
229
    wxBusyCursor cursor;
230
 
231
    const wxString strOldPath(GetFilename());
232
 
233
#if 0
234
    bool bSaveAs=(filename!=strOldPath);
235
    if(!IsModified() && wxFileExists(filename))
236
    {
237
        return TRUE;
238
    }
239
#endif
240
 
241
    bool rc=FALSE;
242
    if (CheckConflictsBeforeSave())
243
    { // errors already emitted
244
 
245
        const wxString strPathName(filename);
246
 
247
        wxString str;
248
        str.Printf(_("Saving configuration %s"), (const wxChar*) filename);
249
 
250
        /* TODO
251
        CIdleMessage IM(str);
252
        if(CConfigTool::GetCellView()){
253
        CConfigTool::GetCellView()->CancelCellEdit();
254
        }
255
        */
256
 
257
        // check the configuration
258
 
259
        wxASSERT (m_CdlConfig->check_this (cyg_extreme));
260
 
261
        // save the configuration
262
 
263
        try
264
        {
265
            m_CdlConfig->save ((const wxChar*) filename);
266
            rc=TRUE;
267
        }
268
 
269
        catch (CdlStringException exception)
270
        {
271
            wxString msg;
272
            msg.Printf(_("Error saving eCos configuration:\n\n%s"), exception.get_message ().c_str ());
273
            wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK);
274
        }
275
 
276
        catch (...)
277
        {
278
            wxString msg;
279
            msg.Printf(_("Error saving eCos configuration"));
280
            wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK);
281
        }
282
 
283
        if(rc){
284
            rc=FALSE;
285
            SetFilename (filename); // called to ensure that MLTDir() will work in this function TODO??
286
 
287
            // save the memory layout files to the build tree and copy to the install tree
288
            /* TODO
289
            if (bSaveAs || MemoryMap.map_modified ()) {
290
            SaveMemoryMap();
291
            }
292
            */
293
 
294
            ecConfigToolHint hint(NULL, ecAllSaved);
295
            UpdateAllViews (NULL, & hint);
296
 
297
            wxASSERT( !m_strBuildTree.IsEmpty() );
298
            wxASSERT( !m_strInstallTree.IsEmpty() );
299
 
300
            ecFileName buildFilename(m_strBuildTree);
301
            ecFileName installFilename(m_strInstallTree);
302
 
303
            if (!wxGetApp().GetSettings().m_editSaveFileOnly)
304
            {
305
                if (!buildFilename.EC_CreateDirectory(FALSE) || !installFilename.EC_CreateDirectory(FALSE))
306
                {
307
                    wxString msg;
308
                    msg.Printf(_("Failed to save %s"), (const wxChar*) filename);
309
 
310
                    wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION);
311
                    rc = FALSE;
312
                }
313
                else if (GenerateHeaders() && CopyMLTFiles())
314
                {
315
                    // in each case errors already emitted
316
                    // copy new MLT files to the build tree as necessary
317
                    rc=generate_build_tree (GetCdlConfig(), ecUtils::UnicodeToStdStr(m_strBuildTree.CygPath()), ecUtils::UnicodeToStdStr(m_strInstallTree.CygPath()));
318
                    rc = TRUE;
319
                }
320
            }
321
            else
322
            {
323
                rc = TRUE;
324
            }
325
        }
326
    }
327
    if(rc)
328
    {
329
        Modify(FALSE);
330
        SetDocumentSaved(TRUE);
331
        SetFilename(filename);
332
        wxGetApp().GetSettings().m_lastFilename = filename;
333
    } else
334
    {
335
        SetFilename(strOldPath);
336
    }
337
    wxGetApp().GetMainFrame()->UpdateFrameTitle();
338
    return rc;
339
}
340
 
341
// Can we generate the build tree yet?
342
bool ecConfigToolDoc::CanGenerateBuildTree()
343
{
344
    if (m_strBuildTree.IsEmpty() || m_strInstallTree.IsEmpty() )
345
        return FALSE;
346
 
347
    int nCount=0;
348
    if (GetCdlConfig ())
349
    {
350
        // calculate the number of conflicts
351
        int nCount = GetCdlConfig ()->get_all_conflicts ().size ();
352
 
353
        if (nCount > 0)
354
            return FALSE;
355
    }
356
    else
357
        return FALSE;
358
 
359
    return TRUE;
360
}
361
 
362
// A standalone method for generating a build tree without saving first
363
bool ecConfigToolDoc::GenerateBuildTree()
364
{
365
    wxBusyCursor wait;
366
    if (CanGenerateBuildTree())
367
    {
368
        ecFileName buildFilename(m_strBuildTree);
369
        ecFileName installFilename(m_strInstallTree);
370
 
371
        if (!buildFilename.EC_CreateDirectory() || !installFilename.EC_CreateDirectory())
372
        {
373
            wxString msg;
374
            msg.Printf(_("Failed to create build tree"));
375
 
376
            wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION);
377
            return FALSE;
378
        }
379
        else if (GenerateHeaders() && CopyMLTFiles())
380
        {
381
            // in each case errors already emitted
382
            // copy new MLT files to the build tree as necessary
383
            bool rc = generate_build_tree (GetCdlConfig(), ecUtils::UnicodeToStdStr(m_strBuildTree.CygPath()), ecUtils::UnicodeToStdStr(m_strInstallTree.CygPath()));
384
            rc = TRUE;
385
        }
386
 
387
    }
388
    else
389
        return FALSE;
390
    return TRUE;
391
}
392
 
393
bool ecConfigToolDoc::OnOpenDocument(const wxString& filename)
394
{
395
    wxGetApp().GetSettings().m_lastFilename = filename;
396
 
397
    wxBusyCursor cursor;
398
 
399
    bool rc=FALSE; // Assume the worst
400
    CdlInterpreter NewCdlInterp = NULL;
401
    CdlConfiguration NewCdlConfig = NULL;
402
 
403
    // We have to open the repository or m_CdlPkgData and co. won't be set
404
    if (!OpenRepository())
405
        return FALSE;
406
 
407
    wxString str;
408
    str.Printf(_("Opening save file %s"), (const wxChar*) filename);
409
    wxGetApp().SetStatusText(str);
410
 
411
    EnableCallbacks(FALSE);
412
 
413
    try
414
    {
415
        NewCdlInterp = CdlInterpreterBody::make ();
416
        NewCdlConfig = CdlConfigurationBody::load ((const wxChar*) filename, m_CdlPkgData, NewCdlInterp, &CdlLoadErrorHandler, &CdlLoadWarningHandler);
417
        rc = TRUE;
418
    }
419
    catch (CdlStringException exception)
420
    {
421
        wxString msg;
422
        msg.Printf(_("Error opening eCos configuration:\n\n%s"), exception.get_message ().c_str ());
423
        wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK);
424
    }
425
    catch (...)
426
    {
427
        wxString msg;
428
        msg.Printf(_("Error opening eCos configuration"));
429
        wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK);
430
    }
431
 
432
    if (rc)
433
    {
434
        rc=FALSE;
435
        // check the new configuration
436
 
437
        wxASSERT (NewCdlConfig->check_this (cyg_extreme));
438
 
439
        // switch to the new configuration
440
 
441
        delete m_CdlConfig;
442
        delete m_CdlInterp;
443
        m_CdlInterp = NewCdlInterp;
444
        m_CdlConfig = NewCdlConfig;
445
        //SetPathName (lpszPathName, TRUE); // called to ensure that MLTDir() will work in this function
446
 
447
        AddAllItems (); // must precede NewMemoryLayout() [CurrentLinkerScript() calls Find()]
448
 
449
        // load the memory layout from the build tree
450
        // TODO
451
        NewMemoryLayout (MLTDir ());
452
 
453
        UpdateFailingRuleCount();
454
 
455
        SetFilename(filename);
456
 
457
        // UpdateBuildInfo(); // Don't create directories on opening file
458
 
459
        rc = TRUE;
460
 
461
 
462
        ecConfigToolHint hint(NULL, ecFilenameChanged);
463
        UpdateAllViews (NULL, & hint);
464
    }
465
 
466
    // re-enable the transaction callback
467
    EnableCallbacks(TRUE);
468
 
469
    SetDocumentSaved(TRUE); // Necessary or it will pop up the Save As dialog
470
 
471
    wxGetApp().SetStatusText(wxEmptyString, FALSE);
472
 
473
    return rc;
474
}
475
 
476
void ecConfigToolDoc::AddAllItems()
477
{
478
    ecConfigTreeCtrl* treeCtrl = wxGetApp().GetMainFrame()->GetTreeCtrl();
479
    // Ensure there's no dangling pointer
480
    wxGetApp().GetMainFrame()->GetPropertyListWindow()->Fill(NULL);
481
 
482
    treeCtrl->DeleteAllItems();
483
    DeleteItems();
484
 
485
    m_strMemoryLayoutFolder = wxT("");
486
    m_strLinkerScriptFolder = wxT("");
487
 
488
    // Add the root item
489
    ecConfigItem* item = NULL;
490
    wxTreeItemId rootId = treeCtrl->AddRoot(_(""), -1, -1, new ecTreeItemData(item = new ecConfigItem(NULL, _("Configuration"), ecContainer)));
491
    item->SetTreeItem(rootId);
492
    item->UpdateTreeItem(* treeCtrl);
493
    item->SetDescription(_("The root node for all configurable items"));
494
    m_items.Append(item);
495
 
496
    AddContents(m_CdlConfig, item);
497
    treeCtrl->Expand(rootId);
498
 
499
    // check that exactly one radio button in each group is enabled
500
    CheckRadios ();
501
 
502
    // update the rules (conflicts) view
503
    UpdateFailingRuleCount ();
504
 
505
    if( ! wxGetApp().GetMainFrame() || ! wxGetApp().GetMainFrame()->GetConflictsWindow() ||
506
        ! wxGetApp().GetMainFrame()->GetConflictsWindow()->IsShown())
507
    {
508
        // log all conflicts
509
        //      LogConflicts (m_CdlConfig->get_structural_conflicts ()); // relating to package availability - ignore for now
510
        LogConflicts (m_CdlConfig->get_all_conflicts ());
511
    }
512
 
513
    wxGetApp().GetTreeCtrl()->SelectItem(wxGetApp().GetTreeCtrl()->GetRootItem());
514
    //ecConfigToolHint hint(item, ecValueChanged);
515
    ecConfigToolHint hint(NULL, ecSelChanged);
516
 
517
    UpdateAllViews (NULL, & hint);
518
 
519
#if wxCHECK_VERSION(2, 6, 0)
520
    if(GetItems().GetCount() > 0)
521
#else
522
    if(GetItems().Number() > 0)
523
#endif
524
        {
525
        wxGetApp().GetTreeCtrl()->Expand(rootId);
526
    }
527
    wxGetApp().GetTreeCtrl()->SetFocus();
528
}
529
 
530
void ecConfigToolDoc::AddContents (const CdlContainer container, ecConfigItem *pParent)
531
{
532
    // determine the container contents
533
 
534
    const std::vector<CdlNode>& contents = container->get_contents ();
535
    std::vector<CdlNode>::const_iterator node_i;
536
    for (node_i = contents.begin (); node_i != contents.end (); node_i++)
537
    {
538
        const CdlNode node = * node_i;
539
        const CdlPackage pkg = dynamic_cast<CdlPackage> (node);
540
        const CdlComponent comp = dynamic_cast<CdlComponent> (node);
541
        const CdlOption opt = dynamic_cast<CdlOption> (node);
542
        const CdlContainer contnr = dynamic_cast<CdlContainer> (node);
543
 
544
        // if the node in the container is a package, component or option
545
        // then it is visible and should be added to the tree
546
        if  (0 != pkg) // the node is a package
547
        {
548
            ecConfigItem * pItem = AddItem (pkg, pParent); // add the package
549
            AddContents (pkg, pItem); // add the package contents
550
        }
551
        else if (0 != comp) // the node is a component
552
        {
553
            ecConfigItem * pItem = AddItem (comp, pParent); // add the component
554
            AddContents (comp, pItem); // add the component contents
555
        }
556
        else if (0 != opt) // the node is an option
557
            AddItem (opt, pParent); // add the option
558
 
559
        else if (0 != contnr) // if the node is a container
560
            AddContents (contnr, pParent); // add the container contents
561
 
562
        // ignore nodes of any other class
563
    }
564
}
565
 
566
ecConfigItem * ecConfigToolDoc::AddItem (const CdlUserVisible vitem, ecConfigItem * pParent)
567
{
568
    ecConfigItem * pItem = new ecConfigItem (pParent, vitem);
569
 
570
    m_items.Append(pItem);
571
 
572
    if (vitem->get_name () == "CYGHWR_MEMORY_LAYOUT")
573
    {
574
        wxASSERT (m_strMemoryLayoutFolder.IsEmpty ());
575
        m_strMemoryLayoutFolder = vitem->get_owner ()->get_directory().c_str ();
576
#ifdef __WXMSW__
577
        m_strMemoryLayoutFolder.Replace(wxT("/"),wxT("\\"));
578
#endif
579
        //TRACE (_T("Found memory layout folder: %s\n"), m_strMemoryLayoutFolder);
580
    }
581
 
582
    if (vitem->get_name () == "CYGBLD_LINKER_SCRIPT")
583
    {
584
        wxASSERT (m_strLinkerScriptFolder.IsEmpty ());
585
        m_strLinkerScriptFolder = vitem->get_owner ()->get_directory().c_str ();
586
#ifdef __WXMSW__
587
        m_strLinkerScriptFolder.Replace(wxT("/"),wxT("\\"));
588
#endif
589
        //TRACE (_T("Found linker script folder: %s\n"), m_strLinkerScriptFolder);
590
 
591
        // the CDL hardware template name will eventually become the target name,
592
        // but for now we must deduce the target name from the linker script file name
593
 
594
        const CdlValuable valuable = dynamic_cast<CdlValuable> (vitem);
595
        ecFileName strLinkerScript (m_strPackagesDir, m_strLinkerScriptFolder, wxString (valuable->get_value ().c_str ()));
596
 
597
#ifdef __WXMSW__
598
        strLinkerScript.Replace (wxT("/"), wxT("\\"));
599
#endif
600
 
601
        if(!strLinkerScript.Exists ()){
602
            wxString msg;
603
            msg.Printf(wxT("%s does not exist\n"), (const wxChar*) strLinkerScript);
604
            wxGetApp().Log(msg);
605
        }
606
        //TRACE (_T("Target '%s' selected\n"), strLinkerScript.Tail ().Root (), pItem->Macro());
607
    }
608
 
609
    //TRACE(_T("Created new item from cdl: "));
610
    //pItem->DumpItem();
611
    return pItem;
612
}
613
 
614
void ecConfigToolDoc::CheckRadios()
615
{
616
    int nItem;
617
#if wxCHECK_VERSION(2, 6, 0)
618
    for(nItem=0; nItem < GetItems().GetCount() ; nItem++)
619
#else
620
    for(nItem=0; nItem < GetItems().Number() ; nItem++)
621
#endif
622
    {
623
        ecConfigItem *pItem=(ecConfigItem*) GetItems()[nItem];
624
 
625
        if(pItem->HasRadio () && pItem==pItem->FirstRadio())
626
        {
627
            wxString strMsg;
628
            ecConfigItem *pFirstSet=NULL;
629
            ecConfigItem *pSibItem;
630
 
631
            for ( pSibItem=pItem; pSibItem; pSibItem = pSibItem->NextRadio() )
632
            {
633
                if(pSibItem->IsEnabled ())
634
                {
635
                    if(pFirstSet)
636
                    {
637
                        strMsg += wxT(" ");
638
                        strMsg += pSibItem->GetMacro ();
639
                    } else
640
                    {
641
                        pFirstSet = pSibItem;
642
                    }
643
                }
644
            }
645
 
646
            if ( !strMsg.IsEmpty() )
647
            {
648
                wxString msg2;
649
                msg2.Printf(_("%s, multiple radio buttons are set: %s%s"),
650
                    (const wxChar*) pItem->GetMacro(), (const wxChar*) pFirstSet->GetMacro(), (const wxChar*) strMsg);
651
                wxGetApp().Log(msg2);
652
            } else if ( !pFirstSet )
653
            {
654
                wxString msg2;
655
                msg2.Printf(_("%s, no radio buttons are set"), (const wxChar*) pItem->GetMacro());
656
                wxGetApp().Log(msg2);
657
            }
658
        }
659
    }
660
}
661
 
662
// Find the ecConfigItem referencing the given CdlValuable
663
ecConfigItem * ecConfigToolDoc::Find (CdlValuable v)
664
{
665
    int nItem;
666
#if wxCHECK_VERSION(2, 6, 0)
667
    for (nItem=0 ; nItem < m_items.GetCount() ; nItem++)
668
#else
669
    for (nItem=0 ; nItem < m_items.Number() ; nItem++)
670
#endif
671
    {
672
        ecConfigItem *pItem = (ecConfigItem*) m_items[nItem];
673
        if( v == pItem->GetCdlValuable() )
674
        {
675
            return pItem;
676
        }
677
    }
678
    return NULL;
679
}
680
 
681
ecConfigItem * ecConfigToolDoc::Find(const wxString & strWhat, ecWhereType where)
682
{
683
    int nItem;
684
#if wxCHECK_VERSION(2, 6, 0)
685
    for (nItem=0 ; nItem < m_items.GetCount() ; nItem++)
686
#else
687
    for (nItem=0 ; nItem < m_items.Number() ; nItem++)
688
#endif
689
    {
690
        ecConfigItem *pItem = (ecConfigItem*) m_items[nItem];
691
        if (pItem->StringValue(where) == strWhat)
692
        {
693
            return pItem;
694
        }
695
    }
696
    return NULL;
697
}
698
 
699
// a trivial CDL load error handler
700
void ecConfigToolDoc::CdlLoadErrorHandler (std::string message)
701
{
702
    wxGetApp().Log(message.c_str());
703
};
704
 
705
// a trivial CDL load warning handler
706
void ecConfigToolDoc::CdlLoadWarningHandler (std::string message)
707
{
708
    wxGetApp().Log(message.c_str());
709
};
710
 
711
// a trivial CDL parse error handler
712
void ecConfigToolDoc::CdlParseErrorHandler (std::string message)
713
{
714
    wxGetApp().Log(message.c_str());
715
};
716
 
717
// a trivial CDL parse warning handler
718
void ecConfigToolDoc::CdlParseWarningHandler (std::string message)
719
{
720
    wxGetApp().Log(message.c_str());
721
};
722
 
723
 
724
void ecConfigToolDoc::CloseRepository()
725
{
726
    if(m_bRepositoryOpen){
727
        // delete the libCDL objects with the document
728
        EnableCallbacks(FALSE); // first disable the transaction handler
729
        delete m_CdlConfig; m_CdlConfig = NULL;
730
        delete m_CdlInterp; m_CdlInterp = NULL;
731
        delete m_CdlPkgData; m_CdlPkgData = NULL;
732
        m_bRepositoryOpen=FALSE;
733
    }
734
}
735
 
736
bool ecConfigToolDoc::OpenRepository(const wxString& pszRepository /* = wxEmptyString */, bool bPromptInitially/* =FALSE */)
737
{
738
    ecMainFrame* mainFrame = wxGetApp().GetMainFrame();
739
    if(!m_bRepositoryOpen)
740
    {
741
        UpdateFailingRuleCount();
742
 
743
        ecFileName strNewRepository;
744
        while(!m_bRepositoryOpen)
745
        {
746
            if(bPromptInitially)
747
            {
748
                ecChooseRepositoryDialog dlg(wxGetApp().GetTopWindow());
749
 
750
                if(wxID_CANCEL==dlg.ShowModal()){
751
                    wxGetApp().SetStatusText(wxEmptyString);
752
                    return FALSE;
753
                }
754
#ifdef __WXMSW__
755
                // Ensure display gets updated
756
                ::UpdateWindow((HWND) mainFrame->GetHWND());
757
                //wxYield();
758
#endif
759
                strNewRepository=dlg.GetFolder();
760
            } else
761
            {
762
                // Use what came in as parameter or what was found in registry
763
                if (!pszRepository.IsEmpty())
764
                    strNewRepository = pszRepository;
765
                else
766
                    strNewRepository = m_strRepository;
767
 
768
                bPromptInitially=TRUE;
769
            }
770
            wxString str;
771
            if (strNewRepository.IsEmpty())
772
                str.Printf(_("Opening repository..."));
773
            else
774
                str.Printf(_("Opening repository %s..."), (const wxChar*) strNewRepository);
775
            wxGetApp().SetStatusText(str);
776
 
777
            CdlPackagesDatabase NewCdlPkgData = NULL;
778
            CdlInterpreter      NewCdlInterp  = NULL;
779
            CdlConfiguration    NewCdlConfig  = NULL;
780
            wxString strNewPackagesDir;
781
 
782
            EnableCallbacks(FALSE); // disable transaction callbacks until the config tree is regenerated
783
 
784
            wxBusyCursor wait;
785
            if(OpenRepository(strNewRepository,NewCdlPkgData,NewCdlInterp,NewCdlConfig,strNewPackagesDir))
786
            {
787
                // select the "default" template if it exists
788
                // otherwise select the first available template
789
 
790
                std::string default_template = "default";
791
                if (! NewCdlPkgData->is_known_template (default_template))
792
                {
793
                    const std::vector<std::string>& templates = NewCdlPkgData->get_templates ();
794
                    if (templates.size () != 0)
795
                        default_template = templates [0];
796
                }
797
 
798
                m_templateVersion = "";
799
                try
800
                {
801
                    const std::vector<std::string>& template_versions = NewCdlPkgData->get_template_versions (default_template);
802
                    NewCdlConfig->set_template (default_template, template_versions [0], &CdlParseErrorHandler, &CdlParseWarningHandler);
803
                    m_templateVersion = template_versions [0].c_str();
804
                }
805
                catch (CdlStringException exception) {
806
                    wxString msg;
807
                    msg.Printf(_("Error loading package template '%s':\n\n%s"), default_template.c_str (), exception.get_message ().c_str ());
808
                    wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK);
809
                }
810
                catch (...) {
811
                    wxString msg;
812
                    msg.Printf(_("Error loading package template '%s'."), default_template.c_str ());
813
                    wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK);
814
                }
815
 
816
                // check the configuration
817
                wxASSERT (NewCdlConfig->check_this (cyg_extreme));
818
 
819
                // use the new package database, interpreter and configuration
820
                delete m_CdlConfig; // delete the previous configuration
821
                delete m_CdlInterp; // delete the previous interpreter
822
                delete m_CdlPkgData; // delete the previous package database
823
 
824
                m_CdlPkgData = NewCdlPkgData;
825
                m_CdlInterp  = NewCdlInterp;
826
                m_CdlConfig  = NewCdlConfig;
827
 
828
                // save the repository location
829
 
830
                SetRepository(strNewRepository);
831
                m_strPackagesDir = strNewPackagesDir;
832
 
833
                // clear the previously specified document file name (if any),
834
                // OnNewDocument() calls DeleteContents() so must be called
835
                // before AddAllItems()
836
 
837
                wxDocument::OnNewDocument ();
838
 
839
                // generate the CConfigItems from their CDL descriptions
840
                AddAllItems ();
841
 
842
                m_bRepositoryOpen=TRUE;
843
 
844
                // Rebuild help index if it needs building
845
                RebuildHelpIndex(FALSE);
846
 
847
            } else {
848
                // failure
849
                delete NewCdlConfig; NewCdlConfig = NULL;
850
                delete NewCdlInterp; NewCdlInterp = NULL;
851
                delete NewCdlPkgData; NewCdlPkgData = NULL;
852
 
853
            }
854
 
855
            // install a transaction handler callback function now that the tree exists
856
            EnableCallbacks(TRUE);
857
        }
858
 
859
    }
860
    wxGetApp().SetStatusText(wxEmptyString, FALSE);
861
    return m_bRepositoryOpen;
862
}
863
 
864
// Find a valid repository given a directory name
865
bool ecConfigToolDoc::FindRepository (ecFileName& repositoryIn, ecFileName& repositoryOut) const
866
{
867
    if (repositoryIn.IsEmpty())
868
        return FALSE;
869
 
870
    if (ecFileName(repositoryIn + wxT("ecos.db")).Exists())
871
    {
872
        repositoryOut = repositoryIn;
873
        repositoryIn = wxPathOnly(repositoryIn);
874
        return TRUE;
875
    }
876
    else if (ecFileName(ecFileName(repositoryIn) + ecFileName(wxT("ecc")) + wxT("ecos.db")).Exists())
877
    {
878
        repositoryOut = repositoryIn + wxT("ecc");
879
        return TRUE;
880
    }
881
    else if (ecFileName(ecFileName(repositoryIn) + ecFileName(wxT("packages")) + wxT("ecos.db")).Exists())
882
    {
883
        repositoryOut = repositoryIn + wxT("packages");
884
        return TRUE;
885
    }
886
    else
887
    {
888
        return FALSE;
889
    }
890
}
891
 
892
 
893
bool ecConfigToolDoc::OpenRepository (ecFileName& strNewRepository, CdlPackagesDatabase &NewCdlPkgData,CdlInterpreter &NewCdlInterp,CdlConfiguration &NewCdlConfig, wxString &strNewPackagesDir)
894
{
895
    bool rc=FALSE;
896
 
897
    if (strNewRepository.IsEmpty())
898
        return FALSE;
899
 
900
    ecFileName strNewPackagesDir1;
901
    if (!FindRepository(strNewRepository, strNewPackagesDir1))
902
    {
903
        wxString msg;
904
        msg.Printf(_("%s does not seem to be a source repository."),
905
                    (const wxChar*) strNewRepository);
906
        wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK);
907
    } else
908
    {
909
                strNewPackagesDir = strNewPackagesDir1;
910
 
911
                const wxString strDatabase = strNewPackagesDir + wxString(wxFILE_SEP_PATH) + wxT("ecos.db");
912
                if(!wxFileExists(strDatabase))
913
                {
914
                    wxString msg;
915
                    msg.Printf(_("%s does not seem to be a source repository: %s does not exist"), (const wxChar*) strNewRepository, (const wxChar*) strDatabase);
916
                    wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK);
917
                } else
918
                {
919
 
920
                    // create a CDL repository, interpreter and configuration
921
                    try {// create a new package database, interpreter and configuration
922
                        NewCdlPkgData = CdlPackagesDatabaseBody::make ((const wxChar*) ecUtils::NativeToPosixPath(strNewPackagesDir), &CdlParseErrorHandler, &CdlParseWarningHandler);
923
                        NewCdlInterp = CdlInterpreterBody::make ();
924
                        NewCdlConfig = CdlConfigurationBody::make ("eCos", NewCdlPkgData, NewCdlInterp);
925
                    }
926
                    catch (CdlStringException exception)
927
                    {
928
                        wxString msg;
929
                        msg.Printf(_("Error opening eCos repository:\n\n%s"), exception.get_message ().c_str ());
930
                        wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK);
931
                        return FALSE;
932
                    }
933
                    catch (...)
934
                    {
935
                        wxString msg;
936
                        msg.Printf(_("Error opening eCos repository."));
937
                        wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK);
938
                        return FALSE;
939
                    }
940
 
941
                    // select the default target if specified in the registry
942
                    // otherwise select the first available target
943
                    wxString default_hardware = GetDefaultHardware ();
944
 
945
                    if (! NewCdlPkgData->is_known_target ((const wxChar*) default_hardware)) {
946
                        const std::vector<std::string>& targets = NewCdlPkgData->get_targets ();
947
                        if (targets.size () == 0)
948
                        {
949
                            wxString msg;
950
                            msg.Printf(_("Error opening eCos repository:\n\nno hardware templates"));
951
                            wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK);
952
                            return FALSE;
953
                        } else {
954
                            default_hardware = targets [0].c_str();
955
                        }
956
                    }
957
 
958
                    try {
959
                        m_strCdlErrorMessage = wxT("");
960
                        NewCdlConfig->set_hardware ((const wxChar*) default_hardware, &CdlParseErrorHandler, &CdlParseWarningHandler);
961
                    }
962
                    catch (CdlStringException exception) {
963
                        if (m_strCdlErrorMessage.IsEmpty ())
964
                        {
965
                            wxString msg;
966
                            msg.Printf(_("Error loading the default hardware template '%s':\n\n%s"), default_hardware.c_str (), exception.get_message ().c_str ());
967
                            wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK);
968
                        }
969
                        else // report the most recent parser message in the message box since there may be no output pane in which to view it
970
                        {
971
                            wxString msg;
972
                            msg.Printf(_("Error loading the default hardware template '%s':\n\n%s\n\nParser message:\n\n%s"), default_hardware.c_str (), exception.get_message ().c_str (), (const wxChar*) m_strCdlErrorMessage);
973
                            wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK);
974
                        }
975
                        return FALSE;
976
                    }
977
                    catch (...) {
978
                        wxString msg;
979
                        msg.Printf(_("Error loading the default hardware template '%s':\n\n%s"), default_hardware.c_str (), (const wxChar*) m_strCdlErrorMessage);
980
                        wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK);
981
                        return FALSE;
982
                    }
983
                    rc=TRUE;
984
                }
985
    }
986
 
987
    return rc;
988
}
989
 
990
void ecConfigToolDoc::SelectTemplate (const wxString& newTemplate, const wxString& newTemplateVersion)
991
{
992
    if ((newTemplate != m_CdlConfig->get_template().c_str()) || (newTemplateVersion != m_templateVersion)){
993
 
994
        wxBusyCursor wait; // this may take a little while
995
        DeleteItems();
996
 
997
        m_templateVersion = wxT("");
998
        try
999
        {
1000
            m_CdlConfig->set_template (newTemplate.c_str(), newTemplateVersion.c_str(), CdlParseErrorHandler, CdlParseWarningHandler);
1001
            m_templateVersion = newTemplateVersion;
1002
        }
1003
        catch (CdlStringException exception)
1004
        {
1005
            wxString msg;
1006
            msg.Printf(wxT("Error loading package template '%s':\n\n%s"), (const wxChar*) newTemplate.c_str (), (const wxChar*) exception.get_message ().c_str ());
1007
            wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK);
1008
        }
1009
        catch (...)
1010
        {
1011
            wxString msg;
1012
            msg.Printf(wxT("Error loading package template '%s'."), (const wxChar*) newTemplate.c_str ());
1013
            wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK);
1014
        }
1015
        RegenerateData();
1016
 
1017
        if (!GetFilename().IsEmpty())
1018
        { // not a new document
1019
#if 0 // TODO
1020
            CopyMLTFiles (); // copy new MLT files to the build tree as necessary
1021
#endif
1022
        }
1023
        Modify(TRUE);
1024
        wxGetApp().GetMainFrame()->UpdateFrameTitle();
1025
    }
1026
}
1027
 
1028
void ecConfigToolDoc::RegenerateData()
1029
{
1030
    wxBusyCursor wait; // This may take a little while
1031
    AddAllItems (); // regenerate all the config items since the topology may have changed
1032
    if (m_strLinkerScriptFolder.IsEmpty ())
1033
    {
1034
        wxMessageBox(_("The eCos linker script macro CYGBLD_LINKER_SCRIPT is not defined."), wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK);
1035
    }
1036
    if (m_strMemoryLayoutFolder.IsEmpty ())
1037
    {
1038
        wxMessageBox(_("The eCos memory layout macro CYGHWR_MEMORY_LAYOUT is not defined."), wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK);
1039
    }
1040
    // TODO
1041
#if 0
1042
    SwitchMemoryLayout (TRUE); // the hardware template may have changed
1043
#endif
1044
 
1045
    if (GetDocumentSaved() && !wxGetApp().GetSettings().m_editSaveFileOnly)
1046
        UpdateBuildInfo();
1047
 
1048
    // TODO
1049
    // CConfigTool::GetControlView()->SelectItem(Item(0));
1050
}
1051
 
1052
void ecConfigToolDoc::SelectHardware (const wxString& newTemplate)
1053
{
1054
    const std::string OldTemplate=m_CdlConfig->get_hardware();
1055
    if (newTemplate != OldTemplate.c_str()){
1056
        DeleteItems();
1057
 
1058
        try
1059
        {
1060
            m_CdlConfig->set_hardware (newTemplate.c_str(), CdlParseErrorHandler, CdlParseWarningHandler);
1061
        }
1062
        catch (CdlStringException exception)
1063
        {
1064
            wxString msg;
1065
            msg.Printf(_("Error loading hardware template '%s':\n\n%s"), (const wxChar*) newTemplate, (const wxChar*) exception.get_message ().c_str ());
1066
            wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK);
1067
            m_CdlConfig->set_hardware (OldTemplate, CdlParseErrorHandler, CdlParseWarningHandler);
1068
        }
1069
        catch (...)
1070
        {
1071
            wxString msg;
1072
            msg.Printf(_("Error loading hardware template '%s'."), (const wxChar*) newTemplate);
1073
            wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK);
1074
            m_CdlConfig->set_hardware (OldTemplate, CdlParseErrorHandler, CdlParseWarningHandler);
1075
        }
1076
 
1077
        RegenerateData();
1078
 
1079
        // TODO
1080
#if 0
1081
        if (!GetFilename().IsEmpty())
1082
        {
1083
            CopyMLTFiles (); // copy new MLT files to the build tree as necessary
1084
        }
1085
#endif
1086
 
1087
        Modify(TRUE);
1088
        wxGetApp().GetMainFrame()->UpdateFrameTitle();
1089
    }
1090
}
1091
 
1092
void ecConfigToolDoc::SelectPackages ()
1093
{
1094
    // Crashes the Cygwin 1.0 compiler
1095
#ifndef __CYGWIN10__
1096
    ecPackagesDialog dlg(wxGetApp().GetTopWindow());
1097
 
1098
    // This map holds the ecConfigItem pointers for the packages loaded before the dialog is invoked.
1099
    // We cannot use Find(), which traverses all items - potentially those that have been removed
1100
    wxHashTable arLoadedPackages(wxKEY_STRING);
1101
 
1102
    wxBeginBusyCursor();
1103
 
1104
    // generate the contents of the add/remove list boxes
1105
    const std::vector<std::string> & packages = m_CdlPkgData->get_packages ();
1106
    std::vector<std::string>::const_iterator package_i;
1107
    for (package_i = packages.begin (); package_i != packages.end (); package_i++)
1108
    {
1109
        //              if (! m_CdlPkgData->is_hardware_package (* package_i)) // do not list hardware packages
1110
        {
1111
            const std::vector<std::string> & aliases = m_CdlPkgData->get_package_aliases (* package_i);
1112
            wxString strMacroName = package_i->c_str ();
1113
 
1114
            // use the first alias (if any) as the package identifier
1115
            wxString strPackageName = aliases.size () ? aliases [0].c_str () : strMacroName.c_str();
1116
            ecConfigItem * pItem = Find (strMacroName);
1117
            if (pItem) // if the package is loaded
1118
            {
1119
                arLoadedPackages.Put(strMacroName, pItem);
1120
                // pass the currently selected package version string to the dialog box
1121
                const CdlValuable valuable = pItem->GetCdlValuable();
1122
                dlg.Insert (strPackageName, TRUE, wxEmptyString, valuable ? wxString (valuable->get_value ().c_str ()) : wxString());
1123
            }
1124
            else
1125
            {
1126
                // pass version string of the most latest version to the dialog box
1127
                dlg.Insert (strPackageName, FALSE, wxEmptyString, wxString (m_CdlPkgData->get_package_versions (* package_i) [0].c_str ()));
1128
            }
1129
        }
1130
    }
1131
 
1132
    wxEndBusyCursor();
1133
 
1134
    if (wxID_OK == dlg.ShowModal ())
1135
    {
1136
        bool bChanged = FALSE; // until proved otherwise
1137
 
1138
        // determine whether each package has changed loaded/unloaded state
1139
        for (package_i = packages.begin (); package_i != packages.end (); package_i++)
1140
            //                  if (! m_CdlPkgData->is_hardware_package (* package_i)) // do not check hardware packages
1141
        {
1142
            const std::vector<std::string> & aliases = m_CdlPkgData->get_package_aliases (* package_i);
1143
            wxString strMacroName = package_i->c_str ();
1144
 
1145
            // use the first alias (if any) as the package identifier
1146
            wxString strPackageName = aliases.size () ? aliases [0].c_str () : strMacroName.c_str();
1147
 
1148
            ecConfigItem *pItem = (ecConfigItem *) arLoadedPackages.Get(strMacroName);
1149
            //bool bPreviouslyLoaded=arLoadedPackages.Lookup(strMacroName,(void *&)pItem);
1150
            bool bPreviouslyLoaded = (pItem != NULL);
1151
            bool bNowLoaded=dlg.IsAdded (strPackageName);
1152
 
1153
            // unload packages which are no longer required before
1154
            // loading new ones to avoid potential duplicate macro definitions
1155
            if (! bNowLoaded && bPreviouslyLoaded){
1156
                // The package was loaded but should now be unloaded:
1157
                bChanged|=pItem->Unload();
1158
                delete pItem;
1159
            } else if (bNowLoaded) {// if the package should be loaded
1160
                const wxString strVersion(dlg.GetVersion (strPackageName));
1161
                if (bPreviouslyLoaded) { // if the package is already loaded
1162
                    CdlTransactionCallback::set_callback_fn (NULL); // avoid value refresh attempts during load/unload
1163
                    bChanged|=pItem->ChangeVersion(strVersion);
1164
                    CdlTransactionCallback::set_callback_fn (CdlTransactionHandler); // restore value refresh
1165
                } else {
1166
                    // the package was not loaded but should now be loaded
1167
                    //TRACE (_T("Loading package %s\n"), strMacroName);
1168
                    try
1169
                    {
1170
                        GetCdlConfig()->load_package (ecUtils::UnicodeToStdStr(strMacroName), ecUtils::UnicodeToStdStr (strVersion), ecConfigToolDoc::CdlParseErrorHandler, ecConfigToolDoc::CdlParseWarningHandler);
1171
                        bChanged=true;
1172
                    }
1173
                    catch (CdlStringException exception)
1174
                    {
1175
                        wxString msg;
1176
                        msg.Printf(_("Error loading package %s:\n\n%s"), (const wxChar*) strMacroName, (const wxChar*) exception.get_message ().c_str ());
1177
                        wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK);
1178
                    }
1179
                    catch (...)
1180
                    {
1181
                        wxString msg;
1182
                        msg.Printf(_("Error loading package %s"), (const wxChar*) strMacroName);
1183
                        wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK);
1184
                    }
1185
                }
1186
            }
1187
        }
1188
 
1189
        if (bChanged) {// at least one package was loaded, unloaded or changed version
1190
            Modify(TRUE);
1191
            wxGetApp().GetMainFrame()->UpdateFrameTitle();
1192
            RegenerateData();
1193
        }
1194
    }
1195
#endif
1196
}
1197
 
1198
 
1199
bool ecConfigToolDoc::UpdateBuildInfo(bool WXUNUSED(bFirstTime))
1200
{
1201
    try {
1202
        GetCdlConfig()->get_build_info(m_BuildInfo);
1203
        generate_build_tree (GetCdlConfig(), ecUtils::UnicodeToStdStr(GetBuildTree()), ecUtils::UnicodeToStdStr(GetInstallTree()));
1204
        return TRUE;
1205
    }
1206
    catch(...){
1207
        return FALSE;
1208
    }
1209
}
1210
 
1211
wxString ecConfigToolDoc::GetDefaultHardware ()
1212
{
1213
#ifdef __WXMSW__
1214
    // get the greatest eCos version subkey
1215
    wxConfig config(wxT("eCos"), wxEmptyString, wxEmptyString, wxEmptyString, wxCONFIG_USE_GLOBAL_FILE);
1216
 
1217
    wxString versionKey(wxT(""));
1218
    wxString key(wxT(""));
1219
    long index;
1220
    bool bMore = config.GetFirstGroup(key, index);
1221
    while (bMore)
1222
    {
1223
        if (wxIsdigit(key.GetChar(0)) && versionKey.CompareTo(key) < 0)
1224
            versionKey = key;
1225
 
1226
        bMore = config.GetNextGroup(key, index);
1227
    }
1228
 
1229
    if (!versionKey.IsEmpty())
1230
    {
1231
        wxString defaultHardware;
1232
        wxString defaultHardwareKey(versionKey + wxString(wxT("/")) + wxString(wxT("Default Hardware")));
1233
        if (config.Read(defaultHardwareKey, & defaultHardware))
1234
        {
1235
            return defaultHardware;
1236
        }
1237
    }
1238
    return wxEmptyString;
1239
#else
1240
    // For other platforms, simply rely on Cdl to get the default hardware.
1241
    return wxEmptyString;
1242
#endif
1243
}
1244
 
1245
void ecConfigToolDoc::EnableCallbacks (bool bEnable/*=TRUE*/)
1246
{
1247
    CdlTransactionCallback::set_callback_fn(bEnable?&CdlTransactionHandler:0);
1248
    CdlTransactionBody::set_inference_callback_fn(bEnable?&CdlInferenceHandler:0);
1249
    CdlTransactionBody::set_inference_override(CdlValueSource_Invalid);
1250
}
1251
 
1252
CdlInferenceCallbackResult ecConfigToolDoc::CdlGlobalInferenceHandler(CdlTransaction transaction)
1253
{
1254
    CdlInferenceCallbackResult rc=CdlInferenceCallbackResult_Continue;
1255
 
1256
    ecConfigToolDoc *pDoc = wxGetApp().GetConfigToolDoc();
1257
    pDoc->m_ConflictsOutcome=NotDone;  // prepare for the case that there are no solutions
1258
 
1259
    const std::list<CdlConflict>& conflicts=pDoc->GetCdlConfig()->get_all_conflicts();
1260
    ecResolveConflictsDialog dlg(wxGetApp().GetTopWindow(), conflicts, transaction, &pDoc->m_arConflictsOfInterest);
1261
 
1262
    rc = (wxID_OK == dlg.ShowModal()) ? CdlInferenceCallbackResult_Continue:CdlInferenceCallbackResult_Cancel;
1263
    pDoc->m_ConflictsOutcome=(CdlInferenceCallbackResult_Continue==rc)?OK:Cancel;
1264
 
1265
    return rc;
1266
}
1267
 
1268
CdlInferenceCallbackResult ecConfigToolDoc::CdlInferenceHandler (CdlTransaction transaction)
1269
{
1270
    CdlInferenceCallbackResult rc=CdlInferenceCallbackResult_Continue;
1271
 
1272
    ecConfigToolDoc *pDoc=wxGetApp().GetConfigToolDoc();
1273
    const std::list<CdlConflict>&conflicts=transaction->get_new_conflicts();
1274
    if ((wxGetApp().GetSettings().m_nRuleChecking & ecSettings::Immediate) && conflicts.size()>0)
1275
    {
1276
        if (wxGetApp().GetSettings().m_nRuleChecking & ecSettings::SuggestFixes)
1277
        {
1278
            std::list<CdlConflict> s_conflicts;
1279
            for (std::list<CdlConflict>::const_iterator conf_i= conflicts.begin (); conf_i != conflicts.end (); conf_i++) { // for each conflict
1280
                if((*conf_i)->has_known_solution()){
1281
                    s_conflicts.push_back(*conf_i);
1282
                }
1283
            }
1284
            if(s_conflicts.size()>0)
1285
            {
1286
                wxGetApp().LockValues();
1287
 
1288
                ecResolveConflictsDialog dlg(wxGetApp().GetTopWindow(), s_conflicts, transaction);
1289
                int ret = dlg.ShowModal() ;
1290
 
1291
                wxGetApp().UnlockValues();
1292
 
1293
                return (wxID_OK == ret ? CdlInferenceCallbackResult_Continue:CdlInferenceCallbackResult_Cancel);
1294
            }
1295
        }
1296
 
1297
        wxGetApp().LockValues();
1298
 
1299
        wxString strMsg;
1300
        if(1==conflicts.size()){
1301
            strMsg=wxT("There is 1 unresolved conflict. Make the change anyway?");
1302
        } else {
1303
            strMsg.Printf(_("There are %d unresolved conflict%s. Make the change anyway?"), conflicts.size(), (const wxChar*) (1==conflicts.size()? wxT(""):wxT("s")) );
1304
        }
1305
        rc = (wxYES == wxMessageBox(strMsg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxYES_NO)) ? CdlInferenceCallbackResult_Continue:CdlInferenceCallbackResult_Cancel;
1306
 
1307
        wxGetApp().UnlockValues();
1308
 
1309
    }
1310
    return rc;
1311
}
1312
 
1313
 
1314
// a CDL transaction handler to refresh the configuration tree
1315
void ecConfigToolDoc::CdlTransactionHandler (const CdlTransactionCallback & data)
1316
{
1317
    static int nNesting=0;
1318
    //TRACE(_T("Transaction handler: nesting level=%d\n"),nNesting++);
1319
    ecConfigToolDoc *pDoc = wxGetApp().GetConfigToolDoc();
1320
 
1321
    std::vector<CdlValuable>::const_iterator val_i;
1322
    std::vector<CdlNode>::const_iterator node_i;
1323
    std::list<CdlConflict>::const_iterator conf_i;
1324
    ecConfigToolView *pControlView = (ecConfigToolView*) pDoc->GetFirstView();
1325
 
1326
    for (val_i = data.value_changes.begin(); val_i != data.value_changes.end(); val_i++)
1327
    {
1328
        const wxString strName((*val_i)->get_name().c_str());
1329
        //TRACE(_T("%s %s : value change\n"), wxString ((*val_i)->get_class_name().c_str()), strName);
1330
        pControlView->Refresh(strName);
1331
        if (strName==wxT("CYGHWR_MEMORY_LAYOUT")){               // the memory layout has changed...
1332
            // TODO
1333
            // pDoc->SwitchMemoryLayout (FALSE); // ...so display a new one
1334
        }
1335
    }
1336
    for (node_i = data.active_changes.begin(); node_i != data.active_changes.end(); node_i++)
1337
    {
1338
        const wxString strName((*node_i)->get_name().c_str());
1339
        //TRACE(_T("%s %s : this has become active or inactive\n"), CString ((*node_i)->get_class_name().c_str()),
1340
        //    CString ((*node_i)->get_name().c_str()));
1341
        if (! dynamic_cast<CdlInterface> (*node_i)){ // if not an interface node
1342
            pControlView->Refresh(strName);
1343
        }
1344
    }
1345
    for (val_i = data.legal_values_changes.begin(); val_i != data.legal_values_changes.end(); val_i++)
1346
    {
1347
        const wxString strName((*node_i)->get_class_name().c_str());
1348
        //TRACE(_T("%s %s : the legal_values list has changed, a new widget may be needed.\n"),
1349
        //    CString ((*val_i)->get_class_name().c_str()), strName);
1350
    }
1351
 
1352
    for (val_i = data.value_source_changes.begin(); val_i != data.value_source_changes.end(); val_i++)
1353
    {
1354
        const wxString strName((*val_i)->get_name().c_str());
1355
        CdlValueSource source = (*val_i)->get_source();
1356
/*
1357
        TRACE(_T("%s %s : the value source has changed to %s\n"),
1358
            CString ((*val_i)->get_class_name().c_str()), strName,
1359
            CString ((CdlValueSource_Default  == source) ? "default"  :
1360
        (CdlValueSource_Inferred == source) ? "inferred" :
1361
        (CdlValueSource_Wizard   == source) ? "wizard"   : "user"));
1362
*/
1363
        pControlView->Refresh (strName);
1364
    }
1365
 
1366
    pDoc->UpdateFailingRuleCount();
1367
    nNesting--;
1368
}
1369
 
1370
bool ecConfigToolDoc::ShowURL(const wxString& strURL1)
1371
{
1372
    bool rc = TRUE;
1373
 
1374
    wxString strURL(strURL1);
1375
 
1376
/*
1377
    if(!QualifyDocURL(strURL)){
1378
        return FALSE; // error message already output
1379
    }
1380
*/
1381
 
1382
    switch (wxGetApp().GetSettings().m_eUseCustomBrowser)
1383
    {
1384
    case ecInternal:
1385
        rc = ShowInternalHtmlHelp(strURL);
1386
        break;
1387
    case ecAssociatedExternal:
1388
        {
1389
            QualifyDocURL(strURL, FALSE);
1390
            rc = ShowExternalHtmlHelp(strURL);
1391
        }
1392
 
1393
        break;
1394
    case ecCustomExternal:
1395
        QualifyDocURL(strURL, FALSE);
1396
        wxGetApp().Launch(strURL, wxGetApp().GetSettings().m_strBrowser);
1397
        break;
1398
    default:
1399
        wxASSERT(FALSE);
1400
    }
1401
    return rc;
1402
}
1403
 
1404
bool ecConfigToolDoc::ShowExternalHtmlHelp (const wxString& strURL)
1405
{
1406
#if defined(__WXMSW__) || defined(__WXGTK__)
1407
 
1408
    wxString url;
1409
 
1410
#ifdef __WXMSW__
1411
    wxString sep(wxT("\\"));
1412
#else
1413
    wxString sep(wxFILE_SEP_PATH);
1414
#endif
1415
    wxString docDir(wxString(m_strRepository) + sep + wxString(wxT("doc")));
1416
    if (wxDirExists(docDir + sep + wxT("html")))
1417
        docDir += sep + wxT("html") ;
1418
 
1419
    if (strURL.Left(7) == wxT("http://") || strURL.Left(7) == wxT("file://"))
1420
        url = strURL;
1421
    else
1422
    {
1423
        if (wxIsAbsolutePath(strURL))
1424
            url = strURL;
1425
        else
1426
            url = docDir + sep + strURL;
1427
    }
1428
 
1429
    wxFileType *ft = wxTheMimeTypesManager->GetFileTypeFromExtension(wxT("html"));
1430
    if ( !ft )
1431
    {
1432
        wxLogError(_T("Impossible to determine the file type for extension html"));
1433
        return FALSE;
1434
    }
1435
 
1436
    wxString cmd;
1437
    bool ok = ft->GetOpenCommand(&cmd,
1438
                                 wxFileType::MessageParameters(url, _T("")));
1439
    delete ft;
1440
 
1441
    if (!ok)
1442
    {
1443
        // TODO: some kind of configuration dialog here.
1444
        wxMessageBox(_("Could not determine the command for running the browser."),
1445
                   wxGetApp().GetSettings().GetAppName(), wxOK|wxICON_EXCLAMATION);
1446
        return FALSE;
1447
    }
1448
 
1449
    // Remove spurious file:// if added
1450
#ifdef __WXMSW__
1451
    if (strURL.Left(7) == wxT("http://"))
1452
        cmd.Replace(wxT("file://"), wxT(""));
1453
#endif
1454
 
1455
    ok = (wxExecute(cmd, FALSE) != 0);
1456
 
1457
    return ok;
1458
 
1459
    // Old code using MS HTML Help
1460
#elif 0
1461
    HWND hwndCaller = ::GetDesktopWindow();
1462
 
1463
    wxString helpFile(wxGetApp().GetHelpFile());
1464
    bool rc = FALSE;
1465
    const ecFileName strFile(HTMLHelpLinkFileName());
1466
    if (wxFileExists(strFile))
1467
        wxRemoveFile(strFile);
1468
 
1469
    wxTextFile f(strFile);
1470
    if(!ecFileName(helpFile).Exists())
1471
    {
1472
        wxString msg;
1473
        msg.Printf(_("Cannot display help - %s does not exist"), (const wxChar*) helpFile);
1474
        wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK);
1475
    } else if (!f.Create())
1476
    {
1477
        wxString msg;
1478
        msg.Printf(_("Cannot display help - error creating %s"), (const wxChar*) strFile);
1479
        wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK);
1480
    } else
1481
    {
1482
        wxString str;
1483
        str.Printf(_T("<meta HTTP-EQUIV=\"refresh\" CONTENT=\"0;URL=%s\">"), (const wxChar*) strURL);
1484
        f.AddLine(str);
1485
        f.Write();
1486
        f.Close();
1487
        if(0==HtmlHelp(hwndCaller, wxGetApp().GetHelpFile(), HH_DISPLAY_TOPIC, 0))
1488
        {
1489
            wxString msg;
1490
            msg.Printf(_("Cannot display %s"), (const wxChar*) strURL);
1491
            wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK);
1492
        }
1493
#if 0
1494
        else
1495
        {
1496
            // JACS: I don't think we need to do this. Even on the MFC version, the notification
1497
            // callback didn't do anything interesting.
1498
#define ID_HHNOTIFICATION               55017
1499
 
1500
            // FIXME: Do this the first time only?
1501
            HH_WINTYPE WinType;
1502
            HWND wnd;
1503
            HH_WINTYPE *pWinType=NULL;
1504
            wxString s = wxGetApp().GetHelpFile() + wxT(">mainwin");
1505
            wnd = HtmlHelp(hwndCaller, s, HH_GET_WIN_TYPE, (DWORD) &pWinType);
1506
            WinType=*pWinType;
1507
            WinType.hwndCaller=hwndCaller;
1508
            WinType.fsWinProperties|=HHWIN_PROP_TRACKING;
1509
            WinType.idNotify = ID_HHNOTIFICATION;
1510
            wnd = HtmlHelp(hwndCaller, wxGetApp().GetHelpFile(), HH_SET_WIN_TYPE, (DWORD) &WinType);
1511
            rc = TRUE;
1512
        }
1513
#endif
1514
        //wxRemoveFile(strFile);
1515
    }
1516
    return rc;
1517
 
1518
#else
1519
    wxMessageBox(_("Sorry, ShowHtmlHelp not yet implemented"), wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK);
1520
    return FALSE;
1521
#endif
1522
}
1523
 
1524
bool ecConfigToolDoc::ShowInternalHtmlHelp (const wxString& strURL)
1525
{
1526
#if defined(__WXMSW__) || defined(__WXGTK__)
1527
 
1528
    wxString url(strURL);
1529
 
1530
    wxString sep(wxFILE_SEP_PATH);
1531
    wxString docDir(wxString(m_strRepository) + sep + wxString(wxT("doc")));
1532
    if (wxDirExists(docDir + sep + wxT("html")))
1533
        docDir += sep + wxT("html") ;
1534
 
1535
    url = docDir + sep + ecHtmlIndexer::Redirect(docDir, url);
1536
 
1537
#if 0
1538
    if (strURL.Left(7) == wxT("http://") || strURL.Left(7) == wxT("file://"))
1539
        url = strURL;
1540
    else
1541
        url = docDir + sep + strURL;
1542
#endif
1543
 
1544
    //url = url.Mid(docDir.Length() + 1);
1545
 
1546
    if (wxGetApp().HasHelpController())
1547
    {
1548
        return wxGetApp().GetHelpController().Display(url);
1549
    }
1550
    else
1551
        return FALSE;
1552
 
1553
    // Old code using MS HTML Help
1554
#elif 0
1555
    HWND hwndCaller = ::GetDesktopWindow();
1556
 
1557
    wxString helpFile(wxGetApp().GetHelpFile());
1558
    bool rc = FALSE;
1559
    const ecFileName strFile(HTMLHelpLinkFileName());
1560
    if (wxFileExists(strFile))
1561
        wxRemoveFile(strFile);
1562
 
1563
    wxTextFile f(strFile);
1564
    if(!ecFileName(helpFile).Exists())
1565
    {
1566
        wxString msg;
1567
        msg.Printf(_("Cannot display help - %s does not exist"), (const wxChar*) helpFile);
1568
        wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK);
1569
    } else if (!f.Create())
1570
    {
1571
        wxString msg;
1572
        msg.Printf(_("Cannot display help - error creating %s"), (const wxChar*) strFile);
1573
        wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK);
1574
    } else
1575
    {
1576
        wxString str;
1577
        str.Printf(_T("<meta HTTP-EQUIV=\"refresh\" CONTENT=\"0;URL=%s\">"), (const wxChar*) strURL);
1578
        f.AddLine(str);
1579
        f.Write();
1580
        f.Close();
1581
        if(0==HtmlHelp(hwndCaller, wxGetApp().GetHelpFile(), HH_DISPLAY_TOPIC, 0))
1582
        {
1583
            wxString msg;
1584
            msg.Printf(_("Cannot display %s"), (const wxChar*) strURL);
1585
            wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK);
1586
        }
1587
    }
1588
    return rc;
1589
 
1590
#else
1591
    wxMessageBox(_("Sorry, ShowHtmlHelp not yet implemented"), wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK);
1592
    return FALSE;
1593
#endif
1594
}
1595
 
1596
const wxString ecConfigToolDoc::HTMLHelpLinkFileName()
1597
{
1598
    return ecFileName(wxGetApp().GetHelpFile()).Head() + wxT("link2.htm");
1599
}
1600
 
1601
bool ecConfigToolDoc::QualifyDocURL(wxString &strURL, bool prefix)
1602
{
1603
    if(-1==strURL.Find(wxT("://")))
1604
    {
1605
#ifdef __WXMSW__
1606
        strURL.Replace(wxT("/"), wxT("\\"));
1607
#endif
1608
        wxString originalURL(strURL);
1609
 
1610
        if (! ecFileName (strURL).IsFile ())
1611
        { // if not an absolute filepath
1612
            strURL = GetDocBase () + ecFileName (originalURL); // prepend the doc directory path
1613
        }
1614
        if (!wxFileExists(strURL))
1615
            strURL = GetDocBase() + ecFileName(wxT("html")) + ecFileName(originalURL);
1616
 
1617
        if (prefix)
1618
            strURL = wxT("file://") + strURL;
1619
    }
1620
 
1621
    if(0==strURL.Find(wxT("file://")))
1622
    {
1623
        ecFileName strFile(strURL.Right(strURL.Length()-7));
1624
        int nIndex=strFile.Find(wxT('#'), TRUE);
1625
 
1626
        if ( -1 != nIndex )
1627
        {
1628
            strFile=strFile.Left(nIndex);
1629
        }
1630
#ifdef __WXMSW__
1631
        strFile.Replace(wxT("/"), wxT("\\"));
1632
#endif
1633
 
1634
        if(!strFile.Exists())
1635
        {
1636
            wxString msg;
1637
            msg.Printf(_("Cannot locate the file %s"), (const wxChar*) strFile);
1638
            wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxID_OK);
1639
            return FALSE;
1640
        }
1641
    }
1642
    return TRUE;
1643
}
1644
 
1645
wxString ecConfigToolDoc::GetPackageName (const wxString & strAlias)
1646
{
1647
    const std::vector<std::string> & packages = m_CdlPkgData->get_packages ();
1648
    std::vector<std::string>::const_iterator package_i;
1649
    for (package_i = packages.begin (); package_i != packages.end (); package_i++)
1650
    {
1651
        const std::vector<std::string> & aliases = m_CdlPkgData->get_package_aliases (* package_i);
1652
        wxString strPackageAlias = aliases [0].c_str ();
1653
        if (aliases.size () && (strAlias == strPackageAlias))
1654
            return package_i->c_str ();
1655
    }
1656
    return wxEmptyString;
1657
}
1658
 
1659
const wxString ecConfigToolDoc::GetCurrentTargetPrefix()
1660
{
1661
    ecConfigItem *pItem = Find(wxT("CYGBLD_GLOBAL_COMMAND_PREFIX"));
1662
    if (pItem)
1663
        return pItem->StringValue();
1664
    else
1665
        return wxT("");
1666
}
1667
 
1668
ecConfigToolDoc::GlobalConflictOutcome ecConfigToolDoc::ResolveGlobalConflicts(wxList *parConflictsOfInterest)
1669
{
1670
    m_ConflictsOutcome=NotDone;
1671
    m_arConflictsOfInterest.Clear();
1672
    if(parConflictsOfInterest)
1673
    {
1674
#if wxCHECK_VERSION(2, 6, 0)
1675
        wxNode* node = parConflictsOfInterest->GetFirst();
1676
        while (node)
1677
        {
1678
            wxObject* obj = (wxObject*) node->GetData();
1679
            m_arConflictsOfInterest.Append(obj);
1680
            node = node->GetNext();
1681
        }
1682
#else
1683
        wxNode* node = parConflictsOfInterest->First();
1684
        while (node)
1685
        {
1686
            wxObject* obj = (wxObject*) node->Data();
1687
            m_arConflictsOfInterest.Append(obj);
1688
            node = node->Next();
1689
        }
1690
#endif
1691
    }
1692
    CdlInferenceCallback fn=CdlTransactionBody::get_inference_callback_fn();
1693
    CdlTransactionBody::set_inference_callback_fn(CdlGlobalInferenceHandler);
1694
    GetCdlInterpreter()->get_toplevel()->resolve_all_conflicts();
1695
    CdlTransactionBody::set_inference_callback_fn(fn);
1696
    if(NotDone==m_ConflictsOutcome){
1697
        // No solutions were available, but we'll run the dialog anyway
1698
        const std::list<CdlConflict>& conflicts=GetCdlConfig()->get_all_conflicts();
1699
        ecResolveConflictsDialog dlg(wxGetApp().GetTopWindow(), conflicts, NULL, &m_arConflictsOfInterest);
1700
        m_ConflictsOutcome = (wxID_OK == dlg.ShowModal())?OK:Cancel;
1701
    }
1702
    return m_ConflictsOutcome;
1703
}
1704
 
1705
bool ecConfigToolDoc::CheckConflictsBeforeSave()
1706
{
1707
    if (GetCdlInterpreter()->get_toplevel()->get_all_conflicts().size()>0)
1708
    {
1709
        if(ecSettings::Deferred & wxGetApp().GetSettings().m_nRuleChecking)
1710
        {
1711
            if ((ecSettings::SuggestFixes & wxGetApp().GetSettings().m_nRuleChecking) &&
1712
                (Cancel==ResolveGlobalConflicts()))
1713
            {
1714
                return FALSE;
1715
            }
1716
            int nConflicts = GetCdlInterpreter()->get_toplevel()->get_all_conflicts().size();
1717
            switch (nConflicts)
1718
            {
1719
            case 0:
1720
                break;
1721
            case 1:
1722
                {
1723
                    wxString msg;
1724
                    msg.Printf(_("There is 1 unresolved conflict. Save anyway?"));
1725
                    if (wxNO == wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxYES_NO))
1726
                    {
1727
                        return FALSE;
1728
                    }
1729
                }
1730
            default:
1731
                {
1732
                    wxString msg;
1733
                    msg.Printf(_("There are %d unresolved conflicts. Save anyway?"), nConflicts);
1734
                    if (wxNO == wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxYES_NO))
1735
                    {
1736
                        return FALSE;
1737
                    }
1738
                }
1739
            }
1740
        }
1741
    }
1742
    return TRUE;
1743
}
1744
 
1745
void ecConfigToolDoc::UpdateFailingRuleCount()
1746
{
1747
    int nCount=0;
1748
    if (GetCdlConfig ())
1749
    {
1750
        // if configuration information
1751
 
1752
        // calculate the number of conflicts
1753
        nCount = GetCdlConfig ()->get_all_conflicts ().size ();
1754
            //          GetCdlConfig ()->get_structural_conflicts ().size () +    ignore for now
1755
 
1756
        // update the conflicts view
1757
        if (wxGetApp().GetMainFrame() && wxGetApp().GetMainFrame()->GetConflictsWindow())
1758
        {
1759
            wxGetApp().GetMainFrame()->GetConflictsWindow()->FillRules ();
1760
        }
1761
    }
1762
 
1763
    if (wxGetApp().GetMainFrame())
1764
    {
1765
        wxGetApp().GetMainFrame()->SetFailRulePane(nCount);
1766
    }
1767
}
1768
 
1769
void ecConfigToolDoc::LogConflicts (const std::list<CdlConflict> & conflicts)
1770
{
1771
    std::list<CdlConflict>::const_iterator conf_i;
1772
    for (conf_i = conflicts.begin (); conf_i != conflicts.end (); conf_i++) // for each conflict
1773
    {
1774
        wxString strExplain = (* conf_i)->get_explanation ().c_str (); // get the conflict explanation
1775
        wxGetApp().Log (ecUtils::StripExtraWhitespace (strExplain)); // display the message in the output window
1776
    }
1777
}
1778
 
1779
bool ecConfigToolDoc::SetValue (ecConfigItem &ti, double dValue, CdlTransaction transaction/*=NULL*/)
1780
{
1781
    wxASSERT (ti.GetOptionType () == ecDouble);
1782
 
1783
    // test if the new double value is in range
1784
    const CdlValuable valuable = ti.GetCdlValuable();
1785
    CdlListValue list_value;
1786
    CdlEvalContext context (NULL, ti.GetCdlItem (), ti.GetCdlItem ()->get_property (CdlPropertyId_LegalValues));
1787
    valuable->get_legal_values ()->eval (context, list_value);
1788
    if (! list_value.is_member (dValue))
1789
    {
1790
        if ( dValue == valuable->get_double_value(CdlValueSource_Current) )
1791
            return FALSE;
1792
 
1793
        wxString msg;
1794
        msg.Printf(_("%s is not a legal value for %s.\n\nDo you want to use this value anyway?"),
1795
            (const wxChar*) ecUtils::DoubleToStr (dValue), (const wxChar*) ti.GetMacro ());
1796
 
1797
        if (wxNO == wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_QUESTION|wxYES_NO))
1798
            return FALSE;
1799
    }
1800
 
1801
    if (! ti.SetValue (dValue,transaction))
1802
        return FALSE;
1803
 
1804
    Modify(TRUE);
1805
    wxGetApp().GetMainFrame()->UpdateFrameTitle();
1806
 
1807
    // NB UpdateAllViews isn't in the MFC Configtool for double (though it is for the
1808
    // other types of value). In theory this should lead to a display inconsistency in the MFC tool.
1809
    ecConfigToolHint hint(& ti, ecValueChanged);
1810
    UpdateAllViews (NULL, & hint);
1811
 
1812
    return TRUE;
1813
}
1814
 
1815
bool ecConfigToolDoc::SetValue(ecConfigItem &ti, const wxString &strValue, CdlTransaction transaction/*=NULL*/)
1816
{
1817
    // TODO
1818
#if 0
1819
    // warn the user if a modified memory layout is about to be discarded
1820
    if (MemoryMap.map_modified () && (ti.Macro () == _T("CYG_HAL_STARTUP")) &&
1821
        (IDCANCEL == CUtils::MessageBoxFT (MB_OKCANCEL, _T("Changes to the current memory layout will be lost."))))
1822
        return false;
1823
#endif
1824
 
1825
    bool rc = FALSE;
1826
 
1827
    switch(ti.GetOptionType())
1828
    {
1829
    case ecOptionTypeNone:
1830
        break;
1831
    case ecEnumerated:
1832
    case ecString:
1833
        rc = ti.SetValue(strValue, transaction);
1834
        break;
1835
    case ecLong:
1836
        {
1837
            long n;
1838
            rc = ecUtils::StrToItemIntegerType(strValue,n) && SetValue(ti,n,transaction);
1839
        }
1840
        break;
1841
    case ecDouble:
1842
        {
1843
            double dValue;
1844
            rc = ecUtils::StrToDouble (strValue, dValue) && SetValue (ti, dValue,transaction);
1845
        }
1846
        break;
1847
    default:
1848
        wxASSERT(FALSE);
1849
        break;
1850
 
1851
    }
1852
    if(rc){
1853
        Modify(TRUE);
1854
        wxGetApp().GetMainFrame()->UpdateFrameTitle();
1855
 
1856
        ecConfigToolHint hint(& ti, ecValueChanged);
1857
        UpdateAllViews (NULL, & hint);
1858
    }
1859
    return rc;
1860
}
1861
 
1862
bool ecConfigToolDoc::SetValue(ecConfigItem &ti, long nValue, CdlTransaction transaction/*=NULL*/)
1863
{
1864
    switch(ti.GetOptionType())
1865
    {
1866
    case ecEnumerated:
1867
    case ecLong:
1868
        break;
1869
    case ecOptionTypeNone:
1870
    case ecString:
1871
    default:
1872
        wxASSERT(FALSE);
1873
        break;
1874
    }
1875
 
1876
    bool rc = FALSE;
1877
 
1878
    // TODO
1879
#if 0
1880
    bool bChangingMemmap = MemoryMap.map_modified () && ((ti.Macro ().Compare (_T ("CYG_HAL_STARTUP")) == 0));
1881
#endif
1882
 
1883
    if(nValue==ti.Value())
1884
    {
1885
        return TRUE;
1886
    }
1887
 
1888
    // test if the new integer value is in range
1889
    if (ecLong == ti.GetOptionType ())
1890
    {
1891
        const CdlValuable valuable = ti.GetCdlValuable();
1892
        CdlListValue list_value;
1893
        CdlEvalContext context (NULL, ti.GetCdlItem (), ti.GetCdlItem ()->get_property (CdlPropertyId_LegalValues));
1894
        valuable->get_legal_values ()->eval (context, list_value);
1895
        if (! list_value.is_member ((cdl_int) nValue))
1896
        {
1897
            if (nValue == (long) valuable->get_integer_value (CdlValueSource_Current))
1898
                goto Exit;
1899
 
1900
            wxString msg;
1901
            msg.Printf(_("%s is not a legal value for %s.\n\nDo you want to use this value anyway?"),
1902
                (const wxChar*) ecUtils::IntToStr (nValue, wxGetApp().GetSettings().m_bHex), (const wxChar*) ti.GetMacro ());
1903
            if (wxNO == wxMessageBox (msg, wxGetApp().GetSettings().GetAppName(), wxICON_QUESTION|wxYES_NO))
1904
                goto Exit;
1905
        };
1906
    }
1907
 
1908
    // TODO
1909
#if 0
1910
    // warn the user if the current memory layout has been changed and will be lost
1911
    // this will happen when the layout has been modified and the target-platform-startup is changed
1912
 
1913
    if (bChangingMemmap && IDCANCEL==CUtils::MessageBoxFT(MB_OKCANCEL,_T("Changes to the current memory layout will be lost."))){
1914
        goto Exit;
1915
    }
1916
#endif
1917
 
1918
    // Save state
1919
    if(!ti.SetValue(nValue,transaction)){
1920
        // CanSetValue above should have caught this
1921
        wxString msg;
1922
        msg.Printf(_("Cannot set '%s' to %d"), (const wxChar*) ti.GetItemNameOrMacro(), nValue);
1923
        wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK);
1924
        goto Exit;
1925
    }
1926
 
1927
    rc = TRUE;
1928
Exit:
1929
    if(rc)
1930
    {
1931
        Modify(TRUE);
1932
        wxGetApp().GetMainFrame()->UpdateFrameTitle();
1933
 
1934
        UpdateFailingRuleCount ();
1935
 
1936
        ecConfigToolHint hint(& ti, ecValueChanged);
1937
        UpdateAllViews (NULL, & hint);
1938
    }
1939
    return rc;
1940
}
1941
 
1942
bool ecConfigToolDoc::SetEnabled(ecConfigItem &ti, bool bEnabled, CdlTransaction transaction/*=NULL*/)
1943
{
1944
    const bool bStatus = ti.SetEnabled (bEnabled, transaction);
1945
 
1946
    if (bStatus)
1947
    {
1948
        Modify(TRUE);
1949
        ecConfigToolHint hint(& ti, ecValueChanged);
1950
        UpdateAllViews (NULL, & hint);
1951
    }
1952
    return bStatus;
1953
}
1954
 
1955
const ecFileName ecConfigToolDoc::CurrentLinkerScript()
1956
{
1957
    const ecConfigItem * pItem = Find (wxT("CYGBLD_LINKER_SCRIPT"));
1958
    return pItem ? ecFileName (m_strPackagesDir, m_strLinkerScriptFolder, pItem->StringValue ()) : ecFileName(wxT(""));
1959
}
1960
 
1961
 
1962
bool ecConfigToolDoc::GenerateHeaders()
1963
{
1964
    wxString sep(wxFILE_SEP_PATH);
1965
 
1966
    // Generate headers
1967
    try {
1968
        ecFileName strPkfConfDir(GetInstallTree());
1969
        strPkfConfDir += ecFileName(wxT("include"));
1970
        strPkfConfDir += ecFileName(wxT("pkgconf"));
1971
        if ( !strPkfConfDir.EC_CreateDirectory())
1972
        {
1973
            wxString msg;
1974
            msg.Printf(_("Failed to create %s"), (const wxChar*) strPkfConfDir);
1975
            wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION);
1976
            return FALSE;
1977
        }
1978
        GetCdlConfig()->generate_config_headers(ecUtils::UnicodeToStdStr(strPkfConfDir.ShortName()));
1979
    }
1980
    catch (CdlInputOutputException e) {
1981
        const wxString strMsg(e.get_message().c_str());
1982
        // TRACE(_T("!!! Exception thrown calling generate_config_headers - %s"),strMsg);
1983
        wxString msg;
1984
        msg.Printf(_("Failed to generate header files - %s"), (const wxChar*) strMsg);
1985
        wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION);
1986
        return FALSE;
1987
    }
1988
    return TRUE;
1989
}
1990
 
1991
const ecFileName ecConfigToolDoc::MLTDir ()
1992
{
1993
    wxString strPathName (GetFilename ());
1994
    wxASSERT (! strPathName.IsEmpty ());
1995
    return strPathName.Left (strPathName.Find (wxT('.'), TRUE)) + wxT("_mlt");
1996
}
1997
 
1998
int ecConfigToolDoc::GetTestExeNames (wxArrayString& arTestExes, wxArrayString& arMissing)
1999
{
2000
    arTestExes.Clear();
2001
    arMissing.Clear();
2002
    typedef std::vector<CdlBuildInfo_Loadable> EntriesArray;
2003
    const EntriesArray &arEntries=GetBuildInfo().entries;
2004
    for(EntriesArray::size_type j=0;j<arEntries.size();j++)
2005
    {
2006
        const CdlBuildInfo_Loadable &e=arEntries[j];
2007
        wxArrayString ar;
2008
        int n = ecUtils::Chop(wxString(get_tests(GetCdlConfig(),e).c_str()),ar);
2009
        int i;
2010
        for (i=0;i<n;i++)
2011
        {
2012
            wxString strFile;
2013
            strFile += GetInstallTree();
2014
            strFile += wxFILE_SEP_PATH;
2015
            strFile += wxT("tests");
2016
            strFile += wxFILE_SEP_PATH;
2017
            strFile += e.directory.c_str();
2018
            strFile += wxFILE_SEP_PATH;
2019
            strFile += ar[i];
2020
 
2021
            // Some tests accidentally specify .c
2022
//            wxStripExtension(strFile);
2023
 
2024
#ifdef __WXMSW__
2025
//            strFile += wxT(".exe");
2026
            strFile.Replace(wxT("/"),wxT("\\"));
2027
#endif
2028
 
2029
            if (wxFileExists(strFile))
2030
            {
2031
                arTestExes.Add(strFile);
2032
            } else
2033
            {
2034
                arMissing.Add(strFile);
2035
            }
2036
        }
2037
    }
2038
    return arTestExes.Count();
2039
}
2040
 
2041
bool ecConfigToolDoc::SaveMemoryMap()
2042
{
2043
    // TODO
2044
#if 0
2045
    wxString sep(wxFILE_SEP_PATH);
2046
 
2047
    const wxString strSuffix(wxT("mlt_") + CurrentMemoryLayout ());
2048
    ecFileName strMLTInstallPkgconfDir(GetInstallTree());
2049
    strMLTInstallPkgconfDir = strMLTInstallPkgconfDir + ecFileName(wxT("include"));
2050
    strMLTInstallPkgconfDir = strMLTInstallPkgconfDir + ecFileName(wxT("pkgconf"));
2051
 
2052
    bool rc=false;
2053
    if(strMLTInstallPkgconfDir.EC_CreateDirectory(TRUE)){
2054
        const wxString strMLTInstallBase(strMLTInstallPkgconfDir+ecFileName(strSuffix));
2055
        const ecFileName strMLTDir (MLTDir());
2056
 
2057
        if(strMLTDir.EC_CreateDirectory (TRUE))
2058
        {
2059
            const wxString strMLTBase (strMLTDir + ecFileName (strSuffix));
2060
            // TRACE(_T("Saving memory layout to %s\n"), strMLTBase + _T(".mlt"));
2061
            if(MemoryMap.save_memory_layout (strMLTBase + _T(".mlt"))){
2062
                // TRACE(_T("Exporting memory layout to %s\n"), strMLTInstallPkgconfDir);
2063
                rc=MemoryMap.export_files (strMLTInstallBase + _T(".ldi"), strMLTInstallBase + _T(".h"));
2064
            }
2065
        }
2066
    }
2067
    return rc;
2068
#else
2069
    return FALSE;
2070
#endif
2071
}
2072
 
2073
bool ecConfigToolDoc::CopyMLTFiles()
2074
{
2075
#if ecUSE_MLT
2076
    wxString sep(wxFILE_SEP_PATH);
2077
 
2078
    // copy default MLT files for the selected target/platform from the repository if they do not already exist
2079
 
2080
    // TRACE (_T("Looking for MLT files at %s\n"), PackagesDir() + m_strMemoryLayoutFolder + _T("include\\pkgconf\\mlt_*.*"));
2081
    const ecFileName strInstallDestination(GetInstallTree () + sep + wxString(wxT("include")) + sep + wxT("pkgconf"));
2082
    const ecFileName strMLTDestination (MLTDir ());
2083
    // TRACE (_T("Copying .ldi and .h files to %s\n"), strInstallDestination);
2084
    // TRACE (_T("Copying .mlt files to %s\n"), strMLTDestination);
2085
    bool rc=strInstallDestination.EC_CreateDirectory ( TRUE ) && strMLTDestination.EC_CreateDirectory ( TRUE );
2086
    if (rc)
2087
    {
2088
        wxDir ffFileFind;
2089
        wxString fileName;
2090
        wxString path = GetPackagesDir();
2091
        path += sep;
2092
        path += m_strMemoryLayoutFolder;
2093
        path += sep;
2094
        path += wxString(wxT("include"));
2095
        path += sep;
2096
        path += wxString(wxT("pkgconf"));
2097
 
2098
        if (!ffFileFind.Open(path))
2099
            return FALSE;
2100
 
2101
        ecFileName wildcard = wxT("mlt_*.*");
2102
 
2103
        //bool bLastFile = ffFileFind.FindFile (PackagesDir() + m_strMemoryLayoutFolder + wxT("\\include\\pkgconf\\mlt_*.*"));
2104
        bool bLastFile = ffFileFind.GetFirst (& fileName, wildcard);
2105
        while (bLastFile)
2106
        {
2107
            wxString fullPath = path + sep + fileName;
2108
 
2109
            if (wxT(".mlt") == fileName.Right (4)) // if a .mlt file
2110
            {
2111
                if (! ecFileName (strMLTDestination, ecFileName (fileName)).Exists ())
2112
                {
2113
                    if (!wxCopyFile (fullPath, strMLTDestination + ecFileName (fileName)))
2114
                    {
2115
                        return FALSE; // message already emitted
2116
                    }
2117
                }
2118
            }
2119
            else // a .h or .ldi file
2120
            {
2121
                if (!ecFileName (strInstallDestination, ecFileName (fileName)).Exists () &&
2122
                    !wxCopyFile (fullPath, strInstallDestination + ecFileName (fileName))){
2123
                    return FALSE; // message already emitted
2124
                }
2125
            }
2126
            bLastFile = ffFileFind.GetNext(& fileName);
2127
        }
2128
    }
2129
    return rc; //FIXME
2130
#else
2131
    return TRUE;
2132
#endif
2133
}
2134
 
2135
const wxString ecConfigToolDoc::CurrentMemoryLayout ()
2136
{
2137
    const ecConfigItem * pItem = Find (wxT("CYGHWR_MEMORY_LAYOUT"));
2138
 
2139
    wxString str;
2140
    if (pItem)
2141
        str = pItem->StringValue ();
2142
    return str;
2143
}
2144
 
2145
bool ecConfigToolDoc::ExportFile()
2146
{
2147
    wxFileDialog dialog(wxGetApp().GetTopWindow(), _("Export eCos Minimal Configuration"),
2148
        wxT(""), wxT(""),
2149
#ifdef __WXMSW__
2150
        wxT("eCos Minimal Configuration Files (*.ecm)|*.ecm|All Files (*.*)|*.*"),
2151
#else
2152
        wxT("eCos Minimal Configuration Files (*.ecm)|*.ecm|All Files (*)|*"),
2153
#endif
2154
#if wxCHECK_VERSION(2, 6, 0)
2155
        wxSAVE|wxOVERWRITE_PROMPT);
2156
#else
2157
        wxSAVE|wxOVERWRITE_PROMPT|wxHIDE_READONLY);
2158
#endif
2159
 
2160
    if (dialog.ShowModal() == wxID_OK)
2161
    {
2162
        try {
2163
            m_CdlConfig->save (ecUtils::UnicodeToStdStr (dialog.GetPath()), /* minimal = */ true);
2164
        }
2165
        catch (CdlStringException exception)
2166
        {
2167
            wxString msg;
2168
            wxString err(exception.get_message ().c_str ());
2169
            msg.Printf(_("Error exporting eCos minimal configuration:\n\n%s"), (const wxChar*) err );
2170
            wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK);
2171
            return FALSE;
2172
        }
2173
        catch (...)
2174
        {
2175
            wxString msg;
2176
            msg.Printf(_("Error exporting eCos minimal configuration"));
2177
            wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK);
2178
            return FALSE;
2179
        }
2180
    }
2181
    return TRUE;
2182
}
2183
 
2184
bool ecConfigToolDoc::ImportFile()
2185
{
2186
    wxFileDialog dialog(wxGetApp().GetTopWindow(), _("Import eCos Minimal Configuration"),
2187
        wxT(""), wxT(""),
2188
#ifdef __WXMSW__
2189
        wxT("eCos Minimal Configuration Files (*.ecm)|*.ecm|All Files (*.*)|*.*"),
2190
#else
2191
        wxT("eCos Minimal Configuration Files (*.ecm)|*.ecm|All Files (*)|*"),
2192
#endif
2193
#if wxCHECK_VERSION(2, 6, 0)
2194
        wxOPEN|wxFILE_MUST_EXIST);
2195
#else
2196
        wxOPEN|wxFILE_MUST_EXIST|wxHIDE_READONLY);
2197
#endif
2198
 
2199
    if (dialog.ShowModal() == wxID_OK)
2200
    {
2201
        try {
2202
            m_CdlConfig->add (ecUtils::UnicodeToStdStr (dialog.GetPath ()), ecConfigToolDoc::CdlParseErrorHandler, ecConfigToolDoc::CdlParseWarningHandler);
2203
        }
2204
        catch (CdlStringException exception)
2205
        {
2206
            wxString msg;
2207
            wxString err(exception.get_message ().c_str ());
2208
            msg.Printf(_("Error importing eCos minimal configuration:\n\n%s"), (const wxChar*) err );
2209
            wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK);
2210
            return FALSE;
2211
        }
2212
        catch (...)
2213
        {
2214
            wxString msg;
2215
            msg.Printf(_("Error importing eCos minimal configuration"));
2216
            wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK);
2217
            return FALSE;
2218
        }
2219
 
2220
        wxBusyCursor wait;
2221
 
2222
        AddAllItems (); // regenerate all the config items since the topology may have changed
2223
 
2224
        if (m_strLinkerScriptFolder.IsEmpty ())
2225
        {
2226
            wxMessageBox(_("The eCos linker script macro CYGBLD_LINKER_SCRIPT is not defined."), wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK);
2227
        }
2228
        if (m_strMemoryLayoutFolder.IsEmpty ())
2229
        {
2230
            wxMessageBox(_("The eCos memory layout macro CYGHWR_MEMORY_LAYOUT is not defined."), wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK);
2231
        }
2232
        SwitchMemoryLayout (TRUE); // the hardware template may have changed
2233
        UpdateBuildInfo ();
2234
        wxGetApp().GetTreeCtrl()->SelectItem (wxGetApp().GetTreeCtrl()->GetRootItem());
2235
        Modify(TRUE);
2236
 
2237
    }
2238
    return TRUE;
2239
}
2240
 
2241
bool ecConfigToolDoc::SwitchMemoryLayout (bool bNewTargetPlatform)
2242
{
2243
    bool rc = TRUE;
2244
    if (bNewTargetPlatform && ! m_strBuildTree.IsEmpty ()) // the user has changed target/platform within a build tree
2245
    {
2246
        // copy default MLT save files for the selected target/platform from the repository to the build tree if they do not already exist
2247
        CopyMLTFiles();
2248
    }
2249
 
2250
    if (m_strBuildTree.IsEmpty ()) // load the memory layout from the repository
2251
    {
2252
        wxString sep(wxFILE_SEP_PATH);
2253
        wxString filename(m_strPackagesDir);
2254
        filename += sep;
2255
        filename += m_strMemoryLayoutFolder;
2256
        filename += sep;
2257
        filename += wxT("include");
2258
        filename += sep;
2259
        filename += wxT("pkgconf");
2260
 
2261
        rc = NewMemoryLayout (ecFileName (filename));
2262
    }
2263
    else // load the memory layout from the build tree
2264
    {
2265
        rc = NewMemoryLayout (MLTDir ());
2266
    }
2267
 
2268
    return TRUE; // FIXME
2269
}
2270
 
2271
bool ecConfigToolDoc::NewMemoryLayout (const wxString &strPrefix)
2272
{
2273
    // TODO
2274
#if ecUSE_MLT
2275
    ecFileName strFileName = CurrentLinkerScript ();
2276
    wxString sep(wxFILE_SEP_PATH);
2277
 
2278
    m_memoryMap.new_memory_layout (); // delete the old memory layout regardless
2279
    if (! strFileName.IsEmpty ())
2280
        m_memoryMap.import_linker_defined_sections (strFileName); // read the linker-defined section names from the repository (failure is silent)
2281
 
2282
    wxString strMemoryLayoutFileName = strPrefix + sep + wxString(wxT("mlt_")) + CurrentMemoryLayout () + wxT(".mlt");
2283
 
2284
    m_memoryMap.load_memory_layout (strMemoryLayoutFileName); // load the new memory layout (failure is silent)
2285
    m_strSelectedSection = wxT("");
2286
    m_strSelectedRegion = wxT("");
2287
 
2288
    wxGetApp().GetMLTWindow()->RefreshMLT();
2289
 
2290
    // ecConfigToolHint hint(NULL, ecMemLayoutChanged);
2291
    // UpdateAllViews (NULL, & hint);
2292
#endif
2293
 
2294
    return TRUE; // FIXME
2295
}
2296
 
2297
void ecConfigToolDoc::RunTests()
2298
{
2299
    wxString strTarget(GetCdlConfig()->get_hardware ().c_str ());
2300
    wxArrayString ar;
2301
    wxArrayString arTestsMissing;
2302
    int nTests;
2303
    wxGetApp().GetSettings().GetRunTestsSettings().m_strTarget = strTarget;
2304
 
2305
    {
2306
        wxBusyCursor busy;
2307
 
2308
        GetCdlConfig()->get_build_info(m_BuildInfo);
2309
        if (NULL==CeCosTestPlatform::Get(strTarget))
2310
        {
2311
            wxString msg;
2312
            msg.Printf(_("%s is not a recognized test platform - do you wish to add it?"), (const wxChar*) strTarget);
2313
            if (wxNO == wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_QUESTION|wxYES_NO))
2314
                return;
2315
 
2316
            ecPlatformEditorDialog dlg(wxGetApp().GetTopWindow());
2317
 
2318
            dlg.m_strPlatform = strTarget;
2319
            dlg.m_strPrefix = GetCurrentTargetPrefix();
2320
            dlg.m_strGDB = _("set height 0\n"
2321
                        "set debug remote 0\n"
2322
                        "set remotebaud %b\n"
2323
                        "target remote %p\n"
2324
                        "load\n"
2325
                        "break cyg_test_exit\n"
2326
                        "rbreak cyg_assert_fail\n"
2327
                        "break cyg_test_init\n"
2328
                        "cont\n"
2329
                        "set cyg_test_is_simulator=0\n"
2330
                        "cont\n"
2331
                        "bt 64");
2332
            dlg.m_strPrompt = _("(gdb) ");
2333
            dlg.m_strInferior = dlg.m_strPrefix + _("-gdb -nw -q %e");
2334
            dlg.m_strCaption=_("New Platform");
2335
            if(wxID_CANCEL == dlg.ShowModal())
2336
            {
2337
                return;
2338
            }
2339
            CeCosTestPlatform::Add(CeCosTestPlatform(dlg.m_strPlatform,dlg.m_strPrefix,dlg.m_strPrompt,dlg.m_strGDB,dlg.m_bServerSideGdb,dlg.m_strInferior));
2340
            CeCosTestPlatform::Save();
2341
        }
2342
 
2343
        nTests = GetTestExeNames(ar, arTestsMissing);
2344
    }
2345
 
2346
    const CeCosTestPlatform * etPlatform = CeCosTestPlatform::Get(strTarget);
2347
    wxASSERT (NULL != etPlatform);
2348
 
2349
    if (-1 != wxString (etPlatform->GdbCmds ()).Find (wxT("cyg_test_is_simulator=1")))
2350
    {   // if a simulator target, disable 'reset hardware' message box
2351
        wxGetApp().GetSettings().GetRunTestsSettings().m_nReset = RESET_NONE ;
2352
    }
2353
 
2354
    // TODO: I think the remote controls was something that wasn't quite implemented in the MFC tool.
2355
    // It's in the properties dialog, but not used.
2356
    // sheet.HideRemoteControls();
2357
    if (arTestsMissing.Count() > 0)
2358
    {
2359
        wxString msg;
2360
        msg.Printf(_("Not all tests are built. Do you wish to build them now?"));
2361
        if (wxYES == wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_QUESTION|wxYES_NO))
2362
        {
2363
            wxGetApp().Build(wxT("tests"));
2364
            return;
2365
        }
2366
    }
2367
    wxString shellCommands;
2368
    // Don't know why we passed TRUE (no build tools) but we need build tools for gdb
2369
    if (wxGetApp().PrepareEnvironment(TRUE /* FALSE */, & shellCommands))
2370
    {
2371
        ecRunTestsDialog dialog(wxGetApp().GetTopWindow());
2372
        int i;
2373
        for ( i = 0 ; i < nTests; i++)
2374
        {
2375
            dialog.Populate(ar[i], TRUE);
2376
        }
2377
        for ( i = 0 ; i < arTestsMissing.Count(); i++)
2378
        {
2379
            dialog.Populate(arTestsMissing[i], FALSE);
2380
        }
2381
 
2382
        dialog.ShowModal();
2383
    }
2384
}
2385
 
2386
// Rebuild the .hhc, .hhp, .hhk files and reinitialize the help controller
2387
bool ecConfigToolDoc::RebuildHelpIndex(bool force)
2388
{
2389
    ecHtmlIndexer indexer(FALSE /* useRelativeURLs */ );
2390
 
2391
    wxString docDir = GetRepository() ;
2392
 
2393
    wxString projectFile;
2394
    if (!indexer.IndexDocs(docDir, projectFile, force))
2395
    {
2396
        wxMessageBox("Sorry, could not index documentation.");
2397
        return FALSE;
2398
    }
2399
    else
2400
    {
2401
        // Now we need to reset the help controller.
2402
        wxGetApp().SetHelpFile(projectFile);
2403
        wxGetApp().InitializeHelpController();
2404
        return TRUE;
2405
    }
2406
}
2407
 

powered by: WebSVN 2.1.0

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