###---------------------------------------------------------------------
#	Name : Grow.rb
# Description : Plugins > Grow - Copy, Rotate & Scale selection...
# Author:  TIG (c) 2007-2013
# Install: Put Grow.rb into Plugins folder.
#         Put growCursor.png in Plugins/Icons/ folder.
#         (make folder if it doesn't exist)
# Usage : Move/Place Objects,Select them and pick Grow.  Pick Point, 
#         Enter desired data in dialogs and see results.  Undo is 1 go.
#         Ungrouped Faces and Edges can stick together after 'Growing'.
#         Play around to see types of results...
#         Shape, location, scale, order all produce different results...
#         Linear Scaling goes 1 2 3 4 5 6 7... on any scaling factor
#         Exponential + goes 1 2 4 8 16 32... on any scaling factor !=1
#         Exponential - goes 1 1/2 1/4 1/8 1/16 1/32... on any scaling factor !=1
#         Fibonacci + goes 1 1 2 3 5 8 13... on any scaling factor
#         Fibonacci - goes 1 1 1/2 1/3 1/5 1/8 1/13... on any scaling factor
# Version : 1.0  20070207 First issue.
#           1.1  20070209 General tweaking,1 copy type,origin option.
#			      1.2  20070210 Revised scaling options etc, added pick point.
#           1.3  20070211 Units simplified, scaling dialogs separated, 
#                         two scaling types (Exponential/Fibonacci) and 
#                         operation ordering added.
#           1.4  20070212 Methods tweaked to sort Mac errors.
#           2.0  20070218 Added Grow Pointer cursor.
#                         Dialog 'Use Scaling' > 'No' = no scaling. 
#                         Now Linear, Expo' + & -, and Fibo' + & -.
#                         Order of XYZ rotation changeable.
#			2.1	20070120  Bugspalts with new versions of SUp trapped.
#           2.2 20120519  Clash with some rogue scripts selction observers fixed.
#           2.3 20120519 More 3rd party rogue script messes fixed !
#           2.4 20131205 Future-proofed.
#			2.5 20131222 Custom-cursor glitch trapped on MACs.
#			2.6 20131223 MAC friendly cursors reintroduced.
#
###---------------------------------------------------------------------
require 'sketchup.rb'
### ####################################################################
class Grow_TIG
  ###
  @@growCursor=nil
### point picker
### initialize on tool activation
def initialize()
  unless @@growCursor
    gpath=File.join((File.dirname(__FILE__)), "Icons", "growCursor.png")
	if gpath
      @@growCursor=UI::create_cursor(gpath,0,31)
    #else
      #UI.beep
    end#if
  end### growCursor.png MUST be in ../Plugins/Icons/ folder
end
def activate
  @ip=Sketchup::InputPoint.new
  @iptemp=Sketchup::InputPoint.new
  @displayed=false
  @model=Sketchup.active_model
  @ss=@model.selection
  if @ss.empty?
    Sketchup::set_status_text("GROW: NO SELECTION ! ",SB_PROMPT)
    UI.beep
    UI.messagebox("Grow:\nNo Selection !\n\nFirst Select Object(s)\nThen 'Grow'\nThen Pick 'Growth' Point\nThen Input Parameters in Dialogs... \n")
    Sketchup.send_action("selectSelectionTool:")
    return nil
  end
end
### set cursor
def onSetCursor()
	#return nil if RUBY_PLATFORM =~ /darwin/
	UI::set_cursor(@@growCursor) if @@growCursor
end
### on MouseMove display InputPoint and update VCB
def onMouseMove(flags,x,y,view)
  ### show VCB and status info
  Sketchup::set_status_text("GROW: Pick Point for 'Growth'... ",SB_PROMPT)
  Sketchup::set_status_text("Point: ",SB_VCB_LABEL)
  Sketchup::set_status_text("#{@ip.position}",SB_VCB_VALUE)
  view.tooltip="Growth Point: "+@ip.tooltip ###show on tooltip
  ### get position in the model
  @iptemp.pick(view,x,y)
  if(@iptemp.valid?)
    changed=@iptemp!=@ip
    @ip.copy!(@iptemp)
    @pos=@ip.position
    ### view update? 
    if changed && (@ip.display? || @displayed) 
      view.invalidate
    end
  end
