]> Creatis software - creaImageIO.git/commitdiff
Added field edition capability.
authorcaballero <caballero>
Wed, 20 May 2009 15:00:31 +0000 (15:00 +0000)
committercaballero <caballero>
Wed, 20 May 2009 15:00:31 +0000 (15:00 +0000)
14 files changed:
src2/CMakeLists.txt
src2/creaImageIOGimmick.cpp
src2/creaImageIOGimmick.h
src2/creaImageIOGimmickView.h
src2/creaImageIOTreeAttributeDescriptor.h
src2/creaImageIOTreeDescriptor.cpp
src2/creaImageIOTreeHandlerImageAdder.cpp
src2/creaImageIOTreeHandlerImageAdder.h
src2/creaImageIOWxEditFieldsPanel.cpp [new file with mode: 0644]
src2/creaImageIOWxEditFieldsPanel.h [new file with mode: 0644]
src2/creaImageIOWxGimmickView.cpp
src2/creaImageIOWxGimmickView.h
src2/creaImageIOWxTreeView.cpp
src2/creaImageIOWxTreeView.h

index 68ff6fe8dc94019298e762503ef500a09c16783f..0ced6db0bcec3473e6f5d3c1c84e8aab0103e318 100644 (file)
@@ -50,6 +50,7 @@ SET( SRCS
   creaImageIOWxGimmickTools
   creaImageIOWxCustomizeConfigPanel
   creaImageIOWxListenerPanel
+  creaImageIOWxEditFieldsPanel
 
   # 
   BlockScopeWxApp
index 3aae8a855e242c7fbc8a7f4b04bdc5531bc9df58..e54d1bf1e44597fcd5b9d88daa179e4f4694598b 100644 (file)
@@ -391,6 +391,17 @@ namespace creaImageIO
          mImageAdder.DeleteDriveFromOtherDB(drive);
   }
 
+  //========================================================================
+  void Gimmick::EditField(tree::Node* node, const std::string& d, const std::string& name, const std::string& key, const std::string& val)
+  {
+         TreeHandler * handler=GetTreeHandler(d);
+         mImageAdder.SetCurrentDatabase(d);
+         mImageAdder.SetTreeHandler(handler);
+         mImageAdder.EditField(node,name,key,val);
+  }
+  //========================================================================
+
+
   /////////////////////////////////////////////////////////////////////////
   // add DB from Settings file                                                                              //
   // @param : -                                                                                                                         //
index 09423fe0c00a7e8a057170e635b2358749f5cae1..b8e2ee8a8b37999d2df85ff8b7a5337ea6e87b71 100644 (file)
@@ -136,9 +136,12 @@ namespace creaImageIO
        ///Updates the settings file
        void UpdateSetting(const std::string& name, const std::string& value);
 
-       // add DB from Settings file
+       /// add DB from Settings file
     void addDBSettings();
 
+       ///Edits the field described by the name and key provided with the value given
+       void EditField(tree::Node* node, const std::string& d, const std::string& name, const std::string& key, const std::string& val);
+
     /// 
     const std::string& GetHomeDirectory();
     const std::string& GetUserSettingsDirectory();
index 4621dbd6a3b727b2c53b08dc1cd78115ae521d5c..bc160c5bf853962664755009974ec6b0466b227e 100644 (file)
@@ -86,6 +86,10 @@ namespace creaImageIO
          ///Copies selected files
          virtual void CopyFiles(const std::vector<std::string>& filenames)
          { GimmickError("INTERNAL ERROR : CopyFiles not implemented"); }
+
+         ///Edits the fields of a given node
+         virtual void CreateEditFieldsDialog(tree::Node* node, std::vector<std::string> names, std::vector<std::string> keys)
+         { GimmickError("INTERNAL ERROR : EditFields not implemented"); }
       
       ///Validates the dimension compliance of the images with the maximum and minimum given, and between their sizes
       bool ValidateSelected (tree::Node* sel, int min_dim, int max_dim);
index ad4d7bfe601fe38922f3fb3b10fae6e97b482cb4..68f0da965af186c68791c86404a7b812ae6fcf65 100644 (file)
@@ -24,6 +24,8 @@ namespace creaImageIO
       static const unsigned int IDENTIFIER;
       /// The attribute enters in label constitution (for printing)
       static const unsigned int LABEL;
+          /// The attribute can be edited
+      static const unsigned int EDITABLE;
 
          /// Types
       /// The attribute is of numeric type
index 0d772866bcbecf28076556d780ccf446c6d79300..c1dca8e78b1d5ee575aee2bc12d6d00614a9d866 100644 (file)
@@ -19,6 +19,8 @@ namespace creaImageIO
     const unsigned int AttributeDescriptor::PRIVATE = 1;
     /// The attribute enters in unique identifier constitution 
     const unsigned int AttributeDescriptor::IDENTIFIER = 2;
+       /// The attribute can be edited
+       const unsigned int AttributeDescriptor::EDITABLE = 3;
     const unsigned int AttributeDescriptor::LABEL = 4;
     //==================================================================
 
index 471c785317df2e0e0c4289d6dcdcedff6b50a5dd..16008be93bc989f90da80cc57ad922f10727fb02 100644 (file)
@@ -577,5 +577,12 @@ namespace creaImageIO
          mSynchronizer->RemoveEntries("IGNORED_FILES", "PATH", "LIKE", drive+"%");
   }
 
+  //=======================================================================
+  void TreeHandlerImageAdder::EditField(tree::Node* node, const std::string& name, const std::string& key, const std::string& val)
+  {
+         node->SetAttribute(key,val);
+         mTreeHandler->SetAttribute(node,key,val);
+  }
+
  
 }
index 53cff0b7b325d8ec8ac4fe1dc688014e7b4bc651..2fe9efd993e00563c461bca9ad2a56e981b2e70e 100644 (file)
@@ -140,6 +140,9 @@ namespace creaImageIO
        void DeleteDriveFromMainDB(const std::string& drive);
        ///Deletes the drive with the given name (use for maintenance and timestamp databases)
        void DeleteDriveFromOtherDB(const std::string& drive);
+       ///Edits the given field and sets the new parameters
+       void EditField(tree::Node* node, const std::string& name, const std::string& key, const std::string& val);
+  
   
  
     //====================================================================
diff --git a/src2/creaImageIOWxEditFieldsPanel.cpp b/src2/creaImageIOWxEditFieldsPanel.cpp
new file mode 100644 (file)
index 0000000..aa48137
--- /dev/null
@@ -0,0 +1,85 @@
+#include <creaImageIOWxEditFieldsPanel.h>
+#include <creaImageIOSystem.h>
+#include <wx/arrstr.h>
+//using namespace tree;
+namespace creaImageIO
+{
+       const int  ID_COMBO             = 140;
+  // CTor
+       WxEditFieldsPanel::WxEditFieldsPanel(wxWindow *parent, wxDialog* dial, WxGimmickView* view, tree::Node* nod, 
+               const std::vector<std::string> name,
+               const std::vector<std::string> key)
+ :   wxPanel( parent, 
+                 -1, wxDefaultPosition, 
+                 wxDefaultSize,
+                 wxRESIZE_BORDER | 
+             wxSYSTEM_MENU  |
+                 wxCLOSE_BOX |
+                 wxMAXIMIZE_BOX | 
+                 wxMINIMIZE_BOX | 
+                 wxCAPTION  
+              ),       
+                  dialog(dial),
+                  node (nod), 
+                  names(name), 
+                  keys(key),
+                  mView(view)
+  {
+    GimmickDebugMessage(1,"WxCustomizeConfigPanel::WxCustomizeConfigPanel"
+                       <<std::endl);
+       wxStaticText * cp=new wxStaticText(this,-1,_T(" Attribute to change: "), wxPoint(5,10));
+       wxArrayString as;
+       std::vector<std::string>::const_iterator it;
+       for(it=names.begin();it!=names.end();++it)
+       {
+               as.Add(*it);
+       }
+       attributes=new wxComboBox(this, ID_COMBO,names.front(),wxPoint(110, 10),wxDefaultSize,as);
+       std::string val=node->GetAttribute(keys[0]);
+       if(val.compare("")==0){val="?";}
+
+       wxStaticText * av=new wxStaticText(this,-1,_T(" Actual Value: "), wxPoint(5,40));
+       actualVal=new wxStaticText(this,-1,_T(val), wxPoint(110,40));
+
+       wxStaticText * nv=new wxStaticText(this,-1,_T(" New Value: "), wxPoint(5,70));
+       newVal=new wxTextCtrl(this, wxID_ANY, _T(val), wxPoint(110,70), wxSize(220,20));
+
+       wxButton *save = new wxButton(this,wxID_ANY,_T("Save Changes"), wxPoint(5,100) );
+       Connect( save->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WxEditFieldsPanel::OnEdit ); 
+      
+    Layout(); 
+  }
+
+  /// Destructor
+  WxEditFieldsPanel::~WxEditFieldsPanel()
+  {
+    GimmickDebugMessage(1,"WxEditFieldsPanel::~WxEditFieldsPanel"
+                       <<std::endl);
+  }
+
+  void WxEditFieldsPanel::OnEdit(wxCommandEvent& event)
+  {
+         std::string val=crea::wx2std(newVal->GetValue());
+         mView->OnFieldsEdited(node,names[attributes->GetSelection()],keys[attributes->GetSelection()],val);
+         dialog->Destroy();
+  }
+
+  void WxEditFieldsPanel::OnComboChange(wxCommandEvent& event)
+  {
+         std::string val=node->GetAttribute(keys[attributes->GetSelection()]);
+         if(val.compare("")==0){val="?";}
+         actualVal->SetLabel(crea::std2wx(val));
+         newVal->SetValue(crea::std2wx(val));
+  }
+  
+//======================================================================
+BEGIN_EVENT_TABLE(WxEditFieldsPanel, wxPanel)
+EVT_COMBOBOX  (ID_COMBO,WxEditFieldsPanel::OnComboChange)
+END_EVENT_TABLE()
+//====================================================================== 
+
+} // EO namespace creaImageIO
+
+
+
+
diff --git a/src2/creaImageIOWxEditFieldsPanel.h b/src2/creaImageIOWxEditFieldsPanel.h
new file mode 100644 (file)
index 0000000..eca344d
--- /dev/null
@@ -0,0 +1,54 @@
+#ifndef __creaImageIOWxEditFieldsPanel_h_INCLUDED__
+#define __creaImageIOWxEditFieldsPanel_h_INCLUDED__
+
+#ifdef USE_WXWIDGETS
+#include <creaWx.h>
+#include <creaImageIOWxGimmickView.h>
+
+
+namespace creaImageIO
+{
+  /**
+   * \ingroup GUI
+   */
+  //=====================================================================
+ //=====================================================================
+  class WxEditFieldsPanel : public wxPanel
+  {
+  public:
+    WxEditFieldsPanel();    
+       WxEditFieldsPanel(wxWindow *parent, 
+               wxDialog* dial,
+               WxGimmickView* view, 
+               tree::Node* nod, 
+               const std::vector<std::string> name,
+               const std::vector<std::string> key);
+    
+    ~WxEditFieldsPanel();
+       ///Saves the configuration
+        void OnEdit(wxCommandEvent& event);
+        void OnComboChange(wxCommandEvent& event);
+
+  private :
+       tree::Node* node; 
+       std::vector<std::string> names;
+       std::vector<std::string> keys;
+       wxDialog* dialog;
+       WxGimmickView* mView;
+       wxComboBox* attributes;
+       wxStaticText * actualVal;
+       wxTextCtrl* newVal;
+
+       DECLARE_EVENT_TABLE()
+
+
+  }; // class WxEditFieldsPanel
+  //=====================================================================
+
+  
+} // EO namespace creaImageIO
+
+
+#endif // USE_WIDGETS
+// EOF
+#endif  
\ No newline at end of file
index 53b0342e919eea1b0b934a4d2ec0d5398f3d6253..a900d0d5be2e1bf5ba3be86313d1a1314b74962d 100644 (file)
@@ -3,6 +3,7 @@
 #include <creaImageIOSystem.h>
 #include <creaImageIOWxCustomizeConfigPanel.h>
 #include <creaImageIOWxListenerPanel.h>
+#include <creaImageIOWxEditFieldsPanel.h>
 
 using namespace crea;
 // Icons
@@ -878,6 +879,24 @@ namespace creaImageIO
          mListener->Pause();
   }
 
+  //========================================================================
+  void WxGimmickView::CreateEditFieldsDialog(tree::Node* node, std::vector<std::string> names, std::vector<std::string> keys)
+  {
+         wxDialog* dial= new wxDialog (this,-1,_T("Edit Fields for node "+node->GetLabel()),wxDefaultPosition, wxSize(350,155));
+    wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
+    WxEditFieldsPanel* ef = new WxEditFieldsPanel(dial, dial, this, node, names, keys);
+
+    siz->Add( ef,1,wxGROW  ,0); 
+    dial->SetSizer(siz);
+    dial->ShowModal();  
+  }
+
+  //========================================================================
+  void WxGimmickView::OnFieldsEdited(tree::Node* node, const std::string& name, const std::string& key, const std::string& val)
+  {
+         mGimmick->EditField(node, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())), name, key, val);
+         UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
+  }
 
   //=================================================
   /// AddProgress Gimmick callback
index d6df0f61a79aadff926d594ad016cb558e4e7d59..f4dcb2da5407de4bc881c906b5c3af3985fb9b2a 100644 (file)
@@ -89,6 +89,10 @@ namespace creaImageIO
 
        ///Stops the listening thread on the CD/DVD drive
        void StopListeningThread();
+
+       ///Called upon when a field has been edited
+       void OnFieldsEdited(tree::Node* node, const std::string& name, const std::string& key, const std::string& val);
+  
   
     
   protected:
@@ -154,12 +158,15 @@ namespace creaImageIO
     /// Called upon to refresh the viewer once there are no actions to be done
     void OnInternalIdle();
 
-       // callback to add a database
+       /// callback to add a database
        void OnAddDB(wxCommandEvent& event);
     
-       //Create a DB from an Attributes Descriptor files 
+       ///Create a DB from an Attributes Descriptor files 
        void OnCreateDB(wxCommandEvent& event);
 
+       ///Edits the fields of a given node
+       void CreateEditFieldsDialog(tree::Node* node, std::vector<std::string> names, std::vector<std::string> keys);
     /// Progress dialog
     wxProgressDialog* mProgressDialog;
     ///The selection's maximum dimension
index 58ddc631421d889b5a5c0a89466056af3a4007a9..ef99f2848427de7bb6c76584908b494b6f556644 100644 (file)
@@ -695,9 +695,8 @@ namespace creaImageIO
       }
          long* ptr=0;
          int flag;
-         long itemId=GetCtrl(level)->HitTest(wxPoint(clientpt.x,clientpt.y-8),flag,ptr);
-         tree::Node* node=((ItemData*)GetCtrl(level)->GetItemData(itemId))->node;
-         std::cout<<node->GetLabel()<<std::endl;
+         mLastRightLevel=level;
+         mLastRightSelected=GetCtrl(level)->HitTest(wxPoint(0,clientpt.y-8),flag,ptr);
     PopupMenu(menuItem, clientpt);
     
   }
@@ -837,9 +836,24 @@ namespace creaImageIO
    //================================================================
   void WxTreeView::OnEditField(wxCommandEvent& event)
   {
-    
-    
-    
+       if(mLastRightSelected!=-1)
+       {
+    tree::Node* node=((ItemData*)GetCtrl(mLastRightLevel)->GetItemData(mLastRightSelected))->node;
+       tree::LevelDescriptor::AttributeDescriptorListType::const_iterator a;
+       std::vector<std::string> names;
+       std::vector<std::string> keys;
+       for (a  = GetTreeHandler()->GetTree().GetAttributeDescriptorList(mLastRightLevel+1).begin();
+            a != GetTreeHandler()->GetTree().GetAttributeDescriptorList(mLastRightLevel+1).end();
+            ++a)
+       {
+               if(a->GetFlags()==creaImageIO::tree::AttributeDescriptor::EDITABLE)
+           {
+                       names.push_back(a->GetName());
+                       keys.push_back(a->GetKey());
+               }
+       }
+       GetGimmickView()->CreateEditFieldsDialog(node,names,keys);
+       }
   }
   //================================================================
 
index 465d704bb3fe42aaa2189eecd50f5cb089fb448a..d6290c8828c8707233f5f7824d3d57bfc21e7994 100644 (file)
@@ -132,8 +132,14 @@ namespace creaImageIO
       
       /// Currently Selected Column
       int mColumnSelected;
-      ///The last selected item on the list
+      ///The last selected item on the list (left click)
       long mLastSelected;
+
+         ///The last selected item on the list (right click)
+         long mLastRightSelected;
+
+         ///The last selected level (by right click)
+         int mLastRightLevel;
       ///The color map
       typedef std::map<tree::Node*,wxColour> ColorMap;
       typedef std::pair<tree::Node*,wxColour> NodeColorPair;
@@ -153,6 +159,7 @@ namespace creaImageIO
          int mAnonymizingID;
          int mLocalCopyID;
          int mEditFieldID;
+         
       // If set to true then OnSelectedChanged returns immediately.
       // Used to do avoid useless process during multiple selections 
       // or sorting