Exemplo n.º 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;
 }
Exemplo n.º 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;
 }
Exemplo n.º 3
0
 function restart_ajax()
 {
     $ret_val = 0;
     $display = NULL;
     $action = $this->input->get('action');
     $this->load->helper('slicer');
     if (Slicer_checkOnline(FALSE)) {
         $this->output->set_status_header(202, 'Opened');
         return;
     } else {
         if ($action) {
             $this->load->helper('printerlog');
             PrinterLog_logDebug('restarting slicer', __FILE__, __LINE__);
             Slicer_restart();
         }
     }
     $display = 200 . " " . t(MyERRMSG(200));
     $this->output->set_status_header(200, $display);
     return;
 }
Exemplo n.º 4
0
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;
}