Salome HOME
b42de0c99dd5b9ce827c64cc15fd992b2e123be3
[tools/sat.git] / data / templates / PythonComponent / src / Controller / Controller.py
1 from Polyline import Polyline
2 from Circle import Circle
3
4 class Controller() :
5     """Manages the Model instances"""
6
7     def __init__( self, MainFrame ) :
8         """Constructor"""
9
10         self._models = []
11         self._mainFrame = MainFrame
12         self._nbPolylines = 0
13         self._nbCircles = 0
14         pass
15
16     def getModels( self ) :
17         return self._models
18
19     def getMainFrame( self ) :
20         return self._mainFrame
21
22     def getNbPolylines( self ) :
23         return self._nbPolylines
24
25     def setNbPolylines( self, n ) :
26         self._nbPolylines = n
27         pass
28
29     def getNbCircles( self ) :
30         return self._nbCircles
31
32     def setNbCircles( self, n ) :
33         self._nbCircles = n
34         pass
35
36     def createPolyline( self, name, randomNumberOfPoints ) :
37         """Creates a Polyline object nammed name with randomNumberOfPoints points"""
38
39         import random
40
41         # Making randomNumberOfPoints random positionned points
42         points = []
43         x = random.uniform( 0, randomNumberOfPoints )
44         for i in range( randomNumberOfPoints ) :
45            x = random.uniform( x, x+randomNumberOfPoints )
46            y = random.uniform( 0, x )
47            point = x, y
48            points.append( point )
49            pass
50
51         myPolyline = Polyline( name, points, self )
52         self._models.append( myPolyline )
53         myPolyline.updateViews( mode = 'creation' )
54
55         self._nbPolylines +=1
56         return myPolyline
57
58     def createCircle( self, name, center, radius ) :
59         """Creates a Circle object nammed name with center and radius"""
60
61         myCircle = Circle( name, center, radius, self )
62         self._models.append( myCircle )
63         myCircle.updateViews( mode = 'creation' )
64
65         self._nbCircles +=1
66         return myCircle
67
68     def showModel( self, model ) :
69         model.updateViews( mode = 'showing' )
70         pass
71
72     def editName( self, model, name ) :
73         model.setName( name )
74         model.updateViews( mode = 'modification' )
75         return model
76
77     def editPoint( self, polyline, newPoint, pointRange ) :
78         polyline.editPoint( pointRange, newPoint )
79         polyline.updateViews( mode = 'modification' )
80         return polyline
81
82     def editCenter( self, circle, center ) :
83         circle.setCenter( center )
84         circle.updateViews( mode = 'modification' )
85         return circle
86
87     def editRadius( self, circle, radius ) :
88         circle.setRadius( radius )
89         circle.updateViews( mode = 'modification' )
90         return circle
91
92     def removeModel( self, model ) :
93         model.updateViews( mode = 'supression' )
94         index = self._models.index( model )
95         del model
96         pass
97
98     def saveListOfModels( self ) :
99         for model in self._models :
100            model.save()
101            pass
102         pass
103
104 pass