From b2216ec37284b683951039145f6991ff2c58b107 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Fri, 17 Apr 2020 11:15:50 +0200 Subject: [PATCH] WIP: tech component + editor. --- src/db/db/db.pro | 6 +- src/db/db/dbD25TechnologyComponent.cc | 286 ++++++++++++++++++ src/db/db/dbD25TechnologyComponent.h | 152 ++++++++++ .../laybasic/D25TechnologyComponentEditor.ui | 38 +++ .../laybasic/layD25TechnologyComponent.cc | 93 ++++++ .../laybasic/layD25TechnologyComponent.h | 54 ++++ src/laybasic/laybasic/laybasic.pro | 9 +- src/laybasic/laybasic/laybasicResources.qrc | 1 + src/laybasic/laybasic/syntax/d25_text.xml | 76 +++++ .../tools/view_25d/lay_plugin/layD25Plugin.cc | 2 +- 10 files changed, 711 insertions(+), 6 deletions(-) create mode 100644 src/db/db/dbD25TechnologyComponent.cc create mode 100644 src/db/db/dbD25TechnologyComponent.h create mode 100644 src/laybasic/laybasic/D25TechnologyComponentEditor.ui create mode 100644 src/laybasic/laybasic/layD25TechnologyComponent.cc create mode 100644 src/laybasic/laybasic/layD25TechnologyComponent.h create mode 100644 src/laybasic/laybasic/syntax/d25_text.xml diff --git a/src/db/db/db.pro b/src/db/db/db.pro index ea36ff395..81ca2b2c5 100644 --- a/src/db/db/db.pro +++ b/src/db/db/db.pro @@ -184,7 +184,8 @@ SOURCES = \ dbLayoutVsSchematic.cc \ gsiDeclDbNetlistCrossReference.cc \ gsiDeclDbLayoutVsSchematic.cc \ - dbNetlistObject.cc + dbNetlistObject.cc \ + dbD25TechnologyComponent.cc HEADERS = \ dbArray.h \ @@ -331,7 +332,8 @@ HEADERS = \ dbLayoutVsSchematicReader.h \ dbLayoutVsSchematicFormatDefs.h \ dbLayoutVsSchematic.h \ - dbNetlistObject.h + dbNetlistObject.h \ + dbD25TechnologyComponent.h !equals(HAVE_QT, "0") { diff --git a/src/db/db/dbD25TechnologyComponent.cc b/src/db/db/dbD25TechnologyComponent.cc new file mode 100644 index 000000000..7e3742a5e --- /dev/null +++ b/src/db/db/dbD25TechnologyComponent.cc @@ -0,0 +1,286 @@ + +/* + + KLayout Layout Viewer + Copyright (C) 2006-2020 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 "dbD25TechnologyComponent.h" +#include "tlClassRegistry.h" +#include "tlString.h" + +namespace db +{ + +std::string d25_component_name () +{ + return std::string ("d25"); +} + +std::string d25_description () +{ + return tl::to_string (tr ("Z stack (2.5d)")); +} + +// ----------------------------------------------------------------------------------------- +// D25LayerInfo implementation + +D25LayerInfo::D25LayerInfo () + : m_layer (), m_zstart (0.0), m_zstop (0.0) +{ + // .. nothing yet .. +} + +D25LayerInfo::~D25LayerInfo () +{ + // .. nothing yet .. +} + +D25LayerInfo::D25LayerInfo (const D25LayerInfo &other) +{ + operator= (other); +} + +D25LayerInfo & +D25LayerInfo::operator= (const D25LayerInfo &other) +{ + if (this != &other) { + m_layer = other.m_layer; + m_zstart = other.m_zstart; + m_zstop = other.m_zstop; + } + return *this; +} + +bool +D25LayerInfo::operator== (const D25LayerInfo &other) const +{ + return fabs (m_zstart - other.m_zstart) < db::epsilon && fabs (m_zstop - other.m_zstop) < db::epsilon; +} + +void +D25LayerInfo::set_layer (const db::LayerProperties &l) +{ + m_layer = l; +} + +void +D25LayerInfo::set_layer_from_string (const std::string &l) +{ + db::LayerProperties lp; + tl::Extractor ex (l.c_str ()); + try { + lp.read (ex); + } catch (tl::Exception &) { + // ignore errors for now. + } + m_layer = lp; +} + +std::string +D25LayerInfo::layer_as_string () const +{ + return m_layer.to_string (); +} + +void +D25LayerInfo::set_zstart (double z0) +{ + m_zstart = z0; +} + +void +D25LayerInfo::set_zstop (double z1) +{ + m_zstop = z1; +} + +// ----------------------------------------------------------------------------------- +// D25TechnologyComponent implementation + +D25TechnologyComponent::D25TechnologyComponent () + : db::TechnologyComponent (d25_component_name (), d25_description ()) +{ + // provide some explanation for the initialization + m_src = + "# Provide z stack information here\n" + "# Each line is one layer. The specification consists of a layer specification, a colon and arguments.\n" + "# The arguments are named (like \"x=...\") or in serial. Parameters are separated by comma or blanks.\n" + "# Named arguments are:\n" + "#\n" + "# zstart The lower z position of the extruded layer in µm\n" + "# zstop The upper z position of the extruded layer in µm\n" + "# height The height of the extruded layer in µm\n" + "#\n" + "# 'height', 'zstart' and 'zstop' can be used in any combination. If no value is given for 'zstart', " + "# the upper level of the previous layer will be used.\n" + "#\n" + "# If a single unnamed parameter is given, it corresponds to 'height'. Two parameters correspond to\n" + "# 'zstart' and 'zstop'.\n" + "#\n" + "# Examples:\n" + "# 1: 0.5 1.5 # extrude layer 1/0 from 0.5 to 1.5 vertically\n" + "# 1: zstop=1.5, zstart=0.5 # same as above\n" + "# 1: height=1.0, zstop=1.5 # same as above\n" + "# 1: 1.0 zstop=1.5 # same as above\n" + ; +} + +D25TechnologyComponent::D25TechnologyComponent (const D25TechnologyComponent &d) + : db::TechnologyComponent (d25_component_name (), d25_description ()) +{ + m_layers = d.m_layers; + m_src = d.m_src; +} + +void +D25TechnologyComponent::compile_from_source (const std::string &src) +{ + int current_line = 0; + m_layers.clear (); + + try { + + std::vector lines = tl::split (src, "\n"); + for (std::vector::const_iterator l = lines.begin (); l != lines.end (); ++l) { + + ++current_line; + + tl::Extractor ex (l->c_str ()); + + if (ex.test ("#")) { + // ignore comments + } else if (ex.at_end ()) { + // ignore empty lines + } else { + + db::D25LayerInfo info; + if (! m_layers.empty ()) { + info.set_zstart (m_layers.back ().zstop ()); + info.set_zstop (m_layers.back ().zstop ()); + } + + tl::Variant z0, z1, h; + std::vector args; + + db::LayerProperties lp; + lp.read (ex); + info.set_layer (lp); + + ex.expect (":"); + + while (! ex.at_end ()) { + + double pv = 0.0; + + std::string pn; + if (ex.try_read_name (pn)) { + ex.expect ("="); + ex.read (pv); + } else { + ex.read (pv); + } + + ex.test (","); + + if (pn.empty ()) { + args.push_back (pv); + } else if (pn == "zstart") { + z0 = pv; + } else if (pn == "zstop") { + z1 = pv; + } else if (pn == "height") { + h = pv; + } else { + throw tl::Exception (tl::to_string (tr ("Invalid parameter name: ")) + pn); + } + + } + + if (args.size () == 0) { + if (z0.is_nil () && z1.is_nil ()) { + if (! h.is_nil ()) { + info.set_zstop (info.zstart () + h.to_double ()); + } + } else if (z0.is_nil ()) { + info.set_zstop (z1.to_double ()); + if (! h.is_nil ()) { + info.set_zstart (info.zstop () - h.to_double ()); + } + } else if (z1.is_nil ()) { + info.set_zstart (z0.to_double ()); + if (! h.is_nil ()) { + info.set_zstop (info.zstart () + h.to_double ()); + } + } + } else if (args.size () == 1) { + info.set_zstop ((! z0.is_nil () ? z0.to_double () : info.zstart ()) + args[0]); + } else if (args.size () == 2) { + info.set_zstart (args[0]); + info.set_zstop (args[1]); + } else { + throw tl::Exception (tl::to_string (tr ("Too many parameters (max 2)"))); + } + + m_layers.push_back (info); + + } + + } + + } catch (tl::Exception &ex) { + throw tl::Exception (ex.msg () + tl::sprintf (tl::to_string (tr (" in line %d")), current_line)); + } + + m_src = src; +} + +// ----------------------------------------------------------------------------------- +// D25TechnologyComponent technology component registration + +class D25TechnologyComponentProvider + : public db::TechnologyComponentProvider +{ +public: + D25TechnologyComponentProvider () + : db::TechnologyComponentProvider () + { + // .. nothing yet .. + } + + virtual db::TechnologyComponent *create_component () const + { + return new D25TechnologyComponent (); + } + + virtual tl::XMLElementBase *xml_element () const + { + return new db::TechnologyComponentXMLElement (d25_component_name (), + tl::make_element ((D25TechnologyComponent::const_iterator (D25TechnologyComponent::*) () const) &D25TechnologyComponent::begin, (D25TechnologyComponent::const_iterator (D25TechnologyComponent::*) () const) &D25TechnologyComponent::end, &D25TechnologyComponent::add, "layer", + tl::make_member (&D25LayerInfo::layer_as_string, &D25LayerInfo::set_layer_from_string, "layer") + + tl::make_member (&D25LayerInfo::zstart, &D25LayerInfo::set_zstart, "zstart") + + tl::make_member (&D25LayerInfo::zstop, &D25LayerInfo::set_zstop, "zstop") + ) + + tl::make_member (&D25TechnologyComponent::src, &D25TechnologyComponent::set_src, "src") + ); + } +}; + +static tl::RegisteredClass tc_decl (new D25TechnologyComponentProvider (), 3100, d25_component_name ().c_str ()); + +} diff --git a/src/db/db/dbD25TechnologyComponent.h b/src/db/db/dbD25TechnologyComponent.h new file mode 100644 index 000000000..8d16796e0 --- /dev/null +++ b/src/db/db/dbD25TechnologyComponent.h @@ -0,0 +1,152 @@ + +/* + + KLayout Layout Viewer + Copyright (C) 2006-2020 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 + +*/ + +#ifndef HDR_dbD25TechnologyComponent +#define HDR_dbD25TechnologyComponent + +#include "dbTechnology.h" +#include "dbLayerProperties.h" + +namespace db +{ + +class DB_PUBLIC D25LayerInfo +{ +public: + D25LayerInfo (); + ~D25LayerInfo (); + D25LayerInfo (const D25LayerInfo &other); + D25LayerInfo &operator= (const D25LayerInfo &other); + + bool operator== (const D25LayerInfo &other) const; + + const db::LayerProperties &layer () const + { + return m_layer; + } + + void set_layer_from_string (const std::string &l); + std::string layer_as_string () const; + + void set_layer (const db::LayerProperties &l); + + double zstart () const + { + return m_zstart; + } + + void set_zstart (double z0); + + double zstop () const + { + return m_zstop; + } + + void set_zstop (double z1); + +private: + db::LayerProperties m_layer; + double m_zstart, m_zstop; +}; + +class DB_PUBLIC D25TechnologyComponent + : public db::TechnologyComponent +{ +public: + D25TechnologyComponent (); + D25TechnologyComponent (const D25TechnologyComponent &d); + + typedef std::list layers_type; + typedef layers_type::const_iterator const_iterator; + typedef layers_type::iterator iterator; + + void compile_from_source (const std::string &src); + + const_iterator begin () const + { + return m_layers.begin (); + } + + iterator begin () + { + return m_layers.begin (); + } + + const_iterator end () const + { + return m_layers.end (); + } + + iterator end () + { + return m_layers.end (); + } + + void clear () + { + m_layers.clear (); + } + + void erase (iterator p) + { + m_layers.erase (p); + } + + void insert (iterator p, const D25LayerInfo &info) + { + m_layers.insert (p, info); + } + + void add (const D25LayerInfo &info) + { + m_layers.push_back (info); + } + + size_t size () const + { + return m_layers.size (); + } + + const std::string &src () const + { + return m_src; + } + + // for persistency only, use "compile_from_source" to read from a source string + void set_src (const std::string &s) + { + m_src = s; + } + + db::TechnologyComponent *clone () const + { + return new D25TechnologyComponent (*this); + } + +private: + layers_type m_layers; + std::string m_src; +}; + +} + +#endif diff --git a/src/laybasic/laybasic/D25TechnologyComponentEditor.ui b/src/laybasic/laybasic/D25TechnologyComponentEditor.ui new file mode 100644 index 000000000..5a8b631cd --- /dev/null +++ b/src/laybasic/laybasic/D25TechnologyComponentEditor.ui @@ -0,0 +1,38 @@ + + + D25TechnologyComponentEditor + + + + 0 + 0 + 549 + 434 + + + + Settings + + + + + + 2.5d Vertical Stack Information + + + + + + + + Monospace + + + + + + + + + + diff --git a/src/laybasic/laybasic/layD25TechnologyComponent.cc b/src/laybasic/laybasic/layD25TechnologyComponent.cc new file mode 100644 index 000000000..4935360f1 --- /dev/null +++ b/src/laybasic/laybasic/layD25TechnologyComponent.cc @@ -0,0 +1,93 @@ + +/* + + KLayout Layout Viewer + Copyright (C) 2006-2020 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 "laybasicConfig.h" +#include "dbD25TechnologyComponent.h" +#include "layD25TechnologyComponent.h" + +#include +#include + +namespace lay +{ + +D25TechnologyComponentEditor::D25TechnologyComponentEditor (QWidget *parent) + : TechnologyComponentEditor (parent) +{ + setupUi (this); + + // TODO: activate_help_links (mp_ui->help_label); + + QResource res (tl::to_qstring (":/syntax/d25_text.xml")); + QByteArray data ((const char *) res.data (), int (res.size ())); + if (res.isCompressed ()) { + data = qUncompress (data); + } + + QBuffer input (&data); + input.open (QIODevice::ReadOnly); + mp_hl_basic_attributes.reset (new GenericSyntaxHighlighterAttributes ()); + mp_hl_attributes.reset (new GenericSyntaxHighlighterAttributes (mp_hl_basic_attributes.get ())); + lay::GenericSyntaxHighlighter *hl = new GenericSyntaxHighlighter (src_te, input, mp_hl_attributes.get ()); + input.close (); + + hl->setDocument (src_te->document ()); +} + +void +D25TechnologyComponentEditor::commit () +{ + db::D25TechnologyComponent *data = dynamic_cast (tech_component ()); + if (! data) { + return; + } + + std::string src = tl::to_string (src_te->toPlainText ()); + data->compile_from_source (src); +} + +void +D25TechnologyComponentEditor::setup () +{ + db::D25TechnologyComponent *data = dynamic_cast (tech_component ()); + if (! data) { + return; + } + + src_te->setPlainText (tl::to_qstring (data->src ())); +} + +class D25TechnologyComponentEditorProvider + : public lay::TechnologyEditorProvider +{ +public: + virtual lay::TechnologyComponentEditor *create_editor (QWidget *parent) const + { + return new D25TechnologyComponentEditor (parent); + } +}; + +static tl::RegisteredClass editor_decl (new D25TechnologyComponentEditorProvider (), 3100, "d25"); + +} // namespace lay + diff --git a/src/laybasic/laybasic/layD25TechnologyComponent.h b/src/laybasic/laybasic/layD25TechnologyComponent.h new file mode 100644 index 000000000..aeec28b7e --- /dev/null +++ b/src/laybasic/laybasic/layD25TechnologyComponent.h @@ -0,0 +1,54 @@ + +/* + + KLayout Layout Viewer + Copyright (C) 2006-2020 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 + +*/ + + +#ifndef HDR_layD25TechnologyComponent +#define HDR_layD25TechnologyComponent + +#include "ui_D25TechnologyComponentEditor.h" +#include "layTechnology.h" +#include "layGenericSyntaxHighlighter.h" + +#include + +namespace lay { + +class D25TechnologyComponentEditor + : public lay::TechnologyComponentEditor, + public Ui::D25TechnologyComponentEditor +{ +Q_OBJECT + +public: + D25TechnologyComponentEditor (QWidget *parent); + + void commit (); + void setup (); + +private: + std::auto_ptr mp_hl_attributes, mp_hl_basic_attributes; +}; + +} + +#endif + diff --git a/src/laybasic/laybasic/laybasic.pro b/src/laybasic/laybasic/laybasic.pro index 7a7c8a92e..42c128414 100644 --- a/src/laybasic/laybasic/laybasic.pro +++ b/src/laybasic/laybasic/laybasic.pro @@ -73,7 +73,8 @@ FORMS = \ NetInfoDialog.ui \ NetExportDialog.ui \ SelectCellViewForm.ui \ - LayoutStatistics.ui + LayoutStatistics.ui \ + D25TechnologyComponentEditor.ui RESOURCES = \ laybasicResources.qrc \ @@ -183,7 +184,8 @@ SOURCES = \ layGenericSyntaxHighlighter.cc \ layDispatcher.cc \ laySelectCellViewForm.cc \ - layLayoutStatisticsForm.cc + layLayoutStatisticsForm.cc \ + layD25TechnologyComponent.cc HEADERS = \ gtf.h \ @@ -284,7 +286,8 @@ HEADERS = \ layGenericSyntaxHighlighter.h \ layDispatcher.h \ laySelectCellViewForm.h \ - layLayoutStatisticsForm.h + layLayoutStatisticsForm.h \ + layD25TechnologyComponent.h INCLUDEPATH += $$TL_INC $$GSI_INC $$DB_INC $$RDB_INC $$LYM_INC DEPENDPATH += $$TL_INC $$GSI_INC $$DB_INC $$RDB_INC $$LYM_INC diff --git a/src/laybasic/laybasic/laybasicResources.qrc b/src/laybasic/laybasic/laybasicResources.qrc index 86e08c975..f9243ccc4 100644 --- a/src/laybasic/laybasic/laybasicResources.qrc +++ b/src/laybasic/laybasic/laybasicResources.qrc @@ -45,5 +45,6 @@ images/icon_device_bjt_24.png images/icon_device_bjt_16.png syntax/ur_text.xml + syntax/d25_text.xml diff --git a/src/laybasic/laybasic/syntax/d25_text.xml b/src/laybasic/laybasic/syntax/d25_text.xml new file mode 100644 index 000000000..c845bf7b1 --- /dev/null +++ b/src/laybasic/laybasic/syntax/d25_text.xml @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/plugins/tools/view_25d/lay_plugin/layD25Plugin.cc b/src/plugins/tools/view_25d/lay_plugin/layD25Plugin.cc index 7f92fcd62..c2042a2f4 100644 --- a/src/plugins/tools/view_25d/lay_plugin/layD25Plugin.cc +++ b/src/plugins/tools/view_25d/lay_plugin/layD25Plugin.cc @@ -108,7 +108,7 @@ public: } }; -static tl::RegisteredClass config_decl (new lay::D25PluginDeclaration (), 3000, "lay::D25Plugin"); +static tl::RegisteredClass config_decl (new lay::D25PluginDeclaration (), 3100, "lay::D25Plugin"); }