####################################################################################################
#
# Invoking X3D model self-test:
#
#   $ python OpticalDeck.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.0',
  head=head(
    children=[
    meta(content='OpticalDeck.x3d',name='title'),
    meta(content='Optical deck for the ASDS Assembly',name='description'),
    meta(content='Ron Hatt',name='creator'),
    meta(content='14 September 2006',name='created'),
    meta(content='28 November 2019',name='modified'),
    meta(content='https://www.web3d.org/x3d/content/examples/Savage/Space/SatelliteLab/OpticalDeck.x3d',name='identifier'),
    meta(content='Wings3D, VizX3D',name='generator'),
    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='OpticalDeck.x3d'),
    Shape(DEF='OpticalDeck',
      appearance=Appearance(
        material=Material(ambientIntensity=0.4,diffuseColor=(1.0,0.77,0.31),shininess=0.16,specularColor=(0.71,0.70,0.56))),
      geometry=IndexedFaceSet(coordIndex=[0,1,65,-1,0,65,64,-1,0,63,62,-1,0,62,61,-1,0,61,60,-1,0,60,59,-1,0,59,58,-1,0,58,57,-1,0,57,56,-1,0,56,55,-1,0,55,54,-1,0,54,53,-1,0,53,52,-1,0,52,51,-1,0,51,50,-1,0,50,49,-1,0,49,48,-1,0,48,47,-1,0,47,46,-1,0,46,45,-1,0,45,44,-1,0,44,43,-1,0,43,42,-1,0,42,41,-1,0,41,40,-1,0,40,39,-1,0,39,38,-1,0,38,37,-1,0,37,36,-1,0,36,35,-1,0,35,34,-1,0,34,33,-1,0,33,32,-1,0,32,31,-1,0,31,30,-1,0,30,29,-1,0,29,28,-1,0,28,27,-1,0,27,26,-1,0,26,25,-1,0,25,24,-1,0,24,23,-1,0,23,22,-1,0,22,21,-1,0,21,20,-1,0,20,19,-1,0,19,18,-1,0,18,17,-1,0,17,16,-1,0,16,15,-1,0,15,14,-1,0,14,13,-1,0,13,12,-1,0,12,11,-1,0,11,10,-1,0,10,9,-1,0,9,8,-1,0,8,7,-1,0,7,6,-1,0,6,5,-1,0,5,4,-1,0,4,3,-1,0,3,2,-1,0,2,1,-1,0,64,127,-1,0,127,63,-1,1,2,66,-1,1,66,65,-1,2,3,67,-1,2,67,66,-1,3,4,68,-1,3,68,67,-1,4,5,69,-1,4,69,68,-1,5,6,70,-1,5,70,69,-1,6,7,71,-1,6,71,70,-1,7,8,72,-1,7,72,71,-1,8,9,73,-1,8,73,72,-1,9,10,74,-1,9,74,73,-1,10,11,75,-1,10,75,74,-1,11,12,76,-1,11,76,75,-1,12,13,77,-1,12,77,76,-1,13,14,78,-1,13,78,77,-1,14,15,79,-1,14,79,78,-1,15,16,80,-1,15,80,79,-1,16,17,81,-1,16,81,80,-1,17,18,82,-1,17,82,81,-1,18,19,83,-1,18,83,82,-1,19,20,84,-1,19,84,83,-1,20,21,85,-1,20,85,84,-1,21,22,86,-1,21,86,85,-1,22,23,87,-1,22,87,86,-1,23,24,88,-1,23,88,87,-1,24,25,89,-1,24,89,88,-1,25,26,90,-1,25,90,89,-1,26,27,91,-1,26,91,90,-1,27,28,92,-1,27,92,91,-1,28,29,93,-1,28,93,92,-1,29,30,94,-1,29,94,93,-1,30,31,95,-1,30,95,94,-1,31,32,96,-1,31,96,95,-1,32,33,97,-1,32,97,96,-1,33,34,98,-1,33,98,97,-1,34,35,99,-1,34,99,98,-1,35,36,100,-1,35,100,99,-1,36,37,101,-1,36,101,100,-1,37,38,102,-1,37,102,101,-1,38,39,103,-1,38,103,102,-1,39,40,104,-1,39,104,103,-1,40,41,105,-1,40,105,104,-1,41,42,106,-1,41,106,105,-1,42,43,107,-1,42,107,106,-1,43,44,108,-1,43,108,107,-1,44,45,109,-1,44,109,108,-1,45,46,110,-1,45,110,109,-1,46,47,111,-1,46,111,110,-1,47,48,112,-1,47,112,111,-1,48,49,113,-1,48,113,112,-1,49,50,114,-1,49,114,113,-1,50,51,115,-1,50,115,114,-1,51,52,116,-1,51,116,115,-1,52,53,117,-1,52,117,116,-1,53,54,118,-1,53,118,117,-1,54,55,119,-1,54,119,118,-1,55,56,120,-1,55,120,119,-1,56,57,121,-1,56,121,120,-1,57,58,122,-1,57,122,121,-1,58,59,123,-1,58,123,122,-1,59,60,124,-1,59,124,123,-1,60,61,125,-1,60,125,124,-1,61,62,126,-1,61,126,125,-1,62,63,127,-1,62,127,126,-1,64,65,66,-1,64,66,67,-1,64,67,68,-1,64,68,69,-1,64,69,70,-1,64,70,71,-1,64,71,72,-1,64,72,73,-1,64,73,74,-1,64,74,75,-1,64,75,76,-1,64,76,77,-1,64,77,78,-1,64,78,79,-1,64,79,80,-1,64,80,81,-1,64,81,82,-1,64,82,83,-1,64,83,84,-1,64,84,85,-1,64,85,86,-1,64,86,87,-1,64,87,88,-1,64,88,89,-1,64,89,90,-1,64,90,91,-1,64,91,92,-1,64,92,93,-1,64,93,94,-1,64,94,95,-1,64,95,96,-1,64,96,97,-1,64,97,98,-1,64,98,99,-1,64,99,100,-1,64,100,101,-1,64,101,102,-1,64,102,103,-1,64,103,104,-1,64,104,105,-1,64,105,106,-1,64,106,107,-1,64,107,108,-1,64,108,109,-1,64,109,110,-1,64,110,111,-1,64,111,112,-1,64,112,113,-1,64,113,114,-1,64,114,115,-1,64,115,116,-1,64,116,117,-1,64,117,118,-1,64,118,119,-1,64,119,120,-1,64,120,121,-1,64,121,122,-1,64,122,123,-1,64,123,124,-1,64,124,125,-1,64,125,126,-1,64,126,127,-1],creaseAngle=0.524,
        coord=Coordinate(point=[(4.45,.1,0),(4.42857,.1,.43618),(4.36449,.1,.86815),(4.25838,.1,1.29177),(4.11126,.1,1.70294),(3.92455,.1,2.09772),(3.70004,.1,2.47229),(3.4399,.1,2.82305),(3.14663,.1,3.14663),(2.82305,.1,3.4399),(2.47229,.1,3.70004),(2.09772,.1,3.92455),(1.70294,.1,4.11126),(1.29177,.1,4.25838),(.86815,.1,4.36449),(.43618,.1,4.42857),(0,.1,4.45),(-.43618,.1,4.42857),(-.86815,.1,4.36449),(-1.29177,.1,4.25838),(-1.70294,.1,4.11126),(-2.09772,.1,3.92455),(-2.47229,.1,3.70004),(-2.82305,.1,3.4399),(-3.14663,.1,3.14663),(-3.4399,.1,2.82305),(-3.70004,.1,2.47229),(-3.92455,.1,2.09772),(-4.11126,.1,1.70294),(-4.25838,.1,1.29177),(-4.36449,.1,.86815),(-4.42857,.1,.43618),(-4.45,.1,0),(-4.42857,.1,-.43618),(-4.36449,.1,-.86815),(-4.25838,.1,-1.29177),(-4.11126,.1,-1.70294),(-3.92455,.1,-2.09772),(-3.70004,.1,-2.47229),(-3.4399,.1,-2.82305),(-3.14663,.1,-3.14663),(-2.82305,.1,-3.4399),(-2.47229,.1,-3.70004),(-2.09772,.1,-3.92455),(-1.70294,.1,-4.11126),(-1.29177,.1,-4.25838),(-.86815,.1,-4.36449),(-.43618,.1,-4.42857),(-0,.1,-4.45),(.43618,.1,-4.42857),(.86815,.1,-4.36449),(1.29177,.1,-4.25838),(1.70294,.1,-4.11126),(2.09772,.1,-3.92455),(2.47229,.1,-3.70004),(2.82305,.1,-3.4399),(3.14663,.1,-3.14663),(3.4399,.1,-2.82305),(3.70004,.1,-2.47229),(3.92455,.1,-2.09772),(4.11126,.1,-1.70294),(4.25838,.1,-1.29177),(4.36449,.1,-.86815),(4.42857,.1,-.43618),(4.45,0,0),(4.42857,0,.43618),(4.36449,0,.86815),(4.25838,0,1.29177),(4.11126,0,1.70294),(3.92455,0,2.09772),(3.70004,0,2.47229),(3.4399,0,2.82305),(3.14663,0,3.14663),(2.82305,0,3.4399),(2.47229,0,3.70004),(2.09772,0,3.92455),(1.70294,0,4.11126),(1.29177,0,4.25838),(.86815,0,4.36449),(.43618,0,4.42857),(0,0,4.45),(-.43618,0,4.42857),(-.86815,0,4.36449),(-1.29177,0,4.25838),(-1.70294,0,4.11126),(-2.09772,0,3.92455),(-2.47229,0,3.70004),(-2.82305,0,3.4399),(-3.14663,0,3.14663),(-3.4399,0,2.82305),(-3.70004,0,2.47229),(-3.92455,0,2.09772),(-4.11126,0,1.70294),(-4.25838,0,1.29177),(-4.36449,0,.86815),(-4.42857,0,.43618),(-4.45,0,0),(-4.42857,0,-.43618),(-4.36449,0,-.86815),(-4.25838,0,-1.29177),(-4.11126,0,-1.70294),(-3.92455,0,-2.09772),(-3.70004,0,-2.47229),(-3.4399,0,-2.82305),(-3.14663,0,-3.14663),(-2.82305,0,-3.4399),(-2.47229,0,-3.70004),(-2.09772,0,-3.92455),(-1.70294,0,-4.11126),(-1.29177,0,-4.25838),(-.86815,0,-4.36449),(-.43618,0,-4.42857),(-0,0,-4.45),(.43618,0,-4.42857),(.86815,0,-4.36449),(1.29177,0,-4.25838),(1.70294,0,-4.11126),(2.09772,0,-3.92455),(2.47229,0,-3.70004),(2.82305,0,-3.4399),(3.14663,0,-3.14663),(3.4399,0,-2.82305),(3.70004,0,-2.47229),(3.92455,0,-2.09772),(4.11126,0,-1.70294),(4.25838,0,-1.29177),(4.36449,0,-.86815),(4.42857,0,-.43618)])))])
)

### X3D model conversion complete ###

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

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