From: stephane Domas Date: Mon, 5 Mar 2018 09:54:36 +0000 (+0100) Subject: added new project dialog X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/blast.git/commitdiff_plain/77e28a24d444098399304f0175b1aba43c83017f added new project dialog --- diff --git a/AbstractBlock.cpp b/AbstractBlock.cpp index cdde69f..90031d9 100644 --- a/AbstractBlock.cpp +++ b/AbstractBlock.cpp @@ -3,6 +3,7 @@ #include #include "AbstractInterface.h" #include "BlockParameter.h" +#include "Parameters.h" AbstractBlock::AbstractBlock() { name = ""; @@ -10,7 +11,7 @@ AbstractBlock::AbstractBlock() { } AbstractBlock::AbstractBlock(const QString& _name) { - name = normalizeName(_name); + name = Parameters::normalizeName(_name); parent = NULL; } @@ -25,7 +26,7 @@ AbstractBlock::~AbstractBlock() { } void AbstractBlock::setName(const QString& str) { - name = normalizeName(str); + name = Parameters::normalizeName(str); } void AbstractBlock::setParent(AbstractBlock* _parent) { @@ -235,11 +236,6 @@ QList AbstractBlock::getWishboneParameters() { return lst; } -QString AbstractBlock::normalizeName(const QString &name) { - QString s = name; - s.replace(QRegularExpression("[^a-zA-Z0-9_]"),"_"); - s.replace(QRegularExpression("[_]+"),"_"); - return s; -} + diff --git a/AbstractBlock.h b/AbstractBlock.h index 042a598..ebb1560 100644 --- a/AbstractBlock.h +++ b/AbstractBlock.h @@ -56,7 +56,6 @@ public: bool isWBConfigurable(); // others - static QString normalizeName(const QString& name); virtual void parametersValidation(QList* checkedBlocks, QList* blocksToConfigure) = 0; // ugly but usefull diff --git a/AbstractInterface.cpp b/AbstractInterface.cpp index 1d1e41d..a32f78e 100644 --- a/AbstractInterface.cpp +++ b/AbstractInterface.cpp @@ -1,6 +1,7 @@ #include "AbstractInterface.h" #include "BlockParameterPort.h" #include "AbstractBlock.h" +#include "Parameters.h" AbstractInterface::AbstractInterface(AbstractBlock* _owner) { @@ -18,7 +19,7 @@ AbstractInterface::AbstractInterface(AbstractBlock* _owner) { AbstractInterface::AbstractInterface(AbstractBlock* _owner, const QString& _name, int _direction, int _purpose, const QString& _type, const QString& _width, int _endianess) { owner = _owner; - name = AbstractBlock::normalizeName(_name); + name = Parameters::normalizeName(_name); width = _width; direction = _direction; purpose = _purpose; @@ -29,7 +30,7 @@ AbstractInterface::AbstractInterface(AbstractBlock* _owner, const QString& _name AbstractInterface::AbstractInterface(AbstractInterface* other) { owner = NULL; - name = AbstractBlock::normalizeName(other->name); + name = Parameters::normalizeName(other->name); type = other->type; width = other->width; direction = other->direction; @@ -39,7 +40,7 @@ AbstractInterface::AbstractInterface(AbstractInterface* other) { } void AbstractInterface::setName(const QString& _name) { - name = AbstractBlock::normalizeName(_name); + name = Parameters::normalizeName(_name); } AbstractInterface::~AbstractInterface() { diff --git a/CustomDialog.cpp b/CustomDialog.cpp new file mode 100644 index 0000000..5a91cf4 --- /dev/null +++ b/CustomDialog.cpp @@ -0,0 +1,53 @@ +/*-==============================================================- + +file : CustomDialog.cpp + +creation date : 08/02/2012 + +author : S. Domas (sdomas@iut-bm.univ-fcomte.fr) + +description : + +supp. infos : saved in UTF-8 [éè] + +-==============================================================-*/ +#include "CustomDialog.h" + +CustomDialog::CustomDialog(const QString &dialogTitle, const QString &boxTitle, QWidget *_parent) : QDialog(_parent) { + + setWindowTitle(dialogTitle); + box = new QGroupBox(boxTitle); + + okButton = new QPushButton(tr("OK")); + cancelButton = new QPushButton(tr("Cancel")); + + layBottom = new QHBoxLayout; + layBottom->addStretch(); + layBottom->addWidget(okButton); + layBottom->addWidget(cancelButton); + + connect(okButton,SIGNAL(clicked()),this, SLOT(checkBeforeAccept())); + connect(cancelButton,SIGNAL(clicked()),this,SLOT(reject())); +} + +void CustomDialog::checkBeforeAccept() { + accept(); +} + +bool CustomDialog::confirmAccept() { + + int ret = QMessageBox::question(NULL,tr("Confirmation"),tr("Are you sure ?"),QMessageBox::Ok | QMessageBox::Cancel,QMessageBox::Ok); + if (ret == QMessageBox::Ok) return true; + return false; +} + +void CustomDialog::setContent(QVBoxLayout *boxLayout) { + box->setLayout(boxLayout); + + QVBoxLayout *layAll = new QVBoxLayout; + + layAll->addWidget(box); + layAll->addLayout(layBottom); + + setLayout(layAll); +} diff --git a/CustomDialog.h b/CustomDialog.h new file mode 100644 index 0000000..6494ae8 --- /dev/null +++ b/CustomDialog.h @@ -0,0 +1,51 @@ +/*-==============================================================- + +file : CustomDialog.hpp + +creation date : 08/02/2012 + +author : S. Domas (sdomas@iut-bm.univ-fcomte.fr) + +description : + +supp. infos : saved in UTF-8 [éè] + +-==============================================================-*/ +#ifndef __CUSTOMDIALOG_H__ +#define __CUSTOMDIALOG_H__ + +#include +#include + +#include +#include +#include + +using namespace std; +using namespace Qt; + +class CustomDialog : public QDialog { + + Q_OBJECT + +public: + + CustomDialog(const QString &dialogTitle, const QString &boxTitle, QWidget *_parent = NULL); + +protected: + + QGroupBox *box; + QPushButton *okButton; + QPushButton *cancelButton; + + void setContent(QVBoxLayout *boxLayout); + +private: + QHBoxLayout *layBottom; + +protected slots: + virtual void checkBeforeAccept(); + virtual bool confirmAccept(); + +}; +#endif //__CUSTOMDIALOG_H__ diff --git a/Graph.cpp b/Graph.cpp index bd1eb70..5b491b0 100644 --- a/Graph.cpp +++ b/Graph.cpp @@ -192,3 +192,12 @@ void Graph::computeOutputPatterns(int nbExec) throw(Exception) { throw(e); } } + +void Graph::generateVHDL(const QString &path) throw(Exception) { + try { + topGroup->generateVHDL(path); + } + catch(Exception e) { + throw(e); + } +} diff --git a/Graph.h b/Graph.h index b9c598a..e7ff3e2 100644 --- a/Graph.h +++ b/Graph.h @@ -55,7 +55,8 @@ public: void resetPatternComputed(); void computeOutputPatterns(int nbExec) throw(Exception); - + void generateVHDL(const QString& path) throw(Exception); + private: GroupBlock* topGroup; QList groups; //! usefull to avoid recursive methods to find a particular group. diff --git a/GroupBlock.cpp b/GroupBlock.cpp index 6950b30..0ba203d 100644 --- a/GroupBlock.cpp +++ b/GroupBlock.cpp @@ -5,6 +5,7 @@ #include "GroupInterface.h" #include "string.h" #include +#include "Parameters.h" int GroupBlock::counter = 1; @@ -268,7 +269,7 @@ void GroupBlock::generateVHDL(const QString& path) throw(Exception) { QString coreFile = ""; coreFile = path; - coreFile.append(normalizeName(name)); + coreFile.append(Parameters::normalizeName(name)); coreFile.append(".vhd"); QFile vhdlCore(coreFile); diff --git a/MainWindow.cpp b/MainWindow.cpp index 79bc6f9..683ba3d 100644 --- a/MainWindow.cpp +++ b/MainWindow.cpp @@ -11,6 +11,7 @@ #include #include #include +#include "NewProjectDialog.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { @@ -223,6 +224,12 @@ void MainWindow::enableAnalysisActions(bool enbMenu, quint16 mask, quint8 op) { else { graphAnalysis->setEnabled(false); } + if (analysisMenuEnb & ANALYSIS_GENERATE) { + generateVHDL->setEnabled(true); + } + else { + generateVHDL->setEnabled(false); + } } void MainWindow::createMenus(){ @@ -241,6 +248,7 @@ void MainWindow::createMenus(){ projectMenu->addAction(openLibrary); analysisMenu->addAction(graphAnalysis); + analysisMenu->addAction(generateVHDL); toolsMenu->addAction(vhdlToXmlAct); @@ -284,23 +292,28 @@ void MainWindow::createActions() { vhdlToXmlAct->setStatusTip(tr("Create a new XML generator")); connect(vhdlToXmlAct, SIGNAL(triggered()), this, SLOT(slotVHDLToXml())); - graphAnalysis = new QAction(tr("&graph validation"), this); + 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(); @@ -322,13 +335,18 @@ void MainWindow::slotLoadProject(){ void MainWindow::slotNewProject(){ - enableProjectActions(true, PROJECT_CLOSE | PROJECT_SAVE | PROJECT_SAVEAS | PROJECT_LIB, OP_RAZ); - enableAnalysisActions(true, ANALYSIS_ANALYZE, OP_RAZ); - GroupWidget* topGroup = dispatcher->createTopScene(); - addTopGroup(topGroup); - library->updateComboScene(); - library->show(); - params->isCurrentProject = true; + 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(); + addTopGroup(topGroup); + library->updateComboScene(); + library->show(); + params->isCurrentProject = true; + } } bool MainWindow::slotCloseProject(){ @@ -368,7 +386,7 @@ bool MainWindow::slotCloseProject(){ params->isCurrentProject = false; params->unsaveModif = false; - absoluteFilename = QString(); + params->projectFile = QString(); initialize(); } @@ -382,8 +400,8 @@ void MainWindow::slotVHDLToXml() { } void MainWindow::slotSaveProject(){ - if(absoluteFilename != QString()){ - save(absoluteFilename); + if(params->projectFile != QString()){ + save(params->projectFile); } else { slotSaveAsProject(); } @@ -395,9 +413,9 @@ void MainWindow::slotSaveAsProject(){ 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); } } } @@ -428,6 +446,15 @@ void MainWindow::slotGraphAnalysis() { } } +void MainWindow::slotGenerateVHDL() { + try { + params->getGraph()->generateVHDL(params->projectPath); + } + catch(Exception e) { + cerr << qPrintable(e.getMessage()) << endl; + } +} + void MainWindow::addTopGroup(GroupWidget *_topGroup) { topGroup = _topGroup; stackedWidget->addWidget(topGroup); diff --git a/MainWindow.h b/MainWindow.h index 9664a96..96fab67 100644 --- a/MainWindow.h +++ b/MainWindow.h @@ -38,6 +38,7 @@ class Graph; #define PROJECT_LIB (quint16)32 #define ANALYSIS_ANALYZE (quint16)1 +#define ANALYSIS_GENERATE (quint16)2 #define OP_ADD (quint8)0 #define OP_REM (quint8)1 @@ -107,6 +108,7 @@ private: // actions for graph analysis QAction *graphAnalysis; + QAction *generateVHDL; // actions for tools QAction *vhdlToXmlAct; @@ -129,6 +131,7 @@ private slots: void slotOpenBlockLibrary(); void slotGraphAnalysis(); + void slotGenerateVHDL(); void slotVHDLToXml(); diff --git a/NewProjectDialog.cpp b/NewProjectDialog.cpp new file mode 100644 index 0000000..033b686 --- /dev/null +++ b/NewProjectDialog.cpp @@ -0,0 +1,79 @@ +#include "NewProjectDialog.h" + +NewProjectDialog::NewProjectDialog(Parameters *_params, QWidget *parent) : CustomDialog(tr("Create a new project"),tr("Location"), parent) { + + params = _params; + + QHBoxLayout *layNameProj = new QHBoxLayout; + QLabel *nameProjLab = new QLabel(tr("Name :")); + nameProjEdit = new QLineEdit(); + nameProjEdit->setMaxLength(100); + nameProjEdit->setText(""); + + layNameProj->addWidget(nameProjLab); + layNameProj->addWidget(nameProjEdit); + + QHBoxLayout *layDirProj = new QHBoxLayout; + QLabel *dirProjLab = new QLabel(tr("Path :")); + dirProjEdit = new QLineEdit(""); + dirProjEdit->setMaxLength(500); + dirProjButton = new QPushButton(QIcon(":/images/filefind.png"),""); + dirProjButton->setFixedWidth(30); + pathOk = false; + + layDirProj->addWidget(dirProjLab); + layDirProj->addWidget(dirProjEdit); + layDirProj->addWidget(dirProjButton); + + + QVBoxLayout *layAll = new QVBoxLayout; + layAll->addLayout(layNameProj); + layAll->addLayout(layDirProj); + + setContent(layAll); + + connect(dirProjButton,SIGNAL(clicked()),this,SLOT(chooseProjectPath())); + connect(nameProjEdit,SIGNAL(textChanged(QString)),this,SLOT(checkProjectName(QString))); + connect(dirProjEdit,SIGNAL(textChanged(QString)),this,SLOT(checkProjectPath(QString))); + +} + +void NewProjectDialog::checkBeforeAccept() { + + if ((!nameProjEdit->text().isEmpty()) && (pathOk)) { + //cout << "all ok" << endl; + params->projectPath = dirProjEdit->text(); + params->projectFile = params->projectPath + "/" + params->projectName + ".xml"; + + accept(); + } + else { + int ret = QMessageBox::warning(this,"Cannot create the project","Invalid project path"); + + } +} + +void NewProjectDialog::chooseProjectPath() { + + QString where; + where = QDir::currentPath(); + QString dir = QFileDialog::getExistingDirectory(this, tr("Open Directory"),where); + dirProjEdit->setText(dir); +} + +void NewProjectDialog::checkProjectPath(QString name) { + QDir dir(name); + if (dir.exists()) { + pathOk = true; + } + else { + pathOk = false; + } +} + +void NewProjectDialog::checkProjectName(QString name) { + params->projectName = Parameters::normalizeName(name); + if (name != params->projectName) { + nameProjEdit->setText(params->projectName); + } +} diff --git a/NewProjectDialog.h b/NewProjectDialog.h new file mode 100644 index 0000000..cad5c06 --- /dev/null +++ b/NewProjectDialog.h @@ -0,0 +1,42 @@ +#ifndef __NEWPROJECTDIALOG_H__ +#define __NEWPROJECTDIALOG_H__ + +#include +#include + +#include +#include + +#include "CustomDialog.h" +#include "Parameters.h" + +using namespace std; +using namespace Qt; + +class NewProjectDialog : public CustomDialog { + + Q_OBJECT + +public: + + NewProjectDialog(Parameters *_params, QWidget *parent = NULL); + +private: + + Parameters *params; + + QLineEdit *nameProjEdit; + QLineEdit *dirProjEdit; + QPushButton *dirProjButton; + bool pathOk; + +private slots: + void checkBeforeAccept(); + void chooseProjectPath(); + void checkProjectPath(QString name); + void checkProjectName(QString name); + + +}; + +#endif //__NEWPROJECTDIALOG_H__ diff --git a/Parameters.cpp b/Parameters.cpp index c60a927..46437c3 100644 --- a/Parameters.cpp +++ b/Parameters.cpp @@ -46,10 +46,12 @@ Parameters::Parameters() { unsaveModif = false; isRstClkShown = false; - - projectPath = QDir::currentPath(); validityExtension = "_enb"; + + projectPath = ""; + projectName = ""; + projectFile = ""; } Parameters::~Parameters() { @@ -1222,3 +1224,10 @@ InterfaceItem* Parameters::searchInterfaceItemById(int id, GroupScene* scene) { } return NULL; } + +QString Parameters::normalizeName(const QString &name) { + QString s = name; + s.replace(QRegularExpression("[^a-zA-Z0-9_]"),"_"); + s.replace(QRegularExpression("[_]+"),"_"); + return s; +} diff --git a/Parameters.h b/Parameters.h index ccd24ff..f03ca0a 100644 --- a/Parameters.h +++ b/Parameters.h @@ -78,6 +78,11 @@ public : inline void setCursorState(CursorState state) { cursorState = state; } inline void setDispatcher(Dispatcher* _dispatcher) { dispatcher = _dispatcher;} + // testers + + // others + static QString normalizeName(const QString& name); + /*************************************************** attributes that are general to the application ***************************************************/ @@ -125,6 +130,9 @@ public : bool unsaveModif; bool isRstClkShown; QMap blockToItem; // allow to retrieve a box item from a functionnal block + QString projectPath; + QString projectName; + QString projectFile; // equals to projectPath/projectName.xml Graph* createGraph(); void destroyGraph(); @@ -165,7 +173,7 @@ public : void save(QString confFile); - QString projectPath; + private: Graph* graph; // the graph model of blocks diff --git a/blast.creator.user b/blast.creator.user index 76fb271..2d89560 100755 --- a/blast.creator.user +++ b/blast.creator.user @@ -1,10 +1,10 @@ - + EnvironmentId - {3701e197-5b6c-48ea-9e98-a6cf6de18672} + {94112477-caab-4897-8f75-5f412f2c883a} ProjectExplorer.Project.ActiveTarget @@ -19,7 +19,7 @@ Cpp - qt2 + CppGlobal @@ -31,7 +31,7 @@ 2 UTF-8 false - 2 + 4 false 80 true @@ -43,12 +43,12 @@ true true 0 - 4 - false + 8 + true 1 true true - false + true false @@ -61,7 +61,7 @@ Desktop Desktop - {ed04208c-8774-456b-99b9-4a02094ca7a4} + {c934e180-ebc6-41ed-be82-502cc94f41f6} 0 0 0 @@ -128,7 +128,7 @@ false false - 0 + 1000 true @@ -169,9 +169,8 @@ - false %{buildDir} - Exécutable personnalisé + Custom Executable ProjectExplorer.CustomExecutableRunConfiguration 3768 diff --git a/blast.files b/blast.files index 3c08c87..2ef2768 100755 --- a/blast.files +++ b/blast.files @@ -1,3 +1,7 @@ +CustomDialog.h +CustomDialog.cpp +NewProjectDialog.h +NewProjectDialog.cpp Exception.h Exception.cpp AbstractInputModifier.h diff --git a/lib/implementations/impls.bmf b/lib/implementations/impls.bmf index 2115cfc..1d8c695 100644 Binary files a/lib/implementations/impls.bmf and b/lib/implementations/impls.bmf differ diff --git a/object-files.txt b/object-files.txt index 9a90873..4df5ed7 100644 --- a/object-files.txt +++ b/object-files.txt @@ -48,4 +48,8 @@ COMMON-OBJ = $(BUILDPATH)/AbstractBlock.o \ $(BUILDPATH)/moc_ParametersWindow.o \ $(BUILDPATH)/InterfacePropertiesWindow.o \ $(BUILDPATH)/moc_InterfacePropertiesWindow.o \ + $(BUILDPATH)/CustomDialog.o \ + $(BUILDPATH)/moc_CustomDialog.o \ + $(BUILDPATH)/NewProjectDialog.o \ + $(BUILDPATH)/moc_NewProjectDialog.o \ $(BUILDPATH)/blast.o