aurora-dxf 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/aurora-dxf.gemspec +1 -1
- data/lib/dxf/unparser.rb +100 -87
- data/test/dxf/unparser.rb +1 -1
- metadata +19 -11
- checksums.yaml +0 -7
data/aurora-dxf.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |gem|
|
6
6
|
gem.name = "aurora-dxf"
|
7
|
-
gem.version = '0.0.
|
7
|
+
gem.version = '0.0.4'
|
8
8
|
gem.authors = ["Brandon Fosdick", "Meseker Yohannes"]
|
9
9
|
gem.email = ["meseker.yohannes@gmail.com"]
|
10
10
|
gem.description = %q{Read and write DXF files using Ruby}
|
data/lib/dxf/unparser.rb
CHANGED
@@ -4,102 +4,115 @@ require 'units'
|
|
4
4
|
require 'stringio'
|
5
5
|
|
6
6
|
module DXF
|
7
|
-
|
8
|
-
|
7
|
+
class Unparser
|
8
|
+
attr_accessor :container
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
# Initialize with a Sketch
|
11
|
+
# @param [String,Symbol] units The units to convert length values to (:inches or :millimeters)
|
12
|
+
def initialize(units=:mm)
|
13
|
+
@units = units
|
14
|
+
end
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
def to_s
|
17
|
+
io = StringIO.new
|
18
|
+
unparse(io, container)
|
19
|
+
io.string
|
20
|
+
end
|
21
21
|
|
22
|
-
# @group Element Formatters
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
# @group Element Formatters
|
23
|
+
# Convert a {Geometry::Line} into group codes
|
24
|
+
def line(first, last, layer=0, transformation=nil)
|
25
|
+
first, last = Geometry::Point[first], Geometry::Point[last]
|
26
|
+
first, last = [first, last].map {|point| transformation.transform(point) } if transformation
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
# @endgroup
|
28
|
+
[ 0, 'LINE',
|
29
|
+
8, layer,
|
30
|
+
10, format_value(first.x),
|
31
|
+
20, format_value(first.y),
|
32
|
+
11, format_value(last.x),
|
33
|
+
21, format_value(last.y)]
|
34
|
+
end
|
35
|
+
# @endgroup
|
36
|
+
|
37
|
+
def text(position, content, layer=0, transformation=nil)
|
38
|
+
position = transformation.transform(position) if transformation
|
39
|
+
|
40
|
+
[0, 'TEXT',
|
41
|
+
8, layer,
|
42
|
+
10, format_value(position.x),
|
43
|
+
20, format_value(position.y),
|
44
|
+
1, content,
|
45
|
+
7, 'NewTextStyle_4']
|
46
|
+
end
|
47
|
+
|
48
|
+
# @group Property Converters
|
49
|
+
# Convert the given value to the correct units and return it as a formatted string
|
50
|
+
# @return [String]
|
51
|
+
def format_value(value)
|
52
|
+
if value.is_a? Units::Numeric
|
53
|
+
"%g" % value.send("to_#{@units}".to_sym)
|
54
|
+
else
|
55
|
+
"%g" % value
|
56
|
+
end
|
57
|
+
end
|
36
58
|
|
37
|
-
#
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
else
|
44
|
-
"%g" % value
|
45
|
-
end
|
46
|
-
end
|
59
|
+
# Emit the group codes for the center property of an element
|
60
|
+
# @param [Point] point The center point to format
|
61
|
+
def center(point, transformation)
|
62
|
+
point = transformation.transform(point) if transformation
|
63
|
+
[10, format_value(point.x), 20, format_value(point.y)]
|
64
|
+
end
|
47
65
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
[10, format_value(point.x), 20, format_value(point.y)]
|
53
|
-
end
|
66
|
+
# Emit the group codes for the radius property of an element
|
67
|
+
def radius(element, transformation=nil)
|
68
|
+
[40, format_value(transformation ? transformation.transform(element.radius) : element.radius)]
|
69
|
+
end
|
54
70
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
end
|
71
|
+
def section_end
|
72
|
+
[0, 'ENDSEC']
|
73
|
+
end
|
59
74
|
|
60
|
-
|
61
|
-
|
62
|
-
|
75
|
+
def section_start(name)
|
76
|
+
[0, 'SECTION', 2, name]
|
77
|
+
end
|
78
|
+
# @endgroup
|
63
79
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
80
|
+
# Convert an element to an Array
|
81
|
+
# @param [Transformation] transformation The transformation to apply to each geometry element
|
82
|
+
# @return [Array]
|
83
|
+
def to_array(element, transformation=nil)
|
84
|
+
layer = 0;
|
85
|
+
case element
|
86
|
+
when Geometry::Arc
|
87
|
+
[ 0, 'ARC', center(element.center, transformation), radius(element),
|
88
|
+
50, format_value(element.start_angle),
|
89
|
+
51, format_value(element.end_angle)]
|
90
|
+
when Geometry::Circle
|
91
|
+
[0, 'CIRCLE', 8, layer, center(element.center, transformation), radius(element)]
|
92
|
+
when Geometry::Text
|
93
|
+
text(element.position, element.content, layer)
|
94
|
+
when Geometry::Edge, Geometry::Line
|
95
|
+
line(element.first, element.last, layer, transformation)
|
96
|
+
when Geometry::Polyline
|
97
|
+
element.edges.map {|edge| line(edge.first, edge.last, layer, transformation) }
|
98
|
+
when Geometry::Rectangle
|
99
|
+
element.edges.map {|edge| line(edge.first, edge.last, layer, transformation) }
|
100
|
+
when Geometry::Square
|
101
|
+
points = element.points
|
102
|
+
points.each_cons(2).map {|p1,p2| line(p1,p2, layer, transformation) } + line(points.last, points.first, layer, transformation)
|
103
|
+
when Sketch
|
104
|
+
transformation = transformation ? (transformation + element.transformation) : element.transformation
|
105
|
+
element.geometry.map {|e| to_array(e, transformation)}
|
106
|
+
end
|
107
|
+
end
|
68
108
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
50, format_value(element.start_angle),
|
78
|
-
51, format_value(element.end_angle)]
|
79
|
-
when Geometry::Circle
|
80
|
-
[0, 'CIRCLE', 8, layer, center(element.center, transformation), radius(element)]
|
81
|
-
when Geometry::Edge, Geometry::Line
|
82
|
-
line(element.first, element.last, layer, transformation)
|
83
|
-
when Geometry::Polyline
|
84
|
-
element.edges.map {|edge| line(edge.first, edge.last, layer, transformation) }
|
85
|
-
when Geometry::Rectangle
|
86
|
-
element.edges.map {|edge| line(edge.first, edge.last, layer, transformation) }
|
87
|
-
when Geometry::Square
|
88
|
-
points = element.points
|
89
|
-
points.each_cons(2).map {|p1,p2| line(p1,p2, layer, transformation) } + line(points.last, points.first, layer, transformation)
|
90
|
-
when Sketch
|
91
|
-
transformation = transformation ? (transformation + element.transformation) : element.transformation
|
92
|
-
element.geometry.map {|e| to_array(e, transformation)}
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
# Convert a {Sketch} to a DXF file and write it to the given output
|
97
|
-
# @param [IO] output A writable IO-like object
|
98
|
-
# @param [Sketch] sketch The {Sketch} to unparse
|
99
|
-
def unparse(output, sketch)
|
100
|
-
output << (section_start('HEADER') + section_end +
|
101
|
-
section_start('ENTITIES') + to_array(sketch) + section_end +
|
102
|
-
[0, 'EOF']).join("\n")
|
103
|
-
end
|
109
|
+
# Convert a {Sketch} to a DXF file and write it to the given output
|
110
|
+
# @param [IO] output A writable IO-like object
|
111
|
+
# @param [Sketch] sketch The {Sketch} to unparse
|
112
|
+
def unparse(output, sketch)
|
113
|
+
output << (section_start('HEADER') + section_end +
|
114
|
+
section_start('ENTITIES') + to_array(sketch) + section_end +
|
115
|
+
[0, 'EOF']).join("\n")
|
116
|
+
end
|
104
117
|
end
|
105
118
|
end
|
data/test/dxf/unparser.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aurora-dxf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Brandon Fosdick
|
@@ -9,39 +10,44 @@ authors:
|
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date: 2014-03-
|
13
|
+
date: 2014-03-11 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: aurora-geometry
|
16
17
|
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
17
19
|
requirements:
|
18
|
-
- - '>='
|
20
|
+
- - ! '>='
|
19
21
|
- !ruby/object:Gem::Version
|
20
22
|
version: '0'
|
21
23
|
type: :runtime
|
22
24
|
prerelease: false
|
23
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
24
27
|
requirements:
|
25
|
-
- - '>='
|
28
|
+
- - ! '>='
|
26
29
|
- !ruby/object:Gem::Version
|
27
30
|
version: '0'
|
28
31
|
- !ruby/object:Gem::Dependency
|
29
32
|
name: aurora-sketch
|
30
33
|
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
31
35
|
requirements:
|
32
|
-
- - '>='
|
36
|
+
- - ! '>='
|
33
37
|
- !ruby/object:Gem::Version
|
34
38
|
version: '0'
|
35
39
|
type: :runtime
|
36
40
|
prerelease: false
|
37
41
|
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
38
43
|
requirements:
|
39
|
-
- - '>='
|
44
|
+
- - ! '>='
|
40
45
|
- !ruby/object:Gem::Version
|
41
46
|
version: '0'
|
42
47
|
- !ruby/object:Gem::Dependency
|
43
48
|
name: units
|
44
49
|
requirement: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
45
51
|
requirements:
|
46
52
|
- - ~>
|
47
53
|
- !ruby/object:Gem::Version
|
@@ -49,6 +55,7 @@ dependencies:
|
|
49
55
|
type: :runtime
|
50
56
|
prerelease: false
|
51
57
|
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
52
59
|
requirements:
|
53
60
|
- - ~>
|
54
61
|
- !ruby/object:Gem::Version
|
@@ -78,26 +85,27 @@ files:
|
|
78
85
|
- test/fixtures/square_millimeters.dxf
|
79
86
|
homepage: http://github.com/meseker/dxf-ruby
|
80
87
|
licenses: []
|
81
|
-
metadata: {}
|
82
88
|
post_install_message:
|
83
89
|
rdoc_options: []
|
84
90
|
require_paths:
|
85
91
|
- lib
|
86
92
|
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
87
94
|
requirements:
|
88
|
-
- - '>='
|
95
|
+
- - ! '>='
|
89
96
|
- !ruby/object:Gem::Version
|
90
97
|
version: '0'
|
91
98
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
92
100
|
requirements:
|
93
|
-
- - '>='
|
101
|
+
- - ! '>='
|
94
102
|
- !ruby/object:Gem::Version
|
95
103
|
version: '0'
|
96
104
|
requirements: []
|
97
105
|
rubyforge_project:
|
98
|
-
rubygems_version:
|
106
|
+
rubygems_version: 1.8.23
|
99
107
|
signing_key:
|
100
|
-
specification_version:
|
108
|
+
specification_version: 3
|
101
109
|
summary: Tools for working with the popular DXF file format
|
102
110
|
test_files:
|
103
111
|
- test/dxf/parser.rb
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: a03bc384bb55b21b7c1bd910b73985797191fa05
|
4
|
-
data.tar.gz: bcebe25e0f79bd3cafc2fd0eed0486d4dc77c113
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: d08d53dc672d2e65f8e1e767cb60dc880255548065255b2e1de0ce2e8ffa1c3a2c8b8e58be855df7ab8a393ae5ab232920d4dd937ccec4cb72fcf0d81018816e
|
7
|
-
data.tar.gz: b3ff2a61715effb1505ca73ce49c39782a54139167e85752f585ca30e0b51d8772b868fc52e736973a1601885f0f772e23bac532f79052cf6cffdc7a2d9f18d3
|