end
### on left click add text
def onLButtonDown(flags,x,y,view)
  pickpoint=@ip.position
  Grow_TIG::run(pickpoint)
  Sketchup.send_action("selectSelectionTool:")
end
### update the view
def draw(view)
   if(@ip.valid? && @ip.display?)
      @ip.draw(view)
      @displayed=true
   else
      @displayed=false
   end
end
### run grower
def Grow_TIG::run(pickpoint)
  @pickpoint=pickpoint
  @model=Sketchup.active_model
  @model.start_operation("Grow")
  @entities=@model.active_entities
  @ss=@model.selection
### get points
@group=@entities.add_group(@ss.to_a)
@gtrans=@group.transformation
@gpoint=@gtrans.origin
@gx=@gpoint.x
@gy=@gpoint.y
@gz=@gpoint.z
@ppoint=Geom::Point3d.new(@pickpoint.x-@gx,@pickpoint.y-@gy,@pickpoint.z-@gz)
### get current units
@units="???"
@units="inches" if @model.options["UnitsOptions"]["LengthUnit"]==0
@units="feet" if @model.options["UnitsOptions"]["LengthUnit"]==1
@units="mm" if @model.options["UnitsOptions"]["LengthUnit"]==2
@units="cm" if @model.options["UnitsOptions"]["LengthUnit"]==3
@units="m" if @model.options["UnitsOptions"]["LengthUnit"]==4
### defaults
  unless @numcopies
    ###
	@numcopies=10
	###
    if @units=~/m$/ ### metric units so these are in mm
      @xspace=0.mm
      @yspace=0.mm
      @zspace=150.mm
    else ### not metric so these are in feet ?
      @xspace=0.feet
      @yspace=0.feet
      @zspace=0.5.feet
    end #if
    ###
    @xrotate=0.0
    @yrotate=0.0
    @zrotate=36.0
    ###
    @scaling="No"
    ###
    @xspacescale=1.0
    @xspsctype="Exponential +"
    @yspacescale=1.0
    @yspsctype="Exponential +"
    @zspacescale=1.0
    @zspsctype="Exponential +"
    ###
    @xrotatescale=1.0
    @xrosctype="Exponential +"
    @yrotatescale=1.0
    @yrosctype="Exponential +"
    @zrotatescale=1.0
    @zrosctype="Exponential +"
    ###
    @xscale=1.0
    @xsctype="Exponential +"
    @yscale=1.0
    @ysctype="Exponential +"
    @zscale=1.0
    @zsctype="Exponential +"
    ###
    @order="Move Rotate Scale" unless @order
    ###
    @xyzrotation="X Y Z" unless @xyzrotation
	###
  end
###
def Grow_TIG::dialog1(numc)
### dialog 1
  @numcopies=numc
### show VCB and status info
  Sketchup::set_status_text(("GROW... Parameters ("+@units+"/degrees)..." ),SB_PROMPT)
  Sketchup::set_status_text(" ",SB_VCB_LABEL)
  Sketchup::set_status_text(" ",SB_VCB_VALUE)
###
  prompts=["Number of Copies: ", "X Spacing (#{@units}): ", ("Y Spacing (#{@units}): "), ("Z Spacing (#{@units}): "), "X Rotation(degrees): ", "Y Rotation(degrees): ", "Z Rotation(degrees): ","Use Scaling ? : "]
  values=[@numcopies, @xspace, @yspace, @zspace, @xrotate, @yrotate, @zrotate, @scaling]
  popups=["", "", "", "", "", "", "", "Yes|No"]
  results=inputbox(prompts,values,popups,"Grow: Parameters (#{@units}/degrees)")
  if not results
    @group.explode if @group.valid?
    return nil
  end#if
  num=results[0]
  if num < 1
    @numcopies=1
    UI.beep
    UI.messagebox("Grow:\n\nThe Number of Copies MUST be at least 1.")
    results=Grow_TIG::dialog1(@numcopies)
  else
    return results
  end#if
