LStream writer options page, updated LStream sources, strm2lstr writer options

This commit is contained in:
Matthias Koefferlein 2025-11-09 10:17:58 +01:00
parent be62abd646
commit f2928e94a8
9 changed files with 499 additions and 1 deletions

View File

@ -84,6 +84,10 @@ GenericWriterOptions::init_from_options (const db::SaveLayoutOptions &save_optio
m_magic_lambda = 1.0;
m_dxf_polygon_mode = save_options.get_option_by_name ("dxf_polygon_mode").to_int ();
m_lstream_compression_level = save_options.get_option_by_name ("lstream_compression_level").to_int ();
m_lstream_recompress = save_options.get_option_by_name ("lstream_recompress").to_bool ();
m_lstream_permissive = save_options.get_option_by_name ("lstream_permissive").to_bool ();
}
const std::string GenericWriterOptions::gds2_format_name = "GDS2";
@ -278,6 +282,34 @@ GenericWriterOptions::add_options (tl::CommandLineOptions &cmd, const std::strin
}
if (format.empty () || format == lstream_format_name) {
// Add LStream format options
std::string group = "[Output options - LStream specific]";
cmd << tl::arg (group +
"-oc|--lstr-compression-level=level", &m_lstream_compression_level, "Specifies the LStream compression level",
"This level describes how hard the LStream writer will try to compress the shapes "
"using shape arrays. Building shape arrays may take some time and requires some memory. "
"The default compression level is 2.\n"
"* 0 - no shape array building\n"
"* 1 - nearest neighbor shape array formation\n"
"* 2++ - enhanced shape array search algorithm using 2nd and further neighbor distances as well\n"
)
<< tl::arg (group +
"#--lstr-recompress", &m_lstream_recompress, "Compresses shape arrays again",
"With this option, shape arrays will be expanded and recompressed. This may result in a better "
"compression ratio, but at the cost of slower execution."
)
<< tl::arg (group +
"#--lstr-permissive", &m_lstream_permissive, "Permissive mode",
"In permissive mode, certain forbidden objects are reported as warnings, not as errors: "
"paths with odd width, polygons with less than three points etc."
)
;
}
if (format.empty () || format == dxf_format_name) {
// Add DXF format options
@ -419,6 +451,10 @@ GenericWriterOptions::configure (db::SaveLayoutOptions &save_options, const db::
save_options.set_option_by_name ("dxf_polygon_mode", m_dxf_polygon_mode);
save_options.set_option_by_name ("lstream_compression_level", m_lstream_compression_level);
save_options.set_option_by_name ("lstream_recompress", m_lstream_recompress);
save_options.set_option_by_name ("lstream_permissive", m_lstream_permissive);
save_options.set_option_by_name ("mag_lambda", m_magic_lambda);
save_options.set_option_by_name ("mag_tech", m_magic_tech);

View File

@ -149,6 +149,10 @@ private:
int m_dxf_polygon_mode;
int m_lstream_compression_level;
bool m_lstream_recompress;
bool m_lstream_permissive;
void set_oasis_substitution_char (const std::string &text);
void init_from_options (const db::SaveLayoutOptions &options);
};

View File

@ -72,6 +72,14 @@ public:
// by the stream and won't trigger a reset of the stream which is not available
// on some sources.
std::string head = s.read_all (4000);
// CIF files must not contain null characters
for (auto c = head.begin (); c != head.end (); ++c) {
if (*c == 0) {
return false;
}
}
int n = 0;
tl::Extractor ex (head.c_str ());

View File

@ -115,7 +115,7 @@ class LStreamFormatDeclaration
}
};
static tl::RegisteredClass<db::StreamFormatDeclaration> format_decl (new LStreamFormatDeclaration (), 0, "LStream");
static tl::RegisteredClass<db::StreamFormatDeclaration> format_decl (new LStreamFormatDeclaration (), 2050, "LStream");
}

View File

@ -91,6 +91,18 @@ Writer::write (db::Layout &layout, tl::OutputStream &stream, const db::SaveLayou
m_compression_level = lstr_options.compression_level;
m_recompress = lstr_options.recompress;
double dbu = (options.dbu () == 0.0) ? layout.dbu () : options.dbu ();
double sf = options.scale_factor () * (layout.dbu () / dbu);
if (fabs (sf - 1.0) < 1e-9) {
// to avoid rounding problems, set to 1.0 exactly if possible.
sf = 1.0;
}
// TODO: implement
if (sf != 1.0) {
throw tl::Exception (tl::to_string (tr ("Scaling is not supported in LStream writer currently")));
}
mp_stream = &stream;
m_options = options;
mp_layout = &layout;

View File

@ -0,0 +1,283 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>LStreamWriterOptionPage</class>
<widget class="QWidget" name="LStreamWriterOptionPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>633</width>
<height>338</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="leftMargin">
<number>9</number>
</property>
<property name="topMargin">
<number>9</number>
</property>
<property name="rightMargin">
<number>9</number>
</property>
<property name="bottomMargin">
<number>9</number>
</property>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>LStream Writer Options</string>
</property>
<layout class="QVBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="leftMargin">
<number>9</number>
</property>
<property name="topMargin">
<number>9</number>
</property>
<property name="rightMargin">
<number>9</number>
</property>
<property name="bottomMargin">
<number>9</number>
</property>
<item>
<widget class="QFrame" name="frame">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QGridLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<item row="1" column="3">
<widget class="QLabel" name="label_2">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="0" column="1">
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>10</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="2" colspan="3">
<widget class="QFrame" name="cblock_warning_frame">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
</layout>
</widget>
</item>
<item row="5" column="2" colspan="3">
<widget class="QFrame" name="frame_2">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
</layout>
</widget>
</item>
<item row="4" column="2" colspan="3">
<widget class="QFrame" name="strict_mode_warning_frame">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
</layout>
</widget>
</item>
<item row="0" column="0" rowspan="2">
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Compaction level
(repetition detection)</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLabel" name="label_3">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>0 (low)</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_10">
<property name="text">
<string>Permissive mode</string>
</property>
</widget>
</item>
<item row="0" column="2" colspan="3">
<widget class="QSlider" name="compression_slider">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximum">
<number>10</number>
</property>
<property name="pageStep">
<number>1</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="tickPosition">
<enum>QSlider::TicksBelow</enum>
</property>
</widget>
</item>
<item row="6" column="2" colspan="3">
<widget class="QCheckBox" name="permissive">
<property name="text">
<string>Don't fail on paths with odd width and other odd shapes</string>
</property>
</widget>
</item>
<item row="1" column="4">
<widget class="QLabel" name="label_4">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>(high) 10</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>524</width>
<height>51</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<tabstops>
<tabstop>compression_slider</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,99 @@
/*
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 "dbSaveLayoutOptions.h"
#include "lstrWriter.h"
#include "lstrFormat.h"
#include "layLStreamWriterPlugin.h"
#include <QFrame>
namespace lay
{
// ---------------------------------------------------------------
// LStreamWriterOptionPage definition and implementation
LStreamWriterOptionPage::LStreamWriterOptionPage (QWidget *parent)
: StreamWriterOptionsPage (parent)
{
mp_ui = new Ui::LStreamWriterOptionPage ();
mp_ui->setupUi (this);
}
LStreamWriterOptionPage::~LStreamWriterOptionPage ()
{
delete mp_ui;
}
void
LStreamWriterOptionPage::setup (const db::FormatSpecificWriterOptions *o, const db::Technology * /*tech*/)
{
const lstr::WriterOptions *options = dynamic_cast<const lstr::WriterOptions *> (o);
if (options) {
mp_ui->compression_slider->setValue (options->compression_level);
mp_ui->permissive->setChecked (options->permissive);
}
}
void
LStreamWriterOptionPage::commit (db::FormatSpecificWriterOptions *o, const db::Technology * /*tech*/, bool gzip)
{
lstr::WriterOptions *options = dynamic_cast<lstr::WriterOptions *> (o);
if (options) {
options->compression_level = mp_ui->compression_slider->value ();
options->permissive = mp_ui->permissive->isChecked ();
}
}
// ---------------------------------------------------------------
// LStreamWriterPluginDeclaration definition and implementation
class LStreamWriterPluginDeclaration
: public StreamWriterPluginDeclaration
{
public:
LStreamWriterPluginDeclaration ()
: StreamWriterPluginDeclaration (lstr::WriterOptions ().format_name ())
{
// .. nothing yet ..
}
StreamWriterOptionsPage *format_specific_options_page (QWidget *parent) const
{
return new LStreamWriterOptionPage (parent);
}
db::FormatSpecificWriterOptions *create_specific_options () const
{
return new lstr::WriterOptions ();
}
};
static tl::RegisteredClass<lay::PluginDeclaration> plugin_decl (new lay::LStreamWriterPluginDeclaration (), 10002, "LStreamWriter");
}

View File

@ -0,0 +1,52 @@
/*
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
*/
#ifndef HDR_layLStreamWriterPlugin_h
#define HDR_layLStreamWriterPlugin_h
#include "layStream.h"
#include "ui_LStreamWriterOptionPage.h"
namespace lay
{
class LStreamWriterOptionPage
: public StreamWriterOptionsPage
{
Q_OBJECT
public:
LStreamWriterOptionPage (QWidget *parent);
~LStreamWriterOptionPage ();
void setup (const db::FormatSpecificWriterOptions *options, const db::Technology *tech);
void commit (db::FormatSpecificWriterOptions *options, const db::Technology *tech, bool gzip);
private:
Ui::LStreamWriterOptionPage *mp_ui;
};
}
#endif

View File

@ -14,8 +14,12 @@ LIBS += -L$$DESTDIR/../db_plugins -llstream
HEADERS = \
layLStreamReaderPlugin.h \
layLStreamWriterPlugin.h \
SOURCES = \
layLStreamReaderPlugin.cc \
layLStreamWriterPlugin.cc \
FORMS = \
LStreamWriterOptionPage.ui \