Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into oms
Browse files Browse the repository at this point in the history
  • Loading branch information
Adeel Asghar committed Jun 13, 2018
2 parents 11f71a3 + 50faa87 commit ee2d623
Show file tree
Hide file tree
Showing 9 changed files with 229 additions and 6 deletions.
107 changes: 107 additions & 0 deletions OMEdit/OMEditGUI/MainWindow.cpp
Expand Up @@ -879,6 +879,39 @@ void MainWindow::exportModelFMU(LibraryTreeItem *pLibraryTreeItem)
mpStatusBar->clearMessage();
}

/*!
* \brief MainWindow::exportEncryptedPackage
* Exports the package as encrypted package
* \param pLibraryTreeItem
*/
void MainWindow::exportEncryptedPackage(LibraryTreeItem *pLibraryTreeItem)
{
/* if Modelica text is changed manually by user then validate it before saving. */
if (pLibraryTreeItem->getModelWidget()) {
if (!pLibraryTreeItem->getModelWidget()->validateText(&pLibraryTreeItem)) {
return;
}
}
// set the status message.
mpStatusBar->showMessage(tr("Exporting the package as encrypted package"));
// show the progress bar
mpProgressBar->setRange(0, 0);
showProgressBar();
// build encrypted package
if (mpOMCProxy->buildEncryptedPackage(pLibraryTreeItem->getNameStructure())) {
MessagesWidget::instance()->addGUIMessage(MessageItem(MessageItem::Modelica, "", false, 0, 0, 0, 0,
GUIMessages::getMessage(GUIMessages::ENCRYPTED_PACKAGE_GENERATED)
.arg(QString("%1/%2.mol")
.arg(MainWindow::instance()->getOMCProxy()->changeDirectory())
.arg(pLibraryTreeItem->getNameStructure())),
Helper::scriptingKind, Helper::notificationLevel));
}
// hide progress bar
hideProgressBar();
// clear the status bar message
mpStatusBar->clearMessage();
}

void MainWindow::exportModelXML(LibraryTreeItem *pLibraryTreeItem)
{
/* if Modelica text is changed manually by user then validate it before saving. */
Expand Down Expand Up @@ -1336,6 +1369,55 @@ void MainWindow::loadModelicaLibrary()
mpLibraryWidget->openFile(libraryPath, Helper::utf8, true, true);
}

void MainWindow::loadEncryptedLibrary()
{
QStringList fileNames;
fileNames = StringHandler::getOpenFileNames(this, QString(Helper::applicationName).append(" - ").append(Helper::chooseFiles),
NULL, Helper::omEncryptedFileTypes, NULL);
if (fileNames.isEmpty()) {
return;
}
int progressValue = 0;
mpProgressBar->setRange(0, fileNames.size());
showProgressBar();
foreach (QString file, fileNames) {
file = file.replace("\\", "/");
mpStatusBar->showMessage(QString(Helper::loading).append(": ").append(file));
mpProgressBar->setValue(++progressValue);
// if file doesn't exists
if (!QFile::exists(file)) {
QMessageBox *pMessageBox = new QMessageBox(this);
pMessageBox->setWindowTitle(QString(Helper::applicationName).append(" - ").append(Helper::error));
pMessageBox->setIcon(QMessageBox::Critical);
pMessageBox->setAttribute(Qt::WA_DeleteOnClose);
pMessageBox->setText(QString(GUIMessages::getMessage(GUIMessages::UNABLE_TO_LOAD_FILE).arg(file)));
pMessageBox->setInformativeText(QString(GUIMessages::getMessage(GUIMessages::FILE_NOT_FOUND).arg(file)));
pMessageBox->setStandardButtons(QMessageBox::Ok);
pMessageBox->exec();
} else {
QFileInfo fileInfo(file);
QString library = fileInfo.completeBaseName();
LibraryTreeModel *pLibraryTreeModel = mpLibraryWidget->getLibraryTreeModel();
if (pLibraryTreeModel->findLibraryTreeItemOneLevel(library)) {
QMessageBox *pMessageBox = new QMessageBox(this);
pMessageBox->setWindowTitle(QString("%1 - %2").arg(Helper::applicationName, Helper::information));
pMessageBox->setIcon(QMessageBox::Information);
pMessageBox->setAttribute(Qt::WA_DeleteOnClose);
pMessageBox->setText(QString(GUIMessages::getMessage(GUIMessages::UNABLE_TO_LOAD_FILE).arg(library)));
pMessageBox->setInformativeText(QString(GUIMessages::getMessage(GUIMessages::REDEFINING_EXISTING_CLASSES))
.arg(library).append("\n")
.append(GUIMessages::getMessage(GUIMessages::DELETE_AND_LOAD).arg(library)));
pMessageBox->setStandardButtons(QMessageBox::Ok);
pMessageBox->exec();
} else { /* if library is not loaded then load it. */
mpLibraryWidget->openFile(file, Helper::utf8, false);
}
}
}
mpStatusBar->clearMessage();
hideProgressBar();
}

void MainWindow::showOpenResultFileDialog()
{
QStringList fileNames = StringHandler::getOpenFileNames(this, QString(Helper::applicationName).append(" - ").append(Helper::chooseFiles),
Expand Down Expand Up @@ -2011,6 +2093,21 @@ void MainWindow::exportModelFMU()
}
}

/*!
* \brief MainWindow::exportEncryptedPackage
* Slot activated when mpExportEncryptedPackageAction triggered SIGNAL is raised.
*/
void MainWindow::exportEncryptedPackage()
{
ModelWidget *pModelWidget = mpModelWidgetContainer->getCurrentModelWidget();
if (pModelWidget) {
exportEncryptedPackage(pModelWidget->getLibraryTreeItem());
} else {
MessagesWidget::instance()->addGUIMessage(MessageItem(MessageItem::Modelica, "", false, 0, 0, 0, 0, GUIMessages::getMessage(GUIMessages::NO_MODELICA_CLASS_OPEN)
.arg(tr("making encrypted package")), Helper::scriptingKind, Helper::notificationLevel));
}
}

//! Exports the current model to XML
void MainWindow::exportModelXML()
{
Expand Down Expand Up @@ -2915,6 +3012,10 @@ void MainWindow::createActions()
mpLoadModelicaLibraryAction = new QAction(tr("Load Library"), this);
mpLoadModelicaLibraryAction->setStatusTip(tr("Loads the Modelica library"));
connect(mpLoadModelicaLibraryAction, SIGNAL(triggered()), SLOT(loadModelicaLibrary()));
// load encrypted library action
mpLoadEncryptedLibraryAction = new QAction(tr("Load Encrypted Library"), this);
mpLoadEncryptedLibraryAction->setStatusTip(tr("Loads the encrypted Modelica library"));
connect(mpLoadEncryptedLibraryAction, SIGNAL(triggered()), SLOT(loadEncryptedLibrary()));
// open result file action
mpOpenResultFileAction = new QAction(tr("Open Result File(s)"), this);
mpOpenResultFileAction->setShortcut(QKeySequence("Ctrl+shift+o"));
Expand Down Expand Up @@ -3122,6 +3223,10 @@ void MainWindow::createActions()
mpImportFMUModelDescriptionAction->setStatusTip(Helper::importFMUTip);
connect(mpImportFMUModelDescriptionAction, SIGNAL(triggered()), SLOT(importFMUModelDescription()));
// XML Menu
// export encrypted package action
mpExportEncryptedPackageAction = new QAction(Helper::exportEncryptedPackage, this);
mpExportEncryptedPackageAction->setStatusTip(Helper::exportEncryptedPackageTip);
connect(mpExportEncryptedPackageAction, SIGNAL(triggered()), SLOT(exportEncryptedPackage()));
// export XML action
mpExportXMLAction = new QAction(QIcon(":/Resources/icons/export-xml.svg"), Helper::exportXML, this);
mpExportXMLAction->setStatusTip(Helper::exportXMLTip);
Expand Down Expand Up @@ -3398,6 +3503,7 @@ void MainWindow::createMenus()
pFileMenu->addAction(mpOpenModelicaFileAction);
pFileMenu->addAction(mpOpenModelicaFileWithEncodingAction);
pFileMenu->addAction(mpLoadModelicaLibraryAction);
pFileMenu->addAction(mpLoadEncryptedLibraryAction);
pFileMenu->addAction(mpOpenResultFileAction);
pFileMenu->addAction(mpOpenTransformationFileAction);
pFileMenu->addSeparator();
Expand Down Expand Up @@ -3546,6 +3652,7 @@ void MainWindow::createMenus()
QMenu *pExportMenu = new QMenu(menuBar());
pExportMenu->setTitle(tr("E&xport"));
// add actions to Export menu
pExportMenu->addAction(mpExportEncryptedPackageAction);
pExportMenu->addAction(mpExportXMLAction);
pExportMenu->addAction(mpExportFigaroAction);
// add Export menu to menu bar
Expand Down
6 changes: 6 additions & 0 deletions OMEdit/OMEditGUI/MainWindow.h
Expand Up @@ -163,6 +163,7 @@ class MainWindow : public QMainWindow
QAction* getCheckModelAction() {return mpCheckModelAction;}
QAction* getCheckAllModelsAction() {return mpCheckAllModelsAction;}
QAction* getExportFMUAction() {return mpExportFMUAction;}
QAction* getExportEncryptedPackageAction() {return mpExportEncryptedPackageAction;}
QAction* getExportXMLAction() {return mpExportXMLAction;}
QAction* getExportFigaroAction() {return mpExportFigaroAction;}
QAction* getLineShapeAction() {return mpLineShapeAction;}
Expand Down Expand Up @@ -212,6 +213,7 @@ class MainWindow : public QMainWindow
void checkModel(LibraryTreeItem *pLibraryTreeItem);
void checkAllModels(LibraryTreeItem *pLibraryTreeItem);
void exportModelFMU(LibraryTreeItem *pLibraryTreeItem);
void exportEncryptedPackage(LibraryTreeItem *pLibraryTreeItem);
void exportModelXML(LibraryTreeItem *pLibraryTreeItem);
void exportModelFigaro(LibraryTreeItem *pLibraryTreeItem);
void fetchInterfaceData(LibraryTreeItem *pLibraryTreeItem, QString singleModel=QString());
Expand Down Expand Up @@ -278,6 +280,7 @@ class MainWindow : public QMainWindow
QAction *mpOpenModelicaFileAction;
QAction *mpOpenModelicaFileWithEncodingAction;
QAction *mpLoadModelicaLibraryAction;
QAction *mpLoadEncryptedLibraryAction;
QAction *mpOpenResultFileAction;
QAction *mpOpenTransformationFileAction;
// CompositeModel File Actions
Expand Down Expand Up @@ -331,6 +334,7 @@ class MainWindow : public QMainWindow
QAction *mpImportFMUAction;
QAction *mpImportFMUModelDescriptionAction;
// Export Menu
QAction *mpExportEncryptedPackageAction;
QAction *mpExportXMLAction;
QAction *mpExportFigaroAction;
// Debug Menu
Expand Down Expand Up @@ -428,6 +432,7 @@ public slots:
void openModelicaFile();
void showOpenModelicaFileDialog();
void loadModelicaLibrary();
void loadEncryptedLibrary();
void showOpenResultFileDialog();
void showOpenTransformationFileDialog();
void createNewCompositeModelFile();
Expand Down Expand Up @@ -466,6 +471,7 @@ public slots:
void exportModelFMU();
void importModelFMU();
void importFMUModelDescription();
void exportEncryptedPackage();
void exportModelXML();
void exportModelFigaro();
void showOpenModelicaCommandPrompt();
Expand Down
43 changes: 43 additions & 0 deletions OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.cpp
Expand Up @@ -3005,6 +3005,10 @@ void LibraryTreeView::createActions()
mpExportFMUAction = new QAction(QIcon(":/Resources/icons/export-fmu.svg"), Helper::exportFMU, this);
mpExportFMUAction->setStatusTip(Helper::exportFMUTip);
connect(mpExportFMUAction, SIGNAL(triggered()), SLOT(exportModelFMU()));
// Export encrypted package Action
mpExportEncryptedPackageAction = new QAction(Helper::exportEncryptedPackage, this);
mpExportEncryptedPackageAction->setStatusTip(Helper::exportEncryptedPackageTip);
connect(mpExportEncryptedPackageAction, SIGNAL(triggered()), SLOT(exportEncryptedPackage()));
// Export XML Action
mpExportXMLAction = new QAction(QIcon(":/Resources/icons/export-xml.svg"), Helper::exportXML, this);
mpExportXMLAction->setStatusTip(Helper::exportXMLTip);
Expand Down Expand Up @@ -3183,6 +3187,10 @@ void LibraryTreeView::showContextMenu(QPoint point)
}
menu.addSeparator();
menu.addAction(mpExportFMUAction);
if (pLibraryTreeItem->isTopLevel() && pLibraryTreeItem->getRestriction() == StringHandler::Package
&& pLibraryTreeItem->getSaveContentsType() == LibraryTreeItem::SaveFolderStructure) {
menu.addAction(mpExportEncryptedPackageAction);
}
menu.addAction(mpExportXMLAction);
menu.addAction(mpExportFigaroAction);
if (pLibraryTreeItem->isSimulationAllowed()) {
Expand Down Expand Up @@ -3655,6 +3663,14 @@ void LibraryTreeView::exportModelFMU()
}
}

