source: sasview/src/sas/sasgui/perspectives/simulation/ShapeAdapter.py @ 5251ec6

magnetic_scattrelease-4.2.2ticket-1009ticket-1249
Last change on this file since 5251ec6 was 5251ec6, checked in by Paul Kienzle <pkienzle@…>, 6 years ago

improved support for py37 in sasgui

  • Property mode set to 100644
File size: 4.9 KB
Line 
1"""
2This software was developed by the University of Tennessee as part of the
3Distributed Data Analysis of Neutron Scattering Experiments (DANSE)
4project funded by the US National Science Foundation.
5
6See the license text in license.txt
7
8copyright 2009, University of Tennessee
9"""
10import sas.sascalc.realspace.VolumeCanvas as VolumeCanvas
11
12class ShapeVisitor:
13    """
14        The shape visitor process a GUI object representing
15        a shape and returns a shape description that can be
16        processed by the VolumeCanvas.
17    """
18   
19    def __init__(self):
20        """
21            Initialize visitor
22        """
23        ## Place holder for the simulation canvas
24        self.sim_canvas = None
25   
26    def fromCylinder(self, cyl):
27        """
28            Create a simulation cylinder descriptor (computation)
29            from the information produced by the GUI
30            @param cyl: Cylinder object from the GUI canvas
31            @return: VolumeCanvas.CylinderDescriptor object
32        """
33        from sas.sascalc.realspace.VolumeCanvas import CylinderDescriptor
34        desc = CylinderDescriptor()
35         
36        desc.params["center"] = [cyl.x, cyl.y, cyl.z]
37        # Orientation are angular offsets in degrees with respect to X, Y, Z
38        desc.params["orientation"] = [cyl.theta_x, cyl.theta_y, cyl.theta_z]
39        desc.params["order"] = cyl.params["order"]
40       
41       
42        # Length of the cylinder
43        desc.params["length"] = cyl.params["length"]
44        # Radius of the cylinder
45        desc.params["radius"] = cyl.params["radius"]
46        # Constrast parameter
47        desc.params["contrast"] = cyl.params["contrast"]
48       
49        return desc
50   
51    def fromSphere(self, sph):
52        """
53            Create a simulation sphere descriptor (computation)
54            from the information produced by the GUI
55            @param sph: Sphere object from the GUI canvas
56            @return: VolumeCanvas.SphereDescriptor object
57        """
58        from sas.sascalc.realspace.VolumeCanvas import SphereDescriptor
59        desc = SphereDescriptor()
60         
61        desc.params["center"] = [sph.x, sph.y, sph.z]
62        desc.params["order"] = sph.params["order"]
63        # Radius of the sphere
64        desc.params["radius"] = sph.params["radius"]
65        # Constrast parameter
66        desc.params["contrast"] = sph.params["contrast"]
67       
68        return desc
69   
70    def update_sphere(self, sph):
71        """
72            Update a shape description in the simulation canvas (computation)
73            according to the new parameters of the GUI canvas.
74            @param sph: Sphere object from the GUI canvas
75        """
76        # Check class
77        if self.sim_canvas.shapes[sph.name].__class__.__name__=="SphereDescriptor":
78            desc = self.sim_canvas.shapes[sph.name]
79           
80            desc.params["center"] = [sph.x, sph.y, sph.z]
81            desc.params["order"] = sph.params["order"]
82            # Radius of the sphere
83            desc.params["radius"] = sph.params["radius"]
84            # Constrast parameter
85            desc.params["contrast"] = sph.params["contrast"]
86           
87            self.sim_canvas._model_changed()
88        else:
89            raise ValueError("SimShapeVisitor: Wrong class for visited object")
90       
91       
92       
93    def update_cylinder(self, cyl):
94        """
95            Update a shape description in the simulation canvas (computation)
96            according to the new parameters of the GUI canvas.
97            @param cyl: Cylinder object from the GUI canvas
98        """
99        # Check class
100        if self.sim_canvas.shapes[cyl.name].__class__.__name__=="CylinderDescriptor":
101            desc = self.sim_canvas.shapes[cyl.name]
102           
103            desc.params["center"] = [cyl.x, cyl.y, cyl.z]
104            # Orientation are angular offsets in degrees with respect to X, Y, Z
105            desc.params["orientation"] = [cyl.theta_x, cyl.theta_y, cyl.theta_z]
106            desc.params["order"] = cyl.params["order"]
107           
108            # Length of the cylinder
109            desc.params["length"] = cyl.params["length"]
110            # Radius of the cylinder
111            desc.params["radius"] = cyl.params["radius"]
112            # Constrast parameter
113            desc.params["contrast"] = cyl.params["contrast"]
114           
115            self.sim_canvas._model_changed()
116        else:
117            raise ValueError("SimShapeVisitor: Wrong class for visited object")
118       
119   
120    def update(self, volCanvas, shape):
121        """
122            Update the shape descriptor in the VolumeCanvas
123            corresponding to the given 'shape' parameter
124           
125            @param volCanvas: VolumeCanvas object
126            @param shape: SimCanvas.BaseShape object
127        """
128        if shape.name in volCanvas.getShapeList():
129            self.sim_canvas = volCanvas
130            shape.accept_update(self)
131        else:
132            raise ValueError("ShapeAdapter: Shape [%s] not in list" % shape.name)
133
Note: See TracBrowser for help on using the repository browser.