dxf

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 13, 2019 License: MIT Imports: 18 Imported by: 0

README

dxf-go

A go package for reading and writing DXF CAD files.

Usage

Acquisition:

go get -d -t github.com/ixmilia/dxf-go
go generate github.com/ixmilia/dxf-go

Open a DXF file:

import dxf "github.com/ixmilia/dxf-go"
// ...

drawing, err := dxf.ReadFile("path/to/file.dxf")
// if err != nil

for _, entity := range drawing.Entities {
    switch ent := entity.(type) {
    case *dxf.Line:
        fmt.Printf("Line from %s to %s\n", ent.P1.String(), ent.P2.String())
    // ...
    }
}

Save a DXF file:

import dxf "github.com/ixmilia/dxf-go"
//...

drawing := *dxf.NewDrawing()
line := dxf.NewLine()
line.P1 = dxf.Point{X: 1.0, Y: 2.0, Z: 3.0}
line.P2 = dxf.Point{X: 4.0, Y: 5.0, Z: 6.0}
drawing.Entities = append(drawing.Entities, line)
// ...

err := drawing.SaveFile("path/to/file.dxf")
// if err != nil

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AcadVersion

type AcadVersion int

AcadVersion represents the minimum version of AutoCAD that is expected to be able to read the file.

const (
	// Version1_0 corresponds to the value "MC0.0"
	Version1_0 AcadVersion = iota

	// Version1_2 corresponds to the value "AC1.2"
	Version1_2

	// Version1_40 corresponds to the value "AC1.40"
	Version1_40

	// Version2_05 corresponds to the value "AC1.50"
	Version2_05

	// Version2_10 corresponds to the value "AC2.10"
	Version2_10

	// Version2_21 corresponds to the value "AC2.21"
	Version2_21

	// Version2_22 corresponds to the value "AC2.22"
	Version2_22

	// Version2_5 corresponds to the value "AC1002"
	Version2_5

	// Version2_6 corresponds to the value "AC1003"
	Version2_6

	// R9 corresponds to the value "AC1004"
	R9

	// R10 corresponds to the value "AC1006"
	R10

	// R11 corresponds to the value "AC1009"
	R11

	// R12 corresponds to the value "AC1009"
	R12

	// R13 corresponds to the value "AC1012"
	R13

	// R14 corresponds to the value "AC1014"
	R14

	// R2000 corresponds to the value "AC1015"
	R2000

	// R2004 corresponds to the value "AC1018"
	R2004

	// R2007 corresponds to the value "AC1021"
	R2007

	// R2010 corresponds to the value "AC1024"
	R2010

	// R2013 corresponds to the value "AC1027"
	R2013

	// R2018 corresponds to the value "AC1032"
	R2018
)

func (AcadVersion) String

func (v AcadVersion) String() string

type BoolCodePairValue

type BoolCodePairValue struct {
	CodePairValue
	Value bool
}

BoolCodePairValue represents a boolean code pair value.

type CodePair

type CodePair struct {
	Code  int
	Value CodePairValue
}

CodePair represents a code and value pair from a DXF drawing.

func NewBoolCodePair

func NewBoolCodePair(code int, value bool) CodePair

NewBoolCodePair creates a code pair representing a boolean value.

func NewDoubleCodePair

func NewDoubleCodePair(code int, value float64) CodePair

NewDoubleCodePair creates a code pair representing a floating point value.

func NewIntCodePair

func NewIntCodePair(code int, value int) CodePair

NewIntCodePair creates a code pair representing an integer value.

func NewLongCodePair

func NewLongCodePair(code int, value int64) CodePair

NewLongCodePair creates a code pair representing a long integer value.

func NewShortCodePair

func NewShortCodePair(code int, value int16) CodePair

NewShortCodePair creates a code pair representing a short integer value.

func NewStringCodePair

func NewStringCodePair(code int, value string) CodePair

NewStringCodePair creates a code pair representing a string value.

func (*CodePair) String

func (pair *CodePair) String() string

type CodePairValue

type CodePairValue interface {
}

CodePairValue represents a value in a single code pair.

func NewBoolCodePairValue

func NewBoolCodePairValue(value bool) CodePairValue

NewBoolCodePairValue creates a boolean code pair value.

func NewDoubleCodePairValue

func NewDoubleCodePairValue(value float64) CodePairValue

NewDoubleCodePairValue creates a floating point code pair value.

func NewIntCodePairValue

func NewIntCodePairValue(value int) CodePairValue

NewIntCodePairValue creates an integer code pair value.

func NewLongCodePairValue

func NewLongCodePairValue(value int64) CodePairValue

NewLongCodePairValue creates a long integer code pair value.

func NewShortCodePairValue

func NewShortCodePairValue(value int16) CodePairValue

NewShortCodePairValue creates a short integer code pair value.

