####################################################################################################
#
# Invoking X3D model self-test:
#
#   $ python NavigationLights.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='Interchange',version='3.2',
  head=head(
    children=[
    meta(content='NavigationLights.x3d',name='title'),
    meta(content='Brazilian Naval Academy Training Ship',name='description'),
    meta(content='Claudio Coreixas',name='creator'),
    meta(content='20 October 2009',name='created'),
    meta(content='20 October 2019',name='modified'),
    meta(content='http://www.en.mar.mil.br',name='reference'),
    meta(content='ships parts',name='subject'),
    meta(content='https://www.web3d.org/x3d/content/examples/Savage/ShipsMilitary/PatrolCraftNavalAcademyBrazil/NavigationLights.x3d',name='identifier'),
    meta(content='X3D-Edit, https://www.web3d.org/x3d/tools/X3D-Edit',name='generator'),
    meta(content='../../license.html',name='license')]),
  Scene=Scene(
    children=[
    WorldInfo(title='NavigationLights.x3d'),
    Viewpoint(DEF='basic',description='basic view',position=(6,1.9,6)),
    NavigationInfo(headlight=False,type=["EXAMINE"]),
    Shape(DEF='stbSideLightGray',
      appearance=Appearance(
        material=Material(diffuseColor=(0.82,0.78,0.74))),
      geometry=IndexedFaceSet(DEF='stbSideLightGrayIFS',coordIndex=[1,12,11,0,-1,1,2,13,0,-1,2,3,13,-1,3,4,5,13,-1,5,6,13,-1,13,6,7,-1,13,7,8,9,-1,13,9,10,-1,13,10,11,0,-1],creaseAngle=1.5,solid=False,
        coord=Coordinate(DEF='stbSideLightGrayCOORD',point=[(5.9,1.9,1.001),(5.9,1.9,1.1),(6.1,1.9,1.1),(6.138,1.9,1.092),(6.171,1.9,1.071),(6.192,1.9,1.038),(6.2,1.9,1.001),(6.192,1.938,1.001),(6.171,1.971,1.001),(6.138,1.971,1.001),(6.100,1.971,1.001),(5.9,1.971,1.001),(5.9,1.971,1.1),(6.1,1.9,1.001)]))),
    Shape(DEF='stbSideLightBlack',
      appearance=Appearance(
        material=Material(diffuseColor=(0,0,0))),
      geometry=IndexedFaceSet(DEF='stbSideLightBlackIFS',coordIndex=[1,12,11,0,-1,1,2,13,0,-1,2,3,13,-1,3,4,5,13,-1,5,6,13,-1,13,6,7,-1,13,7,8,9,-1,13,9,10,-1,13,10,11,0,-1],creaseAngle=1.5,solid=False,
        coord=Coordinate(DEF='stbSideLightBlackCOORD',point=[(5.901,1.901,1.002),(5.901,1.901,1.100),(6.100,1.901,1.100),(6.138,1.901,1.092),(6.171,1.901,1.071),(6.192,1.901,1.038),(6.200,1.901,1.002),(6.192,1.938,1.002),(6.171,1.971,1.002),(6.138,1.971,1.002),(6.100,1.971,1.002),(5.901,1.971,1.002),(5.901,1.971,1.100),(6.100,1.901,1.002)]))),
    Shape(DEF='stbSideLightBulbDome',
      appearance=Appearance(
        material=Material(ambientIntensity=0.04,diffuseColor=(0,0.419608,0.094118),shininess=0.09)),
      geometry=IndexedFaceSet(DEF='stbSideLightBulbDomeIFS',coordIndex=[0,1,15,-1,1,2,14,15,-1,2,3,13,14,-1,3,4,12,13,-1,4,5,11,12,-1,5,6,10,11,-1,6,7,9,10,-1,7,8,9,-1,16,17,31,-1,17,18,30,31,-1,18,19,29,30,-1,19,20,28,29,-1,20,21,27,28,-1,21,22,26,27,-1,22,23,25,26,-1,23,24,25,-1,33,36,42,32,-1,41,34,35,47,-1,0,16,17,1,-1,1,17,18,2,-1,2,18,19,3,-1,3,19,20,4,-1,4,20,21,5,-1,5,21,22,6,-1,6,22,23,7,-1,7,23,24,8,-1,8,24,25,9,-1,9,25,26,10,-1,10,26,27,11,-1,11,41,40,12,-1,12,40,39,13,-1,13,39,38,14,-1,14,38,37,15,-1,15,37,36,0,-1,47,27,28,46,-1,46,28,29,45,-1,45,29,30,44,-1,44,30,31,43,-1,43,31,0,42,-1],creaseAngle=1.5,solid=False,
        coord=Coordinate(DEF='stbSideLightBulbDomeCOORD',point=[(6.010,1.98,1.050),(6.007,1.98,1.035),(5.998,1.98,1.022),(5.985,1.98,1.013),(5.970,1.98,1.010),(5.955,1.98,1.013),(5.942,1.98,1.022),(5.933,1.98,1.035),(5.930,1.98,1.050),(5.933,1.98,1.065),(5.942,1.98,1.078),(5.955,1.98,1.087),(5.970,1.98,1.090),(5.985,1.98,1.087),(5.998,1.98,1.078),(6.007,1.98,1.065),(6.01,1.901,1.05),(6.007,1.901,1.03470002),(5.998,1.901,1.021726993),(5.985,1.901,1.013053968),(5.970,1.901,1.010000013),(5.955,1.901,1.0130296),(5.942,1.901,1.021681964),(5.933,1.901,1.034641178),(5.930,1.901,1.049936294),(5.933,1.901,1.065241099),(5.942,1.901,1.078227906),(5.955,1.901,1.086921571),(5.970,1.901,1.089999886),(5.985,1.901,1.086994674),(5.998,1.901,1.078362994),(6.007,1.901,1.065417625),(6.025,1.915,1.05),(6.025,1.965,1.05),(5.948841186,1.965,1.10076716),(5.948841186,1.915,1.10076716),(6.01,1.965,1.05),(6.006909305,1.965,1.065417625),(5.998205329,1.965,1.078362994),(5.985211644,1.965,1.086994674),(5.969904441,1.965,1.089999886),(5.954611771,1.965,1.086921571),(6.01,1.915,1.05),(6.006909305,1.915,1.065417625),(5.998205329,1.915,1.078362994),(5.985211644,1.915,1.086994674),(5.969904441,1.915,1.089999886),(5.954611771,1.915,1.086921571)]))),
    Shape(DEF='stbSideLightBulbGlass',
      appearance=Appearance(
        material=Material(ambientIntensity=1,diffuseColor=(0.062745,0.780392,0),emissiveColor=(0.101961,0.6,0),shininess=0.46)),
      geometry=IndexedFaceSet(DEF='stbSideLightBulbGlassIFS',coordIndex=[41,47,46,40,-1,40,46,45,39,-1,39,45,44,38,-1,38,44,43,37,-1,37,43,42,36,-1],creaseAngle=1.5,solid=False,
        coord=Coordinate(DEF='stbSideLightBulbGlassCOORD',point=[(6.010,1.98,1.050),(6.007,1.98,1.035),(5.998,1.98,1.022),(5.985,1.98,1.013),(5.970,1.98,1.010),(5.955,1.98,1.013),(5.942,1.98,1.022),(5.933,1.98,1.035),(5.930,1.98,1.050),(5.933,1.98,1.065),(5.942,1.98,1.078),(5.955,1.98,1.087),(5.970,1.98,1.090),(5.985,1.98,1.087),(5.998,1.98,1.078),(6.007,1.98,1.065),(6.01,1.901,1.05),(6.007,1.901,1.03470002),(5.998,1.901,1.021726993),(5.985,1.901,1.013053968),(5.970,1.901,1.010000013),(5.955,1.901,1.0130296),(5.942,1.901,1.021681964),(5.933,1.901,1.034641178),(5.930,1.901,1.049936294),(5.933,1.901,1.065241099),(5.942,1.901,1.078227906),(5.955,1.901,1.086921571),(5.970,1.901,1.089999886),(5.985,1.901,1.086994674),(5.998,1.901,1.078362994),(6.007,1.901,1.065417625),(6.025,1.915,1.05),(6.025,1.965,1.05),(5.948841186,1.965,1.10076716),(5.948841186,1.915,1.10076716),(6.01,1.965,1.05),(6.006909305,1.965,1.065417625),(5.998205329,1.965,1.078362994),(5.985211644,1.965,1.086994674),(5.969904441,1.965,1.089999886),(5.954611771,1.965,1.086921571),(6.01,1.915,1.05),(6.006909305,1.915,1.065417625),(5.998205329,1.915,1.078362994),(5.985211644,1.915,1.086994674),(5.969904441,1.915,1.089999886),(5.954611771,1.915,1.086921571),(0,0,0)]))),
    Shape(DEF='portSideLightGray',
      appearance=Appearance(
        material=Material(diffuseColor=(0.82,0.78,0.74))),
      geometry=IndexedFaceSet(DEF='portSideLightGrayIFS',coordIndex=[1,12,11,0,-1,1,2,13,0,-1,2,3,13,-1,3,4,5,13,-1,5,6,13,-1,13,6,7,-1,13,7,8,9,-1,13,9,10,-1,13,10,11,0,-1],creaseAngle=1.5,solid=False,
        coord=Coordinate(DEF='portSideLightGrayCOORD',point=[(5.900,1.900,-1.001),(5.900,1.900,-1.100),(6.100,1.900,-1.100),(6.138,1.900,-1.092),(6.171,1.900,-1.071),(6.192,1.900,-1.038),(6.200,1.900,-1.001),(6.192,1.938,-1.001),(6.171,1.971,-1.001),(6.138,1.971,-1.001),(6.100,1.971,-1.001),(5.900,1.971,-1.001),(5.900,1.971,-1.100),(6.100,1.900,-1.001)]))),
    Shape(DEF='portSideLightBlack',
      appearance=Appearance(
        material=Material(diffuseColor=(0,0,0))),
      geometry=IndexedFaceSet(DEF='portSideLightBlackIFS',coordIndex=[1,12,11,0,-1,1,2,13,0,-1,2,3,13,-1,3,4,5,13,-1,5,6,13,-1,13,6,7,-1,13,7,8,9,-1,13,9,10,-1,13,10,11,0,-1],creaseAngle=1.5,solid=False,
        coord=Coordinate(DEF='portSideLightBlackCOORD',point=[(5.901,1.901,-1.002),(5.901,1.901,-1.100),(6.100,1.901,-1.100),(6.138,1.901,-1.092),(6.171,1.901,-1.071),(6.192,1.901,-1.038),(6.200,1.901,-1.002),(6.192,1.938,-1.002),(6.171,1.971,-1.002),(6.138,1.971,-1.002),(6.100,1.971,-1.002),(5.901,1.971,-1.002),(5.901,1.971,-1.100),(6.100,1.901,-1.002)]))),
    Shape(DEF='portSideLightBulbDome',
      appearance=Appearance(
        material=Material(ambientIntensity=0.04,diffuseColor=(0.639216,0,0.039216),shininess=0.09)),
      geometry=IndexedFaceSet(DEF='portSideLightBulbDomeIFS',coordIndex=[0,1,15,-1,1,2,14,15,-1,2,3,13,14,-1,3,4,12,13,-1,4,5,11,12,-1,5,6,10,11,-1,6,7,9,10,-1,7,8,9,-1,16,17,31,-1,17,18,30,31,-1,18,19,29,30,-1,19,20,28,29,-1,20,21,27,28,-1,21,22,26,27,-1,22,23,25,26,-1,23,24,25,-1,33,36,42,32,-1,41,34,35,47,-1,0,16,17,1,-1,1,17,18,2,-1,2,18,19,3,-1,3,19,20,4,-1,4,20,21,5,-1,5,21,22,6,-1,6,22,23,7,-1,7,23,24,8,-1,8,24,25,9,-1,9,25,26,10,-1,10,26,27,11,-1,11,41,40,12,-1,12,40,39,13,-1,13,39,38,14,-1,14,38,37,15,-1,15,37,36,0,-1,47,27,28,46,-1,46,28,29,45,-1,45,29,30,44,-1,44,30,31,43,-1,43,31,0,42,-1],creaseAngle=1.5,solid=False,
        coord=Coordinate(DEF='portSideLightBulbDomeCOORD',point=[(6.010,1.980,-1.050),(6.007,1.980,-1.035),(5.998,1.980,-1.022),(5.985,1.980,-1.013),(5.970,1.980,-1.010),(5.955,1.980,-1.013),(5.942,1.980,-1.022),(5.933,1.980,-1.035),(5.930,1.980,-1.050),(5.933,1.980,-1.065),(5.942,1.980,-1.078),(5.955,1.980,-1.087),(5.970,1.980,-1.090),(5.985,1.980,-1.087),(5.998,1.980,-1.078),(6.007,1.980,-1.065),(6.010,1.901,-1.050),(6.007,1.901,-1.035),(5.998,1.901,-1.022),(5.985,1.901,-1.013),(5.970,1.901,-1.010),(5.955,1.901,-1.013),(5.942,1.901,-1.022),(5.933,1.901,-1.035),(5.930,1.901,-1.050),(5.933,1.901,-1.065),(5.942,1.901,-1.078),(5.955,1.901,-1.087),(5.970,1.901,-1.090),(5.985,1.901,-1.087),(5.998,1.901,-1.078),(6.007,1.901,-1.065),(6.025,1.915,-1.050),(6.025,1.965,-1.050),(5.949,1.965,-1.101),(5.949,1.915,-1.101),(6.010,1.965,-1.050),(6.007,1.965,-1.065),(5.998,1.965,-1.078),(5.985,1.965,-1.087),(5.970,1.965,-1.090),(5.955,1.965,-1.087),(6.010,1.915,-1.050),(6.007,1.915,-1.065),(5.998,1.915,-1.078),(5.985,1.915,-1.087),(5.970,1.915,-1.090),(5.955,1.915,-1.087)]))),
    Shape(DEF='portSideLightBulbGlass',
      appearance=Appearance(
        material=Material(ambientIntensity=1,diffuseColor=(1,0.12549,0.101961),emissiveColor=(1,0.121569,0.121569),shininess=0.58,transparency=0.13)),
      geometry=IndexedFaceSet(DEF='portSideLightBulbGlassIFS',coordIndex=[41,47,46,40,-1,40,46,45,39,-1,39,45,44,38,-1,38,44,43,37,-1,37,43,42,36,-1],creaseAngle=1.5,solid=False,
        coord=Coordinate(DEF='portSideLightBulbGlassCOORD',point=[(6.010,1.980,-1.050),(6.007,1.980,-1.035),(5.998,1.980,-1.022),(5.985,1.980,-1.013),(5.970,1.980,-1.010),(5.955,1.980,-1.013),(5.942,1.980,-1.022),(5.933,1.980,-1.035),(5.930,1.980,-1.050),(5.933,1.980,-1.065),(5.942,1.980,-1.078),(5.955,1.980,-1.087),(5.970,1.980,-1.090),(5.985,1.980,-1.087),(5.998,1.980,-1.078),(6.007,1.980,-1.065),(6.010,1.901,-1.050),(6.007,1.901,-1.035),(5.998,1.901,-1.022),(5.985,1.901,-1.013),(5.970,1.901,-1.010),(5.955,1.901,-1.013),(5.942,1.901,-1.022),(5.933,1.901,-1.035),(5.930,1.901,-1.050),(5.933,1.901,-1.065),(5.942,1.901,-1.078),(5.955,1.901,-1.087),(5.970,1.901,-1.090),(5.985,1.901,-1.087),(5.998,1.901,-1.078),(6.007,1.901,-1.065),(6.025,1.915,-1.050),(6.025,1.965,-1.050),(5.949,1.965,-1.101),(5.949,1.915,-1.101),(6.010,1.965,-1.050),(6.007,1.965,-1.065),(5.998,1.965,-1.078),(5.985,1.965,-1.087),(5.970,1.965,-1.090),(5.955,1.965,-1.087),(6.010,1.915,-1.050),(6.007,1.915,-1.065),(5.998,1.915,-1.078),(5.985,1.915,-1.087),(5.970,1.915,-1.090),(5.955,1.915,-1.087),(0,0,0)])))])
)

### X3D model conversion complete ###

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

print('Self-test diagnostics for NavigationLights.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 NavigationLights.py load and self-test diagnostics complete.")
