diff options
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/CMakeLists.txt | 44 | ||||
-rw-r--r-- | src/util/Makefile.am | 51 | ||||
-rw-r--r-- | src/util/Makefile.in | 599 | ||||
-rw-r--r-- | src/util/gmapview.c | 601 | ||||
-rw-r--r-- | src/util/gps.c | 60 | ||||
-rw-r--r-- | src/util/mmapview.c | 762 | ||||
-rw-r--r-- | src/util/qmapview.cpp | 633 | ||||
-rw-r--r-- | src/util/wmapview.c | 653 | ||||
-rw-r--r-- | src/util/worldgen.c | 126 |
9 files changed, 3529 insertions, 0 deletions
diff --git a/src/util/CMakeLists.txt b/src/util/CMakeLists.txt new file mode 100644 index 0000000..1cbabfa --- /dev/null +++ b/src/util/CMakeLists.txt @@ -0,0 +1,44 @@ +project(util) + +find_package(GDAL REQUIRED) + +set(UTIL_INCLUDE_DIRS + ${CMAKE_CURRENT_SOURCE_DIR} + ${GTK2_INCLUDE_DIRS} + ${GDAL_INCLUDE_DIRS} +) + +#includes +set(util_INCLUDE_DIR + ${util_SOURCE_DIR}/ + CACHE INTERNAL "" +) + +add_definitions(-DHAVE_GTK -DHAVE_CAIRO) + +include_directories(${UTIL_INCLUDE_DIRS}) + +set(worldgen_SRCS + worldgen.c +) + +set(gmapview_SRCS + gmapview.c +) + +if (GDAL_FOUND) + add_executable(worldgen ${worldgen_SRCS}) + target_link_libraries(worldgen ${GDAL_LIBRARIES}) + install(TARGETS worldgen DESTINATION ${BIN_INSTALL_DIR}) +endif (GDAL_FOUND) + +if (GDAL_FOUND AND GTK2_FOUND) + add_executable(gmapview ${gmapview_SRCS}) + target_link_libraries(gmapview + map + ${GDAL_LIBRARIES} + ${GTK2_LIBRARIES} + ) + install(TARGETS gmapview DESTINATION ${BIN_INSTALL_DIR}) +endif (GDAL_FOUND AND GTK2_FOUND) + diff --git a/src/util/Makefile.am b/src/util/Makefile.am new file mode 100644 index 0000000..31e4698 --- /dev/null +++ b/src/util/Makefile.am @@ -0,0 +1,51 @@ +LIB_MAP=../lib_map/map_gpsdrive.c ../lib_map/map_load.c \ + ../lib_map/map_transform.c ../lib_map/map_gpsmisc.c \ + ../lib_map/map_render.c \ + ../lib_map/map.h ../lib_map/map_priv.h + + +LIB_MAP_O=../lib_map/map_gpsdrive.o ../lib_map/map_load.o \ + ../lib_map/map_transform.o ../lib_map/map_gpsmisc.o \ + ../lib_map/map_render.o + +LIB_MAP_L= map_gpsdrive.c map_load.c \ + map_transform.c map_gpsmisc.c \ + map_render.c + +if HAVE_GDAL +worldgendir=$(bindir) +worldgen_PROGRAMS = worldgen +worldgen_SOURCES= worldgen.c +# ../lib_map/lib_map.a +worldgen_LDFLAGS = $(GDAL_LIBS) + +if HAVE_GTK +#CFLAGS += -DHAVE_CAIRO +#CFLAGS += -DHAVE_GTK + +# the $(GDAL_LIBS) part is a quick hack. So please could +# someone knowing autoconf reconsidder if there is a better solution +lib_map_lflags = \ + $(GDAL_LIBS) \ + `pkg-config cairo --libs` \ + `pkg-config gtk+-2.0 --libs`\ + `gdal-config --libs` + + +gmapviewdir=$(bindir) +gmapview_PROGRAMS = gmapview +gmapview_SOURCES= gmapview.c +gmapview_LDFLAGS = \ + ../lib_map/lib_map.a \ + $(lib_map_lflags) \ + $(LDADD) $(GDAL_LDADD) $(LFLAGS) -lm +gmapview_CXXFLAGS = $(CFLAGS) $(PREFIX) $(PLUGINPATH) \ + $(PKGDATAPATH) $(GDAL_CFLAGS) $(CXXFLAGS) $(EXTRA_CXXFLAGS) \ + -DHAVE_CAIRO -DHAVE_GTK +endif + +endif + +EXTRA_DIST = $(gmapview_SOURCES) $(worldgen_SOURCES) \ + gps.c mmapview.c qmapview.cpp wmapview.c CMakeLists.txt + diff --git a/src/util/Makefile.in b/src/util/Makefile.in new file mode 100644 index 0000000..45dd458 --- /dev/null +++ b/src/util/Makefile.in @@ -0,0 +1,599 @@ +# Makefile.in generated by automake 1.9.6 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +top_builddir = ../.. +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +INSTALL = @INSTALL@ +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +@HAVE_GDAL_TRUE@worldgen_PROGRAMS = worldgen$(EXEEXT) +@HAVE_GDAL_TRUE@@HAVE_GTK_TRUE@gmapview_PROGRAMS = gmapview$(EXEEXT) +subdir = src/util +DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/m4/ac_check_perl_modules.m4 \ + $(top_srcdir)/m4/ac_check_socketlen_t.m4 \ + $(top_srcdir)/m4/aq_check_gdal.m4 $(top_srcdir)/m4/gettext.m4 \ + $(top_srcdir)/m4/iconv.m4 $(top_srcdir)/m4/lib-ld.m4 \ + $(top_srcdir)/m4/lib-link.m4 $(top_srcdir)/m4/lib-prefix.m4 \ + $(top_srcdir)/m4/nls.m4 $(top_srcdir)/m4/po.m4 \ + $(top_srcdir)/m4/progtest.m4 $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +am__installdirs = "$(DESTDIR)$(gmapviewdir)" \ + "$(DESTDIR)$(worldgendir)" +gmapviewPROGRAMS_INSTALL = $(INSTALL_PROGRAM) +worldgenPROGRAMS_INSTALL = $(INSTALL_PROGRAM) +PROGRAMS = $(gmapview_PROGRAMS) $(worldgen_PROGRAMS) +am__gmapview_SOURCES_DIST = gmapview.c +@HAVE_GDAL_TRUE@@HAVE_GTK_TRUE@am_gmapview_OBJECTS = \ +@HAVE_GDAL_TRUE@@HAVE_GTK_TRUE@ gmapview.$(OBJEXT) +gmapview_OBJECTS = $(am_gmapview_OBJECTS) +gmapview_LDADD = $(LDADD) +am__worldgen_SOURCES_DIST = worldgen.c +@HAVE_GDAL_TRUE@am_worldgen_OBJECTS = worldgen.$(OBJEXT) +worldgen_OBJECTS = $(am_worldgen_OBJECTS) +worldgen_LDADD = $(LDADD) +DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir) +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__depfiles_maybe = depfiles +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --tag=CC --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(AM_LDFLAGS) $(LDFLAGS) -o $@ +SOURCES = $(gmapview_SOURCES) $(worldgen_SOURCES) +DIST_SOURCES = $(am__gmapview_SOURCES_DIST) \ + $(am__worldgen_SOURCES_DIST) +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +pkgdatadir = @pkgdatadir@ +ACLOCAL = @ACLOCAL@ +AMAPNIK = @AMAPNIK@ +AMDEP_FALSE = @AMDEP_FALSE@ +AMDEP_TRUE = @AMDEP_TRUE@ +AMTAR = @AMTAR@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DBUS_CFLAGS = @DBUS_CFLAGS@ +DBUS_GLIB_LIBS = @DBUS_GLIB_LIBS@ +DBUS_LIBS = @DBUS_LIBS@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DISABLEGARMIN_FALSE = @DISABLEGARMIN_FALSE@ +DISABLEGARMIN_TRUE = @DISABLEGARMIN_TRUE@ +DISABLEPLUGINS_FALSE = @DISABLEPLUGINS_FALSE@ +DISABLEPLUGINS_TRUE = @DISABLEPLUGINS_TRUE@ +ECHO = @ECHO@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +F77 = @F77@ +FFLAGS = @FFLAGS@ +FRIENDSSERVERVERSION = @FRIENDSSERVERVERSION@ +GDAL_CFLAGS = @GDAL_CFLAGS@ +GDAL_CONFIG = @GDAL_CONFIG@ +GDAL_LDADD = @GDAL_LDADD@ +GETTEXT_PACKAGE = @GETTEXT_PACKAGE@ +GLIB_CFLAGS = @GLIB_CFLAGS@ +GLIB_GENMARSHAL = @GLIB_GENMARSHAL@ +GLIB_LIBS = @GLIB_LIBS@ +GLIB_MKENUMS = @GLIB_MKENUMS@ +GMSGFMT = @GMSGFMT@ +GMSGFMT_015 = @GMSGFMT_015@ +GOBJECT_QUERY = @GOBJECT_QUERY@ +GREP = @GREP@ +GTK_CFLAGS = @GTK_CFLAGS@ +GTK_LIBS = @GTK_LIBS@ +HAVE_DBUS_FALSE = @HAVE_DBUS_FALSE@ +HAVE_DBUS_TRUE = @HAVE_DBUS_TRUE@ +HAVE_GDAL_FALSE = @HAVE_GDAL_FALSE@ +HAVE_GDAL_TRUE = @HAVE_GDAL_TRUE@ +HAVE_GTK_FALSE = @HAVE_GTK_FALSE@ +HAVE_GTK_TRUE = @HAVE_GTK_TRUE@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +INTLLIBS = @INTLLIBS@ +INTL_MACOSX_LIBS = @INTL_MACOSX_LIBS@ +LDFLAGS = @LDFLAGS@ +LIBADD_DL = @LIBADD_DL@ +LIBICONV = @LIBICONV@ +LIBINTL = @LIBINTL@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LN_S = @LN_S@ +LTLIBICONV = @LTLIBICONV@ +LTLIBINTL = @LTLIBINTL@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +MSGFMT = @MSGFMT@ +MSGFMT_015 = @MSGFMT_015@ +MSGMERGE = @MSGMERGE@ +NOGARMIN = @NOGARMIN@ +NOPLUGINS = @NOPLUGINS@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PCRE_CONFIG = @PCRE_CONFIG@ +PERL = @PERL@ +PERL_PACKAGE_DIR = @PERL_PACKAGE_DIR@ +PKGCONFIG_CFLAGS = @PKGCONFIG_CFLAGS@ +PKGCONFIG_LIBS = @PKGCONFIG_LIBS@ +PKG_CONFIG = @PKG_CONFIG@ +POSUB = @POSUB@ +POW_LIB = @POW_LIB@ +RANLIB = @RANLIB@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +USE_NLS = @USE_NLS@ +VERSION = @VERSION@ +WITH_MAPNIK_FALSE = @WITH_MAPNIK_FALSE@ +WITH_MAPNIK_TRUE = @WITH_MAPNIK_TRUE@ +XGETTEXT = @XGETTEXT@ +XGETTEXT_015 = @XGETTEXT_015@ +XML_CFLAGS = @XML_CFLAGS@ +XML_LIBS = @XML_LIBS@ +YACC = @YACC@ +YFLAGS = @YFLAGS@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_F77 = @ac_ct_F77@ +am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ +am__fastdepCC_TRUE = @am__fastdepCC_TRUE@ +am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@ +am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +LIB_MAP = ../lib_map/map_gpsdrive.c ../lib_map/map_load.c \ + ../lib_map/map_transform.c ../lib_map/map_gpsmisc.c \ + ../lib_map/map_render.c \ + ../lib_map/map.h ../lib_map/map_priv.h + +LIB_MAP_O = ../lib_map/map_gpsdrive.o ../lib_map/map_load.o \ + ../lib_map/map_transform.o ../lib_map/map_gpsmisc.o \ + ../lib_map/map_render.o + +LIB_MAP_L = map_gpsdrive.c map_load.c \ + map_transform.c map_gpsmisc.c \ + map_render.c + +@HAVE_GDAL_TRUE@worldgendir = $(bindir) +@HAVE_GDAL_TRUE@worldgen_SOURCES = worldgen.c +# ../lib_map/lib_map.a +@HAVE_GDAL_TRUE@worldgen_LDFLAGS = $(GDAL_LIBS) + +#CFLAGS += -DHAVE_CAIRO +#CFLAGS += -DHAVE_GTK + +# the $(GDAL_LIBS) part is a quick hack. So please could +# someone knowing autoconf reconsidder if there is a better solution +@HAVE_GDAL_TRUE@@HAVE_GTK_TRUE@lib_map_lflags = \ +@HAVE_GDAL_TRUE@@HAVE_GTK_TRUE@ $(GDAL_LIBS) \ +@HAVE_GDAL_TRUE@@HAVE_GTK_TRUE@ `pkg-config cairo --libs` \ +@HAVE_GDAL_TRUE@@HAVE_GTK_TRUE@ `pkg-config gtk+-2.0 --libs`\ +@HAVE_GDAL_TRUE@@HAVE_GTK_TRUE@ `gdal-config --libs` + +@HAVE_GDAL_TRUE@@HAVE_GTK_TRUE@gmapviewdir = $(bindir) +@HAVE_GDAL_TRUE@@HAVE_GTK_TRUE@gmapview_SOURCES = gmapview.c +@HAVE_GDAL_TRUE@@HAVE_GTK_TRUE@gmapview_LDFLAGS = \ +@HAVE_GDAL_TRUE@@HAVE_GTK_TRUE@ ../lib_map/lib_map.a \ +@HAVE_GDAL_TRUE@@HAVE_GTK_TRUE@ $(lib_map_lflags) \ +@HAVE_GDAL_TRUE@@HAVE_GTK_TRUE@ $(LDADD) $(GDAL_LDADD) $(LFLAGS) -lm + +@HAVE_GDAL_TRUE@@HAVE_GTK_TRUE@gmapview_CXXFLAGS = $(CFLAGS) $(PREFIX) $(PLUGINPATH) \ +@HAVE_GDAL_TRUE@@HAVE_GTK_TRUE@ $(PKGDATAPATH) $(GDAL_CFLAGS) $(CXXFLAGS) $(EXTRA_CXXFLAGS) \ +@HAVE_GDAL_TRUE@@HAVE_GTK_TRUE@ -DHAVE_CAIRO -DHAVE_GTK + +EXTRA_DIST = $(gmapview_SOURCES) $(worldgen_SOURCES) \ + gps.c mmapview.c qmapview.cpp wmapview.c CMakeLists.txt + +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ + && exit 0; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/util/Makefile'; \ + cd $(top_srcdir) && \ + $(AUTOMAKE) --gnu src/util/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +install-gmapviewPROGRAMS: $(gmapview_PROGRAMS) + @$(NORMAL_INSTALL) + test -z "$(gmapviewdir)" || $(mkdir_p) "$(DESTDIR)$(gmapviewdir)" + @list='$(gmapview_PROGRAMS)'; for p in $$list; do \ + p1=`echo $$p|sed 's/$(EXEEXT)$$//'`; \ + if test -f $$p \ + || test -f $$p1 \ + ; then \ + f=`echo "$$p1" | sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`; \ + echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) --mode=install $(gmapviewPROGRAMS_INSTALL) '$$p' '$(DESTDIR)$(gmapviewdir)/$$f'"; \ + $(INSTALL_PROGRAM_ENV) $(LIBTOOL) --mode=install $(gmapviewPROGRAMS_INSTALL) "$$p" "$(DESTDIR)$(gmapviewdir)/$$f" || exit 1; \ + else :; fi; \ + done + +uninstall-gmapviewPROGRAMS: + @$(NORMAL_UNINSTALL) + @list='$(gmapview_PROGRAMS)'; for p in $$list; do \ + f=`echo "$$p" | sed 's,^.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \ + echo " rm -f '$(DESTDIR)$(gmapviewdir)/$$f'"; \ + rm -f "$(DESTDIR)$(gmapviewdir)/$$f"; \ + done + +clean-gmapviewPROGRAMS: + @list='$(gmapview_PROGRAMS)'; for p in $$list; do \ + f=`echo $$p|sed 's/$(EXEEXT)$$//'`; \ + echo " rm -f $$p $$f"; \ + rm -f $$p $$f ; \ + done +install-worldgenPROGRAMS: $(worldgen_PROGRAMS) + @$(NORMAL_INSTALL) + test -z "$(worldgendir)" || $(mkdir_p) "$(DESTDIR)$(worldgendir)" + @list='$(worldgen_PROGRAMS)'; for p in $$list; do \ + p1=`echo $$p|sed 's/$(EXEEXT)$$//'`; \ + if test -f $$p \ + || test -f $$p1 \ + ; then \ + f=`echo "$$p1" | sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`; \ + echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) --mode=install $(worldgenPROGRAMS_INSTALL) '$$p' '$(DESTDIR)$(worldgendir)/$$f'"; \ + $(INSTALL_PROGRAM_ENV) $(LIBTOOL) --mode=install $(worldgenPROGRAMS_INSTALL) "$$p" "$(DESTDIR)$(worldgendir)/$$f" || exit 1; \ + else :; fi; \ + done + +uninstall-worldgenPROGRAMS: + @$(NORMAL_UNINSTALL) + @list='$(worldgen_PROGRAMS)'; for p in $$list; do \ + f=`echo "$$p" | sed 's,^.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \ + echo " rm -f '$(DESTDIR)$(worldgendir)/$$f'"; \ + rm -f "$(DESTDIR)$(worldgendir)/$$f"; \ + done + +clean-worldgenPROGRAMS: + @list='$(worldgen_PROGRAMS)'; for p in $$list; do \ + f=`echo $$p|sed 's/$(EXEEXT)$$//'`; \ + echo " rm -f $$p $$f"; \ + rm -f $$p $$f ; \ + done +gmapview$(EXEEXT): $(gmapview_OBJECTS) $(gmapview_DEPENDENCIES) + @rm -f gmapview$(EXEEXT) + $(LINK) $(gmapview_LDFLAGS) $(gmapview_OBJECTS) $(gmapview_LDADD) $(LIBS) +worldgen$(EXEEXT): $(worldgen_OBJECTS) $(worldgen_DEPENDENCIES) + @rm -f worldgen$(EXEEXT) + $(LINK) $(worldgen_LDFLAGS) $(worldgen_OBJECTS) $(worldgen_LDADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gmapview.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/worldgen.Po@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c $< + +.c.obj: +@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ `$(CYGPATH_W) '$<'`; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ if $(LTCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Plo"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +distclean-libtool: + -rm -f libtool +uninstall-info-am: + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$tags $$unique; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(CTAGS_ARGS)$$tags$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$tags $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && cd $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) $$here + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \ + list='$(DISTFILES)'; for file in $$list; do \ + case $$file in \ + $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \ + $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \ + esac; \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test "$$dir" != "$$file" && test "$$dir" != "."; then \ + dir="/$$dir"; \ + $(mkdir_p) "$(distdir)$$dir"; \ + else \ + dir=''; \ + fi; \ + if test -d $$d/$$file; then \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + fi; \ + cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ + else \ + test -f $(distdir)/$$file \ + || cp -p $$d/$$file $(distdir)/$$file \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(PROGRAMS) +installdirs: + for dir in "$(DESTDIR)$(gmapviewdir)" "$(DESTDIR)$(worldgendir)"; do \ + test -z "$$dir" || $(mkdir_p) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-gmapviewPROGRAMS clean-libtool \ + clean-worldgenPROGRAMS mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-libtool distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +info: info-am + +info-am: + +install-data-am: install-gmapviewPROGRAMS install-worldgenPROGRAMS + +install-exec-am: + +install-info: install-info-am + +install-man: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-gmapviewPROGRAMS uninstall-info-am \ + uninstall-worldgenPROGRAMS + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-gmapviewPROGRAMS clean-libtool clean-worldgenPROGRAMS \ + ctags distclean distclean-compile distclean-generic \ + distclean-libtool distclean-tags distdir dvi dvi-am html \ + html-am info info-am install install-am install-data \ + install-data-am install-exec install-exec-am \ + install-gmapviewPROGRAMS install-info install-info-am \ + install-man install-strip install-worldgenPROGRAMS \ + installcheck installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags uninstall uninstall-am uninstall-gmapviewPROGRAMS \ + uninstall-info-am uninstall-worldgenPROGRAMS + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/src/util/gmapview.c b/src/util/gmapview.c new file mode 100644 index 0000000..bb0979f --- /dev/null +++ b/src/util/gmapview.c @@ -0,0 +1,601 @@ +// +// Copyright (c) 2005 -- Daniel Wallner +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// + +#include "../lib_map/map.h" + +#include <gtk/gtk.h> +#include <stdio.h> +#ifdef USE_CAIRO +#include <cairo.h> +#endif + +#include <unistd.h> +#include <stdlib.h> + +void init_gps(); +void free_gps(); + +#define PIXEL_SIZE 0.22E-3 +#define SCALE_RATIO 10 + +MapSettings mapsettings; +MapSet mapset; +MapState mapstates[16]; +GtkWidget *canvases[16]; +int views = 1; +int render_mode = 0x100; +int cover = 0; +int transparent = 0; +double pixel_size = PIXEL_SIZE; +int noZoom = FALSE; + +static void expose(GtkWidget *widget, GdkEventExpose *event, + MapState *mapstate) +{ + gint width = widget->allocation.width; + gint height = widget->allocation.height; + +#ifdef USE_CAIRO + MapGC mgc; + + memset((void*)&mgc, 0, sizeof(mgc)); + + mgc.cairo_cr = gdk_cairo_create(widget->window); + + if (cover) + coverifpossible(mapstate, width, height); + + drawmap(mapstate, &mgc, width, height, transparent); + + drawmarkers(&mgc, width, height, + &mapsettings, mapstate, pixel_size, + 0, 0); + + cairo_destroy(mgc.cairo_cr); +#else + MapGC mgc; + + memset((void*)&mgc, 0, sizeof(mgc)); + + mgc.gtk_widget = widget; + mgc.gtk_drawable = widget->window; + mgc.gtk_gc = gdk_gc_new(widget->window); + + if (cover) + coverifpossible(mapstate, width, height); + + drawmap(mapstate, &mgc, width, height, transparent); + + drawmarkers(&mgc, width, height, + &mapsettings, mapstate, pixel_size, + 0, 0); + + gdk_gc_unref(mgc.gtk_gc); +#endif +} + +static gboolean button_press(GtkWidget *widget, GdkEventButton *event, + MapState *mapstate) +{ + int i; + + mapsettings.posmode = TRUE; + + screen2wgs(mapstate, event->x, event->y, + &mapstate->req_lat, &mapstate->req_lon); + + fprintf(stderr, "new center: %lf;%lf\n", + mapstate->req_lat, mapstate->req_lon); + + for (i = 0; i < views; i++) + { + mapstates[i].req_lat = mapstate->req_lat; + mapstates[i].req_lon = mapstate->req_lon; + + if (views != mapset.maps) + { + selectbestmap(&mapset, &mapstates[i], render_mode, pixel_size); + } + else + { + double pseudo_lat = (render_mode & 0x100) ? mapstate->req_lat : 0; + + wgs2pixel(mapstates[i].dataset[0], mapstates[i].path[0], + mapstate->req_lat, mapstate->req_lon, + &mapstates[i].act_xPixel[0], &mapstates[i].act_yPixel[0]); + + scale2zoom(mapstates[i].dataset[0], mapstates[i].path[0], + mapstates[i].req_scale, pixel_size, pseudo_lat, + &mapstates[i].act_xZoom[0], &mapstates[i].act_yZoom[0]); + } + + if (noZoom) + { + mapstates[i].act_xZoom[0] = 1; + mapstates[i].act_yZoom[0] = 1; + } + + gtk_widget_queue_draw(canvases[i]); + } + + return TRUE; +} + +static gint key_press(GtkWidget *widget, GdkEventKey *event, + MapState *mapstate) +{ + int i; + + int redraw = 0; + + double factor = 1; + + if (!event->length) + return FALSE; + + switch (event->string[0]) + { + case '+': + factor = 1 / 1.5; + redraw = 1; + break; + + case '-': + factor = 1.5; + redraw = 1; + break; + + case 'm': + render_mode = (render_mode & 0xfff0) + (((render_mode & 0x0f) + 1) % 3); + redraw = 1; + break; + + case 'f': + render_mode = (render_mode & 0xff0f) + + (((((render_mode & 0xf0) >> 4) + 1) % 3) << 4); + redraw = 1; + break; + + case 'a': + render_mode = render_mode | 0x200; + redraw = 1; + break; + + case 'c': + cover = !cover; + redraw = 1; + break; + + case 'p': + mapsettings.havepos = !mapsettings.havepos; + redraw = 1; + break; + + case 's': + render_mode ^= 0x100; + redraw = 1; + break; + + case 'g': + mapsettings.drawgrid = !mapsettings.drawgrid; + redraw = 1; + break; + + case 't': + transparent = !transparent; + redraw = 1; + break; + + case 'r': + mapstate->req_rotation += 45; + if (mapstate->req_rotation >= 360) + mapstate->req_rotation -= 360; + redraw = 1; + break; + } + + fprintf(stderr, "mode: %X\n", render_mode); + + if (redraw) + for (i = 0; i < views; i++) + { + mapstates[i].req_scale *= factor; + + if (views != mapset.maps) + { + selectbestmap(&mapset, &mapstates[i], render_mode, pixel_size); + } + else + { + double pseudo_lat = (render_mode & 0x100) ? mapstate->req_lat : 0; + + wgs2pixel(mapstates[i].dataset[0], mapstates[i].path[0], + mapstate->req_lat, mapstate->req_lon, + &mapstates[i].act_xPixel[0], + &mapstates[i].act_yPixel[0]); + + scale2zoom(mapstates[i].dataset[0], mapstates[i].path[0], + mapstates[i].req_scale, pixel_size, pseudo_lat, + &mapstates[i].act_xZoom[0], &mapstates[i].act_yZoom[0]); + } + + if (noZoom) + { + mapstates[i].act_xZoom[0] = 1; + mapstates[i].act_yZoom[0] = 1; + } + + gtk_widget_queue_draw(canvases[i]); + } + + render_mode &= ~0x200; + + return TRUE; +} + +void usage() +{ + fprintf(stderr, "libmap test and sample application\n\n"); + fprintf(stderr, " usage: gmapview [input map files or directories] [options and arguments]\n\n"); + fprintf(stderr, " -h print this message\n"); + fprintf(stderr, " -a latitude initial latitude\n"); + fprintf(stderr, " -o longitude initial longitude\n"); + fprintf(stderr, " -s scale initial scale\n"); + fprintf(stderr, " -r rotation initial rotation\n"); + fprintf(stderr, " -p pixel size (mm) pixel size\n"); + fprintf(stderr, " -d dpi (1/inch) pixel size\n"); + fprintf(stderr, " -z no zoom\n"); + fprintf(stderr, " -v n number of views\n"); + fprintf(stderr, " -w windowed views\n"); + fprintf(stderr, " -l linear view scale\n"); + fprintf(stderr, " -m ratio view scale ratio\n\n"); + fprintf(stderr, " If no input is given, gmapview uses the current directory.\n"); + fprintf(stderr, " When the number of views equals the number of maps,\n"); + fprintf(stderr, " each map is fixed to each view.\n"); + fprintf(stderr, " You can combine short flags, so `-w -z' means the same as -wz or -zw.\n"); + fprintf(stderr, "\n When gmapview is running it can be controlled with the following keys:\n"); + fprintf(stderr, "\n + Zoom in\n"); + fprintf(stderr, " - Zoom out\n"); + fprintf(stderr, " m Drawing mode (Single, overview, tiled)\n"); + fprintf(stderr, " f Filter maps (Street, topo, all)\n"); + fprintf(stderr, " a Show alternate map\n"); + fprintf(stderr, " c Cover if possible\n"); + fprintf(stderr, " p Show current position\n"); + fprintf(stderr, " s Pseudo projection\n"); + fprintf(stderr, " g Grid\n"); + fprintf(stderr, " t Transparent\n"); + fprintf(stderr, " r Rotate\n"); + fprintf(stderr, "\n Left mouse click selects a new center point.\n"); +} + +int main(int argc, char **argv) +{ + extern char *optarg; + extern int optind; + extern int optopt; + + int i; + + GtkWidget *windows[16]; + GtkWidget *paned; + GtkWidget *box1 = NULL; + GtkWidget *box2 = NULL; + + gboolean windowed = FALSE; + gboolean latSet = FALSE; + gboolean lonSet = FALSE; + gboolean scaleSet = FALSE; + gboolean linear = FALSE; + double ratio = SCALE_RATIO; + + gtk_init(&argc, &argv); + + mapinit(&mapsettings); + + resetmap(&mapstates[0]); + + while (optind < argc) + { + if (argv[optind][0] != '-' || strlen(argv[optind]) <= 1) + { + // Load maps + if (!addmaps(argv[optind], &mapset)) + { + fprintf(stderr, + "Unable to open input file: %s\n", + argv[optind]); + return 1; + } + + optind++; + } + else + { + // Option + int opt = getopt(argc, argv, ":ha:o:s:r:p:d:zv:wlm:"); + if (opt != -1) + { + switch (opt) + { + case 'h': + usage(); + return 1; + + case 'a': + mapstates[0].req_lat = atof(optarg); + latSet = TRUE; + break; + + case 'o': + mapstates[0].req_lon = atof(optarg); + lonSet = TRUE; + break; + + case 's': + mapstates[0].req_scale = atof(optarg); + scaleSet = TRUE; + break; + + case 'r': + mapstates[0].req_rotation = atof(optarg) * M_PI / 180; + break; + + case 'p': + pixel_size = atof(optarg) / 1000; + break; + + case 'd': + pixel_size = 0.0254 / atof(optarg); + break; + + case 'z': + noZoom = TRUE; + break; + + case 'v': + views = atoi(optarg); + break; + + case 'w': + windowed = TRUE; + break; + + case 'l': + linear = TRUE; + break; + + case 'm': + ratio = atof(optarg); + break; + + case ':': // No argument + fprintf(stderr, + "Option -%c is missing an argument\n", + (char)optopt); + return 1; + + case '?': + default: + fprintf(stderr, + "Unknown option -%c\n", + (char)optopt); + return 1; + } + } + } + } + + if (!mapset.maps && !addmaps(".", &mapset)) + { + fprintf(stderr, "No maps in current directory\n"); + return 1; + } + + if (views < 0 || views > 16) + { + fprintf(stderr, "Unsupported number of views\n"); + return 1; + } + + { + GInt32 xPixel; + GInt32 yPixel; + + double lat; + double lon; + + int smallest = -1; + double smallestScale = 0; + + // Find smallest map + for (i = 0; i < mapset.maps; i++) + { + double scale; + + scale2zoom(mapset.dataset[i], mapset.path[i], + 1, pixel_size, 0, &scale, &scale); + + if (smallest == -1 || scale < smallestScale) + { + smallest = i; + smallestScale = scale; + } + } + + // Center on smallest map + center2pixel(mapset.dataset[smallest], &xPixel, &yPixel); + pixel2wgs(mapset.dataset[smallest], mapset.path[smallest], + xPixel, yPixel, &lat, &lon); + + if (latSet) + { + lat = mapstates[0].req_lat; + } + if (lonSet) + { + lon = mapstates[0].req_lon; + } + + // Init mapstates + for (i = 0; i < views; i++) + { + if (i) + resetmap(&mapstates[i]); + + mapstates[i].req_lat = lat; + mapstates[i].req_lon = lon; + + mapstates[i].req_rotation = mapstates[0].req_rotation; + + if (views == mapset.maps) + { + mapstates[i].dataset[0] = mapset.dataset[i]; + mapstates[i].path[0] = mapset.path[i]; + mapstates[i].dataset[1] = NULL; + mapstates[i].path[1] = NULL; + + scale2zoom(mapstates[i].dataset[0], mapstates[i].path[0], + 1, pixel_size, 0, + &mapstates[i].req_scale, &mapstates[i].req_scale); + + mapstates[i].act_xZoom[0] = 1.0; + mapstates[i].act_yZoom[0] = 1.0; + } + else + { + if (i == 0 && !scaleSet) + { + mapstates[i].dataset[0] = mapset.dataset[smallest]; + mapstates[i].path[0] = mapset.path[smallest]; + + scale2zoom(mapset.dataset[smallest], mapset.path[smallest], + 1, pixel_size, 0, + &mapstates[0].req_scale, &mapstates[0].req_scale); + } + + // Set scales relative to smallest map + if (i) + { + if (linear) + mapstates[i].req_scale = ratio * i * mapstates[0].req_scale; + else + mapstates[i].req_scale = ratio * mapstates[i - 1].req_scale; + } + + selectbestmap(&mapset, &mapstates[i], render_mode, pixel_size); + } + + if (noZoom) + { + mapstates[i].act_xZoom[0] = 1; + mapstates[i].act_yZoom[0] = 1; + } + + wgs2pixel(mapstates[i].dataset[0], mapstates[i].path[0], lat, lon, + &mapstates[i].act_xPixel[0], &mapstates[i].act_yPixel[0]); + } + } + + if (views == 1) + windowed = TRUE; + + if (windowed) + { + for (i = 0; i < views; i++) + { + windows[i] = gtk_window_new(GTK_WINDOW_TOPLEVEL); + + g_signal_connect(G_OBJECT(windows[i]), "delete-event", + G_CALLBACK(gtk_main_quit), NULL); + + g_signal_connect(G_OBJECT(windows[i]), "key_press_event", + G_CALLBACK(key_press), mapstates); + } + } + else + { + windows[0] = gtk_window_new(GTK_WINDOW_TOPLEVEL); + + g_signal_connect(G_OBJECT(windows[0]), "delete-event", + G_CALLBACK(gtk_main_quit), NULL); + + g_signal_connect(G_OBJECT(windows[0]), "key_press_event", + G_CALLBACK(key_press), mapstates); + + paned = gtk_hpaned_new(); + + gtk_container_add(GTK_CONTAINER(windows[0]), paned); + + box1 = gtk_vbox_new(TRUE, 4); + box2 = gtk_vbox_new(TRUE, 4); + + gtk_paned_pack1(GTK_PANED(paned), box1, FALSE, FALSE); + gtk_paned_pack2(GTK_PANED(paned), box2, FALSE, FALSE); + } + + for (i = 0; i < views; i++) + { + canvases[i] = gtk_drawing_area_new(); + + gtk_widget_set_size_request(canvases[i], 100, 100); + + gtk_widget_add_events(canvases[i], GDK_BUTTON_PRESS_MASK); + + g_signal_connect(G_OBJECT(canvases[i]), "expose-event", + G_CALLBACK(expose), &mapstates[i]); + + g_signal_connect(G_OBJECT(canvases[i]), "button_press_event", + G_CALLBACK(button_press), &mapstates[i]); + + if (windowed) + { + gtk_container_add(GTK_CONTAINER(windows[i]), canvases[i]); + + gtk_widget_show_all(windows[i]); + } + else + { + if ((i & 1 && (!(views & 1) || i < 2)) || + (!(i & 1) && (views & 1) && (i > 1))) + { + gtk_box_pack_start_defaults(GTK_BOX(box2), canvases[i]); + } + else + { + gtk_box_pack_start_defaults(GTK_BOX(box1), canvases[i]); + } + } + } + + if (!windowed) + gtk_widget_show_all(windows[0]); + +#ifdef HAVE_GPS + init_gps(); +#endif + + gtk_main(); + +#ifdef HAVE_GPS + free_gps(); +#endif + + freemaps(&mapset); + + return 0; +} diff --git a/src/util/gps.c b/src/util/gps.c new file mode 100644 index 0000000..0340b15 --- /dev/null +++ b/src/util/gps.c @@ -0,0 +1,60 @@ +// +// Copyright (c) 2005 -- Daniel Wallner +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// + +#ifdef HAVE_GPS + +#include <../lib_map/gps.h> + +#include <stdio.h> + +struct gps_data_t *gpsdata; +pthread_t handler; + +void gps_callback(struct gps_data_t *sentence, + char *buf, size_t len, int level) +{ + printf("gps\n"); +} + +void init_gps() +{ + gpsdata = gps_open("localhost", DEFAULT_GPSD_PORT); + + if (!gpsdata) + { + fprintf(stderr, "Unable to open gps\n"); + return; + } + + if (!gps_set_callback(gpsdata, gps_callback, &handler)) + { + fprintf(stderr, "Unable to create gps thread\n"); + return; + } +} + +void free_gps() +{ + if (gpsdata) + { + gps_del_callback(gpsdata, &handler); + gps_close(gpsdata); + } +} + +#endif diff --git a/src/util/mmapview.c b/src/util/mmapview.c new file mode 100644 index 0000000..5988abb --- /dev/null +++ b/src/util/mmapview.c @@ -0,0 +1,762 @@ +// +// Copyright (c) 2005 -- Daniel Wallner +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// + +#include "../lib_map/map.h" + +#include <stdio.h> +#ifdef USE_CAIRO +#include <cairo.h> +#endif +#include <Carbon/Carbon.h> + +#include <unistd.h> +#include <stdlib.h> + +void init_gps(); +void free_gps(); + +#define PIXEL_SIZE 0.22E-3 +#define SCALE_RATIO 10 + +typedef struct +{ + HIViewRef view; + MapState *mapstate; +} +ViewData; + +MapSettings mapsettings; +MapSet mapset; +MapState mapstates[16]; +ViewData canvases[16]; +int views = 1; +int render_mode = 0x100; +int cover = 0; +int draw_transparent = 0; +double pixel_size = PIXEL_SIZE; +int noZoom = FALSE; + +static void expose(CGContextRef gc, int width, int height, MapState *mapstate) +{ +#ifdef USE_CAIRO +#else + MapGC mgc; + + memset((void*)&mgc, 0, sizeof(mgc)); + + mgc.quartz_gc = gc; + + if (cover) + coverifpossible(mapstate, width, height); + + drawmap(mapstate, &mgc, width, height, draw_transparent); + + drawmarkers(&mgc, width, height, + &mapsettings, mapstate, pixel_size, + 0, 0); +#endif +} + +static void button_press(int x, int y, MapState *mapstate) +{ + int i; + + mapsettings.posmode = TRUE; + + screen2wgs(mapstate, x, y, + &mapstate->req_lat, &mapstate->req_lon); + + fprintf(stderr, "new center: %lf;%lf\n", + mapstate->req_lat, mapstate->req_lon); + + for (i = 0; i < views; i++) + { + mapstates[i].req_lat = mapstate->req_lat; + mapstates[i].req_lon = mapstate->req_lon; + + if (views != mapset.maps) + { + selectbestmap(&mapset, &mapstates[i], render_mode, pixel_size); + } + else + { + double pseudo_lat = (render_mode & 0x100) ? mapstate->req_lat : 0; + + wgs2pixel(mapstates[i].dataset[0], mapstates[i].path[0], + mapstate->req_lat, mapstate->req_lon, + &mapstates[i].act_xPixel[0], &mapstates[i].act_yPixel[0]); + + scale2zoom(mapstates[i].dataset[0], mapstates[i].path[0], + mapstates[i].req_scale, pixel_size, pseudo_lat, + &mapstates[i].act_xZoom[0], &mapstates[i].act_yZoom[0]); + } + + if (noZoom) + { + mapstates[i].act_xZoom[0] = 1; + mapstates[i].act_yZoom[0] = 1; + } + + HIViewSetNeedsDisplay(canvases[i].view, TRUE); + } +} + +static void key_press(char key, MapState *mapstate) +{ + int i; + + int redraw = 0; + + double factor = 1; + + switch (key) + { + case '+': + factor = 1 / 1.5; + redraw = 1; + break; + + case '-': + factor = 1.5; + redraw = 1; + break; + + case 'm': + render_mode = (render_mode & 0xfff0) + (((render_mode & 0x0f) + 1) % 3); + redraw = 1; + break; + + case 'f': + render_mode = (render_mode & 0xff0f) + + (((((render_mode & 0xf0) >> 4) + 1) % 3) << 4); + redraw = 1; + break; + + case 'a': + render_mode = render_mode | 0x200; + redraw = 1; + break; + + case 'c': + cover = !cover; + redraw = 1; + break; + + case 'p': + mapsettings.havepos = !mapsettings.havepos; + redraw = 1; + break; + + case 's': + render_mode ^= 0x100; + redraw = 1; + break; + + case 'g': + mapsettings.drawgrid = !mapsettings.drawgrid; + redraw = 1; + break; + + case 't': + draw_transparent = !draw_transparent; + redraw = 1; + break; + + case 'r': + mapstate->req_rotation += 45; + if (mapstate->req_rotation >= 360) + mapstate->req_rotation -= 360; + redraw = 1; + break; + } + + fprintf(stderr, "mode: %X\n", render_mode); + + if (redraw) + for (i = 0; i < views; i++) + { + mapstates[i].req_scale *= factor; + + if (views != mapset.maps) + { + selectbestmap(&mapset, &mapstates[i], render_mode, pixel_size); + } + else + { + double pseudo_lat = (render_mode & 0x100) ? mapstate->req_lat : 0; + + wgs2pixel(mapstates[i].dataset[0], mapstates[i].path[0], + mapstate->req_lat, mapstate->req_lon, + &mapstates[i].act_xPixel[0], + &mapstates[i].act_yPixel[0]); + + scale2zoom(mapstates[i].dataset[0], mapstates[i].path[0], + mapstates[i].req_scale, pixel_size, pseudo_lat, + &mapstates[i].act_xZoom[0], &mapstates[i].act_yZoom[0]); + } + + if (noZoom) + { + mapstates[i].act_xZoom[0] = 1; + mapstates[i].act_yZoom[0] = 1; + } + + HIViewSetNeedsDisplay(canvases[i].view, TRUE); + } + + render_mode &= ~0x200; +} + +static pascal OSStatus OnViewEvent(EventHandlerCallRef handler, + EventRef event, ViewData *data) +{ + OSStatus err = CallNextEventHandler(handler, event); + UInt32 kind = GetEventKind(event); + + if (err) + return err; + + switch (kind) + { + case kEventControlBoundsChanged: + // Force redraw + HIViewSetNeedsDisplay(data->view, TRUE); + return noErr; + + case kEventControlClick: + { + HIPoint where; + err = GetEventParameter(event, kEventParamMouseLocation, typeHIPoint, + NULL, sizeof( HIPoint ), NULL, &where); + Point local; + local.h = where.x; + local.v = where.y; + QDGlobalToLocalPoint(GetWindowPort(GetControlOwner(data->view)), + &local); + button_press(local.h, local.v, data->mapstate); + } + return noErr; + + case kEventControlDraw: + { + // Get CGContextRef + CGContextRef gc; + err = GetEventParameter(event, + kEventParamCGContextRef, + typeCGContextRef, + NULL, + sizeof(CGContextRef), + NULL, + &gc); + if (err) + return err; + + CGRect r; + + HIViewGetBounds(data->view, &r); + + expose(gc, r.size.width, r.size.height, data->mapstate); + } + return noErr; + } + + return err; +} + +static pascal OSStatus OnWindowEvent(EventHandlerCallRef handler, + EventRef event, MapState *mapstate) +{ + UInt32 kind = GetEventKind(event); + + switch (kind) + { + case kEventRawKeyDown: + { + char charCode; + GetEventParameter(event, kEventParamKeyMacCharCodes, typeChar, + NULL, sizeof(char), NULL, &charCode); + key_press(charCode, mapstate); + } + break; + + case kEventWindowClose: + QuitApplicationEventLoop(); + break; + + default: + return eventNotHandledErr; + } + + return noErr; +} + +WindowRef CreateWindow(int width, int height, MapState *mapstate) +{ + WindowRef window; + + Rect rect; + SetRect(&rect, 0, 0, width, height); + + OSStatus err = CreateNewWindow(kDocumentWindowClass, + kWindowStandardDocumentAttributes | + kWindowStandardHandlerAttribute | + kWindowCompositingAttribute | + kWindowInWindowMenuAttribute, + &rect, + &window); + + // Setup window + Str255 title = "\pmmapview"; + SetWTitle(window, title); + RepositionWindow(window, NULL, kWindowCascadeOnMainScreen); + + // Change size box to transparent + HIViewRef growThumb = NULL; + HIViewFindByID(HIViewGetRoot(window), kHIViewWindowGrowBoxID, &growThumb); + if (growThumb != NULL) + { + err = HIGrowBoxViewSetTransparent(growThumb, TRUE); + } + + // Setup window events + InstallStandardEventHandler(GetWindowEventTarget(window)); + + EventTypeSpec eventList[] = { + {kEventClassKeyboard, kEventRawKeyDown}, + {kEventClassWindow, kEventWindowClickContentRgn}, + {kEventClassWindow, kEventWindowClose}}; + + InstallWindowEventHandler(window, NewEventHandlerUPP + ((EventHandlerProcPtr)OnWindowEvent), + GetEventTypeCount(eventList), + eventList, (void*)mapstate, NULL); + + return window; +} + +HIViewRef CreateMapView(HIViewRef parent, int left, int top, + int right, int bottom, ViewData *data) +{ + HIViewRef view; + + HIRect bounds = CGRectMake(left, top, right, bottom); + + OSStatus err = HIObjectCreate(kHIViewClassID, nil, (HIObjectRef *)&view); + data->view = view; + + err = HIViewChangeAttributes(view, kHIViewAllowsSubviews, 0); + err = HIViewAddSubview(parent, view); + err = HIViewSetFrame(view, &bounds); + err = HIViewSetVisible(view, true); + + // Setup view events + static EventTypeSpec viewEvents[] = { + {kEventClassControl, kEventControlClick}, + {kEventClassControl, kEventControlBoundsChanged}, + {kEventClassControl, kEventControlDraw}}; + + InstallControlEventHandler(view, + NewEventHandlerUPP((EventHandlerProcPtr)OnViewEvent), + GetEventTypeCount(viewEvents), + viewEvents, + (void*)data, + NULL); + + return view; +} + +void usage() +{ + fprintf(stderr, "libmap test and sample application\n\n"); + fprintf(stderr, " usage: gmapview [input map files or directories] [options and arguments]\n\n"); + fprintf(stderr, " -h print this message\n"); + fprintf(stderr, " -a latitude initial latitude\n"); + fprintf(stderr, " -o longitude initial longitude\n"); + fprintf(stderr, " -s scale initial scale\n"); + fprintf(stderr, " -r rotation initial rotation\n"); + fprintf(stderr, " -p pixel size (mm) pixel size\n"); + fprintf(stderr, " -d dpi (1/inch) pixel size\n"); + fprintf(stderr, " -z no zoom\n"); + fprintf(stderr, " -v n number of views\n"); + fprintf(stderr, " -w windowed views\n"); + fprintf(stderr, " -l linear view scale\n"); + fprintf(stderr, " -m ratio view scale ratio\n\n"); + fprintf(stderr, " If no input is given, gmapview uses the current directory.\n"); + fprintf(stderr, " When the number of views equals the number of maps,\n"); + fprintf(stderr, " each map is fixed to each view.\n"); + fprintf(stderr, " You can combine short flags, so `-w -z' means the same as -wz or -zw.\n"); + fprintf(stderr, "\n When gmapview is running it can be controlled with the following keys:\n"); + fprintf(stderr, "\n + Zoom in\n"); + fprintf(stderr, " - Zoom out\n"); + fprintf(stderr, " m Drawing mode (Single, overview, tiled)\n"); + fprintf(stderr, " f Filter maps (Street, topo, all)\n"); + fprintf(stderr, " a Show alternate map\n"); + fprintf(stderr, " c Cover if possible\n"); + fprintf(stderr, " p Show current position\n"); + fprintf(stderr, " s Pseudo projection\n"); + fprintf(stderr, " g Grid\n"); + fprintf(stderr, " t Transparent\n"); + fprintf(stderr, " r Rotate\n"); + fprintf(stderr, "\n Left mouse click selects a new center point.\n"); +} + +int main(int argc, char **argv) +{ + extern char *optarg; + extern int optind; + extern int optopt; + + int i; + + WindowRef windows[16]; + //GtkWidget *paned; + //GtkWidget *box1; + //GtkWidget *box2; + + int windowed = FALSE; + int latSet = FALSE; + int lonSet = FALSE; + int scaleSet = FALSE; + int linear = FALSE; + double ratio = SCALE_RATIO; + + mapinit(&mapsettings); + + resetmap(&mapstates[0]); + + while (optind < argc) + { + if (argv[optind][0] != '-' || strlen(argv[optind]) <= 1) + { + // Load maps + if (!addmaps(argv[optind], &mapset)) + { + fprintf(stderr, + "Unable to open input file: %s\n", + argv[optind]); + return 1; + } + + optind++; + } + else + { + // Option + int opt = getopt(argc, argv, ":ha:o:s:r:p:d:zv:wlm:"); + if (opt != -1) + { + switch (opt) + { + case 'h': + usage(); + return 1; + + case 'a': + mapstates[0].req_lat = atof(optarg); + latSet = TRUE; + break; + + case 'o': + mapstates[0].req_lon = atof(optarg); + lonSet = TRUE; + break; + + case 's': + mapstates[0].req_scale = atof(optarg); + scaleSet = TRUE; + break; + + case 'r': + mapstates[0].req_rotation = atof(optarg) * M_PI / 180; + break; + + case 'p': + pixel_size = atof(optarg) / 1000; + break; + + case 'd': + pixel_size = 0.0254 / atof(optarg); + break; + + case 'z': + noZoom = TRUE; + break; + + case 'v': + views = atoi(optarg); + break; + + case 'w': + windowed = TRUE; + break; + + case 'l': + linear = TRUE; + break; + + case 'm': + ratio = atof(optarg); + break; + + case ':': // No argument + fprintf(stderr, + "Option -%c is missing an argument\n", + (char)optopt); + return 1; + + case '?': + default: + fprintf(stderr, + "Unknown option -%c\n", + (char)optopt); + return 1; + } + } + } + } + + if (!mapset.maps && !addmaps(".", &mapset)) + { + fprintf(stderr, "No maps in current directory\n"); + return 1; + } + + if (views < 0 || views > 16) + { + fprintf(stderr, "Unsupported number of views\n"); + return 1; + } + + { + GInt32 xPixel; + GInt32 yPixel; + + double lat; + double lon; + + int smallest = -1; + double smallestScale = 0; + + // Find smallest map + for (i = 0; i < mapset.maps; i++) + { + double scale; + + scale2zoom(mapset.dataset[i], mapset.path[i], + 1, pixel_size, 0, &scale, &scale); + + if (smallest == -1 || scale < smallestScale) + { + smallest = i; + smallestScale = scale; + } + } + + // Center on smallest map + center2pixel(mapset.dataset[smallest], &xPixel, &yPixel); + pixel2wgs(mapset.dataset[smallest], mapset.path[smallest], + xPixel, yPixel, &lat, &lon); + + if (latSet) + { + lat = mapstates[0].req_lat; + } + if (lonSet) + { + lon = mapstates[0].req_lon; + } + + // Init mapstates + for (i = 0; i < views; i++) + { + if (i) + resetmap(&mapstates[i]); + + mapstates[i].req_lat = lat; + mapstates[i].req_lon = lon; + + mapstates[i].req_rotation = mapstates[0].req_rotation; + + if (views == mapset.maps) + { + mapstates[i].dataset[0] = mapset.dataset[i]; + mapstates[i].path[0] = mapset.path[i]; + mapstates[i].dataset[1] = NULL; + mapstates[i].path[1] = NULL; + + scale2zoom(mapstates[i].dataset[0], mapstates[i].path[0], + 1, pixel_size, 0, + &mapstates[i].req_scale, &mapstates[i].req_scale); + + mapstates[i].act_xZoom[0] = 1.0; + mapstates[i].act_yZoom[0] = 1.0; + } + else + { + if (i == 0 && !scaleSet) + { + mapstates[i].dataset[0] = mapset.dataset[smallest]; + mapstates[i].path[0] = mapset.path[smallest]; + + scale2zoom(mapset.dataset[smallest], mapset.path[smallest], + 1, pixel_size, 0, + &mapstates[0].req_scale, &mapstates[0].req_scale); + } + + // Set scales relative to smallest map + if (i) + { + if (linear) + mapstates[i].req_scale = ratio * i * mapstates[0].req_scale; + else + mapstates[i].req_scale = ratio * mapstates[i - 1].req_scale; + } + + selectbestmap(&mapset, &mapstates[i], render_mode, pixel_size); + } + + if (noZoom) + { + mapstates[i].act_xZoom[0] = 1; + mapstates[i].act_yZoom[0] = 1; + } + + wgs2pixel(mapstates[i].dataset[0], mapstates[i].path[0], lat, lon, + &mapstates[i].act_xPixel[0], &mapstates[i].act_yPixel[0]); + } + } + + if (views == 1) + windowed = TRUE; + + CGRect screenRect = CGDisplayBounds(kCGDirectMainDisplay); + + int width = screenRect.size.width; + int height = screenRect.size.height; + + width = width * 3 / 4; + height = height * 5 / 8; + + if (windowed) + { + width /= 2; + height /= 2; + } + + if (windowed) + { + for (i = 0; i < views; i++) + { + windows[i] = CreateWindow(width, height, &mapstates[i]); + } + } + else + { + windows[0] = CreateWindow(width, height, &mapstates[0]); + + //HIViewRef rootView = HIViewGetRoot(windows[0]); + Rect rect; + + HIViewRef separator; + + SetRect(&rect, width / 2 - 2, 0, width / 2 + 2, height); + CreateSeparatorControl(windows[0], &rect, &separator); + //HIViewAddSubview(rootView, separator); + + //err = HIViewChangeAttributes(view, kHIViewAllowsSubviews, 0); + //err = HIViewAddSubview(parent, view); + //err = HIViewSetFrame(view, &bounds); + //err = HIViewSetVisible(view, true); + +/* + paned = gtk_hpaned_new(); + + gtk_container_add(GTK_CONTAINER(windows[0]), paned); + + box1 = gtk_vbox_new(TRUE, 4); + box2 = gtk_vbox_new(TRUE, 4); + + gtk_paned_pack1(GTK_PANED(paned), box1, FALSE, FALSE); + gtk_paned_pack2(GTK_PANED(paned), box2, FALSE, FALSE);*/ + } + + for (i = 0; i < views; i++) + { + canvases[i].mapstate = &mapstates[i]; + + if (windowed) + { + HIViewRef root = NULL; + OSStatus err = HIViewFindByID(HIViewGetRoot(windows[i]), kHIViewWindowContentID, &root); + + HIViewRef view = CreateMapView(root, 0, 0, width, height, &canvases[i]); + + HILayoutInfo li; + li.version = kHILayoutInfoVersionZero; + err = HIViewGetLayoutInfo(view, &li); + li.binding.top.toView = root; + li.binding.top.kind = kHILayoutBindTop; + li.binding.bottom.toView = root; + li.binding.bottom.kind = kHILayoutBindBottom; + li.binding.left.toView = root; + li.binding.left.kind = kHILayoutBindLeft; + li.binding.right.toView = root; + li.binding.right.kind = kHILayoutBindRight; + err = HIViewSetLayoutInfo(view, &li); + + ShowWindow(windows[i]); + } + else + { + HIViewRef root = NULL; + OSStatus err = HIViewFindByID(HIViewGetRoot(windows[0]), + kHIViewWindowContentID, &root); + + int viewTop = height * (i / 2) / ((views + 1) / 2); + int viewBot = height * (i / 2 + 1) / ((views + 1) / 2); + if ((i & 1 && (!(views & 1) || i < 2)) || + (!(i & 1) && (views & 1) && (i > 1))) + { + HIViewRef view = CreateMapView(root, 0, viewTop, + width / 2 - 2, viewBot, &canvases[i]); + } + else + { + HIViewRef view = CreateMapView(root, width / 2 + 2, viewTop, + width / 2, viewBot, &canvases[i]); + } + } + } + + if (!windowed) + ShowWindow(windows[0]); + +#ifdef HAVE_GPS + init_gps(); +#endif + + RunApplicationEventLoop(); + +#ifdef HAVE_GPS + free_gps(); +#endif + + freemaps(&mapset); + + return 0; +} diff --git a/src/util/qmapview.cpp b/src/util/qmapview.cpp new file mode 100644 index 0000000..38eef1a --- /dev/null +++ b/src/util/qmapview.cpp @@ -0,0 +1,633 @@ +// +// Copyright (c) 2005 -- Daniel Wallner +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// + +// Qt API reference: +// http://doc.trolltech.com/ + +#include "../lib_map/map.h" + +#include <qapplication.h> +#include <qmainwindow.h> +#include <qwidget.h> +#include <qsplitter.h> +#include <qlayout.h> +#include <qpainter.h> +#include <qpixmap.h> +#include <stdio.h> +#ifdef USE_CAIRO +#include <cairo.h> +#include <cairo-xlib.h> +#endif + +#include <unistd.h> +#include <stdlib.h> + +extern "C" { + void init_gps(); + void free_gps(); +} + +#define PIXEL_SIZE 0.22E-3 +#define SCALE_RATIO 10 + +class MapWidget : public QWidget +{ + Q_OBJECT +public: + MapWidget(QWidget *parent, MapState *mapstate); + ~MapWidget(); + +protected: + void paintEvent(QPaintEvent *event); + void mousePressEvent(QMouseEvent *event); + void keyPressEvent(QKeyEvent *event); + +private: +#ifdef USE_CAIRO + cairo_t *m_cr; + cairo_surface_t *m_surf; +#endif + MapState *m_mapstate; +}; + +MapSettings mapsettings; +MapSet mapset; +MapState mapstates[16]; +MapWidget *canvases[16]; +int views = 1; +int render_mode = 0x100; +int cover = 0; +int transparent = 0; +double pixel_size = PIXEL_SIZE; +int noZoom = 0; + + +MapWidget::MapWidget(QWidget *parent, MapState *mapstate): + QWidget(parent, "MapWidget"), + m_mapstate(mapstate) +{ +#ifdef USE_CAIRO + m_surf = cairo_xlib_surface_create((Display *)x11AppDisplay(), + (Drawable)handle(), + (Visual *)x11Visual(), + width(), height()); + m_cr = cairo_create(m_surf); + cairo_surface_destroy(m_surf); +#endif + + setFocus(); + setFocusPolicy(QWidget::StrongFocus); + setBackgroundMode(Qt::NoBackground); +} + +MapWidget::~MapWidget() +{ +#ifdef USE_CAIRO + cairo_destroy(m_cr); + m_cr = 0; +#endif +} + +void MapWidget::paintEvent(QPaintEvent *) +{ +#ifdef USE_CAIRO + MapGC mgc; + + memset((void*)&mgc, 0, sizeof(mgc)); + + m_surf = cairo_get_target(m_cr); + cairo_xlib_surface_set_drawable(m_surf, handle(), width(), height()); + mgc.cairo_cr = m_cr; + + if (cover) + coverifpossible(m_mapstate, width(), height()); + + cairo_save(m_cr); + + drawmap(m_mapstate, &mgc, width(), height(), transparent); + + drawmarkers(&mgc, width(), height(), + &mapsettings, m_mapstate, pixel_size, + 0, 0); + + cairo_restore(m_cr); +#else + QPainter painter(this); + + MapGC mgc; + + memset((void*)&mgc, 0, sizeof(mgc)); + + mgc.qt_painter = &painter; + + if (cover) + coverifpossible(m_mapstate, width(), height()); + + drawmap(m_mapstate, &mgc, width(), height(), transparent); + + drawmarkers(&mgc, width(), height(), + &mapsettings, m_mapstate, pixel_size, + 0, 0); +#endif +} + +void MapWidget::mousePressEvent(QMouseEvent *event) +{ + int i; + + mapsettings.posmode = TRUE; + + screen2wgs(m_mapstate, event->x(), event->y(), + &m_mapstate->req_lat, &m_mapstate->req_lon); + + fprintf(stderr, "new center: %lf;%lf\n", + m_mapstate->req_lat, m_mapstate->req_lon); + + for (i = 0; i < views; i++) + { + mapstates[i].req_lat = m_mapstate->req_lat; + mapstates[i].req_lon = m_mapstate->req_lon; + + if (views != mapset.maps) + { + selectbestmap(&mapset, &mapstates[i], render_mode, pixel_size); + } + else + { + double pseudo_lat = (render_mode & 0x100) ? m_mapstate->req_lat : 0; + + wgs2pixel(mapstates[i].dataset[0], mapstates[i].path[0], + m_mapstate->req_lat, m_mapstate->req_lon, + &mapstates[i].act_xPixel[0], &mapstates[i].act_yPixel[0]); + + scale2zoom(mapstates[i].dataset[0], mapstates[i].path[0], + mapstates[i].req_scale, pixel_size, pseudo_lat, + &mapstates[i].act_xZoom[0], &mapstates[i].act_yZoom[0]); + } + + if (noZoom) + { + mapstates[i].act_xZoom[0] = 1; + mapstates[i].act_yZoom[0] = 1; + } + + canvases[i]->update(); + } +} + +void MapWidget::keyPressEvent(QKeyEvent *event) +{ + int i; + + int redraw = 0; + + double factor = 1; + + switch (event->ascii()) + { + case '+': + factor = 1 / 1.5; + redraw = 1; + break; + + case '-': + factor = 1.5; + redraw = 1; + break; + + case 'm': + render_mode = (render_mode & 0xfff0) + (((render_mode & 0x0f) + 1) % 3); + redraw = 1; + break; + + case 'f': + render_mode = (render_mode & 0xff0f) + + (((((render_mode & 0xf0) >> 4) + 1) % 3) << 4); + redraw = 1; + break; + + case 'a': + render_mode = render_mode | 0x200; + redraw = 1; + break; + + case 'c': + cover = !cover; + redraw = 1; + break; + + case 'p': + mapsettings.havepos = !mapsettings.havepos; + redraw = 1; + break; + + case 's': + render_mode ^= 0x100; + redraw = 1; + break; + + case 'g': + mapsettings.drawgrid = !mapsettings.drawgrid; + redraw = 1; + break; + + case 't': + transparent = !transparent; + redraw = 1; + break; + + case 'r': + m_mapstate->req_rotation += 45; + if (m_mapstate->req_rotation >= 360) + m_mapstate->req_rotation -= 360; + redraw = 1; + break; + } + + fprintf(stderr, "mode: %X\n", render_mode); + + if (redraw) + for (i = 0; i < views; i++) + { + mapstates[i].req_scale *= factor; + + if (views != mapset.maps) + { + selectbestmap(&mapset, &mapstates[i], render_mode, pixel_size); + } + else + { + double pseudo_lat = (render_mode & 0x100) ? + m_mapstate->req_lat : 0; + + wgs2pixel(mapstates[i].dataset[0], mapstates[i].path[0], + m_mapstate->req_lat, m_mapstate->req_lon, + &mapstates[i].act_xPixel[0], + &mapstates[i].act_yPixel[0]); + + scale2zoom(mapstates[i].dataset[0], mapstates[i].path[0], + mapstates[i].req_scale, pixel_size, pseudo_lat, + &mapstates[i].act_xZoom[0], &mapstates[i].act_yZoom[0]); + } + + if (noZoom) + { + mapstates[i].act_xZoom[0] = 1; + mapstates[i].act_yZoom[0] = 1; + } + + canvases[i]->update(); + } + + render_mode &= ~0x200; +} + +void usage() +{ + fprintf(stderr, "libmap test and sample application\n\n"); + fprintf(stderr, " usage: qmapview [input map files or directories] [options and arguments]\n\n"); + fprintf(stderr, " -h print this message\n"); + fprintf(stderr, " -a latitude initial latitude\n"); + fprintf(stderr, " -o longitude initial longitude\n"); + fprintf(stderr, " -s scale initial scale\n"); + fprintf(stderr, " -r rotation initial rotation\n"); + fprintf(stderr, " -p pixel size (mm) pixel size\n"); + fprintf(stderr, " -d dpi (1/inch) pixel size\n"); + fprintf(stderr, " -z no zoom\n"); + fprintf(stderr, " -v n number of views\n"); + fprintf(stderr, " -w windowed views\n"); + fprintf(stderr, " -l linear view scale\n"); + fprintf(stderr, " -m ratio view scale ratio\n\n"); + fprintf(stderr, " If no input is given, gmapview uses the current directory.\n"); + fprintf(stderr, " When the number of views equals the number of maps,\n"); + fprintf(stderr, " each map is fixed to each view.\n"); + fprintf(stderr, " You can combine short flags, so `-w -z' means the same as -wz or -zw.\n"); + fprintf(stderr, "\n When qmapview is running it can be controlled with the following keys:\n"); + fprintf(stderr, "\n + Zoom in\n"); + fprintf(stderr, " - Zoom out\n"); + fprintf(stderr, " m Drawing mode (Single, overview, tiled)\n"); + fprintf(stderr, " f Filter maps (Street, topo, all)\n"); + fprintf(stderr, " a Show alternate map\n"); + fprintf(stderr, " c Cover if possible\n"); + fprintf(stderr, " p Show current position\n"); + fprintf(stderr, " s Pseudo projection\n"); + fprintf(stderr, " g Grid\n"); + fprintf(stderr, " t Transparent\n"); + fprintf(stderr, " r Rotate\n"); + fprintf(stderr, "\n Left mouse click selects a new center point.\n"); +} + +int main(int argc, char **argv) +{ + extern char *optarg; + extern int optind; + extern int optopt; + + int i; + + int latSet = FALSE; + int lonSet = FALSE; + int scaleSet = FALSE; + int linear = FALSE; + int windowed = FALSE; + double ratio = SCALE_RATIO; + + QApplication theApp(argc, argv); + + mapinit(&mapsettings); + + resetmap(&mapstates[0]); + + while (optind < argc) + { + if (argv[optind][0] != '-' || strlen(argv[optind]) <= 1) + { + // Load maps + if (!addmaps(argv[optind], &mapset)) + { + fprintf(stderr, + "Unable to open input file: %s\n", + argv[optind]); + return 1; + } + + optind++; + } + else + { + // Option + int opt = getopt(argc, argv, ":ha:o:s:r:p:d:zv:wlm:"); + if (opt != -1) + { + switch (opt) + { + case 'h': + usage(); + return 1; + + case 'a': + mapstates[0].req_lat = atof(optarg); + latSet = TRUE; + break; + + case 'o': + mapstates[0].req_lon = atof(optarg); + lonSet = TRUE; + break; + + case 's': + mapstates[0].req_scale = atof(optarg); + scaleSet = TRUE; + break; + + case 'r': + mapstates[0].req_rotation = atof(optarg) * M_PI / 180; + break; + + case 'p': + pixel_size = atof(optarg) / 1000; + break; + + case 'd': + pixel_size = 0.0254 / atof(optarg); + break; + + case 'z': + noZoom = TRUE; + break; + + case 'v': + views = atoi(optarg); + break; + + case 'w': + windowed = TRUE; + break; + + case 'l': + linear = TRUE; + break; + + case 'm': + ratio = atof(optarg); + break; + + case ':': // No argument + fprintf(stderr, + "Option -%c is missing an argument\n", + (char)optopt); + return 1; + + case '?': + default: + fprintf(stderr, + "Unknown option -%c\n", + (char)optopt); + return 1; + } + } + } + } + + if (!mapset.maps && !addmaps(".", &mapset)) + { + fprintf(stderr, "No maps in current directory\n"); + return 1; + } + + if (views < 0 || views > 16) + { + fprintf(stderr, "Unsupported number of views\n"); + return 1; + } + + { + GInt32 xPixel; + GInt32 yPixel; + + double lat; + double lon; + + int smallest = -1; + double smallestScale = 0; + + // Find smallest map + for (i = 0; i < mapset.maps; i++) + { + double scale; + + scale2zoom(mapset.dataset[i], mapset.path[i], + 1, pixel_size, 0, &scale, &scale); + + if (smallest == -1 || scale < smallestScale) + { + smallest = i; + smallestScale = scale; + } + } + + // Center on smallest map + center2pixel(mapset.dataset[smallest], &xPixel, &yPixel); + pixel2wgs(mapset.dataset[smallest], mapset.path[smallest], + xPixel, yPixel, &lat, &lon); + + if (latSet) + { + lat = mapstates[0].req_lat; + } + if (lonSet) + { + lon = mapstates[0].req_lon; + } + + // Init mapstates + for (i = 0; i < views; i++) + { + if (i) + resetmap(&mapstates[i]); + + mapstates[i].req_lat = lat; + mapstates[i].req_lon = lon; + + mapstates[i].req_rotation = mapstates[0].req_rotation; + + if (views == mapset.maps) + { + mapstates[i].dataset[0] = mapset.dataset[i]; + mapstates[i].path[0] = mapset.path[i]; + mapstates[i].dataset[1] = NULL; + mapstates[i].path[1] = NULL; + + scale2zoom(mapstates[i].dataset[0], mapstates[i].path[0], + 1, pixel_size, 0, + &mapstates[i].req_scale, &mapstates[i].req_scale); + + mapstates[i].act_xZoom[0] = 1.0; + mapstates[i].act_yZoom[0] = 1.0; + } + else + { + if (i == 0 && !scaleSet) + { + mapstates[i].dataset[0] = mapset.dataset[smallest]; + mapstates[i].path[0] = mapset.path[smallest]; + + scale2zoom(mapset.dataset[smallest], mapset.path[smallest], + 1, pixel_size, 0, + &mapstates[0].req_scale, &mapstates[0].req_scale); + } + + // Set scales relative to smallest map + if (i) + { + if (linear) + mapstates[i].req_scale = ratio * i * mapstates[0].req_scale; + else + mapstates[i].req_scale = ratio * mapstates[i - 1].req_scale; + } + + selectbestmap(&mapset, &mapstates[i], render_mode, pixel_size); + } + + if (noZoom) + { + mapstates[i].act_xZoom[0] = 1; + mapstates[i].act_yZoom[0] = 1; + } + + wgs2pixel(mapstates[i].dataset[0], mapstates[i].path[0], lat, lon, + &mapstates[i].act_xPixel[0], &mapstates[i].act_yPixel[0]); + } + } + + // Create windows and views + + QMainWindow *windows[16]; + QSplitter *box1 = 0; + QSplitter *box2 = 0; + + if (views == 1) + windowed = TRUE; + + if (windowed) + { + for (i = 0; i < views; i++) + { + windows[i] = new QMainWindow(); + } + } + else + { + windows[0] = new QMainWindow(); + + QSplitter *split = new QSplitter(windows[0]); + windows[0]->setCentralWidget(split); + + box1 = new QSplitter(split); + box1->setOrientation(QSplitter::Vertical); + box2 = new QSplitter(split); + box2->setOrientation(QSplitter::Vertical); + } + + for (i = 0; i < views; i++) + { + if (windowed) + { + canvases[i] = new MapWidget(windows[i], &mapstates[i]); + + windows[i]->setCentralWidget(canvases[i]); + + windows[i]->show(); + } + else + { + if ((i & 1 && (!(views & 1) || i < 2)) || + (!(i & 1) && (views & 1) && (i > 1))) + { + canvases[i] = new MapWidget(box2, &mapstates[i]); + } + else + { + canvases[i] = new MapWidget(box1, &mapstates[i]); + } + } + } + + theApp.setMainWidget(windows[0]); + + if (!windowed) + windows[0]->show(); + +#ifdef HAVE_GPS + init_gps(); +#endif + + int ret = theApp.exec(); + +#ifdef HAVE_GPS + free_gps(); +#endif + + freemaps(&mapset); + + return ret; +} + +// This line is necessary when there are no separate header files: +// http://doc.trolltech.com/3.1/moc.html +#include "qmapview.moc" diff --git a/src/util/wmapview.c b/src/util/wmapview.c new file mode 100644 index 0000000..992d9ff --- /dev/null +++ b/src/util/wmapview.c @@ -0,0 +1,653 @@ +// +// Copyright (c) 2005 -- Daniel Wallner +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// + +#include "../lib_map/map.h" + +#include <windows.h> +#include <windowsx.h> +#include <stdio.h> +#ifdef USE_CAIRO +#include <cairo.h> +#endif +#include <unistd.h> +#include <stdlib.h> + +#define PIXEL_SIZE 0.22E-3 +#define SCALE_RATIO 10 + +typedef struct +{ + HWND view; + MapState *mapstate; +} +ViewData; + +MapSettings mapsettings; +MapSet mapset; +MapState mapstates[16]; +ViewData canvases[16]; +int views = 1; +int render_mode = 0x100; +int cover = 0; +int transparent = 0; +double pixel_size = PIXEL_SIZE; +int noZoom = FALSE; + +static void expose(HDC dc, int width, int height, MapState *mapstate) +{ + MapGC mgc; + + memset((void*)&mgc, 0, sizeof(mgc)); + + mgc.win_dc = dc; + + if (cover) + coverifpossible(mapstate, width, height); + + drawmap(mapstate, &mgc, width, height, transparent); + + drawmarkers(&mgc, width, height, + &mapsettings, mapstate, pixel_size, + 0, 0); + + if (mgc.win_pen) + DeleteObject(SelectObject(mgc.win_dc, mgc.win_pen)); +} + +static void button_press(int x, int y, MapState *mapstate) +{ + int i; + + mapsettings.posmode = TRUE; + + screen2wgs(mapstate, x, y, + &mapstate->req_lat, &mapstate->req_lon); + + fprintf(stderr, "new center: %lf;%lf\n", + mapstate->req_lat, mapstate->req_lon); + + for (i = 0; i < views; i++) + { + mapstates[i].req_lat = mapstate->req_lat; + mapstates[i].req_lon = mapstate->req_lon; + + if (views != mapset.maps) + { + selectbestmap(&mapset, &mapstates[i], render_mode, pixel_size); + } + else + { + double pseudo_lat = (render_mode & 0x100) ? mapstate->req_lat : 0; + + wgs2pixel(mapstates[i].dataset[0], mapstates[i].path[0], + mapstate->req_lat, mapstate->req_lon, + &mapstates[i].act_xPixel[0], &mapstates[i].act_yPixel[0]); + + scale2zoom(mapstates[i].dataset[0], mapstates[i].path[0], + mapstates[i].req_scale, pixel_size, pseudo_lat, + &mapstates[i].act_xZoom[0], &mapstates[i].act_yZoom[0]); + } + + if (noZoom) + { + mapstates[i].act_xZoom[0] = 1; + mapstates[i].act_yZoom[0] = 1; + } + + InvalidateRect(canvases[i].view, NULL, FALSE); + } +} + +static void key_press(char key, MapState *mapstate) +{ + int i; + + int redraw = 0; + + double factor = 1; + + switch (key) + { + case '+': + factor = 1 / 1.5; + redraw = 1; + break; + + case '-': + factor = 1.5; + redraw = 1; + break; + + case 'm': + render_mode = (render_mode & 0xfff0) + (((render_mode & 0x0f) + 1) % 3); + redraw = 1; + break; + + case 'f': + render_mode = (render_mode & 0xff0f) + + (((((render_mode & 0xf0) >> 4) + 1) % 3) << 4); + redraw = 1; + break; + + case 'a': + render_mode = render_mode | 0x200; + redraw = 1; + break; + + case 'c': + cover = !cover; + redraw = 1; + break; + + case 'p': + mapsettings.havepos = !mapsettings.havepos; + redraw = 1; + break; + + case 's': + render_mode ^= 0x100; + redraw = 1; + break; + + case 'g': + mapsettings.drawgrid = !mapsettings.drawgrid; + redraw = 1; + break; + + case 't': + transparent = !transparent; + redraw = 1; + break; + + case 'r': + mapstate->req_rotation += 45; + if (mapstate->req_rotation >= 360) + mapstate->req_rotation -= 360; + redraw = 1; + break; + } + + fprintf(stderr, "mode: %X\n", render_mode); + + if (redraw) + for (i = 0; i < views; i++) + { + mapstates[i].req_scale *= factor; + + if (views != mapset.maps) + { + selectbestmap(&mapset, &mapstates[i], render_mode, pixel_size); + } + else + { + double pseudo_lat = (render_mode & 0x100) ? mapstate->req_lat : 0; + + wgs2pixel(mapstates[i].dataset[0], mapstates[i].path[0], + mapstate->req_lat, mapstate->req_lon, + &mapstates[i].act_xPixel[0], + &mapstates[i].act_yPixel[0]); + + scale2zoom(mapstates[i].dataset[0], mapstates[i].path[0], + mapstates[i].req_scale, pixel_size, pseudo_lat, + &mapstates[i].act_xZoom[0], &mapstates[i].act_yZoom[0]); + } + + if (noZoom) + { + mapstates[i].act_xZoom[0] = 1; + mapstates[i].act_yZoom[0] = 1; + } + + InvalidateRect(canvases[i].view, NULL, FALSE); + } + + render_mode &= ~0x200; +} + +static LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, + WPARAM wParam, LPARAM lParam) +{ + MapState *mapstate = (MapState *)GetWindowLong(hWnd, GWL_USERDATA); + + switch (msg) + { + case WM_CHAR: + key_press(wParam, mapstate); + break; + + case WM_LBUTTONDOWN: + button_press(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), mapstate); + break; + + case WM_ERASEBKGND: + return TRUE; + + case WM_PAINT: + { + PAINTSTRUCT ps; + HDC dc; + RECT rect; + GetClientRect(hWnd, &rect); + dc = BeginPaint(hWnd, &ps); + expose(dc, rect.right, rect.bottom, mapstate); + EndPaint(hWnd, &ps); + } + break; + + case WM_DESTROY: + PostQuitMessage(0); + break; + + default: + return DefWindowProc(hWnd, msg, wParam, lParam); + } + + return FALSE; +} + +#define CLASSNAME "wmapview" +#define TITLE CLASSNAME + +void WinInit() +{ + WNDCLASSEX wc = {0}; + + wc.cbSize = sizeof(WNDCLASSEX); + wc.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW; + wc.lpfnWndProc = (WNDPROC)WndProc; + wc.hInstance = GetModuleHandle(NULL); + wc.hCursor = LoadCursor(NULL, IDC_ARROW); + wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); + wc.lpszClassName = CLASSNAME; + + if (!RegisterClassEx(&wc)) + { + fprintf(stderr, "Failed to register window class"); + exit(1); + } +} + +HWND CreateFrameWindow(MapState *mapstate) +{ + HWND window = CreateWindow(CLASSNAME, TITLE, + WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, + CW_USEDEFAULT, 0, NULL, NULL, + GetModuleHandle(NULL), NULL); + + if (!window) + { + fprintf(stderr, "Failed to create window"); + return 0; + } + + SetWindowLong(window, GWL_USERDATA, (LONG)mapstate); + + return window; +} + +void usage() +{ + fprintf(stderr, "libmap test and sample application\n\n"); + fprintf(stderr, " usage: wmapview [input map files or directories] [options and arguments]\n\n"); + fprintf(stderr, " -h print this message\n"); + fprintf(stderr, " -a latitude initial latitude\n"); + fprintf(stderr, " -o longitude initial longitude\n"); + fprintf(stderr, " -s scale initial scale\n"); + fprintf(stderr, " -r rotation initial rotation\n"); + fprintf(stderr, " -p pixel size (mm) pixel size\n"); + fprintf(stderr, " -d dpi (1/inch) pixel size\n"); + fprintf(stderr, " -z no zoom\n"); + fprintf(stderr, " -v n number of views\n"); + fprintf(stderr, " -w windowed views\n"); + fprintf(stderr, " -l linear view scale\n"); + fprintf(stderr, " -m ratio view scale ratio\n\n"); + fprintf(stderr, " If no input is given, gmapview uses the current directory.\n"); + fprintf(stderr, " When the number of views equals the number of maps,\n"); + fprintf(stderr, " each map is fixed to each view.\n"); + fprintf(stderr, " You can combine short flags, so `-w -z' means the same as -wz or -zw.\n"); + fprintf(stderr, "\n When wmapview is running it can be controlled with the following keys:\n"); + fprintf(stderr, "\n + Zoom in\n"); + fprintf(stderr, " - Zoom out\n"); + fprintf(stderr, " m Drawing mode (Single, overview, tiled)\n"); + fprintf(stderr, " f Filter maps (Street, topo, all)\n"); + fprintf(stderr, " a Show alternate map\n"); + fprintf(stderr, " c Cover if possible\n"); + fprintf(stderr, " p Show current position\n"); + fprintf(stderr, " s Pseudo projection\n"); + fprintf(stderr, " g Grid\n"); + fprintf(stderr, " t Transparent\n"); + fprintf(stderr, " r Rotate\n"); + fprintf(stderr, "\n Left mouse click selects a new center point.\n"); +} + +int main(int argc, char **argv) +{ + extern char *optarg; + extern int optind; + extern int optopt; + + int i; + + HWND windows[16]; + //GtkWidget *paned; + //GtkWidget *box1; + //GtkWidget *box2; + MSG msg; + + int windowed = FALSE; + int latSet = FALSE; + int lonSet = FALSE; + int scaleSet = FALSE; + int linear = FALSE; + double ratio = SCALE_RATIO; + + WinInit(); + + mapinit(&mapsettings); + + resetmap(&mapstates[0]); + + while (optind < argc) + { + if (argv[optind][0] != '-' || strlen(argv[optind]) <= 1) + { + // Load maps + if (!addmaps(argv[optind], &mapset)) + { + fprintf(stderr, + "Unable to open input file: %s\n", + argv[optind]); + return 1; + } + + optind++; + } + else + { + // Option + int opt = getopt(argc, argv, ":ha:o:s:r:p:d:zv:wlm:"); + if (opt != -1) + { + switch (opt) + { + case 'h': + usage(); + return 1; + + case 'a': + mapstates[0].req_lat = atof(optarg); + latSet = TRUE; + break; + + case 'o': + mapstates[0].req_lon = atof(optarg); + lonSet = TRUE; + break; + + case 's': + mapstates[0].req_scale = atof(optarg); + scaleSet = TRUE; + break; + + case 'r': + mapstates[0].req_rotation = atof(optarg) * M_PI / 180; + break; + + case 'p': + pixel_size = atof(optarg) / 1000; + break; + + case 'd': + pixel_size = 0.0254 / atof(optarg); + break; + + case 'z': + noZoom = TRUE; + break; + + case 'v': + views = atoi(optarg); + break; + + case 'w': + windowed = TRUE; + break; + + case 'l': + linear = TRUE; + break; + + case 'm': + ratio = atof(optarg); + break; + + case ':': // No argument + fprintf(stderr, + "Option -%c is missing an argument\n", + (char)optopt); + return 1; + + case '?': + default: + fprintf(stderr, + "Unknown option -%c\n", + (char)optopt); + return 1; + } + } + } + } + + if (!mapset.maps && !addmaps(".", &mapset)) + { + fprintf(stderr, "No maps in current directory\n"); + return 1; + } + + if (views < 0 || views > 16) + { + fprintf(stderr, "Unsupported number of views\n"); + return 1; + } + + { + GInt32 xPixel; + GInt32 yPixel; + + double lat; + double lon; + + int smallest = -1; + double smallestScale = 0; + + // Find smallest map + for (i = 0; i < mapset.maps; i++) + { + double scale; + + scale2zoom(mapset.dataset[i], mapset.path[i], + 1, pixel_size, 0, &scale, &scale); + + if (smallest == -1 || scale < smallestScale) + { + smallest = i; + smallestScale = scale; + } + } + + // Center on smallest map + center2pixel(mapset.dataset[smallest], &xPixel, &yPixel); + pixel2wgs(mapset.dataset[smallest], mapset.path[smallest], + xPixel, yPixel, &lat, &lon); + + if (latSet) + { + lat = mapstates[0].req_lat; + } + if (lonSet) + { + lon = mapstates[0].req_lon; + } + + // Init mapstates + for (i = 0; i < views; i++) + { + if (i) + resetmap(&mapstates[i]); + + mapstates[i].req_lat = lat; + mapstates[i].req_lon = lon; + + mapstates[i].req_rotation = mapstates[0].req_rotation; + + if (views == mapset.maps) + { + mapstates[i].dataset[0] = mapset.dataset[i]; + mapstates[i].path[0] = mapset.path[i]; + mapstates[i].dataset[1] = NULL; + mapstates[i].path[1] = NULL; + + scale2zoom(mapstates[i].dataset[0], mapstates[i].path[0], + 1, pixel_size, 0, + &mapstates[i].req_scale, &mapstates[i].req_scale); + + mapstates[i].act_xZoom[0] = 1.0; + mapstates[i].act_yZoom[0] = 1.0; + } + else + { + if (i == 0 && !scaleSet) + { + mapstates[i].dataset[0] = mapset.dataset[smallest]; + mapstates[i].path[0] = mapset.path[smallest]; + + scale2zoom(mapset.dataset[smallest], mapset.path[smallest], + 1, pixel_size, 0, + &mapstates[0].req_scale, &mapstates[0].req_scale); + } + + // Set scales relative to smallest map + if (i) + { + if (linear) + mapstates[i].req_scale = ratio * i * mapstates[0].req_scale; + else + mapstates[i].req_scale = ratio * mapstates[i - 1].req_scale; + } + + selectbestmap(&mapset, &mapstates[i], render_mode, pixel_size); + } + + if (noZoom) + { + mapstates[i].act_xZoom[0] = 1; + mapstates[i].act_yZoom[0] = 1; + } + + wgs2pixel(mapstates[i].dataset[0], mapstates[i].path[0], lat, lon, + &mapstates[i].act_xPixel[0], &mapstates[i].act_yPixel[0]); + } + } + + if (views == 1) + windowed = TRUE; + + if (windowed) + { + for (i = 0; i < views; i++) + { + windows[i] = CreateFrameWindow(&mapstates[i]); +/* + g_signal_connect(G_OBJECT(windows[i]), "delete-event", + G_CALLBACK(gtk_main_quit), NULL); + + g_signal_connect(G_OBJECT(windows[i]), "key_press_event", + G_CALLBACK(key_press), mapstates);*/ + } + } + else + { + windows[0] = CreateFrameWindow(&mapstates[0]); +/* + g_signal_connect(G_OBJECT(windows[0]), "delete-event", + G_CALLBACK(gtk_main_quit), NULL); + + g_signal_connect(G_OBJECT(windows[0]), "key_press_event", + G_CALLBACK(key_press), mapstates); + + paned = gtk_hpaned_new(); + + gtk_container_add(GTK_CONTAINER(windows[0]), paned); + + box1 = gtk_vbox_new(TRUE, 4); + box2 = gtk_vbox_new(TRUE, 4); + + gtk_paned_pack1(GTK_PANED(paned), box1, FALSE, FALSE); + gtk_paned_pack2(GTK_PANED(paned), box2, FALSE, FALSE);*/ + } + + for (i = 0; i < views; i++) + { + canvases[i].mapstate = &mapstates[i]; + canvases[i].view = windows[i]; +/* canvases[i] = gtk_drawing_area_new(); + + gtk_widget_set_size_request(canvases[i], 100, 100); + + gtk_widget_add_events(canvases[i], GDK_BUTTON_PRESS_MASK); + + g_signal_connect(G_OBJECT(canvases[i]), "expose-event", + G_CALLBACK(expose), &mapstates[i]); + + g_signal_connect(G_OBJECT(canvases[i]), "button_press_event", + G_CALLBACK(button_press), &mapstates[i]); +*/ + if (windowed) + { + //gtk_container_add(GTK_CONTAINER(windows[i]), canvases[i]); + + ShowWindow(windows[i], TRUE); + }/* + else + { + if ((i & 1 && (!(views & 1) || i < 2)) || + (!(i & 1) && (views & 1) && (i > 1))) + { + gtk_box_pack_start_defaults(GTK_BOX(box2), canvases[i]); + } + else + { + gtk_box_pack_start_defaults(GTK_BOX(box1), canvases[i]); + } + }*/ + } + + if (!windowed) + ShowWindow(windows[0], TRUE); + + // Main message loop: + while (GetMessage(&msg, NULL, 0, 0)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + + freemaps(&mapset); + + return 0; +} diff --git a/src/util/worldgen.c b/src/util/worldgen.c new file mode 100644 index 0000000..93b0d69 --- /dev/null +++ b/src/util/worldgen.c @@ -0,0 +1,126 @@ +// +// Copyright (c) 2005 -- Daniel Wallner +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// + +#include <stdio.h> +#include <string.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> +#include <errno.h> + +int worldgen(char *path, double latitude, double longitude, double scale) +{ + FILE *outfile; + + outfile = fopen(path, "w"); + + if (!outfile) + { + fprintf(stderr, "unable to open output file '%s': %s\n", + path,strerror(errno)); + return 0; + } + + fprintf(outfile, "%lf\n0\n0\n%lf\n", scale, -scale); + fprintf(outfile, "%lf\n", longitude); + fprintf(outfile, "%lf\n", latitude); + + fclose(outfile); + + return 1; +} + +int koordread(char *path) +{ + printf( " koordread: %s\n", path); + + FILE *infile = fopen(path, "r"); + + char mapname[264]; + double latitude; + double longitude; + double scale; + long count; + long linenumber = 0; + + if (!infile) + { + fprintf(stderr, "unable to open input file '%s': %s\n", + path,strerror(errno)); + return 1; + } + + while ((count = fscanf(infile, "%s %lf %lf %lf\n", + mapname, &latitude, &longitude, &scale)) && + count != EOF) + { + linenumber++; + + if (count != 4) + { + fprintf(stderr, "Error reading line %ld\n", linenumber); + fprintf(stderr, " map name: '%s'\n", mapname); + continue; + } + + char worldname[264]; + char *extchar; + int is_image; + + fprintf(stderr, "Line: '%s' '%lf' '%lf' '%lf'\n", + mapname, latitude, longitude, scale); + + strcpy(worldname, mapname); + extchar = strrchr(worldname, '.'); + + is_image = + strstr(worldname, ".jpg") || + strstr(worldname, ".png") || + strstr(worldname, ".gif"); + + if (extchar && is_image) + { + fprintf(stderr, " is image with extention '%s'\n",extchar); + + strcpy(extchar, ".wld"); + + fprintf(stderr, " generating '%s'\n", worldname); + + worldgen(worldname, latitude, longitude, scale); + } + else + { + fprintf(stderr, " no image extension, skipping '%s'\n", mapname); + } + } + + fclose(infile); + + return 0; +} + +int main(int argc, char **argv) +{ + if (argc != 2) + { + fprintf(stderr, "usage: worldgen infile\n"); + return 1; + } + + return koordread(argv[1]); +} |