summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaalleen <36401965+kaalleen@users.noreply.github.com>2021-12-18 08:44:37 +0100
committerGitHub <noreply@github.com>2021-12-18 08:44:37 +0100
commit1d3cb680c4ec253165fb5cd183e8b4e920f635be (patch)
treef17f5e55d4e510dc04f41d764065519bc69916ff
parentffeb265e5310e3c899c27f5364b070c09e50e5ff (diff)
PDF: Estimated thread (#1389)
-rw-r--r--lib/extensions/print_pdf.py2
-rw-r--r--lib/stitch_plan/color_block.py9
-rw-r--r--lib/stitch_plan/stitch_plan.py8
-rw-r--r--print/resources/inkstitch.js27
-rw-r--r--print/templates/operator_overview.html5
-rw-r--r--print/templates/print_overview.html2
-rw-r--r--print/templates/ui.html22
7 files changed, 70 insertions, 5 deletions
diff --git a/lib/extensions/print_pdf.py b/lib/extensions/print_pdf.py
index 97a806a7..16ca3a08 100644
--- a/lib/extensions/print_pdf.py
+++ b/lib/extensions/print_pdf.py
@@ -287,7 +287,7 @@ class Print(InkstitchExtension):
'num_trims': stitch_plan.num_trims,
'dimensions': stitch_plan.dimensions_mm,
'num_stitches': stitch_plan.num_stitches,
- 'estimated_thread': '', # TODO
+ 'estimated_thread': stitch_plan.estimated_thread
},
svg_overview=overview_svg,
color_blocks=stitch_plan.color_blocks,
diff --git a/lib/stitch_plan/color_block.py b/lib/stitch_plan/color_block.py
index 10d199c2..cd7b9c6d 100644
--- a/lib/stitch_plan/color_block.py
+++ b/lib/stitch_plan/color_block.py
@@ -63,6 +63,15 @@ class ColorBlock(object):
return len(self.stitches)
@property
+ def estimated_thread(self):
+ previous_stitch = self.stitches[0]
+ length = 0
+ for stitch in self.stitches[1:]:
+ length += (stitch - previous_stitch).length()
+ previous_stitch = stitch
+ return length
+
+ @property
def num_trims(self):
"""Number of trims in this color block."""
diff --git a/lib/stitch_plan/stitch_plan.py b/lib/stitch_plan/stitch_plan.py
index f6895197..a501391d 100644
--- a/lib/stitch_plan/stitch_plan.py
+++ b/lib/stitch_plan/stitch_plan.py
@@ -113,7 +113,8 @@ class StitchPlan(object):
num_stops=self.num_stops,
num_trims=self.num_trims,
num_stitches=self.num_stitches,
- bounding_box=self.bounding_box
+ bounding_box=self.bounding_box,
+ estimated_thread=self.estimated_thread
)
@property
@@ -148,6 +149,11 @@ class StitchPlan(object):
return minx, miny, maxx, maxy
@property
+ def estimated_thread(self):
+ thread_meter = sum(block.estimated_thread for block in self) / PIXELS_PER_MM / 1000
+ return round(thread_meter, 2)
+
+ @property
def dimensions(self):
minx, miny, maxx, maxy = self.bounding_box
return (maxx - minx, maxy - miny)
diff --git a/print/resources/inkstitch.js b/print/resources/inkstitch.js
index 8bdc4ec0..01908246 100644
--- a/print/resources/inkstitch.js
+++ b/print/resources/inkstitch.js
@@ -146,6 +146,16 @@ function writeEstimatedTime( selector, estimatedTime ) {
$(selector).text( hours + ':' + minutes + ':' + seconds );
}
+function setEstimatedThread() {
+ var multiplyThread = ($('#multiply-thread').val() == '') ? 2 : parseInt($('#multiply-thread').val());
+ var estimatedThread = (parseFloat($('#estimated-thread').text()) * multiplyThread).toFixed(2);
+ var multiplyBobbin = ($('#multiply-bobbin').val() == '') ? 1 : parseInt($('#multiply-bobbin').val());
+ var estimatedBobbin = (parseFloat($('#estimated-thread').text()) * multiplyBobbin).toFixed(2);
+ $('.total-estimated-thread').each(function(index, item) {
+ $(this).text(estimatedThread + "m / " + estimatedBobbin + "m");
+ })
+}
+
// Scale SVG (fit || full size)
function scaleSVG(element, scale = 'fit') {
@@ -596,6 +606,20 @@ $(function() {
$('.modal').hide();
});
+ // Estimated thread and bobbin
+ $('#multiply-thread').on('input initialize', function() {
+ setEstimatedThread();
+ }).on('change', function() {
+ var field_name = $(this).attr('data-field-name');
+ $.postJSON('/settings/' + field_name, {value: $(this).val()});
+ });
+ $('#multiply-bobbin').on('input initialize', function() {
+ setEstimatedThread();
+ }).on('change', function() {
+ var field_name = $(this).attr('data-field-name');
+ $.postJSON('/settings/' + field_name, {value: $(this).val()});
+ });
+
// View selection checkboxes
$(':checkbox.view').on('change initialize', function() {
var field_name = $(this).attr('data-field-name');
@@ -684,6 +708,7 @@ $(function() {
setTimeout(function() {
setEstimatedTime();
+ setEstimatedThread();
}, 100);
$('button.svg-realistic').click(function(e){
@@ -729,6 +754,8 @@ $(function() {
settings["time-opo"] = $("[data-field-name='time-opo']").val();
settings["time-opd"] = $("[data-field-name='time-opd']").val();
+ settings["multiply-thread"] = $("[data-field-name='multiply-thread']").val();
+
$.postJSON('/defaults', {'value': settings});
});
});
diff --git a/print/templates/operator_overview.html b/print/templates/operator_overview.html
index a7f33a85..f61c2a6f 100644
--- a/print/templates/operator_overview.html
+++ b/print/templates/operator_overview.html
@@ -12,8 +12,9 @@
<div>
<div class="table">
<p><span>{{ _('Design box size') }}:</span><span>{{ "%0.1fmm X %0.1fmm" | format(*job.dimensions) }}</span></p>
- <p><span>{{ _('Total stitch count') }}:</span><span>{{job.num_stitches }}</span></p>
- <p><span>{{ _('Total thread used') }}:</span><span>{{job.total_thread_used }}</span></p>
+ <p><span>{{ _('Total stitch count') }}:</span><span>{{ job.num_stitches }}</span></p>
+ <p><span>{{ _('Total thread used') }}:</span><span class="total-estimated-thread"></span></p>
+ <p style="display:none;" id="estimated-thread">{{ job.estimated_thread }}</p>
</div>
</div>
<div>
diff --git a/print/templates/print_overview.html b/print/templates/print_overview.html
index 04269e20..7d09ff1a 100644
--- a/print/templates/print_overview.html
+++ b/print/templates/print_overview.html
@@ -13,7 +13,7 @@
<div class="table">
<p><span>{{ _('Design box size') }}:</span><span>{{ "%0.1fmm X %0.1fmm" | format(*job.dimensions) }}</span></p>
<p><span>{{ _('Total stitch count') }}:</span><span>{{job.num_stitches }}</span></p>
- <p><span>{{ _('Total thread used') }}:</span><span>{{job.estimated_thread }}</span></p>
+ <p><span>{{ _('Total thread used') }}:</span><span class="total-estimated-thread"></span></p>
</div>
</div>
<div>
diff --git a/print/templates/ui.html b/print/templates/ui.html
index 57c17205..dd61e2d8 100644
--- a/print/templates/ui.html
+++ b/print/templates/ui.html
@@ -19,6 +19,7 @@
<button class="tab active">{{ _('Page Setup') }}</button>
<button class="tab" id="branding-tab">{{ _('Branding') }}</button>
<button class="tab">{{ _('Estimated Time') }}</button>
+ <button class="tab">{{ _('Estimated Thread') }}</button>
<button class="tab">{{ _('Design') }}</button>
</div>
@@ -142,6 +143,27 @@
<button class="save-settings" title="{{ _('Includes page setup, estimated time and also the branding.') }}">{{ _("Save as defaults") }}</button>
</fieldset>
+ <fieldset id="ui-time" class="ui-tab">
+ <legend>{{ _('Estimated Thread') }}</legend>
+ <fieldset>
+ <legend>{{ _('Factors') }}</legend>
+ <p>{{ _('The thread length calculation depends on a lot of factors in embroidery designs. We will only get a very inacurate approximation.
+ Ink/Stitch simply calculates the path length, so the factor of 1 will always be much, much less than the real thread consumption.') }}</p>
+ <p>{{ _('Set a factor to multiply the path length with, depending on your standard setup or adapt it to your current design (tension, thread, fabric, stitch count, etc.).') }}</p>
+ <p><b>Upper thread</b></p>
+ <p>
+ <input type="number" id="multiply-thread" data-field-name="multiply-thread" min="1" value="2" />
+ <label for="multiply-thread" title="{{ _('Factor to multiply with thread length') }}">{{ _('* path length') }}</label>
+ </p>
+ <p><b>Bobbin</b></p>
+ <p>
+ <input type="number" id="multiply-bobbin" data-field-name="multiply-bobbin" min="1" value="1" />
+ <label for="multiply-bobbin" title="{{ _('Factor to multiply with thread length') }}">{{ _('* path length') }}</label>
+ </p>
+ </fieldset>
+ <button class="save-settings" title="{{ _('Includes page setup, estimated time and also the branding.') }}">{{ _("Save as defaults") }}</button>
+ </fieldset>
+
<fieldset id="ui-design" class="ui-tab">
<legend>{{ _('Design') }}</legend>
<p class="select-container"><label for="thread-palette">{{ _('Thread Palette') }}:</label>