Skip to content

Commit 9fbaf8f

Browse files
Merge pull request #2232 from KLayout/bugfix/issue-2221
Bugfix/issue 2221
2 parents 590bc91 + bc835ad commit 9fbaf8f

File tree

6 files changed

+125
-131
lines changed

6 files changed

+125
-131
lines changed

src/lay/lay/layMainWindow.cc

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2277,6 +2277,29 @@ MainWindow::cm_save_as ()
22772277
do_save (true);
22782278
}
22792279

2280+
static db::SaveLayoutOptions
2281+
get_save_options_from_cv (const lay::CellView &cv)
2282+
{
2283+
db::SaveLayoutOptions options = cv->save_options ();
2284+
if (!cv->save_options_valid () && cv->technology ()) {
2285+
options = cv->technology ()->save_layout_options ();
2286+
options.set_format (cv->save_options ().format ());
2287+
}
2288+
2289+
// preconfigure options with current values
2290+
2291+
options.set_dbu (cv->layout ().dbu ());
2292+
2293+
if (cv->layout ().has_meta_info ("libname")) {
2294+
tl::Variant libname = cv->layout ().meta_info ("libname").value;
2295+
if (libname.is_a_string ()) {
2296+
options.set_libname (libname.to_stdstring ());
2297+
}
2298+
}
2299+
2300+
return options;
2301+
}
2302+
22802303
void
22812304
MainWindow::do_save (bool as)
22822305
{
@@ -2309,22 +2332,7 @@ MainWindow::do_save (bool as)
23092332
// - if the layout's save options are valid we take the options from there, otherwise we take the options from the technology
23102333
// - on "save as" we let the user edit the options
23112334

2312-
db::SaveLayoutOptions options = cv->save_options ();
2313-
if (!cv->save_options_valid () && cv->technology ()) {
2314-
options = cv->technology ()->save_layout_options ();
2315-
options.set_format (cv->save_options ().format ());
2316-
}
2317-
2318-
// preconfigure options with current values
2319-
2320-
options.set_dbu (cv->layout ().dbu ());
2321-
2322-
if (cv->layout ().has_meta_info ("libname")) {
2323-
tl::Variant libname = cv->layout ().meta_info ("libname").value;
2324-
if (libname.is_a_string ()) {
2325-
options.set_libname (libname.to_stdstring ());
2326-
}
2327-
}
2335+
db::SaveLayoutOptions options = get_save_options_from_cv (cv);
23282336

23292337
if (as || options.format ().empty ()) {
23302338
options.set_format_from_filename (fn);
@@ -2337,7 +2345,18 @@ MainWindow::do_save (bool as)
23372345
}
23382346

23392347
current_view ()->save_as ((unsigned int) cv_index, fn, om, options, true, m_keep_backups);
2340-
add_mru (fn, current_view ()->cellview (cv_index)->tech_name ());
2348+
add_mru (fn, cv->tech_name ());
2349+
2350+
if (as) {
2351+
2352+
lay::LayoutViewNotification n ("reload", tl::to_string (tr ("The next 'save' operations will use the writer options you have picked, instead of the application-wide ones.")));
2353+
current_view ()->add_notification (n);
2354+
2355+
// freeze writer options in the 'save_as' case, so we can do another "save" and get the
2356+
// selected options again
2357+
cv->set_save_options (options, true);
2358+
2359+
}
23412360

23422361
}
23432362

@@ -2362,23 +2381,14 @@ MainWindow::cm_save_all ()
23622381

