Index: sansview/perspectives/fitting/basepage.py
===================================================================
--- sansview/perspectives/fitting/basepage.py	(revision dad49a0eda2b68ae0a70d5552131de1779c5a7aa)
+++ sansview/perspectives/fitting/basepage.py	(revision 71f03737f44ec12a86e74f08ab8a1dc96640bc08)
@@ -75,5 +75,7 @@
         
         self.state= PageState(parent= self.parent,model=self.model, data=self.data)
-        
+        ## save customized array
+        self.values=[]
+        self.weights=[]
         ## retrieve saved state
         self.number_saved_state= 0
@@ -195,6 +197,5 @@
         self.disable_disp = wx.RadioButton(self, -1, 'Off', (10, 10), style=wx.RB_GROUP)
         self.enable_disp = wx.RadioButton(self, -1, 'On', (10, 30))
-        ## saving the state of enable dispersity button
-        self.state.enable_disp= self.enable_disp.GetValue()
+       
         
         self.Bind(wx.EVT_RADIOBUTTON, self._set_dipers_Param, id=self.disable_disp.GetId())
@@ -251,5 +252,8 @@
         self.SetScrollbars(20,20,200,100)
         self.Refresh()
-        
+        ## saving the state of enable dispersity button
+        self.state.enable_disp= self.enable_disp.GetValue()
+        self.state.disable_disp= self.disable_disp.GetValue()
+    
     
     def select_disp_angle(self, event): 
@@ -258,4 +262,6 @@
             @param event: check box event
         """
+        self.values=[]
+        self.weights=[]
         # Go through the list of dispersion check boxes to identify which one has changed 
         for p in self.disp_cb_dict:
@@ -263,5 +269,5 @@
             if event.GetEventObject() == self.disp_cb_dict[p]:              
 
-                self.state.disp_cb_dict[p]=  self.disp_cb_dict[p].GetValue()
+                
                 if self.disp_cb_dict[p].GetValue() == True:
                     # The user wants this parameter to be averaged. 
@@ -278,5 +284,5 @@
                         pass 
                     try:
-                        values,weights = self.read_file(path)
+                        self.values,self.weights = self.read_file(path)
                     except:
                         msg="Could not read input file"
@@ -286,5 +292,6 @@
                     # If any of the two arrays is empty, notify the user that we won't
                     # proceed 
-                    if values is None or weights is None:
+                    if self.values is None or self.weights is None or \
+                         self.values ==[] or self.weights ==[]:
                         wx.PostEvent(self.parent.parent, StatusEvent(status=\
                             "The loaded %s distrubtion is corrupted or empty" % p))
@@ -298,5 +305,6 @@
                     from sans.models.dispersion_models import ArrayDispersion
                     disp_model = ArrayDispersion()
-                    disp_model.set_weights(values, weights)
+                    disp_model.set_weights(self.values, self.weights)
+                   
                     # Store the object to make it persist outside the scope of this method
                     #TODO: refactor model to clean this up?
@@ -305,6 +313,6 @@
                     self.state.values=[]
                     self.state.weights=[]
-                    self.state.values = values
-                    self.state.weights = weights
+                    self.state.values = self.values
+                    self.state.weights = self.weights
                     # Set the new model as the dispersion object for the selected parameter
                     self.model.set_dispersion(p, disp_model)
@@ -312,7 +320,9 @@
                     # it's not lost when we use the model within another thread.
                     #TODO: total hack - fix this
+                    self.state.model= self.model.clone()
                     if not hasattr(self.model, "_persistency_dict"):
                         self.model._persistency_dict = {}
-                    self.model._persistency_dict[p] = [values, weights]
+                    self.model._persistency_dict[p] = [self.values, self.weights]
+                    self.state.model._persistency_dict[p] = [self.values, self.weights]
                 else:
                     # The parameter was un-selected. Go back to Gaussian model (with 0 pts)
@@ -320,6 +330,9 @@
               
                 ## Redraw the model
+                print "select angle => draw"
                 self._draw_model()
                 ## post state to fit panel
+                
+                self.state.disp_cb_dict[p]=  self.disp_cb_dict[p].GetValue()
                 event = PageInfoEvent(page = self)
                 wx.PostEvent(self.parent, event)
@@ -346,7 +359,5 @@
             save history of the data and model
         """
