CMS 3D CMS Logo

Public Member Functions | Static Public Attributes | Private Attributes

python::Vispa::Views::LineDecayView::DecayLine Class Reference

Inheritance diagram for python::Vispa::Views::LineDecayView::DecayLine:
python::Vispa::Views::LineDecayView::DecayObject

List of all members.

Public Member Functions

def __init__
def arrowBoundingRect
def boundingRect
def containsPoint
def dataAccessor
def daughterNode
def delete
def drawArrow
def drawText
def extendedSize
def labelBoundingRect
def length
def lineWidth
def motherNode
def move
def nodeType
def object
def paint
def qtLineStyle
def replaceNode
def select
def setColor
def setLabel
def setLineStyle
def setObject
def setShowLabel
def setZoom
def slope
def transform

Static Public Attributes

int ARROW_LENGTH = 14
int ARROW_WIDTH = 8
int DEFAULT_LENGTH = 70
int HUNDREDEIGHTY_OVER_PI = 180
int LABEL_OFFSET = 7
int LINE_WIDTH = 2

Private Attributes

 _arrowBoundingRect
 _boundingRect
 _color
 _endNode
 _forwardDirection
 _label
 _labelBoundingRect
 _labelFont
 _labelMatrix
 _lineStyle
 l = (n + 1/2) * r * 2 * math.pi
 _pxlObject
 _recalculateBoundingRect
 _recalculateTransform
 _selfContained
 _showLabel
 _startNode
 _transform

Detailed Description

Definition at line 1185 of file LineDecayView.py.


Constructor & Destructor Documentation

def python::Vispa::Views::LineDecayView::DecayLine::__init__ (   self,
  parent,
  startPointOrNode,
  endPointOrNode 
)

Definition at line 1197 of file LineDecayView.py.

01198                                                                 :
01199         self._color = QColor(176, 179, 177)
01200         self._lineStyle = Qt.SolidLine
01201         self._label = None
01202         self._labelFont = None
01203         self._showLabel = True
01204         self._labelMatrix = None
01205         self._labelBoundingRect = None
01206         self._recalculateBoundingRect = True
01207         self._boundingRect = None
01208         self._arrowBoundingRect = None
01209         self._forwardDirection = True
01210         self._recalculateTransform = True
01211         self._transform = None
01212         self._pxlObject = None
01213         
01214         DecayObject.__init__(self, parent)
01215         
01216         if isinstance(parent, LineDecayContainer):
01217             self._selfContained = False
01218             if isinstance(startPointOrNode, QPoint):
01219                 # startPoint
01220                 self._startNode = parent.addDecayNode(startPointOrNode)
01221             else:
01222                 # startNode
01223                 self._startNode = startPointOrNode
01224             if isinstance(endPointOrNode, QPoint):
01225                 # endPoint
01226                 self._endNode = parent.addDecayNode(endPointOrNode)
01227             else:
01228                 # endNode
01229                 self._endNode = endPointOrNode
01230         else:
01231             # make it possible to use DecayLine outside LineDecayContainer
01232             self._selfContained = True
01233             self._startNode = DecayNode(parent, startPointOrNode)
01234             self._endNode = DecayNode(parent, endPointOrNode)
01235         
01236         self._startNode.appendObject(self)
01237         self._endNode.appendObject(self)
        

Member Function Documentation

def python::Vispa::Views::LineDecayView::DecayLine::arrowBoundingRect (   self,
  forceRecalculation = False 
)

Definition at line 1512 of file LineDecayView.py.

01513                                                          :
01514         if not self._arrowBoundingRect or forceRecalculation:
01515             zoomFactor = self.zoomFactor()
01516             l = self.length(zoomed = True)
01517             arrowLength = self.ARROW_LENGTH * zoomFactor
01518             arrowWidth = self.ARROW_WIDTH * zoomFactor
01519             horizontalOffset = self.CONTAINS_AREA_SIZE * 0.4 * self.zoomFactor()    # offset from end of line
01520             if self._forwardDirection:
01521                 self._arrowBoundingRect = QRect(l-arrowLength - horizontalOffset, -arrowWidth, arrowLength, 2*arrowWidth)
01522             else:
01523                 self._arrowBoundingRect = QRect(horizontalOffset, -arrowWidth, arrowLength, 2*arrowWidth)
01524         
01525         return self._arrowBoundingRect
    