23632382
if (! fn.empty () || mp_layout_fdia->get_save (fn, tl::to_string (tr ("Save Layout '%1'").arg (tl::to_qstring (cv->name ()))))) {
23642383

2365-
db::SaveLayoutOptions options (cv->save_options ());
2366-
options.set_dbu (cv->layout ().dbu ());
2384+
db::SaveLayoutOptions options = get_save_options_from_cv (cv);
23672385

23682386
if (options.format ().empty ()) {
23692387
options.set_format_from_filename (fn);
23702388
}
23712389

23722390
tl::OutputStream::OutputStreamMode om = tl::OutputStream::OM_Auto;
23732391

2374-
// initialize the specific options from the configuration if required
2375-
for (tl::Registrar<lay::PluginDeclaration>::iterator cls = tl::Registrar<lay::PluginDeclaration>::begin (); cls != tl::Registrar<lay::PluginDeclaration>::end (); ++cls) {
2376-
const StreamWriterPluginDeclaration *decl = dynamic_cast <const StreamWriterPluginDeclaration *> (&*cls);
2377-
if (decl) {
2378-
options.set_options (decl->create_specific_options ());
2379-
}
2380-
}
2381-
23822392
view (view_index)->save_as (cv_index, fn, om, options, true, m_keep_backups);
23832393
add_mru (fn, cv->tech_name ());
23842394

src/laybasic/laybasic/layCellView.cc

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -300,39 +300,11 @@ LayoutHandle::set_save_options (const db::SaveLayoutOptions &options, bool valid
300300
m_save_options_valid = valid;
301301
}
302302

303-
void
304-
LayoutHandle::update_save_options (db::SaveLayoutOptions &options)
305-
{
306-
#if defined(HAVE_QT)
307-
for (tl::Registrar<lay::PluginDeclaration>::iterator cls = tl::Registrar<lay::PluginDeclaration>::begin (); cls != tl::Registrar<lay::PluginDeclaration>::end (); ++cls) {
308-
309-
const lay::StreamWriterPluginDeclaration *decl = dynamic_cast <const lay::StreamWriterPluginDeclaration *> (&*cls);
310-
if (! decl || decl->options_alias ()) {
311-
continue;
312-
}
313-
314-
std::unique_ptr<db::FormatSpecificWriterOptions> specific_options;
315-
if (options.get_options (decl->format_name ())) {
316-
specific_options.reset (options.get_options (decl->format_name ())->clone ());
317-
} else {
318-
specific_options.reset (decl->create_specific_options ());
319-
}
320-
321-
if (specific_options.get ()) {
322-
options.set_options (specific_options.release ());
323-
}
324-
325-
}
326-
#endif
327-
}
328-
329303
void
330304
LayoutHandle::save_as (const std::string &fn, tl::OutputStream::OutputStreamMode om, const db::SaveLayoutOptions &options, bool update, int keep_backups)
331305
{
332306
if (update) {
333307

334-
m_save_options = options;
335-
m_save_options_valid = true;
336308
// We must not load with the original options after we have saved the file - hence we reset the
337309
// reader options.
338310
m_load_options = db::LoadLayoutOptions ();

src/laybasic/laybasic/layCellView.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -242,15 +242,6 @@ class LAYBASIC_PUBLIC LayoutHandle
242242
return m_save_options;
243243
}
244244

245-
/**
246-
* @brief Updates the given save options with attributes from this cell view
247-
*
248-
* Some formats will initialize attributes from the cell view and the layout's
249-
* metadata (example: libname of GDS2). This method will update the options
250-
* if the layout provides attributes for initializing the latter.
251-
*/
252-
void update_save_options (db::SaveLayoutOptions &options);
253-
254245
/**
255246
* @brief Gets a flag indicating whether the save options are valid
256247
*

src/laybasic/laybasic/layLayoutViewBase.h

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,70 @@ struct LAYBASIC_PUBLIC LayerDisplayProperties
149149
std::string name;
150150
};
151151

152+
/**
153+
* @brief Descriptor for a notification inside the layout view
154+
*
155+
* Notifications are popups added at the top of the view to indicate need for reloading for example.
156+
* Notifications have a name, a title, optional actions (id, title) and a parameter (e.g. file path to reload).
157+
* Actions are mapped to QPushButtons.
158+
*/
159+
class LAYBASIC_PUBLIC LayoutViewNotification
160+
{
161+
public:
162+
LayoutViewNotification (const std::string &name, const std::string &title, const tl::Variant &parameter = tl::Variant ())
163+
: m_name (name), m_title (title), m_parameter (parameter)
164+
{
165+
// .. nothing yet ..
166+
}
167+
168+
void add_action (const std::string &name, const std::string &title)
169+
{
170+
m_actions.push_back (std::make_pair (name, title));
171+
}
172+
173+
const std::vector<std::pair<std::string, std::string> > &actions () const
174+
{
175+
return m_actions;
176+
}
177+
178+
const std::string &name () const
179+
{
180+
return m_name;
181+
}
182+
183+
const std::string &title () const
184+
{
185+
return m_title;
186+
}
187+
188+
const tl::Variant &parameter () const
189+
{
190+
return m_parameter;
191+
}
192+
193+
bool operator<(const LayoutViewNotification &other) const
194+
{
195+
if (m_name != other.name ()) {
196+
return m_name < other.name ();
197+
}
198+
return m_parameter < other.parameter ();
199+
}
200+
201+
bool operator==(const LayoutViewNotification &other) const
202+
{
203+
if (m_name != other.name ()) {
204+
return false;
205+
}
206+
return m_parameter == other.parameter ();
207+
}
208+
209+
private:
210+
std::string m_name;
211+
std::string m_title;
212+
tl::Variant m_parameter;
213+
std::vector<std::pair<std::string, std::string> > m_actions;
214+
};
215+
152216
/**
153217
* @brief The layout view object
154218
*
@@ -279,6 +343,14 @@ class LAYBASIC_PUBLIC LayoutViewBase :
279343
*/
280344
virtual void cut ();
281345

346+
/**
347+
* @brief Adds a notification
348+
*/
349+
virtual void add_notification (const LayoutViewNotification & /*notification*/)
350+
{
351+
// the base implementation does nothing
352+
}
353+
282354
/**
283355
* @brief Gets the explicit title string of the view
284356
*

src/layview/layview/layLayoutView_qt.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,14 @@ LayoutView::LayoutView (lay::LayoutView *source, db::Manager *manager, bool edit
453453
LayoutView::set_active_cellview_index (source->active_cellview_index ());
454454
}
455455

456+
void
457+
LayoutView::add_notification (const LayoutViewNotification &notification)
458+
{
459+
if (mp_widget) {
460+
mp_widget->add_notification (notification);
461+
}
462+
}
463+
456464
bool
457465
LayoutView::event_filter (QObject *obj, QEvent *event, bool &taken)
458466
{

src/layview/layview/layLayoutView_qt.h

Lines changed: 8 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
#
22
/*
33
44
KLayout Layout Viewer
@@ -149,6 +149,11 @@ class LAYVIEW_PUBLIC LayoutView
149149
*/
150150
~LayoutView ();
151151

152+
/**
153+
* @brief Adds a notification
154+
*/
155+
virtual void add_notification (const LayoutViewNotification &notification);
156+
152157
/**
153158
* @brief Gets the widget object that view is embedded in
154159
*/
@@ -695,70 +700,6 @@ class LAYVIEW_PUBLIC LayoutView
695700
void activate_editor_option_pages ();
696701
};
697702

698-
/**
699-
* @brief Descriptor for a notification inside the layout view
700-
*
701-
* Notifications are popups added at the top of the view to indicate need for reloading for example.
702-
* Notifications have a name, a title, optional actions (id, title) and a parameter (e.g. file path to reload).
703-
* Actions are mapped to QPushButtons.
704-
*/
705-
class LAYVIEW_PUBLIC LayoutViewNotification
706-
{
707-
public:
708-
LayoutViewNotification (const std::string &name, const std::string &title, const tl::Variant &parameter = tl::Variant ())
709-
: m_name (name), m_title (title), m_parameter (parameter)
710-
{
711-
// .. nothing yet ..
712-
}
713-
714-
void add_action (const std::string &name, const std::string &title)
715-
{
716-
m_actions.push_back (std::make_pair (name, title));
717-
}
718-
719-
const std::vector<std::pair<std::string, std::string> > &actions () const
720-
{
721-
return m_actions;
722-
}
723-
724-
const std::string &name () const
725-
{
726-
return m_name;
727-
}
728-
729-
const std::string &title () const
730-
{
731-
return m_title;
732-
}
733-
734-
const tl::Variant &parameter () const
735-
{
736-
return m_parameter;
737-
}
738-
739-
bool operator<(const LayoutViewNotification &other) const
740-
{
741-
if (m_name != other.name ()) {
742-
return m_name < other.name ();
743-
}
744-
return m_parameter < other.parameter ();
745-
}
746-
747-
bool operator==(const LayoutViewNotification &other) const
748-
{
749-
if (m_name != other.name ()) {
750-
return false;
751-
}
752-
return m_parameter == other.parameter ();
753-
}
754-
755-
private:
756-
std::string m_name;
757-
std::string m_title;
758-
tl::Variant m_parameter;
759-
std::vector<std::pair<std::string, std::string> > m_actions;
760-
};
761-
762703
/**
763704
* @brief A widget representing a notification
764705
*/
@@ -810,12 +751,12 @@ Q_OBJECT
810751
/**
811752
* @brief Adds a notification
812753
*/
813-
void add_notification (const LayoutViewNotification &notificaton);
754+
void add_notification (const LayoutViewNotification &notification);
814755

815756
/**
816757
* @brief Removes a notification
817758
*/
818-
void remove_notification (const LayoutViewNotification &notificaton);
759+
void remove_notification (const LayoutViewNotification &notification);
819760

820761
/**
821762
* @brief Gets the LayoutView embedded into this widget

0 commit comments

Comments
 (0)