Index: sansview/perspectives/fitting/fitpage.py
===================================================================
--- sansview/perspectives/fitting/fitpage.py	(revision 948add7b3e543b2f6928425d6b889b3328df699a)
+++ sansview/perspectives/fitting/fitpage.py	(revision 6f73a0814a0b253c6d3e57a483cb1817b0dfa6ff)
@@ -140,13 +140,9 @@
         # flag to check if the user has selected a new model in the combox box
         self.model_hasChanged=False
-        #flag to check if the user has selected a new data
-        self.data_hasChanged=False
+        
         #dictionary of model name and model class
         self.model_list_box={}
-        # Data1D to make a deep comparison between 2 Data1D for checking data
-        #change
-        from sans.guitools.plottables import Data1D
-        self.prevData = Data1D(x=[], y=[],dx=None, dy=None)
-        self.prevData.name= None
+        #  comparison between 2 group_id for checking data changes
+        self.prev_group_id= None
         
         self.data=None
@@ -191,22 +187,5 @@
                 self.GrandParent.GetSizer().Layout()
                 
-                
-    def copy_data(self,dataset):
-        """
-             copy a select data in the panel to compared with the previous selected data
-             @param dataset: the data selected
-             @note : everything a data is selected, the panel check is it is different 
-             from the previous selected data
-        """
-        try:
-            if dataset !=None:
-                self.prevData.x= copy.deepcopy(dataset.x)
-                self.prevData.y= copy.deepcopy(dataset.y)
-                self.prevData.name=dataset.name
-                if dataset.dy==None:
-                    self.prevData.dy= copy.deepcopy(dataset.dy)
-        except:
-            raise ValueError, " copy_data: cannot copy data" 
-        
+  
         
     def onClose(self,event):
@@ -224,12 +203,14 @@
                 qmin = float(self.xmin.GetValue())
                 qmax = float(self.xmax.GetValue())
-                x,y,dy = [numpy.asarray(v) for v in (self.data.x,self.data.y,self.data.dy)]
-                if qmin==None and qmax==None: 
-                    fx =numpy.asarray([self.model.run(v) for v in x])
-                    res=(y - fx)/dy
-                else:
-                    idx = (x>= qmin) & (x <=qmax)
-                    fx = numpy.asarray([self.model.run(item)for item in x[idx ]])
-                    res= (y[idx] - fx)/dy[idx]  
+                #x,y,dy = [numpy.asarray(v) for v in (self.data.x,self.data.y,self.data.dy)]
+                #if qmin==None and qmax==None: 
+                #    fx =numpy.asarray([self.model.run(v) for v in x])
+                #    res=(y - fx)/dy
+                #else:
+                #    idx = (x>= qmin) & (x <=qmax)
+                #    fx = numpy.asarray([self.model.run(item)for item in x[idx ]])
+                #    res= (y[idx] - fx)/dy[idx]  
+                self.data.setFitRange(qmin,qmax)
+                res=self.data.residuals(self.model.runXY)
                 sum=0
                 for item in res:
@@ -304,8 +285,9 @@
             flag=self.checkFitRange()
             if flag==True and self.model!=None:
-                 self.manager.redraw_model(float(self.xmin.GetValue())\
+                print"fit page",self.xmin.GetValue(),self.xmax.GetValue()
+                self.manager.redraw_model(float(self.xmin.GetValue())\
                                                ,float(self.xmax.GetValue()))
-           
         except:
+
             wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\
                             "Drawing  Error:wrong value entered %s"% sys.exc_value))
@@ -322,5 +304,5 @@
         valueMax = self.xmax.GetValue()
         # Check for possible values entered
-        
+        print "fitpage: checkfitrange:",valueMin,valueMax
         try:
             if (float(valueMax)> float(valueMin)):
@@ -340,35 +322,5 @@
         return flag
     
-    def check_data_change(self,dataset):
-        """
-             check if data selected has changed and set flag self.data_hasChanged
-             has true is changed or false is unchanged
-             @param dataset: data selected
-        """
-        self.data_hasChanged=False
-        if self.prevData.__class__ !=dataset.__class__:
-            self.data_hasChanged=True
-            
-        elif self.prevData.name != dataset.name:
-            self.data_hasChanged=True
-            
-        elif len(self.prevData.x) != len(self.prevData.y):
-            self.data_hasChanged=True
-            
-        else:
-            for i in range(len(dataset.x)):
-                if self.prevData.x[i] !=dataset.x[i]:
-                    self.data_hasChanged=True
-                    break
-                
-                if self.prevData.y[i] !=dataset.y[i]:
-                    self.data_hasChanged=True
-                    break
-                
-                if dataset.dy !=None:
-                    if self.prevData.dy[i] !=dataset.dy[i]:
-                        self.data_hasChanged=True
-                        break
-                    
+   
                     
     def set_data_name(self,dataset):