def python::Vispa::Views::LineDecayView::DecayLine::boundingRect (   self)

Reimplemented from python::Vispa::Views::LineDecayView::DecayObject.

Definition at line 1526 of file LineDecayView.py.

01527                           :
01528         if not self._recalculateBoundingRect and self._boundingRect:
01529             return self._boundingRect
01530         
01531         self._recalculateTransform = True
01532         contains_area_size = self.CONTAINS_AREA_SIZE
01533         if self.extendedSize():
01534             contains_area_size += 4
01535             
01536         zoomFactor = self.zoomFactor()
01537         offset = contains_area_size * zoomFactor
01538         startPoint = self._startNode.position() * zoomFactor
01539         endPoint = self._endNode.position() * zoomFactor
01540         
01541         topLeft = QPoint(min(startPoint.x(), endPoint.x()) - offset, min(startPoint.y(), endPoint.y()) - offset)
01542         bottomRight = QPoint(max(startPoint.x(), endPoint.x()) + offset, max(startPoint.y(), endPoint.y()) + offset) 
01543         
01544         rect = QRect(topLeft, bottomRight)
01545         
01546         # increase rect for label and arrow (shows when selected or hovered
01547         rect = rect.united(self.transform().mapRect(self.arrowBoundingRect(True)))
01548         if self._label and self._labelFont:
01549             rect = rect.united(self.transform().mapRect(self.labelBoundingRect(True)))
01550 
01551         self._boundingRect = rect
01552         return self._boundingRect
    
def python::Vispa::Views::LineDecayView::DecayLine::containsPoint (   self,
  pos 
)

Reimplemented from python::Vispa::Views::LineDecayView::DecayObject.

Definition at line 1566 of file LineDecayView.py.

01567                                 :
01568         pos = pos / self.zoomFactor()
01569 
01570         # label
01571         if self._label and self._labelFont and self.labelBoundingRect().contains(self.transform().inverted()[0].map(pos)):
01572             return True
01573         
01574         # line
01575         line_width = self.LINE_WIDTH + 1
01576         if self.extendedSize():
01577             line_width += 6
01578             
01579         if self._endNode.position().x() == self._startNode.position().x():
01580             # vertical
01581             if abs(pos.x() - self._endNode.position().x()) < line_width:
01582                 return True
01583             return False
01584     
01585         if pos.x() < (min(self._startNode.position().x(), self._endNode.position().x()) - line_width) or pos.x() > (max(self._startNode.position().x(), self._endNode.position().x()) + line_width):
01586             return False
01587         
01588         slope = self.slope()
01589         deltaY = slope * (pos.x() - self._startNode.position().x()) + self._startNode.position().y() - pos.y()
01590         if abs(deltaY) < 0.5* line_width * max(1, abs(slope)):
01591             return True
01592         return False
        
def python::Vispa::Views::LineDecayView::DecayLine::dataAccessor (   self)

Definition at line 1314 of file LineDecayView.py.

01315                           :
01316         if self.parent():
01317             return self.parent().dataAccessor()
01318         return None
    
def python::Vispa::Views::LineDecayView::DecayLine::daughterNode (   self)

Definition at line 1256 of file LineDecayView.py.

01257                           :
01258         return self._endNode
        
def python::Vispa::Views::LineDecayView::DecayLine::delete (   self)

Reimplemented from python::Vispa::Views::LineDecayView::DecayObject.

Definition at line 1243 of file LineDecayView.py.

01244                     :
01245         self._startNode.removeObject(self)
01246         self._endNode.removeObject(self)
01247         self.parent().removeObject(self._startNode)
01248         self.parent().removeObject(self._endNode)
01249         
01250         # remove this DecayObject's pxl particle from parent's pxl event / eventview
01251         self.parent().object().removeObject(self.object())
01252         return True
        
def python::Vispa::Views::LineDecayView::DecayLine::drawArrow (   self,
  painter,
  paintMode = 0x0 
)

Definition at line 1476 of file LineDecayView.py.

01477                                                :
01478         # make sure to stay within bounding rect, therefore add / substract arrowPixelOffset
01479         arrowPixelOffset =  0.7* self.lineWidth()
01480         arrowBoundingRect = self.arrowBoundingRect()
01481         arrowBoundingRectLeft = arrowBoundingRect.left() + arrowPixelOffset
01482         arrowBoundingRectRight = arrowBoundingRect.right() - arrowPixelOffset
01483         arrowBoundingRectTop = arrowBoundingRect.top() + arrowPixelOffset
01484         arrowBoundingRectBottom = arrowBoundingRect.bottom() - arrowPixelOffset
01485         arrowBoundingRectVerticalCenter = arrowBoundingRect.center().y()
01486         if self._forwardDirection:
01487             painter.drawLine(arrowBoundingRectLeft, arrowBoundingRectTop, arrowBoundingRectRight, arrowBoundingRectVerticalCenter)
01488             painter.drawLine(arrowBoundingRectLeft, arrowBoundingRectBottom, arrowBoundingRectRight, arrowBoundingRectVerticalCenter)
01489             
01490         else:
01491             painter.drawLine(arrowBoundingRectLeft, arrowBoundingRectVerticalCenter, arrowBoundingRectRight, arrowBoundingRectTop)
01492             painter.drawLine(arrowBoundingRectLeft, arrowBoundingRectVerticalCenter, arrowBoundingRectRight, arrowBoundingRectBottom)
01493         
        
def python::Vispa::Views::LineDecayView::DecayLine::drawText (   self,
  painter,
  paintMode = 0x0 
)
Draws self._label on given painter.

Expects coordinates of painter transformed as returned by transform()

Definition at line 1457 of file LineDecayView.py.

01458                                               :
01459         """ Draws self._label on given painter.
01460         
01461         Expects coordinates of painter transformed as returned by transform()
01462         """
01463         if not self._showLabel or not self._label:
01464             return
01465         
01466         if paintMode & DecayObject.PAINT_MODE_SELECTED:
01467             textColor = QColor(Qt.blue)
01468         elif paintMode & DecayObject.PAINT_MODE_HOVERED:
01469             textColor = QColor(Qt.gray)
01470         else:
01471             textColor = QColor(Qt.black)
01472 
01473         path = QPainterPath()
01474         path.addText(QPointF(self.labelBoundingRect().bottomLeft()), self._labelFont, self._label)
01475         painter.fillPath(path, textColor)
        
def python::Vispa::Views::LineDecayView::DecayLine::extendedSize (   self)
Returns True if instead of simple line a spiral or a sinus function is plotted.

Definition at line 1319 of file LineDecayView.py.

01320                           :
01321         """ Returns True if instead of simple line a spiral or a sinus function is plotted.
01322         """
01323         if not self.parent().dataAccessor():
01324             return False
01325         return self._lineStyle == self.parent().dataAccessor().LINE_STYLE_SPIRAL or self._lineStyle == self.parent().dataAccessor().LINE_STYLE_WAVE or self._lineStyle == self.parent().dataAccessor().LINE_VERTEX
        
def python::Vispa::Views::LineDecayView::DecayLine::labelBoundingRect (   self,
  forceRecalculation = False 
)

Definition at line 1494 of file LineDecayView.py.

01495                                                          :
01496         if not self._label or not self._labelFont:
01497             return QRect()
01498         
01499         if not self._labelBoundingRect or forceRecalculation:
01500             label_offset = self.LABEL_OFFSET
01501             if self.extendedSize():
01502                 label_offset += 2 
01503             
01504             fm = QFontMetrics(self._labelFont)
01505             self._labelBoundingRect = fm.boundingRect(self._label)
01506             
01507             labelWidth = self._labelBoundingRect.width()
01508             offset = QPointF(0.5 * (self.length(zoomed=True) - labelWidth), - label_offset * self.zoomFactor())
01509             self._labelBoundingRect.translate(offset.x(), offset.y())
01510             
01511         return self._labelBoundingRect
    
