import dds
import ddsutil
import struct

# Volgende zelf toegevoegd anders vindt hij Vector3_ niet 
from idlpython.geometry_msgs.Point_.geometry_msgs.msg.dds_ import Point_
from idlpython.geometry_msgs.Quaternion_.geometry_msgs.msg.dds_ import Quaternion_

class Pose___TypeSupport(dds.TypeSupport):

    _typename = 'geometry_msgs::msg::dds_::Pose_'
    _keylist = ''
    _metadescriptor = '<MetaData version="1.0.0"><Module name="geometry_msgs"><Module name="msg"><Module name="dds_"><Struct name="Point_"><Member name="x_"><Double/></Member><Member name="y_"><Double/></Member><Member name="z_"><Double/></Member></Struct><Struct name="Quaternion_"><Member name="x_"><Double/></Member><Member name="y_"><Double/></Member><Member name="z_"><Double/></Member><Member name="w_"><Double/></Member></Struct><Struct name="Pose_"><Member name="position_"><Type name="Point_"/></Member><Member name="orientation_"><Type name="Quaternion_"/></Member></Struct></Module></Module></Module></MetaData>'

    def __init__(self):
        super(Pose___TypeSupport, self).__init__(self._typename,
              self._keylist,
              self._metadescriptor,
              struct.calcsize(Pose_()._get_packing_fmt()))

    def _serialize(self, o):
        if not isinstance(o, Pose_):
            raise TypeError('Incorrect data type')
        result = o._serialize()
        return result

    def _deserialize(self, buf):
        result = Pose_()
        data = struct.unpack(result._get_packing_fmt(), buf)
        result._deserialize(list(data))
        return result

class Pose_(ddsutil.TopicDataClass):

    @staticmethod
    def get_type_support():
        ''' Return type support information required for dds.Topic constructor '''
        return Pose___TypeSupport()

    @property
    def position_(self):
        '''
        a DDS geometry_msgs::msg::dds_::Point_ value
        @rtype: Point_
        '''
        return self._position__

    _position__checker = ddsutil._class_checker(Point_)
    @position_.setter
    def position_(self, value):
        self._position__checker(value)
        self._position__ = value

    @property
    def orientation_(self):
        '''
        a DDS geometry_msgs::msg::dds_::Quaternion_ value
        @rtype: Quaternion_
        '''
        return self._orientation__

    _orientation__checker = ddsutil._class_checker(Quaternion_)
    @orientation_.setter
    def orientation_(self, value):
        self._orientation__checker(value)
        self._orientation__ = value

    _member_attributes = ('position_', 'orientation_')

    def __init__(self, **kwargs):
        ''' Create a Pose_ instance, optionally initializing fields by name '''
        # init attributes to default value
        self.position_ = Point_()
        self.orientation_ = Quaternion_()
        # set values for attributes passed in
        for key, value in kwargs.items():
            if key not in self._member_attributes:
                raise TypeError('Invalid argument name : %s' %(key))
            setattr(self, key, value)

    _packing_fmt = None

    @staticmethod
    def _get_packing_fmt():
        ''' Returns packing format of this class data '''
        if Pose_._packing_fmt is not None:
            return Pose_._packing_fmt
        fmt = ''
        fmt += ddsutil._align(fmt, Point_._get_packing_fmt())
        fmt += ddsutil._align(fmt, Quaternion_._get_packing_fmt())

        Pose_._packing_fmt = ddsutil._pad_fmt(fmt)
        return Pose_._packing_fmt

    def _serialize(self):
        ''' Serialize data for writing '''
        fmt = self._get_packing_fmt()
        args = self._get_packing_args()
        result = struct.pack(fmt, *args)
        return result

    def _deserialize(self, data):
        ''' Initialize values from data returned by struct.unpack()'''
        self.position_ = Point_()._deserialize(data)
        self.orientation_ = Quaternion_()._deserialize(data)
        return self;

    def _get_packing_args(self):
        ''' Return an list of data suitable for struct.pack '''
        args = []
        args.extend(self.position_._get_packing_args())
        args.extend(self.orientation_._get_packing_args())
        return args