func NewStringCodePairValue

func NewStringCodePairValue(value string) CodePairValue

NewStringCodePairValue creates a string code pair value.

type Color

type Color int16

Color represents a color present in a DXF drawing.

func ByBlock

func ByBlock() Color

ByBlock creates a color that inherits from the item's block.

func ByEntity

func ByEntity() Color

ByEntity creates a color that inherits from the item's entity.

func ByLayer

func ByLayer() Color

ByLayer creates a color that inherits from the item's layer color.

func (*Color) ByBlock

func (c *Color) ByBlock() bool

ByBlock returns true if the color is inherited from the item's block.

func (*Color) ByEntity

func (c *Color) ByEntity() bool

ByEntity returns true if the color is inherited from the item's entity.

func (*Color) ByLayer

func (c *Color) ByLayer() bool

ByLayer returns true if the color is inherited from the item's layer.

func (*Color) SetByBlock

func (c *Color) SetByBlock()

SetByBlock sets the color to inherit from the item's block.

func (*Color) SetByEntity

func (c *Color) SetByEntity()

SetByEntity sets the color to inherit from the item's entity.

func (*Color) SetByLayer

func (c *Color) SetByLayer()

SetByLayer sets the color to inherit from the item's layer.

func (*Color) String

func (c *Color) String() string

func (*Color) TurnOff

func (c *Color) TurnOff()

TurnOff sets the color to be disabled.

func (*Color) TurnedOff

func (c *Color) TurnedOff() bool

TurnedOff returns true if the item's color is disabled.

type ControlPoint

type ControlPoint struct {
	Point  Point
	Weight float64
}

ControlPoint represents a control point of a Spline

func NewControlPoint

func NewControlPoint() *ControlPoint

NewControlPoint creates a new ControlPoint for a Spline

type DoubleCodePairValue

type DoubleCodePairValue struct {
	CodePairValue
	Value float64
}

DoubleCodePairValue represents a floating point code pair value.

type Drawing

type Drawing struct {
	Header Header

	AppIds       []AppId
	BlockRecords []BlockRecord
	DimStyles    []DimStyle
	Layers       []Layer
	LineTypes    []LineType
	Styles       []Style
	Ucss         []Ucs
	Views        []View
	ViewPorts    []ViewPort

	Entities []Entity
}

The Drawing struct represents a complete DXF drawing.

func NewDrawing

func NewDrawing() *Drawing

NewDrawing returns a new, fully initialized drawing.

func ParseDrawing

func ParseDrawing(content string) (Drawing, error)

ParseDrawing returns a drawing as parsed from a `string`.

func ReadFile

func ReadFile(path string) (Drawing, error)

ReadFile reads a DXF drawing from the specified path.

func ReadFromReader

func ReadFromReader(reader io.Reader) (drawing Drawing, err error)

ReadFromReader reads a DXF drawing from the specified io.Reader.

func ReadFromReaderWithEncoding

func ReadFromReaderWithEncoding(reader io.Reader, e encoding.Encoding) (drawing Drawing, err error)

ReadFromReaderWithEncoding reads a DXF drawing from the specified io.Reader with the specified default text encoding.

func (*Drawing) SaveFile

func (d *Drawing) SaveFile(path string) error

SaveFile writes the current drawing to the specified path.

func (*Drawing) SaveFileBinary

func (d *Drawing) SaveFileBinary(path string) error

SaveFileBinary writes the current drawing to the specified path as a binary DXF.

func (*Drawing) SaveToWriter

func (d *Drawing) SaveToWriter(writer io.Writer) error

SaveToWriter writes the current drawing to the specified io.Writer.

func (*Drawing) SaveToWriterBinary

func (d *Drawing) SaveToWriterBinary(writer io.Writer) error

SaveToWriterBinary writes the current drawing to the specified io.Writer as a binary DXF.

func (*Drawing) String

func (d *Drawing) String() string

type Handle

type Handle uint32

Handle represents a unique identifier for various drawing elements.

type IntCodePairValue

type IntCodePairValue struct {
	CodePairValue
	Value int
}

IntCodePairValue represents an integer code pair value.

type LineWeight

type LineWeight int16

LineWeight represents a plotted drawing elements line weight.

const (
	// LineWeightStandard represents the standard line weight.
	LineWeightStandard LineWeight = -3

	// LineWeightByLayer represents a line weight inherited from the item's layer.
	LineWeightByLayer LineWeight = -2

	// LineWeightByBlock represents a line weight inherited from the item's block.
	LineWeightByBlock LineWeight = -1
)

func NewLineWeightByBlock

func NewLineWeightByBlock() LineWeight

NewLineWeightByBlock creates a line weight that is inherited from the item's block.

func NewLineWeightByLayer

func NewLineWeightByLayer() LineWeight

NewLineWeightByLayer creates a line weight that is inherited from the item's layer.

