def get_panels(self, parent): """ Create and return a list of panel objects """ self.parent = parent # 3D viewer self.plotPanel = SimCanvas.SimPanel(self.parent, -1, style=wx.RAISED_BORDER) # Central simulation panel self.paramPanel = ShapeParameters.ShapeParameterPanel( self.parent, q_min=self.q_min, q_max=self.q_max, q_npts=self.q_npts, pt_density=DEFAULT_PT_DENSITY, style=wx.RAISED_BORDER) # Simulation self.volCanvas = VolumeCanvas.VolumeCanvas() self.volCanvas.setParam('lores_density', DEFAULT_PT_DENSITY) self.adapter = ShapeAdapter.ShapeVisitor() self._data_1D = None self.calc_thread_1D = None self.speedCheck = False self.speed = 3.0e-7 # Q-values for plotting simulated I(Q) step = (self.q_max - self.q_min) / (self.q_npts - 1) self.x = np.arange(self.q_min, self.q_max + step * 0.01, step) # Set the list of panels that are part of the simulation perspective self.perspective = [] self.perspective.append(self.plotPanel.window_name) self.perspective.append(self.paramPanel.window_name) # Bind state events self.parent.Bind(ShapeParameters.EVT_ADD_SHAPE, self._onAddShape) self.parent.Bind(ShapeParameters.EVT_DEL_SHAPE, self._onDelShape) self.parent.Bind(ShapeParameters.EVT_Q_RANGE, self._on_q_range_changed) self.parent.Bind(ShapeParameters.EVT_PT_DENSITY, self._on_pt_density_changed) return [self.plotPanel, self.paramPanel]
def __init__(self, parent, q_min=0.001, q_max=0.5, q_npts=10, pt_density=0.1, *args, **kwargs): wx.Panel.__init__(self, parent, *args, **kwargs) self.window_name = "ShapeParams" self.window_caption = "Shape parameter" self.params = {} self.parent = parent self.type = None self.listeners = [] self.parameters = [] self.bck = wx.GridBagSizer(5, 5) self.SetSizer(self.bck) # position and orientation ctrl self.xctrl = None self.yctrl = None self.zctrl = None self.actrl = None self.bctrl = None self.cctrl = None # Sizer to hold the shape parameters self.shape_sizer = wx.GridBagSizer(5, 5) ny = 0 title = wx.StaticText(self, -1, "[Temporary form]", style=wx.ALIGN_LEFT) self.bck.Add(title, (ny, 0), (1, 2), flag=wx.LEFT | wx.ALIGN_CENTER_VERTICAL, border=15) # Shape list shape_text = wx.StaticText(self, -1, "Geometric shape", style=wx.ALIGN_LEFT) self.shape_list = SimCanvas.getShapes() value_list = [] for item in self.shape_list: value_list.append(item['name']) self.model_combo = wx.ComboBox(self, -1, value=value_list[0], choices=value_list, style=wx.CB_READONLY) self.model_combo.SetToolTip( wx.ToolTip("Select a geometric shape from the drop-down list")) ny += 1 self.bck.Add(shape_text, (ny, 0), flag=wx.LEFT | wx.ALIGN_CENTER_VERTICAL, border=15) self.bck.Add(self.model_combo, (ny, 1), flag=wx.LEFT | wx.ALIGN_CENTER_VERTICAL, border=15) wx.EVT_COMBOBOX(self.model_combo, -1, self._on_select_shape) # Placeholder for parameter form ny += 1 self.bck.Add(self.shape_sizer, (ny, 0), (1, 2), flag=wx.LEFT | wx.ALIGN_CENTER_VERTICAL, border=0) # Point density control point_density_text = wx.StaticText(self, -1, "Point density", style=wx.ALIGN_LEFT) ny += 1 self.bck.Add(point_density_text, (ny, 0), flag=wx.LEFT | wx.ALIGN_CENTER_VERTICAL, border=15) self.point_density_ctrl = wx.TextCtrl(self, -1, size=(40, 20), style=wx.TE_PROCESS_ENTER) self.point_density_ctrl.SetValue(str(pt_density)) self.point_density_ctrl.SetToolTip( wx.ToolTip( "Enter the number of real-space points per Angstrom cube")) self.point_density_ctrl.Bind(wx.EVT_TEXT_ENTER, self._on_density_changed) self.point_density_ctrl.Bind(wx.EVT_KILL_FOCUS, self._on_density_changed) self.bck.Add(self.point_density_ctrl, (ny, 1), flag=wx.LEFT | wx.ALIGN_CENTER_VERTICAL, border=15) # Q range q_min_text = wx.StaticText(self, -1, "Q min", style=wx.ALIGN_LEFT) ny += 1 self.bck.Add(q_min_text, (ny, 0), flag=wx.LEFT | wx.ALIGN_CENTER_VERTICAL, border=15) self.q_min_ctrl = wx.TextCtrl(self, -1, size=(40, 20), style=wx.TE_PROCESS_ENTER) self.q_min_ctrl.SetValue(str(q_min)) self.q_min_ctrl.SetToolTip( wx.ToolTip("Enter the minimum Q value to be simulated")) self.q_min_ctrl.Bind(wx.EVT_TEXT_ENTER, self._on_q_range_changed) self.q_min_ctrl.Bind(wx.EVT_KILL_FOCUS, self._on_q_range_changed) self.bck.Add(self.q_min_ctrl, (ny, 1), flag=wx.LEFT | wx.ALIGN_CENTER_VERTICAL, border=15) q_max_text = wx.StaticText(self, -1, "Q max", style=wx.ALIGN_LEFT) self.bck.Add(q_max_text, (ny, 2), flag=wx.LEFT | wx.ALIGN_CENTER_VERTICAL, border=15) self.q_max_ctrl = wx.TextCtrl(self, -1, size=(40, 20), style=wx.TE_PROCESS_ENTER) self.q_max_ctrl.SetValue(str(q_max)) self.q_min_ctrl.SetToolTip( wx.ToolTip("Enter the maximum Q value to be simulated")) self.q_max_ctrl.Bind(wx.EVT_TEXT_ENTER, self._on_q_range_changed) self.q_max_ctrl.Bind(wx.EVT_KILL_FOCUS, self._on_q_range_changed) self.bck.Add(self.q_max_ctrl, (ny, 3), flag=wx.LEFT | wx.ALIGN_CENTER_VERTICAL, border=15) q_npts_text = wx.StaticText(self, -1, "No. of Q pts", style=wx.ALIGN_LEFT) self.bck.Add(q_npts_text, (ny, 4), flag=wx.LEFT | wx.ALIGN_CENTER_VERTICAL, border=15) self.q_npts_ctrl = wx.TextCtrl(self, -1, size=(40, 20), style=wx.TE_PROCESS_ENTER) self.q_npts_ctrl.SetValue(str(q_npts)) self.q_min_ctrl.SetToolTip( wx.ToolTip("Enter the number of Q points to be simulated")) self.q_npts_ctrl.Bind(wx.EVT_TEXT_ENTER, self._on_q_range_changed) self.q_npts_ctrl.Bind(wx.EVT_KILL_FOCUS, self._on_q_range_changed) self.bck.Add(self.q_npts_ctrl, (ny, 5), flag=wx.LEFT | wx.ALIGN_CENTER_VERTICAL, border=15) # Shape List # Internal counter of shapes in the listbox self.counter = 0 # Buffer filled flag self.buffer_filled = False # Save current flag self.current_saved = False id = wx.NewId() shape_listbox_text = wx.StaticText(self, -1, "List of shapes on 3D canvas", style=wx.ALIGN_LEFT) self.shape_listbox = wx.ListBox(self, id, wx.DefaultPosition, (295, 200), [], wx.LB_SINGLE | wx.LB_HSCROLL) # Listen to history events self.parent.Bind(EVT_ADD_SHAPE, self._on_add_shape_to_listbox) self.shape_listbox.Bind(wx.EVT_LISTBOX, self._on_select_from_listbox, id=id) self.shape_listbox.Bind(wx.EVT_CONTEXT_MENU, self._on_listbox_context_menu, id=id) ny += 1 self.bck.Add(shape_listbox_text, (ny, 0), (1, 2), flag=wx.LEFT | wx.ALIGN_CENTER_VERTICAL, border=15) ny += 1 self.bck.Add(self.shape_listbox, (ny, 0), (1, 5), flag=wx.LEFT | wx.ALIGN_CENTER_VERTICAL, border=15) self.current_shape = None # Default shape if type(self.shape_list) == list and len(self.shape_list) > 0: shape = SimCanvas.getShapeClassByName(self.shape_list[0]['name'])() self.editShape(shape)
def _on_select_shape(self, event): shape = SimCanvas.getShapeClassByName( self.shape_list[event.GetEventObject().GetSelection()]['name'])() self.editShape(shape)
def __init__(self, parent, q_min=0.001, q_max=0.5, q_npts=10, pt_density=0.1, *args, **kwargs): wx.Panel.__init__(self, parent, *args, **kwargs) self.window_name = "ShapeParams" self.window_caption = "Shape parameter" self.params = {} self.parent = parent self.type = None self.listeners = [] self.parameters = [] self.bck = wx.GridBagSizer(5,5) self.SetSizer(self.bck) # position and orientation ctrl self.xctrl = None self.yctrl = None self.zctrl = None self.actrl = None self.bctrl = None self.cctrl = None # Sizer to hold the shape parameters self.shape_sizer = wx.GridBagSizer(5,5) ny = 0 title = wx.StaticText(self, -1, "[Temporary form]", style=wx.ALIGN_LEFT) self.bck.Add(title, (ny,0), (1,2), flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=15) # Shape list shape_text = wx.StaticText(self, -1, "Geometric shape", style=wx.ALIGN_LEFT) self.shape_list = SimCanvas.getShapes() value_list = [] for item in self.shape_list: value_list.append(item['name']) self.model_combo = wx.ComboBox(self, -1, value=value_list[0], choices=value_list, style=wx.CB_READONLY) self.model_combo.SetToolTip(wx.ToolTip("Select a geometric shape from the drop-down list")) ny+=1 self.bck.Add(shape_text, (ny,0), flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=15) self.bck.Add(self.model_combo, (ny,1), flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=15) wx.EVT_COMBOBOX(self.model_combo,-1, self._on_select_shape) # Placeholder for parameter form ny+=1 self.bck.Add(self.shape_sizer, (ny,0), (1,2), flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=0) # Point density control point_density_text = wx.StaticText(self, -1, "Point density", style=wx.ALIGN_LEFT) ny+=1 self.bck.Add(point_density_text, (ny,0), flag = wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border = 15) self.point_density_ctrl = wx.TextCtrl(self, -1, size=(40,20), style=wx.TE_PROCESS_ENTER) self.point_density_ctrl.SetValue(str(pt_density)) self.point_density_ctrl.SetToolTip(wx.ToolTip("Enter the number of real-space points per Angstrom cube")) self.point_density_ctrl.Bind(wx.EVT_TEXT_ENTER, self._on_density_changed) self.point_density_ctrl.Bind(wx.EVT_KILL_FOCUS, self._on_density_changed) self.bck.Add(self.point_density_ctrl, (ny,1), flag = wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border = 15) # Q range q_min_text = wx.StaticText(self, -1, "Q min", style=wx.ALIGN_LEFT) ny+=1 self.bck.Add(q_min_text, (ny,0), flag = wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border = 15) self.q_min_ctrl = wx.TextCtrl(self, -1, size=(40,20), style=wx.TE_PROCESS_ENTER) self.q_min_ctrl.SetValue(str(q_min)) self.q_min_ctrl.SetToolTip(wx.ToolTip("Enter the minimum Q value to be simulated")) self.q_min_ctrl.Bind(wx.EVT_TEXT_ENTER, self._on_q_range_changed) self.q_min_ctrl.Bind(wx.EVT_KILL_FOCUS, self._on_q_range_changed) self.bck.Add(self.q_min_ctrl, (ny,1), flag = wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border = 15) q_max_text = wx.StaticText(self, -1, "Q max", style=wx.ALIGN_LEFT) self.bck.Add(q_max_text, (ny,2), flag = wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border = 15) self.q_max_ctrl = wx.TextCtrl(self, -1, size=(40,20), style=wx.TE_PROCESS_ENTER) self.q_max_ctrl.SetValue(str(q_max)) self.q_min_ctrl.SetToolTip(wx.ToolTip("Enter the maximum Q value to be simulated")) self.q_max_ctrl.Bind(wx.EVT_TEXT_ENTER, self._on_q_range_changed) self.q_max_ctrl.Bind(wx.EVT_KILL_FOCUS, self._on_q_range_changed) self.bck.Add(self.q_max_ctrl, (ny,3), flag = wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border = 15) q_npts_text = wx.StaticText(self, -1, "No. of Q pts", style=wx.ALIGN_LEFT) self.bck.Add(q_npts_text, (ny,4), flag = wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border = 15) self.q_npts_ctrl = wx.TextCtrl(self, -1, size=(40,20), style=wx.TE_PROCESS_ENTER) self.q_npts_ctrl.SetValue(str(q_npts)) self.q_min_ctrl.SetToolTip(wx.ToolTip("Enter the number of Q points to be simulated")) self.q_npts_ctrl.Bind(wx.EVT_TEXT_ENTER, self._on_q_range_changed) self.q_npts_ctrl.Bind(wx.EVT_KILL_FOCUS, self._on_q_range_changed) self.bck.Add(self.q_npts_ctrl, (ny,5), flag = wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border = 15) # Shape List # Internal counter of shapes in the listbox self.counter = 0 # Buffer filled flag self.buffer_filled = False # Save current flag self.current_saved = False id = wx.NewId() shape_listbox_text = wx.StaticText(self, -1, "List of shapes on 3D canvas", style=wx.ALIGN_LEFT) self.shape_listbox = wx.ListBox(self, id, wx.DefaultPosition, (295, 200), [], wx.LB_SINGLE | wx.LB_HSCROLL) # Listen to history events self.parent.Bind(EVT_ADD_SHAPE, self._on_add_shape_to_listbox) self.shape_listbox.Bind(wx.EVT_LISTBOX, self._on_select_from_listbox, id=id) self.shape_listbox.Bind(wx.EVT_CONTEXT_MENU, self._on_listbox_context_menu, id=id) ny+=1 self.bck.Add(shape_listbox_text, (ny,0), (1,2), flag = wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border = 15) ny+=1 self.bck.Add(self.shape_listbox, (ny,0), (1,5), flag = wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border = 15) self.current_shape = None # Default shape if type(self.shape_list)==list and len(self.shape_list)>0: shape = SimCanvas.getShapeClassByName(self.shape_list[0]['name'])() self.editShape(shape)
def _on_select_shape(self, event): shape = SimCanvas.getShapeClassByName(self.shape_list[event.GetEventObject().GetSelection()]['name'])() self.editShape(shape)