####################################################################################################
#
# Invoking X3D model self-test:
#
#   $ python .py
#
# Python package x3d.py package is available on PyPI for import.
#   This approach simplifies Python X3D deployment and use.
#   https://pypi.org/project/x3d
#
# Installation:
#       pip install x3d
# or
#       python -m pip install x3d
#
# Developer options for loading x3d package in other Python programs:
#
#    from x3d import *  # preferred approach, terser source that avoids x3d.* class prefixes
#
# or
#    import x3d         # traditional way to subclass x3d package, all classes require x3d.* prefix,
#                       # but python source is very verbose, for example x3d.Material x3d.Shape etc.
#                       # X3dToPython.xslt stylesheet insertPackagePrefix=true supports this option.
#
# Project home page:    # X3D Python Scene Access Interface Library (X3DPSAIL)
#                       # https://www.web3d.org/x3d/stylesheets/python/python.html
# Conversion generator: # https://www.web3d.org/x3d/stylesheets/X3dToPython.xslt
#
####################################################################################################

from x3d import *

newModel=X3D(profile='Immersive',version='3.0',
  head=head(
    children=[
    meta(content='GreekFrigateDesign',name='title'),
    meta(content='Copyright [2001] By George Stavritis',name='creator'),
    meta(content='28 February 2001',name='created'),
    meta(content='20 October 2019',name='modified'),
    meta(content='A simpler version of frigate.',name='description'),
    meta(content='https://www.web3d.org/x3d/content/examples/Savage/ShipsMilitary/FrigateGreece/GreekFrigateDesign.x3d',name='identifier'),
    meta(content='X3D-Edit 3.2, https://www.web3d.org/x3d/tools/X3D-Edit',name='generator'),
    meta(content='../../license.html',name='license')]),
  Scene=Scene(
    children=[
    WorldInfo(title='GreekFrigateDesign'),
    Background(backUrl=["mountns.png","https://www.web3d.org/x3d/content/examples/Vrml2Sourcebook/mountns.png"],frontUrl=["mountns.png","https://www.web3d.org/x3d/content/examples/Vrml2Sourcebook/mountns.png"],groundAngle=[1.309,1.570796],groundColor=[(1,1,1),(0.1,0.1,0.5),(0.4,0.25,0.2),(0.1,0.6,0.1)],leftUrl=["mountns.png","https://www.web3d.org/x3d/content/examples/Vrml2Sourcebook/mountns.png"],rightUrl=["mountns.png","https://www.web3d.org/x3d/content/examples/Vrml2Sourcebook/mountns.png"],skyAngle=[1.309,1.571],skyColor=[(0,0.2,0.7),(0,0.5,1),(1,1,1)]),
    Viewpoint(description='Extruded ship hull and deck',orientation=(0,1,0,0.4),position=(20,10,100)),
    Viewpoint(description='High up',orientation=(0,1,0,0.4),position=(40,50,250)),
    Viewpoint(description='Bridge',orientation=(0,1,0,0.4),position=(10,10,40)),
    Viewpoint(description='Heli deck view',orientation=(0,1,0,-1.2),position=(-120,10,30)),
    Comment(' The helicopter hagar '),
    Transform(rotation=(0,0,1,0.2),translation=(0,-2,0)),
    Transform(scale=(3,3,3),translation=(-25,26,10),
      children=[
      Inline(url=["hoistgreekflag.x3d","https://www.web3d.org/x3d/content/examples/Savage/ShipsMilitary/FrigateGreece/hoistgreekflag.x3d","hoistgreekflag.wrl","https://www.web3d.org/x3d/content/examples/Savage/ShipsMilitary/FrigateGreece/hoistgreekflag.wrl"])]),
    Transform(rotation=(1,0,0,0.3),scale=(3,3,3),translation=(9,-3,8),
      children=[
      Transform(rotation=(0,1,0,0.3),
        children=[
        Inline(url=["textF459.x3d","https://www.web3d.org/x3d/content/examples/Savage/ShipsMilitary/FrigateGreece/textF459.x3d","textF459.wrl","https://www.web3d.org/x3d/content/examples/Savage/ShipsMilitary/FrigateGreece/textF459.wrl"])])]),
    Transform(rotation=(1,0,0,-1.2),scale=(2,2,2),translation=(-23,4,14.5),
      children=[
      Inline(url=["harpoon.x3d","https://www.web3d.org/x3d/content/examples/Savage/ShipsMilitary/FrigateGreece/harpoon.x3d","harpoon.wrl","https://www.web3d.org/x3d/content/examples/Savage/ShipsMilitary/FrigateGreece/harpoon.wrl"])]),
    Transform(rotation=(1,0,0,1.2),scale=(2,2,2),translation=(-25,5,-14),
      children=[
      Inline(url=["harpoon.x3d","https://www.web3d.org/x3d/content/examples/Savage/ShipsMilitary/FrigateGreece/harpoon.x3d","harpoon.wrl","https://www.web3d.org/x3d/content/examples/Savage/ShipsMilitary/FrigateGreece/harpoon.wrl"])]),
    Transform(scale=(1,2,1),translation=(-25,15,0),
      children=[
      Inline(url=["flagMast.x3d","https://www.web3d.org/x3d/content/examples/Savage/ShipsMilitary/FrigateGreece/flagMast.x3d","flagMast.wrl","https://www.web3d.org/x3d/content/examples/Savage/ShipsMilitary/FrigateGreece/flagMast.wrl"])]),
    Transform(rotation=(1,0,0,-0.2),scale=(1.5,1.5,1.5),translation=(-20.5,4,-14),
      children=[
      Inline(url=["hoistPort.x3d","https://www.web3d.org/x3d/content/examples/Savage/ShipsMilitary/FrigateGreece/hoistPort.x3d","hoistPort.wrl","https://www.web3d.org/x3d/content/examples/Savage/ShipsMilitary/FrigateGreece/hoistPort.wrl"])]),
    Transform(rotation=(1,0,0,0.2),scale=(1.5,1.5,1.5),translation=(-20.5,3,10),
      children=[
      Inline(url=["hoist.x3d","https://www.web3d.org/x3d/content/examples/Savage/ShipsMilitary/FrigateGreece/hoist.x3d","hoist.wrl","https://www.web3d.org/x3d/content/examples/Savage/ShipsMilitary/FrigateGreece/hoist.wrl"])]),
    Transform(rotation=(0,1,0,-1.57),scale=(1,1,1.5),translation=(-30,10,0),
      children=[
      Inline(url=["funel.x3d","https://www.web3d.org/x3d/content/examples/Savage/ShipsMilitary/FrigateGreece/funel.x3d","funel.wrl","https://www.web3d.org/x3d/content/examples/Savage/ShipsMilitary/FrigateGreece/funel.wrl"])]),
    Transform(scale=(3,3,3),translation=(-5,30,0),
      children=[
      Inline(url=["zw06.x3d","https://www.web3d.org/x3d/content/examples/Savage/ShipsMilitary/FrigateGreece/zw06.x3d","zw06.wrl","https://www.web3d.org/x3d/content/examples/Savage/ShipsMilitary/FrigateGreece/zw06.wrl"])]),
    Transform(scale=(2,2,2),translation=(-17.9,42,0),
      children=[
      Inline(url=["wm25.x3d","https://www.web3d.org/x3d/content/examples/Savage/ShipsMilitary/FrigateGreece/wm25.x3d","wm25.wrl","https://www.web3d.org/x3d/content/examples/Savage/ShipsMilitary/FrigateGreece/wm25.wrl"])]),
    Comment(' The sailors in the hangar '),
    Transform(scale=(1,2,1),translation=(-82,1,-3),
      children=[
      Inline(url=["sailors.x3d","https://www.web3d.org/x3d/content/examples/Savage/ShipsMilitary/FrigateGreece/sailors.x3d","sailors.wrl","https://www.web3d.org/x3d/content/examples/Savage/ShipsMilitary/FrigateGreece/sailors.wrl"])]),
    Transform(scale=(1,1.5,1.2),translation=(-81,1,4),
      children=[
      Inline(url=["sailors.x3d","https://www.web3d.org/x3d/content/examples/Savage/ShipsMilitary/FrigateGreece/sailors.x3d","sailors.wrl","https://www.web3d.org/x3d/content/examples/Savage/ShipsMilitary/FrigateGreece/sailors.wrl"])]),
    Transform(scale=(1,2,1),translation=(-80,1,3),
      children=[
      Inline(url=["sailors.x3d","https://www.web3d.org/x3d/content/examples/Savage/ShipsMilitary/FrigateGreece/sailors.x3d","sailors.wrl","https://www.web3d.org/x3d/content/examples/Savage/ShipsMilitary/FrigateGreece/sailors.wrl"])]),
    Transform(scale=(1,2,1),translation=(-80,1,0),
      children=[
      Inline(url=["Sailors.x3d","https://www.web3d.org/x3d/content/examples/Savage/ShipsMilitary/FrigateGreece/Sailors.x3d","Sailors.wrl","https://www.web3d.org/x3d/content/examples/Savage/ShipsMilitary/FrigateGreece/Sailors.wrl"])]),
    Comment(' the helicopter hagar '),
    Transform(rotation=(0,1,0,-1.57),translation=(-65,3,0),
      children=[
      Inline(url=["helideck.x3d","https://www.web3d.org/x3d/content/examples/Savage/ShipsMilitary/FrigateGreece/helideck.x3d","helideck.wrl","https://www.web3d.org/x3d/content/examples/Savage/ShipsMilitary/FrigateGreece/helideck.wrl"])]),
    Comment(' The main hull of the ship '),
    Transform(
      children=[
      Inline(url=["hull.x3d","https://www.web3d.org/x3d/content/examples/Savage/ShipsMilitary/FrigateGreece/hull.x3d","hull.wrl","https://www.web3d.org/x3d/content/examples/Savage/ShipsMilitary/FrigateGreece/hull.wrl"])]),
    Transform(scale=(2,2,2),translation=(15,5,0),
      children=[
      Inline(url=["OtoMelara.x3d","https://www.web3d.org/x3d/content/examples/Savage/ShipsMilitary/FrigateGreece/OtoMelara.x3d","OtoMelara.wrl","https://www.web3d.org/x3d/content/examples/Savage/ShipsMilitary/FrigateGreece/OtoMelara.wrl"])]),
    Transform(rotation=(0,1,0,3.14),scale=(2,2,2),translation=(-100,15,0),
      children=[
      Inline(url=["Otomelara.x3d","https://www.web3d.org/x3d/content/examples/Savage/ShipsMilitary/FrigateGreece/Otomelara.x3d","Otomelara.wrl","https://www.web3d.org/x3d/content/examples/Savage/ShipsMilitary/FrigateGreece/Otomelara.wrl"])]),
    Transform(scale=(3,3,3),translation=(-70,16,0),
      children=[
      Inline(url=["AirRadarLW08.x3d","https://www.web3d.org/x3d/content/examples/Savage/ShipsMilitary/FrigateGreece/AirRadarLW08.x3d","AirRadarLW08.wrl","https://www.web3d.org/x3d/content/examples/Savage/ShipsMilitary/FrigateGreece/AirRadarLW08.wrl"]),
      Transform(translation=(0,-1.8,0),
        children=[
        Shape(
          geometry=Cylinder(height=1),
          appearance=Appearance(
            material=Material(),))])]),
    Transform(rotation=(0,1,0,1.57),translation=(-25,5,0),
      children=[
      Inline(url=["OfficersMess.x3d","https://www.web3d.org/x3d/content/examples/Savage/ShipsMilitary/FrigateGreece/OfficersMess.x3d","OfficersMess.wrl","https://www.web3d.org/x3d/content/examples/Savage/ShipsMilitary/FrigateGreece/OfficersMess.wrl"])]),
    Transform(rotation=(0,1,0,1.57),translation=(-20,10,0),
      children=[
      Inline(url=["CommandOfficerRoom.x3d","https://www.web3d.org/x3d/content/examples/Savage/ShipsMilitary/FrigateGreece/CommandOfficerRoom.x3d","CommandOfficerRoom.wrl","https://www.web3d.org/x3d/content/examples/Savage/ShipsMilitary/FrigateGreece/CommandOfficerRoom.wrl"])]),
    Transform(rotation=(0,1,0,1.57),scale=(0.8,1,1),translation=(-11,18,0),
      children=[
      Inline(url=["Bridge.x3d","https://www.web3d.org/x3d/content/examples/Savage/ShipsMilitary/FrigateGreece/Bridge.x3d","Bridge.wrl","https://www.web3d.org/x3d/content/examples/Savage/ShipsMilitary/FrigateGreece/Bridge.wrl"])]),
    Transform(scale=(0.2,0.9,0.2),translation=(-41,25,0),
      children=[
      Inline(url=["Pyramid.x3d","https://www.web3d.org/x3d/content/examples/Savage/ShipsMilitary/FrigateGreece/Pyramid.x3d","Pyramid.wrl","https://www.web3d.org/x3d/content/examples/Savage/ShipsMilitary/FrigateGreece/Pyramid.wrl"])]),
    Transform(scale=(0.6,1.2,0.6),translation=(-18,15,0),
      children=[
      Inline(url=["Pyramid.x3d","https://www.web3d.org/x3d/content/examples/Savage/ShipsMilitary/FrigateGreece/Pyramid.x3d","Pyramid.wrl","https://www.web3d.org/x3d/content/examples/Savage/ShipsMilitary/FrigateGreece/Pyramid.wrl"])]),
    Transform(rotation=(0,1,0,1.57),scale=(1,4,1),translation=(-25,30,0),
      children=[
      Inline(url=["MainMast.x3d","https://www.web3d.org/x3d/content/examples/Savage/ShipsMilitary/FrigateGreece/MainMast.x3d","MainMast.wrl","https://www.web3d.org/x3d/content/examples/Savage/ShipsMilitary/FrigateGreece/MainMast.wrl"])])])
)