void LibraryTreeView::exportEncryptedPackage()
{
LibraryTreeItem *pLibraryTreeItem = getSelectedLibraryTreeItem();
if (pLibraryTreeItem) {
MainWindow::instance()->exportEncryptedPackage(pLibraryTreeItem);
}
}

/*!
* \brief LibraryTreeView::exportModelXML
* Exports the selected LibraryTreeItem to XML.
Expand Down Expand Up @@ -3933,6 +3949,8 @@ void LibraryWidget::openFile(QString fileName, QString encoding, bool showProgre
}
if (fileInfo.suffix().compare("mo") == 0 && !loadExternalModel) {
openModelicaFile(fileName, encoding, showProgress);
} else if (fileInfo.suffix().compare("mol") == 0 && !loadExternalModel) {
openEncrytpedModelicaLibrary(fileName, encoding, showProgress);
} else if (fileInfo.isDir()) {
openDirectory(fileInfo, showProgress);
} else {
Expand Down Expand Up @@ -4028,6 +4046,31 @@ void LibraryWidget::openModelicaFile(QString fileName, QString encoding, bool sh
}
}

/*!
* \brief LibraryWidget::openEncrytpedModelicaLibrary
* Opens the encrypted library package.
* \param fileName
* \param encoding
* \param showProgress
*/
void LibraryWidget::openEncrytpedModelicaLibrary(QString fileName, QString encoding, bool showProgress)
{
if (showProgress) {
MainWindow::instance()->getStatusBar()->showMessage(QString(Helper::loading).append(": ").append(fileName));
}
// load the encrypted package in OMC
if (MainWindow::instance()->getOMCProxy()->loadEncryptedPackage(fileName, Utilities::tempDirectory())) {
MainWindow::instance()->addRecentFile(fileName, encoding);
mpLibraryTreeModel->loadDependentLibraries(MainWindow::instance()->getOMCProxy()->getClassNames());
if (showProgress) {
MainWindow::instance()->hideProgressBar();
}
}
if (showProgress) {
MainWindow::instance()->getStatusBar()->clearMessage();
}
}

