]> Creatis software - creaImageIO.git/blobdiff - src2/creaImageIOWxTreeView.cpp
Clean Up Code and Added min dimension check
[creaImageIO.git] / src2 / creaImageIOWxTreeView.cpp
index bd640783e8a210ffec1bdbec9dfa76f3317fd5fe..829549a2212feca51e2c8847897be80b15bde201 100644 (file)
@@ -456,10 +456,10 @@ namespace creaImageIO
   {
        int level=mLevelList.size();
        std::vector<tree::Node*> sel=GetSelected(level+1);
+       bool valid=true;
        if(sel.size()>0)
        {
                std::vector<tree::Node*>::iterator i;
-               bool valid=true;
                std::string row;
                std::string col;
                std::string plane;
@@ -492,52 +492,65 @@ namespace creaImageIO
                                << 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;
+                       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;
+                               }
+                               if ( dim < GetMinDimension() && sel.size()<2 )
+                               {
+                                       GimmickMessage(1,"Cannot build the selection as it would result in a "
+                                                                       <<dim<<"D image, and the minimum is"<<GetMinDimension()<<"D!" << std::endl);
+                                       valid= false;
+                               }
                        }
-               }
-                 
+         }
+       else
+       {
+               GimmickMessage(1,"Cannot have 0 images selected"<< std::endl);
+               valid=false;
+       }
+       
                //Send an event telling wether the selection is valid or not
                wxCommandEvent event( 0, GetId() );
                event.SetEventObject( this );
@@ -546,7 +559,7 @@ namespace creaImageIO
                else
                {event.SetInt(1);}
                GetEventHandler()->ProcessEvent( event );
-         }
+         
        
   }