Skip to content

Commit

Permalink
add forcepipes
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvanmele committed Nov 21, 2024
1 parent 0859d6b commit 4091575
Show file tree
Hide file tree
Showing 45 changed files with 505 additions and 180 deletions.
2 changes: 1 addition & 1 deletion commands/IGS.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! python3
# venv: brg-csd
# r: compas_session>=0.4.5, compas_ags>=1.3.1
# r: compas_session>=0.4.5, compas_ags>=1.3.2

import pathlib

Expand Down
47 changes: 47 additions & 0 deletions commands/IGS_check_angles.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#! python3
# venv: brg-csd
# r: compas_session>=0.4.5, compas_ags>=1.3.2

import rhinoscriptsyntax as rs # type: ignore # noqa: F401

from compas_igs.session import IGSSession
from compas_igs.utilities import compute_angle_deviations

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


def RunCommand():
session = IGSSession()

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

force = session.find_forcediagram(warn=True)
if not force:
return

max_angle = session.settings.solver.max_angle
min_force = session.settings.solver.min_force

compute_angle_deviations(form.diagram, force.diagram, tol_force=min_force)

max_dev = max(form.diagram.edges_attribute("a"))
result = max_dev <= max_angle

if not result:
message = f"Diagrams ARE NOT parallel: {max_dev} > {max_angle}"
else:
message = f"Diagrams ARE parallel: {max_dev} <= {max_angle}"

rs.MessageBox(message)


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

if __name__ == "__main__":
RunCommand()
53 changes: 53 additions & 0 deletions commands/IGS_check_equilibrium.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#! python3
# venv: brg-csd
# r: compas_session>=0.4.5, compas_ags>=1.3.2

import rhinoscriptsyntax as rs # type: ignore # noqa: F401

from compas_igs.session import IGSSession
from compas_igs.utilities import check_equilibrium

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


def RunCommand():
session = IGSSession()

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

force = session.find_forcediagram(warn=True)
if not force:
return

max_angle = session.settings.solver.max_angle
min_force = session.settings.solver.min_force
max_ldiff = session.settings.solver.max_ldiff

result = check_equilibrium(
form.diagram,
force.diagram,
tol_angle=max_angle,
tol_force=min_force,
tol_ldiff=max_ldiff,
)

# max_dev = max(form.diagram.edges_attribute("a"))

if not result:
message = "Diagrams ARE NOT in equilibrium."
else:
message = "Diagrams ARE in equilibrium."

rs.MessageBox(message)


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

if __name__ == "__main__":
RunCommand()
8 changes: 5 additions & 3 deletions commands/IGS_force_from_form.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! python3
# venv: brg-csd
# r: compas_session>=0.4.5, compas_ags>=1.3.1
# r: compas_session>=0.4.5, compas_ags>=1.3.2

import rhinoscriptsyntax as rs # type: ignore # noqa: F401

Expand Down Expand Up @@ -70,11 +70,13 @@ def RunCommand():

drawingscale = compute_force_drawingscale(form, force) # scale factor for the diagram
drawinglocation = compute_force_drawinglocation(form, force) # translation of the diagram

# forcescale = compute_form_forcescale(form) # thickness
forcescale = compute_form_forcescale(form) # thickness

force.scale = drawingscale
force.location = drawinglocation
form.scale_internal_forcepipes = forcescale

form.show_internal_forcepipes = True

session.scene.redraw()

Expand Down
5 changes: 2 additions & 3 deletions commands/IGS_force_move.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! python3
# venv: brg-csd
# r: compas_session>=0.4.5, compas_ags>=1.3.1
# r: compas_session>=0.4.5, compas_ags>=1.3.2

import rhinoscriptsyntax as rs # type: ignore # noqa: F401

Expand Down Expand Up @@ -28,8 +28,7 @@ def RunCommand():
# move to update_location_from_current_anchorpoint
vertex_guid = {v: k for k, v in force._guid_vertex.items()}
guid = vertex_guid[force.anchor]
rpoint = compas_rhino.objects.get_point_coordinates([guid])[0]
point = compas_rhino.conversions.point_to_compas(rpoint)
point = compas_rhino.conversions.pointobject_to_compas(guid)
force.location = point

