Loading build.py +1 −2 Original line number Diff line number Diff line Loading @@ -96,11 +96,10 @@ def write_ninja_file(build_dir): writer.openscad("nut_trap_test.stl", "test_pieces/nut_trap_test.scad") writer.openscad("leg_test.stl", "test_pieces/leg_test.scad") writer.openscad("rms_thread.stl", "test_pieces/rms_thread.scad") open_v_string = ["Open", "Actuators"] writer.openscad( "test_pieces/main_body_open_actuators.stl", "test_pieces/main_body_open_actuators.scad", {"VERSION_STRING": open_v_string, "HASH": commit_str} {"VERSION_STRING": version_str, "HASH": commit_str} ) writer.openscad("test_pieces/feet_open_slot.stl","test_pieces/feet_open_slot.scad") Loading build_system/util.py +20 −2 Original line number Diff line number Diff line Loading @@ -59,9 +59,12 @@ def version_string(force_clean, check_env=True): The version string for the microscope. """ if check_env: # First check environment vars for CI version string ci_version_string = os.getenv("CI_VERSION_STRING", None) if ci_version_string is not None: return ci_version_string # Set to custom if not clean if not _repo_is_clean(): if force_clean: print("Warning! Git repository is not clean:") Loading @@ -70,16 +73,31 @@ def version_string(force_clean, check_env=True): sys.exit(1) return "Custom" # Next priority is the tag. tag = _get_commit_tag() if _is_release(tag): return tag # Next priority is pipeline ID if in a merged_result pipeline event_type = os.getenv("CI_MERGE_REQUEST_EVENT_TYPE", None) print(f"Merge Event Type: {event_type}") pipeline_id = os.getenv("CI_PIPELINE_ID", None) if pipeline_id is None: print(f"Pipeline ID: {pipeline_id}") # If we are in a merged result pipeline then the hash isn't in the repo. if event_type == "merged_result" and pipeline_id is not None: # Pint the pipeline id on the main body if len(pipeline_id) <= 10: return f"Pipeline\\n{pipeline_id}" # With a fallback in case the ids get longer return f"Pipe {pipeline_id[0:2]}-\\n{pipeline_id[2:]}" # Finally use hash (unless it is None) commit_hash = _get_commit_hash() if commit_hash is None: if force_clean: sys.exit(1) return "Custom" return ["Pipeline", pipeline_id[0:10]] return commit_hash[0:7] def commit_string(force_clean, check_env=True): """ Loading openscad/libs/main_body_structure.scad +10 −5 Original line number Diff line number Diff line use <./utilities.scad> use <./string_utils.scad> use <./compact_nut_seat.scad> use <./logo.scad> use <./z_axis.scad> Loading Loading @@ -754,14 +755,18 @@ module xy_only_body(params){ /*This module creates the main body of the microscope, including the positioning mechanism. :param params: microscope parameters dictionary :param version_string: string or list of two strings. :param version_string: string of 1 or 2 lines. Placed on the outer wall of the main body, under the open hardware logo :param hash: string. placed on the inner wall of the main body */ module main_body(params, version_string, hash){ // If version_string is a string, make it into a list, so that version_string_list[0] // gives the whole string, not the first letter, and version_string_list[1] is empty version_string_list = (is_string(version_string)) ? [version_string] : version_string; // Split version_string into a list by line version_string_list = split_string_lines(version_string); // Check the list isn't longer than 2 lines (will error already if empty) assert(len(version_string_list) <= 2, "Can only have 1 or 2 lines in a version string."); // Get the lines and use "" as a fallback for line 2 if only 1 line is provided. version_line1 = version_string_list[0]; version_line2 = len(version_string_list) == 1 ? "" : version_string_list[1]; difference(){ xy_positioning_system(params); Loading @@ -777,6 +782,6 @@ module main_body(params, version_string, hash){ difference(){ actuator_walls_and_z_casing(params, z_axis=true); body_logos(params, version_string_list[0],version_string_list[1]); body_logos(params, version_line1, version_line2); } } openscad/libs/string_utils.scad 0 → 100644 +62 −0 Original line number Diff line number Diff line /* A collection of string utilities for OpenSCAD. These functions provide basic string manipulation features that are not available natively in stable OpenSCAD. */ // SPDX-License-Identifier: CERN-OHL-S-2.0 // For copyright and authorship information, see the Git history at: // https://gitlab.com/openflexure/openflexure-microscope /* Concatenate a list of strings into a single string. This function reduces the list recursively, concatenating pairs of elements until a single string remains. :param input: A list of strings :return: A single string formed by concatenating all elements of `input` */ function str_cat(input) = // Empty list becomes "" len(input) == 0 ? "" : // Single element is coerced into a string and output len(input) == 1 ? str(input[0]) : // 2 elements are concatedated as strings len(input) == 2 ? str(input[0], input[1]) : // Greater then than 2 elements, the first 2 strings in the list are // combined, then recursively recall this function. str_cat( concat( [str(input[0], input[1])], [for (i = [2:len(input)-1]) input[i]] ) ); /* Return a substring using inclusive start and end indices. No bounds checking is performed. Supplying indices outside the valid range may result in undefined behaviour. :param string: The source string :param start: Starting index (inclusive, zero-based) :param end: Ending index (inclusive, zero-based) :return: The substring from `start` to `end` */ function sub_str(string, start, end) = str_cat([ for (i = [start:end]) string[i] ]); /* Split a multi-line string into a list of one-line strings. :param string: The input string :return: A list of strings, one per line */ function split_string_lines(string) = let( // get position of any \n pos = search("\n", string, 0)[0], s_pos = concat([0], [for (p=pos) p+1]), e_pos = concat( [for (p=pos) p-1], len(string)-1) ) [for (i = [0:len(pos)]) sub_str(string, s_pos[i], e_pos[i])]; openscad/main_body.scad +1 −1 Original line number Diff line number Diff line Loading @@ -18,7 +18,7 @@ use <./libs/main_body_structure.scad> //Note that the main body is complex enough you should run Render not preview // To use in preview wrap with render(6) VERSION_STRING = ["Custom",""]; VERSION_STRING = "Custom"; HASH = "#untracked"; main_body_stl(VERSION_STRING, HASH); Loading Loading
build.py +1 −2 Original line number Diff line number Diff line Loading @@ -96,11 +96,10 @@ def write_ninja_file(build_dir): writer.openscad("nut_trap_test.stl", "test_pieces/nut_trap_test.scad") writer.openscad("leg_test.stl", "test_pieces/leg_test.scad") writer.openscad("rms_thread.stl", "test_pieces/rms_thread.scad") open_v_string = ["Open", "Actuators"] writer.openscad( "test_pieces/main_body_open_actuators.stl", "test_pieces/main_body_open_actuators.scad", {"VERSION_STRING": open_v_string, "HASH": commit_str} {"VERSION_STRING": version_str, "HASH": commit_str} ) writer.openscad("test_pieces/feet_open_slot.stl","test_pieces/feet_open_slot.scad") Loading
build_system/util.py +20 −2 Original line number Diff line number Diff line Loading @@ -59,9 +59,12 @@ def version_string(force_clean, check_env=True): The version string for the microscope. """ if check_env: # First check environment vars for CI version string ci_version_string = os.getenv("CI_VERSION_STRING", None) if ci_version_string is not None: return ci_version_string # Set to custom if not clean if not _repo_is_clean(): if force_clean: print("Warning! Git repository is not clean:") Loading @@ -70,16 +73,31 @@ def version_string(force_clean, check_env=True): sys.exit(1) return "Custom" # Next priority is the tag. tag = _get_commit_tag() if _is_release(tag): return tag # Next priority is pipeline ID if in a merged_result pipeline event_type = os.getenv("CI_MERGE_REQUEST_EVENT_TYPE", None) print(f"Merge Event Type: {event_type}") pipeline_id = os.getenv("CI_PIPELINE_ID", None) if pipeline_id is None: print(f"Pipeline ID: {pipeline_id}") # If we are in a merged result pipeline then the hash isn't in the repo. if event_type == "merged_result" and pipeline_id is not None: # Pint the pipeline id on the main body if len(pipeline_id) <= 10: return f"Pipeline\\n{pipeline_id}" # With a fallback in case the ids get longer return f"Pipe {pipeline_id[0:2]}-\\n{pipeline_id[2:]}" # Finally use hash (unless it is None) commit_hash = _get_commit_hash() if commit_hash is None: if force_clean: sys.exit(1) return "Custom" return ["Pipeline", pipeline_id[0:10]] return commit_hash[0:7] def commit_string(force_clean, check_env=True): """ Loading
openscad/libs/main_body_structure.scad +10 −5 Original line number Diff line number Diff line use <./utilities.scad> use <./string_utils.scad> use <./compact_nut_seat.scad> use <./logo.scad> use <./z_axis.scad> Loading Loading @@ -754,14 +755,18 @@ module xy_only_body(params){ /*This module creates the main body of the microscope, including the positioning mechanism. :param params: microscope parameters dictionary :param version_string: string or list of two strings. :param version_string: string of 1 or 2 lines. Placed on the outer wall of the main body, under the open hardware logo :param hash: string. placed on the inner wall of the main body */ module main_body(params, version_string, hash){ // If version_string is a string, make it into a list, so that version_string_list[0] // gives the whole string, not the first letter, and version_string_list[1] is empty version_string_list = (is_string(version_string)) ? [version_string] : version_string; // Split version_string into a list by line version_string_list = split_string_lines(version_string); // Check the list isn't longer than 2 lines (will error already if empty) assert(len(version_string_list) <= 2, "Can only have 1 or 2 lines in a version string."); // Get the lines and use "" as a fallback for line 2 if only 1 line is provided. version_line1 = version_string_list[0]; version_line2 = len(version_string_list) == 1 ? "" : version_string_list[1]; difference(){ xy_positioning_system(params); Loading @@ -777,6 +782,6 @@ module main_body(params, version_string, hash){ difference(){ actuator_walls_and_z_casing(params, z_axis=true); body_logos(params, version_string_list[0],version_string_list[1]); body_logos(params, version_line1, version_line2); } }
openscad/libs/string_utils.scad 0 → 100644 +62 −0 Original line number Diff line number Diff line /* A collection of string utilities for OpenSCAD. These functions provide basic string manipulation features that are not available natively in stable OpenSCAD. */ // SPDX-License-Identifier: CERN-OHL-S-2.0 // For copyright and authorship information, see the Git history at: // https://gitlab.com/openflexure/openflexure-microscope /* Concatenate a list of strings into a single string. This function reduces the list recursively, concatenating pairs of elements until a single string remains. :param input: A list of strings :return: A single string formed by concatenating all elements of `input` */ function str_cat(input) = // Empty list becomes "" len(input) == 0 ? "" : // Single element is coerced into a string and output len(input) == 1 ? str(input[0]) : // 2 elements are concatedated as strings len(input) == 2 ? str(input[0], input[1]) : // Greater then than 2 elements, the first 2 strings in the list are // combined, then recursively recall this function. str_cat( concat( [str(input[0], input[1])], [for (i = [2:len(input)-1]) input[i]] ) ); /* Return a substring using inclusive start and end indices. No bounds checking is performed. Supplying indices outside the valid range may result in undefined behaviour. :param string: The source string :param start: Starting index (inclusive, zero-based) :param end: Ending index (inclusive, zero-based) :return: The substring from `start` to `end` */ function sub_str(string, start, end) = str_cat([ for (i = [start:end]) string[i] ]); /* Split a multi-line string into a list of one-line strings. :param string: The input string :return: A list of strings, one per line */ function split_string_lines(string) = let( // get position of any \n pos = search("\n", string, 0)[0], s_pos = concat([0], [for (p=pos) p+1]), e_pos = concat( [for (p=pos) p-1], len(string)-1) ) [for (i = [0:len(pos)]) sub_str(string, s_pos[i], e_pos[i])];
openscad/main_body.scad +1 −1 Original line number Diff line number Diff line Loading @@ -18,7 +18,7 @@ use <./libs/main_body_structure.scad> //Note that the main body is complex enough you should run Render not preview // To use in preview wrap with render(6) VERSION_STRING = ["Custom",""]; VERSION_STRING = "Custom"; HASH = "#untracked"; main_body_stl(VERSION_STRING, HASH); Loading