node_network.py 23.5 KB
Newer Older
Daniel Brown's avatar
Daniel Brown committed
1
2
3
4
5
6
# -*- coding: utf-8 -*-
"""
Created on Sun Jan 27 10:02:41 2013

@author: Daniel
"""
7
8
9
10
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
11

Daniel Brown's avatar
Daniel Brown committed
12
13
14
15
16
from pykat import USE_GUI, NoGUIException

if USE_GUI:
    import pykat.gui.graphics
    
Daniel Brown's avatar
Daniel Brown committed
17
import pykat.exceptions as pkex
18
import pykat.external.six as six
Daniel Brown's avatar
Daniel Brown committed
19

20
from pykat.components import Component, NodeGaussSetter
21
from pykat.detectors import BaseDetector as Detector
22
from pykat.optics.gaussian_beams import beam_param
23
from copy import deepcopy
Daniel Brown's avatar
Daniel Brown committed
24

25
26
id___ = 0
    
Daniel Brown's avatar
Daniel Brown committed
27
class NodeNetwork(object):
28
    
29
    def __new__(cls, *args, **kwargs):
30
31
32
33
34
35
36
37
38
39
        # This creates an instance specific class for the component
        # this enables us to add properties to instances rather than
        # all classes
        global id___
        id___ += 1
        cnew_name = str("%s.%s_%i" % (cls.__module__, cls.__name__, id___))
        
        cnew = type(cnew_name, (cls,), {})
        
        return object.__new__(cnew, *args, **kwargs)
40

Daniel Brown's avatar
Daniel Brown committed
41
42
43
44
45
46
47
    def __init__(self, kat):
        self.__nodes = {}
        self.__kat = kat
        self.__nodeComponents = {} # dictionary of tuples containing which components are connected to a node
        self.__componentNodes = {} # dictionary of tuples containing which nodes are connected to a given component
        self.__componentCallback = {}
        self.__node_id = 1
48
49
50
51
52
53
54
55
56
57
58
59
60
61
    
    def __deepcopy__(self, memo):
        """
        When deep copying a kat object we need to take into account
        the instance specific properties.
        """
        
        # Here we create a copy of this object based of the base class
        # of this one, otherwise we're making a copy of a copy of a copy...
        result = self.__class__.__new__(self.__class__.__base__)
        result.__dict__ = deepcopy(self.__dict__, memo)
        
        return result
                
62
63
    @property
    def kat(self): return self.__kat
Daniel Brown's avatar
Daniel Brown committed
64
65
66
67
68
69
70
71
72
        
    def registerComponentNodes(self, comp, node_names, change_callback):
        """
        For a given component we create some nodes or get existing ones and 
        attach them to this component. Also specify a callback function that
        is called whenever the nodes attached to this component are changed
        , e.g. connected, disconnected, name change, etc.
        """
        if not isinstance(comp, Component):
73
            raise pkex.BasePyKatException("comp argument is not of type Component")
Daniel Brown's avatar
Daniel Brown committed
74
75
76
77
78
79
80
81
        
        if comp.id in self.__componentNodes:
            raise pkex.BasePyKatException("Component has already been registered")
        
        list = []
        
        for name in node_names:
            n = self.createNode(name)
82
            self.__connectNodeToComp(n, comp, do_callback=False)
Daniel Brown's avatar
Daniel Brown committed
83
84
85
86
87
88
89
90
            list.append(n)
        
        self.__componentNodes[comp.id] = tuple(list)
        self.__componentCallback[comp.id] = change_callback
        
        change_callback()
    
    def replaceNode(self, comp, node_old, node_new):
91
92
93
94
95
96
97
98
        """
        For a particular pykat component this will replace a node that is currently
        connected to it with another. This can be used to dynamically change layouts
        once components have been read into the pykat.finesse.kat object.
        
        node_old is the node that is attached to the component. This will accept
             str - name of a node
             pykat.node_network.Node - The direct node object
99
             NodeGaussSetter - the node object that is used to set gaussian parameters
100
101
102
103
             
        This will call a components __on_node_change callback function to let it know that the nodes
        connected to it have changed.
        """
Daniel Brown's avatar
Daniel Brown committed
104
        
105
        if isinstance(node_old, six.string_types):
