Skip to content

Commit

Permalink
Add markup2gds CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-fritchman committed Jan 12, 2023
1 parent e16d1e3 commit adc117a
Show file tree
Hide file tree
Showing 10 changed files with 194 additions and 128 deletions.
7 changes: 1 addition & 6 deletions gds21/resources/gds21.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -682,11 +682,6 @@
"title": "Gds Translation Settings",
"description": "Reflection, rotation, and magnification for text-elements and references. As configured by `STRANS` records.",
"type": "object",
"required": [
"abs_angle",
"abs_mag",
"reflected"
],
"properties": {
"abs_angle": {
"description": "Absolute Angle Setting",
Expand All @@ -705,7 +700,7 @@
"format": "double"
},
"mag": {
"description": "Magnification Factor. Defaults to 1.0 if not specified.",
"description": "Magnification Factor. Interpreted as unit-scaling (mag==1.0) if not specified.",
"type": [
"number",
"null"
Expand Down
17 changes: 13 additions & 4 deletions gds21/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,22 +251,23 @@ impl GdsFloat64 {
#[derive(Default, Debug, Clone, Deserialize, Serialize, JsonSchema, PartialEq, Eq)]
pub struct Unsupported;


/// # Gds Translation Settings
/// Reflection, rotation, and magnification for text-elements and references.
/// As configured by `STRANS` records.
#[derive(Default, Clone, Debug, Deserialize, Serialize, JsonSchema, PartialEq)]
pub struct GdsStrans {
// Required Fields
/// Reflection, about the x-axis.
/// Applied before rotation.
#[serde(default, skip_serializing_if = "is_false")]
pub reflected: bool,
/// Absolute Magnification Setting
#[serde(default, skip_serializing_if = "is_false")]
pub abs_mag: bool,
/// Absolute Angle Setting
#[serde(default, skip_serializing_if = "is_false")]
pub abs_angle: bool,

// Optional Fields
/// Magnification Factor. Defaults to 1.0 if not specified.
/// Magnification Factor. Interpreted as unit-scaling (mag==1.0) if not specified.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub mag: Option<f64>,
/// Angle, in degrees counter-clockwise. Defaults to zero if not specified.
Expand Down Expand Up @@ -553,6 +554,7 @@ pub struct GdsArrayRef {
pub cols: i16,
/// Number of rows
pub rows: i16,

// Optional Fields
/// Translation & Reflection Options
#[serde(default, skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -1147,6 +1149,13 @@ impl From<layout21utils::ser::Error> for GdsError {
}
}

/// Our helper for "do not serialize default `false` boolean values".
/// This is a function primarily because those are what `#[serde(skip_serializing_if)]` understands.
/// (Or at least what we understand how to make it understand).
fn is_false(b:& bool) -> bool {
!b
}

#[cfg(any(test, feature = "selftest"))]
/// Check `lib` matches across a write-read round-trip cycle
pub fn roundtrip(lib: &GdsLibrary) -> GdsResult<()> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,6 @@
"y": 0
},
"strans": {
"reflected": false,
"abs_mag": false,
"abs_angle": false,
"mag": 0.1,
"angle": 90.0
}
Expand Down Expand Up @@ -5045,9 +5042,6 @@
5
],
"strans": {
"reflected": false,
"abs_mag": false,
"abs_angle": false,
"mag": 0.1
}
}
Expand All @@ -5066,9 +5060,6 @@
5
],
"strans": {
"reflected": false,
"abs_mag": false,
"abs_angle": false,
"mag": 0.1
}
}
Expand All @@ -5087,9 +5078,6 @@
5
],
"strans": {
"reflected": false,
"abs_mag": false,
"abs_angle": false,
"mag": 0.1
}
}
Expand All @@ -5108,9 +5096,6 @@
5
],
"strans": {
"reflected": false,
"abs_mag": false,
"abs_angle": false,
"mag": 0.1
}
}
Expand All @@ -5129,9 +5114,6 @@
5
],
"strans": {
"reflected": false,
"abs_mag": false,
"abs_angle": false,
"mag": 0.2
}
}
Expand All @@ -5150,9 +5132,6 @@
5
],
"strans": {
"reflected": false,
"abs_mag": false,
"abs_angle": false,
"mag": 0.2
}
}
Expand All @@ -5171,9 +5150,6 @@
5
],
"strans": {
"reflected": false,
"abs_mag": false,
"abs_angle": false,
"mag": 0.1
}
}
Expand All @@ -5192,9 +5168,6 @@
5
],
"strans": {
"reflected": false,
"abs_mag": false,
"abs_angle": false,
"mag": 0.1
}
}
Expand All @@ -5213,9 +5186,6 @@
5
],
"strans": {
"reflected": false,
"abs_mag": false,
"abs_angle": false,
"mag": 0.1
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ structs:
x: 0
y: 0
strans:
reflected: false
abs_mag: false
abs_angle: false
mag: 0.1
angle: 90.0
- GdsBoundary:
Expand Down Expand Up @@ -2545,9 +2542,6 @@ structs:
- 0
- 5
strans:
reflected: false
abs_mag: false
abs_angle: false
mag: 0.1
- GdsTextElem:
string: VPB
Expand All @@ -2560,9 +2554,6 @@ structs:
- 0
- 5
strans:
reflected: false
abs_mag: false
abs_angle: false
mag: 0.1
- GdsTextElem:
string: VNB
Expand All @@ -2575,9 +2566,6 @@ structs:
- 0
- 5
strans:
reflected: false
abs_mag: false
abs_angle: false
mag: 0.1
- GdsTextElem:
string: VNB
Expand All @@ -2590,9 +2578,6 @@ structs:
- 0
- 5
strans:
reflected: false
abs_mag: false
abs_angle: false
mag: 0.1
- GdsTextElem:
string: Q
Expand All @@ -2605,9 +2590,6 @@ structs:
- 0
- 5
strans:
reflected: false
abs_mag: false
abs_angle: false
mag: 0.2
- GdsTextElem:
string: CLK
Expand All @@ -2620,9 +2602,6 @@ structs:
- 0
- 5
strans:
reflected: false
abs_mag: false
abs_angle: false
mag: 0.2
- GdsTextElem:
string: D
Expand All @@ -2635,9 +2614,6 @@ structs:
- 0
- 5
strans:
reflected: false
abs_mag: false
abs_angle: false
mag: 0.1
- GdsTextElem:
string: VPWR
Expand All @@ -2650,9 +2626,6 @@ structs:
- 0
- 5
strans:
reflected: false
abs_mag: false
abs_angle: false
mag: 0.1
- GdsTextElem:
string: VGND
Expand All @@ -2665,9 +2638,6 @@ structs:
- 0
- 5
strans:
reflected: false
abs_mag: false
abs_angle: false
mag: 0.1
- GdsBoundary:
layer: 64
Expand Down
14 changes: 7 additions & 7 deletions layout21converters/src/bin/gds2json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use clap::Parser;
use std::error::Error;

// Use our own crate, note by name, not `crate::` or `super::`.
use layout21converters::gds_serialization::{convert, ConvOptions};
use layout21converters::gds_serialization::{to_markup, ToMarkupOptions};

// => The doc-comment on `ProgramOptions` here is displayed by the `clap`-generated help docs =>

Expand All @@ -27,10 +27,10 @@ pub struct ProgramOptions {
pub verbose: bool,
}

impl Into<ConvOptions> for ProgramOptions {
/// Convert into the [`gds_serialization::ConvOptions`] struct.
fn into(self) -> ConvOptions {
ConvOptions {
impl Into<ToMarkupOptions> for ProgramOptions {
/// Convert into the [`gds_serialization::ToMarkupOptions`] struct.
fn into(self) -> ToMarkupOptions {
ToMarkupOptions {
gds: self.gds,
fmt: "json".to_string(), // <= this is kinda the whole program right here!
out: self.out,
Expand All @@ -40,8 +40,8 @@ impl Into<ConvOptions> for ProgramOptions {
}

/// Main entry point.
/// Parses the command-line arguments and calls [`gds_serialization::convert`].
/// Parses the command-line arguments and calls [`gds_serialization::to_markup`].
pub fn main() -> Result<(), Box<dyn Error>> {
let options = ProgramOptions::parse();
convert(&options.into())
to_markup(&options.into())
}
14 changes: 7 additions & 7 deletions layout21converters/src/bin/gds2markup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use clap::Parser;
use std::error::Error;

// Use our own crate, note by name, not `crate::` or `super::`.
use layout21converters::gds_serialization::{convert, ConvOptions};
use layout21converters::gds_serialization::{to_markup, ToMarkupOptions};

// => The doc-comment on `ProgramOptions` here is displayed by the `clap`-generated help docs =>

Expand All @@ -30,10 +30,10 @@ pub struct ProgramOptions {
pub verbose: bool,
}

impl Into<ConvOptions> for ProgramOptions {
/// Convert into the [`gds_serialization::ConvOptions`] struct.
fn into(self) -> ConvOptions {
ConvOptions {
impl Into<ToMarkupOptions> for ProgramOptions {
/// Convert into the [`gds_serialization::ToMarkupOptions`] struct.
fn into(self) -> ToMarkupOptions {
ToMarkupOptions {
gds: self.gds,
fmt: self.fmt,
out: self.out,
Expand All @@ -43,8 +43,8 @@ impl Into<ConvOptions> for ProgramOptions {
}

/// Main entry point.
/// Parses the command-line arguments and calls [`gds_serialization::convert`].
/// Parses the command-line arguments and calls [`gds_serialization::to_markup`].
pub fn main() -> Result<(), Box<dyn Error>> {
let options = ProgramOptions::parse();
convert(&options.into())
to_markup(&options.into())
}
14 changes: 7 additions & 7 deletions layout21converters/src/bin/gds2toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use clap::Parser;
use std::error::Error;

// Use our own crate, note by name, not `crate::` or `super::`.
use layout21converters::gds_serialization::{convert, ConvOptions};
use layout21converters::gds_serialization::{to_markup, ToMarkupOptions};

// => The doc-comment on `ProgramOptions` here is displayed by the `clap`-generated help docs =>

Expand All @@ -27,10 +27,10 @@ pub struct ProgramOptions {
pub verbose: bool,
}

impl Into<ConvOptions> for ProgramOptions {
/// Convert into the [`gds_serialization::ConvOptions`] struct.
fn into(self) -> ConvOptions {
ConvOptions {
impl Into<ToMarkupOptions> for ProgramOptions {
/// Convert into the [`gds_serialization::ToMarkupOptions`] struct.
fn into(self) -> ToMarkupOptions {
ToMarkupOptions {
gds: self.gds,
fmt: "toml".to_string(), // <= this is kinda the whole program right here!
out: self.out,
Expand All @@ -40,8 +40,8 @@ impl Into<ConvOptions> for ProgramOptions {
}

/// Main entry point.
/// Parses the command-line arguments and calls [`gds_serialization::convert`].
/// Parses the command-line arguments and calls [`gds_serialization::to_markup`].
pub fn main() -> Result<(), Box<dyn Error>> {
let options = ProgramOptions::parse();
convert(&options.into())
to_markup(&options.into())
}
Loading

0 comments on commit adc117a

Please sign in to comment.