Skip to content

Commit

Permalink
Tested Linted Formatted with Videos
Browse files Browse the repository at this point in the history
  • Loading branch information
obucklin committed Mar 8, 2024
1 parent 0c9cfba commit f89fac3
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 230 deletions.
4 changes: 1 addition & 3 deletions src/compas_timber/connections/l_halflap.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ def add_features(self):

extension_tolerance = 0.01 # TODO: this should be proportional to the unit used
self.beam_a.add_blank_extension(start_main + extension_tolerance, end_main + extension_tolerance, self.key)
self.beam_b.add_blank_extension(
start_cross + extension_tolerance, end_cross + extension_tolerance, self.key
)
self.beam_b.add_blank_extension(start_cross + extension_tolerance, end_cross + extension_tolerance, self.key)

self.beam_a.add_features(MillVolume(negative_brep_beam_a))
self.beam_b.add_features(MillVolume(negative_brep_beam_b))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,78 +1,68 @@
from ghpythonlib.componentbase import executingcomponent as component
from Grasshopper.Kernel.GH_RuntimeMessageLevel import Warning
import clr
import System
import inspect

from compas_timber.connections import Joint
from compas_timber.ghpython.ghcomponent_helpers import manage_dynamic_params
from compas_timber.ghpython.ghcomponent_helpers import get_all_subclasses
from compas_timber.ghpython.ghcomponent_helpers import get_leaf_subclasses
from compas_timber.ghpython.ghcomponent_helpers import rename_GH_output
from compas_timber.ghpython import CategoryRule


class CategoryJointRule(component):
def __init__(self):
super(CategoryJointRule, self).__init__()
self.classes = {}
for cls in get_all_subclasses(Joint):
self.classes = {}
for cls in get_leaf_subclasses(Joint):
self.classes[cls.__name__] = cls
self.items = []
self.joint_type = None
self.joint_name = None

if ghenv.Component.Params.Output[0].NickName == "Rule":
self.joint_type = None
else:
self.joint_type = self.classes.get(ghenv.Component.Params.Output[0].NickName, None)

def RunScript(self, *args):
if not self.joint_type:
ghenv.Component.Message = "Select joint type from context menu (right click)"
self.AddRuntimeMessage(Warning, "Select joint type from context menu (right click)")
return None
else:
ghenv.Component.Message = self.joint_name
ghenv.Component.Message = self.joint_type.__name__
cat_a = args[0]
cat_b = args[1]

kwargs = {}
for i, val in enumerate(args[2:]):
if val:
kwargs[self.arg_names()[i+2]] = val
kwargs[self.arg_names()[i + 2]] = val
print(kwargs)
if not cat_a:
self.AddRuntimeMessage(Warning, "Input parameter {} failed to collect data.".format(self.arg_names()[0]))
self.AddRuntimeMessage(
Warning, "Input parameter {} failed to collect data.".format(self.arg_names()[0])
)
if not cat_b:
self.AddRuntimeMessage(Warning, "Input parameter {} failed to collect data.".format(self.arg_names()[1]))
self.AddRuntimeMessage(
Warning, "Input parameter {} failed to collect data.".format(self.arg_names()[1])
)
if not (cat_a and cat_b):
return

return CategoryRule(self.joint_type, cat_a, cat_b, **kwargs)


def arg_names(self):
names = inspect.getargspec(self.joint_type.__init__)[0][1:]
for i in range(2):
names[i] += " category"
return [name for name in names if (name != 'key') and (name != 'frame')]

return [name for name in names if (name != "key") and (name != "frame")]

def AppendAdditionalMenuItems(self, menu):
if self.items:
for item in self.items:
menu.Items.Add(item)
else:
for name in self.classes.keys():
item = menu.Items.Add(name, None, self.on_item_click)
self.items.append(item)

for name in self.classes.keys():
item = menu.Items.Add(name, None, self.on_item_click)
if self.joint_type and name == self.joint_type.__name__:
item.Checked = True

def on_item_click(self, sender, event_info):
active_item = clr.Convert(sender, System.Windows.Forms.ToolStripItem)
active_item.Checked = True

for item in self.items:
if str(item) != str(sender):
item.Checked = False

self.joint_name = str(sender)
self.joint_type = self.classes[self.joint_name]

