コード例 #1
0
ファイル: sliceupload.php プロジェクト: Jaesin/zim-web
 function slice_result_ajax()
 {
     $template_data = array();
     $cr = ERROR_OK;
     $array_data = array();
     $check_filament = array();
     $change_filament = array();
     $data_json = array();
     $error = NULL;
     $bicolor_model = FALSE;
     $exchange_select_snd = FALSE;
     $bicolor_printer = $this->config->item('nb_extruder') >= 2;
     $heat_bed = $this->config->item('heat_bed');
     $enable_print = 'false';
     $enable_exchange = 'disabled="disabled"';
     // select disable
     $option_selected = 'selected="selected"';
     $this->load->helper(array('printerstate', 'slicer'));
     $this->load->library('parser');
     $this->lang->load('sliceupload/slice_status_ajax', $this->config->item('language'));
     $cr = PrinterState_getSlicedJson($data_json);
     if ($cr != ERROR_OK) {
         $display = $cr . " " . t(MyERRMSG($cr));
         $this->output->set_status_header($cr);
         $this->output->set_content_type('txt_u');
         $this->parser->parse('plaintxt', array('display' => $display));
         //optional
         return;
     } else {
         $material = NULL;
         $check_filament = array('l' => t('filament_ok'), 'r' => t('filament_ok'));
         $change_filament = array('l' => t('change_filament'), 'r' => t('change_filament'));
         foreach (array('r', 'l') as $abb_filament) {
             $data_cartridge = array();
             $data_slice = array();
             $tmp_ret = 0;
             $volume_need = 0;
             if (isset($data_json[$abb_filament])) {
                 $data_slice = $data_json[$abb_filament];
                 if (isset($data_slice[PRINTERSTATE_TITLE_NEED_L])) {
                     $volume_need = $data_slice[PRINTERSTATE_TITLE_NEED_L];
                 }
             } else {
                 $check_filament[$abb_filament] = t('filament_not_need');
             }
             // check mono extruder case (normally, it's not necessary)
             if ($bicolor_printer == FALSE && $abb_filament == 'l') {
                 $tmp_ret = ERROR_MISS_LEFT_CART;
             } else {
                 $tmp_ret = PrinterState_checkFilament($abb_filament, $volume_need, $data_cartridge);
             }
             if (in_array($tmp_ret, array(ERROR_OK, ERROR_MISS_LEFT_FILA, ERROR_MISS_RIGT_FILA, ERROR_LOW_LEFT_FILA, ERROR_LOW_RIGT_FILA))) {
                 $array_data[$abb_filament] = array(PRINTERSTATE_TITLE_COLOR => $data_cartridge[PRINTERSTATE_TITLE_COLOR], PRINTERSTATE_TITLE_EXT_TEMPER => $data_cartridge[PRINTERSTATE_TITLE_EXT_TEMPER], PRINTERSTATE_TITLE_EXT_TEMP_1 => $data_cartridge[PRINTERSTATE_TITLE_EXT_TEMP_1]);
                 // set default temperature if pla
                 if ($data_cartridge[PRINTERSTATE_TITLE_MATERIAL] == PRINTERSTATE_DESP_MATERIAL_PLA) {
                     $array_data[$abb_filament][PRINTERSTATE_TITLE_EXT_TEMPER] = PRINTERSTATE_VALUE_FILAMENT_PLA_PRINT_TEMPER;
                 }
             } else {
                 $array_data[$abb_filament] = array(PRINTERSTATE_TITLE_COLOR => PRINTERSTATE_VALUE_DEFAULT_COLOR, PRINTERSTATE_TITLE_EXT_TEMPER => SLICER_VALUE_DEFAULT_TEMPER, PRINTERSTATE_TITLE_EXT_TEMP_1 => SLICER_VALUE_DEFAULT_FIRST_TEMPER);
             }
             $array_data[$abb_filament][PRINTERSTATE_TITLE_NEED_L] = $volume_need;
             // treat error
             switch ($tmp_ret) {
                 case ERROR_OK:
                     // do nothing if no error
                     break;
                 case ERROR_LOW_RIGT_FILA:
                     $check_filament['r'] = t('filament_not_enough');
                     break;
                 case ERROR_MISS_RIGT_FILA:
                     $check_filament['r'] = t('filament_unloaded');
                     $change_filament['r'] = t('load_filament');
                     break;
                 case ERROR_MISS_RIGT_CART:
                     $check_filament['r'] = t('filament_empty');
                     $change_filament['r'] = t('load_filament');
                     break;
                 case ERROR_LOW_LEFT_FILA:
                     $check_filament['l'] = t('filament_not_enough');
                     break;
                 case ERROR_MISS_LEFT_FILA:
                     $check_filament['l'] = t('filament_unloaded');
                     $change_filament['l'] = t('load_filament');
                     break;
                 case ERROR_MISS_LEFT_CART:
                     $check_filament['l'] = t('filament_empty');
                     $change_filament['l'] = t('load_filament');
                     break;
                 default:
                     $this->load->helper('printerlog');
                     PrinterLog_logError('unexpected return when generating slicing result: ' . $tmp_ret, __FILE__, __LINE__);
                     // assign error message if necessary
                     $check_filament[$abb_filament] = t('filament_error');
                     break;
             }
             // assign $cr only when status is ok (acts like a flag of error)
             if ($cr == ERROR_OK && $volume_need > 0) {
                 $cr = $tmp_ret;
             }
             // check material difference for all used cartridges
             if (!in_array($tmp_ret, array(ERROR_INTERNAL, ERROR_MISS_LEFT_CART, ERROR_MISS_RIGT_CART)) && $volume_need > 0) {
                 if ($material == NULL) {
                     $material = $data_cartridge[PRINTERSTATE_TITLE_MATERIAL];
                 } else {
                     if ($material != $data_cartridge[PRINTERSTATE_TITLE_MATERIAL]) {
                         $error .= t('cartridge_material_diff_msg') . '<br>';
                     }
                 }
                 // 					if ($volume_need > 0) { // act as count($data_slice), but with more verification
                 // 						if ($data_slice[PRINTERSTATE_TITLE_EXT_TEMPER] != $data_cartridge[PRINTERSTATE_TITLE_EXT_TEMPER]) {
                 // 							$error .= t('temper_diff_msg',
                 // 									array(
                 // 											$data_slice[PRINTERSTATE_TITLE_EXT_TEMPER],
                 // 											$data_cartridge[PRINTERSTATE_TITLE_EXT_TEMPER],
                 // 									)
                 // 							) . '<br>';
                 // 						}
                 // 						if ($data_slice[PRINTERSTATE_TITLE_EXT_TEMP_1] != $data_cartridge[PRINTERSTATE_TITLE_EXT_TEMP_1]) {
                 // 							$error .= t('first_temper_diff_msg',
                 // 									array(
                 // 											$data_slice[PRINTERSTATE_TITLE_EXT_TEMP_1],
                 // 											$data_cartridge[PRINTERSTATE_TITLE_EXT_TEMP_1],
                 // 									)
                 // 							) . '<br>';
                 // 						}
                 // 					}
             }
         }
         if (!is_null($error)) {
             $error .= t('suggest_reslice');
         }
         // check enable print
         if ($cr == ERROR_OK) {
             $enable_print = 'true';
         }
         // check bicolor model
         if ($array_data['r'][PRINTERSTATE_TITLE_NEED_L] > 0 && $array_data['l'][PRINTERSTATE_TITLE_NEED_L] > 0) {
             $bicolor_model = TRUE;
         } else {
             if ($array_data['r'][PRINTERSTATE_TITLE_NEED_L] > 0) {
                 $exchange_select_snd = TRUE;
             }
         }
         // check exchange possiblity
         if (ERROR_OK == PrinterState_checkFilaments(array('l' => $array_data['r'][PRINTERSTATE_TITLE_NEED_L], 'r' => $array_data['l'][PRINTERSTATE_TITLE_NEED_L]))) {
             $enable_exchange = NULL;
             // enable exchange if verification is passed
         } else {
             if ($bicolor_model == FALSE) {
                 if ($array_data['l'][PRINTERSTATE_TITLE_NEED_L] == 0 && $check_filament['l'] == t('filament_not_need')) {
                     $check_filament['l'] = t('filament_not_enough_for_switch');
                 } else {
                     if ($array_data['r'][PRINTERSTATE_TITLE_NEED_L] == 0 && $check_filament['r'] == t('filament_not_need')) {
                         $check_filament['r'] = t('filament_not_enough_for_switch');
                     }
                 }
             }
         }
     }
     if ($heat_bed) {
         $bed_temper = 0;
         $cr = Slicer_getParameter('bed_temperature', $bed_temper);
         $heat_bed = (int) $bed_temper > 0;
         // disable heat bed if it is not set by user
     }
     $template_data = array('cartridge_c_l' => $array_data['l'][PRINTERSTATE_TITLE_COLOR], 'cartridge_c_r' => $array_data['r'][PRINTERSTATE_TITLE_COLOR], 'state_f_l' => $check_filament['l'], 'state_f_r' => $check_filament['r'], 'need_filament_l' => $array_data['l'][PRINTERSTATE_TITLE_NEED_L], 'need_filament_r' => $array_data['r'][PRINTERSTATE_TITLE_NEED_L], 'temper_l' => $array_data['l'][PRINTERSTATE_TITLE_EXT_TEMPER], 'temper_r' => $array_data['r'][PRINTERSTATE_TITLE_EXT_TEMPER], 'print_button' => t('print_button'), 'left_temperature' => t('left_temperature'), 'right_temperature' => t('right_temperature'), 'chg_temperature' => t('chg_temperature'), 'change_left' => $change_filament['l'], 'change_right' => $change_filament['r'], 'error_msg' => $error, 'reslice_button' => t('reslice_button'), 'exchange_extruder' => t('exchange_extruder'), 'exchange_o1_val' => $exchange_select_snd ? 1 : 0, 'exchange_o2_val' => $exchange_select_snd ? 0 : 1, 'exchange_o2_sel' => $exchange_select_snd ? $option_selected : NULL, 'exchange_o1' => t('exchange_left'), 'exchange_o2' => t('exchange_right'), 'advanced' => t('advanced'), 'gcode_link' => t('gcode_link'), '2drender_link' => t('2drender_link'), 'filament_not_need' => t('filament_not_need'), 'filament_ok' => t('filament_ok'), 'result_title' => t('result_title'), 'temper_max' => PRINTERSTATE_TEMPER_CHANGE_MAX, 'temper_min' => PRINTERSTATE_TEMPER_CHANGE_MIN, 'temper_delta' => PRINTERSTATE_TEMPER_CHANGE_VAL, 'enable_print' => $enable_print, 'enable_exchange' => $enable_exchange, 'enable_reslice' => $error ? 'true' : 'false', 'bicolor_printer' => $bicolor_printer ? 'true' : 'false', 'bicolor_model' => $bicolor_model ? 'true' : 'false', 'extrud_multiply' => t('extrud_multiply'), 'left_extrud_mult' => t('left_extrud_mult'), 'right_extrud_mult' => t('right_extrud_mult'), 'extrud_r' => PRINTERSTATE_EXT_MULTIPLY_DEFAULT, 'extrud_l' => PRINTERSTATE_EXT_MULTIPLY_DEFAULT, 'extrud_min' => PRINTERSTATE_EXT_MULTIPLY_MIN, 'extrud_max' => PRINTERSTATE_EXT_MULTIPLY_MAX, 'title_heatbed' => t('title_heatbed'), 'button_bed_off' => t('button_bed_off'), 'heat_bed' => $heat_bed ? 'true' : 'false', 'bed_temper_pla' => PRINTERSTATE_TEMPER_BED_PLA, 'bed_temper_abs' => PRINTERSTATE_TEMPER_BED_ABS, 'bed_temper_max' => PRINTERSTATE_TEMPER_MAX_H);
     $this->parser->parse('sliceupload/slice_result_ajax', $template_data);
     $this->output->set_status_header(202);
     return;
 }
