source: TI05-delivery/ows_framework/trunk/ows_server/ows_server/controllers/visualise.py @ 3661

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI05-delivery/ows_framework/trunk/ows_server/ows_server/controllers/visualise.py
Revision 3661, 4.6 KB checked in by cbyrom, 13 years ago (diff)

Various code tidy ups - including removal of print statements and
addition of extra header + documentation.

Line 
1from ows_server.lib.base import *
2from ows_server.lib.ndgInterface import interface
3
4
5class VisualiseController(BaseController):
6   
7    def __setup(self):
8       
9        c.fullpage=1  # we want the whole page
10        c.selections = {}
11        c.selected = {}
12        c.names={}
13        c.bbox = (90, -180, 180, -90)
14        c.inpageid = 'api'
15
16        for uri, name in session.get('selection', []):
17            (rstatus, dataset) = interface.GetParsedCSML(uri)               
18            if not rstatus: 
19                c.xml='<div class="error">%s</div>'%dataset
20                return render('error')
21            c.selections[uri]=dataset
22            c.names[uri]=name
23       
24        c.nothing2see=0
25        if c.selections=={}:
26            c.nothing2see=1
27            return 0
28       
29        # Need two fundamental variables: the granules which has been selected
30        # for *possible* visualisation, and the granules (up to two) which have been
31        # selected for *actual* visualisation:
32        # session['selection'] holds the uris assocated with the first
33        # session['selectedVis'] holds the uris and featureIDs associated with the second
34        # c.selections holds the uris and the parsed csml for the datasets
35        # c.selected holds the uris, featureIDs and the parsed feature instances for the second
36       
37        # some defaults
38        defURI=c.selections.keys()[0]
39        defFid=c.selections[defURI].getFeatureList()[0]
40       
41        keys=session.get('selectedVis',[])
42        if keys==[]: keys=[(defURI,defFid)]
43        #yes, I know I could have sued the default on the session.get, but
44        #it's also possible that selectedVis is actually set to [] and we
45        #want to override that case too!
46        for uri,featureID in keys:
47            featureInstance=c.selections[uri].getFeature(featureID)
48            c.selected[(uri,featureID)]=featureInstance
49         
50        # We also need to know which dataset (if any) we are looking at   
51        c.viewedDataset=session.get('viewedDataset',c.selections.keys()[0])
52        return 0
53       
54    def __plotops(self):
55        ''' Works out what we can do in the way of plot options and flags the info to the template'''
56        c.wmsAvailable=0
57        for i in c.selected:
58            if 'latitude' and 'longitude' in c.selected[i].getAxisLabels(): c.wmsAvailable=1
59     
60    def index(self):
61        s=self.__setup()
62        if s: return s
63        c.visible='Granules'
64        self.__plotops()
65        return render('visualise')
66       
67    def tabChange(self,dataset,view):
68        ''' Take ajax request for inpage tab change '''
69       
70        s=self.__setup()
71        if s: return s
72        c.visible=view
73        formValue=request.params.get('dataset',0)
74        if formValue: dataset=formValue
75        #dataset is really a uri ...shame about the variable name we chose ...
76       
77        # the incoming dataset ought to be in the selections, so this is only
78        # about telling the interface what variable list to display ... and
79        # remembering it
80        c.viewedDataset=dataset
81        session['viewedDataset']=dataset
82        session.save()
83       
84        c.fullpage=0 
85        self.__plotops()
86        return render('visualise',fragment=True)
87       
88    def featureChange(self,view):
89        ''' Take an ajax request and update the current list of features '''
90       
91        self.__setup()
92        if s: return s
93        c.visible=view
94        checkedFeatures=[]
95       
96        # ok, we know we are getting features from viewedDataset
97        # let's collect them up a we go so we know which ones we've
98        # lost (if any), as well as parse them as we go ...
99        checkedFeatures
100        for i in request.params:
101            featureID=request.params[i]
102            checkedFeatures.append(featureID)
103            if 'Feature' in i: 
104                if (c.viewedDataset,featureID) not in c.selected:
105                    featureInstance=c.selections[c.viewedDataset].getFeature(featureID)
106                    c.selected[(c.viewedDataset,featureID)]=featureInstance
107        #ok, now we remove them if necessary
108        removeList=[]
109        for suri,sf in c.selected:
110            if suri==c.viewedDataset and sf not in checkedFeatures:
111                removeList.append((suri,sf)) 
112        for i in removeList: del c.selected[i]
113        # and update the session
114        session['selectedVis']=c.selected.keys()
115        session.save()   
116       
117        c.fullpage=0
118        self.__plotops()
119        return render('visualise',fragment=True)
120       
121    def tabcontent(self):
122        pass
123   
124    def plot(self):
125        pass
126       
Note: See TracBrowser for help on using the repository browser.