-        # Skipping the save state functionality for release 0.9.0
-        return
-    
+        
         if self.model==None:
             return 
@@ -357,4 +368,8 @@
         
         self.state.model = self.model.clone()
+        if not hasattr(self.model, "_persistency_dict"):
+                            self.model._persistency_dict = {}
+        self.state.model._persistency_dict= copy.deepcopy(self.model._persistency_dict)
+                        
         new_state = self.state.clone()
         new_state.enable2D = copy.deepcopy(self.enable2D)
@@ -377,4 +392,5 @@
         self.slicerpop.Append(id,name,str(msg))
         wx.EVT_MENU(self, id, self.onResetModel)
+        
         
     def onSetFocus(self, evt):
@@ -447,4 +463,5 @@
             return the current state of the page
         """
+       
         return self.state.clone()
     
@@ -455,8 +472,12 @@
         """
         if self.model!= None:
+            self.disp_list= self.model.getDispParamList()
+            self.state.disp_list= copy.deepcopy(self.disp_list)
             self.state.model = self.model.clone()
         self.state.save_data(self.data)
-        
+        self.state.disp_list = self.disp_list
         self.state.enable2D = copy.deepcopy(self.enable2D)
+        self.state.values= copy.deepcopy(self.values)
+        self.state.weights = copy.deepcopy( self.weights)
         try:
             n = self.disp_box.GetCurrentSelection()
@@ -493,5 +514,6 @@
                 for k , v in self._disp_obj_dict.iteritems():
                     self.state._disp_obj_dict[k]= v
-           
+            self.state.values = copy.deepcopy(self.values)
+            self.state.weights = copy.deepcopy(self.weights)
         self._save_plotting_range()
         
