int main(int argc, char **argv) { Args args(argc, argv, "COLOR ..."); const char *s = args.ExpectNext(); while (true) { RGB8Color color; if (!ParseHexColor(s, color)) { fprintf(stderr, "Failed to parse '%s'\n", s); return EXIT_FAILURE; } char buffer[32]; FormatHexColor(buffer, ARRAY_SIZE(buffer), color); printf("%s -> %s\n", s, buffer); if (args.IsEmpty()) break; s = args.ExpectNext(); } return EXIT_SUCCESS; }
bool Profile::GetColor(const TCHAR *key, Color &color) { const TCHAR *color_string = Get(key); if (!color_string) return false; return ParseHexColor(color_string, color); }
bool Profile::GetColor(const char *key, RGB8Color &color) { const char *color_string = Get(key); if (!color_string) return false; return ParseHexColor(color_string, color); }
void UtilityVisitor::startElement(const char *name, const XMLAttributes &atts) { const char *attval; // clear data at the start of each element m_data = ""; if (m_state == 0) { if (!strcmp(name, "UtilityCollection")) { m_state = 1; } else { string message = "Root element name is "; message += name; message += "; expected UtilityCollection"; throw xh_io_exception(message, "XML Reader"); } return; } if (m_state == 1) { if (!strcmp(name, "OverheadLine")) { m_pRoute = new vtRoute(GetCurrentTerrain()); // Create new route (should this be in vtUtilityMap ??) attval = atts.getValue("name"); if (attval) m_pRoute->SetName(attval); // TODO Set Name of the overhead line GetCurrentTerrain()->AddRoute(m_pRoute); m_state = 2; } return; } if (m_state == 2) // Conductor { if (!strcmp(name, "Conductor")) { attval = atts.getValue("width"); if (attval) m_pRoute->SetThickness(atof(attval)); attval = atts.getValue("color"); if (attval) m_pRoute->SetColor(ParseHexColor(attval)); m_state = 3; } return; } if (m_state == 3) // Pylon { if (!strcmp(name, "Pylon")) { attval = atts.getValue("name"); if (attval) SetName(attval); attval = atts.getValue("reference"); if (attval) SetReference(attval); attval = atts.getValue("rotation"); if (attval) SetRotation(atof(attval)); m_state = 4; // now read in the coordinate ... } else m_state = 1; // then it is a new overhead line return; } }
void StructVisitorGML::startElement(const char *name, const XMLAttributes &atts) { const char *attval; float f; // clear data at the start of each element m_data = ""; if (m_state == 0 && !strcmp(name, "StructureCollection")) { m_state = 1; return; } if (m_state == 1) { if (!strcmp(name, "Building")) { m_pBuilding = m_pSA->NewBuilding(); m_pStructure = m_pBuilding; m_state = 2; m_iLevel = 0; } else if (!strcmp(name, "Linear")) { m_pFence = m_pSA->NewFence(); m_pFence->GetParams().Blank(); m_pStructure = m_pFence; // support obsolete attribute attval = atts.getValue("Height"); if (attval) { f = (float) atof(attval); m_pFence->GetParams().m_fPostHeight = f; m_pFence->GetParams().m_fConnectTop = f; } m_state = 10; } else if (!strcmp(name, "Imported")) { m_pInstance = m_pSA->NewInstance(); m_pStructure = m_pInstance; m_state = 20; } attval = atts.getValue("ElevationOffset"); if (attval) m_pStructure->SetElevationOffset((float) atof(attval)); attval = atts.getValue("Absolute"); if (attval) m_pStructure->SetAbsolute(*attval == 't'); return; } if (m_state == 2) // Building { if (!strcmp(name, "Level")) { m_pLevel = m_pBuilding->CreateLevel(); attval = atts.getValue("FloorHeight"); if (attval) m_pLevel->m_fStoryHeight = (float) atof(attval); attval = atts.getValue("StoryCount"); if (attval) m_pLevel->m_iStories = atoi(attval); m_state = 3; m_iEdge = 0; } return; } if (m_state == 3) // Level { if (!strcmp(name, "Footprint")) { m_state = 4; m_Footprint.clear(); } else if (!strcmp(name, "Edge")) { m_pEdge = m_pLevel->GetEdge(m_iEdge); if (m_pEdge) // safety check { m_pEdge->m_Features.clear(); attval = atts.getValue("Material"); if (attval) { vtMaterialDescriptorArray *mats = GetGlobalMaterials(); m_pEdge->m_pMaterial = mats->FindName(attval); if (m_pEdge->m_pMaterial == NULL) { // What to do when a VTST references a material that // we don't have? We don't want to lose the material // name information, and we also don't want to crash // later with a NULL material. So, make a dummy. vtMaterialDescriptor *mat; mat = new vtMaterialDescriptor(attval, "", VT_MATERIAL_COLOUR); mat->SetRGB(RGBi(255,255,255)); // white means: missing mats->Append(mat); m_pEdge->m_pMaterial = &mat->GetName(); } } attval = atts.getValue("Color"); if (attval) m_pEdge->m_Color = ParseHexColor(attval); attval = atts.getValue("Slope"); if (attval) m_pEdge->m_iSlope = atoi(attval); attval = atts.getValue("EaveLength"); if (attval) m_pEdge->m_fEaveLength = (float) atof(attval); attval = atts.getValue("Facade"); if (attval) m_pEdge->m_Facade = attval; } m_state = 7; // in Edge } return; } if (m_state == 4) // Footprint { if (!strcmp(name, "gml:outerBoundaryIs")) m_state = 5; if (!strcmp(name, "gml:innerBoundaryIs")) m_state = 6; } if (m_state == 5) // Footprint outerBoundaryIs { // nothing necessary here, catch the end of element } if (m_state == 6) // Footprint innerBoundaryIs { // nothing necessary here, catch the end of element } if (m_state == 7) // Edge { if (!strcmp(name, "EdgeElement")) { vtEdgeFeature ef; attval = atts.getValue("Type"); if (attval) ef.m_code = vtBuilding::GetEdgeFeatureValue(attval); attval = atts.getValue("Begin"); if (attval) ef.m_vf1 = (float) atof(attval); attval = atts.getValue("End"); if (attval) ef.m_vf2 = (float) atof(attval); if (m_pEdge) m_pEdge->m_Features.push_back(ef); } } if (m_state == 10) // Linear { vtLinearParams ¶m = m_pFence->GetParams(); if (!strcmp(name, "Path")) { m_state = 11; } else if (!strcmp(name, "Posts")) { // this linear structure has posts const char *type = atts.getValue("Type"); if (type) param.m_PostType = type; else param.m_PostType = "none"; const char *spacing = atts.getValue("Spacing"); if (spacing) param.m_fPostSpacing = (float)atof(spacing); const char *height = atts.getValue("Height"); if (height) param.m_fPostHeight = (float)atof(height); const char *size = atts.getValue("Size"); if (size) { FPoint3 postsize; sscanf(size, "%f, %f", &postsize.x, &postsize.z); param.m_fPostWidth = postsize.x; param.m_fPostDepth = postsize.z; } const char *exten = atts.getValue("Extension"); if (exten) param.m_PostExtension = exten; } else if (!strcmp(name, "Connect")) { const char *type = atts.getValue("Type"); if (type) { // Older format version had string "none", "wire", or a material for type // Newer format has integer 0,1,2,3 for none,wire,simple,profile if (*type >= '0' && *type <= '9') param.m_iConnectType = atoi(type); else { // Convert old to new if (!strcmp(type, "none")) param.m_iConnectType = 0; else if (!strcmp(type, "wire")) param.m_iConnectType = 1; else { param.m_iConnectType = 2; param.m_ConnectMaterial = type; } } } else param.m_iConnectType = 0; attval = atts.getValue("Material"); if (attval) param.m_ConnectMaterial = attval; attval = atts.getValue("Top"); if (attval) param.m_fConnectTop = (float)atof(attval); attval = atts.getValue("Bottom"); if (attval) param.m_fConnectBottom = (float)atof(attval); attval = atts.getValue("Width"); if (attval) param.m_fConnectWidth = (float)atof(attval); attval = atts.getValue("Slope"); if (attval) param.m_iConnectSlope = atoi(attval); attval = atts.getValue("ConstantTop"); if (attval) param.m_bConstantTop = (*attval == 't'); attval = atts.getValue("Profile"); if (attval) param.m_ConnectProfile = attval; } } if (m_state == 20) // Imported { if (!strcmp(name, "Location")) { m_state = 21; } } }