manage_dynamic_params(self.arg_names(), ghenv, rename_count = 2, permanent_param_count = 0)
self.joint_type = self.classes[str(sender)]
rename_GH_output(self.joint_type.__name__, 0, ghenv)
manage_dynamic_params(self.arg_names(), ghenv, rename_count=2, permanent_param_count=0)
ghenv.Component.ExpireSolution(True)
64 changes: 27 additions & 37 deletions src/compas_timber/ghpython/components/CT_Joint_Rule_Direct/code.py
Original file line number Diff line number Diff line change
@@ -1,57 +1,63 @@
from ghpythonlib.componentbase import executingcomponent as component
from Grasshopper.Kernel.GH_RuntimeMessageLevel import Error
from Grasshopper.Kernel.GH_RuntimeMessageLevel import Warning
import clr
import System
import inspect
import itertools


from compas_timber.connections import Joint
from compas_timber.connections import ConnectionSolver
from compas_timber.connections import JointTopology

from compas_timber.ghpython.ghcomponent_helpers import manage_dynamic_params
from compas_timber.ghpython.ghcomponent_helpers import get_all_subclasses
from compas_timber.ghpython.ghcomponent_helpers import get_leaf_subclasses
from compas_timber.ghpython.ghcomponent_helpers import rename_GH_output
from compas_timber.ghpython import DirectRule


class DirectJointRule(component):
def __init__(self):
super(DirectJointRule, self).__init__()
self.classes = {}
for cls in get_all_subclasses(Joint):
self.classes = {}
for cls in get_leaf_subclasses(Joint):
self.classes[cls.__name__] = cls
self.items = []
self.joint_type = None
self.joint_name = None

if ghenv.Component.Params.Output[0].NickName == "Rule":
self.joint_type = None
else:
self.joint_type = self.classes.get(ghenv.Component.Params.Output[0].NickName, None)

def RunScript(self, *args):
if not self.joint_type:
ghenv.Component.Message = "Select joint type from context menu (right click)"
self.AddRuntimeMessage(Warning, "Select joint type from context menu (right click)")
return None
else:
ghenv.Component.Message = self.joint_name
ghenv.Component.Message = self.joint_type.__name__
beam_a = args[0]
beam_b = args[1]
kwargs = {}
for i, val in enumerate(args[2:]):
if val:
kwargs[self.arg_names()[i+2]] = val
kwargs[self.arg_names()[i + 2]] = val

if not beam_a:
self.AddRuntimeMessage(Warning, "Input parameter {} failed to collect data.".format(self.arg_names()[0]))
self.AddRuntimeMessage(
Warning, "Input parameter {} failed to collect data.".format(self.arg_names()[0])
)
if not beam_b:
self.AddRuntimeMessage(Warning, "Input parameter {} failed to collect data.".format(self.arg_names()[1]))
self.AddRuntimeMessage(
Warning, "Input parameter {} failed to collect data.".format(self.arg_names()[1])
)
if not (args[0] and args[1]):
return
if not isinstance(beam_a, list):
beam_a = [beam_a]
if not isinstance(beam_b, list):
beam_b = [beam_b]
if len(beam_a) != len(beam_b):
self.AddRuntimeMessage(Error, "Number of items in {} and {} must match!".format(self.arg_names()[0], self.arg_names()[1]))
self.AddRuntimeMessage(
Error, "Number of items in {} and {} must match!".format(self.arg_names()[0], self.arg_names()[1])
)
return
Rules = []
for main, secondary in zip(beam_a, beam_b):
Expand All @@ -66,33 +72,17 @@ def RunScript(self, *args):
Rules.append(DirectRule(self.joint_type, [secondary, main], **kwargs))
return Rules


def arg_names(self):
return inspect.getargspec(self.joint_type.__init__)[0][1:]

def AppendAdditionalMenuItems(self, menu):
if self.items:
for item in self.items:
menu.Items.Add(item)
else:
for name in self.classes.keys():
item = menu.Items.Add(name, None, self.on_item_click)
self.items.append(item)

for name in self.classes.keys():
item = menu.Items.Add(name, None, self.on_item_click)
if self.joint_type and name == self.joint_type.__name__:
item.Checked = True

def on_item_click(self, sender, event_info):
active_item = clr.Convert(sender, System.Windows.Forms.ToolStripItem)
active_item.Checked = True

for item in self.items:
if str(item) != str(sender):
item.Checked = False

self.joint_name = str(sender)

