Back to index

gcompris  8.2.2
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions
electric.Wire Class Reference

List of all members.

Public Member Functions

def __init__
def set_wire_id
def get_wire_id
def destroy
def set_target_node
def move_all_wire
def move
def move_source_node
def move_target_node
def delete_wire

Public Attributes

 electric
 rootitem
 source_node
 target_node
 x1
 y1
 x2
 y2
 wire_item
 wire_id

Static Public Attributes

int counter = 1
dictionary connection = {}
list colors

Private Member Functions

def _add_connection

Detailed Description

Definition at line 485 of file electric.py.


Constructor & Destructor Documentation

def electric.Wire.__init__ (   self,
  electric,
  source_node,
  x1,
  y1,
  x2,
  y2 
)

Definition at line 506 of file electric.py.

00506 
00507     def __init__(self, electric, source_node, x1, y1, x2, y2):
00508       self.electric = electric
00509       self.rootitem = electric.rootitem
00510       self.source_node = source_node
00511       self.target_node = None
00512       self.x1 = x1
00513       self.y1 = y1
00514       self.x2 = x2
00515       self.y2 = y2
00516       self.wire_item = self.rootitem.add(
00517         gnomecanvas.CanvasLine,
00518         points=( self.x1, self.y1, self.x2, self.y2),
00519         fill_color_rgba = 0xFF0000FFL,
00520         width_units=5.0
00521         )
00522       self.wire_item.connect("event", self.delete_wire, self)
00523       self.wire_id = -1
00524       self._add_connection(source_node)


Member Function Documentation

def electric.Wire._add_connection (   self,
  node 
) [private]

Definition at line 525 of file electric.py.

00525 
00526     def _add_connection(self, node):
00527       # Is this node already connected
00528       if(node.get_wires()):
00529         wire_id = node.get_wires()[0].get_wire_id()
00530         if debug: print "Node already connected to %d (self.wire_id=%d)" %(wire_id, self.wire_id)
00531         if self.wire_id >= 0:
00532           # This node was already connected elsewhere, reset it to use our
00533           # wire_id
00534           for wire in node.get_wires():
00535             if debug: print "   Was connected to %d" %(wire.get_wire_id(),)
00536             if wire.get_wire_id() != self.wire_id:
00537               wire.set_wire_id(self.wire_id)
00538         else:
00539           if wire_id == -1:
00540             self.wire_id = Wire.counter
00541             Wire.counter += 1
00542           else:
00543             self.wire_id = wire_id
00544 
00545       else:
00546         if self.wire_id == -1:
00547           self.wire_id = Wire.counter
00548           Wire.counter += 1
00549 
00550         Wire.connection[node] = self
00551 
00552       if debug: print "WIRE_ID = %d" %self.wire_id

Here is the call graph for this function:

Here is the caller graph for this function:

def electric.Wire.delete_wire (   self,
  widget,
  event,
  wire 
)

Definition at line 615 of file electric.py.

00615 
00616     def delete_wire(self, widget, event, wire):
00617 
00618       if event.type == gtk.gdk.BUTTON_PRESS:
00619         if event.button == 1:
00620           wire.destroy()
00621         elif event.button == 3:
00622           if debug: print "WIRE_ID = %d" %self.wire_id
00623 
00624       return False
00625 
00626 
00627 #------------------------------------------------------------
00628 # Node
00629 #
# x, y are node coordinate relative to the component image
def electric.Wire.destroy (   self)

Definition at line 566 of file electric.py.

00566 
00567     def destroy(self):
00568       self.wire_item.destroy()
00569       self.wire_id = -1
00570       self.source_node.remove_wire(self, None)
00571       if self.target_node:
00572         self.target_node.remove_wire(self, Wire.counter)
00573       Wire.counter += 1
00574       self.source_node = None
00575       self.target_node = None
00576       self.electric.run_simulation()
00577 

Here is the caller graph for this function:

def electric.Wire.get_wire_id (   self)

Definition at line 563 of file electric.py.

00563 
00564     def get_wire_id(self):
00565       return self.wire_id

Here is the caller graph for this function:

def electric.Wire.move (   self,
  node,
  x,
  y 
)

Definition at line 595 of file electric.py.

00595 
00596     def move(self, node, x, y):
00597       if(node == self.source_node):
00598         self.move_source_node(x, y)
00599       elif(node== self.target_node):
00600         self.move_target_node(x, y)

Here is the call graph for this function:

Here is the caller graph for this function:

def electric.Wire.move_all_wire (   self,
  x,
  y 
)

Definition at line 587 of file electric.py.

00587 
00588     def move_all_wire(self, x, y):
00589       if(self.source_node and self.target_node):
00590         source_component = self.source_node.get_component()
00591         target_component = self.target_node.get_component()
00592         # TBD Need to move the components but not loosing their distance.
00593         #     Don't know yet how

def electric.Wire.move_source_node (   self,
  x1,
  y1 
)

Definition at line 601 of file electric.py.

00601 
00602     def move_source_node(self, x1, y1):
00603       self.x1 = x1
00604       self.y1 = y1
00605       self.wire_item.set( points = (self.x1, self.y1,
00606                                     self.x2, self.y2) )

Here is the caller graph for this function:

def electric.Wire.move_target_node (   self,
  x2,
  y2 
)

Definition at line 607 of file electric.py.

00607 
00608     def move_target_node(self, x2, y2):
00609       self.x2 = x2
00610       self.y2 = y2
00611       self.wire_item.set( points = (self.x1, self.y1,
00612                                     self.x2, self.y2) )
00613 

Here is the caller graph for this function:

def electric.Wire.set_target_node (   self,
  node 
)

Definition at line 578 of file electric.py.

00578 
00579     def set_target_node(self, node):
00580       self.target_node = node
00581       self._add_connection(node)
00582 
00583       # Colorize the wire
00584       self.wire_item.set(fill_color_rgba = Wire.colors[self.wire_id % len(Wire.colors)])

Here is the call graph for this function:

def electric.Wire.set_wire_id (   self,
  id 
)

Definition at line 553 of file electric.py.

00553 
00554     def set_wire_id(self, id):
00555       self.wire_id = id
00556       if(self.target_node):
00557         self.target_node.renumber_wire(self, id)
00558       if(self.source_node):
00559         self.source_node.renumber_wire(self, id)
00560 
00561       # Colorize the wire
00562       self.wire_item.set(fill_color_rgba = Wire.colors[id % len(Wire.colors)])


Member Data Documentation

list electric.Wire.colors [static]
Initial value:
[ 0xdfc766FFL,
               0xdf9766FFL,
               0xdf667dFFL,
               0xdf66bcFFL,
               0xc466dfFFL,
               0x9c66dfFFL,
               0xA4FFB3FFL,
               0x6666dfFFL,
               0x669fdfFFL,
               0x66df6cFFL,
               0x66dfd8FFL ]

Definition at line 494 of file electric.py.

dictionary electric.Wire.connection = {} [static]

Definition at line 493 of file electric.py.

int electric.Wire.counter = 1 [static]

Definition at line 492 of file electric.py.

Definition at line 507 of file electric.py.

Definition at line 508 of file electric.py.

Definition at line 509 of file electric.py.

Definition at line 510 of file electric.py.

Definition at line 522 of file electric.py.

Definition at line 515 of file electric.py.

Definition at line 511 of file electric.py.

Definition at line 513 of file electric.py.

Definition at line 512 of file electric.py.

Definition at line 514 of file electric.py.


The documentation for this class was generated from the following file: