Skip to content

Commit

Permalink
forms
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvanmele committed Nov 15, 2024
1 parent 105ec0b commit 0859d6b
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 107 deletions.
83 changes: 83 additions & 0 deletions commands/IGS_form_attributes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#! python3
# venv: brg-csd
# r: compas_session>=0.4.5, compas_ags>=1.3.1

import rhinoscriptsyntax as rs # type: ignore

from compas_igs.forms import Attribute
from compas_igs.forms import EdgeAttributesForm
from compas_igs.forms import VertexAttributesForm
from compas_igs.session import IGSSession

# =============================================================================
# Command
# =============================================================================


def RunCommand():
session = IGSSession()

form = session.find_formdiagram(warn=True)
if not form:
return

# =============================================================================
# Attributes
# =============================================================================

option = rs.GetString("Form Attributes", strings=["VertexAttributes", "EdgeAttributes"])
if not option:
return

if option == "VertexAttributes":
attributes = [
Attribute(name="x", text="X", value=float, width=48, editable=False),
Attribute(name="y", text="Y", value=float, width=48, editable=False),
Attribute(name="z", text="Z", value=float, width=48, editable=False),
Attribute(name="is_fixed", text="FIXED", value=bool, width=48, editable=False),
Attribute(name="cx", text="CX", value=float, width=48, editable=False),
Attribute(name="cy", text="CY", value=float, width=48, editable=False),
]

vertices = {}
for vertex in form.diagram.vertices():
vertices[vertex] = {}
for attr in attributes:
vertices[vertex][attr.name] = form.diagram.vertex_attribute(vertex, name=attr.name)

form = VertexAttributesForm(attributes, vertices)
if form.show():
pass

elif option == "EdgeAttributes":
attributes = [
Attribute(name="l", text="L", value=float, width=48, editable=False),
Attribute(name="q", text="Q", value=float, width=48, editable=False),
Attribute(name="f", text="F", value=float, width=48, editable=False),
Attribute(name="is_ind", text="IND", value=bool, width=48, editable=False),
]

edges = {}
for edge in form.diagram.edges():
edges[edge] = {}
for attr in attributes:
edges[edge][attr.name] = form.diagram.edge_attribute(edge, name=attr.name)

form = EdgeAttributesForm(attributes, edges)
if form.show():
pass

# =============================================================================
# Update scene
# =============================================================================

# if session.settings.autosave:
# session.record(name="Form Attributes")


# =============================================================================
# Main
# =============================================================================