106
107
            node_old = self.__kat.nodes[node_old]
        
108
        if isinstance(node_new, six.string_types):
109
110
            node_new = self.__kat.nodes[node_new]
            
111
        if isinstance(node_old, NodeGaussSetter):
112
113
            node_old = node_old.node
        
114
        if isinstance(node_new, NodeGaussSetter):
115
116
117
            node_new = node_new.node
            
        if not node_new.isDump and node_new.components.count(None) == 0:
Daniel Brown's avatar
Daniel Brown committed
118
119
120
121
122
            raise pkex.BasePyKatException("New node already connected to two components")
            
        if comp not in node_old.components:
            raise pkex.BasePyKatException("Old node not attached to component")
        
123
        if not node_new.isDump and comp in node_new.components:
Daniel Brown's avatar
Daniel Brown committed
124
125
126
127
128
129
            raise pkex.BasePyKatException("New node already attached to component")
        
        # add component to new node component list
        new_node_comps = list(node_new.components)
        new_node_comps[new_node_comps.index(None)] = comp
        self.__nodeComponents[node_new.id] = tuple(new_node_comps)
130
        del new_node_comps
Daniel Brown's avatar
Daniel Brown committed
131
132
133
134
135
        
        # remove component from old node list
        old_node_comps = list(node_old.components)
        old_node_comps[old_node_comps.index(comp)] = None
        self.__nodeComponents[node_old.id] = tuple(old_node_comps)
136
        del old_node_comps
Daniel Brown's avatar
Daniel Brown committed
137
138
139
140
        
        comp_nodes = list(comp.nodes)
        comp_nodes[comp_nodes.index(node_old)] = node_new
        self.__componentNodes[comp.id] = tuple(comp_nodes)
141
        del comp_nodes
Daniel Brown's avatar
Daniel Brown committed
142
143
144
145
        
        # if old node is no longer connected to anything then delete it
        if node_old.components.count(None) == 2:
            self.removeNode(node_old)
146
147
148
        
        # Call component callback to let it know that we have changed the 
        # nodes attached to it
Daniel Brown's avatar
Daniel Brown committed
149
150
        self.__componentCallback[comp.id]()
            
151
152
153
154
    def __connectNodeToComp(self, node, comp, do_callback=True):
        """
        This is an internal function used to create connections between nodes
        """
Daniel Brown's avatar
Daniel Brown committed
155
156
157
158
159
160
        if node.id in self.__nodeComponents:
            comps = self.__nodeComponents[node.id]
        else:
            comps = (None,) * 2
        
        if len(comps) >= 2 and comps[0] != None and comps[1] != None:
161
            raise pkex.BasePyKatException("Node '{0}' is already connected to 2 components ({1}, {2})".format(node.name, comps[0], comps[1]))
Daniel Brown's avatar
Daniel Brown committed
162
163
164
165
166
167
168
169
170
171
172
173
174
        
        l = list(comps)
        
        if l[0] == None:
            l[0] = comp
        elif l[1] == None:
            l[1] = comp
        else:
            raise pkex.BasePyKatException("Connected to two coponents already")
        
        self.__nodeComponents[node.id] = tuple(l)
        
        if do_callback: self.__componentCallback[comp.id]()
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
    
    def __update_nodes_properties(self):
        # check if any node setters have already been added. If so we
        # need to remove them. This function should get called if the nodes
        # are updated, either by some function call or the GUI
        key_rm = [k for k in self.__dict__ if k.startswith("__node_", 0, 7)]

        # now we have a list of which to remove
        for key in key_rm:
            ns = self.__dict__[key]
            name = str(ns.name)
            
            if '__node_' + name in self.__dict__:
                delattr(self, '__node_' + name)
            
            if name in self.__class__.__dict__:
                delattr(self.__class__, name)
        
        # Now re-add them pointing to the recent nodes
        for node in self.__nodes:
            if not self.__nodes[node].isDump:
                self.__add_node_attr(self.__nodes[node])
         
Daniel Brown's avatar
Daniel Brown committed
198
    def createNode(self, node_name):
