WIP: tech component + editor.

This commit is contained in:
Matthias Koefferlein 2020-04-17 11:15:50 +02:00
parent 7884446da1
commit b2216ec372
10 changed files with 711 additions and 6 deletions

View File

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

View File

@ -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<std::string> lines = tl::split (src, "\n");
for (std::vector<std::string>::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<double> 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<D25TechnologyComponent> (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<db::TechnologyComponentProvider> tc_decl (new D25TechnologyComponentProvider (), 3100, d25_component_name ().c_str ());
}

View File

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

View File

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>D25TechnologyComponentEditor</class>
<widget class="QFrame" name="D25TechnologyComponentEditor">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>549</width>
<height>434</height>
</rect>
</property>
<property name="windowTitle">
<string>Settings</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>2.5d Vertical Stack Information</string>
</property>
</widget>
</item>
<item>
<widget class="QTextEdit" name="src_te">
<property name="font">
<font>
<family>Monospace</family>
</font>
</property>
</widget>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>

View File

@ -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 <QResource>
#include <QBuffer>
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 <db::D25TechnologyComponent *> (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 <db::D25TechnologyComponent *> (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<lay::TechnologyEditorProvider> editor_decl (new D25TechnologyComponentEditorProvider (), 3100, "d25");
} // namespace lay

View File

@ -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 <memory>
namespace lay {
class D25TechnologyComponentEditor
: public lay::TechnologyComponentEditor,
public Ui::D25TechnologyComponentEditor
{
Q_OBJECT
public:
D25TechnologyComponentEditor (QWidget *parent);
void commit ();
void setup ();
private:
std::auto_ptr<lay::GenericSyntaxHighlighterAttributes> mp_hl_attributes, mp_hl_basic_attributes;
};
}
#endif

View File

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

View File

@ -45,5 +45,6 @@
<file>images/icon_device_bjt_24.png</file>
<file>images/icon_device_bjt_16.png</file>
<file>syntax/ur_text.xml</file>
<file>syntax/d25_text.xml</file>
</qresource>
</RCC>

View File

@ -0,0 +1,76 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE language SYSTEM "language.dtd">
<language name="UserPropertiesTextFormat">
<highlighting>
<contexts>
<context name="Normal" attribute="Normal Text">
<DetectChar attribute="String" char="&quot;" context="Quoted String"/>
<DetectChar attribute="Comment" char="#" context="Comment"/>
<DetectChar attribute="Raw String" char="'" context="Apostrophed String"/>
<RegExpr attribute="Normal" String=":" context="After LD"/>
<RegExpr attribute="Dec" String="\-?[1-9][0-9]*" context="#stay"/>
<DetectChar attribute="Normal" char="*" context="#stay"/>
<DetectChar attribute="Normal" char="(" context="#stay"/>
<DetectChar attribute="Normal" char=")" context="#stay"/>
<DetectChar attribute="Normal" char="/" context="#stay"/>
<RegExpr attribute="Raw String" String="[_a-zA-Z]\w*" context="#stay"/>
<RegExpr attribute="Error" String="[^\s]" context="Error"/>
</context>
<context name="Comment" attribute="Comment" lineEndContext="Normal">
</context>
<context name="After LD" attribute="Normal" lineEndContext="Normal">
<DetectChar attribute="Comment" char="#" context="Comment"/>
<RegExpr attribute="Float" String="\-?[0-9]([0-9]|_[0-9])*(\.[0-9]([0-9]|_[0-9])*)?([eE]\-?[1-9]([0-9]|_[0-9])*(\.[0-9]*)?)?" context="#stay"/>
<DetectChar attribute="Normal" char="," context="#stay"/>
<DetectChar attribute="Normal" char="=" context="#stay"/>
<StringDetect attribute="Symbol" String="zstart" context="#stay"/>
<StringDetect attribute="Symbol" String="zstop" context="#stay"/>
<StringDetect attribute="Symbol" String="height" context="#stay"/>
<RegExpr attribute="Error" String="[^\s]" context="Error"/>
</context>
<context name="Error" attribute="Error" lineEndContext="Normal">
</context>
<context name="Quoted String" attribute="String" lineEndContext="Error">
<StringDetect attribute="String" String="\\" context="#stay"/>
<RegExpr attribute="String" String="\\\&quot;" context="#stay"/>
<DetectChar char="&quot;" attribute="String" context="After Key"/>
</context>
<context name="Apostrophed String" attribute="Raw String" lineEndContext="Error">
<StringDetect attribute="String" String="\\" context="#stay"/>
<RegExpr attribute="String" String="\\\'" context="#stay"/>
<DetectChar char="'" attribute="Raw String" context="After Key"/>
</context>
</contexts>
<itemDatas>
<itemData name="Normal Text" defStyleNum="dsNormal"/>
<itemData name="Comment" defStyleNum="dsComment"/>
<itemData name="Float" defStyleNum="dsFloat"/>
<itemData name="Dec" defStyleNum="dsDecVal"/>
<itemData name="Symbol" defStyleNum="dsString" color="#D40000"/>
<itemData name="String" defStyleNum="dsString"/>
<itemData name="Raw String" defStyleNum="dsString" color="#DD4A4A" selColor="#DD4A4A"/>
<!-- use these to mark errors and alerts things -->
<itemData name="Error" defStyleNum="dsAlert"/>
</itemDatas>
</highlighting>
</language>

View File

@ -108,7 +108,7 @@ public:
}
};
static tl::RegisteredClass<lay::PluginDeclaration> config_decl (new lay::D25PluginDeclaration (), 3000, "lay::D25Plugin");
static tl::RegisteredClass<lay::PluginDeclaration> config_decl (new lay::D25PluginDeclaration (), 3100, "lay::D25Plugin");
}