Index: sansview/perspectives/fitting/basepage.py
===================================================================
--- sansview/perspectives/fitting/basepage.py	(revision b2d98260cb7c4d561f45d7b4b5a619d1ceba43a1)
+++ sansview/perspectives/fitting/basepage.py	(revision e88ebfd2e12449882f12bc250cc13a70851e559f)
@@ -946,5 +946,108 @@
             return  True
         
-           
+    def set_model_state(self, state):
+        """
+        reset page given a model state
+        """
+        self.disp_cb_dict = state.disp_cb_dict
+        self.disp_list = state.disp_list
+      
+        ## set the state of the radio box
+        self.shape_rbutton.SetValue(state.shape_rbutton )
+        self.shape_indep_rbutton.SetValue(state.shape_indep_rbutton)
+        self.struct_rbutton.SetValue(state.struct_rbutton)
+        self.plugin_rbutton.SetValue(state.plugin_rbutton)
+        
+        ## fill model combobox
+        self._show_combox_helper()
+        #select the current model
+        self.formfactorbox.Select(int(state.formfactorcombobox))
+        self.structurebox.SetSelection(state.structurecombobox )
+        if state.multi_factor != None:
+            self.multifactorbox.SetSelection(state.multi_factor)
+            
+         ## reset state of checkbox,textcrtl  and  regular parameters value
+        self._reset_parameters_state(self.orientation_params_disp,
+                                     state.orientation_params_disp)
+        self._reset_parameters_state(self.orientation_params,
+                                     state.orientation_params)
+        self._reset_parameters_state(self.str_parameters,
+                                     state.str_parameters)
+        self._reset_parameters_state(self.parameters,state.parameters)
+         ## display dispersion info layer        
+        self.enable_disp.SetValue(state.enable_disp)
+        self.disable_disp.SetValue(state.disable_disp)
+        
+        if hasattr(self, "disp_box"):
+            
+            self.disp_box.SetSelection(state.disp_box) 
+            n= self.disp_box.GetCurrentSelection()
+            dispersity= self.disp_box.GetClientData(n)
+            name = dispersity.__name__     
+
+            self._set_dipers_Param(event=None)
+       
+            if name == "ArrayDispersion":
+                
+                for item in self.disp_cb_dict.keys():
+                    
+                    if hasattr(self.disp_cb_dict[item], "SetValue") :
+                        self.disp_cb_dict[item].SetValue(\
+                                                    state.disp_cb_dict[item])
+                        # Create the dispersion objects
+                        from sans.models.dispersion_models import ArrayDispersion
+                        disp_model = ArrayDispersion()
+                        if hasattr(state,"values")and\
+                                 self.disp_cb_dict[item].GetValue() == True:
+                            if len(state.values)>0:
+                                self.values=state.values
+                                self.weights=state.weights
+                                disp_model.set_weights(self.values,
+                                                        state.weights)
+                            else:
+                                self._reset_dispersity()
+                        
+                        self._disp_obj_dict[item] = disp_model
+                        # Set the new model as the dispersion object 
+                        #for the selected parameter
+                        self.model.set_dispersion(item, disp_model)
+                    
+                        self.model._persistency_dict[item] = \
+                                                [state.values, state.weights]
+                    
+            else:
+                keys = self.model.getParamList()
+                for item in keys:
+                    if item in self.disp_list and \
+                        not self.model.details.has_key(item):
+                        self.model.details[item] = ["", None, None]
+                for k,v in self.state.disp_cb_dict.iteritems():
+                    self.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) 
+                    self.state.disp_cb_dict = copy.deepcopy(state.disp_cb_dict)
+         ## smearing info  restore
+        if hasattr(self, "enable_smearer"):
+            ## set smearing value whether or not the data 
+            #contain the smearing info
+            self.enable_smearer.SetValue(state.enable_smearer)
+            self.disable_smearer.SetValue(state.disable_smearer)
+            self.onSmear(event=None)           
+        self.pinhole_smearer.SetValue(state.pinhole_smearer)
+        self.slit_smearer.SetValue(state.slit_smearer)
+        ## we have two more options for smearing
+        if self.pinhole_smearer.GetValue(): self.onPinholeSmear(event=None)
+        elif self.slit_smearer.GetValue(): self.onSlitSmear(event=None)
+       
+        ## reset state of checkbox,textcrtl  and dispersity parameters value
+        self._reset_parameters_state(self.fittable_param,state.fittable_param)
+        self._reset_parameters_state(self.fixed_param,state.fixed_param)
+        
+        ## draw the model with previous parameters value
+        self._onparamEnter_helper()
+        self.select_param(event=None) 
+        #Save state_fit
+        self.save_current_state_fit()
+        self._lay_out()
+        self.Refresh()
+        
     def reset_page_helper(self, state):
         """
Index: sansview/perspectives/fitting/fitpanel.py
===================================================================
--- sansview/perspectives/fitting/fitpanel.py	(revision b2d98260cb7c4d561f45d7b4b5a619d1ceba43a1)
+++ sansview/perspectives/fitting/fitpanel.py	(revision e88ebfd2e12449882f12bc250cc13a70851e559f)
@@ -101,4 +101,13 @@
             return selected_page.get_data()
     
+    def set_model_state(state):
+        """
+        receive a state to reset the model in the current page
+        """
+        pos = self.GetSelection()
+        if pos != -1:
+            selected_page = self.GetPage(pos)
+            selected_page.set_model_state(state)
+            
     def get_state(self):
         """
