From 3f80f80fbe3ae582c6f7051704b8dee3dab4ead3 Mon Sep 17 00:00:00 2001 From: Jon Date: Thu, 31 May 2018 14:06:42 +1000 Subject: [PATCH] Updated Readme Made app check for API's available before using them --- CMakeLists.txt | 4 +- README.md | 3 +- include/testplugin_pi.h | 40 +++++++++++------ include/tpControlDialogImpl.h | 1 + src/testplugin_pi.cpp | 83 ++++++++++++++++++++++++++++++++++- src/tpControlDialogImpl.cpp | 26 +++++++++++ src/tpJSON.cpp | 18 +++++--- 7 files changed, 149 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 661218c1d..2fa9166e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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" ) diff --git a/README.md b/README.md index f4d0930cd..7d3d46ba5 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/include/testplugin_pi.h b/include/testplugin_pi.h index 5a0d442e2..946c387de 100644 --- a/include/testplugin_pi.h +++ b/include/testplugin_pi.h @@ -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); @@ -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: @@ -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; diff --git a/include/tpControlDialogImpl.h b/include/tpControlDialogImpl.h index 36d7016e0..cc06915e4 100644 --- a/include/tpControlDialogImpl.h +++ b/include/tpControlDialogImpl.h @@ -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; diff --git a/src/testplugin_pi.cpp b/src/testplugin_pi.cpp index fe6532310..b8ae17733 100644 --- a/src/testplugin_pi.cpp +++ b/src/testplugin_pi.cpp @@ -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 ); @@ -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) @@ -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(); } } @@ -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) diff --git a/src/tpControlDialogImpl.cpp b/src/tpControlDialogImpl.cpp index b136c136f..fea4676ad 100644 --- a/src/tpControlDialogImpl.cpp +++ b/src/tpControlDialogImpl.cpp @@ -28,6 +28,7 @@ #ifndef WX_PRECOMP #include "wx/wx.h" #endif +#include #include "tpControlDialogImpl.h" #include "testplugin_pi.h" @@ -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 ) @@ -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 ) @@ -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(); +} + diff --git a/src/tpJSON.cpp b/src/tpJSON.cpp index c5a950dfd..9b86f0baf 100644 --- a/src/tpJSON.cpp +++ b/src/tpJSON.cpp @@ -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 ); @@ -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") ); @@ -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"); @@ -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; @@ -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