force.redraw()
Expand Down
38 changes: 23 additions & 15 deletions commands/IGS_force_move_nodes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! python3
# venv: brg-csd
# r: compas_session>=0.4.5, compas_ags>=1.3.1
# r: compas_session>=0.4.5, compas_ags>=1.3.2

import rhinoscriptsyntax as rs # type: ignore # noqa: F401

Expand All @@ -25,36 +25,44 @@ def RunCommand():
if not force:
return

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

# include in while loop

selected = force.select_vertices()
selected = force.select_vertices_manual()
if not selected:
return

if force.move_vertices(selected):
force.redraw()

if session.settings.autoupdate:
max_angle = session.settings.ags.max_angle
min_force = session.settings.ags.min_force

form_update_from_force(form.diagram, force.diagram)
form.redraw()

# compute and check angle deviations
# =============================================================================
# Check equilibrium
# =============================================================================

# max_angle = session.settings.solver.max_angle
# min_force = session.settings.solver.min_force

compute_angle_deviations(form.diagram, force.diagram, tol_force=min_force)
check = check_equilibrium(form.diagram, force.diagram, tol_angle=max_angle, tol_force=min_force)
deviation = max(form.diagram.edges_attribute("a"))
# compute_angle_deviations(form.diagram, force.diagram, tol_force=min_force)
# check = check_equilibrium(form.diagram, force.diagram, tol_angle=max_angle, tol_force=min_force)
# deviation = max(form.diagram.edges_attribute("a"))

if check:
message = f"Diagrams are parallel!\nMax. angle deviation: {deviation:.2g} deg\nThreshold assumed: {max_angle:.2g} deg."
else:
message = f"Diagrams are not parallel!\nMax. angle deviation: {deviation:.2g} deg\nThreshold assumed: {max_angle:.2g} deg."
# if check:
# message = f"Diagrams are parallel!\nMax. angle deviation: {deviation:.2g} deg\nThreshold assumed: {max_angle:.2g} deg."
# else:
# message = f"Diagrams are not parallel!\nMax. angle deviation: {deviation:.2g} deg\nThreshold assumed: {max_angle:.2g} deg."

rs.MessageBox(message, title="Info")
# rs.MessageBox(message, title="Info")

print(force.show_vertices)
# =============================================================================
# Update scene
# =============================================================================

session.scene.redraw()

Expand Down
2 changes: 1 addition & 1 deletion commands/IGS_force_scale.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! python3
# venv: brg-csd
# r: compas_session>=0.4.5, compas_ags>=1.3.1
# r: compas_session>=0.4.5, compas_ags>=1.3.2

import rhinoscriptsyntax as rs # type: ignore # noqa: F401

Expand Down
10 changes: 9 additions & 1 deletion commands/IGS_force_select_anchor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! python3
# venv: brg-csd
# r: compas_session>=0.4.5, compas_ags>=1.3.1
# r: compas_session>=0.4.5, compas_ags>=1.3.2

import rhinoscriptsyntax as rs # type: ignore # noqa: F401

Expand All @@ -24,6 +24,10 @@ def RunCommand():
if not force:
return

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

vertex = force.select_anchor()
if vertex is None:
return
Expand All @@ -37,6 +41,10 @@ def RunCommand():
point = compas_rhino.conversions.point_to_compas(rpoint)
force.location = point

# =============================================================================
# Update Scene
# =============================================================================

rs.UnselectAllObjects()

session.scene.redraw()
Expand Down
2 changes: 1 addition & 1 deletion commands/IGS_force_select_fixed.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! python3
# venv: brg-csd
# r: compas_session>=0.4.5, compas_ags>=1.3.1
# r: compas_session>=0.4.5, compas_ags>=1.3.2

import rhinoscriptsyntax as rs # type: ignore # noqa: F401

Expand Down
2 changes: 1 addition & 1 deletion commands/IGS_force_update.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! python3
# venv: brg-csd
# r: compas_session>=0.4.5, compas_ags>=1.3.1
# r: compas_session>=0.4.5, compas_ags>=1.3.2

