[Avida-cvs] [avida-svn] r750 - branches/developers/avida-edward/source/python/AvidaGui2

avidaedward@myxo.css.msu.edu avidaedward at myxo.css.msu.edu
Thu Jun 15 13:38:43 PDT 2006


Author: avidaedward
Date: 2006-06-15 16:38:43 -0400 (Thu, 15 Jun 2006)
New Revision: 750

Modified:
   branches/developers/avida-edward/source/python/AvidaGui2/pyOrganismScopeView2.py
Log:

In organism scope, organism divide is now animated, and heads are
displayed.



Modified: branches/developers/avida-edward/source/python/AvidaGui2/pyOrganismScopeView2.py
===================================================================
--- branches/developers/avida-edward/source/python/AvidaGui2/pyOrganismScopeView2.py	2006-06-14 17:08:32 UTC (rev 749)
+++ branches/developers/avida-edward/source/python/AvidaGui2/pyOrganismScopeView2.py	2006-06-15 20:38:43 UTC (rev 750)
@@ -7,6 +7,57 @@
 from qtcanvas import *
 import math
 
+class pyCircle:
+  def __init__(self):
+    self.setNumPoints(1)
+    self.setRadius(0.)
+    self.setCenterX(0.)
+    self.setCenterY(0.)
+    self.setOTheta(0.)
+  def setNumPoints(self, pts):
+    self.m_num_points = pts
+    self.setDTheta(2.*math.pi/self.m_num_points)
+  def setRadius(self, r):
+    self.m_radius = r
+  def setCenterX(self, x):
+    self.m_center_x = x
+  def setCenterY(self, y):
+    self.m_center_y = y
+  def setDTheta(self, d):
+    self.m_d_theta = d
+  def setOTheta(self, o):
+    self.m_o_theta = o
+  def numPoints(self):
+    return self.m_num_points
+  def radius(self):
+    return self.m_radius
+  def centerX(self):
+    return self.m_center_x
+  def centerY(self):
+    return self.m_center_y
+  def oTheta(self):
+    return self.m_o_theta
+  def dTheta(self):
+    return self.m_d_theta
+
+class pyInstructionPoint:
+  def __init__(self):
+    self.setHidden(True)
+    self.setCircle(None)
+    self.setPosition(0)
+  def setHidden(self, is_hidden):
+    self.m_hidden = is_hidden
+  def setCircle(self, circle):
+    self.m_circle = circle
+  def setPosition(self, position):
+    self.m_position = position
+  def hidden(self):
+    return self.m_hidden
+  def circle(self):
+    return self.m_circle
+  def position(self):
+    return self.m_position
+
 def checkDimensions(outer_diameter, n):
   print "checkDimensions(outer_diameter: %d, n: %d)" % (outer_diameter, n)
   sin_n = math.sin(math.pi/n)
@@ -129,17 +180,22 @@
 
     self.m_visible_width = 1
     self.m_visible_height = 1
+    self.m_parent_circle = pyCircle()
+    self.m_child_circle = pyCircle()
 
     self.reset()
 
   def reset(self):
     print "pyOrganismScopeView2.reset()..."
 
-    if hasattr(self, "m_instruction_items") and self.m_instruction_items is not None:
-      for item in self.m_instruction_items:
+    if hasattr(self, "m_inst_pts") and self.m_inst_pts is not None:
+      for item in self.m_inst_pts:
+        item.setCircle(None)
+    if hasattr(self, "m_inst_items") and self.m_inst_items is not None:
+      for item in self.m_inst_items:
         item.setCanvas(None)
-    if hasattr(self, "m_instruction_bg_items") and self.m_instruction_bg_items is not None:
-      for item in self.m_instruction_bg_items:
+    if hasattr(self, "m_inst_bg_items") and self.m_inst_bg_items is not None:
+      for item in self.m_inst_bg_items:
         item.setCanvas(None)
     if hasattr(self, "m_ihead_move_items") and self.m_ihead_move_items is not None:
       for item in self.m_ihead_move_items:
@@ -153,8 +209,9 @@
     if hasattr(self, "m_fhead_item") and self.m_fhead_item is not None:
       self.m_fhead_item.setCanvas(None)
 
-    self.m_instruction_items = None
-    self.m_instruction_bg_items = None
+    self.m_inst_pts = None
+    self.m_inst_items = None
+    self.m_inst_bg_items = None
     self.m_ihead_move_items = None
     self.m_ihead_item = None
     self.m_rhead_item = None
@@ -212,46 +269,43 @@
       self.m_child_size = max(0, last_copied_instruction - self.m_parent_size + 1)
       print "parent_size %d, max_genome_size %d" % (self.m_parent_size, self.m_max_genome_size)
 
-      self.updateCircle()
+      self.updateParentCircle()
 
-      text_height = 2. * self.m_spot_radius
+      text_height = 2. * self.m_instruction_spot_radius
       font = QFont(self.font())
       point_size_float = self.m_font_oversize_factor * text_height * self.m_font_points_per_pixel
       font.setPointSizeFloat(point_size_float)
 
-      self.m_instruction_items = [QCanvasText(self.m_canvas) for i in xrange(self.m_max_genome_size)]
-      self.m_instruction_bg_items = [QCanvasEllipse(self.m_canvas) for i in xrange(self.m_max_genome_size)]
-      for item in self.m_instruction_items:
+      self.m_inst_pts = [pyInstructionPoint() for i in xrange(self.m_max_genome_size)]
+      self.m_inst_items = [QCanvasText(self.m_canvas) for i in xrange(self.m_max_genome_size)]
+      self.m_inst_bg_items = [QCanvasEllipse(self.m_canvas) for i in xrange(self.m_max_genome_size)]
+      for item in self.m_inst_items:
         item.setTextFlags(Qt.AlignCenter)
-        item.setZ(1.)
-      for item in self.m_instruction_bg_items:
+        item.setZ(3.)
+      for item in self.m_inst_bg_items:
         item.setSize(text_height, text_height)
-        item.setZ(0.)
+        item.setZ(2.)
 
       if self.m_frames.m_ihead_info is not None:
-        self.m_ihead_item = QCanvasText(self.m_canvas)
-        self.m_ihead_item.setTextFlags(Qt.AlignCenter)
+        self.m_ihead_item = QCanvasEllipse(self.m_canvas)
+        self.m_ihead_item.setSize(text_height + 6, text_height + 6)
         self.m_ihead_item.setZ(1.)
-        self.m_ihead_item.setFont(font)
-        self.m_ihead_item.setText('i')
+        self.m_ihead_item.setBrush(QBrush(Qt.blue))
       if self.m_frames.m_rhead_info is not None:
-        self.m_rhead_item = QCanvasText(self.m_canvas)
-        self.m_rhead_item.setTextFlags(Qt.AlignCenter)
+        self.m_rhead_item = QCanvasEllipse(self.m_canvas)
+        self.m_rhead_item.setSize(text_height + 6, text_height + 6)
         self.m_rhead_item.setZ(1.)
-        self.m_rhead_item.setFont(font)
-        self.m_rhead_item.setText('r')
+        self.m_rhead_item.setBrush(QBrush(Qt.green))
       if self.m_frames.m_whead_info is not None:
-        self.m_whead_item = QCanvasText(self.m_canvas)
-        self.m_whead_item.setTextFlags(Qt.AlignCenter)
+        self.m_whead_item = QCanvasEllipse(self.m_canvas)
+        self.m_whead_item.setSize(text_height + 6, text_height + 6)
         self.m_whead_item.setZ(1.)
-        self.m_whead_item.setFont(font)
-        self.m_whead_item.setText('w')
+        self.m_whead_item.setBrush(QBrush(Qt.red))
       if self.m_frames.m_fhead_info is not None:
-        self.m_fhead_item = QCanvasText(self.m_canvas)
-        self.m_fhead_item.setTextFlags(Qt.AlignCenter)
+        self.m_fhead_item = QCanvasEllipse(self.m_canvas)
+        self.m_fhead_item.setSize(text_height + 6, text_height + 6)
         self.m_fhead_item.setZ(1.)
-        self.m_fhead_item.setFont(font)
-        self.m_fhead_item.setText('f')
+        self.m_fhead_item.setBrush(QBrush(Qt.cyan))
 
       # XXX
       ###if self.m_frames.m_ihead_moves is not None:
@@ -275,11 +329,11 @@
       self.m_canvas.resize(resize_event.size().width(), resize_event.size().height())
       self.m_visible_width = resize_event.size().width()
       self.m_visible_height = resize_event.size().height()
-      self.updateCircle()
+      self.updateParentCircle()
       self.showFrame(self.m_current_frame_number)
 
-  def updateCircle(self):
-    print "pyOrganismScopeView2.updateCircle()..."
+  def updateParentCircle(self):
+    print "pyOrganismScopeView2.updateParentCircle()..."
 
     if self.m_frames is not None:
       extra_width_factor = float(self.m_parent_size + self.m_child_size)/self.m_parent_size
@@ -287,50 +341,33 @@
       n = max(self.m_parent_size, self.m_child_size)
       bounded_width = self.m_visible_width - 2.*self.m_organism_circle_margin
       bounded_height = self.m_visible_height - 2.*self.m_organism_circle_margin
-      self.outer_diameter = min(bounded_width/extra_width_factor, bounded_height)
-      R, r = checkDimensions(self.outer_diameter, n)
-      c_x = self.outer_diameter/2.
-      c_y = self.m_visible_height/2.
-      print "R, r, c_x, c_y, extra_width_factor, outer_diameter:", R, r, c_x, c_y, extra_width_factor, self.outer_diameter
+      outer_diameter = min(bounded_width/extra_width_factor, bounded_height)
 
-      self.m_circle_center_x = self.outer_diameter/2.
-      self.m_circle_center_y = self.m_visible_height/2.
-      self.m_circle_radius = R
-      self.m_spot_radius = r
-      if self.m_instruction_items is not None:
-        text_height = 2. * self.m_spot_radius
+      radius, self.m_instruction_spot_radius = checkDimensions(outer_diameter, n)
+      self.m_parent_circle.setRadius(radius)
+      self.m_parent_circle.setCenterX(outer_diameter/2.)
+      self.m_parent_circle.setCenterY(self.m_visible_height/2.)
+      self.m_parent_circle.setNumPoints(self.m_parent_size)
+      self.m_parent_circle.setOTheta(0.)
+
+      if self.m_inst_items is not None:
+        text_height = 2. * self.m_instruction_spot_radius
         font = QFont(self.font())
         point_size_float = self.m_font_oversize_factor * text_height * self.m_font_points_per_pixel
         font.setPointSizeFloat(point_size_float)
-        for item in self.m_instruction_items:
+        for item in self.m_inst_items:
           item.setFont(font)
-        for item in self.m_instruction_bg_items:
+        for item in self.m_inst_bg_items:
           item.setSize(point_size_float, point_size_float)
-        #self.m_circles = []
-        #self.m_head_circles = []
-        #self.m_circle_radii = []
-        #for frame_no in xrange(self.m_frames.m_gestation_time):
-        #  organism_current_size = max(self.m_frames.m_last_copy_info[frame_no] + 1, self.m_frames.m_size)
-        #  circumference = text_height * organism_current_size
-        #  radius = circumference / (2 * 3.14159)
-        #  dt = 2 * 3.14159 / (organism_current_size + 1)
-        #  angle_offset = 3.14159 / 2
-        #  circle_pts = []
-        #  head_circle_pts = []
-        #  for i in xrange(organism_current_size + 1):
-        #    theta = i * dt + angle_offset
-        #    c = math.cos(theta)
-        #    s = -math.sin(theta)
-        #    x = radius * c + self.m_circle_center_x
-        #    y = radius * s + self.m_circle_center_y
-        #    h_x = (radius + 10) * c + self.m_circle_center_x
-        #    h_y = (radius + 10) * s + self.m_circle_center_y
-        #    circle_pts.append((x,y))
-        #    head_circle_pts.append((h_x,h_y))
-        #  self.m_circles.append(circle_pts)
-        #  self.m_head_circles.append(head_circle_pts)
-        #  self.m_circle_radii.append(radius)
 
+  def updateChildCircle(self, child_size, parent_size, parent_circle_radius, parent_center_x, parent_center_y, instruction_spot_radius):
+    print "pyOrganismScopeView2.updateChildCircle()..."
+    self.m_child_circle.setRadius(parent_circle_radius * child_size / parent_size)
+    self.m_child_circle.setCenterX(parent_center_x + parent_circle_radius + 2*instruction_spot_radius + self.m_child_circle.radius())
+    self.m_child_circle.setCenterY(parent_center_y)
+    self.m_child_circle.setNumPoints(child_size)
+    self.m_child_circle.setOTheta(math.pi)
+
   def debug_displayHardwareCPUSnapshot(self, frame_number):
     print "pyOrganismScopeView2.debug_displayHardwareCPUSnapshot(%d)..." % frame_number
     hardware_snapshot = self.m_frames.getHardwareSnapshotAt(frame_number)
@@ -392,54 +429,128 @@
       self.m_current_frame_number = frame_number
       self.m_current_genome = self.m_frames.m_genome_info[self.m_current_frame_number]
       displayed_genome_size = max(self.last_copied_instruction_cache[self.m_current_frame_number] + 1, self.m_parent_size)
-      theta = 2.*math.pi/self.m_parent_size
       color = QColor()
 
+      current_child_size = displayed_genome_size - self.m_parent_size
+      if current_child_size > 0:
+        self.updateChildCircle(
+          current_child_size,
+          self.m_parent_size,
+          self.m_parent_circle.radius(),
+          self.m_parent_circle.centerX(),
+          self.m_parent_circle.centerY(),
+          self.m_instruction_spot_radius
+        )
+        self.m_child_circle.setDTheta(-self.m_child_circle.dTheta())
+
       for i in xrange(self.m_parent_size):
-        x = self.m_circle_radius*math.cos(i * theta) + self.m_circle_center_x
-        y = self.m_circle_radius*math.sin(i * theta) + self.m_circle_center_y
+        pt = self.m_inst_pts[i]
+        pt.setHidden(False)
+        pt.setCircle(self.m_parent_circle)
+        pt.setPosition(i)
+      for i in xrange(current_child_size):
+        pt = self.m_inst_pts[i + self.m_parent_size]
+        pt.setHidden(False)
+        pt.setCircle(self.m_child_circle)
+        pt.setPosition(i)
+      for i in xrange(displayed_genome_size, self.m_max_genome_size):
+        pt = self.m_inst_pts[i]
+        pt.setHidden(True)
 
-        item = self.m_instruction_items[i]
-        item.setX(x)
-        item.setY(y)
-        item.setText(self.m_current_genome[i])
-        item.show()
+      if self.m_current_frame_number >= (self.m_frames.m_gestation_time - 1) and self.m_frames.m_is_viable:
+        self.m_child_circle.setCenterX(self.m_child_circle.centerX() + 2 * self.m_instruction_spot_radius)
 
-        bg_item = self.m_instruction_bg_items[i]
-        bg_item.setX(x)
-        bg_item.setY(y)
-        color.setHsv((self.m_ops_dict[self.m_current_genome[i]] * 360) / len(self.m_ops_dict), 85, 248)
-        bg_item.setBrush(QBrush(color))
-        bg_item.show()
+      ###
+      for i in xrange(self.m_max_genome_size):
+        pt = self.m_inst_pts[i]
+        item = self.m_inst_items[i]
+        bg_item = self.m_inst_bg_items[i]
+        if pt.hidden():
+          item.hide()
+          bg_item.hide()
+        else:
+          theta = pt.circle().oTheta() + pt.position() * pt.circle().dTheta()
+          x = pt.circle().radius()*math.cos(theta) + pt.circle().centerX()
+          y = pt.circle().radius()*math.sin(theta) + pt.circle().centerY()
 
-      current_child_size = displayed_genome_size - self.m_parent_size
-      if current_child_size > 0:
-        current_child_radius = self.m_circle_radius * current_child_size / self.m_parent_size
-        current_child_center_x = self.m_circle_center_x + self.m_circle_radius + 2*self.m_spot_radius + current_child_radius
-        current_child_center_y = self.m_circle_center_y
-        theta = 2.*math.pi/current_child_size
-        for i in xrange(current_child_size):
-          x = current_child_radius*math.cos(i * theta + math.pi) + current_child_center_x
-          y = current_child_radius*math.sin(i * theta + math.pi) + current_child_center_y
-
-          item = self.m_instruction_items[i + self.m_parent_size]
           item.setX(x)
           item.setY(y)
-          item.setText(self.m_current_genome[i + self.m_parent_size])
+          item.setText(self.m_current_genome[i])
           item.show()
 
-          bg_item = self.m_instruction_bg_items[i + self.m_parent_size]
           bg_item.setX(x)
           bg_item.setY(y)
-          color.setHsv((self.m_ops_dict[self.m_current_genome[i + self.m_parent_size]] * 360) / len(self.m_ops_dict), 85, 248)
+          color.setHsv((self.m_ops_dict[self.m_current_genome[i]] * 360) / len(self.m_ops_dict), 85, 248)
           bg_item.setBrush(QBrush(color))
           bg_item.show()
 
-      for i in xrange(displayed_genome_size, self.m_max_genome_size):
-        item = self.m_instruction_items[i]
-        item.hide()
-        bg_item = self.m_instruction_bg_items[i]
-        bg_item.hide()
+      if self.m_frames.m_ihead_info is not None:
+        head_item = self.m_ihead_item
+        head = self.m_frames.m_ihead_info[self.m_current_frame_number]
+        if displayed_genome_size < head:
+          head = -1
+        pt = self.m_inst_pts[head]
+        if pt.hidden():
+          head_item.hide()
+        else:
+          theta = pt.circle().oTheta() + pt.position() * pt.circle().dTheta()
+          x = pt.circle().radius()*math.cos(theta) + pt.circle().centerX()
+          y = pt.circle().radius()*math.sin(theta) + pt.circle().centerY()
 
+          head_item.setX(x)
+          head_item.setY(y)
+          head_item.show()
+
+      if self.m_frames.m_rhead_info is not None:
+        head_item = self.m_rhead_item
+        head = self.m_frames.m_rhead_info[self.m_current_frame_number]
+        if displayed_genome_size < head:
+          head = -1
+        pt = self.m_inst_pts[head]
+        if pt.hidden():
+          head_item.hide()
+        else:
+          theta = pt.circle().oTheta() + pt.position() * pt.circle().dTheta()
+          x = pt.circle().radius()*math.cos(theta) + pt.circle().centerX()
+          y = pt.circle().radius()*math.sin(theta) + pt.circle().centerY()
+
+          head_item.setX(x)
+          head_item.setY(y)
+          head_item.show()
+
+      if self.m_frames.m_whead_info is not None:
+        head_item = self.m_whead_item
+        head = self.m_frames.m_whead_info[self.m_current_frame_number]
+        if displayed_genome_size < head:
+          head = -1
+        pt = self.m_inst_pts[head]
+        if pt.hidden():
+          head_item.hide()
+        else:
+          theta = pt.circle().oTheta() + pt.position() * pt.circle().dTheta()
+          x = pt.circle().radius()*math.cos(theta) + pt.circle().centerX()
+          y = pt.circle().radius()*math.sin(theta) + pt.circle().centerY()
+
+          head_item.setX(x)
+          head_item.setY(y)
+          head_item.show()
+
+      if self.m_frames.m_fhead_info is not None:
+        head_item = self.m_fhead_item
+        head = self.m_frames.m_fhead_info[self.m_current_frame_number]
+        if displayed_genome_size < head:
+          head = -1
+        pt = self.m_inst_pts[head]
+        if pt.hidden():
+          head_item.hide()
+        else:
+          theta = pt.circle().oTheta() + pt.position() * pt.circle().dTheta()
+          x = pt.circle().radius()*math.cos(theta) + pt.circle().centerX()
+          y = pt.circle().radius()*math.sin(theta) + pt.circle().centerY()
+
+          head_item.setX(x)
+          head_item.setY(y)
+          head_item.show()
+
     self.emit(PYSIGNAL("frameShownSig"),(self.m_frames, self.m_current_frame_number))
     self.m_canvas.update()




More information about the Avida-cvs mailing list