1 | # -*- coding: utf-8 -*- |
---|
2 | # |
---|
3 | # Copyright (C) 2008-2011 Marcus Walther (walther@szgrf.bgr.de) |
---|
4 | # |
---|
5 | # This file is part of Seismic Handler eXtended (SHX) |
---|
6 | # Full details can be found at project website http://www.seismic-handler.org/ |
---|
7 | # |
---|
8 | # SHX is free software; you can redistribute it and/or modify |
---|
9 | # it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as published by |
---|
10 | # the Free Software Foundation; either version 3 of the License, or |
---|
11 | # (at your option) any later version. |
---|
12 | # |
---|
13 | # SHX is distributed in the hope that it will be useful, |
---|
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | # GNU Lesser General Public License for more details. |
---|
17 | # |
---|
18 | # You should have received a copy of the GNU Lesser General Public License |
---|
19 | # along with SHX (see license.txt); if not, write to the Free Software |
---|
20 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
---|
21 | |
---|
22 | from obspy.core.util import AttribDict |
---|
23 | from SeismicHandler.basics import Singleton |
---|
24 | from SeismicHandler.basics.messages import logMessage, msgs |
---|
25 | from obspy.core.stream import Stream |
---|
26 | from SeismicHandler.config import Settings |
---|
27 | |
---|
28 | |
---|
29 | class Traces(object): |
---|
30 | """ |
---|
31 | Supply access for two streams of traces. One is used for plotting, the other |
---|
32 | holds hidden traces. This will be enhanced later, but for compatibility |
---|
33 | reasons to existing command procedures it's done that way first. |
---|
34 | """ |
---|
35 | __metaclass__ = Singleton |
---|
36 | |
---|
37 | traces = AttribDict() |
---|
38 | |
---|
39 | def __init__(self, *args, **kwargs): |
---|
40 | self.traces.visible = Stream() |
---|
41 | self.traces.hidden = Stream() |
---|
42 | |
---|
43 | def __getattr__(self, name): |
---|
44 | try: |
---|
45 | return self.__class__.__dict__["traces"][name] |
---|
46 | except: |
---|
47 | raise AttributeError(name) |
---|
48 | |
---|
49 | def addreplace(self, stream): |
---|
50 | """ |
---|
51 | Adds or replaces visible streams depending on runtime setting. |
---|
52 | """ |
---|
53 | # this is always a global switch! |
---|
54 | if not Settings.swKeeptraces: |
---|
55 | logMessage("debug.traces", "replacing visible traces") |
---|
56 | self.traces.visible.clear() |
---|
57 | |
---|
58 | self.traces.visible += stream |
---|
59 | self.updateCounter() |
---|
60 | |
---|
61 | def updateCounter(self): |
---|
62 | dsptrcs = len(self.traces.visible) |
---|
63 | hidtrcs = len(self.traces.hidden) |
---|
64 | logMessage("debug.traces", "Now %u visible and %u hidden traces" % ( |
---|
65 | dsptrcs, hidtrcs)) |
---|
66 | |
---|
67 | msgs.sendMessage('runtime', name="dsptrcs", value=dsptrcs) |
---|
68 | msgs.sendMessage('runtime', name="tottrcs", value=dsptrcs+hidtrcs) |
---|
69 | |
---|
70 | |
---|
71 | if __name__ == "__main__": |
---|
72 | pass |
---|