Skip to content

Commit

Permalink
Change Example mode to just make an SVG for print mode
Browse files Browse the repository at this point in the history
This heavily simplifies the code, and offloads work for modes better suited.
  • Loading branch information
techninja committed Oct 25, 2014
1 parent 928cccc commit 141c05b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 125 deletions.
2 changes: 1 addition & 1 deletion resources/modes/example/example.css
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ svg#main {
position: absolute;
top: 3px;
height: 864px;
width: 1152px;
width: 1056px;
z-index: -5;
margin: 2px auto;
}
Expand Down
32 changes: 9 additions & 23 deletions resources/modes/example/example.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
</div>
<div>
<label for="hcenter">H Center:</label>
<input type="range" id="hcenter" min="10" value="200" max="1152"/>
<input type="range" id="hcenter" min="10" value="208" max="1152"/>
</div>
<div>
<label for="vcenter">V Center:</label>
<input type="range" id="vcenter" min="10" value="200" max="1152"/>
<input type="range" id="vcenter" min="10" value="185" max="1152"/>
</div>
<div>
<label for="wrap">Wrap Width:</label>
Expand All @@ -39,31 +39,17 @@

<fieldset id="buttons">
<legend>Control</legend>
<button id="pause" class="ready" title="Click to start painting">Start</button>
<button id="cancel" disabled="disabled" title="Cancel current print job.">Cancel Print</button>
<button id="pen" class="normal">Brush</button>
<button id="park" class="normal" title="Move the carriage back to the home position">Park Home</button>
<button id="disable" class="normal" title="Raise brush and Unlock (disable) stepper motors, so that you can move the carriage by hand.">Unlock Motors</button>
</fieldset>

<fieldset id="status">
<legend>Status</legend>
<div id="statusmessage"></div>
<div class="progress-wrapper">
<progress title="Current progress" max="100" value="0"></progress>
</div>
<button id="save" class="normal" title="Click to save this as the current drawing.">Save</button>
<button id="print" class="normal" title="Click to save and move to print mode">Print</button>
</fieldset>
</fieldset>

<div id="scale-container">
<svg id="main" xmlns="http://www.w3.org/2000/svg" version="1.1" height="864" width="1152">
<g id="target" transform="translate(48,48)"></g>

<path id="drawpoint" style="fill:red;" d="M17.25-0.833H7.482C7.037-4.199,4.426-6.865,1.083-7.381V-17h-2v9.579c-3.495,0.385-6.273,3.11-6.732,6.588h-9.435v2h9.435
c0.459,3.478,3.237,6.204,6.732,6.59v9.577h2V7.715c3.343-0.517,5.953-3.184,6.398-6.549h9.769V-0.833z M1.083,5.709V2.667h-2v3.092
c-2.397-0.357-4.307-2.214-4.732-4.592h3.232v-2h-3.232c0.426-2.376,2.335-4.233,4.732-4.591v3.091h2v-3.042
c2.243,0.472,3.991,2.276,4.397,4.542H2.583v2h2.898C5.075,3.433,3.327,5.238,1.083,5.709z"/>
</svg>
<div id="export">
<svg id="main" xmlns="http://www.w3.org/2000/svg" version="1.1" height="816" width="1056">
<g id="target"></g>
</svg>
</div>

<div id="shadow"></div>
</div>
Expand Down
110 changes: 10 additions & 100 deletions resources/modes/example/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @file Holds all RoboPaint example mode text renderer initialization code
*/

