bool BaseDataset::parse(const Value &v, const std::string &parentId, bool useCache) { std::lock_guard<std::recursive_mutex> lock(_mutex); AMIGO_LOG_I(TAG, "::parse()...\n"); id = getJSONInt(v, "id"); url = getJSONString(v, "url"); project = getJSONString(v, "project"); name = getJSONString(v, "name"); description = getJSONString(v, "description"); visible = getJSONBool(v, "visible", true); created_on = getJSONString(v, "created_on"); type = getJSONString(v, "type", "raster"); boundingbox = getJSONString(v, "boundingbox"); preview_image = getJSONString(v, "preview_image"); tiles = getJSONString(v, "tiles"); preview = getJSONString(v, "preview"); read_only = getJSONBool(v, "read_only", true); online_only = getJSONBool(v, "online_only", false); return true; }
Field SchemaHelper::parseField(const rapidjson::Document &data, int index) { Field field = std::make_shared<SchemaField>(); field->index = index; field->name = getJSONString(data, "name"); field->type = getJSONString(data, "type"); field->geometry_type = getJSONString(data, "geometry_type"); field->nullable = getJSONBool(data, "nullable"); field->related_to = getJSONLong(data, "related_to", -1); field->max_length = getJSONInt(data, "max_length", -1); field->default_value = getJSONString(data, "default"); StringBuffer buffer; PrettyWriter<StringBuffer> writer(buffer); data.Accept(writer); field->json = buffer.GetString(); if(field->name == "amigo_id") { field->unique = true; } return field; }
Scene *loadScene(char *aFilename) { Scene *t = new Scene; json_stream json; FILE * f = fopen(aFilename, "rb"); json_open_stream(&json, f); json_type type = json_next(&json); assert(type == JSON_OBJECT); while (json_peek(&json) != JSON_OBJECT_END && json_peek(&json) != JSON_ERROR) { type = json_next(&json); assert(type == JSON_STRING); const char *otype = json_get_string(&json, 0); if (strcmp(otype, "material") == 0) { const char *name = "[untitled]"; glm::vec3 diffuse(1); glm::vec3 specular(0); glm::vec3 ambient(0); float opacity = 1; float reflection = 0; type = json_next(&json); assert(type == JSON_OBJECT); while (json_peek(&json) != JSON_OBJECT_END) { type = json_next(&json); assert(type == JSON_STRING); otype = json_get_string(&json, 0); if (!getJSONString(&json, "name", otype, (char**)&name)) if (!getJSONVec3(&json, "diffuse", otype, diffuse)) if (!getJSONVec3(&json, "ambient", otype, ambient)) if (!getJSONVec3(&json, "specular", otype, specular)) if (!getJSONNumber(&json, "opacity", otype, opacity)) if (!getJSONNumber(&json, "reflection", otype, reflection)) assert(0 && "error parsing material"); } type = json_next(&json); assert(type == JSON_OBJECT_END); Material *m = new Material(); m->mName = (char*)name; m->mDiffuse = diffuse; m->mAmbient = ambient; m->mSpecular = specular; m->mOpacity = opacity; m->mReflection = reflection; m->mNext = t->mMaterial; t->mMaterial = m; } else if (strcmp(otype, "box") == 0) { const char *name = "[untitled]"; const char *material = "default"; glm::vec3 center; glm::vec3 size; float dynamic = 0; type = json_next(&json); assert(type == JSON_OBJECT); while (json_peek(&json) != JSON_OBJECT_END) { type = json_next(&json); assert(type == JSON_STRING); otype = json_get_string(&json, 0); if (!getJSONString(&json, "name", otype, (char**)&name)) if (!getJSONString(&json, "material", otype, (char**)&material)) if (!getJSONNumber(&json, "dynamic", otype, dynamic)) if (!getJSONVec3(&json, "position", otype, center)) if (!getJSONVec3(&json, "center", otype, center)) if (!getJSONVec3(&json, "size", otype, size)) assert(0 && "error parsing box"); } type = json_next(&json); assert(type == JSON_OBJECT_END); SceneObject *so; t->insert(so = new Box((char*)name, center, size, t->getMaterialByName((char*)material))); so->mDynamic = dynamic != 0; } else if (strcmp(otype, "plane") == 0) { const char *name = "[untitled]"; const char *material = "default"; glm::vec3 point; glm::vec3 normal; float dynamic = 0; type = json_next(&json); assert(type == JSON_OBJECT); while (json_peek(&json) != JSON_OBJECT_END) { type = json_next(&json); assert(type == JSON_STRING); otype = json_get_string(&json, 0); if (!getJSONString(&json, "name", otype, (char**)&name)) if (!getJSONString(&json, "material", otype, (char**)&material)) if (!getJSONNumber(&json, "dynamic", otype, dynamic)) if (!getJSONVec3(&json, "point", otype, point)) if (!getJSONVec3(&json, "normal", otype, normal)) assert(0 && "error parsing box"); } type = json_next(&json); assert(type == JSON_OBJECT_END); SceneObject *so; t->insert(so = new Plane((char*)name, point, normal, t->getMaterialByName((char*)material))); so->mDynamic = dynamic != 0; } else if (strcmp(otype, "sphere") == 0) { const char *name = "[untitled]"; const char *material = "default"; glm::vec3 center; float radius = 5; float dynamic = 0; type = json_next(&json); assert(type == JSON_OBJECT); while (json_peek(&json) != JSON_OBJECT_END) { type = json_next(&json); assert(type == JSON_STRING); otype = json_get_string(&json, 0); if (!getJSONString(&json, "name", otype, (char**)&name)) if (!getJSONString(&json, "material", otype, (char**)&material)) if (!getJSONNumber(&json, "dynamic", otype, dynamic)) if (!getJSONVec3(&json, "center", otype, center)) if (!getJSONVec3(&json, "position", otype, center)) if (!getJSONNumber(&json, "radius", otype, radius)) assert(0 && "error parsing sphere"); } type = json_next(&json); assert(type == JSON_OBJECT_END); SceneObject *so; t->insert(so = new Sphere((char*)name, center, radius, t->getMaterialByName((char*)material))); so->mDynamic = dynamic != 0; } else if (strcmp(otype, "light") == 0) { const char *name = "[untitled]"; const char *material = "default"; glm::vec3 position; type = json_next(&json); assert(type == JSON_OBJECT); while (json_peek(&json) != JSON_OBJECT_END) { type = json_next(&json); assert(type == JSON_STRING); otype = json_get_string(&json, 0); if (!getJSONString(&json, "name", otype, (char**)&name)) if (!getJSONString(&json, "material", otype, (char**)&material)) if (!getJSONVec3(&json, "position", otype, position)) assert(0 && "error parsing light"); } type = json_next(&json); assert(type == JSON_OBJECT_END); t->insert(new Light((char*)name, position, t->getMaterialByName((char*)material))); } else { assert(0); } } type = json_next(&json); if (type == JSON_ERROR) { const char * err = json_get_error(&json); err = err; } assert(type == JSON_OBJECT_END); type = json_next(&json); assert(type == JSON_DONE); json_close(&json); setupScene(t); t->optimize(); return t; };
bool StyleData::parse(const Value& v, unsigned long projectId) { std::string typeStr = getJSONString(v, "type"); type = _getType(typeStr); zoom_level_min = atoi(getJSONString(v, "zoom_level_min", "2").c_str()); zoom_level_max = atoi(getJSONString(v, "zoom_level_max", "20").c_str()); icon = getJSONString(v, "icon-mobile", "point"); transform = getJSONString(v, "transform", ""); transormValid = _parseTransform(transform); dasharray = getJSONString(v, "dasharray", ""); if(dasharray.empty()) dasharray = getJSONString(v, "outline-dasharray", ""); color = _parseColor( getJSONString(v, "color"), colorValid ); color.v[3] = atof(getJSONString(v, "opacity", "1.0").c_str()); size = atof(getJSONString(v, "size", "0").c_str()); outline_color = _parseColor( getJSONString(v, "outline-color"), outlineColorValid ); outline_color.v[3] = atof(getJSONString(v, "outline-opacity", "1.0").c_str()); outline_size = atof(getJSONString(v, "outline-size", "0").c_str()); filter = getJSONString(v, "filter"); filter_hash = getJSONString(v, "filter_hash"); // Font style field_name = getJSONString(v, "field-name"); font_name = getJSONString(v, "font-name"); font_filename = getJSONString(v, "font-filename"); font_size = atof(getJSONString(v, "font-size", "0").c_str()); font_opacity = atof(getJSONString(v, "font-opacity", "1").c_str()); font_color = _parseColor( getJSONString(v, "font-color"), fontColorValid); font_halo_color = _parseColor( getJSONString(v, "font-halo-color"), fontHaloColorValid); font_halo_size = atof(getJSONString(v, "font-halo-size", "0").c_str()); offset_x = atof(getJSONString(v, "offset-x", "0").c_str()); offset_y = atof(getJSONString(v, "offset-y", "0").c_str()); mode = getJSONString(v, "mode"); modeType = _getType(mode); allow_overlap = getJSONBool(v, "allow-overlap", false); if(type==ICON) { fullIconPath = SupportFiles::getFullPath(projectId) + icon; } return true; }