Skip to content

Commit

Permalink
Updated Readme
Browse files Browse the repository at this point in the history
Made app check for API's available before using them
  • Loading branch information
jongough committed May 31, 2018
1 parent e6806cf commit 3f80f80
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 26 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ SET(CPACK_PACKAGE_CONTACT "Jon Gough")

SET(VERSION_MAJOR "1")
SET(VERSION_MINOR "0")
SET(VERSION_PATCH "4")
SET(VERSION_DATE "30/05/2018")
SET(VERSION_PATCH "5")
SET(VERSION_DATE "31/05/2018")

SET(BUNDLE_DATA FALSE)
SET( CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build" )
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@ Only ODAPI is working at the moment. JSON is being developed now.
3. then click create.
4. The object 'should' be created. T

NOTE the Boundary works, but may initially crash opencpn, until the initialization has taken.
Try selecting the number of boundary points first.
NOTE this is currently a work in progress and should be considered 'Alpha/Beta'. It may have issues at times as new functionality is added. It is a test tool not a production plugin.
40 changes: 26 additions & 14 deletions include/testplugin_pi.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class testplugin_pi : public opencpn_plugin_113
void loadLayouts(wxWindow * parent);
// void startLogbook();
void shutdown(bool menu);

void LateInit(void);
bool KeyboardEventHook( wxKeyEvent &event );
bool MouseEventHook( wxMouseEvent &event );
void SetCursorLatLon(double lat, double lon);
Expand Down Expand Up @@ -231,13 +231,24 @@ class testplugin_pi : public opencpn_plugin_113

void appendOSDirSlash(wxString* pString);

tpicons *m_ptpicons;
tpicons *m_ptpicons;
tpControlDialogImpl *m_tpControlDialogImpl;

bool eventsEnabled;
int m_iCallerId;
bool m_btpDialog;
int m_testplugin_button_id;
bool eventsEnabled;
bool m_bReadyForRequests;
bool m_bDoneODAPIVersionCall;
int m_iCallerId;
bool m_btpDialog;
int m_testplugin_button_id;
int m_iODAPIVersionMajor;
int m_iODAPIVersionMinor;
int m_iODAPIVersionPatch;
bool m_bOD_FindPointInAnyBoundary;
bool m_bODFindClosestBoundaryLineCrossing;
bool m_bODFindFirstBoundaryLineCrossing;
bool m_bODCreateBoundary;
bool m_bODCreateBoundaryPoint;
bool m_bODCreateTextPoint;


private:
Expand All @@ -250,16 +261,17 @@ class testplugin_pi : public opencpn_plugin_113
void FindSelectedObject( void ) ;

PlugIn_ViewPort m_VP;

int m_show_id;
int m_hide_id;
bool show;
int m_config_button_id;

int m_show_id;
int m_hide_id;
bool show;
int m_config_button_id;
double m_cursor_lat;
double m_cursor_lon;
double m_click_lat;
double m_click_lon;

double m_cursor_lat;
double m_cursor_lon;
double m_click_lat;
double m_click_lon;
OD_FindPointInAnyBoundary m_pOD_FindPointInAnyBoundary;
OD_FindClosestBoundaryLineCrossing m_pODFindClosestBoundaryLineCrossing;
OD_FindFirstBoundaryLineCrossing m_pODFindFirstBoundaryLineCrossing;
Expand Down
1 change: 1 addition & 0 deletions include/tpControlDialogImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class tpControlDialogImpl : public tpControlDialogDef
tpControlDialogImpl( wxWindow *parent );
void SetDialogSize( void );
void SetLatLon( double lat, double lon );
void SetPanels(void);

bool m_bOK;
int m_iSelection;
Expand Down
83 changes: 81 additions & 2 deletions src/testplugin_pi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,31 @@ testplugin_pi::~testplugin_pi()
int testplugin_pi::Init(void)
{
g_tplocale = NULL;
m_bReadyForRequests = false;
m_bDoneODAPIVersionCall = false;
m_btpDialog = false;
m_tpControlDialogImpl = NULL;
m_cursor_lat = 0.0;
m_cursor_lon = 0.0;
m_click_lat = 0.0;
m_click_lon = 0.0;
m_bOD_FindPointInAnyBoundary = false;
m_bODFindClosestBoundaryLineCrossing = false;
m_bODFindFirstBoundaryLineCrossing = false;
m_bODCreateBoundary = false;
m_bODCreateBoundaryPoint = false;
m_bODCreateTextPoint = false;
m_pOD_FindPointInAnyBoundary = NULL;
m_pODFindClosestBoundaryLineCrossing = NULL;
m_pODFindFirstBoundaryLineCrossing = NULL;
m_pODFindFirstBoundaryLineCrossing = NULL;
m_pODCreateBoundary = NULL;
m_pODCreateBoundaryPoint = NULL;
m_pODCreateTextPoint = NULL;
m_iODAPIVersionMajor = 0;
m_iODAPIVersionMinor = 0;
m_iODAPIVersionPatch = 0;


// Adds local language support for the plugin to OCPN
AddLocaleCatalog( PLUGIN_CATALOG_NAME );
Expand Down Expand Up @@ -248,11 +267,19 @@ int testplugin_pi::Init(void)
// WANTS_PREFERENCES |
// WANTS_ONPAINT_VIEWPORT |
WANTS_PLUGIN_MESSAGING |
WANTS_LATE_INIT |
WANTS_MOUSE_EVENTS |
WANTS_KEYBOARD_EVENTS
);
}

