-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
168 additions
and
230 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 24 additions & 34 deletions
58
src/compas_timber/ghpython/components/CT_Joint_Rule_Category/code.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 22 additions & 44 deletions
66
src/compas_timber/ghpython/components/CT_Joint_Rule_Topology_L/code.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.