199
200
201
202
203
204
205
206
207
        """
        This creates a new node object. It won't be connected to anything or added to a
        pykat.finesse.kat object until it is specifically attached to a particular 
        component. This should be used in conjunction with kat.nodes.replaceNode to 
        add a new node into a system, as every component will already have the nodes
        setup, including dump nodes.
        
        This will return a dump node if the name of the node is "dump" (case senstive)
        """
Daniel Brown's avatar
Daniel Brown committed
208
            
209
        if node_name != 'dump' and node_name in self.__nodes:
Daniel Brown's avatar
Daniel Brown committed
210
211
212
            # then this node already exists
            return self.__nodes[node_name]
        else:
213
214
215
216
            if node_name == 'dump':
                n = DumpNode(self)
            else:
                n = Node(node_name, self, self.__node_id)
Daniel Brown's avatar
Daniel Brown committed
217
218
219
            
            self.__node_id += 1
            self.__nodeComponents[n.id] = (None, None)
220
221
222
223
224
225
            
            if not n.isDump:
                self.__add_node_attr(n) # add node as a member of this object, e.g. kat.nodes.n
                self.__nodes[node_name] = n
                
            
Daniel Brown's avatar
Daniel Brown committed
226
            return n
227
    
228
229
230
231
232
233
    def _removeComponent(self, comp):
        """
        This is an internal function that shouldn't be used directly. This removes
        a particular component from the node network. For this to work it has to be 
        detached from all other connections first.
        """
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
        C = self.__componentNodes[comp.id]
        
        for n in C:
           if comp in self.__nodeComponents[n.id]:
               l = list(self.__nodeComponents[n.id])
               l[l.index(comp)] = None
               self.__nodeComponents[n.id] = tuple(l)
               
               if l.count(None) == 2:
                   self.removeNode(n) 
               
               del l
               
        del self.__componentCallback[comp.id]
        del self.__componentNodes[comp.id]
Daniel Brown's avatar
Daniel Brown committed
249
250
        
    def removeNode(self, node):
251
252
253
254
255
256
257
258
259
        """
        This will remove a particular node object from the network. The node in question
        must be fully detached from all components and connections first. This function is 
        called by replaceNode directly so a replaced node, that is no longer connected to 
        anything, is removed automatically.
        
        node_old is the node that is attached to the component. This will accept
             str - name of a node
             pykat.node_network.Node - The direct node object
260
             NodeGaussSetter - the node object that is used to set gaussian parameters
261
262
              
        """
263
        
264
        if isinstance(node, six.string_types):
265
266
            node = self.__kat.nodes[node]
            
267
        if isinstance(node, NodeGaussSetter):
268
269
            node = node.node
            
270
271
        if not isinstance(node, Node):
            raise pkex.BasePyKatException("node argument is not of type Node")
Daniel Brown's avatar
Daniel Brown committed
272
        
273
274
        if not isinstance(node, DumpNode) and node.name not in self.__nodes:
            raise pkex.BasePyKatException("Trying to remove node {0} when it has not been added".format(node.name))
Daniel Brown's avatar
Daniel Brown committed
275
276
277
278
        
        C = self.getNodeComponents(node)
        
        if C[0] is not None or C[1] is not None:
279
            raise pkex.BasePyKatException("Cannot remove a node which is attached to components still")
Daniel Brown's avatar
Daniel Brown committed
280
281
            
        if len(node.getDetectors()) > 0:
282
            raise pkex.BasePyKatException("Cannot remove a node which is attached to detectors still")
Daniel Brown's avatar
Daniel Brown committed
283
        
284
285
286
        if not isinstance(node, DumpNode):
            self.__remove_node_attr(node)
            del self.__nodes[node.name] 
287
288
            
        del self.__nodeComponents[node.id]
Daniel Brown's avatar
Daniel Brown committed
289
290
        
    def hasNode(self, name):
291
        ""
Daniel Brown's avatar
Daniel Brown committed
292
293
294
        return (name in self.__nodes)
    
    def getNodes(self):
295
296
297
298
        """
        Returns a copy of the node dictionary, this is for infomration purposes any edits won't make
        any changes to the node network.
        """
Daniel Brown's avatar
Daniel Brown committed
299
300
301
        return self.__nodes.copy()
    
    def getComponentNodes(self, comp):
302
303
304
305
        """
        This function returns a tuple of the nodes connected to the component specified.
        For information only, you cannot edit the connections using this function.
        """
