Skip to content

Commit

Permalink
use working src code ques
Browse files Browse the repository at this point in the history
  • Loading branch information
Rasbats committed Jan 5, 2021
1 parent 9ccd612 commit 469741a
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 1,270 deletions.
4 changes: 2 additions & 2 deletions src/AboutDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
#include <wx/wx.h>

#include <stdlib.h>
#include <math.h>
#include <cmath>
#include <time.h>

#include "AboutDialog.h"
#include "PhotoLayer_pi.h"

AboutDialog::AboutDialog( wxWindow *parent ) : AboutDialogBase(parent)
{
m_stVersion->SetLabel(wxString::Format(_T("%d.%d"), MY_PLUGIN_VERSION_MAJOR, MY_PLUGIN_VERSION_MINOR));
m_stVersion->SetLabel(wxString::Format(_T("%d.%d"), PLUGIN_VERSION_MAJOR, PLUGIN_VERSION_MINOR));
}

void AboutDialog::OnAboutAuthor( wxCommandEvent& event )
Expand Down
13 changes: 6 additions & 7 deletions src/PhotoLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include "wximgkap.h"

/* XPM */
static char *photolayer_xpm[] = {
static const char *photolayer_xpm[] = {
"32 32 4 1 0 0",
" c #E6E6E6",
"! c #FF0080",
Expand Down Expand Up @@ -234,8 +234,9 @@ void PhotoLayer::SaveTIFCoordinatesToXml(PhotoLayerImageCoordinateList &coords,
}

wxString layer_path = PhotoLayer_pi::StandardPath();
wxString s = wxFileName::GetPathSeparator();

if (!doc.SaveFile((layer_path + filename).mb_str()))
if (!doc.SaveFile((layer_path + s + filename).mb_str()))
wxLogMessage(_("PhotoLayer") + wxString(_T(": ")) + _("Failed to save xml file: ") + filename);
}

Expand All @@ -245,8 +246,9 @@ void PhotoLayer::LoadTIFCoordinatesFromXml(PhotoLayerImageCoordinateList &coords
wxString name;
wxString error;
wxString coordinatesets_path = PhotoLayer_pi::StandardPath();
wxString s = wxFileName::GetPathSeparator();

if(!doc.LoadFile((coordinatesets_path + coordinatesets).mb_str()))
if(!doc.LoadFile((coordinatesets_path + s + coordinatesets).mb_str()))
FAIL(_("Failed to load data sets"));
else {
TiXmlElement* root = doc.RootElement();
Expand Down Expand Up @@ -469,11 +471,8 @@ void PhotoLayer::Goto(int selection)
lon1 += 360;

double distance;
#if 0 // for opencpn 3.3 and later
DistanceBearingMercator_Plugin(lat0, lon0, lat1, lon1, NULL, &distance);
#else
WFDistanceBearingMercator(lat0, lon0, lat1, lon1, NULL, &distance);
#endif

if(!isnan(distance))
JumpToPosition((lat0 + lat1) / 2, (lon0 + lon1) / 2, .5/distance);
}
Expand Down
25 changes: 18 additions & 7 deletions src/PhotoLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,22 @@
#include <vector>

#include "PhotoLayerUI.h"
#include "geotiffio.h"
#include "xtiffio.h"
#include "geo_normalize.h"
#include "geo_simpletags.h"
#include "geovalues.h"
#include "tiffio.h"
#include "cpl_serv.h"

#if not defined WIN32
#define __int64 long int
#include <tiffio.h>
#include <xtiffio.h>
#include <geotiffio.h>
#endif

#include "geotiffio.h"
#include "xtiffio.h"
#include "geo_normalize.h"
#include "geo_simpletags.h"
#include "geovalues.h"
#include "tiffio.h"
#include "cpl_serv.h"


#include <wx/dynarray.h>
#include <ctype.h>
Expand All @@ -43,6 +52,8 @@
#include <wchar.h>
#include <bitset>

#include <cmath>

enum { VERSION = 0, MAJOR, MINOR };

extern const char * box_xpm[];
Expand Down
1 change: 1 addition & 0 deletions src/PhotoLayerImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
*/

#include "ocpn_plugin.h"
#include <cmath>

struct PhotoLayerImageCoordinates
{
Expand Down
115 changes: 46 additions & 69 deletions src/PhotoLayer_pi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,19 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************
*/
#include "wx/wxprec.h"

#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif //precompiled headers

#include "PhotoLayer_pi.h"
#include "PhotoLayerImage.h"
#include "PhotoLayer.h"
#include "icons.h"

#include "version.h"

// the class factories, used to create and destroy instances of the PlugIn

extern "C" DECL_EXP opencpn_plugin* create_pi(void *ppimgr)
Expand All @@ -48,22 +55,32 @@ extern "C" DECL_EXP void destroy_pi(opencpn_plugin* p)
//---------------------------------------------------------------------------------------------------------

PhotoLayer_pi::PhotoLayer_pi(void *ppimgr)
: opencpn_plugin_113(ppimgr)
:opencpn_plugin_116(ppimgr)
{
// Create the PlugIn icons
initialize_images();
wxFileName fn;
wxString tmp_path;

tmp_path = GetPluginDataDir("photolayer_pi");
fn.SetPath(tmp_path);
fn.AppendDir(_T("data"));
fn.SetFullName("photolayer_panel_icon.png");

wxString shareLocn = fn.GetFullPath();

wxString shareLocn = *GetpSharedDataLocation() +
_T("plugins") + wxFileName::GetPathSeparator() +
_T("photolayer_pi") + wxFileName::GetPathSeparator()
+ _T("data") + wxFileName::GetPathSeparator();
wxImage panelIcon(shareLocn + _T("photolayer_panel_icon.png"));
wxImage panelIcon(shareLocn);
if (panelIcon.IsOk())
m_panelBitmap = wxBitmap(panelIcon);
else
wxLogMessage(_T(" PhotoLayer panel icon NOT loaded"));
}

PhotoLayer_pi::~PhotoLayer_pi(void)
{

}

//---------------------------------------------------------------------------------------------------------
//
// PlugIn initialization and de-init
Expand All @@ -72,33 +89,15 @@ PhotoLayer_pi::PhotoLayer_pi(void *ppimgr)

int PhotoLayer_pi::Init(void)
{
AddLocaleCatalog( _T("opencpn-PhotoLayer_pi") );
//m_leftclick_tool_id = InsertPlugInTool(_T(""), _img_photolayer,
// _img_photolayer, wxITEM_NORMAL,
// _("PhotoLayer"), _T(""), NULL,
// PHOTOLAYER_TOOL_POSITION, 0, this);
AddLocaleCatalog(PLUGIN_CATALOG_NAME);

m_pPhotoLayer = NULL;

m_bShowPhoto = false;

wxString shareLocn = *GetpSharedDataLocation() +
_T("plugins") + wxFileName::GetPathSeparator() +
_T("photolayer_pi") + wxFileName::GetPathSeparator()
+ _T("data") + wxFileName::GetPathSeparator();

wxString normalIcon = shareLocn + _T("photolayer.svg");
wxString toggledIcon = shareLocn + _T("photolayer_toggled.svg");

// For journeyman styles, we prefer the built-in raster icons which match the rest of the toolbar.
/* if (GetActiveStyleName().Lower() != _T("traditional")) {
normalIcon = _T("");
toggledIcon = _T("");
rolloverIcon = _T("");
}
*/
wxLogMessage(normalIcon);
m_leftclick_tool_id = InsertPlugInToolSVG(_T(""), normalIcon, normalIcon, toggledIcon, wxITEM_CHECK,
_("PhotoLayer"), _T(""), NULL, PHOTOLAYER_TOOL_POSITION, 0, this);

m_leftclick_tool_id = InsertPlugInToolSVG(_T(""), _svg_photolayer, _svg_photolayer, _svg_photolayer_toggled,
wxITEM_CHECK, _("PhotoLayer"), _T(""), NULL, PHOTOLAYER_TOOL_POSITION, 0, this);



Expand Down Expand Up @@ -132,22 +131,22 @@ bool PhotoLayer_pi::DeInit(void)

int PhotoLayer_pi::GetAPIVersionMajor()
{
return MY_API_VERSION_MAJOR;
return OCPN_API_VERSION_MAJOR;
}

int PhotoLayer_pi::GetAPIVersionMinor()
{
return MY_API_VERSION_MINOR;
return OCPN_API_VERSION_MINOR;
}

int PhotoLayer_pi::GetPlugInVersionMajor()
{
return MY_PLUGIN_VERSION_MAJOR;
return PLUGIN_VERSION_MAJOR;
}

int PhotoLayer_pi::GetPlugInVersionMinor()
{
return MY_PLUGIN_VERSION_MINOR;
return PLUGIN_VERSION_MINOR;
}

wxBitmap *PhotoLayer_pi::GetPlugInBitmap()
Expand All @@ -157,7 +156,7 @@ wxBitmap *PhotoLayer_pi::GetPlugInBitmap()

wxString PhotoLayer_pi::GetCommonName()
{
return _("PhotoLayer");
return PLUGIN_COMMON_NAME;
}

wxString PhotoLayer_pi::GetShortDescription()
Expand Down Expand Up @@ -272,46 +271,25 @@ bool PhotoLayer_pi::RenderGLOverlay(wxGLContext *pcontext, PlugIn_ViewPort *vp)

wxString PhotoLayer_pi::StandardPath()
{
wxStandardPathsBase& std_path = wxStandardPathsBase::Get();
wxString s = wxFileName::GetPathSeparator();

#if defined(__WXMSW__)
wxString stdPath = std_path.GetConfigDir();
#elif defined(__WXGTK__) || defined(__WXQT__)
wxString stdPath = std_path.GetUserDataDir();
#elif defined(__WXOSX__)
wxString stdPath = (std_path.GetUserConfigDir() + s + _T("opencpn"));
#endif

stdPath += s + _T("plugins");
if (!wxDirExists(stdPath))
wxMkdir(stdPath);

stdPath += s + _T("PhotoLayer");

#ifdef __WXOSX__
// Compatibility with pre-OCPN-4.2; move config dir to
// ~/Library/Preferences/opencpn if it exists
wxString oldPath = (std_path.GetUserConfigDir() + s + _T("plugins") + s + _T("PhotoLayer"));
if (wxDirExists(oldPath) && !wxDirExists(stdPath)) {
wxLogMessage("PhotoLayer_pi: moving config dir %s to %s", oldPath, stdPath);
wxRenameFile(oldPath, stdPath);
}
#endif

if (!wxDirExists(stdPath))
wxMkdir(stdPath);

stdPath += s; // is this necessary?

wxString stdPath(*GetpPrivateApplicationDataLocation());
wxString s = wxFileName::GetPathSeparator();

stdPath += s + _T("plugins") + s + _T("photolayer_pi");
if (!wxDirExists(stdPath))
wxMkdir(stdPath);
stdPath += s + _T("data");
if (!wxDirExists(stdPath))
wxMkdir(stdPath);

return stdPath;
}

bool PhotoLayer_pi::LoadConfig(void)
{
wxFileConfig *pConf = GetOCPNConfigObject();

if(!pConf)
return false;
if(!pConf){return false;}

wxString m_export_colors;

Expand All @@ -332,8 +310,7 @@ bool PhotoLayer_pi::SaveConfig(void)
{
wxFileConfig *pConf = GetOCPNConfigObject();

if(!pConf)
return false;
if(!pConf){return false;}

pConf->SetPath(_T("/Settings/PhotoLayer"));
pConf->Write(_T("Path"), m_path);
Expand Down
15 changes: 6 additions & 9 deletions src/PhotoLayer_pi.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,17 @@
#include <wx/stdpaths.h>
#include <wx/fileconf.h>

#include "ocpn_plugin.h"
#include "version.h"

#define MY_API_VERSION_MAJOR 1
#define MY_API_VERSION_MINOR 13

#define MY_PLUGIN_VERSION_MAJOR 2
#define MY_PLUGIN_VERSION_MINOR 2

#define ABOUT_AUTHOR_URL "http://mikerossiter.co.uk"

#include "ocpn_plugin.h"

#include "defs.h"

#include "version.h"


//----------------------------------------------------------------------------------------------------------
// The PlugIn Class Definition
//----------------------------------------------------------------------------------------------------------
Expand All @@ -54,11 +51,11 @@
class PhotoLayerImage;
class PhotoLayer;

class PhotoLayer_pi : public opencpn_plugin_113
class PhotoLayer_pi : public opencpn_plugin_116
{
public:
PhotoLayer_pi(void *ppimgr);

~PhotoLayer_pi(void);

// The required PlugIn Methods
int Init(void);
Expand Down
12 changes: 7 additions & 5 deletions src/icons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
wxBitmap *_img_photolayer;
wxBitmap *_img_photolayer_pi;

#ifdef PHOTOLAYER_USE_SVG

#include "ocpn_plugin.h"
wxString _svg_photolayer;
wxString _svg_photolayer_rollover;
wxString _svg_photolayer_toggled;
#endif




Expand All @@ -32,10 +32,12 @@ void initialize_images(void)

#ifdef PHOTOLAYER_USE_SVG
wxFileName fn;
fn.SetPath(*GetpSharedDataLocation());
fn.AppendDir(_T("plugins"));
fn.AppendDir(_T("photolayer_pi"));
wxString tmp_path;

tmp_path = GetPluginDataDir("photolayer_pi");
fn.SetPath(tmp_path);
fn.AppendDir(_T("data"));

fn.SetFullName(_T("photolayer.svg"));
_svg_photolayer = fn.GetFullPath();
fn.SetFullName(_T("photolayer_rollover.svg"));
Expand Down
Loading

0 comments on commit 469741a

Please sign in to comment.