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 | #fit page manager |
---|
26 | self.manager = None |
---|
27 | #Store the parent of this panel parent |
---|
28 | # For this application fitpanel is the parent |
---|
29 | self.parent = parent |
---|
30 | # Event_owner is the owner of model event |
---|
31 | self.event_owner = None |
---|
32 | ##page name |
---|
33 | self.page_name = "" |
---|
34 | # Contains link between model ,all its parameters, and panel organization |
---|
35 | self.parameters =[] |
---|
36 | # Contains list of parameters that cannot be fitted and reference to |
---|
37 | #panel objects |
---|
38 | self.fixed_param =[] |
---|
39 | # Contains list of parameters with dispersity and reference to |
---|
40 | #panel objects |
---|
41 | self.fittable_param =[] |
---|
42 | ## orientation parameters |
---|
43 | self.orientation_params=[] |
---|
44 | ## orientation parmaters for gaussian dispersity |
---|
45 | self.orientation_params_disp=[] |
---|
46 | ## smearer info |
---|
47 | self.smearer=None |
---|
48 | #list of dispersion paramaters |
---|
49 | self.disp_list =[] |
---|
50 | #contains link between a model and selected parameters to fit |
---|
51 | self.param_toFit =[] |
---|
52 | ##dictionary of model type and model class |
---|
53 | self.model_list_box = None |
---|
54 | ## save the state of the context menu |
---|
55 | self.saved_states={} |
---|
56 | ## save current value of combobox |
---|
57 | self.formfactorcombobox = "" |
---|
58 | self.structurecombobox = "" |
---|
59 | ## the indice of the current selection |
---|
60 | self.disp_box = 0 |
---|
61 | ## Qrange |
---|
62 | ## Q range |
---|
63 | self.qmin= 0.001 |
---|
64 | self.qmax= 0.1 |
---|
65 | self.npts = None |
---|
66 | ## enable smearering state |
---|
67 | self.enable_smearer = False |
---|
68 | self.disable_smearer = True |
---|
69 | ## disperity selection |
---|
70 | self.enable_disp= False |
---|
71 | self.disable_disp= True |
---|
72 | ## state of selected all check button |
---|
73 | self.cb1 = False |
---|
74 | |
---|
75 | |
---|
76 | def save_data(self, data): |
---|
77 | """ |
---|
78 | Save data |
---|
79 | """ |
---|
80 | self.data = copy.deepcopy(data) |
---|
81 | |
---|
82 | |
---|
83 | def clone(self): |
---|
84 | model=None |
---|
85 | if self.model !=None: |
---|
86 | model = self.model.clone() |
---|
87 | |
---|
88 | obj = PageState( self.parent,model= model ) |
---|
89 | obj.data = copy.deepcopy(self.data) |
---|
90 | obj.model_list_box = copy.deepcopy(self.model_list_box) |
---|
91 | obj.manager = self.manager |
---|
92 | obj.event_owner = self.event_owner |
---|
93 | |
---|
94 | obj.parameters = copy.deepcopy(self.parameters) |
---|
95 | obj.fixed_param = copy.deepcopy(self.fixed_param) |
---|
96 | obj.fittable_param = copy.deepcopy(self.fittable_param) |
---|
97 | obj.orientation_params = copy.deepcopy(self.orientation_params) |
---|
98 | obj.orientation_params_disp = copy.deepcopy(self.orientation_params_disp) |
---|
99 | |
---|
100 | obj.enable_disp = copy.deepcopy(self.enable_disp) |
---|
101 | obj.disable_disp = copy.deepcopy(self.disable_disp) |
---|
102 | |
---|
103 | obj.enable_smearer = copy.deepcopy(self.enable_smearer) |
---|
104 | obj.disable_smearer = copy.deepcopy(self.disable_smearer) |
---|
105 | |
---|
106 | obj.disp_box = copy.deepcopy(self.disp_box) |
---|
107 | obj.qmin = copy.deepcopy(self.qmin) |
---|
108 | obj.qmax = copy.deepcopy(self.qmax) |
---|
109 | obj.npts = copy.deepcopy(self.npts ) |
---|
110 | obj.cb1 = copy.deepcopy(self.cb1) |
---|
111 | obj.smearer = copy.deepcopy(self.smearer) |
---|
112 | |
---|
113 | for name, state in self.saved_states.iteritems(): |
---|
114 | copy_name = copy.deepcopy(name) |
---|
115 | copy_state = state.clone() |
---|
116 | obj.saved_states[copy_name]= copy_state |
---|
117 | return obj |
---|
118 | |
---|
119 | class PageMemento(object): |
---|
120 | """ |
---|
121 | Store the state of a fitpage or model page of fitpanel |
---|
122 | """ |
---|
123 | def __init__(self, state): |
---|
124 | """ Initialization""" |
---|
125 | self.state = state |
---|
126 | |
---|
127 | def setState(self,state): |
---|
128 | """ |
---|
129 | set current state |
---|
130 | @param state: new state |
---|
131 | """ |
---|
132 | self.state = state |
---|
133 | |
---|
134 | def getState(self): |
---|
135 | """ |
---|
136 | @return state |
---|
137 | """ |
---|
138 | return self.state |
---|
139 | |
---|
140 | |
---|
141 | |
---|
142 | |
---|