Daniel Brown's avatar
Daniel Brown committed
306
307
308
        return self.__componentNodes[comp.id]
    
    def getNodeComponents(self, node):
309
310
311
312
        """
        This function returns a tuple of the components connected to the node specified.
        For information only, you cannot edit the connections using this function.
        """
Daniel Brown's avatar
Daniel Brown committed
313
314
315
316
317
        return self.__nodeComponents[node.id]
    
    def __add_node_attr(self, node):

        if not isinstance(node, Node):
318
            raise pkex.BasePyKatException("Argument is not of type Node")
Daniel Brown's avatar
Daniel Brown committed
319
320
321
322
323
324
325
326
327
        
        name = node.name
        fget = lambda self: self.__get_node_attr(name)
        
        setattr(self.__class__, name, property(fget))
        setattr(self, '__node_' + name, node)                   
    
    def __remove_node_attr(self, node):
        if not isinstance(node, Node):
328
            kat.nodes.replaceNode(kat.bs1, "n1", kat.nodes.createNode("test1"))
Daniel Brown's avatar
Daniel Brown committed
329
330
        
        name = node.name
331
        
Daniel Brown's avatar
Daniel Brown committed
332
333
334
335
336
337
338
        delattr(self, '__node_' + name)
        delattr(self.__class__, name)
        
    def __get_node_attr(self, name):
        return getattr(self, '__node_' + name)        
        
    def __getitem__(self, value):
339
340
341
342
        if str(value) in self.__nodes:
            return self.__nodes[str(value)]
        else:
            raise pkex.BasePyKatException("The node '%s' could not be found in the network." % str(value))
Daniel Brown's avatar
Daniel Brown committed
343
344
345
        
    def __contains__(self, value):
        return value in self.__nodes
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
    
    def __nodeSearch(self, fnode, currcomp, branches, tnode):
        
        if fnode == tnode:
            branches[-1][0] = True
            branches[-1][1] = True
            return True # Hurrah, we have found a path to the node
        elif fnode.isDump:
            branches[-1][0] = True
            return False # if the current node is a dump, we need to check another branch

        nextnode = None
        
        if isinstance(currcomp, pykat.components.beamSplitter):
            # if we get to a beamsplitter then we need to 
            # create new branches to search: the rfelected
            # and transmitted
            
            # set this branch as searched
            branches[-1][0] = True
            # add two new ones
            
            if fnode == currcomp.nodes[0]:
                rn = currcomp.nodes[1]
                tn = currcomp.nodes[2]
            elif fnode == currcomp.nodes[1]:
                rn = currcomp.nodes[0]
                tn = currcomp.nodes[3]
            elif fnode == currcomp.nodes[2]:
                rn = currcomp.nodes[3]
                tn = currcomp.nodes[0]
            elif fnode == currcomp.nodes[3]:
                rn = currcomp.nodes[2]
                tn = currcomp.nodes[1]
            else:
381
                raise pkex.BasePyKatException("Node not attached in path find to BS")
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
            
            nextcomp = None
            
            if tn.components[0] == currcomp:
                nextcomp = tn.components[1]
            elif tn.components[1] == currcomp:
                nextcomp = tn.components[0]
            
            if nextcomp != None:
                branches.append([False, False, tn, nextcomp, []])
            
            if rn.components[0] == currcomp:
                nextcomp = rn.components[1]
            elif rn.components[1] == currcomp:
                nextcomp = rn.components[0]
            
            if nextcomp != None:
                branches.append([False, False, rn, nextcomp, []])
            
            branches[-1][-1].append(currcomp)
            
            return False
            
        elif isinstance(currcomp, pykat.components.isolator):