end#def dialog1
###
  results=Grow_TIG::dialog1(@numcopies)
  return nil if not results
###
  @numcopies=results[0]
  ###
  @xspace=results[1]
  @yspace=results[2]
  @zspace=results[3]
###
  @xrotate=results[4]
  @yrotate=results[5]
  @zrotate=results[6]
###
  @scaling=results[7]
###
###
### dialog 2
def Grow_TIG::dialog2(scal,xscal,yscal,zscal)
@scaling=scal;@xscale=xscal;@yscale=yscal;@zscale=zscal
if @scaling=="Yes"
### show VCB and status info
  Sketchup::set_status_text(("GROW... Scaling..." ),SB_PROMPT)
  Sketchup::set_status_text(" ",SB_VCB_LABEL)
  Sketchup::set_status_text(" ",SB_VCB_VALUE)
###
  prompts=["X Spacing Scaling:   ","  X Spacing Scaling Type: ","Y Spacing Scaling:   ","  Y Spacing Scaling Type: ","Z Spacing Scaling:   ","  Z Spacing Scaling Type: ","X Rotation Scaling:   ","  X Rotation Scaling Type: ","Y Rotation Scaling:   ","  Y Rotation Scaling Type: ","Z Rotation Scaling:   ","  Z Rotation Scaling Type: ","X Copy Scaling:   ","  X Copy Scaling Type: ","Y Copy Scaling:   ","  Y Copy Scaling Type: ","Z Copy Scaling:   ","  Z Copy Scaling Type: "]
  values=[@xspacescale,@xspsctype,@yspacescale,@yspsctype,@zspacescale,@zspsctype,@xrotatescale,@xrosctype,@yrotatescale,@yrosctype,@zrotatescale,@zrosctype,@xscale,@xsctype,@yscale,@ysctype,@zscale,@zsctype]
  sctype="Linear|Exponential +|Exponential -|Fibonacci +|Fibonacci -"
  popups=["",sctype,"",sctype,"",sctype,"",sctype,"",sctype,"",sctype,"",sctype,"",sctype,"",sctype]
  results=inputbox(prompts,values,popups,"Grow: Scaling Parameters")
  if not results
    @group.explode if @group.valid?
    return nil
  end#if
###
  if results[12]==0
    @xscale=1.0
    UI.beep
    UI.messagebox("Grow:\n\nX Copy Scaling CANNOT be 0.")
    results=Grow_TIG::dialog2(@scaling,@xscale,@yscale,@zscale)
  end#if
  if results[14]==0
    @yscale=1.0
    UI.beep
    UI.messagebox("Grow:\n\nY Copy Scaling CANNOT be 0.")
    results=Grow_TIG::dialog2(@scaling,@xscale,@yscale,@zscale)
  end#if
  if results[16]==0
    @zscale=1.0
    UI.beep
    UI.messagebox("Grow:\n\nZ Copy Scaling CANNOT be 0.")
     results=Grow_TIG::dialog2(@scaling,@xscale,@yscale,@zscale)
  end#if
  ###
  return results if results
  ###
else#NO scaling
  return "NO SCALING"
end#if
end#def dialog2
###
results=Grow_TIG::dialog2(@scaling, @xscale, @yscale, @zscale)
###
if results
 if results!="NO SCALING"
  @xspacescale=results[0]
  @xspsctype=results[1]
  @yspacescale=results[2]
  @yspsctype=results[3]
  @zspacescale=results[4]
  @zspsctype=results[5]
  ###
  @xrotatescale=results[6]
  @xrosctype=results[7]
  @yrotatescale=results[8]
  @yrosctype=results[9]
  @zrotatescale=results[10]
  @zrosctype=results[11]
  ###
  @xscale=results[12]
  @xsctype=results[13]
  @yscale=results[14]
  @ysctype=results[15]
  @zscale=results[16]
  @zsctype=results[17]
 end#if
else# cancelled
  @group.explode if @group.valid?
  return nil
end#if results
###
def Grow_TIG::dialog3(ord, xyz)
### ordering dialog 3
### show VCB and status info
  Sketchup::set_status_text(("GROW... Order..." ),SB_PROMPT)
  Sketchup::set_status_text(" ",SB_VCB_LABEL)
  Sketchup::set_status_text(" ",SB_VCB_VALUE)
###
prompts=["Order of Operations: ","Order of Rotation: "]
values=[ord, xyz]
ordtype="Move Rotate Scale|Move Scale Rotate|Rotate Move Scale|Rotate Scale Move|Scale Move Rotate |Scale Rotate Move"
xyztype="X Y Z|X Z Y|Y X Z|Y Z X|Z X Y|Z Y X"
popups=[ordtype, xyztype]
results=inputbox(prompts,values,popups,"Grow: Order Parameters")
  unless results
    @group.explode if @group.valid?
    return nil
  else
    return results
  end#if
end#def dialog3
###
results=Grow_TIG::dialog3(@order, @xyzrotation)
###
if results
  @order, @xyzrotation = results
else
  return nil
end#if
###
def Grow_TIG::copy()
  @copies=[]
  0.upto(@numcopies){
    copy=@entities.add_instance(@group.entities.parent, @group.transformation)
    @copies << copy
  }#upto
end#def
###
def Grow_TIG::move()
  xspace=@xspace; yspace=@yspace; zspace=@zspace
  x=@gx; y=@gy; z=@gz
  if @scaling=="Yes"
    xspacescale=@xspacescale; yspacescale=@yspacescale; zspacescale=@zspacescale
  else
    xspacescale=1.0; yspacescale=1.0; zspacescale=1.0
  end#if
  ### for Linear
  ###
  xspaceFib1=0;yspaceFib1=0;zspaceFib1=0
  xspaceFib2=xspace;yspaceFib2=yspace;zspaceFib2=zspace
  counter=0
  @copies.each{|e|
    point=Geom::Point3d.new(x,y,z)
    transform=Geom::Transformation.new(point)
    e.move!(transform)
    if counter==0
      x=@gx+xspace;y=@gy+yspace;z=@gz+zspace
    else
      xspacescale=xspacescale+@xspacescale if @xspsctype=="Linear" && @scaling=="Yes"
      yspacescale=yspacescale+@yspacescale if @yspsctype=="Linear" && @scaling=="Yes"
      zspacescale=zspacescale+@zspacescale if @zspsctype=="Linear" && @scaling=="Yes"
      ###
      xspace=@xspace*xspacescale if @xspsctype=="Linear" && @scaling=="Yes"
      yspace=@yspace*yspacescale if @yspsctype=="Linear" && @scaling=="Yes"
      zspace=@zspace*zspacescale if @zspsctype=="Linear" && @scaling=="Yes"
      ###
      xspace=xspace*xspacescale if @xspsctype=="Exponential +"
      yspace=yspace*yspacescale if @yspsctype=="Exponential +"
      zspace=zspace*zspacescale if @zspsctype=="Exponential +"
      ###
      xspace=xspace/xspacescale if @xspsctype=="Exponential -"
      yspace=yspace/yspacescale if @yspsctype=="Exponential -"
      zspace=zspace/zspacescale if @zspsctype=="Exponential -"
      ###
      f=xspaceFib2;xspaceFib2=xspaceFib1+xspaceFib2;xspaceFib1=f
      f=yspaceFib2;yspaceFib2=yspaceFib1+yspaceFib2;yspaceFib1=f
      f=zspaceFib2;zspaceFib2=zspaceFib1+zspaceFib2;zspaceFib1=f
      xspace=xspaceFib2 if @xspsctype=="Fibonacci +" && @scaling=="Yes"
      yspace=yspaceFib2 if @yspsctype=="Fibonacci +" && @scaling=="Yes"
      zspace=zspaceFib2 if @zspsctype=="Fibonacci +" && @scaling=="Yes"
      ###
      xspace=1/xspaceFib2 if @xspsctype=="Fibonacci -" && @scaling=="Yes"
      yspace=1/yspaceFib2 if @yspsctype=="Fibonacci -" && @scaling=="Yes"
      zspace=1/zspaceFib2 if @zspsctype=="Fibonacci -" && @scaling=="Yes"
      ###
      x=x+xspace;y=y+yspace;z=z+zspace
    end#if
    counter=1
  }#end each
end#def
###
def Grow_TIG::rotateX()
  xrotate=@xrotate;xrot=-xrotate
  if @scaling=="Yes"
    xrotatescale=@xrotatescale
  else
    xrotatescale=1.0
  end#if
  xrotateFib1=0;xrotateFib2=xrotatescale
  xinc=@xrotate*@xrotatescale
  @copies.each{|e|
    xrot=xrot+xrotate
    ###
    p=Geom::Point3d.new(@ppoint.transform(e.transformation))
    ###
    v=Geom::Vector3d.new(1,0,0)
    r=Math::PI*xrot/180
    rotate=Geom::Transformation.rotation(p,v,r)
    e.transform!(rotate)
    ###
    xrotate=xrotate*xrotatescale if @scaling=="No"
    ###
    xrotatescale=xrotatescale+@xrotatescale if @xrosctype=="Linear" && @scaling=="Yes"
    xrotate=@xrotate*xrotatescale if @xrosctype=="Linear" && @scaling=="Yes"
    ###
    xrotate=xrotate*xrotatescale if @xrosctype=="Exponential +" && @scaling=="Yes"
    xrotate=xrotate/xrotatescale if @xrosctype=="Exponential -" && @scaling=="Yes"
    ###
    f=xrotateFib2;xrotateFib2=xrotateFib1+xrotateFib2;xrotateFib1=f
    xrotate=xrotate*xrotateFib2 if @xrosctype=="Fibonacci +" && @scaling=="Yes"
    xrotate=xrotate/xrotateFib2 if @xrosctype=="Fibonacci -" && @scaling=="Yes"
    ###
  }#end each
end#def
def Grow_TIG::rotateY()
  yrotate=@yrotate;yrot=-yrotate
  if @scaling=="Yes"
    yrotatescale=@yrotatescale
  else
    yrotatescale=1.0
  end#if
  yrotateFib1=0;yrotateFib2=yrotatescale
  yinc=@yrotate*@yrotatescale
  @copies.each{|e|
    yrot=yrot+yrotate
    ###
    p=Geom::Point3d.new(@ppoint.transform(e.transformation))
    ###
    v=Geom::Vector3d.new(0,1,0)
    r=Math::PI*yrot/180
    rotate=Geom::Transformation.rotation(p,v,r)
    e.transform!(rotate)
    ###
    yrotate=yrotate*yrotatescale if @scaling=="No"
    ###
    yrotatescale=yrotatescale+@yrotatescale if @yrosctype=="Linear" && @scaling=="Yes"
    yrotate=@yrotate*yrotatescale if @yrosctype=="Linear" && @scaling=="Yes"
    ###
    yrotate=yrotate*yrotatescale if @yrosctype=="Exponential +" && @scaling=="Yes"
    yrotate=yrotate/yrotatescale if @yrosctype=="Exponential -" && @scaling=="Yes"
    ###
    f=yrotateFib2;yrotateFib2=yrotateFib1+yrotateFib2;yrotateFib1=f
    yrotate=yrotate*yrotateFib2 if @yrosctype=="Fibonacci +" && @scaling=="Yes"
    yrotate=yrotate/yrotateFib2 if @yrosctype=="Fibonacci -" && @scaling=="Yes"
    ###
  }#end each
