import bpy

class VIEW3D_MT_HiPhy_object_mode_submenu_constraints(bpy.types.Menu):
    bl_label = "HiPhy Constraints"
    bl_idname = "VIEW3D_MT_hiphy_object_mode_submenu_constraints"

    def draw(self, context):
        layout = self.layout
        layout.operator_context = 'INVOKE_DEFAULT'
        layout.operator("hi_phy.create_mesh_constraint")
        layout.operator("hi_phy.create_root_constraint")
        layout.operator("hi_phy.create_binding_constraint")
        layout.operator("hi_phy.convert_edges_to_binding_constraint")
        layout.operator("hi_phy.create_joint_constraint")
        layout.operator("hi_phy.create_grab_constraint")

class VIEW3D_MT_HiPhy_object_mode_submenu_utils(bpy.types.Menu):
    bl_label = "HiPhy Utils"
    bl_idname = "VIEW3D_MT_hiphy_object_mode_submenu_utils"

    def draw(self, context):
        layout = self.layout
        layout.operator_context = 'INVOKE_DEFAULT'
        layout.operator("hi_phy.copy_parameter")
        layout.operator("hi_phy.add_base_normal")
        layout.operator("hi_phy.compute_curves_normal")
        # layout.operator("hi_phy.mesh_to_hair")

def draw_object_menu(self, context):
    layout = self.layout
    layout.separator()
    layout.menu("VIEW3D_MT_hiphy_object_mode_submenu_constraints")
    layout.menu("VIEW3D_MT_hiphy_object_mode_submenu_utils")

class VIEW3D_MT_HiPhy_mesh_edit_mode_submenu_constraints(bpy.types.Menu):
    bl_label = "HiPhy Constraints"
    bl_idname = "VIEW3D_MT_hiphy_mesh_edit_mode_submenu_constraints"

    def draw(self, context):
        layout = self.layout
        layout.operator_context = 'INVOKE_DEFAULT'
        layout.operator("hi_phy.create_mesh_constraint")
        layout.operator("hi_phy.create_point_constraint")
        layout.operator("hi_phy.create_binding_constraint")
        layout.operator("hi_phy.convert_edges_to_binding_constraint")

def draw_mesh_edit_menu(self, context):
    layout = self.layout
    layout.separator()
    layout.menu("VIEW3D_MT_hiphy_mesh_edit_mode_submenu_constraints")

class VIEW3D_MT_HiPhy_curves_edit_mode_submenu_constraints(bpy.types.Menu):
    bl_label = "HiPhy Constraints"
    bl_idname = "VIEW3D_MT_hiphy_curves_edit_mode_submenu_constraints"

    def draw(self, context):
        layout = self.layout
        layout.operator_context = 'INVOKE_DEFAULT'
        layout.operator("hi_phy.create_mesh_constraint")
        layout.operator("hi_phy.create_point_constraint")
        layout.operator("hi_phy.create_binding_constraint")
        layout.operator("hi_phy.convert_edges_to_binding_constraint")

def draw_curves_edit_menu(self, context):
    layout = self.layout
    layout.separator()
    layout.menu("VIEW3D_MT_hiphy_curves_edit_mode_submenu_constraints")

__CLASSES__ = [
    VIEW3D_MT_HiPhy_object_mode_submenu_constraints,
    VIEW3D_MT_HiPhy_object_mode_submenu_utils,
    VIEW3D_MT_HiPhy_mesh_edit_mode_submenu_constraints,
    VIEW3D_MT_HiPhy_curves_edit_mode_submenu_constraints
]

def register():
    for class_ in __CLASSES__:
        bpy.utils.register_class(class_)
    bpy.types.VIEW3D_MT_object_context_menu.append(draw_object_menu)
    bpy.types.VIEW3D_MT_edit_mesh_context_menu.append(draw_mesh_edit_menu)
    bpy.types.VIEW3D_MT_edit_curves_context_menu.append(draw_curves_edit_menu)

def unregister():
    bpy.types.VIEW3D_MT_object_context_menu.remove(draw_object_menu)
    bpy.types.VIEW3D_MT_edit_mesh_context_menu.remove(draw_mesh_edit_menu)
    bpy.types.VIEW3D_MT_edit_curves_context_menu.remove(draw_curves_edit_menu)
    for class_ in reversed(__CLASSES__):
        bpy.utils.unregister_class(class_)
