[x3d-public] x3d.py error; fixed and deployed updates to X3D Schema, X3DUOM, X3DJSAIL, X3D Ontology and x3d.py X3DPSAIL

Don Brutzman brutzman at nps.edu
Sun Apr 26 23:32:43 PDT 2020


Did a lot of work this weekend, all interrelated and cross-checked.  Uploads in progress.

Test logs are themselves maintained in version control so that (a) output changes are evident during development, and (b) other developers can see what is expected.

a. X3D Schema and X3DUOM
   http://web3d.org/specifications
- annotation appinfo added to a number of String enumeration values, which can be either strict choices or optional values in X3D spec.
- X3DUOM updated to indicate simpleType as well as baseType for each field when appropriate, giving fuller expression to object model.
- X3DUOM name attributes now appear first for readability.
- These changes supported the follow-on library improvements, additional work also applied.

-------

b. X3DJSAIL
   X3D Java Scene Access Interface Library (X3DJSAIL)
   https://www.web3d.org/specifications/java/X3DJSAIL.html
- Corresponding update applied to X3DJSAIL with only minor tweaks.

-------

c. X3D Ontology
   https://www.web3d.org/x3d/content/semantics/semantics.html
- simple-type enumeration lists added, excerpt follows
- typing of fields now reflects these simple types
- name attribute typing is also stricter, e.g. some names are NMTOKEN
- found feature in protege for diagnosing error lines in turtle .ttl
- ready for further work on accessType representations, continuing prior efforts

:closureTypeChoices rdf:type rdfs:Datatype ;
   rdfs:label "closureTypeChoices" ;
   dc:description "closureTypeChoices are strictly allowed enumeration values for ArcClose2D closureType field" ;
   rdfs:range xs:NMTOKEN ;
   rdfs:domain [ owl:unionOf ( 'PIE' 'CHORD' ) ] .
# PIE "Connects arc endpoints to center, forming a pie wedge"
# CHORD "Connects arc endpoints directly to each other, as in chord on a circle"

-------

d. x3d.py X3DPSAIL package
   https://www.web3d.org/x3d/stylesheets/python/python.html
- renamed toXML() as XML(), added XML() export methods to all X3D types
- used these for export output for all field values for consistency
- added unit tests for all types, tests successful
   https://www.web3d.org/x3d/stylesheets/python/examples/PythonX3dSmokeTests.py
   https://www.web3d.org/x3d/stylesheets/python/build.examples.log.txt

example excerpts:
- - - - - - - - - -
SFString test       = 'test setter'
SFString test.value = test setter
SFString test.XML() = test setter
SFString     isValidSFString(test)=True
SFString assertValidSFString(test)
MFString test       = [test, setters and getters]
MFString test.value = ['test', 'setters and getters']
MFString test.XML() = "test" "setters and getters"
MFString     isValidMFString(test)=True
MFString assertValidMFString(test)
downcasting by dereferencing simple-list value=[one], type=<class 'x3d.MFString'> as one
SFString test downcast legal singleton: SFString(MFString("one"))='one', type=<class 'x3d.SFString'>
MFString test   upcast legal SF value:  MFString(SFString("two"))=['two'], type=<class 'x3d.MFString'>
- - - - - - - - - -
MFNode test.XML()             =
<Group DEF='B'/>
<Shape DEF='C'>
   <Appearance DEF='D'>
     <Material DEF='E'/>
   </Appearance>
</Shape>
<WorldInfo DEF='F'/>
- - - - - - - - - -
- simple-type enumeration lists added, excerpt follows
- added assertion methods to check enumeration values valid, throws exception otherwise

