import omni.kit.ui
import omni.usd

# ======================================================================
MENU_CREATE_BUILTIN_PROCEDURAL_MESH_CUBE = (
    f'OmniGraph/{omni.kit.ui.get_custom_glyph_code("${glyphs}/menu_prim.svg")} Procedural Mesh/Cube'
)
MENU_CREATE_BUILTIN_PROCEDURAL_MESH_SPHERE = (
    f'OmniGraph/{omni.kit.ui.get_custom_glyph_code("${glyphs}/menu_prim.svg")} Procedural Mesh/Sphere'
)
MENU_CREATE_BUILTIN_PROCEDURAL_MESH_CAPSULE = (
    f'OmniGraph/{omni.kit.ui.get_custom_glyph_code("${glyphs}/menu_prim.svg")} Procedural Mesh/Capsule'
)
MENU_CREATE_BUILTIN_PROCEDURAL_MESH_CYLINDER = (
    f'OmniGraph/{omni.kit.ui.get_custom_glyph_code("${glyphs}/menu_prim.svg")} Procedural Mesh/Cylinder'
)
MENU_CREATE_BUILTIN_PROCEDURAL_MESH_CONE = (
    f'OmniGraph/{omni.kit.ui.get_custom_glyph_code("${glyphs}/menu_prim.svg")} Procedural Mesh/Cone'
)
MENU_CREATE_BUILTIN_PROCEDURAL_MESH_TORUS = (
    f'OmniGraph/{omni.kit.ui.get_custom_glyph_code("${glyphs}/menu_prim.svg")} Procedural Mesh/Torus'
)
MENU_CREATE_BUILTIN_PROCEDURAL_MESH_PLANE = (
    f'OmniGraph/{omni.kit.ui.get_custom_glyph_code("${glyphs}/menu_prim.svg")} Procedural Mesh/Plane'
)
MENU_CREATE_BUILTIN_PROCEDURAL_MESH_DISK = (
    f'OmniGraph/{omni.kit.ui.get_custom_glyph_code("${glyphs}/menu_prim.svg")} Procedural Mesh/Disk'
)


class Menu:
    def __init__(self):
        self.on_startup()

    def on_startup(self):
        self.menus = []

        editor_menu = omni.kit.ui.get_editor_menu()

        self.menus.append(editor_menu.add_item(MENU_CREATE_BUILTIN_PROCEDURAL_MESH_CUBE, self._on_menu_click))
        self.menus.append(editor_menu.add_item(MENU_CREATE_BUILTIN_PROCEDURAL_MESH_SPHERE, self._on_menu_click))
        self.menus.append(editor_menu.add_item(MENU_CREATE_BUILTIN_PROCEDURAL_MESH_CAPSULE, self._on_menu_click))
        self.menus.append(editor_menu.add_item(MENU_CREATE_BUILTIN_PROCEDURAL_MESH_CYLINDER, self._on_menu_click))
        self.menus.append(editor_menu.add_item(MENU_CREATE_BUILTIN_PROCEDURAL_MESH_CONE, self._on_menu_click))
        self.menus.append(editor_menu.add_item(MENU_CREATE_BUILTIN_PROCEDURAL_MESH_PLANE, self._on_menu_click))
        self.menus.append(editor_menu.add_item(MENU_CREATE_BUILTIN_PROCEDURAL_MESH_TORUS, self._on_menu_click))
        self.menus.append(editor_menu.add_item(MENU_CREATE_BUILTIN_PROCEDURAL_MESH_DISK, self._on_menu_click))

    def _on_menu_click(self, menu_item, value):
        if menu_item == MENU_CREATE_BUILTIN_PROCEDURAL_MESH_CUBE:
            omni.kit.commands.execute("CreateProceduralMeshCube")
        elif menu_item == MENU_CREATE_BUILTIN_PROCEDURAL_MESH_SPHERE:
            omni.kit.commands.execute("CreateProceduralMeshSphere")
        elif menu_item == MENU_CREATE_BUILTIN_PROCEDURAL_MESH_CAPSULE:
            omni.kit.commands.execute("CreateProceduralMeshCapsule")
        elif menu_item == MENU_CREATE_BUILTIN_PROCEDURAL_MESH_CYLINDER:
            omni.kit.commands.execute("CreateProceduralMeshCylinder")
        elif menu_item == MENU_CREATE_BUILTIN_PROCEDURAL_MESH_CONE:
            omni.kit.commands.execute("CreateProceduralMeshCone")
        elif menu_item == MENU_CREATE_BUILTIN_PROCEDURAL_MESH_TORUS:
            omni.kit.commands.execute("CreateProceduralMeshTorus")
        elif menu_item == MENU_CREATE_BUILTIN_PROCEDURAL_MESH_PLANE:
            omni.kit.commands.execute("CreateProceduralMeshPlane")
        elif menu_item == MENU_CREATE_BUILTIN_PROCEDURAL_MESH_DISK:
            omni.kit.commands.execute("CreateProceduralMeshDisk")

    def on_shutdown(self):
        self.menus = []
