From b296cdd9156feb8973bad240a8e6d744601eda8f Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sat, 19 Aug 2017 10:23:19 +0200 Subject: [PATCH] Heavy refactoring of buddy sources * To reduce the redundancy * To enable testing of the bd library including the apps The apps are entirely configured through their names. Their .pro files are identical and the app implementation is inside the bd lib (partially generic too). Hence the apps can be tested by bd library unit tests. --- src/buddies/bd/bd.pro | 10 + .../strm2cif.cc => bd/bdConverterMain.cc} | 22 +- src/buddies/bd/bdConverterMain.h | 39 +++ src/buddies/bd/bdInit.cc | 19 ++ src/buddies/bd/bdInit.h | 38 +-- src/buddies/bd/bdWriterOptions.cc | 2 +- src/buddies/bd/main.cc | 39 +++ src/buddies/bd/strm2cif.cc | 29 +++ src/buddies/bd/strm2dxf.cc | 29 +++ src/buddies/bd/strm2gds.cc | 29 +++ src/buddies/bd/strm2gdstxt.cc | 29 +++ src/buddies/bd/strm2oas.cc | 29 +++ src/buddies/{strm2txt => bd}/strm2txt.cc | 9 +- src/buddies/{strmclip => bd}/strmclip.cc | 11 +- src/buddies/{strmcmp => bd}/strmcmp.cc | 7 +- src/buddies/buddy_app.pri | 18 ++ src/buddies/strm2cif.cc | 49 ---- src/buddies/strm2cif/strm2cif.pro | 13 +- src/buddies/strm2dxf.cc | 49 ---- src/buddies/strm2dxf/strm2dxf.cc | 72 ------ src/buddies/strm2dxf/strm2dxf.pro | 13 +- src/buddies/strm2gds.cc | 49 ---- src/buddies/strm2gds/strm2gds.cc | 72 ------ src/buddies/strm2gds/strm2gds.pro | 13 +- src/buddies/strm2gdstxt.cc | 49 ---- src/buddies/strm2gdstxt/strm2gdstxt.cc | 72 ------ src/buddies/strm2gdstxt/strm2gdstxt.pro | 13 +- src/buddies/strm2oas.cc | 108 -------- src/buddies/strm2oas/strm2oas.cc | 72 ------ src/buddies/strm2oas/strm2oas.pro | 13 +- src/buddies/strm2txt.cc | 50 ---- src/buddies/strm2txt/strm2txt.pro | 13 +- src/buddies/strmclip.cc | 235 ------------------ src/buddies/strmclip/strmclip.pro | 13 +- src/buddies/strmcmp.cc | 54 ---- src/buddies/strmcmp/strmcmp.pro | 13 +- src/buddies/strmxor.cc | 215 ---------------- src/tl/tlCommandLineParser.cc | 6 +- 38 files changed, 304 insertions(+), 1311 deletions(-) rename src/buddies/{strm2cif/strm2cif.cc => bd/bdConverterMain.cc} (73%) create mode 100644 src/buddies/bd/bdConverterMain.h create mode 100644 src/buddies/bd/main.cc create mode 100644 src/buddies/bd/strm2cif.cc create mode 100644 src/buddies/bd/strm2dxf.cc create mode 100644 src/buddies/bd/strm2gds.cc create mode 100644 src/buddies/bd/strm2gdstxt.cc create mode 100644 src/buddies/bd/strm2oas.cc rename src/buddies/{strm2txt => bd}/strm2txt.cc (85%) rename src/buddies/{strmclip => bd}/strmclip.cc (97%) rename src/buddies/{strmcmp => bd}/strmcmp.cc (99%) create mode 100644 src/buddies/buddy_app.pri delete mode 100644 src/buddies/strm2cif.cc delete mode 100644 src/buddies/strm2dxf.cc delete mode 100644 src/buddies/strm2dxf/strm2dxf.cc delete mode 100644 src/buddies/strm2gds.cc delete mode 100644 src/buddies/strm2gds/strm2gds.cc delete mode 100644 src/buddies/strm2gdstxt.cc delete mode 100644 src/buddies/strm2gdstxt/strm2gdstxt.cc delete mode 100644 src/buddies/strm2oas.cc delete mode 100644 src/buddies/strm2oas/strm2oas.cc delete mode 100644 src/buddies/strm2txt.cc delete mode 100644 src/buddies/strmclip.cc delete mode 100644 src/buddies/strmcmp.cc delete mode 100644 src/buddies/strmxor.cc diff --git a/src/buddies/bd/bd.pro b/src/buddies/bd/bd.pro index c4cafc503..a051b5505 100644 --- a/src/buddies/bd/bd.pro +++ b/src/buddies/bd/bd.pro @@ -12,12 +12,22 @@ SOURCES = \ bdInit.cc \ bdReaderOptions.cc \ bdWriterOptions.cc \ + bdConverterMain.cc \ + strm2cif.cc \ + strm2gds.cc \ + strm2oas.cc \ + strmclip.cc \ + strm2dxf.cc \ + strm2gdstxt.cc \ + strm2txt.cc \ + strmcmp.cc \ HEADERS = \ bdCommon.h \ bdInit.h \ bdReaderOptions.h \ bdWriterOptions.h \ + bdConverterMain.h \ RESOURCES = \ diff --git a/src/buddies/strm2cif/strm2cif.cc b/src/buddies/bd/bdConverterMain.cc similarity index 73% rename from src/buddies/strm2cif/strm2cif.cc rename to src/buddies/bd/bdConverterMain.cc index 669f007fa..b04d63fdc 100644 --- a/src/buddies/strm2cif/strm2cif.cc +++ b/src/buddies/bd/bdConverterMain.cc @@ -20,29 +20,32 @@ */ -#include "bdInit.h" #include "bdWriterOptions.h" #include "bdReaderOptions.h" +#include "bdConverterMain.h" #include "dbLayout.h" #include "dbReader.h" #include "dbCIFWriter.h" #include "tlCommandLineParser.h" -BD_MAIN_FUNC +namespace bd +{ + +int converter_main (int argc, char *argv[], const std::string &format) { bd::GenericWriterOptions generic_writer_options; bd::GenericReaderOptions generic_reader_options; std::string infile, outfile; tl::CommandLineOptions cmd; - generic_writer_options.add_options_for_cif (cmd); + generic_writer_options.add_options (cmd, format); generic_reader_options.add_options (cmd); - cmd << tl::arg ("input", &infile, "The input file (any format, may be gzip compressed)") - << tl::arg ("output", &outfile, "The output file") + cmd << tl::arg ("input", &infile, "The input file (any format, may be gzip compressed)") + << tl::arg ("output", &outfile, tl::sprintf ("The output file (%s format)", format)) ; - cmd.brief ("This program will convert the given file to a CIF file"); + cmd.brief (tl::sprintf ("This program will convert the given file to a %s file", format)); cmd.parse (argc, argv); @@ -60,13 +63,14 @@ BD_MAIN_FUNC { db::SaveLayoutOptions save_options; generic_writer_options.configure (save_options, layout); + save_options.set_format (format); tl::OutputStream stream (outfile); - db::CIFWriter writer; - writer.write (layout, stream, save_options); + db::Writer writer (save_options); + writer.write (layout, stream); } return 0; } -BD_MAIN +} diff --git a/src/buddies/bd/bdConverterMain.h b/src/buddies/bd/bdConverterMain.h new file mode 100644 index 000000000..780315c0c --- /dev/null +++ b/src/buddies/bd/bdConverterMain.h @@ -0,0 +1,39 @@ + +/* + + KLayout Layout Viewer + Copyright (C) 2006-2017 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_bdConverterMain +#define HDR_bdConverterMain + +#include "bdCommon.h" +#include + +namespace bd +{ + +/** + * @brief A common main() implementation for the "to" converters + */ +BD_PUBLIC int converter_main (int argc, char *argv[], const std::string &format); + +} + +#endif diff --git a/src/buddies/bd/bdInit.cc b/src/buddies/bd/bdInit.cc index 7021a79b7..3f1486f7f 100644 --- a/src/buddies/bd/bdInit.cc +++ b/src/buddies/bd/bdInit.cc @@ -47,4 +47,23 @@ void init () tl::CommandLineOptions::set_license (license); } +int _main_impl (int (*delegate) (int, char *[]), int argc, char *argv[]) +{ + try { + init (); + return (*delegate) (argc, argv); + } catch (tl::CancelException & /*ex*/) { + return 1; + } catch (std::exception &ex) { + tl::error << ex.what (); + return 1; + } catch (tl::Exception &ex) { + tl::error << ex.msg (); + return 1; + } catch (...) { + tl::error << "unspecific error"; + return 1; + } +} + } diff --git a/src/buddies/bd/bdInit.h b/src/buddies/bd/bdInit.h index e83290885..6549b6e9f 100644 --- a/src/buddies/bd/bdInit.h +++ b/src/buddies/bd/bdInit.h @@ -24,7 +24,6 @@ #define HDR_bdInit #include "bdCommon.h" -#include "tlLog.h" // because of BD_MAIN namespace bd { @@ -36,42 +35,9 @@ namespace bd void BD_PUBLIC init (); /** - * @brief Provides a main () implementation - * - * Use this macro like this: - * - * @code - * #include "bdInit.h" - * - * BD_MAIN_FUNC - * { - * .. your code. Use argc and argv for the arguments. - * } - * - * BD_MAIN + * @brief The main function implementation */ - -#define BD_MAIN \ - int main (int argc, char *argv []) \ - { \ - try { \ - bd::init (); \ - return main_func (argc, argv); \ - } catch (tl::CancelException & /*ex*/) { \ - return 1; \ - } catch (std::exception &ex) { \ - tl::error << ex.what (); \ - return 1; \ - } catch (tl::Exception &ex) { \ - tl::error << ex.msg (); \ - return 1; \ - } catch (...) { \ - tl::error << "unspecific error"; \ - } \ - } - -#define BD_MAIN_FUNC \ - int main_func (int argc, char *argv []) +int BD_PUBLIC _main_impl (int (*delegate) (int, char *[]), int argc, char *argv[]); } diff --git a/src/buddies/bd/bdWriterOptions.cc b/src/buddies/bd/bdWriterOptions.cc index bad4efa62..b8be30d07 100644 --- a/src/buddies/bd/bdWriterOptions.cc +++ b/src/buddies/bd/bdWriterOptions.cc @@ -212,7 +212,7 @@ GenericWriterOptions::add_options (tl::CommandLineOptions &cmd, const std::strin "* 0: create POLYLINE\n" "* 1: create LWPOLYLINE\n" "* 2: decompose into SOLID\n" - "* 3: create HATCH\n" + "* 3: create HATCH" ) ; diff --git a/src/buddies/bd/main.cc b/src/buddies/bd/main.cc new file mode 100644 index 000000000..f850d4275 --- /dev/null +++ b/src/buddies/bd/main.cc @@ -0,0 +1,39 @@ + +/* + + KLayout Layout Viewer + Copyright (C) 2006-2017 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 "bdInit.h" + +BD_PUBLIC int BD_TARGET (int argc, char *argv []); + +/** + * @brief Provides a main () implementation + * + * NOTE: + * This file is not part of the bd sources, but the template for the + * main() function of the various applications. It's configured through the + * BD_TARGET macro which is set to the application name in the app's .pro + * files. + */ +int main (int argc, char *argv []) +{ + return bd::_main_impl (&BD_TARGET, argc, argv); +} diff --git a/src/buddies/bd/strm2cif.cc b/src/buddies/bd/strm2cif.cc new file mode 100644 index 000000000..c44a68b6e --- /dev/null +++ b/src/buddies/bd/strm2cif.cc @@ -0,0 +1,29 @@ + +/* + + KLayout Layout Viewer + Copyright (C) 2006-2017 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 "bdConverterMain.h" +#include "dbCIFWriter.h" + +BD_PUBLIC int strm2cif (int argc, char *argv[]) +{ + return bd::converter_main (argc, argv, db::CIFWriterOptions ().format_name ()); +} diff --git a/src/buddies/bd/strm2dxf.cc b/src/buddies/bd/strm2dxf.cc new file mode 100644 index 000000000..6ff11ade3 --- /dev/null +++ b/src/buddies/bd/strm2dxf.cc @@ -0,0 +1,29 @@ + +/* + + KLayout Layout Viewer + Copyright (C) 2006-2017 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 "bdConverterMain.h" +#include "dbDXFWriter.h" + +BD_PUBLIC int strm2dxf (int argc, char *argv[]) +{ + return bd::converter_main (argc, argv, db::DXFWriterOptions ().format_name ()); +} diff --git a/src/buddies/bd/strm2gds.cc b/src/buddies/bd/strm2gds.cc new file mode 100644 index 000000000..0ebe07396 --- /dev/null +++ b/src/buddies/bd/strm2gds.cc @@ -0,0 +1,29 @@ + +/* + + KLayout Layout Viewer + Copyright (C) 2006-2017 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 "bdConverterMain.h" +#include "dbGDS2Writer.h" + +BD_PUBLIC int strm2gds (int argc, char *argv[]) +{ + return bd::converter_main (argc, argv, db::GDS2WriterOptions ().format_name ()); +} diff --git a/src/buddies/bd/strm2gdstxt.cc b/src/buddies/bd/strm2gdstxt.cc new file mode 100644 index 000000000..dcb8594a5 --- /dev/null +++ b/src/buddies/bd/strm2gdstxt.cc @@ -0,0 +1,29 @@ + +/* + + KLayout Layout Viewer + Copyright (C) 2006-2017 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 "bdConverterMain.h" +#include "dbGDS2Writer.h" + +BD_PUBLIC int strm2gdstxt (int argc, char *argv[]) +{ + return bd::converter_main (argc, argv, db::GDS2WriterOptions ().format_name () + "Text"); +} diff --git a/src/buddies/bd/strm2oas.cc b/src/buddies/bd/strm2oas.cc new file mode 100644 index 000000000..7853fcf61 --- /dev/null +++ b/src/buddies/bd/strm2oas.cc @@ -0,0 +1,29 @@ + +/* + + KLayout Layout Viewer + Copyright (C) 2006-2017 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 "bdConverterMain.h" +#include "dbOASISWriter.h" + +BD_PUBLIC int strm2oas (int argc, char *argv[]) +{ + return bd::converter_main (argc, argv, db::OASISWriterOptions ().format_name ()); +} diff --git a/src/buddies/strm2txt/strm2txt.cc b/src/buddies/bd/strm2txt.cc similarity index 85% rename from src/buddies/strm2txt/strm2txt.cc rename to src/buddies/bd/strm2txt.cc index 6a05edb91..22a7f8806 100644 --- a/src/buddies/strm2txt/strm2txt.cc +++ b/src/buddies/bd/strm2txt.cc @@ -20,14 +20,13 @@ */ -#include "bdInit.h" #include "bdReaderOptions.h" #include "dbLayout.h" #include "dbReader.h" #include "dbTextWriter.h" #include "tlCommandLineParser.h" -BD_MAIN_FUNC +BD_PUBLIC int strm2txt (int argc, char *argv[]) { bd::GenericReaderOptions generic_reader_options; std::string infile, outfile; @@ -35,8 +34,8 @@ BD_MAIN_FUNC tl::CommandLineOptions cmd; generic_reader_options.add_options (cmd); - cmd << tl::arg ("input", &infile, "The input file (any format, may be gzip compressed)") - << tl::arg ("output", &outfile, "The output file") + cmd << tl::arg ("input", &infile, "The input file (any format, may be gzip compressed)") + << tl::arg ("output", &outfile, "The output file (proprietary text format)") ; cmd.brief ("This program will convert the given file to a proprietary text format file"); @@ -62,5 +61,3 @@ BD_MAIN_FUNC return 0; } - -BD_MAIN diff --git a/src/buddies/strmclip/strmclip.cc b/src/buddies/bd/strmclip.cc similarity index 97% rename from src/buddies/strmclip/strmclip.cc rename to src/buddies/bd/strmclip.cc index 24ee33d0a..e329b5242 100644 --- a/src/buddies/strmclip/strmclip.cc +++ b/src/buddies/bd/strmclip.cc @@ -20,7 +20,6 @@ */ -#include "bdInit.h" #include "bdReaderOptions.h" #include "bdWriterOptions.h" #include "dbClip.h" @@ -165,12 +164,10 @@ void clip (const ClipData &data) writer.write (target_layout, stream); } -BD_MAIN_FUNC +BD_PUBLIC int strmclip (int argc, char *argv[]) { ClipData data; - bd::init (); - tl::CommandLineOptions cmd; data.reader_options.add_options (cmd); data.writer_options.add_options (cmd); @@ -182,7 +179,7 @@ BD_MAIN_FUNC << tl::arg ("output", &data.file_out, "The output file", "The output format is determined from the suffix of the file. If the suffix indicates " "gzip compression, the file will be compressed on output. Examples for recognized suffixes are " - "\".oas\", \".gds.gz\", \".dxf\" or \"gds2\"." + "\".oas\", \".gds.gz\", \".dxf\" or \".gds2\"." ) << tl::arg ("-l|--clip-layer=spec", &data, &ClipData::set_clip_layer, "Specifies a layer to take the clip regions from", "If this option is given, the clip rectangles are taken from the given layer." @@ -196,7 +193,7 @@ BD_MAIN_FUNC "If given, this name will be used as the top cell name in the output file. " "By default the output's top cell will be \"CLIPPED_\" plus the input's top cell name." ) - << tl::arg ("*-r|--clip-box=l,b,r,t", &data, &ClipData::add_box, "Specifies a clip box", + << tl::arg ("*-r|--rect=\"l,b,r,t\"", &data, &ClipData::add_box, "Specifies a clip box", "This option specifies the box to clip in micrometer units. The box is given " "by left, bottom, right and top coordinates. This option can be used multiple times " "to produce a clip covering more than one rectangle." @@ -211,5 +208,3 @@ BD_MAIN_FUNC return 0; } - -BD_MAIN diff --git a/src/buddies/strmcmp/strmcmp.cc b/src/buddies/bd/strmcmp.cc similarity index 99% rename from src/buddies/strmcmp/strmcmp.cc rename to src/buddies/bd/strmcmp.cc index a59f60d4d..8f7c828ad 100644 --- a/src/buddies/strmcmp/strmcmp.cc +++ b/src/buddies/bd/strmcmp.cc @@ -20,17 +20,14 @@ */ -#include "bdInit.h" #include "bdReaderOptions.h" #include "dbLayout.h" #include "dbLayoutDiff.h" #include "dbReader.h" #include "tlCommandLineParser.h" -BD_MAIN_FUNC +BD_PUBLIC int strmcmp (int argc, char *argv[]) { - bd::init (); - bd::GenericReaderOptions generic_reader_options_a; generic_reader_options_a.set_prefix ("a"); generic_reader_options_a.set_long_prefix ("a-"); @@ -222,5 +219,3 @@ BD_MAIN_FUNC return result ? 0 : 1; } - -BD_MAIN diff --git a/src/buddies/buddy_app.pri b/src/buddies/buddy_app.pri new file mode 100644 index 000000000..4b983c378 --- /dev/null +++ b/src/buddies/buddy_app.pri @@ -0,0 +1,18 @@ + +include($$PWD/../klayout.pri) + +TEMPLATE = app + +PRO_BASENAME = $$basename(_PRO_FILE_) +TARGET = $$replace(PRO_BASENAME, ".pro", "") +DESTDIR = $$OUT_PWD/../.. + +# Since the main function is entirely unspecific, we can put it into a common +# place - it's not part of the bd sources. +SOURCES = $$PWD/bd/main.cc + +INCLUDEPATH += ../bd +DEPENDPATH += ../bd +LIBS += -L$$DESTDIR -lklayout_bd + +DEFINES += BD_TARGET=$$TARGET diff --git a/src/buddies/strm2cif.cc b/src/buddies/strm2cif.cc deleted file mode 100644 index 251a86d2e..000000000 --- a/src/buddies/strm2cif.cc +++ /dev/null @@ -1,49 +0,0 @@ - -#include "dbLayout.h" -#include "dbReader.h" -#include "dbCIFWriter.h" - -int -main (int argc, char *argv []) -{ - if (argc != 3) { - printf ("Syntax: strm2cif \n"); - return 1; - } - - std::string infile (argv[1]); - std::string outfile (argv[2]); - - try { - - db::Manager m; - db::Layout layout (&m); - db::LayerMap map; - - { - tl::InputStream stream (infile); - db::Reader reader (stream); - map = reader.read (layout); - } - - { - tl::OutputStream stream (outfile); - db::CIFWriter writer; - writer.write (layout, stream, db::SaveLayoutOptions ()); - } - - } catch (std::exception &ex) { - fprintf (stderr, "*** ERROR: %s\n", ex.what ()); - return 1; - } catch (tl::Exception &ex) { - fprintf (stderr, "*** ERROR: %s\n", ex.msg ().c_str ()); - return 1; - } catch (...) { - fprintf (stderr, "*** ERROR: unspecific error\n"); - return 1; - } - - return 0; -} - - diff --git a/src/buddies/strm2cif/strm2cif.pro b/src/buddies/strm2cif/strm2cif.pro index b90ecaa01..e04ca961a 100644 --- a/src/buddies/strm2cif/strm2cif.pro +++ b/src/buddies/strm2cif/strm2cif.pro @@ -1,13 +1,2 @@ -include($$PWD/../../klayout.pri) - -TEMPLATE = app - -TARGET = strm2cif -DESTDIR = $$OUT_PWD/../.. - -SOURCES = strm2cif.cc - -INCLUDEPATH += ../bd ../../tl ../../db ../../gsi -DEPENDPATH += ../bd ../../tl ../../db ../../gsi -LIBS += -L$$DESTDIR -lklayout_bd -lklayout_tl -lklayout_db -lklayout_gsi +include($$PWD/../buddy_app.pri) diff --git a/src/buddies/strm2dxf.cc b/src/buddies/strm2dxf.cc deleted file mode 100644 index 54fd99ed3..000000000 --- a/src/buddies/strm2dxf.cc +++ /dev/null @@ -1,49 +0,0 @@ - -#include "dbLayout.h" -#include "dbReader.h" -#include "dbDXFWriter.h" - -int -main (int argc, char *argv []) -{ - if (argc != 3) { - printf ("Syntax: strm2dxf \n"); - return 1; - } - - std::string infile (argv[1]); - std::string outfile (argv[2]); - - try { - - db::Manager m; - db::Layout layout (&m); - db::LayerMap map; - - { - tl::InputStream stream (infile); - db::Reader reader (stream); - map = reader.read (layout); - } - - { - tl::OutputStream stream (outfile); - db::DXFWriter writer; - writer.write (layout, stream, db::SaveLayoutOptions ()); - } - - } catch (std::exception &ex) { - fprintf (stderr, "*** ERROR: %s\n", ex.what ()); - return 1; - } catch (tl::Exception &ex) { - fprintf (stderr, "*** ERROR: %s\n", ex.msg ().c_str ()); - return 1; - } catch (...) { - fprintf (stderr, "*** ERROR: unspecific error\n"); - return 1; - } - - return 0; -} - - diff --git a/src/buddies/strm2dxf/strm2dxf.cc b/src/buddies/strm2dxf/strm2dxf.cc deleted file mode 100644 index 1de3b265d..000000000 --- a/src/buddies/strm2dxf/strm2dxf.cc +++ /dev/null @@ -1,72 +0,0 @@ - -/* - - KLayout Layout Viewer - Copyright (C) 2006-2017 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 "bdInit.h" -#include "bdWriterOptions.h" -#include "bdReaderOptions.h" -#include "dbLayout.h" -#include "dbReader.h" -#include "dbDXFWriter.h" -#include "tlCommandLineParser.h" - -BD_MAIN_FUNC -{ - bd::GenericWriterOptions generic_writer_options; - bd::GenericReaderOptions generic_reader_options; - std::string infile, outfile; - - tl::CommandLineOptions cmd; - generic_writer_options.add_options_for_dxf (cmd); - generic_reader_options.add_options (cmd); - - cmd << tl::arg ("input", &infile, "The input file (any format, may be gzip compressed)") - << tl::arg ("output", &outfile, "The output file") - ; - - cmd.brief ("This program will convert the given file to a DXF file"); - - cmd.parse (argc, argv); - - db::Layout layout; - - { - db::LoadLayoutOptions load_options; - generic_reader_options.configure (load_options); - - tl::InputStream stream (infile); - db::Reader reader (stream); - reader.read (layout, load_options); - } - - { - db::SaveLayoutOptions save_options; - generic_writer_options.configure (save_options, layout); - - tl::OutputStream stream (outfile); - db::DXFWriter writer; - writer.write (layout, stream, save_options); - } - - return 0; -} - -BD_MAIN diff --git a/src/buddies/strm2dxf/strm2dxf.pro b/src/buddies/strm2dxf/strm2dxf.pro index d6bbd7980..e04ca961a 100644 --- a/src/buddies/strm2dxf/strm2dxf.pro +++ b/src/buddies/strm2dxf/strm2dxf.pro @@ -1,13 +1,2 @@ -include($$PWD/../../klayout.pri) - -TEMPLATE = app - -TARGET = strm2dxf -DESTDIR = $$OUT_PWD/../.. - -SOURCES = strm2dxf.cc - -INCLUDEPATH += ../bd ../../tl ../../db ../../gsi -DEPENDPATH += ../bd ../../tl ../../db ../../gsi -LIBS += -L$$DESTDIR -lklayout_bd -lklayout_tl -lklayout_db -lklayout_gsi +include($$PWD/../buddy_app.pri) diff --git a/src/buddies/strm2gds.cc b/src/buddies/strm2gds.cc deleted file mode 100644 index 25b1a1981..000000000 --- a/src/buddies/strm2gds.cc +++ /dev/null @@ -1,49 +0,0 @@ - -#include "dbLayout.h" -#include "dbReader.h" -#include "dbGDS2Writer.h" - -int -main (int argc, char *argv []) -{ - if (argc != 3) { - printf ("Syntax: strm2gds \n"); - return 1; - } - - std::string infile (argv[1]); - std::string outfile (argv[2]); - - try { - - db::Manager m; - db::Layout layout (&m); - db::LayerMap map; - - { - tl::InputStream stream (infile); - db::Reader reader (stream); - map = reader.read (layout); - } - - { - tl::OutputStream stream (outfile); - db::GDS2Writer writer; - writer.write (layout, stream, db::SaveLayoutOptions ()); - } - - } catch (std::exception &ex) { - fprintf (stderr, "*** ERROR: %s\n", ex.what ()); - return 1; - } catch (tl::Exception &ex) { - fprintf (stderr, "*** ERROR: %s\n", ex.msg ().c_str ()); - return 1; - } catch (...) { - fprintf (stderr, "*** ERROR: unspecific error\n"); - return 1; - } - - return 0; -} - - diff --git a/src/buddies/strm2gds/strm2gds.cc b/src/buddies/strm2gds/strm2gds.cc deleted file mode 100644 index 6da35ce8e..000000000 --- a/src/buddies/strm2gds/strm2gds.cc +++ /dev/null @@ -1,72 +0,0 @@ - -/* - - KLayout Layout Viewer - Copyright (C) 2006-2017 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 "bdInit.h" -#include "bdWriterOptions.h" -#include "bdReaderOptions.h" -#include "dbLayout.h" -#include "dbReader.h" -#include "dbGDS2Writer.h" -#include "tlCommandLineParser.h" - -BD_MAIN_FUNC -{ - bd::GenericWriterOptions generic_writer_options; - bd::GenericReaderOptions generic_reader_options; - std::string infile, outfile; - - tl::CommandLineOptions cmd; - generic_writer_options.add_options_for_gds2 (cmd); - generic_reader_options.add_options (cmd); - - cmd << tl::arg ("input", &infile, "The input file (any format, may be gzip compressed)") - << tl::arg ("output", &outfile, "The output file") - ; - - cmd.brief ("This program will convert the given file to a GDS2 file"); - - cmd.parse (argc, argv); - - db::Layout layout; - - { - db::LoadLayoutOptions load_options; - generic_reader_options.configure (load_options); - - tl::InputStream stream (infile); - db::Reader reader (stream); - reader.read (layout, load_options); - } - - { - db::SaveLayoutOptions save_options; - generic_writer_options.configure (save_options, layout); - - tl::OutputStream stream (outfile); - db::GDS2Writer writer; - writer.write (layout, stream, save_options); - } - - return 0; -} - -BD_MAIN diff --git a/src/buddies/strm2gds/strm2gds.pro b/src/buddies/strm2gds/strm2gds.pro index 9f6fb2acf..e04ca961a 100644 --- a/src/buddies/strm2gds/strm2gds.pro +++ b/src/buddies/strm2gds/strm2gds.pro @@ -1,13 +1,2 @@ -include($$PWD/../../klayout.pri) - -TEMPLATE = app - -TARGET = strm2gds -DESTDIR = $$OUT_PWD/../.. - -SOURCES = strm2gds.cc - -INCLUDEPATH += ../bd ../../tl ../../db ../../gsi -DEPENDPATH += ../bd ../../tl ../../db ../../gsi -LIBS += -L$$DESTDIR -lklayout_bd -lklayout_tl -lklayout_db -lklayout_gsi +include($$PWD/../buddy_app.pri) diff --git a/src/buddies/strm2gdstxt.cc b/src/buddies/strm2gdstxt.cc deleted file mode 100644 index cc281f048..000000000 --- a/src/buddies/strm2gdstxt.cc +++ /dev/null @@ -1,49 +0,0 @@ - -#include "dbLayout.h" -#include "dbReader.h" -#include "contrib/gds2_txt/dbGDS2TextWriter.h" - -int -main (int argc, char *argv []) -{ - if (argc != 3) { - printf ("Syntax: strm2gdstxt \n"); - return 1; - } - - std::string infile (argv[1]); - std::string outfile (argv[2]); - - try { - - db::Manager m; - db::Layout layout (&m); - db::LayerMap map; - - { - tl::InputStream stream (infile); - db::Reader reader (stream); - map = reader.read (layout); - } - - { - tl::OutputStream stream (outfile); - db::GDS2WriterText writer; - writer.write (layout, stream, db::SaveLayoutOptions ()); - } - - } catch (std::exception &ex) { - fprintf (stderr, "*** ERROR: %s\n", ex.what ()); - return 1; - } catch (tl::Exception &ex) { - fprintf (stderr, "*** ERROR: %s\n", ex.msg ().c_str ()); - return 1; - } catch (...) { - fprintf (stderr, "*** ERROR: unspecific error\n"); - return 1; - } - - return 0; -} - - diff --git a/src/buddies/strm2gdstxt/strm2gdstxt.cc b/src/buddies/strm2gdstxt/strm2gdstxt.cc deleted file mode 100644 index c5be4ebe4..000000000 --- a/src/buddies/strm2gdstxt/strm2gdstxt.cc +++ /dev/null @@ -1,72 +0,0 @@ - -/* - - KLayout Layout Viewer - Copyright (C) 2006-2017 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 "bdInit.h" -#include "bdWriterOptions.h" -#include "bdReaderOptions.h" -#include "dbLayout.h" -#include "dbReader.h" -#include "contrib/dbGDS2TextWriter.h" -#include "tlCommandLineParser.h" - -BD_MAIN_FUNC -{ - bd::GenericWriterOptions generic_writer_options; - bd::GenericReaderOptions generic_reader_options; - std::string infile, outfile; - - tl::CommandLineOptions cmd; - generic_reader_options.add_options (cmd); - generic_writer_options.add_options_for_gds2 (cmd); - - cmd << tl::arg ("input", &infile, "The input file (any format, may be gzip compressed)") - << tl::arg ("output", &outfile, "The output file") - ; - - cmd.brief ("This program will convert the given file to a GDS2Text file"); - - cmd.parse (argc, argv); - - db::Layout layout; - - { - db::LoadLayoutOptions load_options; - generic_reader_options.configure (load_options); - - tl::InputStream stream (infile); - db::Reader reader (stream); - reader.read (layout, load_options); - } - - { - db::SaveLayoutOptions save_options; - generic_writer_options.configure (save_options, layout); - - tl::OutputStream stream (outfile); - db::GDS2WriterText writer; - writer.write (layout, stream, save_options); - } - - return 0; -} - -BD_MAIN diff --git a/src/buddies/strm2gdstxt/strm2gdstxt.pro b/src/buddies/strm2gdstxt/strm2gdstxt.pro index 3bd8de7cf..e04ca961a 100644 --- a/src/buddies/strm2gdstxt/strm2gdstxt.pro +++ b/src/buddies/strm2gdstxt/strm2gdstxt.pro @@ -1,13 +1,2 @@ -include($$PWD/../../klayout.pri) - -TEMPLATE = app - -TARGET = strm2gdstxt -DESTDIR = $$OUT_PWD/../.. - -SOURCES = strm2gdstxt.cc - -INCLUDEPATH += ../bd ../../tl ../../db ../../gsi -DEPENDPATH += ../bd ../../tl ../../db ../../gsi -LIBS += -L$$DESTDIR -lklayout_bd -lklayout_tl -lklayout_db -lklayout_gsi +include($$PWD/../buddy_app.pri) diff --git a/src/buddies/strm2oas.cc b/src/buddies/strm2oas.cc deleted file mode 100644 index 8376b6bc3..000000000 --- a/src/buddies/strm2oas.cc +++ /dev/null @@ -1,108 +0,0 @@ - -#include "dbLayout.h" -#include "dbReader.h" -#include "dbOASISWriter.h" -#include "tlTimer.h" - -#include - -void -syntax () -{ - printf ("Syntax: strm2oas [-o ] [-c] \n"); - printf ("\n"); - printf (" -o n Specify optimization level (0..10, default is 2)\n"); - printf (" -c Use CBLOCK compression\n"); - printf (" -s Use strict mode\n"); - printf (" -r Recompression (ignore existing arrays)\n"); - printf (" -v Verbose - print timing information\n"); -} - -int -main (int argc, char *argv []) -{ - std::string infile, outfile; - bool verbose = false; - - try { - - db::OASISWriterOptions writer_options; - - for (int i = 1; i < argc; ++i) { - std::string o (argv[i]); - if (o == "-o") { - if (i < argc - 1) { - ++i; - tl::from_string (argv[i], writer_options.compression_level); - } - } else if (o == "-v") { - verbose = true; - } else if (o == "-c") { - writer_options.write_cblocks = true; - } else if (o == "-s") { - writer_options.strict_mode = true; - } else if (o == "-r") { - writer_options.recompress = true; - } else if (o == "-h" || o == "-help" || o == "--help") { - syntax (); - return 0; - } else if (argv[i][0] == '-') { - throw tl::Exception ("Unknown option: %s - use '-h' for help", (const char *) argv[i]); - } else if (infile.empty ()) { - infile = argv[i]; - } else if (outfile.empty ()) { - outfile = argv[i]; - } else { - throw tl::Exception ("Superfluous argument: %s - use '-h' for help", (const char *) argv[i]); - } - } - - if (infile.empty ()) { - throw tl::Exception ("Input file not given"); - } - if (outfile.empty ()) { - throw tl::Exception ("Output file not given"); - } - - db::Manager m; - db::Layout layout (false, &m); - db::LayerMap map; - - { - std::auto_ptr timer; - if (verbose) { - timer.reset (new tl::SelfTimer ("Reading input layout")); - } - tl::InputStream stream (infile); - db::Reader reader (stream); - map = reader.read (layout); - } - - { - db::SaveLayoutOptions options; - options.set_specific_options (writer_options); - - std::auto_ptr timer; - if (verbose) { - timer.reset (new tl::SelfTimer ("Writing OAS")); - } - tl::OutputStream stream (outfile); - db::OASISWriter writer; - writer.write (layout, stream, options); - } - - } catch (std::exception &ex) { - fprintf (stderr, "*** ERROR: %s\n", ex.what ()); - return 1; - } catch (tl::Exception &ex) { - fprintf (stderr, "*** ERROR: %s\n", ex.msg ().c_str ()); - return 1; - } catch (...) { - fprintf (stderr, "*** ERROR: unspecific error\n"); - return 1; - } - - return 0; -} - - diff --git a/src/buddies/strm2oas/strm2oas.cc b/src/buddies/strm2oas/strm2oas.cc deleted file mode 100644 index 7832e2747..000000000 --- a/src/buddies/strm2oas/strm2oas.cc +++ /dev/null @@ -1,72 +0,0 @@ - -/* - - KLayout Layout Viewer - Copyright (C) 2006-2017 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 "bdInit.h" -#include "bdWriterOptions.h" -#include "bdReaderOptions.h" -#include "dbLayout.h" -#include "dbReader.h" -#include "dbOASISWriter.h" -#include "tlCommandLineParser.h" - -BD_MAIN_FUNC -{ - bd::GenericWriterOptions generic_writer_options; - bd::GenericReaderOptions generic_reader_options; - std::string infile, outfile; - - tl::CommandLineOptions cmd; - generic_reader_options.add_options (cmd); - generic_writer_options.add_options_for_oasis (cmd); - - cmd << tl::arg ("input", &infile, "The input file (any format, may be gzip compressed)") - << tl::arg ("output", &outfile, "The output file") - ; - - cmd.brief ("This program will convert the given file to an OASIS file"); - - cmd.parse (argc, argv); - - db::Layout layout; - - { - db::LoadLayoutOptions load_options; - generic_reader_options.configure (load_options); - - tl::InputStream stream (infile); - db::Reader reader (stream); - reader.read (layout, load_options); - } - - { - db::SaveLayoutOptions save_options; - generic_writer_options.configure (save_options, layout); - - tl::OutputStream stream (outfile); - db::OASISWriter writer; - writer.write (layout, stream, save_options); - } - - return 0; -} - -BD_MAIN diff --git a/src/buddies/strm2oas/strm2oas.pro b/src/buddies/strm2oas/strm2oas.pro index 0f72fe651..e04ca961a 100644 --- a/src/buddies/strm2oas/strm2oas.pro +++ b/src/buddies/strm2oas/strm2oas.pro @@ -1,13 +1,2 @@ -include($$PWD/../../klayout.pri) - -TEMPLATE = app - -TARGET = strm2oas -DESTDIR = $$OUT_PWD/../.. - -SOURCES = strm2oas.cc - -INCLUDEPATH += ../bd ../../tl ../../db ../../gsi -DEPENDPATH += ../bd ../../tl ../../db ../../gsi -LIBS += -L$$DESTDIR -lklayout_bd -lklayout_tl -lklayout_db -lklayout_gsi +include($$PWD/../buddy_app.pri) diff --git a/src/buddies/strm2txt.cc b/src/buddies/strm2txt.cc deleted file mode 100644 index 76205a542..000000000 --- a/src/buddies/strm2txt.cc +++ /dev/null @@ -1,50 +0,0 @@ - -#include "dbLayout.h" -#include "dbReader.h" -#include "dbTextWriter.h" - -int -main (int argc, char *argv []) -{ - if (argc != 3) { - printf ("Syntax: strm2txt \n"); - return 1; - } - - std::string infile (argv[1]); - std::string outfile (argv[2]); - - try { - - db::Manager m; - db::Layout layout (&m); - db::LayerMap map; - - { - tl::InputStream stream (infile); - db::Reader reader (stream); - reader.set_warnings_as_errors (true); - map = reader.read (layout); - } - - { - tl::OutputStream stream (outfile); - db::TextWriter writer (stream); - writer.write (layout); - } - - } catch (std::exception &ex) { - fprintf (stderr, "*** ERROR: %s\n", ex.what ()); - return 1; - } catch (tl::Exception &ex) { - fprintf (stderr, "*** ERROR: %s\n", ex.msg ().c_str ()); - return 1; - } catch (...) { - fprintf (stderr, "*** ERROR: unspecific error\n"); - return 1; - } - - return 0; -} - - diff --git a/src/buddies/strm2txt/strm2txt.pro b/src/buddies/strm2txt/strm2txt.pro index 5f0a41326..e04ca961a 100644 --- a/src/buddies/strm2txt/strm2txt.pro +++ b/src/buddies/strm2txt/strm2txt.pro @@ -1,13 +1,2 @@ -include($$PWD/../../klayout.pri) - -TEMPLATE = app - -TARGET = strm2txt -DESTDIR = $$OUT_PWD/../.. - -SOURCES = strm2txt.cc - -INCLUDEPATH += ../bd ../../tl ../../db ../../gsi -DEPENDPATH += ../bd ../../tl ../../db ../../gsi -LIBS += -L$$DESTDIR -lklayout_bd -lklayout_tl -lklayout_db -lklayout_gsi +include($$PWD/../buddy_app.pri) diff --git a/src/buddies/strmclip.cc b/src/buddies/strmclip.cc deleted file mode 100644 index e9fa18a51..000000000 --- a/src/buddies/strmclip.cc +++ /dev/null @@ -1,235 +0,0 @@ - - -#include "dbClip.h" -#include "dbLayout.h" -#include "dbGDS2Writer.h" -#include "dbOASISWriter.h" -#include "dbReader.h" -#include "layParsedLayerSource.h" -#include "tlLog.h" - - -struct ClipData -{ - ClipData () - : file_in (), file_out (), clip_layer (), - oasis (false), gzip (false) - { } - - std::string file_in; - std::string file_out; - lay::ParsedLayerSource clip_layer; - bool oasis; - bool gzip; - std::vector clip_boxes; - std::string result; - std::string top; -}; - - -void clip (const ClipData &data) -{ - db::Manager m; - db::Layout layout (&m); - db::Layout target_layout (&m); - - { - tl::InputStream stream (data.file_in); - db::Reader reader (stream); - reader.read (layout); - } - - // create the layers in the target layout as well - for (unsigned int i = 0; i < layout.layers (); ++i) { - if (layout.is_valid_layer (i)) { - target_layout.insert_layer (i, layout.get_properties (i)); - } - } - - // copy the properties repository in order to have the same ID mapping - target_layout.properties_repository () = layout.properties_repository (); - target_layout.dbu (layout.dbu ()); - - // look for the clip layer - int clip_layer_index = -1; - for (unsigned int i = 0; i < layout.layers (); ++i) { - if (layout.is_valid_layer (i) && data.clip_layer.match (layout.get_properties (i))) { - clip_layer_index = int (i); - break; - } - } - - tl::log << "Clip layer index is " << clip_layer_index; - - // get top cells - std::vector top_cells; - if (data.top.empty ()) { - top_cells.assign (layout.begin_top_down (), layout.end_top_cells ()); - } else { - std::pair tc = layout.cell_by_name (data.top.c_str ()); - if (! tc.first) { - throw tl::Exception ("Cell %s is not a valid cell in the input layout", data.top); - } - top_cells.push_back (tc.second); - } - - // go through the top cells - for (std::vector ::const_iterator tc = top_cells.begin (); tc != top_cells.end (); ++tc) { - - std::vector clip_boxes; - - // add the explicit boxes first - for (std::vector ::const_iterator b = data.clip_boxes.begin (); b != data.clip_boxes.end (); ++b) { - clip_boxes.push_back (db::Box::from_double (*b * (1.0 / layout.dbu ()))); - } - - // fetch the boxes of the clip shapes - if (clip_layer_index >= 0) { - collect_clip_boxes (layout, *tc, clip_layer_index, clip_boxes); - } - - // sort our duplicate boxes - std::sort (clip_boxes.begin (), clip_boxes.end ()); - clip_boxes.erase (std::unique (clip_boxes.begin (), clip_boxes.end ()), clip_boxes.end ()); - - tl::log << "Clip boxes are:"; - for (std::vector ::const_iterator cbx = clip_boxes.begin (); cbx != clip_boxes.end (); ++cbx) { - tl::log << " " << cbx->to_string (); - } - - std::vector new_cells = db::clip_layout (layout, target_layout, *tc, clip_boxes); - - // create "very top" cells to put the result cells into - std::string result_top; - if (! data.result.empty ()) { - result_top = data.result; - } else { - result_top = std::string ("CLIPPED_") + layout.cell_name (*tc); - } - db::cell_index_type clip_top = target_layout.add_cell (result_top.c_str ()); - db::Cell &clip_top_cell = target_layout.cell (clip_top); - - for (std::vector ::const_iterator cc = new_cells.begin (); cc != new_cells.end (); ++cc) { - clip_top_cell.insert (db::CellInstArray (db::CellInst (*cc), db::Trans ())); - } - - } - - // write the layout - tl::OutputStreamBase *out_file = 0; - try { - - tl::OutputStream stream (data.file_out, data.gzip ? tl::OutputStream::OM_Zlib : tl::OutputStream::OM_Plain); - - if (data.oasis) { - db::OASISWriter writer; - writer.write (target_layout, stream, db::SaveLayoutOptions ()); - } else { - db::GDS2Writer writer; - writer.write (target_layout, stream, db::SaveLayoutOptions ()); - } - - delete out_file; - - } catch (...) { - if (out_file) { - delete out_file; - } - throw; - } -} - -void print_syntax () -{ - printf ("Syntax: strmclip [] \n"); - printf ("\n"); - printf ("Options are:\n"); - printf (" -l 'l/d' take clip regions from layer l, datatype d\n"); - printf (" -o produce oasis output\n"); - printf (" -g produce gds output\n"); - printf (" -z gzip output\n"); - printf (" -t 'cell' use this cell from input (default: determine top cell automatically)\n"); - printf (" -x 'name' use this cell as top cell in output\n"); - printf (" -r 'l,b,r,t' explicitly specify a clip retangle (can be present multiple times)\n"); -} - -int -main (int argc, char *argv []) -{ - try { - - ClipData data; - - for (int n = 1; n < argc; ++n) { - - if (std::string (argv [n]) == "-h") { - print_syntax (); - return 0; - } else if (std::string (argv [n]) == "-o") { - data.oasis = true; - } else if (std::string (argv [n]) == "-g") { - data.oasis = false; - } else if (std::string (argv [n]) == "-z") { - data.gzip = true; - } else if (std::string (argv [n]) == "-x") { - if (n < argc + 1) { - ++n; - data.result = argv [n]; - } - } else if (std::string (argv [n]) == "-t") { - if (n < argc + 1) { - ++n; - data.top = argv [n]; - } - } else if (std::string (argv [n]) == "-r") { - if (n < argc + 1) { - ++n; - tl::Extractor ex (argv [n]); - double l = 0.0, b = 0.0, r = 0.0, t = 0.0; - ex.read (l); ex.expect (","); - ex.read (b); ex.expect (","); - ex.read (r); ex.expect (","); - ex.read (t); ex.expect_end (); - data.clip_boxes.push_back (db::DBox (l, b, r, t)); - } - } else if (std::string (argv [n]) == "-l") { - if (n < argc + 1) { - ++n; - data.clip_layer = lay::ParsedLayerSource (argv [n]); - } - } else if (argv [n][0] == '-') { - print_syntax (); - throw tl::Exception ("Unknown option: " + std::string (argv [n])); - } else if (data.file_in.empty ()) { - data.file_in = argv [n]; - } else if (data.file_out.empty ()) { - data.file_out = argv [n]; - } else { - print_syntax (); - throw tl::Exception ("Superfluous command element: " + std::string (argv [n])); - } - - } - - if (data.file_in.empty () || data.file_out.empty ()) { - print_syntax (); - throw tl::Exception ("Input or output file name missing"); - } - - clip (data); - - } catch (std::exception &ex) { - tl::error << ex.what (); - return 1; - } catch (tl::Exception &ex) { - tl::error << ex.msg (); - return 1; - } catch (...) { - tl::error << "unspecific error"; - return 1; - } - - return 0; -} - - diff --git a/src/buddies/strmclip/strmclip.pro b/src/buddies/strmclip/strmclip.pro index 1b589be8b..e04ca961a 100644 --- a/src/buddies/strmclip/strmclip.pro +++ b/src/buddies/strmclip/strmclip.pro @@ -1,13 +1,2 @@ -include($$PWD/../../klayout.pri) - -TEMPLATE = app - -TARGET = strmclip -DESTDIR = $$OUT_PWD/../.. - -SOURCES = strmclip.cc - -INCLUDEPATH += ../bd ../../tl ../../db ../../gsi -DEPENDPATH += ../bd ../../tl ../../db ../../gsi -LIBS += -L$$DESTDIR -lklayout_bd -lklayout_tl -lklayout_db -lklayout_gsi +include($$PWD/../buddy_app.pri) diff --git a/src/buddies/strmcmp.cc b/src/buddies/strmcmp.cc deleted file mode 100644 index bbfae5767..000000000 --- a/src/buddies/strmcmp.cc +++ /dev/null @@ -1,54 +0,0 @@ - - -#include "dbLayout.h" -#include "dbLayoutDiff.h" -#include "dbReader.h" - -int -main (int argc, char *argv []) -{ - if (argc != 3) { - printf ("Syntax: strmcmp \n"); - return 1; - } - - std::string infile_a (argv[1]); - std::string infile_b (argv[2]); - - try { - - db::Manager m; - db::Layout layout_a (false, &m); - db::Layout layout_b (false, &m); - - { - tl::InputStream stream (infile_a); - db::Reader reader (stream); - reader.read (layout_a); - } - - { - tl::InputStream stream (infile_b); - db::Reader reader (stream); - reader.read (layout_b); - } - - if (! db::compare_layouts (layout_a, layout_b, db::layout_diff::f_boxes_as_polygons | db::layout_diff::f_no_text_orientation | db::layout_diff::f_verbose)) { - throw tl::Exception ("layouts differ"); - } - - } catch (std::exception &ex) { - tl::error << ex.what (); - return 1; - } catch (tl::Exception &ex) { - tl::error << ex.msg (); - return 1; - } catch (...) { - tl::error << "unspecific error"; - return 1; - } - - return 0; -} - - diff --git a/src/buddies/strmcmp/strmcmp.pro b/src/buddies/strmcmp/strmcmp.pro index 94633f5af..e04ca961a 100644 --- a/src/buddies/strmcmp/strmcmp.pro +++ b/src/buddies/strmcmp/strmcmp.pro @@ -1,13 +1,2 @@ -include($$PWD/../../klayout.pri) - -TEMPLATE = app - -TARGET = strmcmp -DESTDIR = $$OUT_PWD/../.. - -SOURCES = strmcmp.cc - -INCLUDEPATH += ../bd ../../tl ../../db ../../gsi -DEPENDPATH += ../bd ../../tl ../../db ../../gsi -LIBS += -L$$DESTDIR -lklayout_bd -lklayout_tl -lklayout_db -lklayout_gsi +include($$PWD/../buddy_app.pri) diff --git a/src/buddies/strmxor.cc b/src/buddies/strmxor.cc deleted file mode 100644 index 107d34a51..000000000 --- a/src/buddies/strmxor.cc +++ /dev/null @@ -1,215 +0,0 @@ - - -#include "dbLayout.h" -#include "dbReader.h" -#include "dbWriter.h" -#include "dbEdgeProcessor.h" -#include "tlString.h" - -void -syntax () -{ - printf ("Syntax: strmxor [-u ] [-topa ] [-topb ] [-oasis|-oas] [-gds2|-gds] []\n"); -} - -int -main (int argc, char *argv []) -{ - std::string topcell_a; - std::string topcell_b; - std::string infile_a; - std::string infile_b; - std::string outfile; - double undersize = 0.0; - bool format_set = false; - std::string format; - - int ret = 0; - - try { - - for (int i = 1; i < argc; ++i) { - std::string o (argv[i]); - if (o == "-u") { - if (i < argc - 1) { - ++i; - tl::from_string (argv[i], undersize); - } - } else if (o == "-topa") { - if (i < argc - 1) { - ++i; - topcell_a = argv[i]; - } - } else if (o == "-topb") { - if (i < argc - 1) { - ++i; - topcell_b = argv[i]; - } - } else if (o == "-oasis" || o == "-oas") { - format_set = true; - format = "OASIS"; - } else if (o == "-gds2" || o == "-gds") { - format_set = true; - format = "GDS2"; - } else if (o == "-h" || o == "-help" || o == "--help") { - syntax (); - return 0; - } else if (argv[i][0] == '-') { - throw tl::Exception("Unknown option: %s - use '-h' for help", (const char *) argv[i]); - } else if (infile_a.empty ()) { - infile_a = argv[i]; - } else if (infile_b.empty ()) { - infile_b = argv[i]; - } else if (outfile.empty ()) { - outfile = argv[i]; - } else { - throw tl::Exception("Superfluous argument: %s - use '-h' for help", (const char *) argv[i]); - } - } - - if (infile_a.empty () || infile_b.empty ()) { - throw tl::Exception("Both input files must be specified"); - } - - db::Manager m; - db::Layout layout_a (&m); - db::Layout layout_b (&m); - - { - tl::InputStream stream (infile_a); - db::Reader reader (stream); - reader.read (layout_a); - } - - { - tl::InputStream stream (infile_b); - db::Reader reader (stream); - reader.read (layout_b); - } - - db::cell_index_type top_a; - if (topcell_a.empty ()) { - db::Layout::top_down_iterator t = layout_a.begin_top_down (); - if (t == layout_a.end_top_cells ()) { - throw tl::Exception ("Layout A (%s) does not have a top cell", infile_a); - } - top_a = *t++; - if (t != layout_a.end_top_cells ()) { - throw tl::Exception ("Layout A (%s) has multiple top cells", infile_a); - } - } else { - std::pair cn = layout_a.cell_by_name (topcell_a.c_str ()); - if (! cn.first) { - throw tl::Exception ("Layout A (%s) does not have a topcell called '%s'", infile_a, topcell_a); - } - top_a = cn.second; - } - - db::cell_index_type top_b; - if (topcell_b.empty ()) { - db::Layout::top_down_iterator t = layout_b.begin_top_down (); - if (t == layout_b.end_top_cells ()) { - throw tl::Exception ("Layout B (%s) does not have a top cell", infile_b); - } - top_b = *t++; - if (t != layout_b.end_top_cells ()) { - throw tl::Exception ("Layout B (%s) has multiple top cells", infile_b); - } - } else { - std::pair cn = layout_b.cell_by_name (topcell_b.c_str ()); - if (! cn.first) { - throw tl::Exception ("Layout B (%s) does not have a topcell called '%s'", infile_b, topcell_b); - } - top_b = cn.second; - } - - if (fabs (layout_a.dbu () - layout_b.dbu ()) > 1e-6) { - throw tl::Exception("Input file database units differ (A:%g vs. B:%g)", layout_a.dbu (), layout_b.dbu ()); - } - - std::map > all_layers; - for (unsigned int i = 0; i < layout_a.layers (); ++i) { - if (layout_a.is_valid_layer (i)) { - all_layers.insert (std::make_pair(layout_a.get_properties (i), std::make_pair(-1, -1))).first->second.first = int (i); - } - } - for (unsigned int i = 0; i < layout_b.layers (); ++i) { - if (layout_b.is_valid_layer (i)) { - all_layers.insert (std::make_pair(layout_b.get_properties (i), std::make_pair(-1, -1))).first->second.second = int (i); - } - } - - db::Layout output; - output.dbu (layout_a.dbu ()); - db::cell_index_type top_id = output.add_cell (layout_a.cell_name (top_a)); - - db::Coord us = db::coord_traits::rounded (undersize / layout_a.dbu ()); - - db::ShapeProcessor sp; - - size_t ndiff = 0; - - for (std::map >::const_iterator l = all_layers.begin (); l != all_layers.end (); ++l) { - - int layer_id = output.insert_layer (l->first); - - if (l->second.first >= 0 && l->second.second >= 0) { - - sp.boolean (layout_a, layout_a.cell (top_a), l->second.first, layout_b, layout_b.cell (top_b), l->second.second, - output.cell (top_id).shapes (layer_id), db::BooleanOp::Xor, true /*recursive*/); - - sp.size (output, output.cell (top_id), layer_id, output.cell (top_id).shapes (layer_id), -us, (unsigned int) 2, true /*recursive*/); - - } else if (l->second.first >= 0) { - - sp.size (layout_a, layout_a.cell (top_a), l->second.first, output.cell (top_id).shapes (layer_id), -us, (unsigned int) 2, true /*recursive*/); - - } else if (l->second.second >= 0) { - - sp.size (layout_b, layout_b.cell (top_b), l->second.second, output.cell (top_id).shapes (layer_id), -us, (unsigned int) 2, true /*recursive*/); - - } - - size_t n = output.cell (top_id).shapes (layer_id).size (); - // if (n > 0) { - ndiff += n; - tl::info << " " << l->first.to_string () << ": " << n; - // } - - } - - if (ndiff > 0) { - tl::info << "----------------------------------------------------"; - tl::info << " Total differences: " << ndiff; - ret = 1; - } - - if (! outfile.empty ()) { - - db::SaveLayoutOptions options; - options.set_format_from_filename (outfile); - if (format_set) { - options.set_format (format); - } - - db::Writer writer (options); - tl::OutputStream file (outfile, tl::OutputStream::OM_Auto); - writer.write (output, file); - - } - - } catch (std::exception &ex) { - tl::error << ex.what (); - return 1; - } catch (tl::Exception &ex) { - tl::error << ex.msg (); - return 1; - } catch (...) { - tl::error << "unspecific error"; - return 1; - } - - return ret; -} - - diff --git a/src/tl/tlCommandLineParser.cc b/src/tl/tlCommandLineParser.cc index 6aaacd963..27eadf24d 100644 --- a/src/tl/tlCommandLineParser.cc +++ b/src/tl/tlCommandLineParser.cc @@ -66,16 +66,16 @@ ArgBase::ParsedOption::ParsedOption (const std::string &option) optional = true; ex.read_word (long_option, "_-"); if (ex.test ("=")) { - ex.read_word (name); + ex.read_word_or_quoted (name); } } else if (ex.test ("-")) { optional = true; ex.read_word (short_option, ""); if (ex.test ("=")) { - ex.read_word (name); + ex.read_word_or_quoted (name); } } else { - ex.read_word (name); + ex.read_word_or_quoted (name); } ex.test("|"); }