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

Subversion Repositories ezidebug

[/] [ezidebug/] [trunk/] [EziDebug_src/] [toolwindow.cpp] - Blame information for rev 2

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

Line No. Rev Author Line
1 2 EziDebug
#include <QtGui>
2
#include <QDebug>
3
#include <QSystemTrayIcon>
4
#include <QDir>
5
#include <QList>
6
 
7
 
8
#include "button.h"
9
#include "toolwindow.h"
10
#include "ezidebugprj.h"
11
 
12
#include "ezidebugmodule.h"
13
#include "ezidebugvlgfile.h"
14
#include "ezidebugvhdlfile.h"
15
#include "ezidebuginstancetreeitem.h"
16
#include "ezidebugscanchain.h"
17
#include "importdatadialog.h"
18
#include "textquery.h"
19
//#include "updatedetectthread.h"
20
 
21
#define ZERO_REG_NUM  0
22
#define PARAMETER_OK            0x0
23
#define NO_PARAMETER_TOOL       0x01
24
#define NO_PARAMETER_REG_NUM    0x02
25
#define NO_PARAMETER_DIR        0x04
26
#define NO_PARAMETER_ALL        (0x01|0x02|0x04)
27
static unsigned long long tic = 0 ;
28
 
29
 
30
ToolWindow::ToolWindow(QWidget *parent) :
31
    QWidget(parent)
32
{
33
    QTextCodec::setCodecForTr(QTextCodec::codecForName("gb18030"));
34
    isNeededUpdate = false ;
35
    currentPrj = NULL  ;
36
    readSetting() ;  // 读取软件保存的配置信息
37
    setWindowTitle(tr("EziDebug"));
38
    //普通模式下的列表窗口 Qt::FramelessWindowHint
39
    listWindow = new ListWindow(this,Qt::FramelessWindowHint);
40
    m_proSetWiz = 0 ;
41
    //m_pcurrentPrj = 0 ;
42
    createActions();   //创建右键菜单的选项
43
    createButtons();   //创建按钮
44
    creatTrayIcon();   //创建托盘图标
45
 
46
    //设置背景
47
    QPixmap backgroundPix;
48
    QPixmap maskPix;
49
    QPalette palette;
50
    maskPix.load(":/images/toolWindowMask.bmp");
51
    setMask(maskPix);
52
    backgroundPix.load(":/images/mainBackground.bmp",0,Qt::AvoidDither|Qt::ThresholdDither|Qt::ThresholdAlphaDither);
53
    palette.setBrush(QPalette::Background, QBrush(backgroundPix));
54
    setPalette(palette);
55
    //setMask(backgroundPix.mask());   //通过QPixmap的方法获得图片的过滤掉透明的部分得到的图片,作为Widget的不规则边框
56
    //setWindowOpacity(1.0);  //设置图片透明度
57
    //设置对话框的位置和大小
58
    //setGeometry(QRect(250,100,355,25));
59
    setFixedSize(backgroundPix.size());//设置窗口的尺寸为图片的尺寸
60
    move((qApp->desktop()->width() - this->width()) / 2,
61
         (qApp->desktop()->height() - this->height()) /2 - 100);//将窗口移至屏幕中间靠上的位置
62
    setWindowFlags(Qt::FramelessWindowHint|Qt::WindowSystemMenuHint | Qt::WindowMinimizeButtonHint);//设置为无边框 允许任务栏按钮右键菜单 允许最小化与还原
63
    //
64
    //设置普通模式下按钮的位置和大小
65
    //标题栏按钮
66
    minimizeButton->setGeometry(251, 0, 27, 19);//最小化
67
    miniModeButton->setGeometry(QRect(277, 0, 27, 19));//迷你模式
68
    showListWindowButton->setGeometry(QRect(303, 0, 27, 19));//展开listWindow的按钮
69
    exitButton->setGeometry(QRect(329, 0, 33, 19));//关闭
70
    //功能按钮
71
    proSettingButton->setGeometry(QRect(23, 37, 42, 41));//工程设置
72
    proUpdateButton->setGeometry(QRect(65, 37, 42, 41));//更新
73
    proPartlyUpdateButton->setGeometry(QRect(107, 37, 42, 41));//部分更新
74
    deleteChainButton->setGeometry(QRect(149, 37, 42, 41));//删除
75
    testbenchGenerationButton->setGeometry(QRect(191, 37, 42, 41));//testbench生成
76
    proUndoButton->setGeometry(QRect(233, 37, 42, 41));//撤销(undo)
77
 
78
    //进度条
79
    progressBar = new QProgressBar(this);
80
    progressBar->setGeometry(QRect(28, 88, 248, 10));
81
    progressBar->setRange(0, 100);
82
    progressBar->setValue(0);
83
 
84
    //progressBar->setStyleSheet("QProgressBar { border: 2px solid grey; border-radius: 5px; }");
85
//    progressBar->setStyleSheet("QProgressBar::chunk { background-color: #6cccff;width: 6px;}");
86
//    progressBar->setStyleSheet("QProgressBar { border: 0px solid grey;border-radius: 2px; text-align: right;}");
87
 
88
    progressBar->setTextVisible(false);
89
    progressBar->setStyleSheet(
90
    "QProgressBar {"
91
    "border: 0px solid black;"
92
    "width: 10px;"
93
    "background: QLinearGradient( x1: 0, y1: 0.1, x2: 0, y2: 0.9,"
94
    "stop: 0 #fff,"
95
    "stop: 0.4999 #eee,"
96
    "stop: 0.5 #ddd,"
97
    "stop: 1 #eee );}");
98
 
99
    progressBar->setStyleSheet(
100
    "QProgressBar::chunk {"
101
    "background: QLinearGradient( x1: 0, y1: 0.1, x2: 0, y2: 0.9,"
102
    "stop: 0 #ace5ff,"
103
    "stop: 0.4999 #42c8ff,"
104
    "stop: 0.5 #22b8ff,"
105
    "stop: 1 #ace5ff );"
106
    "border: 0px solid black;}");
107
 
108
 
109
//    progressBar->setStyleSheet("  \
110
//    QProgressBar {  \
111
//    border: 0px solid black;  \
112
//    text-align: right;    \
113
//    padding: 1px;   \
114
//    border-top-left-radius: 5px;    \
115
//    border-bottom-left-radius: 5px; \
116
//    width: 8px;   \
117
//    background: QLinearGradient( x1: 0, y1: 0, x2: 0, y2: 1,    \
118
//    stop: 0 #fff,   \
119
//    stop: 0.4999 #eee,  \
120
//    stop: 0.5 #ddd, \
121
//    stop: 1 #eee );}");
122
 
123
//    progressBar->setStyleSheet("    \
124
//    QProgressBar::chunk {   \
125
//    background: QLinearGradient( x1: 0, y1: 0, x2: 0, y2: 1,   \
126
//    stop: 0 #78d,   \
127
//    stop: 0.4999 #46a,   \
128
//    stop: 0.5 #45a,   \
129
//    stop: 1 #238 );   \
130
//    border-top-left-radius: 5px;    \
131
//    border-bottom-left-radius: 5px; \
132
//    border: 0px solid black;}");
133
 
134
 
135
    //m_iplogolabel = new QLabel(this) ;
136
    //EziDebugIcon1
137
    //m_iplogolabel->setPixmap(QPixmap(":/images/indication.bmp"));
138
    //m_iplogolabel->setGeometry(QRect(30, 20, 80, 44));
139
 
140
    updatehintButton = new QPushButton(this) ;
141
    //updatehintButton->setIcon(QIcon(":/images/update2.png"));
142
    updatehintButton->setIcon(QIcon(":/images/update2.png"));
143
    updatehintButton->setFlat(true);
144
    updatehintButton->setIconSize(QSize(30,29));
145
    updatehintButton->setGeometry(QRect(320, 75, 30, 29));
146
    updatehintButton->setFocusPolicy(Qt::NoFocus);
147
    updatehintButton->setDisabled(true);
148
 
149
    iChangeUpdateButtonTimer = new QTimer(this) ;
150
    connect(iChangeUpdateButtonTimer, SIGNAL(timeout()), this, SLOT(changeUpdatePic()));
151
 
152
 
153
    // setListWindowAdsorbedFlag(true);
154
 
155
//进度条演示
156
//   QTimer *timer = new QTimer(this);
157
//       connect(timer, SIGNAL(timeout()), this, SLOT(progressBarDemo()));
158
//       timer->start(1000);
159
 
160
 
161
 
162
//单独的窗口显示进度条
163
//    QProgressDialog progressDialog(this);
164
//    progressDialog.setCancelButtonText(tr("取消"));
165
//    progressDialog.setRange(0, 100);
166
//    progressDialog.setWindowTitle(tr("进度条"));
167
 
168
//    for (int i = 0; i < 100; ++i) {
169
//        progressDialog.setValue(i);
170
//        progressDialog.setLabelText(tr("进度为 %1 / %2...")
171
//                                    .arg(i).arg(100));
172
//        qApp->processEvents();
173
//        if (progressDialog.wasCanceled()){
174
//            //添加取消时的工作
175
//            break;
176
//        }
177
//        for (int j = 0; j < 100000000; ++j);
178
//    }
179
 
180
 
181
 
182
    listWindow->setWindowFlags(Qt::SplashScreen);
183
 
184
    // 为 listwindow 安装事件过滤器
185
    // listWindow->installEventFilter(this);
186
    // listWindow->setWindowFlags(Qt::Window);
187
 
188
//    aa = new QWidget(this,Qt::FramelessWindowHint) ;
189
//    aa->setWindowTitle("zenmehuishi");
190
//    aa->show();
191
//    aa->raise();
192
//    aa->activateWindow();
193
//    qDebug()<< this->frameGeometry().left() << this->frameGeometry().bottom();
194
 
195
 
196
    listWindow->move(this->frameGeometry().bottomLeft());//列表窗口初始位置为toolWindow的正下方
197
    listWindow->setWindowStick(true);
198
//  listWindow->move(this->frameGeometry().left()-3,this->frameGeometry().bottom()-29);
199
//  listWindow->move(0,0);
200
 
201
//    qDebug()<< listWindow->pos().x()<<listWindow->pos().y();
202
//    qDebug()<< listWindow->pos().rx()<<listWindow->pos().ry();
203
 
204
//    qDebug()<< this->frameGeometry().bottom();
205
//    qDebug()<< listWindow->frameGeometry().top();
206
 
207
 
208
 
209
 
210
    //不隐藏列表窗口
211
    listWindow->setListWindowHidden(false);
212
    //列表窗口默认吸附在工具栏窗口下方
213
    isListWindowAdsorbed = true;
214
 
215
    //已修改
216
#if 0
217
    connect(listWindow, SIGNAL(mouseReleased(const QRect)),
218
            this, SLOT(listWindowMouseReleased(const QRect)));
219
#endif
220
 
221
    connect(this,SIGNAL(updateTreeView(EziDebugInstanceTreeItem*)),listWindow,SLOT(generateTreeView(EziDebugInstanceTreeItem*)));
222
 
223
 
224
    //迷你模式下的主窗口和状态栏
225
    //miniWindow = 0;
226
    miniWindow = new MiniWindow;
227
    miniWindow->hide();
228
    isNormalMode = true ;
229
    //迷你模式转换到普通模式
230
    connect(miniWindow, SIGNAL(toNormalMode()), this, SLOT(toNormalMode()));
231
    //miniWindow最小化时,修改相关菜单信息
232
    connect(miniWindow->minimizeButton, SIGNAL(clicked()), this, SLOT(miniWindowMinimized()));
233
 
234
    //工程设置
235
    connect(miniWindow->proSettingButton, SIGNAL(clicked()), this, SLOT(proSetting()));
236
    //更新
237
    connect(miniWindow->proUpdateButton, SIGNAL(clicked()), this, SLOT(proUpdate()));
238
    //部分更新
239
    connect(miniWindow->proPartlyUpdateButton, SIGNAL(clicked()), this, SLOT(fastUpdate()));
240
    //删除
241
    connect(miniWindow->deleteChainButton, SIGNAL(clicked()), this, SLOT(deleteAllChain()));
242
    //testbench生成
243
    connect(miniWindow->testbenchGenerationButton, SIGNAL(clicked()), this, SLOT(testbenchGeneration()));
244
    //撤销(undo)
245
    connect(miniWindow->proUndoButton, SIGNAL(clicked()), this, SLOT(undoOperation()));
246
}
247
 
248
ToolWindow::~ToolWindow()
249
{
250
    qDebug() << "Attention:Begin to destruct toolwindow!";
251
    if(currentPrj)
252
        delete currentPrj ;
253
}
254
 
255
//bool ToolWindow::eventFilter(QObject *obj, QEvent *event)
256
//{
257
//    if(obj == listWindow)
258
//    {
259
//        qDebug()<< "nothing to do !";
260
//        return 0 ;
261
//    }
262
//    else
263
//    {
264
//        return QWidget::eventFilter(obj,event);
265
//    }
266
//}
267
void ToolWindow::proSetting()
268
{
269
    int nexecResult = 0 ;
270
    if(!m_proSetWiz)
271
    {
272
        m_proSetWiz = new ProjectSetWizard(this);
273
    }
274
    else
275
    {
276
        delete m_proSetWiz ;
277
        m_proSetWiz = new ProjectSetWizard(this);
278
    }
279
    //connect
280
    if((nexecResult = m_proSetWiz->exec()))
281
    {
282
        QMessageBox::information(this, QObject::tr("工程向导"),QObject::tr("参数设置完成"));
283
 
284
        /*根据设置的参数来 判断是否进行重新创建工程对象*/
285
        if(!currentPrj)
286
        {
287
            currentPrj = new EziDebugPrj(m_proSetWiz->m_uncurrentRegNum,m_proSetWiz->m_icurrentDir,m_proSetWiz->m_ecurrentTool,this);
288
                            currentPrj->setXilinxErrCheckedFlag(m_proSetWiz->m_isXilinxErrChecked);
289
            UpdateDetectThread * pthread =  currentPrj->getThread() ;
290
            connect(pthread,SIGNAL(codeFileChanged()),this,SLOT(updateIndicate()));
291
            connect(currentPrj,SIGNAL(updateProgressBar(int)),this,SLOT(changeProgressBar(int)));
292
 
293
            listWindow->addMessage("info","EziDebug info: create new project!");
294
            QStandardItem * pitem = listWindow->addMessage("info",tr("The new project parameter:"));
295
            listWindow->addMessage("process",tr("      The chain max reg number: %1").arg(m_proSetWiz->m_uncurrentRegNum),pitem);
296
            listWindow->addMessage("process",tr("      The current project path: %1").arg(m_proSetWiz->m_icurrentDir),pitem);
297
            listWindow->addMessage("process",tr("      The compile software: \"%1\"").arg((m_proSetWiz->m_ecurrentTool == EziDebugPrj::ToolQuartus) ? ("quartus") :("ise")),pitem);
298
        }
299
        else
300
        {
301
            if((m_proSetWiz->m_uncurrentRegNum == currentPrj->getMaxRegNumPerChain())\
302
                &&(m_proSetWiz->m_ecurrentTool == currentPrj->getToolType())\
303
                &&(QDir::toNativeSeparators(m_proSetWiz->m_icurrentDir) == QDir::toNativeSeparators(currentPrj->getCurrentDir().absolutePath()))\
304
                    &&(m_proSetWiz->m_isXilinxErrChecked == currentPrj->getSoftwareXilinxErrCheckedFlag()))
305
            {
306
                /*do nothing*/
307
                listWindow->addMessage("info","EziDebug info: The project parameter is same as before!");
308
                QStandardItem * pitem = listWindow->addMessage("process",tr("The new project parameter:"));
309
                listWindow->addMessage("info",tr("      The chain max reg number: %1").arg(m_proSetWiz->m_uncurrentRegNum),pitem);
310
                listWindow->addMessage("info",tr("      The current project path: %1").arg(m_proSetWiz->m_icurrentDir),pitem);
311
                listWindow->addMessage("info",tr("      The compile software: \"%1\"").arg((m_proSetWiz->m_ecurrentTool == EziDebugPrj::ToolQuartus) ? ("quartus") :("ise")),pitem);
312
            }
313
            else if(QDir::toNativeSeparators(m_proSetWiz->m_icurrentDir) != QDir::toNativeSeparators(currentPrj->getCurrentDir().absolutePath()))
314
            {
315
                qDebug() << m_proSetWiz->m_icurrentDir << endl << currentPrj->getCurrentDir().absolutePath() << QDir::toNativeSeparators(currentPrj->getCurrentDir().absolutePath()) ;
316
                delete currentPrj ;
317
                currentPrj = NULL ;
318
                EziDebugInstanceTreeItem::setProject(NULL);
319
                listWindow->clearTreeView();
320
 
321
                currentPrj = new EziDebugPrj(m_proSetWiz->m_uncurrentRegNum,m_proSetWiz->m_icurrentDir,m_proSetWiz->m_ecurrentTool,this);
322
                currentPrj->setXilinxErrCheckedFlag(m_proSetWiz->m_isXilinxErrChecked);
323
                //pparent->setCurrentProject(pcurrentPrj);
324
                UpdateDetectThread * pthread =  currentPrj->getThread() ;
325
                connect(pthread,SIGNAL(codeFileChanged()),this,SLOT(updateIndicate()));
326
                connect(currentPrj,SIGNAL(updateProgressBar(int)),this,SLOT(changeProgressBar(int)));
327
 
328
                QMessageBox::information(this, QObject::tr("工程设置"),QObject::tr("准备解析新的工程!"));
329
                listWindow->addMessage("info","EziDebug info: The project is changed !");
330
                QStandardItem * pitem = listWindow->addMessage("warning",tr("The new project parameter:"));
331
                listWindow->addMessage("warning",tr("      The chain max reg number: %1").arg(m_proSetWiz->m_uncurrentRegNum),pitem);
332
                listWindow->addMessage("warning",tr("      The current project path: %1").arg(m_proSetWiz->m_icurrentDir),pitem);
333
                listWindow->addMessage("warning",tr("      The compile software: \"%1\"").arg((m_proSetWiz->m_ecurrentTool == EziDebugPrj::ToolQuartus) ? ("quartus") :("ise")),pitem);
334
 
335
 
336
                /*等待用户 update all 重新解析工程*/
337
                /*toolwindow 初始化时 部分更新 全部更新 删除全部链 生成testbench 均不可用*/
338
            }
339
            else if(m_proSetWiz->m_ecurrentTool != currentPrj->getToolType())
340
            {
341
 
342
                /*重新设置工程参数*/
343
                currentPrj->setToolType(m_proSetWiz->m_ecurrentTool);
344
                listWindow->addMessage("warning","EziDebug warning: The project's parameters have changed!");
345
                listWindow->addMessage("warning","EziDebug warning: Please delete all scan chain and insert the chain again!");
346
 
347
 
348
                bool eneededCreateTestBenchFlag = false ;
349
                QMap<QString,EziDebugScanChain*>::const_iterator i = currentPrj->getScanChainInfo().constBegin();
350
                while (i != currentPrj->getScanChainInfo().constEnd())
351
                {
352
                    EziDebugScanChain * pchain = i.value() ;
353
                    if(!pchain->getCfgFileName().isEmpty())
354
                    {
355
                        eneededCreateTestBenchFlag = true ;
356
                        break ;
357
                    }
358
                }
359
 
360
                if(eneededCreateTestBenchFlag)
361
                {
362
                    /*提示是否重新生成testbench*/
363
                    QMessageBox::information(this, QObject::tr("工程设置"),QObject::tr("原代码中存在扫描链,请删除所有链之后重新添加并生成相应的testBench文件!"));
364
                }
365
 
366
                delete currentPrj ;
367
                currentPrj = NULL ;
368
                EziDebugInstanceTreeItem::setProject(NULL);
369
                listWindow->clearTreeView();
370
 
371
                currentPrj = new EziDebugPrj(m_proSetWiz->m_uncurrentRegNum,m_proSetWiz->m_icurrentDir,m_proSetWiz->m_ecurrentTool,this);
372
                currentPrj->setXilinxErrCheckedFlag(m_proSetWiz->m_isXilinxErrChecked);
373
                //pparent->setCurrentProject(pcurrentPrj);
374
                UpdateDetectThread * pthread =  currentPrj->getThread() ;
375
                connect(pthread,SIGNAL(codeFileChanged()),this,SLOT(updateIndicate()));
376
                connect(currentPrj,SIGNAL(updateProgressBar(int)),this,SLOT(changeProgressBar(int)));
377
 
378
                QMessageBox::information(this, QObject::tr("工程设置"),QObject::tr("准备解析新的工程!"));
379
                listWindow->addMessage("info","EziDebug info: The project is changed !");
380
                QStandardItem * pitem = listWindow->addMessage("warning",tr("The new project parameter:"));
381
                listWindow->addMessage("warning",tr("      The chain max reg number: %1").arg(m_proSetWiz->m_uncurrentRegNum),pitem);
382
                listWindow->addMessage("warning",tr("      The current project path: %1").arg(m_proSetWiz->m_icurrentDir),pitem);
383
                listWindow->addMessage("warning",tr("      The compile software: \"%1\"").arg((m_proSetWiz->m_ecurrentTool == EziDebugPrj::ToolQuartus) ? ("quartus") :("ise")),pitem);
384
 
385
            }
386
            else
387
            {
388
                if(m_proSetWiz->m_uncurrentRegNum != currentPrj->getMaxRegNumPerChain())
389
                {
390
                    /*重新设置工程参数*/
391
                    currentPrj->setMaxRegNumPerChain(m_proSetWiz->m_uncurrentRegNum);
392
                    listWindow->addMessage("info","EziDebug info: The project parameter is changed ,!");
393
                    if(currentPrj->getScanChainInfo().count())
394
                    {
395
                        /*提示重新添加链 并重新生成testbench*/
396
                        QMessageBox::information(this, QObject::tr("工程设置"),QObject::tr("最大链寄存器个数已更改,之前所加扫描链不可用,请删除所有扫描链!"));
397
                    }
398
                }
399
 
400
 
401
                if((m_proSetWiz->m_isXilinxErrChecked != currentPrj->getSoftwareXilinxErrCheckedFlag())&&(m_proSetWiz->m_ecurrentTool == EziDebugPrj::ToolIse))
402
                {
403
                    /*提示是否重新生成testbench*/
404
                    QMessageBox::warning(this, QObject::tr("工程设置"),QObject::tr("注意在 Xilinx 工程下 可能会导致 扫描链截取信号不正确!"));
405
                    /**/
406
                }
407
 
408
                QStandardItem * pitem = listWindow->addMessage("warning",tr("The new project parameter:"));
409
                listWindow->addMessage("process",tr("      The chain max reg number: %1").arg(m_proSetWiz->m_uncurrentRegNum),pitem);
410
                listWindow->addMessage("process",tr("      The current project path: %1").arg(m_proSetWiz->m_icurrentDir),pitem);
411
                listWindow->addMessage("process",tr("      The compile software: \"%1\"").arg((m_proSetWiz->m_ecurrentTool == EziDebugPrj::ToolQuartus) ? ("quartus") :("ise")),pitem);
412
 
413
            }
414
 
415
        }
416
        return ;
417
    }
418
}
419
 
