Skip to content

Commit

Permalink
Merge branch 'OpenCPN:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Hakansv authored Sep 26, 2024
2 parents d73f442 + 2b0017c commit caaa4f8
Show file tree
Hide file tree
Showing 57 changed files with 2,619 additions and 2,607 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ buildwin/NSIS_Unicode/Include/Langstrings_*.nsh
buildwin/crashrpt/CrashRpt1402.dll
buildwin/crashrpt/CrashSender1402.exe
buildwin/configdev.bat
build-*
cache
cmake-build-*
crowdin.yaml
cscope.files
cscope.out
Expand Down
16 changes: 11 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,7 @@ set(GUI_HDRS
${GUI_HDR_DIR}/GoToPositionDialog.h
${GUI_HDR_DIR}/gshhs.h
${GUI_HDR_DIR}/gui_lib.h
${GUI_HDR_DIR}/hotkeys_dlg.h
${GUI_HDR_DIR}/IDX_entry.h
${GUI_HDR_DIR}/iENCToolbar.h
${GUI_HDR_DIR}/kml.h
Expand Down Expand Up @@ -903,6 +904,7 @@ set(GUI_SRC
${GUI_SRC_DIR}/GoToPositionDialog.cpp
${GUI_SRC_DIR}/gshhs.cpp
${GUI_SRC_DIR}/gui_lib.cpp
${GUI_SRC_DIR}/hotkeys_dlg.cpp
${GUI_SRC_DIR}/IDX_entry.cpp
${GUI_SRC_DIR}/iENCToolbar.cpp
${GUI_SRC_DIR}/kml.cpp
Expand All @@ -911,11 +913,12 @@ set(GUI_SRC
${GUI_SRC_DIR}/load_errors_dlg.cpp
${GUI_SRC_DIR}/MarkInfo.cpp
${GUI_SRC_DIR}/mbtiles/mbtiles.cpp
${GUI_SRC_DIR}/mbtiles/WorkerThread.cpp
${GUI_SRC_DIR}/mbtiles/WorkerThread.hpp
${GUI_SRC_DIR}/mbtiles/TileQueue.hpp
${GUI_SRC_DIR}/mbtiles/TileDescriptor.hpp
${GUI_SRC_DIR}/mbtiles/TileCache.hpp
${GUI_SRC_DIR}/mbtiles/tile_thread.cpp
${GUI_SRC_DIR}/mbtiles/tile_thread.h
${GUI_SRC_DIR}/mbtiles/tile_queue.h
${GUI_SRC_DIR}/mbtiles/tile_descr.h
${GUI_SRC_DIR}/mbtiles/tile_cache.h
${GUI_SRC_DIR}/mbtiles/tile_cache.cpp
${GUI_SRC_DIR}/MUIBar.cpp
${GUI_SRC_DIR}/navutil.cpp
${GUI_SRC_DIR}/NMEALogWindow.cpp
Expand Down Expand Up @@ -1467,6 +1470,9 @@ target_link_libraries(${PACKAGE_NAME} PRIVATE ocpn::tinyxml)
message(STATUS " Adding local wxserverdisc")
add_subdirectory(libs/wxservdisc)

add_subdirectory(libs/manual)
target_link_libraries(${PACKAGE_NAME} PRIVATE ocpn::manual)

if (MSVC)
install(FILES "cache/buildwin/libssl-3.dll" DESTINATION ".")
install(FILES "cache/buildwin/libcrypto-3.dll" DESTINATION ".")
Expand Down
26 changes: 26 additions & 0 deletions gui/include/gui/glChartCanvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,32 @@
#ifndef __GLCHARTCANVAS_H__
#define __GLCHARTCANVAS_H__

// We need to set up our openGL environment before including
// glcanvas.h which includes GL/gl.h
#ifdef __ANDROID__
#include <qopengl.h>
#include <GL/gl_private.h> // this is a cut-down version of gl.h
#include <GLES2/gl2.h>

#elif defined(ocpnUSE_GL)
#if defined(__MSVC__)
#include "glew.h"

#elif defined(__WXOSX__)
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
typedef void (*_GLUfuncptr)();
#define GL_COMPRESSED_RGB_FXT1_3DFX 0x86B0

#elif defined(__WXQT__) || defined(__WXGTK__)
#include <GL/glew.h>
#include <GL/glu.h>

#else
# error platform not supported.
#endif // __ANDROID__
#endif // ocpnUSE_GL

#include <wx/glcanvas.h>

#include "dychart.h"
Expand Down
34 changes: 34 additions & 0 deletions gui/include/gui/hotkeys_dlg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**************************************************************************
* Copyright (C) 2024 Alec Leamas *
* *
* 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., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
**************************************************************************/

#ifndef HOTKEYS_DLG_H_
#define HOTKEYS_DLG_H_

#include <wx/dialog.h>
#include <wx/window.h>

/**
* Modal dialog displaying hotkeys.
*/
class HotkeysDlg : public wxDialog {
public:
HotkeysDlg(wxWindow* parent);
};

#endif // HOTKEYS_DLG_H
199 changes: 116 additions & 83 deletions gui/include/gui/mbtiles.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
/******************************************************************************
*
* Project: OpenCPN
* Purpose: MBTiles Chart Support
* Author: David Register
*
***************************************************************************
/***************************************************************************
* Copyright (C) 2018 by David S. Register *
* *
* This program is free software; you can redistribute it and/or modify *
Expand All @@ -21,144 +15,183 @@
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************
*
*
*/
***************************************************************************/

#ifndef _CHARTMBTILES_H_
#define _CHARTMBTILES_H_

#include <cstdint>
#include <thread>

#include "chartbase.h"
#include "model/georef.h" // for GeoRef type
#include "OCPNRegion.h"
#include "ocpn_pixel.h"
#include "viewport.h"
#include "TileDescriptor.hpp"
#include "WorkerThread.hpp"
#include "TileCache.hpp"

enum class MBTilesType : std::int8_t { BASE, OVERLAY };
enum class MBTilesScheme : std::int8_t { XYZ, TMS };
#include "tile_descr.h"
#include "tile_thread.h"
#include "tile_cache.h"

class WXDLLEXPORT ChartMbTiles;

//-----------------------------------------------------------------------------
// Constants, etc.
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// Fwd Refs
//-----------------------------------------------------------------------------

class ViewPort;
class PixelCache;
class ocpnBitmap;
class mbTileDescriptor;

namespace SQLite {
class Database;
}
#ifdef ocpnUSE_GL
#include "shaders.h"
#endif

class GLShaderProgram;
class MbtTilesThread;
//-----------------------------------------------------------------------------
// Helper classes
//-----------------------------------------------------------------------------
/** The type of a MBTiles chart. */
enum class MbTilesType : std::int8_t {
BASE, ///< Base map, providing the primary chart imagery
OVERLAY ///< Overlay map, adding additional information on top of a base map
};

// ----------------------------------------------------------------------------
// ChartMBTiles
// ----------------------------------------------------------------------------
/** The tile scheme used in the MBTiles chart. */
enum class MbTilesScheme : std::int8_t {
XYZ, ///< "Slippy Map" tilenames. Origin at top-left, Y increases
/// southward.
TMS ///< Tile Map Service scheme. Origin at bottom-left, Y increases
/// northward.
};

class ChartMBTiles : public ChartBase {
/**
* Represents an MBTiles format chart.
*
* Provides functionality to load, render, and interact with MBTiles format
* charts. MBTiles stores tiled map data in SQLite databases for efficient
* storage and retrieval.
*
* An MBTiles chart consists of:
*
* - A set of image tiles at various zoom levels.
* - Metadata about the tileset (e.g., attribution, description).
* - An SQLite database structure for organizing and accessing tiles.
*
* Handles tile management, caching, and rendering for efficient
* display of large tiled datasets, supporting both XYZ and TMS tile schemes.
*/
class ChartMbTiles : public ChartBase {
public:
// Public methods

ChartMBTiles();
virtual ~ChartMBTiles();
ChartMbTiles();
virtual ~ChartMbTiles();

// Accessors
virtual ThumbData *GetThumbData(int tnx, int tny, float lat, float lon);
virtual ThumbData *GetThumbData();

/**
* Get the Chart thumbnail data structure,
* creating the thumbnail bitmap as required
*/
virtual ThumbData* GetThumbData(int tnx, int tny, float lat, float lon);
virtual ThumbData* GetThumbData();
virtual bool UpdateThumbData(double lat, double lon);

virtual bool AdjustVP(ViewPort &vp_last, ViewPort &vp_proposed);
virtual bool AdjustVP(ViewPort& vp_last, ViewPort& vp_proposed);

int GetNativeScale() { return m_Chart_Scale; }

/**
* Report recommended minimum scale values for which use of this
* chart is valid
*/
double GetNormalScaleMin(double canvas_scale_factor, bool b_allow_overzoom);

/**
* Report recommended maximum scale values for which use of this
* chart is valid
*/
double GetNormalScaleMax(double canvas_scale_factor, int canvas_width);

virtual InitReturn Init(const wxString &name, ChartInitFlag init_flags);
virtual InitReturn Init(const wxString& name, ChartInitFlag init_flags);

bool RenderRegionViewOnDC(wxMemoryDC &dc, const ViewPort &VPoint,
const OCPNRegion &Region);
bool RenderRegionViewOnDC(wxMemoryDC& dc, const ViewPort& VPoint,
const OCPNRegion& Region);

virtual bool RenderRegionViewOnGL(const wxGLContext &glc,
const ViewPort &VPoint,
const OCPNRegion &RectRegion,
const LLRegion &Region);
virtual bool RenderRegionViewOnGL(const wxGLContext& glc,
const ViewPort& vpoint,
const OCPNRegion& rect_region,
const LLRegion& region);

virtual double GetNearestPreferredScalePPM(double target_scale_ppm);

virtual void GetValidCanvasRegion(const ViewPort &VPoint,
OCPNRegion *pValidRegion);
virtual void GetValidCanvasRegion(const ViewPort& v_point,
OCPNRegion* valid_region);
virtual LLRegion GetValidRegion();

virtual bool GetChartExtent(Extent *pext);
virtual bool GetChartExtent(Extent* pext);

void SetColorScheme(ColorScheme cs, bool bApplyImmediate);

double GetPPM() { return m_ppm_avg; }
double GetZoomFactor() { return m_zoomScaleFactor; }
MBTilesType GetTileType() { return m_TileType; }
double GetZoomFactor() { return m_zoom_scale_factor; }
MbTilesType GetTileType() { return m_tile_type; }

protected:
// Methods
bool RenderViewOnDC(wxMemoryDC &dc, const ViewPort &VPoint);
InitReturn PreInit(const wxString &name, ChartInitFlag init_flags,
bool RenderViewOnDC(wxMemoryDC& dc, const ViewPort& VPoint);
InitReturn PreInit(const wxString& name, ChartInitFlag init_flags,
ColorScheme cs);
InitReturn PostInit(void);

void PrepareTiles();
void PrepareTilesForZoom(int zoomFactor, bool bset_geom);
bool getTileTexture(mbTileDescriptor *tile);

/**
* Loads a tile into OpenGL's texture memory for rendering. If the tile
* is not ready to be rendered (i.e. the tile has not been loaded from
* disk or ndecompressed to memory), the function sends a request to
* the worker thread which will do this later in the background
* @param tile Pointer to the tile descriptor to be prepared
* @return true if the tile is ready to be rendered, false else.
*/
bool GetTileTexture(SharedTilePtr tile);
void FlushTiles(void);
bool RenderTile(mbTileDescriptor *tile, int zoomLevel,
const ViewPort &VPoint);
bool RenderTile(SharedTilePtr tile, int zoom_level, const ViewPort& vpoint);

// Protected Data

float m_LonMax, m_LonMin, m_LatMax, m_LatMin;
float m_lon_max;
float m_lon_min;
float m_lat_max;
float m_lat_min;

double m_ppm_avg; // Calculated true scale factor of the 1X chart,
// pixels per meter
MBTilesType m_TileType;
MbTilesType m_tile_type;

int m_b_cdebug;

int m_minZoom, m_maxZoom;
TileCache *m_tileCache;
LLRegion m_minZoomRegion;
wxBitmapType m_imageType;
int m_min_zoom;
int m_max_zoom;
std::unique_ptr<TileCache> m_tile_cache;
LLRegion m_min_zoom_region;
wxBitmapType m_image_type;
int m_last_clean_zoom;

double m_zoomScaleFactor;
double m_zoom_scale_factor;

MBTilesScheme m_Scheme;
MbTilesScheme m_scheme;

SQLite::Database *m_pDB;
int m_nTiles;
std::shared_ptr<SQLite::Database> m_db;
int m_n_tiles;
std::string m_format;

GLShaderProgram *m_tile_shader_program;
uint32_t m_tileCount;
MbtTilesThread *m_workerThread;
uint32_t m_tile_count;
std::unique_ptr<MbtTilesThread> m_worker_thread;
std::thread m_thread;

#ifdef ocpnUSE_GL
GLShaderProgram* m_tile_shader_program;
#endif

/**
* Create and start the worker thread. This thread is dedicated at
* loading and decompressing chart tiles into memory, in the background. If
* for any reason the thread would fail to load, the method return false
*/
bool StartThread();

/** Stop and delete the worker thread. Called when OpenCPN is quitting. */
void StopThread();

private:
void InitFromTiles(const wxString &name);
wxPoint2DDouble GetDoublePixFromLL(ViewPort &vp, double lat, double lon);
void InitFromTiles(const wxString& name);
wxPoint2DDouble GetDoublePixFromLL(ViewPort& vp, double lat, double lon);
};

#endif
Loading

0 comments on commit caaa4f8

Please sign in to comment.