Back to index

gcompris  8.2.2
Public Member Functions | Public Attributes | Static Public Attributes
electric.Rheostat Class Reference
Inheritance diagram for electric.Rheostat:
Inheritance graph
[legend]
Collaboration diagram for electric.Rheostat:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def update_wiper_wire
def move_wiper
def component_scroll
def component_click
def component_move
def is_connected
def to_gnucap_res
def to_gnucap
def set_voltage_intensity
def get_rootitem
def move
def show
def hide
def destroy
def get_nodes
def create_wire

Public Attributes

 gnucap_current_resistor
 gnucap_nb_resistor
 wiper_ofset_x
 wiper_ofset_min_y
 wiper_ofset_max_y
 wiper_ofset_y
 resitance
 item_values_x
 item_values_y
 wiper_wire_item
 wiper_item
 voltage
 intensity
 electric
 canvas
 rootitem
 gnucap_name
 gnucap_value
 nodes
 comp_rootitem
 x
 y
 center_x
 center_y
 component_item_offset_x
 component_item_offset_y
 component_item
 item_values
 pos_x
 pos_y
 wire

Static Public Attributes

string image = "electric/resistor_track.png"
string icon = "electric/resistor_track_icon.png"
int counter = 0

Detailed Description

Definition at line 1231 of file electric.py.


Constructor & Destructor Documentation

def electric.Rheostat.__init__ (   self,
  electric,
  x,
  y,
  resitance 
)

Definition at line 1235 of file electric.py.

01235 
01236                x, y, resitance):
01237     self.gnucap_current_resistor = 1
01238     self.gnucap_nb_resistor = 0
01239     self.wiper_ofset_x = -2
01240     self.wiper_ofset_min_y = 22
01241     self.wiper_ofset_max_y = 103
01242     self.wiper_ofset_y = self.wiper_ofset_min_y
01243     self.resitance = resitance
01244     super(Rheostat, self).__init__(electric,
01245                                    "R",
01246                                    self.resitance,
01247                                    self.image,
01248                                    [Node("electric/connect.png", "A", 0, -25),
01249                                     Node("electric/connect.png", "B", 50, 50),
01250                                     Node("electric/connect.png", "C", 0, 125)])
01251 
01252     # Overide some values
01253     self.item_values_x = 20
01254     self.item_values_y = 70
01255     self.item_values.set(fill_color="blue")
01256 
01257     self.move(x, y)
01258 
01259     # The wiper wire
01260     self.wiper_wire_item = self.comp_rootitem.add(
01261       gnomecanvas.CanvasLine,
01262       points = (0,0,0,0),
01263       fill_color_rgba = 0x5A5A5AFFL,
01264       width_units=5.0
01265       )
01266     self.update_wiper_wire()
01267 
01268     pixmap = gcompris.utils.load_pixmap("electric/resistor_wiper.png")
01269     self.wiper_item = self.comp_rootitem.add(
01270       gnomecanvas.CanvasPixbuf,
01271       pixbuf = pixmap,
01272       x = self.x + self.wiper_ofset_x,
01273       y = self.y + self.wiper_ofset_y,
01274       )
01275     self.wiper_item.connect("event", self.component_click)
01276 
01277     self.show()


Member Function Documentation

def electric.Rheostat.component_click (   self,
  widget,
  event 
)

Definition at line 1309 of file electric.py.

01309 
01310   def component_click(self, widget, event):
01311     # drag and drop
01312     if event.type == gtk.gdk.MOTION_NOTIFY:
01313       if event.state & gtk.gdk.BUTTON1_MASK:
01314         self.move_wiper(event.y)
01315 
01316     return True

Here is the call graph for this function:

def electric.Rheostat.component_move (   self,
  widget,
  event,
  component 
)

Reimplemented from electric.Component.

Definition at line 1318 of file electric.py.

01318 
01319   def component_move(self, widget, event, component):
01320      super(Rheostat, self).component_move(widget, event, component)
01321 
01322      if(self.electric.get_current_tools()=="DEL"):
01323        return True
01324 
01325      self.wiper_item.set(
01326        x = self.x + self.wiper_ofset_x,
01327        y = self.y + self.wiper_ofset_y)
01328      self.update_wiper_wire()
01329 
01330      return True