406
            print ("isol")
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
        elif isinstance(currcomp, pykat.components.laser):
            # if we are at a laser then we can't go any further
            # and it isn;t this node as we checked before
            branches[-1][0] = True
            return False
        elif len(currcomp.nodes) == 2:
            if currcomp.nodes[0] == fnode:
                nextnode = currcomp.nodes[1]
            elif currcomp.nodes[1] == fnode:
                nextnode = currcomp.nodes[0]
            else:
                raise pkex.BasePyKatException("Unexpeceted condition")
        else:
            raise pkex.BasePyKatException("Did not handle component {0} correctly, has more or less than 2 nodes.".format(currcomp))
        
        if nextnode == None:
            branches[-1][0] = True
            return False
        elif nextnode == tnode:
            branches[-1][0] = True
            branches[-1][1] = True
            branches[-1][-1].append(currcomp)
            return True
        else:
            # Now we have the next node, we need the next component
            if nextnode.components[0] == currcomp:
                nextcomp = nextnode.components[1]
            elif nextnode.components[1] == currcomp:
                nextcomp = nextnode.components[0]
            else:
                raise pkex.BasePyKatException("Unexpeceted condition")

            if nextcomp == None:
                branches[-1][0] = True
                return False
            
            branches[-1][-1].append(currcomp)
            
            return self.__nodeSearch(nextnode, nextcomp, branches, tnode)
            
    def getComponentsBetween(self, from_node, to_node):
448
449
450
451
452
        """
        This function will trace the path between the two nodes specified and return a list
        of the components it finds between them.
        """
        
453
        if isinstance(from_node, six.string_types):
454
455
            from_node = self.__kat.nodes[from_node]
            
456
        if isinstance(from_node, NodeGaussSetter):
457
458
            from_node = from_node.node
            
459
        if isinstance(to_node, six.string_types):
460
461
            to_node = self.__kat.nodes[to_node]
            
462
        if isinstance(to_node, NodeGaussSetter):
463
464
465
466
467
            to_node = to_node.node
            
        if to_node == from_node:
            return []
        
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
        if from_node not in self.__nodes:
            raise pkex.BasePyKatException("Node {0} cannot be found in this kat object".format(from_node))

        if to_node not in self.__nodes:
            raise pkex.BasePyKatException("Node {0} cannot be found in this kat object".format(to_node))
        
        branches = []
        
        fn = self.__nodes[from_node]
        tn = self.__nodes[to_node]
        
        branches.append([False, False, fn, fn.components[1], []])
        branches.append([False, False, fn, fn.components[0], []])
        
        while len(branches) > 0 and branches[-1][1] != True:
            while branches[-1][0] == False:
                branch = branches[-1]
            
                if not self.__nodeSearch(branch[2], branch[3], branches, tn):
                    if len(branches) > 0 and branches[-1][0] != False:
                        branches.pop()
            
            if branches[-1][1] != True:
                while len(branches) > 0 and branches[-1][0] == True:
                    branches.pop()
            
            
        comps = []
        
        if len(branches) > 0  and branches[-1][0] == True and branches[-1][1] == True:
            # select the branches that form the path from node to node
            br = [b for b in branches if b[0] == True]
Daniel Brown's avatar
Daniel Brown committed
500
        
501
502
503
504
505
            for b in br:
                comps.extend(b[-1])
        
        return comps
    
Daniel Brown's avatar
Daniel Brown committed
506
507
508
509
510
511
512
513
514
515
516
517
    
class Node(object):

    def __init__(self, name, network, id):
        self._detectors = []
        self.__name = name
        self._item = None
        self._network = network
        self.__q_x = None
        self.__q_y = None
        self.__q_comp = None
        self.__id = id
518
519
        self._isDump = False
        
Daniel Brown's avatar
Daniel Brown committed
520
    def __str__(self): return self.__name
521
522
523
524

    @property
    def isDump(self): return self._isDump
        
Daniel Brown's avatar
Daniel Brown committed
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
    @property
    def id(self): return self.__id
    
    @property
    def network(self): return self._network
    
    @property
    def components(self): return self._network.getNodeComponents(self)
    
    @property
    def q(self):
        if self.__q_x == self.__q_y:
            return self.__q_x
        else:
            return (self.__q_x, self.__q_y)
            
    @property
    def qx(self): return self.__q_x
    @property
    def qy(self): return self.__q_y
    
546
    def removeGauss(self):
Daniel Brown's avatar
Daniel Brown committed
547
548
549
550
551
552
553
        self.__q_x = None
        self.__q_y = None
        self.__q_comp = None
    
    def setGauss(self, component, *args):
        self.__q_comp = component
        
554
        if len(args) == 1:  
