####################################################################################################
#
# Invoking X3D model self-test:
#
#   $ python Seven.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.1',
  head=head(
    children=[
    meta(content='Seven.x3d',name='title'),
    meta(content='3D Hull Number',name='description'),
    meta(content='Patrick Sullivan',name='creator'),
    meta(content='20 February 2006',name='created'),
    meta(content='20 October 2019',name='modified'),
    meta(content='1.0',name='version'),
    meta(content='Hull Numbers, ship markings',name='subject'),
    meta(content='https://www.web3d.org/x3d/content/examples/Savage/ModelDetailing/HullNumbers/Seven.x3d',name='identifier'),
    meta(content='../../license.html',name='license')]),
  Scene=Scene(
    children=[
    WorldInfo(title='Seven.x3d'),
    Group(DEF='Seven',
      children=[
      Transform(DEF='dad_HullNumber7_copy18',
        children=[
        Shape(DEF='HullNumber7_copy18',
          appearance=Appearance(
            material=Material(DEF='white2_mat',ambientIntensity=1,diffuseColor=(1,1,1),shininess=0,specularColor=(1,1,1))),
          geometry=IndexedFaceSet(coordIndex=[0,1,2,-1,0,2,3,-1,0,3,4,-1,0,4,5,-1,0,5,6,-1,0,6,1,-1,1,7,2,-1,1,6,8,-1,1,8,7,-1,7,8,9,-1,7,9,2,-1,2,10,3,-1,2,9,11,-1,2,11,10,-1,10,12,13,-1,10,13,14,-1,10,14,15,-1,10,15,16,-1,10,16,17,-1,10,17,18,-1,10,18,3,-1,10,11,19,-1,10,19,12,-1,12,20,21,-1,12,21,13,-1,12,19,22,-1,12,22,20,-1,20,23,24,-1,20,24,21,-1,20,22,25,-1,20,25,23,-1,23,26,27,-1,23,27,28,-1,23,28,24,-1,23,25,29,-1,23,29,26,-1,26,29,30,-1,26,30,27,-1,27,30,31,-1,27,31,28,-1,28,31,32,-1,28,32,24,-1,24,32,33,-1,24,33,21,-1,21,33,34,-1,21,34,13,-1,13,34,35,-1,13,35,14,-1,14,35,36,-1,14,36,15,-1,15,36,37,-1,15,37,16,-1,16,37,38,-1,16,38,17,-1,17,38,39,-1,17,39,18,-1,18,39,4,-1,18,4,3,-1,5,4,9,-1,5,9,6,-1,6,9,8,-1,9,4,11,-1,11,35,34,-1,11,34,19,-1,11,36,35,-1,11,38,37,-1,11,37,36,-1,11,4,39,-1,11,39,38,-1,19,34,33,-1,19,33,22,-1,22,33,32,-1,22,32,25,-1,25,30,29,-1,25,32,31,-1,25,31,30,-1],creaseAngle=0.524,
            coord=Coordinate(point=[(-.63488,1.44957,-.04102),(-.63488,1.2816,-.04102),(-.28136,1.11363,-.04102),(-.05431,1.44957,-.04102),(-.06434,1.44639,-.2),(-.6449,1.44639,-.2),(-.6449,1.27842,-.2),(-.63488,1.11363,-.04102),(-.6449,1.11045,-.2),(-.29139,1.11045,-.2),(.07215,1.11363,-.04102),(.06213,1.11045,-.2),(-.11633,.85142,-.04102),(.16322,.68077,-.04102),(.27332,.88512,-.04102),(.38734,1.03868,-.04102),(.52625,1.18101,-.04102),(.52625,1.31529,-.04102),(.52625,1.44957,-.04102),(-.12635,.84824,-.2),(-.24621,.60582,-.04102),(.07899,.45445,-.04102),(-.25623,.60264,-.2),(-.33337,.3402,-.04102),(.03162,.25304,-.04102),(-.34339,.33701,-.2),(-.39367,.01793,-.04102),(-.19543,.01793,-.04102),(.00282,.01793,-.04102),(-.40369,.01475,-.2),(-.20545,.01475,-.2),(-.00721,.01475,-.2),(.0216,.24985,-.2),(.06897,.45127,-.2),(.15319,.67759,-.2),(.2633,.88193,-.2),(.37732,1.0355,-.2),(.51623,1.17783,-.2),(.51623,1.31211,-.2),(.51623,1.44639,-.2)])))]),
      Transform(DEF='dad_HullNumber7',
        children=[
        Shape(DEF='HullNumber7',
          appearance=Appearance(
            material=Material(DEF='main_mat',ambientIntensity=0.001,diffuseColor=(.001,.001,.001),shininess=0,specularColor=(.001,.001,.001))),
          geometry=IndexedFaceSet(coordIndex=[0,1,2,-1,0,2,3,-1,0,3,4,-1,0,4,5,-1,0,5,6,-1,0,6,1,-1,1,7,2,-1,1,6,8,-1,1,8,7,-1,7,8,9,-1,7,9,2,-1,2,10,3,-1,2,9,11,-1,2,11,10,-1,10,12,13,-1,10,13,14,-1,10,14,15,-1,10,15,16,-1,10,16,17,-1,10,17,18,-1,10,18,3,-1,10,11,19,-1,10,19,12,-1,12,20,21,-1,12,21,13,-1,12,19,22,-1,12,22,20,-1,20,23,24,-1,20,24,21,-1,20,22,25,-1,20,25,23,-1,23,26,27,-1,23,27,28,-1,23,28,24,-1,23,25,29,-1,23,29,26,-1,26,29,30,-1,26,30,27,-1,27,30,31,-1,27,31,28,-1,28,31,32,-1,28,32,24,-1,24,32,33,-1,24,33,21,-1,21,33,34,-1,21,34,13,-1,13,34,35,-1,13,35,14,-1,14,35,36,-1,14,36,15,-1,15,36,37,-1,15,37,16,-1,16,37,38,-1,16,38,17,-1,17,38,39,-1,17,39,18,-1,18,39,4,-1,18,4,3,-1,5,4,9,-1,5,9,6,-1,6,9,8,-1,9,4,11,-1,11,35,34,-1,11,34,19,-1,11,36,35,-1,11,38,37,-1,11,37,36,-1,11,4,39,-1,11,39,38,-1,19,34,33,-1,19,33,22,-1,22,33,32,-1,22,32,25,-1,25,30,29,-1,25,32,31,-1,25,31,30,-1],creaseAngle=0.524,
            coord=Coordinate(point=[(-.48952,1.43482,-.08798),(-.48952,1.26686,-.08798),(-.136,1.09889,-.08798),(.09105,1.43482,-.08798),(.08103,1.43164,-.24696),(-.49954,1.43164,-.24696),(-.49954,1.26367,-.24696),(-.48952,1.09889,-.08798),(-.49954,1.0957,-.24696),(-.14602,1.0957,-.24696),(.21751,1.09889,-.08798),(.20749,1.0957,-.24696),(.02904,.83668,-.08798),(.30858,.66602,-.08798),(.41868,.87037,-.08798),(.5327,1.02394,-.08798),(.67161,1.16627,-.08798),(.67161,1.30055,-.08798),(.67161,1.43482,-.08798),(.01901,.8335,-.24696),(-.10085,.59107,-.08798),(.22435,.43971,-.08798),(-.11087,.58789,-.24696),(-.18801,.32545,-.08798),(.17699,.23829,-.08798),(-.19803,.32227,-.24696),(-.24831,.00318,-.08798),(-.05007,.00318,-.08798),(.14818,.00318,-.08798),(-.25833,0,-.24696),(-.06009,0,-.24696),(.13816,0,-.24696),(.16696,.23511,-.24696),(.21433,.43652,-.24696),(.29856,.66284,-.24696),(.40866,.86719,-.24696),(.52268,1.02075,-.24696),(.66159,1.16309,-.24696),(.66159,1.29736,-.24696),(.66159,1.43164,-.24696)])))])])])
)

### X3D model conversion complete ###

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

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