Here is the call graph for this function:

def electric.Rheostat.component_scroll (   self,
  widget,
  event 
)

Definition at line 1300 of file electric.py.

01300 
01301   def component_scroll(self, widget, event):
01302     if event.type == gtk.gdk.SCROLL:
01303       if event.direction == gtk.gdk.SCROLL_UP:
01304         self.move_wiper(self.y - 5)
01305       elif event.type == gtk.gdk.SCROLL_DOWN:
01306         self.move_wiper(self.y + 5)
01307     return True

Here is the call graph for this function:

def electric.Component.create_wire (   self,
  widget,
  event,
  node 
) [inherited]

Definition at line 887 of file electric.py.

00887 
00888     def create_wire(self, widget, event, node):
00889 
00890       if(self.electric.get_current_tools()=="DEL"):
00891         return True
00892 
00893       if event.type == gtk.gdk.BUTTON_PRESS:
00894         if event.button == 1:
00895           bounds = widget.get_bounds()
00896           self.pos_x = (bounds[0]+bounds[2])/2
00897           self.pos_y = (bounds[1]+bounds[3])/2
00898           self.wire = Wire(self.electric, node,
00899                            self.pos_x, self.pos_y, event.x, event.y)
00900           node.add_wire(self.wire)
00901           return True
00902 
00903       if event.type == gtk.gdk.MOTION_NOTIFY:
00904         if event.state & gtk.gdk.BUTTON1_MASK:
00905           self.wire.move_target_node(event.x, event.y)
00906 
00907       if event.type == gtk.gdk.BUTTON_RELEASE:
00908         if event.button == 1:
00909           node_target = None
00910           # Our wire line confuses the get_item_at. Look arround.
00911           for x in range(-10, 11, 5):
00912             target_item = self.canvas.get_item_at(event.x + x, event.y)
00913             if target_item:
00914               node_target = target_item.get_data('node')
00915               if(node_target):
00916                 break
00917 
00918           # Take care not to wire the same component or 2 times the same node
00919           if(not node_target
00920              or node.get_component() == node_target.get_component()
00921              or node_target.has_wire(self.wire)):
00922             node.remove_wire(self.wire, None)
00923             self.wire.destroy()
00924           else:
00925             self.wire.set_target_node(node_target)
00926             node_target.add_wire(self.wire)
00927             self.electric.run_simulation()
00928 
00929           return True
00930 
00931       return False
00932 
00933 # -----------------------------------------------------------------------
00934 # -----------------------------------------------------------------------
00935 # -----------------------------------------------------------------------
00936 #
00937 # Pre defined components
00938 # ----------------------
00939 #
00940 
00941 # ----------------------------------------
00942 # RESISTOR
00943 #
#
def electric.Component.destroy (   self) [inherited]

Definition at line 810 of file electric.py.

00810 
00811     def destroy(self):
00812       try:
00813         # Remove ourself from the list of gnucap aware components
00814         self.electric.components.remove(self)
00815       except:
00816         pass
00817 
00818       for node in self.nodes:
00819         while node.get_wires():
00820           wire = node.get_wires()[0]
00821           node.remove_wire(wire, None)
00822           wire.destroy()
00823 
00824       self.comp_rootitem.destroy()

Here is the caller graph for this function:

def electric.Component.get_nodes (   self) [inherited]

Definition at line 826 of file electric.py.

00826 
00827     def get_nodes(self):
00828       return self.nodes

def electric.Component.get_rootitem (   self) [inherited]

Definition at line 788 of file electric.py.

00788 
00789     def get_rootitem(self):
00790       return self.comp_rootitem

def electric.Component.hide (   self) [inherited]

Definition at line 807 of file electric.py.

00807 
00808     def hide(self):
00809       self.comp_rootitem.hide()

Reimplemented from electric.Component.

Definition at line 1336 of file electric.py.

01336 
01337   def is_connected(self):
01338     count = 0
01339     for node in self.nodes:
01340       if node.get_wires():
01341         count += 1
01342 
01343     if count >= 2:
01344       return True
01345 
01346     return False

