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

Subversion Repositories ezidebug

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

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

powered by: WebSVN 2.1.0

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