From 5509afa82aa8170d5eab542c35e0b1fcb8097ab0 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Mon, 5 Nov 2018 19:50:29 -0600 Subject: [PATCH 1/7] #4569 Added new gcode placeholder, [filament_extruder_id] that is only valid in filament start/end gcode and refers to which position this filament is loaded in. --- lib/Slic3r/Print/GCode.pm | 6 ++++++ xs/src/libslic3r/PrintGCode.cpp | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/lib/Slic3r/Print/GCode.pm b/lib/Slic3r/Print/GCode.pm index ef6515473..d559a5ea2 100644 --- a/lib/Slic3r/Print/GCode.pm +++ b/lib/Slic3r/Print/GCode.pm @@ -160,7 +160,10 @@ sub export { $self->_print_first_layer_temperature(0) if $include_start_extruder_temp; printf $fh "%s\n", Slic3r::ConditionalGCode::apply_math($gcodegen->placeholder_parser->process($self->config->start_gcode)); + my $filament_extruder = 0; foreach my $start_gcode (@{ $self->config->start_filament_gcode }) { # process filament gcode in order + $gcodegen->placeholder_parser->set("filament_extruder_id", $filament_extruder); + $filament_extruder++; printf $fh "%s\n", Slic3r::ConditionalGCode::apply_math($gcodegen->placeholder_parser->process($start_gcode)); } $self->_print_first_layer_temperature(1) @@ -303,7 +306,10 @@ sub export { # write end commands to file print $fh $gcodegen->retract; # TODO: process this retract through PressureRegulator in order to discharge fully print $fh $gcodegen->writer->set_fan(0); + my $filament_extruder = 0; foreach my $end_gcode (@{ $self->config->end_filament_gcode }) { # Process filament-specific gcode in extruder order. + $gcodegen->placeholder_parser->set("filament_extruder_id", $filament_extruder); + $filament_extruder++; printf $fh "%s\n", Slic3r::ConditionalGCode::apply_math($gcodegen->placeholder_parser->process($end_gcode)); } printf $fh "%s\n", Slic3r::ConditionalGCode::apply_math($gcodegen->placeholder_parser->process($self->config->end_gcode)); diff --git a/xs/src/libslic3r/PrintGCode.cpp b/xs/src/libslic3r/PrintGCode.cpp index 0af21863c..2f9e65e46 100644 --- a/xs/src/libslic3r/PrintGCode.cpp +++ b/xs/src/libslic3r/PrintGCode.cpp @@ -131,7 +131,9 @@ PrintGCode::output() // Apply gcode math to start gcode fh << apply_math(gcodegen.placeholder_parser->process(config.start_gcode.value)); + auto filament_extruder {0U}; for(const auto& start_gcode : config.start_filament_gcode.values) { + gcodegen.placeholder_parser->set("filament_extruder", filament_extruder++); fh << apply_math(gcodegen.placeholder_parser->process(start_gcode)); } @@ -278,7 +280,10 @@ PrintGCode::output() // Write end commands to file. fh << gcodegen.retract(); // TODO: process this retract through PressureRegulator in order to discharge fully + + auto filament_extruder {0U}; for(const auto& end_gcode : config.end_filament_gcode.values) { + gcodegen.placeholder_parser->set("filament_extruder", filament_extruder++); fh << apply_math(gcodegen.placeholder_parser->process(end_gcode)); } From 704429eb58a32bd0b22c0f93f89f4b5f2d184982 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Mon, 5 Nov 2018 19:50:40 -0600 Subject: [PATCH 2/7] Revert "Convert filament_settings_id to something that can be set instead of just read from a configuration file." This reverts commit d9c1d459c5744aa880cd0c5e9093b0ee42f5321b. --- lib/Slic3r/GUI/PresetEditor.pm | 1 - xs/src/libslic3r/PrintConfig.cpp | 11 ++--------- xs/src/libslic3r/PrintConfig.hpp | 2 -- 3 files changed, 2 insertions(+), 12 deletions(-) diff --git a/lib/Slic3r/GUI/PresetEditor.pm b/lib/Slic3r/GUI/PresetEditor.pm index 1a6e540c1..256394042 100644 --- a/lib/Slic3r/GUI/PresetEditor.pm +++ b/lib/Slic3r/GUI/PresetEditor.pm @@ -1046,7 +1046,6 @@ sub build { my $optgroup = $page->new_optgroup('Optional information'); $optgroup->append_single_option_line('filament_density', 0); $optgroup->append_single_option_line('filament_cost', 0); - $optgroup->append_single_option_line('filament_settings_id', 0); } } diff --git a/xs/src/libslic3r/PrintConfig.cpp b/xs/src/libslic3r/PrintConfig.cpp index 1521881ea..48d43fba5 100644 --- a/xs/src/libslic3r/PrintConfig.cpp +++ b/xs/src/libslic3r/PrintConfig.cpp @@ -447,15 +447,8 @@ PrintConfigDef::PrintConfigDef() def->default_value = opt; } - def = this->add("filament_settings_id", coStrings); - def->label = __TRANS("Custom GCode ID"); - def->tooltip = __TRANS("Identifer for this filament. Used to mark specific filament profiles for custom gcode."); - def->cli = "filament-settings-id=s@"; - { - ConfigOptionStrings* opt = new ConfigOptionStrings(); - opt->values.push_back(""); - def->default_value = opt; - } + def = this->add("filament_settings_id", coString); + def->default_value = new ConfigOptionString(""); def = this->add("fill_angle", coFloat); def->label = __TRANS("Fill angle"); diff --git a/xs/src/libslic3r/PrintConfig.hpp b/xs/src/libslic3r/PrintConfig.hpp index 99ba80dc6..17f629541 100644 --- a/xs/src/libslic3r/PrintConfig.hpp +++ b/xs/src/libslic3r/PrintConfig.hpp @@ -336,7 +336,6 @@ class GCodeConfig : public virtual StaticPrintConfig ConfigOptionFloats filament_cost; ConfigOptionFloats filament_max_volumetric_speed; ConfigOptionStrings filament_notes; - ConfigOptionStrings filament_settings_id; ConfigOptionBool gcode_comments; ConfigOptionEnum gcode_flavor; ConfigOptionBool label_printed_objects; @@ -381,7 +380,6 @@ class GCodeConfig : public virtual StaticPrintConfig OPT_PTR(filament_cost); OPT_PTR(filament_max_volumetric_speed); OPT_PTR(filament_notes); - OPT_PTR(filament_settings_id); OPT_PTR(gcode_comments); OPT_PTR(gcode_flavor); OPT_PTR(label_printed_objects); From f8e222c722d2a36e3941fa9e54f1938ba2cbba5d Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Mon, 5 Nov 2018 20:13:55 -0600 Subject: [PATCH 3/7] Derp, typo'd the placeholder name. --- xs/src/libslic3r/PrintGCode.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xs/src/libslic3r/PrintGCode.cpp b/xs/src/libslic3r/PrintGCode.cpp index 2f9e65e46..9ba01209a 100644 --- a/xs/src/libslic3r/PrintGCode.cpp +++ b/xs/src/libslic3r/PrintGCode.cpp @@ -133,7 +133,7 @@ PrintGCode::output() auto filament_extruder {0U}; for(const auto& start_gcode : config.start_filament_gcode.values) { - gcodegen.placeholder_parser->set("filament_extruder", filament_extruder++); + gcodegen.placeholder_parser->set("filament_extruder_id", filament_extruder++); fh << apply_math(gcodegen.placeholder_parser->process(start_gcode)); } @@ -283,7 +283,7 @@ PrintGCode::output() auto filament_extruder {0U}; for(const auto& end_gcode : config.end_filament_gcode.values) { - gcodegen.placeholder_parser->set("filament_extruder", filament_extruder++); + gcodegen.placeholder_parser->set("filament_extruder_id", filament_extruder++); fh << apply_math(gcodegen.placeholder_parser->process(end_gcode)); } From 6e73582e0d816754a88767cac1794c21d695e362 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Tue, 6 Nov 2018 11:33:21 +0100 Subject: [PATCH 4/7] Compress the DMG image --- package/osx/make_dmg.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/package/osx/make_dmg.sh b/package/osx/make_dmg.sh index 7839a6414..0cd6a3867 100755 --- a/package/osx/make_dmg.sh +++ b/package/osx/make_dmg.sh @@ -147,11 +147,17 @@ if [[ -e "${KEYCHAIN_FILE}" ]]; then security default-keychain -s "${KEYCHAIN_FILE}" security unlock-keychain -p "${KEYCHAIN_PASSWORD}" "${KEYCHAIN_FILE}" codesign --sign "${KEYCHAIN_IDENTITY}" --deep "$appfolder" +else + echo "No KEYCHAIN_FILE env variable; skipping codesign" fi echo "Creating dmg file...." hdiutil create -fs HFS+ -srcfolder "$appfolder" -volname "$appname" "$dmgfile" +# Compress the DMG image +hdiutil convert "$dmgfile" -format UDZO -imagekey zlib-level=9 -o "$dmgfile-compressed.dmg" +mv "$dmgfile-compressed.dmg" "$dmgfile" + if [[ -e "${KEYCHAIN_FILE}" ]]; then echo "Signing app dmg..." chmod +w $dmgfile From 208feb088e505c71214707199b66c2e5a9c3a703 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Tue, 6 Nov 2018 12:24:42 +0100 Subject: [PATCH 5/7] Simplify the naming logic and make the script stricter --- package/osx/make_dmg.sh | 89 +++++++++++++++++++++-------------------- package/osx/plist.sh | 6 +-- 2 files changed, 47 insertions(+), 48 deletions(-) diff --git a/package/osx/make_dmg.sh b/package/osx/make_dmg.sh index 0cd6a3867..5b06cd9f3 100755 --- a/package/osx/make_dmg.sh +++ b/package/osx/make_dmg.sh @@ -1,53 +1,55 @@ #!/bin/bash +set -euo pipefail # Assembles an installation bundle from a built copy of Slic3r. # Requires PAR::Packer to be installed for the version of # perl copied. # Adapted from script written by bubnikv for Prusa3D. # Run from slic3r repo root directory. -SLIC3R_VERSION=$(grep "VERSION" xs/src/libslic3r/libslic3r.h | awk -F\" '{print $2}') - -if [ "$#" -ne 1 ]; then - echo "Usage: $(basename $0) dmg_name" - exit 1; -fi WD=$(dirname $0) +appname=Slic3r + # Determine if this is a tagged (release) commit. # Change the build id accordingly. -if [ $(git describe &>/dev/null) ]; then - TAGGED=true +if [ $(git describe --exact-match &>/dev/null) ]; then + echo "This is a tagged build" SLIC3R_BUILD_ID=$(git describe) else - TAGGED=false - SLIC3R_BUILD_ID=${SLIC3R_VERSION} -fi -if [ -z ${GIT_BRANCH+x} ] && [ -z ${APPVEYOR_REPO_BRANCH+x} ]; then - current_branch=$(git symbolic-ref HEAD | sed 's!refs\/heads\/!!') -else - current_branch="unknown" - if [ ! -z ${GIT_BRANCH+x} ]; then - echo "Setting to GIT_BRANCH" - current_branch=$(echo $GIT_BRANCH | cut -d / -f 2) + # Get the current branch + if [ -z ${GIT_BRANCH+x} ] && [ -z ${APPVEYOR_REPO_BRANCH+x} ]; then + current_branch=$(git symbolic-ref HEAD | sed 's!refs\/heads\/!!') + else + current_branch="unknown" + if [ ! -z ${GIT_BRANCH+x} ]; then + echo "Setting to GIT_BRANCH" + current_branch=$(echo $GIT_BRANCH | cut -d / -f 2) + fi + if [ ! -z ${APPVEYOR_REPO_BRANCH+x} ]; then + echo "Setting to APPVEYOR_REPO_BRANCH" + current_branch=$APPVEYOR_REPO_BRANCH + fi fi - if [ ! -z ${APPVEYOR_REPO_BRANCH+x} ]; then - echo "Setting to APPVEYOR_REPO_BRANCH" - current_branch=$APPVEYOR_REPO_BRANCH + + if [ "$current_branch" == "master" ]; then + echo "This is a build of the master branch" + SLIC3R_VERSION=$(grep "VERSION" xs/src/libslic3r/libslic3r.h | awk -F\" '{print $2}') + SLIC3R_BUILD_ID=${SLIC3R_VERSION}-$(git rev-parse --short HEAD) + else + echo "This is a build of a non-master branch" + appname=Slic3r-${current_branch} + SLIC3R_BUILD_ID=${current_branch}-$(git rev-parse --short HEAD) fi fi +dmgfile=slic3r-${SLIC3R_BUILD_ID}.dmg +echo "DMG filename: ${dmgfile}" + # If we're on a branch, add the branch name to the app name. -if [ "$current_branch" == "master" ]; then - appname=Slic3r - dmgfile=slic3r-${SLIC3R_BUILD_ID}-${1}.dmg -else - appname=Slic3r-$(git symbolic-ref HEAD | sed 's!refs\/heads\/!!') - dmgfile=slic3r-${SLIC3R_BUILD_ID}-${1}-$(git symbolic-ref HEAD | sed 's!refs\/heads\/!!').dmg -fi + rm -rf $WD/_tmp mkdir -p $WD/_tmp - # OSX Application folder shenanigans. appfolder="$WD/${appname}.app" macosfolder=$appfolder/Contents/MacOS @@ -104,10 +106,9 @@ echo "Copying perl from $PERL_BIN" cp -f $PERL_BIN $macosfolder/perl-local ${PP_BIN} \ -M $(grep -v "^#" ${WD}/../common/coreperl | xargs | awk 'BEGIN { OFS=" -M "}; {$1=$1; print $0}') \ - -B -p -e "print 123" -o $WD/_tmp/test.par -unzip -o $WD/_tmp/test.par -d $WD/_tmp/ + -B -p -e "print 123" -o $WD/_tmp/bundle.par +unzip -o $WD/_tmp/bundle.par -d $WD/_tmp/ cp -rf $WD/_tmp/lib/* $macosfolder/local-lib/lib/perl5/ -rm -rf $WD/_tmp echo "Cleaning bundle" rm -rf $macosfolder/local-lib/bin @@ -140,29 +141,31 @@ make_plist echo $PkgInfoContents >$appfolder/Contents/PkgInfo -if [[ -e "${KEYCHAIN_FILE}" ]]; then +KEYCHAIN_FILE_=${KEYCHAIN_FILE:-} +if [ ! -z $KEYCHAIN_FILE_ ]; then echo "Signing app..." chmod -R +w $macosfolder/* - security list-keychains -s "${KEYCHAIN_FILE}" - security default-keychain -s "${KEYCHAIN_FILE}" - security unlock-keychain -p "${KEYCHAIN_PASSWORD}" "${KEYCHAIN_FILE}" + security list-keychains -s "${KEYCHAIN_FILE_}" + security default-keychain -s "${KEYCHAIN_FILE_}" + security unlock-keychain -p "${KEYCHAIN_PASSWORD}" "${KEYCHAIN_FILE_}" codesign --sign "${KEYCHAIN_IDENTITY}" --deep "$appfolder" else echo "No KEYCHAIN_FILE env variable; skipping codesign" fi echo "Creating dmg file...." -hdiutil create -fs HFS+ -srcfolder "$appfolder" -volname "$appname" "$dmgfile" +hdiutil create -fs HFS+ -srcfolder "$appfolder" -volname "$appname" "$WD/_tmp/$dmgfile" # Compress the DMG image -hdiutil convert "$dmgfile" -format UDZO -imagekey zlib-level=9 -o "$dmgfile-compressed.dmg" -mv "$dmgfile-compressed.dmg" "$dmgfile" +hdiutil convert "$WD/_tmp/$dmgfile" -format UDZO -imagekey zlib-level=9 -o "$dmgfile" -if [[ -e "${KEYCHAIN_FILE}" ]]; then +if [ ! -z $KEYCHAIN_FILE_ ]; then echo "Signing app dmg..." chmod +w $dmgfile - security list-keychains -s "${KEYCHAIN_FILE}" - security default-keychain -s "${KEYCHAIN_FILE}" - security unlock-keychain -p "${KEYCHAIN_PASSWORD}" "${KEYCHAIN_FILE}" + security list-keychains -s "${KEYCHAIN_FILE_}" + security default-keychain -s "${KEYCHAIN_FILE_}" + security unlock-keychain -p "${KEYCHAIN_PASSWORD}" "${KEYCHAIN_FILE_}" codesign --sign "${KEYCHAIN_IDENTITY}" "$dmgfile" fi + +rm -rf $WD/_tmp diff --git a/package/osx/plist.sh b/package/osx/plist.sh index 8c62d2088..331a03d01 100755 --- a/package/osx/plist.sh +++ b/package/osx/plist.sh @@ -18,11 +18,7 @@ cat << EOF > $plistfile CFBundleShortVersionString EOF -if [ $TAGGED ]; then - echo " Slic3r $SLIC3R_BUILD_ID" >>$plistfile -else - echo " Slic3r $SLIC3R_BUILD_ID-$(git rev-parse --short head)" >>$plistfile -fi +echo " Slic3r $SLIC3R_BUILD_ID" >>$plistfile cat << EOF >> $plistfile CFBundleIdentifier From d1446fe2af3b1b890a65a3b7ff88ab701d041ba5 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Tue, 6 Nov 2018 08:15:55 -0600 Subject: [PATCH 6/7] Wrap in brackets to restrict scope of temporary variables. --- xs/src/libslic3r/PrintGCode.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/xs/src/libslic3r/PrintGCode.cpp b/xs/src/libslic3r/PrintGCode.cpp index 9ba01209a..724679d0e 100644 --- a/xs/src/libslic3r/PrintGCode.cpp +++ b/xs/src/libslic3r/PrintGCode.cpp @@ -130,11 +130,12 @@ PrintGCode::output() // Apply gcode math to start gcode fh << apply_math(gcodegen.placeholder_parser->process(config.start_gcode.value)); - - auto filament_extruder {0U}; - for(const auto& start_gcode : config.start_filament_gcode.values) { - gcodegen.placeholder_parser->set("filament_extruder_id", filament_extruder++); - fh << apply_math(gcodegen.placeholder_parser->process(start_gcode)); + { + auto filament_extruder {0U}; + for(const auto& start_gcode : config.start_filament_gcode.values) { + gcodegen.placeholder_parser->set("filament_extruder_id", filament_extruder++); + fh << apply_math(gcodegen.placeholder_parser->process(start_gcode)); + } } if (include_start_extruder_temp) this->_print_first_layer_temperature(1); @@ -281,10 +282,12 @@ PrintGCode::output() // Write end commands to file. fh << gcodegen.retract(); // TODO: process this retract through PressureRegulator in order to discharge fully - auto filament_extruder {0U}; - for(const auto& end_gcode : config.end_filament_gcode.values) { - gcodegen.placeholder_parser->set("filament_extruder_id", filament_extruder++); - fh << apply_math(gcodegen.placeholder_parser->process(end_gcode)); + { + auto filament_extruder {0U}; + for(const auto& end_gcode : config.end_filament_gcode.values) { + gcodegen.placeholder_parser->set("filament_extruder_id", filament_extruder++); + fh << apply_math(gcodegen.placeholder_parser->process(end_gcode)); + } } fh << apply_math(gcodegen.placeholder_parser->process(config.end_gcode)); From 1ae53d02c56141b6f8f4a8dc778d2ee0c03b1509 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Tue, 6 Nov 2018 08:17:37 -0600 Subject: [PATCH 7/7] Ensure filament_extruder is reinitialized. --- lib/Slic3r/Print/GCode.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Slic3r/Print/GCode.pm b/lib/Slic3r/Print/GCode.pm index d559a5ea2..b856b498a 100644 --- a/lib/Slic3r/Print/GCode.pm +++ b/lib/Slic3r/Print/GCode.pm @@ -306,7 +306,7 @@ sub export { # write end commands to file print $fh $gcodegen->retract; # TODO: process this retract through PressureRegulator in order to discharge fully print $fh $gcodegen->writer->set_fan(0); - my $filament_extruder = 0; + $filament_extruder = 0; foreach my $end_gcode (@{ $self->config->end_filament_gcode }) { # Process filament-specific gcode in extruder order. $gcodegen->placeholder_parser->set("filament_extruder_id", $filament_extruder); $filament_extruder++;