]> Creatis software - creaImageIO.git/blobdiff - src2/creaImageIOWxTreeView.cpp
Added validation function (visible in ok button being enabled or not)
[creaImageIO.git] / src2 / creaImageIOWxTreeView.cpp
index 1b3d20d7d0ff829db0b92e30b4ae12ab1aca9add..bd640783e8a210ffec1bdbec9dfa76f3317fd5fe 100644 (file)
@@ -308,7 +308,7 @@ namespace creaImageIO
 
 
   //================================================================
-  void WxTreeView::OnSelected(wxListEvent& event)
+  void WxTreeView::OnSelectedChanged(wxListEvent& event)
   { 
     GimmickDebugMessage(1,
                        GetTreeHandler()->GetTree().GetLabel()
@@ -454,15 +454,99 @@ namespace creaImageIO
 
   void WxTreeView::ValidateSelectedImages()
   {
-         GimmickMessage(1,
-                       "Hello World Validate"
-                           <<std::endl);
-         /*
-       MyEvent event( MyCommandEvent, 0 );
-       wxString bar( wxT("This is a Foo_DoFirstThing event") );
-       event.SetText( bar );
-       wxPostEvent( this, event );
-       */
+       int level=mLevelList.size();
+       std::vector<tree::Node*> sel=GetSelected(level+1);
+       if(sel.size()>0)
+       {
+               std::vector<tree::Node*>::iterator i;
+               bool valid=true;
+               std::string row;
+               std::string col;
+               std::string plane;
+               
+               //Validation between image sizes
+               for (i=sel.begin(); i!=sel.end() && valid; ++i)
+               {
+                       if(i==sel.begin())
+                       {
+                               row=(*i)->GetAttribute(mLevelList[level-1].key[1]);
+                               col=(*i)->GetAttribute(mLevelList[level-1].key[2]);
+                               plane=(*i)->GetAttribute(mLevelList[level-1].key[3]);
+                       }
+                       else
+                       {
+                               if(((*i)->GetAttribute(mLevelList[level-1].key[1]))!=row ||
+                                       ((*i)->GetAttribute(mLevelList[level-1].key[2]))!=col ||
+                                       ((*i)->GetAttribute(mLevelList[level-1].key[3]))!=plane)
+                                       {
+                                               valid=false;
+                                       }
+                       }
+               }
+
+               GimmickMessage(1,
+                       "State check: Planes:" 
+                       <<plane<<" Cols: "
+                       <<col<<" Rows:"
+                               <<row<<" "
+                               << std::endl);
+               //Dimention validation
+               //Compatibility with maximum 
+               if(valid)
+               {       
+                       int rows;
+                       int cols;
+                       int planes;
+                       std::string s;
+                       std::istringstream t(s);
+                       s=row;
+                       t >> rows;
+                       if(row==""){rows=1;}
+                       s=col;
+                       t >> cols;
+                       if(col==""){cols=1;}
+                       s=plane;
+                       t >> planes;
+                       if(plane==""){planes=1;}
+
+                       int dim = 0;
+                       if (planes>1) dim=3;
+                       else if (cols>1) dim=2;
+                       else if (rows>1) dim=1;
+                   
+                       if (dim == 0) 
+                       {
+                       GimmickMessage(1,
+                               "Unknown image dimension : cannot select !" 
+                               <<dim<<" "
+                               <<plane<<" "
+                               <<col<<" "
+                               <<row<<" "
+                               << std::endl);
+                               valid= false;
+                       }
+                       else if (dim>GetMaxDimension())
+                       {
+                               GimmickMessage(1,"Selecting "<<dim<<"D images is not allowed !" 
+                               << std::endl);
+                               valid= false;
+                       }
+                       if ( dim == GetMaxDimension() )
+                       {
+                               GimmickMessage(1,"Cannot add this image to selection : would result in a "<<dim+1<<"D image !" << std::endl);
+                               valid= false;
+                       }
+               }
+                 
+               //Send an event telling wether the selection is valid or not
+               wxCommandEvent event( 0, GetId() );
+               event.SetEventObject( this );
+               if(valid)
+               {event.SetInt(0);}
+               else
+               {event.SetInt(1);}
+               GetEventHandler()->ProcessEvent( event );
+         }
        
   }
 
@@ -625,9 +709,10 @@ BEGIN_EVENT_TABLE(MyListCtrl, wxListCtrl)
     EVT_LIST_SET_INFO(LIST_CTRL, MyListCtrl::OnSetInfo)
 #endif
   */
-    EVT_LIST_ITEM_SELECTED(-1, WxTreeView::OnSelected)
-  /*
-    EVT_LIST_ITEM_DESELECTED(LIST_CTRL, MyListCtrl::OnDeselected)
+    EVT_LIST_ITEM_SELECTED(-1, WxTreeView::OnSelectedChanged)
+  
+    EVT_LIST_ITEM_DESELECTED(-1, WxTreeView::OnSelectedChanged)
+       /*
     EVT_LIST_KEY_DOWN(LIST_CTRL, MyListCtrl::OnListKeyDown)
     EVT_LIST_ITEM_ACTIVATED(LIST_CTRL, MyListCtrl::OnActivated)
     EVT_LIST_ITEM_FOCUSED(LIST_CTRL, MyListCtrl::OnFocused)