@@ -519,18 +541,20 @@
         """
             Use page_state and change the state of existing page
-        """
-        self.state = state.clone()
+            @precondition: the page is already drawn or created
+            @postcondition: the state of the underlying data change as well as the
+            state of the graphic interface
+        """
+        ## set the value of the current state to the state given as parameter
+        self.state = state.clone() 
+        
         self.model= self.state.model
         self.data = self.state.data
         self.smearer= self.state.smearer
-        self.state.enable_smearer=state.enable_smearer
-       
-        ##model parameter values restore
+        self.enable2D= state.enable2D
+        
+        ##draw sizer containing model parameters value for the current model
         self._set_model_sizer_selection( self.model )
         self.set_model_param_sizer(self.model)
-       
-        self.enable2D= state.enable2D
-        self.state.enable2D= state.enable2D
-        
+        ## enable the view 2d button if this is a modelpage type
         if hasattr(self,"model_view"):
             if not self.enable2D:
@@ -538,17 +562,24 @@
             else:
                 self.model_view.Disable()
-            
+        ## set the select all check box to the a given state
         if hasattr(self, "cb1"):   
-            self.cb1.SetValue(self.state.cb1)
+            self.cb1.SetValue(state.cb1)
+        ## 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.parameters,state.parameters)    
+            
         ## display dispersion info layer
         self.enable_disp.SetValue(self.state.enable_disp)
         self.disable_disp.SetValue(self.state.disable_disp)
+        
         if hasattr(self, "disp_box"):
             self.disp_box.SetSelection(self.state.disp_box)  
-          
-            self._set_dipers_Param(event=None)
-          
             n = self.disp_box.GetCurrentSelection()
             dispersity= self.disp_box.GetClientData(n)
+           
+            self._set_dipers_Param(event=None)
             name= dispersity.__name__
             if name == "GaussianDispersion":
@@ -556,35 +587,43 @@
                 self.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) 
                 self.state.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) 
-                    
+               
                 self._disp_obj_dict={}
                 for k , v in self.state._disp_obj_dict.iteritems():
                     self._disp_obj_dict[k]=v
-            
+          
             if  name=="ArrayDispersion":
-               
+                self.model_disp.Show(True)
+                self.disp_box.Show(True)
+                self._set_sizer_arraydispersion()
+                
                 for k,v in state.disp_cb_dict.iteritems():
                     self.disp_cb_dict[k].SetValue(v) 
+                    self.state.disp_cb_dict[k]=v 
+                    if self.disp_cb_dict[k].GetValue():
+                        # Create the dispersion objects
+                        from sans.models.dispersion_models import ArrayDispersion
+                        disp_model = ArrayDispersion()
+                        
+                        disp_model.set_weights(state.values, state.weights)
+                       
+                        # Store the object to make it persist outside the scope of this method
+                        #TODO: refactor model to clean this up?
+                        self._disp_obj_dict[k] = disp_model
+                        self.state._disp_obj_dict [k]= disp_model
+                        self.state.values=[]
+                        self.state.weights=[]
+                        self.state.values = self.values
+                        self.state.weights = self.weights
+                        self.values=[]
+                        self.weights = []
+                        self.values= state.values
+                        self.weights = state.weights
                     
-                self._disp_obj_dict={}    
-                for k , v in state._disp_obj_dict.iteritems():
-                    # Create the dispersion objects
-                    from sans.models.dispersion_models import ArrayDispersion
-                    disp_model = ArrayDispersion()
-                    self.state.values = copy.deepcopy(state.values)
-                    self.state.weights = copy.deepcopy(state.weights)
-                    
-                    disp_model.set_weights(self.state.values, self.state.weights)
-                    
-                    self._disp_obj_dict[k] = disp_model
-                    self.state._disp_obj_dict[k]= disp_model
-                    self.state.values=[]
-                    self.state.weights=[]
-                    
-                    if not hasattr(self.model, "_persistency_dict"):
-                        self.model._persistency_dict = {}
-                    self.model._persistency_dict[k] = [self.state.values, self.state.weights]
-                    # Set the new model as the dispersion object for the selected parameter
-                    self.model.set_dispersion(k, disp_model)
-                   
+                        # Set the new model as the dispersion object for the selected parameter
+                        if not hasattr(self.model, "_persistency_dict"):
+                            self.model._persistency_dict = {}
+                        self.model._persistency_dict[k] = [state.values, state.weights]
+                        self.model.set_dispersion(k, disp_model)
+                        
         ##plotting range restore    
         self._reset_plotting_range()
@@ -592,22 +631,20 @@
         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.enable_smearer.SetValue(self.state.enable_smearer)
+            self.disable_smearer.SetValue(self.state.disable_smearer)
             self.compute_chisqr(smearer= self.smearer)  
             
-        ## reset state of checkbox,textcrtl  and 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.parameters,state.parameters)
+        ## 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()
+      
         ## reset context menu items
         self._reset_context_menu()
-       
-         
+        
+
         
     def _selectDlg(self):
@@ -636,4 +673,5 @@
             wx.EVT_MENU(self, id, self.onResetModel)
     
+    
     def _reset_plotting_range(self):
         """
@@ -668,6 +706,8 @@
         """
         if self.model !=None:
+            
             ## save current state
             self.save_current_state()
+            
             # Flag to register when a parameter has changed.
             is_modified = False
@@ -703,4 +743,5 @@
             ## if any value is modify draw model with new value
             if is_modified:
+                print "is_modified--->",is_modified
                 self._draw_model() 
                 self.save_current_state()
@@ -919,4 +960,5 @@
                 if self.enable_smearer.GetValue():
                     temp_smear= self.smearer
+            print "self.model.dispersion",self.model.dispersion
             self.manager.draw_model(self.model, data=self.data,
                                     smearer= temp_smear,
@@ -924,4 +966,5 @@
                                     qstep= float(self.num_points),
                                     enable2D=self.enable2D) 
+        
         
     def _set_model_sizer(self, sizer, title="", object=None):
@@ -970,6 +1013,5 @@
         wx.EVT_COMBOBOX(self.structurebox,-1, self._on_select_model)
         
-        
-        
+    
         ## fill combox box
         if len(self.model_list_box)>0:
@@ -1074,11 +1116,5 @@
                     name = model.name
                 combobox.Append(name,models)
-        #try:
-
-            #combobox.SetSelection(0)
-            
-        #except:
-            #pass
-    
+     
         return 0
    
@@ -1116,4 +1152,7 @@
         ## post state to fit panel
         self.state.model =self.model
+        self.disp_list =self.model.getDispParamList()
+        self.state.disp_list = self.disp_list
+        
         ## post state to fit panel
         event = PageInfoEvent(page = self)
@@ -1185,5 +1224,4 @@
                     item[4].Hide()
                     
-           
                 value= float(item[2].GetValue())
                 
@@ -1211,5 +1249,4 @@
             self.disp_box.Hide()
             self.sizer4_4.Clear(True)
-            self._reset_dispersity()
             ## post state to fit panel
             self.save_current_state()
@@ -1220,4 +1257,5 @@
             self.disp_box.Show(True)
             ## layout for model containing no dispersity parameters
+            self.disp_list= self.model.getDispParamList()
             if len(self.disp_list)==0:
                 self._layout_sizer_noDipers()  
@@ -1228,11 +1266,15 @@
             self.model_disp.Hide()
             self.disp_box.Hide()
+            self.disp_box.SetSelection(0) 
             self.sizer4_4.Clear(True)
-            self._reset_dispersity()
-            
-      
+            #self._reset_dispersity()
+            
         ## post state to fit panel
         self.save_current_state()
-            
+        self.sizer4_4.Layout()
+        self.sizer4.Layout()
+        self.Layout()
+        self.Refresh()
+        self.SetScrollbars(20,20,200,100)       
           
             
@@ -1273,5 +1315,8 @@
         self.fixed_param=[]
         self.orientation_params_disp=[]
-       
+        self.values=[]
+        self.weights=[]
+       
+        
         from sans.models.dispersion_models import GaussianDispersion
         if len(self.disp_cb_dict)==0:
@@ -1284,4 +1329,5 @@
             return 
         
+        
         for p in self.disp_cb_dict:
             # The parameter was un-selected. Go back to Gaussian model (with 0 pts)
@@ -1293,4 +1339,5 @@
             self.model.set_dispersion(p, disp_model)
             # Redraw the model
+            print "reset dispersity=> draw"
             self._draw_model()
             
@@ -1315,5 +1362,5 @@
             self._set_sizer_gaussian()
             
-        if  name=="ArrayDispersion":
+        if name == "ArrayDispersion":
             self._set_sizer_arraydispersion()
             
@@ -1343,4 +1390,5 @@
                 if item in self.param_toFit:
                     self.param_toFit.remove(item)
+                    
         self.fittable_param=[]
         self.fixed_param=[]
@@ -1368,5 +1416,5 @@
         self.sizer4.Layout()
         self.SetScrollbars(20,20,200,100)
-      
+       
 
     def _set_range_sizer(self, title, object1=None,object=None):
@@ -1379,6 +1427,4 @@
         #--------------------------------------------------------------
         self.qmin    = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20))
-        #For qmin and qmax, do not use format_number.(If do, qmin and max could be different from what is in the data.)
-        #self.qmin.SetValue(format_number(self.qmin_x))
         self.qmin.SetValue(str(self.qmin_x))
         self.qmin.SetToolTipString("Minimun value of Q in linear scale.")
@@ -1388,6 +1434,4 @@
      
         self.qmax    = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20))
-        #For qmin and qmax, do not use format_number.(If do, qmin and max could be different from what is in the data.)
-        #self.qmax.SetValue(format_number(self.qmax_x))
         self.qmax.SetValue(str(self.qmax_x))
         self.qmax.SetToolTipString("Maximum value of Q in linear scale.")
Index: sansview/perspectives/fitting/fitpage.py
===================================================================
--- sansview/perspectives/fitting/fitpage.py	(revision 848a2ef13f7ff02ac2ba77a50890ad96b5d4eef2)
+++ sansview/perspectives/fitting/fitpage.py	(revision 71f03737f44ec12a86e74f08ab8a1dc96640bc08)
@@ -452,5 +452,7 @@
                                                      ,None,None, None, None,None])
    
-        self.state.disp_cb_dict = copy.deepcopy(self.disp_cb_dict)                         
+        self.state.disp_cb_dict = copy.deepcopy(self.disp_cb_dict)      
+        self.state.model = self.model.clone()  
+                         
         wx.PostEvent(self.parent, StatusEvent(status=\
                         " Selected Distribution: Gaussian"))   
@@ -460,5 +462,7 @@
         self.sizer4_4.Layout()
         self.sizer4.Layout()
+        self.Layout()
         self.SetScrollbars(20,20,200,100)
+        self.Refresh()
      
         
Index: sansview/perspectives/fitting/fitpanel.py
===================================================================
--- sansview/perspectives/fitting/fitpanel.py	(revision df4c3ad47513b369c38dc71d3803ca149ed2a529)
+++ sansview/perspectives/fitting/fitpanel.py	(revision 71f03737f44ec12a86e74f08ab8a1dc96640bc08)
@@ -339,13 +339,11 @@
 
                 memento= self.fit_page_name[page_title][0]
+                
                 panel.reset_page(memento)
         else:
             self.fit_page_name[page_title]=[]
             self.fit_page_name[page_title].insert(0,panel.createMemento())
-         
-        # We just created a model page, we are ready to plot the model
-        #self.manager.draw_model(model, model.name)
-        #FOR PLUGIN  for some reason model.name is = BASEcomponent
-        self.manager.draw_model(model, qmin=qmin, qmax=qmax)
+            ## We just created a model page, we are ready to plot the model
+            self.manager.draw_model(model, qmin=qmin, qmax=qmax)
   
   
Index: sansview/perspectives/fitting/modelpage.py
===================================================================
--- sansview/perspectives/fitting/modelpage.py	(revision dad49a0eda2b68ae0a70d5552131de1779c5a7aa)
+++ sansview/perspectives/fitting/modelpage.py	(revision 71f03737f44ec12a86e74f08ab8a1dc96640bc08)
@@ -284,5 +284,6 @@
             
         msg = " Selected Distribution: Gaussian"        
-        wx.PostEvent(self.parent.parent, StatusEvent( status= msg ))   
+        wx.PostEvent(self.parent.parent, StatusEvent( status= msg )) 
+        self.state.disp_cb_dict = copy.deepcopy(self.disp_cb_dict)   
         ix =0
         iy +=1 
@@ -334,4 +335,6 @@
         """
         self.model = model
