=begin
#-------------------------------------------------------------------------------------------------------------------------------------------------
#*************************************************************************************************
# Designed by Fredo6 - Copyright April 2009

# 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			:   HoverSelect_Main.rb
# Original Date	:   8 May 2009 - version 1.0
# Description	:   Modules waiting for incorporation into LibFredo6
#-------------------------------------------------------------------------------------------------------------------------------------------------
#*************************************************************************************************
=end


#--------------------------------------------------------------------------------------------------------------
# Class DrawMark_FourArrows: 4 arrows 
#--------------------------------------------------------------------------------------------------------------			 
module Traductor

T6[:T_DLG_EdgePlain] = "Plain"
T6[:T_DLG_EdgeAll] = "ALL"

end

module G6

#Dialog box for Dicing parameters - Return a list [dice, dice_format]
def G6.ask_edge_prop_filter(titletool, edge_prop)
	#Creating the dialog box
	hparams = {}
	title = ((titletool) ? titletool + ' - ' : '') + T6[:T_DLG_EdgeProp_Title]
	dlg = Traductor::DialogBox.new title
		
	enum_yesno = { 'Y' => T6[:T_DLG_YES], 'N' => T6[:T_DLG_NO] }
	ted = ' '
	dlg.field_enum "Plain", ted + T6[:T_DLG_EdgePlain], 'Y', enum_yesno
	dlg.field_enum "Soft", ted + T6[:T_DLG_EdgeSoft], 'Y', enum_yesno
	dlg.field_enum "Smooth", ted + T6[:T_DLG_EdgeSmooth], 'Y', enum_yesno
	dlg.field_enum "Hidden", ted + T6[:T_DLG_EdgeHidden], 'N', enum_yesno

	#Invoking the dialog box
	hparams["Plain"] = (edge_prop =~ /P/i) ? 'Y' : 'N'
	hparams["Soft"] = (edge_prop =~ /S/i) ? 'Y' : 'N'
	hparams["Smooth"] = (edge_prop =~ /M/i) ? 'Y' : 'N'
	hparams["Hidden"] = (edge_prop =~ /H/i) ? 'Y' : 'N'
	
	#Cancel dialog box
	return edge_prop unless dlg.show! hparams		
	
	#Transfering the parameters
	ep = []
	ep.push 'P' if hparams["Plain"] == 'Y'
	ep.push 'S' if hparams["Soft"] == 'Y'
	ep.push 'M' if hparams["Smooth"] == 'Y'
	ep.push 'H' if hparams["Hidden"] == 'Y'
	ep.join ';;'	
end

#check the filtering by edge property
def G6.edge_filter?(edge, filter)
	filter = 'P;;S;;M;;H' unless filter && filter.length > 0
	
	return false if edge.smooth? && !(filter =~ /M/i)
	return false if edge.soft? && !(filter =~ /S/i)
	return false if edge.hidden? && !(filter =~ /H/i)
	return false if !(edge.smooth? || edge.soft? || edge.hidden?) && !(filter =~ /P/i)
	true
end

#check the filtering by edge property
def G6.edge_filter_text(filter)
	return T6[:T_DLG_EdgeAll] unless filter && filter.length > 0
	return T6[:T_DLG_EdgeAll] if filter =~ /P/i && filter =~ /S/i && filter =~ /M/i && filter =~ /H/i
	
	ls = []
	ls.push  T6[:T_DLG_EdgePlain] if filter =~ /P/i
	ls.push  T6[:T_DLG_EdgeSoft] if filter =~ /S/i
	ls.push  T6[:T_DLG_EdgeSmooth] if filter =~ /M/i
	ls.push  T6[:T_DLG_EdgeHidden] if filter =~ /H/i
	
	ls.join '+'
end

class DrawMark_H2Arrows < G6::AllDrawMark

def initialize(size=nil, color=nil, width=nil)
	creation_mark
	@size = (size) ? size : 7
	@color = (color) ? color : 'darkgreen'
	@width = (width) ? width : 2
	
	#Shape
	dec = 0.4
	pt1 = Geom::Point3d.new -1, 0, 0
	pt2 = Geom::Point3d.new 1, 0, 0
	@list_elts.push create_line([pt1, pt2])
	@list_elts += make_arrow(pt1, -dec)
	@list_elts += make_arrow(pt2, dec)
end

def make_arrow(pt2d, dec)
	lselt = []
	x1 = pt2d.x - dec
	y1 = pt2d.y + dec
	y2 = pt2d.y - dec
	lselt.push create_line([pt2d, Geom::Point3d.new(x1, y1, 0)])
	lselt.push create_line([pt2d, Geom::Point3d.new(x1, y2, 0)])
	lselt	
end

end	#class DrawMark_FourArrows

class DrawMark_Curve < G6::AllDrawMark

def initialize(size=nil, color=nil, width=nil)
	creation_mark
	@size = (size) ? size : 9
	@color = (color) ? color : 'blue'
	@width = (width) ? width : 2
	
	#Shape
	lpt = []
	n = 8
	angle = Math::PI / n
	for i in 0..n
		lpt.push Geom::Point3d.new(Math.sin(angle * i), Math.cos(angle * i), 0)
	end	
	for i in 0..n-1
		@list_elts.push create_line([lpt[i], lpt[i+1]])
	end	
end

end	#class DrawMark_Curve

end #module G6