src/jwm_draw_framing/draw_framing_main_v0.56.rb
## Draw the geometry 
## This section of code feeds back to the user the size and orientation of the face that will be created to 
## start drawing a piece of timber. 
## The first pick point defines the location of a corner of the timber.
## Press a cursor (arrow) key to lock the long axis direction 
## Moving the cursor around the first pick point changes the orientation 
## of the cross-section face.
## Clicking the second pick point fixes the axis and orientation of the face to be drawn, 
## draws a face at the origin, then transforms it to move it to the first pick point, 
## ready for a pushpull operation to create the desired length
Draw the geometry
This section of code feeds back to the user the size and orientation of the face that will be created to
start drawing a piece of timber.
The first pick point defines the location of a corner of the timber.
Press a cursor (arrow) key to lock the long axis direction
Moving the cursor around the first pick point changes the orientation
of the cross-section face.
Clicking the second pick point fixes the axis and orientation of the face to be drawn,
draws a face at the origin, then transforms it to move it to the first pick point,
ready for a pushpull operation to create the desired length
Draw the geometry This section of code feeds back to the user the size and orientation of the face that will be created to start drawing a piece of timber . The first pick point defines the location of a corner of the timber . Press a cursor ( arrow ) key to lock the long axis direction Moving the cursor around the first pick point changes the orientation of the cross - section face . Clicking the second pick point fixes the axis and orientation of the face to be drawn draws a face at the origin then transforms it to move it to the first pick point ready for a pushpull operation to create the desired length
def draw_geometry(pt1, pt2, view)
	w = @@act_size[0] 
	d = @@act_size[1] 
	r = 0; g = 1; b = 2
	rdir = 1.0 
	gdir = 1.0
	bdir = 1.0
	vec = pt2 - pt1 
	rdir = -1.0 if vec[r]<0 
	gdir = -1.0 if vec[g]<0
	bdir = -1.0 if vec[b]<0
	gb = Geom::Point3d.new; rb = Geom::Point3d.new ; rg = Geom::Point3d.new
  gb2 = Geom::Point3d.new; rb2 = Geom::Point3d.new ; rg2 = Geom::Point3d.new
	gb  = [[0,0,0],[0, w*gdir, 0], [0, w*gdir, d*bdir], [0, 0, d*bdir],[0,0,0]]
  gb2 =  [[0,0,0],[0, d*gdir, 0], [0, d*gdir, w*bdir], [0, 0, w*bdir],[0,0,0]]
	rb  = [[0,0,0],[w*rdir, 0, 0], [w*rdir, 0, d*bdir], [0, 0, d*bdir],[0,0,0]]
  rb2 = [[0,0,0],[d*rdir, 0, 0], [d*rdir, 0, w*bdir], [0, 0, w*bdir],[0,0,0]]
	rg  = [[0,0,0],[w*rdir, 0, 0], [w*rdir, d*gdir, 0], [0, d*gdir, 0],[0,0,0]]
  rg2 = [[0,0,0],[d*rdir, 0, 0], [d*rdir, w*gdir, 0], [0, w*gdir, 0],[0,0,0]]
	cross_sect = [gb, gb2, rb,rb2, rg]
 	@lAxis = Geom::Vector3d.new 
	if @@axis_lock == X_AXIS 
		@plane = 'gb'
		text = "\ngb plane"
		n = 0 
	if vec[b].abs > vec[g].abs 
    n = 1
	end
	elsif  @@axis_lock == Y_AXIS
		@plane = 'rb'
	  text = "\nrb plane"
	  n = 2 
	if vec[b].abs > vec[r].abs 
    n = 3
	end
	elsif @@axis_lock == Z_AXIS
		@plane = 'rg'
	  text = "\nrg plane"
	n = 4 
	if vec[g].abs > vec[r].abs 
  n = 5
	end
	else
		@plane = 'no'
	  text = "\nnon-orthogonal plane"
	end
	view.draw_text view.  screen_coords(pt2), @cursor_text 
	if @plane != "no" 
		view.line_width = 2; view.line_stipple = ""
		@lAxis[(n/2).to_int] = d*2.0 
		@lAxis.transform!(@tf)
		view.set_color_from_line(pt1 - @lAxis, pt1 + @lAxis)
		view.draw_line(pt1 - @lAxis, pt1 + @lAxis) 
		@pts = []; @pts0 = []
		cross_sect[n].each_index {|i| @pts0[i] = cross_sect[n][i]}
		ip = @tf.origin 
		vec = ip.vector_to(pt1) 
		@tf2 = translate(@tf,vec) 
		@pts0.each_index {|i| @pts[i] = @pts0[i].transform(@tf2)}
		view.drawing_color = "magenta" 
		view.draw_polyline(@pts)
	end 
	end
