#VRML V2.0 utf8
# A supercluster astronomical plotting object. 

# Uses:  lib_astro_SC_inline_Shape.wrl 
#  Color is grey but shape is same as moving groups.  Is translucent. 
# Prototyped from: 	lib_UD_Shape.wrl or other user defined file 
# 			lib_UD_inline_Shape.wrl 

# A user-defined prototype wrapper implementation.
#  A component in a 3D data plotting application 
# Kurt A. Fisher fisherka@csolutions.net  beginner level VRML coder
# 12/2003

#  This is a heavyweight data plotting template that inlines a user created VRML Shape.  
#  This object can be used as a template to extend other future user created shapes 
#  like an indexedFaceSet.  Just inLine the Shape. 

#   This template is intended to be used to encapsulate unique one-time created plotting 
#   objects and to bring them into the data plotting application reference world.  

# Uses:  lib_UD_inline_Shape.wrl or other user defined file 

#  Heavy-weight implementation extracted from SO_proto.wrl 
#  This heavy-weight version reports metadata on the a user defined shape 
#   only via an anchor on the Label.  
#   Reporting metadata via the browswer and the onMouse event retained for 
#   future extensions,  but is not expressed. 
#  Position angle can be set.  Label offset is configured manually. 
#  A color field is exposed but does not implement.  
#  The user must implement object color and translucency in the inlined file. 

#   Developer notes:  This object differs on SO_proto.wrl in that Anchor and Brower metadata display 
#   applies only to object label.  Unlike all other objects, where the object label offset is automatically 
#   set, in this object the user configures the label offset. 

# ====================================
# Usage 

# SC { 
#	objName		[ "Object", "Alternate Name" ]	# object
#	objClass		"Type"			# type of object for EIA sort select
#	subClass		"SubType"		# subtype of object for EIA sort select
#	objPosition	0.0 0.0 0.0			# usually set to world origin 0 0 0 
#	objSize		1.00 1.00 1.00		# scale equally to adjust object size to world scale without changing user defined object aspects 
# 	posAngle		0.0 1.0 0.0 0.00		# position angle ( z y x rot );  normal plotted space rotations are around y-axis; note rotation form is not normal "x y z rot" syntax   
#						# object color must be set in user defined object 
#	lblType		4			# label type 0=none; 1=1st strg; 2=2nd strg; 3=3rd strg; 4=all
#	fontSize		0.5			# font size
#	lblColor		0.0 0.0 0.0			# label color 
#	lblPosition		0.0 1.0 0.0			# Label position - because of the large object size, the label position is user configurable
#						# object transparency must be set in user defined object 
#	url_InLine		[ "lib_astro_SC_inline_Shape.wrl" ]	# relative path to user defined shape 
#}

# Syntax - default value should be  "lib_astro_SC_inline_Shape.wrl" for CosmoPlayer runtime compatability 