コード例 #2
0
ファイル: printer_helper.php プロジェクト: Jaesin/zim-web
function Printer_printFromSlice($exchange_extruder = FALSE, $array_temper = array())
{
    $ret_val = 0;
    $file_temp_data = NULL;
    $data_json = array();
    $array_filament = array();
    $CI =& get_instance();
    $CI->load->helper('slicer');
    $gcode_path = $CI->config->item('temp') . SLICER_FILE_MODEL;
    if (!file_exists($gcode_path)) {
        return ERROR_NO_SLICED;
    }
    $CI->load->helper(array('printerstate', 'corestatus'));
    if (ERROR_OK != PrinterState_getSlicedJson($data_json)) {
        $CI->load->helper('printerlog');
        PrinterLog_logError('read temp data file error', __FILE__, __LINE__);
        return ERROR_INTERNAL;
    } else {
        // move all the verification of filament into printFromFile by array_filament
        foreach ($data_json as $abb_filament => $array_temp) {
            $array_filament[$abb_filament] = $array_temp[PRINTERSTATE_TITLE_NEED_L];
        }
        if ($exchange_extruder) {
            Printer__inverseFilament($array_filament);
        }
    }
    // modify the temperature of gcode file according to cartridge info
    $ret_val = Printer__changeGcode($gcode_path, $array_filament, $exchange_extruder, $array_temper);
    if ($ret_val != ERROR_OK) {
        return $ret_val;
    }
    $ret_val = Printer_printFromFile($gcode_path, CORESTATUS_VALUE_MID_SLICE, 0, TRUE, $exchange_extruder, $array_filament, $array_temper);
    return $ret_val;
}
コード例 #3
0
function PrinterStoring_storeGcode($name)
{
    global $CFG;
    $CI =& get_instance();
    $gcode_library_path = $CFG->config['gcode_library'];
    $data_json = NULL;
    $array_length = array();
    $array_material = array();
    $nb_models = 0;
    $preset_id = NULL;
    // check if library folder exist
    if (@is_dir($gcode_library_path) == false) {
        $CI->load->helper('printerlog');
        PrinterLog_logError('gcode library folder does not exist', __FILE__, __LINE__);
        return ERROR_INTERNAL;
    }
    // get last unused ID
    if (($model_id = PrinterStoring__getLastId($gcode_library_path)) < 0) {
        $CI->load->helper('printerlog');
        PrinterLog_logError('could not get the last id from gcode library', __FILE__, __LINE__);
        return ERROR_INTERNAL;
    }
    // create model folder
    $model_folder = $gcode_library_path . sprintf('%06d', $model_id) . '/';
    if (@mkdir($model_folder) == false) {
        $CI->load->helper('printerlog');
        PrinterLog_logError('could not create the model folder', __FILE__, __LINE__);
        return ERROR_DISK_FULL;
    }
    // get length and material info
    $CI->load->helper('printerstate');
    if (ERROR_OK != PrinterState_getSlicedJson($data_json)) {
        return ERROR_INTERNAL;
    }
    foreach (array('r', 'l') as $abb_cartridge) {
        if (array_key_exists($abb_cartridge, $data_json) && array_key_exists(PRINTERSTATE_TITLE_NEED_L, $data_json[$abb_cartridge]) && $data_json[$abb_cartridge][PRINTERSTATE_TITLE_NEED_L] > 0) {
            $array_length[$abb_cartridge] = $data_json[$abb_cartridge][PRINTERSTATE_TITLE_NEED_L];
            $array_material[$abb_cartridge] = $data_json[$abb_cartridge][PRINTERSTATE_TITLE_MATERIAL];
            ++$nb_models;
        } else {
            $array_length[$abb_cartridge] = 0;
            $array_material[$abb_cartridge] = NULL;
        }
    }
    // get preset id
    $CI->load->helper('zimapi');
    if (!ZimAPI_getPreset($preset_id)) {
        $preset_id = NULL;
    }
    // create info file
    $info_file = $model_folder . PRINTERSTORING_FILE_INFO_JSON;
    $info = array("id" => $model_id, "name" => $name, PRINTERSTORING_TITLE_CREATE_TIME => time(), PRINTERSTORING_TITLE_LENG_R => $array_length['r'], PRINTERSTORING_TITLE_LENG_L => $array_length['l'], PRINTERSTORING_TITLE_MATER_R => $array_material['r'], PRINTERSTORING_TITLE_MATER_L => $array_material['l'], PRINTERSTORING_TITLE_PRESET_ID => $preset_id);
    if (!PrinterStoring__createInfoFile($info_file, $info)) {
        PrinterStoring_deleteGcode($model_id);
        $CI->load->helper('printerlog');
        PrinterLog_logError('could not create the model info file', __FILE__, __LINE__);
        return ERROR_DISK_FULL;
    }
    // store captured image
    $CI->load->helper('zimapi');
    $image_path = ZIMAPI_FILEPATH_CAPTURE;
    if (file_exists($image_path) === false) {
        $CI->load->helper('printerlog');
        PrinterLog_logError('could not find the captured image', __FILE__, __LINE__);
        return ERROR_IMG_NOTFOUND;
    } elseif (!copy($image_path, $model_folder . PRINTERSTORING_FILE_IMG_JPG)) {
        $CI->load->helper('printerlog');
        PrinterLog_logError('could not store the captured image', __FILE__, __LINE__);
        return ERROR_DISK_FULL;
    }
    // store file(s)
    $CI->load->helper('slicer');
    $file_path = $CI->config->item('temp') . SLICER_FILE_MODEL;
    if (@file_exists($file_path) == false) {
        PrinterStoring_deleteGcode($model_id);
        $CI->load->helper('printerlog');
        PrinterLog_logError('could not find the gcode model', __FILE__, __LINE__);
        return ERROR_GCODE_NOTFOUND;
    } elseif (!PrinterStoring__storeModelFile($model_folder . PRINTERSTORING_FILE_GCODE_BZ2, $file_path)) {
        PrinterStoring_deleteGcode($model_id);
        $CI->load->helper('printerlog');
        PrinterLog_logError('disk full, could not store the gcode file', __FILE__, __LINE__);
        return ERROR_DISK_FULL;
    }
    // check disk free space
    if (!PrinterStoring__checkFreeSpace()) {
        PrinterStoring_deleteGcode($model_id);
        $CI->load->helper('printerlog');
        PrinterLog_logError('overpass user library minimum free space limit', __FILE__, __LINE__);
        return ERROR_DISK_FULL;
    }
    // stats info
    $CI->load->helper('printerlog');
    PrinterLog_statsLibraryGcode(PRINTERLOG_STATS_LABEL_LOAD, $nb_models);
    return ERROR_OK;
}
コード例 #4
0
function PrinterState_prepareStatsSliceLabel($end_slice = FALSE)
{
    $stats_info = array();
    $preset_id = NULL;
    $model_filename = array();
    $array_slice = array();
    $array_check = array('l' => array(PRINTERLOG_STATS_FILA_TYPE_L, PRINTERLOG_STATS_FILA_COLOR_L, PRINTERLOG_STATS_FILA_USED_L), 'r' => array(PRINTERLOG_STATS_FILA_TYPE_R, PRINTERLOG_STATS_FILA_COLOR_R, PRINTERLOG_STATS_FILA_USED_R));
    $CI =& get_instance();
    $CI->load->helper(array('slicer', 'zimapi'));
    // remove unused filament
    if ($end_slice == TRUE) {
        if (ERROR_OK == PrinterState_getSlicedJson($array_slice)) {
            foreach (array('r', 'l') as $abb_filament) {
                if (!isset($array_slice[$abb_filament])) {
                    unset($array_check[$abb_filament]);
                }
            }
        }
    }
    // filament info
    foreach ($array_check as $abb_filament => $assign_key) {
        $json_cartridge = array();
        if (ERROR_OK == PrinterState_getCartridgeAsArray($json_cartridge, $abb_filament)) {
            $stats_info[$assign_key[0]] = $json_cartridge[PRINTERSTATE_TITLE_MATERIAL];
            $stats_info[$assign_key[1]] = $json_cartridge[PRINTERSTATE_TITLE_COLOR];
            if ($end_slice == TRUE) {
                $stats_info[$assign_key[2]] = $array_slice[$abb_filament][PRINTERSTATE_TITLE_NEED_L];
            }
        }
    }
    // model name
    if (ERROR_OK == Slicer_getModelFile(0, $model_filename, TRUE)) {
        $model_displayname = NULL;
        foreach ($model_filename as $model_basename) {
            if (strlen($model_displayname)) {
                $model_displayname .= ' + ' . $model_basename;
            } else {
                $model_displayname = $model_basename;
            }
        }
        if (strlen($model_displayname)) {
            $stats_info[PRINTERLOG_STATS_MODEL] = $model_displayname;
        }
    }
    // preset name
    if (ZimAPI_getPreset($preset_id)) {
        $array_json = array();
        if (ERROR_OK == ZimAPI_getPresetInfoAsArray($preset_id, $array_json)) {
            $stats_info[PRINTERLOG_STATS_PRESET] = $array_json[ZIMAPI_TITLE_PRESET_NAME];
        }
    }
    return $stats_info;
}