void testplugin_pi::LateInit(void)
{
SendPluginMessage(wxS("TESTPLUGIN_PI_READY_FOR_REQUESTS"), wxS("TRUE"));
m_bReadyForRequests = true;
return;
}

bool testplugin_pi::DeInit(void)
{
if(m_tpControlDialogImpl)
Expand Down Expand Up @@ -409,6 +436,8 @@ void testplugin_pi::ToggleToolbarIcon( void )
} else {
m_btpDialog = true;
SetToolbarItemState( m_testplugin_button_id, true );
if(!m_bDoneODAPIVersionCall) GetODAPI();
m_tpControlDialogImpl->SetPanels();
m_tpControlDialogImpl->Show();
}
}
Expand All @@ -418,38 +447,88 @@ void testplugin_pi::GetODAPI()
wxJSONValue jMsg;
wxJSONWriter writer;
wxString MsgString;

jMsg[wxT("Source")] = wxT("TESTPLUGIN_PI");
jMsg[wxT("Type")] = wxT("Request");
jMsg[wxT("Msg")] = wxS("GetAPIAddresses");
jMsg[wxT("MsgId")] = wxS("GetAPIAddresses");
jMsg[wxT("Msg")] = wxS("Version");
jMsg[wxT("MsgId")] = wxS("Version");
writer.Write( jMsg, MsgString );
SendPluginMessage( wxS("OCPN_DRAW_PI"), MsgString );
if(g_ReceivedODAPIMessage != wxEmptyString && g_ReceivedODAPIJSONMsg[wxT("MsgId")].AsString() == wxS("Version")) {
m_iODAPIVersionMajor = g_ReceivedODAPIJSONMsg[wxS("Major")].AsInt();
m_iODAPIVersionMinor = g_ReceivedODAPIJSONMsg[wxS("Minor")].AsInt();
m_iODAPIVersionPatch = g_ReceivedODAPIJSONMsg[wxS("Patch")].AsInt();
}
m_bDoneODAPIVersionCall = true;

wxJSONValue jMsg1;
jMsg1[wxT("Source")] = wxT("TESTPLUGIN_PI");
jMsg1[wxT("Type")] = wxT("Request");
jMsg1[wxT("Msg")] = wxS("GetAPIAddresses");
jMsg1[wxT("MsgId")] = wxS("GetAPIAddresses");
writer.Write( jMsg1, MsgString );
SendPluginMessage( wxS("OCPN_DRAW_PI"), MsgString );
if(g_ReceivedODAPIMessage != wxEmptyString && g_ReceivedODAPIJSONMsg[wxT("MsgId")].AsString() == wxS("GetAPIAddresses")) {
wxString sptr = g_ReceivedODAPIJSONMsg[_T("OD_FindPointInAnyBoundary")].AsString();
if(sptr != _T("null")) {
sscanf(sptr.To8BitData().data(), "%p", &m_pOD_FindPointInAnyBoundary);
m_bOD_FindPointInAnyBoundary = true;
}
sptr = g_ReceivedODAPIJSONMsg[_T("OD_FindClosestBoundaryLineCrossing")].AsString();
if(sptr != _T("null")) {
sscanf(sptr.To8BitData().data(), "%p", &m_pODFindClosestBoundaryLineCrossing);
m_bODFindClosestBoundaryLineCrossing = true;
}
sptr = g_ReceivedODAPIJSONMsg[_T("OD_FindFirstBoundaryLineCrossing")].AsString();
if(sptr != _T("null")) {
sscanf(sptr.To8BitData().data(), "%p", &m_pODFindFirstBoundaryLineCrossing);
m_bODFindFirstBoundaryLineCrossing = true;
}
sptr = g_ReceivedODAPIJSONMsg[_T("OD_CreateBoundary")].AsString();
if(sptr != _T("null")) {
sscanf(sptr.To8BitData().data(), "%p", &m_pODCreateBoundary);
m_bODCreateBoundary = true;
}
sptr = g_ReceivedODAPIJSONMsg[_T("OD_CreateBoundaryPoint")].AsString();
if(sptr != _T("null")) {
sscanf(sptr.To8BitData().data(), "%p", &m_pODCreateBoundaryPoint);
m_bODCreateBoundaryPoint = true;
}
sptr = g_ReceivedODAPIJSONMsg[_T("OD_CreateTextPoint")].AsString();
if(sptr != _T("null")) {
sscanf(sptr.To8BitData().data(), "%p", &m_pODCreateTextPoint);
m_bODCreateTextPoint = true;
}
}