555
556
            self.__q_x = beam_param(self._network.kat.lambda0, q=args[0])
            self.__q_y = beam_param(self._network.kat.lambda0, q=args[0])
Daniel Brown's avatar
Daniel Brown committed
557
        elif len(args) == 2:
558
559
            self.__q_x = beam_param(self._network.kat.lambda0, q=args[0])
            self.__q_y = beam_param(self._network.kat.lambda0, q=args[1])
Daniel Brown's avatar
Daniel Brown committed
560
561
        else:
            raise pkex.BasePyKatException("Must specify either 1 Gaussian beam parameter or 2 for astigmatic beams")
562
                
Daniel Brown's avatar
Daniel Brown committed
563
564
565
566
567
    def getFinesseText(self):    
        if self.__q_x is None or self.__q_y is None or self.__q_comp is None:
            return []
            
        rtn = []
Daniel Brown's avatar
Daniel Brown committed
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
        
        # to get the name of the gauss parameter is a bit convoluted...
        # firstly the name is set in the NodeGaussSetter object which is
        # connected to each component, so this has to be retrieved and 
        # then applied.
        if hasattr(self.__q_comp, self.name):
            ns = getattr(self.__q_comp, self.name)
            
            # if no name is present give it a default one
            if ns.name != None:
                name = ns.name
            else:
                name = "g_%s" % self.name
        else:
            raise pkex.BasePyKatException("Node {0} is not connected to {1}".format(self.name, self.__q_comp.name))
        
        
Daniel Brown's avatar
Daniel Brown committed
585
        if self.__q_x == self.__q_y:
Daniel Brown's avatar
Daniel Brown committed
586
            rtn.append("gauss {name} {comp} {node} {w0:.15g} {z:.15g}".format(name=name, node=self.name, comp=self.__q_comp.name, w0=self.__q_x.w0, z=self.__q_x.z))
Daniel Brown's avatar
Daniel Brown committed
587
        else:
Daniel Brown's avatar
Daniel Brown committed
588
            rtn.append("gauss {name} {comp} {node} {w0x:.15g} {zx:.15g} {w0y:.15g} {zy:.15g}".format(name=name, node=self.name, comp=self.__q_comp.name, w0x=self.__q_x.w0, zx=self.__q_x.z, w0y=self.__q_y.w0, zy=self.__q_y.z))
Daniel Brown's avatar
Daniel Brown committed
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
            
        return rtn
        
    def isConnected(self):
        if (self.components[0] is not None) and (self.components[1] is not None):
            return True
        else:
            return False
      
    def remove(self):
        self._network.removeNode(self)
        
        if self._item != None:
            self._item.scene().removeItem(self._item)
    
    def getQGraphicsItem(self,dx=0,dy=0,nsize=8,parent=None):
Daniel Brown's avatar
Daniel Brown committed
605
606
607
        if not USE_GUI:
            raise NoGUIException
            
Daniel Brown's avatar
Daniel Brown committed
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
        if self._item == None:
            self._item = pykat.gui.graphics.NodeQGraphicItem(self,
                                                             dx,dy,
                                                             -nsize/2,-nsize/2,
                                                             nsize, nsize, parent)
            
        return self._item
    
    def getDetectors(self):
        return self._detectors[:]
        
    def amIConnected(self, obj):
        """
        Checks if obj is connected to the node. Returns true or false in tuple
        with None or the other object and the node index which it is attached to
        """ 
        comps = self.components
        
        if obj == comps[0]:
            if comps[1] == None:
                ix = -1
            else:
                ix = comps[1].nodes.index(self)
                
            return [True, comps[1], ix]
            
        elif obj == comps[1]:
            if comps[0] == None:
                ix = -1
            else:
                ix = comps[0].nodes.index(self)
                
            return [True, comps[0], ix]
        else:
            return [False, None]
        
    @property
    def name(self): return self.__name      
646
647
        
        
Daniel Brown's avatar
Daniel Brown committed
648
class DumpNode(Node):
649
650
    __total_dump_node_id = 0
    
651
    def __init__(self, network):
652
        DumpNode.__total_dump_node_id -= 1
653
        Node.__init__(self, 'dump', network, DumpNode.__total_dump_node_id)
654
        self._isDump = True
Daniel Brown's avatar
Daniel Brown committed
655
        
656