Пример #1
0
static void osm_delete_relations(osm_upload_context_t *context, gchar *cred) {
  relation_t *relation = context->osm->relation;
  project_t *project = context->project;

  for(; relation; relation = relation->next) {
    /* make sure gui gets updated */
    while(gtk_events_pending()) gtk_main_iteration();

    if(!(OSM_FLAGS(relation) & OSM_FLAG_DELETED))
      continue;

    printf("deleting relation on server\n");

    appendf(&context->log, NULL,
            _("Delete relation #" ITEM_ID_FORMAT " "), OSM_ID(relation));

    char *url = g_strdup_printf("%s/relation/" ITEM_ID_FORMAT,
                                project->server, OSM_ID(relation));
    char *xml_str = osm_generate_xml_relation(context->changeset, relation);

    if(osm_delete_item(&context->log, xml_str, url, cred, context->proxy)) {
      OSM_FLAGS(relation) &= ~(OSM_FLAG_DIRTY | OSM_FLAG_DELETED);
      project->data_dirty = TRUE;
    }
  }
}
Пример #2
0
static void osm_delete_ways(osm_upload_context_t *context, gchar *cred) {
  way_t *way = context->osm->way;
  project_t *project = context->project;

  for(; way; way = way->next) {
    /* make sure gui gets updated */
    while(gtk_events_pending()) gtk_main_iteration();

    if(!(OSM_FLAGS(way) & OSM_FLAG_DELETED))
      continue;

    printf("deleting way on server\n");

    appendf(&context->log, NULL, _("Delete way #" ITEM_ID_FORMAT " "), OSM_ID(way));

    char *url = g_strdup_printf("%s/way/" ITEM_ID_FORMAT,
                                project->server, OSM_ID(way));
    char *xml_str = osm_generate_xml_way(context->changeset, way);

    if(osm_delete_item(&context->log, xml_str, url, cred, context->proxy)) {
      OSM_FLAGS(way) &= ~(OSM_FLAG_DIRTY | OSM_FLAG_DELETED);
      project->data_dirty = TRUE;
    }
  }
}
Пример #3
0
static void osm_delete_nodes(osm_upload_context_t *context, gchar *cred) {
  node_t *node = context->osm->node;
  project_t *project = context->project;

  for(; node; node = node->next) {
    /* make sure gui gets updated */
    while(gtk_events_pending()) gtk_main_iteration();

    if(!(OSM_FLAGS(node) & OSM_FLAG_DELETED))
      continue;

    printf("deleting node on server\n");

    appendf(&context->log, NULL, _("Delete node #" ITEM_ID_FORMAT " "), OSM_ID(node));

    char *url = g_strdup_printf("%s/node/" ITEM_ID_FORMAT,
                                project->server, OSM_ID(node));

    char *xml_str = osm_generate_xml_node(context->changeset, node);

    if(osm_delete_item(&context->log, xml_str, url, cred, context->proxy)) {
      OSM_FLAGS(node) &= ~(OSM_FLAG_DIRTY | OSM_FLAG_DELETED);
      project->data_dirty = TRUE;
    }
  }
}
Пример #4
0
static void osm_upload_relations(osm_upload_context_t *context, gchar *cred) {
  relation_t *relation = context->osm->relation;
  project_t *project = context->project;

  for(; relation; relation = relation->next) {
    /* make sure gui gets updated */
    while(gtk_events_pending()) gtk_main_iteration();

    if(!(OSM_FLAGS(relation) & (OSM_FLAG_DIRTY | OSM_FLAG_NEW)) ||
       (OSM_FLAGS(relation) & OSM_FLAG_DELETED))
      continue;

    char *url = NULL;

    if(OSM_FLAGS(relation) & OSM_FLAG_NEW) {
      url = g_strdup_printf("%s/relation/create", project->server);
      appendf(&context->log, NULL, _("New relation "));
    } else {
      url = g_strdup_printf("%s/relation/" ITEM_ID_FORMAT,
                            project->server,OSM_ID(relation));
      appendf(&context->log, NULL, _("Modified relation #" ITEM_ID_FORMAT " "),
              OSM_ID(relation));
    }

    /* upload this relation */
    char *xml_str = osm_generate_xml_relation(context->changeset, relation);
    if(xml_str) {
      printf("uploading relation %s from address %p\n", url, xml_str);

      if(osm_update_item(&context->log, xml_str, url, cred,
         (OSM_FLAGS(relation) & OSM_FLAG_NEW) ? &(OSM_ID(relation)) :
          &OSM_VERSION(relation), context->proxy)) {
        OSM_FLAGS(relation) &= ~(OSM_FLAG_DIRTY | OSM_FLAG_NEW);
        project->data_dirty = TRUE;
      }
    }
    g_free(url);
  }
}
Пример #5
0
static void osm_upload_ways(osm_upload_context_t *context, gchar *cred) {
  way_t *way = context->osm->way;
  project_t *project = context->project;

  for(; way; way = way->next) {
    /* make sure gui gets updated */
    while(gtk_events_pending()) gtk_main_iteration();

    if(!(OSM_FLAGS(way) & (OSM_FLAG_DIRTY | OSM_FLAG_NEW)) ||
       (OSM_FLAGS(way) & OSM_FLAG_DELETED))
      continue;

    char *url = NULL;

    if(OSM_FLAGS(way) & OSM_FLAG_NEW) {
      url = g_strconcat(project->server, "/way/create", NULL);
      appendf(&context->log, NULL, _("New way "));
    } else {
      url = g_strdup_printf("%s/way/" ITEM_ID_FORMAT,
                            project->server, OSM_ID(way));
      appendf(&context->log, NULL, _("Modified way #" ITEM_ID_FORMAT " "), OSM_ID(way));
    }

    /* upload this node */
    char *xml_str = osm_generate_xml_way(context->changeset, way);
    if(xml_str) {
      printf("uploading way %s from address %p\n", url, xml_str);

      if(osm_update_item(&context->log, xml_str, url, cred,
        (OSM_FLAGS(way) & OSM_FLAG_NEW) ? &(OSM_ID(way)) : &OSM_VERSION(way),
                         context->proxy)) {
        OSM_FLAGS(way) &= ~(OSM_FLAG_DIRTY | OSM_FLAG_NEW);
        project->data_dirty = TRUE;
      }
    }
    g_free(url);
  }
}
Пример #6
0
void josm_elemstyles_colorize_way(const style_t *style, way_t *way) {
  elemstyle_t *elemstyle = style->elemstyles;

  /* use dark grey/no stroke/not filled for everything unknown */
  way->draw.color = style->way.color;
  way->draw.width = style->way.width;
  way->draw.flags = 0;
  way->draw.zoom_max = 0;   // draw at all zoom levels

  /* during the elemstyle search a line_mod may be found. save it here */
  elemstyle_line_mod_t *line_mod = NULL;

  gboolean way_processed = FALSE;
  gboolean way_is_closed = osm_way_is_closed(way);

  while(elemstyle) {
    //  printf("a %s %s\n", elemstyle->condition.key,
    //                        elemstyle->condition.value);

    gboolean match = elemstyle->condition ? TRUE : FALSE;

    elemstyle_condition_t *cond;
    for (cond = elemstyle->condition; cond && match; cond = cond->next) {
      if(cond->key) {
        const char *value = osm_way_get_value(way, (char*)cond->key);
        if(!value || (cond->value && strcasecmp(value, (char*)cond->value) != 0))
          match = FALSE;
      } else if(cond->value) {
        if(!osm_way_has_value(way, (char*)cond->value))
          match = FALSE;
      }
    }

    if(match) {
      switch(elemstyle->type) {
      case ES_TYPE_NONE:
	/* this entry does not contain line or area descriptions and is */
	/* likely just an icon. ignore this as it doesn't make much sense */
	/* for a way */
	break;

      case ES_TYPE_LINE:
	if(!way_processed) {
	  way->draw.color = elemstyle->line->color;
	  way->draw.width =  WIDTH_SCALE * elemstyle->line->width;
	  if(elemstyle->line->bg.valid) {
	    way->draw.flags |= OSM_DRAW_FLAG_BG;
	    way->draw.bg.color = elemstyle->line->bg.color;
	    way->draw.bg.width =  WIDTH_SCALE * elemstyle->line->bg.width;
	  }
	  if (elemstyle->line->zoom_max > 0) {
	    way->draw.zoom_max = elemstyle->line->zoom_max;
	  }
	  else {
	    way->draw.zoom_max = style->way.zoom_max;
	  }
	  way->draw.dashed = elemstyle->line->dashed;
	  way->draw.dash_length = elemstyle->line->dash_length;
	  way_processed = TRUE;
	}
	break;

      case ES_TYPE_LINE_MOD:
	/* just save the fact that a line mod was found for later */
	line_mod = elemstyle->line_mod;
	break;

      case ES_TYPE_AREA:
	if(way_is_closed && !way_processed) {
	  way->draw.flags |= OSM_DRAW_FLAG_AREA;
	  /* comment the following line for grey border around all areas */
	  /* (potlatch style) */

	  if(style->area.has_border_color)
	    way->draw.color = style->area.border_color;
	  else
	    way->draw.color = elemstyle->area->color;

	  way->draw.width =  WIDTH_SCALE * style->area.border_width;
	  /* apply area alpha */
	  way->draw.area.color =
	    RGBA_COMBINE(elemstyle->area->color, style->area.color);
	  if (elemstyle->area->zoom_max > 0) {
	    way->draw.zoom_max = elemstyle->area->zoom_max;
	  }
	  else {
	    way->draw.zoom_max = style->area.zoom_max;
	  }
	  way_processed = TRUE;
	}
	break;
      }
    }
    elemstyle = elemstyle->next;
  }

  /* apply the last line mod entry that has been found during search */
  if(line_mod) {
    printf("applying last matching line mod to way #" ITEM_ID_FORMAT "\n",
	   OSM_ID(way));
    line_mod_apply(&way->draw.width, &line_mod->line);

    /* special case: the way does not have a background, but it is to */
    /* be modified */
    if((line_mod->bg.mod != ES_MOD_NONE) &&
       (!(way->draw.flags & OSM_DRAW_FLAG_BG))) {
      printf("forcing background\n");

      /* add a background in black color */
      way->draw.flags |= OSM_DRAW_FLAG_BG;
      way->draw.bg.color = (0) | 0xff;
      way->draw.bg.width =  way->draw.width;
    }

    line_mod_apply(&way->draw.bg.width, &line_mod->bg);
  }
}