package Savage.Tools.Symbology;

import org.web3d.x3d.jsail.Core.*;
import org.web3d.x3d.jsail.fields.*;
import org.web3d.x3d.jsail.Geometry3D.*;
import org.web3d.x3d.jsail.Grouping.*;
import org.web3d.x3d.jsail.Rendering.*;
import org.web3d.x3d.jsail.Shape.*;

// Javadoc metadata annotations follow, see below for X3DJSAIL Java source code.
/**
 * <p> WeaponsCoverage is a prototype to show effective weapons range. </p>
 <p> Related links: Catalog page <a href="../../../../Tools/Symbology/WeaponsCoverageIndex.html" target="_blank">WeaponsCoverage</a>,  source <a href="../../../../Tools/Symbology/WeaponsCoverage.java">WeaponsCoverage.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="../../../../Tools/Symbology/WeaponsCoverage.x3d">WeaponsCoverage.x3d</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> description </i> </td>
			<td> WeaponsCoverage is a prototype to show effective weapons range </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> creator </i> </td>
			<td> LT Patrick Sullivan </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> created </i> </td>
			<td> 3 August 2006 </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> modified </i> </td>
			<td> 28 November 2019 </td>
		</tr>
		<tr style="color:red">
			<td style="text-align:right; vertical-align: text-top;"> <i> error </i> </td>
			<td> Duplicate of WeaponsCoveragePrototype.x3d, need to delete </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/Tools/Symbology/WeaponsCoverage.x3d" target="_blank">https://www.web3d.org/x3d/content/examples/Savage/Tools/Symbology/WeaponsCoverage.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="../../../../Tools/Symbology/../../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 LT Patrick Sullivan
 */

public class WeaponsCoverage
{
	/** Default constructor to create this object. */
	public WeaponsCoverage ()
	{
	  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("WeaponsCoverage.x3d"))
    .addMeta(new meta().setName(meta.NAME_DESCRIPTION).setContent("WeaponsCoverage is a prototype to show effective weapons range"))
    .addMeta(new meta().setName(meta.NAME_CREATOR    ).setContent("LT Patrick Sullivan"))
    .addMeta(new meta().setName(meta.NAME_CREATED    ).setContent("3 August 2006"))
    .addMeta(new meta().setName(meta.NAME_MODIFIED   ).setContent("28 November 2019"))
    .addMeta(new meta().setName(meta.NAME_ERROR      ).setContent("Duplicate of WeaponsCoveragePrototype.x3d, need to delete"))
    .addMeta(new meta().setName(meta.NAME_IDENTIFIER ).setContent("https://www.web3d.org/x3d/content/examples/Savage/Tools/Symbology/WeaponsCoverage.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 WorldInfo().setTitle("WeaponsCoverage.x3d"))
    .addChild(new ProtoDeclare("WeaponsCoverage").setName("WeaponsCoverage")
      .setProtoInterface(new ProtoInterface()
        .addField(new field().setName("whichChoice").setType(field.TYPE_SFINT32).setAccessType(field.ACCESSTYPE_INPUTOUTPUT).setValue(-1).setAppinfo("Turns zones on and off")))
      .setProtoBody(new ProtoBody()
        .addChild(new Switch().setWhichChoice(-1)
          .setIS(new IS()
            .addConnect(new connect().setNodeField("whichChoice").setProtoField("whichChoice")))
          .addChild(new Transform("WeaponsCoverage").setScale(10.0,10.0,20.0).setTranslation(31.767,1.071,0.0)
            .addChild(new Shape("CoverageGeometry")
              .setAppearance(new Appearance()
                .setMaterial(new Material("LightBlue").setDiffuseColor(0.0,1.0,1.0).setTransparency(0.5)))
              .setGeometry(new IndexedFaceSet().setCreaseAngle(0.524).setCoordIndex(getIndexedFaceSet_8_18_coordIndex())
                .setCoord(new Coordinate().setPoint(getCoordinate_9_18_point())))))))));
            }
            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

