Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 63 additions & 29 deletions src/openstudio_app/OpenStudioApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ OpenStudioApp::OpenStudioApp(int& argc, char** argv)
}

OpenStudioApp::~OpenStudioApp() {
disconnect();

if (m_measureManagerProcess) {
m_measureManagerProcess->disconnect();
m_measureManagerProcess->kill();
Expand Down Expand Up @@ -280,6 +282,8 @@ void OpenStudioApp::onMeasureManagerAndLibraryReady() {
boost::optional<openstudio::model::Model> model = versionTranslator.loadModel(toPath(fileName));
if (model) {

disconnectOSDocumentSignals();

m_osDocument = std::shared_ptr<OSDocument>(new OSDocument(componentLibrary(), resourcesPath(), model, fileName, false, startTabIndex()));

connectOSDocumentSignals();
Expand Down Expand Up @@ -350,6 +354,8 @@ bool OpenStudioApp::openFile(const QString& fileName, bool restoreTabs) {
waitDialog()->setVisible(true);
processEvents();

disconnectOSDocumentSignals();

m_osDocument =
std::shared_ptr<OSDocument>(new OSDocument(componentLibrary(), resourcesPath(), model, fileName, false, startTabIndex, startSubTabIndex));

Expand Down Expand Up @@ -456,6 +462,8 @@ void OpenStudioApp::newFromEmptyTemplateSlot() {
}

void OpenStudioApp::newFromTemplateSlot(NewFromTemplateEnum newFromTemplateEnum) {
disconnectOSDocumentSignals();

m_osDocument = std::shared_ptr<OSDocument>(new OSDocument(componentLibrary(), resourcesPath(), boost::none, QString(), false, startTabIndex()));

connectOSDocumentSignals();
Expand Down Expand Up @@ -555,6 +563,8 @@ void OpenStudioApp::importIdf() {
processEvents();
}

disconnectOSDocumentSignals();

m_osDocument = std::shared_ptr<OSDocument>(new OSDocument(componentLibrary(), resourcesPath(), model, QString(), false, startTabIndex()));
m_osDocument->markAsModified();
// ETH: parent should change now ...
Expand Down Expand Up @@ -681,6 +691,8 @@ void OpenStudioApp::importIFC() {
processEvents();
}

disconnectOSDocumentSignals();

m_osDocument = std::shared_ptr<OSDocument>(new OSDocument(componentLibrary(), resourcesPath(), *model, QString(), false, startTabIndex()));

m_osDocument->markAsModified();
Expand Down Expand Up @@ -743,6 +755,8 @@ void OpenStudioApp::import(OpenStudioApp::fileType type) {
processEvents();
}

disconnectOSDocumentSignals();

m_osDocument = std::shared_ptr<OSDocument>(new OSDocument(componentLibrary(), resourcesPath(), *model, QString(), false, startTabIndex()));
m_osDocument->markAsModified();
// ETH: parent should change now ...
Expand Down Expand Up @@ -894,35 +908,6 @@ void OpenStudioApp::open() {
waitDialog()->resetLabels();
}

//void OpenStudioApp::loadLibrary()
//{
// if( this->currentDocument() )
// {
// QWidget * parent = this->currentDocument()->mainWindow();
//
//
// QString fileName = QFileDialog::getOpenFileName( parent,
// tr("Select Library"),
// toQString(resourcesPath()),
// tr("(*.osm)") );
//
// if( ! (fileName == "") )
// {
// osversion::VersionTranslator versionTranslator;
// versionTranslator.setAllowNewerVersions(false);
//
// boost::optional<openstudio::model::Model> model = versionTranslator.loadModel(toPath(fileName));
// if( model ) {
// this->currentDocument()->setComponentLibrary(*model);
// versionUpdateMessageBox(versionTranslator, true, fileName, openstudio::path());
// }else{
// LOG_FREE(Warn, "OpenStudio", "Could not open file at " << toString(fileName));
// versionUpdateMessageBox(versionTranslator, false, fileName, openstudio::path());
// }
// }
// }
//}

void OpenStudioApp::newModel() {
bool wasQuitOnLastWindowClosed = this->quitOnLastWindowClosed();
this->setQuitOnLastWindowClosed(false);
Expand Down Expand Up @@ -1234,12 +1219,34 @@ void OpenStudioApp::connectOSDocumentSignals() {
connect(m_osDocument.get(), &OSDocument::changeDefaultLibrariesClicked, this, &OpenStudioApp::changeDefaultLibraries);
connect(m_osDocument.get(), &OSDocument::configureExternalToolsClicked, this, &OpenStudioApp::configureExternalTools);
connect(m_osDocument.get(), &OSDocument::loadLibraryClicked, this, &OpenStudioApp::loadLibrary);
connect(m_osDocument.get(), &OSDocument::loadExampleModelClicked, this, &OpenStudioApp::loadExampleModel);
connect(m_osDocument.get(), &OSDocument::newClicked, this, &OpenStudioApp::newModel);
connect(m_osDocument.get(), &OSDocument::helpClicked, this, &OpenStudioApp::showHelp);
connect(m_osDocument.get(), &OSDocument::checkForUpdateClicked, this, &OpenStudioApp::checkForUpdate);
connect(m_osDocument.get(), &OSDocument::aboutClicked, this, &OpenStudioApp::showAbout);
}

void OpenStudioApp::disconnectOSDocumentSignals() {
if (m_osDocument) {
disconnect(m_osDocument.get(), &OSDocument::closeClicked, this, &OpenStudioApp::onCloseClicked);
disconnect(m_osDocument.get(), &OSDocument::exitClicked, this, &OpenStudioApp::quit);
disconnect(m_osDocument.get(), &OSDocument::importClicked, this, &OpenStudioApp::importIdf);
disconnect(m_osDocument.get(), &OSDocument::importgbXMLClicked, this, &OpenStudioApp::importgbXML);
disconnect(m_osDocument.get(), &OSDocument::importSDDClicked, this, &OpenStudioApp::importSDD);
disconnect(m_osDocument.get(), &OSDocument::importIFCClicked, this, &OpenStudioApp::importIFC);
disconnect(m_osDocument.get(), &OSDocument::loadFileClicked, this, &OpenStudioApp::open);
disconnect(m_osDocument.get(), &OSDocument::osmDropped, this, &OpenStudioApp::openFromDrag);
disconnect(m_osDocument.get(), &OSDocument::changeDefaultLibrariesClicked, this, &OpenStudioApp::changeDefaultLibraries);
disconnect(m_osDocument.get(), &OSDocument::configureExternalToolsClicked, this, &OpenStudioApp::configureExternalTools);
disconnect(m_osDocument.get(), &OSDocument::loadLibraryClicked, this, &OpenStudioApp::loadLibrary);
disconnect(m_osDocument.get(), &OSDocument::loadExampleModelClicked, this, &OpenStudioApp::loadExampleModel);
disconnect(m_osDocument.get(), &OSDocument::newClicked, this, &OpenStudioApp::newModel);
disconnect(m_osDocument.get(), &OSDocument::helpClicked, this, &OpenStudioApp::showHelp);
disconnect(m_osDocument.get(), &OSDocument::checkForUpdateClicked, this, &OpenStudioApp::checkForUpdate);
disconnect(m_osDocument.get(), &OSDocument::aboutClicked, this, &OpenStudioApp::showAbout);
}
}

void OpenStudioApp::measureManagerProcessStateChanged(QProcess::ProcessState newState) {}

void OpenStudioApp::measureManagerProcessFinished() {
Expand Down Expand Up @@ -1411,6 +1418,33 @@ void OpenStudioApp::loadLibrary() {
}
}

void OpenStudioApp::loadExampleModel() {

bool wasQuitOnLastWindowClosed = this->quitOnLastWindowClosed();
this->setQuitOnLastWindowClosed(false);

if (m_osDocument) {
if (!closeDocument()) {
this->setQuitOnLastWindowClosed(wasQuitOnLastWindowClosed);
return;
}
processEvents();
}

disconnectOSDocumentSignals();

processEvents();

auto model = openstudio::model::exampleModel();
m_osDocument = std::shared_ptr<OSDocument>(new OSDocument(componentLibrary(), resourcesPath(), model, QString(), false, startTabIndex()));

connectOSDocumentSignals();

waitDialog()->hide();

this->setQuitOnLastWindowClosed(wasQuitOnLastWindowClosed);
}

void OpenStudioApp::changeDefaultLibraries() {
auto defaultPaths = defaultLibraryPaths();
auto paths = libraryPaths();
Expand Down
5 changes: 5 additions & 0 deletions src/openstudio_app/OpenStudioApp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ class OpenStudioApp : public OSAppBase
// Loads the selected file (File > Load Library), and adds it to the user settings if not already there, by calling writeLibraryPaths
void loadLibrary();

// Loads the result of openstudio::model::exampleModel()
void loadExampleModel();

// Checks what happened in the LibraryDialog preference panes, and calls writeLibraryPaths to set the user settings
void changeDefaultLibraries();

Expand Down Expand Up @@ -230,6 +233,8 @@ class OpenStudioApp : public OSAppBase

void connectOSDocumentSignals();

void disconnectOSDocumentSignals();

// Removes the given path from the list of library settings (and calls writeLibraryPaths)
void removeLibraryFromsSettings(const openstudio::path& path);

Expand Down
10 changes: 9 additions & 1 deletion src/openstudio_lib/MainMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ MainMenu::MainMenu(bool isIP, bool isPlugin, QWidget* parent) : QMenuBar(parent)
m_fileImportActions.push_back(action);
//m_preferencesActions.push_back(action); // DLM: I'm unclear if this should be enabled/disabled with preferences or file imports, right now does not matter

QMenu* exampleMenu = m_fileMenu->addMenu(tr("E&xamples"));

action = new QAction(tr("&Example Model"), this);
exampleMenu->addAction(action);
connect(action, &QAction::triggered, this, &MainMenu::loadExampleModelClicked);

if (!m_isPlugin) {

m_fileMenu->addSeparator();
Expand Down Expand Up @@ -234,7 +240,9 @@ MainMenu::MainMenu(bool isIP, bool isPlugin, QWidget* parent) : QMenuBar(parent)
connect(action, &QAction::triggered, this, &MainMenu::aboutClicked);
}

MainMenu::~MainMenu() {}
MainMenu::~MainMenu() {
disconnect();
}

void MainMenu::displaySIUnitsClicked() {
m_displaySIUnitsAction->setChecked(true);
Expand Down
2 changes: 2 additions & 0 deletions src/openstudio_lib/MainMenu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ class MainMenu : public QMenuBar

void loadLibraryClicked();

void loadExampleModelClicked();

void revertFileClicked();

void saveAsFileClicked();
Expand Down
1 change: 1 addition & 0 deletions src/openstudio_lib/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ MainWindow::MainWindow(bool isPlugin, QWidget* parent) : QMainWindow(parent), m_
connect(mainMenu, &MainMenu::changeDefaultLibrariesClicked, this, &MainWindow::changeDefaultLibrariesClicked);
connect(mainMenu, &MainMenu::configureExternalToolsClicked, this, &MainWindow::configureExternalToolsClicked);
connect(mainMenu, &MainMenu::loadLibraryClicked, this, &MainWindow::loadLibraryClicked);
connect(mainMenu, &MainMenu::loadExampleModelClicked, this, &MainWindow::loadExampleModelClicked);
connect(mainMenu, &MainMenu::saveAsFileClicked, this, &MainWindow::saveAsFileClicked);
connect(mainMenu, &MainMenu::saveFileClicked, this, &MainWindow::saveFileClicked);
connect(mainMenu, &MainMenu::revertFileClicked, this, &MainWindow::revertFileClicked);
Expand Down
2 changes: 2 additions & 0 deletions src/openstudio_lib/MainWindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ class MainWindow : public QMainWindow

void loadLibraryClicked();

void loadExampleModelClicked();

void saveAsFileClicked();

void saveFileClicked();
Expand Down
4 changes: 4 additions & 0 deletions src/openstudio_lib/OSDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ OSDocument::OSDocument(const openstudio::model::Model& library, const openstudio
} else {
modelTempDir = model::initializeModel(*model);
m_mainWindow->setWindowTitle("Untitled[*]");
initalizeWorkflow = true;
}
m_modelTempDir = toQString(modelTempDir);

Expand All @@ -196,6 +197,7 @@ OSDocument::OSDocument(const openstudio::model::Model& library, const openstudio
connect(m_mainWindow, &MainWindow::changeDefaultLibrariesClicked, this, &OSDocument::changeDefaultLibrariesClicked);
connect(m_mainWindow, &MainWindow::configureExternalToolsClicked, this, &OSDocument::configureExternalToolsClicked);
connect(m_mainWindow, &MainWindow::loadLibraryClicked, this, &OSDocument::loadLibraryClicked);
connect(m_mainWindow, &MainWindow::loadExampleModelClicked, this, &OSDocument::loadExampleModelClicked);
connect(m_mainWindow, &MainWindow::newClicked, this, &OSDocument::newClicked);
connect(m_mainWindow, &MainWindow::exitClicked, this, &OSDocument::exitClicked);
connect(m_mainWindow, &MainWindow::helpClicked, this, &OSDocument::helpClicked);
Expand Down Expand Up @@ -249,6 +251,8 @@ OSDocument::~OSDocument() {
// blockSignals wouldn't work now anyways because of nano signal slot implementation
// m_model.getImpl<openstudio::model::detail::Model_Impl>()->blockSignals(true);

disconnect();

// release the file watchers so can remove model temp dir
m_mainTabController.reset();

Expand Down
2 changes: 2 additions & 0 deletions src/openstudio_lib/OSDocument.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ class OPENSTUDIO_API OSDocument : public OSQObjectController

void loadLibraryClicked();

void loadExampleModelClicked();

void newClicked();

void exitClicked();
Expand Down