예제 #1
0
 public function upload()
 {
     $template_data = array();
     $error = NULL;
     $response = 0;
     $button_goto_slice = NULL;
     $bicolor = $this->config->item('nb_extruder') >= 2;
     $this->load->library('parser');
     $this->load->helper('slicer');
     $this->lang->load('sliceupload/upload', $this->config->item('language'));
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         $array_model = array();
         $upload_config = array('upload_path' => $this->config->item('temp'), 'allowed_types' => '*', 'overwrite' => FALSE, 'remove_spaces' => TRUE);
         $this->load->library('upload', $upload_config);
         if ($this->upload->do_upload('file')) {
             $model = $this->upload->data();
             $model_ext = strtolower($model['file_ext']);
             // we just let xml pass to check amf.xml by slicer itself
             $array_check = $bicolor ? array('.stl', '.amf', '.obj', '.xml') : array('.stl');
             if (!is_null($model_ext) && !in_array($model_ext, $array_check)) {
                 // we can treat extension error differently
                 $error = t('fail_message_ext');
             } else {
                 $array_model[] = $model['file_name'];
             }
         } else {
             if ($this->upload->do_upload('file_c1')) {
                 $first_combine = TRUE;
                 $model = $this->upload->data();
                 $model_ext = strtolower($model['file_ext']);
                 if (!is_null($model_ext) && $model_ext != '.stl') {
                     // we can treat extension error differently
                     $error = t('fail_message_ext');
                 } else {
                     $array_model[] = $model['file_name'];
                     foreach (array('file_c2') as $file_key) {
                         if ($this->upload->do_upload($file_key)) {
                             $first_combine = FALSE;
                             $model = $this->upload->data();
                             $model_ext = strtolower($model['file_ext']);
                             if (!is_null($model_ext) && $model_ext != '.stl') {
                                 // we can treat extension error differently
                                 $error = t('fail_message_ext');
                             } else {
                                 $array_model[] = $model['file_name'];
                             }
                         } else {
                             if ($first_combine == TRUE) {
                                 $error = t('fail_message');
                                 break;
                             }
                         }
                     }
                 }
             } else {
                 // treat error - missing gcode file
                 $error = t('fail_message');
             }
         }
         if (is_null($error) && count($array_model)) {
             // load a wait page for adding model into slicer
             $template_data = array('wait_message' => t('wait_message'), 'return_button' => t('return_button'), 'model_name' => json_encode($array_model), 'fail_message' => t('fail_message'), 'fin_message' => t('fin_message'), 'key_smax' => SLICER_TITLE_MAXSCALE);
             $this->_parseBaseTemplate(t('sliceupload_upload_pagetitle'), $this->parser->parse('sliceupload/upload_wait', $template_data, TRUE));
             return;
         }
     }
     if (0 == strlen(@file_get_contents($this->config->item('temp') . SLICER_FILE_HTTP_PORT)) && FALSE == $this->config->item('simulator')) {
         $this->output->set_header('Location: /sliceupload/restart?inboot=1');
         return;
     } else {
         if (!Slicer_checkOnline(FALSE)) {
             $this->output->set_header('Location: /sliceupload/restart');
             return;
         }
     }
     // cleanup old upload temporary files
     Slicer_cleanUploadFolder($this->config->item('temp'));
     if (ERROR_OK == Slicer_listModel($response) && $response != "[]" && ERROR_OK == Slicer_checkPlatformModel()) {
         $template_data = array('text' => t('button_goto_slice'), 'link' => '/sliceupload/slice', 'id' => 'goto_slice_button');
         $button_goto_slice = $this->parser->parse('sliceupload/a_button', $template_data, TRUE);
         if (Slicer_checkSlicedModel()) {
             $template_data = array('text' => t('button_goto_result'), 'link' => '/sliceupload/slice?callback', 'id' => 'goto_result_button');
             $button_goto_slice .= $this->parser->parse('sliceupload/a_button', $template_data, TRUE);
         }
     }
     // parse the main body
     $template_data = array('back' => t('back'), 'select_hint' => t('select_hint'), 'select_hint_multi' => t('select_hint_multi'), 'header_single' => t('header_single'), 'header_multi' => t('header_multi'), 'upload_button' => t('upload_button'), 'goto_slice' => $button_goto_slice, 'error' => $error, 'bicolor' => $bicolor ? 'true' : 'false');
     $this->_parseBaseTemplate(t('sliceupload_upload_pagetitle'), $this->parser->parse('sliceupload/upload', $template_data, TRUE));
     return;
 }
예제 #2
0
function PrinterState_checkSlicedCondition(&$data_json)
{
    $temp_data = array();
    $in_sliced = TRUE;
    $CI =& get_instance();
    // check if we need to change idle into sliced or not
    $CI->load->helper(array('corestatus', 'slicer'));
    $in_sliced = Slicer_checkSlicedModel();
    if ($in_sliced == TRUE) {
        $array_tmp = array();
        $data_json[PRINTERSTATE_TITLE_STATUS] = CORESTATUS_VALUE_SLICED;
        // try to get information of slicing
        $CI->load->helper('json');
        $array_tmp = json_read($CI->config->item('temp') . SLICER_FILE_TEMP_DATA, TRUE);
        if (isset($array_tmp['error'])) {
            $CI->load->helper('printerlog');
            PrinterLog_logError('read json error', __FILE__, __LINE__);
        } else {
            $temp_data = $array_tmp['json'];
            foreach ($temp_data as $abb_filament => $array_temp) {
                $title_length = NULL;
                $title_temperature = NULL;
                switch ($abb_filament) {
                    case 'r':
                        $title_length = PRINTERSTATE_TITLE_EXT_LENG_R;
                        $title_temperature = PRINTERSTATE_TITLE_EXT_TEMP_R;
                        break;
                    case 'l':
                        $title_length = PRINTERSTATE_TITLE_EXT_LENG_L;
                        $title_temperature = PRINTERSTATE_TITLE_EXT_TEMP_L;
                        break;
                    default:
                        $CI->load->helper('printerlog');
                        PrinterLog_logError('unknown extruder abb name', __FILE__, __LINE__);
                        return ERROR_INTERNAL;
                        break;
                        // never reach here
                }
                $data_json[PRINTERSTATE_TITLE_EXTEND_PRM][$title_length] = $array_temp[PRINTERSTATE_TITLE_NEED_L];
                $data_json[PRINTERSTATE_TITLE_EXTEND_PRM][$title_temperature] = $array_temp[PRINTERSTATE_TITLE_EXT_TEMPER];
            }
        }
    }
    return ERROR_OK;
}