From cf9b62742f0699be21da81b01cb9656be0f78c4f Mon Sep 17 00:00:00 2001 From: caballero Date: Wed, 3 Jun 2009 15:40:30 +0000 Subject: [PATCH] Added the PACS Connection Panel, a basic socket connection class and on .Gimmick there is now a default localdatabase_Descriptor --- src2/CMakeLists.txt | 9 +- src2/creaImageIOGimmick.cpp | 149 +++++++++++++++++++++- src2/creaImageIOGimmick.h | 1 + src2/creaImageIOPACSConnection.cpp | 42 ++++++ src2/creaImageIOPACSConnection.h | 16 +++ src2/creaImageIOWxGimmickView.cpp | 9 +- src2/creaImageIOWxListenerPanel.cpp | 2 +- src2/creaImageIOWxPACSConnectionPanel.cpp | 61 +++++++++ src2/creaImageIOWxPACSConnectionPanel.h | 45 +++++++ src2/data/localdatabase_Descriptor.txt | 59 +++++++++ 10 files changed, 387 insertions(+), 6 deletions(-) create mode 100644 src2/creaImageIOPACSConnection.cpp create mode 100644 src2/creaImageIOPACSConnection.h create mode 100644 src2/creaImageIOWxPACSConnectionPanel.cpp create mode 100644 src2/creaImageIOWxPACSConnectionPanel.h create mode 100644 src2/data/localdatabase_Descriptor.txt diff --git a/src2/CMakeLists.txt b/src2/CMakeLists.txt index 951ccc7..c775592 100644 --- a/src2/CMakeLists.txt +++ b/src2/CMakeLists.txt @@ -36,6 +36,7 @@ SET( SRCS creaImageIOSynchron creaImageIOTimestampDatabaseHandler creaImageIOListener + creaImageIOPACSConnection # Abstract views creaImageIOGimmickView @@ -52,6 +53,7 @@ SET( SRCS creaImageIOWxListenerPanel creaImageIOWxEditFieldsPanel creaImageIOWxAttributeSelectionPanel + creaImageIOWxPACSConnectionPanel # BlockScopeWxApp @@ -67,7 +69,6 @@ SET( SRCS ) - OPTION(${LIBRARY_NAME}_BUILD_SHARED "Build ${LIBRARY_NAME} as a shared library (dynamic) ?" ON) IF (${LIBRARY_NAME}_BUILD_SHARED) @@ -144,6 +145,10 @@ SET(${LIBRARY_NAME}_ADDITIONAL_USE_FILE # Invoke the advanced macro CREA_ADVANCED_INSTALL_LIBRARY_FOR_CMAKE(${LIBRARY_NAME}) +SET(INPUT_DATA_DIR ${PROJECT_SOURCE_DIR}/src2/data) +SET(OUTPUT_DATA_DIR ${PROJECT_BINARY_DIR}/data) +CREA_CPDIR(${INPUT_DATA_DIR} ${OUTPUT_DATA_DIR}) + #CREA_INSTALL_LIBRARY_FOR_CMAKE(${LIBRARY_NAME}) #----------------------------------------------------------------------------- @@ -157,4 +162,4 @@ INCLUDE_DIRECTORIES( # ${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR}/src2 # ${PROJECT_SOURCE_DIR}/src2/CppSQLite3 - ) \ No newline at end of file + ) diff --git a/src2/creaImageIOGimmick.cpp b/src2/creaImageIOGimmick.cpp index e54d1bf..af7f701 100644 --- a/src2/creaImageIOGimmick.cpp +++ b/src2/creaImageIOGimmick.cpp @@ -4,6 +4,10 @@ #include #include +#ifndef PATH_MAX // If not defined yet : do it +# define PATH_MAX 2048 +#endif + namespace creaImageIO { @@ -39,7 +43,7 @@ namespace creaImageIO //============================================================== void Gimmick::Initialize() { - std::string i_nameDB = "Local database"; + std::string i_nameDB = "Local database"; // Create the UserSettings dir if does not exist CreateUserSettingsDirectory(); // Sets the current directory to the home dir @@ -201,6 +205,130 @@ namespace creaImageIO } //================================================================ + //================================================================ + int Gimmick::GetBinaryDirectory(char *pname, size_t pathsize) + { + + #ifdef LINUX + /* Oddly, the readlink(2) man page says no NULL is appended. */ + /* So you have to do it yourself, based on the return value: */ + pathsize --; /* Preserve a space to add the trailing NULL */ + long result = readlink("/proc/self/exe", pname, pathsize); + if (result > 0) + { + pname[result] = 0; /* add the #@!%ing NULL */ + + if ((access(pname, 0) == 0)) + return 0; /* file exists, return OK */ + /*else name doesn't seem to exist, return FAIL (falls + through) */ + } + #endif /* LINUX */ + + #ifdef WIN32 + long result = GetModuleFileName(NULL, pname, pathsize); + if (result > 0) + { + /* fix up the dir slashes... */ + int len = strlen(pname); + int idx; + for (idx = 0; idx < len; idx++) + { + if (pname[idx] == '\\') pname[idx] = '/'; + } + + for (idx = len-1; idx >=0 ; idx--) + { + if (pname[idx] == '/') + { + pname[idx+1] = '\0'; + idx = -1; + } + } + + if ((access(pname, 0) == 0)) + return 0; /* file exists, return OK */ + /*else name doesn't seem to exist, return FAIL (falls + through) */ + } + #endif /* WIN32 */ + + #ifdef SOLARIS + char *p = getexecname(); + if (p) + { + /* According to the Sun manpages, getexecname will + "normally" return an */ + /* absolute path - BUT might not... AND that IF it is not, + pre-pending */ + /* getcwd() will "usually" be the correct thing... Urgh! + */ + + /* check pathname is absolute (begins with a / ???) */ + if (p[0] == '/') /* assume this means we have an + absolute path */ + { + strncpy(pname, p, pathsize); + if ((access(pname, 0) == 0)) + return 0; /* file exists, return OK */ + } + else /* if not, prepend getcwd() then check if file + exists */ + { + getcwd(pname, pathsize); + long result = strlen(pname); + strncat(pname, "/", (pathsize - result)); + result ++; + strncat(pname, p, (pathsize - result)); + + if ((access(pname, 0) == 0)) + return 0; /* file exists, return OK */ + /*else name doesn't seem to exist, return FAIL + (falls through) */ + } + } + #endif /* SOLARIS */ + + #ifdef MACOSX /* assume this is OSX */ + /* + from http://www.hmug.org/man/3/NSModule.html + + extern int _NSGetExecutablePath(char *buf, unsigned long + *bufsize); + + _NSGetExecutablePath copies the path of the executable + into the buffer and returns 0 if the path was successfully + copied in the provided buffer. If the buffer is not large + enough, -1 is returned and the expected buffer size is + copied in *bufsize. Note that _NSGetExecutablePath will + return "a path" to the executable not a "real path" to the + executable. That is the path may be a symbolic link and + not the real file. And with deep directories the total + bufsize needed could be more than MAXPATHLEN. + */ + + int status = -1; + char *given_path = (char*)malloc(MAXPATHLEN * 2); + if (!given_path) return status; + + uint32_t npathsize = MAXPATHLEN * 2; + long result = _NSGetExecutablePath(given_path, &npathsize); + if (result == 0) + { /* OK, we got something - now try and resolve the real path... + */ + if (realpath(given_path, pname) != NULL) + { + if ((access(pname, 0) == 0)) + status = 0; /* file exists, return OK */ + } + } + free (given_path); + return status; + #endif /* MACOSX */ + + return -1; /* Path Lookup Failed */ + } + //================================================================ const std::string& Gimmick::GetLocalDatabasePath() { @@ -245,6 +373,25 @@ namespace creaImageIO GimmickError("ERROR CREATING '"< +#include +#include +#include +#include + +using boost::asio::ip::tcp; + +enum { max_length = 3086 }; +using namespace std; +namespace creaImageIO +{ + PACSConnection::PACSConnection(std::string command) + { + try + { + + boost::asio::io_service io_service; + + tcp::resolver resolver(io_service); + tcp::resolver::query query(tcp::v4(), "localhost", "3306"); + tcp::resolver::iterator iterator = resolver.resolve(query); + + tcp::socket s(io_service); + s.connect(*iterator); + + size_t request_length = strlen(command.c_str()); + boost::asio::write(s, boost::asio::buffer(command.c_str(), request_length)); + + char reply[max_length]; + size_t reply_length = boost::asio::read(s, + boost::asio::buffer(reply, request_length)); + std::cout << "Reply is: "; + std::cout.write(reply, reply_length); + std::cout << "\n"; + } + catch (std::exception& e) + { + std::cerr << "Exception: " << e.what() << "\n"; + } + } +} diff --git a/src2/creaImageIOPACSConnection.h b/src2/creaImageIOPACSConnection.h new file mode 100644 index 0000000..659be58 --- /dev/null +++ b/src2/creaImageIOPACSConnection.h @@ -0,0 +1,16 @@ +#ifndef __creaImageIOPACSConnection_h_INCLUDED__ +#define __creaImageIOPACSConnection_h_INCLUDED__ +#include + +namespace creaImageIO +{ +class PACSConnection + { + public: + /// Ctor + PACSConnection(std::string command); + };// EO PACSConnection +} // EO namespace creaImageIO + +// EOF +#endif \ No newline at end of file diff --git a/src2/creaImageIOWxGimmickView.cpp b/src2/creaImageIOWxGimmickView.cpp index d6ddcdc..a77f9a7 100644 --- a/src2/creaImageIOWxGimmickView.cpp +++ b/src2/creaImageIOWxGimmickView.cpp @@ -5,6 +5,7 @@ #include #include #include +#include using namespace crea; // Icons @@ -808,8 +809,12 @@ namespace creaImageIO nb->AddPage( customConfig, crea::std2wx("Customize Configuration") ); //Second page: Creation of Databases - wxPanel* databaseCreation=new wxPanel(nb); - nb->AddPage( databaseCreation, crea::std2wx("Create Database") ); + /*wxPanel* databaseCreation=new wxPanel(nb); + nb->AddPage( databaseCreation, crea::std2wx("Create Database") );*/ + + //Second page (temporary): Connection to PACS + WxPACSConnectionPanel* pacs=new WxPACSConnectionPanel(nb,dial, this); + nb->AddPage( pacs, crea::std2wx("Connect to PACS") ); //Third page: CD/DVD Watch WxListenerPanel* cdWatch=new WxListenerPanel(nb,dial, this, mListener->IsPaused()); diff --git a/src2/creaImageIOWxListenerPanel.cpp b/src2/creaImageIOWxListenerPanel.cpp index 86c5e90..b921276 100644 --- a/src2/creaImageIOWxListenerPanel.cpp +++ b/src2/creaImageIOWxListenerPanel.cpp @@ -26,7 +26,7 @@ namespace creaImageIO _T("E:"), _T("F:"), _T("G:") }; - drives=new wxComboBox(this, -1,_T("E:"),wxPoint(100, 10),wxDefaultSize,4,choices); + drives=new wxComboBox(this, -1,crea::std2wx("E:"),wxPoint(100, 10),wxDefaultSize,4,choices); addCheckBox = new wxCheckBox(this, -1, _T("Automatically add images to the database when CD/DVD is mounted?"), wxPoint(5,45) ); addCheckBox->SetValue(true); diff --git a/src2/creaImageIOWxPACSConnectionPanel.cpp b/src2/creaImageIOWxPACSConnectionPanel.cpp new file mode 100644 index 0000000..36b22d4 --- /dev/null +++ b/src2/creaImageIOWxPACSConnectionPanel.cpp @@ -0,0 +1,61 @@ +#include +#include +#include + +namespace creaImageIO +{ + // CTor + WxPACSConnectionPanel::WxPACSConnectionPanel(wxWindow *parent, wxDialog* dial, WxGimmickView* view) + : wxPanel( parent, + -1, wxDefaultPosition, + wxDefaultSize, + wxRESIZE_BORDER | + wxSYSTEM_MENU | + wxCLOSE_BOX | + wxMAXIMIZE_BOX | + wxMINIMIZE_BOX | + wxCAPTION + ), + dialog(dial), + mView(view) + { + GimmickDebugMessage(1,"WxPACSConnectionPanel::WxPACSConnectionPanel" + <GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WxPACSConnectionPanel::OnQueryPACS ); + + Layout(); + } + + /// Destructor + WxPACSConnectionPanel::~WxPACSConnectionPanel() + { + GimmickDebugMessage(1,"WxPACSConnectionPanel::~WxPACSConnectionPanel" + <GetValue())); + //mView->OnListenerCallback(crea::wx2std(drives->GetValue()),addFiles, removeFiles); + //dialog->Destroy(); + } + +//====================================================================== + +//====================================================================== + +} // EO namespace creaImageIO + + diff --git a/src2/creaImageIOWxPACSConnectionPanel.h b/src2/creaImageIOWxPACSConnectionPanel.h new file mode 100644 index 0000000..1f69056 --- /dev/null +++ b/src2/creaImageIOWxPACSConnectionPanel.h @@ -0,0 +1,45 @@ +#ifndef __creaImageIOWxPACSConnectionPanel_h_INCLUDED__ +#define __creaImageIOWxPACSConnectionPanel_h_INCLUDED__ + +#ifdef USE_WXWIDGETS +#include +#include + + +namespace creaImageIO +{ + /** + * \ingroup GUI + */ + //===================================================================== + //===================================================================== + class WxPACSConnectionPanel : public wxPanel + { + public: + WxPACSConnectionPanel(); + WxPACSConnectionPanel(wxWindow *parent, + wxDialog* dial, + WxGimmickView* view); + + ~WxPACSConnectionPanel(); + ///Queries the PACS + void OnQueryPACS(wxCommandEvent& event); + + private : + wxTextCtrl* aeTitle; + wxTextCtrl* pNumber; + wxTextCtrl* address; + wxDialog* dialog; + WxGimmickView* mView; + + + }; // class WxPACSConnectionPanel + //===================================================================== + + +} // EO namespace creaImageIO + + +#endif // USE_WIDGETS +// EOF +#endif \ No newline at end of file diff --git a/src2/data/localdatabase_Descriptor.txt b/src2/data/localdatabase_Descriptor.txt new file mode 100644 index 0000000..4f5603b --- /dev/null +++ b/src2/data/localdatabase_Descriptor.txt @@ -0,0 +1,59 @@ + +Root +O Name Name 4 + +Patient +O NumberOfChildren #Series +D 0x0010 0x0010 4 +D 0x0010 0x0040 +D 0x0010 0x0030 +D 0x0010 0x0020 2 + +Series +O NumberOfChildren #Images +D 0x0008 0x0060 4 +D 0x0008 0x1030 +D 0x0008 0x103E +D 0x0008 0x0080 +D 0x0008 0x0081 +D 0x0008 0x1010 +D 0x0008 0x1048 +D 0x0008 0x1050 +D 0x0018 0x1030 +D 0x0020 0x0010 +D 0x0008 0x0020 +D 0x0008 0x0030 +D 0x0008 0x0050 +D 0x0008 0x0005 +D 0x0008 0x0021 +D 0x0008 0x0031 +D 0x0020 0x000D +D 0x0020 0x000E 2 + +Image +D 0x0020 0x0013 +D 0x0028 0x0010 +D 0x0028 0x0011 +D 0x0028 0x0012 +D 0x0028 0x0002 +D 0x0028 0x0008 +D 0x0028 0x0004 +D 0x0028 0x0103 +D 0x0020 0x0032 +D 0x0020 0x0037 +D 0x0020 0x1041 +D 0x0028 0x0006 +D 0x0028 0x0030 +D 0x0028 0x0100 +D 0x0028 0x0101 +D 0x0008 0x0008 +D 0x0008 0x0023 +D 0x0008 0x0033 +D 0x0020 0x4000 +D 0x0004 0x1500 4 +D 0x0028 0x1052 +D 0x0028 0x1053 +D 0x0050 0x0004 +D 0x0020 0x0052 +D 0x0008 0x0016 +O FullFileName Full_file_name 2 -- 2.45.0