package Savage.CommunicationsAndSensors.Sonar;

import org.web3d.x3d.jsail.Core.*;
import org.web3d.x3d.jsail.EnvironmentalEffects.*;
import org.web3d.x3d.jsail.fields.*;
import org.web3d.x3d.jsail.Geometry3D.*;
import org.web3d.x3d.jsail.Grouping.*;
import org.web3d.x3d.jsail.Navigation.*;
import org.web3d.x3d.jsail.Networking.*;
import org.web3d.x3d.jsail.Rendering.*;
import org.web3d.x3d.jsail.Scripting.*;
import org.web3d.x3d.jsail.Shape.*;
import org.web3d.x3d.jsail.Text.*;

// Javadoc metadata annotations follow, see below for X3DJSAIL Java source code.
/**
 * <p> Produce wireframe or transparent sidescan sonar beams. </p>
 <p> Related links: Catalog page <a href="../../../../CommunicationsAndSensors/Sonar/SideScanSonarPrototypeIndex.html" target="_blank">SideScanSonarPrototype</a>,  source <a href="../../../../CommunicationsAndSensors/Sonar/SideScanSonarPrototype.java">SideScanSonarPrototype.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/Sonar/SideScanSonarPrototype.x3d">SideScanSonarPrototype.x3d</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> description </i> </td>
			<td> Produce wireframe or transparent sidescan sonar beams. </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> creator </i> </td>
			<td> Don Brutzman </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> created </i> </td>
			<td> 15 March 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/Sonar/SideScanSonarPrototype.x3d" target="_blank">https://www.web3d.org/x3d/content/examples/Savage/CommunicationsAndSensors/Sonar/SideScanSonarPrototype.x3d</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> generator </i> </td>
			<td> X3D-Edit 3.3, <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/Sonar/../../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 Don Brutzman
 */