def python::Vispa::Views::LineDecayView::DecayLine::length (   self,
  zoomed = False 
)

Definition at line 1560 of file LineDecayView.py.

01561                                   :
01562         l = math.sqrt((self._endNode.x() - self._startNode.x())**2 + (self._endNode.y() - self._startNode.y())**2)
01563         if zoomed:
01564             return self.zoomFactor() * l
01565         return l
        
def python::Vispa::Views::LineDecayView::DecayLine::lineWidth (   self)

Definition at line 1311 of file LineDecayView.py.

01312                        :
01313         return self.LINE_WIDTH * self.zoomFactor()
    
def python::Vispa::Views::LineDecayView::DecayLine::motherNode (   self)

Definition at line 1253 of file LineDecayView.py.

01254                         :
01255         return self._startNode
    
def python::Vispa::Views::LineDecayView::DecayLine::move (   self,
  pos 
)

Reimplemented from python::Vispa::Views::LineDecayView::DecayObject.

Definition at line 1600 of file LineDecayView.py.

01601                        :
01602         self._startNode.move(pos)
01603         self._endNode.move(pos)
01604         self._recalculateBoundingRect = True

def python::Vispa::Views::LineDecayView::DecayLine::nodeType (   self,
  node 
)

Definition at line 1292 of file LineDecayView.py.

01293                             :
01294         if self._startNode == node:
01295             return DecayNode.TYPE_MOTHER
01296         if self._endNode == node:
01297             return DecayNode.TYPE_DAUGHTER
01298         return None
    
def python::Vispa::Views::LineDecayView::DecayLine::object (   self)

Reimplemented from python::Vispa::Views::LineDecayView::DecayObject.

Definition at line 1263 of file LineDecayView.py.

01264                     :
01265         return self._pxlObject
    
def python::Vispa::Views::LineDecayView::DecayLine::paint (   self,
  painter,
  paintMode = 0x0 
)

Reimplemented from python::Vispa::Views::LineDecayView::DecayObject.

Definition at line 1354 of file LineDecayView.py.

