STLExtract 1.0.0 → 1.0.1

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/README.md CHANGED
@@ -20,7 +20,7 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- First create a new StlExtract object using the following command
23
+ First create a new StlExtract object using the following command.
24
24
 
25
25
  ```ruby
26
26
  s = StlExtract.new()
@@ -32,20 +32,26 @@ Then use the following command to get info about a file specified as an argument
32
32
  s.get_info("C:/Users/Tom/Documents/champagne_bottle.stl")
33
33
  ```
34
34
 
35
+ You can automate the above two commands by specifying the optional file path in the new construct as shown below
36
+
37
+ ```ruby
38
+ s = StlExtract.new("C:/Users/Tom/Documents/champagne_bottle.stl")
39
+ ```
40
+
35
41
  Should there be any errors with getting the details from the file then you can retrieve the error from
36
42
 
37
43
  ```ruby
38
- s.get_error
44
+ s.error
39
45
  ```
40
46
 
41
- The error will be a string value containing text about the error or -1 if the program ran correctly and there was no error. If there was no errors then you can access x,y,z,volume and if file needs repair using
47
+ The error will be a string value containing text about the error or false if the program ran correctly and there was no error. If there was no errors then you can access x,y,z,volume and if file needs repair using
42
48
 
43
49
  ```ruby
44
- s.get_x_value
45
- s.get_y_value
46
- s.get_z_value
47
- s.get_volume
48
- s.get_repair
50
+ s.x
51
+ s.y
52
+ s.z
53
+ s.volume
54
+ s.repair
49
55
  ```
50
56
 
51
57
  Should the STL file need repairing we can use the following command
@@ -54,7 +60,8 @@ Should the STL file need repairing we can use the following command
54
60
  s.repair_file("C:/Users/Tom/Documents/champagne_bottle.stl")
