Esempio n. 1
0
 def on_remove_map(self, evt):
     if not self.maptreectrl.GetSelection().IsOk():
         util.Warn(self,
                   _("No map selected!\n\n" +
                     "Please select the map you want to remove."))
         return
     self.delete(self.maptreectrl.GetSelection())
Esempio n. 2
0
 def on_overlay_tool(self, evt):
     if not self.maptreectrl.GetSelection().IsOk():
         util.Warn(self,
                   _("No map selected!\n\n" +
                     "Please select the map you want to overlay."))
         return
     self.overlay_map(self.maptreectrl.GetSelection())
Esempio n. 3
0
 def on_display_tool(self, evt):
     if not self.maptreectrl.GetSelection().IsOk():
         util.Warn(self,
                   _("No map selected!\n\n" +
                     "Please select the map you want to display."))
         return
     self.display_map(self.maptreectrl.GetSelection())
     util.force_show_window(self.parent)
Esempio n. 4
0
    def on_copy_coord(self, evt):
        center = self.mapviewmodel.GetCenter()
        ok, ll = self.mapviewmodel.GetBaseMap().PixelToLatLon(center)
        if not ok:
            util.Warn(_("Could not retrieve map center position.\n" +
                        "Is this map georeferenced?"))
            return

        if not wx.TheClipboard.Open():
            util.Warn(_("Could not open clipboard for copying.\n"))
            return

        tdo = util.CustomTextDataObject(self.format_latlon(ll))
        try:
            wx.TheClipboard.SetData(tdo)
        finally:
            wx.TheClipboard.Close()
Esempio n. 5
0
    def on_show_gpstrackanalyzer(self, evt):
        for overlay in self.overlays: # FIXME -> mapviewmodel-ize me
            maptype = overlay.GetMap().GetType()
            if maptype == pymaplib.GeoDrawable.TYPE_GPSTRACK:
                gpstrack = overlay.GetMap()
                break
        else:
            util.Warn(self, _("No GPS Track currently displayed."))
            return

        self.show_gpstrackanalyzer(gpstrack)
Esempio n. 6
0
    def finish_list_change(self):
        with config.Config.write() as conf:
            try:
                self.filelist.store_to(conf)
            except KeyError:
                util.Warn(self,
                          _("Couldn't save map preferences\n\n" +
                            "Maps Evolved will continue to work, but the " +
                            "map database changes will be lost on exit."))

        self.iteminfo.set_info(None)
        self.repopulate_filtertree()
        self.insert_drawables()
Esempio n. 7
0
    def on_smaller_scale_map(self, evt):
        basemap = self.mapviewmodel.GetBaseMap()
        ok, center_ll = basemap.PixelToLatLon(self.mapviewmodel.GetCenter())
        if not ok:
            util.Warn(_("Could not retrieve map center position.\n" +
                        "Is the current map georeferenced?"))
            return

        viable_maps = pymaplib.smaller_scale_maps(basemap, center_ll,
                                                  self.filelist.maplist)
        if viable_maps:
            self.set_basemap(viable_maps[0])
            self.mapviewmodel.SetZoomOneToOne()
Esempio n. 8
0
 def delete(self, item):
     if not item:
         util.Warn(self,
                   _("No map selected for removal\n\n" +
                     "Please select the map you want to remove."))
         return
     container, drawable = self.maptreectrl.GetItemData(item)
     if drawable != container.drawable:
         # Trying to delete an alternative view.
         # Notify the user we're deleting the whole file.
         force = util.YesNo(self,
                            _("Are you sure you want to remove the " +
                              "following map (including all its views):" +
                              "\n{}").format(container.basename))
         if not force:
             return
     self.filelist.delete(container)
     self.finish_list_change()
Esempio n. 9
0
    def on_save_bitmap(self, evt):
        saveFileDialog = wx.FileDialog(
                self, "Export map region as image", "", "",
                "Bitmap files (*.bmp)|*.bmp|" +
                "JPEG files (*.jpg)|*.jpg|" +
                "PNG files (*.png)|*.png",
                wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
        if saveFileDialog.ShowModal() == wx.ID_CANCEL:
            return

        fname_lower = saveFileDialog.GetPath().lower()
        if fname_lower.endswith('.bmp'):
            ftype = wx.BITMAP_TYPE_BMP
        elif fname_lower.endswith('.jpg') or fname_lower.endswith('.jpeg'):
            ftype = wx.BITMAP_TYPE_JPEG
        elif fname_lower.endswith('.png'):
            ftype = wx.BITMAP_TYPE_PNG
        else:
            util.Warn(self, _("Could not infer the intended file type from " +
                              "the filename."))
            return

        # PaintToBuffer extracts its parameters from the MapViewModel.
        # Create a temporary instance to hold the data.
        mvm = pymaplib.MapViewModel(self.mapviewmodel)
        w = int(self.ogldisplay.GetDisplayWidth()  / mvm.GetZoom())
        h = int(self.ogldisplay.GetDisplayHeight() / mvm.GetZoom())
        mvm.SetDisplaySize(pymaplib.DisplayDeltaInt(w, h))
        mvm.SetZoomOneToOne()
        mr = self.mapview.PaintToBuffer(pymaplib.ODM_PIX_RGBA4, mvm)
        # Copy the image data to a modifyable buffer and set the alpha
        # values to 255. wx.Bitmap multiplies R,G,B by alpha on Win32, leading
        # to an all-black bitmap otherwise.
        # We can't use wx.BitmapBufferFormat_RGB32, as that swaps the
        # R and B channels.
        data = bytearray(mr.GetData())
        for i in range(w*h):
            data[4*i + 3] = 0xFF
        bmp = wx.Bitmap.FromBufferRGBA(w, h, data)
        # Mirror image vertically - PaintToBuffer produces the wrong
        # top-down/bottom-up orientation for us.
        img = bmp.ConvertToImage().Mirror(horizontally=False)
        img.SaveFile(saveFileDialog.GetPath(), ftype)