Index: sansview/perspectives/fitting/fitproblem.py
===================================================================
--- sansview/perspectives/fitting/fitproblem.py	(revision 6bbeacd466719479cfdf24b6e7c1c5f52c93e03d)
+++ sansview/perspectives/fitting/fitproblem.py	(revision e88ebfd2e12449882f12bc250cc13a70851e559f)
@@ -1,2 +1,3 @@
+import copy 
 
 class FitProblem:
@@ -32,5 +33,5 @@
         copy fitproblem
         """
-        import copy 
+        
         obj          = FitProblem()
         model= None
@@ -110,7 +111,6 @@
         
         """
-        self.theory_data = data
-        
-
+        self.theory_data = copy.deepcopy(data)
+      
     def get_theory_data(self):
         """
Index: sansview/perspectives/fitting/fitting.py
===================================================================
--- sansview/perspectives/fitting/fitting.py	(revision b2d98260cb7c4d561f45d7b4b5a619d1ceba43a1)
+++ sansview/perspectives/fitting/fitting.py	(revision e88ebfd2e12449882f12bc250cc13a70851e559f)
@@ -17,10 +17,7 @@
 import logging
 import numpy
-#import math
 import string
 import time
-#import thread
 from copy import deepcopy
-
 import models
 import fitpage
@@ -36,5 +33,4 @@
 from sans.guiframe.gui_style import GUIFRAME_ID
 from sans.guiframe.plugin_base import PluginBase 
-
 
 from .console import ConsoleUpdate
@@ -256,5 +252,5 @@
         return True
     
-    def set_data(self, data_list=None, theory_list=None):
+    def set_data(self, data_list=None):
         """
         receive a list of data to fit
@@ -270,8 +266,25 @@
         else:
             selected_data_list = data_list
-        for data in selected_data_list:
-            self.add_fit_page(data=data)
-            wx.PostEvent(self.parent, NewPlotEvent(plot=data, 
-                                                   title=str(data.title)))
+        try:
+            for data in selected_data_list:
+                self.add_fit_page(data=data)
+                wx.PostEvent(self.parent, NewPlotEvent(plot=data, 
+                                                       title=str(data.title)))
+        except:
+            msg = "Fitting Set_data: " + str(sys.exc_value)
+            wx.PostEvent(self.parent, StatusEvent(status=msg, info="error"))
+            
+    def set_theory(self,  theory_list=None):
+        """
+        """
+        #set the model state for a given theory_state:
+        for item in theory_list:
+            try:
+                _, theory_state = item
+                self.fit_panel.set_model_state(theory_state)
+            except:
+                msg = "Fitting: cannot deal with the theory received"
+                logging.error("set_theory " + msg + "\n" + str(sys.exc_value))
+                wx.PostEvent(self.parent, StatusEvent(status=msg, info="error"))
             
     def set_state(self, state=None, datainfo=None, format=None):
@@ -593,5 +606,5 @@
         if theory:
             id = data.id 
