Пример #1
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;
}
Пример #2
0
function Printer_printFromLibrary($id_gcode, $exchange_extruder = FALSE, $array_temper = array())
{
    $ret_val = 0;
    $array_info = NULL;
    $array_filament = array();
    $CI =& get_instance();
    $ret_val = Printer_getFileFromModel(PRINTER_TYPE_GCODELIB, $id_gcode, $gcode_path, NULL, $array_info);
    if ($ret_val == ERROR_OK && $gcode_path) {
        $array_filament = array();
        if (Printer__getLengthFromJson(PRINTER_TYPE_GCODELIB, $array_info, $array_filament)) {
            if ($exchange_extruder) {
                Printer__inverseFilament($array_filament);
            }
        } else {
            return ERROR_INTERNAL;
            // $ret_val = ERROR_INTERNAL;
        }
        // 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;
        }
        $CI->load->helper('corestatus');
        $ret_val = Printer_printFromFile($gcode_path, CORESTATUS_VALUE_MID_PREFIXGCODE . $id_gcode, 0, TRUE, $exchange_extruder, $array_filament, $array_temper);
        // stats info
        $CI->load->helper('printerlog');
        PrinterLog_statsLibraryGcode(PRINTERLOG_STATS_LABEL_PRINT, count($array_filament));
    }
    return $ret_val;
}