Commit b8f6f661 authored by JosefBrandt's avatar JosefBrandt

Contour selection works as previously
parent 9b10245c
......@@ -500,14 +500,14 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
def getSelectedPolymers(self):
return [checkbox.text() for checkbox in self.polymerCheckBoxes if checkbox.isChecked()]
@QtCore.pyqtSlot(int)
def selectParticleIndex(self, particleIndex, centerOn=True):
assignment = self.particleContainer.getParticleAssignmentByIndex(particleIndex)
self.typeSelectorCombo.setCurrentText(assignment)
particleIndices = self.particleContainer.getIndicesOfParticleType(assignment)
self.particleSelector.setValue(particleIndices.index(particleIndex)+1)
self.updateToSelectedParticle(resetSpectrumCount=True, centerOn=False)
# @QtCore.pyqtSlot(int) #TODO: Connect to widget that allows jumping to particular particle
# def selectParticleIndex(self, particleIndex, centerOn=True):
# assignment = self.particleContainer.getParticleAssignmentByIndex(particleIndex)
# self.typeSelectorCombo.setCurrentText(assignment)
# particleIndices = self.particleContainer.getIndicesOfParticleType(assignment)
# self.particleSelector.setValue(particleIndices.index(particleIndex)+1)
#
# self.updateToSelectedParticle(resetSpectrumCount=True, centerOn=False)
def displayNewPolymerType(self, resetCurrentIndex=True):
......
......@@ -299,11 +299,13 @@ class SampleView(QtWidgets.QGraphicsView):
if self.dataset.ramanscandone: #uncomment!!
maxmode = "ParticleAnalysis"
return maxmode
def mousePressEvent(self, event):
# if event.button()==QtCore.Qt.RightButton:
if event.button()==QtCore.Qt.MiddleButton:
self.drag = event.pos()
elif event.button()==QtCore.Qt.LeftButton:
self.checkForContourSelection(event)
event.ignore()
elif event.button()==QtCore.Qt.LeftButton and self.mode in ["OpticalScan", "RamanScan"] \
and event.modifiers()==QtCore.Qt.ControlModifier:
p0 = self.mapToScene(event.pos())
......@@ -317,17 +319,16 @@ class SampleView(QtWidgets.QGraphicsView):
self.dataset.readin = False
else:
return
x, y, z = self.dataset.mapToLengthRaman([p0.x(), p0.y()],
microscopeMode=self.microscopeMode,
noz=(False if self.mode=="RamanScan" else True))
# x, y, z = self.dataset.mapToLengthRaman([p0.x(), p0.y()],
# microscopeMode=self.microscopeMode,
# noz=(False if self.mode=="RamanScan" else True))
x, y, z = self.dataset.mapToLengthRaman([p0.x(), p0.y()], microscopeMode=self.microscopeMode, noz=False)
if z is not None:
assert z>-100.
self.ramanctrl.moveToAbsolutePosition(x, y, z)
elif event.button()==QtCore.Qt.LeftButton and self.mode=="ParticleDetection":
p0 = self.mapToScene(event.pos())
self.detectionwidget.setImageCenter([p0.x(), p0.y()])
# elif event.button()==QtCore.Qt.LeftButton and self.mode=="ParticleAnalysis":
# p0 = self.mapToScene(event.pos())
else:
p0 = self.mapToScene(event.pos())
......@@ -352,6 +353,62 @@ class SampleView(QtWidgets.QGraphicsView):
factor = 1.01**(event.angleDelta().y()/8)
self.scaleImage(factor)
def checkForContourSelection(self, event):
def addContourToSelection(cnt):
cnt.isSelected = True
cnt.update()
self.selectedContours.append(cnt.particleIndex)
def removeContourFromSelection(cnt):
cnt.isSelected = False
cnt.update()
self.selectedContours.remove(cnt.particleIndex)
p = self.mapToScene(event.pos())
p = QtCore.QPointF(p.x(), p.y())
for index, cnt in enumerate(self.contourItems):
if cnt.polygon.containsPoint(p, QtCore.Qt.OddEvenFill): #clicked on particle
if not event.modifiers()==QtCore.Qt.ShiftModifier:
addContourToSelection(cnt)
else:
if cnt.particleIndex not in self.selectedContours:
addContourToSelection(cnt)
elif cnt.particleIndex in self.selectedContours:
removeContourFromSelection(cnt)
else: #not clicked on particle
if event.modifiers()!=QtCore.Qt.ShiftModifier and cnt.particleIndex in self.selectedContours:
removeContourFromSelection(cnt)
# if event.modifiers()==QtCore.Qt.ShiftModifier:
# if index not in self.selectedContours:
# cnt.isSelected = True
# self.selectedContours.append(cnt.particleIndex)
# else:
# cnt.isSelected = False
# self.selectedContours.remove(cnt.particleIndex)
# else:
# cnt.isSelected = True
# self.selectedContours = [cnt.particleIndex]
#
# elif cnt.particleIndex not in self.selectedContours:
# cnt.isSelected = False
# self.selectedContours = [] #reset selection, if nothing was hit...
self.update()
def scaleImage(self, factor):
if factor<1 and not self.imparent.zoomOutAct.isEnabled():
return
......@@ -521,10 +578,10 @@ class SampleView(QtWidgets.QGraphicsView):
assignment = self.dataset.particleContainer.getParticleAssignmentByIndex(particleIndex)
color = getColorFromNameWithSeed(assignment, self.dataset.colorSeed)
newCnt.setColor(QtGui.QColor(color[0], color[1], color[2], 255))
if self.analysiswidget is not None:
newCnt.connectContourSelectedSignalTo(self.analysiswidget.selectParticleIndex)
# newCnt.contourSelected.connect(self.analysiswidget.selectContour)
#
# if self.analysiswidget is not None:
# newCnt.connectContourSelectedSignalTo(self.analysiswidget.selectParticleIndex)
## newCnt.contourSelected.connect(self.analysiswidget.selectContour)
self.contourItems.append(newCnt)
self.scene().addItem(newCnt)
......
......@@ -21,17 +21,10 @@ If not, see <https://www.gnu.org/licenses/>.
import numpy as np
from PyQt5 import QtCore, QtWidgets, QtGui
class ContourSignalEmitter(QtCore.QObject):
contourSelected = QtCore.pyqtSignal(int)
def __init__(self):
super(ContourSignalEmitter, self).__init__()
class SegmentationContour(QtWidgets.QGraphicsItem):
def __init__(self, parent, contourData, pos=(0,0)):
super().__init__()
self.parent = parent
self.signalEmitter = ContourSignalEmitter()
self.setPos(pos[0], pos[1])
self.setFlag(QtWidgets.QGraphicsItem.ItemIsSelectable)
self.setAcceptedMouseButtons(QtCore.Qt.AllButtons)
......@@ -45,10 +38,7 @@ class SegmentationContour(QtWidgets.QGraphicsItem):
self.particleIndex = None
self.isSelected = False
self.getBrectAndPolygon()
def connectContourSelectedSignalTo(self, targetMethod):
self.signalEmitter.contourSelected.connect(targetMethod)
def getBrectAndPolygon(self):
polygon = QtGui.QPolygonF()
x0 = self.contourData[:,0,0].min()
......@@ -76,10 +66,12 @@ class SegmentationContour(QtWidgets.QGraphicsItem):
def mousePressEvent(self, event):
if event.button()==QtCore.Qt.LeftButton:
print('selected particle index', self.particleIndex)
self.isSelected = True
self.signalEmitter.contourSelected.emit(self.particleIndex)
# self.isSelected = True
# self.signalEmitter.contourSelected.emit(self.particleIndex)
def paint(self, painter, option, widget):
self.isSelected = (self.particleIndex in self.parent.selectedContours)
if self.polygon is not None and not self.hidden:
painter.setPen(QtCore.Qt.green)
if self.isSelected:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment