Skip to content
This repository has been archived by the owner on Oct 27, 2022. It is now read-only.

Commit

Permalink
Merge pull request #28 from AlexSnipes/fixed-test
Browse files Browse the repository at this point in the history
Fixed test
  • Loading branch information
cleder authored May 11, 2017
2 parents 6f7ec03 + e6902d8 commit 7b4a1f8
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 69 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
czml/*.pyc
czml/__pycache__/
.idea
build
czml.egg-info/
dist
.cache
pytest-3.0.7-py2.7.egg/
py-1.4.33-py2.7.egg/
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
language: python
python:
- "3.6"
- "3.5"
- "3.4"
- "3.3"
- "2.7"
- pypy
- pypy3
# command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors
# install: PLEASE CHANGE ME
install:
Expand Down
124 changes: 94 additions & 30 deletions czml/czml.py
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,7 @@ class Label(_CZMLBaseObject):
horizontalOrigin = None
scale = None
pixelOffset = None
fillColor = None

def __init__(self, text=None, show=False):
self.text = text
Expand All @@ -945,6 +946,8 @@ def data(self):
d['scale'] = self.scale
if self.pixelOffset:
d['pixelOffset'] = self.pixelOffset
if self.fillColor:
d['fillColor'] = self.fillColor
return d

def load(self, data):
Expand Down Expand Up @@ -1264,26 +1267,6 @@ class Camera(_CZMLBaseObject):
"""A camera."""
pass

class Description(_CZMLBaseObject):
string = None
reference = None

def __init__(self, string=None, reference=None):
self.string = string
self.reference = reference

def data(self):
d = {}
if self.string:
d['string'] = self.string
if self.reference:
d['reference'] = self.reference
return d

def load(self, data):
self.string = data.get('string', None)
self.reference = data.get('reference', None)

class CZMLPacket(_CZMLBaseObject):
""" A CZML packet describes the graphical properties for a single
object in the scene, such as a single aircraft.
Expand Down Expand Up @@ -1378,26 +1361,42 @@ class CZMLPacket(_CZMLBaseObject):
# try adding description
_description = None

_properties = ('id', 'description', 'version', 'availability', 'billboard', 'clock', 'position', 'label', 'point', 'positions', 'polyline', 'polygon', 'path', 'orientation', 'ellipse', 'ellipsoid', 'cone', 'pyramid')
# Model 3D
_model = None

_name = None

_properties = ('id', 'name', 'description', 'version', 'availability', 'billboard', 'clock', 'position', 'label', 'point', 'positions', 'polyline', 'polygon', 'path', 'orientation', 'ellipse', 'ellipsoid', 'cone', 'pyramid', 'model')

# TODO: Figure out how to set __doc__ from here.
# position = class_property(Position, 'position')


@property
def name(self):
if self._name is not None:
return self._name


@name.setter
def name(self, name):
if isinstance(name, str):
self._name = name
elif isinstance(name, basestring):
self._name = name
else:
raise TypeError

@property
def description(self):
if self._description is not None:
return self._description.data()
return self._description

@description.setter
def description(self, description):
if isinstance(description, Description):
if isinstance(description, str):
self._description = description
elif isinstance(description, basestring):
self._description = description
elif isinstance(description, dict):
d = Description()
d.load(description)
self._description = d
elif description is None:
self._description = None
else:
raise TypeError

Expand Down Expand Up @@ -1633,6 +1632,26 @@ def cone(self, cone):
else:
raise TypeError


@property
def model(self):
"""The Model 3d."""
if self._model is not None:
return self._model.data()

@model.setter
def model(self, model):
if isinstance(model, Model):
self._model = model
elif isinstance(model, dict):
m = Model()
m.load(model)
self._model = m
elif model is None:
self._model = None
else:
raise TypeError

def data(self):
d = {}
for property_name in self._properties:
Expand All @@ -1648,3 +1667,48 @@ def load(self, data):
setattr(self, property_name, property_value)


class Model(_CZMLBaseObject):
"""A 3D model. Based on https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/Model """

# Whether or not the model is shown.
# Boolean
show = None

#Color
_color = None
color = class_property(Color, 'silhouetteColor')

#Double
_scale = None
scale = class_property(Number, 'scale')

#URI
gltf = None

minimumPixelSize = None

runAnimations = None

maximumScale = None

incrementallyLoadTextures = None

shadows = None

heightReference = None

_silhouetteColor = None
silhouetteColor = class_property(Color, 'silhouetteColor')

silhouetteSize = None

colorBlendMode = None

colorBlendAmount = None

nodeTransformations = None
# height = class_property(Number, 'height')

_properties = ('show', 'gltf', 'runAnimations', 'scale', 'maximumScale', 'minimumPixelSize',
'incrementallyLoadTextures', 'shadows', 'heightReference', 'silhouetteColor', 'silhouetteSize',
'color', 'colorBlendMode', 'colorBlendAmount', 'nodeTransformations')
42 changes: 4 additions & 38 deletions czml/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1010,47 +1010,13 @@ def testCone(self):
})

def testDescription(self):

# Create a new description
d = czml.Description(string='<h1>Hello World</h1>',
reference='the reference'
)
self.assertEqual(d.data(), {'string': '<h1>Hello World</h1>',
'reference': 'the reference'
})

# Create a new description from an existing description
d2 = czml.Description()
d2.loads(d.dumps())
self.assertEqual(d2.data(), d.data())

# Change an existing description
d.string = '<h1>Hello World Again</h1>'
print(d)

self.assertEqual(d.data(), {'string': '<h1>Hello World Again</h1>',
'reference': 'the reference'
})

# Verfy passing unkown value
with self.assertRaises(Exception):
d3 = czml.Description(bad_data=None)

# Add description to CZML packet
packet = czml.CZMLPacket(id='the_id')
packet.description = d2
self.assertEqual(packet.data(), {'id': 'the_id',
'description': {'string': '<h1>Hello World</h1>',
'reference': 'the reference'
}
})
packet.description = '<h1>Hello World</h1>'
self.assertEqual(packet.data(), {'id': 'the_id', 'description': '<h1>Hello World</h1>'})

# Add a description as a dict
packet.description = {'string': 'As a dict'}
self.assertEqual(packet.data(), {'id': 'the_id',
'description': {'string': 'As a dict'
}
})
packet.description = 'As a dict'
self.assertEqual(packet.data(), {'id': 'the_id', 'description': 'As a dict'})


def test_suite():
Expand Down

0 comments on commit 7b4a1f8

Please sign in to comment.