# ====================================
# Prototype for plotting user-defined shapes in world reference frame 
PROTO SC [ 
	exposedField MFString	objName		[ "Object", "Alternate Name" ]	# object
	exposedField SFString	objClass		"Type"			# type of object for EIA sort select
	exposedField SFString	subClass		"SubType"		# subtype of object for EIA sort select
	exposedField SFVec3f	objPosition	0.0 0.0 0.0			# position
	exposedField SFVec3f 	objSize		1.00 1.00 1.00		# scale equally to adjust object size to world scale without changing user defined object aspects 
	exposedField SFRotation	posAngle		0.0 1.0 0.0 0.00		# position angle ( z y x rot );  normal plotted space rotations are around y-axis; note rotation form is not normal "x y z rot" syntax   
#									# object color must be set in user defined object 
	exposedField SFInt32	lblType		4			# label type 0=none; 1=1st strg; 2=2nd strg; 3=3rd strg; 4=all
	exposedField SFFloat	fontSize		0.5			# font size
	exposedField SFColor	lblColor		0.0 0.0 0.0			# label color 
#									# Label family, style (bold,italics,etc.) and justify cannot be changed 
#									# See "DEF tmp_lblFontStyleText" for hardcoding of these characteristics  
	exposedField SFVec3f	lblPosition		0.0 1.0 0.0			# Label position - because of the large object size, the label position is user configurable
#									# object transparency must be set in user defined object 
	exposedField MFString	url_InLine		[ "SC_inline_Shape.wrl" ]	# relative path to user defined shape 
] {

#  Start plot point  
DEF Sphere_Object Transform {
#                           Key position of object, translated in x,y,z
		translation IS objPosition
		rotation IS posAngle 
		children [

#  Start shape of Sphere_Object
#       Start sphere of a SO 

#  To keep objSize type uniform as 3f vector,  use Transform to resize the spherical object 
		Transform {
#                                         Key size of object, stretched in x,y,z
			scale IS objSize
			children [

#  PLOT SHAPE WITH USER DEFINED OBJECT
	# version 0: shape User Defined 
		Group { 
			children [ 

DEF UD_object Inline { 
	url  IS url_InLine
	bboxCenter 0 0 0
} 

			] # end children Anchor 
			} # end Anchor 
		] # children Group 
		} # end Group

#  START LABELS FOR OBJECT 
		DEF lblObject Transform {
#  Unlike SO_proto,  the label position in SP_proto is user configurable, due to the large size of the object. 
				translation	IS lblPosition
#  
#  Since labels are auto-billboarding to face viewer,  there is no need to orient the labels with rotation. 
				children [
# Begin billboarding text label
					Billboard {
						axisOfRotation 0 0 0
# Auto-point the labels to the viewer 
						children [ 
# Begin billboarding shape

#  Start Anchor for referral for more object information 
				DEF SO_Anchor_Sphere Anchor {
#				              Displays refered page in new browser instance
#  Pop-up display disabled 		parameter [ "target='_blank'" ]
#					parameter [ "target='_blank'" ]
					children [

							Shape {
							appearance Appearance { 
								material Material { 
#								diffuseColor IS lblColor
								emissiveColor IS lblColor
								} # end Material 
							}  # end Appearance 
						    	geometry DEF lblName Text {
#     Label string and style are set in initialization script 
#								string IS objName    
								fontStyle DEF lblNameStyle FontStyle { 
									family "SANS"
									style "BOLD"
									justify "BEGIN"
#									size 1.0 
#									size IS fontSize
								}  # End of fontStyle 
							}  # End of geometry Text
						}  # End of shape Text Label 

						] # end children
						} # End Anchor	

					]  # End of billboarding children 
					}  # End of billboarding text label
  	
			] # end children of Transform of lblObject 
		}  # end Transform of lblObject 
# END LABEL FOR OBJECT 

# ADD SENOR (TOUCH) FOR LABEL  
		DEF sense_Sphere_Object TouchSensor {  }
# END SENOR (TOUCH) FOR LABEL 

		]  # end children of Transform of Sphere_Object 
	}  # end of Transform of Sphere_Object 
#  END PLOTTED OBJECT


# BEGIN PASS DATA FROM EXPOSED FIELDS IN PROTOTYPE TO OBJECT INSTANCE 
DEF tmp_lblName Text { string IS objName }						# to set label types on initialization
DEF tmp_lblType Switch { whichChoice IS lblType }					# to set label types on initialization
DEF tmp_objSize Transform { scale IS objSize } 						# to set label types on initialization
DEF tmp_lblFontStyleTextPass Text {  maxExtent IS fontSize }	                        # pass label size on initialization; 
                                                                                        # unique syntax to handle that Text size is not exposed field 

# Syntax - disabled on CosmoPlayer compatability adjustments 
# DEF tmp_lblFontStyleText Text {                                                       # to set label size on initialization
#	fontStyle DEF tmp_lblFontStyle FontStyle {                                      # syntax note - unable to set family, style, justify with script
#                          family "SANS" 
#                          style "BOLD"
#                          justify "BEGIN"
#		  size 0.0  } # end fontStyle 
#             }  # end Text	                                                              

# END PASS DATA FROM PROTOTYPE TO OBJECT INSTANCE 

#  BEGIN BEHAVIORS OF OBJECT
# Initialization script 
DEF get_Initialize Script {
#   Pass object variables as input variables for these functions  
field SFNode LabelNode USE tmp_lblName                                  # label array string
field SFNode LabelType USE tmp_lblType                                  # labeling type
field SFNode LabelScale USE tmp_objSize                                 # object size for label spacing 
field SFNode LabelFontSizePass USE tmp_lblFontStyleTextPass 		# to pass font size stored in maxExtent exposed field 
# Syntax - disabled on CosmoPlayer compatability adjustments 
# field SFNode LabelFontStyle USE tmp_lblFontStyle                      # font size for label spacing 
directOutput TRUE
  url [ 
	"javascript:
	 function initialize (  ) {

//  Note all arrays received from VRML are 0 based, while ECMA javascript arrays are 1 based

//  Syntax -  initialize variable for CosmoPlayer compatability - Cosmo wants array hard-initialized 
string_changed = new MFString() ;


//           Set label string 
//                          Case 0 - If no labels, label is blank    
		if ( LabelType.whichChoice == 0 ) { string_changed = [ '', '' ] ; }
//                          Case 1 - Use first string as label     
		if ( LabelType.whichChoice == 1 ) { string_changed[0] = LabelNode.string[0] ; }
//                          Case 2 - Use second string as label     
		if ( LabelType.whichChoice == 2 ) { string_changed[0] = LabelNode.string[1] ; }
//                          Case 3 - Use third string as label          
		if ( LabelType.whichChoice == 3 ) { string_changed[0] = LabelNode.string[2] ; }
//                          Case 4 - Use all strings in array as label     
		if ( LabelType.whichChoice == 4 ) { string_changed = LabelNode.string ; }

//           Assertion - check for undefined empty strings 
		if ( string_changed[0] == 'undefined' )  { string_changed[0] = '' ; }
		if ( string_changed[1] == 'undefined' )  { string_changed[1] = '' ; }
		if ( string_changed[2] == 'undefined' )  { string_changed[2] = '' ; }


//  Syntax -  initialize variable CosmoPlayer compatability 
		anchor_url_changed = new MFString(); 
// Syntax note - = new SFString is not recognized within Javascript 
		anchor_desc_changed = new String(); 
		array_desc_changed = new Array();

//           Set anchor url - based on first label name 
		anchor_url_changed[0] = 'refer_'+LabelNode.string[0] + '.htm'  ;
		anchor_url_changed[1] = 'refer_Not_implemented.htm'  ;

//  Syntax -	CosmoPlayer incompatability - CosmoPlayer will not implement cascading checks of not located links.
//		Implement a second copy of the refer - not implemented file as refer_.htm to pick up no label items 

//           Set anchor description - use all information 
//		anchor_desc_changed = LabelNode.string; 
		array_desc_changed = LabelNode.string;
		anchor_desc_changed = array_desc_changed.toString(); 

//           Determine and set the label spacing from object 
//           Creates a 3FVector for use in translating the label in the x-axis
//             Pass fontsize - a non-exposedfield of SFFloat type

// 			Syntax - Disable - For CosmoPlayer compatability - FontStyle.size is non-exposed object
//			LabelFontStyle.size = LabelFontSizePass.maxExtent ;

//   			Syntax - Replacement code CosmoPlayer compatability - FontStyle.size is non-exposed object
//           Creates a 3FVector for use in translating the label in the x-axis
		var flt_FontSize_changed = LabelFontSizePass.maxExtent; 
		SFVec3f_FontSize_changed = new SFVec3f(); 
		SFVec3f_FontSize_changed[0] = flt_FontSize_changed;
		SFVec3f_FontSize_changed[1] = flt_FontSize_changed;
		SFVec3f_FontSize_changed[2] = flt_FontSize_changed;

//             Set the label spacing 

//   Syntax - Replacement code for CosmoPlayer compatability - FontStyle.size is non-exposed object
//                Label spacing is fontsize plus object size where object size in x axis is equal or greater than font size 
                           if (   LabelScale.scale[0]  >= flt_FontSize_changed ) { label_spacing[0] = LabelScale.scale[0] + ( 0.25 * flt_FontSize_changed ) ; }
//                Label spacing is object size where object size in x axis is less than font size
                           if (   LabelScale.scale[0]  < flt_FontSize_changed ) { label_spacing[0] = LabelScale.scale[0] + ( 0.25 * flt_FontSize_changed ) ; }

//	    Set y and z translation values 
	             label_spacing[1]  = 0 ;
   	             label_spacing[2]  = 0 ;

	  }"
      ] # end url 
#  Make events for function output 
eventOut MFString string_changed                # label string
eventOut SFVec3f label_spacing                  # label spacing
# Syntax - disable to convert to Cosmo compability 
# eventOut SFNode label_fontstyle_out		# label fontstyle 
eventOut SFVec3f SFVec3f_FontSize_changed	# new fontsize rescalar
eventOut MFString anchor_url_changed            # anchor url
eventOut SFString anchor_desc_changed           # anchor label
 } # end Script 
# Route function results back to object 
ROUTE get_Initialize.anchor_url_changed TO SO_Anchor_Sphere.set_url		# begin set anchors and urls
ROUTE get_Initialize.anchor_desc_changed TO SO_Anchor_Sphere.set_description	# end set anchors and urls
ROUTE get_Initialize.string_changed TO lblName.set_string			# set the label string 
#  DEVELOPER SETTING - AUTO SPACING OF LABEL DISABLED 
# ROUTE get_Initialize.label_spacing TO lblObject.set_translation		# sets label lead spacing 
ROUTE get_Initialize.SFVec3f_FontSize_changed TO lblObject.set_scale		# sets sets fontsize
# End routers

# Popup label in browser status bar 
DEF display_Message Script { 
	field SFNode LabelNode USE tmp_lblName
	eventIn SFBool set_boolean
	url [
		"javascript:
		function set_boolean (bolValue) { 

	//  Syntax - for Cosmo compability
//  Convert string array to string 
browser_desc_changed = new String();
array_desc_changed = new Array();

array_desc_changed = LabelNode.string;
browser_desc_changed = array_desc_changed.toString(); 

//           Set popup label
if( bolValue == true ) { Browser.setDescription(browser_desc_changed); }
	//  Syntax - for Blaxxun compatibility - remove if ... else statement 
if( bolValue == false ) { Browser.setDescription(''); }

	}" 
	] # end url 
#            Output events for browser router are implied 
}  # end Script
# Router for popup label in browser 
ROUTE sense_Sphere_Object.isOver TO display_Message.set_boolean 
# End routers 

#  END BEHAVIORS OF OBJECT

}  # END OF USER DEINED SHAPE PROTOTYPE 


