Module: SolidRuby
- Includes:
- Math, Assemblies, BillOfMaterial, CSGModelling, CSGModifiers, Extras, Helpers, Primitives, PrintedThreads, ScrewThreads, Transformations
- Defined in:
- lib/solidruby/version.rb,
lib/solidruby/solidruby.rb,
lib/solidruby/rubyscad_bridge.rb,
lib/solidruby/solidruby_object.rb
Overview
This file is part of SolidRuby.
SolidRuby is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
SolidRuby is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with SolidRuby. If not, see <http://www.gnu.org/licenses/>.
Defined Under Namespace
Modules: Assemblies, BillOfMaterial, CSGModelling, CSGModifiers, Extras, Helpers, Primitives, PrintedThreads, ScrewThreads, Transformations Classes: RubyScadBridge, SolidRubyObject
Constant Summary collapse
- VERSION =
'0.1.0'.freeze
Instance Attribute Summary
Attributes included from Transformations
Instance Method Summary collapse
- #degrees(a) ⇒ Object
- #get_classes_from_file(filename) ⇒ Object
- #get_position_rec(obj, level = 0) ⇒ Object
-
#long_slot(args) ⇒ Object
produces a hull() of 2 cylidners accepts d,r,h for cylinder options l long slot length.
-
#position(obj) ⇒ Object
this is experimental, does only work on simple parts.
- #radians(a) ⇒ Object
- #save! ⇒ Object
-
#save_all(class_name, fn = $fn) ⇒ Object
Saves all files generated of a SolidRuby file Saves outputs of - show - output - view*.
-
#stack(args = {}, *parts) ⇒ Object
Deprecated: Stacks parts along the Z axis works on all Assemblies that have a @height definition TODO: Make a better functionality similar to this, that is: - easier to use - throws better error messages - doesn’t assume that everything falls down like gravity in every case.
Methods included from CSGModifiers
#color, #linear_extrude, #projection, #rotate_extrude
Methods included from CSGModelling
#*, #+, #-, #hull, #minkowski, #optimize_difference, #optimize_union
Methods included from Primitives
#circle, #cube, #cylinder, #import, #polygon, #polyhedron, #render, #sphere, #square, #surface, #text
Methods included from Helpers
#calculate_point_on, #chamfer, #corners, #fillet, #is_horizontal?, #is_vertical?, #is_x_dir?, #is_y_dir?, #normalise_edges, #rounded_cube, #translations_for_edge, #triangle
Methods included from Extras
#knurl, #knurled_cube, #knurled_cylinder
Methods included from ScrewThreads
Methods included from BillOfMaterial
Instance Method Details
#degrees(a) ⇒ Object
91 92 93 |
# File 'lib/solidruby/solidruby.rb', line 91 def degrees(a) a * 180 / Math::PI end |
#get_classes_from_file(filename) ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/solidruby/solidruby.rb', line 135 def get_classes_from_file(filename) classes = [] File.readlines(filename).find_all { |l| l.include?('class') }.each do |line| # strip all spaces, tabs line.strip! # ignore comments (Warning: will not worth with ruby multi line comments) next if line[0..0] == '#' # strip class definition line = line[6..-1] # strip until space appears - or if not, to the end classes << Object.const_get(line[0..line.index(' ').to_i - 1]) end classes end |
#get_position_rec(obj, level = 0) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/solidruby/solidruby.rb', line 52 def get_position_rec(obj, level = 0) position = [0, 0, 0] return position if obj.nil? obj.each do |o| o.transformations.each do |t| next unless t.class == Translate t.args[:x] ||= 0 t.args[:y] ||= 0 t.args[:z] ||= 0 position[0] += t.args[:x] position[1] += t.args[:y] position[2] += t.args[:z] end # puts " " * level + position.inspect x, y, z = get_position_rec(o.children, level + 1) position[0] += x position[1] += y position[2] += z end position end |
#long_slot(args) ⇒ Object
produces a hull() of 2 cylidners accepts d,r,h for cylinder options l long slot length
83 84 85 |
# File 'lib/solidruby/solidruby.rb', line 83 def long_slot(args) hull(cylinder(d: args[:d], r: args[:r], h: args[:h]), cylinder(d: args[:d], r: args[:r], h: args[:h]).translate(x: args[:l])) end |
#position(obj) ⇒ Object
this is experimental, does only work on simple parts. example: The bolt head is on the -z plane, this will move it to “zero”
76 77 78 |
# File 'lib/solidruby/solidruby.rb', line 76 def position(obj) get_position_rec(obj.children) end |
#radians(a) ⇒ Object
87 88 89 |
# File 'lib/solidruby/solidruby.rb', line 87 def radians(a) a / 180.0 * Math::PI end |
#save! ⇒ Object
95 96 97 |
# File 'lib/solidruby/solidruby.rb', line 95 def save! Dir.glob('lib/**/*.rb').map { |l| get_classes_from_file(l) }.flatten.map { |l| save_all(l) } end |
#save_all(class_name, fn = $fn) ⇒ Object
Saves all files generated of a SolidRuby file Saves outputs of
-
show
-
output
-
view*
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/solidruby/solidruby.rb', line 104 def save_all(class_name, fn = $fn) res = class_name.send :new # skip defined classes skip = class_name.send :get_skip skip = [] if skip.nil? skip << 'show_hardware' added_views = class_name.send :get_views # regexp for output* view* show* (res.methods.grep(Regexp.union(/^output/, /^view/, /^show/)) + added_views).each do |i| next if skip.include? i.to_s output = nil res.send :initialize # ensure default values are loaded at each interation output = res.send i # if previous call resulted in a SolidRubyObject, don't call the show method again, # otherwise call it. unless output.is_a? SolidRubyObject output = if i.to_s.include? 'output' res.output else res.show end end output.save("output/#{res.class}_#{i}.scad", "$fn=#{fn};") unless output.nil? end end |
#stack(args = {}, *parts) ⇒ Object
Deprecated: Stacks parts along the Z axis works on all Assemblies that have a @height definition TODO: Make a better functionality similar to this, that is: - easier to use - throws better error messages - doesn’t assume that everything falls down like gravity in every case
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/solidruby/solidruby.rb', line 37 def stack(args = {}, *parts) args[:method] ||= 'show' args[:spacing] ||= 0 warn 'SolidRuby Warning: Please note that the stack method is deprecated and will be removed or replaced in the future' @assembly = nil z = 0 parts.each do |part| item = (part.send args[:method]) next if item.nil? || !item.respond_to?('translate') @assembly += item.translate(z: z) z += part.height + args[:spacing] end @assembly end |