from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import compas
import compas.colors
import compas.geometry
from compas.data import Data
from compas.datastructures import Mesh
from compas.files.urdf import URDFElement
from compas.geometry import Frame
from compas.robots.model.base import ProxyObject
from compas.robots.model.base import _attr_from_data
from compas.robots.model.base import _attr_to_data
from compas.robots.model.base import _parse_floats

__all__ = [
    'Geometry',
    'MeshDescriptor',
    'Color',
    'Texture',
    'Material',
    'Origin',
    'Cylinder',
    'Box',
    'Sphere',
    'Capsule',
]


class BoxProxy(ProxyObject):
    """Proxy class that adds URDF functionality to an instance of :class:`~compas.geometry.Box`.

    This class is internal and not intended to be referenced externally.
    """

    def get_urdf_element(self):
        attributes = {'size': '{} {} {}'.format(*self.size)}
        return URDFElement('box', attributes)

    @classmethod
    def from_urdf(cls, attributes, elements=None, text=None):
        size = _parse_floats(attributes['size'])
        return cls(compas.geometry.Box(Frame.worldXY(), *size))

    @property
    def meshes(self):
        return [Mesh.from_shape(self)]

    @property
    def size(self):
        return [self.xsize, self.ysize, self.zsize]


class CylinderProxy(ProxyObject):
    """Proxy class that adds URDF functionality to an instance of :class:`~compas.geometry.Cylinder`.

    This class is internal and not intended to be referenced externally.
    """

    def get_urdf_element(self):
        attributes = {'radius': self.radius, 'length': self.length}
        return URDFElement('cylinder', attributes)

    @classmethod
    def from_urdf(cls, attributes, elements=None, text=None):
        radius = float(attributes['radius'])
        length = float(attributes['length'])
        plane = compas.geometry.Plane([0, 0, 0], [0, 0, 1])
        circle = compas.geometry.Circle(plane, radius)