public class SideScanSonarPrototype
{
	/** Default constructor to create this object. */
	public SideScanSonarPrototype ()
	{
	  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_3)
  .setHead(new head()
    .addMeta(new meta().setName(meta.NAME_TITLE      ).setContent("SideScanSonarPrototype.x3d"))
    .addMeta(new meta().setName(meta.NAME_DESCRIPTION).setContent("Produce wireframe or transparent sidescan sonar beams."))
    .addMeta(new meta().setName(meta.NAME_CREATOR    ).setContent("Don Brutzman"))
    .addMeta(new meta().setName(meta.NAME_CREATED    ).setContent("15 March 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/Sonar/SideScanSonarPrototype.x3d"))
    .addMeta(new meta().setName(meta.NAME_GENERATOR  ).setContent("X3D-Edit 3.3, https://www.web3d.org/x3d/tools/X3D-Edit"))
    .addMeta(new meta().setName(meta.NAME_LICENSE    ).setContent("../../license.html")))
  .setScene(new Scene()
    .addChild(new NavigationInfo("LockedDownInterface2D").setType(new String[] {"NONE"}))
    .addChild(new Background().setSkyColor(new MFColor(new double[] {0.0,0.3,0.5})))
    .addChild(new WorldInfo().setInfo(new String[] {"Produce wireframe or transparent beam cones."}).setTitle("BeamCone Prototyupe"))
    .addChild(new Viewpoint().setDescription("SideScanSonar Prototype").setPosition(0.0,0.0,15.0))
    .addChild(new ProtoDeclare("SideScanSonar").setName("SideScanSonar").setAppinfo("Produce wireframe or semi-transparent sonar sidescan beams")
      .setProtoInterface(new ProtoInterface()
        .addField(new field().setName("altitude").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INPUTONLY).setAppinfo("vertical distance above bottom in meters along y axis"))
        .addField(new field().setName("defaultAltitude").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(3).setAppinfo("default vertical distance above bottom in meters along y axis"))
        .addField(new field().setName("maxAltitude").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(3).setAppinfo("maximum effective altitude of sidescan sonar above bottom"))
        .addField(new field().setName("defaultCrossTrackHalfRange").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(30).setAppinfo("distance in meters from nadir to rightmost/leftmost edge when operating at defaultAltitude above the bottom"))
        .addField(new field().setName("defaultTrackWidthMeters").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(0.30).setAppinfo("longitudinal width of a single return"))
        .addField(new field().setName("vehicleWidthMeters").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(0.178).setAppinfo("width (or diameter) of vehicle carrying port/starboard sidescan sonar transducers"))
        .addField(new field().setName("contact").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INPUTONLY).setAppinfo("(communications) whether transmitted signal is in contact with receiver or (sensor) is a target return detected?"))
        .addField(new field().setName("wireframe").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(true).setAppinfo("draw lines for tracking shape?"))
        .addField(new field().setName("solid").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(true).setAppinfo("draw solid tracking shape?"))
        .addField(new field().setName("contactColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(new SFColor(.8,.1,.1)).setAppinfo("rendering color when contact=true"))
        .addField(new field().setName("noContactColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(new SFColor(.3,.5,.5)).setAppinfo("rendering color when contact=false"))
        .addField(new field().setName("transparency").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INPUTOUTPUT).setValue(0).setAppinfo("1 = fully transparent wireframe only")))
      .setProtoBody(new ProtoBody()
        .addComments(" BEAM_CONTROL beam scaling is controlled by range/beamHeightDegrees/beamWidthDegrees/direction inputs ")
        .addChild(new Transform("BEAM_CONTROL")
          .addChild(new Switch("WIREFRAME_SWITCH").setWhichChoice(1)
            .addComments(" TODO refactor index values starting from -1, remove WorldInfo ")
            .addChild(new WorldInfo().setInfo(new String[] {"initial choice is null node (WorldInfo), meaning no wireframe beam"}))
            .addChild(new Shape()
              .setAppearance(new Appearance()
                .setMaterial(new Material("WireMaterial").setDiffuseColor(.1,.1,.1).setEmissiveColor(.1,.1,.1)
                  .setIS(new IS()
                    .addConnect(new connect().setNodeField("transparency").setProtoField("transparency")))))
              .setGeometry(new IndexedLineSet("ILS").setDEF("ILS").setCoordIndex(new int[] {1,2,3,1,-1,5,3,4,5,-1,6,8,7,6,-1,10,9,8,10,-1,6,7,2,1,6,-1,10,5,4,9,10,-1})
                .setCoord(new Coordinate("BeamPatternCoordinatePoints").setPoint(new MFVec3f(new double[] {0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0}))))))
          .addChild(new Switch("SOLID_SWITCH").setWhichChoice(0)
            .addComments(" TODO refactor index values starting from -1, remove WorldInfo ")
            .addChild(new WorldInfo().setInfo(new String[] {"initial choice is null node (WorldInfo), meaning no solid beam"}))
            .addChild(new Shape()
              .setAppearance(new Appearance()
                .setMaterial(new Material("FaceMaterial").setDiffuseColor(.1,.1,.1)
                  .setIS(new IS()
                    .addConnect(new connect().setNodeField("transparency").setProtoField("transparency")))))
              .setGeometry(new IndexedFaceSet("IFS").setDEF("IFS").setSolid(false).setCoordIndex(new int[] {1,2,3,1,-1,5,3,4,5,-1,6,8,7,6,-1,10,9,8,10,-1,6,7,2,1,6,-1,10,5,4,9,10,-1})
                .setCoord(new Coordinate().setUSE("BeamPatternCoordinatePoints"))))))
        .addComments(" Non-renderable animation controls ")
        .addChild(new Script("BEAM_CALCULATE").setSourceCode("""
ecmascript:

function tracePrint (value)
{
	if (traceEnabled) Browser.println ('[SideScanSonar BEAM_CALCULATE] ' + value);
}

function initialize () {
 beamScale = new SFVec3f (1, 1, 1);
 dt2 = defaultTrackWidthMeters/2;

 origin = new SFVec3f (0, 0, 0);
 a  = new SFVec3f (-dt2,  0,               -vehicleWidthMeters/2);
 b  = new SFVec3f (-dt2, -defaultAltitude, -defaultCrossTrackHalfRange);
 c  = new SFVec3f (-dt2, -defaultAltitude,  0);
 d  = new SFVec3f (-dt2, -defaultAltitude,  defaultCrossTrackHalfRange);
 e  = new SFVec3f (-dt2,  0,                vehicleWidthMeters/2);
 aa = new SFVec3f ( dt2,  0,               -vehicleWidthMeters/2);
 bb = new SFVec3f ( dt2, -defaultAltitude, -defaultCrossTrackHalfRange);
 cc = new SFVec3f ( dt2, -defaultAltitude,  0);
 dd = new SFVec3f ( dt2, -defaultAltitude,  defaultCrossTrackHalfRange);
 ee = new SFVec3f ( dt2,  0,                vehicleWidthMeters/2);

 coordinatePoints = new MFVec3f (origin, a, b, c, d, e, aa, bb, cc, dd, ee);

 tracePrint ('coordinatePoints =' + coordinatePoints);
}
function altitude (newAltitude, timeStamp) {
 if (newAltitude <= 0)
 {
   beamHeightFactor= 0.001;
   beamScale = new SFVec3f (1, beamHeightFactor, beamHeightFactor);
 }
 else if (newAltitude < maxAltitude)
 {
   beamHeightFactor= newAltitude / defaultAltitude;
   beamScale = new SFVec3f (1, beamHeightFactor, beamHeightFactor);
 }
 else
 {
   beamHeightFactor= maxAltitude / defaultAltitude;
   beamScale = new SFVec3f (1, beamHeightFactor, beamHeightFactor);
 }
 tracePrint ('newAltitude      =' + newAltitude);
 tracePrint ('beamHeightFactor =' + beamHeightFactor);
 tracePrint ('beamScale        =' + beamScale);
}
""")
          .addField(new field().setName("altitude").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INPUTONLY))
          .addField(new field().setName("defaultAltitude").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
          .addField(new field().setName("maxAltitude").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
          .addField(new field().setName("defaultCrossTrackHalfRange").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
          .addField(new field().setName("defaultTrackWidthMeters").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
          .addField(new field().setName("vehicleWidthMeters").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
          .addField(new field().setName("beamScale").setType(field.TYPE_SFVEC3F).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
          .addField(new field().setName("coordinatePoints").setType(field.TYPE_MFVEC3F).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
          .addField(new field().setName("traceEnabled").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(false).setAppinfo("internal flag to turn on Script tracing"))
          .setIS(new IS()
            .addConnect(new connect().setNodeField("altitude").setProtoField("altitude"))
            .addConnect(new connect().setNodeField("defaultAltitude").setProtoField("defaultAltitude"))
            .addConnect(new connect().setNodeField("maxAltitude").setProtoField("maxAltitude"))
            .addConnect(new connect().setNodeField("defaultCrossTrackHalfRange").setProtoField("defaultCrossTrackHalfRange"))
            .addConnect(new connect().setNodeField("defaultTrackWidthMeters").setProtoField("defaultTrackWidthMeters"))
            .addConnect(new connect().setNodeField("vehicleWidthMeters").setProtoField("vehicleWidthMeters"))))
        .addChild(new Script("DETECTION").setDirectOutput(true).setSourceCode("""
ecmascript:

function tracePrint (value)
{
	if (traceEnabled) Browser.println ('[SideScanSonar DETECTION] ' + value);
}

function initialize ()
{
	beamColor = noContactColor;
	if (wireframe == true) wireframeChoice = 1;
	if (solid     == true) solidChoice     = 1;

	// Debug  statements
	tracePrint ('  wireframe       =' + wireframe);
	tracePrint ('  solid           =' + solid);
	tracePrint ('  contactColor    =' + contactColor);
	tracePrint ('  noContactColor  =' + noContactColor);
	tracePrint ('  beamColor       =' + beamColor);
	tracePrint ('  wireframeChoice =' + wireframeChoice);
	tracePrint ('  solidChoice     =' + solidChoice);
	tracePrint ('  transparency    =' + MaterialNodeHolder.transparency);
}
function contact (newDetect, timeStamp)
{
	tracePrint ('  newDetect       =' + newDetect);
	if (newDetect) beamColor = contactColor;
	else           beamColor = noContactColor;
}
""")
          .addField(new field().setName("contact").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INPUTONLY))
          .addField(new field().setName("wireframe").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
          .addField(new field().setName("solid").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
          .addField(new field().setName("contactColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
          .addField(new field().setName("noContactColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
          .addField(new field().setName("beamColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
          .addField(new field().setName("wireframeChoice").setType(field.TYPE_SFINT32).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
          .addField(new field().setName("solidChoice").setType(field.TYPE_SFINT32).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
          .addField(new field().setName("MaterialNodeHolder").setType(field.TYPE_SFNODE).setAccessType(field.ACCESSTYPE_INITIALIZEONLY)
            .addChild(new Material().setUSE("FaceMaterial")))
          .addField(new field().setName("traceEnabled").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(false).setAppinfo("internal flag to turn on Script tracing"))
          .setIS(new IS()
            .addConnect(new connect().setNodeField("contact").setProtoField("contact"))
            .addConnect(new connect().setNodeField("wireframe").setProtoField("wireframe"))
            .addConnect(new connect().setNodeField("solid").setProtoField("solid"))
            .addConnect(new connect().setNodeField("contactColor").setProtoField("contactColor"))
            .addConnect(new connect().setNodeField("noContactColor").setProtoField("noContactColor"))))
        .addChild(new ROUTE().setFromNode("BEAM_CALCULATE").setFromField("beamScale").setToNode("BEAM_CONTROL").setToField("scale"))
        .addChild(new ROUTE().setFromNode("BEAM_CALCULATE").setFromField("coordinatePoints").setToNode("BeamPatternCoordinatePoints").setToField("point"))
        .addChild(new ROUTE().setFromNode("DETECTION").setFromField("beamColor").setToNode("WireMaterial").setToField("emissiveColor"))
        .addChild(new ROUTE().setFromNode("DETECTION").setFromField("beamColor").setToNode("FaceMaterial").setToField("emissiveColor"))
        .addChild(new ROUTE().setFromNode("DETECTION").setFromField("wireframeChoice").setToNode("WIREFRAME_SWITCH").setToField("whichChoice"))
        .addChild(new ROUTE().setFromNode("DETECTION").setFromField("solidChoice").setToNode("SOLID_SWITCH").setToField("whichChoice"))))
    .addComments(" Viewable geometry for this scene is anchored text that links to an example showing ExternProtoDeclare usage of BeamCone ")
    .addChild(new Anchor().setDescription("SideScanSonar Example").setParameter(new String[] {"target=_blank"}).setUrl(new String[] {"SideScanSonarExample.x3d","https://www.web3d.org/x3d/content/examples/Savage/CommunicationsAndSensors/Sonar/SideScanSonarExample.x3d","SideScanSonarExample.wrl","https://www.web3d.org/x3d/content/examples/Savage/CommunicationsAndSensors/Sonar/SideScanSonarExample.wrl"})
      .addChild(new Shape()
        .setAppearance(new Appearance()
          .setMaterial(new Material().setDiffuseColor(0.0,1.0,1.0).setEmissiveColor(0.0,1.0,1.0)))
        .setGeometry(new Text().setString(new String[] {"SideScanSonarPrototype","is a Prototype definition file.","","To see an example scene","click this text and view","SideScanSonarExample."})
          .setFontStyle(new FontStyle().setJustify(FontStyle.JUSTIFY_MIDDLE_MIDDLE))))
      .addChild(new Shape()
        .addComments(" transparent Box as text-selection assist ")
        .setGeometry(new Box().setSize(10.5,6.0,.001))
        .setAppearance(new Appearance()
          .setMaterial(new Material().setTransparency(1))))));
            }
            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 SideScanSonarPrototype 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 SideScanSonarPrototype().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.Sonar.SideScanSonarPrototype\" 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.Sonar.SideScanSonarPrototype self-validation test confirmation: ");
                if (!validationResults.equals("success"))
                    System.out.println();
                System.out.println(validationResults.trim());

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