|
| 1 | +#! python3 |
| 2 | +# venv: timber_connections |
| 3 | +import Rhino |
| 4 | +import Rhino.Input.Custom as ric |
| 5 | +from wood_rui import wood_rui_globals, add_joinery, add_polylines, generalized_input_method, Element |
| 6 | +from wood_nano import get_connection_zones as wood_nano_get_connection_zones |
| 7 | +from wood_nano import cut_type2 as wood_nano_cut_type2 |
| 8 | +from wood_nano import point3 as wood_nano_point3 |
| 9 | +from wood_nano.conversions_python import to_int2 |
| 10 | +from wood_nano.conversions_python import to_int1 |
| 11 | +from wood_nano.conversions_python import to_double1 |
| 12 | +from wood_nano.conversions_python import from_cut_type2 |
| 13 | +from compas_wood.conversions_rhino import to_point2 |
| 14 | +from compas_wood.conversions_rhino import to_vector2 |
| 15 | +from compas_wood.conversions_rhino import from_point3 |
| 16 | +from compas_wood.binding import wood_globals |
| 17 | +from typing import List |
| 18 | + |
| 19 | +###################################################################### |
| 20 | +# Select Elements: |
| 21 | +# a) get indices and neighbors since selection is made in a random order. |
| 22 | +# b) store joints in elements. |
| 23 | +# c) create lofts and cylinders from the polyline geometry and store them in features. |
| 24 | +# d) repeat the process for side-to-end, end-to-end, and cross connections as examples. |
| 25 | +###################################################################### |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | +def solver(dataset_name: str) -> None: |
| 30 | + """ |
| 31 | + Run the solver with the selected dataset, using properties from global parameters. |
| 32 | +
|
| 33 | + Args: |
| 34 | + dataset_name (str): Name of the dataset to solve. |
| 35 | + """ |
| 36 | + |
| 37 | + w_output_plines: wood_nano_point3 = wood_nano_point3() |
| 38 | + w_output_types: wood_nano_cut_type2 = wood_nano_cut_type2() |
| 39 | + |
| 40 | + adjacency_flat_list: List[int] = [] |
| 41 | + adjacency_data: List[List[int]] = ( |
| 42 | + wood_rui_globals[dataset_name]["adjacency"] |
| 43 | + if wood_rui_globals[dataset_name]["adjacency"] |
| 44 | + else wood_rui_globals.adjacency |
| 45 | + ) |
| 46 | + |
| 47 | + for sublist in adjacency_data: |
| 48 | + for item in sublist: |
| 49 | + adjacency_flat_list.append(item) |
| 50 | + |
| 51 | + # print(wood_rui_globals[dataset_name]["joints_per_face"]) |
| 52 | + # print(wood_rui_globals[dataset_name]["three_valence"]) |
| 53 | + |
| 54 | + # select the three valence depending on the dataset dictionary property or the global property |
| 55 | + three_valence = ( |
| 56 | + wood_rui_globals[dataset_name]["three_valence"] |
| 57 | + if wood_rui_globals[dataset_name]["three_valence"] |
| 58 | + else wood_rui_globals.three_valence |
| 59 | + ) |
| 60 | + three_valence = ( |
| 61 | + wood_rui_globals[dataset_name]["three_valence"] |
| 62 | + if wood_rui_globals[dataset_name]["three_valence"] |
| 63 | + else wood_rui_globals.three_valence |
| 64 | + ) |
| 65 | + |
| 66 | + print(wood_rui_globals[dataset_name]["polylines"]) |
| 67 | + |
| 68 | + wood_nano_get_connection_zones( |
| 69 | + to_point2(wood_rui_globals[dataset_name]["polylines"]), |
| 70 | + to_vector2(wood_rui_globals[dataset_name]["insertion_vectors"]), |
| 71 | + to_int2( |
| 72 | + wood_rui_globals[dataset_name]["joints_per_face"] |
| 73 | + ), # to_int2(wood_rui_globals[dataset_name]["joints_dots"]), |
| 74 | + to_int2( |
| 75 | + three_valence |
| 76 | + ), # to_int2(wood_rui_globals[dataset_name]["three_valence_element_indices_and_instruction"]), |
| 77 | + to_int1(adjacency_flat_list), |
| 78 | + to_double1(wood_globals.joints_parameters_and_types), |
| 79 | + int(wood_rui_globals.search_type), |
| 80 | + to_double1(wood_rui_globals.scale), |
| 81 | + int(wood_globals.output_geometry_type), |
| 82 | + w_output_plines, |
| 83 | + w_output_types, |
| 84 | + to_double1(wood_rui_globals.joint_volume_extension), |
| 85 | + ) |
| 86 | + |
| 87 | + add_joinery(from_point3(w_output_plines), dataset_name) |
| 88 | + print(wood_rui_globals[dataset_name]["joinery"]) |
| 89 | + |
| 90 | + # Add joint types if the output type is 3 |
| 91 | + is_output_type_3: bool = int(wood_globals.output_geometry_type) == 3 |
| 92 | + |
| 93 | + if is_output_type_3: |
| 94 | + joint_types: List[List[int]] = from_cut_type2(w_output_types) |
| 95 | + |
| 96 | + # Before assigning the joint type, be sure to have correct number of valid joinery polylines |
| 97 | + number_added_polylines: int = 0 |
| 98 | + for i in range(len(wood_rui_globals[dataset_name]["joinery"])): |
| 99 | + number_added_polylines += len(wood_rui_globals[dataset_name]["joinery"][i]) |
| 100 | + |
| 101 | + if number_added_polylines == len(wood_rui_globals[dataset_name]["joinery_guid"]): |
| 102 | + counter: int = 0 |
| 103 | + for i, output_type in enumerate(w_output_types): |
| 104 | + for j in range(len(wood_rui_globals[dataset_name]["joinery"][i])): |
| 105 | + guid: str = wood_rui_globals[dataset_name]["joinery_guid"][counter] |
| 106 | + rhino_object: Rhino.DocObjects.RhinoObject = Rhino.RhinoDoc.ActiveDoc.Objects.Find(guid) |
| 107 | + |
| 108 | + if is_output_type_3: |
| 109 | + joint_type: int = joint_types[i][int(j * 0.5)] |
| 110 | + rhino_object.Attributes.SetUserString("joint_type", str(joint_type)) |
| 111 | + |
| 112 | + rhino_object.Attributes.SetUserString("element_id", str(i)) |
| 113 | + rhino_object.Attributes.SetUserString("face_id", str(j)) |
| 114 | + counter += 1 |
| 115 | + else: |
| 116 | + print("Number of added joinery is not equal to number joinery_guids. There are invalid polylines.") |
| 117 | + |
| 118 | + Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.Redraw() # 0 ms |
| 119 | + |
| 120 | + |
| 121 | +def my_callback( |
| 122 | + name_value_type, |
| 123 | + dataset_name, |
| 124 | +): |
| 125 | + |
| 126 | + print(name_value_type) |
| 127 | + input_elements = name_value_type["elements"] |
| 128 | + |
| 129 | + if len(input_elements) == 0: |
| 130 | + print("Attention: no elements selected.") |
| 131 | + return |
| 132 | + |
| 133 | +if __name__ == "__main__": |
| 134 | + |
| 135 | + # Define the input dictionary based on your initial dataset |
| 136 | + input_dict = { |
| 137 | + "elements" : ([], List[Element]), |
| 138 | + } |
| 139 | + |
| 140 | + # Call the generalized input method with the dataset name and input dictionary |
| 141 | + dataset_name = "beams" |
| 142 | + wood_rui_globals.init_data(dataset_name) |
| 143 | + generalized_input_method(dataset_name, input_dict, my_callback) |
| 144 | + |
| 145 | + |
| 146 | +# if __name__ == "__main__": |
| 147 | +# dataset_name: str = command_line_input() |
| 148 | +# if dataset_name: |
| 149 | +# solver(dataset_name) |
0 commit comments