-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcontroller.php
292 lines (230 loc) · 10.4 KB
/
controller.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
<?php
/**
*
* @author FABteam
* @version 1.0
* @license https://opensource.org/licenses/GPL-3.0
*
*/
defined('BASEPATH') OR exit('No direct script access allowed');
class Plugin_fab_laser extends FAB_Controller {
function __construct()
{
parent::__construct();
if(!$this->input->is_cli_request()){ //avoid this form command line
//check if there's a running task
//load libraries, models, helpers
$this->load->model('Tasks', 'tasks');
//$this->tasks->truncate();
$this->runningTask = $this->tasks->getRunning();
}
}
public function index()
{
$this->load->library('smart');
$this->load->helper('form');
$this->load->helper('fabtotum_helper');
$this->load->helper('plugin_helper');
$data = array();
$widgetOptions = array(
'sortable' => false, 'fullscreenbutton' => true, 'refreshbutton' => false, 'togglebutton' => false,
'deletebutton' => false, 'editbutton' => false, 'colorbutton' => false, 'collapsed' => false
);
$widgeFooterButtons = '';
$widget = $this->smart->create_widget($widgetOptions);
$widget->id = 'main-widget-head-installation';
$widget->header = array('icon' => 'fa-cube', "title" => "<h2>Laser Utils</h2>");
$widget->body = array('content' => $this->load->view(plugin_url('main_widget'), $data, true ), 'class'=>'no-padding', 'footer'=>$widgeFooterButtons);
$this->addJsInLine($this->load->view(plugin_url('js'), $data, true));
$this->content = $widget->print_html(true);
$this->view();
}
public function make($fileID = '-1')
{
$this->load->library('smart');
$this->load->helper(array('language_helper', 'form', 'fabtotum_helper', 'utility_helper', 'plugin_helper'));
$this->load->model('Files', 'files');
//load plugin translation
loadPluginTranslation('fab_laser', 'fab_laser');
$data = array();
$data['runningTask'] = $this->runningTask;
//~ $data['runningTask'] = array('id' => 5);
$data['file_id'] = '';
// Skip file selection step if fileID is provided
$file = $this->files->get($fileID, 1);
$file_is_ok = False;
if($file)
{
if($file['print_type'] == 'laser')
{
$data['file_id'] = $fileID;
$file_is_ok = True;
$data['wizard_jump_to'] = 2; // jump to step 2 if fileID is available
}
}
// Skip to Job Execution step if task is already running
$task_is_running = False;
if($data['runningTask'])
{
$data['wizard_jump_to'] = 4;
$task_is_running = True;
}
//$data['wizard_jump_to'] = 0;
$data['type'] = 'laser';
$data['type_label'] = 'Engraving';
// Safety check
if(!$task_is_running){
$data['safety_check'] = safetyCheck("laser", "no");
$data['safety_check']['url'] = 'std/safetyCheck/laser/no';
$data['safety_check']['content'] = $this->load->view( 'std/task_safety_check', $data, true );
}
$data['is_laser'] = true;
$data['is_laser_pro'] = isLaserProHead();
$language = getCurrentLanguage() == 'it_IT' ? 'it' : '';
$data['safety_guide_lines_link'] = $data['is_laser_pro'] ? 'https://www.fabtotum.com/'.$language.'/laser-head-pro-safety-health-guidelines/' : 'https://www.fabtotum.com/'.$language.'/laser-head-safety-health-guidelines';
// select_file
$data['get_files_url'] = 'std/getFiles/laser';
$data['get_reacent_url'] = 'std/getRecentFiles/laser';
// task_wizard
$data['start_task_url'] = plugin_url('startTask');
$data['restart_task_url_file'] = plugin_url('make', true);
// jog_setup
$data['jog_message'] = dgettext('fab_laser', 'Position the laser point to the origin (bottom-left corner) of the drawing.<br>Jog to desired XY position, press <i class="fa fa-bullseye"></i> and then press "Engrave" ');
$data['jog_image'] = !$data['is_laser_pro'] ? plugin_assets_url('img/fabui_laser_02a.png') : plugin_assets_url('img/fabui_laser_pro_02a.png');
$data['fourth_axis'] = False;
// job_execute
$data['set_rpm_function'] = 'setLaserPWM';
$data['rpm_label'] = 'PWM';
//~ $data['rpm_message'] = 'PWM value set to:';
$data['rpm_min'] = 0;
$data['rpm_max'] = 255;
// job finish
$data['z_height_save_message'] = dgettext('fab_laser', "Z's height correction is <strong><span class=\"z-height\"></span></strong>, do you want to save it and override the value for the next engraving?");
$data['task_jump_restart'] = 3;
$data['steps'] = array(
array('number' => 1,
'title' => dgettext('fab_laser', 'Choose File'),
'content' => !$task_is_running ? $this->load->view( 'std/select_file', $data, true ) : '',
'active' => !$file_is_ok && !$task_is_running
),
array('number' => 2,
'title' => dgettext('fab_laser', 'Safety'),
'content' => !$task_is_running ? $this->load->view( plugin_url('make/wizard/safety'), $data, true ) : '',
'active' => $file_is_ok && !$task_is_running
),
array('number' => 3,
'title' => dgettext('fab_laser', 'Get Ready'),
'content' => !$task_is_running ? $this->load->view( 'std/jog_setup', $data, true ) : '',
),
array('number' => 4,
'title' => dgettext('fab_laser', 'Laser Engraving'),
'content' => $this->load->view( 'std/task_execute', $data, true ),
'active' => $task_is_running
),
array('number' => 5,
'title' => dgettext('fab_laser', 'Finish'),
'content' => $this->load->view( 'std/task_finished', $data, true )
)
);
$widgetOptions = array(
'sortable' => false, 'fullscreenbutton' => true, 'refreshbutton' => false, 'togglebutton' => false,
'deletebutton' => false, 'editbutton' => false, 'colorbutton' => false, 'collapsed' => false
);
$widgeFooterButtons = '';
$widget = $this->smart->create_widget($widgetOptions);
$widget->id = 'main-widget-make-laser';
$widget->header = array('icon' => 'fa-cube', "title" => "<h2>Laser Engraving</h2>");
$widget->body = array('content' => $this->load->view('std/task_wizard', $data, true ), 'class'=>'fuelux');
if(!$task_is_running){
$this->addCssFile('/assets/css/std/select_file.css');
$this->addCssFile('/assets/css/std/jog_setup.css');
$this->addCssFile('/assets/css/std/jogtouch.css');
$this->addCssFile('/assets/css/std/jogcontrols.css');
$this->addJSFile('/assets/js/plugin/datatables/jquery.dataTables.min.js'); //datatable
$this->addJSFile('/assets/js/plugin/datatables/dataTables.colVis.min.js'); //datatable
$this->addJSFile('/assets/js/plugin/datatables/dataTables.tableTools.min.js'); //datatable
$this->addJSFile('/assets/js/plugin/datatables/dataTables.bootstrap.min.js'); //datatable
$this->addJSFile('/assets/js/plugin/datatable-responsive/datatables.responsive.min.js'); //datatable */
$this->addJSFile('/assets/js/std/raphael.min.js' ); //vector library
$this->addJSFile('/assets/js/std/modernizr-touch.js' ); //touch device detection
$this->addJSFile('/assets/js/std/jogcontrols.js' ); //jog controls
$this->addJSFile('/assets/js/std/jogtouch.js' ); //jog controls
$this->addJSFile('/assets/js/plugin/knob/jquery.knob.min.js');
}
$this->addJSFile('/assets/js/plugin/flot/jquery.flot.cust.min.js');
$this->addJSFile('/assets/js/plugin/flot/jquery.flot.resize.min.js');
$this->addJSFile('/assets/js/plugin/flot/jquery.flot.fillbetween.min.js');
$this->addJSFile('/assets/js/plugin/flot/jquery.flot.time.min.js');
$this->addJSFile('/assets/js/plugin/flot/jquery.flot.tooltip.min.js');
$this->addJSFile('/assets/js/plugin/fuelux/wizard/wizard.min.old.js'); //wizard
$this->addJsInLine($this->load->view( plugin_url('make/js'), $data, true));
if(!$task_is_running){
$this->addJsInLine($this->load->view( 'std/task_safety_check_js', $data, true));
$this->addJsInLine($this->load->view( 'std/select_file_js', $data, true));
$this->addJsInLine($this->load->view( 'std/jog_setup_js', $data, true));
}
$this->addJsInLine($this->load->view( 'std/task_wizard_js', $data, true));
$this->addJsInLine($this->load->view( 'std/task_execute_js', $data, true));
$this->addJsInLine($this->load->view( 'std/task_finished_js', $data, true));
$this->addCssFile('/assets/css/std/task_execute.css');
$this->content = $widget->print_html(true);
$this->view();
}
public function startTask()
{
//load helpers
$this->load->helpers('fabtotum_helper');
$this->load->helper('plugin_helper');
$this->load->model('Files', 'files');
$data = $this->input->post();
$go_to_focus_point = $data['go_to_focus'] == 'true' ? 1 : 0;
$automatic_positioning = isset($data['automatic_positioning']) && $data['automatic_positioning'] == 'true' ? 1 : 0;
$fan_on = isset($data['fan']) && $data['fan'] == 'true' ? 1 : 0;
$fileToCreate = $this->files->get($data['idFile'], 1);
//reset task monitor file
resetTaskMonitor();
$checkResult = doMacro('check_engraving');
if($checkResult['response'] != 'success')
{
$this->output->set_content_type('application/json')->set_output(json_encode(array('start' => false, 'message' => $checkResult['message'], 'response' => $checkResult['response'] )));
return;
}
$startSubtractive = doMacro('start_engraving', '', [$go_to_focus_point, $automatic_positioning, $fan_on]);
if($startSubtractive['response'] != 'success'){
$this->output->set_content_type('application/json')->set_output(json_encode(array('start' => false, 'message' => $startSubtractive['message'])));
return;
}
resetTrace( _("Please wait...") );
//get object record
$object = $this->files->getObject($fileToCreate['id']);
$response = array(
'start' => false,
'message' => dgettext('fab_laser', "Task Not Implemented yet."),
'trace' => '',
'error' => ''
);
//add record to DB
$this->load->model('Tasks', 'tasks');
$taskData = array(
'user' => $this->session->user['id'],
'controller' => 'plugin/fab_laser/make',
'type' => 'laser',
'status' => 'running',
'id_file' => $data['idFile'],
'id_object' => $object['id'],
'start_date' => date('Y-m-d H:i:s')
);
$taskId = $this->tasks->add($taskData);
$response['start'] = true;
$response['id_task'] = $taskId;
$response['file']['name'] = $fileToCreate['client_name'];
//start print
$params = array(
'-T' => $taskId,
'-F' => $fileToCreate['full_path']
);
startPluginPyScript('engrave.py', $params, true);
$this->output->set_content_type('application/json')->set_output(json_encode($response));
}
}
?>