robopaintRequire(['hersheytext', 'svgshared', 'wcb', 'commander', 'paths'],
robopaintRequire(['hersheytext', 'svgshared', 'wcb', 'commander'],
function($, robopaint, cncserver) {

// We don't ever check visibility/overlap for this mode because the
Expand All @@ -11,30 +11,6 @@ function($, robopaint, cncserver) {

// On page load complete...
$(function() {
var run = cncserver.cmd.run; // Handy shortcut for run

// Pause/resume buffer text
// TODO: Translate these!
var bufferStateText = {
ready: 'Click to start painting',
pause: 'Click to stop current operations',
resume: 'Click to resume operations',
wait: 'Please wait while executed processes complete...'
}

// Handle buffer triggered callbacks
robopaint.socket.on('callback update', function(callback){
switch(callback.name) {
case 'drawcomplete': // Should happen when we're completely done
run('park');
cncserver.wcb.status('All done!');
$('#pause').attr('class', 'ready').attr('title', bufferStateText.ready).text('Start');
$('#buttons button.normal').prop('disabled', false); // Enable options
$('#cancel').prop('disabled', true); // Disable the cancel print button
break;
}
});

// Fit the canvas and other controls to the screen size
responsiveResize();
setTimeout(responsiveResize, 500);
Expand Down Expand Up @@ -69,86 +45,20 @@ $(function() {
$('#scale-container').html($('#scale-container').html());
}).val('futural').change(); // Trigger initial run (and default font)

// Re-render on keypress
$('input').on('input', function(e){
// Re-render on keypress/change
$('input').on('input change', function(e){
$('#fontselect').change();
});

// Cancel Print
$('#cancel').click(function(){
var cancelPrint = confirm("Are you sure you want to cancel the current print job?");
if (cancelPrint) {
cncserver.wcb.status('Cancelling...');
run(['localclear', 'clear', 'resume', 'park', ['callbackname', 'drawcomplete']]);
}
});

// Bind pause click and functionality
$('#pause').click(function() {
// With nothing in the queue, start painting the text
if (cncserver.state.buffer.length == 0) {
$('#pause').removeClass('ready').attr('title', bufferStateText.pause).text('Pause');
$('#buttons button.normal').prop('disabled', true); // Disable options
$('#cancel').prop('disabled', false); // Enable the cancel print button

// Run all paths into run buffer for drawing
//run(['wash', ['tool', 'color1']]);
$('#textexample path').each(function(){
run('status', 'Drawing character "' + $(this).attr('letter') + '"');
cncserver.paths.runOutline($(this));
});

// Run the "drawcomplete" callback when finished
run('callbackname', 'drawcomplete');

} else {
// With something in the queue... we're either pausing, or resuming
if (!cncserver.state.process.paused) {
// Starting Pause =========
$('#pause').prop('disabled', true).attr('title', bufferStateText.wait);
cncserver.wcb.status('Pausing current process...');

robopaint.cncserver.api.buffer.pause(function(){
cncserver.wcb.status('Paused. Click resume to continue.', 'complete');
$('#buttons button.normal').prop('disabled', false); // Enable options
$('#pause').addClass('active').attr('title', bufferStateText.resume).text('Resume');
$('#pause').prop('disabled', false);
});
} else {
// Resuming ===============
$('#buttons button.normal').prop('disabled', true); // Disable options
cncserver.wcb.status('Resuming current process...');
robopaint.cncserver.api.buffer.resume(function(){
$('#pause').removeClass('active').attr('title', bufferStateText.pause).text('Pause');
cncserver.wcb.status('Drawing resumed...', true);
});
}
}
// Bind save functionality
$('#save').click(function() {
cncserver.canvas.saveSVG($('#export').html());
});

// Bind to control buttons
$('#park').click(function(){
cncserver.wcb.status('Parking brush...');
robopaint.cncserver.api.pen.park(function(d){
cncserver.wcb.status(['Brush parked succesfully', "Can't Park, already parked"], d);
}, {skipBuffer: cncserver.state.process.paused ? 1 : ''});
});

// Pen/Brush up & down
$('#pen').click(function(){
robopaint.cncserver.api.pen.height($('#pen').is('.up') ? 0 : 1, null, {
skipBuffer: cncserver.state.process.paused ? 1 : ''
});
});

// Motor unlock: Also lifts pen and zeros out.
$('#disable').click(function(){
cncserver.wcb.status('Unlocking motors...');
robopaint.cncserver.api.pen.up();
robopaint.cncserver.api.pen.zero();
robopaint.cncserver.api.motors.unlock(function(d){
cncserver.wcb.status(['Motors unlocked! Place in home corner when done'], d);
});
// Bind print functionality
$('#print').click(function() {
$('#save').click();
robopaint.switchMode('print');
});
}

Expand Down
2 changes: 1 addition & 1 deletion resources/modes/example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"weight": 2,
"word": "Text",
"core": false,
"description": "An example mode for rendering text that you can print directly",
"description": "An example mode for rendering text that can be sent to other modes.",
"title": "Example Text Rendering Mode",
"detail": "A simple example RoboPaint mode to show how to build your own mode.",
"main": "example.html",
Expand Down

0 comments on commit 141c05b

Please sign in to comment.