Moving code around so that laybasic can again be host for Plugin class - this enables putting that into the Python module without having Qt.

This commit is contained in:
Matthias Koefferlein 2025-09-24 23:17:43 +02:00
parent d1e49dfd90
commit de72b05334
17 changed files with 229 additions and 208 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

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

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

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