if __name__ == "__main__":
RunCommand()
4 changes: 4 additions & 0 deletions compas-IGS.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
"name": "IGS_form_assign_forces",
"tooltip": "Assign forces"
},
{
"name": "IGS_form_attributes",
"tooltip": "Form Diagram Attributes"
},
{
"name": "IGS_form_check_dof",
"icon": 6,
Expand Down
11 changes: 10 additions & 1 deletion compas-IGS.rhproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"id": "ea785b43-c1c1-43da-b896-69df6c0e4b19",
"identity": {
"name": "COMPAS-IGS",
"version": "0.2.12-beta",
"version": "0.2.16-beta",
"publisher": {
"email": "tom.v.mele@gmail.com",
"name": "Tom Van Mele",
Expand Down Expand Up @@ -303,6 +303,15 @@
},
"title": "IGS_update_both",
"uri": "commands/IGS_update_both.py"
},
{
"id": "6894f5c1-6822-449c-ac0b-7139d2cca021",
"language": {
"id": "*.*.python",
"version": "3.*.*"
},
"title": "IGS_form_attributes",
"uri": "commands/IGS_form_attributes.py"
}
],
"libraries": [
Expand Down
6 changes: 6 additions & 0 deletions src/compas_igs/forms/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
from .attribute import Attribute
from .edgeforces import EdgeForcesForm
from .edgeattributes import EdgeAttributesForm
from .vertexattributes import VertexAttributesForm

__all__ = [
"Attribute",
"EdgeForcesForm",
"EdgeAttributesForm",
"VertexAttributesForm",
]
12 changes: 12 additions & 0 deletions src/compas_igs/forms/attribute.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from typing import Type

from pydantic import BaseModel


class Attribute(BaseModel):
name: str
value: Type
text: str
editable: bool = False
expand: bool = False
width: int = 0
64 changes: 10 additions & 54 deletions src/compas_igs/forms/edgeattributes.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,15 @@
#! python3
# venv: brg-csd

import ast
from typing import Any
from typing import Type

import Eto.Drawing # type: ignore
import Eto.Forms # type: ignore
import Rhino # type: ignore
import Rhino.UI # type: ignore
from pydantic import BaseModel


class Attribute(BaseModel):
name: str
value: Type
text: str
editable: bool = False
expand: bool = False
width: int = 0
from .attribute import Attribute


class EdgeAttributesForm(Eto.Forms.Dialog[bool]):
""""""

def __init__(
self,
attributes: list[Attribute],
Expand All @@ -48,6 +34,7 @@ def on_cell_formatting(sender, e):

self.table = Eto.Forms.GridView()
self.table.ShowHeader = True
self.table.GridLines = Eto.Forms.GridLines.Horizontal
self.table.CellFormatting += on_cell_formatting

# index column
Expand Down Expand Up @@ -103,19 +90,25 @@ def on_cell_formatting(sender, e):
@property
def ok(self):
self.DefaultButton = Eto.Forms.Button()
self.DefaultButton.Text = "OK1"
self.DefaultButton.Text = "OK"
self.DefaultButton.Click += self.on_ok
return self.DefaultButton

def on_ok(self, sender, event):
self.Close(True)

@property
def cancel(self):
self.AbortButton = Eto.Forms.Button()
self.AbortButton.Text = "Cancel"
self.AbortButton.Click += self.on_cancel
return self.AbortButton

def on_cancel(self, sender, event):
self.Close(False)

@property
def temp(self):
def edgedata(self):
edges = {}
for row in self.table.DataStore:
edge = ast.literal_eval(row.getValue(1))
Expand All @@ -124,42 +117,5 @@ def temp(self):
edges[edge][model.name] = ast.literal_eval(row.GetValue(2 + i))
return edges

def on_ok(self, sender, event):
self.Close(True)

def on_cancel(self, sender, event):
self.Close(False)

def show(self):
return self.ShowModal(Rhino.UI.RhinoEtoApp.MainWindow)


# =============================================================================
# Main
# =============================================================================

if __name__ == "__main__":
from compas.datastructures import Mesh

mesh = Mesh.from_meshgrid(10, 10)
mesh.update_default_edge_attributes({"q": 1.0, "f": 10, "is_ind": False})

attributes = [
Attribute(name="l", text="L", value=float, width=48),
Attribute(name="q", text="Q", value=float, width=48),
Attribute(name="f", text="F", value=float, width=48),
Attribute(name="is_ind", text="IND", value=bool, width=48),
]

edges = {}
for edge in mesh.edges():
edges[edge] = {}
for attr in attributes:
edges[edge][attr.name] = mesh.edge_attribute(edge, name=attr.name)

form = EdgeAttributesForm(attributes, edges)

if form.show():
for edge, data in form.temp.items():
for attr, value in zip(attributes, data):
print(attr.name, value)
18 changes: 18 additions & 0 deletions src/compas_igs/forms/settingsform.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# import ast
# from typing import Any
# from typing import Type

import Eto.Drawing # type: ignore
import Eto.Forms # type: ignore
import Rhino # type: ignore
import Rhino.UI # type: ignore
from pydantic import BaseModel


class SettingsForm(Eto.Forms.Dialog[bool]):
def __init__(self, model: BaseModel):
super().__init__()
self.model = model

def show(self):
return self.ShowModal(Rhino.UI.RhinoEtoApp.MainWindow)
61 changes: 9 additions & 52 deletions src/compas_igs/forms/vertexattributes.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,19 @@
#! python3
# venv: brg-csd

import ast
from typing import Any
from typing import Type

import Eto.Drawing # type: ignore
import Eto.Forms # type: ignore
import Rhino # type: ignore
import Rhino.UI # type: ignore
from pydantic import BaseModel


class Attribute(BaseModel):
name: str
value: Type
text: str
editable: bool = False
expand: bool = False
width: int = 0
from .attribute import Attribute


class VertexAttributesForm(Eto.Forms.Dialog[bool]):
""""""

def __init__(
self,
attributes: list[Attribute],
vertices: dict[tuple[int, int], Any],
vertices: dict[int, Any],
title: str = "Vertex Attributes",
width: int = 500,
height: int = 500,
Expand All @@ -48,6 +34,7 @@ def on_cell_formatting(sender, e):

self.table = Eto.Forms.GridView()
self.table.ShowHeader = True
self.table.GridLines = Eto.Forms.GridLines.Horizontal
self.table.CellFormatting += on_cell_formatting

# index column
Expand Down Expand Up @@ -107,13 +94,19 @@ def ok(self):
self.DefaultButton.Click += self.on_ok
return self.DefaultButton

def on_ok(self, sender, event):
self.Close(True)

@property
def cancel(self):
self.AbortButton = Eto.Forms.Button()
self.AbortButton.Text = "Cancel"
self.AbortButton.Click += self.on_cancel
return self.AbortButton

def on_cancel(self, sender, event):
self.Close(False)

@property
def vertexdata(self):
vertices = {}
Expand All @@ -124,41 +117,5 @@ def vertexdata(self):
vertices[vertex][model.name] = ast.literal_eval(row.GetValue(2 + i))
return vertices

def on_ok(self, sender, event):
self.Close(True)

def on_cancel(self, sender, event):
self.Close(False)

def show(self):
return self.ShowModal(Rhino.UI.RhinoEtoApp.MainWindow)


# =============================================================================
# Main
# =============================================================================

if __name__ == "__main__":
from compas.datastructures import Mesh

mesh = Mesh.from_meshgrid(10, 10)
mesh.update_default_vertex_attributes({"a": 1.0, "b": 10, "c": False})

attributes = [
Attribute(name="a", text="A", value=float, width=48),
Attribute(name="b", text="B", value=float, width=48),
Attribute(name="c", text="C", value=float, width=48),
]

vertices = {}
for vertex in mesh.vertices():
vertices[vertex] = {}
for attr in attributes:
vertices[vertex][attr.name] = mesh.vertex_attribute(vertex, name=attr.name)

form = VertexAttributesForm(attributes, vertices)

if form.show():
for vertex, data in form.vertexdata.items():
for attr, value in zip(attributes, data):
print(attr.name, value)

0 comments on commit 0859d6b

Please sign in to comment.