compas-dev / compas_view2

Standalone viewer for COMPAS
https://compas.dev/compas_view2/
MIT License
6 stars 8 forks source link

Sidedock #140

Closed Licini closed 2 years ago

Licini commented 2 years ago

Adding ability to create side docks programmatically #139 , will add the docs once approved

from compas.geometry import Point, Polyline, Bezier
from compas.colors import Color
from compas_view2.app import App

curve = Bezier([[0, 0, 0], [3, 6, 0], [5, -3, 0], [10, 0, 0]])

viewer = App(viewmode="shaded", enable_sidebar=True, width=1600, height=900)
pointobj = viewer.add(Point(* curve.point(0)), size=20, color=(1, 0, 0))
curveobj = viewer.add(Polyline(curve.locus()), linewidth=2)

@viewer.button(text="Open Dock 1")
def click():
    dock = viewer.sidedock('Dock 1')
    @viewer.checkbox(text="Show Point", checked=True, parent = dock._layout)
    def check(checked):
        pointobj.is_visible = checked
        viewer.view.update()

    dock._layout.addStretch()

@viewer.button(text="Open Dock 2")
def click():
    dock = viewer.sidedock('Dock 2')

    @viewer.slider(title="Slide Point", maxval=100, step=1, bgcolor=Color.white(), parent = dock._layout)
    def slide(value):
        value = value / 100
        pointobj._data = curve.point(value)
        pointobj.update()
        viewer.view.update()

    @viewer.button(text="Reset", parent = dock._layout)
    def click():
        if viewer.confirm('This will reset the point to parameter t=0.'):
            pointobj._data = curve.point(0)
            pointobj.update()
            slide.value = 0
            viewer.view.update()

    dock._layout.addStretch()

@viewer.button(text="Open Dock 3")
def click():
    dock = viewer.sidedock('Dock 3')

    @viewer.radio(title='Display', items=[
    {'text': 'Ghosted', 'value': 'ghosted', 'checked': viewer.view.mode == 'ghosted'},
    {'text': 'Shaded', 'value': 'shaded', 'checked': viewer.view.mode == 'shaded'},
    {'text': 'Lighted', 'value': 'lighted', 'checked': viewer.view.mode == 'lighted'},
    {'text': 'Wireframe', 'value': 'wireframe', 'checked': viewer.view.mode == 'wireframe'}
    ], parent = dock._layout)
    def select1(value):
        viewer.view.mode = value
        viewer.view.update()

    @viewer.select(items=[
        {'text': 'Item 1'},
        {'text': 'Item 2'},
        {'text': 'Item 3'},
        {'text': 'Item 4'}
    ], parent = dock._layout)
    def select2(index, text):
        viewer.info(f"You selected item '{index}' with text '{text}'")

    dock._layout.addStretch()

viewer.run()
image
tomvanmele commented 2 years ago

can we simplify this by not making them dockable, just popups?

nizartaha commented 2 years ago

Hello @Licini any update on this feature? Thanks a lot for the effort