self.joint_type = self.classes[self.joint_name]


manage_dynamic_params(self.arg_names(), ghenv, rename_count = 2, permanent_param_count = 0)

self.joint_type = self.classes[str(sender)]
rename_GH_output(self.joint_type.__name__, 0, ghenv)
manage_dynamic_params(self.arg_names(), ghenv, rename_count=2, permanent_param_count=0)
ghenv.Component.ExpireSolution(True)
Original file line number Diff line number Diff line change
@@ -1,77 +1,55 @@

from ghpythonlib.componentbase import executingcomponent as component
from Grasshopper.Kernel.GH_RuntimeMessageLevel import Warning
import clr
import System
import inspect

from compas_timber.connections import Joint
from compas_timber.ghpython.ghcomponent_helpers import manage_dynamic_params
from compas_timber.ghpython.ghcomponent_helpers import get_all_subclasses
from compas_timber.ghpython import CategoryRule
from compas_timber.ghpython.ghcomponent_helpers import get_leaf_subclasses
from compas_timber.ghpython.ghcomponent_helpers import rename_GH_output

from compas_timber.connections import Joint
from compas_timber.connections import JointTopology
from compas_timber.ghpython import TopologyRule

from compas_timber.connections import LMiterJoint

from compas_timber.ghpython import TopologyRule


class L_TopologyJointRule(component):
def __init__(self):
super(L_TopologyJointRule, self).__init__()
self.classes = {}
for cls in get_all_subclasses(Joint):
self.classes[cls.__name__] = cls
self.items = []
self.joint_type = None
self.joint_name = 'LMiterJoint'
self.classes = {}
for cls in get_leaf_subclasses(Joint):
if cls.SUPPORTED_TOPOLOGY == JointTopology.TOPO_L:
self.classes[cls.__name__] = cls
self.joint_type = LMiterJoint
self.clicked = False


def RunScript(self, *args):
if not self.clicked:
ghenv.Component.Message = "Default: LMiterJoint"
self.AddRuntimeMessage(Warning, "LMiterJoint is default, change in context menu (right click)")
return (TopologyRule(JointTopology.TOPO_L, LMiterJoint))
return TopologyRule(JointTopology.TOPO_L, LMiterJoint)
else:
ghenv.Component.Message = self.joint_name
ghenv.Component.Message = self.joint_type.__name__
kwargs = {}
for i, val in enumerate(args[2:]):
for i, val in enumerate(args):
if val:
kwargs[self.arg_names()[i+2]] = val
kwargs[self.arg_names()[i]] = val
if self.joint_type.SUPPORTED_TOPOLOGY != JointTopology.TOPO_L:
self.AddRuntimeMessage(Warning, "Joint type does not match topology. Joint may not be generated.")
return (TopologyRule(JointTopology.TOPO_L, self.joint_type, **kwargs))

return TopologyRule(JointTopology.TOPO_L, self.joint_type, **kwargs)

def arg_names(self):
names = inspect.getargspec(self.joint_type.__init__)[0][3:]
return [name for name in names if (name != 'key') and (name != 'frame')]

return [name for name in names if (name != "key") and (name != "frame")]

def AppendAdditionalMenuItems(self, menu):
if self.items:
for item in self.items:
menu.Items.Add(item)
else:
for name in self.classes.keys():
item = menu.Items.Add(name, None, self.on_item_click)
if name == "LMiterJoint":
item.Checked = True
self.items.append(item)

for name in self.classes.keys():
item = menu.Items.Add(name, None, self.on_item_click)
if self.joint_type and name == self.joint_type.__name__:
item.Checked = True

def on_item_click(self, sender, event_info):
active_item = clr.Convert(sender, System.Windows.Forms.ToolStripItem)
active_item.Checked = True
self.clicked = True
for item in self.items:
if str(item) != str(sender):
item.Checked = False

self.joint_name = str(sender)
self.joint_type = self.classes[self.joint_name]

manage_dynamic_params(self.arg_names(), ghenv, rename_count = 0, permanent_param_count = 0)
self.joint_type = self.classes[str(sender)]
rename_GH_output(self.joint_type.__name__, 0, ghenv)
manage_dynamic_params(self.arg_names(), ghenv, rename_count=0, permanent_param_count=0)
ghenv.Component.ExpireSolution(True)
Loading

0 comments on commit f89fac3

Please sign in to comment.