1 from builtins
import range
5 from PyQt4.QtCore import Qt, QPoint, QPointF, QRect, QSize, SIGNAL, QCoreApplication, QMimeData, QRectF
6 from PyQt4.QtGui import QWidget, QPainter, QPolygon, QColor, QPen, QPalette, QPainterPath, QFont, QFontMetrics, QApplication, QDrag, QPixmap,QSizePolicy,QMessageBox, QTransform, QBrush
24 import_autolayout_error=
None 25 except Exception
as e:
30 LABEL =
"&Line Decay View" 32 DECAY_OBJECT_MIME_TYPE =
"text/x-decay-object" 36 WidgetView.__init__(self, parent)
37 self.setAutoFillBackground(
True)
38 self.setPalette(QPalette(Qt.white))
39 self.setAcceptDrops(
True)
58 return self.DECAY_OBJECT_MIME_TYPE
61 """ Overwrite WidgetView's function. 63 Do not clear content. This will be done by updateContent() only if it is necessary. 65 AbstractView.setDataObjects(self, objects)
69 """ Stop all running operations. 74 logging.debug(self.__class__.__name__ +
": updateContent()")
81 result=QCoreApplication.instance().showMessageBox(
"You are about to display more than "+
str(numObjects)+
" (>"+
str(self.
WARNING_ABOVE)+
") objects. This may take some time. Labels will not be displayed.",
82 "Would you like to continue?",
83 QMessageBox.Yes | QMessageBox.No,
84 QMessageBox.Yes, [(
"Yes (remember my decision)",QMessageBox.YesRole)])
85 if result == QMessageBox.No:
99 existingWidgets += [eventWidget]
102 particleWidget =
ParticleWidget(self, ParticleWidget.NONE,
"",
"")
103 particleWidget.setMinimumSize(DecayLine.DEFAULT_LENGTH, 40)
104 particleWidget.setColors(QColor(
'white'), QColor(
'white'), QColor(
'white'))
105 particleWidget.setSelectable(
True)
106 particleWidget.setObject(object)
107 decayLine =
DecayLine(particleWidget, QPoint(5, 20), QPoint(particleWidget.width() -5, 20))
113 decayLine.setLabel(
"Particle")
115 particleWidget.setDecayObject(decayLine)
116 existingWidgets += [particleWidget]
118 for child
in self.children():
122 if hasattr(child,
"object")
and not child
in existingWidgets:
124 child.setDeletable(
True)
126 elif hasattr(child,
"createDecayObjectsFromPxlObject"):
132 child.createDecayObjectsFromPxlObject(operationId)
133 child.setDeletable(
False)
134 child.setDragable(
False)
148 if import_autolayout_error!=
None:
149 logging.error(__name__ +
": Could not import autolayout algorithm: "+import_autolayout_error[1])
150 QCoreApplication.instance().errorMessage(
"Could not import autolayout algorithm (see logfile for details):\n"+import_autolayout_error[0])
155 for child
in self.children():
156 if isinstance(child, QWidget):
157 if isinstance(child, LineDecayContainer):
160 y += child.height() + margin
170 """ Returns the widget component representing the given pxl object. 176 for child
in self.children():
177 if isinstance(child, LineDecayContainer):
180 subChild = child.childContainer(objectId)
198 oldParent = existingWidget.parent()
200 if parentWidget != oldParent:
201 self.disconnect(existingWidget, SIGNAL(
"finishedAutolayouting"), oldParent.childFinishedAutolayouting)
202 existingWidget.setParent(parentWidget)
203 self.connect(existingWidget, SIGNAL(
"finishedAutolayouting"), parentWidget.childFinishedAutolayouting)
204 existingWidget.setVisible(
True)
206 return existingWidget
211 logging.warning(self.__class__.__name__ +
": createLineDecayContainer() - Cannot add child object to given object. Object does not belong to this "+ self.__class__.__name__ +
".")
214 lineDecayView = parentWidget.createChildContainer(object)
219 lineDecayView.setPxlObject(object)
221 self.connect(lineDecayView, SIGNAL(
"selected"), self.
onSelected)
232 """ Return tab controller. 234 See setTabController() 238 if hasattr(parent,
"controller"):
239 return parent.controller()
240 parent=parent.parent()
247 """ When item is selected in SubView forward signal. 250 self.emit(SIGNAL(
"selected"), object)
254 for child
in self.children():
255 if isinstance(child, LineDecayContainer):
256 child.setEditable(editable)
262 for child
in self.children():
263 if isinstance(child, LineDecayContainer):
264 child.scheduleUpdateVisibleList(
True)
268 """ Represents an Event or EventView 272 AUTOSIZE_KEEP_ASPECT_RATIO =
False 273 AUTOLAYOUT_CHILDREN_ENABLED =
True 274 AUTOSIZE_ADJUST_CONTAINER_POSITION =
False 279 logging.debug(self.__class__.__name__ +
": __init__()")
282 ObjectHolder.__init__(self)
283 WidgetContainer.__init__(self, parent)
290 self.setMouseTracking(
True)
300 if isinstance(parent, LineDecayContainer):
301 self.connect(self, SIGNAL(
"finishedAutolayouting"), parent.childFinishedAutolayouting)
307 """ Redirect filtering to parent. 312 """ Do not filter widget but rather the pxl objects 322 if isinstance(child, LineDecayContainer):
323 child.setEditable(editable)
329 """ Sets whether this view accepts drops and forwards the information to sub LineDecayContainers. 331 WidgetContainer.setAcceptDrops(self, accept)
333 if isinstance(child, LineDecayContainer):
334 child.setAcceptDrops(accept)
337 """ Sets the DataAccessor from which the lines are created. 339 You need to call updateContent() in order to make the changes visible. 341 if not isinstance(accessor, BasicDataAccessor):
342 raise TypeError(__name__ +
" requires data accessor of type BasicDataAccessor.")
343 if not isinstance(accessor, RelativeDataAccessor):
344 raise TypeError(__name__ +
" requires data accessor of type RelativeDataAccessor.")
345 if not isinstance(accessor, ParticleDataAccessor):
346 raise TypeError(__name__ +
" requires data accessor of type ParticleDataAccessor.")
347 AbstractView.setDataAccessor(self, accessor)
350 """ If there is only one container in parent increase it so it fills whole space. 353 return WidgetContainer.sizeHint(self)
367 sizeHint = WidgetContainer.sizeHint(self)
368 return QSize(
max(sizeHint.width() + increaseSize, minWidth),
max(sizeHint.height() + increaseSize, minHeight))
371 """ Overwrites QWidget's method and includes DecayObjects in addition to QWidgets. 380 if not isinstance(object, DecayNode):
382 if first
or minX > object.x():
384 if first
or minY > object.y():
386 if first
or maxX < object.x():
388 if first
or maxY < object.y():
395 return QRect(minX, minY, maxX - minX, maxY - minY).united(WidgetContainer.childrenRect(self))
398 return WidgetContainer.children(self) + [node
for node
in self.
dataObjects()
if isinstance(node, DecayNode)]
401 """ Overwrite VispaWidgetOwner's method so in addition deselectAllObjects() is called. 404 WidgetContainer.deselectAllWidgets(self, exception)
407 """ Sets zoom of this widget and of it's children. 409 WidgetContainer.setZoom(self, zoom)
412 if isinstance(child, Zoomable):
432 """ Return tab controller. 434 See setTabController() 442 """ Returns the widget component representing the given pxl object. 448 if isinstance(child, LineDecayContainer):
451 subChild = child.childContainer(object)
458 lineDecayView.setPxlObject(object)
462 pos = QPoint(margin, margin)
464 pos -= QPoint(0.5* lineDecayView.width(), 0.5* lineDecayView.height())
466 lineDecayView.move(pos)
470 """ Accepts drag enter event if module is dragged. 475 if event.mimeData().hasFormat(LineDecayView.DECAY_OBJECT_MIME_TYPE):
476 event.acceptProposedAction()
480 if dropType ==
"Node":
484 elif dropType ==
"EventView":
486 newObject.select(
True)
490 while hasattr(parent,
"parent"):
491 if hasattr(parent,
"onSelected"):
492 self.connect(newObject, SIGNAL(
"selected"), parent.onSelected)
494 parent=parent.parent()
502 self.update(newObject.boundingRect())
512 """ Handle drop of module. 514 logging.debug(self.__class__.__name__ +
": dropEvent()")
518 if event.mimeData().hasFormat(LineDecayView.DECAY_OBJECT_MIME_TYPE):
519 dropType =
str(event.mimeData().
data(LineDecayView.DECAY_OBJECT_MIME_TYPE))
522 event.acceptProposedAction()
525 """ This function asks the data accessor to create a new particle and makes sure it gets the properties (name, pdg id, charge) of the desired type. 527 particleType may either be None or a string specifying the object type. 528 pos is in 100% coordinates. 536 newParticle = dataAccessor.createParticle()
538 categoryName =
"Object info" 539 dataAccessor.setProperty(newParticle,
"Name", particleType, categoryName)
540 particleId = self.
dataAccessor().particleId(newParticle)
541 if particleId !=
None:
543 dataAccessor.setProperty(newParticle,
"PdgNumber", particleId, categoryName)
544 particleName = self.
dataAccessor().defaultName(newParticle)
548 dataAccessor.setProperty(newParticle,
"Name", particleName, categoryName)
550 dataAccessor.setProperty(newParticle,
"Charge", dataAccessor.charge(newParticle), categoryName)
551 self._pxlObject.setObject(newParticle)
556 """ This function accepts a data object (e.g. a pxl object), creates a DecayLine for it and adds the latter to this container's objects list. 565 pos -= QPoint(0.5 * DecayLine.DEFAULT_LENGTH, 0)
573 self._existingObjectIds.append(
str(dataObjectId))
580 for daughter
in self.
dataAccessor().daughterRelations(object):
581 if daughter
in self._particlesDict.keys():
584 daughterNode = daughterDecayObject.motherNode()
585 elif daughterDecayObject.motherNode() != daughterNode
and \
586 daughterDecayObject.motherNode().unite(daughterNode):
590 daughterNode = daughterDecayObject.motherNode()
592 for mother
in self.
dataAccessor().motherRelations(object):
593 if mother
in self._particlesDict.keys():
596 motherNode = motherDecayObject.daughterNode()
597 elif motherDecayObject.daughterNode() != motherNode
and \
598 motherDecayObject.daughterNode().unite(motherNode):
602 motherNode = motherDecayObject.daughterNode()
604 motherNode = QPoint(pos)
606 daughterNode = QPoint(pos.x() + DecayLine.DEFAULT_LENGTH, pos.y())
609 newDecayLine =
DecayLine(self, motherNode, daughterNode)
610 newDecayLine.setObject(object)
630 """ Creates DecayObjects for all particles in the set pxl object. 632 In addition this function is called on all child LineDecayContainers. 649 if isinstance(child, LineDecayContainer):
650 if not child.createDecayObjectsFromPxlObject(operationId):
655 """ Returns the DecayObject which represents the given pxlObject or None if there is no such one. 657 This function is to slow for massive usage with many dataObjects as it loops over all dataObjects. 660 if decayObject.object() == pxlObject:
665 if isinstance(decayObject, type(
True)):
666 WidgetContainer.select(self, decayObject)
678 self._selectedList.append(decayObject)
679 self.update(decayObject.boundingRect())
681 logging.error(self.__class__.__name__ +
": select() - Tried to remove non data object from data objects list. This is not supposed to happen. Check it.")
689 self.update(object.boundingRect())
693 boundingRect = decayObject.boundingRect()
695 self.update(boundingRect.unite(oldBoundingRect))
697 self.update(boundingRect)
700 objectIsVisible =
False 701 if self.visibleRegion().intersects(boundingRect):
702 objectIsVisible =
True 704 if not objectIsVisible:
705 self._visibleList.remove(decayObject)
706 elif objectIsVisible:
707 self._visibleList.append(decayObject)
712 if isinstance(child, LineDecayContainer):
713 child.scheduleUpdateVisibleList(update)
721 region = self.visibleRegion()
725 if region.intersects(decayObject.boundingRect()):
726 self._visibleList.append(decayObject)
734 WidgetContainer.paint(self, painter)
740 generalPaintMode = 0x0
742 generalPaintMode = DecayObject.PAINT_MODE_NO_DECORATIONS
749 painterClipRegion = self.visibleRegion()
751 if isinstance(decayObject, DecayLine):
753 if isinstance(decayObject, DecayNode):
755 decayNodes.append(decayObject)
757 for decayObject
in decayNodes:
761 paintMode = generalPaintMode
763 paintMode |= DecayObject.PAINT_MODE_SELECTED
765 paintMode |= DecayObject.PAINT_MODE_HOVERED
766 decayObject.paint(painter, paintMode)
770 WidgetContainer.mousePressEvent(self, event)
777 toSelectObject =
None 779 if object.containsPoint(event.pos()):
780 if isinstance(object, DecayNode):
782 toSelectObject = object
784 elif not toSelectObject:
785 toSelectObject = object
787 toSelectObject.select(event.pos())
788 self.
select(toSelectObject)
790 WidgetContainer.mousePressEvent(self, event)
795 WidgetContainer.mouseMoveEvent(self, event)
804 if not bool(event.buttons()):
806 to_hover_object =
None 811 if object.containsPoint(event.pos()):
812 if isinstance(object, DecayNode):
814 to_hover_object = object
816 elif not to_hover_object:
817 to_hover_object = object
822 self.update(self._hoveredObject.boundingRect())
823 if previously_hovered_object:
825 self.update(previously_hovered_object.boundingRect())
827 self.update(self._hoveredObject.boundingRect())
835 """ Join nodes if they belong to objects with relations. 841 for obj
in dataObjects:
842 if obj != self.
_selectedList[0]
and isinstance(obj, DecayNode)
and obj.containsPoint(event.pos()):
845 hasRelations=hasRelations
and self.
dataAccessor().hasRelations(decayLine.object())
851 self._selectedList.append(obj)
857 """ Calls delete() method if backspace or delete key is pressed when widget has focus. 859 if (event.key() == Qt.Key_Backspace
or event.key() == Qt.Key_Delete)
and self.
_editable:
862 controller.tab().propertyView().
clear()
870 controller.setModified()
871 if hasattr(controller,
"updateTreeView"):
872 controller.updateTreeView()
876 parent = self.parent()
877 if WidgetContainer.delete(self)
and hasattr(parent,
"object"):
884 self.update(decayObject.boundingRect())
885 if decayObject.delete():
887 self._selectedList.remove(decayObject)
888 if decayObject.object():
892 self._existingObjectIds.remove(id)
893 self._particlesDict.pop(decayObject.object(),
None)
894 self._pxlObject.removeObject(decayObject.object())
895 ObjectHolder.removeObject(self, decayObject)
900 logging.debug(self.__class__.__name__ +
": autolayout() - %s" %
str(self.
title()))
901 if self._threadChain.isRunning():
902 logging.info(self.__class__.__name__ +
": autolayout() - Autolayout thread is already running. Aborting...")
910 if isinstance(object, DecayLine):
913 if not object.motherNode()
in self._allNodes.keys():
916 motherNode.position = Vector2(0, 0)
917 motherNode.isVertex =
False 918 self.
_allNodes[object.motherNode()] = motherNode
922 motherNode = self.
_allNodes[object.motherNode()]
924 if not object.daughterNode()
in self._allNodes.keys():
925 daughterNode =
Node()
926 daughterNode.position = Vector2(0, 0)
927 daughterNode.isVertex =
False 928 self.
_allNodes[object.daughterNode()] = daughterNode
931 daughterNode = self.
_allNodes[object.daughterNode()]
936 motherNode.children.append(daughterNode)
937 daughterNode.mothers.append(motherNode)
941 self._nodeVector.append(motherNode)
943 self._nodeVector.append(daughterNode)
945 nodeVectorSize = self._nodeVector.size()
946 if nodeVectorSize > 1:
947 adhoc = nodeVectorSize > 40
948 autolayouter = AutoLayout()
951 logging.debug(self.__class__.__name__ +
": calling pxl::AutoLayout.layout(%s) with %d Particles" % (
str(adhoc), nodeVectorSize))
953 autolayouter.layout(
False)
955 autolayouter.layout(
True)
962 if isinstance(child, LineDecayContainer):
963 self._autolayoutingChildren.append(child)
967 logging.debug(self.__class__.__name__ +
" autolayoutThreadFinished() - %s" %
str(self.
title()))
968 if self._threadChain.isRunning():
969 logging.info(self.__class__.__name__ +
": autolayoutThreadFinished() - Thread is still running. Aborting...")
973 firstMinOrphanY =
True 974 firstMaxNonOrphanY =
True 978 if i == 0
or self.
_nodeVector[i].position.y < minY:
980 if i == 0
or self.
_nodeVector[i].position.y > maxY:
987 if firstMinOrphanY
or self.
_nodeVector[i].position.y > minOrphanY:
989 firstMinOrphanY =
False 992 if firstMaxNonOrphanY
or self.
_nodeVector[i].position.y < maxNonOrphanY:
994 firstMaxNonOrphanY =
False 1000 if isinstance(decayNode, DecayNode)
and decayNode
in self._allNodes.keys():
1001 decayNode.setPosition(QPoint(self.
_allNodes[decayNode].position.x + xOffset, self.
_allNodes[decayNode].position.y + yOffset))
1016 logging.debug(self.__class__.__name__ +
": childFinishedAutolayouting() - %s" %
str(self.
title()))
1017 if self.sender()
and isinstance(self.sender(), LineDecayContainer):
1018 child = self.sender()
1020 self._autolayoutingChildren.remove(child)
1034 self.emit(SIGNAL(
"finishedAutolayouting"))
1038 CONTAINS_AREA_SIZE = 4
1039 PAINT_MODE_SELECTED = 0x1
1040 PAINT_MODE_HOVERED = 0x2
1041 PAINT_MODE_NO_DECORATIONS = 0x4
1044 Zoomable.__init__(self)
1046 if isinstance(self.
_parent, Zoomable):
1047 self.
setZoom(self._parent.zoom())
1052 def paint(self, painter, paintMode=0x0):
1053 raise NotImplementedError
1056 raise NotImplementedError
1059 raise NotImplementedError
1062 raise NotImplementedError
1065 return QRect( (position - QPoint(self.CONTAINS_AREA_SIZE, self.CONTAINS_AREA_SIZE)*0.5 ) * self.
zoomFactor(), QSize(self.CONTAINS_AREA_SIZE, self.CONTAINS_AREA_SIZE) * self.
zoomFactor() + QSize(1, 1))
1068 raise NotImplementedError
1078 CONTAINS_AREA_SIZE = 8
1083 DecayObject.__init__(self, parent)
1084 ObjectHolder.__init__(self)
1093 if decayObject2.object()
in self.
parent().
dataAccessor().motherRelations(decayObject.object()):
1094 decayObject.object().unlinkMother(decayObject2.object())
1095 if decayObject2.object()
in self.
parent().
dataAccessor().daughterRelations(decayObject.object()):
1096 decayObject.object().unlinkDaughter(decayObject2.object())
1108 return self._position.x()
1111 return self._position.y()
1113 def paint(self, painter, paintMode=0x0):
1114 if paintMode & DecayObject.PAINT_MODE_SELECTED:
1115 penColor = QColor(Qt.blue)
1119 penColor = QColor(Qt.blue).lighter(140)
1120 if paintMode & DecayObject.PAINT_MODE_HOVERED:
1121 penColor = penColor.lighter(120)
1123 painter.setPen(QPen(penColor, 1 * self.
zoomFactor(), Qt.SolidLine))
1124 painter.setBrush(penColor)
1144 pos = QPoint(arg[0], arg[1])
1148 oldBoundingRects = {}
1150 oldBoundingRects[object] = object.boundingRect()
1156 self.
parent().objectMoved(object, oldBoundingRects[object])
1157 self.
parent().objectMoved(self, oldBoundingRect)
1164 useDataAccessor =
False 1166 useDataAccessor =
True 1169 newDecayObjects = node.dataObjects()[:]
1170 for newDecayObject
in newDecayObjects:
1173 nodeType = newDecayObject.replaceNode(node, self)
1176 for oldDecayObject
in oldDecayObjects:
1177 if nodeType == DecayNode.TYPE_MOTHER
and oldDecayObject.nodeType(self) == DecayNode.TYPE_DAUGHTER:
1179 self.
parent().
dataAccessor().linkMother(newDecayObject.object(), oldDecayObject.object())
1180 if nodeType == DecayNode.TYPE_DAUGHTER
and oldDecayObject.nodeType(self) == DecayNode.TYPE_MOTHER:
1182 self.
parent().
dataAccessor().linkDaughter(newDecayObject.object(), oldDecayObject.object())
1196 HUNDREDEIGHTY_OVER_PI = 180 / math.pi
1198 def __init__(self, parent, startPointOrNode, endPointOrNode):
1214 DecayObject.__init__(self, parent)
1216 if isinstance(parent, LineDecayContainer):
1218 if isinstance(startPointOrNode, QPoint):
1224 if isinstance(endPointOrNode, QPoint):
1236 self._startNode.appendObject(self)
1237 self._endNode.appendObject(self)
1240 DecayObject.setZoom(self, zoom)
1242 self._labelFont.setPointSize(12 * self.
zoomFactor())
1245 self._startNode.removeObject(self)
1246 self._endNode.removeObject(self)
1288 self._labelFont.setPointSize(12 * self.
zoomFactor())
1295 return DecayNode.TYPE_MOTHER
1297 return DecayNode.TYPE_DAUGHTER
1302 self._startNode.removeObject(self)
1304 self._startNode.appendObject(self)
1306 self._endNode.removeObject(self)
1308 self._endNode.appendObject(self)
1321 """ Returns True if instead of simple line a spiral or a sinus function is plotted. 1328 """ Returns QTransform that sets the origin to the start point and rotates by the slope angle. 1330 Used to change coordinates of painter in paint(). 1337 if self._startNode.x() < self._endNode.x():
1339 xNull = self._startNode.x() * z
1340 yNull = self._startNode.y() * z
1343 xNull = self._endNode.x() * z
1344 yNull = self._endNode.y() * z
1346 slope = self.
slope()
1347 angle = math.atan(slope)
1348 angleDegree = angle * self.HUNDREDEIGHTY_OVER_PI
1351 self._transform.translate(xNull, yNull)
1352 self._transform.rotate(angleDegree)
1355 def paint(self, painter, paintMode=0x0):
1356 if paintMode & DecayObject.PAINT_MODE_SELECTED:
1357 penColor = QColor(Qt.blue)
1360 if paintMode & DecayObject.PAINT_MODE_HOVERED:
1361 penColor = penColor.lighter(80)
1363 showDirectionArrow = paintMode & DecayObject.PAINT_MODE_HOVERED
or paintMode & DecayObject.PAINT_MODE_SELECTED
1367 l = self.
length(zoomed =
True)
1373 painter.setPen(QPen(penColor, 0.5*self.
lineWidth(), Qt.SolidLine))
1376 designRadius = 1.2 * z
1378 n =
max(
int(1.0 * l / (2 * math.pi * designRadius)), 4)
1380 r = 1.0 * l / (2 * math.pi * (n + 0.5))
1385 path = QPainterPath()
1391 phase = 1.0 * (xM-a)/r
1392 x = xM - a * math.cos(phase)
1393 y = yM - a * math.sin(phase)
1398 path.lineTo(QPointF(x, y))
1400 painter.drawPath(path)
1402 path = QPainterPath()
1404 while x < l - 0.5*a:
1405 y = a * math.cos(x/r)
1406 path.lineTo(QPointF(x, y))
1408 painter.drawPath(path)
1410 painter.setBrush(QBrush(penColor, Qt.SolidPattern))
1411 painter.drawEllipse(QPointF(l/2.,0.),l/2.,a)
1415 painter.drawLine(QPoint(0,0), QPoint(l, 0))
1417 if not paintMode & DecayObject.PAINT_MODE_NO_DECORATIONS:
1421 if showDirectionArrow:
1422 painter.setPen(QPen(penColor, 0.8*self.
lineWidth(), Qt.SolidLine, Qt.RoundCap))
1430 painter.resetTransform()
1434 self._startNode.paint(painter, paintMode)
1435 self._endNode.paint(painter, paintMode)
1459 """ Draws self._label on given painter. 1461 Expects coordinates of painter transformed as returned by transform() 1466 if paintMode & DecayObject.PAINT_MODE_SELECTED:
1467 textColor = QColor(Qt.blue)
1468 elif paintMode & DecayObject.PAINT_MODE_HOVERED:
1469 textColor = QColor(Qt.gray)
1471 textColor = QColor(Qt.black)
1473 path = QPainterPath()
1475 painter.fillPath(path, textColor)
1479 arrowPixelOffset = 0.7* self.
lineWidth()
1481 arrowBoundingRectLeft = arrowBoundingRect.left() + arrowPixelOffset
1482 arrowBoundingRectRight = arrowBoundingRect.right() - arrowPixelOffset
1483 arrowBoundingRectTop = arrowBoundingRect.top() + arrowPixelOffset
1484 arrowBoundingRectBottom = arrowBoundingRect.bottom() - arrowPixelOffset
1485 arrowBoundingRectVerticalCenter = arrowBoundingRect.center().y()
1487 painter.drawLine(arrowBoundingRectLeft, arrowBoundingRectTop, arrowBoundingRectRight, arrowBoundingRectVerticalCenter)
1488 painter.drawLine(arrowBoundingRectLeft, arrowBoundingRectBottom, arrowBoundingRectRight, arrowBoundingRectVerticalCenter)
1491 painter.drawLine(arrowBoundingRectLeft, arrowBoundingRectVerticalCenter, arrowBoundingRectRight, arrowBoundingRectTop)
1492 painter.drawLine(arrowBoundingRectLeft, arrowBoundingRectVerticalCenter, arrowBoundingRectRight, arrowBoundingRectBottom)
1500 label_offset = self.LABEL_OFFSET
1507 labelWidth = self._labelBoundingRect.width()
1508 offset = QPointF(0.5 * (self.
length(zoomed=
True) - labelWidth), - label_offset * self.
zoomFactor())
1509 self._labelBoundingRect.translate(offset.x(), offset.y())
1516 l = self.
length(zoomed =
True)
1517 arrowLength = self.ARROW_LENGTH * zoomFactor
1518 arrowWidth = self.ARROW_WIDTH * zoomFactor
1519 horizontalOffset = self.CONTAINS_AREA_SIZE * 0.4 * self.
zoomFactor()
1521 self.
_arrowBoundingRect = QRect(l-arrowLength - horizontalOffset, -arrowWidth, arrowLength, 2*arrowWidth)
1523 self.
_arrowBoundingRect = QRect(horizontalOffset, -arrowWidth, arrowLength, 2*arrowWidth)
1532 contains_area_size = self.CONTAINS_AREA_SIZE
1534 contains_area_size += 4
1537 offset = contains_area_size * zoomFactor
1538 startPoint = self._startNode.position() * zoomFactor
1539 endPoint = self._endNode.position() * zoomFactor
1541 topLeft = QPoint(
min(startPoint.x(), endPoint.x()) - offset,
min(startPoint.y(), endPoint.y()) - offset)
1542 bottomRight = QPoint(
max(startPoint.x(), endPoint.x()) + offset,
max(startPoint.y(), endPoint.y()) + offset)
1544 rect = QRect(topLeft, bottomRight)
1555 deltaX = self._endNode.x() - self._startNode.x()
1559 return 1.0 * (self._endNode.y() - self._startNode.y()) / deltaX
1562 l = math.sqrt((self._endNode.x() - self._startNode.x())**2 + (self._endNode.y() - self._startNode.y())**2)
1575 line_width = self.LINE_WIDTH + 1
1579 if self._endNode.position().x() == self._startNode.position().x():
1581 if abs(pos.x() - self._endNode.position().x()) < line_width:
1585 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):
1588 slope = self.
slope()
1589 deltaY = slope * (pos.x() - self._startNode.position().x()) + self._startNode.position().y() - pos.y()
1590 if abs(deltaY) < 0.5* line_width *
max(1,
abs(slope)):
1596 pos = (self._startNode.position() + self._endNode.position()) * 0.5
1597 self._startNode.select(pos)
1598 self._endNode.select(pos)
1602 self._startNode.move(pos)
1603 self._endNode.move(pos)
1626 VispaWidget.__init__(self, parent)
1628 self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
1633 self.
textField().setPenColor(QColor(
"white"))
1642 if type == self.LEPTON:
1643 self.
setColors(QColor(117, 57, 18), QColor(180, 88, 28), QColor(244, 119, 38))
1644 elif type == self.QUARK:
1645 self.
setColors(QColor(19, 56, 0), QColor(27, 79, 27), QColor(57, 129, 51))
1646 elif type == self.BOSON:
1647 self.
setColors(QColor(64, 0, 0), QColor(127, 0, 0), QColor(191, 0, 0))
1648 elif type == self.HIGGS:
1649 self.
setColors(QColor(28, 63, 253), QColor(27, 118, 255), QColor(21, 169, 250))
1651 if hasattr(parent,
"particleDoubleClicked"):
1652 self.connect(self,SIGNAL(
"mouseDoubleClicked"),parent.particleDoubleClicked)
1653 if hasattr(parent,
"particleRightClicked"):
1654 self.connect(self,SIGNAL(
"mouseRightPressed"),parent.particleRightClicked)
1663 self.emit(SIGNAL(
"mouseDoubleClicked"), self)
1666 if event.button() == Qt.LeftButton:
1668 if isinstance(self.parent(), WidgetView):
1669 self.parent().widgetSelected(self)
1670 if event.button()==Qt.RightButton:
1671 self.emit(SIGNAL(
"mouseRightPressed"), event.globalPos(), self)
1674 if not (event.buttons() & Qt.LeftButton):
1676 if (event.pos() - self.
_dragStartPosition).manhattanLength() < QApplication.startDragDistance():
1680 mimeData = QMimeData()
1682 drag.setMimeData(mimeData)
1683 drag.setPixmap(QPixmap.grabWidget(self))
1684 drag.setHotSpot(QPoint(drag.pixmap().
width()/2, drag.pixmap().
height()/2))
1688 """ Will be painted in content area. 1693 """ The particle widget can optionally carry a real physics object, e.g. pxl particle. 1695 Required for example if widget's parent is a WidgetView that should react on clicks. 1703 VispaWidget.paint(self, painter)
1707 paintMode |= DecayObject.PAINT_MODE_SELECTED
1708 self._decayObect.paint(painter, paintMode)
1711 """ Return None for decay object. def dropEvent(self, event)
def setDataObjects(self, objects)
def setColor(self, color)
def containsPoint(self, pos)
def deselectAllObjects(self)
def containsPoint(self, pos)
def decayObjectMimeType(self)
def setShowLabel(self, show)
def setPxlObject(self, object)
def mousePressEvent(self, event)
def select(self, pos=None, selected=True)
def numberDataObjectChildren(self, objects=None)
bool contains(EventRange const &lh, EventID const &rh)
_lineStyle
l = (n + 1/2) * r * 2 * math.pi
def labelBoundingRect(self, forceRecalculation=False)
def setPosition(self, pos)
def autolayoutPostprocess(self)
def mousePressEvent(self, event)
def paint(self, painter, paintMode=0x0)
def __init__(self, parent, position)
def exception_traceback()
def lineDecayContainer(self, object)
def decayObject(self, pxlObject)
_crateDecayObjectsDecaysThreadChain
def createDecayObjectsThreadChainFinished(self, result)
def arrowBoundingRect(self, forceRecalculation=False)
def __init__(self, parent=None)
def setExclusiveMode(self, exclusive=True)
def paint(self, painter, paintMode=0x0)
def select(self, pos=None, selected=True)
def noDecorationsMode(self)
def childFinishedAutolayouting(self)
def mouseDoubleClickEvent(self, event)
def setObject(self, object)
def setEditable(self, editable)
def paint(self, painter, paintMode=0x0)
def select(self, decayObject)
def drawArrow(self, painter, paintMode=0x0)
def noDecorationsMode(self)
def setLabel(self, label)
def addDecayLine(self, object, pos=None)
void clear(CLHEP::HepGenMatrix &m)
Helper function: Reset all elements of a matrix to 0.
def setAcceptDrops(self, accept)
def deselectAllWidgets(self, exception=None)
Abs< T >::type abs(const T &t)
def setLineStyle(self, style)
def childContainer(self, objectId)
def length(self, zoomed=False)
def updateVisibleList(self, force=False)
def setDecayObject(self, decayObject)
def dragEnterEvent(self, event)
bool insert(Storage &iStorage, ItemType *iItem, const IdTag &iIdTag)
def __init__(self, parent)
def setObject(self, object)
def mouseMoveEvent(self, event)
def replaceNode(self, oldNode, newNode)
def topLevelContainer(self)
def onSelected(self, object)
def __init__(self, parent, startPointOrNode, endPointOrNode)
def scrollBarValueChanged(self, event)
def addParticleByType(self, particleType=None, pos=None)
def applyFilter(self, objects)
def scheduleUpdateVisibleList(self, update=True)
def drawText(self, painter, paintMode=0x0)
def dataObjectsCount(self)
def remove(d, key, TELL=False)
def position(self, zoomed=False)
def createLineDecayContainer(self, object, objectMother=None)
def removeObject(self, decayObject)
def createObject(self, dropType, pos)
def childFinishedAutolayouting(self)
def containsPoint(self, pos)
def applyFilter(self, objects)
def addDecayNode(self, pos)
def removeObject(self, object)
char data[epos_bytes_allocation]
def setMimeDataType(self, type)
def setDataAccessor(self, accessor)
def showEvent(self, event)
def paintDecayObject(self, painter, decayObject, generalPaintMode)
def autolayoutThreadFinished(self, result)
def mouseMoveEvent(self, event)
def mouseReleaseEvent(self, event)
def keyPressEvent(self, event)
def select(self, pos=None, selected=True)
def setEditable(self, editable)
def __init__(self, parent, type, name, dragData=None)
def createDecayObjectsFromPxlObject(self, operationId)
def containsAreaSquareRect(self, position)
def objectMoved(self, decayObject, oldBoundingRect=None)
def createChildContainer(self, object, pos=None)
def __init__(self, parent=None)
def appendObject(self, object)