1 | |
---|
2 | |
---|
3 | import copy |
---|
4 | |
---|
5 | class PageState(object): |
---|
6 | """ |
---|
7 | Contains info to reconstruct a page |
---|
8 | """ |
---|
9 | def __init__(self, parent,model=None, data=None): |
---|
10 | |
---|
11 | """ |
---|
12 | Initialization of the Panel |
---|
13 | """ |
---|
14 | #TODO: remove this once the inheritence is cleaned up |
---|
15 | ## Data member to store the dispersion object created |
---|
16 | self._disp_obj_dict = {} |
---|
17 | ## reset True change the state of exsiting button |
---|
18 | self.reset = False |
---|
19 | #Data used for fitting |
---|
20 | self.data = data |
---|
21 | # flag to allow data2D plot |
---|
22 | self.enable2D = False |
---|
23 | # model on which the fit would be performed |
---|
24 | self.model = model |
---|
25 | if not hasattr(self.model, "_persistency_dict"): |
---|
26 | self.model._persistency_dict = {} |
---|
27 | self.model._persistency_dict = copy.deepcopy(model._persistency_dict) |
---|
28 | #fit page manager |
---|
29 | self.manager = None |
---|
30 | #Store the parent of this panel parent |
---|
31 | # For this application fitpanel is the parent |
---|
32 | self.parent = parent |
---|
33 | # Event_owner is the owner of model event |
---|
34 | self.event_owner = None |
---|
35 | ##page name |
---|
36 | self.page_name = "" |
---|
37 | # Contains link between model ,all its parameters, and panel organization |
---|
38 | self.parameters =[] |
---|
39 | # Contains list of parameters that cannot be fitted and reference to |
---|
40 | #panel objects |
---|
41 | self.fixed_param =[] |
---|
42 | # Contains list of parameters with dispersity and reference to |
---|
43 | #panel objects |
---|
44 | self.fittable_param =[] |
---|
45 | ## orientation parameters |
---|
46 | self.orientation_params=[] |
---|
47 | ## orientation parmaters for gaussian dispersity |
---|
48 | self.orientation_params_disp=[] |
---|
49 | ## smearer info |
---|
50 | self.smearer=None |
---|
51 | #list of dispersion paramaters |
---|
52 | self.disp_list =[] |
---|
53 | if self.model !=None: |
---|
54 | self.disp_list = self.model.getDispParamList() |
---|
55 | self._disp_obj_dict={} |
---|
56 | self.disp_cb_dict={} |
---|
57 | self.values=[] |
---|
58 | self.weights=[] |
---|
59 | |
---|
60 | #contains link between a model and selected parameters to fit |
---|
61 | self.param_toFit =[] |
---|
62 | ##dictionary of model type and model class |
---|
63 | self.model_list_box = None |
---|
64 | ## save the state of the context menu |
---|
65 | self.saved_states={} |
---|
66 | ## save current value of combobox |
---|
67 | self.formfactorcombobox = "" |
---|
68 | self.structurecombobox = "" |
---|
69 | ## the indice of the current selection |
---|
70 | self.disp_box = 0 |
---|
71 | ## Qrange |
---|
72 | ## Q range |
---|
73 | self.qmin= 0.001 |
---|
74 | self.qmax= 0.1 |
---|
75 | self.npts = None |
---|
76 | ## enable smearering state |
---|
77 | self.enable_smearer = False |
---|
78 | self.disable_smearer = True |
---|
79 | ## disperity selection |
---|
80 | self.enable_disp= False |
---|
81 | self.disable_disp= True |
---|
82 | ## plot 2D data |
---|
83 | self.enable2D= False |
---|
84 | ## state of selected all check button |
---|
85 | self.cb1 = False |
---|
86 | |
---|
87 | |
---|
88 | def save_data(self, data): |
---|
89 | """ |
---|
90 | Save data |
---|
91 | """ |
---|
92 | self.data = copy.deepcopy(data) |
---|
93 | |
---|
94 | |
---|
95 | def clone(self): |
---|
96 | model=None |
---|
97 | if self.model !=None: |
---|
98 | model = self.model.clone() |
---|
99 | |
---|
100 | obj = PageState( self.parent,model= model ) |
---|
101 | obj.data = copy.deepcopy(self.data) |
---|
102 | obj.model_list_box = copy.deepcopy(self.model_list_box) |
---|
103 | |
---|
104 | obj.manager = self.manager |
---|
105 | obj.event_owner = self.event_owner |
---|
106 | obj.disp_list = copy.deepcopy(self.disp_list) |
---|
107 | |
---|
108 | obj.enable2D = copy.deepcopy(self.enable2D) |
---|
109 | obj.parameters = copy.deepcopy(self.parameters) |
---|
110 | obj.fixed_param = copy.deepcopy(self.fixed_param) |
---|
111 | obj.fittable_param = copy.deepcopy(self.fittable_param) |
---|
112 | obj.orientation_params = copy.deepcopy(self.orientation_params) |
---|
113 | obj.orientation_params_disp = copy.deepcopy(self.orientation_params_disp) |
---|
114 | |
---|
115 | obj.enable_disp = copy.deepcopy(self.enable_disp) |
---|
116 | obj.disable_disp = copy.deepcopy(self.disable_disp) |
---|
117 | if self.model !=None and len(self.model._persistency_dict)>0: |
---|
118 | for k, v in self.model._persistency_dict.iteritems(): |
---|
119 | obj.model._persistency_dict[k] = copy.deepcopy(v) |
---|
120 | if len(self._disp_obj_dict)>0: |
---|
121 | for k , v in self._disp_obj_dict.iteritems(): |
---|
122 | obj._disp_obj_dict[k]= v |
---|
123 | if len(self.disp_cb_dict)>0: |
---|
124 | for k , v in self.disp_cb_dict.iteritems(): |
---|
125 | obj.disp_cb_dict[k]= v |
---|
126 | obj.values = copy.deepcopy(self.values) |
---|
127 | obj.weights = copy.deepcopy(self.weights) |
---|
128 | obj.enable_smearer = copy.deepcopy(self.enable_smearer) |
---|
129 | obj.disable_smearer = copy.deepcopy(self.disable_smearer) |
---|
130 | |
---|
131 | obj.disp_box = copy.deepcopy(self.disp_box) |
---|
132 | obj.qmin = copy.deepcopy(self.qmin) |
---|
133 | obj.qmax = copy.deepcopy(self.qmax) |
---|
134 | obj.npts = copy.deepcopy(self.npts ) |
---|
135 | obj.cb1 = copy.deepcopy(self.cb1) |
---|
136 | obj.smearer = copy.deepcopy(self.smearer) |
---|
137 | |
---|
138 | for name, state in self.saved_states.iteritems(): |
---|
139 | copy_name = copy.deepcopy(name) |
---|
140 | copy_state = state.clone() |
---|
141 | obj.saved_states[copy_name]= copy_state |
---|
142 | return obj |
---|
143 | |
---|
144 | |
---|
145 | class PageMemento(object): |
---|
146 | """ |
---|
147 | Store the state of a fitpage or model page of fitpanel |
---|
148 | """ |
---|
149 | def __init__(self, state): |
---|
150 | """ Initialization""" |
---|
151 | self.state = state |
---|
152 | |
---|
153 | def setState(self,state): |
---|
154 | """ |
---|
155 | set current state |
---|
156 | @param state: new state |
---|
157 | """ |
---|
158 | self.state = state |
---|
159 | |
---|
160 | def getState(self): |
---|
161 | """ |
---|
162 | @return state |
---|
163 | """ |
---|
164 | return self.state |
---|
165 | |
---|
166 | |
---|
167 | |
---|
168 | |
---|