@@ -379,23 +331,26 @@
             for xmin and xmax range sizer
         """
-        self.check_data_change(dataset)
-        if self.data_hasChanged==True:
+        
+        if self.prev_group_id !=dataset.data.group_id:
             self._DataNameEnter()
-        self.data=dataset
-        self.copy_data(dataset)
+        self.data = dataset
+        self.prev_group_id=dataset.data.group_id
         #Displaying Data information
-        self.DataSource.SetValue(str(dataset.name))
-        self._xaxis,self._xunit=dataset.get_xaxis()
+        self.DataSource.SetValue(str(dataset.data.name))
+        self._xaxis,self._xunit=dataset.data.get_xaxis()
         self.text4_3.SetLabel(self._xaxis+"["+self._xunit+"]")
         self.text4_1.Show()
         self.text4_2.Show()
         self.text4_3.Show()
-        
-        self.xmin.SetValue(format_number(min(dataset.x)))
-        self.xmin.Show()
-
-        self.xmax.SetValue(format_number(max(dataset.x)))
-        self.xmax.Show()
-        
+        if not dataset.data.__class__.__name__=='Data2D':
+            self.xmin.SetValue(format_number(min(dataset.data.x)))
+            self.xmin.Show()
+            self.xmax.SetValue(format_number(max(dataset.data.x)))
+            self.xmax.Show()
+        else:
+            self.xmin.SetValue(format_number(numpy.min(dataset.data.image)))
+            self.xmin.Show()
+            self.xmax.SetValue(format_number(numpy.max(dataset.data.image)))
+            self.xmax.Show()
         if ((len(self.param_toFit ) >0) and self.DataSource.GetValue()and \
             self.modelbox.GetValue() and (self.model_hasChanged ==False)):
Index: sansview/perspectives/fitting/fitting.py
===================================================================
--- sansview/perspectives/fitting/fitting.py	(revision 57f3320feeb526cb0b8bff80aa998e193c8911e5)
+++ sansview/perspectives/fitting/fitting.py	(revision 6f73a0814a0b253c6d3e57a483cb1817b0dfa6ff)
@@ -4,8 +4,10 @@
 
 from copy import deepcopy 
-from sans.guitools.plottables import Data1D, Theory1D
-from sans.guitools.PlotPanel import PlotPanel
+#from sans.guitools.plottables import Data1D, Theory1D
+#from sans.guitools.PlotPanel import PlotPanel
+from danse.common.plottools.plottables import Data1D, Theory1D, Data2D
+from danse.common.plottools.PlotPanel import PlotPanel
 from sans.guicomm.events import NewPlotEvent, StatusEvent  
-from sans.fit.AbstractFitEngine import Model,Data
+from sans.fit.AbstractFitEngine import Model,Data,FitData1D,FitData2D
 from fitproblem import FitProblem
 from fitpanel import FitPanel
@@ -82,6 +84,9 @@
         self.graph=graph
         for item in graph.plottables:
-            if item.name==graph.selected_plottable and item.__class__.__name__ is not "Theory1D":
-                return [["Select Data", "Dialog with fitting parameters ", self._onSelect]] 
+            if item.__class__.__name__ is "Data2D":
+                return [["Fit Data2D", "Dialog with fitting parameters ", self._onSelect]] 
+            else:
+                if item.name==graph.selected_plottable and item.__class__.__name__ is not "Theory1D":
+                    return [["Select Data", "Dialog with fitting parameters ", self._onSelect]] 
         return []   
 
@@ -138,5 +143,5 @@
         self.panel = event.GetEventObject()
         for item in self.panel.graph.plottables:
-            if item.name == self.panel.graph.selected_plottable:
+            if item.name == self.panel.graph.selected_plottable or item.__class__.__name__ is "Data2D":
                 #find a name for the page created for notebook
                 try:
@@ -147,15 +152,20 @@
                     page = self.fit_panel.add_fit_page(name)
                     # add data associated to the page created
-                    page.set_data_name(item)
-                    #create a fitproblem storing all link to data,model,page creation
-                    self.page_finder[page]= FitProblem()
-                    #data_for_park= Data(sans_data=item)
-                    #datap = PlottableData(data=data_for_park,data1d=item)
-                    #self.page_finder[page].add_data(datap)
-                    self.page_finder[page].add_data(item)
+                    if item.__class__.__name__=='Data1D':
+                        new_item=FitData1D(item)
+                    else:
+                        new_item=FitData2D(item)
+                    if page !=None:    
+                        page.set_data_name(new_item)
+                        #create a fitproblem storing all link to data,model,page creation
+                        self.page_finder[page]= FitProblem()
+                        #data_for_park= Data(sans_data=item)
+                        #datap = PlottableData(data=data_for_park,data1d=item)
+                        #self.page_finder[page].add_data(datap)
+                        self.page_finder[page].add_data(new_item)
                 except:
-                    #raise
-                    wx.PostEvent(self.parent, StatusEvent(status="Fitting error: \
-                    data already Selected "))
+                    raise
+                    wx.PostEvent(self.parent, StatusEvent(status="Creating Fit page: %s"\
+                    %sys.exc_value))
     def schedule_for_fit(self,value=0,fitproblem =None):  
         """
