Exemple #1
0
 private function _stlupload_main($model_name, $model_url)
 {
     $save_path = $this->config->item('temp');
     $this->load->helper(array('printerstoring', 'errorcode', 'slicer'));
     $model_url = filter_var($model_url, FILTER_SANITIZE_URL);
     $save_path .= PrinterStoring__generateFilename($model_name) . '.stl';
     // verify slicer online
     $slicer_ok = Slicer_checkOnline(TRUE);
     $fp = fopen($model_url, 'r');
     if (!$fp) {
         $this->_stlupload_fail('remote model url open failed');
     }
     file_put_contents($save_path, $fp);
     fclose($fp);
     if ($slicer_ok == FALSE) {
         // wait slicer to get online if in restarting (only 10s)
         for ($i = 0; $i < 10; ++$i) {
             if (Slicer_checkOnline(FALSE)) {
                 break;
             } else {
                 sleep(1);
             }
         }
     }
     $ret_val = Slicer_addModel(array($save_path), 'APIV1', TRUE, $slicer_return);
     if ($ret_val != ERROR_OK) {
         $this->_stlupload_fail('remote model import failed');
     } else {
         $this->output->set_header('Location: /sliceupload/slice');
     }
     return;
 }
Exemple #2
0
 private function _treat3dslash($name_model, $token_model)
 {
     //TODO think if we pass defined variable to constant and pass basic function to helper
     $key_3dslash = '179c2398cf1ab499e7f68070856f3de7ceac10764e89de05f8aaa0f047eb3b14';
     $url_3dslash = 'https://www.3dslash.net/i.php?src=zim&token=';
     $save_path = $this->config->item('temp');
     $ret_val = 0;
     $slicer_return = array();
     $slicer_ok = TRUE;
     $fp = NULL;
     if (!preg_match("/^([a-z0-9])+\$/i", $token_model)) {
         $this->_exitWithError500('3dslash token format invalid');
         return;
     }
     $this->load->helper(array('printerstoring', 'errorcode', 'slicer', 'printerlog'));
     $url_3dslash .= hash('sha256', $token_model . '|' . $key_3dslash);
     $save_path .= PrinterStoring__generateFilename($name_model) . '.stl';
     // verify slicer online
     $slicer_ok = Slicer_checkOnline(TRUE);
     // 		copy($url_3dslash, $save_path);
     $fp = fopen($url_3dslash, 'r');
     if (!$fp) {
         $this->_exitWithError500('3dslash remote file initialize failed');
     }
     file_put_contents($save_path, $fp);
     fclose($fp);
     if ($slicer_ok == FALSE) {
         // wait slicer to get online if in restarting (only 10s)
         for ($i = 0; $i < 10; ++$i) {
             if (Slicer_checkOnline(FALSE)) {
                 break;
             } else {
                 sleep(1);
             }
         }
     }
     $ret_val = Slicer_addModel(array($save_path), PRINTERLOG_STATS_LABEL_3DSLASH, TRUE, $slicer_return);
     if ($ret_val != ERROR_OK) {
         $this->_exitWithError500('3dslash model import failed');
     } else {
         $this->output->set_header('Location: /sliceupload/slice');
     }
     return;
 }
Exemple #3
0
 public function upload($resize = NULL)
 {
     $cr = ERROR_OK;
     $model = NULL;
     // cleanup old upload temporary files
     $this->load->helper('slicer');
     Slicer_cleanUploadFolder($this->config->item('temp'));
     if (FALSE !== $this->input->get('noresize')) {
         $resize = 'noresize';
     }
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         $array_model = array();
         $upload_config = array('upload_path' => $this->config->item('temp'), 'allowed_types' => '*', 'overwrite' => TRUE, 'remove_spaces' => TRUE, 'encrypt_name' => TRUE);
         $this->load->library('upload', $upload_config);
         if ($this->upload->do_upload('f')) {
             $model = $this->upload->data();
             $model_path = $model['full_path'];
             $array_model[] = $model_path;
         } else {
             if ($this->upload->do_upload('s1')) {
                 $first_combine = TRUE;
                 $model = $this->upload->data();
                 $array_model[] = $model['full_path'];
                 foreach (array('s2') as $file_key) {
                     if ($this->upload->do_upload($file_key)) {
                         $first_combine = FALSE;
                         $model = $this->upload->data();
                         $array_model[] = $model['full_path'];
                     } else {
                         if ($first_combine == TRUE) {
                             $cr = ERROR_MISS_PRM;
                             break;
                         }
                     }
                 }
             } else {
                 // treat error - missing gcode file
                 $cr = ERROR_MISS_PRM;
             }
         }
         if ($cr == ERROR_OK) {
             if ($resize != 'noresize') {
                 $cr = Slicer_addModel($array_model);
             } else {
                 $array_return = array();
                 $cr = Slicer_addModel($array_model, TRUE, FALSE, $array_return);
                 if ($cr == ERROR_OK) {
                     $display = json_encode($array_return);
                     $this->output->set_content_type(RETURN_CONTENT_TYPE_JSON);
                     $this->load->library('parser');
                     $this->parser->parse('plaintxt', array('display' => $display));
                     return;
                 }
             }
         }
         $this->_return_cr($cr);
     } else {
         //TODO change load view into parser?
         $this->load->view('template/rest/model_form');
     }
     return;
 }
