-
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
14 changed files
with
162 additions
and
62 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
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
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
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
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
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
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
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
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
69 changes: 65 additions & 4 deletions
69
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,9 +1,70 @@ | ||
from ghpythonlib.componentbase import executingcomponent as component | ||
from Grasshopper.Kernel.GH_RuntimeMessageLevel import Error | ||
from Grasshopper.Kernel.GH_RuntimeMessageLevel import Warning | ||
import Grasshopper | ||
|
||
from compas_timber.ghpython import CategoryRule | ||
|
||
|
||
class CategoryJointRule(component): | ||
def RunScript(self, JointOptions, CatA, CatB): | ||
if JointOptions and CatA and CatB: | ||
return CategoryRule(JointOptions.type, CatA, CatB, **JointOptions.kwargs) | ||
def AddParam(name, IO, list = True): | ||
assert IO in ('Output', 'Input') | ||
params = [param.NickName for param in getattr(ghenv.Component.Params,IO)] | ||
if name not in params: | ||
param = Grasshopper.Kernel.Parameters.Param_GenericObject() | ||
param.NickName = name + " category" | ||
param.Name = name | ||
param.Description = name | ||
param.Access = Grasshopper.Kernel.GH_ParamAccess.item | ||
param.Optional = True | ||
index = getattr(ghenv.Component.Params, IO).Count | ||
registers = dict(Input = 'RegisterInputParam' | ||
,Output = 'RegisterOutputParam' | ||
) | ||
getattr(ghenv.Component.Params,registers[IO])(param, index) | ||
ghenv.Component.Params.OnParametersChanged() | ||
return param | ||
|
||
class DirectJointRule(component): | ||
def __init__(self): | ||
self.joint_type = None | ||
|
||
def ClearParams(self): | ||
while len(ghenv.Component.Params.Input)>1: | ||
ghenv.Component.Params.UnregisterInputParameter(ghenv.Component.Params.Input[len(ghenv.Component.Params.Input)-1]) | ||
ghenv.Component.Params.OnParametersChanged() | ||
ghenv.Component.ExpireSolution(True) | ||
|
||
|
||
def RunScript(self, JointOptions, *args): | ||
if not JointOptions: #if no JointOptions is input | ||
print("no joint") | ||
self.ClearParams() | ||
self.joint_type = None | ||
return | ||
|
||
if JointOptions.type != self.joint_type: # if JointOptions changes | ||
if len(JointOptions.beam_names) != 2: | ||
self.AddRuntimeMessage(Error, "Component currently only supports joint types with 2 beams.") | ||
self.ClearParams() | ||
self.joint_type = JointOptions.type | ||
for name in JointOptions.beam_names: | ||
AddParam(name, "Input") | ||
|
||
if len(ghenv.Component.Params.Input) != 3: # something went wrong and the number of input parameters is wrong | ||
self.AddRuntimeMessage(Warning, "Input parameter error.") | ||
return | ||
|
||
if len(args) < 2: | ||
self.AddRuntimeMessage(Warning, "Input parameters failed to collect data.") | ||
return | ||
categories = [] | ||
create_rule = True | ||
for i in range(len(ghenv.Component.Params.Input)-1): | ||
if not args[i]: | ||
self.AddRuntimeMessage(Warning, "Input parameter {} {} failed to collect data.".format(JointOptions.beam_names[i], 'categories')) | ||
create_rule = False | ||
else: | ||
categories.append(args[i]) | ||
|
||
if create_rule: | ||
return CategoryRule(JointOptions.type, categories[0], categories[1], **JointOptions.kwargs) |
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
105 changes: 80 additions & 25 deletions
105
src/compas_timber/ghpython/components/CT_Joint_Rule_Direct/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,37 +1,92 @@ | ||
from ghpythonlib.componentbase import executingcomponent as component | ||
from Grasshopper.Kernel.GH_RuntimeMessageLevel import Error | ||
from Grasshopper.Kernel.GH_RuntimeMessageLevel import Warning | ||
import Grasshopper | ||
|
||
from compas_timber.connections import ConnectionSolver | ||
from compas_timber.connections import JointTopology | ||
from compas_timber.ghpython import DirectRule | ||
|
||
|
||
def AddParam(name, IO, list = True): | ||
assert IO in ('Output', 'Input') | ||
params = [param.NickName for param in getattr(ghenv.Component.Params,IO)] | ||
if name not in params: | ||
param = Grasshopper.Kernel.Parameters.Param_GenericObject() | ||
param.NickName = name | ||
param.Name = name | ||
param.Description = name | ||
param.Access = Grasshopper.Kernel.GH_ParamAccess.list | ||
param.Optional = True | ||
index = getattr(ghenv.Component.Params, IO).Count | ||
registers = dict(Input = 'RegisterInputParam' | ||
,Output = 'RegisterOutputParam' | ||
) | ||
getattr(ghenv.Component.Params,registers[IO])(param, index) | ||
ghenv.Component.Params.OnParametersChanged() | ||
return param | ||
|
||
|
||
|
||
|
||
class DirectJointRule(component): | ||
def RunScript(self, JointOptions, MainBeam, SecondaryBeam): | ||
if not MainBeam: | ||
self.AddRuntimeMessage(Warning, "Input parameter MainBeams failed to collect data.") | ||
if not SecondaryBeam: | ||
self.AddRuntimeMessage(Warning, "Input parameter CrossBeams failed to collect data.") | ||
if not (MainBeam and SecondaryBeam): | ||
def __init__(self): | ||
self.joint_type = None | ||
|
||
def ClearParams(self): | ||
while len(ghenv.Component.Params.Input)>1: | ||
ghenv.Component.Params.UnregisterInputParameter(ghenv.Component.Params.Input[len(ghenv.Component.Params.Input)-1]) | ||
ghenv.Component.Params.OnParametersChanged() | ||
|
||
|
||
def RunScript(self, JointOptions, *args): | ||
if not JointOptions: #if no JointOptions is input | ||
self.ClearParams() | ||
self.joint_type = None | ||
return | ||
if not isinstance(MainBeam, list): | ||
MainBeam = [MainBeam] | ||
if not isinstance(SecondaryBeam, list): | ||
SecondaryBeam = [SecondaryBeam] | ||
if len(MainBeam) != len(SecondaryBeam): | ||
self.AddRuntimeMessage(Error, "Number of items in MainBeams and CrossBeams must match!") | ||
|
||
if JointOptions.type != self.joint_type: # if JointOptions changes | ||
if len(JointOptions.beam_names) != 2: | ||
self.AddRuntimeMessage(Error, "Component currently only supports joint types with 2 beams.") | ||
self.ClearParams() | ||
self.joint_type = JointOptions.type | ||
for name in JointOptions.beam_names: | ||
AddParam(name, "Input") | ||
|
||
if len(ghenv.Component.Params.Input) != 3: | ||
self.AddRuntimeMessage(Warning, "Input parameter error.") | ||
return | ||
|
||
if len(args) < 2: | ||
self.AddRuntimeMessage(Warning, "Input parameters failed to collect data.") | ||
return | ||
Rules = [] | ||
for main, secondary in zip(MainBeam, SecondaryBeam): | ||
topology, _, _ = ConnectionSolver().find_topology(main, secondary) | ||
if topology != JointOptions.type.SUPPORTED_TOPOLOGY: | ||
self.AddRuntimeMessage( | ||
Warning, | ||
"Beams meet with topology: {} which does not agree with joint of type: {}".format( | ||
JointTopology.get_name(topology), JointOptions.type.__name__ | ||
), | ||
) | ||
continue | ||
Rules.append(DirectRule(JointOptions.type, [secondary, main], **JointOptions.kwargs)) | ||
return Rules | ||
|
||
beams = [] | ||
create_rule = True | ||
for i in range(len(ghenv.Component.Params.Input)-1): | ||
if not args[i]: | ||
self.AddRuntimeMessage(Warning, "Input parameter {} failed to collect data.".format(JointOptions.beam_names[i])) | ||
create_rule = False | ||
else: | ||
arg_beams= args[i] | ||
if not isinstance(arg_beams, list): | ||
arg_beams = [arg_beams] | ||
beams.append(arg_beams) | ||
|
||
if create_rule: | ||
if len(beams[0]) != len(beams[1]): | ||
self.AddRuntimeMessage(Error, "Number of items in {} and {} must match!".format(JointOptions.beam_names[0], JointOptions.beam_names[1])) | ||
return | ||
Rules = [] | ||
for main, secondary in zip(beams[0], beams[1]): | ||
topology, _, _ = ConnectionSolver().find_topology(main, secondary) | ||
if topology != JointOptions.type.SUPPORTED_TOPOLOGY: | ||
self.AddRuntimeMessage( | ||
Warning, | ||
"Beams meet with topology: {} which does not agree with joint of type: {}".format( | ||
JointTopology.get_name(topology), JointOptions.type.__name__ | ||
), | ||
) | ||
continue | ||
Rules.append(DirectRule(JointOptions.type, [main, secondary], **JointOptions.kwargs)) | ||
return Rules |
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
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