From 516c3ff9250affb1ad294c4f6618cb80aeb36ec4 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sun, 16 Apr 2017 00:27:28 +0200 Subject: [PATCH] WIP: tech controller and tech setup dialog Some bug fixes (description was not updated in tree, base path of new tech was not set, dirs were not reused for new tech). Some enhancements (tech setup dialog's window state is persisted etc.) --- src/lay/layTechSetupDialog.cc | 29 +++++++++++++-------- src/lay/layTechnologyController.cc | 41 ++++++++++++++++++++++-------- src/laybasic/layAbstractMenu.cc | 1 - src/laybasic/layQtTools.cc | 4 +++ 4 files changed, 52 insertions(+), 23 deletions(-) diff --git a/src/lay/layTechSetupDialog.cc b/src/lay/layTechSetupDialog.cc index c143043ef..996f69a76 100644 --- a/src/lay/layTechSetupDialog.cc +++ b/src/lay/layTechSetupDialog.cc @@ -504,14 +504,6 @@ TechSetupDialog::TechSetupDialog (QWidget *parent) connect (add_pb, SIGNAL (clicked ()), this, SLOT (add_clicked ())); connect (delete_pb, SIGNAL (clicked ()), this, SLOT (delete_clicked ())); connect (rename_pb, SIGNAL (clicked ()), this, SLOT (rename_clicked ())); - - if (s_first_show) { - TipDialog td (this, - tl::to_string (QObject::tr ("To get started with the technology manager, read the documentation provided: About Technology Management.")), - "tech-manager-basic-tips"); - td.exec_dialog (); - s_first_show = false; - } } TechSetupDialog::~TechSetupDialog () @@ -559,6 +551,14 @@ TechSetupDialog::update () int TechSetupDialog::exec (lay::Technologies &technologies) { + if (s_first_show) { + TipDialog td (this, + tl::to_string (QObject::tr ("To get started with the technology manager, read the documentation provided: About Technology Management.")), + "tech-manager-basic-tips"); + td.exec_dialog (); + s_first_show = false; + } + m_technologies = technologies; update (); @@ -613,12 +613,17 @@ BEGIN_PROTECTED QDir root = QDir (tl::to_qstring (lay::TechnologyController::instance ()->default_root ())); QDir tech_dir (root.filePath (tn)); if (tech_dir.exists ()) { - throw tl::Exception (tl::to_string (QObject::tr ("A target folder with path '%1' already exists").arg (tech_dir.path ()))); + if (QMessageBox::question (this, QObject::tr ("Creating Technology"), + QObject::tr ("A target folder with path '%1' already exists\nUse this directory for the new technology?").arg (tech_dir.path ()), + QMessageBox::No | QMessageBox::Yes) == QMessageBox::No) { + throw tl::CancelException (); + } } lay::Technology *nt = new lay::Technology (*t); nt->set_tech_file_path (tl::to_string (tech_dir.absoluteFilePath (tn + QString::fromUtf8 (".lyt")))); + nt->set_default_base_path (tl::to_string (tech_dir.absolutePath ())); nt->set_persisted (false); nt->set_name (tl::to_string (tn)); nt->set_description (std::string ()); @@ -990,9 +995,11 @@ TechSetupDialog::commit_tech_component () mp_current_editor->commit (); } - if (mp_current_tech && mp_current_tech_component && !mp_current_tech->is_readonly ()) { + if (mp_current_tech && !mp_current_tech->is_readonly ()) { - mp_current_tech->set_component (mp_current_tech_component->clone ()); + if (mp_current_tech_component) { + mp_current_tech->set_component (mp_current_tech_component->clone ()); + } // because commit may have changed the description text, update the technology titles for (int i = tech_tree->topLevelItemCount (); i > 0; --i) { diff --git a/src/lay/layTechnologyController.cc b/src/lay/layTechnologyController.cc index d10aa2340..6178f0944 100644 --- a/src/lay/layTechnologyController.cc +++ b/src/lay/layTechnologyController.cc @@ -26,6 +26,7 @@ #include "layMainWindow.h" #include "layApplication.h" #include "layConfig.h" +#include "layQtTools.h" #include "laybasicConfig.h" #include @@ -36,6 +37,8 @@ namespace lay { +static const std::string cfg_tech_editor_window_state ("tech-editor-window-state"); + std::string tech_string_from_name (const std::string &tn) { if (tn.empty ()) { @@ -65,20 +68,18 @@ TechnologyController::instance () } void -TechnologyController::initialize (lay::PluginRoot * /*root*/) -{ - // .. nothing yet .. -} - -void -TechnologyController::initialized (lay::PluginRoot *root) +TechnologyController::initialize (lay::PluginRoot *root) { mp_mw = dynamic_cast (root); if (mp_mw) { mp_editor = new lay::TechSetupDialog (mp_mw); mp_editor->setModal (false); } +} +void +TechnologyController::initialized (lay::PluginRoot * /*root*/) +{ update_menu (); connect_events (); } @@ -94,6 +95,7 @@ void TechnologyController::get_options (std::vector < std::pair > &options) const { options.push_back (std::pair (cfg_initial_technology, "")); + options.push_back (std::pair (cfg_tech_editor_window_state, "")); } void @@ -153,7 +155,12 @@ TechnologyController::update_active_technology () { lay::Technology *active_tech = 0; if (mp_mw && mp_mw->current_view () && mp_mw->current_view ()->active_cellview_index () >= 0 && mp_mw->current_view ()->active_cellview_index () <= int (mp_mw->current_view ()->cellviews ())) { - active_tech = lay::Technologies::instance ()->technology_by_name (mp_mw->current_view ()->active_cellview ()->tech_name ()); + + std::string tn = mp_mw->current_view ()->active_cellview ()->tech_name (); + if (lay::Technologies::instance ()->has_technology (tn)) { + active_tech = lay::Technologies::instance ()->technology_by_name (tn); + } + } if (mp_active_technology != active_tech) { @@ -192,6 +199,7 @@ TechnologyController::technologies_changed () } update_menu (); + emit technologies_edited (); } void @@ -210,6 +218,10 @@ TechnologyController::configure (const std::string &name, const std::string &val m_current_technology_updated = true; } + } else if (name == cfg_tech_editor_window_state) { + + lay::restore_dialog_state (mp_editor, value); + } else if (name == cfg_technologies) { if (! value.empty ()) { @@ -295,6 +307,10 @@ TechnologyController::update_menu () m_current_technology = lay::LayoutView::current ()->active_cellview ()->tech_name (); } + if (! lay::Technologies::instance()->has_technology (m_current_technology)) { + m_current_technology = std::string (); + } + std::string title = tech_string_from_name (m_current_technology); size_t ntech = 0; @@ -307,7 +323,7 @@ TechnologyController::update_menu () for (std::vector::const_iterator t = tech_group.begin (); t != tech_group.end (); ++t) { lay::Action action = pr->menu ()->action (*t); action.set_title (title); - action.set_visible (ntech > 1); + action.set_enabled (ntech > 1); std::vector items = pr->menu ()->items (*t); for (std::vector::const_iterator i = items.begin (); i != items.end (); ++i) { pr->menu ()->delete_item (*i); @@ -428,10 +444,13 @@ TechnologyController::show_editor () QMessageBox::Ok); } - update_menu (); - emit technologies_edited (); + technologies_changed (); } + + if (mp_mw) { + mp_mw->config_set (cfg_tech_editor_window_state, lay::save_dialog_state (mp_editor)); + } } const std::string & diff --git a/src/laybasic/layAbstractMenu.cc b/src/laybasic/layAbstractMenu.cc index 3c62f6bb9..6e5fd7c32 100644 --- a/src/laybasic/layAbstractMenu.cc +++ b/src/laybasic/layAbstractMenu.cc @@ -873,7 +873,6 @@ AbstractMenu::build (QToolBar *t, std::list &items) } } - } QMenu * diff --git a/src/laybasic/layQtTools.cc b/src/laybasic/layQtTools.cc index 6d395e8e9..0ed979770 100644 --- a/src/laybasic/layQtTools.cc +++ b/src/laybasic/layQtTools.cc @@ -103,6 +103,10 @@ save_dialog_state (QWidget *w) void restore_dialog_state (QWidget *dialog, const std::string &s) { + if (! dialog) { + return; + } + tl::Extractor ex (s.c_str ()); while (! ex.at_end ()) {