-        group_id = data.group_id[len(data.group_id)-1]
+        group_id = data.group_id
         wx.PostEvent(self.parent, NewPlotEvent(id=id,
                                                    group_id=group_id,
@@ -643,14 +656,10 @@
         #append Data1D to the panel containing its theory
         #if theory already plotted
-        
         if page.id in self.page_finder:
             theory_data = self.page_finder[page.id].get_theory_data()
-            
             if issubclass(data.__class__, Data2D):
-                data.group_id.append(wx.NewId())
+                data.group_id = wx.NewId()
                 if theory_data is not None:
                     group_id = str(page.id) + " Model1D"
-                    if group_id in theory_data.group_id:
-                        theory_data.group_id.remove(group_id)
                     wx.PostEvent(self.parent, 
                              NewPlotEvent(group_id=group_id,
@@ -660,13 +669,10 @@
                 if theory_data is not None:
                     group_id = str(page.id) + " Model2D"
-                    if group_id in theory_data.group_id:
-                        theory_data.group_id.remove(group_id)
-                    data_group_id = theory_data.group_id[len(theory_data.group_id)-1]
-                    if data_group_id not in data.group_id:
-                        data.group_id.append(data_group_id)
+                    data.group_id = theory_data.group_id
                     wx.PostEvent(self.parent, 
                              NewPlotEvent(group_id=group_id,
                                                action="delete"))
-                    self.parent.update_data(prev_data=theory_data, new_data=data)       
+                    self.parent.update_data(prev_data=theory_data, new_data=data)   
+              
         self.store_data(id=page.id, data=data, caption=page.window_name)
         if self.sim_page is not None:
@@ -725,5 +731,5 @@
                 if name !="Model":
                     data= fitproblem.get_fit_data()
-                    page = self.fit_panel.add_fit_page(data= data,reset=True)
+                    page = self.fit_panel.add_fit_page(data=data, reset=True)
                     if fitproblem != None:
                         self.page_finder[id] = fitproblem
@@ -1103,10 +1109,7 @@
         theory.ymin = ymin 
         theory.ymax = ymax 
-        group_id = str(id) + " Model2D"
-        if group_id not in theory.group_id:
-            theory.group_id.append(group_id)
+        theory.group_id = str(id) + " Model2D"
         theory.id = str(id) + " Model2D"
   
-                
     def _complete1D(self, x,y, id, elapsed,index,model,
                     toggle_mode_on=False,state=None, data=None):
@@ -1126,12 +1129,8 @@
                     theory_data = self.page_finder[id].get_theory_data()
                     if theory_data is not None:
-                        group_id = theory_data.group_id[len(theory_data.group_id)-1]
-                        if group_id not in data.group_id:
-                            data.group_id.append(group_id)
+                       data.group_id = theory_data.group_id
                 #data is plotted before the theory, then take its group_id
                 #assign to the new theory
-                group_id = data.group_id[len(data.group_id)-1]
-                if group_id not in new_plot.group_id:
-                    new_plot.group_id.append(group_id)
+                new_plot.group_id = data.group_id
                
             else:
@@ -1140,7 +1139,5 @@
                 new_plot.title = "Analytical model 1D "
                 #find a group id to plot theory without data
-                group_id =  str(id) + " Model1D"  
-                if group_id not in new_plot.group_id:
-                    new_plot.group_id.append(group_id)
+                new_plot.group_id =  str(id) + " Model1D"  
                 new_plot.is_data = False 
             new_plot.id =  str(id) + " Model1D"  
@@ -1161,8 +1158,10 @@
                              NewPlotEvent(group_id=str(id) + " Model2D",
                                                action="Hide"))
-                
+           
             self.page_finder[id].set_theory_data(new_plot)
+            theory_data = self.page_finder[id].get_theory_data()
             if data is None:
-                theory_data = self.page_finder[id].get_theory_data()
+                name = "Data generates by Fitting "
+                theory_data.name = name
                 self.parent.add_data_helper({theory_data.id:theory_data})
                 data_id = theory_data.id
@@ -1170,6 +1169,7 @@
                 data_id = data.id
            
-            self.parent.append_theory(data_id=data_id, 
-                                          theory=new_plot, state=state)
+            self.parent.update_theory(data_id=data_id, 
+                                       theory=theory_data,
+                                       state=state)     
             current_pg = self.fit_panel.get_page_by_id(id)
             title = new_plot.title
@@ -1218,8 +1218,5 @@
         else:
             new_plot.id = str(id) + " Model2D"
-            group_id = str(id) + " Model2D"
-            if group_id not in new_plot.group_id:
-                new_plot.group_id.append(group_id)
-         
+            new_plot.group_id = str(id) + " Model2D"
             new_plot.x_bins = data.x_bins
             new_plot.y_bins = data.y_bins
@@ -1247,15 +1244,17 @@
                              NewPlotEvent(group_id=str(id) + " Model1D",
                                                action="Hide"))
-        self.page_finder[id].set_theory_data(theory_data)
-        
+        
+        self.page_finder[id].set_theory_data(new_plot)
+        theory_data = self.page_finder[id].get_theory_data()
         if data is None:
-            theory_data = self.page_finder[id].get_theory_data()
+            name = "Data generates by Fitting "
+            theory_data.name = name
             self.parent.add_data_helper({theory_data.id:theory_data})
             data_id = theory_data.id
         else:
             data_id = data.id
-        
-        self.parent.append_theory(data_id=data_id, 
-                                          theory=new_plot, state=state)
+        self.parent.update_theory(data_id=data_id, 
+                                       theory=theory_data,
+                                       state=state)  
         current_pg = self.fit_panel.get_page_by_id(id)
         title = new_plot.title
