=begin
#-------------------------------------------------------------------------------------------------------------------------------------------------
#*************************************************************************************************
# Designed June 2013 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_GeneralOffset.rb
# Original Date	:   15 Jun 2013
# Description	:   Loader for the GeneralOffset menu and toolbar
#-------------------------------------------------------------------------------------------------------------------------------------------------
#*************************************************************************************************
=end

module F6_JointPushPull

#---------------------------------------------------------------------------------------------------------------------------
# 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)	
#---------------------------------------------------------------------------------------------------------------------------

#Menu and Toolbar icons
T6[:JPP_JOINT_Menu] = "Joint Push Pull"
T6[:JPP_JOINT_Tooltip] = "Joint Push Pull: Push-pull or thicken a surface"
JPP_JOINT_Icon = "JPP_icon_J"

T6[:JPP_ROUND_Menu] = "Round Push Pull"
T6[:JPP_ROUND_Tooltip] = "Round Push Pull: Thicken a surface with possible rounding at sharp corners of faces"
JPP_ROUND_Icon = "JPP_icon_R"

T6[:JPP_VECTOR_Menu] = "Vector Push Pull"
T6[:JPP_VECTOR_Tooltip] = "Vector Push Pull: Push-pull along a direction"
JPP_VECTOR_Icon = "JPP_icon_V"

T6[:JPP_NORMAL_Menu] = "Normal Push Pull"
T6[:JPP_NORMAL_Tooltip] = "Normal Push Pull: Push-pull multiple faces individually"
JPP_NORMAL_Icon = "JPP_icon_N"

T6[:JPP_EXTRUDE_Menu] = "Extrude Push Pull"
T6[:JPP_EXTRUDE_Tooltip] = "Extrude Push Pull: Compact Push-pull on average direction"
JPP_EXTRUDE_Icon = "JPP_icon_X"

T6[:JPP_FOLLOW_Menu] = "Follow Push Pull"
T6[:JPP_FOLLOW_Tooltip] = "Follow Push Pull: Push pull following the directions at borders (kind of multi-face 'Smart Push Pull')"
JPP_FOLLOW_Icon = "JPP_icon_F"

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

T6[:JPP_DEFAULT_SECTION_General] = "Parameters at startup of Sketchup"
T6[:JPP_PARAM_AutoGeom] = "Generate directly geometry if number of faces is lower than (0 for never)"
T6[:JPP_PARAM_PreviewFaces] = "Maximum Number of top faces shown in Preview mode"
T6[:JPP_PARAM_PreviewBorders] = "Maximum Number of borders shown in Preview mode"
T6[:JPP_PARAM_Preview_on_component] = "Preview on all instances of components"
T6[:JPP_PARAM_AutoSoftenBorders] = "Automatically soften borders if angle in degrees is lower than"
T6[:JPP_PARAM_RandomExtended] = "Enable Random option for all Push-Pull modes (impact performance) - Default is for Normal Push-Pull only"
T6[:JPP_PARAM_ColorAdjacent] = "Material of borders is inherited from adjacent faces when coplanar"
T6[:JPP_PARAM_NoTooltip] = "Do NOT show tooltips in the viewport"

#---------------------------------------------------------------------------------------------------------------------------------
#---------------------------------------------------------------------------------------------------------------------------------
# EXTERNAL API to launch RoundCorner menus
# Action code must be passed as a symbol
#---------------------------------------------------------------------------------------------------------------------------------
#---------------------------------------------------------------------------------------------------------------------------------
	
def F6_JointPushPull.launch_action(action_code, *args)
	MYPLUGIN.launch_action action_code, *args
end

def F6_JointPushPull.get_title(action_code) ; T6["JPP_#{action_code.to_s.upcase}_Menu".intern] ; end
def F6_JointPushPull.get_tooltip(action_code) ; T6["JPP_#{action_code.to_s.upcase}_Tooltip".intern] ; end

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

def F6_JointPushPull.selection_contextual?
	selection = Sketchup.active_model.selection
	return nil if selection.empty?	
	selection.find { |e| e.instance_of?(Sketchup::Face) }
end

#--------------------------------------------------------
# Startup routine (called from LibFredo6)
#--------------------------------------------------------
	
#Create all commands with menus and toolbar icons
def F6_JointPushPull.startup	

	#Conditions for contextual menus
	@tc_face = Traductor::TestCondition.new() { F6_JointPushPull.selection_contextual? }
	@submenu = "JointPushPull"
	
	#Top menu
	MYPLUGIN.declare_topmenu nil, MENU_PERSO

	#Declaring command icons
	@hfrom = { :from => :contextual }
	MYPLUGIN.declare_separator
	ql_mnu, ql_tip = Traductor::QuickLauncherDialog.get_menu_tip(MYPLUGIN)
	MYPLUGIN.declare_command_long(:quick_launcher, ql_mnu, ql_tip, "JPP_icon_QuickLauncher") { F6_JointPushPull.invoke_quick_launcher }
	@lst_commands = [:joint, :round, :vector, :normal, :extrude, :follow]
	@lst_commands.each { |mode| F6_JointPushPull.declare_command(mode) }
	
	#Declaring the default parameter
	F6_JointPushPull.default_param
	
	#Startup of the Plugin
	MYPLUGIN.go	
end

def F6_JointPushPull.declare_command(mode)
	symb = "JPP_#{mode.to_s.upcase}_".intern
	MYPLUGIN.declare_command(symb) { F6_JointPushPull.launch_action mode }
	MYPLUGIN.declare_context_handler(symb, @tc_face, nil, @submenu) { F6_JointPushPull.launch_action mode, @hfrom }
end
	
#Invoke the Quick Launcher
def F6_JointPushPull.invoke_quick_launcher
	lst_cmd = @lst_commands.collect do |symb| 
		ss = symb.to_s.upcase
		txt_mnu = T6[("JPP_#{ss}_Menu").intern]
		txt_tip = T6[("JPP_#{ss}_Tooltip").intern]
		[symb, txt_mnu, txt_tip]
	end	
	Traductor::QuickLauncherDialog.invoke(MYPLUGIN, lst_cmd) { |action_code| F6_JointPushPull.launch_action action_code, :launcher }
end
	
#Declaring the Default Parameters	
def F6_JointPushPull.default_param
	dp = MYDEFPARAM
	dp.separator :JPP_DEFAULT_SECTION_General
	dp.declare :JPP_PARAM_AutoGeom, 250, 'I:>=0<=2000'	
	dp.declare :JPP_PARAM_PreviewFaces, 150, 'I:>=0<=400'	
	dp.declare :JPP_PARAM_PreviewBorders, 100, 'I:>=0<=400'	
	dp.declare :JPP_PARAM_NoTooltip, false, 'B'	
	dp.declare :JPP_PARAM_Preview_on_component, true, 'B'	
	dp.declare :JPP_PARAM_AutoSoftenBorders, 30.0, 'F:>=0<=80'	
	dp.declare :JPP_PARAM_RandomExtended, false, 'B'	
	dp.declare :JPP_PARAM_ColorAdjacent, true, 'B'	
end
		
end	#End Module F6_JointPushPull