55
61
  ```
56
62
 
57
- to create a fixed file named [OrginalName]_fixed.obj so in our above example we will now have a file named champagne_bottle_fixed.obj in C:/Users/Tom/Documents/
63
+ to create a fixed file named [OrginalName]_fixed.obj so in our above example we will now have a file named champagne_bottle_fixed.obj in C:/Users/Tom/Documents/.
64
+ If no argument is given to repair_file it automatically uses the last string passed to new() or get_info()
58
65
 
59
66
 
60
67
  ## Contributing
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
7
7
  spec.name = "STLExtract"
8
8
  spec.version = STLExtract::VERSION
9
9
  spec.authors = ["Thomas Preece"]
10
- spec.email = ["t.preece@warwick.ac.uk"]
10
+ spec.email = ["RubyGems@thomaspreece.com"]
11
11
  spec.summary = 'Extracts data from STL, OBJ and AMF files using Slic3r'
12
12
  spec.description = 'Extracts x,y,z and volume data from STL, OBJ and AMF files using Slic3r'
13
13
  spec.homepage = "http://thomaspreece.com"
@@ -2,28 +2,47 @@ require "STLExtract/version"
2
2
  require 'io/console'
3
3
 
4
4
  class StlExtract
5
- def repair_file(file)
6
- @error = -1
5
+ def repair_file(file=nil)
6
+ @error = false
7
7
 
8
- io = IO.popen(@slic3r_path+' --repair '+file+" 2>&1")
9
- io.each do |s|
10
- if s.include? "No such file"
11
- @error = "Incorrect filename"
8
+ if file==nil
9
+ #Check for file to repair in local @file
10
+ if @file!=nil
11
+ #Use file found in @file to repair
12
+ file = @file
13
+ else
14
+ #No file provided, give error
15
+ @error = "No file provided to repair"
16
+ end
17
+ else
18
+ #Use file provided to function in repair
19
+ end
20
+
21
+ #If no errors, repair file
22
+ if @error == false
23
+ io = IO.popen(@slic3r_path+" --repair \""+file+"\" 2>&1")
24
+ io.each do |s|
25
+ if s.include? "No such file"
26
+ @error = "Incorrect filename"
27
+ end
12
28
  end
13
29
  end
14
30
  end
15
31
 
16
32
  def get_info(file)
17
- #reset initial values to -1
18
- @x_value = -1
19
- @y_value = -1
20
- @z_value = -1
21
- @volume = -1
22
- @repair = -1
23
- @error = -1
33
+ #Set @file to use later in repair
34
+ @file = file
35
+
36
+ #Set our initial values to nil and false for error
37
+ @x_value = nil
38
+ @y_value = nil
39
+ @z_value = nil
40
+ @volume = nil
41
+ @repair = nil
42
+ @error = false
24
43
 
25
44
  #Open slic3r with filename supplied
26
- io = IO.popen(@slic3r_path+' --info '+file+" 2>&1")
45
+ io = IO.popen(@slic3r_path+" --info \""+file+"\" 2>&1")
27
46
 
28
47
  io.each do |s|
29
48
  #If output contains size, extract size information using regex
@@ -40,9 +59,9 @@ class StlExtract
40
59
  sizeMatch = s.match( /needed repair:[^y]+(yes|no)/ )
41
60
  if sizeMatch!=nil
42
61
  if sizeMatch.values_at( 1 )[0]=="yes"
43
- @repair = 1
62
+ @repair = true
44
63
  else
45
- @repair = 0
64
+ @repair = false
46
65
  end
47
66
  end
48
67
  end
@@ -67,19 +86,19 @@ class StlExtract
67
86
  end
68
87
 
69
88
  #Check that all required data is extracted
70
- if ((@x_value==-1 || @y_value==-1 || @z_value==-1 || @volume==-1 || @repair==-1 ) && @error == -1)
89
+ if ((@x_value==nil || @y_value==nil || @z_value==nil || @volume==nil || @repair==nil ) && @error == false)
71
90
  @error = "Could not extract all data"
72
91
  end
73
92
  end
74
93
 
75
- def initialize()
76
- #Set our initial values to -1
77
- @x_value = -1
78
- @y_value = -1
79
- @z_value = -1
80
- @volume = -1
81
- @repair = -1
82
- @error = -1
94
+ def initialize(file=nil)
95
+ #Set our initial values to nil and false for error
96
+ @x_value = nil
97
+ @y_value = nil
98
+ @z_value = nil
99
+ @volume = nil
100
+ @repair = nil
101
+ @error = false
83
102
 
84
103
  #Find Slic3r location
85
104
  @slic3r_path = File.expand_path('../../', __FILE__)
@@ -101,34 +120,38 @@ class StlExtract
101
120
  raise "Could not make Slic3r executable"
102
121
  end
103
122
  end
123
+
124
+ if file!=nil
125
+ get_info(file)
126
+ end
104
127
  end
105
128
 
106
- def get_x_value()
129
+ def x()
107
130
  #Return stored x value
108
131
  @x_value
109
132
  end
110
133
 
111
- def get_y_value()
134
+ def y()
112
135
  #Return stored y value
113
136
  @y_value
114
137
  end
115
138
 
116
- def get_z_value()
139
+ def z()
117
140
  #Return stored z value
118
141
  @z_value
119
142
  end
120
143
 
121
- def get_volume()
144
+ def volume()
122
145
  #Return stored volume
123
146
  @volume
124
147
  end
125
148
 
126
- def get_repair()
149
+ def repair()
127
150
  #Return stored volume
128
151
  @repair
129
152
  end
130
153
 
131
- def get_error()
154
+ def error()
132
155
  #Return stored volume
133
156
  @error
134
157
  end
@@ -1,3 +1,3 @@
1
1
  module STLExtract
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: STLExtract
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-10-08 00:00:00.000000000 Z
12
+ date: 2014-10-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -45,7 +45,7 @@ dependencies:
45
45
  version: '10.0'
46
46
  description: Extracts x,y,z and volume data from STL, OBJ and AMF files using Slic3r
47
47
  email:
48
- - t.preece@warwick.ac.uk
48
+ - RubyGems@thomaspreece.com
49
49
  executables: []
50
50
  extensions: []
51
51
  extra_rdoc_files: []
@@ -55,7 +55,6 @@ files:
55
55
  - LICENSE.txt
56
56
  - README.md
57
57
  - Rakefile
58
- - STLExtract-0.0.1.gem
59
58
  - STLExtract.gemspec
60
59
  - Slic3r/Linux/bin/slic3r
61
60
  - Slic3r/Linux/dll/libGLU.so