From 7ae87404a07b3d62d41771a1d7a01ddf54150cda Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sun, 22 Feb 2026 15:16:56 +0100 Subject: [PATCH] [consider merging] Adding an option '-of|--format' to strmxor and strmclip to specify the output format instead of taking it from the suffix --- src/buddies/src/bd/bdWriterOptions.cc | 39 +++++++++++++++++++++++++++ src/buddies/src/bd/bdWriterOptions.h | 7 +++++ 2 files changed, 46 insertions(+) diff --git a/src/buddies/src/bd/bdWriterOptions.cc b/src/buddies/src/bd/bdWriterOptions.cc index dc8bc4287..8d9ccf24f 100644 --- a/src/buddies/src/bd/bdWriterOptions.cc +++ b/src/buddies/src/bd/bdWriterOptions.cc @@ -98,6 +98,20 @@ const std::string GenericWriterOptions::dxf_format_name = "DXF"; const std::string GenericWriterOptions::cif_format_name = "CIF"; const std::string GenericWriterOptions::mag_format_name = "MAG"; +std::vector +GenericWriterOptions::all_format_names () +{ + std::vector names; + names.push_back (gds2_format_name); + names.push_back (gds2text_format_name); + names.push_back (oasis_format_name); + names.push_back (lstream_format_name); + names.push_back (dxf_format_name); + names.push_back (cif_format_name); + names.push_back (mag_format_name); + return names; +} + void GenericWriterOptions::add_options (tl::CommandLineOptions &cmd, const std::string &format) { @@ -109,6 +123,15 @@ GenericWriterOptions::add_options (tl::CommandLineOptions &cmd, const std::strin "given factor." ); + if (format.empty ()) { + cmd << tl::arg (group + + "-of|--format=format", &m_format, "Specifies the output format", + "By default, the output format is derived from the file name suffix. " + "You can also specify the format directly using this option. Allowed format names are: " + + tl::join (all_format_names (), ", ") + ); + } + if (format.empty () || format == gds2_format_name || format == gds2text_format_name || format == oasis_format_name) { cmd << tl::arg (group + "-od|--dbu-out=dbu", &m_dbu, "Uses the specified database unit", @@ -426,6 +449,22 @@ GenericWriterOptions::configure (db::SaveLayoutOptions &save_options, const db:: save_options.set_keep_instances (m_keep_instances); save_options.set_write_context_info (m_write_context_info); + if (! m_format.empty ()) { + + // check, if the format name is a valid one + std::vector af = all_format_names (); + auto i = af.begin (); + while (i != af.end () && *i != m_format) { + ++i; + } + if (i == af.end ()) { + throw tl::Exception (tl::sprintf (tl::to_string (tr ("Invalid fornat name %s. Allowed names are: %s")), m_format, tl::join (af, ", "))); + } + + save_options.set_format (m_format); + + } + save_options.set_option_by_name ("gds2_max_vertex_count", m_gds2_max_vertex_count); save_options.set_option_by_name ("gds2_no_zero_length_paths", m_gds2_no_zero_length_paths); save_options.set_option_by_name ("gds2_multi_xy_records", m_gds2_multi_xy_records); diff --git a/src/buddies/src/bd/bdWriterOptions.h b/src/buddies/src/bd/bdWriterOptions.h index 67119d1d8..b0831044a 100644 --- a/src/buddies/src/bd/bdWriterOptions.h +++ b/src/buddies/src/bd/bdWriterOptions.h @@ -26,6 +26,7 @@ #include "bdCommon.h" #include +#include namespace tl { @@ -60,6 +61,11 @@ public: */ GenericWriterOptions (const db::SaveLayoutOptions &options); + /** + * @brief Gets a list with all format names available + */ + static std::vector all_format_names (); + /** * @brief Adds the generic options to the command line parser object * The format string gives a hint about the target format. Certain options will be @@ -114,6 +120,7 @@ public: static const std::string mag_format_name; private: + std::string m_format; double m_scale_factor; double m_dbu; bool m_dont_write_empty_cells;