wxString l_msg;
wxString l_avail;
wxString l_notavail;
l_msg.Printf(_("ODAPI Version: Major: %i, Minor: %i, Patch: %i\n"), m_iODAPIVersionMajor, m_iODAPIVersionMinor, m_iODAPIVersionPatch);
if(m_bOD_FindPointInAnyBoundary) l_avail.Append(_("OD_FindPointInAnyBoundary\n"));
if(m_bODFindClosestBoundaryLineCrossing) l_avail.Append(_("ODFindClosestBoundaryLineCrossing\n"));
if(m_bODFindFirstBoundaryLineCrossing) l_avail.Append(_("ODFindFirstBoundaryLineCrossing\n"));
if(m_bODCreateBoundary) l_avail.Append(_("ODCreateBoundary\n"));
if(m_bODCreateBoundaryPoint) l_avail.Append(_("ODCreateBoundaryPoint\n"));
if(m_bODCreateTextPoint) l_avail.Append(_("ODCreateTextPoint\n"));
if(l_avail.Length() > 0) {
l_msg.Append(_("The following ODAPI's are available: \n"));
l_msg.Append(l_avail);
}

if(!m_bOD_FindPointInAnyBoundary) l_notavail.Append(_("OD_FindPointInAnyBoundary\n"));
if(!m_bODFindClosestBoundaryLineCrossing) l_notavail.Append(_("ODFindClosestBoundaryLineCrossing\n"));
if(!m_bODFindFirstBoundaryLineCrossing) l_notavail.Append(_("ODFindFirstBoundaryLineCrossing\n"));
if(!m_bODCreateBoundary) l_notavail.Append(_("ODCreateBoundary\n"));
if(!m_bODCreateBoundaryPoint) l_notavail.Append(_("ODCreateBoundaryPoint\n"));
if(!m_bODCreateTextPoint) l_notavail.Append(_("ODCreateTextPoint\n"));
if(l_notavail.Length() > 0) {
l_msg.Append(_("The following ODAPI's are not available:\m"));
l_msg.Append(l_avail);
}

OCPNMessageBox_PlugIn( m_parent_window, l_msg, _("TESTPLUGIN"), (long) wxYES );

}

void testplugin_pi::FindClosestBoundaryLineCrossing(FindClosestBoundaryLineCrossing_t *pFCPBLC)
Expand Down
26 changes: 26 additions & 0 deletions src/tpControlDialogImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#include <wx/ffile.h>

#include "tpControlDialogImpl.h"
#include "testplugin_pi.h"
Expand Down Expand Up @@ -58,6 +59,10 @@ tpControlDialogImpl::tpControlDialogImpl( wxWindow* parent ) : tpControlDialogDe
m_bCreateBoundaryPointHasFocus = FALSE;
m_pfdDialog = NULL;

if(!g_testplugin_pi->m_bODCreateBoundary) m_panelODAPICreateBoundary->Disable();
if(!g_testplugin_pi->m_bODCreateBoundaryPoint) m_panelODAPICreateBoundaryPoint->Disable();
if(!g_testplugin_pi->m_bODCreateTextPoint) m_panelODAPICreateTextPoint->Disable();

}

void tpControlDialogImpl::OnButtonClickCreateBoundary( wxCommandEvent& event )
Expand Down Expand Up @@ -329,7 +334,18 @@ void tpControlDialogImpl::tpControlCancelClick( wxCommandEvent& event )

void tpControlDialogImpl::tpControlOnClickProcessJSON( wxCommandEvent& event )
{
wxFileName l_FileName = m_filePickerJSON->GetPath();
if(!l_FileName.IsOk()) {
OCPNMessageBox_PlugIn( NULL, l_FileName.GetFullPath(), _("File not found"), wxICON_EXCLAMATION | wxCANCEL );
return;
}
wxString l_file = l_FileName.GetFullPath();
wxFFile *l_ffFile = new wxFFile(l_FileName.GetFullPath());
wxString l_jString;
//l_ffFile->Open(l_FileName.GetFullPath());
l_ffFile->ReadAll(&l_jString);

wxString l_name = l_FileName.GetFullName();
}

void tpControlDialogImpl::SetLatLon( double lat, double lon )
Expand Down Expand Up @@ -383,3 +399,13 @@ void tpControlDialogImpl::SetDialogSize( void )
this->Layout();
}

void tpControlDialogImpl::SetPanels()
{
if(g_testplugin_pi->m_bODCreateBoundary) m_panelODAPICreateBoundary->Enable();
else m_panelODAPICreateBoundary->Disable();
if(g_testplugin_pi->m_bODCreateBoundaryPoint) m_panelODAPICreateBoundaryPoint->Enable();
else m_panelODAPICreateBoundaryPoint->Disable();
if(g_testplugin_pi->m_bODCreateTextPoint) m_panelODAPICreateTextPoint->Enable();
else m_panelODAPICreateTextPoint->Disable();
}

18 changes: 12 additions & 6 deletions src/tpJSON.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,14 @@ void tpJSON::ProcessMessage(wxString &message_id, wxString &message_body)
int l_BoundaryState;
bool bFail = false;

if(message_id == wxS("TESTPLUGIN_PI")) {
if(message_id != _T("TESTPLUGIN_PI")) {
if(message_id == _T("OCPN_DRAW_PI_READY_FOR_REQUESTS")) {
if(message_body == _T("TRUE")) {
if(g_testplugin_pi->m_bReadyForRequests)
g_testplugin_pi->GetODAPI();
}
}
} else if(message_id == wxS("TESTPLUGIN_PI")) {
// now read the JSON text and store it in the 'root' structure
// check for errors before retreiving values...
int numErrors = reader.Parse( message_body, &root );
Expand All @@ -103,7 +110,6 @@ void tpJSON::ProcessMessage(wxString &message_id, wxString &message_body)
}
return;
}

if(!root.HasMember( wxS("Source"))) {
// Originator
wxLogMessage( wxS("No Source found in message") );
Expand All @@ -128,7 +134,7 @@ void tpJSON::ProcessMessage(wxString &message_id, wxString &message_body)
bFail = true;
}

if(!bFail && root[wxS("Msg")].AsString() == wxS("Version")) {
if(!bFail && root[wxS("Msg")].AsString() == wxS("Version") && root[wxS("Type")].AsString() == wxS("Request")) {
jMsg[wxT("Source")] = wxT("TESTPLUGIN_PI");
jMsg[wxT("Msg")] = root[wxT("Msg")];
jMsg[wxT("Type")] = wxT("Response");
Expand All @@ -139,7 +145,9 @@ void tpJSON::ProcessMessage(wxString &message_id, wxString &message_body)
jMsg[wxS("Date")] = PLUGIN_VERSION_DATE;
writer.Write( jMsg, MsgString );
SendPluginMessage( root[wxS("Source")].AsString(), MsgString );

} else if(!bFail && root[wxS("Msg")].AsString() == wxS("Version") && root[wxS("Type")].AsString() == wxS("Response")) {
g_ReceivedODAPIJSONMsg = root;
g_ReceivedODAPIMessage = message_body;
} else if(root[wxS("Msg")].AsString() == wxS("GetAPIAddresses") ) {
g_ReceivedODAPIJSONMsg = root;
g_ReceivedODAPIMessage = message_body;
Expand Down Expand Up @@ -167,8 +175,6 @@ void tpJSON::ProcessMessage(wxString &message_id, wxString &message_body)
}
}

} else if(message_id == _T("OCPN_DRAW_PI_READY_FOR_REQUESTS")) {
g_testplugin_pi->GetODAPI();
} else if(message_id == _T("WMM_VARIATION_BOAT")) {

// construct the JSON root object
Expand Down

0 comments on commit 3f80f80

Please sign in to comment.