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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5c3c875e13f40a3230c7146228502167eae4452b
4
- data.tar.gz: e572579b6da6f51705ced9dded95eec810a2230f
3
+ metadata.gz: d90fb95397ffff9fb584f6cd12134aa40b6271ef
4
+ data.tar.gz: 38411044dcd10075e8f147545f6c81eaf23c8359
5
5
  SHA512:
6
- metadata.gz: 3eda18a557d21f60cf8236786002085afa545236e206df90794f66341125f447e48ffa1189a898786cabb678cab74f650f45867a49938abfea82072129d20fb8
7
- data.tar.gz: e4da8cb5bdab1a1fac1b36cfa351d542ebcef28738c13716d6dc928ebcb7dc7b8978d2b7bba7d20ce51107f989bb4ee3eaf2b7cc64351787bf1f1432417f8bcc
6
+ metadata.gz: fafd151796e8e752fecbf967be80ff0fc29206f69f1fdd4e252b0302bffa4de2d0110fc7fb2f1d6fd708177ee40ea02d5a5745cb135a9c46d90954694ef749db
7
+ data.tar.gz: f98af76d0ffcbe56a67486b8b2e0a572ad49e30ac75836eb55db8ac98843be7086315edf6320fc1c4df49c1cfc984311f5f216ad9c3cf24b9ae65744f4ec4d7d
data/lib/ruby3mf.rb CHANGED
@@ -8,8 +8,6 @@ require "ruby3mf/relationships"
8
8
  require "ruby3mf/thumbnail3mf"
9
9
  require "ruby3mf/texture3mf"
10
10
 
11
-
12
-
13
11
  require 'zip'
14
12
  require 'nokogiri'
15
13
  require 'json'
@@ -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
@@ -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
 
@@ -12,7 +12,7 @@ class Model3mf
12
12
  end
13
13
  end
14
14
 
15
- def self.parse(zip_entry, relationships)
15
+ def self.parse(document, zip_entry, relationships)
16
16
  model_hash = {}
17
17
  Log3mf.context "parsing model" do |l|
18
18
  begin
@@ -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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Ruby3mf
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
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.3
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 00:00:00.000000000 Z
11
+ date: 2016-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler