import bpy
from . import utils
from ..cAPI import SimulationAPI
from .. import utils as ut

class HI_PHY_PT_MeshMotionMapper(bpy.types.Panel):
    bl_space_type = "PROPERTIES"
    bl_region_type = "WINDOW"
    bl_context = "physics"
    bl_label = "Hi Phy: Mesh Motion Mapper"

    @classmethod
    def poll(cls, context):
        hi_phy = context.object.hi_phy
        return hi_phy.is_active and hi_phy.object_type == 'MESH_MOTION_MAPPER'

    def draw(self, context):
        obj = context.object
        hi_phy = obj.hi_phy
        lay = self.layout
        utils.draw_prop(lay, hi_phy, 'guide_shape', 'Guide Shape', expand=False, use_column=True)
        utils.draw_prop(lay, hi_phy, 'driven_shape', 'Driven Shape', expand=False, use_column=True)
        utils.draw_prop(lay, hi_phy, 'target_shape', 'Target Shape for Unbond Vertices', expand=False, use_column=True)
        utils.draw_prop(lay, hi_phy, 'motion_mapper_binding_radius', 'Binding Radius', expand=False, use_column=True)
        utils.draw_prop(lay, hi_phy, 'motion_mapper_live_update', 'Live Update', expand=False, use_column=True)
        row = lay.row(align=True)

        if (hi_phy.motion_mapper_is_bond):
            row.label(text="The motion mapper has been bond.")

        row = lay.row(align=True)
        operator = row.operator('hi_phy.motion_mapper_mesh_binding', text='Binding')
        operator.motion_mapper = obj.name
        if (hi_phy.guide_shape):
            operator.guide = hi_phy.guide_shape.name
        if (hi_phy.driven_shape):
            operator.driven = hi_phy.driven_shape.name
        operator.binding_radius = hi_phy.motion_mapper_binding_radius