		/** Define subarrays using type int[] */
		private int[] getIndexedFaceSet_8_18_coordIndex_1()
		{
			int[] value = {0,1,2,-1,0,2,3,-1,0,4,5,-1,0,5,1,-1,0,3,6,-1,0,6,4,-1,7,1,5,-1,7,5,8,-1,7,8,9,-1,7,9,10,-1,7,10,2,-1,7,2,1,-1,11,8,5,-1,11,5,12,-1,11,12,13,-1,11,13,14,-1,11,14,9,-1,11,9,8,-1,15,12,5,-1,15,5,16,-1,15,16,17,-1,15,17,18,-1,15,18,13,-1,15,13,12,-1,19,16,5,-1,19,5,20,-1,19,20,21,-1,19,21,22,-1,19,22,17,-1,19,17,16,-1,23,20,5,-1,23,5,24,-1,23,25,21,-1,23,21,20,-1,23,26,27,-1,23,27,25,-1,23,24,28,-1,23,28,26,-1,29,26,28,-1,29,28,30,-1,29,30,31,-1,29,31,32,-1,29,32,27,-1,29,27,26,-1,33,34,35,-1,33,35,36,-1,33,36,31,-1,33,31,30,-1,33,30,28,-1,33,28,24,-1,33,24,5,-1,33,5,34,-1,37,34,5,-1,37,5,38,-1,37,38,39,-1,37,39,40,-1,37,40,35,-1,37,35,34,-1,41,38,5,-1,41,5,42,-1,41,42,43,-1,41,43,44,-1,41,44,39,-1,41,39,38,-1,45,42,5,-1,45,5,46,-1,45,46,47,-1,45,47,48,-1,45,48,43,-1,45,43,42,-1,49,4,6,-1,49,6,50,-1,49,46,5,-1,49,5,4,-1,49,50,47,-1,49,47,46,-1,51,3,2,-1,51,2,52,-1,51,52,53,-1,51,53,54,-1,51,54,6,-1,51,6,3,-1,55,10,9,-1,55,9,56,-1,55,52,2,-1,55,2,10,-1,55,56,53,-1,55,53,52,-1,57,14,13,-1,57,13,58,-1,57,56,9,-1,57,9,14,-1,57,58,53,-1,57,53,56,-1,59,18,17,-1,59,17,60,-1,59,58,13,-1,59,13,18,-1,59,60,53,-1,59,53,58,-1,61,22,21,-1,61,21,62,-1,61,60,17,-1,61,17,22,-1,61,62,53,-1,61,53,60,-1,63,25,27,-1,63,27,64,-1,63,62,21,-1,63,21,25,-1,63,64,65,-1,63,65,66,-1,63,66,53,-1,63,53,62,-1,67,68,65,-1,67,65,64,-1,67,64,27,-1,67,27,32,-1,67,32,31,-1,67,31,68,-1,69,36,35,-1,69,35,70,-1,69,70,53,-1,69,53,66,-1,69,68,31,-1,69,31,36,-1,69,66,65,-1,69,65,68,-1,71,40,39,-1,71,39,72,-1,71,70,35,-1,71,35,40,-1,71,72,53,-1,71,53,70,-1,73,44,43,-1,73,43,74,-1,73,72,39,-1,73,39,44,-1,73,74,53,-1,73,53,72,-1,75,48,47,-1,75,47,76,-1,75,74,43,-1,75,43,48,-1,75,76,53,-1,75,53,74,-1,77,50,6,-1,77,6,54,-1,77,54,53,-1,77,53,76,-1,77,76,47,-1,77,47,50,-1};
			return value;
		}


		/** Large attribute array: IndexedFaceSet coordIndex field, scene-graph level=8, element #18, 608 total numbers.
		 * Reassemble split array as single method to improve readability and runnability.
		 * Provide large array values via separate methods, hoping to avoid 'code too large' Java compilation errors. 
		 * Individual Java methods (including aggregated initializations) are limited to 64KB.
		 * @see https://stackoverflow.com/questions/2407912/code-too-large-compilation-error-in-java
		 * @see https://stackoverflow.com/questions/11437905/java-too-many-constants-jvm-error
		 */
		private MFInt32 getIndexedFaceSet_8_18_coordIndex()
		{
			MFInt32 IndexedFaceSet_8_18_coordIndex = new MFInt32()/*2.finalize*/
				.append(new MFInt32(getIndexedFaceSet_8_18_coordIndex_1()));
			return IndexedFaceSet_8_18_coordIndex;
		}
		/** Large attribute array: Coordinate point field, scene-graph level=9, element #18, 234 total numbers made up of 78 3-tuple values.
		 * Reassemble split array as single method to improve readability and runnability.
		 * Provide large array values via separate methods, hoping to avoid 'code too large' Java compilation errors. 
		 * Individual Java methods (including aggregated initializations) are limited to 64KB.
		 * @see https://stackoverflow.com/questions/2407912/code-too-large-compilation-error-in-java
		 * @see https://stackoverflow.com/questions/11437905/java-too-many-constants-jvm-error
		 */
		private MFVec3f getCoordinate_9_18_point()
		{
			MFVec3f Coordinate_9_18_point = new MFVec3f(new double[] {2.28,.05,-0.0,2.23,.05,.52,2.23,0.0,.52,2.28,0.0,-0.0,2.23,.05,-.52,.66,.05,-0.0,2.23,0.0,-.52,2.08,.05,1.03,1.83,.05,1.49,1.83,0.0,1.49,2.08,0.0,1.03,1.49,.05,1.9,1.09,.05,2.24,1.09,0.0,2.24,1.49,0.0,1.9,.62,.05,2.49,.12,.05,2.64,.12,0.0,2.64,.62,0.0,2.49,-.41,.05,2.69,-.93,.05,2.64,-.93,0.0,2.64,-.41,0.0,2.69,-1.54,.05,2.24,-1.07,.05,0.0,-1.54,0.0,2.24,-2.3,.05,1.27,-2.3,0.0,1.27,-2.02,.05,0.0,-3.15,.05,0.0,-2.3,.05,-1.27,-2.3,0.0,-1.27,-3.15,0.0,0.0,-1.54,.05,-2.24,-.93,.05,-2.64,-.93,0.0,-2.64,-1.54,0.0,-2.24,-.41,.05,-2.69,.12,.05,-2.64,.12,0.0,-2.64,-.41,0.0,-2.69,.62,.05,-2.49,1.09,.05,-2.24,1.09,0.0,-2.24,.62,0.0,-2.49,1.49,.05,-1.9,1.83,.05,-1.49,1.83,0.0,-1.49,1.49,0.0,-1.9,2.08,.05,-1.03,2.08,0.0,-1.03,2.28,-.05,-0.0,2.23,-.05,.52,.66,-.05,-0.0,2.23,-.05,-.52,2.08,-.05,1.03,1.83,-.05,1.49,1.49,-.05,1.9,1.09,-.05,2.24,.62,-.05,2.49,.12,-.05,2.64,-.41,-.05,2.69,-.93,-.05,2.64,-1.54,-.05,2.24,-2.3,-.05,1.27,-2.02,-.05,0.0,-1.07,-.05,0.0,-3.15,-.05,0.0,-2.3,-.05,-1.27,-1.54,-.05,-2.24,-.93,-.05,-2.64,-.41,-.05,-2.69,.12,-.05,-2.64,.62,-.05,-2.49,1.09,-.05,-2.24,1.49,-.05,-1.9,1.83,-.05,-1.49,2.08,-.05,-1.03});
			return Coordinate_9_18_point;
		}

	/** 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 WeaponsCoverage 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 WeaponsCoverage().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.Tools.Symbology.WeaponsCoverage\" 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.Tools.Symbology.WeaponsCoverage self-validation test confirmation: ");
                if (!validationResults.equals("success"))
                    System.out.println();
                System.out.println(validationResults.trim());

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