ruby3mf 0.1.8 → 0.1.10

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: 28365afa35fee85496d68bd42bce1b2f2c8c9881
4
- data.tar.gz: abb54781a8012d7526662ff118502f5ee55fa0f1
3
+ metadata.gz: f15c7a59a41748c2b7f788fbdc89a930f4799f74
4
+ data.tar.gz: e0cfb446ab590d4d036f939f25c4b1cb10c5c692
5
5
  SHA512:
6
- metadata.gz: 73d47d9de40fda1e701f11452c6feab4c479a59798a23d439045ec7810fba6b43a2aa639b9f48c7c475d061524b8d71b0b3a316de851f9c3d8f2a24e8c82137a
7
- data.tar.gz: ffd4f47c393311dba9c00d3aa78fb5aa1eaf2e128af72d28d4d724569064631e162409925fc9691c46045ba4cad402ab779ca4695e66d1bc9a0108daf4122e66
6
+ metadata.gz: 4d79b78bf1b7ef8a7e4a72e1caac69dd7dd73147928e22d65d83aab3b1c5ec67c752842f4f18c2c217a8d2227c360b65bba61e9f40c7ef052d00454e812ea8b7
7
+ data.tar.gz: 735bcb3499bcbf02278a8dd58f5a956b3a101cd157493d2aa730318e47e68249e9d8135c2ad3f37a34fae3d223e197a067fb9b285c6d42ec31e581c3520cc3bc
@@ -1,5 +1,7 @@
1
1
  class Document
2
2
 
3
+ attr_accessor :types
4
+ attr_accessor :relationships
3
5
  attr_accessor :models
4
6
  attr_accessor :thumbnails
5
7
  attr_accessor :textures
@@ -18,6 +20,8 @@ class Document
18
20
  self.thumbnails=[]
19
21
  self.textures=[]
20
22
  self.objects={}
23
+ self.relationships=[]
24
+ self.types=[]
21
25
  @zip_filename = zip_filename
22
26
  end
23
27
 
@@ -37,7 +41,7 @@ class Document
37
41
  # 1. Get Content Types
38
42
  content_type_match = zip_file.glob('\[Content_Types\].xml').first
39
43
  if content_type_match
40
- @types = ContentTypes.parse(content_type_match)
44
+ m.types = ContentTypes.parse(content_type_match)
41
45
  else
42
46
  l.error "Missing required file: [Content_Types].xml", page: 4
43
47
  end
@@ -52,15 +56,14 @@ class Document
52
56
  rel_file = zip_file.glob('_rels/.rels').first
53
57
  l.fatal_error "Missing required file _rels/.rels", page: 4 unless rel_file
54
58
 
55
- @relationships=[]
56
59
  zip_file.glob('**/*.rels').each do |rel|
57
- @relationships += Relationships.parse(rel)
60
+ m.relationships += Relationships.parse(rel)
58
61
  end
59
62
  end
60
63
 
61
64
  l.context "relationship elements" do |l|
62
65
  # 3. Validate all relationships
63
- @relationships.each do |rel|
66
+ m.relationships.each do |rel|
64
67
  l.context rel[:target] do |l|
65
68
  target = rel[:target].gsub(/^\//, "")
66
69
  relationship_file = zip_file.glob(target).first
@@ -73,7 +76,7 @@ class Document
73
76
  m.send(relationship_type[:collection]) << {
74
77
  rel_id: rel[:id],
75
78
  target: rel[:target],
76
- object: Object.const_get(relationship_type[:klass]).parse(m, relationship_file, @relationships)
79
+ object: Object.const_get(relationship_type[:klass]).parse(m, relationship_file)
77
80
  }
78
81
  end
79
82
  else
@@ -1,6 +1,6 @@
1
1
  class Model3mf
2
2
 
3
- def self.parse(document, zip_entry, relationships)
3
+ def self.parse(document, zip_entry)
4
4
  model_doc = nil
5
5
 
6
6
  Log3mf.context "parsing model" do |l|
@@ -17,8 +17,8 @@ class Model3mf
17
17
  # results = model_doc.css("model resources m:texture2d")
18
18
  required_resources = model_doc.css("//model//resources//*[path]").collect { |n| n["path"] }
19
19
 
20
- # for each, ensure that they exist in @relationships
21
- relationship_resources = relationships.map { |relationship| relationship[:target] }
20
+ # for each, ensure that they exist in m.relationships
21
+ relationship_resources = document.relationships.map { |relationship| relationship[:target] }
22
22
 
23
23
  missing_resources = (required_resources - relationship_resources)
24
24
  if missing_resources.empty?
@@ -29,6 +29,23 @@ class Model3mf
29
29
  }
30
30
  end
31
31
 
32
+ l.context "verifying 3D resource types" do |l|
33
+ model_types = model_doc.css("//model//resources//*[path]").collect { |t| t["contenttype"] }
34
+
35
+ #for each, ensure they exist in ContentTypes
36
+ all_types = document.types.map { |t, v| v }
37
+
38
+ bad_types = (model_types - all_types)
39
+ if bad_types.empty?
40
+ l.info "All model resource contenttypes are valid"
41
+ else
42
+ bad_types.each { |bt|
43
+ puts "bad type: #{bt}"
44
+ l.error "resource in model has invalid contenttype #{bt}", page: 10
45
+ }
46
+ end
47
+ end
48
+
32
49
  end
33
50
  end
34
51
  model_doc
@@ -5,14 +5,14 @@ class Texture3mf
5
5
  @doc = document
6
6
  end
7
7
 
8
- def self.parse(document, relationship_file, relationships)
8
+ def self.parse(document, relationship_file)
9
9
 
10
10
  t = new(document)
11
11
  t.name = relationship_file.name
12
12
  stream = relationship_file.get_input_stream
13
13
  img_type = MimeMagic.by_magic(stream)
14
- @bytes = stream.read
15
14
  Log3mf.context "Texture3mf" do |l|
15
+ l.fatal_error "Texture file must be valid image file", spec: :material, page: 16 unless img_type
16
16
  l.debug "texture is of type: #{img_type}"
17
17
  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
18
18
  end
@@ -1,8 +1,9 @@
1
1
  class Thumbnail3mf
2
2
 
3
- def self.parse(doc, relationship_file, relationships)
3
+ def self.parse(doc, relationship_file)
4
4
  img_type = MimeMagic.by_magic(relationship_file.get_input_stream)
5
5
  Log3mf.context "Thumbnail3mf" do |l|
6
+ l.fatal_error "thumbnail file must be valid image file", page: 10 unless img_type
6
7
  l.debug "thumbnail is of type: #{img_type}"
7
8
  l.error "Expected a png or jpeg thumbnail but the thumbnail was of type #{img_type}", page: 12 unless ['image/png', 'image/jpeg'].include? img_type.type
8
9
  end
@@ -1,3 +1,3 @@
1
1
  module Ruby3mf
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.10"
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.8
4
+ version: 0.1.10
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-30 00:00:00.000000000 Z
11
+ date: 2016-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler