/[ascend]/trunk/pygtk/canvas/blockitem.py
ViewVC logotype

Diff of /trunk/pygtk/canvas/blockitem.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1978 by jpye, Sat Dec 27 07:19:35 2008 UTC revision 1979 by jpye, Sat Jan 10 00:21:37 2009 UTC
# Line 7  from gaphas.solver import solvable, WEAK Line 7  from gaphas.solver import solvable, WEAK
7  from gaphas.state import observed, reversible_method, reversible_pair, reversible_property, disable_dispatching  from gaphas.state import observed, reversible_method, reversible_pair, reversible_property, disable_dispatching
8  from gaphas.geometry import distance_rectangle_point  from gaphas.geometry import distance_rectangle_point
9    
10    from blockport import BlockPort
11    from blockinstance import PORT_IN, PORT_OUT
12    
13  class ElementNoPorts(Item):  class ElementNoPorts(Item):
14      """      """
15      This is a copy of the Element class, but without the declaration      This is a copy of the Element class, but without the declaration
# Line 197  class DefaultBlockItem(BlockItem): Line 200  class DefaultBlockItem(BlockItem):
200      def __init__(self, blockinstance):      def __init__(self, blockinstance):
201    
202          self.blockinstance = blockinstance          self.blockinstance = blockinstance
         inputs = len(blockinstance.blocktype.inputs)  
         outputs = len(blockinstance.blocktype.outputs)  
203          super(DefaultBlockItem, self).__init__(64, 64)          super(DefaultBlockItem, self).__init__(64, 64)
204    
205          eq = EqualsConstraint          eq = EqualsConstraint
# Line 209  class DefaultBlockItem(BlockItem): Line 210  class DefaultBlockItem(BlockItem):
210          h_sw = handles[SW]          h_sw = handles[SW]
211          h_se = handles[SE]          h_se = handles[SE]
212    
213            ninputs = len(blockinstance.blocktype.inputs)
214            noutputs = len(blockinstance.blocktype.outputs)
215            ii, oi = (0,0) # input and output index counters
216          _ports = []          _ports = []
217          for i in range(inputs):          for i in self.blockinstance.ports:
218              p = PointPort(VariablePoint((0,0),strength=WEAK))              p = BlockPort(blockinstance, i)
219              self._constraints.append(eq(p.point.x, h_nw.x))              if self.blockinstance.ports[i].type is PORT_IN:
220              self._constraints.append(bal(band=(h_nw.y, h_sw.y),v=p.point.y, balance=(0.5 + i)/inputs))                  self._constraints.append(eq(p.point.x, h_nw.x))
221              _ports.append(p)                  self._constraints.append(bal(band=(h_nw.y, h_sw.y),v=p.point.y, balance=(0.5 + ii)/ninputs))
222                    ii += 1
223          for i in range(outputs):              elif self.blockinstance.ports[i].type is PORT_OUT:
224              p = PointPort(VariablePoint((0,0),strength=WEAK))                  self._constraints.append(eq(p.point.x, h_ne.x))
225                    self._constraints.append(bal(band=(h_ne.y,h_se.y),v=p.point.y, balance=(0.5 + oi)/noutputs))
226                    oi += 1
227                else:
228                    raise RuntimeError("Unknown port type")
229              _ports.append(p)              _ports.append(p)
             self._constraints.append(eq(p.point.x, h_ne.x))  
             self._constraints.append(bal(band=(h_ne.y,h_se.y),v=p.point.y, balance=(0.5 + i)/outputs))  
230    
231          self._ports = _ports          self._ports = _ports
232    

Legend:
Removed from v.1978  
changed lines
  Added in v.1979

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22