/*!
* \brief LibraryWidget::openCompositeModelOrTextFile
* Opens a CompositeModel/Text file and creates a LibraryTreeItem for it.
Expand Down
3 changes: 3 additions & 0 deletions OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.h
Expand Up @@ -366,6 +366,7 @@ class LibraryTreeView : public QTreeView
QAction *mpRenameAction;
QAction *mpDeleteAction;
QAction *mpExportFMUAction;
QAction *mpExportEncryptedPackageAction;
QAction *mpExportXMLAction;
QAction *mpExportFigaroAction;
QAction *mpUpdateBindingsAction;
Expand Down Expand Up @@ -414,6 +415,7 @@ public slots:
void renameLibraryTreeItem();
void deleteTextFile();
void exportModelFMU();
void exportEncryptedPackage();
void exportModelXML();
void exportModelFigaro();
void updateBindings();
Expand Down Expand Up @@ -441,6 +443,7 @@ class LibraryWidget : public QWidget
void openFile(QString fileName, QString encoding = Helper::utf8, bool showProgress = true, bool checkFileExists = false,
bool loadExternalModel = false);
void openModelicaFile(QString fileName, QString encoding = Helper::utf8, bool showProgress = true);
void openEncrytpedModelicaLibrary(QString fileName, QString encoding = Helper::utf8, bool showProgress = true);
void openCompositeModelOrTextFile(QFileInfo fileInfo, bool showProgress = true);
void openDirectory(QFileInfo fileInfo, bool showProgress = true);
void openOMSModelFile(QFileInfo fileInfo, bool showProgress = true);
Expand Down

0 comments on commit ee2d623

Please sign in to comment.