@@ -224,5 +234,5 @@
             for page, value in self.page_finder.iteritems():
                 if page==cpage :
-                    data = value.get_data()
+                    #fitdata = value.get_data()
                     list = value.get_model()
                     model= list[0]
@@ -258,5 +268,5 @@
             for page, value in self.page_finder.iteritems():
                 if value.get_scheduled()==1:
-                    data = value.get_data()
+                    #fitdata = value.get_data()
                     list = value.get_model()
                     model= list[0]
@@ -305,5 +315,5 @@
         for page, value in self.page_finder.iteritems():
             if  value.get_scheduled() ==1 :
-                data = value.get_data()
+                fitdata = value.get_data()
                 list=value.get_model()
                 model=list[0]
@@ -319,5 +329,5 @@
                     #Do the single fit
                     self.fitter.set_model(Model(model), self.id, pars) 
-                    self.fitter.set_data(Data(sans_data=data),self.id,qmin,qmax)
+                    self.fitter.set_data(fitdata,self.id,qmin,qmax)
                     self.fitter.select_problem_for_fit(Uid=self.id,value=value.get_scheduled())
                     page_fitted=page
@@ -336,4 +346,5 @@
             self._single_fit_completed(result,pars,page_fitted,qmin,qmax)
         except:
+            raise
             wx.PostEvent(self.parent, StatusEvent(status="Single Fit error: %s" % sys.exc_value))
             return
@@ -360,5 +371,5 @@
             try:
                 if value.get_scheduled()==1:
-                    data = value.get_data()
+                    fitdata = value.get_data()
                     list = value.get_model()
                     model= list[0]
@@ -389,5 +400,5 @@
                             
                     self.fitter.set_model(new_model, self.id, pars) 
-                    self.fitter.set_data(Data(sans_data=data),self.id,qmin,qmax)
+                    self.fitter.set_data(fitdata,self.id,qmin,qmax)
                     self.fitter.select_problem_for_fit(Uid=self.id,value=value.get_scheduled())
                     self.id += 1 
@@ -433,6 +444,6 @@
             current_pg.set_panel(model)
             try:
-                data=self.page_finder[current_pg].get_data()
-                M_name="M"+str(self.index_model)+"= "+name+"("+data.group_id+")"
+                fitdata=self.page_finder[current_pg].get_data()
+                M_name="M"+str(self.index_model)+"= "+name+"("+fitdata.data.group_id+")"
             except:
                 raise 
@@ -468,8 +479,10 @@
                 if  page==currpage :  
                     break 
-            data=self.page_finder[page].get_data()
+            fitdata=self.page_finder[page].get_data()
             list=self.page_finder[page].get_model()
             model=list[0]
-            if data!=None:
+            data=fitdata.data
+            
+            if data!=None and data.__class__.__name__ != 'Data2D':
                 theory = Theory1D(x=[], y=[])
                 theory.name = "Model"
@@ -498,5 +511,4 @@
                             tempx = data.x[i]
                             tempy = model.run(tempx)
-                            
                             theory.x.append(tempx) 
                             theory.y.append(tempy)
@@ -509,10 +521,30 @@
                     theory.x.append(tempx)
                     theory.y.append(tempy)
-                    wx.PostEvent(self.parent, NewPlotEvent(plot=theory, title="Analytical model"))
+                   
                 except:
                     wx.PostEvent(self.parent, StatusEvent(status="fitting \
                         skipping point x %g %s" %(qmax, sys.exc_value)))
-               
-            
+            else:
+                theory=Data2D(data.image, data.err_image)
+                theory.x_bins= data.x_bins
+                theory.y_bins= data.y_bins
+                tempy=[]
+                for i in range(len(data.x_bins)):
+                    theory.image= model.runXY([data.x_bins[i],data.y_bins[i]])
+                    #print "fitting : plot_helper:", theory.image
+                #print data.image
+                #theory.image=model.runXY(data.image)
+                theory.image=model.run(data.image)
+                print "fitting : plot_helper:",theory.image
+                theory.zmin= data.zmin
+                theory.zmax= data.zmax
+                theory.xmin= data.xmin
+                theory.xmax= data.xmax
+                theory.ymin= data.ymin
+                theory.ymax= data.ymax
+                
+        wx.PostEvent(self.parent, NewPlotEvent(plot=theory, title="Analytical model"))
+        
+        
     def _on_model_menu(self, evt):
         """