CLOSURETYPECHOICES = (
     # strict set of allowed values follow, no other values are valid
     'PIE', # Connects arc endpoints to center, forming a pie wedge
     'CHORD' # Connects arc endpoints directly to each other, as in chord on a circle
)
def assertValidClosureType(fieldName, value):
     """
     Utility function to assert type validity of closureTypeChoices value, otherwise raise X3DTypeError with diagnostic message.
     Note MFString enumeration values are provided in XML syntax, so check accordingly.
     """
     if  not value:
         return True # no failure on empty defaults
     if  isinstance(value,SFString) or isinstance(value,str):
         if str(value) in CLOSURETYPECHOICES:
             return True
         raise X3DTypeError(fieldName + ' value=' + value + ' does not match allowed enumerations in CLOSURETYPECHOICES=' + str(CLOSURETYPECHOICES))
     if  isinstance(value,MFString):
         if MFString(value).XML() in CLOSURETYPECHOICES:
             return True
         raise X3DTypeError(fieldName + ' value=' + MFString(value).XML() + ' does not match allowed enumerations in CLOSURETYPECHOICES=' + str(CLOSURETYPECHOICES))

class ArcClose2D(_X3DGeometryNode):
# ...
     @property # getter - - - - - - - - - -
     def closureType(self):
         """Defines whether pair of line segments connect to center (PIE), or single line-segment chord connects arc endpoints (CHORD)."""
         return self.__closureType
     @closureType.setter
     def closureType(self, closureType=None):
         if  closureType is None:
             closureType = SFString.DEFAULT_VALUE
         assertValidSFString(closureType)
         assertValidClosureType('closureType', closureType)
         self.__closureType = closureType

-------

So Andreas hopefully this should give you everything you might need and expect for .XML() export.

Am hoping Loren can help me with incantation so that all we need syntactically is .XML export.

It will be straightforward to add .VRML export (.X3DV and .WRL methods perhaps) once we are satisfied with .XML for .x3d files/strings.

I like how Python usually fails bitterly until you get things exactly right.

Didn't have time to check anything with python packaging yet.

Feedback welcome.

On 4/23/2020 12:14 PM, Don Brutzman wrote:
> Thanks for trouble report.  This was similar to error a few days ago, common cause was incorrect handling of MFString fields by toXML() method.
> 
> Now fixed and deployed.  I've performed regression tests on about 4000 models, have ~30 Traceback errors to continue diagnosis on.  So... toXML() is pretty much implemented now!
> 
> * Python X3D Package x3d.py
>    X3D Python Scene Access Interface Library (X3DPSAIL)
>    https://www.web3d.org/x3d/stylesheets/python/python.html
> 
> * pip install x3d; Python package x3d
>    https://pypi.org/project/x3d
> 
> Further improvement suggestions and bug reports welcome.  Hoping to complement other work, today's Design Printing Scanning demo was great - thanks very much.
> 
> Have fun with X3D Python!
> 
> On 4/23/2020 3:55 AM, Andreas Plesch wrote:
>> When I try this:
>>
>> inline=Inline(url=["Vent.x3d"])
>>
>> toXML() generates an error:
>>
>> inline.toXML()
>>
>> ---------------------------------------------------------------------------
>> TypeError                                 Traceback (most recent call last)
>> <ipython-input-26-2e0e2ed2e4db> in <module>
>> ----> 1 inline.toXML()
>>
>> ~/x3d.py in toXML(self, indentLevel)
>>    22341             result += " load='" + str(self.load) + "'"
>>    22342         if self.url != list():
>>> 22343             result += " url='" + self.url + "'"
>>    22344         if self.visible != True:
>>    22345             result += " visible='" + str(self.visible) + "'"
>>
>> TypeError: can only concatenate str (not "list") to str
>>
>> This is the x3d.py linked from the web3d web page.
>>
>> Do I need to do something different?
>>
>> -Andreas
all the best, Don
-- 
Don Brutzman  Naval Postgraduate School, Code USW/Br       brutzman at nps.edu
Watkins 270,  MOVES Institute, Monterey CA 93943-5000 USA   +1.831.656.2149
X3D graphics, virtual worlds, navy robotics http://faculty.nps.edu/brutzman



More information about the x3d-public mailing list