package Savage.Locations.MontereyPeninsulaCollege;

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.Navigation.*;
import org.web3d.x3d.jsail.Networking.*;
import org.web3d.x3d.jsail.Scripting.*;
import org.web3d.x3d.jsail.Shape.*;

// Javadoc metadata annotations follow, see below for X3DJSAIL Java source code.
/**
 * <p> Monterey Peninsula College (MPC) swimming pool, simplest model. </p>
 <p> Related links: Catalog page <a href="../../../../Locations/MontereyPeninsulaCollege/PoolMontereyPeninsulaCollegeUsingBoxesIndex.html" target="_blank">PoolMontereyPeninsulaCollegeUsingBoxes</a>,  source <a href="../../../../Locations/MontereyPeninsulaCollege/PoolMontereyPeninsulaCollegeUsingBoxes.java">PoolMontereyPeninsulaCollegeUsingBoxes.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="../../../../Locations/MontereyPeninsulaCollege/PoolMontereyPeninsulaCollegeUsingBoxes.x3d">PoolMontereyPeninsulaCollegeUsingBoxes.x3d</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> description </i> </td>
			<td> Monterey Peninsula College (MPC) swimming pool, simplest model </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> creator </i> </td>
			<td> Don Brutzman and MV3204 class </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> created </i> </td>
			<td> 9 April 2010 </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> modified </i> </td>
			<td> 2 December 2024 </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> info </i> </td>
			<td> Includes trace diagnostic for changing user navigation from EXAMINE to FLY when binding/unbinding the initial overhead-perspective Viewpoint </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> reference </i> </td>
			<td> TODO information about ROV races </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> drawing </i> </td>
			<td> <a href="../../../../Locations/MontereyPeninsulaCollege/PoolMontereyPeninsulaCollegeSketch">PoolMontereyPeninsulaCollegeSketch</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> Image </i> </td>
			<td> <a href="../../../../Locations/MontereyPeninsulaCollege/PoolMontereyPeninsulaCollegeDiagram.png">PoolMontereyPeninsulaCollegeDiagram.png</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> Image </i> </td>
			<td> <a href="../../../../Locations/MontereyPeninsulaCollege/PoolMontereyPeninsulaCollegeDiagram.vsd">PoolMontereyPeninsulaCollegeDiagram.vsd</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> photo </i> </td>
			<td> TODO photo(s) of pool </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> subject </i> </td>
			<td> X3D swimming pool </td>
		</tr>
		<tr style="color:burntorange">
			<td style="text-align:right; vertical-align: text-top;"> <i> warning </i> </td>
			<td> under development </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> reference </i> </td>
			<td> <a href="../../../../Locations/MontereyPeninsulaCollege/PoolMontereyPeninsulaCollege.x3d">PoolMontereyPeninsulaCollege.x3d</a> </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/Locations/MontereyPeninsulaCollege/PoolMontereyPeninsulaCollegeUsingBoxes.x3d" target="_blank">https://www.web3d.org/x3d/content/examples/Savage/Locations/MontereyPeninsulaCollege/PoolMontereyPeninsulaCollegeUsingBoxes.x3d</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> generator </i> </td>
			<td> X3D-Edit, <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="../../../../Locations/MontereyPeninsulaCollege/../../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 and MV3204 class
 */

