ruby3mf 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ruby3mf.rb +0 -2
- data/lib/ruby3mf/document.rb +32 -4
- data/lib/ruby3mf/log3mf.rb +1 -1
- data/lib/ruby3mf/model3mf.rb +1 -1
- data/lib/ruby3mf/texture3mf.rb +15 -1
- data/lib/ruby3mf/thumbnail3mf.rb +2 -2
- data/lib/ruby3mf/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d90fb95397ffff9fb584f6cd12134aa40b6271ef
|
4
|
+
data.tar.gz: 38411044dcd10075e8f147545f6c81eaf23c8359
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fafd151796e8e752fecbf967be80ff0fc29206f69f1fdd4e252b0302bffa4de2d0110fc7fb2f1d6fd708177ee40ea02d5a5745cb135a9c46d90954694ef749db
|
7
|
+
data.tar.gz: f98af76d0ffcbe56a67486b8b2e0a572ad49e30ac75836eb55db8ac98843be7086315edf6320fc1c4df49c1cfc984311f5f216ad9c3cf24b9ae65744f4ec4d7d
|
data/lib/ruby3mf.rb
CHANGED
data/lib/ruby3mf/document.rb
CHANGED
@@ -3,6 +3,7 @@ class Document
|
|
3
3
|
attr_accessor :models
|
4
4
|
attr_accessor :thumbnails
|
5
5
|
attr_accessor :textures
|
6
|
+
attr_accessor :objects
|
6
7
|
|
7
8
|
# Relationship Type => Class validating relationship type
|
8
9
|
RELATIONSHIP_TYPES = {
|
@@ -11,15 +12,17 @@ class Document
|
|
11
12
|
'http://schemas.microsoft.com/3dmanufacturing/2013/01/3dtexture' => {klass: 'Texture3mf', collection: :textures}
|
12
13
|
}
|
13
14
|
|
14
|
-
def initialize
|
15
|
+
def initialize(zip_filename)
|
15
16
|
self.models=[]
|
16
17
|
self.thumbnails=[]
|
17
18
|
self.textures=[]
|
19
|
+
self.objects={}
|
20
|
+
@zip_filename = zip_filename
|
18
21
|
end
|
19
22
|
|
20
23
|
def self.read(input_file)
|
21
|
-
m=self.new
|
22
|
-
begin
|
24
|
+
m=self.new(input_file)
|
25
|
+
m.zip_filename = input_file begin
|
23
26
|
Log3mf.context "examining zip" do |l|
|
24
27
|
begin
|
25
28
|
Zip.warn_invalid_date = false
|
@@ -72,7 +75,7 @@ class Document
|
|
72
75
|
m.send(relationship_type[:collection]) << {
|
73
76
|
rel_id: rel[:id],
|
74
77
|
target: rel[:target],
|
75
|
-
object: Object.const_get(relationship_type[:klass]).parse(relationship_file, @relationships)
|
78
|
+
object: Object.const_get(relationship_type[:klass]).parse(m, relationship_file, @relationships)
|
76
79
|
}
|
77
80
|
end
|
78
81
|
else
|
@@ -93,4 +96,29 @@ class Document
|
|
93
96
|
return nil
|
94
97
|
end
|
95
98
|
end
|
99
|
+
|
100
|
+
def write(output_file = nil)
|
101
|
+
output_file = @zip_filename if output_file.nil?
|
102
|
+
|
103
|
+
input_zip_file = Zip::File.open(@zip_filename)
|
104
|
+
|
105
|
+
buffer = Zip::OutputStream.write_buffer do |out|
|
106
|
+
input_zip_file.entries.each do |e|
|
107
|
+
if e.directory?
|
108
|
+
out.copy_raw_entry(e)
|
109
|
+
else
|
110
|
+
out.put_next_entry(e.name)
|
111
|
+
if objects[e.name]
|
112
|
+
out.write objects[e.name]
|
113
|
+
else
|
114
|
+
out.write e.get_input_stream.read
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
input_zip_file.close
|
121
|
+
|
122
|
+
File.open(output_file, "wb") {|f| f.write(buffer.string) }
|
123
|
+
end
|
96
124
|
end
|
data/lib/ruby3mf/log3mf.rb
CHANGED
@@ -69,7 +69,7 @@ class Log3mf
|
|
69
69
|
|
70
70
|
def log(severity, message, options={})
|
71
71
|
@log_list << ["#{@context_stack.join("/")}", severity, message, options] unless severity==:debug && ENV['LOGDEBUG'].nil?
|
72
|
-
#puts "[#{@context_stack.join("/")}] #{severity.to_s.upcase} #{message}"
|
72
|
+
# puts "[#{@context_stack.join("/")}] #{severity.to_s.upcase} #{message}"
|
73
73
|
raise FatalError if severity == :fatal_error
|
74
74
|
end
|
75
75
|
|
data/lib/ruby3mf/model3mf.rb
CHANGED
data/lib/ruby3mf/texture3mf.rb
CHANGED
@@ -1,11 +1,25 @@
|
|
1
1
|
class Texture3mf
|
2
|
+
attr_accessor :name
|
3
|
+
|
4
|
+
def initialize(document)
|
5
|
+
@doc = document
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.parse(document, relationship_file, relationships)
|
9
|
+
t = Texture3mf.new(document)
|
10
|
+
t.name = relationship_file.name
|
2
11
|
|
3
|
-
def self.parse(relationship_file, relationships)
|
4
12
|
img_type = MimeMagic.by_magic(relationship_file.get_input_stream)
|
13
|
+
@bytes = relationship_file.get_input_stream.read
|
5
14
|
Log3mf.context "Texture3mf" do |l|
|
6
15
|
l.debug "texture is of type: #{img_type}"
|
7
16
|
l.error "Expected a png or jpeg texture but the texture was of type #{img_type}", spec: :material, page: 16 unless ['image/png', 'image/jpeg'].include? img_type.type
|
8
17
|
end
|
18
|
+
t
|
19
|
+
end
|
9
20
|
|
21
|
+
def update(bytes)
|
22
|
+
@doc.objects[name]=bytes
|
10
23
|
end
|
24
|
+
|
11
25
|
end
|
data/lib/ruby3mf/thumbnail3mf.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
class Thumbnail3mf
|
2
2
|
|
3
|
-
def self.parse(relationship_file, relationships)
|
3
|
+
def self.parse(doc, relationship_file, relationships)
|
4
4
|
img_type = MimeMagic.by_magic(relationship_file.get_input_stream)
|
5
5
|
Log3mf.context "Thumbnail3mf" do |l|
|
6
6
|
l.debug "thumbnail is of type: #{img_type}"
|
@@ -8,4 +8,4 @@ class Thumbnail3mf
|
|
8
8
|
end
|
9
9
|
|
10
10
|
end
|
11
|
-
end
|
11
|
+
end
|
data/lib/ruby3mf/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby3mf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Whitmarsh, Jeff Porter, and William Hertling
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|