+        if self.model !=None:
+            self.disp_list= self.model.getDispParamList()
         self.set_model_param_sizer(self.model)
         ## keep the sizer view consistent with the model menu selecting
@@ -562,5 +565,5 @@
             else:
                 self.text2_4.Hide()
-        self.state.disp_cb_dict = copy.deepcopy(self.disp_cb_dict) 
+      
         boxsizer1.Add(sizer)
         self.sizer3.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10)
Index: sansview/perspectives/fitting/pagestate.py
===================================================================
--- sansview/perspectives/fitting/pagestate.py	(revision dad49a0eda2b68ae0a70d5552131de1779c5a7aa)
+++ sansview/perspectives/fitting/pagestate.py	(revision 71f03737f44ec12a86e74f08ab8a1dc96640bc08)
@@ -25,4 +25,5 @@
         if not hasattr(self.model, "_persistency_dict"):
             self.model._persistency_dict = {}
+        self.model._persistency_dict = copy.deepcopy(model._persistency_dict)
         #fit page manager 
         self.manager = None
@@ -50,4 +51,6 @@
         #list of dispersion paramaters
         self.disp_list =[]
+        if self.model !=None:
+            self.disp_list = self.model.getDispParamList()
         self._disp_obj_dict={}
         self.disp_cb_dict={}
@@ -98,6 +101,8 @@
         obj.data = copy.deepcopy(self.data)
         obj.model_list_box = copy.deepcopy(self.model_list_box)
+      
         obj.manager = self.manager
         obj.event_owner = self.event_owner
+        obj.disp_list = copy.deepcopy(self.disp_list)
         
         obj.enable2D = copy.deepcopy(self.enable2D)
@@ -110,5 +115,5 @@
         obj.enable_disp = copy.deepcopy(self.enable_disp)
         obj.disable_disp = copy.deepcopy(self.disable_disp)
-        if len(self.model._persistency_dict)>0:
+        if self.model !=None and len(self.model._persistency_dict)>0:
             for k, v in self.model._persistency_dict.iteritems():
                 obj.model._persistency_dict[k] = copy.deepcopy(v)
@@ -137,4 +142,5 @@
         return obj
 
+
 class PageMemento(object):
     """
