package Savage.CommunicationsAndSensors.TSSR;

import org.web3d.x3d.jsail.Core.*;
import org.web3d.x3d.jsail.EnvironmentalEffects.*;
import org.web3d.x3d.jsail.fields.*;
import org.web3d.x3d.jsail.Grouping.*;
import org.web3d.x3d.jsail.Navigation.*;
import org.web3d.x3d.jsail.Networking.*;
import org.web3d.x3d.jsail.Scripting.*;

// Javadoc metadata annotations follow, see below for X3DJSAIL Java source code.
/**
 * <p> A pair of Tropo Satellite Support Radios (TSSR) used for short-range (&lt; 20 miles) point-to-point SHF communication. The system designed to support remote equipment and users by replacing long cable runs. </p>
 <p> Related links: Catalog page <a href="../../../../CommunicationsAndSensors/TSSR/TSSRPairPrototypeIndex.html" target="_blank">TSSRPairPrototype</a>,  source <a href="../../../../CommunicationsAndSensors/TSSR/TSSRPairPrototype.java">TSSRPairPrototype.java</a>, <a href="https://www.web3d.org/x3d/content/examples/X3dResources.html" target="_blank">X3D Resources</a>, <a href="https://www.web3d.org/x3d/content/examples/X3dSceneAuthoringHints.html" target="_blank">X3D Scene Authoring Hints</a>, and <a href="https://www.web3d.org/x3d/content/X3dTooltips.html" target="_blank">X3D Tooltips</a>. </p>
	<table style="color:black; border:0px solid; border-spacing:10px 0px;">
        <caption>Scene Meta Information</caption>
		<tr style="background-color:silver; border-color:silver;">
			<td style="text-align:center; padding:10px 0px;"><i>meta tags</i></td>
			<td style="text-align:left;   padding:10px 0px;">&nbsp; Document Metadata </td>
		</tr>

		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> title </i> </td>
			<td> <a href="../../../../CommunicationsAndSensors/TSSR/TSSRPairPrototype.x3d">TSSRPairPrototype.x3d</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> description </i> </td>
			<td> A pair of Tropo Satellite Support Radios (TSSR) used for short-range (&lt; 20 miles) point-to-point SHF communication. The system designed to support remote equipment and users by replacing long cable runs. </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> creator </i> </td>
			<td> Mike Hunsberger </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> created </i> </td>
			<td> 1 May 2001 </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> modified </i> </td>
			<td> 20 October 2019 </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> identifier </i> </td>
			<td> <a href="https://www.web3d.org/x3d/content/examples/Savage/CommunicationsAndSensors/TSSR/TSSRPairPrototype.x3d" target="_blank">https://www.web3d.org/x3d/content/examples/Savage/CommunicationsAndSensors/TSSR/TSSRPairPrototype.x3d</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> reference </i> </td>
			<td> <a href="https://www.web3d.org/x3d/content/examples/Savage/CommunicationsAndSensors/TSSR/TSSRPairExample.x3d" target="_blank">https://www.web3d.org/x3d/content/examples/Savage/CommunicationsAndSensors/TSSR/TSSRPairExample.x3d</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> generator </i> </td>
			<td> X3D-Edit 3.2, <a href="https://www.web3d.org/x3d/tools/X3D-Edit" target="_blank">https://www.web3d.org/x3d/tools/X3D-Edit</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> license </i> </td>
			<td> <a href="../../../../CommunicationsAndSensors/TSSR/../../license.html">../../license.html</a> </td>
		</tr>
		<tr style="background-color:silver; border-color:silver;">
			<td style="text-align:center;" colspan="2">  &nbsp; </td>
		</tr>
	</table>

	<p>
		This program uses the
		<a href="https://www.web3d.org/specifications/java/X3DJSAIL.html" target="_blank">X3D Java Scene Access Interface Library (X3DJSAIL)</a>.
		It has been produced using the 
		<a href="https://www.web3d.org/x3d/stylesheets/X3dToJava.xslt" target="_blank">X3dToJava.xslt</a>
		stylesheet
	       (<a href="https://sourceforge.net/p/x3d/code/HEAD/tree/www.web3d.org/x3d/stylesheets/X3dToJava.xslt" target="_blank">version control</a>)
                which is used to create Java source code from an original <code>.x3d</code> model.
	</p>

	* @author Mike Hunsberger
 */

