Merge pull request #2158 from KLayout/issue-2154

Issue 2154
This commit is contained in:
Matthias Köfferlein 2025-09-25 20:20:18 +02:00 committed by GitHub
commit ec5de0ffe8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
20 changed files with 387 additions and 326 deletions

View File

@ -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 ();
}
}

View File

@ -26,11 +26,9 @@
#include <string>
#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

View File

@ -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;

View File

@ -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);

View File

@ -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) {

View File

@ -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);

View File

@ -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 \

View File

@ -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<gsi::CursorNamespace> 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<gsi::ButtonStateNamespace> 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<gsi::KeyCodesNamespace> 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"
);
}

View File

@ -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);
@ -1048,121 +1062,4 @@ gsi::Enum<lay::angle_constraint_type> decl_AngleConstraintType ("lay", "AngleCon
gsi::ClassExt<gsi::PluginImpl> 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<gsi::CursorNamespace> 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<gsi::ButtonStateNamespace> 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<gsi::KeyCodesNamespace> 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"
);
}

View File

@ -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 ();
}
}

View File

@ -25,7 +25,9 @@
#define HDR_layConverters
#include "laybasicCommon.h"
#include "laySnap.h"
#include "tlColor.h"
#include "dbHersheyFont.h"
#if defined(HAVE_QT)
# include <QColor>
@ -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

View File

@ -27,6 +27,7 @@ DEFINES += MAKE_LAYBASIC_LIBRARY
}
SOURCES += \
gsiDeclLayAdded.cc \
gsiDeclLayLayers.cc \
gsiDeclLayDispatcher.cc \
gsiDeclLayLayoutViewBase.cc \
@ -34,6 +35,10 @@ SOURCES += \
gsiDeclLayMenu.cc \
gsiDeclLayTlAdded.cc \
gsiDeclLayRdbAdded.cc \
gsiDeclLayConfigPage.cc \
gsiDeclLayEditorOptionsPage.cc \
gsiDeclLayPlugin.cc \
gsiDeclLayPluginFactory.cc \
layAbstractMenu.cc \
layEditorOptionsPage.cc \
layEditorOptionsPages.cc \
@ -90,6 +95,9 @@ SOURCES += \
layUtils.cc \
HEADERS += \
gsiDeclLayConfigPage.h \
gsiDeclLayEditorOptionsPage.h \
gsiDeclLayPlugin.h \
layEditorOptionsPage.h \
layEditorOptionsPages.h \
layEditorUtils.h \

View File

@ -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()

View File

@ -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")