####################################################################################################
#
# Invoking X3D model self-test:
#
#   $ python Five.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='Five.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/Five.x3d',name='identifier'),
    meta(content='../../license.html',name='license')]),
  Scene=Scene(
    children=[
    WorldInfo(title='Five.x3d'),
    Group(DEF='Five',
      children=[
      Transform(DEF='dad_HullNumber5_copy16',
        children=[
        Shape(DEF='HullNumber5_copy16',
          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,7,-1,0,7,8,-1,0,8,1,-1,1,9,10,-1,1,10,11,-1,1,11,12,-1,1,12,2,-1,1,8,13,-1,1,13,9,-1,9,13,14,-1,9,14,10,-1,10,15,11,-1,10,14,16,-1,10,16,15,-1,15,16,17,-1,15,17,11,-1,11,18,12,-1,11,17,19,-1,11,19,18,-1,18,20,21,-1,18,21,12,-1,18,19,22,-1,18,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,24,-1,23,25,28,-1,23,28,26,-1,26,29,30,-1,26,30,31,-1,26,31,27,-1,26,28,32,-1,26,32,29,-1,29,33,34,-1,29,34,35,-1,29,35,30,-1,29,32,36,-1,29,36,33,-1,33,37,38,-1,33,38,34,-1,33,36,39,-1,33,39,37,-1,37,40,41,-1,37,41,42,-1,37,42,38,-1,37,39,43,-1,37,43,40,-1,40,44,45,-1,40,45,41,-1,40,43,46,-1,40,46,44,-1,44,47,48,-1,44,48,49,-1,44,49,45,-1,44,46,50,-1,44,50,47,-1,47,51,52,-1,47,52,48,-1,47,50,53,-1,47,53,51,-1,51,54,55,-1,51,55,52,-1,51,53,56,-1,51,56,54,-1,54,57,58,-1,54,58,59,-1,54,59,55,-1,54,56,60,-1,54,60,57,-1,57,61,62,-1,57,62,58,-1,57,60,63,-1,57,63,61,-1,61,64,65,-1,61,65,66,-1,61,66,62,-1,61,63,67,-1,61,67,64,-1,64,67,68,-1,64,68,65,-1,65,69,70,-1,65,70,71,-1,65,71,66,-1,65,68,72,-1,65,72,69,-1,69,72,73,-1,69,73,70,-1,70,73,74,-1,70,74,71,-1,71,74,75,-1,71,75,66,-1,66,75,76,-1,66,76,62,-1,62,76,77,-1,62,77,58,-1,58,77,78,-1,58,78,59,-1,59,78,79,-1,59,79,55,-1,55,79,80,-1,55,80,52,-1,52,80,81,-1,52,81,48,-1,48,81,82,-1,48,82,49,-1,49,82,83,-1,49,83,45,-1,45,83,84,-1,45,84,41,-1,41,84,85,-1,41,85,42,-1,42,85,86,-1,42,86,38,-1,38,86,87,-1,38,87,34,-1,34,87,88,-1,34,88,35,-1,35,88,89,-1,35,89,30,-1,30,89,90,-1,30,90,31,-1,31,90,91,-1,31,91,27,-1,27,91,92,-1,27,92,24,-1,24,92,93,-1,24,93,21,-1,21,93,94,-1,21,94,12,-1,12,94,95,-1,12,95,2,-1,2,95,96,-1,2,96,3,-1,3,96,97,-1,3,97,4,-1,4,98,99,-1,4,99,100,-1,4,100,5,-1,4,97,101,-1,4,101,98,-1,98,101,102,-1,98,102,99,-1,99,102,103,-1,99,103,100,-1,100,103,6,-1,100,6,5,-1,7,96,95,-1,7,95,8,-1,7,6,97,-1,7,97,96,-1,8,14,13,-1,8,94,17,-1,8,17,14,-1,8,95,94,-1,14,17,16,-1,17,94,19,-1,19,94,93,-1,19,93,22,-1,22,93,92,-1,22,92,25,-1,25,92,91,-1,25,91,28,-1,28,90,89,-1,28,89,32,-1,28,91,90,-1,32,88,87,-1,32,87,36,-1,32,89,88,-1,36,87,86,-1,36,86,39,-1,39,85,84,-1,39,84,43,-1,39,86,85,-1,43,84,83,-1,43,83,46,-1,46,82,81,-1,46,81,50,-1,46,83,82,-1,50,81,80,-1,50,80,53,-1,53,80,79,-1,53,79,56,-1,56,78,77,-1,56,77,60,-1,56,79,78,-1,60,77,76,-1,60,76,63,-1,63,68,67,-1,63,76,75,-1,63,75,68,-1,68,73,72,-1,68,75,74,-1,68,74,73,-1,97,102,101,-1,97,6,103,-1,97,103,102,-1],creaseAngle=0.524,
            coord=Coordinate(point=[(-.53492,1.44957,-.04102),(-.59791,1.0648,-.04102),(-.24732,1.02476,-.04102),(-.23023,1.13219,-.04102),(.08959,1.13219,-.04102),(-.06275,1.44957,-.04102),(-.07278,1.44639,-.2),(-.54494,1.44639,-.2),(-.60793,1.06162,-.2),(-.6609,.68004,-.04102),(-.49146,.65562,-.04102),(-.27613,.67662,-.04102),(-.26441,.91734,-.04102),(-.67092,.67685,-.2),(-.50149,.65244,-.2),(-.32203,.63121,-.04102),(-.33205,.62803,-.2),(-.28615,.67344,-.2),(-.23414,.70543,-.04102),(-.24416,.70225,-.2),(-.17945,.72667,-.04102),(-.19837,.94469,-.04102),(-.18947,.72349,-.2),(-.12281,.73375,-.04102),(-.13306,.96422,-.04102),(-.13283,.73057,-.2),(-.04102,.71886,-.04102),(-.06849,.97594,-.04102),(-.05105,.71567,-.2),(.0227,.67418,-.04102),(.18993,.94737,-.04102),(-.00465,.97984,-.04102),(.01267,.671,-.2),(.06371,.59752,-.04102),(.44433,.70323,-.04102),(.34398,.84996,-.04102),(.05369,.59433,-.2),(.07738,.48668,-.04102),(.47777,.52281,-.04102),(.06736,.4835,-.2),(.06383,.37718,-.04102),(.40893,.25621,-.04102),(.46056,.38682,-.04102),(.05381,.374,-.2),(.02318,.29869,-.04102),(.32567,.14342,-.04102),(.01316,.29551,-.2),(-.03822,.25145,-.04102),(.06945,.01036,-.04102),(.21361,.0609,-.04102),(-.04824,.24827,-.2),(-.11402,.2357,-.04102),(-.11012,-.00649,-.04102),(-.12405,.23252,-.2),(-.18311,.24828,-.04102),(-.24159,.00023,-.04102),(-.19314,.24509,-.2),(-.24195,.286,-.04102),(-.4463,.05382,-.04102),(-.35279,.02037,-.04102),(-.25197,.28281,-.2),(-.2859,.34789,-.04102),(-.52467,.10045,-.04102),(-.29592,.3447,-.2),(-.31031,.43297,-.04102),(-.51148,.411,-.04102),(-.58875,.15721,-.04102),(-.32033,.42978,-.2),(-.52151,.40781,-.2),(-.71266,.38902,-.04102),(-.6797,.29674,-.04102),(-.63941,.22105,-.04102),(-.72268,.38584,-.2),(-.68972,.29355,-.2),(-.64943,.21787,-.2),(-.59878,.15403,-.2),(-.53469,.09727,-.2),(-.45632,.05063,-.2),(-.36281,.01719,-.2),(-.25161,-.00295,-.2),(-.12014,-.00967,-.2),(.05943,.00718,-.2),(.20359,.05771,-.2),(.31565,.14023,-.2),(.39891,.25303,-.2),(.45054,.38364,-.2),(.46775,.51963,-.2),(.43431,.70005,-.2),(.33396,.84678,-.2),(.17991,.94419,-.2),(-.01467,.97666,-.2),(-.07851,.97275,-.2),(-.14309,.96103,-.2),(-.2084,.9415,-.2),(-.27443,.91416,-.2),(-.25734,1.02158,-.2),(-.24026,1.129,-.2),(.07957,1.129,-.2),(.40941,1.13219,-.04102),(.40941,1.29088,-.04102),(.40941,1.44957,-.04102),(.39939,1.129,-.2),(.39939,1.28769,-.2),(.39939,1.44639,-.2)])))]),
      Transform(DEF='dad_HullNumber5',
        children=[
        Shape(DEF='HullNumber5',
          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,7,-1,0,7,8,-1,0,8,1,-1,1,9,10,-1,1,10,11,-1,1,11,12,-1,1,12,2,-1,1,8,13,-1,1,13,9,-1,9,13,14,-1,9,14,10,-1,10,15,11,-1,10,14,16,-1,10,16,15,-1,15,16,17,-1,15,17,11,-1,11,18,12,-1,11,17,19,-1,11,19,18,-1,18,20,21,-1,18,21,12,-1,18,19,22,-1,18,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,24,-1,23,25,28,-1,23,28,26,-1,26,29,30,-1,26,30,31,-1,26,31,27,-1,26,28,32,-1,26,32,29,-1,29,33,34,-1,29,34,35,-1,29,35,30,-1,29,32,36,-1,29,36,33,-1,33,37,38,-1,33,38,34,-1,33,36,39,-1,33,39,37,-1,37,40,41,-1,37,41,42,-1,37,42,38,-1,37,39,43,-1,37,43,40,-1,40,44,45,-1,40,45,41,-1,40,43,46,-1,40,46,44,-1,44,47,48,-1,44,48,49,-1,44,49,45,-1,44,46,50,-1,44,50,47,-1,47,51,52,-1,47,52,48,-1,47,50,53,-1,47,53,51,-1,51,54,55,-1,51,55,52,-1,51,53,56,-1,51,56,54,-1,54,57,58,-1,54,58,59,-1,54,59,55,-1,54,56,60,-1,54,60,57,-1,57,61,62,-1,57,62,58,-1,57,60,63,-1,57,63,61,-1,61,64,65,-1,61,65,66,-1,61,66,62,-1,61,63,67,-1,61,67,64,-1,64,67,68,-1,64,68,65,-1,65,69,70,-1,65,70,71,-1,65,71,66,-1,65,68,72,-1,65,72,69,-1,69,72,73,-1,69,73,70,-1,70,73,74,-1,70,74,71,-1,71,74,75,-1,71,75,66,-1,66,75,76,-1,66,76,62,-1,62,76,77,-1,62,77,58,-1,58,77,78,-1,58,78,59,-1,59,78,79,-1,59,79,55,-1,55,79,80,-1,55,80,52,-1,52,80,81,-1,52,81,48,-1,48,81,82,-1,48,82,49,-1,49,82,83,-1,49,83,45,-1,45,83,84,-1,45,84,41,-1,41,84,85,-1,41,85,42,-1,42,85,86,-1,42,86,38,-1,38,86,87,-1,38,87,34,-1,34,87,88,-1,34,88,35,-1,35,88,89,-1,35,89,30,-1,30,89,90,-1,30,90,31,-1,31,90,91,-1,31,91,27,-1,27,91,92,-1,27,92,24,-1,24,92,93,-1,24,93,21,-1,21,93,94,-1,21,94,12,-1,12,94,95,-1,12,95,2,-1,2,95,96,-1,2,96,3,-1,3,96,97,-1,3,97,4,-1,4,98,99,-1,4,99,100,-1,4,100,5,-1,4,97,101,-1,4,101,98,-1,98,101,102,-1,98,102,99,-1,99,102,103,-1,99,103,100,-1,100,103,6,-1,100,6,5,-1,7,96,95,-1,7,95,8,-1,7,6,97,-1,7,97,96,-1,8,14,13,-1,8,94,17,-1,8,17,14,-1,8,95,94,-1,14,17,16,-1,17,94,19,-1,19,94,93,-1,19,93,22,-1,22,93,92,-1,22,92,25,-1,25,92,91,-1,25,91,28,-1,28,90,89,-1,28,89,32,-1,28,91,90,-1,32,88,87,-1,32,87,36,-1,32,89,88,-1,36,87,86,-1,36,86,39,-1,39,85,84,-1,39,84,43,-1,39,86,85,-1,43,84,83,-1,43,83,46,-1,46,82,81,-1,46,81,50,-1,46,83,82,-1,50,81,80,-1,50,80,53,-1,53,80,79,-1,53,79,56,-1,56,78,77,-1,56,77,60,-1,56,79,78,-1,60,77,76,-1,60,76,63,-1,63,68,67,-1,63,76,75,-1,63,75,68,-1,68,73,72,-1,68,75,74,-1,68,74,73,-1,97,102,101,-1,97,6,103,-1,97,103,102,-1],creaseAngle=0.524,
            coord=Coordinate(point=[(-.38956,1.43482,-.08798),(-.45255,1.05006,-.08798),(-.10196,1.01002,-.08798),(-.08487,1.11744,-.08798),(.23495,1.11744,-.08798),(.08261,1.43482,-.08798),(.07259,1.43164,-.24696),(-.39958,1.43164,-.24696),(-.46257,1.04688,-.24696),(-.51554,.66529,-.08798),(-.3461,.64088,-.08798),(-.13077,.66187,-.08798),(-.11905,.9026,-.08798),(-.52556,.66211,-.24696),(-.35613,.6377,-.24696),(-.17667,.61647,-.08798),(-.18669,.61328,-.24696),(-.14079,.65869,-.24696),(-.08878,.69068,-.08798),(-.0988,.6875,-.24696),(-.03409,.71192,-.08798),(-.05301,.92994,-.08798),(-.04411,.70874,-.24696),(.02255,.719,-.08798),(.0123,.94947,-.08798),(.01253,.71582,-.24696),(.10434,.70411,-.08798),(.07687,.96119,-.08798),(.09431,.70093,-.24696),(.16806,.65943,-.08798),(.33529,.93263,-.08798),(.14071,.9651,-.08798),(.15804,.65625,-.24696),(.20907,.58277,-.08798),(.58969,.68849,-.08798),(.48935,.83522,-.08798),(.19905,.57959,-.24696),(.22275,.47193,-.08798),(.62314,.50807,-.08798),(.21272,.46875,-.24696),(.20919,.36244,-.08798),(.55429,.24147,-.08798),(.60592,.37208,-.08798),(.19917,.35925,-.24696),(.16855,.28395,-.08798),(.47104,.12867,-.08798),(.15852,.28076,-.24696),(.10715,.2367,-.08798),(.21481,-.00438,-.08798),(.35898,.04615,-.08798),(.09712,.23352,-.24696),(.03134,.22096,-.08798),(.03525,-.02123,-.08798),(.02132,.21777,-.24696),(-.03775,.23353,-.08798),(-.09622,-.01452,-.08798),(-.04777,.23035,-.24696),(-.09659,.27125,-.08798),(-.30094,.03907,-.08798),(-.20743,.00562,-.08798),(-.10661,.26807,-.24696),(-.14054,.33314,-.08798),(-.37931,.0857,-.08798),(-.15056,.32996,-.24696),(-.16495,.41822,-.08798),(-.36612,.39625,-.08798),(-.44339,.14247,-.08798),(-.17497,.41504,-.24696),(-.37614,.39307,-.24696),(-.56729,.37428,-.08798),(-.53434,.28199,-.08798),(-.49405,.20631,-.08798),(-.57732,.37109,-.24696),(-.54436,.27881,-.24696),(-.50407,.20313,-.24696),(-.45342,.13928,-.24696),(-.38933,.08252,-.24696),(-.31096,.03589,-.24696),(-.21745,.00244,-.24696),(-.10625,-.0177,-.24696),(.02522,-.02441,-.24696),(.20479,-.00757,-.24696),(.34895,.04297,-.24696),(.46101,.12549,-.24696),(.54427,.23828,-.24696),(.5959,.3689,-.24696),(.61311,.50488,-.24696),(.57967,.6853,-.24696),(.47933,.83203,-.24696),(.32527,.92944,-.24696),(.13069,.96191,-.24696),(.06685,.95801,-.24696),(.00227,.94629,-.24696),(-.06303,.92676,-.24696),(-.12907,.89941,-.24696),(-.11198,1.00684,-.24696),(-.09489,1.11426,-.24696),(.22493,1.11426,-.24696),(.55478,1.11744,-.08798),(.55478,1.27613,-.08798),(.55478,1.43482,-.08798),(.54475,1.11426,-.24696),(.54475,1.27295,-.24696),(.54475,1.43164,-.24696)])))])])])
)

### X3D model conversion complete ###

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

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