end#def
def Grow_TIG::rotateZ()
  zrotate=@zrotate
  zrot=-zrotate
  if @scaling=="Yes"
    zrotatescale=@zrotatescale
  else
    zrotatescale=1.0
  end#if
  zrotateFib1=0;zrotateFib2=zrotatescale
  zinc=@zrotate*@zrotatescale
  @copies.each{|e|
    zrot=zrot+zrotate
    ###
    p=Geom::Point3d.new(@ppoint.transform(e.transformation))
    ###
    v=Geom::Vector3d.new(0,0,1)
    r=Math::PI*zrot/180
    rotate=Geom::Transformation.rotation(p,v,r)
    e.transform!(rotate)
    ### 
    zrotate=zrotate*zrotatescale if @scaling=="No"
    ###
    zrotatescale=zrotatescale+@zrotatescale if @zrosctype=="Linear" && @scaling=="Yes"
    zrotate=@zrotate*zrotatescale if @zrosctype=="Linear" && @scaling=="Yes"
    ###
    zrotate=zrotate*zrotatescale if @zrosctype=="Exponential +" && @scaling=="Yes"
    zrotate=zrotate/zrotatescale if @zrosctype=="Exponential -" && @scaling=="Yes"
    ###
    f=zrotateFib2;zrotateFib2=zrotateFib1+zrotateFib2;zrotateFib1=f
    zrotate=zrotate*zrotateFib2 if @zrosctype=="Fibonacci +" && @scaling=="Yes"
    zrotate=zrotate/zrotateFib2 if @zrosctype=="Fibonacci -" && @scaling=="Yes"
    ###
  }#end each
end#def
###
def Grow_TIG::rotate()
  case @xyzrotation
	when "X Y Z"
		Grow_TIG::rotateX();Grow_TIG::rotateY();Grow_TIG::rotateZ()
	when "X Z Y"
		Grow_TIG::rotateX();Grow_TIG::rotateZ();Grow_TIG::rotateY()
	when "Y X Z"
		Grow_TIG::rotateY();Grow_TIG::rotateX();Grow_TIG::rotateZ()
	when "Y Z X"
		Grow_TIG::rotateY();Grow_TIG::rotateZ();Grow_TIG::rotateX()
	when "Z X Y"
		Grow_TIG::rotateZ();Grow_TIG::rotateX();Grow_TIG::rotateY()
	when"Z Y X"
		Grow_TIG::rotateZ();Grow_TIG::rotateY();Grow_TIG::rotateX()
	else
		Grow_TIG::rotateX();Grow_TIG::rotateY();Grow_TIG::rotateZ()
  end#case
end#def
###
def Grow_TIG::scale()
  xscale=1.0;yscale=1.0;zscale=1.0
  if @scaling=="Yes"
    xscale2=@xscale;yscale2=@yscale;zscale2=@zscale
  else
    xscale2=1.0;yscale2=1.0;zscale2=1.0
  end#if
  xFib1=0;yFib1=0;zFib1=0
  xFib2=xscale2;yFib2=yscale2;zFib2=zscale2
  xscale=xFib2 if @xsctype=="Fibonacci +" && @scaling=="Yes"
  yscale=yFib2 if @ysctype=="Fibonacci +" && @scaling=="Yes"
  zscale=zFib2 if @zsctype=="Fibonacci +" && @scaling=="Yes"
  xscale=xFib2 if @xsctype=="Fibonacci -" && @scaling=="Yes"
  yscale=yFib2 if @ysctype=="Fibonacci -" && @scaling=="Yes"
  zscale=zFib2 if @zsctype=="Fibonacci -" && @scaling=="Yes"
  ###
  @copies.each{|e|
    p=Geom::Point3d.new(@ppoint.transform(e.transformation))
    scaler=Geom::Transformation.scaling(p,xscale,yscale,zscale)
    e.transform!(scaler)
    ###
    xscale=xscale*xscale2 if @scaling=="No"
    yscale=yscale*yscale2 if @scaling=="No"
    zscale=zscale*zscale2 if @scaling=="No"
    ###
    xscale=xscale+@xscale if @xsctype=="Linear" && @scaling=="Yes"
    yscale=yscale+@yscale if @ysctype=="Linear" && @scaling=="Yes"
    zscale=zscale+@zscale if @zsctype=="Linear" && @scaling=="Yes"
    ###
    xscale=xscale*xscale2 if @xsctype=="Linear" && @scaling=="Yes"
    yscale=yscale*yscale2 if @ysctype=="Linear" && @scaling=="Yes"
    zscale=zscale*zscale2 if @zsctype=="Linear" && @scaling=="Yes"
    ###
    xscale=xscale*xscale2 if @xsctype=="Exponential +" && @scaling=="Yes"
    yscale=yscale*yscale2 if @ysctype=="Exponential +" && @scaling=="Yes"
    zscale=zscale*zscale2 if @zsctype=="Exponential +" && @scaling=="Yes"
    ###
    xscale=xscale/xscale2 if @xsctype=="Exponential -" && @scaling=="Yes"
    yscale=yscale/yscale2 if @ysctype=="Exponential -" && @scaling=="Yes"
    zscale=zscale/zscale2 if @zsctype=="Exponential -" && @scaling=="Yes"
    ###
    f=xFib2;xFib2=xFib1+xFib2;xFib1=f
    f=yFib2;yFib2=yFib1+yFib2;yFib1=f
    f=zFib2;zFib2=zFib1+zFib2;zFib1=f
    xscale=xFib2 if @xsctype=="Fibonacci +" && @scaling=="Yes"
    yscale=yFib2 if @ysctype=="Fibonacci +" && @scaling=="Yes"
    zscale=zFib2 if @zsctype=="Fibonacci +" && @scaling=="Yes"
    ###
    xscale=1/xFib2 if @xsctype=="Fibonacci -" && @scaling=="Yes"
    yscale=1/yFib2 if @ysctype=="Fibonacci -" && @scaling=="Yes"
    zscale=1/zFib2 if @zsctype=="Fibonacci -" && @scaling=="Yes"
  }#end each
end#def
### growth do stuff...
Grow_TIG::copy()
### ordering
  case @order
	when "Move Rotate Scale"
		Grow_TIG::move();Grow_TIG::rotate();Grow_TIG::scale()
	when "Move Scale Rotate"
		Grow_TIG::move();Grow_TIG::scale();Grow_TIG::rotate()
	when "Rotate Move Scale"
		Grow_TIG::rotate();Grow_TIG::move();Grow_TIG::scale()
	when "Rotate Scale Move"
		Grow_TIG::rotate();Grow_TIG::scale();Grow_TIG::move()
	when "Scale Move Rotate"
		Grow_TIG::scale();Grow_TIG::move();Grow_TIG::rotate()
	when "Scale Rotate Move"
		Grow_TIG::scale();Grow_TIG::rotate();Grow_TIG::move()
    else
		Grow_TIG::move();Grow_TIG::rotate();Grow_TIG::scale()
  end#case
###
### tidy up...
### remove 'spare' original group...
@group.erase! if @group.valid?
### return copies back to original state...
@copies.each{|e|e.explode if e.valid?}
### commit for total undo
  @model.commit_operation
###
end#def
end#class
### menu  #### #########################################################
unless file_loaded?(File.basename(__FILE__))###
  ###UI.menu("Plugins").add_separator
  UI.menu("Plugins").add_item("Grow"){Sketchup.active_model.select_tool(Grow_TIG.new())}
  ###$submenu5.add_item("Grow [Selection]"){Sketchup.active_model.select_tool(Grow_TIG.new)}
end#if
file_loaded(File.basename(__FILE__))
### ####################################################################