Exemple #4
0
 function add_model_ajax()
 {
     $cr = ERROR_OK;
     $display = NULL;
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         $filename = $this->input->post('file');
         if ($filename) {
             $array_model = json_decode($filename, TRUE);
             $number_model = count($array_model);
             if ($number_model) {
                 $tmp_i = 0;
                 for ($tmp_i = 0; $tmp_i < $number_model; $tmp_i++) {
                     $array_model[$tmp_i] = $this->config->item('temp') . $array_model[$tmp_i];
                     if (!file_exists($array_model[$tmp_i])) {
                         $cr = ERROR_WRONG_PRM;
                         break;
                     }
                 }
                 if ($cr == ERROR_OK) {
                     $array_return = array();
                     $this->load->helper('slicer');
                     // 						$cr = Slicer_addModel($array_model);
                     $cr = Slicer_addModel($array_model, TRUE, FALSE, $array_return);
                     if ($cr == ERROR_OK) {
                         try {
                             if ($array_return[SLICER_TITLE_MAXSCALE] < 100) {
                                 $display = json_encode($array_return);
                                 $this->output->set_status_header(202);
                                 $this->output->set_content_type('txt_u');
                                 $this->load->library('parser');
                                 $this->parser->parse('plaintxt', array('display' => $display));
                                 //optional
                                 return;
                             }
                         } catch (Exception $e) {
                             $cr = ERROR_INTERNAL;
                         }
                     }
                 }
             }
         } else {
             $cr = ERROR_MISS_PRM;
         }
     } else {
         $cr = ERROR_WRONG_PRM;
     }
     $display = $cr . " " . t(MyERRMSG($cr));
     $this->output->set_status_header($cr, $display);
     $this->output->set_content_type('txt_u');
     $this->load->library('parser');
     $this->parser->parse('plaintxt', array('display' => $display));
     //optional
     if ($cr != ERROR_OK) {
         $this->load->helper('printerlog');
         PrinterLog_logError('add model in slicer error, ' . $cr, __FILE__, __LINE__);
     }
     return;
 }
function PrinterStoring_printStl($id)
{
    global $CFG;
    $CI =& get_instance();
    $CI->load->helper('slicer');
    $info_file = $CFG->config['stl_library'] . sprintf('%06d', $id) . '/' . PRINTERSTORING_FILE_INFO_JSON;
    try {
        $name_stl1 = NULL;
        //		$str = file_get_contents($info_file);
        if (($str = @file_get_contents($info_file)) === false || ($info = json_decode($str, true)) != TRUE || !array_key_exists('name', $info)) {
            $CI->load->helper('printerlog');
            PrinterLog_logError('stl model id not found', __FILE__, __LINE__);
            return ERROR_UNKNOWN_MODEL;
        }
        Slicer_checkOnline(TRUE);
        // extract, copy model file(s) to tmp and addModel to slicer
        $model_file1 = $CFG->config['stl_library'] . sprintf('%06d', $id) . '/' . PRINTERSTORING_FILE_STL1_BZ2;
        $name_stl1 = PrinterStoring__generateFilename($info['name'] . PRINTERSTORING_FILE_STL1_EXT);
        if (($file_path = PrinterStoring__extractFile($model_file1, $name_stl1)) !== null) {
            //stats info
            $CI->load->helper('printerlog');
            if ($info[PRINTERSTORING_TITLE_MULTI_STL] === true) {
                $name_stl2 = NULL;
                $model_file2 = $CFG->config['stl_library'] . sprintf('%06d', $id) . '/' . PRINTERSTORING_FILE_STL2_BZ2;
                $name_stl2 = PrinterStoring__generateFilename($info['name'] . PRINTERSTORING_FILE_STL2_EXT);
                if (($file2_path = PrinterStoring__extractFile($model_file2, $name_stl2)) !== null) {
                    //stats info
                    PrinterLog_statsLibrarySTL(PRINTERLOG_STATS_LABEL_PRINT, 2);
                    return Slicer_addModel(array($file_path, $file2_path), FALSE);
                } else {
                    $CI->load->helper('printerlog');
                    PrinterLog_logError('could not extract the stl model', __FILE__, __LINE__);
                    return ERROR_INTERNAL;
                }
            } else {
                //stats info
                PrinterLog_statsLibrarySTL(PRINTERLOG_STATS_LABEL_PRINT, 1);
                return Slicer_addModel(array($file_path), FALSE);
            }
        } else {
            $CI->load->helper('printerlog');
            PrinterLog_logDebug('after name: ' . $name_stl1);
            PrinterLog_logError('could not extract the stl model', __FILE__, __LINE__);
            return ERROR_INTERNAL;
        }
    } catch (Exception $e) {
        $CI->load->helper('printerlog');
        PrinterLog_logError('stl model print error', __FILE__, __LINE__);
        return ERROR_INTERNAL;
    }
    return ERROR_OK;
}