import rhinoscriptsyntax as rs # type: ignore # noqa: F401

Expand Down
53 changes: 44 additions & 9 deletions commands/IGS_form.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#! python3
# venv: brg-csd
# r: compas_session>=0.4.5, compas_ags>=1.3.1
# r: compas_session>=0.4.5, compas_ags>=1.3.2

import pathlib

import rhinoscriptsyntax as rs # type: ignore

from compas_igs.commands.form import create_from_lines
from compas_igs.commands.form import create_from_meshgrid
from compas_igs.commands.form import create_from_obj
import compas_rhino.objects
from compas_ags.diagrams import FormDiagram
from compas_ags.diagrams import FormGraph
from compas_igs.session import IGSSession
from compas_rui.forms import FileForm

# =============================================================================
# Command
Expand All @@ -27,18 +30,50 @@ def RunCommand():
# Create form diagram
# =============================================================================

option = rs.GetString(message="FormDiagram From", strings=["RhinoLines", "MeshGrid", "OBJ"])
option = rs.GetString(message="FormDiagram From", strings=["RhinoLines", "OBJ"])
if not option:
return

if option == "RhinoLines":
formdiagram = create_from_lines()
guids = compas_rhino.objects.select_lines()
if not guids:
return

elif option == "MeshGrid":
formdiagram = create_from_meshgrid()
lines = compas_rhino.objects.get_line_coordinates(guids)
graph = FormGraph.from_lines(lines)

if not graph.is_planar_embedding():
return rs.MessageBox(
message="The graph is not planar. Therefore, a form diagram cannot be created.",
title="Create FormDiagram Error",
)

formdiagram = FormDiagram.from_graph(graph)

elif option == "OBJ":
formdiagram = create_from_obj(session.basedir)
filepath = FileForm.open(session.basedir)
if not filepath:
return

filepath = pathlib.Path(filepath)
if not filepath.suffix == ".obj":
return rs.MessageBox(
message="The file is not an OBJ file.",
title="Error FormDiagram",
)

graph = FormGraph.from_obj(filepath)

if not graph.is_planar_embedding():
return rs.MessageBox(
message="The graph is not planar. Therefore, a form diagram cannot be created.",
title="Create FormDiagram Error",
)

formdiagram = FormDiagram.from_graph(graph)

elif option == "MeshGrid":
raise NotImplementedError

else:
raise NotImplementedError
Expand Down
2 changes: 1 addition & 1 deletion commands/IGS_form_assign_forces.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! python3
# venv: brg-csd
# r: compas_session>=0.4.5, compas_ags>=1.3.1
# r: compas_session>=0.4.5, compas_ags>=1.3.2

import rhinoscriptsyntax as rs # type: ignore

Expand Down
8 changes: 4 additions & 4 deletions commands/IGS_form_attributes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! python3
# venv: brg-csd
# r: compas_session>=0.4.5, compas_ags>=1.3.1
# r: compas_session>=0.4.5, compas_ags>=1.3.2

import rhinoscriptsyntax as rs # type: ignore

Expand Down Expand Up @@ -51,9 +51,9 @@ def RunCommand():

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="l", text="L", value=float, width=64, editable=False),
Attribute(name="q", text="Q", value=float, width=64, editable=False),
Attribute(name="f", text="F", value=float, width=64, editable=False),
Attribute(name="is_ind", text="IND", value=bool, width=48, editable=False),
]

Expand Down
2 changes: 1 addition & 1 deletion commands/IGS_form_check_dof.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! python3
# venv: brg-csd
# r: compas_session>=0.4.5, compas_ags>=1.3.1
# r: compas_session>=0.4.5, compas_ags>=1.3.2

import rhinoscriptsyntax as rs # type: ignore # noqa: F401

Expand Down
2 changes: 1 addition & 1 deletion commands/IGS_form_compute_loadpath.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! python3
# venv: brg-csd
# r: compas_session>=0.4.5, compas_ags>=1.3.1
# r: compas_session>=0.4.5, compas_ags>=1.3.2

import rhinoscriptsyntax as rs # type: ignore # noqa: F401

Expand Down
Loading

0 comments on commit 4091575

Please sign in to comment.