def draw_geometry ( pt1 , pt2 , view ) w = @@act_size [ 0 ] d = @@act_size [ 1 ] r = 0 ; g = 1 ; b = 2 rdir = 1.0 gdir = 1.0 bdir = 1.0 vec = pt2 - pt1 rdir = - 1.0 if vec [ r ] < 0 gdir = - 1.0 if vec [ g ] < 0 bdir = - 1.0 if vec [ b ] < 0 gb = Geom :: Point3d . new ; rb = Geom :: Point3d . new ; rg = Geom :: Point3d . new gb2 = Geom :: Point3d . new ; rb2 = Geom :: Point3d . new ; rg2 = Geom :: Point3d . new gb = [ [ 0 , 0 , 0 ] , [ 0 , w * gdir , 0 ] , [ 0 , w * gdir , d * bdir ] , [ 0 , 0 , d * bdir ] , [ 0 , 0 , 0 ] ] gb2 = [ [ 0 , 0 , 0 ] , [ 0 , d * gdir , 0 ] , [ 0 , d * gdir , w * bdir ] , [ 0 , 0 , w * bdir ] , [ 0 , 0 , 0 ] ] rb = [ [ 0 , 0 , 0 ] , [ w * rdir , 0 , 0 ] , [ w * rdir , 0 , d * bdir ] , [ 0 , 0 , d * bdir ] , [ 0 , 0 , 0 ] ] rb2 = [ [ 0 , 0 , 0 ] , [ d * rdir , 0 , 0 ] , [ d * rdir , 0 , w * bdir ] , [ 0 , 0 , w * bdir ] , [ 0 , 0 , 0 ] ] rg = [ [ 0 , 0 , 0 ] , [ w * rdir , 0 , 0 ] , [ w * rdir , d * gdir , 0 ] , [ 0 , d * gdir , 0 ] , [ 0 , 0 , 0 ] ] rg2 = [ [ 0 , 0 , 0 ] , [ d * rdir , 0 , 0 ] , [ d * rdir , w * gdir , 0 ] , [ 0 , w * gdir , 0 ] , [ 0 , 0 , 0 ] ] cross_sect = [ gb , gb2 , rb , rb2 , rg ] @lAxis = Geom :: Vector3d . new if @@axis_lock == X_AXIS @plane = 'gb' text = "\ngb plane" n = 0 if vec [ b ] . abs > vec [ g ] . abs n = 1 end elsif @@axis_lock == Y_AXIS @plane = 'rb' text = "\nrb plane" n = 2 if vec [ b ] . abs > vec [ r ] . abs n = 3 end elsif @@axis_lock == Z_AXIS @plane = 'rg' text = "\nrg plane" n = 4 if vec [ g ] . abs > vec [ r ] . abs n = 5 end else @plane = 'no' text = "\nnon-orthogonal plane" end view . draw_text view . screen_coords ( pt2 ) , @cursor_text if @plane != "no" view . line_width = 2 ; view . line_stipple = "" @lAxis [ ( n / 2 ) . to_int ] = d * 2.0 @lAxis . transform! ( @tf ) view . set_color_from_line ( pt1 - @lAxis , pt1 + @lAxis ) view . draw_line ( pt1 - @lAxis , pt1 + @lAxis ) @pts = [ ] ; @pts0 = [ ] cross_sect [ n ] . each_index { | i | @pts0 [ i ] = cross_sect [ n ] [ i ] } ip = @tf . origin vec = ip . vector_to ( pt1 ) @tf2 = translate ( @tf , vec ) @pts0 . each_index { | i | @pts [ i ] = @pts0 [ i ] . transform ( @tf2 ) } view . drawing_color = "magenta" view . draw_polyline ( @pts ) end end
Draw the geometry
This section of code feeds back to the user the size and orientation of the face that will be created to
start drawing a piece of timber.
Draw the geometry This section of code feeds back to the user the size and orientation of the face that will be created to start drawing a piece of timber .
# Set local variables to actual width and depth of wood cross-section # Width of wood # Depth of wood # Orient the rectangle for wood cross section according to (initially only orthogonal) plane of #   pt1 - pt2, which are first pick point, and current mouse (inferred) position, respectively # Set axis labels (red, green, blue) to match index of 3D points # Plane is defined by the direction of its normal # Calculate orientation of vec # direction positive # direction negative # Set up different orientations of cross-section # gb plane # Reverse width and depth # rb plane # Reverse width and depth # rg plane # Reverse width and depth # Put cross_section into an array of different orientations #Direction of long axis of wood (normal to plane of cross-section) #normal is in r direction # then swap width and depth dimensions # cross_sect[1] = [[0,0,0],[0, d*gdir, 0], [0, d*gdir, w*bdir], [0, 0, w*bdir],[0,0,0]] #normal is in g direction # then rotate wood cross section # cross_sect[3] = [[0,0,0],[d*rdir, 0, 0], [d*rdir, 0, w*bdir], [0, 0, w*bdir],[0,0,0]] #normal is in b direction #puts "b-value = " + vec[b].to_s + " g-value = " + vec[g].to_s # then rotate wood cross section # cross_sect[5] = [[0,0,0],[d*rdir, 0, 0], [d*rdir, w*gdir, 0], [0, w*gdir, 0],[0,0,0] ] ###puts "Text set to " + text # Give feedback at cursor #for orthogonal cases only  # Set long axis direction normal to @plane # to show direction of long axis of wood #@pts = [cross_sect[n][0], cross_sect[n][1], cross_sect[n][2], cross_sect[n][3], cross_sect[n][4]] # Relocate drawn cross section to pick point location # Transform @tf moves to origin of component (if any) that initial click was on # Have to move and rotate drawn component from World origin first to component origin,  #   then add translation to pick point # Vector from component or world origin  # Component or World origin # Vector from there to pick point # Uses Martin Rinehart's translate function included below #puts "@pts0[] = \n" + @pts0.to_a.inspect #@pts.each {|pt| pt.transform!(@tf) } # Transform points into axes of component clicked (?) #puts "@pts.transformed![] = \n" + @pts.to_a.inspect #if 
pt1
<not_specific>
pt2
<not_specific>
view
<not_specific>