### X3D model conversion complete ###

####################################################################################################
# Self-test diagnostics
####################################################################################################

print('Self-test diagnostics for .py:')
if        metaDiagnostics(newModel): # built-in utility method in X3D class
    print(metaDiagnostics(newModel)) # display meta info, hint, warning, error, TODO values in this model
# print('check newModel.XML() serialization...')
newModelXML= newModel.XML() # test export method XML() for exceptions during export
newModel.XMLvalidate()
# print(newModelXML) # diagnostic

try:
#   print('check newModel.VRML() serialization...')
    newModelVRML=newModel.VRML() # test export method VRML() for exceptions during export
    # print(prependLineNumbers(newModelVRML)) # debug
    print("Python-to-VRML export of VRML output successful", flush=True)
except Exception as err: # usually BaseException
    # https://stackoverflow.com/questions/18176602/how-to-get-the-name-of-an-exception-that-was-caught-in-python
    print("*** Python-to-VRML export of VRML output failed:", type(err).__name__, err)
    if newModelVRML: # may have failed to generate
        print(prependLineNumbers(newModelVRML, err.lineno))

try:
#   print('check newModel.JSON() serialization...')
    newModelJSON=newModel.JSON() # test export method JSON() for exceptions during export
#   print(prependLineNumbers(newModelJSON)) # debug
    print("Python-to-JSON export of JSON output successful (under development)")
except Exception as err: # usually SyntaxError
    print("*** Python-to-JSON export of JSON output failed:", type(err).__name__, err)
    if newModelJSON: # may have failed to generate
        print(prependLineNumbers(newModelJSON,err.lineno))

print("python .py load and self-test diagnostics complete.")
