diff --git a/Boolean.go b/Boolean.go new file mode 100644 index 0000000..0f4dfaf --- /dev/null +++ b/Boolean.go @@ -0,0 +1,15 @@ +package geagle + +type Boolean string + +func True() Boolean { + return "yes" +} + +func False() Boolean { + return "no" +} + +func (b Boolean) ToBool() bool { + return b == "yes" || b == "on" +} diff --git a/Grid.go b/Grid.go new file mode 100644 index 0000000..2be86ca --- /dev/null +++ b/Grid.go @@ -0,0 +1,27 @@ +package geagle + +type GridUnit string + +// Grid Units +const ( + GRID_INCH GridUnit = "inch" // inch + GRID_MIL = "mil" // milli inch + + GRID_MM = "mm" // milli meter + GRID_MICRONS = "mic" // micrometer +) + +// Grid definition +type Grid struct { + Distance float32 `xml:"distance,attr"` + Unitdist GridUnit `xml:"unitdist,attr"` + Unit GridUnit `xml:"unit,attr"` + Style string `xml:"style,attr"` + Multiple int `xml:"multiple,attr"` + Display Boolean `xml:"display,attr"` + + // Alternative Grid Information + AlternativeDistance float32 `xml:"altdistance,attr"` + AlternativeDistanceUnit GridUnit `xml:"altunitdist,attr"` + AlternativeUnit GridUnit `xml:"altunit,attr"` +} diff --git a/Layer.go b/Layer.go new file mode 100644 index 0000000..b0b8d3a --- /dev/null +++ b/Layer.go @@ -0,0 +1,12 @@ +package geagle + +// Layer definition +type Layer struct { + Number int `xml:"number,attr"` + Name string `xml:"name,attr"` + Color int `xml:"color,attr"` + + Fill int `xml:"fill,attr"` + Visible Boolean `xml:"visible,attr"` + Active Boolean `xml:"active,attr"` +} diff --git a/Library.go b/Library.go index a9f1885..a09f435 100644 --- a/Library.go +++ b/Library.go @@ -3,173 +3,40 @@ package geagle import ( "encoding/xml" "io" - "strconv" - "strings" ) -type Boolean string - -func True() Boolean { - return "yes" -} - -func False() Boolean { - return "no" -} - -func (b Boolean) ToBool() bool { - return b == "yes" || b == "on" -} - -type Rotation string - -func (r Rotation) Angle() int { - s := strings.TrimPrefix(string(r), "R") - v, _ := strconv.Atoi(s) - return v -} - -// Layer definition -type Layer struct { - Number int `xml:"number,attr"` - Name string `xml:"name,attr"` - Color int `xml:"color,attr"` - - Fill int `xml:"fill,attr"` - Visible Boolean `xml:"visible,attr"` - Active Boolean `xml:"active,attr"` -} - -// Grid definition -type Grid struct { - Distance float32 `xml:"distance,attr"` - Unitdist string `xml:"unitdist,attr"` - Unit string `xml:"unit,attr"` - Style string `xml:"style,attr"` - Multiple int `xml:"multiple,attr"` - Display Boolean `xml:"display,attr"` - - // Alternative Grid Information - AlternativeDistance float32 `xml:"altdistance,attr"` - AlternativeDistanceUnit string `xml:"altunitdist,attr"` - AlternativeUnit string `xml:"altunit,attr"` -} - -type Point struct { - X float32 `xml:"x,attr"` - Y float32 `xml:"y,attr"` -} -type Hole struct { - Point - Drill string `xml:"drill,attr"` -} - -type Line struct { - X1 float32 `xml:"x1,attr"` - X2 float32 `xml:"x2,attr"` - Y1 float32 `xml:"y1,attr"` - Y2 float32 `xml:"y2,attr"` -} -type Wire struct { - Line - Width float32 `xml:"width,attr"` - Layer int `xml:"layer,attr"` - Curve float64 `xml:"curve,attr,omitempty"` - Cap string `xml:"cap,attr,omitempty"` -} - -type Pad struct { - Point - Name string `xml:"name,attr"` - Drill float32 `xml:"drill,attr"` - Shape string `xml:"shape,attr"` - Rotation Rotation `xml:"rot,attr,omitempty"` -} -type SmdPad struct { - Point - Name string `xml:"name,attr"` - Width float32 `xml:"dx,attr"` - Height float32 `xml:"dy,attr"` - Layer int `xml:"layer,attr"` -} - -type Text struct { - Point - Size float32 `xml:"size,attr"` - Layer int `xml:"layer,attr"` - Alignment string `xml:"align,attr,omitempty"` - Ratio int `xml:"ratio,attr,omitempty"` - Text string `xml:",innerxml"` -} - -type Circle struct { - Point - Radius float32 `xml:"radius,attr"` - Width float32 `xml:"width,attr"` - Layer int `xml:"layer,attr"` -} - -type Rectangle struct { - Line - Layer int `xml:"layer,attr"` -} - -type Primitives struct { - Wires []Wire `xml:"wire"` - Circles []Circle `xml:"circle"` - Texts []Text `xml:"text"` - Rectangle []Rectangle `xml:"rectangle"` -} - -type Package struct { - Name string `xml:"name,attr"` - Description string `xml:"description"` - Urn string `xml:"urn,attr,omitempty"` - - Primitives - Holes []Hole `xml:"hole"` - Pads []Pad `xml:"pad"` - SmdPads []SmdPad `xml:"smd"` -} - -type Pin struct { - Point - Name string `xml:"name,attr"` - Visible string `xml:"visible,attr,omitempty"` - Length string `xml:"length,attr,omitempty"` - Direction string `xml:"direction,attr,omitempty"` - Rotation Rotation `xml:"rot,attr,omitempty"` - Function string `xml:"function,attr,omitempty"` -} - -type Symbol struct { - Name string `xml:"name,attr"` - Urn string `xml:"urn,attr,omitempty"` - - Primitives - Pins []Pin `xml:"pin"` -} - +// A Gate +// multiple gates form a device type Gate struct { Point Name string `xml:"name,attr"` Symbol string `xml:"symbol,attr"` } +// A list of technologies type Technology struct { Name string `xml:"name,attr"` } +// A connection +// Connectes Pads of one package with the pins of +// all gates a device posseses type Connection struct { Gate string `xml:"gate,attr"` Pin string `xml:"pin,attr"` Pad string `xml:"pad,attr"` } +// A 3d package +// new in Eagle 8 and above +// only contains a urn for the autodesk library service type Package3d struct { Urn string `xml:"package3d_urn,attr"` } +// A device +// bundles multiple gates and packages +// then defines how they are connected type Device struct { Name string `xml:"name,attr"` Package string `xml:"package,attr"` diff --git a/Package.go b/Package.go new file mode 100644 index 0000000..1588c5e --- /dev/null +++ b/Package.go @@ -0,0 +1,48 @@ +package geagle + +// A drill hole +type Hole struct { + Point + Drill string `xml:"drill,attr"` +} + +type PadShape string + +const ( + PAD_LONG PadShape = "long" + PAD_SQUARE = "square" + PAD_ROUND = "round" + PAD_OCTAGONAL = "octagon" + PAD_OFFSET = "offset" +) + +// A drilled pad +type Pad struct { + Point + Name string `xml:"name,attr"` + Drill float32 `xml:"drill,attr"` + Shape PadShape `xml:"shape,attr"` + Rotation Rotation `xml:"rot,attr,omitempty"` +} + +// An undrilled smd pad +type SmdPad struct { + Point + Name string `xml:"name,attr"` + Width float32 `xml:"dx,attr"` + Height float32 `xml:"dy,attr"` + Layer int `xml:"layer,attr"` +} + +// A package +// bundles all kinds of geometry shapes +type Package struct { + Name string `xml:"name,attr"` + Description string `xml:"description"` + Urn string `xml:"urn,attr,omitempty"` + + Primitives + Holes []Hole `xml:"hole"` + Pads []Pad `xml:"pad"` + SmdPads []SmdPad `xml:"smd"` +} diff --git a/Primitves.go b/Primitves.go new file mode 100644 index 0000000..a76cd90 --- /dev/null +++ b/Primitves.go @@ -0,0 +1,56 @@ +package geagle + +// An abstract Point +type Point struct { + X float32 `xml:"x,attr"` + Y float32 `xml:"y,attr"` +} + +// An abstract line +type Line struct { + X1 float32 `xml:"x1,attr"` + X2 float32 `xml:"x2,attr"` + Y1 float32 `xml:"y1,attr"` + Y2 float32 `xml:"y2,attr"` +} + +// A Wire (line with thickness) +type Wire struct { + Line + Width float32 `xml:"width,attr"` + Layer int `xml:"layer,attr"` + Curve float64 `xml:"curve,attr,omitempty"` + Cap string `xml:"cap,attr,omitempty"` +} + +// A text field +type Text struct { + Point + Size float32 `xml:"size,attr"` + Layer int `xml:"layer,attr"` + Alignment string `xml:"align,attr,omitempty"` + Ratio int `xml:"ratio,attr,omitempty"` + Text string `xml:",innerxml"` +} + +// A circle +type Circle struct { + Point + Radius float32 `xml:"radius,attr"` + Width float32 `xml:"width,attr"` + Layer int `xml:"layer,attr"` +} + +// A rectangle with two corner-points +type Rectangle struct { + Line + Layer int `xml:"layer,attr"` +} + +// bundles all geometry shapes +type Primitives struct { + Wires []Wire `xml:"wire"` + Circles []Circle `xml:"circle"` + Texts []Text `xml:"text"` + Rectangle []Rectangle `xml:"rectangle"` +} diff --git a/Rotation.go b/Rotation.go new file mode 100644 index 0000000..dde3984 --- /dev/null +++ b/Rotation.go @@ -0,0 +1,18 @@ +package geagle + +import ( + "strconv" + "strings" +) + +type Rotation string + +func (r Rotation) Angle() int { + s := strings.TrimPrefix(string(r), "R") + v, _ := strconv.Atoi(s) + return v +} + +func FromAngle(degrees int) Rotation { + return Rotation("R" + strconv.Itoa(degrees)) +} diff --git a/Symbol.go b/Symbol.go new file mode 100644 index 0000000..1c75e77 --- /dev/null +++ b/Symbol.go @@ -0,0 +1,35 @@ +package geagle + +type PinDirection string + +const ( + PinNotConnected PinDirection = "nc" + PinInput = "in" + PinOutput = "out" + PinInputOutput = "io" + PinOC = "oc" + PinPower = "pwr" + PinPassiv = "pas" + PinHighz = "hiz" + PinSupply = "sup" +) + +// A schematic pin +type Pin struct { + Point + Name string `xml:"name,attr"` + Visible string `xml:"visible,attr,omitempty"` + Length string `xml:"length,attr,omitempty"` + Direction string `xml:"direction,attr,omitempty"` + Rotation Rotation `xml:"rot,attr,omitempty"` + Function string `xml:"function,attr,omitempty"` +} + +// A schematic symbol +type Symbol struct { + Name string `xml:"name,attr"` + Urn string `xml:"urn,attr,omitempty"` + + Primitives + Pins []Pin `xml:"pin"` +}