]> Creatis software - creaImageIO.git/commitdiff
Added the PACS Connection Panel, a basic socket connection class and on .Gimmick...
authorcaballero <caballero>
Wed, 3 Jun 2009 15:40:30 +0000 (15:40 +0000)
committercaballero <caballero>
Wed, 3 Jun 2009 15:40:30 +0000 (15:40 +0000)
src2/CMakeLists.txt
src2/creaImageIOGimmick.cpp
src2/creaImageIOGimmick.h
src2/creaImageIOPACSConnection.cpp [new file with mode: 0644]
src2/creaImageIOPACSConnection.h [new file with mode: 0644]
src2/creaImageIOWxGimmickView.cpp
src2/creaImageIOWxListenerPanel.cpp
src2/creaImageIOWxPACSConnectionPanel.cpp [new file with mode: 0644]
src2/creaImageIOWxPACSConnectionPanel.h [new file with mode: 0644]
src2/data/localdatabase_Descriptor.txt [new file with mode: 0644]

index 951ccc7671bb71d64e8e7ce9ee8154ef08909996..c775592cc31c649ae977d5d94bac78b28bbe1fc4 100644 (file)
@@ -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
+  )
index e54d1bf1e44597fcd5b9d88daa179e4f4694598b..af7f7010c1dc9276d32b0de3647f10995ab52d8a 100644 (file)
@@ -4,6 +4,10 @@
 #include <boost/filesystem.hpp>
 #include <boost/algorithm/string.hpp>
 
+#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 '"<<GetUserSettingsDirectory()<<"'");
          }
       }
+
+       std::string setDir=GetUserSettingsDirectory();
+       boost::algorithm::replace_all( setDir,
+                                      VALID_FILE_SEPARATOR , 
+                                      INVALID_FILE_SEPARATOR);
+       setDir+="localdatabase_Descriptor.txt";
+       if(!boost::filesystem::is_regular_file(setDir))
+       {
+               char name[PATH_MAX];
+               int err = GetBinaryDirectory(name, PATH_MAX);
+               std::string path=name;
+               path=path.substr(0,path.size()-1);
+               path=path.substr(0,path.find_last_of("/"));
+               path+="/data/localdatabase_Descriptor.txt";
+               boost::algorithm::replace_all( path,
+                                               VALID_FILE_SEPARATOR , 
+                                               INVALID_FILE_SEPARATOR);
+               boost::filesystem::copy_file(path,setDir);
+       }
   }
   //========================================================================
 
index b8e2ee8a8b37999d2df85ff8b7a5337ea6e87b71..448fc9ba9fd79c27f82ed89e3b2bcd5d7dd2e23a 100644 (file)
@@ -145,6 +145,7 @@ namespace creaImageIO
     /// 
     const std::string& GetHomeDirectory();
     const std::string& GetUserSettingsDirectory();
+       int GetBinaryDirectory(char *pname, size_t pathsize);
     void CreateUserSettingsDirectory();
     const std::string& GetLocalDatabasePath();
        const std::string& GetTimestampDatabasePath();
diff --git a/src2/creaImageIOPACSConnection.cpp b/src2/creaImageIOPACSConnection.cpp
new file mode 100644 (file)
index 0000000..4d66c3c
--- /dev/null
@@ -0,0 +1,42 @@
+#include <creaImageIOPACSConnection.h>
+#include <cstdlib>
+#include <cstring>
+#include <iostream>
+#include <boost/asio.hpp>
+
+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 (file)
index 0000000..659be58
--- /dev/null
@@ -0,0 +1,16 @@
+#ifndef __creaImageIOPACSConnection_h_INCLUDED__
+#define __creaImageIOPACSConnection_h_INCLUDED__
+#include <string>
+
+namespace creaImageIO
+{
+class PACSConnection
+  {
+  public:
+    /// Ctor
+         PACSConnection(std::string command);
+  };// EO PACSConnection
+} // EO namespace creaImageIO
+
+// EOF
+#endif
\ No newline at end of file
index d6ddcdca3c63546ef537e9952cb46a975b484f47..a77f9a7fe9de9bdc1726f0db2b1d01a3b22868ee 100644 (file)
@@ -5,6 +5,7 @@
 #include <creaImageIOWxListenerPanel.h>
 #include <creaImageIOWxEditFieldsPanel.h>
 #include <creaImageIOWxAttributeSelectionPanel.h>
+#include <creaImageIOWxPACSConnectionPanel.h>
 
 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());
index 86c5e9006527c5465c1a23053c5efb8379ba11a0..b9212766370a67ad563239f7634ba6493c54f875 100644 (file)
@@ -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 (file)
index 0000000..36b22d4
--- /dev/null
@@ -0,0 +1,61 @@
+#include <creaImageIOWxPACSConnectionPanel.h>
+#include <creaImageIOPACSConnection.h>
+#include <creaImageIOSystem.h>
+
+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"
+                       <<std::endl);
+       wxStaticText * dicId=new wxStaticText(this,-1,_T(" DICOM Identification: "), wxPoint(5,5));
+       wxStaticText * aet=new wxStaticText(this,-1,_T(" AETitle: "), wxPoint(5,25));
+       aeTitle=new wxTextCtrl(this, wxID_ANY, _T("MyAeTitle"), wxPoint(75,25), wxSize(220,20));
+
+       wxStaticText * pn=new wxStaticText(this,-1,_T(" Port Number: "), wxPoint(5,53));
+       pNumber=new wxTextCtrl(this, wxID_ANY, _T("3306"), wxPoint(75,50), wxSize(220,20));
+       wxStaticText * adv1=new wxStaticText(this,-1,_T(" (1 - 131072) "), wxPoint(300,53));
+
+       wxStaticText * ad=new wxStaticText(this,-1,_T(" Address: "), wxPoint(5,80));
+       address=new wxTextCtrl(this, wxID_ANY, _T("localhost"), wxPoint(75,75), wxSize(220,20));
+       
+       wxButton *query = new wxButton(this,wxID_ANY,_T("Query PACS Server"), wxPoint(5,110) );
+       Connect( query->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WxPACSConnectionPanel::OnQueryPACS ); 
+   
+    Layout(); 
+  }
+
+  /// Destructor
+  WxPACSConnectionPanel::~WxPACSConnectionPanel()
+  {
+    GimmickDebugMessage(1,"WxPACSConnectionPanel::~WxPACSConnectionPanel"
+                       <<std::endl);
+  }
+
+  void WxPACSConnectionPanel::OnQueryPACS(wxCommandEvent& event)
+  {
+         PACSConnection* pc=new PACSConnection(crea::wx2std(aeTitle->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 (file)
index 0000000..1f69056
--- /dev/null
@@ -0,0 +1,45 @@
+#ifndef __creaImageIOWxPACSConnectionPanel_h_INCLUDED__
+#define __creaImageIOWxPACSConnectionPanel_h_INCLUDED__
+
+#ifdef USE_WXWIDGETS
+#include <creaWx.h>
+#include <creaImageIOWxGimmickView.h>
+
+
+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 (file)
index 0000000..4f5603b
--- /dev/null
@@ -0,0 +1,59 @@
+<level>
+Root
+O Name Name 4
+<level>
+Patient
+O NumberOfChildren #Series
+D 0x0010 0x0010 4
+D 0x0010 0x0040
+D 0x0010 0x0030
+D 0x0010 0x0020 2
+<level>
+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
+<level>
+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