01355                                            :
01356         if paintMode & DecayObject.PAINT_MODE_SELECTED:
01357             penColor = QColor(Qt.blue)
01358         else:
01359             penColor = self._color
01360             if paintMode & DecayObject.PAINT_MODE_HOVERED:
01361                 penColor = penColor.lighter(80)
01362                 
01363         showDirectionArrow = paintMode & DecayObject.PAINT_MODE_HOVERED or paintMode & DecayObject.PAINT_MODE_SELECTED
01364         extendedSize = self.extendedSize()
01365         
01366         z = self.zoomFactor()
01367         l = self.length(zoomed = True)
01368         
01369         # transform coordinates to make following calculations easier
01370         painter.setTransform(self.transform())
01371         
01372         if extendedSize:
01373             painter.setPen(QPen(penColor, 0.5*self.lineWidth(), Qt.SolidLine))
01374             # spiral or wave line
01375             ## l = (n + 1/2) * r * 2 * math.pi
01376             designRadius = 1.2 * z
01377             # n: number of spirals
01378             n = max(int(1.0 * l / (2 * math.pi * designRadius)), 4)
01379             # r: radius of cycloide wheel
01380             r = 1.0 * l / (2 * math.pi * (n + 0.5))
01381             # a: cycloide is trace of point with radius a
01382             a = 3.5 * r
01383             
01384             if self.parent().dataAccessor() and self._lineStyle == self.parent().dataAccessor().LINE_STYLE_SPIRAL:
01385                 path = QPainterPath()
01386                 # draw spiral using a cycloide
01387                 # coordinates of center of wheel
01388                 xM = a
01389                 yM = 0
01390                 while xM < l:
01391                     phase = 1.0 * (xM-a)/r
01392                     x = xM - a * math.cos(phase)
01393                     y = yM - a * math.sin(phase)
01394                     if x > l:
01395                         x = l
01396                         #path.lineTo(QPointF(x, y))
01397                         break
01398                     path.lineTo(QPointF(x, y))
01399                     xM += 0.2 * r / z
01400                 painter.drawPath(path)
01401             elif self.parent().dataAccessor() and self._lineStyle == self.parent().dataAccessor().LINE_STYLE_WAVE:
01402                 path = QPainterPath()
01403                 x = a
01404                 while x < l - 0.5*a:
01405                     y = a * math.cos(x/r)
01406                     path.lineTo(QPointF(x, y))
01407                     x += 0.2 * r / z
01408                 painter.drawPath(path)
01409             elif self.parent().dataAccessor() and self._lineStyle == self.parent().dataAccessor().LINE_VERTEX:
01410                 painter.setBrush(QBrush(penColor, Qt.SolidPattern))
01411                 painter.drawEllipse(QPointF(l/2.,0.),l/2.,a)
01412 
01413         else:
01414             painter.setPen(QPen(penColor, self.lineWidth(), self.qtLineStyle()))
01415             painter.drawLine(QPoint(0,0), QPoint(l, 0))
01416             
01417         if not paintMode & DecayObject.PAINT_MODE_NO_DECORATIONS:
01418             self.drawText(painter, paintMode)
01419             
01420         # paint arrow lines
01421         if showDirectionArrow:
01422             painter.setPen(QPen(penColor, 0.8*self.lineWidth(), Qt.SolidLine, Qt.RoundCap))
01423             self.drawArrow(painter, paintMode)
01424         
01425         ## DEBUG
01426         #painter.setPen(QPen(penColor, 1, Qt.SolidLine))
01427         #painter.drawRect(self.labelBoundingRect())
01428         #painter.drawRect(self.arrowBoundingRect())
01429         
01430         painter.resetTransform()
01431         #painter.drawRect(self.boundingRect())
01432         
01433         if self._selfContained:
01434             self._startNode.paint(painter, paintMode)
01435             self._endNode.paint(painter, paintMode)
            
def python::Vispa::Views::LineDecayView::DecayLine::qtLineStyle (   self)

Definition at line 1266 of file LineDecayView.py.

01267                          :
01268         if not self.parent().dataAccessor():
01269             return Qt.SolidLine
01270         if self._lineStyle == self.parent().dataAccessor().LINE_STYLE_DASH:
01271             return Qt.DashLine
01272         elif self._lineStyle == self.parent().dataAccessor().LINE_STYLE_SOLID:
01273             return Qt.SolidLine
01274         return None
    
def python::Vispa::Views::LineDecayView::DecayLine::replaceNode (   self,
  oldNode,
  newNode 
)

Definition at line 1299 of file LineDecayView.py.

01300                                            :
01301         if self._startNode == oldNode:
01302             self._startNode.removeObject(self)
01303             self._startNode = newNode
01304             self._startNode.appendObject(self)
01305         if self._endNode == oldNode:
01306             self._endNode.removeObject(self)
01307             self._endNode = newNode
01308             self._endNode.appendObject(self)
01309         self._recalculateBoundingRect = True
01310         return self.nodeType(newNode)
    
def python::Vispa::Views::LineDecayView::DecayLine::select (   self,
  pos = None,
  selected = True 
)

Reimplemented from python::Vispa::Views::LineDecayView::DecayObject.

Definition at line 1593 of file LineDecayView.py.

01594                                              :
01595         if not pos:
01596             pos = (self._startNode.position() + self._endNode.position()) * 0.5
01597         self._startNode.select(pos)
01598         self._endNode.select(pos)
01599         self._recalculateBoundingRect = True
        
def python::Vispa::Views::LineDecayView::DecayLine::setColor (   self,
  color 
)

Definition at line 1279 of file LineDecayView.py.

01280                              :
01281         self._color = color
01282         self._recalculateBoundingRect = True
        
def python::Vispa::Views::LineDecayView::DecayLine::setLabel (   self,
  label 
)

Definition at line 1283 of file LineDecayView.py.