func NewLineWeightStandard

func NewLineWeightStandard() LineWeight

NewLineWeightStandard creates a new standard line weight.

func (*LineWeight) ByBlock

func (l *LineWeight) ByBlock() bool

ByBlock returns true if the line weight is inherited from the item's block.

func (*LineWeight) ByLayer

func (l *LineWeight) ByLayer() bool

ByLayer returns true if the line weight is inherited from the item's layer.

func (*LineWeight) Custom

func (l *LineWeight) Custom() bool

Custom returns true if the line weight is a custom value. To retreive the custom value, use `int16(lineWeight)`.

func (*LineWeight) SetByBlock

func (l *LineWeight) SetByBlock()

SetByBlock sets the line weight to inherit from the item's block.

func (*LineWeight) SetByLayer

func (l *LineWeight) SetByLayer()

SetByLayer sets the line weight to inherit from the item's layer.

func (*LineWeight) SetCustom

func (l *LineWeight) SetCustom(val int16)

SetCustom sets the line weight to a custom value.

func (*LineWeight) SetStandard

func (l *LineWeight) SetStandard()

SetStandard sets the line weight to the standard value.

func (*LineWeight) Standard

func (l *LineWeight) Standard() bool

Standard returns true if the line weight is the standard value.

type LongCodePairValue

type LongCodePairValue struct {
	CodePairValue
	Value int64
}

LongCodePairValue represents a long integer code pair value.

type LwVertex

type LwVertex struct {
	X             float64
	Y             float64
	ID            int
	StartingWidth float64
	EndingWidth   float64
	Bulge         float64
}

LwVertex represents a vertex of an LWPolyline

func NewLwVertex

func NewLwVertex() *LwVertex

NewLwVertex creates a new LwVertex for an LWPolyline

type Point

type Point struct {
	X float64
	Y float64
	Z float64
}

The Point struct represents a 3D coordinate.

func NewOrigin

func NewOrigin() *Point

NewOrigin creates a new Point representing the (0, 0, 0) location.

func (*Point) String

func (p *Point) String() string

type ShortCodePairValue

type ShortCodePairValue struct {
	CodePairValue
	Value int16
}

ShortCodePairValue represents a short integer code pair value.

type StringCodePairValue

type StringCodePairValue struct {
	CodePairValue
	Value string
}

StringCodePairValue represents a string code pair value.

type Vector

type Vector struct {
	X float64
	Y float64
	Z float64
}

The Vector struct represents a vector in 3D space.

func NewXAxis

func NewXAxis() *Vector

NewXAxis creates a unit vector along the X axis.

func NewYAxis

func NewYAxis() *Vector

NewYAxis creates a unit vector along the Y axis.

func NewZAxis

func NewZAxis() *Vector

NewZAxis creates a unit vector along the Z axis.

func NewZeroVector

func NewZeroVector() *Vector

NewZeroVector creates a vector representing zero distance across any axis.

func (*Vector) String

func (v *Vector) String() string

type ViewMode

type ViewMode int

ViewMode represents the various states a given `ViewPort` can have.

func (*ViewMode) BackClippingOn

func (v *ViewMode) BackClippingOn() bool

BackClippingOn specifies whether back clipping is on.

func (*ViewMode) FrontClippingAtEye

func (v *ViewMode) FrontClippingAtEye() bool

FrontClippingAtEye specifies whether front eye clipping is on.

func (*ViewMode) FrontClippingOn

func (v *ViewMode) FrontClippingOn() bool

FrontClippingOn specifies whether front clipping is on.

func (*ViewMode) PerspectiveViewActive

func (v *ViewMode) PerspectiveViewActive() bool

PerspectiveViewActive specifies whether the perspective view is active.

func (*ViewMode) SetBackClippingOn

func (v *ViewMode) SetBackClippingOn(val bool)

SetBackClippingOn sets the front clipping state of the view.

func (*ViewMode) SetFrontClippingAtEye

func (v *ViewMode) SetFrontClippingAtEye(val bool)

SetFrontClippingAtEye sets the front eye clipping mode of the view.

func (*ViewMode) SetFrontClippingOn

func (v *ViewMode) SetFrontClippingOn(val bool)

SetFrontClippingOn sets the front clipping state of the view.

func (*ViewMode) SetPerspectiveViewActive

func (v *ViewMode) SetPerspectiveViewActive(val bool)

SetPerspectiveViewActive sets the active state of the perspective view.

func (*ViewMode) SetUcsFollowModeOn

func (v *ViewMode) SetUcsFollowModeOn(val bool)

SetUcsFollowModeOn sets the UCS follow mode of the view.

func (*ViewMode) UcsFollowModeOn

func (v *ViewMode) UcsFollowModeOn() bool

UcsFollowModeOn specifies whether UCS follow mode is on.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL