#################################
### COPYRIGHT: Anders Lyhagen ###
#################################

module CAUL_FAQS

load File.join(File.expand_path(File.dirname(__FILE__)), "Cut.rb")
load File.join(File.expand_path(File.dirname(__FILE__)), "EdgeHash.rb")
load File.join(File.expand_path(File.dirname(__FILE__)), "FaceHash.rb")
load File.join(File.expand_path(File.dirname(__FILE__)), "Flow.rb")
load File.join(File.expand_path(File.dirname(__FILE__)), "FlowAuxScripts.rb")
load File.join(File.expand_path(File.dirname(__FILE__)), "FlowData.rb")
load File.join(File.expand_path(File.dirname(__FILE__)), "FlowInput.rb")
load File.join(File.expand_path(File.dirname(__FILE__)), "GridParser.rb")
load File.join(File.expand_path(File.dirname(__FILE__)), "Input.rb")
load File.join(File.expand_path(File.dirname(__FILE__)), "Matrix.rb")
load File.join(File.expand_path(File.dirname(__FILE__)), "ProjectionInput.rb")
load File.join(File.expand_path(File.dirname(__FILE__)), "QuadGrid.rb")
load File.join(File.expand_path(File.dirname(__FILE__)), "VertexHash.rb")
  
module Main


  def self.main(mode)
     
    mod = Sketchup.active_model
    ent = mod.entities
    sel = mod.selection
    
    status = true
    error = ''
    
    if mode == 0 #Flow along
      mod.start_operation("Flowify", true)
      status = FlowInput.flowMain(ent, sel, 0)
      error = FlowInput.getErrorString()
      mod.commit_operation if status == true
    elsif mode == 1 #project Along
      mod.start_operation("Project Along", true)
      Projection.projectMain(ent, sel)
      mod.commit_operation      
    elsif mode == 2 #Edge -> Cline
      mod.start_operation("Convert To CLine", true)
      FlowAlongAux.convertToCLines(sel)
      mod.commit_operation
    elsif mode == 3 #Edge -> Quad Dia
      mod.start_operation("Convert To Quad Dia", true)
      FlowAlongAux.convertDiagonal(sel)
      mod.commit_operation
    elsif mode == 4 #Create Proj Plane
      mod.start_operation("Create Proj Plane", true)
      FlowAlongAux.constructProjPlane(ent, sel)
      mod.commit_operation
    elsif mode == 5 #Add CPoint
      mod.start_operation("Add CPoint", true)
      FlowAlongAux.addConstructionPoint(sel)
      mod.commit_operation
    elsif mode == 6 #Cut
      mod.start_operation("Cut", true)
      status = FlowInput.flowMain(ent, sel, 1)
      error = FlowInput.getErrorString()
      mod.commit_operation if status == true
    elsif mode == 7 #Flow Without Cut
      mod.start_operation("Flowify without Cut", true)
      status = FlowInput.flowMain(ent, sel, 2)
      error = FlowInput.getErrorString()
      mod.commit_operation if status == true
    elsif mode == 8 #Reconstruct Path
      mod.start_operation("Flow Along", true)
      FlowAlongAux.reshapePath(ent, sel)
      mod.commit_operation
    elsif mode == 9 #Reconstruct Path
      mod.start_operation("Impose Grid", true)
      Input.imposeGrid(sel)
      mod.commit_operation
    end
    
    if status == false
      UI.messagebox(error)
    end
    
  end
  
  unless file_loaded?( __FILE__ )
    menu = UI.menu( 'Plugins' )
    sub = menu.add_submenu('Flowify')
    sub.add_item('Flowify') {self.main 0}
    sub.add_separator
    subsub = sub.add_submenu('Aux')
       subsub.add_item( 'Reconstruct Path' ) { self.main 8}
       subsub.add_item( 'Edge -> CLine' ) { self.main 2}
    sub.add_separator
    sub.add_item('Impose Grid') {self.main 9}
    sub.add_item( 'Cut' ) { self.main 6}
    sub.add_item( 'Flowify without Cut' ) { self.main 7}
  end
  
  file_loaded( __FILE__ )

end
end