public class TSSRPairPrototype
{
	/** Default constructor to create this object. */
	public TSSRPairPrototype ()
	{
	  initialize();
	}

	/** Create and initialize the X3D model for this object. */
	public final void initialize()
	{
            try { // catch-all
  x3dModel = new X3D().setProfile(X3D.PROFILE_IMMERSIVE).setVersion(X3D.VERSION_3_0)
  .setHead(new head()
    .addMeta(new meta().setName(meta.NAME_TITLE      ).setContent("TSSRPairPrototype.x3d"))
    .addMeta(new meta().setName(meta.NAME_DESCRIPTION).setContent("A pair of Tropo Satellite Support Radios (TSSR) used for short-range (< 20 miles) point-to-point SHF communication. The system designed to support remote equipment and users by replacing long cable runs."))
    .addMeta(new meta().setName(meta.NAME_CREATOR    ).setContent("Mike Hunsberger"))
    .addMeta(new meta().setName(meta.NAME_CREATED    ).setContent("1 May 2001"))
    .addMeta(new meta().setName(meta.NAME_MODIFIED   ).setContent("20 October 2019"))
    .addMeta(new meta().setName(meta.NAME_IDENTIFIER ).setContent("https://www.web3d.org/x3d/content/examples/Savage/CommunicationsAndSensors/TSSR/TSSRPairPrototype.x3d"))
    .addMeta(new meta().setName(meta.NAME_REFERENCE  ).setContent("https://www.web3d.org/x3d/content/examples/Savage/CommunicationsAndSensors/TSSR/TSSRPairExample.x3d"))
    .addMeta(new meta().setName(meta.NAME_GENERATOR  ).setContent("X3D-Edit 3.2, https://www.web3d.org/x3d/tools/X3D-Edit"))
    .addMeta(new meta().setName(meta.NAME_LICENSE    ).setContent("../../license.html")))
  .setScene(new Scene()
    .addChild(new ExternProtoDeclare("BeamCylinder").setName("BeamCylinder").setAppinfo("Produce wireframe or transparent beam cylinders. Typical uses include propeller/thruster water flow or line-of-sight sonar/radar/light beams. Negative range values invert base and apex at same relative location. Default: beam with apex at (0 0 0) and base of radius 1 in x-z plane at (1 0 0).").setUrl(new String[] {"../../CommunicationsAndSensors/Beam/BeamCylinderPrototype.x3d#BeamCylinder","https://www.web3d.org/x3d/content/examples/Savage/CommunicationsAndSensors/Beam/BeamCylinderPrototype.x3d#BeamCylinder","../../CommunicationsAndSensors/Beam/BeamCylinderPrototype.wrl#BeamCylinder","https://www.web3d.org/x3d/content/examples/Savage/CommunicationsAndSensors/Beam/BeamCylinderPrototype.wrl#BeamCylinder"})
      .addField(new field().setName("name").setType(field.TYPE_SFSTRING).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setAppinfo("Assigning a name to a BeamCylinder aids tracing"))
      .addField(new field().setName("contact").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INPUTONLY).setAppinfo("(communications) is transmitted signal in contact with receiver or (sensor) is a target return detected?"))
      .addField(new field().setName("range").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INPUTONLY).setAppinfo("distance in meters along x axis"))
      .addField(new field().setName("defaultRange").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setAppinfo("distance in meters used until eventIn range sent"))
      .addField(new field().setName("wireframe").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setAppinfo("whether wireframe beam is drawn"))
      .addField(new field().setName("solid").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setAppinfo("whether solid beam is drawn"))
      .addField(new field().setName("beamHeight").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setAppinfo("meters across vertical y axis"))
      .addField(new field().setName("beamWidth").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setAppinfo("meters across horizontal z axis"))
      .addField(new field().setName("contactColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setAppinfo("rendering color when contact=true"))
      .addField(new field().setName("noContactColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setAppinfo("rendering color when contact=false"))
      .addField(new field().setName("transparency").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INPUTOUTPUT).setAppinfo("1 = fully transparent wireframe only")))
    .addComments(" ExternProtoDeclare definitions must be included verbatim ")
    .addComments(" PROTO consists of two TSSRs for short range (< 5 mile) point-to-point communication. TSSRs eliminate the need for long cable runs. This PROTO allow specification for the initial placement of each TSSR. It automatically calculates the correct angle to complete the link. ")
    .addChild(new ProtoDeclare("TSSRPair").setName("TSSRPair")
      .setProtoInterface(new ProtoInterface()
        .addField(new field().setName("TSSR1Location").setType(field.TYPE_SFVEC3F).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(new SFVec3f(1.0,1.0,1.0)))
        .addField(new field().setName("TSSR2Location").setType(field.TYPE_SFVEC3F).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(new SFVec3f(0.0,0.0,0.0))))
      .setProtoBody(new ProtoBody()
        .addChild(new Group()
          .addChild(new Viewpoint("TSSRPairViewpoint").setDescription("TSSR Pair Viewpoint"))
          .addChild(new LOD().setRange(new double[] {40000.0})
            .addComments(" TSSR 1 Two Transforms. One in the XZ plane, the second in the XY plane. Inlines for the TSSR body, stand, and the dome pattern. ")
            .addChild(new Transform("TSSR1_TRANSFORM")
              .setIS(new IS()
                .addConnect(new connect().setNodeField("translation").setProtoField("TSSR1Location")))
              .addChild(new Transform("TSSR1_XY_TRANSFORM")
                .addChild(new Inline("TSSRBody").setUrl(new String[] {"../../CommunicationsAndSensors/TSSR/TSSRBody.x3d","https://www.web3d.org/x3d/content/examples/Savage/CommunicationsAndSensors/TSSR/TSSRBody.x3d","../../CommunicationsAndSensors/TSSR/TSSRBody.wrl","https://www.web3d.org/x3d/content/examples/Savage/CommunicationsAndSensors/TSSR/TSSRBody.wrl"}))
                .addChild(new Transform("TSSR1Cone").setTranslation(1.0,0.0,0.0)
                  .addChild(new ProtoInstance("BeamCylinder", "TSSR1_BEAMCYLINDER").setContainerField("children")
                    .addFieldValue(new fieldValue().setName("defaultRange").setValue(10))
                    .addFieldValue(new fieldValue().setName("beamHeight").setValue(1))
                    .addFieldValue(new fieldValue().setName("beamWidth").setValue(1))
                    .addFieldValue(new fieldValue().setName("transparency").setValue(0.2))
                    .addFieldValue(new fieldValue().setName("wireframe").setValue(true))
                    .addFieldValue(new fieldValue().setName("solid").setValue(true))
                    .addFieldValue(new fieldValue().setName("contactColor").setValue(new SFColor(.3,.5,.5)))
                    .addFieldValue(new fieldValue().setName("noContactColor").setValue(new SFColor(.8,.1,.1))))
                  .addChild(new LOD().setRange(new double[] {100.0})
                    .addChild(new Transform()
                      .addChild(new Viewpoint().setDescription("TSSR1 side view")))
                    .addChild(new WorldInfo().setInfo(new String[] {"null node for no rendering when distant"})))))
              .addChild(new Transform()
                .addChild(new Inline("TSSRStand").setUrl(new String[] {"../../CommunicationsAndSensors/TSSR/TSSRTripod.x3d","https://www.web3d.org/x3d/content/examples/Savage/CommunicationsAndSensors/TSSR/TSSRTripod.x3d","../../CommunicationsAndSensors/TSSR/TSSRTripod.wrl","https://www.web3d.org/x3d/content/examples/Savage/CommunicationsAndSensors/TSSR/TSSRTripod.wrl"}))))
            .addChild(new WorldInfo().setInfo(new String[] {"null node for no rendering when distant"})))
          .addChild(new LOD().setRange(new double[] {40000.0})
            .addComments(" TSSR 2 Two Transforms. One in the XZ plane, the second in the XY plane. Inlines for the TSSR body, stand, and the dome pattern. ")
            .addChild(new Transform("TSSR2_TRANSFORM")
              .setIS(new IS()
                .addConnect(new connect().setNodeField("translation").setProtoField("TSSR2Location")))
              .addChild(new Transform("TSSR2_XY_TRANSFORM")
                .addChild(new Inline().setUSE("TSSRBody"))
                .addChild(new Transform("TSSR2Cone").setTranslation(1.0,0.0,0.0)
                  .addChild(new ProtoInstance("BeamCylinder", "TSSR2_BEAMCYLINDER").setContainerField("children")
                    .addFieldValue(new fieldValue().setName("defaultRange").setValue(10))
                    .addFieldValue(new fieldValue().setName("beamHeight").setValue(1))
                    .addFieldValue(new fieldValue().setName("beamWidth").setValue(1))
                    .addFieldValue(new fieldValue().setName("transparency").setValue(0.2))
                    .addFieldValue(new fieldValue().setName("wireframe").setValue(true))
                    .addFieldValue(new fieldValue().setName("solid").setValue(true))
                    .addFieldValue(new fieldValue().setName("contactColor").setValue(new SFColor(.3,.5,.5)))
                    .addFieldValue(new fieldValue().setName("noContactColor").setValue(new SFColor(.8,.1,.1))))
                  .addChild(new LOD().setRange(new double[] {100.0})
                    .addChild(new Transform()
                      .addChild(new Viewpoint().setDescription("TSSR2 side view").setOrientation(0.0,1.0,0.0,3.14).setPosition(0.0,0.0,-10.0)))
                    .addChild(new WorldInfo().setInfo(new String[] {"null node for no rendering when distant"})))))
              .addChild(new Transform()
                .addChild(new Inline().setUSE("TSSRStand"))))
            .addChild(new WorldInfo().setInfo(new String[] {"null node for no rendering when distant"})))
          .addChild(new Script("TransmitScript").setSourceCode("""
ecmascript:

function initialize ()
{
	size = new SFVec3f(100, 100, 100) ;
	Browser.println ('TransmitScript initialize() complete') ;
}

// function name matches eventIn variable name ('hour')
// hourValue captures the new value of the ROUTE hour event
// minutes is just the current field value

function transState (newValue, timestamp)
{
	transmitState = newValue ;
	if (transmitState == 3) {
		size = new SFVec3f(10, 10, 10) ;
	}
	else {
		size = new SFVec3f(100, 100, 100) ;
	}
	Browser.println ('size	= ' + size) ;
}
""")
            .addField(new field().setName("transState").setType(field.TYPE_SFINT32).setAccessType(field.ACCESSTYPE_INPUTONLY))
            .addField(new field().setName("size").setType(field.TYPE_SFVEC3F).setAccessType(field.ACCESSTYPE_OUTPUTONLY)))
          .addChild(new Script("TransmitScript2").setSourceCode("""
ecmascript:

function initialize ()
{
	size = new SFVec3f(100, 100, 100) ;
	Browser.println ('TransmitScript initialize() complete') ;
}

// function name matches eventIn variable name ('hour')
// hourValue captures the new value of the ROUTE hour event
// minutes is just the current field value

function transState (newValue, timestamp)
{
	transmitState = newValue ;
	if (transmitState == 3) {
		size = new SFVec3f(10, 10, 10) ;
	}
	else {
		size = new SFVec3f(100, 100, 100) ;
	}
	Browser.println ('size	= ' + size) ;
}
""")
            .addField(new field().setName("transState").setType(field.TYPE_SFINT32).setAccessType(field.ACCESSTYPE_INPUTONLY))
            .addField(new field().setName("size").setType(field.TYPE_SFVEC3F).setAccessType(field.ACCESSTYPE_OUTPUTONLY)))
          .addComments(" This script is used to calculate the corresponding rotation angles so the TSSRs will be pointed at each other ")
          .addChild(new Script("CalculateAngleScript").setSourceCode("""
ecmascript:

function initialize ()
{
	Browser.println ('TSSR1	=' + TSSR1Location) ;
	Browser.println ('TSSR2	=' + TSSR2Location) ;
	Browser.println ('TransmitScript initialize() complete') ;
	active = true ;
	TSSR1_XZangle	= new SFRotation(0, 1, 0, 0) ;
	TSSR2_XZangle	= new SFRotation(0, 1, 0, 0) ;
	TSSR1_XYangle	= new SFRotation(0, 0, 1, 0) ;
	TSSR2_XYangle	= new SFRotation(0, 0, 1, 0) ;
	
	beamScale		= new SFVec3f ( ) ;
	ViewpointLocation	= new SFVec3f ( ) ;
	ViewpointAngle		= new SFRotation(0, 1, 0, 0) ;
	LinkEstablished	= true;
	
	compute(active) ;
}


function compute ( )
{
	computeDistance( ) ;
	computeXZangle( );
	ViewpointLocation[0] = TSSR1Location[0] ;
	ViewpointLocation[1] = TSSR1Location[1] + 4;
	ViewpointLocation[2] = TSSR1Location[2] ;
	Browser.println ('ViewpointLocation	=' + ViewpointLocation) ;
	ViewpointAngle[3] = TSSR1_XZangle[3] - Math.PI/2;
	Browser.println ('ViewpointAngle	=' + ViewpointAngle) ;
	computeXYangle( ) ;
	
}
	
function computeDistance( ) 
{
	Browser.println ('TSSR1	=' + TSSR1Location) ;
	Browser.println ('TSSR2	=' + TSSR2Location) ;
	deltaX 	= (TSSR2Location[0] - TSSR1Location[0]) ;
	deltaY 	= (TSSR2Location[1] - TSSR1Location[1]) ;
	deltaZ 	= (TSSR2Location[2] - TSSR1Location[2]) ;
	distanceSquared	= deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ ;
	Browser.println ('Distance Squared	=' + distanceSquared) ;
	distance 	= Math.sqrt(distanceSquared) ;
	Browser.println ('Distance	=' + distance) ;


	beamScale[0] 	= distance/10;
	beamScale[1]	= 5;
	beamScale[2]	= 5;	
	Browser.println ('BeamScale	=' + beamScale) ;
	beamLength 	= distance - 2 ;
	if (distance > 5000/.6) {
		LinkEstablished = false;
		beamLength = 5000;
	}
}

function computeXZangle( ) 
{
	if (deltaZ == 0) {
		deltaZ = .00000001 ;
	}
	
	angle 	= Math.atan(deltaX/deltaZ) ;
	if (deltaZ < 0) {
		TSSR1_XZangle[3] = angle + Math.PI/2;
	}
	else {
		TSSR1_XZangle[3] = angle -  Math.PI/2;
	}
	TSSR2_XZangle[3]  = TSSR1_XZangle[3] +  Math.PI;
	
	Browser.println ('Angle	=' + TSSR1_XZangle[3]) ;
	Browser.println ('Angle2	=' + TSSR2_XZangle[3]) ;
}	
		


function computeXYangle( ) 
{
	angle 	= Math.asin(deltaY/distance) ;
	TSSR1_XYangle[3] = angle ;
	TSSR2_XYangle[3]  = - TSSR1_XYangle[3];
	
	Browser.println ('AngleXY	=' + TSSR1_XYangle[3]) ;
	Browser.println ('Angle2XY	=' + TSSR2_XYangle[3]) ;
}
""")
            .addField(new field().setName("TSSR1Location").setType(field.TYPE_SFVEC3F).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
            .addField(new field().setName("TSSR2Location").setType(field.TYPE_SFVEC3F).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
            .addField(new field().setName("TSSR1_XZangle").setType(field.TYPE_SFROTATION).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("TSSR2_XZangle").setType(field.TYPE_SFROTATION).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("beamScale").setType(field.TYPE_SFVEC3F).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("beamLength").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("TSSR1_XYangle").setType(field.TYPE_SFROTATION).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("TSSR2_XYangle").setType(field.TYPE_SFROTATION).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("LinkEstablished").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("ViewpointLocation").setType(field.TYPE_SFVEC3F).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("ViewpointAngle").setType(field.TYPE_SFROTATION).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .setIS(new IS()
              .addConnect(new connect().setNodeField("TSSR1Location").setProtoField("TSSR1Location"))
              .addConnect(new connect().setNodeField("TSSR2Location").setProtoField("TSSR2Location")))))
        .addChild(new ROUTE().setFromNode("CalculateAngleScript").setFromField("TSSR1_XZangle").setToNode("TSSR1_TRANSFORM").setToField("rotation"))
        .addChild(new ROUTE().setFromNode("CalculateAngleScript").setFromField("TSSR2_XZangle").setToNode("TSSR2_TRANSFORM").setToField("rotation"))
        .addChild(new ROUTE().setFromNode("CalculateAngleScript").setFromField("beamLength").setToNode("TSSR1_BEAMCYLINDER").setToField("range"))
        .addChild(new ROUTE().setFromNode("CalculateAngleScript").setFromField("beamLength").setToNode("TSSR2_BEAMCYLINDER").setToField("range"))
        .addChild(new ROUTE().setFromNode("CalculateAngleScript").setFromField("TSSR1_XYangle").setToNode("TSSR1_XY_TRANSFORM").setToField("rotation"))
        .addChild(new ROUTE().setFromNode("CalculateAngleScript").setFromField("TSSR2_XYangle").setToNode("TSSR2_XY_TRANSFORM").setToField("rotation"))
        .addChild(new ROUTE().setFromNode("CalculateAngleScript").setFromField("LinkEstablished").setToNode("TSSR1_BEAMCYLINDER").setToField("contact"))
        .addChild(new ROUTE().setFromNode("CalculateAngleScript").setFromField("LinkEstablished").setToNode("TSSR2_BEAMCYLINDER").setToField("contact"))
        .addChild(new ROUTE().setFromNode("CalculateAngleScript").setFromField("ViewpointLocation").setToNode("TSSRPairViewpoint").setToField("position"))
        .addChild(new ROUTE().setFromNode("CalculateAngleScript").setFromField("ViewpointAngle").setToNode("TSSRPairViewpoint").setToField("orientation"))))
    .addComments(" ==================== ")
    .addChild(new WorldInfo().setInfo(new String[] {"Author: Mike Hunsberger","Revised: 30 April 2001","Purpose: Pair of TSSRs","Browser: CosmoPlayer"}).setTitle("AntennaWorld"))
    .addChild(new ProtoInstance("TSSRPair").setContainerField("children")
      .addFieldValue(new fieldValue().setName("TSSR1Location").setValue(new SFVec3f(0.0,0.0,0.0)))
      .addFieldValue(new fieldValue().setName("TSSR2Location").setValue(new SFVec3f(50.0,0.0,50.0))))
    .addChild(new Background().setGroundAngle(new double[] {1.57079}).setGroundColor(new MFColor(new double[] {1.0,0.8,0.6,0.6,0.4,0.2})).setSkyAngle(new double[] {0.2}).setSkyColor(new MFColor(new double[] {1.0,1.0,1.0,0.2,0.2,1.0}))));
            }
            catch (Exception ex)
            {       
                System.err.println ("*** Further hints on X3DJSAIL errors and exceptions at");
                System.err.println ("*** https://www.web3d.org/specifications/java/X3DJSAIL.html");
                throw (ex);
            }
	}
	// end of initialize() method

	/** The initialized model object, created within initialize() method. */
	private X3D x3dModel;

	/** 
	 * Provide a 
	 * <a href="https://dzone.com/articles/java-copy-shallow-vs-deep-in-which-you-will-swim" target="_blank">shallow copy</a>
	 * of the X3D model.
	 * @see <a href="https://www.web3d.org/specifications/java/javadoc/org/web3d/x3d/jsail/Core/X3D.html">X3D</a>
	 * @return TSSRPairPrototype model
	 */
	public X3D getX3dModel()
	{	  
		return x3dModel;
	}
	   
    /** 
     * Default main() method provided for test purposes, uses CommandLine to set global ConfigurationProperties for this object.
     * @param args array of input parameters, provided as arguments
     * @see <a href="https://www.web3d.org/specifications/java/javadoc/org/web3d/x3d/jsail/Core/X3D.html#handleArguments-java.lang.String:A-">X3D.handleArguments(args)</a>
     * @see <a href="https://www.web3d.org/specifications/java/javadoc/org/web3d/x3d/jsail/Core/X3D.html#validationReport--">X3D.validationReport()</a>
     * @see <a href="https://www.web3d.org/specifications/java/javadoc/org/web3d/x3d/jsail/CommandLine.html">CommandLine</a>
     * @see <a href="https://www.web3d.org/specifications/java/javadoc/org/web3d/x3d/jsail/CommandLine.html#USAGE">CommandLine.USAGE</a>
     * @see <a href="https://www.web3d.org/specifications/java/javadoc/org/web3d/x3d/jsail/ConfigurationProperties.html">ConfigurationProperties</a>
     */
    public static void main(String args[])
    {
        System.out.println("Build this X3D model, showing validation diagnostics...");
        X3D thisExampleX3dModel = new TSSRPairPrototype().getX3dModel();
//      System.out.println("X3D model construction complete.");
	
        // next handle command line arguments
        boolean hasArguments = (args != null) && (args.length > 0);
        boolean validate = true; // default
        boolean argumentsLoadNewModel = false;
        String  fileName = new String();

        if (args != null)
        {
                for (String arg : args)
                {
                        if (arg.toLowerCase().startsWith("-v") || arg.toLowerCase().contains("validate"))
                        {
                                validate = true; // making sure
                        }
                        if (arg.toLowerCase().endsWith(X3D.FILE_EXTENSION_X3D) ||
                                arg.toLowerCase().endsWith(X3D.FILE_EXTENSION_CLASSICVRML) ||
                                arg.toLowerCase().endsWith(X3D.FILE_EXTENSION_X3DB) ||
                                arg.toLowerCase().endsWith(X3D.FILE_EXTENSION_VRML97) ||
                                arg.toLowerCase().endsWith(X3D.FILE_EXTENSION_EXI) ||
                                arg.toLowerCase().endsWith(X3D.FILE_EXTENSION_GZIP) ||
                                arg.toLowerCase().endsWith(X3D.FILE_EXTENSION_ZIP) ||
                                arg.toLowerCase().endsWith(X3D.FILE_EXTENSION_HTML) ||
                                arg.toLowerCase().endsWith(X3D.FILE_EXTENSION_XHTML))
                        {
                                argumentsLoadNewModel = true;
                                fileName = arg;
                        }
                }
        }
        if      (argumentsLoadNewModel)
                System.out.println("WARNING: \"Savage.CommunicationsAndSensors.TSSR.TSSRPairPrototype\" model invocation is attempting to load file \"" + fileName + "\" instead of simply validating itself... file loading ignored.");
        else if (hasArguments) // if no arguments provided, this method produces usage warning
                thisExampleX3dModel.handleArguments(args);
	
        if (validate)
        {
            //  System.out.println("--- TODO fix duplicated outputs ---"); // omit when duplicated outputs problem is solved/refactored
		String validationResults = thisExampleX3dModel.validationReport();
            //  System.out.println("-----------------------------------"); // omit when duplicated outputs problem is solved/refactored
                System.out.print("Savage.CommunicationsAndSensors.TSSR.TSSRPairPrototype self-validation test confirmation: ");
                if (!validationResults.equals("success"))
                    System.out.println();
                System.out.println(validationResults.trim());

                // experimental: test X3DJSAIL output files
                // CommunicationsAndSensors/TSSR/TSSRPairPrototype_JavaExport.* file validation is checked when building X3D Example Archives
                String filenameX3D  = "CommunicationsAndSensors/TSSR/TSSRPairPrototype_JavaExport.x3d"; 
                String filenameX3DV = "CommunicationsAndSensors/TSSR/TSSRPairPrototype_JavaExport.x3dv"; 
                String filenameJSON = "CommunicationsAndSensors/TSSR/TSSRPairPrototype_JavaExport.json";
                thisExampleX3dModel.toFileX3D        (filenameX3D);
                thisExampleX3dModel.toFileClassicVRML(filenameX3DV);
// TODO         thisExampleX3dModel.toFileJSON       (filenameJSON);
        }
    }
}