01284                              :
01285         self._label = label
01286         if not self._labelFont:
01287             self._labelFont = QFont()
01288             self._labelFont.setPointSize(12 * self.zoomFactor())
        
def python::Vispa::Views::LineDecayView::DecayLine::setLineStyle (   self,
  style 
)

Definition at line 1275 of file LineDecayView.py.

01276                                  :
01277         self._lineStyle = style
01278         self._recalculateBoundingRect = True
        
def python::Vispa::Views::LineDecayView::DecayLine::setObject (   self,
  object 
)

Definition at line 1259 of file LineDecayView.py.

01260                                :
01261         self._pxlObject = object
01262         self._recalculateBoundingRect = True
        
def python::Vispa::Views::LineDecayView::DecayLine::setShowLabel (   self,
  show 
)

Definition at line 1289 of file LineDecayView.py.

01290                                 :
01291         self._showLabel = show
    
def python::Vispa::Views::LineDecayView::DecayLine::setZoom (   self,
  zoom 
)

Definition at line 1238 of file LineDecayView.py.

01239                            :
01240         DecayObject.setZoom(self, zoom)
01241         if self._labelFont:
01242             self._labelFont.setPointSize(12 * self.zoomFactor())
        
def python::Vispa::Views::LineDecayView::DecayLine::slope (   self)

Definition at line 1553 of file LineDecayView.py.

01554                    :
01555         deltaX = self._endNode.x() - self._startNode.x()
01556         if deltaX == 0:
01557             return sys.maxint
01558         
01559         return 1.0 * (self._endNode.y() - self._startNode.y()) / deltaX
    
def python::Vispa::Views::LineDecayView::DecayLine::transform (   self)
Returns QTransform that sets the origin to the start point and rotates by the slope angle.

Used to change coordinates of painter in paint().

Definition at line 1326 of file LineDecayView.py.

01327                        :
01328         """ Returns QTransform that sets the origin to the start point and rotates by the slope angle.
01329 
01330         Used to change coordinates of painter in paint().
01331         """
01332 
01333         if not self._recalculateTransform and self._transform:
01334             return self._transform
01335         
01336         z = self.zoomFactor()
01337         if self._startNode.x() < self._endNode.x():
01338             self._forwardDirection = True
01339             xNull = self._startNode.x() * z
01340             yNull = self._startNode.y() * z
01341         else:
01342             self._forwardDirection = False
01343             xNull = self._endNode.x() * z
01344             yNull = self._endNode.y() * z
01345         
01346         slope = self.slope()
01347         angle = math.atan(slope)
01348         angleDegree = angle * self.HUNDREDEIGHTY_OVER_PI
01349         
01350         self._transform = QTransform()
01351         self._transform.translate(xNull, yNull)    # rotate around start point
01352         self._transform.rotate(angleDegree)
01353         return self._transform
        

Member Data Documentation

Definition at line 1197 of file LineDecayView.py.

Definition at line 1197 of file LineDecayView.py.

Definition at line 1197 of file LineDecayView.py.

Definition at line 1197 of file LineDecayView.py.

Definition at line 1197 of file LineDecayView.py.

Definition at line 1197 of file LineDecayView.py.

Definition at line 1197 of file LineDecayView.py.

Definition at line 1197 of file LineDecayView.py.

Definition at line 1197 of file LineDecayView.py.

l = (n + 1/2) * r * 2 * math.pi

Definition at line 1197 of file LineDecayView.py.

Definition at line 1197 of file LineDecayView.py.

Definition at line 1197 of file LineDecayView.py.

Definition at line 1197 of file LineDecayView.py.

Definition at line 1197 of file LineDecayView.py.

Definition at line 1197 of file LineDecayView.py.

Definition at line 1197 of file LineDecayView.py.

Definition at line 1197 of file LineDecayView.py.

Definition at line 1192 of file LineDecayView.py.

Definition at line 1193 of file LineDecayView.py.

Definition at line 1189 of file LineDecayView.py.

Definition at line 1195 of file LineDecayView.py.

Definition at line 1190 of file LineDecayView.py.

Definition at line 1188 of file LineDecayView.py.