def electric.Component.move (   self,
  x,
  y 
) [inherited]

Definition at line 791 of file electric.py.

00791 
00792     def move(self, x, y):
00793       self.x =  x - self.center_x
00794       self.y =  y - self.center_y
00795 
00796       self.item_values.set(x =  self.item_values_x + self.x,
00797                            y =  self.item_values_y + self.y)
00798 
00799       self.component_item.set(x =  self.x + self.component_item_offset_x,
00800                               y =  self.y + self.component_item_offset_y )
00801 
00802       for node in self.nodes:
00803         node.move( self.x,  self.y)

Here is the caller graph for this function:

def electric.Rheostat.move_wiper (   self,
  new_y 
)

Definition at line 1285 of file electric.py.

01285 
01286   def move_wiper(self, new_y):
01287     if(new_y>self.y+self.wiper_ofset_max_y):
01288       self.wiper_ofset_y = self.wiper_ofset_max_y
01289     elif(new_y<self.y+self.wiper_ofset_min_y):
01290       self.wiper_ofset_y = self.wiper_ofset_min_y
01291     else:
01292       self.wiper_ofset_y = new_y - self.y
01293 
01294     self.wiper_item.set(
01295       y = self.y + self.wiper_ofset_y,
01296       )
01297     self.update_wiper_wire()
01298     self.electric.run_simulation()

Here is the call graph for this function:

Here is the caller graph for this function:

def electric.Rheostat.set_voltage_intensity (   self,
  valid_value,
  voltage,
  intensity 
)

Reimplemented from electric.Component.

Definition at line 1422 of file electric.py.

01422 
01423   def set_voltage_intensity(self, valid_value, voltage, intensity):
01424     self.gnucap_current_resistor += 1
01425     if self.gnucap_current_resistor == 1:
01426       self.voltage = voltage
01427       self.intensity = intensity
01428       if(valid_value ):
01429         self.item_values.set(text="U=%.1fV\nI=%.2fA"%(voltage,intensity))
01430         self.item_values.show()
01431       else:
01432         self.item_values.hide()
01433 
01434     if self.gnucap_nb_resistor != 1:
01435       self.gnucap_current_resistor += 1
01436       if self.gnucap_current_resistor > self.gnucap_nb_resistor:
01437         self.gnucap_current_resistor = 0
01438         return True
01439     else:
01440       self.gnucap_current_resistor = 0
01441       return True
01442     return False
01443 
01444 # ----------------------------------------
01445 # BULB
01446 #
#
def electric.Component.show (   self) [inherited]

Definition at line 804 of file electric.py.

00804 
00805     def show(self):
00806       self.comp_rootitem.show()

Here is the caller graph for this function:

def electric.Rheostat.to_gnucap (   self,
  model 
)

Reimplemented from electric.Component.

Definition at line 1375 of file electric.py.

01375 
01376   def to_gnucap(self, model):
01377 
01378     gnucap = ["", ""]
01379 
01380     # reset set_voltage_intensity counter
01381     self.gnucap_current_resistor = 0
01382 
01383     gnucap_value = self.resitance * \
01384                    (self.wiper_ofset_y - self.wiper_ofset_min_y) / \
01385                    (self.wiper_ofset_max_y - self.wiper_ofset_min_y)
01386 
01387     # Main resistor
01388     if self.nodes[0].get_wires() and \
01389        not self.nodes[1].get_wires() and \
01390        self.nodes[2].get_wires():
01391       self.gnucap_nb_resistor = 1
01392       gnucap_resp = self.to_gnucap_res(self.gnucap_name + "_all", 0, 2,
01393                                        self.resitance)
01394       gnucap[0] += gnucap_resp[0]
01395       gnucap[1] += gnucap_resp[1]
01396       return [gnucap[0], gnucap[1]]
01397 
01398 
01399     self.gnucap_nb_resistor = 0
01400 
01401     # top resistor
01402     if self.nodes[0].get_wires() and \
01403        self.nodes[1].get_wires():
01404       self.gnucap_nb_resistor += 1
01405       gnucap_resp  = self.to_gnucap_res(self.gnucap_name + "_top", 0, 1,
01406                                         gnucap_value)
01407       gnucap[0] += gnucap_resp[0]
01408       gnucap[1] += gnucap_resp[1]
01409 
01410     # bottom resistor
01411     if self.nodes[1].get_wires() and \
01412        self.nodes[2].get_wires():
01413       self.gnucap_nb_resistor += 1
01414       gnucap_resp = self.to_gnucap_res(self.gnucap_name + "_bot", 1, 2,
01415                                        self.resitance - gnucap_value)
01416       gnucap[0] += gnucap_resp[0]
01417       gnucap[1] += gnucap_resp[1]
01418 
01419     return [gnucap[0], gnucap[1]]

