ProjectionWidget.py 4.95 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#MDANSE : Molecular Dynamics Analysis for Neutron Scattering Experiments
#------------------------------------------------------------------------------------------
#Copyright (C)
#2015- Eric C. Pellegrini Institut Laue-Langevin
#BP 156
#6, rue Jules Horowitz
#38042 Grenoble Cedex 9
#France
#pellegrini[at]ill.fr
#goret[at]ill.fr
#aoun[at]ill.fr
#
#This library is free software; you can redistribute it and/or
#modify it under the terms of the GNU Lesser General Public
#License as published by the Free Software Foundation; either
#version 2.1 of the License, or (at your option) any later version.
#
#This library is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#Lesser General Public License for more details.
#
#You should have received a copy of the GNU Lesser General Public
#License along with this library; if not, write to the Free Software
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

''' 
Created on Mar 30, 2015

30
:author: Eric C. Pellegrini
31
32
33
34
'''

import wx

35
from MDANSE.Framework.Configurable import ConfigurationError
36

37
38
39
from MDANSE.App.GUI.Framework.Widgets.IWidget import IWidget

class ProjectionWidget(IWidget):
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
    
    type = "projection"

    def add_widgets(self):

        sizer = wx.BoxSizer(wx.VERTICAL)

        gbSizer = wx.GridBagSizer(0,0)

        self._none = wx.RadioButton(self._widgetPanel, wx.ID_ANY, label="None", style=wx.RB_GROUP)
        self._none.SetValue(True)
        self._axial = wx.RadioButton(self._widgetPanel, wx.ID_ANY, label="Axial")
        self._planar = wx.RadioButton(self._widgetPanel, wx.ID_ANY, label="Planar")

        self._panelAxial = wx.Panel(self._widgetPanel, wx.ID_ANY)
        sizerAxial = wx.BoxSizer(wx.HORIZONTAL)
        
        labelAxial = wx.StaticText(self._panelAxial, wx.ID_ANY, size=(80,-1), label="Axis vector")        
        self._ax = wx.TextCtrl(self._panelAxial, wx.ID_ANY)
        self._ay = wx.TextCtrl(self._panelAxial, wx.ID_ANY)
        self._az = wx.TextCtrl(self._panelAxial, wx.ID_ANY)

        sizerAxial.Add(labelAxial, flag=wx.ALIGN_CENTER_VERTICAL)
        sizerAxial.Add(self._ax, 1, wx.EXPAND|wx.ALL, 5)
        sizerAxial.Add(self._ay, 1, wx.EXPAND|wx.ALL, 5)
        sizerAxial.Add(self._az, 1, wx.EXPAND|wx.ALL, 5)

        self._panelAxial.SetSizer(sizerAxial)
        self._panelAxial.Enable(False)

        self._panelPlanar = wx.Panel(self._widgetPanel, wx.ID_ANY)
        sizerPlanar = wx.BoxSizer(wx.HORIZONTAL)

        labelPlanar = wx.StaticText(self._panelPlanar, wx.ID_ANY, size=(80,-1), label="Normal vector")        
        self._px = wx.TextCtrl(self._panelPlanar, wx.ID_ANY)
        self._py = wx.TextCtrl(self._panelPlanar, wx.ID_ANY)
        self._pz = wx.TextCtrl(self._panelPlanar, wx.ID_ANY)

        sizerPlanar.Add(labelPlanar, flag=wx.ALIGN_CENTER_VERTICAL)
        sizerPlanar.Add(self._px, 1, wx.EXPAND|wx.ALL, 5)
        sizerPlanar.Add(self._py, 1, wx.EXPAND|wx.ALL, 5)
        sizerPlanar.Add(self._pz, 1, wx.EXPAND|wx.ALL, 5)

        self._panelPlanar.SetSizer(sizerPlanar)
        self._panelPlanar.Enable(False)

        gbSizer.Add(self._none, (0,0), flag=wx.ALIGN_CENTER_VERTICAL)
        gbSizer.Add(self._axial, (1,0), flag=wx.ALIGN_CENTER_VERTICAL)
        gbSizer.Add(self._planar, (2,0), flag=wx.ALIGN_CENTER_VERTICAL)

        gbSizer.Add(self._panelAxial, (1,2), flag=wx.EXPAND)

        gbSizer.Add(self._panelPlanar, (2,2), flag=wx.EXPAND)

        sizer.Add(gbSizer, 1, wx.EXPAND|wx.ALL, 5)
        
        self.Bind(wx.EVT_RADIOBUTTON, self.on_select_projection_mode, self._none)
        self.Bind(wx.EVT_RADIOBUTTON, self.on_select_projection_mode, self._axial)
        self.Bind(wx.EVT_RADIOBUTTON, self.on_select_projection_mode, self._planar)
        
        return sizer

    def get_widget_value(self):

        rb = [rb for rb in (self._none, self._axial, self._planar) if rb.GetValue()][0]
        
        if rb == self._none:
            return None
        
        elif rb == self._axial:
            try:
                val = ("axial", tuple([float(v.GetValue()) for v in (self._ax,self._ay,self._az)]))
            except ValueError:
113
                raise ConfigurationError("Invalid value for %r entry" % self.name)
114
115
116
117
118
119
120
            else:
                return val
            
        elif rb == self._planar:
            try:
                val = ("planar", tuple([v.GetValue() for v in (self._px,self._py,self._pz)]))
            except ValueError:
121
                raise ConfigurationError("Invalid value for %r entry" % self.name)
122
123
124
125
126
127
128
129
130
            else:
                return val            
    
    def on_select_projection_mode(self, event):
        
        rb = event.GetEventObject()
        
        self._panelAxial.Enable(rb == self._axial)
        self._panelPlanar.Enable(rb == self._planar)