#include "debug.h"
#include "coord.h"
#include "projection.h"
+#include "item.h"
#include "map.h"
#include "maptype.h"
#include "transform.h"
-#include "item.h"
#include "plugin.h"
#include "callback.h"
#include "country.h"
* @return The opened map or NULL on failure
*/
struct map *
-map_new(struct attr **attrs)
+map_new(struct attr *parent, struct attr **attrs)
{
struct map *m;
struct map_priv *(*maptype_new)(struct map_methods *meth, struct attr **attrs);
map_set_attr(struct map *this_, struct attr *attr)
{
this_->attrs=attr_generic_set_attr(this_->attrs, attr);
+ if (this_->meth.map_set_attr)
+ this_->meth.map_set_attr(this_->priv, attr);
callback_list_call_attr_2(this_->attr_cbl, attr->type, this_, attr);
return 1;
}
map_rect_get_item(struct map_rect *mr)
{
struct item *ret;
- g_assert(mr != NULL);
- g_assert(mr->m != NULL);
- g_assert(mr->m->meth.map_rect_get_item != NULL);
+ dbg_assert(mr != NULL);
+ dbg_assert(mr->m != NULL);
+ dbg_assert(mr->m->meth.map_rect_get_item != NULL);
ret=mr->m->meth.map_rect_get_item(mr->priv);
if (ret)
ret->map=mr->m;
map_rect_get_item_byid(struct map_rect *mr, int id_hi, int id_lo)
{
struct item *ret=NULL;
- g_assert(mr != NULL);
- g_assert(mr->m != NULL);
+ dbg_assert(mr != NULL);
+ dbg_assert(mr->m != NULL);
if (mr->m->meth.map_rect_get_item_byid)
ret=mr->m->meth.map_rect_get_item_byid(mr->priv, id_hi, id_lo);
if (ret)
void
map_rect_destroy(struct map_rect *mr)
{
- mr->m->meth.map_rect_destroy(mr->priv);
- g_free(mr);
+ if (mr) {
+ mr->m->meth.map_rect_destroy(mr->priv);
+ g_free(mr);
+ }
}
/**
* have a look into country.c for details. Because of that every map plugin has to accept a country item
* to be passed as "superior item".
*
- * Note: If you change something here, please make shure to also update the documentation of mapset_search_new()
+ * Note: If you change something here, please make sure to also update the documentation of mapset_search_new()
* in mapset.c!
*
* @param m The map that should be searched
this_=g_new0(struct map_search,1);
this_->m=m;
this_->search_attr=*search_attr;
- if (search_attr->type >= attr_country_all && search_attr->type <= attr_country_name)
+ if ((search_attr->type >= attr_country_all && search_attr->type <= attr_country_name) || search_attr->type == attr_country_id)
this_->priv=country_search_new(&this_->search_attr, partial);
else {
if (m->meth.map_search_new) {
if (! this_)
return NULL;
- if (this_->search_attr.type >= attr_country_all && this_->search_attr.type <= attr_country_name)
+ if ((this_->search_attr.type >= attr_country_all && this_->search_attr.type <= attr_country_name) || this_->search_attr.type == attr_country_id)
return country_search_get_item(this_->priv);
ret=this_->m->meth.map_search_get_item(this_->priv);
if (ret)
struct map_selection *
map_selection_rect_new(struct pcoord *center, int distance, int order)
{
- int i;
struct map_selection *ret=g_new0(struct map_selection, 1);
- for (i = 0 ; i < layer_end ; i++) {
- ret->order[i]=order;
- }
+ ret->order=order;
+ ret->range=item_range_all;
ret->u.c_rect.lu.x=center->x-distance;
ret->u.c_rect.lu.y=center->y+distance;
ret->u.c_rect.rl.x=center->x+distance;
}
+
+/**
+ * @brief Checks if a selection contains a item range
+ *
+ * This function checks if a selection contains at least one of the items in range
+ *
+ * @param sel The selection to be checked
+ * @param follow Whether the next pointer of the selection should be followed
+ * @param ranges The item ranges to be checked
+ * @count the number of elements in ranges
+ * @return True if there is a match, false otherwise
+ */
+
+int
+map_selection_contains_item_range(struct map_selection *sel, int follow, struct item_range *range, int count)
+{
+ int i;
+ if (! sel)
+ return 1;
+ while (sel) {
+ for (i = 0 ; i < count ; i++) {
+ if (item_range_intersects_range(&sel->range, &range[i]))
+ return 1;
+ }
+ if (! follow)
+ break;
+ sel=sel->next;
+ }
+ return 0;
+}
+/**
+ * @brief Checks if a selection contains a item
+ *
+ * This function checks if a selection contains a item type
+ *
+ * @param sel The selection to be checked
+ * @param follow Whether the next pointer of the selection should be followed
+ * @param item The item type to be checked
+ * @return True if there is a match, false otherwise
+ */
+
+int
+map_selection_contains_item(struct map_selection *sel, int follow, enum item_type type)
+{
+ if (! sel)
+ return 1;
+ while (sel) {
+ if (item_range_contains_item(&sel->range, type))
+ return 1;
+ if (! follow)
+ break;
+ sel=sel->next;
+ }
+ return 0;
+}
+
+
+
/**
* @brief Checks if a pointer points to the private data of a map
*
}
void
-map_dump(struct map *map)
+map_dump_filedesc(struct map *map, FILE *out)
{
struct map_rect *mr=map_rect_new(map, NULL);
struct item *item;
- int i,count,max=16384;
- struct coord ca[max];
- struct attr attr;
-
- while ((item = map_rect_get_item(mr))) {
- count=item_coord_get(item, ca, item->type < type_line ? 1: max);
- if (item->type < type_line)
- printf("mg:0x%x 0x%x ", ca[0].x, ca[0].y);
- printf("%s", item_to_name(item->type));
- while (item_attr_get(item, attr_any, &attr))
- printf(" %s='%s'", attr_to_name(attr.type), attr_to_text(&attr, map, 1));
- printf("\n");
- if (item->type >= type_line)
- for (i = 0 ; i < count ; i++)
- printf("mg:0x%x 0x%x\n", ca[i].x, ca[i].y);
- }
+
+ while ((item = map_rect_get_item(mr)))
+ item_dump_filedesc(item, map, out);
map_rect_destroy(mr);
}
+
+void
+map_dump_file(struct map *map, const char *file)
+{
+ FILE *f;
+ f=fopen(file,"w");
+ if (f) {
+ map_dump_filedesc(map, f);
+ fclose(f);
+ } else
+ dbg(0,"failed to open file '%s'\n",file);
+}
+
+void
+map_dump(struct map *map)
+{
+ map_dump_filedesc(map, stdout);
+}