void json_config(cJSON *json) { cJSON *child; assert(json); if (json->type != cJSON_Object) { log_error("config is not a json object: %d", json->type); return; } reset_locales(); for (child = json->child; child; child = child->next) { if (strcmp(child->string, "races") == 0) { json_races(child); } else if (strcmp(child->string, "items") == 0) { json_items(child); } else if (strcmp(child->string, "include") == 0) { json_include(child); } else if (strcmp(child->string, "ships") == 0) { json_ships(child); } else if (strcmp(child->string, "strings") == 0) { json_strings(child); } else if (strcmp(child->string, "directions") == 0) { json_directions(child); } else if (strcmp(child->string, "keywords") == 0) { json_keywords(child); } else if (strcmp(child->string, "settings") == 0) { json_settings(child); } else if (strcmp(child->string, "skills") == 0) { json_skills(child); } else if (strcmp(child->string, "buildings") == 0) { json_buildings(child); } else if (strcmp(child->string, "spells") == 0) { json_spells(child); } else if (strcmp(child->string, "prefixes") == 0) { json_prefixes(child); } else if (strcmp(child->string, "disabled") == 0) { json_disable_features(child); } else if (strcmp(child->string, "terrains") == 0) { json_terrains(child); init_terrains(); } else { log_error("config contains unknown attribute %s", child->string); } } }
void File::loadTriangles(vector< vector<Triangle> > &triangles, vector<ustring> &names, uint max_triangles) { Gio::FileType type = _file->query_file_type(); if (type != Gio::FILE_TYPE_REGULAR && type != Gio::FILE_TYPE_SYMBOLIC_LINK) return; ustring name_by_file = _file->get_basename(); size_t found = name_by_file.find_last_of("."); name_by_file = (ustring)name_by_file.substr(0,found); set_locales("C"); if(_type == ASCII_STL) { // multiple shapes per file load_asciiSTL(triangles, names, max_triangles); if (names.size() == 1) // if single shape name by file names[0] = name_by_file; if (triangles.size() == 0) {// if no success, try binary mode _type = BINARY_STL; loadTriangles(triangles, names, max_triangles); return; } } else if (_type == AMF) { // multiple shapes per file load_AMF(triangles, names, max_triangles); if (names.size() == 1) // if single shape name by file names[0] = name_by_file; } else { // single shape per file triangles.resize(1); names.resize(1); names[0] = name_by_file; if (_type == BINARY_STL) { load_binarySTL(triangles[0], max_triangles); } else if (_type == VRML) { load_VRML(triangles[0], max_triangles); } else { cerr << _("Unrecognized file - ") << _file->get_parse_name() << endl; cerr << _("Known extensions: ") << "STL, WRL, AMF." << endl; } } reset_locales(); }
void GCode::Read(Model *model, const vector<char> E_letters, ViewProgress *progress, string filename) { clear(); ifstream file; file.open(filename.c_str()); //open a file file.seekg (0, ios::end); double filesize = double(file.tellg()); file.seekg (0); progress->start(_("Loading GCode"), filesize); int progress_steps=(int)(filesize/1000); if (progress_steps==0) progress_steps=1; buffer_zpos_lines.clear(); if(!file.good()) { // MessageBrowser->add(str(boost::format("Error opening file %s") % Filename).c_str()); return; } set_locales("C"); uint LineNr = 0; string s; bool relativePos = false; Vector3d globalPos(0,0,0); Min.set(99999999.0,99999999.0,99999999.0); Max.set(-99999999.0,-99999999.0,-99999999.0); std::vector<Command> loaded_commands; double lastZ=0.; double lastE=0.; double lastF=0.; layerchanges.clear(); stringstream alltext; int current_extruder = 0; while(getline(file,s)) { alltext << s << endl; LineNr++; unsigned long fpos = file.tellg(); if (fpos%progress_steps==0) if (!progress->update(fpos)) break; Command command; if (relativePos) command = Command(s, Vector3d::ZERO, E_letters); else command = Command(s, globalPos, E_letters); if (command.Code == COMMENT) { continue; } if (command.Code == UNKNOWN) { cerr << "Unknown GCode " << s << endl; continue; } if (command.Code == RELATIVEPOSITIONING) { relativePos = true; continue; } if (command.Code == ABSOLUTEPOSITIONING) { relativePos = false; continue; } if (command.Code == SELECTEXTRUDER) { current_extruder = command.extruder_no; continue; } command.extruder_no = current_extruder; // not used yet // if (command.Code == ABSOLUTE_ECODE) { // relativeE = false; // continue; // } // if (command.Code == RELATIVE_ECODE) { // relativeE = true; // continue; // } if (command.e == 0) command.e = lastE; else lastE = command.e; if (command.f != 0) lastF = command.f; else command.f = lastF; // cout << s << endl; //cerr << command.info()<< endl; // if(command.where.x() < -100) // continue; // if(command.where.y() < -100) // continue; if (command.Code == SETCURRENTPOS) { continue;//if (relativePos) globalPos = command.where; } else { command.addToPosition(globalPos, relativePos); } if (globalPos.z() < 0){ cerr << "GCode below zero!"<< endl; continue; } if ( command.Code == RAPIDMOTION || command.Code == COORDINATEDMOTION || command.Code == ARC_CW || command.Code == ARC_CCW || command.Code == GOHOME ) { if(globalPos.x() < Min.x()) Min.x() = globalPos.x(); if(globalPos.y() < Min.y()) Min.y() = globalPos.y(); if(globalPos.z() < Min.z()) Min.z() = globalPos.z(); if(globalPos.x() > Max.x()) Max.x() = globalPos.x(); if(globalPos.y() > Max.y()) Max.y() = globalPos.y(); if(globalPos.z() > Max.z()) Max.z() = globalPos.z(); if (globalPos.z() > lastZ) { // if (lastZ > 0){ // don't record first layer unsigned long num = loaded_commands.size(); layerchanges.push_back(num); loaded_commands.push_back(Command(LAYERCHANGE, layerchanges.size())); // } lastZ = globalPos.z(); buffer_zpos_lines.push_back(LineNr-1); } else if (globalPos.z() < lastZ) { lastZ = globalPos.z(); if (layerchanges.size()>0) layerchanges.erase(layerchanges.end()-1); } } loaded_commands.push_back(command); } file.close(); reset_locales(); commands = loaded_commands; buffer->set_text(alltext.str()); Center = (Max + Min)/2; model->m_signal_gcode_changed.emit(); double time = GetTimeEstimation(); int h = (int)time/3600; int min = ((int)time%3600)/60; int sec = ((int)time-3600*h-60*min); cerr << "GCode Time Estimation "<< h <<"h "<<min <<"m " <<sec <<"s" <<endl; //??? to statusbar or where else? }