420
void ToolWindow::proUpdate()
421
{
422
    EziDebugInstanceTreeItem *pitem = NULL ;
423
    UpdateDetectThread* pthread = NULL ;
424
 
425
    QMap<QString,EziDebugVlgFile*> ivlgFileMap ;
426
    QMap<QString,EziDebugVhdlFile*> ivhdlFileMap ;
427
    QList<EziDebugPrj::LOG_FILE_INFO*> iaddedinfoList ;
428
    QList<EziDebugPrj::LOG_FILE_INFO*> ideletedinfoList ;
429
    EziDebugPrj::SCAN_TYPE etype = EziDebugPrj::partScanType ;
430
    QStringList ideletedChainList ;
431
 
432
    if(!currentPrj)
433
    {
434
        QMessageBox::information(this, QObject::tr("全部更新"),QObject::tr("您所指定的工程不存在或者未设置工程参数!"));
435
        return ;
436
    }
437
 
438
    // progress
439
 
440
    pthread = currentPrj->getThread() ;
441
    /*
442
      1、重新构建 工程 进行扫描
443
      2、发现有更新的文件,进行扫描
444
      3、更改工程参数 进行扫描  = 重建工程进行扫描 ; 这时候需要 根据 路径 对比结果 来判断, 然后析构前工程,再后创建新的工程
445
    */
446
 
447
    // 发现有更新的文件,进行全部更新
448
    if((currentPrj->getPrjVlgFileMap().count()!= 0)||(currentPrj->getPrjVhdlFileMap().count()!= 0))
449
    {
450
        if(isNeededUpdate)
451
        {
452
            listWindow->addMessage("info","EziDebug info: You can continue to update Project!");
453
        }
454
        else
455
        {
456
            QMessageBox::information(this, QObject::tr("全部更新"),QObject::tr("无文件可更新!"));
457
            progressBar->setValue(0);
458
 
459
            return ;
460
        }
461
 
462
        if(pthread->isRunning())
463
        {
464
            pthread->quit();
465
            pthread->wait();
466
        }
467
 
468
        // 5%
469
        progressBar->setValue(5);
470
 
471
        // 重新得到所有代码文件
472
        if(currentPrj->parsePrjFile(ivlgFileMap,ivhdlFileMap))
473
        {
474
            listWindow->addMessage("error","EziDebug error: parse project file Error!");
475
 
476
            QMap<QString,EziDebugVlgFile*>::iterator i =  ivlgFileMap.begin() ;
477
            while(i != ivlgFileMap.end())
478
            {
479
               EziDebugVlgFile* pfile = ivlgFileMap.value(i.key());
480
               if(pfile)
481
               {
482
                   delete pfile ;
483
               }
484
               ++i ;
485
            }
486
            ivlgFileMap.clear() ;
487
 
488
            // vhdl file pointer destruct
489
            QMap<QString,EziDebugVhdlFile*>::iterator j =  ivhdlFileMap.begin() ;
490
            while(j != ivhdlFileMap.end())
491
            {
492
               EziDebugVhdlFile* pfile = ivhdlFileMap.value(j.key());
493
               if(pfile)
494
               {
495
                   delete pfile ;
496
               }
497
               ++j ;
498
            }
499
            ivhdlFileMap.clear() ;
500
 
501
            delete currentPrj ;
502
            setCurrentProject(NULL);
503
 
504
            // 0%
505
            QMessageBox::critical(this, QObject::tr("全部更新失败"),QObject::tr("软件内部错误!"));
506
 
507
            progressBar->setValue(0);
508
 
509
 
510
            return ;
511
        }
512
        etype = EziDebugPrj::partScanType ;
513
 
514
        // 10%
515
        progressBar->setValue(10);
516
 
517
        // check deleted files
518
        currentPrj->checkDelFile(ivlgFileMap,ivhdlFileMap,ideletedinfoList);
519
 
520
        // clear up the related chainlist last time
521
        currentPrj->clearupCheckedChainList();
522
        currentPrj->clearupDestroyedChainList();
523
 
524
        // 15%
525
        progressBar->setValue(15);
526
 
527
        // scan file all over (can't find the deleted file)
528
        if(currentPrj->traverseAllCodeFile(etype ,ivlgFileMap , ivhdlFileMap ,iaddedinfoList,ideletedinfoList))
529
        {
530
            listWindow->addMessage("error","EziDebug error: traverseAllCodeFile encounter the error !");
531
 
532
            QMap<QString,EziDebugVlgFile*>::iterator i =  ivlgFileMap.begin() ;
533
            while(i != ivlgFileMap.end())
534
            {
535
               EziDebugVlgFile* pfile = ivlgFileMap.value(i.key());
536
               if(pfile)
537
               {
538
                   delete pfile ;
539
               }
540
               ++i ;
541
            }
542
            ivlgFileMap.clear() ;
543
 
544
            // vhdl file pointer destruct
545
            QMap<QString,EziDebugVhdlFile*>::iterator j =  ivhdlFileMap.begin() ;
546
            while(j != ivhdlFileMap.end())
547
            {
548
               EziDebugVhdlFile* pfile = ivhdlFileMap.value(j.key());
549
               if(pfile)
550
               {
551
                   delete pfile ;
552
               }
553
               ++j ;
554
            }
555
            ivhdlFileMap.clear() ;
556
 
557
            delete currentPrj ;
558
            setCurrentProject(NULL);
559
 
560
            qDeleteAll(iaddedinfoList);
561
            qDeleteAll(ideletedinfoList);
562
 
563
 
564
            QMessageBox::critical(this, QObject::tr("全部更新失败"),QObject::tr("软件内部错误!"));
565
            // 0%
566
            progressBar->setValue(0);
567
 
568
            return ;
569
        }
570
 
571
        // 60%
572
        progressBar->setValue(60);
573
 
574
        // update file  map
575
        currentPrj->updateFileMap(ivlgFileMap,ivhdlFileMap);
576
 
577
        currentPrj->addToMacroMap();
578
        // 老的树状 头节点 置空
579
        currentPrj->setInstanceTreeHeadItem(NULL);
580
 
581
 
582
        QString itopModule = currentPrj->getTopModule() ;
583
 
584
        if(!currentPrj->getPrjModuleMap().contains(itopModule))
585
        {
586
            listWindow->addMessage("error","EziDebug error: There is no Topmodule definition!");
587
            delete currentPrj ;
588
            setCurrentProject(NULL);
589
 
590
            QMessageBox::critical(this, QObject::tr("全部更新失败"),QObject::tr("软件内部错误!"));
591
 
592
            progressBar->setValue(0);
593
 
594
            return ;
595
        }
596
 
597
        QString itopModuleComboName = itopModule + QObject::tr(":")+ itopModule ;
598
 
599
        // 创建新的树状 头节点
600
        EziDebugInstanceTreeItem* pnewHeadItem = new EziDebugInstanceTreeItem(itopModule,itopModule);
601
        if(!pnewHeadItem)
602
        {
603
            listWindow->addMessage("error","EziDebug error: There is no memory left!");
604
            delete currentPrj ;
605
            setCurrentProject(NULL);
606
 
607
            QMessageBox::critical(this, QObject::tr("全部更新失败"),QObject::tr("软件内部错误!"));
608
 
609
            progressBar->setValue(0);
610
 
611
            return ;
612
        }
613
 
614
        // 65%
615
        progressBar->setValue(65);
616
 
617
        //  生成整个树的 节点
618
        if(currentPrj->traverseModuleTree(itopModuleComboName,pnewHeadItem))
619
        {
620
            listWindow->addMessage("error","EziDebug error: fast update failed!");
621
            QMessageBox::critical(this, QObject::tr("全部更新失败"),QObject::tr("软件内部错误!"));
622
 
623
            progressBar->setValue(0);
624
            return ;
625
        }
626
 
627
        // 75%
628
        progressBar->setValue(75);
629
 
630
        currentPrj->setInstanceTreeHeadItem(pnewHeadItem);
631
 
632
        if(currentPrj->getDestroyedChainList().count())
633
        {
634
            // 把所有破坏掉的链打印出来
635
            QString ichain ;
636
            QStringList idestroyedChainList = currentPrj->getDestroyedChainList() ;
637
 
638
            listWindow->addMessage("warning","EziDebug warning: Some chains are destroyed!");
639
            listWindow->addMessage("warning","the destroyed chain are:");
640
            for(int i = 0 ; i < idestroyedChainList.count() ;i++)
641
            {
642
                QString ichainName = idestroyedChainList.at(i) ;
643
 
644
                EziDebugInstanceTreeItem *pitem = currentPrj->getChainTreeItemMap().value(ichainName,NULL);
645
                if(pitem)
646
                {
647
                    ichain.append(tr("EziDebug chain:%1  topInstance:%2:%3").arg(ichainName)\
648
                                  .arg(pitem->getModuleName()).arg(pitem->getInstanceName())) ;
649
                }
650
                listWindow->addMessage("warning",ichain);
651
            }
652
 
653
            // 扫描链被破坏 ,提示删除
654
            QMessageBox::StandardButton rb = QMessageBox::question(this, tr("部分扫描链被破坏"), tr("是否删除相关扫描链代码"), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
655
            if(rb == QMessageBox::Yes)
656
            {
657
                QStringList iunDelChainList = currentPrj->deleteDestroyedChain(iaddedinfoList,ideletedinfoList) ;
658
                if(iunDelChainList.count())
659
                {
660
                    listWindow->addMessage("error","EziDebug error: Some chains do not be deleted for some reasons!");
661
                    for(int i = 0 ; i < iunDelChainList.count() ;i++)
662
                    {
663
                        listWindow->addMessage("error",tr("EziDebug chain:%1").arg(iunDelChainList.at(i)));
664
                    }
665
                    listWindow->addMessage("error","EziDebug error: Please check the code file is compiled successed!");
666
                }
667
 
668
                for(int i = 0 ; i < idestroyedChainList.count() ; i++)
669
                {
670
                    QString idestroyedChain = idestroyedChainList.at(i) ;
671
                    ideletedChainList.append(idestroyedChain);
672
                    if(!iunDelChainList.contains(idestroyedChain))
673
                    {
674
                        struct EziDebugPrj::LOG_FILE_INFO* pdelChainInfo = new EziDebugPrj::LOG_FILE_INFO ;
675
                        memcpy(pdelChainInfo->ainfoName,idestroyedChain.toAscii().data(),idestroyedChain.size()+1);
676
                        pdelChainInfo->pinfo = NULL ;
677
                        pdelChainInfo->etype = EziDebugPrj::infoTypeScanChainStructure ;
678
                        ideletedinfoList << pdelChainInfo ;
679
                    }
680
                }
681
            }
682
        }
683
 
684
        QStringList icheckChainList = currentPrj->checkChainExist();
685
 
686
        for(int i = 0 ; i < icheckChainList.count() ;i++)
687
        {
688
            QString iupdatedChain = icheckChainList.at(i) ;
689
            if(!ideletedChainList.contains(iupdatedChain))
690
            {
691
                struct EziDebugPrj::LOG_FILE_INFO* pdelChainInfo = new EziDebugPrj::LOG_FILE_INFO ;
692
                memcpy(pdelChainInfo->ainfoName,iupdatedChain.toAscii().data(),iupdatedChain.size()+1);
693
                pdelChainInfo->pinfo = NULL ;
694
                pdelChainInfo->etype = EziDebugPrj::infoTypeScanChainStructure ;
695
                ideletedinfoList << pdelChainInfo ;
696
 
697
                struct EziDebugPrj::LOG_FILE_INFO* paddChainInfo = new EziDebugPrj::LOG_FILE_INFO ;
698
                memcpy(paddChainInfo->ainfoName,iupdatedChain.toAscii().data(),iupdatedChain.size()+1);
699
                paddChainInfo->pinfo = paddChainInfo ;
700
                paddChainInfo->etype = EziDebugPrj::infoTypeScanChainStructure ;
701
                iaddedinfoList << paddChainInfo ;
702
            }
703
        }
704
 
705
 
706
 
707
        // 80%
708
        progressBar->setValue(80);
709
 
710
        if(currentPrj->changedLogFile(iaddedinfoList,ideletedinfoList))
711
        {
712
           listWindow->addMessage("info","EziDebug info: save log file failed!");
713
        }
714
 
715
        qDeleteAll(iaddedinfoList);
716
        qDeleteAll(ideletedinfoList);
717
 
718
        // 90%
719
        progressBar->setValue(90);
720
 
721
        currentPrj->cleanupChainTreeItemMap();
722
        currentPrj->cleanupBakChainTreeItemMap();
723
 
724
        if(currentPrj->getLastOperation() == EziDebugPrj::OperateTypeDelAllScanChain)
725
        {
726
            currentPrj->cleanupChainQueryTreeItemMap();
727
        }
728
        else
729
        {
730
            currentPrj->cleanupBakChainQueryTreeItemMap();
731
        }
732
 
733
        // 原来加入 链的节点 信息 导入
734
        currentPrj->updateTreeItem(pnewHeadItem);
735
 
736
        if(currentPrj->getLastOperation() == EziDebugPrj::OperateTypeDelAllScanChain)
737
        {
738
            // ChainTreeItemMap 存放新的节点map
739
            // 恢复 bakChainTreeItemMap 删除 ChainTreeItemMap
740
 
741
            // ChainQueryTreeItemMap 存放新的节点map
742
            // 恢复 bakChainQueryTreeItemMap 删除 ChainQueryTreeItemMap
743
            // update 用的 BakChainQueryTreeItemMap 放原始的、 ChainQueryTreeItemMap 放的新的
744
            currentPrj->cleanupBakChainQueryTreeItemMap();
745
            currentPrj->backupChainQueryTreeItemMap();
746
            currentPrj->cleanupChainQueryTreeItemMap();
747
        }
748
        else
749
        {
750
            // update 用的 ChainQueryTreeItemMap 放原始的、 bakChainQueryTreeItemMap 放新的
751
            currentPrj->cleanupChainQueryTreeItemMap();
752
            currentPrj->resumeChainQueryTreeItemMap();
753
            currentPrj->cleanupBakChainQueryTreeItemMap();
754
        }
755
 
756
 
757
        isNeededUpdate = false ;
758
        iChangeUpdateButtonTimer->stop();
759
        updatehintButton->setIcon(QIcon(":/images/update2.png"));
760
        updatehintButton->setDisabled(true);
761
 
762
 
763
        pthread->start();
764
 
765
        emit updateTreeView(pnewHeadItem);
766
 
767
        // 100%
768
        progressBar->setValue(100);
769
 
770
        QMessageBox::information(this, QObject::tr("全部更新"),QObject::tr("更新代码完毕!"));
771
 
772
 
773
    }
774
    else
775
    {
776
        /*检查所需工程文件是否存在 0:存在 1:不存在*/
777
        if(!currentPrj->isPrjFileExist())
778
        {
779
            listWindow->addMessage("error","EziDebug error: The project file is not exist!");
780
            delete currentPrj ;
781
            setCurrentProject(NULL);
782
 
783
            QMessageBox::warning(this, QObject::tr("全部更新失败"),QObject::tr("您所指定的工程文件不存在!"));
784
 
785
            progressBar->setValue(0);
786
 
787
            return ;
788
        }
789
        // 2%
790
        progressBar->setValue(2);
791
 
792
        if(currentPrj->getCurrentDir().exists("config.ezi"))
793
        {
794
            currentPrj->setLogFileExistFlag(true);
795
 
796
            currentPrj->setLogFileName(currentPrj->getCurrentDir().absoluteFilePath("config.ezi")) ;
797
 
798
            if(currentPrj->parsePrjFile(ivlgFileMap,ivhdlFileMap))
799
            {
800
                listWindow->addMessage("error","EziDebug error: parse project file failed!");
801
                delete currentPrj ;
802
                setCurrentProject(NULL);
803
                QMessageBox::critical(this, QObject::tr("全部更新失败"),QObject::tr("软件内部错误!"));
804
                progressBar->setValue(0);
805
 
806
                return ;
807
            }
808
 
809
            // 5%
810
            progressBar->setValue(5);
811
 
812
            if(currentPrj->detectLogFile(READ_CHAIN_INFO))
813
            {
814
                QMessageBox::StandardButton rb = QMessageBox::question(this, tr("log文件内部被破坏"), tr("是否删除内部可能存在的扫描链代码后再进行扫描"), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
815
                if(rb == QMessageBox::Yes)
816
                {
817
                    // 遍历所有文件 删除可能存在的 EziDebug 代码
818
                    currentPrj->deleteAllEziDebugCode(ivlgFileMap,ivhdlFileMap);
819
 
820
                    QMap<QString,EziDebugScanChain*> ichainMap = currentPrj->getScanChainInfo();
821
                    QMap<QString,EziDebugScanChain*>::const_iterator k = ichainMap.constBegin() ;
822
                    while(k != ichainMap.constEnd())
823
                    {
824
                        EziDebugScanChain* pchain = k.value() ;
825
                        if(pchain)
826
                        {
827
                            delete pchain ;
828
                        }
829
                        ++k ;
830
                    }
831
                    currentPrj->cleanupChainMap();
832
 
833
                    // 原log文件 完全删除 无任何以前的信息
834
                    currentPrj->setLogFileExistFlag(false);
835
 
836
                }
837
            }
838
 
839
            // 删除 原log 文件
840
            QFile ilogFile(currentPrj->getCurrentDir().absoluteFilePath("config.ezi")) ;
841
            ilogFile.remove();
842
 
843
            // 如果 源 EziDebug_v1.0文件夹存在  暂不删除
844
 
845
            // 重新 创建新log文件
846
            if(currentPrj->createLogFile())
847
            {
848
                listWindow->addMessage("error","EziDebug error: create EziDebug config file failed!");
849
                delete currentPrj ;
850
                setCurrentProject(NULL);
851
 
852
                QMessageBox::critical(this, QObject::tr("全部更新失败"),QObject::tr("软件内部错误!"));
853
                progressBar->setValue(0);
854
 
855
                return  ;
856
            }
857
 
858
            progressBar->setValue(10);
859
 
860
            etype = EziDebugPrj::fullScanType ;
861
        }
862
        else
863
        {
864
            // 不存在则创建文件
865
            if(currentPrj->createLogFile())
866
            {
867
                listWindow->addMessage("error","EziDebug error: create EziDebug config file failed!");
868
                delete currentPrj ;
869
                setCurrentProject(NULL);
870
 
871
                QMessageBox::critical(this, QObject::tr("全部更新失败"),QObject::tr("软件内部错误!"));
872
                progressBar->setValue(0);
873
 
874
                return  ;
875
            }
876
            // 5%
877
            progressBar->setValue(5);
878
 
879
            currentPrj->setLogFileName(currentPrj->getCurrentDir().absoluteFilePath("config.ezi")) ;
880
 
881
            if(currentPrj->parsePrjFile(ivlgFileMap,ivhdlFileMap))
882
            {
883
                listWindow->addMessage("error","EziDebug error: parsePrjFile Error !");
884
                QMap<QString,EziDebugVlgFile*>::iterator i =  ivlgFileMap.begin() ;
885
                while(i != ivlgFileMap.end())
886
                {
887
                   EziDebugVlgFile* pfile = ivlgFileMap.value(i.key());
888
                   if(pfile)
889
                   {
890
                       delete pfile ;
891
                   }
892
                   ++i ;
893
                }
894
 
895
                ivlgFileMap.clear() ;
896
 
897
                // vhdl file 指针析构
898
                QMap<QString,EziDebugVhdlFile*>::iterator j =  ivhdlFileMap.begin() ;
899
                while(j != ivhdlFileMap.end())
900
                {
901
                   EziDebugVhdlFile* pfile = ivhdlFileMap.value(j.key());
902
                   if(pfile)
903
                   {
904
                       delete pfile ;
905
                   }
906
                   ++j ;
907
                }
908
                ivhdlFileMap.clear() ;
909
 
910
                delete currentPrj ;
911
                setCurrentProject(NULL);
912
 
913
                QMessageBox::critical(this, QObject::tr("全部更新失败"),QObject::tr("软件内部错误!"));
914
                progressBar->setValue(0);
915
 
916
                return ;
917
            }
918
            // 10%
919
            progressBar->setValue(10);
920
 
921
            etype = EziDebugPrj::partScanType ;
922
        }
923
 
924
        QMessageBox::information(this, QObject::tr("扫描所有代码文件"),QObject::tr("准备获取module信息"));
925
 
926
 
927
 
928
        if(currentPrj->traverseAllCodeFile(etype , ivlgFileMap , ivhdlFileMap ,iaddedinfoList,ideletedinfoList))
929
        {
930
            qDeleteAll(iaddedinfoList) ;
931
            qDeleteAll(ideletedinfoList) ;
932
            iaddedinfoList.clear();
933
            ideletedinfoList.clear();
934
 
935
            listWindow->addMessage("error","EziDebug error: traverseAllCodeFile encounter the error !");
936
            QMap<QString,EziDebugVlgFile*>::iterator i =  ivlgFileMap.begin() ;
937
            while(i != ivlgFileMap.end())
938
            {
939
                EziDebugVlgFile* pfile = ivlgFileMap.value(i.key());
940
                if(pfile)
941
                {
942
                    delete pfile ;
943
                }
944
                ++i ;
945
            }
946
            ivlgFileMap.clear() ;
947
 
948
            // vhdl file 指针析构
949
            QMap<QString,EziDebugVhdlFile*>::iterator j =  ivhdlFileMap.begin() ;
950
            while(j != ivhdlFileMap.end())
951
            {
952
                EziDebugVhdlFile* pfile = ivhdlFileMap.value(j.key());
953
                if(pfile)
954
                {
955
                    delete pfile ;
956
                }
957
                ++j ;
958
            }
959
            ivhdlFileMap.clear() ;
960
 
961
 
962
            delete currentPrj ;
963
            setCurrentProject(NULL);
964
 
965
 
966
            qDeleteAll(iaddedinfoList);
967
            qDeleteAll(ideletedinfoList);
968
 
969
            QMessageBox::critical(this, QObject::tr("全部更新失败"),QObject::tr("软件内部错误!"));
970
            progressBar->setValue(0);
971
 
972
            return ;
973
        }
974
 
975
 
976
        currentPrj->updateFileMap(ivlgFileMap,ivhdlFileMap);
977
 
978
        currentPrj->addToMacroMap() ;
979
        listWindow->addMessage("info","EziDebug info: ready to traverse instances Tree !");
980
 
981
        progressBar->setValue(65);
982
 
983
        if(currentPrj->getScanChainInfo().count())
984
        {
985
            currentPrj->backupChainMap();
986
            currentPrj->cleanupBakChainTreeItemMap();
987
            currentPrj->cleanupChainTreeItemMap();
988
        }
989
 
990
        if(currentPrj->generateTreeView())
991
        {
992
            listWindow->addMessage("error","EziDebug error: traverse instances Tree error !");
993
            delete currentPrj ;
994
            setCurrentProject(NULL);
995
 
996
            QMessageBox::critical(this, QObject::tr("全部更新失败"),QObject::tr("软件内部错误!"));
997
            progressBar->setValue(0);
998
 
999
            return ;
1000
        }
1001
 
1002
        progressBar->setValue(70);
1003
 
1004
        if(currentPrj->getBackupChainMap().count())
1005
        {
1006
            currentPrj->resumeChainMap();
1007
            currentPrj->resumeChainTreeItemMap();
1008
            // 用于清空 备份的 map
1009
            currentPrj->updateOperation(EziDebugPrj::OperateTypeNone,NULL,NULL);
1010
        }
1011
 
1012
        listWindow->addMessage("info","EziDebug info: finish traverse instances Tree !");
1013
 
1014
        pitem = currentPrj->getInstanceTreeHeadItem() ;
1015
 
1016
        EziDebugInstanceTreeItem::setProject(currentPrj);
1017
 
1018
        progressBar->setValue(75);
1019
 
1020
        // (代码中的扫描链 在 log文件中不存在  说明log文件曾经被破坏过!)
1021
        if(currentPrj->getLogFileExistFlag()&&currentPrj->getLogfileDestroyedFlag())
1022
        {
1023
            // 提示删除所有链
1024
            QMessageBox::StandardButton rb = QMessageBox::question(this, tr("部分扫描链信息丢失"), tr("是否删除所有扫描链代码"), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
1025
            if(rb == QMessageBox::Yes)
1026
            {
1027
                // 删除所有链代码
1028
                currentPrj->deleteAllEziDebugCode(ivlgFileMap,ivhdlFileMap);
1029
                // 删除所有链相关的信息
1030
                QMap<QString,EziDebugScanChain*> ichainMap = currentPrj->getScanChainInfo();
1031
                QMap<QString,EziDebugScanChain*>::const_iterator k = ichainMap.constBegin() ;
1032
                while(k != ichainMap.constEnd())
1033
                {
1034
                    EziDebugScanChain* pchain = k.value() ;
1035
                    if(pchain)
1036
                    {
1037
                        delete pchain ;
1038
                        pchain = NULL ;
1039
                    }
1040
                    ++k ;
1041
                }
1042
                currentPrj->cleanupChainMap();
1043
                currentPrj->cleanupChainTreeItemMap();
1044
                currentPrj->cleanupChainQueryTreeItemMap();
1045
 
1046
                // 删除log所有链信息 (新的log文件所以不用添加信息,此步可跳过)
1047
 
1048
                // 清空 被破坏的扫描链list
1049
                currentPrj->clearupDestroyedChainList();
1050
 
1051
            }
1052
            else
1053
            {
1054
                // 不处理
1055
            }
1056
 
1057
        }
1058
 
1059
        progressBar->setValue(80);
1060
 
1061
 
1062
        if(currentPrj->getDestroyedChainList().count())
1063
        {
1064
            // 把所有破坏掉的链打印出来
1065
            QString ichain ;
1066
            QStringList idestroyedChain = currentPrj->getDestroyedChainList() ;
1067
 
1068
            listWindow->addMessage("warning","EziDebug warning: Some chains are destroyed!");
1069
            listWindow->addMessage("warning","the chain :");
1070
            for(int i = 0 ; i < idestroyedChain.count() ;i++)
1071
            {
1072
                QString ichainName = idestroyedChain.at(i) ;
1073
 
1074
                EziDebugInstanceTreeItem *pitem = currentPrj->getChainTreeItemMap().value(ichainName);
1075
                if(pitem)
1076
                {
1077
                    ichain.append(tr("EziDebug chain:%1  topInstance:%2:%3").arg(ichainName)\
1078
                                  .arg(pitem->getModuleName()).arg(pitem->getInstanceName())) ;
1079
                }
1080
                listWindow->addMessage("warning",ichain);
1081
            }
1082
 
1083
            // 扫描链被破坏 ,提示删除
1084
            QMessageBox::StandardButton rb = QMessageBox::question(this, tr("部分扫描链被破坏"), tr("是否删除相关扫描链代码"), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
1085
            if(rb == QMessageBox::Yes)
1086
            {
1087
                QStringList iunDelChainList = currentPrj->deleteDestroyedChain(iaddedinfoList,ideletedinfoList) ;
1088
                if(iunDelChainList.count())
1089
                {
1090
                    listWindow->addMessage("error","EziDebug error: Some chains do not be deleted for some reasons!");
1091
                    for(int i = 0 ; i < iunDelChainList.count() ;i++)
1092
                    {
1093
                        listWindow->addMessage("error",tr("EziDebug chain:%1").arg(iunDelChainList.at(i)));
1094
                    }
1095
                    listWindow->addMessage("error","EziDebug error: Please check the code file is compiled successed!");
1096
                }
1097
            }
1098
        }
1099
        progressBar->setValue(85);
1100
 
1101
 
1102
        QMap<QString,EziDebugScanChain*>::const_iterator iaddedChainIter = currentPrj->getScanChainInfo().constBegin() ;
1103
        while(iaddedChainIter !=  currentPrj->getScanChainInfo().constEnd())
1104
        {
1105
           QString ichainName = iaddedChainIter.key();
1106
           struct EziDebugPrj::LOG_FILE_INFO* pinfo = new EziDebugPrj::LOG_FILE_INFO ;
1107
           memcpy(pinfo->ainfoName ,ichainName.toAscii().data(),ichainName.size()+1);
1108
           pinfo->pinfo = iaddedChainIter.value() ;
1109
           pinfo->etype = EziDebugPrj::infoTypeScanChainStructure ;
1110
           iaddedinfoList << pinfo ;
1111
           ++iaddedChainIter ;
1112
        }
1113
 
1114
        // modify the project file at last
1115
        currentPrj->preModifyPrjFile();
1116
 
1117
        progressBar->setValue(90);
1118
 
1119
        if(currentPrj->changedLogFile(iaddedinfoList,ideletedinfoList))
1120
        {
1121
            qDebug() << QObject::tr("保存log文件错误!");
1122
        }
1123
 
1124
        qDeleteAll(iaddedinfoList);
1125
        qDeleteAll(ideletedinfoList);
1126
 
1127
        pthread->start();
1128
 
1129
        emit updateTreeView(pitem);
1130
 
1131
        progressBar->setValue(100);
1132
 
1133
        QMessageBox::information(this, QObject::tr("全部更新"),QObject::tr("更新代码完毕!"));
1134
 
1135
    }
1136
    progressBar->setValue(0);
1137
 
1138
}
1139
 
1140
 
1141
int ToolWindow::deleteScanChain()
1142
{
1143
    EziDebugInstanceTreeItem * ptreeItem = NULL ;
1144
    EziDebugScanChain *pchain = NULL ;
1145
    UpdateDetectThread* pthread = NULL ;
1146
    QList<EziDebugPrj::LOG_FILE_INFO*> iaddedinfoList ;
1147
    QList<EziDebugPrj::LOG_FILE_INFO*> ideletedinfoList ;
1148
 
1149
    // 是否需要更新
1150
    if(isNeededUpdate)
1151
    {
1152
        // 提示需要 请快速更新后再进行 操作
1153
        QMessageBox::information(this, QObject::tr("删除扫描链"),QObject::tr("检测到有文件被更新,请更新后再进行删除"));
1154
 
1155
        return 0 ;
1156
    }
1157
    else
1158
    {
1159
        //
1160
        UpdateDetectThread *pthread = currentPrj->getThread();
1161
        pthread->update() ;
1162
        if(isNeededUpdate)
1163
        {
1164
            QMessageBox::information(this, QObject::tr("删除扫描链"),QObject::tr("检测到有文件被更新,请更新后再进行删除"));
1165
            return 0 ;
1166
        }
1167
    }
1168
 
1169
 
1170
    ptreeItem = listWindow->getCurrentTreeItem();
1171
    if(!ptreeItem)
1172
    {
1173
        QMessageBox::critical(this, QObject::tr("删除扫描链"),QObject::tr("软件内部错误!"));
1174
        return 1;
1175
    }
1176
 
1177
    pchain = ptreeItem->getScanChainInfo();
1178
    if(!pchain)
1179
    {
1180
        QMessageBox::critical(this, QObject::tr("删除扫描链"),QObject::tr("软件内部错误!"));
1181
        return 1;
1182
    }
1183
 
1184
 
1185
    pchain->backupFileList();
1186
 
1187
    pchain->clearupFileList();
1188
 
1189
 
1190
    // 停止检测更新   退出线程
1191
    pthread = currentPrj->getThread() ;
1192
    if(pthread->isRunning())
1193
    {
1194
        pthread->quit();
1195
        pthread->wait();
1196
    }
1197
 
1198
    if(!ptreeItem->deleteScanChain(EziDebugPrj::OperateTypeDelSingleScanChain))
1199
    {
1200
        /*对上一步操作进行善后*/
1201
        if(currentPrj->eliminateLastOperation())
1202
        {
1203
            listWindow->addMessage("error","EziDebug error: delete last chain error!");
1204
            QMessageBox::critical(this, QObject::tr("删除扫描链"),QObject::tr("软件内部错误!"));
1205
 
1206
            return  1 ;
1207
        }
1208
 
1209
        /*更新上一步操作*/
1210
        currentPrj->updateOperation(EziDebugPrj::OperateTypeDelSingleScanChain,pchain,ptreeItem);
1211
 
1212
        /*将扫描链 从 链 map 取下来*/
1213
        currentPrj->eliminateChainFromMap(pchain->getChainName());
1214
 
1215
        /*将扫描链 从 树状节点 map 取下来*/
1216
        currentPrj->eliminateTreeItemFromMap(pchain->getChainName());
1217
 
1218
        /*重置节点下 链指针*/
1219
        ptreeItem->setScanChainInfo(NULL);
1220
 
1221
        /*删除用于查询的 map*/
1222
        currentPrj->eliminateTreeItemFromQueryMap(ptreeItem->getNameData());
1223
 
1224
        /*改动 log 文件 */
1225
        struct EziDebugPrj::LOG_FILE_INFO* pdelChainInfo = new EziDebugPrj::LOG_FILE_INFO ;
1226
        memcpy(pdelChainInfo->ainfoName,pchain->getChainName().toAscii().data(),pchain->getChainName().size()+1);
1227
        pdelChainInfo->pinfo = NULL ;
1228
        pdelChainInfo->etype = EziDebugPrj::infoTypeScanChainStructure ;
1229
        ideletedinfoList << pdelChainInfo ;
1230
 
1231
        QStringList iscanFileList = pchain->getScanedFileList() ;
1232
 
1233
        for(int i = 0 ; i < iscanFileList.count() ; i++)
1234
        {
1235
            QString ifileName = iscanFileList.at(i) ;
1236
            QString irelativeFileName = currentPrj->getCurrentDir().relativeFilePath(ifileName);
1237
 
1238
            // 文件被修改了 需要重新保存文件日期
1239
            struct EziDebugPrj::LOG_FILE_INFO* pdelFileInfo = new EziDebugPrj::LOG_FILE_INFO ;
1240
            pdelFileInfo->etype = EziDebugPrj::infoTypeFileInfo ;
1241
            pdelFileInfo->pinfo = NULL ;
1242
            memcpy(pdelFileInfo->ainfoName , irelativeFileName.toAscii().data() , irelativeFileName.size()+1);
1243
            ideletedinfoList.append(pdelFileInfo);
1244
 
1245
            struct EziDebugPrj::LOG_FILE_INFO* paddFileInfo = new EziDebugPrj::LOG_FILE_INFO ;
1246
            paddFileInfo->etype = EziDebugPrj::infoTypeFileInfo ;
1247
 
1248
 
1249
            if(irelativeFileName.endsWith(".v"))
1250
            {
1251
                EziDebugVlgFile *pvlgFile = currentPrj->getPrjVlgFileMap().value(irelativeFileName,NULL);
1252
                paddFileInfo->pinfo = pvlgFile ;
1253
            }
1254
            else if(irelativeFileName.endsWith(".vhd"))
1255
            {
1256
                EziDebugVhdlFile *pvhdlFile = currentPrj->getPrjVhdlFileMap().value(irelativeFileName,NULL);
1257
                paddFileInfo->pinfo = pvhdlFile ;
1258
            }
1259
            else
1260
            {
1261
                delete paddFileInfo ;
1262
                continue ;
1263
            }
1264
 
1265
            memcpy(paddFileInfo->ainfoName , irelativeFileName.toAscii().data(), irelativeFileName.size()+1);
1266
            iaddedinfoList.append(paddFileInfo);
1267
        }
1268
 
1269
 
1270
        if(currentPrj->changedLogFile(iaddedinfoList,ideletedinfoList))
1271
        {
1272
            // 提示 保存 log 文件出错
1273
            qDebug() << tr("保存log文件出错") ;
1274
        }
1275
 
1276
//        // 根据链的个数 删除创建的自定义core文件
1277
//        if(!currentPrj->getScanChainInfo().count())
1278
//        {
1279
//            // 删除 创建的文件夹
1280
//            QDir idir(currentPrj->getCurrentDir().absolutePath() + EziDebugScanChain::getUserDir());
1281
//            idir.remove(EziDebugScanChain::getChainRegCore()+tr(".v"));
1282
//            idir.remove(EziDebugScanChain::getChainToutCore()+tr(".v"));
1283
//            currentPrj->getCurrentDir().rmdir(idir.absolutePath());
1284
//        }
1285
 
1286
 
1287
        qDeleteAll(ideletedinfoList);
1288
        qDeleteAll(iaddedinfoList);
1289
 
1290
        pthread->start();
1291
 
1292
        QMessageBox::information(this, QObject::tr("删除扫描链"),QObject::tr("删除扫描链成功!"));
1293
 
1294
    }
1295
    else
1296
    {
1297
        /*读取删除链 已经扫描过的文件,从已经备份的文件进行恢复*/
1298
        for(int i = 0 ; i < pchain->getScanedFileList().count();i++)
1299
        {
1300
            // 获取备份的文件名全称
1301
            QString ifileName = pchain->getScanedFileList().at(i) ;
1302
            QFileInfo ifileInfo(pchain->getScanedFileList().at(i));
1303
            QString ieziDebugFileSuffix ;
1304
            ieziDebugFileSuffix.append(QObject::tr(".delete.%1").arg(currentPrj->getLastOperateChain()->getChainName()));
1305
 
1306
            QString ibackupFileName = currentPrj->getCurrentDir().absolutePath() \
1307
                    + EziDebugScanChain::getUserDir() + ifileInfo.fileName() \
1308
                    + ieziDebugFileSuffix;
1309
            QFile ibackupFile(ibackupFileName) ;
1310
 
1311
            QFileInfo ibakfileInfo(ibackupFileName);
1312
            QDateTime idateTime = ibakfileInfo.lastModified();
1313
            // 已经是绝对路径了
1314
 
1315
            // 更改时间
1316
            QString irelativeName = currentPrj->getCurrentDir().relativeFilePath(ifileName) ;
1317
 
1318
            if(ibakfileInfo.exists())
1319
            {
1320
                if(ifileName.endsWith(".v"))
1321
                {
1322
                    currentPrj->getPrjVlgFileMap().value(irelativeName)->remove();
1323
                    ibackupFile.copy(ifileName);
1324
                    currentPrj->getPrjVlgFileMap().value(irelativeName)->modifyStoredTime(idateTime);
1325
                }
1326
                else if(ifileName.endsWith(".vhd"))
1327
                {
1328
                    currentPrj->getPrjVlgFileMap().value(irelativeName)->remove();
1329
                    ibackupFile.copy(ifileName);
1330
                    currentPrj->getPrjVlgFileMap().value(irelativeName)->modifyStoredTime(idateTime);
1331
                }
1332
                else
1333
                {
1334
                    // do nothing
1335
                }
1336
                // 删除当前备份的文件
1337
                ibackupFile.remove();
1338
            }
1339
        }
1340
 
1341
        pchain->resumeFileList();
1342
 
1343
        qDeleteAll(ideletedinfoList);
1344
        qDeleteAll(iaddedinfoList);
1345
 
1346
        pthread->start();
1347
 
1348
        QMessageBox::warning(this, QObject::tr("删除扫描链"),QObject::tr("删除扫描链失败!"));
1349
 
1350
        return 1;
1351
    }
1352
 
1353
    return 0 ;
1354
}
1355
 
1356
void ToolWindow::addScanChain()
1357
{
1358
    EziDebugInstanceTreeItem * ptreeItem = NULL ;
1359
    EziDebugModule* pmodule = NULL ;
1360
    UpdateDetectThread* pthread = NULL ;
1361
    QList<EziDebugPrj::LOG_FILE_INFO*> iaddedinfoList ;
1362
    QList<EziDebugPrj::LOG_FILE_INFO*> ideletedinfoList ;
1363
    QMap<QString,int> iregNumMap ;
1364
    bool isrepeatFlag = false ;
1365
    QString ichainName = tr("chn") ;
1366
    int nresult = 0 ;
1367
    int i = 0 ;
1368
 
1369
 
1370
    // 是否需要更新
1371
    if(isNeededUpdate)
1372
    {
1373
        // 提示需要 请快速更新后再进行 操作
1374
        QMessageBox::information(0, QObject::tr("添加扫描链"),QObject::tr("检测到有文件被更新,请更新后再进行添加链!"));
1375
 
1376
        return ;
1377
    }
1378
    else
1379
    {
1380
        //
1381
        UpdateDetectThread *pthread = currentPrj->getThread();
1382
        pthread->update() ;
1383
        if(isNeededUpdate)
1384
        {
1385
            QMessageBox::information(0, QObject::tr("添加扫描链"),QObject::tr("检测到有文件被更新,请更新后再进行添加链!"));
1386
            return ;
1387
        }
1388
    }
1389
 
1390
    ptreeItem = listWindow->getCurrentTreeItem();
1391
    if(!ptreeItem)
1392
    {
1393
        /*向文本栏提示 添加链错误 该节点不存在*/
1394
        listWindow->addMessage("error","EziDebug error: The tree item is not exitst!");
1395
        QMessageBox::critical(this, QObject::tr("添加扫描链"),QObject::tr("软件内部错误!"));
1396
 
1397
        return ;
1398
    }
1399
 
1400
    if(currentPrj->getPrjModuleMap().contains(ptreeItem->getModuleName()))
1401
    {
1402
        pmodule =  currentPrj->getPrjModuleMap().value(ptreeItem->getModuleName());
1403
        if(!pmodule)
1404
        {
1405
            /*向文本栏提示 添加链错误 该节点对应的module无定义*/
1406
            listWindow->addMessage("error", tr("EziDebug error: the module:%1 object is null pointer!").arg(ptreeItem->getModuleName()));
1407
            QMessageBox::critical(this, QObject::tr("添加扫描链"),QObject::tr("软件内部错误!"));
1408
 
1409
            return ;
1410
        }
1411
    }
1412
    else
1413
    {
1414
        /*向文本栏提示 添加链错误 该节点对应的module无定义*/
1415
        listWindow->addMessage("error", tr("EziDebug error: the module:").arg(ptreeItem->getModuleName()) + tr("has no definition!"));
1416
        QMessageBox::critical(this, QObject::tr("添加扫描链"),QObject::tr("软件内部错误!"));
1417
 
1418
        return ;
1419
    }
1420
    //QString iinstanceName = ptreeItem->getInstanceName() ;
1421
 
1422
    /*判断扫描链名字是否重复*/
1423
    isrepeatFlag = currentPrj->getScanChainInfo().contains(ichainName) ;
1424
    while(isrepeatFlag)
1425
    {
1426
        ichainName = tr("chn") + tr("%1").arg(i) ;
1427
        isrepeatFlag = currentPrj->getScanChainInfo().contains(ichainName) ;
1428
        i++ ;
1429
    }
1430
 
1431
    if((pmodule->getLocatedFileName()).endsWith(".v"))
1432
    {
1433
        QMap<QString,EziDebugInstanceTreeItem::SCAN_CHAIN_STRUCTURE *> ichainListStructureMap ;
1434
        int nmaxRegNum = currentPrj->getMaxRegNumPerChain() ;
1435
        EziDebugVlgFile* pvlgFile =  currentPrj->getPrjVlgFileMap().value(pmodule->getLocatedFileName());
1436
//      EziDebugInstanceTreeItem *pparent = ptreeItem->parent();
1437
        EziDebugModule* pmodule = currentPrj->getPrjModuleMap().value(ptreeItem->getModuleName()) ;
1438
        EziDebugScanChain * pscanChain = new EziDebugScanChain(ichainName);
1439
        pscanChain->traverseAllInstanceNode(ptreeItem) ;
1440
        pscanChain->traverseChainAllReg(ptreeItem) ;
1441
        QMap<QString,QString>::const_iterator i =  pmodule->getClockSignal().constBegin() ;
1442
 
1443
        //1、遍历树状结构 先查找有几个clock 分别计算每个 clock 下面 寄存器 个数,
1444
        // 从右键 选择的 顶层节点开始 往下一层层遍历
1445
        while(i != pmodule->getClockSignal().constEnd())
1446
        {
1447
            //QString iclock = pparent->getModuleClockMap().value(i.key());
1448
            int nbitWidth  = 0  ;
1449
            /*获得当前节点的clock名字*/
1450
            int nregBitCount = 0 ;
1451
            ptreeItem->getAllRegNum(i.key() ,ichainName, nregBitCount , nbitWidth , pscanChain->getInstanceItemList());
1452
            if((!nregBitCount) && (!nbitWidth))
1453
            {
1454
                listWindow->addMessage("warning", tr("EziDebug warning: There is no reg with Clock:%1 in the chain:%2").arg(i.key()).arg(ichainName));
1455
                ++i;
1456
                continue ;
1457
            }
1458
            iregNumMap.insert(i.key(),nbitWidth*currentPrj->getMaxRegNumPerChain()+nregBitCount);
1459
            nbitWidth++ ;
1460
 
1461
            // 根据设置的 最大链个数 得到要 每个 clock 要 分配的 TDI、TDO 位宽  ,加入到对应的 map 中
1462
 
1463
            EziDebugInstanceTreeItem::SCAN_CHAIN_STRUCTURE *pchainStructure = (EziDebugInstanceTreeItem::SCAN_CHAIN_STRUCTURE *)operator new(sizeof(EziDebugInstanceTreeItem::SCAN_CHAIN_STRUCTURE));
1464
            pchainStructure->m_uncurrentChainNumber = 0 ;
1465
            pchainStructure->m_untotalChainNumber = nbitWidth ;
1466
            pchainStructure->m_unleftRegNumber = nmaxRegNum ;
1467
 
1468
 
1469
            ichainListStructureMap.insert(i.key(),pchainStructure);
1470
            ++i ;
1471
 
1472
        }
1473
 
1474
        if(!ichainListStructureMap.count())
1475
        {
1476
            listWindow->addMessage("warning", tr("EziDebug warning: There is no reg in the chain!"));
1477
            delete pscanChain ;
1478
            QMessageBox::warning(this, QObject::tr("添加扫描链"),QObject::tr("添加扫描链失败!"));
1479
 
1480
            return  ;
1481
        }
1482
 
1483
 
1484
        QMap<QString,EziDebugInstanceTreeItem::SCAN_CHAIN_STRUCTURE *>::const_iterator iscanchain = ichainListStructureMap.constBegin();
1485
        while(iscanchain != ichainListStructureMap.constEnd())
1486
        {
1487
            // parent clock(key) -> child clock(value)
1488
 
1489
            QString iclock = ptreeItem->parent()->getModuleClockMap(ptreeItem->getInstanceName()).key(iscanchain.key(),QString());
1490
            if(iclock.isEmpty())
1491
            {
1492
                listWindow->addMessage("warning", tr("EziDebug warning: can't find the module %1 's clock ,insert scan chain failed !").arg(ptreeItem->getModuleName()));
1493
                delete pscanChain ;
1494
                QMessageBox::critical(this, QObject::tr("添加扫描链"),QObject::tr("添加扫描链失败!"));
1495
 
1496
                return ;
1497
            }
1498
            EziDebugInstanceTreeItem::SCAN_CHAIN_STRUCTURE * pchainSt = iscanchain.value();
1499
            pscanChain->setChildChainNum(iclock,pchainSt->m_untotalChainNumber);
1500
            ++iscanchain ;
1501
        }
1502
 
1503
        //2、创建相应的用户module core
1504
        // 如果是第一次加入扫描链 则需要创建  或者 误删除掉了 则重新添加自定义 module
1505
        if(!currentPrj->getScanChainInfo().count())
1506
        {
1507
            if(pvlgFile->createUserCoreFile(currentPrj))
1508
            {
1509
                delete pscanChain ;
1510
                listWindow->addMessage("warning", tr("EziDebug error: create EziDebug core error!"));
1511
                QMessageBox::critical(this, QObject::tr("添加扫描链"),QObject::tr("软件内部错误!"));
1512
 
1513
                return ;
1514
            }
1515
        }
1516
        else
1517
        {
1518
            /*误删除 1、使用过程中 2、没有使用时就删除掉了  在扫描log文件时就没有相应的*/
1519
        }
1520
 
1521
        /*遍历链状树,计算 每个module 在扫描连中例化的次数*/
1522
        //ptreeItem->traverseChainTreeItem();
1523
 
1524
        /*在插入扫描链之前 清空扫描过的文件列表*/
1525
        pscanChain->clearupFileList();
1526
 
1527
        // 插入扫描链之前  停止检测更新   退出线程
1528
        pthread = currentPrj->getThread() ;
1529
        if(pthread->isRunning())
1530
        {
1531
            pthread->quit();
1532
            pthread->wait();
1533
        }
1534
 
1535
 
1536
 
1537
        // m_pheadItem
1538
        pscanChain->setHeadTreeItem(ptreeItem);
1539
 
1540
        if(!(nresult = ptreeItem->insertScanChain(ichainListStructureMap,pscanChain,ptreeItem->getInstanceName())))
1541
        {
1542
            if(currentPrj->eliminateLastOperation())
1543
            {
1544
                listWindow->addMessage("error", tr("EziDebug error: delete last chain error!"));
1545
                QMessageBox::critical(this, QObject::tr("添加扫描链"),QObject::tr("软件内部错误!"));
1546
 
1547
                return ;
1548
            }
1549
 
1550
            /*更新上一步操作*/
1551
            currentPrj->updateOperation(EziDebugPrj::OperateTypeAddScanChain,pscanChain,ptreeItem);
1552
 
1553
            /*将新添加的 扫描链加入 到 prj 的 的 map 中*/
1554
            currentPrj->addToChainMap(pscanChain);
1555
 
1556
            /*加入到 树状节点 map 中*/
1557
            currentPrj->addToTreeItemMap(pscanChain->getChainName(),ptreeItem);
1558
 
1559
            /*加入到 用于查询 的 节点 map 中*/
1560
            currentPrj->addToQueryItemMap(ptreeItem->getNameData(),ptreeItem);
1561
 
1562
            /* 重置 节点下 链指针 */
1563
            ptreeItem->setScanChainInfo(pscanChain);
1564
 
1565
            /*保存各个时钟寄存器 总数 信息*/
1566
            QMap<QString,int>::const_iterator iclkRegNumIter = iregNumMap.constBegin();
1567
            while(iclkRegNumIter != iregNumMap.constEnd())
1568
            {
1569
                QString ichainClock = pscanChain->getChainClock(ptreeItem->getInstanceName(),iclkRegNumIter.key());
1570
                pscanChain->setChainRegCount(ichainClock,iclkRegNumIter.value());
1571
                ++iclkRegNumIter ;
1572
            }
1573
 
1574
            struct EziDebugPrj::LOG_FILE_INFO* pinfo = new EziDebugPrj::LOG_FILE_INFO ;
1575
            memcpy(pinfo->ainfoName ,pscanChain->getChainName().toAscii().data(),pscanChain->getChainName().size()+1);
1576
            pinfo->pinfo = pscanChain ;
1577
            pinfo->etype = EziDebugPrj::infoTypeScanChainStructure ;
1578
            iaddedinfoList << pinfo ;
1579
 
1580
            pscanChain->removeScanedFileListDuplicate();
1581
            for(int i = 0 ; i < pscanChain->getScanedFileList().count() ; i++)
1582
            {
1583
                // 文件被修改了 需要重新保存文件日期
1584
 
1585
                QString ifileName = pscanChain->getScanedFileList().at(i) ;
1586
 
1587
                struct EziDebugPrj::LOG_FILE_INFO* pdelFileInfo = new EziDebugPrj::LOG_FILE_INFO ;
1588
                pdelFileInfo->etype = EziDebugPrj::infoTypeFileInfo ;
1589
                pdelFileInfo->pinfo = NULL ;
1590
 
1591
                qstrcpy(pdelFileInfo->ainfoName,currentPrj->getCurrentDir().relativeFilePath(ifileName).toAscii().data()) ;
1592
                ideletedinfoList.append(pdelFileInfo);
1593
 
1594
                struct EziDebugPrj::LOG_FILE_INFO* paddFileInfo = new EziDebugPrj::LOG_FILE_INFO ;
1595
                paddFileInfo->etype = EziDebugPrj::infoTypeFileInfo ;
1596
 
1597
                if(ifileName.endsWith(".v"))
1598
                {
1599
                    paddFileInfo->pinfo = currentPrj->getPrjVlgFileMap().value(currentPrj->getCurrentDir().relativeFilePath(ifileName)) ;
1600
                }
1601
                else if(ifileName.endsWith(".vhd"))
1602
                {
1603
                    paddFileInfo->pinfo = currentPrj->getPrjVhdlFileMap().value(currentPrj->getCurrentDir().relativeFilePath(ifileName)) ;
1604
                }
1605
                else
1606
                {
1607
                    qDeleteAll(iaddedinfoList);
1608
                    qDeleteAll(ideletedinfoList);
1609
                    pthread->start();
1610
 
1611
                    listWindow->addMessage("warning", tr("EziDebug warning: detect the unknown file!"));
1612
                    continue ;
1613
                }
1614
                qstrcpy(pdelFileInfo->ainfoName,currentPrj->getCurrentDir().relativeFilePath(ifileName).toAscii().data()) ;
1615
                iaddedinfoList.append(paddFileInfo);
1616
            }
1617
 
1618
 
1619
            if(currentPrj->changedLogFile(iaddedinfoList,ideletedinfoList))
1620
            {
1621
                qDebug() << tr("Warnning:addScanChain Save Log File Error!");
1622
            }
1623
 
1624
            qDeleteAll(iaddedinfoList);
1625
            qDeleteAll(ideletedinfoList);
1626
 
1627
            listWindow->addMessage("info","EziDebug info: Create A New ScanChain!");
1628
            QStandardItem * pitem = listWindow->addMessage("info",tr("The New ScanChain Parameter:"));
1629
            listWindow->addMessage("process" , tr("      The chain name: %1").arg(pscanChain->getChainName()),pitem);
1630
            listWindow->addMessage("process" , tr("      The chain topNode: %1").arg(ptreeItem->getNameData()),pitem);
1631
            QString iclockNumStr ;
1632
            QString itraversedInstStr ;
1633
            QMap<QString,QVector<QStringList> > iregChain = pscanChain->getRegChain();
1634
            QMap<QString,QVector<QStringList> >::const_iterator iregChainIter = iregChain.constBegin() ;
1635
            while( iregChainIter != iregChain.constEnd())
1636
            {
1637
                iclockNumStr.append(tr("%1 (%2)     ").arg(pscanChain->getChainRegCount(iregChainIter.key())).arg(iregChainIter.key()));
1638
                ++iregChainIter ;
1639
            }
1640
 
1641
            listWindow->addMessage("process" , tr("      The chain total reg number: %1").arg(iclockNumStr),pitem);
1642
 
1643
            listWindow->addMessage("process" , tr("      The traversed NodeList:"),pitem);
1644
 
1645
            for(int j = 0 ; j < pscanChain->getInstanceItemList().count() ;j++)
1646
            {
1647
                if(j == 0)
1648
                {
1649
                    itraversedInstStr.append("  ->  ");
1650
                }
1651
                if(j == (pscanChain->getInstanceItemList().count()-1))
1652
                {
1653
                    itraversedInstStr.append(pscanChain->getInstanceItemList().at(j)) ;
1654
                }
1655
                else
1656
                {
1657
                    itraversedInstStr.append(pscanChain->getInstanceItemList().at(j) + tr("  ->  ")) ;
1658
                }
1659
                if((j+1)%3 == 0)
1660
                {
1661
                    listWindow->addMessage("process" , tr("      ") + itraversedInstStr,pitem);
1662
                    itraversedInstStr.clear();
1663
                }
1664
            }
1665
 
1666
            if(!itraversedInstStr.isEmpty())
1667
            {
1668
                listWindow->addMessage("process" , tr("      ") + itraversedInstStr,pitem);
1669
            }
1670
 
1671
            /*加入扫描链成功后 ,去使能 树状节点的 右键菜单中 添加链功能*/
1672
//          listWindow->m_paddChainAct->setEnabled(false);
1673
//          listWindow->m_pdeleteChainAct->setEnabled(true);
1674
 
1675
            // 向工程文件中加入 新添加的文件
1676
            // "EziDebug_1.0/_EziDebug_ScanChainReg.v"
1677
            // "EziDebug_1.0/_EziDebug_TOUT_m.v"
1678
            // 单纯修改 restore 文件无效  必须手工添加 工程文件
1679
            nresult = currentPrj->chkEziDebugFileInvolved() ;
1680
            if(nresult == 0)
1681
            {
1682
                QMessageBox::information(this , QObject::tr("注意") , QObject::tr("请将当前工程路径下EziDebug_v1.0目录下的文件加入到工程中!"));
1683
            }
1684
            else if(nresult == -1)
1685
            {
1686
                listWindow->addMessage("error" , tr("EziDebug Error:Please check project file!"));
1687
            }
1688
            else
1689
            {
1690
                //
1691
            }
1692
 
1693
 
1694
            // 生成 signaltap 文件 或者 cdc 文件
1695
            currentPrj->createCfgFile(ptreeItem);
1696
 
1697
            listWindow->addMessage("info",tr("EziDebug info: Before you Synthesis the project ,Please "
1698
                                             "add the source files under \"EziDebug_v1.0\" directory to your project!"));
1699
 
1700
            //qDebug() << "add Scan Chain Success !";
1701
 
1702
            pthread->start();
1703
 
1704
            QMessageBox::information(this, QObject::tr("添加扫描链"),QObject::tr("添加扫描链成功!"));
1705
 
1706
        }
1707
        else
1708
        {
1709
 
1710
            /*读取删除链 已经扫描过的文件,从已经备份的文件中恢复*/
1711
            for(int i = 0 ; i < pscanChain->getScanedFileList().count();i++)
1712
            {
1713
                // 获取备份的文件名全称
1714
                QString ifileName = pscanChain->getScanedFileList().at(i) ;
1715
                QFileInfo ifileInfo(ifileName);
1716
                QString ieziDebugFileSuffix ;
1717
 
1718
                ieziDebugFileSuffix.append(QObject::tr(".add.%1").arg(pscanChain->getChainName()));
1719
 
1720
                QString ibackupFileName = currentPrj->getCurrentDir().absolutePath() \
1721
                        + EziDebugScanChain::getUserDir()+ tr("/")+ ifileInfo.fileName() \
1722
                        + ieziDebugFileSuffix;
1723
                QFile ibackupFile(ibackupFileName) ;
1724
                QFileInfo ibakfileInfo(ibackupFileName);
1725
                QDateTime idateTime = ibakfileInfo.lastModified();
1726
                // 已经是绝对路径了
1727
 
1728
                // 更改时间
1729
                QString irelativeName = currentPrj->getCurrentDir().relativeFilePath(ifileName) ;
1730
 
1731
                if(ibakfileInfo.exists())
1732
                {
1733
                    if(ifileName.endsWith(".v"))
1734
                    {
1735
                        currentPrj->getPrjVlgFileMap().value(irelativeName)->remove();
1736
                        ibackupFile.copy(ifileName);
1737
                        currentPrj->getPrjVlgFileMap().value(irelativeName)->modifyStoredTime(idateTime);
1738
                    }
1739
                    else if(ifileName.endsWith(".vhd"))
1740
                    {
1741
                        currentPrj->getPrjVlgFileMap().value(irelativeName)->remove();
1742
                        ibackupFile.copy(ifileName);
1743
                        currentPrj->getPrjVlgFileMap().value(irelativeName)->modifyStoredTime(idateTime);
1744
                    }
1745
                    else
1746
                    {
1747
                        // do nothing
1748
                    }
1749
                    // 删除当前备份的文件
1750
                    ibackupFile.remove();
1751
                }
1752
            }
1753
 
1754
            pscanChain->setHeadTreeItem(NULL);
1755
 
1756
            /*删除新创建的扫描链*/
1757
            delete pscanChain ;
1758
 
1759
            qDeleteAll(iaddedinfoList);
1760
            qDeleteAll(ideletedinfoList);
1761
 
1762
            pthread->start();
1763
 
1764
            if(nresult == 2)
1765
            {
1766
                listWindow->addMessage("error" , tr("The top clock is not finded for the clock name is not correspond!"));
1767
                QMessageBox::warning(this, QObject::tr("添加扫描链"),QObject::tr("添加扫描链失败!"));
1768
                return ;
1769
            }
1770
            goto ErrorHandle ;
1771
        }
1772
    }
1773
    else if((pmodule->getLocatedFileName()).endsWith(".vhd"))
1774
    {
1775
        //currentPrj->m_ivhdlFileMap ;
1776
    }
1777
    else
1778
    {
1779
 
1780
    }
1781
 
1782
    return ;
1783
 
1784
ErrorHandle:
1785
    QMessageBox::critical(this, QObject::tr("添加扫描链"),QObject::tr("添加扫描链失败!"));
1786
 
1787
    return ;
1788
 
1789
}
1790
 
1791
int ToolWindow::deleteAllChain()
1792
{
1793
    //EziDebugScanChain *plastChain = NULL ;
1794
    QMap<QString,EziDebugInstanceTreeItem*> ichainTreeItemMap ;
1795
    UpdateDetectThread* pthread = NULL ;
1796
    QList<EziDebugPrj::LOG_FILE_INFO*> iaddedinfoList ;
1797
    QList<EziDebugPrj::LOG_FILE_INFO*> ideletedinfoList ;
1798
    QStringList ifileList  ;
1799
 
1800
    //qDebug() << "deleteAllChain";
1801
 
1802
 
1803
    if(!currentPrj)
1804
    {
1805
        QMessageBox::information(this, QObject::tr("删除所有扫描链"),QObject::tr("工程不存在!"));
1806
        return 0 ;
1807
    }
1808
 
1809
    // 是否需要更新
1810
    if(isNeededUpdate)
1811
    {
1812
        // 提示需要 请快速更新后再进行 操作
1813
        QMessageBox::information(this, QObject::tr("删除所有扫描链"),QObject::tr("检测到有文件被更新,检测到有文件被更新,请更新后再进行删除所有链操作!"));
1814
        return 0 ;
1815
    }
1816
    else
1817
    {
1818
        //
1819
        UpdateDetectThread *pthread = currentPrj->getThread();
1820
        pthread->update() ;
1821
        if(isNeededUpdate)
1822
        {
1823
            QMessageBox::information(this, QObject::tr("删除所有扫描链"),QObject::tr("检测到有文件被更新,请更新后再进行删除所有链操作!"));
1824
            return 0 ;
1825
        }
1826
    }
1827
 
1828
 
1829
    // 从扫描链 获取所有的 链信息
1830
    ichainTreeItemMap = currentPrj->getChainTreeItemMap() ;
1831
 
1832
    if(!ichainTreeItemMap.size())
1833
    {
1834
        QMessageBox::information(this, QObject::tr("删除所有扫描链"),QObject::tr("不存在任何扫描链!"));
1835
        return 0 ;
1836
    }
1837
    //QMap<QString,EziDebugScanChain*> ichainMap = currentPrj->getScanChainInfo();
1838
 
1839
    /*成功删除所有链之后 删除上一步操作 备份的文件*/
1840
//    plastChain = currentPrj->getLastOperateChain() ;
1841
//    QStringList iscanFileList = plastChain->getScanedFileList() ;
1842
 
1843
    /*对所有树状节点 备份 针对 undo  deleteAllChain 操作*/
1844
    currentPrj->backupChainTreeItemMap();
1845
 
1846
    /*对所有链进行备份*/
1847
    currentPrj->backupChainMap();
1848
 
1849
    //
1850
    currentPrj->backupChainQueryTreeItemMap();
1851
 
1852
    QMap<QString,EziDebugScanChain*>::const_iterator ibakiterator = currentPrj->getBackupChainMap().constBegin();
1853
 
1854
    // 删除扫描链之前  停止检测更新   退出线程
1855
    pthread = currentPrj->getThread() ;
1856
    if(pthread->isRunning())
1857
    {
1858
        pthread->quit();
1859
        pthread->wait();
1860
    }
1861
 
1862
    QMap<QString,EziDebugInstanceTreeItem*>::const_iterator i = ichainTreeItemMap.constBegin();
1863
    QMap<QString,EziDebugInstanceTreeItem*>::const_iterator backup = i ;
1864
    while(i != ichainTreeItemMap.constEnd())
1865
    {
1866
        EziDebugInstanceTreeItem * ptreeItem = i.value();
1867
        if(!ptreeItem)
1868
        {
1869
            pthread->start();
1870
            QMessageBox::critical(this, QObject::tr("删除所有扫描链"),QObject::tr("软件内部错误!"));
1871
            return 1;
1872
        }
1873
 
1874
        EziDebugScanChain *pchain = ptreeItem->getScanChainInfo();
1875
        if(!pchain)
1876
        {
1877
            pthread->start();
1878
            QMessageBox::critical(this, QObject::tr("删除所有扫描链"),QObject::tr("软件内部错误!"));
1879
            return 1;
1880
        }
1881
 
1882
        pchain->backupFileList();
1883
 
1884
        pchain->clearupFileList();
1885
 
1886
 
1887
        if(!ptreeItem->deleteScanChain(EziDebugPrj::OperateTypeDelAllScanChain))
1888
        {
1889
           /*重置节点下 链指针*/
1890
           ptreeItem->setScanChainInfo(NULL);
1891
        }
1892
        else
1893
        {
1894
            backup = i ;
1895
            /*如果在删除扫描链过程中 出现错误*/
1896
            goto ErrorHandle;
1897
        }
1898
        ++i ;
1899
    }
1900
 
1901
 
1902
    if(currentPrj->eliminateLastOperation())
1903
    {
1904
        qDebug() << tr("删除上一次链错误");
1905
        pthread->start();
1906
        //QMessageBox::critical(this, QObject::tr("删除所有扫描链"),QObject::tr("软件内部错误!"));
1907
 
1908
        goto ErrorHandle;
1909
    }
1910
 
1911
 
1912
    /*更新上一步操作*/
1913
    currentPrj->updateOperation(EziDebugPrj::OperateTypeDelAllScanChain,NULL,NULL);
1914
 
1915
    /*清空 treeItemMap*/
1916
    currentPrj->cleanupChainTreeItemMap();
1917
 
1918
    /*清空 chainMap*/
1919
    currentPrj->cleanupChainMap();
1920
 
1921
    // 全部删除 按键 去使能
1922
    while(ibakiterator != currentPrj->getBackupChainMap().constEnd())
1923
    {
1924
        QString ichainName = ibakiterator.key() ;
1925
        EziDebugScanChain *pchain = ibakiterator.value();
1926
        struct EziDebugPrj::LOG_FILE_INFO* pinfo = new EziDebugPrj::LOG_FILE_INFO ;
1927
        qstrcpy(pinfo->ainfoName,ichainName.toAscii().data());
1928
        pinfo->pinfo = NULL ;
1929
        pinfo->etype = EziDebugPrj::infoTypeScanChainStructure ;
1930
        ideletedinfoList << pinfo ;
1931
 
1932
        QStringList iscanFileList = pchain->getScanedFileList() ;
1933
 
1934
        for(int i = 0 ; i < iscanFileList.count() ; i++)
1935
        {
1936
            QString ifileName = iscanFileList.at(i) ;
1937
            if(!ifileList.contains(ifileName))
1938
            {
1939
                ifileList << ifileName ;
1940
                QString irelativeFileName = currentPrj->getCurrentDir().relativeFilePath(ifileName);
1941
 
1942
                // 文件被修改了 需要重新保存文件日期
1943
                struct EziDebugPrj::LOG_FILE_INFO* pdelFileInfo = new EziDebugPrj::LOG_FILE_INFO ;
1944
                pdelFileInfo->etype = EziDebugPrj::infoTypeFileInfo ;
1945
                pdelFileInfo->pinfo = NULL ;
1946
                memcpy(pdelFileInfo->ainfoName , irelativeFileName.toAscii().data() , irelativeFileName.size()+1);
1947
                ideletedinfoList.append(pdelFileInfo);
1948
 
1949
                struct EziDebugPrj::LOG_FILE_INFO* paddFileInfo = new EziDebugPrj::LOG_FILE_INFO ;
1950
                paddFileInfo->etype = EziDebugPrj::infoTypeFileInfo ;
1951
 
1952
 
1953
                if(irelativeFileName.endsWith(".v"))
1954
                {
1955
                    EziDebugVlgFile *pvlgFile = currentPrj->getPrjVlgFileMap().value(irelativeFileName,NULL);
1956
                    paddFileInfo->pinfo = pvlgFile ;
1957
                }
1958
                else if(irelativeFileName.endsWith(".vhd"))
1959
                {
1960
                    EziDebugVhdlFile *pvhdlFile = currentPrj->getPrjVhdlFileMap().value(irelativeFileName,NULL);
1961
                    paddFileInfo->pinfo = pvhdlFile ;
1962
                }
1963
                else
1964
                {
1965
                    delete paddFileInfo ;
1966
                    continue ;
1967
                }
1968
 
1969
                memcpy(paddFileInfo->ainfoName , irelativeFileName.toAscii().data(), irelativeFileName.size()+1);
1970
                iaddedinfoList.append(paddFileInfo);
1971
            }
1972
        }
1973
        ++ibakiterator;
1974
    }
1975
 
1976
    if(currentPrj->changedLogFile(iaddedinfoList,ideletedinfoList))
1977
    {
1978
        // 提示 保存 log 文件出错
1979
        qDebug() << "Error:Save log info Error In delete all chain!";
1980
    }
1981
 
1982
    qDeleteAll(iaddedinfoList);
1983
    qDeleteAll(ideletedinfoList);
1984
 
1985
    // 开启检测更新线程
1986
    pthread->start();
1987
    QMessageBox::information(this, QObject::tr("删除所有扫描链"),QObject::tr("删除所有扫描链成功!"));
1988
 
1989
    return 0 ;
1990
 
1991
ErrorHandle:
1992
 
1993
    /*恢复 treeItemMap*/
1994
    currentPrj->resumeChainTreeItemMap();
1995
 
1996
    /*恢复 chainMap*/
1997
    currentPrj->resumeChainMap();
1998
 
1999
    i = ichainTreeItemMap.constBegin();
2000
    {
2001
        /*将chain指针加入到 树状节点下面*/
2002
        EziDebugInstanceTreeItem* pitem = i.value() ;
2003
        EziDebugScanChain * plastChain = currentPrj->getScanChainInfo().value(i.key());
2004
        pitem->setScanChainInfo(plastChain);
2005
        plastChain->resumeFileList();
2006
 
2007
        /*读取删除链 已经扫描过的文件,从已经备份的文件中恢复*/
2008
        for(int p = 0 ; p < plastChain->getScanedFileList().count();p++)
2009
        {
2010
            // 获取备份的文件名全称
2011
            QFileInfo ifileInfo(plastChain->getScanedFileList().at(p));
2012
            QString ieziDebugFileSuffix ;
2013
 
2014
            ieziDebugFileSuffix.append(QObject::tr(".deleteall"));
2015
 
2016
            QString ibackupFileName = currentPrj->getCurrentDir().absolutePath() \
2017
                    + EziDebugScanChain::getUserDir() + ifileInfo.fileName() \
2018
                    + ieziDebugFileSuffix;
2019
            QFile ibackupFile(ibackupFileName) ;
2020
 
2021
            // 已经是绝对路径了
2022
            ibackupFile.copy(plastChain->getScanedFileList().at(p));
2023
 
2024
            // 删除当前备份的文件
2025
            ibackupFile.remove();
2026
        }
2027
 
2028
 
2029
        i++ ;
2030
    }while(i != backup)
2031
 
2032
    qDeleteAll(iaddedinfoList);
2033
    qDeleteAll(ideletedinfoList);
2034
 
2035
    // 开启检测更新线程
2036
    pthread->start();
2037
    QMessageBox::warning(this, QObject::tr("删除所有扫描链"),QObject::tr("删除所有扫描链失败!"));
2038
 
2039
    return 1 ;
2040
}
2041
 
2042
void ToolWindow::testbenchGeneration()
2043
{
2044
    qDebug() << "testbenchGeneration!" ;
2045
    QString ichainName ;
2046
    QStringList idataFileNameList ;
2047
    QString ioutputDirectory ;
2048
    UpdateDetectThread* pthread ;
2049
 
2050
    QList<TextQuery::module_top*> inoutList;
2051
    QList<TextQuery::sample*> isampleList ;
2052
    QList<TextQuery::system_port*> isysinoutList ;
2053
    QVector<QList<TextQuery::regchain*> > ichainVec ;
2054
    QMap<int,QString> ifileMap ;
2055
    QMap<int,QString>::const_iterator ifileMapIter ;
2056
 
2057
    TextQuery::FPGA_Type ifgpaType ;
2058
 
2059
    QString iclockPortName ;
2060
    QString iresetPortName ;
2061
 
2062
    ImportDataDialog::EDGE_TYPE eresetType ;
2063
    TextQuery::EDGE_TYPE eresetTypeLast ;
2064
    QString iresetSigVal ;
2065
 
2066
 
2067
    if(!currentPrj)
2068
    {
2069
        QMessageBox::warning(this, QObject::tr("生成testBench"),QObject::tr("工程不存在,请进行设置工程参数并进行扫描!"));
2070
        return ;
2071
    }
2072
 
2073
    if(!currentPrj->getScanChainInfo().count())
2074
    {
2075
        QMessageBox::warning(this, QObject::tr("生成testBench"),QObject::tr("不存在任何扫描链!"));
2076
        return ;
2077
    }
2078
 
2079
    //QMessageBox::information(this, QObject::tr("undo 操作"),QObject::tr("目前只支持对相邻的上一步操作的取消!"));
2080
    //undoOperation();
2081
    // Qt::WA_DeleteOnClose
2082
    ImportDataDialog *idataDialg = new ImportDataDialog(currentPrj->getChainTreeItemMap(),this);
2083
    if(idataDialg->exec())
2084
    {
2085
        qDebug() << "generate test bench" << "chainName:" << idataDialg->getChainName() \
2086
                 << "fileName:" << idataDialg->getDataFileName();
2087
        ichainName = idataDialg->getChainName() ;
2088
        ifileMap = idataDialg->getFileIndexMap() ;
2089
 
2090
        for(int i = 0 ; i < ifileMap.count() ;i++)
2091
        {
2092
            if(!ifileMap.value(i,QString()).isEmpty())
2093
            {
2094
                QString ifileName = ifileMap.value(i);
2095
                if(currentPrj->getToolType() == EziDebugPrj::ToolIse)
2096
                {
2097
                    if(!ifileName.endsWith(".prn"))
2098
                    {
2099
                        QMessageBox::warning(this, QObject::tr("生成testBench"),QObject::tr("数据文件格式不正确!"));
2100
 
2101
                        return ;
2102
                    }
2103
                }
2104
                else if(currentPrj->getToolType() == EziDebugPrj::ToolQuartus)
2105
                {
2106
                    if(!ifileName.endsWith(".txt"))
2107
                    {
2108
                        QMessageBox::warning(this, QObject::tr("生成testBench"),QObject::tr("数据文件格式不正确!"));
2109
 
2110
                        return ;
2111
                    }
2112
                }
2113
                else
2114
                {
2115
                    QMessageBox::warning(this, QObject::tr("生成testBench"),QObject::tr("工具软件类型不正确!"));
2116
                    return ;
2117
                }
2118
                idataFileNameList.append(ifileName);
2119
            }
2120
        }
2121
 
2122
        ioutputDirectory = idataDialg->getOutputDirectory() ;
2123
 
2124
        idataDialg->getResetSig(iresetPortName,eresetType,iresetSigVal);
2125
 
2126
        EziDebugScanChain *pchain = currentPrj->getScanChainInfo().value(idataDialg->getChainName(),NULL);
2127
        if(!pchain)
2128
        {
2129
            QMessageBox::critical(this, QObject::tr("生成testBench"),QObject::tr("%1 不存在!").arg(idataDialg->getChainName()));
2130
            return ;
2131
        }
2132
 
2133
        EziDebugInstanceTreeItem * pitem = currentPrj->getChainTreeItemMap().value(ichainName ,NULL);
2134
        if(!pitem)
2135
        {
2136
            QMessageBox::critical(this, QObject::tr("生成testBench"),QObject::tr("%1 对应的节点不存在!").arg(idataDialg->getChainName()));
2137
            return ;
2138
        }
2139
 
2140
        listWindow->addMessage("info","EziDebug info: Generate TestBench !");
2141
        QStandardItem * pmessageitem = listWindow->addMessage("info","EziDebug info: The input and output parameter as follows:");
2142
        listWindow->addMessage("process",tr("%1ChainName: %2").arg(tr(" ").repeated(6)).arg(ichainName),pmessageitem);
2143
 
2144
        for(int j = 0 ; j < idataFileNameList.count() ; j++)
2145
        {
2146
            QString ifileName = idataFileNameList.at(j) ;
2147
            listWindow->addMessage("process",tr("%1FileName: %2").arg(tr(" ").repeated(6)).arg(QDir::toNativeSeparators(ifileName)),pmessageitem);
2148
        }
2149
 
2150
        listWindow->addMessage("process",tr("%1Output directory: %2").arg(tr(" ").repeated(6)).arg(QDir::toNativeSeparators(ioutputDirectory)),pmessageitem);
2151
 
2152
 
2153
 
2154
 
2155
        // tdo tout
2156
        EziDebugModule *pmodule = currentPrj->getPrjModuleMap().value(pitem->getModuleName(),NULL);
2157
 
2158
        QMap<QString,QString>::const_iterator iclockiter = pmodule->getClockSignal().constBegin() ;
2159
        while(iclockiter != pmodule->getClockSignal().constEnd())
2160
        {
2161
            QString icombinedName ;
2162
            QString iclock = iclockiter.key() ;
2163
 
2164
            QString ichainClock = pitem->parent()->getModuleClockMap(pitem->getInstanceName()).key(iclock,QString());
2165
            int nchildChainNum =  pitem->getScanChainInfo()->getChildChainNum(ichainClock);
2166
 
2167
            QString itdoPortName(QObject::tr("_EziDebug_%1_%2_tdo_r").arg(pitem->getScanChainInfo()->getChainName()).arg(iclock));
2168
            if(nchildChainNum > 1)
2169
            {
2170
                icombinedName = itdoPortName + QObject::tr("[%1:0]").arg(nchildChainNum -1);
2171
            }
2172
            else
2173
            {
2174
                icombinedName = itdoPortName ;
2175
            }
2176
 
2177
            struct TextQuery::sample* psample = (struct TextQuery::sample*)malloc(sizeof(struct TextQuery::sample)) ;
2178
            memset((void*)psample,0,sizeof(struct TextQuery::sample));
2179
 
2180
            psample->sample_name = (char*) malloc(icombinedName.size()+1);
2181
            memset((void*)psample->sample_name,0,icombinedName.size()+1);
2182
            qstrcpy(psample->sample_name , icombinedName.toAscii().constData());
2183
 
2184
            *(psample->sample_name + icombinedName.size()) = '\0' ;
2185
 
2186
            if(nchildChainNum > 1)
2187
            {
2188
                psample->width_first = nchildChainNum -1 ;
2189
                psample->width_second = 0 ;
2190
            }
2191
            else
2192
            {
2193
                psample->width_first = 0 ;
2194
                psample->width_second = 0 ;
2195
            }
2196
 
2197
 
2198
            isampleList.append(psample);
2199
 
2200
            ++iclockiter ;
2201
        }
2202
 
2203
 
2204
        struct TextQuery::sample* psample = (struct TextQuery::sample*)malloc(sizeof(struct TextQuery::sample)) ;
2205
        memset((void*)psample,0,sizeof(struct TextQuery::sample));
2206
        //_EziDebug_%1_TOUT_reg
2207
        QString itoutPortName = QObject::tr("_EziDebug_%1_tout_r").arg(pitem->getScanChainInfo()->getChainName());
2208
        psample->sample_name = (char*)malloc(itoutPortName.size()+1);
2209
        memset((void*)psample->sample_name,0,itoutPortName.size()+1);
2210
 
2211
        qstrcpy(psample->sample_name , itoutPortName.toAscii().constData());
2212
        *(psample->sample_name + itoutPortName.size()) = '\0' ;
2213
 
2214
        psample->width_first = 0 ;
2215
        psample->width_second = 0 ;
2216
 
2217
        isampleList.append(psample);
2218
 
2219
        // port
2220
        QVector<EziDebugModule::PortStructure*> iportVec = pmodule->getPort(currentPrj , pitem->getInstanceName()) ;
2221
        for(int i = 0 ; i < iportVec.count() ;i++)
2222
        {
2223
            EziDebugModule::PortStructure*  pmodulePort = iportVec.at(i) ;
2224
            QString iportName = QString::fromAscii(pmodulePort->m_pPortName);
2225
 
2226
            struct TextQuery::module_top* pport = (struct TextQuery::module_top*)malloc(sizeof(struct TextQuery::module_top)) ;
2227
            memset((void*)pport,0,(sizeof(struct TextQuery::module_top)));
2228
 
2229
            pport->port_name = (char*)malloc(strlen(pmodulePort->m_pPortName)+1);
2230
            memset((void*)pport->port_name,0,(strlen(pmodulePort->m_pPortName)+1));
2231
 
2232
            strncpy(pport->port_name,pmodulePort->m_pPortName,strlen(pmodulePort->m_pPortName)+1);
2233
 
2234
            if(pmodulePort->eDirectionType == EziDebugModule::directionTypeInput)
2235
            {
2236
                pport->inout = 1 ;
2237
            }
2238
            else if(pmodulePort->eDirectionType == EziDebugModule::directionTypeOutput)
2239
            {
2240
                pport->inout = 0 ;
2241
            }
2242
            else
2243
            {
2244
 
2245
            }
2246
 
2247
            pport->width_first = pmodulePort->m_unStartBit ;
2248
            pport->width_second = pmodulePort->m_unEndBit ;
2249
 
2250
            inoutList.append(pport);
2251
 
2252
            if(!(pmodule->getClockSignal().value(iportName,QString())).isEmpty())
2253
            {
2254
                iclockPortName = iportName ;
2255
                continue ;
2256
            }
2257
 
2258
#if 0
2259
            if(!(pmodule->getResetSignal().value(iportName,QString())).isEmpty())
2260
            {
2261
                iresetName = iportName ;
2262
                continue ;
2263
            }
2264
#endif
2265
 
2266
 
2267
            if(iresetPortName == iportName)
2268
            {
2269
                continue ;
2270
            }
2271
 
2272
            struct TextQuery::sample* psample = (struct TextQuery::sample*)malloc((sizeof(struct TextQuery::sample)/4+1)*4) ;
2273
            memset((void*)psample,0,(sizeof(struct TextQuery::sample)/4+1)*4);
2274
 
2275
            // strlen(pmodulePort->m_pPortName + 1)
2276
            psample->sample_name = (char*)malloc(strlen(pmodulePort->m_pPortName) +1);
2277
            memset((void*)psample->sample_name,0,(strlen(pmodulePort->m_pPortName) + 1));
2278
            strcpy(psample->sample_name,pmodulePort->m_pPortName);
2279
 
2280
 
2281
            psample->width_first = pmodulePort->m_unStartBit ;
2282
            psample->width_second = pmodulePort->m_unEndBit ;
2283
 
2284
            isampleList.append(psample);
2285
 
2286
        }
2287
 
2288
        // memory fifo
2289
        QStringList isysPortList = pchain->getSyscoreOutputPortList() ;
2290
        for(int i = 0 ; i < isysPortList.count() ; i++)
2291
        {
2292
            QString ihierarchicalName = isysPortList.at(i).split("#").at(0);
2293
            QString iportName = isysPortList.at(i).split("#").at(1);
2294
            QString iregName = isysPortList.at(i).split("#").at(2);
2295
            int nbitWidth = isysPortList.at(i).split("#").at(3).toInt();
2296
 
2297
 
2298
            QRegExp ireplaceRegExp(QObject::tr("\\b\\w*:"));
2299
 
2300
            struct TextQuery::system_port* pport = (struct TextQuery::system_port*)malloc(sizeof(struct TextQuery::system_port)) ;
2301
            memset((void*)pport,0,sizeof(struct TextQuery::system_port));
2302
 
2303
            iportName.replace("|",".");
2304
            iportName.replace(ireplaceRegExp,"");
2305
 
2306
 
2307
            pport->port_name = (char*)malloc(iportName.size()+1);
2308
            pport->reg_name = (char*)malloc(iregName.size()+1);
2309
            memset((void*)pport->port_name,0,iportName.size()+1);
2310
            memset((void*)pport->reg_name,0,iregName.size()+1);
2311
 
2312
            strcpy(pport->port_name,iportName.toAscii().constData());
2313
            *(pport->port_name +iportName.size()) = '\0' ;
2314
            strcpy(pport->reg_name,iregName.toAscii().constData());
2315
            *(pport->reg_name +iregName.size()) = '\0' ;
2316
 
2317
            pport->width_first = nbitWidth -1 ;
2318
            pport->width_second = 0 ;
2319
 
2320
            isysinoutList.append(pport);
2321
 
2322
            struct TextQuery::sample* psample = (struct TextQuery::sample*)malloc(sizeof(struct TextQuery::sample)) ;
2323
            memset((void*)psample,0,sizeof(struct TextQuery::sample));
2324
 
2325
            psample->sample_name = (char*) malloc(iregName.size() + 1);
2326
            memset((void*)psample->sample_name,0,iregName.size() + 1);
2327
            strcpy(psample->sample_name , iregName.toAscii().constData());
2328
            *(psample->sample_name + iregName.size()) = '\0' ;
2329
 
2330
            psample->width_first = nbitWidth -1 ;
2331
            psample->width_second = 0 ;
2332
 
2333
            isampleList.append(psample);
2334
        }
2335
 
2336
 
2337
        // tdo  _EziDebug_%1_%2_TDO_reg
2338
 
2339
        //EziDebugModule *pmodule = currentPrj->getPrjModuleMap().value(pitem->getModuleName(),NULL);
2340
 
2341
 
2342
        // 采样 寄存器
2343
        // "reg" << sample_table[i].sample_name  << "_temp[1:`DATA_WIDTH]
2344
        // reglist
2345
        QMap<QString,QVector<QStringList> > iregChainMap = pchain->getRegChain();
2346
        QMap<QString,QVector<QStringList> >::const_iterator iregChainIter = iregChainMap.constBegin() ;
2347
        while(iregChainIter != iregChainMap.constEnd())
2348
        {
2349
            QVector<QStringList> iregList = iregChainIter.value();
2350
            for(int i = 0 ; i < iregList.count() ; i++)
2351
            {
2352
                QStringList iregChainStr = iregList.at(i) ;
2353
                QList<TextQuery::regchain*> iregChainList ;
2354
                for(int j = 0 ; j < iregChainStr.count() ; j++)
2355
                {
2356
                    QString iregStr = iregChainStr.at(j);
2357
                    QString ireghiberarchyName = iregStr.split("#").at(3) ;
2358
                    QString iregName = iregStr.split("#").at(4);
2359
 
2360
                    int nstartBit = iregStr.split("#").at(5).toInt();
2361
                    int nendBit = iregStr.split("#").at(6).toInt();
2362
 
2363
                    struct TextQuery::regchain* pregChain = (struct TextQuery::regchain*)malloc(sizeof(struct TextQuery::regchain)) ;
2364
                    memset((char*)pregChain ,0 ,sizeof(struct TextQuery::regchain));
2365
 
2366
                    int nstartPos = ireghiberarchyName.indexOf(tr("%1:%2").arg(pitem->getModuleName()).arg(pitem->getInstanceName()));
2367
                    ireghiberarchyName = ireghiberarchyName.mid(nstartPos);
2368
                    ireghiberarchyName.replace(QRegExp(tr("\\w+:")),"");
2369
                    ireghiberarchyName.replace("|",".");
2370
                    nstartPos = ireghiberarchyName.indexOf(".");
2371
                    ireghiberarchyName = ireghiberarchyName.mid(nstartPos+1);
2372
                    QString icombinedName = tr("%1%2").arg(ireghiberarchyName).arg(iregName);
2373
 
2374
                    pregChain->reg_name = (char*)malloc(icombinedName.size()+1);
2375
                    memset((char*)pregChain->reg_name ,0 ,icombinedName.size()+1);
2376
                    strcpy(pregChain->reg_name,icombinedName.toAscii().data());
2377
                    *(pregChain->reg_name+icombinedName.size()) = '\0' ;
2378
 
2379
                    pregChain->width_first = nstartBit ;
2380
                    pregChain->width_second = nendBit ;
2381
 
2382
                    iregChainList.append(pregChain);
2383
                }
2384
                ichainVec.append(iregChainList);
2385
            }
2386
            ++iregChainIter ;
2387
        }
2388
 
2389
        if(currentPrj->getToolType() == EziDebugPrj::ToolQuartus)
2390
        {
2391
            ifgpaType = TextQuery::Altera ;
2392
        }
2393
        else
2394
        {
2395
            ifgpaType = TextQuery::Xilinx ;
2396
        }
2397
 
2398
        //pitem->getModuleName(),idataFileName,ioutputDirectory ,
2399
        TextQuery itest(pitem->getModuleName(),idataFileNameList , ioutputDirectory , inoutList ,isampleList ,ichainVec , isysinoutList ,ifgpaType) ;
2400
 
2401
 
2402
        eresetTypeLast = static_cast<TextQuery::EDGE_TYPE>(eresetType);
2403
 
2404
        itest.setNoNeedSig(iclockPortName , iresetPortName , eresetTypeLast ,iresetSigVal);
2405
 
2406
        // 插入扫描链之前  停止检测更新   退出线程
2407
        pthread = currentPrj->getThread() ;
2408
 
2409
        if(pthread->isRunning())
2410
        {
2411
            pthread->quit();
2412
            pthread->wait();
2413
        }
2414
 
2415
 
2416
        itest.doit();
2417
 
2418
        pthread->start();
2419
 
2420
        qDebug() << "Generate testBench finish !" << __LINE__ ;
2421
 
2422
        listWindow->addMessage("info","EziDebug info: Finish generate testBench file!");
2423
 
2424
 
2425
 
2426
        // 释放内存
2427
        // malloc 用 free 释放
2428
 
2429
        int nfreecount = 0 ;
2430
 
2431
        for(;nfreecount < inoutList.count(); nfreecount++)
2432
        {
2433
            TextQuery::module_top* pmodule = inoutList.at(nfreecount) ;
2434
            char * pportName = pmodule->port_name ;
2435
 
2436
            free(pportName);
2437
            pportName = NULL ;
2438
 
2439
 
2440
            free((char*)pmodule);
2441
            pmodule = NULL ;
2442
        }
2443
 
2444
        for(nfreecount = 0 ; nfreecount < isampleList.count(); nfreecount++)
2445
        {
2446
            TextQuery::sample *psample = isampleList.at(nfreecount) ;
2447
            char* psampleName = psample->sample_name ;
2448
 
2449
            free(psampleName) ;
2450
            psampleName = NULL ;
2451
            free((char*)psample);
2452
            psample = NULL ;
2453
        }
2454
 
2455
        for(nfreecount = 0 ; nfreecount < isysinoutList.count(); nfreecount++)
2456
        {
2457
            TextQuery::system_port* pport = isysinoutList.at(nfreecount) ;
2458
            char *pportName = pport->port_name ;
2459
            char *pregName = pport->reg_name ;
2460
            free(pportName);
2461
            pportName = NULL ;
2462
            free(pregName);
2463
            pregName = NULL ;
2464
            free((char*)pport);
2465
            pport = NULL ;
2466
        }
2467
 
2468
        for(nfreecount = 0 ; nfreecount < ichainVec.count() ; nfreecount++)
2469
        {
2470
            int nregcount = 0 ;
2471
            QList<TextQuery::regchain*> iregChainList = ichainVec.at(nfreecount) ;
2472
            for(;nregcount < iregChainList.count() ; nregcount++)
2473
            {
2474
                TextQuery::regchain* pregChain = iregChainList.at(nregcount);
2475
                char* pregName = pregChain->reg_name ;
2476
                free(pregName);
2477
                pregName = NULL ;
2478
                free((char*)pregChain);
2479
                pregChain = NULL ;
2480
            }
2481
        }
2482
 
2483
        QMessageBox::information(this, QObject::tr("生成testBench"),QObject::tr("testBench生成完毕!"));
2484
 
2485
    }
2486
    else
2487
    {
2488
        qDebug() << "do nothing!" ;
2489
    }
2490
}
2491
 
2492
void ToolWindow::miniWindowMinimized()
2493
{
2494
    miniSizeAction->setDisabled(true);
2495
    restoreWinAction->setDisabled(false);
2496
}
2497
 
2498
//进度条演示
2499
void ToolWindow::progressBarDemo()
2500
{
2501
    //    QProgressDialog progressDialog(this);
2502
//    progressDialog.setCancelButtonText(tr("取消"));
2503
//    progressDialog.setRange(0, 100);
2504
//    progressDialog.setWindowTitle(tr("进度条"));
2505
 
2506
 
2507
    for (int i = 0; i < 100; ++i) {
2508
        progressBar->setValue(i);
2509
        //progressBarsetLabelText(tr("进度为 %1 / %2...")
2510
                                   // .arg(i).arg(100));
2511
        qApp->processEvents();
2512
 
2513
 
2514
//        if (progressDialog.wasCanceled()){
2515
//            //添加取消时的工作
2516
//            break;
2517
//        }
2518
 
2519
        for (int j = 0; j < 100000000; ++j);
2520
    }
2521
}
2522
 
2523
const EziDebugPrj* ToolWindow::getCurrentProject(void) const
2524
{
2525
    return  currentPrj ;
2526
}
2527
 
2528
void ToolWindow::setCurrentProject(EziDebugPrj* prj)
2529
{
2530
    currentPrj = prj ;
2531
    return ;
2532
}
2533
 
2534
void  ToolWindow::listwindowInfoInit(void)
2535
{
2536
    listWindow->welcomeinfoinit(currentPrj);
2537
}
2538
 
2539
void ToolWindow::setListWindowAdsorbedFlag(bool flag)
2540
{
2541
    isListWindowAdsorbed = flag ;
2542
}
2543
 
2544
void ToolWindow::createButtons()
2545
{
2546
    //工具栏按钮
2547
    // projectSetting AprojectSetting
2548
//    proSettingButton = new Button(tr(":/images/projectSetting4.bmp"), this);
2549
//    proSettingButton->setIconSize(QSize(30, 29));
2550
//    connect(proSettingButton, SIGNAL(clicked()), this, SLOT(proSetting()));
2551
//    proSettingButton->setToolTip(tr("工程设置"));
2552
 
2553
//    proUpdateButton = new Button(tr(":/images/projectUpdate4.bmp"), this);
2554
//    proUpdateButton->setIconSize(QSize(30, 29));
2555
//    connect(proUpdateButton, SIGNAL(clicked()), this, SLOT(proUpdate()));
2556
//    proUpdateButton->setToolTip(tr("更新"));
2557
 
2558
//    proPartlyUpdateButton = new Button(tr(":/images/"), this);
2559
//    proPartlyUpdateButton->setIconSize(QSize(30, 29));
2560
//    connect(proPartlyUpdateButton, SIGNAL(clicked()), this, SLOT(fastUpdate()));
2561
//    proPartlyUpdateButton->setToolTip(tr("部分更新"));
2562
 
2563
//    deleteChainButton = new Button(tr(":/images/deleteChain4.bmp"), this);
2564
//    deleteChainButton->setIconSize(QSize(30, 29));
2565
//    connect(deleteChainButton, SIGNAL(clicked()), this, SLOT(deleteAllChain()));
2566
//    deleteChainButton->setToolTip(tr("删除"));
2567
 
2568
//    proUndoButton = new Button(tr(":/images/undo4.bmp"), this);
2569
//    proUndoButton->setIconSize(QSize(30, 29));
2570
//    connect(proUndoButton, SIGNAL(clicked()), this, SLOT(undoOperation()));
2571
//    proUndoButton->setToolTip(tr("撤销"));
2572
 
2573
//    testbenchGenerationButton = new Button(tr(":/images/testbenchGeneration4.bmp"), this);
2574
//    testbenchGenerationButton->setIconSize(QSize(30, 29));
2575
//    connect(testbenchGenerationButton, SIGNAL(clicked()), this, SLOT(testbenchGeneration()));
2576
//    testbenchGenerationButton->setToolTip(tr("testbench生成"));
2577
 
2578
 
2579
 
2580
    //工具栏按钮
2581
    proSettingButton = createToolButton(tr("工程设置"),
2582
                                        tr(":/images/projectSetting.bmp"),
2583
                                        QSize(42, 41),
2584
                                        this,
2585
                                        SLOT(proSetting()));
2586
 
2587
    proUpdateButton = createToolButton(tr("更新"),
2588
                                       tr(":/images/projectUpdate.bmp"),
2589
                                       QSize(42, 41),
2590
                                       this,
2591
                                       SLOT(proUpdate()));
2592
 
2593
    proPartlyUpdateButton = createToolButton(tr("部分更新"),
2594
                                       tr(":/images/projectPartlyUpdate.bmp"),
2595
                                       QSize(42, 41),
2596
                                       this,
2597
                                       SLOT(fastUpdate()));
2598
 
2599
    deleteChainButton = createToolButton(tr("删除"),
2600
                                         tr(":/images/deleteChain.bmp"),
2601
                                         QSize(42, 41),
2602
                                         this,
2603
                                         SLOT(deleteAllChain()));
2604
 
2605
    testbenchGenerationButton = createToolButton(tr("Testbench生成"),
2606
                                                 tr(":/images/testbenchGeneration.bmp"),
2607
                                                 QSize(42, 41),
2608
                                                 this,
2609
                                                 SLOT(testbenchGeneration()));
2610
 
2611
    proUndoButton = createToolButton(tr("撤消"),
2612
                                                 tr(":/images/undo.bmp"),
2613
                                                 QSize(42, 41),
2614
                                                 this,
2615
                                                 SLOT(undoOperation()));
2616
 
2617
 
2618
    //右上角标题栏按钮
2619
    minimizeButton = createToolButton(tr("最小化"),
2620
                                      tr(":/images/ToolWindowminimize.bmp"),
2621
                                      QSize(27, 19),
2622
                                      this,
2623
                                      SLOT(minimize()));
2624
 
2625
    miniModeButton = createToolButton(tr("迷你模式"),
2626
                                      tr(":/images/ToolWindowNormal.bmp"),
2627
                                      QSize(27, 19),
2628
                                      this,
2629
                                      SLOT(toMiniMode()));
2630
 
2631
    showListWindowButton = createToolButton(tr("完整模式"),
2632
                                            tr(":/images/showListWindow.bmp"),
2633
                                            QSize(27, 19),
2634
                                            this,
2635
                                            SLOT(showListWindow()));
2636
 
2637
    exitButton = createToolButton(tr("退出"),
2638
                                  tr(":/images/ToolWindowExit.bmp"),
2639
                                  QSize(33, 19),
2640
                                  this,
2641
                                  SLOT(close()));
2642
 
2643
 
2644
}
2645
 
2646
void ToolWindow::createActions()
2647
{
2648
    exitAct = new QAction(tr("退  出"), this);
2649
    exitAct->setShortcuts(QKeySequence::Quit);
2650
    //exitAct->setStatusTip(tr("退出"));
2651
    connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
2652
 
2653
    minimizeAct = new QAction(tr("最小化"), this);
2654
    //minimizeAct->setShortcuts(QKeySequence::);
2655
    //minimizeAct->setStatusTip(tr("Exit the application"));
2656
    connect(minimizeAct, SIGNAL(triggered()), this, SLOT(minimize()));
2657
 
2658
    toMiniModeAct = new QAction(tr("迷你模式"), this);
2659
    //normalAct->setShortcuts(QKeySequence::Quit);
2660
    //normalAct->setStatusTip(tr("Exit the application"));
2661
    connect(toMiniModeAct, SIGNAL(triggered()), this, SLOT(toMiniMode()));
2662
 
2663
    aboutAct = new QAction(tr("关 于..."),this);
2664
    connect(aboutAct,SIGNAL(triggered()),this,SLOT(about()));
2665
 
2666
    helpAct = new QAction(tr("帮  助"),this);
2667
    connect(helpAct,SIGNAL(triggered()),this,SLOT(help()));
2668
 
2669
}
2670
 
2671
//创建系统托盘的右键菜单
2672
void ToolWindow::CreatTrayMenu()
2673
{
2674
    miniSizeAction = new QAction(tr("最小化"),this);
2675
    maxSizeAction = new QAction(tr("最大化"),this);
2676
    restoreWinAction = new QAction(tr("还  原"),this);
2677
    quitAction = new QAction(tr("退  出"),this);
2678
    aboutAction = new QAction(tr("关 于..."),this);
2679
    helpAction = new QAction(tr("帮  助"),this);
2680
 
2681
    this->connect(miniSizeAction,SIGNAL(triggered()),this,SLOT(minimize()));
2682
    this->connect(maxSizeAction,SIGNAL(triggered()),this,SLOT(showMaximized()));
2683
    this->connect(restoreWinAction,SIGNAL(triggered()),this,SLOT(showNormal()));
2684
    this->connect(quitAction,SIGNAL(triggered()),qApp,SLOT(quit()));
2685
    this->connect(aboutAction,SIGNAL(triggered()),this,SLOT(about()));
2686
    this->connect(helpAction,SIGNAL(triggered()),this,SLOT(help()));
2687
 
2688
    myMenu = new QMenu((QWidget*)QApplication::desktop());
2689
 
2690
    myMenu->addAction(miniSizeAction);
2691
    miniSizeAction->setDisabled(false);
2692
    myMenu->addAction(maxSizeAction);
2693
    maxSizeAction->setDisabled(true);
2694
    myMenu->addAction(restoreWinAction);
2695
    restoreWinAction->setDisabled(false);
2696
    myMenu->addSeparator();     //加入一个分离符
2697
    myMenu->addAction(aboutAction);
2698
    aboutAction->setDisabled(false);
2699
    myMenu->addAction(helpAction);
2700
    helpAction->setDisabled(false);
2701
    myMenu->addSeparator();     //加入一个分离符
2702
    myMenu->addAction(quitAction);
2703
}
2704
 
2705
//创建系统托盘图标
2706
void ToolWindow::creatTrayIcon()
2707
{
2708
    CreatTrayMenu();
2709
 
2710
    if (!QSystemTrayIcon::isSystemTrayAvailable())      //判断系统是否支持系统托盘图标
2711
    {
2712
        return ;
2713
    }
2714
 
2715
    myTrayIcon = new QSystemTrayIcon(this);
2716
 
2717
    QPixmap objPixmap(tr(":/images/EziDebugIcon.bmp"));
2718
    QPixmap iconPix;
2719
 
2720
//    iconPix = objPixmap.copy(0, 0, 127, 120);//.scaled(21, 20);
2721
//    iconPix.setMask(QPixmap(tr(":/images/EziDebugIconMask.bmp")));
2722
 
2723
    objPixmap.setMask(QPixmap(tr(":/images/EziDebugIconMask.bmp")));
2724
    iconPix = objPixmap.copy(0, 0, 127, 104).scaled(21, 20);
2725
    myTrayIcon->setIcon(iconPix);   //设置图标图片
2726
    setWindowIcon(iconPix);  //把图片设置到窗口上
2727
 
2728
    myTrayIcon->setToolTip("EziDebug");    //托盘时,鼠标放上去的提示信息
2729
 
2730
    myTrayIcon->showMessage("EziDebug", "Hi,This is my EziDebug.",QSystemTrayIcon::Information,10000);
2731
 
2732
 
2733
 
2734
    myTrayIcon->setContextMenu(myMenu);     //设置托盘上下文菜单
2735
 
2736
    myTrayIcon->show();
2737
    this->connect(myTrayIcon,SIGNAL(activated(QSystemTrayIcon::ActivationReason)),this,SLOT(iconActivated(QSystemTrayIcon::ActivationReason)));
2738
}
2739
 
2740
 
2741
Button *ToolWindow::createToolButton(const QString &toolTip, const QString &iconstr,
2742
                                    const QSize &size, const QObject * receiver, const char *member)
2743
{
2744
    Button *button = new Button(iconstr, this);
2745
    button->setToolTip(toolTip);
2746
    //button->setIcon(icon);
2747
    button->setIconSize(size);//(QSize(10, 10));
2748
    // button->setSizeIncrement(size);
2749
    //button->setSizePolicy(size.width(), size.height());
2750
    button->setFlat(true);
2751
    connect(button, SIGNAL(clicked()), receiver, member);
2752
 
2753
//    Button *button = new Button(this);
2754
 
2755
//    button->setToolTip(toolTip);
2756
//    //button->setIcon(icon);
2757
//    button->setIconSize(size);//(QSize(10, 10));
2758
//    // button->setSizeIncrement(size);
2759
//    //button->setSizePolicy(size.width(), size.height());
2760
//    button->setFlat(true);
2761
//    connect(button, SIGNAL(clicked()), receiver, member);
2762
 
2763
    return button;
2764
}
2765
 
2766
//重载各个事件
2767
void ToolWindow::contextMenuEvent(QContextMenuEvent *event)
2768
{
2769
    QMenu menu(this);
2770
    menu.addAction(minimizeAct);
2771
    menu.addAction(toMiniModeAct);
2772
    menu.addAction(aboutAct);
2773
    menu.addAction(helpAct);
2774
    menu.addSeparator();
2775
    menu.addAction(exitAct);
2776
    menu.exec(event->globalPos());
2777
}
2778
 
2779
void ToolWindow::mousePressEvent(QMouseEvent * event)
2780
{
2781
 
2782
//    static int i = 0 ;
2783
//    qDebug()<<"mouse Press Event"<<i++ ;
2784
    if (event->button() == Qt::LeftButton) //点击左边鼠标
2785
    {
2786
        //globalPos()获取根窗口的相对路径,frameGeometry().topLeft()获取主窗口左上角的位置
2787
//        dragPosition = event->globalPos() - frameGeometry().topLeft();
2788
        dragPosition = event->globalPos() - geometry().topLeft();
2789
        oriGlobalPos = event->globalPos() - listWindow->geometry().topLeft();
2790
 
2791
        event->accept();   //鼠标事件被系统接收
2792
    }
2793
//        if (event->button() == Qt::RightButton)
2794
//        {
2795
//             close();
2796
//        }
2797
}
2798
 
2799
void ToolWindow::mouseMoveEvent(QMouseEvent * event)
2800
{
2801
 
2802
//    qDebug()<<"mouse Move Event"<< event->globalX()<< event->globalY() ;
2803
//    qDebug()<<"mouse Move Event"<<event->pos().x()<<event->pos().y() ;
2804
//    qDebug()<< this->pos().x()<< this->pos().y()<< this->geometry().left() \
2805
//            << this->geometry().bottom() <<this->width() << this->height();
2806
//    qDebug()<< listWindow->isListWindowHidden()<< isListWindowAdsorbed ;
2807
 
2808
    if (event->buttons() == Qt::LeftButton) //当满足鼠标左键被点击时。
2809
    {
2810
        move(event->globalPos() - dragPosition);//移动窗口
2811
        if((!listWindow->isListWindowHidden()) &&
2812
                (listWindow->windowIsStick()))
2813
        {
2814
            listWindow->move(event->globalPos() - oriGlobalPos);//移动
2815
        }
2816
        event->accept();
2817
    }
2818
}
2819
 
2820
void ToolWindow::paintEvent(QPaintEvent *)
2821
{
2822
    QPainter painter(this);//创建一个QPainter对象
2823
    painter.drawPixmap(0,0,QPixmap(":/images/Watermelon.png"));//绘制图片到窗口
2824
    /*
2825
      QPixmap(":/images/Watermelon.png")如果改为QPixmap(),则只能看到绘制出的框架,看不到图片颜色,也就是看不到图片。
2826
    */
2827
}
2828
 
2829
void ToolWindow::showEvent(QShowEvent* event)
2830
{
2831
//    qDebug() << "toolwindow show event!";
2832
//    readSetting() ;
2833
//    return ;
2834
}
2835
 
2836
void ToolWindow::readSetting()
2837
{
2838
    int  nparameterFlag  = PARAMETER_OK ;
2839
    UpdateDetectThread * pthread = NULL ;
2840
    EziDebugPrj::TOOL etool = EziDebugPrj::ToolOther ;
2841
    QSettings isettings("Eda Center.", "EziDebug");
2842
    // 获取工程参数,如果有就创建工程对象;没有的话,不创建
2843
    isettings.beginGroup("project");
2844
    unsigned int unMaxRegNum = isettings.value("MaxRegNum").toInt();
2845
    QString idir = isettings.value("dir").toString();
2846
    QString itool = isettings.value("tool").toString();
2847
    bool isXilinxERRChecked = isettings.value("isXilinxERRChecked").toBool();
2848
    isettings.endGroup();
2849
 
2850
    if(idir.isEmpty())
2851
    {
2852
        nparameterFlag |=  NO_PARAMETER_DIR ;
2853
        qDebug() << "EziDebug Info: No the Dir parameter!" ;
2854
    }
2855
 
2856
 
2857
    if(ZERO_REG_NUM == unMaxRegNum)
2858
    {
2859
        nparameterFlag |=  NO_PARAMETER_REG_NUM ;
2860
        qDebug() << "EziDebug Info: No Reg Num parameter!" ;
2861
    }
2862
 
2863
 
2864
    if(itool.isEmpty())
2865
    {
2866
        nparameterFlag |=  NO_PARAMETER_TOOL ;
2867
        qDebug() << "EziDebug Info: No the Tool parameter!" ;
2868
    }
2869
    else
2870
    {
2871
        if(!itool.compare("quartus"))
2872
        {
2873
            etool =  EziDebugPrj::ToolQuartus ;
2874
        }
2875
        else if(!itool.compare("ise"))
2876
        {
2877
            etool =  EziDebugPrj::ToolIse ;
2878
        }
2879
        else
2880
        {
2881
            nparameterFlag |=  NO_PARAMETER_TOOL ;
2882
        }
2883
    }
2884
 
2885
    if(nparameterFlag)
2886
    {
2887
        if(nparameterFlag == NO_PARAMETER_ALL)
2888
        {
2889
            //没有使用过软件
2890
            qDebug() << "EziDebug Info:There is no software infomation finded!";
2891
            goto Parameter_incomplete ;
2892
        }
2893
        else
2894
        {
2895
            //上一次保存的参数 不完整或者不正确
2896
            QMessageBox::information(this, QObject::tr("读取软件使用信息"),QObject::tr("参数错误!"));
2897
            goto Parameter_incomplete ;
2898
        }
2899
    }
2900
 
2901
    currentPrj = new EziDebugPrj(unMaxRegNum,idir,etool,this) ;
2902
    currentPrj->setXilinxErrCheckedFlag(isXilinxERRChecked);
2903
    pthread =  currentPrj->getThread() ;
2904
    connect(pthread,SIGNAL(codeFileChanged()),this,SLOT(updateIndicate()));
2905
    connect(currentPrj,SIGNAL(updateProgressBar(int)),this,SLOT(changeProgressBar(int)));
2906
 
2907
Parameter_incomplete:
2908
    return ;
2909
 
2910
}
2911
 
2912
void ToolWindow::writeSetting()
2913
{
2914
    QString itool ;
2915
    unsigned int unMaxRegNum = 0 ;
2916
    QString idir ;
2917
    bool isXilinxERRChecked = false ;
2918
 
2919
#if 1
2920
    if(currentPrj)
2921
    {
2922
        unMaxRegNum = currentPrj->getMaxRegNumPerChain() ;
2923
 
2924
        idir = currentPrj->getCurrentDir().absolutePath();
2925
 
2926
        if(currentPrj->getToolType() == EziDebugPrj::ToolQuartus)
2927
        {
2928
            itool = "quartus" ;
2929
        }
2930
        else if(currentPrj->getToolType() == EziDebugPrj::ToolIse)
2931
        {
2932
            itool = "ise" ;
2933
        }
2934
        else
2935
        {
2936
            itool = "" ;
2937
        }
2938
 
2939
        isXilinxERRChecked = currentPrj->getSoftwareXilinxErrCheckedFlag() ;
2940
    }
2941
#endif
2942
 
2943
    qDebug() << "Attention: Begin to writtingSetting!" ;
2944
    QSettings isettings("Eda Center.", "EziDebug");
2945
    // 获取工程参数,如果有就创建工程对象;没有的话,不创建
2946
    isettings.beginGroup("project");
2947
    isettings.setValue("MaxRegNum",unMaxRegNum);
2948
    isettings.setValue("dir",idir);
2949
    isettings.setValue("tool",itool);
2950
    isettings.setValue("isXilinxERRChecked",isXilinxERRChecked);
2951
    isettings.endGroup();
2952
    qDebug() << "Attention: End to writtingSetting!" << unMaxRegNum  \
2953
                << idir << itool ;
2954
 
2955
}
2956
 
2957
void ToolWindow::closeEvent(QCloseEvent *event)
2958
{
2959
    myTrayIcon->hide(); //test
2960
    if (myTrayIcon->isVisible())
2961
    {
2962
        myTrayIcon->showMessage("EziDebug", "Hi,This is my EziDebug.",QSystemTrayIcon::Information,5000);
2963
 
2964
        hide();     //最小化
2965
        event->ignore();
2966
    }
2967
    else
2968
    {
2969
        writeSetting() ;
2970
        event->accept();
2971
    }
2972
}
2973
 
2974
 
2975
//-----------------------各个slot------------------------
2976
//最小化//点击最小化按钮时,工具栏窗口和列表窗口都隐藏
2977
void ToolWindow::minimize()
2978
{
2979
    //showMinimized();
2980
    this->hide();
2981
    //if(!isNormalListWindowHidden)
2982
    listWindow->hide();
2983
 
2984
    miniWindow->hide();
2985
 
2986
    miniSizeAction->setDisabled(true);
2987
    restoreWinAction->setDisabled(false);
2988
}
2989
 
2990
//转换到迷你模式
2991
void ToolWindow::toMiniMode()
2992
{
2993
//    mainWindow->show();
2994
//    if(isNormalListWindowHidden == false)
2995
//        listWindow->show();
2996
//    statusWidget->hide();
2997
 
2998
 
2999
//    if(isNormalListWindowHidden == false)
3000
//        emit hideListWindow();
3001
//    this->hide();
3002
    isNormalMode = false;
3003
    this->hide();
3004
    listWindow->hide();
3005
    miniWindow->show();
3006
 
3007
 
3008
}
3009
 
3010
//迷你模式和工具栏窗口关闭时,触发该槽
3011
void ToolWindow::close()
3012
{
3013
//    statusWidget->close();
3014
    listWindow->close();
3015
    miniWindow->close();
3016
    QWidget::close();
3017
}
3018
 
3019
 
3020
void ToolWindow::updateIndicate() // 更新提示
3021
{
3022
    tic = 0 ;
3023
    isNeededUpdate = true ;
3024
    // 快速更新  全部更新 按钮可用
3025
    updatehintButton->setEnabled(true);
3026
    iChangeUpdateButtonTimer->start(300);
3027
 
3028
    return ;
3029
}
3030
 
3031
void ToolWindow::fastUpdate()
3032
{
3033
    QStringList iaddFileList ;
3034
    QStringList idelFileList ;
3035
    QStringList ichgFileList ;
3036
    UpdateDetectThread *pthread = NULL ;
3037
    QStringList ideletedChainList ;
3038
    QList<EziDebugPrj::LOG_FILE_INFO*> iaddedinfoList ;
3039
    QList<EziDebugPrj::LOG_FILE_INFO*> ideletedinfoList ;
3040
 
3041
    if(!currentPrj)
3042
    {
3043
        QMessageBox::warning(this, QObject::tr("快速更新"),QObject::tr("您所指定的工程不存在!"));
3044
        return ;
3045
    }
3046
 
3047
 
3048
    if(!isNeededUpdate)
3049
    {
3050
        QMessageBox::information(this, QObject::tr("快速更新"),QObject::tr("无文件可更新!"));
3051
        return ;
3052
    }
3053
 
3054
    progressBar->setValue(2);
3055
 
3056
    /*退出更新线程*/
3057
    pthread = currentPrj->getThread() ;
3058
    if(pthread->isRunning())
3059
    {
3060
        pthread->quit();
3061
        pthread->wait();
3062
    }
3063
 
3064
    idelFileList = currentPrj->getUpdateFileList(EziDebugPrj::deletedUpdateFileType) ;
3065
    iaddFileList = currentPrj->getUpdateFileList(EziDebugPrj::addedUpdateFileType) ;
3066
    ichgFileList = currentPrj->getUpdateFileList(EziDebugPrj::changedUpdateFileType) ;
3067
 
3068
    // clear up the related chainlist last time
3069
    currentPrj->clearupCheckedChainList();
3070
    currentPrj->clearupDestroyedChainList();
3071
 
3072
    progressBar->setValue(10);
3073
 
3074
    if(currentPrj->updatePrjAllFile(iaddFileList,idelFileList,ichgFileList,iaddedinfoList,ideletedinfoList,true))
3075
    {
3076
        QMessageBox::warning(this, QObject::tr("快速更新失败"),QObject::tr("软件内部错误!"));
3077
 
3078
        /*重启更新线程*/
3079
        pthread->start();
3080
 
3081
        progressBar->setValue(0);
3082
        return ;
3083
 
3084
    }
3085
 
3086
    currentPrj->setInstanceTreeHeadItem(NULL);
3087
    QString itopModule = currentPrj->getTopModule() ;
3088
 
3089
 
3090
    QString itopModuleComboName = itopModule + QObject::tr(":")+ itopModule ;
3091
    EziDebugInstanceTreeItem* pnewHeadItem = new EziDebugInstanceTreeItem(itopModule,itopModule);
3092
    if(!pnewHeadItem)
3093
    {
3094
        QMessageBox::critical(this, QObject::tr("快速更新失败"),QObject::tr("软件内部错误!"));
3095
        return ;
3096
    }
3097
 
3098
    progressBar->setValue(50);
3099
 
3100
    if(currentPrj->traverseModuleTree(itopModuleComboName,pnewHeadItem))
3101
    {
3102
        qDebug() << tr("快速更新失败") << __FILE__ << __LINE__ ;
3103
        delete pnewHeadItem ;
3104
        qDeleteAll(iaddedinfoList);
3105
        qDeleteAll(ideletedinfoList);
3106
        pthread->start();
3107
        QMessageBox::warning(this, QObject::tr("快速更新失败"),QObject::tr("软件内部错误!"));
3108
        return ;
3109
    }
3110
 
3111
    progressBar->setValue(70);
3112
 
3113
    currentPrj->setInstanceTreeHeadItem(pnewHeadItem);
3114
 
3115
    /////////////////////////////
3116
    if(currentPrj->getDestroyedChainList().count())
3117
    {
3118
        // 把所有破坏掉的链打印出来
3119
        QString ichain ;
3120
        QStringList idestroyedChainList = currentPrj->getDestroyedChainList() ;
3121
 
3122
        listWindow->addMessage("warning","EziDebug warning: Some chains are destroyed!");
3123
        listWindow->addMessage("warning","the destroyed chain are:");
3124
        for(int i = 0 ; i < idestroyedChainList.count() ;i++)
3125
        {
3126
            QString ichainName = idestroyedChainList.at(i) ;
3127
 
3128
            EziDebugInstanceTreeItem *pitem = currentPrj->getChainTreeItemMap().value(ichainName,NULL);
3129
            if(pitem)
3130
            {
3131
                ichain.append(tr("EziDebug chain:%1  topInstance:%2:%3").arg(ichainName)\
3132
                              .arg(pitem->getModuleName()).arg(pitem->getInstanceName())) ;
3133
            }
3134
            listWindow->addMessage("warning",ichain);
3135
        }
3136
 
3137
        // 扫描链被破坏 ,提示删除
3138
        QMessageBox::StandardButton rb = QMessageBox::question(this, tr("部分扫描链被破坏"), tr("是否删除相关扫描链代码"), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) ;
3139
        if(rb == QMessageBox::Yes)
3140
        {
3141
            QStringList iunDelChainList = currentPrj->deleteDestroyedChain(iaddedinfoList,ideletedinfoList) ;
3142
            if(iunDelChainList.count())
3143
            {
3144
                listWindow->addMessage("error","EziDebug error: Some chains do not be deleted for some reasons!");
3145
                for(int i = 0 ; i < iunDelChainList.count() ;i++)
3146
                {
3147
                    listWindow->addMessage("error",tr("EziDebug chain:%1").arg(iunDelChainList.at(i)));
3148
                }
3149
                listWindow->addMessage("error","EziDebug error: Please check the code file is compiled successed!");
3150
            }
3151
 
3152
            for(int i = 0 ; i < idestroyedChainList.count() ; i++)
3153
            {
3154
                QString idestroyedChain = idestroyedChainList.at(i) ;
3155
                ideletedChainList.append(idestroyedChain);
3156
                if(!iunDelChainList.contains(idestroyedChain))
3157
                {
3158
                    struct EziDebugPrj::LOG_FILE_INFO* pdelChainInfo = new EziDebugPrj::LOG_FILE_INFO ;
3159
                    memcpy(pdelChainInfo->ainfoName,idestroyedChain.toAscii().data(),idestroyedChain.size()+1);
3160
                    pdelChainInfo->pinfo = NULL ;
3161
                    pdelChainInfo->etype = EziDebugPrj::infoTypeScanChainStructure ;
3162
                    ideletedinfoList << pdelChainInfo ;
3163
                }
3164
            }
3165
        }
3166
    }
3167
 
3168
    QStringList icheckChainList = currentPrj->checkChainExist();
3169
 
3170
    for(int i = 0 ; i < icheckChainList.count() ;i++)
3171
    {
3172
        QString iupdatedChain = icheckChainList.at(i) ;
3173
        if(!ideletedChainList.contains(iupdatedChain))
3174
        {
3175
            struct EziDebugPrj::LOG_FILE_INFO* pdelChainInfo = new EziDebugPrj::LOG_FILE_INFO ;
3176
            memcpy(pdelChainInfo->ainfoName,iupdatedChain.toAscii().data(),iupdatedChain.size()+1);
3177
            pdelChainInfo->pinfo = NULL ;
3178
            pdelChainInfo->etype = EziDebugPrj::infoTypeScanChainStructure ;
3179
            ideletedinfoList << pdelChainInfo ;
3180
 
3181
            struct EziDebugPrj::LOG_FILE_INFO* paddChainInfo = new EziDebugPrj::LOG_FILE_INFO ;
3182
            memcpy(paddChainInfo->ainfoName,iupdatedChain.toAscii().data(),iupdatedChain.size()+1);
3183
            paddChainInfo->pinfo = paddChainInfo ;
3184
            paddChainInfo->etype = EziDebugPrj::infoTypeScanChainStructure ;
3185
            iaddedinfoList << paddChainInfo ;
3186
        }
3187
    }
3188
 
3189
    /////////////////////////////
3190
    progressBar->setValue(80);
3191
 
3192
    if(currentPrj->changedLogFile(iaddedinfoList,ideletedinfoList))
3193
    {
3194
        //提示 保存 log 文件出错
3195
        qDebug() << "Error: changedLogFile Error!";
3196
    }
3197
 
3198
    // 删除 新分配的  log_file_info 指针
3199
    qDeleteAll(iaddedinfoList);
3200
    qDeleteAll(ideletedinfoList);
3201
 
3202
    progressBar->setValue(90);
3203
 
3204
    currentPrj->cleanupChainTreeItemMap();
3205
    currentPrj->cleanupBakChainTreeItemMap();
3206
 
3207
    if(currentPrj->getLastOperation() == EziDebugPrj::OperateTypeDelAllScanChain)
3208
    {
3209
        currentPrj->cleanupChainQueryTreeItemMap();
3210
    }
3211
    else
3212
    {
3213
        currentPrj->cleanupBakChainQueryTreeItemMap();
3214
    }
3215
 
3216
    currentPrj->updateTreeItem(pnewHeadItem);
3217
 
3218
 
3219
    if(currentPrj->getLastOperation() == EziDebugPrj::OperateTypeDelAllScanChain)
3220
    {
3221
        // ChainTreeItemMap 存放新的节点map
3222
        // 恢复 bakChainTreeItemMap 删除 ChainTreeItemMap
3223
 
3224
        // ChainQueryTreeItemMap 存放新的节点map
3225
        // 恢复 bakChainQueryTreeItemMap 删除 ChainQueryTreeItemMap
3226
        // update 用的 BakChainQueryTreeItemMap 放原始的、 ChainQueryTreeItemMap 放的新的
3227
        currentPrj->cleanupBakChainQueryTreeItemMap();
3228
        currentPrj->backupChainQueryTreeItemMap();
3229
        currentPrj->cleanupChainQueryTreeItemMap();
3230
    }
3231
    else
3232
    {
3233
        // update 用的 ChainQueryTreeItemMap 放原始的、 bakChainQueryTreeItemMap 放新的
3234
        currentPrj->cleanupChainQueryTreeItemMap();
3235
        currentPrj->resumeChainQueryTreeItemMap();
3236
        currentPrj->cleanupBakChainQueryTreeItemMap();
3237
        // treeitemmap 、ChainQueryTreeItemMap、m_ichainInfoMap 非空
3238
    }
3239
 
3240
    emit updateTreeView(pnewHeadItem);
3241
 
3242
    // 重置 更新提示
3243
    isNeededUpdate = false ;
3244
    updatehintButton->setIcon(QIcon(":/images/update2.png"));
3245
    updatehintButton->setDisabled(true);
3246
    iChangeUpdateButtonTimer->stop();
3247
 
3248
    /*重启更新线程*/
3249
    pthread->start();
3250
 
3251
    progressBar->setValue(100);
3252
 
3253
    QMessageBox::warning(this, QObject::tr("快速更新"),QObject::tr("快速更新完毕!"));
3254
 
3255
    progressBar->setValue(0);
3256
 
3257
}
3258
 
3259
void ToolWindow::undoOperation()
3260
{
3261
    QList<EziDebugPrj::LOG_FILE_INFO*> iaddedinfoList ;
3262
    QList<EziDebugPrj::LOG_FILE_INFO*> ideletedinfoList ;
3263
    QString irelativeFileName ;
3264
    UpdateDetectThread* pthread = NULL ;
3265
    QDateTime ilastModifedTime ;
3266
    QString ifileName ;
3267
    EziDebugVlgFile *pvlgFile = NULL ;
3268
    EziDebugVhdlFile *pvhdlFile = NULL ;
3269
    QStringList ifileList ;
3270
    bool isstopFlag = false ;
3271
    int i = 0 ;
3272
 
3273
    if(!currentPrj)
3274
    {
3275
        QMessageBox::warning(this, QObject::tr("撤销上一步操作"),QObject::tr("您所指定的工程不存在!"));
3276
        return ;
3277
    }
3278
 
3279
    // 停止检测更新   退出线程
3280
    pthread = currentPrj->getThread() ;
3281
    if(pthread->isRunning())
3282
    {
3283
        pthread->quit();
3284
        pthread->wait();
3285
        isstopFlag = true ;
3286
    }
3287
 
3288
    // 5%
3289
    if(EziDebugPrj::OperateTypeAddScanChain == currentPrj->getLastOperation())
3290
    {
3291
        // 删除链相关的指针对象
3292
        EziDebugScanChain *plastOperatedChain = currentPrj->getLastOperateChain() ;
3293
        if(!plastOperatedChain)
3294
        {
3295
            /*提示 无扫描链*/
3296
            QMessageBox::information(this, QObject::tr("undo"),QObject::tr("上一步操作的扫描链不存在!"));
3297
            pthread->start();
3298
            return ;
3299
        }
3300
 
3301
 
3302
        ifileList = plastOperatedChain->getScanedFileList() ;
3303
        // 10%
3304
        // check the backup file exist
3305
        i = 0 ;
3306
        for( ; i < ifileList.count() ; i++)
3307
        {
3308
            // 获取备份的文件名全称
3309
            // 10% +
3310
            ifileName = ifileList.at(i) ;
3311
            QFileInfo ifileInfo(ifileName);
3312
            QString ieziDebugFileSuffix ;
3313
            irelativeFileName = currentPrj->getCurrentDir().relativeFilePath(ifileName);
3314
 
3315
            ieziDebugFileSuffix.append(QObject::tr(".add.%1").arg(currentPrj->getLastOperateChain()->getChainName()));
3316
 
3317
            QString ibackupFileName = currentPrj->getCurrentDir().absolutePath() \
3318
                    + EziDebugScanChain::getUserDir() + QObject::tr("/") + ifileInfo.fileName() \
3319
                    + ieziDebugFileSuffix;
3320
            QFile ibackupFile(ibackupFileName) ;
3321
 
3322
            if(!ibackupFile.exists())
3323
            {
3324
                QMessageBox::information(this, QObject::tr("undo"),QObject::tr("备份文件%1不存在!").arg(ibackupFileName));
3325
                pthread->start();
3326
                return ;
3327
            }
3328
        }
3329
 
3330
        /*从备份文件中恢复文件*/
3331
        i = 0 ;
3332
        for( ; i < ifileList.count() ; i++)
3333
        {
3334
            // 获取备份的文件名全称
3335
            ifileName = ifileList.at(i) ;
3336
            QFileInfo ifileInfo(ifileName);
3337
            QString ieziDebugFileSuffix ;
3338
            irelativeFileName = currentPrj->getCurrentDir().relativeFilePath(ifileName);
3339
 
3340
            ieziDebugFileSuffix.append(QObject::tr(".add.%1").arg(currentPrj->getLastOperateChain()->getChainName()));
3341
 
3342
            QString ibackupFileName = currentPrj->getCurrentDir().absolutePath() \
3343
                    + EziDebugScanChain::getUserDir() + QObject::tr("/") + ifileInfo.fileName() \
3344
                    + ieziDebugFileSuffix;
3345
            QFile ibackupFile(ibackupFileName) ;
3346
 
3347
            if(!ibackupFile.exists())
3348
            {
3349
                QMessageBox::information(this, QObject::tr("undo失败"),QObject::tr("备份文件%1不存在!").arg(ibackupFileName));
3350
                pthread->start();
3351
                return ;
3352
            }
3353
 
3354
            // 文件被修改了 需要重新保存文件日期
3355
            struct EziDebugPrj::LOG_FILE_INFO* pdelFileInfo = new EziDebugPrj::LOG_FILE_INFO ;
3356
            pdelFileInfo->etype = EziDebugPrj::infoTypeFileInfo ;
3357
            pdelFileInfo->pinfo = NULL ;
3358
            memcpy(pdelFileInfo->ainfoName , irelativeFileName.toAscii().data() , irelativeFileName.size()+1);
3359
            ideletedinfoList.append(pdelFileInfo);
3360
 
3361
 
3362
            struct EziDebugPrj::LOG_FILE_INFO* paddFileInfo = new EziDebugPrj::LOG_FILE_INFO ;
3363
            paddFileInfo->etype = EziDebugPrj::infoTypeFileInfo ;
3364
 
3365
            if(ifileName.endsWith(".v"))
3366
            {
3367
                pvlgFile = currentPrj->getPrjVlgFileMap().value(currentPrj->getCurrentDir().relativeFilePath(ifileName)) ;
3368
                pvlgFile->remove();
3369
                // 已经是绝对路径了
3370
                ibackupFile.copy(ifileName);
3371
                pvlgFile->modifyStoredTime(ifileInfo.lastModified());
3372
                paddFileInfo->pinfo = pvlgFile ;
3373
            }
3374
            else if(ifileName.endsWith(".vhd"))
3375
            {
3376
                // 已经是绝对路径了
3377
                // ibackupFile.copy(plastOperatedChain->getScanedFileList().at(i));
3378
            }
3379
            else
3380
            {
3381
                continue ;
3382
            }
3383
 
3384
            memcpy(paddFileInfo->ainfoName , irelativeFileName.toAscii().data(), irelativeFileName.size()+1);
3385
            iaddedinfoList.append(paddFileInfo);
3386
 
3387
            // 删除备份的文件
3388
            ibackupFile.remove();
3389
        }
3390
 
3391
        // undo success delete scanchain info in log file!
3392
        struct EziDebugPrj::LOG_FILE_INFO* pdelChainInfo = new EziDebugPrj::LOG_FILE_INFO ;
3393
        memcpy(pdelChainInfo->ainfoName,plastOperatedChain->getChainName().toAscii().data(),plastOperatedChain->getChainName().size()+1);
3394
        pdelChainInfo->pinfo = NULL ;
3395
        pdelChainInfo->etype = EziDebugPrj::infoTypeScanChainStructure ;
3396
        ideletedinfoList.append(pdelChainInfo) ;
3397
 
3398
        // 从chain map 中删除
3399
        currentPrj->eliminateChainFromMap(plastOperatedChain->getChainName());
3400
 
3401
        // 将 item 的 chain 置为空
3402
        EziDebugInstanceTreeItem * item = currentPrj->getChainTreeItemMap().value(plastOperatedChain->getChainName());
3403
        if(item)
3404
        {
3405
            item->setScanChainInfo(NULL);
3406
        }
3407
        else
3408
        {
3409
            pthread->start();
3410
            return ;
3411
        }
3412
        // 从item map 中删除
3413
        currentPrj->eliminateTreeItemFromMap(plastOperatedChain->getChainName());
3414
 
3415
        currentPrj->eliminateTreeItemFromQueryMap(item->getNameData());
3416
 
3417
        // 删除指针对象
3418
        delete  plastOperatedChain ;
3419
        plastOperatedChain = NULL ;
3420
 
3421
        // 上一步操作相关对象 置空
3422
        currentPrj->updateOperation(EziDebugPrj::OperateTypeNone,NULL,NULL);
3423
    }
3424
    else if(EziDebugPrj::OperateTypeDelSingleScanChain == currentPrj->getLastOperation())
3425
    {
3426
        // 恢复 上次删除的链
3427
        EziDebugScanChain *plastOperatedChain = currentPrj->getLastOperateChain() ;
3428
        if(!plastOperatedChain)
3429
        {
3430
            /*提示 无扫描链*/
3431
            pthread->start();
3432
            return ;
3433
        }
3434
        EziDebugInstanceTreeItem * plastOperatedItem = currentPrj->getLastOperateTreeItem();
3435
        if(!plastOperatedItem)
3436
        {
3437
            /*提示 无此节点*/
3438
            pthread->start();
3439
            return ;
3440
        }
3441
 
3442
        // check the back up file
3443
        for(i = 0 ; i < plastOperatedChain->getScanedFileList().count();i++)
3444
        {
3445
            // 获取备份的文件名全称
3446
            ifileName = plastOperatedChain->getScanedFileList().at(i) ;
3447
            irelativeFileName = currentPrj->getCurrentDir().relativeFilePath(ifileName);
3448
 
3449
            QFileInfo ifileInfo(ifileName);
3450
            QString ieziDebugFileSuffix ;
3451
            ieziDebugFileSuffix.append(QObject::tr(".delete.%1").arg(plastOperatedChain->getChainName()));
3452
 
3453
            QString ibackupFileName = currentPrj->getCurrentDir().absolutePath() \
3454
                    + EziDebugScanChain::getUserDir() + QObject::tr("/") + ifileInfo.fileName() \
3455
                    + ieziDebugFileSuffix;
3456
            QFile ibackupFile(ibackupFileName) ;
3457
            if(!ibackupFile.exists())
3458
            {
3459
                QMessageBox::information(this, QObject::tr("undo失败"),QObject::tr("备份文件%1不存在!").arg(ibackupFileName));
3460
                pthread->start();
3461
                return ;
3462
            }
3463
        }
3464
 
3465
         // 恢复源文件
3466
        for(i = 0 ; i < plastOperatedChain->getScanedFileList().count();i++)
3467
        {
3468
            // 获取备份的文件名全称
3469
            ifileName = plastOperatedChain->getScanedFileList().at(i) ;
3470
            irelativeFileName = currentPrj->getCurrentDir().relativeFilePath(ifileName);
3471
 
3472
            QFileInfo ifileInfo(ifileName);
3473
            QString ieziDebugFileSuffix ;
3474
            ieziDebugFileSuffix.append(QObject::tr(".delete.%1").arg(plastOperatedChain->getChainName()));
3475
 
3476
            QString ibackupFileName = currentPrj->getCurrentDir().absolutePath() \
3477
                    + EziDebugScanChain::getUserDir() + QObject::tr("/") + ifileInfo.fileName() \
3478
                    + ieziDebugFileSuffix;
3479
            QFile ibackupFile(ibackupFileName) ;
3480
 
3481
 
3482
            struct EziDebugPrj::LOG_FILE_INFO* pdelFileInfo = new EziDebugPrj::LOG_FILE_INFO ;
3483
            pdelFileInfo->etype = EziDebugPrj::infoTypeFileInfo ;
3484
            pdelFileInfo->pinfo = NULL ;
3485
            memcpy(pdelFileInfo->ainfoName , irelativeFileName.toAscii().data() , irelativeFileName.size()+1);
3486
            ideletedinfoList.append(pdelFileInfo);
3487
 
3488
            struct EziDebugPrj::LOG_FILE_INFO* paddFileInfo = new EziDebugPrj::LOG_FILE_INFO ;
3489
            paddFileInfo->etype = EziDebugPrj::infoTypeFileInfo ;
3490
 
3491
            if(ifileName.endsWith(".v"))
3492
            {
3493
                pvlgFile = currentPrj->getPrjVlgFileMap().value(currentPrj->getCurrentDir().relativeFilePath(ifileName)) ;
3494
                pvlgFile->remove();
3495
                // 已经是绝对路径了
3496
                ibackupFile.copy(ifileName);
3497
                pvlgFile->modifyStoredTime(ifileInfo.lastModified());
3498
                paddFileInfo->pinfo = pvlgFile ;
3499
            }
3500
            else if(ifileName.endsWith(".vhd"))
3501
            {
3502
                // 已经是绝对路径了
3503
                // ibackupFile.copy(plastOperatedChain->getScanedFileList().at(i));
3504
            }
3505
            else
3506
            {
3507
                continue ;
3508
            }
3509
            memcpy(paddFileInfo->ainfoName , irelativeFileName.toAscii().data(), irelativeFileName.size()+1);
3510
            iaddedinfoList.append(paddFileInfo);
3511
 
3512
            // 删除备份的文件
3513
            ibackupFile.remove();
3514
        }
3515
 
3516
 
3517
        // add chain info to log file
3518
        struct EziDebugPrj::LOG_FILE_INFO* paddChainInfo = new EziDebugPrj::LOG_FILE_INFO ;
3519
        memcpy(paddChainInfo->ainfoName ,plastOperatedChain->getChainName().toAscii().data(),plastOperatedChain->getChainName().size()+1);
3520
        paddChainInfo->pinfo = plastOperatedChain ;
3521
        paddChainInfo->etype = EziDebugPrj::infoTypeScanChainStructure ;
3522
        iaddedinfoList << paddChainInfo ;
3523
 
3524
        //
3525
        plastOperatedItem->setScanChainInfo(plastOperatedChain);
3526
 
3527
        //  加入 item map
3528
        currentPrj->addToTreeItemMap(plastOperatedChain->getChainName(),plastOperatedItem);
3529
 
3530
 
3531
        //  加入 item map
3532
        currentPrj->addToChainMap(plastOperatedChain);
3533
 
3534
        //
3535
        currentPrj->addToQueryItemMap(plastOperatedItem->getNameData(),plastOperatedItem);
3536
 
3537
        // 上一步操作相关对象 置空
3538
        currentPrj->updateOperation(EziDebugPrj::OperateTypeNone,NULL,NULL);
3539
 
3540
    }
3541
    else if(EziDebugPrj::OperateTypeDelAllScanChain == currentPrj->getLastOperation())
3542
    {
3543
        QStringList irepeatedFileList ;
3544
 
3545
        QMap<QString,EziDebugInstanceTreeItem*> ichainTreeItemMap = currentPrj->getBackupChainTreeItemMap();
3546
        QMap<QString,EziDebugInstanceTreeItem*>::const_iterator i = ichainTreeItemMap.constBegin();
3547
        // check backup file exist
3548
        while( i != ichainTreeItemMap.constEnd())
3549
        {
3550
            EziDebugScanChain * plastChain = currentPrj->getBackupChainMap().value(i.key());
3551
            /*读取删除链 已经扫描过的文件,从已经备份的文件中恢复*/
3552
            for(int p = 0 ; p < plastChain->getScanedFileList().count();p++)
3553
            {
3554
                // 获取备份的文件名全称
3555
                ifileName = plastChain->getScanedFileList().at(p) ;
3556
                irelativeFileName = currentPrj->getCurrentDir().relativeFilePath(ifileName);
3557
 
3558
                QFileInfo ifileInfo(ifileName);
3559
                QString ieziDebugFileSuffix ;
3560
 
3561
                ieziDebugFileSuffix.append(QObject::tr(".deleteall"));
3562
 
3563
                QString ibackupFileName = currentPrj->getCurrentDir().absolutePath() \
3564
                        + EziDebugScanChain::getUserDir()+ QObject::tr("/") + ifileInfo.fileName() \
3565
                        + ieziDebugFileSuffix;
3566
                QFile ibackupFile(ibackupFileName) ;
3567
                if(!ibackupFile.exists())
3568
                {
3569
                    QMessageBox::information(this, QObject::tr("undo失败"),QObject::tr("备份文件%1不存在!").arg(ibackupFileName));
3570
                    pthread->start();
3571
                    return ;
3572
                }
3573
            }
3574
            ++i ;
3575
        }
3576
 
3577
        // 恢复源文件
3578
        i = ichainTreeItemMap.constBegin();
3579
        while(i != ichainTreeItemMap.constEnd())
3580
        {
3581
            /*将chain指针加入到 树状节点下面*/
3582
            EziDebugInstanceTreeItem* pitem = i.value() ;
3583
 
3584
            EziDebugScanChain * plastChain = currentPrj->getBackupChainMap().value(i.key());
3585
            pitem->setScanChainInfo(plastChain);
3586
 
3587
 
3588
            struct EziDebugPrj::LOG_FILE_INFO* paddChainInfo = new EziDebugPrj::LOG_FILE_INFO ;
3589
            memcpy(paddChainInfo->ainfoName ,plastChain->getChainName().toAscii().data(),plastChain->getChainName().size()+1);
3590
            paddChainInfo->pinfo = plastChain ;
3591
            paddChainInfo->etype = EziDebugPrj::infoTypeScanChainStructure ;
3592
            iaddedinfoList << paddChainInfo ;
3593
 
3594
 
3595
            /*读取删除链 已经扫描过的文件,从已经备份的文件中恢复*/
3596
            for(int p = 0 ; p < plastChain->getScanedFileList().count();p++)
3597
            {
3598
                // 获取备份的文件名全称
3599
                ifileName = plastChain->getScanedFileList().at(p) ;
3600
                irelativeFileName = currentPrj->getCurrentDir().relativeFilePath(ifileName);
3601
 
3602
                QFileInfo ifileInfo(ifileName);
3603
                QString ieziDebugFileSuffix ;
3604
 
3605
                ieziDebugFileSuffix.append(QObject::tr(".deleteall"));
3606
 
3607
                QString ibackupFileName = currentPrj->getCurrentDir().absolutePath() \
3608
                        + EziDebugScanChain::getUserDir()+ QObject::tr("/") + ifileInfo.fileName() \
3609
                        + ieziDebugFileSuffix;
3610
                QFile ibackupFile(ibackupFileName) ;
3611
 
3612
                struct EziDebugPrj::LOG_FILE_INFO* pdelFileInfo = new EziDebugPrj::LOG_FILE_INFO ;
3613
                pdelFileInfo->etype = EziDebugPrj::infoTypeFileInfo ;
3614
                pdelFileInfo->pinfo = NULL ;
3615
                memcpy(pdelFileInfo->ainfoName , irelativeFileName.toAscii().data() , irelativeFileName.size()+1);
3616
                ideletedinfoList.append(pdelFileInfo);
3617
 
3618
                struct EziDebugPrj::LOG_FILE_INFO* paddFileInfo = new EziDebugPrj::LOG_FILE_INFO ;
3619
                paddFileInfo->etype = EziDebugPrj::infoTypeFileInfo ;
3620
 
3621
                if(ifileName.endsWith(".v"))
3622
                {
3623
                    pvlgFile = currentPrj->getPrjVlgFileMap().value(currentPrj->getCurrentDir().relativeFilePath(ifileName)) ;
3624
                    pvlgFile->remove();
3625
 
3626
                    ibackupFile.copy(ifileName);
3627
                    pvlgFile->modifyStoredTime(ifileInfo.lastModified());
3628
                    paddFileInfo->pinfo = pvlgFile ;
3629
                }
3630
                else if(ifileName.endsWith(".vhd"))
3631
                {
3632
                    // 已经是绝对路径了
3633
                    // ibackupFile.copy(plastOperatedChain->getScanedFileList().at(i));
3634
                }
3635
                else
3636
                {
3637
                    continue ;
3638
                }
3639
                memcpy(paddFileInfo->ainfoName , irelativeFileName.toAscii().data(), irelativeFileName.size()+1);
3640
                iaddedinfoList.append(paddFileInfo);
3641
                // 删除当前备份的文件
3642
                ibackupFile.remove();
3643
            }
3644
 
3645
            i++ ;
3646
        }
3647
 
3648
        //
3649
        currentPrj->resumeChainMap();
3650
 
3651
        //
3652
        currentPrj->resumeChainTreeItemMap();
3653
 
3654
        //
3655
        currentPrj->resumeChainQueryTreeItemMap();
3656
 
3657
        // 上一步操作相关对象 置空
3658
        currentPrj->updateOperation(EziDebugPrj::OperateTypeNone,NULL,NULL);
3659
    }
3660
    else
3661
    {
3662
        QMessageBox::information(this , QObject::tr("注意") , QObject::tr("上一步无操作!"));
3663
 
3664
        if(isstopFlag == true)
3665
        {
3666
            pthread->start();
3667
        }
3668
        return ;
3669
    }
3670
 
3671
    // 90%
3672
    if(currentPrj->changedLogFile(iaddedinfoList,ideletedinfoList))
3673
    {
3674
        // 提示 保存 log 文件出错
3675
        qDebug() << tr("Error:Save log file Error in undo operation!") ;
3676
    }
3677
 
3678
    qDeleteAll(ideletedinfoList);
3679
    qDeleteAll(iaddedinfoList);
3680
 
3681
    if(isstopFlag == true)
3682
    {
3683
        pthread->start();
3684
    }
3685
 
3686
    // 100%
3687
    QMessageBox::information(this, QObject::tr("undo操作"),QObject::tr("撤销上一步操作完毕!"));
3688
 
3689
    return ;
3690
}
3691
 
3692
void ToolWindow::changeUpdatePic()
3693
{
3694
    tic++ ;
3695
    if(tic%2)
3696
    {
3697
        updatehintButton->setIcon(QIcon(":/images/update3.png"));
3698
    }
3699
    else
3700
    {
3701
        updatehintButton->setIcon(QIcon(":/images/update2.png"));
3702
    }
3703
    iChangeUpdateButtonTimer->start();
3704
}
3705
 
3706
//从最小化还原
3707
void ToolWindow::showNormal()
3708
{
3709
    miniSizeAction->setDisabled(false);
3710
    restoreWinAction->setDisabled(true);
3711
    if(isNormalMode)
3712
    {
3713
 
3714
    if(!listWindow->isListWindowHidden())
3715
        listWindow->show();
3716
        this->show();
3717
    }
3718
    else
3719
        miniWindow->show();
3720
 
3721
}
3722
 
3723
void ToolWindow::changeProgressBar(int value)
3724
{
3725
    progressBar->setValue(value);
3726
}
3727
 
3728
 
3729
//右侧中部按钮,打开toolwindow下方的列表窗口
3730
void ToolWindow::showListWindow()
3731
{
3732
 
3733
    if(listWindow->isListWindowHidden()){
3734
        listWindow->setListWindowHidden(false);
3735
 
3736
    }
3737
    else{
3738
        listWindow->setListWindowHidden(true);
3739
    }
3740
}
3741
 
3742
//关于
3743
void ToolWindow::about()
3744
{
3745
    QMessageBox::about(this, tr("关于"), tr("    版权由中科院EDA中心所有    \n\n"));
3746
 
3747
}
3748
 
3749
//帮助
3750
void ToolWindow::help()
3751
{
3752
 
3753
}
3754
 
3755
 
3756
//系统托盘相关函数
3757
void ToolWindow::iconActivated(QSystemTrayIcon::ActivationReason reason)
3758
{
3759
    switch(reason)
3760
    {
3761
    case QSystemTrayIcon::Trigger:
3762
    case QSystemTrayIcon::DoubleClick:
3763
        //普通模式下,窗口最小化或者不在顶层
3764
        if(isNormalMode)
3765
        {
3766
            if(this->isHidden() || !this->isTopLevel())
3767
            {
3768
                if(!listWindow->isListWindowHidden()){
3769
                    listWindow->show();
3770
                    listWindow->raise();
3771
                    listWindow->activateWindow();
3772
                }
3773
                this->show();
3774
                this->raise();
3775
                this->activateWindow();
3776
 
3777
                miniSizeAction->setDisabled(false);
3778
                restoreWinAction->setDisabled(true);
3779
            }
3780
            else
3781
            {
3782
 
3783
                this->hide();
3784
                listWindow->hide();
3785
 
3786
                miniSizeAction->setDisabled(true);
3787
                restoreWinAction->setDisabled(false);
3788
            }
3789
        }
3790
        //迷你模式下,窗口最小化
3791
        else
3792
        {
3793
            if(miniWindow->isHidden())
3794
            {
3795
                miniWindow->showNormal();
3796
 
3797
                miniSizeAction->setDisabled(false);
3798
                restoreWinAction->setDisabled(true);
3799
            }
3800
            else
3801
            {
3802
                miniWindow->hide();
3803
                miniSizeAction->setDisabled(true);
3804
                restoreWinAction->setDisabled(false);
3805
            }
3806
        }
3807
        break;
3808
    case QSystemTrayIcon::MiddleClick:
3809
        myTrayIcon->showMessage("EziDebug", "Hi,This is my EziDebug.",QSystemTrayIcon::Information,10000);
3810
        break;
3811
 
3812
    default:
3813
        break;
3814
    }
3815
}
3816
 
3817
//迷你模式下,还原为普通模式
3818
void ToolWindow::toNormalMode()
3819
{
3820
    isNormalMode = true;
3821
    this->show();
3822
    if(!listWindow->isListWindowHidden())
3823
        listWindow->show();
3824
    miniWindow->hide();
3825
    //miniWindow->setStatusWidgetHidden(true);
3826
}
3827
 
3828
 
3829
//listWindow的窗口移动或缩放后,判断listWindow是否吸附
3830
void ToolWindow::listWindowMouseReleased(const QRect listWinGeo)
3831
{
3832
    const int disMax = 15;
3833
    isListWindowAdsorbed = false;
3834
    int dis = this->geometry().bottom() - listWinGeo.top();
3835
    if((dis < disMax) && (dis > -disMax)){
3836
        listWindow->move(listWinGeo.left(), this->geometry().bottom());//移动窗口
3837
        isListWindowAdsorbed = true;
3838
    }
3839
    dis = this->geometry().top() - listWinGeo.bottom();
3840
    if((dis < disMax) && (dis > -disMax)){
3841
        listWindow->move(listWinGeo.left(), listWinGeo.top() + dis);//移动窗口
3842
        isListWindowAdsorbed = true;
3843
    }
3844
    dis = this->geometry().right() - listWinGeo.left();
3845
    if((dis < disMax) && (dis > -disMax)){
3846
        listWindow->move(this->geometry().right(), listWindow->geometry().top());//移动窗口
3847
        isListWindowAdsorbed = true;
3848
    }
3849
 
3850
    dis = this->geometry().left() - listWinGeo.right();
3851
    if((dis < disMax) && (dis > -disMax)){
3852
        listWindow->move(listWindow->geometry().left() + dis, listWindow->geometry().top());//移动窗口
3853
        isListWindowAdsorbed = true;
3854
    }
3855
}
3856
 
3857
//void ToolWindow::proSetting()
3858
//{
3859
////    ProjectSetWizard proSetWiz(this);
3860
////    if (proSetWiz.exec()) {
3861
////        QString str = tr("aa");
3862
 
3863
////    }
3864
 
3865
//}
3866
 
3867
 
3868
 
3869
 
3870
 
3871
 
3872
 
3873
 
3874
 
3875
 
3876
 

powered by: WebSVN 2.1.0

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