=begin
#-------------------------------------------------------------------------------------------------------------------------------------------------
#*************************************************************************************************
# Designed April 2012 by Fredo6

# Permission to use this software for any purpose and without fee is hereby granted
# Distribution of this software for commercial purpose is subject to:
#  - the expressed, written consent of the author
#  - the inclusion of the present copyright notice in all copies.

# THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#-----------------------------------------------------------------------------
# Name			:   bootstrap_Curvizard.rb
# Original Date	:   21 Apr 2012
# Description	:   Bootstrap Loader for the Curvizard scripts
# Usage			:   This is the only Ruby file loaded at SU startup
#-------------------------------------------------------------------------------------------------------------------------------------------------
#*************************************************************************************************
=end

module F6_Curvizard

#---------------------------------------------------------------------------------------------------------------------------
# Overall Configuration for the Tools	
#---------------------------------------------------------------------------------------------------------------------------

MENU_PERSO = [:T_MenuTools_Fredo6Collection, "Tools", :T_MenuPlugins_Fredo6Collection, "Plugins"]

#---------------------------------------------------------------------------------------------------------------------------
#Constants for TOS  Modules (do not translate here, use Translation Dialog Box instead)	
#---------------------------------------------------------------------------------------------------------------------------

#--------------------------------------------------------
# Default Parameters
#--------------------------------------------------------

T6[:CVZ_DEFAULT_SECTION_General] = "Global Parameters"
T6[:DEFAULT_Auto_Exit] = "Auto exit when plugin is called:"
T6[:STR_FromContextualMenu] = "from Contextual Menu"
T6[:STR_WithPreselection] = "with a Preselection"

#---------------------------------------------------------------------------------------------------------------------------------
# EXTERNAL API to launch Curvizard menus
# Action code must be passed as a symbol
#   - :make_curve --> multi-Weld
#---------------------------------------------------------------------------------------------------------------------------------
	
def F6_Curvizard.launch_action(action_code, from=nil)
	MYPLUGIN.launch_action action_code, from
end

#--------------------------------------------------------------
# Condition for contextual menu selection
#--------------------------------------------------------------

def F6_Curvizard.selection_has_edges?
	Sketchup.active_model.selection.find { |e| e.instance_of?(Sketchup::Edge) }
end

#--------------------------------------------------------
# Registration of sub plugins
#--------------------------------------------------------

#Declare a main command - Called by the sub modules	
def F6_Curvizard.declare_command(symb, txt_mnu, txt_tip, tc)
	@hsh_plugs = {} unless @hsh_plugs
	hinfo = @hsh_plugs[symb]
	hinfo = @hsh_plugs[symb] = {} unless hinfo
	ssymb = symb.to_s
	hinfo[:symb_mnu] = symb_menu = (ssymb + "_menu").upcase.intern
	hinfo[:symb_tip] = symb_tip = (ssymb + "_tooltip").upcase.intern
	T6[symb_menu] = txt_mnu
	T6[symb_tip] = txt_tip
	txt_mnu = T6[symb_menu]
	txt_tip = T6[symb_tip]
	icon = ssymb
	@lst_commands = [] unless @lst_commands
	@lst_commands.push symb
	MYPLUGIN.declare_command_long(symb, txt_mnu, txt_tip, icon) { F6_Curvizard.launch_action symb, :menu }
	submenu = "Curvizard"
	MYPLUGIN.declare_context_handler_long(symb, txt_mnu, txt_tip, tc, nil, submenu) { F6_Curvizard.launch_action symb, :contextual }
end

def F6_Curvizard.plugin_info ; @hsh_plugs ; end
def F6_Curvizard.plugin_list ; @lst_commands ; end

#--------------------------------------------------------
# Startup routine (called from LibFredo6)
#--------------------------------------------------------
	
#Create all commands with menus and toolbar icons
def F6_Curvizard.startup
	#Top menu
	MYPLUGIN.declare_topmenu nil, MENU_PERSO

	#Conditions for contextual menus
	tc_edge = Traductor::TestCondition.new() { F6_Curvizard.selection_has_edges? }
	submenu = "Curvizard"
	
	#Declaring Quick Launcher
	ql_mnu, ql_tip = Traductor::QuickLauncherDialog.get_menu_tip(MYPLUGIN)
	MYPLUGIN.declare_command_long(:quick_launcher, ql_mnu, ql_tip, "quick_launcher") { F6_Curvizard.invoke_quick_launcher }
	MYPLUGIN.declare_separator 'MT'
	
	#Declaring command icons
	F6_Curvizard.declare_command :make_curve, "Make Curves (weld)", "Transform one or several sequences of edges into Sketchup Curves", tc_edge
	F6_Curvizard.declare_command :explode_curve, "Explode Curves", "Explode curves from selected edges", tc_edge
	MYPLUGIN.declare_separator 'M'
	F6_Curvizard.declare_command :cleanup_curve, "Cleanup Contours", "Cleanup Contours from selected edges", tc_edge
	F6_Curvizard.declare_command :simplify_curve, "Simplify Contours", "Simplify Contours from selected edges", tc_edge
	F6_Curvizard.declare_command :smooth_curve, "Smooth Contours", "Simplify Contours from selected edges", tc_edge
	MYPLUGIN.declare_separator 'M'
	F6_Curvizard.declare_command :edge_prop, "Edge Properties", "Modify edge properties", tc_edge
	F6_Curvizard.declare_command :convert_to_guide, "Convert Edges to Guides", "Convert Edges into Guides (Construction lines)", tc_edge
	
	MYPLUGIN.default_icons_visible :quick_launcher
	
	#Declaring the default parameter
	F6_Curvizard.default_param
	
	#Startup of the Plugin
	MYPLUGIN.go		
end
	
#Invoke the Quick Launcher
def F6_Curvizard.invoke_quick_launcher
	lst_cmd = @lst_commands.collect { |symb| hinfo = @hsh_plugs[symb] ; [symb, T6[hinfo[:symb_mnu]], T6[hinfo[:symb_tip]]] }
	Traductor::QuickLauncherDialog.invoke(MYPLUGIN, lst_cmd) { |action_code| F6_Curvizard.launch_action action_code, :launcher }
end
	
#Declaring the Default Parameters	
def F6_Curvizard.default_param
	dp = MYDEFPARAM
	dp.separator :CVZ_DEFAULT_SECTION_General
	lop = [['C', T6[:STR_FromContextualMenu]], ['P', T6[:STR_WithPreselection]]]
	dp.declare :DEFAULT_Auto_Exit, 'C', 'M', lop
end	
	
end	#End Module F6_Curvizard
