X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/blast.git/blobdiff_plain/abbc64cf04a35ab3549d5c516f44c7c5921baa63..8fb3c55ee009a11db5e1c08a4cfb286979412745:/MainWindow.cpp diff --git a/MainWindow.cpp b/MainWindow.cpp index 01c23c1..8169dd0 100644 --- a/MainWindow.cpp +++ b/MainWindow.cpp @@ -4,14 +4,14 @@ #include "BlockLibraryWidget.h" #include "GroupWidget.h" #include "GroupScene.h" -#include "BlockWidget.h" -#include "AbstractBoxItem.h" +#include "VHDLConverter.h" #include "Graph.h" -#include "GroupItem.h" +#include "FunctionalBlock.h" #include #include #include #include +#include "NewProjectDialog.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { @@ -24,6 +24,9 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { try { params->loadBlastConfiguration("blastconfig.xml"); + // first load external sources + params->loadSources(); + if (!QFileInfo::exists(params->refLib)) { params->loadReferencesFromXml(); int ret = QMessageBox::question(this,tr("Building references library"),tr("The reference block library does not exists.\n References have been read directly from the xml descriptions of blocks.\n It can be saved into a library in order to start application faster. "), QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Ok); @@ -54,13 +57,15 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { cout << "all references and implementations are loaded" << endl; + params->createDelayBlock(); + // create the menu, action, ... dispatcher = new Dispatcher(params,this); params->setDispatcher(dispatcher); // creating block library library = new BlockLibraryWidget(dispatcher,params); - isCurrentProject = false; + params->isCurrentProject = false; QLabel* labDefault = new QLabel("BLAST: BLock ASsembler Tool"); stackedWidget = new QStackedWidget; @@ -86,9 +91,11 @@ MainWindow::~MainWindow() {} void MainWindow::initialize() { projectMenuEnb = 0; + analysisMenuEnb = 0; stackedWidget->setCurrentIndex(0); enableProjectActions(true,PROJECT_NEW | PROJECT_OPEN, OP_RAZ); + enableAnalysisActions(false); stackedWidget->setCurrentIndex(0); @@ -195,11 +202,45 @@ void MainWindow::enableProjectActions(bool enbMenu, quint16 mask, quint8 op) { } } +void MainWindow::enableAnalysisActions(bool enbMenu, quint16 mask, quint8 op) { + if (enbMenu) { + analysisMenu->setEnabled(true); + } + else { + analysisMenu->setEnabled(false); + } + + if (op == OP_ADD) { + analysisMenuEnb = analysisMenuEnb | mask; + } + else if (op == OP_REM) { + analysisMenuEnb = (analysisMenuEnb | mask) ^ mask; + } + else if (op == OP_RAZ) { + analysisMenuEnb = mask; + } + + + if (analysisMenuEnb & ANALYSIS_ANALYZE) { + graphAnalysis->setEnabled(true); + } + else { + graphAnalysis->setEnabled(false); + } + if (analysisMenuEnb & ANALYSIS_GENERATE) { + generateVHDL->setEnabled(true); + } + else { + generateVHDL->setEnabled(false); + } +} + void MainWindow::createMenus(){ allMenuBar = menuBar(); projectMenu = allMenuBar->addMenu(tr("&Project")); + analysisMenu = allMenuBar->addMenu(tr("&Analysis")); toolsMenu = allMenuBar->addMenu(tr("&Tools")); projectMenu->addAction(newProject); @@ -209,8 +250,11 @@ void MainWindow::createMenus(){ projectMenu->addAction(closeProject); projectMenu->addAction(openLibrary); - toolsMenu->addAction(newBlockWidgetAct); - toolsMenu->addAction(graphValidation); + analysisMenu->addAction(graphAnalysis); + analysisMenu->addAction(generateVHDL); + + toolsMenu->addAction(vhdlToXmlAct); + } @@ -246,39 +290,48 @@ void MainWindow::createActions() { openLibrary->setStatusTip(tr("Open block library window")); connect(openLibrary, SIGNAL(triggered()), this, SLOT(slotOpenBlockLibrary())); - newBlockWidgetAct = new QAction(tr("&XML generator"), this); - newBlockWidgetAct->setIcon(QPixmap::fromImage(QImage("icons/new.ico"))); - newBlockWidgetAct->setStatusTip(tr("Create a new XML generator")); - connect(newBlockWidgetAct, SIGNAL(triggered()), this, SLOT(slotNewBlockWidget())); + vhdlToXmlAct = new QAction(tr("&XML generator"), this); + vhdlToXmlAct->setIcon(QPixmap::fromImage(QImage("icons/new.ico"))); + vhdlToXmlAct->setStatusTip(tr("Create a new XML generator")); + connect(vhdlToXmlAct, SIGNAL(triggered()), this, SLOT(slotVHDLToXml())); - graphValidation = new QAction(tr("&graph validation"), this); - graphValidation->setIcon(QPixmap::fromImage(QImage("icons/new.ico"))); - graphValidation->setStatusTip(tr("validate the graph")); - connect(graphValidation, SIGNAL(triggered()), this, SLOT(slotGraphValidation())); + graphAnalysis = new QAction(tr("&graph analysis"), this); + graphAnalysis->setIcon(QPixmap::fromImage(QImage("icons/new.ico"))); + graphAnalysis->setStatusTip(tr("validate the graph")); + connect(graphAnalysis, SIGNAL(triggered()), this, SLOT(slotGraphAnalysis())); + + generateVHDL = new QAction(tr("generate &VHDL"), this); + generateVHDL->setIcon(QPixmap::fromImage(QImage("icons/new.ico"))); + generateVHDL->setStatusTip(tr("generate the VHDL code for the whole design")); + connect(generateVHDL, SIGNAL(triggered()), this, SLOT(slotGenerateVHDL())); } -void MainWindow::save(QString absoluteFilename) { - params->save(absoluteFilename); +void MainWindow::save(QString projectFile) { + params->save(projectFile); } void MainWindow::slotLoadProject(){ - absoluteFilename = QFileDialog::getOpenFileName(0, "select a project file", "save/",tr("sauvegardes (*.xml)")); + params->projectFile = QFileDialog::getOpenFileName(0, "select a project file", "save/",tr("sauvegardes (*.xml)")); - if(! absoluteFilename.isEmpty()){ - GroupWidget* topGroup = dispatcher->loadProject(absoluteFilename); + if(! params->projectFile.isEmpty()){ + GroupWidget* topGroup = dispatcher->loadProject(params->projectFile); if (topGroup != NULL) { addTopGroup(topGroup); + library->updateComboScene(); + library->updateBoxConn(); + params->isCurrentProject = true; + enableProjectActions(true, PROJECT_CLOSE | PROJECT_SAVE | PROJECT_SAVEAS | PROJECT_LIB, OP_RAZ); + enableAnalysisActions(true, ANALYSIS_ANALYZE | ANALYSIS_GENERATE, OP_RAZ); } else { QMessageBox msgBox; - msgBox.setText("Cannot open the project."); - msgBox.setInformativeText("Do you want to save your changes?"); + msgBox.setText("Cannot open the project."); msgBox.setStandardButtons(QMessageBox::Cancel); msgBox.setDefaultButton(QMessageBox::Cancel); - int ret = msgBox.exec(); + msgBox.exec(); } } } @@ -286,51 +339,88 @@ void MainWindow::slotLoadProject(){ void MainWindow::slotNewProject(){ - enableProjectActions(true, PROJECT_CLOSE | PROJECT_SAVE | PROJECT_SAVEAS | PROJECT_LIB, OP_RAZ); - GroupWidget* topGroup = dispatcher->createTopScene(); - addTopGroup(topGroup); - + NewProjectDialog* dialog = new NewProjectDialog(params); + int ret = dialog->exec(); + + if (ret == 1) { + enableProjectActions(true, PROJECT_CLOSE | PROJECT_SAVE | PROJECT_SAVEAS | PROJECT_LIB, OP_RAZ); + enableAnalysisActions(true, ANALYSIS_ANALYZE | ANALYSIS_GENERATE, OP_RAZ); + GroupWidget* topGroup = dispatcher->createTopScene(Dispatcher::Design); + addTopGroup(topGroup); + library->updateComboScene(); + library->updateBoxConn(); + library->show(); + params->isCurrentProject = true; + } } -void MainWindow::slotCloseProject(){ +bool MainWindow::slotCloseProject(){ - // removing the GroupWidget from stack - QWidget *widget = stackedWidget->widget(1); - stackedWidget->removeWidget(widget); - stackedWidget->setCurrentIndex(0); + bool doClose = false; - dispatcher->closeCurrentProject(); + if(params->isCurrentProject) { + if (params->unsaveModif) { + QMessageBox msgBox; + msgBox.setText("The project has been modified."); + msgBox.setInformativeText("Do you want to save your changes?"); + msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel); + msgBox.setDefaultButton(QMessageBox::Save); + int ret = msgBox.exec(); - isCurrentProject = false; - params->unsaveModif = false; - absoluteFilename = QString(); + switch(ret) { + case QMessageBox::Save : + slotSaveProject(); + doClose = true; + break; + case QMessageBox::Discard : + doClose = true; + break; + } + } + else { + doClose = true; + } + if (doClose) { + // removing the GroupWidget from stack + QWidget *widget = stackedWidget->widget(1); + stackedWidget->removeWidget(widget); + stackedWidget->setCurrentIndex(0); - initialize(); + dispatcher->closeCurrentProject(); + + params->isCurrentProject = false; + params->unsaveModif = false; + params->projectFile = QString(); + + initialize(); + } + } + return doClose; } -void MainWindow::slotNewBlockWidget() { - new BlockWidget(); +void MainWindow::slotVHDLToXml() { + new VHDLConverter(); } void MainWindow::slotSaveProject(){ - if(absoluteFilename != QString()){ - save(absoluteFilename); + if(params->projectFile != QString()){ + save(params->projectFile); } else { slotSaveAsProject(); } } void MainWindow::slotSaveAsProject(){ - if(isCurrentProject){ + if(params->isCurrentProject){ QFileDialog dial(0, "Select a file", "save/"); dial.setDefaultSuffix(".xml"); dial.setAcceptMode(QFileDialog::AcceptSave); if(dial.exec() == QFileDialog::AcceptSave){ - absoluteFilename = dial.selectedFiles().at(0); - if(absoluteFilename != QString()) - save(absoluteFilename); + params->projectFile = dial.selectedFiles().at(0); + if(params->projectFile != QString()) + save(params->projectFile); } } } @@ -340,8 +430,35 @@ void MainWindow::slotOpenBlockLibrary() { } -void MainWindow::slotGraphValidation() { - params->parametersValidation(); +void MainWindow::slotGraphAnalysis() { + bool compat = true; + try { + params->getGraph()->computeOutputPatterns(1); + } + catch(Exception e) { + cerr << qPrintable(e.getMessage()) << endl; + compat = false; + if (e.getType() == IP_AP_NOTCOMPAT) { + FunctionalBlock* toBlock = (FunctionalBlock*)(e.getSource()); + QString msg = tr(""); + msg.append(toBlock->getName()); + msg += " is not compatible with its input pattern.\nDo you want to launch automatic modification process to ensure the compatibility ?"; + int ret = QMessageBox::question(this,tr("Building references library"),msg, QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Ok); + if (ret == QMessageBox::Ok) { + dispatcher->findGraphModifications(Dispatcher::Design, toBlock); + } + } + } +} + +void MainWindow::slotGenerateVHDL() { + + try { + dispatcher->generateVHDL(Dispatcher::Design); + } + catch(Exception e) { + cerr << qPrintable(e.getMessage()) << endl; + } } void MainWindow::addTopGroup(GroupWidget *_topGroup) { @@ -356,35 +473,22 @@ void MainWindow::removeTopGroup() { stackedWidget->setCurrentIndex(0); } -void MainWindow::closeEvent(QCloseEvent *event){ - if(isCurrentProject){ - QMessageBox msgBox; - msgBox.setText("The project has been modified."); - msgBox.setInformativeText("Do you want to save your changes?"); - msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel); - msgBox.setDefaultButton(QMessageBox::Save); - - int ret = msgBox.exec(); - - switch(ret) { - case QMessageBox::Save : - slotSaveProject(); - slotCloseProject(); - break; - case QMessageBox::Discard : - slotCloseProject(); - break; - } +void MainWindow::closeEvent(QCloseEvent *event) { + + if (params->isCurrentProject) { + slotCloseProject(); event->ignore(); - } else { - exit(0); } + else { + library->deleteLater(); + } + } void MainWindow::mousePressEvent(QMouseEvent *e) { if (dispatcher->getCurrentGroup() != NULL) { - dispatcher->setCurrentGroupWidget(dispatcher->getCurrentGroup()); + dispatcher->setCurrentGroupWidget(Dispatcher::Design, dispatcher->getCurrentGroup()); } QMainWindow::mousePressEvent(e); }