Here is the call graph for this function:

def electric.Rheostat.to_gnucap_res (   self,
  gnucap_name,
  node_id1,
  node_id2,
  gnucap_value 
)

Definition at line 1349 of file electric.py.

01349 
01350   def to_gnucap_res(self, gnucap_name, node_id1, node_id2, gnucap_value):
01351     # Ignore the component if there is some unconnected nodes.
01352     for i in (node_id1, node_id2):
01353       node = self.nodes[i]
01354       if not node.get_wires():
01355         gnucap = "* %s: component ignored: not connected\n" %(gnucap_name)
01356         return [gnucap, ""]
01357 
01358     gnucap = gnucap_name
01359     gnucap += " "
01360 
01361     for i in (node_id1, node_id2):
01362       node = self.nodes[i]
01363       if node.get_wires():
01364         gnucap += str(node.get_wires()[0].get_wire_id())
01365 
01366       gnucap += " "
01367 
01368     gnucap += " "
01369     gnucap += str(gnucap_value)
01370     gnucap += "\n"
01371 
01372     return [gnucap, ".print dc + v(%s) i(%s)\n" %(gnucap_name, gnucap_name)]

Here is the caller graph for this function:

Definition at line 1278 of file electric.py.

01278 
01279   def update_wiper_wire(self):
01280     self.wiper_wire_item.set(
01281       points = (self.x + self.wiper_ofset_x + 35,
01282                 self.y + self.wiper_ofset_y + 10,
01283                 self.x + 55,
01284                 self.y + 65))

Here is the caller graph for this function:


Member Data Documentation

Definition at line 718 of file electric.py.

Definition at line 743 of file electric.py.

Definition at line 744 of file electric.py.

Definition at line 732 of file electric.py.

Definition at line 748 of file electric.py.

Definition at line 746 of file electric.py.

Reimplemented in electric.Switch2.

Definition at line 747 of file electric.py.

int electric.Component.counter = 0 [static, inherited]

Definition at line 713 of file electric.py.

Definition at line 717 of file electric.py.

Definition at line 1236 of file electric.py.

Definition at line 722 of file electric.py.

Definition at line 1237 of file electric.py.

Reimplemented in electric.Bulb, and electric.Switch.

Definition at line 728 of file electric.py.

string electric.Rheostat.icon = "electric/resistor_track_icon.png" [static]

Definition at line 1233 of file electric.py.

string electric.Rheostat.image = "electric/resistor_track.png" [static]

Reimplemented from electric.Component.

Definition at line 1232 of file electric.py.

Reimplemented from electric.Component.

Definition at line 1426 of file electric.py.

Definition at line 764 of file electric.py.

Reimplemented from electric.Component.

Definition at line 1252 of file electric.py.

Reimplemented from electric.Component.

Definition at line 1253 of file electric.py.

Definition at line 730 of file electric.py.

Definition at line 895 of file electric.py.

Definition at line 896 of file electric.py.

Definition at line 1242 of file electric.py.

Definition at line 719 of file electric.py.

Reimplemented from electric.Component.

Definition at line 1425 of file electric.py.

Definition at line 1268 of file electric.py.

Definition at line 1240 of file electric.py.

Definition at line 1239 of file electric.py.

Definition at line 1238 of file electric.py.

Definition at line 1241 of file electric.py.

Definition at line 1259 of file electric.py.

Definition at line 897 of file electric.py.

electric.Component.x [inherited]

Definition at line 741 of file electric.py.

electric.Component.y [inherited]

Definition at line 742 of file electric.py.


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