public class PoolMontereyPeninsulaCollegeUsingBoxes
{
	/** Default constructor to create this object. */
	public PoolMontereyPeninsulaCollegeUsingBoxes ()
	{
	  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_2)
  .setHead(new head()
    .addMeta(new meta().setName(meta.NAME_TITLE      ).setContent("PoolMontereyPeninsulaCollegeUsingBoxes.x3d"))
    .addMeta(new meta().setName(meta.NAME_DESCRIPTION).setContent("Monterey Peninsula College (MPC) swimming pool, simplest model"))
    .addMeta(new meta().setName(meta.NAME_CREATOR    ).setContent("Don Brutzman and MV3204 class"))
    .addMeta(new meta().setName(meta.NAME_CREATED    ).setContent("9 April 2010"))
    .addMeta(new meta().setName(meta.NAME_MODIFIED   ).setContent("2 December 2024"))
    .addMeta(new meta().setName(meta.NAME_INFO       ).setContent("Includes trace diagnostic for changing user navigation from EXAMINE to FLY when binding/unbinding the initial overhead-perspective Viewpoint"))
    .addMeta(new meta().setName(meta.NAME_REFERENCE  ).setContent("TODO information about ROV races"))
    .addMeta(new meta().setName(meta.NAME_DRAWING    ).setContent("PoolMontereyPeninsulaCollegeSketch"))
    .addMeta(new meta().setName(meta.NAME_IMAGE      ).setContent("PoolMontereyPeninsulaCollegeDiagram.png"))
    .addMeta(new meta().setName(meta.NAME_IMAGE      ).setContent("PoolMontereyPeninsulaCollegeDiagram.vsd"))
    .addMeta(new meta().setName(meta.NAME_PHOTO      ).setContent("TODO photo(s) of pool"))
    .addMeta(new meta().setName(meta.NAME_SUBJECT    ).setContent("X3D swimming pool"))
    .addMeta(new meta().setName(meta.NAME_WARNING    ).setContent("under development"))
    .addMeta(new meta().setName(meta.NAME_REFERENCE  ).setContent("PoolMontereyPeninsulaCollege.x3d"))
    .addMeta(new meta().setName(meta.NAME_IDENTIFIER ).setContent("https://www.web3d.org/x3d/content/examples/Savage/Locations/MontereyPeninsulaCollege/PoolMontereyPeninsulaCollegeUsingBoxes.x3d"))
    .addMeta(new meta().setName(meta.NAME_GENERATOR  ).setContent("X3D-Edit, https://www.web3d.org/x3d/tools/X3D-Edit"))
    .addMeta(new meta().setName(meta.NAME_LICENSE    ).setContent("../../license.html")))
  .setScene(new Scene()
    .addComments(" Put CoordinateAxes with correct directional alignment at pool origin ")
    .addChild(new WorldInfo().setTitle("PoolMontereyPeninsulaCollegeUsingBoxes.x3d"))
    .addChild(new Inline("CoordinateAxes").setUrl(new String[] {"../../Tools/Authoring/CoordinateAxes.x3d","https://www.web3d.org/x3d/content/examples/Savage/Tools/Authoring/CoordinateAxes.x3d","https://www.web3d.org/x3d/content/examples/X3dForWebAuthors/Chapter03Grouping/CoordinateAxes.x3d","../../Tools/Authoring/CoordinateAxes.wrl","https://www.web3d.org/x3d/content/examples/Savage/Tools/Authoring/CoordinateAxes.wrl","https://www.web3d.org/x3d/content/examples/X3dForWebAuthors/Chapter03Grouping/CoordinateAxes.wrl"}))
    .addComments(" Only one NavInfo can be bound at a time. Include \"ANY\" to allow user override. ")
    .addComments(" Note that our local units here are still meters. ")
    .addChild(new NavigationInfo("NavigationExamineMode").setAvatarSize(new double[] {0.25,1.6,2.0}).setSpeed(5).setType(new String[] {"EXAMINE","FLY","ANY"}))
    .addChild(new NavigationInfo("NavigationWalkMode").setAvatarSize(new double[] {0.25,1.6,2.0}).setSpeed(5).setType(new String[] {"WALK","ANY"}))
    .addChild(new NavigationInfo("NavigationFlyMode").setAvatarSize(new double[] {0.25,1.6,2.0}).setSpeed(5).setType(new String[] {"FLY","ANY"}))
    .addComments(" TODO add a deck around the edge of the pool to allow WALKing around ")
    .addComments(" All pool model measurements are in feet, therefore scale them into meters. X is length, Y is height, Z is width. ")
    .addChild(new Transform("ScaleFeetToMeters").setScale(0.305,0.305,0.305)
      .addComments(" Box centers are at local coordinate 0 0 0, this translation shifts them to put corner at pool coordinate 0 0 0 ")
      .addComments(" Viewpoints are placed here since their position is recorded in feet using the pool coordinate system ")
      .addChild(new Viewpoint("ViewOverhead").setDescription("High above looking down from 100 feet above").setCenterOfRotation(37.5,0.0,32.0).setOrientation(1.0,0.0,0.0,-1.5708).setPosition(37.5,100.0,32.0))
      .addChild(new ROUTE().setFromNode("ViewOverhead").setFromField("isBound").setToNode("NavigationExamineMode").setToField("set_bind"))
      .addChild(new Group()
        .addComments(" ======= ROUTE Trace ============================================== ")
        .addChild(new Script("Trace_ROUTE_ViewOverhead_isBound_TO_NavigationExamineMode_set_bind").setMustEvaluate(true).setSourceCode("""
ecmascript:
    function set_traceValue (eventValue, timeStamp)
    {
        Browser.println ('Script method set_traceValue invoked, which is now handing off to traceValueHandler()...');
        traceValueHandler (eventValue, timeStamp);
    }
    function traceValue (eventValue, timeStamp)
    {
        Browser.println ('Script method traceValue invoked, which is now handing off to traceValueHandler()...');
        traceValueHandler (eventValue, timeStamp);
    }
    function traceValueHandler (eventValue, timeStamp)
    {
      // input eventValue received for trace field
      if (timeStamp - timeStampPreviousReport >= reportInterval) {
        Browser.println ('Trace_ROUTE_ViewOverhead_isBound_TO_NavigationExamineMode_set_bind type=SFBool value=' + eventValue);
        timeStampPreviousReport = timeStamp;
        if  (eventValue == true)
             Browser.println ('User navigation should be EXAMINE');
        else Browser.println ('User navigation should be FLY');
      }
    }
    function timeOfDay (someTime) {
      hh = Math.floor (someTime /(60*60)) % 24;
      mm = Math.floor (someTime / 60)     % 60;
      ss = Math.floor (someTime)          % 60;
      if (hh < 9) hour   = '0' + hh;
      else        hour   =       hh;
      if (mm < 9) minute = '0' + mm;
      else        minute =       mm;
      if (ss < 9) second = '0' + ss;
      else        second =       ss;
      return '(' + hour + ':' + minute + ':' + second + ' GMT)';
    }
""")
          .addComments(" Trace ROUTEd values on X3D browser console ")
          .addField(new field().setName("reportInterval").setType(field.TYPE_SFTIME).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(1.0).setAppinfo("Sampling frequency in seconds (0 means all values)"))
          .addField(new field().setName("traceValue").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INPUTOUTPUT).setValue(true))
          .addField(new field().setName("timeStampPreviousReport").setType(field.TYPE_SFTIME).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(-1)))
        .addChild(new ROUTE().setFromNode("ViewOverhead").setFromField("isBound").setToNode("Trace_ROUTE_ViewOverhead_isBound_TO_NavigationExamineMode_set_bind").setToField("traceValue"))
        .addComments(" ======= ROUTE Trace block complete ===================================================== "))
      .addComments(" other Viewpoints do not get EXAMINE navigation type ")
      .addChild(new Viewpoint().setDescription("Shallow end left side, from origin").setOrientation(0.0067,0.9998,0.0161,-2.3563).setPosition(-12.0,6.0,-12.0))
      .addChild(new Viewpoint().setDescription("Pool center left side").setOrientation(0.0,0.9955,0.0949,3.1413).setPosition(37.52,10.0,-20.0))
      .addChild(new Viewpoint().setDescription("Deep end left side").setOrientation(-0.0203,0.9988,0.0451,2.2984).setPosition(87.0,6.0,-12.0))
      .addChild(new Viewpoint().setDescription("Deep end center").setOrientation(-0.0857,0.9926,0.0857,1.5782).setPosition(95.0,10.0,32.0))
      .addChild(new Viewpoint().setDescription("Deep end right side").setOrientation(-0.1001,0.994,0.0449,0.8487).setPosition(87.0,6.0,76.0))
      .addChild(new Viewpoint().setDescription("Pool center right side").setOrientation(-1.0,0.002,0.0002,0.2235).setPosition(37.52,10.0,84.0))
      .addChild(new Viewpoint().setDescription("Shallow end right side").setOrientation(0.1001,0.994,0.0449,-0.8487).setPosition(-12.0,6.0,76.0))
      .addChild(new Viewpoint().setDescription("Shallow end center").setOrientation(0.0864,0.99251,0.0864,-1.578318).setPosition(-20.0,10.0,32.0))
      .addChild(new Transform("ShiftBoxCornersToPoolCenter").setTranslation(37.5,-12.75,32.0)
        .addChild(new Shape("PoolFloor")
          .setGeometry(new Box().setSize(75.0,0.25,64.0))
          .setAppearance(new Appearance("AppearanceWall")
            .setMaterial(new Material().setDiffuseColor(0.5,0.9,0.9))))
        .addChild(new Transform("ShallowWall").setTranslation(-37.5,6.25,0.0)
          .addChild(new Shape("ShortWall")
            .setGeometry(new Box().setSize(0.25,12.75,64.0))
            .setAppearance(new Appearance().setUSE("AppearanceWall"))))
        .addChild(new Transform("DeepWall").setTranslation(37.5,6.25,0.0)
          .addChild(new Shape().setUSE("ShortWall")))
        .addChild(new Transform("LeftWall").setTranslation(0.0,6.25,-32.0)
          .addChild(new Shape("LongWall")
            .setGeometry(new Box().setSize(75.0,12.75,0.25))
            .setAppearance(new Appearance().setUSE("AppearanceWall"))))
        .addChild(new Transform("RightWall").setTranslation(0.0,6.25,32.0)
          .addChild(new Shape().setUSE("LongWall")))
        .addChild(new Transform("DeepFloor").setRotation(0.0,0.0,1.0,0.1732).setTranslation(32.5,.9,0.0)
          .addChild(new Shape()
            .setGeometry(new Box().setSize(10.152,0.25,64.0))
            .setAppearance(new Appearance().setUSE("AppearanceWall"))))
        .addChild(new Transform("DeepFloor2").setRotation(0.0,0.0,1.0,-0.2085).setTranslation(21.0,1.4,0.0)
          .addChild(new Shape()
            .setGeometry(new Box().setSize(13.288,0.25,64.0))
            .setAppearance(new Appearance().setUSE("AppearanceWall"))))
        .addChild(new Transform("DeepFloor3").setRotation(0.0,0.0,1.0,-0.2783).setTranslation(7.5,4.75,0.0)
          .addChild(new Shape()
            .setGeometry(new Box().setSize(14.560,0.25,64.0))
            .setAppearance(new Appearance().setUSE("AppearanceWall"))))
        .addChild(new Transform("DeepFloor4").setRotation(0.0,0.0,1.0,-0.0476).setTranslation(-10.0,7.25,0.0)
          .addChild(new Shape()
            .setGeometry(new Box().setSize(21.024,0.25,64.0))
            .setAppearance(new Appearance().setUSE("AppearanceWall"))))
        .addChild(new Transform("DeepFloor5").setRotation(0.0,0.0,1.0,-0.0588).setTranslation(-29.0,8.25,0.0)
          .addChild(new Shape()
            .setGeometry(new Box().setSize(17.029,0.25,64.0))
            .setAppearance(new Appearance().setUSE("AppearanceWall")))))));
            }
            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 PoolMontereyPeninsulaCollegeUsingBoxes 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 PoolMontereyPeninsulaCollegeUsingBoxes().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.Locations.MontereyPeninsulaCollege.PoolMontereyPeninsulaCollegeUsingBoxes\" 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.Locations.MontereyPeninsulaCollege.PoolMontereyPeninsulaCollegeUsingBoxes self-validation test confirmation: ");
                if (!validationResults.equals("success"))
                    System.out.println();
                System.out.println(validationResults.trim());

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