bool UrdfParser::parseCollision(UrdfCollision& collision, TiXmlElement* config, ErrorLogger* logger) { collision.m_linkLocalFrame.setIdentity(); // Origin TiXmlElement *o = config->FirstChildElement("origin"); if (o) { if (!parseTransform(collision.m_linkLocalFrame, o,logger)) return false; } // Geometry TiXmlElement *geom = config->FirstChildElement("geometry"); if (!parseGeometry(collision.m_geometry,geom,logger)) { return false; } const char *name_char = config->Attribute("name"); if (name_char) collision.m_name = name_char; return true; }
bool ObjectSimpleViewer:: parseDOMLine( const QDomElement &element) { bool st = true; if(element.tagName() == "Title") { setWindowTitle(element.text()); } else if (element.tagName() == "Mix") { if(m_mixSlider) { m_mixSlider->setValue(element.text().toInt()); } } else if (element.tagName() == "Geometry") { parseGeometry(element); } else if (element.tagName() == "ClipPlane") { parseClipPlane(element); } else if (element.tagName() == View::xmlTag) { parseViews(element); } else { st = false; } return(st); }
void Model::loaded(FS::IFile& file, bool success, FS::FileSystem& fs) { PROFILE_FUNCTION(); if (success) { FileHeader header; file.read(&header, sizeof(header)); if (header.m_magic == FILE_MAGIC && header.m_version <= (uint32_t)FileVersion::LATEST && parseMeshes(file) && parseGeometry(file) && parseBones(file) && parseLODs(file)) { m_size = file.size(); decrementDepCount(); } else { g_log_warning.log("renderer") << "Error loading model " << m_path.c_str(); onFailure(); return; } } else { g_log_warning.log("renderer") << "Error loading model " << m_path.c_str(); onFailure(); } }
bool UrdfParser::parseVisual(UrdfModel& model, UrdfVisual& visual, TiXmlElement* config, ErrorLogger* logger) { visual.m_linkLocalFrame.setIdentity(); // Origin TiXmlElement *o = config->FirstChildElement("origin"); if (o) { if (!parseTransform(visual.m_linkLocalFrame, o,logger)) return false; } // Geometry TiXmlElement *geom = config->FirstChildElement("geometry"); if (!parseGeometry(visual.m_geometry,geom,logger)) { return false; } const char *name_char = config->Attribute("name"); if (name_char) visual.m_name = name_char; visual.m_hasLocalMaterial = false; // Material TiXmlElement *mat = config->FirstChildElement("material"); //todo(erwincoumans) skip materials in SDF for now (due to complexity) if (mat && !m_parseSDF) { // get material name if (!mat->Attribute("name")) { logger->reportError("Visual material must contain a name attribute"); return false; } visual.m_materialName = mat->Attribute("name"); // try to parse material element in place TiXmlElement *t = mat->FirstChildElement("texture"); TiXmlElement *c = mat->FirstChildElement("color"); if (t||c) { if (parseMaterial(visual.m_localMaterial, mat,logger)) { UrdfMaterial* matPtr = new UrdfMaterial(visual.m_localMaterial); model.m_materials.insert(matPtr->m_name.c_str(),matPtr); visual.m_hasLocalMaterial = true; } } } return true; }
bool UrdfParser::parseVisual(UrdfVisual& visual, TiXmlElement* config, ErrorLogger* logger) { visual.m_linkLocalFrame.setIdentity(); // Origin TiXmlElement *o = config->FirstChildElement("origin"); if (o) { if (!parseTransform(visual.m_linkLocalFrame, o,logger)) return false; } // Geometry TiXmlElement *geom = config->FirstChildElement("geometry"); if (!parseGeometry(visual.m_geometry,geom,logger)) { return false; } const char *name_char = config->Attribute("name"); if (name_char) visual.m_name = name_char; visual.m_hasLocalMaterial = false; // Material TiXmlElement *mat = config->FirstChildElement("material"); if (mat) { // get material name if (!mat->Attribute("name")) { logger->reportError("Visual material must contain a name attribute"); return false; } visual.m_materialName = mat->Attribute("name"); // try to parse material element in place TiXmlElement *t = mat->FirstChildElement("texture"); TiXmlElement *c = mat->FirstChildElement("color"); if (t||c) { if (parseMaterial(visual.m_localMaterial, mat,logger)) { visual.m_hasLocalMaterial = true; } } } return true; }
bool parseKML(QDomElement& e, Layer* aLayer) { bool ret= false; QDomElement c = e.firstChildElement(); while(!c.isNull()) { ret = parseFeature(c, aLayer); if (!ret) ret = parseGeometry(c, aLayer); c = c.nextSiblingElement(); } return ret; }
bool Model::load(FS::IFile& file) { PROFILE_FUNCTION(); FileHeader header; file.read(&header, sizeof(header)); if (header.m_magic == FILE_MAGIC && header.m_version <= (uint32)FileVersion::LATEST && parseMeshes(file) && parseGeometry(file) && parseBones(file) && parseLODs(file)) { m_size = file.size(); return true; } g_log_warning.log("renderer") << "Error loading model " << getPath().c_str(); return false; }
bool parseVisual(Visual &vis, TiXmlElement *config) { vis.clear(); // Origin TiXmlElement *o = config->FirstChildElement("origin"); if (o) { if (!parsePose(vis.origin, o)) return false; } // Geometry TiXmlElement *geom = config->FirstChildElement("geometry"); vis.geometry = parseGeometry(geom); if (!vis.geometry) return false; const char *name_char = config->Attribute("name"); if (name_char) vis.name = name_char; // Material TiXmlElement *mat = config->FirstChildElement("material"); if (mat) { // get material name if (!mat->Attribute("name")) { logError("Visual material must contain a name attribute"); return false; } vis.material_name = mat->Attribute("name"); // try to parse material element in place resetPtr(vis.material,new Material()); if (!parseMaterial(*vis.material, mat, true)) { logDebug("urdfdom: material has only name, actual material definition may be in the model"); } } return true; }
bool parsePlacemark(QDomElement& e, Layer* aLayer) { Feature* F = NULL; QDomElement c = e.firstChildElement(); QString name; QString address; QString description; QString phone; while(!c.isNull()) { if (c.tagName() == "name") name = c.firstChild().toText().nodeValue(); else if (c.tagName() == "address") address = c.firstChild().toText().nodeValue(); else if (c.tagName() == "description") description = c.firstChild().toText().nodeValue(); else if (c.tagName() == "phoneNumber") phone = c.firstChild().toText().nodeValue(); else F = parseGeometry(c, aLayer); c = c.nextSiblingElement(); } if (F) { if (!name.isEmpty()) F->setTag("name", name); if (!address.isEmpty()) F->setTag("addr:full", address); if (!phone.isEmpty()) F->setTag("addr:phone_number", phone); if (!description.isEmpty()) F->setTag("description", description); return true; } else return false; }
bool UrdfParser::parseCollision(UrdfCollision& collision, TiXmlElement* config, ErrorLogger* logger) { collision.m_linkLocalFrame.setIdentity(); if(m_parseSDF) { TiXmlElement* pose = config->FirstChildElement("pose"); if (pose) { parseTransform(collision.m_linkLocalFrame, pose,logger,m_parseSDF); } } // Origin TiXmlElement *o = config->FirstChildElement("origin"); if (o) { if (!parseTransform(collision.m_linkLocalFrame, o,logger)) return false; } // Geometry TiXmlElement *geom = config->FirstChildElement("geometry"); if (!parseGeometry(collision.m_geometry,geom,logger)) { return false; } const char *name_char = config->Attribute("name"); if (name_char) collision.m_name = name_char; const char *concave_char = config->Attribute("concave"); if (concave_char) collision.m_flags |= URDF_FORCE_CONCAVE_TRIMESH; return true; }
bool parseCollision(Collision &col, TiXmlElement* config) { col.clear(); // Origin TiXmlElement *o = config->FirstChildElement("origin"); if (o) { if (!parsePose(col.origin, o)) return false; } // Geometry TiXmlElement *geom = config->FirstChildElement("geometry"); col.geometry = parseGeometry(geom); if (!col.geometry) return false; const char *name_char = config->Attribute("name"); if (name_char) col.name = name_char; return true; }
bool Collision::initXml(TiXmlElement* config) { this->clear(); // Origin TiXmlElement *o = config->FirstChildElement("origin"); if (!o) { ROS_DEBUG("Origin tag not present for collision element, using default (Identity)"); this->origin.clear(); } else if (!this->origin.initXml(o)) { ROS_ERROR("Collision has a malformed origin tag"); this->origin.clear(); return false; } // Geometry TiXmlElement *geom = config->FirstChildElement("geometry"); geometry = parseGeometry(geom); if (!geometry) { ROS_ERROR("Malformed geometry for Collision element"); return false; } // Group Tag (optional) // collision blocks without a group tag are designated to the "default" group const char *group_name_char = config->Attribute("group"); if (!group_name_char) group_name = std::string("default"); else group_name = std::string(group_name_char); return true; }
void ColladaLoader::startElement(const XML_Char *name, const XML_Char *atts[]) { int id = getTagID(name); switch (id) { case TAG_LIBRARY_MATERIALS: break; case TAG_LIBRARY_GEOMETRIES: break; case TAG_GEOMETRY: parseGeometry(atts); break; case TAG_MESH: break; case TAG_SOURCE: parseSource(atts); break; case TAG_FLOAT_ARRAY: parseFloatArray(atts); break; case TAG_TRIANGLES: parseTriangles(atts); break; } state.push_back(id); }
int main( int argc, char** argv ) { // First parse any options and the filename we need. gengetopt_args_info options; int err = cmdline_parser( argc, argv, &options ); if ( err ) { return err; } // Then set up the x interface. err = xengine->init( options.xdisplay_arg ); if ( err ) { fprintf( stderr, "Failed to grab X display!\n" ); return err; } // Then the imlib2 interface err = imengine->init(); if ( err ) { fprintf( stderr, "Failed to initialize imlib2!\n" ); return err; } float delay = atof( options.delay_arg ); if ( !options.windowid_given ) { options.windowid_arg = None; } std::string file = ""; // If we don't have a file, default to writing to the home directory. if ( options.inputs_num <= 0 ) { char currentdir[MAXPATHLEN]; // FIXME: getcwd is fundamentally broken, switch it with a C++ equivalent that won't ever have // buffer sizing issues. char* error = getcwd( currentdir, MAXPATHLEN ); if ( error == NULL ) { fprintf( stderr, "Failed to get current working directory!\n" ); return errno; } file = currentdir; // Get unix timestamp std::stringstream result; result << (int)time( NULL ); file += "/" + result.str() + ".png"; printf( "No file specified, using %s\n", file.c_str() ); } else if ( options.inputs_num == 1 ) { file = options.inputs[ 0 ]; } else { fprintf( stderr, "Unexpected number of output files! There should only be one.\n" ); cmdline_parser_free( &options ); return 1; } // Check if we were asked to prompt for selection: if ( options.select_flag ) { // Execute slop with any options given. std::string result; std::stringstream slopcommand; slopcommand << "slop "; slopcommand << options.nokeyboard_flag ? "--nokeyboard" : ""; slopcommand << " -b " << options.bordersize_arg; slopcommand << " -p " << options.padding_arg; slopcommand << " -t " << options.tolerance_arg; slopcommand << " -g " << options.gracetime_arg; slopcommand << " -c " << options.color_arg; slopcommand << options.nodecorations_flag ? "-n" : ""; slopcommand << " --min=" << options.min_arg; slopcommand << " --max=" << options.max_arg; slopcommand << options.highlight_flag ? "-l" : ""; err = exec( slopcommand.str(), &result ); if ( err ) { fprintf( stderr, "slop failed to run, canceling screenshot. Is slop installed?\n" ); cmdline_parser_free( &options ); return 1; } // from here we'll just be parsing the output of slop. // Replace all ='s with spaces in the result, this is so sscanf works properly. int find = result.find( "=" ); while( find != result.npos ) { result.at( find ) = ' '; find = result.find( "=" ); } int x, y, w, h; int num = sscanf( result.c_str(), "X %d\n Y %d\n W %d\n H %d\n%*s", &x, &y, &w, &h ); if ( num == 4 && ( w > 0 && h > 0 ) ) { bool mask = checkMask( options.mask_arg, x, y, w, h, options.windowid_arg ); // Wait the designated amount of time before taking the screenshot. // 1000000 microseconds = 1 second usleep( (unsigned int)(delay * 1000000.f) ); err = imengine->screenshot( file, x, y, w, h, options.hidecursor_flag, options.windowid_arg, mask ); cmdline_parser_free( &options ); if ( err ) { return err; } return 0; } fprintf( stderr, "Either the user canceled the query for selection, or slop failed to run properly. Canceling screenshot.\n" ); cmdline_parser_free( &options ); return 1; } if ( options.x_given && options.y_given && options.w_given && options.h_given ) { options.geometry_given = true; char temp[128]; sprintf( temp, "%ix%i+%i+%i\0", options.w_arg, options.h_arg, options.x_arg, options.y_arg ); options.geometry_arg = temp; } else if ( ( options.x_given || options.y_given || options.w_given || options.h_given ) && !options.geometry_given ) { fprintf( stderr, "Partial geometry arguments were set, but it isn't enough data to take a screenshot!" ); fprintf( stderr, "Either give the geometry arugment, or give ALL of the following arguments: x, y, w, h," ); fprintf( stderr, " or don't give any of them." ); cmdline_parser_free( &options ); return 1; } // Just take a full screen shot if we didn't get any geometry. if ( !options.geometry_given ) { // Wait the designated amount of time before taking the screenshot. // 1000000 microseconds = 1 second usleep( (unsigned int)(delay * 1000000.f) ); err = imengine->screenshot( file, options.hidecursor_flag, options.windowid_arg, strcmp( options.mask_arg, "off" ) ? true : false ); cmdline_parser_free( &options ); if ( err ) { return err; } return 0; } // Otherwise take a screen shot of the supplied region. int x, y, w, h; parseGeometry( options.geometry_arg, &x, &y, &w, &h ); bool mask = checkMask( options.mask_arg, x, y, w, h, options.windowid_arg ); usleep( (unsigned int)(delay * 1000000.f) ); err = imengine->screenshot( file, x, y, w, h, options.hidecursor_flag, options.windowid_arg, mask ); cmdline_parser_free( &options ); if ( err ) { return err; } return 0; }
bool Visual::initXml(TiXmlElement *config) { this->clear(); // Origin TiXmlElement *o = config->FirstChildElement("origin"); if (!o) { ROS_DEBUG("Origin tag not present for visual element, using default (Identity)"); this->origin.clear(); } else if (!this->origin.initXml(o)) { ROS_ERROR("Visual has a malformed origin tag"); this->origin.clear(); return false; } // Geometry TiXmlElement *geom = config->FirstChildElement("geometry"); geometry = parseGeometry(geom); if (!geometry) { ROS_ERROR("Malformed geometry for Visual element"); return false; } // Material TiXmlElement *mat = config->FirstChildElement("material"); if (!mat) { ROS_DEBUG("visual element has no material tag."); } else { // get material name if (!mat->Attribute("name")) { ROS_ERROR("Visual material must contain a name attribute"); return false; } this->material_name = mat->Attribute("name"); // try to parse material element in place this->material.reset(new Material); if (!this->material->initXml(mat)) { ROS_DEBUG("Could not parse material element in Visual block, maybe defined outside."); this->material.reset(); } else { ROS_DEBUG("Parsed material element in Visual block."); } } // Group Tag (optional) // collision blocks without a group tag are designated to the "default" group const char *group_name_char = config->Attribute("group"); if (!group_name_char) group_name = std::string("default"); else group_name = std::string(group_name_char); return true; }
static void parseCommandLine(int argc, char ** argv, struct cmdlineInfo *cmdlineP ) { /*---------------------------------------------------------------------------- Parse program command line described in Unix standard form by argc and argv. Return the information in the options as *cmdlineP. If command line is internally inconsistent (invalid options, etc.), issue error message to stderr and abort program. Note that the strings we return are stored in the storage that was passed to us as the argv array. We also trash *argv. -----------------------------------------------------------------------------*/ /* vars for the option parser */ optEntry * option_def; optStruct3 opt; unsigned int option_def_index = 0; /* incremented by OPTENT3 */ unsigned int thresholdSpec, localSpec, dualSpec, contrastSpec; const char * localOpt; const char * dualOpt; MALLOCARRAY_NOFAIL(option_def, 100); /* define the options */ OPTENT3(0, "simple", OPT_FLAG, NULL, &cmdlineP->simple, 0); OPTENT3(0, "local", OPT_STRING, &localOpt, &localSpec, 0); OPTENT3(0, "dual", OPT_STRING, &dualOpt, &dualSpec, 0); OPTENT3(0, "threshold", OPT_FLOAT, &cmdlineP->threshold, &thresholdSpec, 0); OPTENT3(0, "contrast", OPT_FLOAT, &cmdlineP->contrast, &contrastSpec, 0); OPTENT3(0, "verbose", OPT_FLAG, NULL, &cmdlineP->verbose, 0); /* set the defaults */ cmdlineP->width = cmdlineP->height = 0U; /* set the option description for pm_optParseOptions3 */ opt.opt_table = option_def; opt.short_allowed = FALSE; /* long options only */ opt.allowNegNum = FALSE; /* we have no numbers at all */ /* parse commandline, change argc, argv, and *cmdlineP */ pm_optParseOptions3(&argc, argv, opt, sizeof(opt), 0); if (cmdlineP->simple + localSpec + dualSpec > 1) pm_error("You may specify only one of -simple, -local, and -dual"); if (!thresholdSpec) cmdlineP->threshold = 0.5; /* 0 <= threshold <= 1 */ if ((cmdlineP->threshold < 0.0) || (cmdlineP->threshold > 1.0)) pm_error("threshold must be in [0,1]"); if (!contrastSpec) cmdlineP->contrast = 0.05; /* 0 <= contrast <= 1 */ if ((cmdlineP->contrast < 0.0) || (cmdlineP->contrast > 1.0)) pm_error("contrast must be in [0,1]"); if (localSpec) { const char * error; cmdlineP->local = TRUE; parseGeometry(localOpt, &cmdlineP->width, &cmdlineP->height, &error); if (error) { pm_error("Invalid -local value '%s'. %s", localOpt, error); pm_strfree(error); } } else cmdlineP->local = FALSE; if (dualSpec) { const char * error; cmdlineP->dual = TRUE; parseGeometry(dualOpt, &cmdlineP->width, &cmdlineP->height, &error); if (error) { pm_error("Invalid -dual value '%s'. %s", dualOpt, error); pm_strfree(error); } } else cmdlineP->dual = FALSE; if (argc-1 < 1) cmdlineP->inputFileName = "-"; else if (argc-1 == 1) cmdlineP->inputFileName = argv[1]; else pm_error("Progam takes at most 1 parameter: the file name. " "You specified %d", argc-1); }
int app( int argc, char** argv ) { // First parse any options and the filename we need. gengetopt_args_info options; int err = cmdline_parser( argc, argv, &options ); if ( err != EXIT_SUCCESS ) { return EXIT_FAILURE; } maim::IMEngine* imengine = new maim::IMEngine(options); // Then set up the x interface. if ( options.xdisplay_given ) { err = xengine->init( options.xdisplay_arg ); } else { // If we weren't specifically given a xdisplay, we try // to parse it from environment variables char* display = getenv( "DISPLAY" ); if ( display ) { err = xengine->init( display ); } else { fprintf( stderr, "Warning: Failed to parse environment variable: DISPLAY. Using \":0\" instead.\n" ); err = xengine->init( ":0" ); } } if ( err != EXIT_SUCCESS ) { fprintf( stderr, "Failed to grab X display!\n" ); return EXIT_FAILURE; } // Then the imlib2 interface err = imengine->init(); if ( err != EXIT_SUCCESS ) { fprintf( stderr, "Failed to initialize imlib2!\n" ); return EXIT_FAILURE; } // Grab all of our variables from the options. bool gotGeometry = false; bool gotSelectFlag = options.select_flag; int x, y, w, h; float delay; err = sscanf( options.delay_arg, "%f", &delay ); if ( err != 1 ) { fprintf( stderr, "Failed to parse %s as a float for delay!\n", options.delay_arg ); return EXIT_FAILURE; } struct timespec delayTime; delayTime.tv_sec = delay; delayTime.tv_nsec = 0; // Get our geometry if we have any. if ( options.x_given && options.y_given && options.w_given && options.h_given && !options.geometry_given ) { x = options.x_arg; y = options.y_arg; w = options.w_arg; h = options.h_arg; gotGeometry = true; } else if ( ( options.x_given || options.y_given || options.w_given || options.h_given ) && !options.geometry_given ) { fprintf( stderr, "Partial geometry arguments were set, but it isn't enough data to take a screenshot!\n" ); fprintf( stderr, "Please give the geometry argument or give ALL of the following arguments: x, y, w, h.\n" ); cmdline_parser_free( &options ); return EXIT_FAILURE; } else if ( options.geometry_given ) { err = parseGeometry( options, &x, &y, &w, &h ); if ( err != EXIT_SUCCESS ) { fprintf( stderr, "Failed to parse geometry %s, should be in format WxH+X+Y!\n", options.geometry_orig ); cmdline_parser_free( &options ); return EXIT_FAILURE; } gotGeometry = true; } // Get our window if we have one, default to the root window. Window window = xengine->m_root; if ( options.windowid_given ) { window = (Window)options.windowid_arg; } // Get our file name std::string file = ""; // If we don't have a file, default to writing to the home directory. if ( options.inputs_num == 0 ) { // Try as hard as we can to get the current directory. int trycount = 0; char* home_env = getenv("HOME"); int length = MAXPATHLEN; char* currentdir = new char[ length ]; char* error = getcwd( currentdir, length ); while ( error == NULL ) { delete[] currentdir; length *= 2; currentdir = new char[ length ]; error = getcwd( currentdir, length ); trycount++; // Ok someone's trying to be whacky with the current directory if we're going 8 times over // the max path length. if ( trycount > 3 ) { fprintf( stderr, "Failed to grab the current directory!" ); // Try to HOME later if ( home_env == NULL ) { fprintf( stderr, "Failed to get HOME environment variable, no where left to save!" ); cmdline_parser_free( &options ); delete [] currentdir; return EXIT_FAILURE; } } } if ( is_valid_directory ( currentdir ) == EXIT_SUCCESS ) { file = currentdir; } else { file = home_env; } // Get unix timestamp std::stringstream result; result << (int)time( NULL ); file += "/" + result.str() + ".png"; printf( "No file specified, using %s\n", file.c_str() ); delete [] currentdir; } else if ( options.inputs_num == 1 ) { file = options.inputs[ 0 ]; } else { fprintf( stderr, "Unexpected number of output files! There should only be one.\n" ); cmdline_parser_free( &options ); return EXIT_FAILURE; } // Finally we have all our information, now to use it. if ( gotSelectFlag ) { err = slop( options, &x, &y, &w, &h, &window ); if ( err != EXIT_SUCCESS ) { fprintf( stderr, "Selection was cancelled or slop failed to run. Make sure it's installed!\n" ); cmdline_parser_free( &options ); return EXIT_FAILURE; } err = nanosleep( &delayTime, NULL ); if ( err != EXIT_SUCCESS ) { fprintf( stderr, "Warning: Failed to delay the screenshot. Continuing anyway..." ); } err = imengine->screenshot( window, x, y, w, h ); if ( err != EXIT_SUCCESS ) { fprintf( stderr, "Failed to take screenshot.\n" ); return EXIT_FAILURE; } if ( options.showcursor_flag ) { imengine->blendCursor( window, x, y ); } if ( checkMask( options.mask_arg, x, y, w, h, window ) ) { imengine->mask( x, y, w, h ); } err = imengine->save( file, options.format_arg ); cmdline_parser_free( &options ); if ( err != EXIT_SUCCESS ) { fprintf( stderr, "Failed to take screenshot.\n" ); return EXIT_FAILURE; } return EXIT_SUCCESS; } if ( gotGeometry ) { err = nanosleep( &delayTime, NULL ); if ( err != EXIT_SUCCESS ) { fprintf( stderr, "Warning: Failed to delay the screenshot. Continuing anyway..." ); } err = imengine->screenshot( window, x, y, w, h ); if ( err != EXIT_SUCCESS ) { fprintf( stderr, "Failed to take screenshot.\n" ); return EXIT_FAILURE; } if ( options.showcursor_flag ) { imengine->blendCursor( window, x, y ); } if ( checkMask( options.mask_arg, x, y, w, h, window ) ) { imengine->mask( x, y, w, h ); } err = imengine->save( file, options.format_arg ); cmdline_parser_free( &options ); if ( err != EXIT_SUCCESS ) { fprintf( stderr, "Failed to take screenshot.\n" ); return EXIT_FAILURE; } return EXIT_SUCCESS; } // If we didn't get any special options, just screenshot the specified window // (Which defaults to the whole screen). err = nanosleep( &delayTime, NULL ); if ( err != EXIT_SUCCESS ) { fprintf( stderr, "Warning: Failed to delay the screenshot. Continuing anyway..." ); } err = imengine->screenshot( window ); if ( err != EXIT_SUCCESS ) { fprintf( stderr, "Failed to take screenshot.\n" ); return EXIT_FAILURE; } if ( options.showcursor_flag ) { imengine->blendCursor( window ); } if ( checkMask( options.mask_arg, 0, 0, WidthOfScreen( xengine->m_screen ), HeightOfScreen( xengine->m_screen ), window ) ) { imengine->mask(); } err = imengine->save( file, options.format_arg ); cmdline_parser_free( &options ); if ( err != EXIT_SUCCESS ) { fprintf( stderr, "Failed to take screenshot.\n" ); return EXIT_FAILURE; } return EXIT_SUCCESS; }
void QChemInput::readMoleculeSection(TextStream& textStream) { QString msg("Invalid $molecule format on line "); int charge(0); unsigned multiplicity(1); bool ok; // First line can only contain the charge and multiplicity or 'read' QString line(textStream.nextLine()); line = line.replace(',', ' '); QStringList tokens(TextStream::tokenize(line)); switch (tokens.size()) { case 0: // Error m_errors.append(msg + QString::number(textStream.lineNumber())); return; break; case 1: // Could be reading in previous geometry if (tokens[0].contains("read", Qt::CaseInsensitive)) { if (m_geometryList->size() > 0) { // copy previous geometry Data::Geometry* geometry(new Data::Geometry(*(m_geometryList->last()))); m_geometryList->append(geometry); }else { // We assume we are reading an input section from // an output file, so there is no new geometry. } }else { m_errors.append(msg + QString::number(textStream.lineNumber())); } return; break; default: charge = tokens[0].toInt(&ok); if (ok) multiplicity = tokens[1].toUInt(&ok); if (!ok) { m_errors.append(msg + QString::number(textStream.lineNumber())); return; } break; } // Second line could be a 'read' token or the first atom line = textStream.nextLine(); // offset is passed to the CartesianCoordinates parser to give // an accurate line number if an error occurs. int offset(textStream.lineNumber()-1); if (line.isEmpty()) { m_errors.append(msg + QString::number(textStream.lineNumber())); return; } // Special case: read previous geometry if (line.contains("read", Qt::CaseInsensitive)) { if (m_geometryList->size() > 0) { // copy last geometry Data::Geometry* geometry(new Data::Geometry(*(m_geometryList->last()))); geometry->setChargeAndMultiplicity(charge, multiplicity); m_geometryList->append(geometry); }else { m_errors.append(msg + QString::number(textStream.lineNumber())); } return; } // Special case: EFP only fragments if (line.contains("--")) { // Check for an existing list which may have been created if the // $efp_fragments section was parsed before $molecule. Data::EfpFragmentList* efps(0); QList<Data::EfpFragmentList*> lists = m_dataBank.findData<Data::EfpFragmentList>(); if (lists.isEmpty()) { efps = new Data::EfpFragmentList; m_dataBank.append(efps); }else { efps = lists.last(); } int count(1); while (!textStream.atEnd()) { tokens = textStream.nextLineAsTokens(); if (tokens.size() == 1 && tokens[0].contains("$end", Qt::CaseInsensitive)) { break; }else if (tokens.size() == 6) { bool allOk(true); double x, y, z, a, b, c; if (allOk) x = tokens[0].toDouble(&ok); allOk = allOk && ok; if (allOk) y = tokens[1].toDouble(&ok); allOk = allOk && ok; if (allOk) z = tokens[2].toDouble(&ok); allOk = allOk && ok; if (allOk) a = tokens[3].toDouble(&ok); allOk = allOk && ok; if (allOk) b = tokens[4].toDouble(&ok); allOk = allOk && ok; if (allOk) c = tokens[5].toDouble(&ok); allOk = allOk && ok; if (allOk) { Data::EfpFragment* efp(0); if (count <= efps->size()) { efp = efps->at(count-1); }else { efp = new Data::EfpFragment; efps->append(efp); } efp->setPosition(Vec(x,y,z)); efp->setEulerAngles(a,b,c); } ++count; } } return; } tokens = TextStream::tokenize(line); bool zmat(tokens.size() == 1); QStringList lines; while (!textStream.atEnd() && !line.contains("$end", Qt::CaseInsensitive)) { // Account for the possibility of a FSM job, which has two geometries // separated by the **** token. if (line.contains("****")) { Data::Geometry* geom(parseGeometry(lines, offset, zmat)); if (geom) { geom->setChargeAndMultiplicity(charge, multiplicity); m_geometryList->append(geom); } offset = textStream.lineNumber(); lines.clear(); }else { lines.append(line); } line = textStream.nextLine(); } Data::Geometry* geom(parseGeometry(lines, offset, zmat)); if (geom) { geom->setChargeAndMultiplicity(charge, multiplicity); m_geometryList->append(geom); } }