From 97b6d82358e2f79a46ee969749a419bbb440d8a7 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Wed, 24 Sep 2025 22:28:07 +0200 Subject: [PATCH 1/3] Moving lay.ButtonState, KeyCode and Cursor to Qt-less space again --- src/lay/lay/gsiDeclLayPlugin.cc | 117 ------------------ src/laybasic/laybasic/gsiDeclLayAdded.cc | 149 +++++++++++++++++++++++ src/laybasic/laybasic/laybasic.pro | 1 + version.sh | 2 +- 4 files changed, 151 insertions(+), 118 deletions(-) create mode 100644 src/laybasic/laybasic/gsiDeclLayAdded.cc diff --git a/src/lay/lay/gsiDeclLayPlugin.cc b/src/lay/lay/gsiDeclLayPlugin.cc index 418a85bc9..9767ff038 100644 --- a/src/lay/lay/gsiDeclLayPlugin.cc +++ b/src/lay/lay/gsiDeclLayPlugin.cc @@ -1048,121 +1048,4 @@ gsi::Enum decl_AngleConstraintType ("lay", "AngleCon gsi::ClassExt inject_AngleConstraintType_in_parent (decl_AngleConstraintType.defs ()); -class CursorNamespace { }; - -static int cursor_shape_none () { return int (lay::Cursor::none); } -static int cursor_shape_arrow () { return int (lay::Cursor::arrow); } -static int cursor_shape_up_arrow () { return int (lay::Cursor::up_arrow); } -static int cursor_shape_cross () { return int (lay::Cursor::cross); } -static int cursor_shape_wait () { return int (lay::Cursor::wait); } -static int cursor_shape_i_beam () { return int (lay::Cursor::i_beam); } -static int cursor_shape_size_ver () { return int (lay::Cursor::size_ver); } -static int cursor_shape_size_hor () { return int (lay::Cursor::size_hor); } -static int cursor_shape_size_bdiag () { return int (lay::Cursor::size_bdiag); } -static int cursor_shape_size_fdiag () { return int (lay::Cursor::size_fdiag); } -static int cursor_shape_size_all () { return int (lay::Cursor::size_all); } -static int cursor_shape_blank () { return int (lay::Cursor::blank); } -static int cursor_shape_split_v () { return int (lay::Cursor::split_v); } -static int cursor_shape_split_h () { return int (lay::Cursor::split_h); } -static int cursor_shape_pointing_hand () { return int (lay::Cursor::pointing_hand); } -static int cursor_shape_forbidden () { return int (lay::Cursor::forbidden); } -static int cursor_shape_whats_this () { return int (lay::Cursor::whats_this); } -static int cursor_shape_busy () { return int (lay::Cursor::busy); } -static int cursor_shape_open_hand () { return int (lay::Cursor::open_hand); } -static int cursor_shape_closed_hand () { return int (lay::Cursor::closed_hand); } - -Class decl_Cursor ("lay", "Cursor", - method ("None", &cursor_shape_none, "@brief 'No cursor (default)' constant for \\Plugin#set_cursor (resets cursor to default)") + - method ("Arrow", &cursor_shape_arrow, "@brief 'Arrow cursor' constant") + - method ("UpArrow", &cursor_shape_up_arrow, "@brief 'Upward arrow cursor' constant") + - method ("Cross", &cursor_shape_cross, "@brief 'Cross cursor' constant") + - method ("Wait", &cursor_shape_wait, "@brief 'Waiting cursor' constant") + - method ("IBeam", &cursor_shape_i_beam, "@brief 'I beam (text insert) cursor' constant") + - method ("SizeVer", &cursor_shape_size_ver, "@brief 'Vertical resize cursor' constant") + - method ("SizeHor", &cursor_shape_size_hor, "@brief 'Horizontal resize cursor' constant") + - method ("SizeBDiag", &cursor_shape_size_bdiag, "@brief 'Backward diagonal resize cursor' constant") + - method ("SizeFDiag", &cursor_shape_size_fdiag, "@brief 'Forward diagonal resize cursor' constant") + - method ("SizeAll", &cursor_shape_size_all, "@brief 'Size all directions cursor' constant") + - method ("Blank", &cursor_shape_blank, "@brief 'Blank cursor' constant") + - method ("SplitV", &cursor_shape_split_v, "@brief 'Split vertical cursor' constant") + - method ("SplitH", &cursor_shape_split_h, "@brief 'split_horizontal cursor' constant") + - method ("PointingHand", &cursor_shape_pointing_hand, "@brief 'Pointing hand cursor' constant") + - method ("Forbidden", &cursor_shape_forbidden, "@brief 'Forbidden area cursor' constant") + - method ("WhatsThis", &cursor_shape_whats_this, "@brief 'Question mark cursor' constant") + - method ("Busy", &cursor_shape_busy, "@brief 'Busy state cursor' constant") + - method ("OpenHand", &cursor_shape_open_hand, "@brief 'Open hand cursor' constant") + - method ("ClosedHand", &cursor_shape_closed_hand, "@brief 'Closed hand cursor' constant"), - "@brief The namespace for the cursor constants\n" - "This class defines the constants for the cursor setting (for example for method \\Plugin#set_cursor)." - "\n" - "This class has been introduced in version 0.22.\n" -); - -class ButtonStateNamespace { }; - -static int const_ShiftButton() { return (int) lay::ShiftButton; } -static int const_ControlButton() { return (int) lay::ControlButton; } -static int const_AltButton() { return (int) lay::AltButton; } -static int const_LeftButton() { return (int) lay::LeftButton; } -static int const_MidButton() { return (int) lay::MidButton; } -static int const_RightButton() { return (int) lay::RightButton; } - -Class decl_ButtonState ("lay", "ButtonState", - method ("ShiftKey", &const_ShiftButton, "@brief Indicates that the Shift key is pressed\nThis constant is combined with other constants within \\ButtonState") + - method ("ControlKey", &const_ControlButton, "@brief Indicates that the Control key is pressed\nThis constant is combined with other constants within \\ButtonState") + - method ("AltKey", &const_AltButton, "@brief Indicates that the Alt key is pressed\nThis constant is combined with other constants within \\ButtonState") + - method ("LeftButton", &const_LeftButton, "@brief Indicates that the left mouse button is pressed\nThis constant is combined with other constants within \\ButtonState") + - method ("MidButton", &const_MidButton, "@brief Indicates that the middle mouse button is pressed\nThis constant is combined with other constants within \\ButtonState") + - method ("RightButton", &const_RightButton, "@brief Indicates that the right mouse button is pressed\nThis constant is combined with other constants within \\ButtonState"), - "@brief The namespace for the button state flags in the mouse events of the Plugin class.\n" - "This class defines the constants for the button state. In the event handler, the button state is " - "indicated by a bitwise combination of these constants. See \\Plugin for further details." - "\n" - "This class has been introduced in version 0.22.\n" -); - -class KeyCodesNamespace { }; - -static int const_KeyEscape() { return (int) lay::KeyEscape; } -static int const_KeyTab() { return (int) lay::KeyTab; } -static int const_KeyBacktab() { return (int) lay::KeyBacktab; } -static int const_KeyBackspace() { return (int) lay::KeyBackspace; } -static int const_KeyReturn() { return (int) lay::KeyReturn; } -static int const_KeyEnter() { return (int) lay::KeyEnter; } -static int const_KeyInsert() { return (int) lay::KeyInsert; } -static int const_KeyDelete() { return (int) lay::KeyDelete; } -static int const_KeyHome() { return (int) lay::KeyHome; } -static int const_KeyEnd() { return (int) lay::KeyEnd; } -static int const_KeyDown() { return (int) lay::KeyDown; } -static int const_KeyUp() { return (int) lay::KeyUp; } -static int const_KeyLeft() { return (int) lay::KeyLeft; } -static int const_KeyRight() { return (int) lay::KeyRight; } -static int const_KeyPageUp() { return (int) lay::KeyPageUp; } -static int const_KeyPageDown() { return (int) lay::KeyPageDown; } - -Class decl_KeyCode ("lay", "KeyCode", - method ("Escape", &const_KeyEscape, "@brief Indicates the Escape key") + - method ("Tab", &const_KeyTab, "@brief Indicates the Tab key") + - method ("Backtab", &const_KeyBacktab, "@brief Indicates the Backtab key") + - method ("Backspace", &const_KeyBackspace, "@brief Indicates the Backspace key") + - method ("Return", &const_KeyReturn, "@brief Indicates the Return key") + - method ("Enter", &const_KeyEnter, "@brief Indicates the Enter key") + - method ("Insert", &const_KeyInsert, "@brief Indicates the Insert key") + - method ("Delete", &const_KeyDelete, "@brief Indicates the Delete key") + - method ("Home", &const_KeyHome, "@brief Indicates the Home key") + - method ("End", &const_KeyEnd, "@brief Indicates the End key") + - method ("Down", &const_KeyDown, "@brief Indicates the Down key") + - method ("Up", &const_KeyUp, "@brief Indicates the Up key") + - method ("Left", &const_KeyLeft, "@brief Indicates the Left key") + - method ("Right", &const_KeyRight, "@brief Indicates the Right key") + - method ("PageUp", &const_KeyPageUp, "@brief Indicates the PageUp key") + - method ("PageDown", &const_KeyPageDown, "@brief Indicates the PageDown key"), - "@brief The namespace for the some key codes.\n" - "This namespace defines some key codes understood by built-in \\LayoutView components. " - "When compiling with Qt, these codes are compatible with Qt's key codes.\n" - "The key codes are intended to be used when directly interfacing with \\LayoutView in non-Qt-based environments.\n" - "\n" - "This class has been introduced in version 0.28.\n" -); - } diff --git a/src/laybasic/laybasic/gsiDeclLayAdded.cc b/src/laybasic/laybasic/gsiDeclLayAdded.cc new file mode 100644 index 000000000..32cb1c54d --- /dev/null +++ b/src/laybasic/laybasic/gsiDeclLayAdded.cc @@ -0,0 +1,149 @@ + +/* + + KLayout Layout Viewer + Copyright (C) 2006-2025 Matthias Koefferlein + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +#include "gsiDecl.h" +#include "gsiDeclBasic.h" +#include "gsiEnums.h" +#include "layCursor.h" +#include "layViewObject.h" + +namespace gsi +{ + +class CursorNamespace { }; + +static int cursor_shape_none () { return int (lay::Cursor::none); } +static int cursor_shape_arrow () { return int (lay::Cursor::arrow); } +static int cursor_shape_up_arrow () { return int (lay::Cursor::up_arrow); } +static int cursor_shape_cross () { return int (lay::Cursor::cross); } +static int cursor_shape_wait () { return int (lay::Cursor::wait); } +static int cursor_shape_i_beam () { return int (lay::Cursor::i_beam); } +static int cursor_shape_size_ver () { return int (lay::Cursor::size_ver); } +static int cursor_shape_size_hor () { return int (lay::Cursor::size_hor); } +static int cursor_shape_size_bdiag () { return int (lay::Cursor::size_bdiag); } +static int cursor_shape_size_fdiag () { return int (lay::Cursor::size_fdiag); } +static int cursor_shape_size_all () { return int (lay::Cursor::size_all); } +static int cursor_shape_blank () { return int (lay::Cursor::blank); } +static int cursor_shape_split_v () { return int (lay::Cursor::split_v); } +static int cursor_shape_split_h () { return int (lay::Cursor::split_h); } +static int cursor_shape_pointing_hand () { return int (lay::Cursor::pointing_hand); } +static int cursor_shape_forbidden () { return int (lay::Cursor::forbidden); } +static int cursor_shape_whats_this () { return int (lay::Cursor::whats_this); } +static int cursor_shape_busy () { return int (lay::Cursor::busy); } +static int cursor_shape_open_hand () { return int (lay::Cursor::open_hand); } +static int cursor_shape_closed_hand () { return int (lay::Cursor::closed_hand); } + +Class decl_Cursor ("lay", "Cursor", + method ("None", &cursor_shape_none, "@brief 'No cursor (default)' constant for \\Plugin#set_cursor (resets cursor to default)") + + method ("Arrow", &cursor_shape_arrow, "@brief 'Arrow cursor' constant") + + method ("UpArrow", &cursor_shape_up_arrow, "@brief 'Upward arrow cursor' constant") + + method ("Cross", &cursor_shape_cross, "@brief 'Cross cursor' constant") + + method ("Wait", &cursor_shape_wait, "@brief 'Waiting cursor' constant") + + method ("IBeam", &cursor_shape_i_beam, "@brief 'I beam (text insert) cursor' constant") + + method ("SizeVer", &cursor_shape_size_ver, "@brief 'Vertical resize cursor' constant") + + method ("SizeHor", &cursor_shape_size_hor, "@brief 'Horizontal resize cursor' constant") + + method ("SizeBDiag", &cursor_shape_size_bdiag, "@brief 'Backward diagonal resize cursor' constant") + + method ("SizeFDiag", &cursor_shape_size_fdiag, "@brief 'Forward diagonal resize cursor' constant") + + method ("SizeAll", &cursor_shape_size_all, "@brief 'Size all directions cursor' constant") + + method ("Blank", &cursor_shape_blank, "@brief 'Blank cursor' constant") + + method ("SplitV", &cursor_shape_split_v, "@brief 'Split vertical cursor' constant") + + method ("SplitH", &cursor_shape_split_h, "@brief 'split_horizontal cursor' constant") + + method ("PointingHand", &cursor_shape_pointing_hand, "@brief 'Pointing hand cursor' constant") + + method ("Forbidden", &cursor_shape_forbidden, "@brief 'Forbidden area cursor' constant") + + method ("WhatsThis", &cursor_shape_whats_this, "@brief 'Question mark cursor' constant") + + method ("Busy", &cursor_shape_busy, "@brief 'Busy state cursor' constant") + + method ("OpenHand", &cursor_shape_open_hand, "@brief 'Open hand cursor' constant") + + method ("ClosedHand", &cursor_shape_closed_hand, "@brief 'Closed hand cursor' constant"), + "@brief The namespace for the cursor constants\n" + "This class defines the constants for the cursor setting (for example for method \\Plugin#set_cursor)." + "\n" + "This class has been introduced in version 0.22.\n" +); + +class ButtonStateNamespace { }; + +static int const_ShiftButton() { return (int) lay::ShiftButton; } +static int const_ControlButton() { return (int) lay::ControlButton; } +static int const_AltButton() { return (int) lay::AltButton; } +static int const_LeftButton() { return (int) lay::LeftButton; } +static int const_MidButton() { return (int) lay::MidButton; } +static int const_RightButton() { return (int) lay::RightButton; } + +Class decl_ButtonState ("lay", "ButtonState", + method ("ShiftKey", &const_ShiftButton, "@brief Indicates that the Shift key is pressed\nThis constant is combined with other constants within \\ButtonState") + + method ("ControlKey", &const_ControlButton, "@brief Indicates that the Control key is pressed\nThis constant is combined with other constants within \\ButtonState") + + method ("AltKey", &const_AltButton, "@brief Indicates that the Alt key is pressed\nThis constant is combined with other constants within \\ButtonState") + + method ("LeftButton", &const_LeftButton, "@brief Indicates that the left mouse button is pressed\nThis constant is combined with other constants within \\ButtonState") + + method ("MidButton", &const_MidButton, "@brief Indicates that the middle mouse button is pressed\nThis constant is combined with other constants within \\ButtonState") + + method ("RightButton", &const_RightButton, "@brief Indicates that the right mouse button is pressed\nThis constant is combined with other constants within \\ButtonState"), + "@brief The namespace for the button state flags in the mouse events of the Plugin class.\n" + "This class defines the constants for the button state. In the event handler, the button state is " + "indicated by a bitwise combination of these constants. See \\Plugin for further details." + "\n" + "This class has been introduced in version 0.22.\n" +); + +class KeyCodesNamespace { }; + +static int const_KeyEscape() { return (int) lay::KeyEscape; } +static int const_KeyTab() { return (int) lay::KeyTab; } +static int const_KeyBacktab() { return (int) lay::KeyBacktab; } +static int const_KeyBackspace() { return (int) lay::KeyBackspace; } +static int const_KeyReturn() { return (int) lay::KeyReturn; } +static int const_KeyEnter() { return (int) lay::KeyEnter; } +static int const_KeyInsert() { return (int) lay::KeyInsert; } +static int const_KeyDelete() { return (int) lay::KeyDelete; } +static int const_KeyHome() { return (int) lay::KeyHome; } +static int const_KeyEnd() { return (int) lay::KeyEnd; } +static int const_KeyDown() { return (int) lay::KeyDown; } +static int const_KeyUp() { return (int) lay::KeyUp; } +static int const_KeyLeft() { return (int) lay::KeyLeft; } +static int const_KeyRight() { return (int) lay::KeyRight; } +static int const_KeyPageUp() { return (int) lay::KeyPageUp; } +static int const_KeyPageDown() { return (int) lay::KeyPageDown; } + +Class decl_KeyCode ("lay", "KeyCode", + method ("Escape", &const_KeyEscape, "@brief Indicates the Escape key") + + method ("Tab", &const_KeyTab, "@brief Indicates the Tab key") + + method ("Backtab", &const_KeyBacktab, "@brief Indicates the Backtab key") + + method ("Backspace", &const_KeyBackspace, "@brief Indicates the Backspace key") + + method ("Return", &const_KeyReturn, "@brief Indicates the Return key") + + method ("Enter", &const_KeyEnter, "@brief Indicates the Enter key") + + method ("Insert", &const_KeyInsert, "@brief Indicates the Insert key") + + method ("Delete", &const_KeyDelete, "@brief Indicates the Delete key") + + method ("Home", &const_KeyHome, "@brief Indicates the Home key") + + method ("End", &const_KeyEnd, "@brief Indicates the End key") + + method ("Down", &const_KeyDown, "@brief Indicates the Down key") + + method ("Up", &const_KeyUp, "@brief Indicates the Up key") + + method ("Left", &const_KeyLeft, "@brief Indicates the Left key") + + method ("Right", &const_KeyRight, "@brief Indicates the Right key") + + method ("PageUp", &const_KeyPageUp, "@brief Indicates the PageUp key") + + method ("PageDown", &const_KeyPageDown, "@brief Indicates the PageDown key"), + "@brief The namespace for the some key codes.\n" + "This namespace defines some key codes understood by built-in \\LayoutView components. " + "When compiling with Qt, these codes are compatible with Qt's key codes.\n" + "The key codes are intended to be used when directly interfacing with \\LayoutView in non-Qt-based environments.\n" + "\n" + "This class has been introduced in version 0.28.\n" +); + +} diff --git a/src/laybasic/laybasic/laybasic.pro b/src/laybasic/laybasic/laybasic.pro index f6998f621..94f01eb98 100644 --- a/src/laybasic/laybasic/laybasic.pro +++ b/src/laybasic/laybasic/laybasic.pro @@ -27,6 +27,7 @@ DEFINES += MAKE_LAYBASIC_LIBRARY } SOURCES += \ + gsiDeclLayAdded.cc \ gsiDeclLayLayers.cc \ gsiDeclLayDispatcher.cc \ gsiDeclLayLayoutViewBase.cc \ diff --git a/version.sh b/version.sh index 30c6324af..7e1fd272e 100644 --- a/version.sh +++ b/version.sh @@ -5,7 +5,7 @@ KLAYOUT_VERSION="0.30.4" # The version used for PyPI (don't use variables here!) -KLAYOUT_PYPI_VERSION="0.30.4" +KLAYOUT_PYPI_VERSION="0.30.4-1" # The build date KLAYOUT_VERSION_DATE=$(date "+%Y-%m-%d") From d1e49dfd904c372fba8320bc87f0ffe752dcdf6c Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Wed, 24 Sep 2025 22:35:03 +0200 Subject: [PATCH 2/3] Added a smoke test --- testdata/pymod/import_lay.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/testdata/pymod/import_lay.py b/testdata/pymod/import_lay.py index e6483254f..142570c12 100755 --- a/testdata/pymod/import_lay.py +++ b/testdata/pymod/import_lay.py @@ -53,6 +53,13 @@ class BasicTest(unittest.TestCase): p.name = "u" self.assertEqual(p.name, "u") + def test_3(self): + + # smoke test (issue #2154) + x = lay.Cursor.Arrow + x = lay.ButtonState.ShiftKey + x = lay.KeyCode.Escape + # run unit tests if __name__ == '__main__': suite = unittest.TestSuite() From de72b05334fe05dce0f8b30a720fbea71c82a70c Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Wed, 24 Sep 2025 23:17:43 +0200 Subject: [PATCH 3/3] Moving code around so that laybasic can again be host for Plugin class - this enables putting that into the Python module without having Qt. --- src/edt/edt/edtConfig.cc | 157 ------------------ src/edt/edt/edtConfig.h | 27 --- src/edt/edt/edtEditorOptionsPages.cc | 17 +- src/edt/edt/edtPartialService.cc | 5 +- src/edt/edt/edtService.cc | 5 +- src/edt/edt/edtTextService.cc | 5 +- src/lay/lay/lay.pro | 7 - .../laybasic}/gsiDeclLayConfigPage.cc | 0 .../laybasic}/gsiDeclLayConfigPage.h | 0 .../laybasic}/gsiDeclLayEditorOptionsPage.cc | 0 .../laybasic}/gsiDeclLayEditorOptionsPage.h | 0 .../laybasic}/gsiDeclLayPlugin.cc | 20 ++- .../laybasic}/gsiDeclLayPlugin.h | 0 .../laybasic}/gsiDeclLayPluginFactory.cc | 0 src/laybasic/laybasic/layConverters.cc | 157 ++++++++++++++++++ src/laybasic/laybasic/layConverters.h | 30 ++++ src/laybasic/laybasic/laybasic.pro | 7 + 17 files changed, 229 insertions(+), 208 deletions(-) rename src/{lay/lay => laybasic/laybasic}/gsiDeclLayConfigPage.cc (100%) rename src/{lay/lay => laybasic/laybasic}/gsiDeclLayConfigPage.h (100%) rename src/{lay/lay => laybasic/laybasic}/gsiDeclLayEditorOptionsPage.cc (100%) rename src/{lay/lay => laybasic/laybasic}/gsiDeclLayEditorOptionsPage.h (100%) rename src/{lay/lay => laybasic/laybasic}/gsiDeclLayPlugin.cc (98%) rename src/{lay/lay => laybasic/laybasic}/gsiDeclLayPlugin.h (100%) rename src/{lay/lay => laybasic/laybasic}/gsiDeclLayPluginFactory.cc (100%) diff --git a/src/edt/edt/edtConfig.cc b/src/edt/edt/edtConfig.cc index 255b9ccbd..89ff4fd65 100644 --- a/src/edt/edt/edtConfig.cc +++ b/src/edt/edt/edtConfig.cc @@ -106,38 +106,6 @@ CMConverter::from_string (const std::string &s, edt::combine_mode_type &m) } } -// ----------------------------------------------------------------------------- -// ACConverter implementation - -std::string -ACConverter::to_string (const lay::angle_constraint_type &m) -{ - if (m == lay::AC_Any) { - return "any"; - } else if (m == lay::AC_Diagonal) { - return "diagonal"; - } else if (m == lay::AC_Ortho) { - return "ortho"; - } else { - return ""; - } -} - -void -ACConverter::from_string (const std::string &tt, lay::angle_constraint_type &m) -{ - std::string t (tl::trim (tt)); - if (t == "any") { - m = lay::AC_Any; - } else if (t == "diagonal") { - m = lay::AC_Diagonal; - } else if (t == "ortho") { - m = lay::AC_Ortho; - } else { - m = lay::AC_Any; - } -} - // ----------------------------------------------------------------------------- // PathExtConverter implementation @@ -174,130 +142,5 @@ PathExtConverter::from_string (const std::string &tt, edt::path_ext_type &m) } } -// ----------------------------------------------------------------------------- -// HAlignConverter implementation - -std::string -HAlignConverter::to_string (db::HAlign a) -{ - if (a == db::HAlignCenter) { - return "center"; - } else if (a == db::HAlignLeft) { - return "left"; - } else if (a == db::HAlignRight) { - return "right"; - } else { - return ""; - } -} - -void -HAlignConverter::from_string (const std::string &tt, db::HAlign &a) -{ - std::string t (tl::trim (tt)); - if (t == "center") { - a = db::HAlignCenter; - } else if (t == "left") { - a = db::HAlignLeft; - } else if (t == "right") { - a = db::HAlignRight; - } else { - a = db::NoHAlign; - } -} - -// ----------------------------------------------------------------------------- -// VAlignConverter implementation - -std::string -VAlignConverter::to_string (db::VAlign a) -{ - if (a == db::VAlignCenter) { - return "center"; - } else if (a == db::VAlignBottom) { - return "bottom"; - } else if (a == db::VAlignTop) { - return "top"; - } else { - return ""; - } -} - -void -VAlignConverter::from_string (const std::string &tt, db::VAlign &a) -{ - std::string t (tl::trim (tt)); - if (t == "center") { - a = db::VAlignCenter; - } else if (t == "bottom") { - a = db::VAlignBottom; - } else if (t == "top") { - a = db::VAlignTop; - } else { - a = db::NoVAlign; - } -} - -// ----------------------------------------------------------------------------- -// EditGridConverter implementation - -std::string -EditGridConverter::to_string (const db::DVector &eg) -{ - if (eg == db::DVector ()) { - return "global"; - } else if (eg.x () < 1e-6) { - return "none"; - } else if (fabs (eg.x () - eg.y ()) < 1e-6) { - return tl::to_string (eg.x ()); - } else { - return tl::to_string (eg.x ()) + "," + tl::to_string (eg.y ()); - } -} - -void -EditGridConverter::from_string (const std::string &s, db::DVector &eg) -{ - tl::Extractor ex (s.c_str ()); - - double x = 0, y = 0; - if (ex.test ("global")) { - eg = db::DVector (); - } else if (ex.test ("none")) { - eg = db::DVector (-1.0, -1.0); - } else if (ex.try_read (x)) { - y = x; - if (ex.test (",")) { - ex.try_read (y); - } - eg = db::DVector (x, y); - } -} - -void -EditGridConverter::from_string_picky (const std::string &s, db::DVector &eg) -{ - tl::Extractor ex (s.c_str ()); - - if (ex.test ("global")) { - eg = db::DVector (); - } else if (ex.test ("none")) { - eg = db::DVector (-1.0, -1.0); - } else { - double x = 0.0, y = 0.0; - ex.read (x); - if (ex.test (",")) { - ex.read (y); - } else { - y = x; - } - if (x < 1e-6 || y < 1e-6) { - throw tl::Exception (tl::to_string (tr ("The grid must be larger than zero"))); - } - eg = db::DVector (x, y); - } - ex.expect_end (); -} - } diff --git a/src/edt/edt/edtConfig.h b/src/edt/edt/edtConfig.h index 97964a9e0..d1dbea097 100644 --- a/src/edt/edt/edtConfig.h +++ b/src/edt/edt/edtConfig.h @@ -26,11 +26,9 @@ #include -#include "laySnap.h" #include "edtCommon.h" #include "tlString.h" #include "dbPoint.h" -#include "dbHersheyFont.h" namespace edt { @@ -87,37 +85,12 @@ struct EDT_PUBLIC CMConverter enum path_ext_type { Flush = 0, Square, Variable, Round, NumPEModes }; -struct EDT_PUBLIC ACConverter -{ - std::string to_string (const lay::angle_constraint_type &m); - void from_string (const std::string &s, lay::angle_constraint_type &m); -}; - struct EDT_PUBLIC PathExtConverter { std::string to_string (const edt::path_ext_type &m); void from_string (const std::string &s, edt::path_ext_type &m); }; -struct EDT_PUBLIC EditGridConverter -{ - std::string to_string (const db::DVector &eg); - void from_string (const std::string &s, db::DVector &eg); - void from_string_picky (const std::string &s, db::DVector &eg); -}; - -struct EDT_PUBLIC HAlignConverter -{ - std::string to_string (db::HAlign a); - void from_string (const std::string &s, db::HAlign &a); -}; - -struct EDT_PUBLIC VAlignConverter -{ - std::string to_string (db::VAlign a); - void from_string (const std::string &s, db::VAlign &a); -}; - } #endif diff --git a/src/edt/edt/edtEditorOptionsPages.cc b/src/edt/edt/edtEditorOptionsPages.cc index 5ed1ac75a..416e08238 100644 --- a/src/edt/edt/edtEditorOptionsPages.cc +++ b/src/edt/edt/edtEditorOptionsPages.cc @@ -33,6 +33,7 @@ #include "edtPropertiesPageUtils.h" #include "tlExceptions.h" #include "layPlugin.h" +#include "layConverters.h" #include "layLayoutViewBase.h" #include "layCellSelectionForm.h" #include "layQtTools.h" @@ -107,7 +108,7 @@ EditorOptionsGeneric::apply (lay::Dispatcher *root) { // Edit grid - EditGridConverter egc; + lay::EditGridConverter egc; if (mp_ui->grid_cb->currentIndex () == 0) { root->config_set (cfg_edit_grid, egc.to_string (db::DVector (-1.0, -1.0))); } else if (mp_ui->grid_cb->currentIndex () == 1) { @@ -125,7 +126,7 @@ EditorOptionsGeneric::apply (lay::Dispatcher *root) // Edit & move angle - ACConverter acc; + lay::ACConverter acc; root->config_set (cfg_edit_move_angle_mode, acc.to_string (lay::angle_constraint_type (mp_ui->move_angle_cb->currentIndex ()))); root->config_set (cfg_edit_connect_angle_mode, acc.to_string (lay::angle_constraint_type (mp_ui->conn_angle_cb->currentIndex ()))); @@ -156,7 +157,7 @@ EditorOptionsGeneric::setup (lay::Dispatcher *root) { // Edit grid - EditGridConverter egc; + lay::EditGridConverter egc; db::DVector eg; root->config_get (cfg_edit_grid, eg, egc); @@ -173,7 +174,7 @@ EditorOptionsGeneric::setup (lay::Dispatcher *root) // edit & move angle - ACConverter acc; + lay::ACConverter acc; lay::angle_constraint_type ac; ac = lay::AC_Any; @@ -244,11 +245,11 @@ EditorOptionsText::apply (lay::Dispatcher *root) root->config_set (cfg_edit_text_string, tl::unescape_string (tl::to_string (mp_ui->text_le->text ()))); // HAlign - HAlignConverter hac; + lay::HAlignConverter hac; root->config_set (cfg_edit_text_halign, hac.to_string (db::HAlign (mp_ui->halign_cbx->currentIndex () - 1))); // VAlign - VAlignConverter vac; + lay::VAlignConverter vac; root->config_set (cfg_edit_text_valign, vac.to_string (db::VAlign (mp_ui->valign_cbx->currentIndex () - 1))); // Text size @@ -271,12 +272,12 @@ EditorOptionsText::setup (lay::Dispatcher *root) // HAlign db::HAlign ha = db::HAlignLeft; - root->config_get (cfg_edit_text_halign, ha, HAlignConverter ()); + root->config_get (cfg_edit_text_halign, ha, lay::HAlignConverter ()); mp_ui->halign_cbx->setCurrentIndex (int (ha) + 1); // VAlign db::VAlign va = db::VAlignBottom; - root->config_get (cfg_edit_text_valign, va, VAlignConverter ()); + root->config_get (cfg_edit_text_valign, va, lay::VAlignConverter ()); mp_ui->valign_cbx->setCurrentIndex (int (va) + 1); double sz = 0.0; diff --git a/src/edt/edt/edtPartialService.cc b/src/edt/edt/edtPartialService.cc index 0bad58cb0..c1d80a2bb 100644 --- a/src/edt/edt/edtPartialService.cc +++ b/src/edt/edt/edtPartialService.cc @@ -25,6 +25,7 @@ #include "layLayoutViewBase.h" #include "laySnap.h" #include "layFinder.h" +#include "layConverters.h" #include "tlProgress.h" #include "edtPartialService.h" #include "edtService.h" @@ -1344,8 +1345,8 @@ PartialService::menu_activated (const std::string & /*symbol*/) bool PartialService::configure (const std::string &name, const std::string &value) { - edt::EditGridConverter egc; - edt::ACConverter acc; + lay::EditGridConverter egc; + lay::ACConverter acc; if (name == cfg_edit_global_grid) { egc.from_string (value, m_global_grid); diff --git a/src/edt/edt/edtService.cc b/src/edt/edt/edtService.cc index 23377fe4f..ceab2f786 100644 --- a/src/edt/edt/edtService.cc +++ b/src/edt/edt/edtService.cc @@ -33,6 +33,7 @@ #include "layFinder.h" #include "layLayoutView.h" #include "laySnap.h" +#include "layConverters.h" #if defined(HAVE_QT) # include "layEditorOptionsPages.h" #endif @@ -309,8 +310,8 @@ Service::service_configuration_changed () bool Service::configure (const std::string &name, const std::string &value) { - edt::EditGridConverter egc; - edt::ACConverter acc; + lay::EditGridConverter egc; + lay::ACConverter acc; if (name == cfg_edit_global_grid) { diff --git a/src/edt/edt/edtTextService.cc b/src/edt/edt/edtTextService.cc index 6efaa5e12..fe3470a51 100644 --- a/src/edt/edt/edtTextService.cc +++ b/src/edt/edt/edtTextService.cc @@ -24,6 +24,7 @@ #include "edtTextService.h" #include "layLayoutViewBase.h" +#include "layConverters.h" #if defined(HAVE_QT) # include "edtPropertiesPages.h" @@ -215,7 +216,7 @@ TextService::configure (const std::string &name, const std::string &value) if (name == cfg_edit_text_halign) { db::HAlign ha = db::HAlignLeft; - HAlignConverter hac; + lay::HAlignConverter hac; hac.from_string (value, ha); if (m_text.halign () != ha) { m_text.halign (ha); @@ -226,7 +227,7 @@ TextService::configure (const std::string &name, const std::string &value) if (name == cfg_edit_text_valign) { db::VAlign va = db::VAlignBottom; - VAlignConverter vac; + lay::VAlignConverter vac; vac.from_string (value, va); if (m_text.valign () != va) { m_text.valign (va); diff --git a/src/lay/lay/lay.pro b/src/lay/lay/lay.pro index 9ccbc0867..23295c1f8 100644 --- a/src/lay/lay/lay.pro +++ b/src/lay/lay/lay.pro @@ -7,9 +7,6 @@ include($$PWD/../../lib.pri) DEFINES += MAKE_LAY_LIBRARY HEADERS = \ - gsiDeclLayConfigPage.h \ - gsiDeclLayEditorOptionsPage.h \ - gsiDeclLayPlugin.h \ layApplication.h \ layClipDialog.h \ layControlWidgetStack.h \ @@ -120,12 +117,8 @@ FORMS = \ SOURCES = \ gsiDeclLayApplication.cc \ - gsiDeclLayConfigPage.cc \ - gsiDeclLayEditorOptionsPage.cc \ gsiDeclLayHelpDialog.cc \ gsiDeclLayMainWindow.cc \ - gsiDeclLayPlugin.cc \ - gsiDeclLayPluginFactory.cc \ layApplication.cc \ layClipDialog.cc \ layControlWidgetStack.cc \ diff --git a/src/lay/lay/gsiDeclLayConfigPage.cc b/src/laybasic/laybasic/gsiDeclLayConfigPage.cc similarity index 100% rename from src/lay/lay/gsiDeclLayConfigPage.cc rename to src/laybasic/laybasic/gsiDeclLayConfigPage.cc diff --git a/src/lay/lay/gsiDeclLayConfigPage.h b/src/laybasic/laybasic/gsiDeclLayConfigPage.h similarity index 100% rename from src/lay/lay/gsiDeclLayConfigPage.h rename to src/laybasic/laybasic/gsiDeclLayConfigPage.h diff --git a/src/lay/lay/gsiDeclLayEditorOptionsPage.cc b/src/laybasic/laybasic/gsiDeclLayEditorOptionsPage.cc similarity index 100% rename from src/lay/lay/gsiDeclLayEditorOptionsPage.cc rename to src/laybasic/laybasic/gsiDeclLayEditorOptionsPage.cc diff --git a/src/lay/lay/gsiDeclLayEditorOptionsPage.h b/src/laybasic/laybasic/gsiDeclLayEditorOptionsPage.h similarity index 100% rename from src/lay/lay/gsiDeclLayEditorOptionsPage.h rename to src/laybasic/laybasic/gsiDeclLayEditorOptionsPage.h diff --git a/src/lay/lay/gsiDeclLayPlugin.cc b/src/laybasic/laybasic/gsiDeclLayPlugin.cc similarity index 98% rename from src/lay/lay/gsiDeclLayPlugin.cc rename to src/laybasic/laybasic/gsiDeclLayPlugin.cc index 9767ff038..28d5245b3 100644 --- a/src/lay/lay/gsiDeclLayPlugin.cc +++ b/src/laybasic/laybasic/gsiDeclLayPlugin.cc @@ -28,7 +28,7 @@ #include "layEditorOptionsPages.h" #include "layCursor.h" #include "layEditorUtils.h" -#include "edtConfig.h" +#include "layConverters.h" namespace gsi { @@ -309,14 +309,28 @@ PluginImpl::snap2_from_to (const db::DPoint &p, const db::DPoint &plast, bool co return details.snapped_point; } +namespace edt +{ + +// This is a replication of the codes from edtConfig.cc, but avoids +// linking laybasic to edt module. +static std::string cfg_edit_grid ("edit-grid"); +static std::string cfg_edit_global_grid ("grid-micron"); +static std::string cfg_edit_snap_to_objects ("edit-snap-to-objects"); +static std::string cfg_edit_snap_objects_to_grid ("edit-snap-objects-to-grid"); +static std::string cfg_edit_move_angle_mode ("edit-move-angle-mode"); +static std::string cfg_edit_connect_angle_mode ("edit-connect-angle-mode"); + +} + /** * @brief Captures some edt space configuration events for convencience */ void PluginImpl::configure_edt (const std::string &name, const std::string &value) { - edt::EditGridConverter egc; - edt::ACConverter acc; + lay::EditGridConverter egc; + lay::ACConverter acc; if (name == edt::cfg_edit_global_grid) { egc.from_string (value, m_global_grid); diff --git a/src/lay/lay/gsiDeclLayPlugin.h b/src/laybasic/laybasic/gsiDeclLayPlugin.h similarity index 100% rename from src/lay/lay/gsiDeclLayPlugin.h rename to src/laybasic/laybasic/gsiDeclLayPlugin.h diff --git a/src/lay/lay/gsiDeclLayPluginFactory.cc b/src/laybasic/laybasic/gsiDeclLayPluginFactory.cc similarity index 100% rename from src/lay/lay/gsiDeclLayPluginFactory.cc rename to src/laybasic/laybasic/gsiDeclLayPluginFactory.cc diff --git a/src/laybasic/laybasic/layConverters.cc b/src/laybasic/laybasic/layConverters.cc index c6a815078..7fe116af9 100644 --- a/src/laybasic/laybasic/layConverters.cc +++ b/src/laybasic/laybasic/layConverters.cc @@ -77,5 +77,162 @@ ColorConverter::from_string (const std::string &s, tl::Color &c) const } } +// ----------------------------------------------------------------------------- +// ACConverter implementation + +std::string +ACConverter::to_string (const lay::angle_constraint_type &m) +{ + if (m == lay::AC_Any) { + return "any"; + } else if (m == lay::AC_Diagonal) { + return "diagonal"; + } else if (m == lay::AC_Ortho) { + return "ortho"; + } else { + return ""; + } +} + +void +ACConverter::from_string (const std::string &tt, lay::angle_constraint_type &m) +{ + std::string t (tl::trim (tt)); + if (t == "any") { + m = lay::AC_Any; + } else if (t == "diagonal") { + m = lay::AC_Diagonal; + } else if (t == "ortho") { + m = lay::AC_Ortho; + } else { + m = lay::AC_Any; + } +} + +// ----------------------------------------------------------------------------- +// HAlignConverter implementation + +std::string +HAlignConverter::to_string (db::HAlign a) +{ + if (a == db::HAlignCenter) { + return "center"; + } else if (a == db::HAlignLeft) { + return "left"; + } else if (a == db::HAlignRight) { + return "right"; + } else { + return ""; + } +} + +void +HAlignConverter::from_string (const std::string &tt, db::HAlign &a) +{ + std::string t (tl::trim (tt)); + if (t == "center") { + a = db::HAlignCenter; + } else if (t == "left") { + a = db::HAlignLeft; + } else if (t == "right") { + a = db::HAlignRight; + } else { + a = db::NoHAlign; + } +} + +// ----------------------------------------------------------------------------- +// VAlignConverter implementation + +std::string +VAlignConverter::to_string (db::VAlign a) +{ + if (a == db::VAlignCenter) { + return "center"; + } else if (a == db::VAlignBottom) { + return "bottom"; + } else if (a == db::VAlignTop) { + return "top"; + } else { + return ""; + } +} + +void +VAlignConverter::from_string (const std::string &tt, db::VAlign &a) +{ + std::string t (tl::trim (tt)); + if (t == "center") { + a = db::VAlignCenter; + } else if (t == "bottom") { + a = db::VAlignBottom; + } else if (t == "top") { + a = db::VAlignTop; + } else { + a = db::NoVAlign; + } +} + +// ----------------------------------------------------------------------------- +// EditGridConverter implementation + +std::string +EditGridConverter::to_string (const db::DVector &eg) +{ + if (eg == db::DVector ()) { + return "global"; + } else if (eg.x () < 1e-6) { + return "none"; + } else if (fabs (eg.x () - eg.y ()) < 1e-6) { + return tl::to_string (eg.x ()); + } else { + return tl::to_string (eg.x ()) + "," + tl::to_string (eg.y ()); + } +} + +void +EditGridConverter::from_string (const std::string &s, db::DVector &eg) +{ + tl::Extractor ex (s.c_str ()); + + double x = 0, y = 0; + if (ex.test ("global")) { + eg = db::DVector (); + } else if (ex.test ("none")) { + eg = db::DVector (-1.0, -1.0); + } else if (ex.try_read (x)) { + y = x; + if (ex.test (",")) { + ex.try_read (y); + } + eg = db::DVector (x, y); + } +} + +void +EditGridConverter::from_string_picky (const std::string &s, db::DVector &eg) +{ + tl::Extractor ex (s.c_str ()); + + if (ex.test ("global")) { + eg = db::DVector (); + } else if (ex.test ("none")) { + eg = db::DVector (-1.0, -1.0); + } else { + double x = 0.0, y = 0.0; + ex.read (x); + if (ex.test (",")) { + ex.read (y); + } else { + y = x; + } + if (x < 1e-6 || y < 1e-6) { + throw tl::Exception (tl::to_string (tr ("The grid must be larger than zero"))); + } + eg = db::DVector (x, y); + } + ex.expect_end (); +} + } diff --git a/src/laybasic/laybasic/layConverters.h b/src/laybasic/laybasic/layConverters.h index 9f5660a6a..9909ef3ad 100644 --- a/src/laybasic/laybasic/layConverters.h +++ b/src/laybasic/laybasic/layConverters.h @@ -25,7 +25,9 @@ #define HDR_layConverters #include "laybasicCommon.h" +#include "laySnap.h" #include "tlColor.h" +#include "dbHersheyFont.h" #if defined(HAVE_QT) # include @@ -47,6 +49,34 @@ struct LAYBASIC_PUBLIC ColorConverter void from_string (const std::string &s, tl::Color &c) const; }; +/** + * @brief A converter for the angle constraint type + */ +struct LAYBASIC_PUBLIC ACConverter +{ + std::string to_string (const lay::angle_constraint_type &m); + void from_string (const std::string &s, lay::angle_constraint_type &m); +}; + +struct LAYBASIC_PUBLIC EditGridConverter +{ + std::string to_string (const db::DVector &eg); + void from_string (const std::string &s, db::DVector &eg); + void from_string_picky (const std::string &s, db::DVector &eg); +}; + +struct LAYBASIC_PUBLIC HAlignConverter +{ + std::string to_string (db::HAlign a); + void from_string (const std::string &s, db::HAlign &a); +}; + +struct LAYBASIC_PUBLIC VAlignConverter +{ + std::string to_string (db::VAlign a); + void from_string (const std::string &s, db::VAlign &a); +}; + } #endif diff --git a/src/laybasic/laybasic/laybasic.pro b/src/laybasic/laybasic/laybasic.pro index 94f01eb98..30f47b1ab 100644 --- a/src/laybasic/laybasic/laybasic.pro +++ b/src/laybasic/laybasic/laybasic.pro @@ -35,6 +35,10 @@ SOURCES += \ gsiDeclLayMenu.cc \ gsiDeclLayTlAdded.cc \ gsiDeclLayRdbAdded.cc \ + gsiDeclLayConfigPage.cc \ + gsiDeclLayEditorOptionsPage.cc \ + gsiDeclLayPlugin.cc \ + gsiDeclLayPluginFactory.cc \ layAbstractMenu.cc \ layEditorOptionsPage.cc \ layEditorOptionsPages.cc \ @@ -91,6 +95,9 @@ SOURCES += \ layUtils.cc \ HEADERS += \ + gsiDeclLayConfigPage.h \ + gsiDeclLayEditorOptionsPage.h \ + gsiDeclLayPlugin.h \ layEditorOptionsPage.h \ layEditorOptionsPages.h \ layEditorUtils.h \