...
 
Commits (3)
This diff is collapsed.
......@@ -30,13 +30,13 @@ from matplotlib.figure import Figure
class ExpExcelDialog(QtWidgets.QDialog):
def __init__(self, dataset, parent):
super(ExpExcelDialog, self).__init__(parent)
def __init__(self, dataset, particleContainer):
super(ExpExcelDialog, self).__init__()
self.setWindowTitle('Export Options')
self.setGeometry(200, 200, 300, 300)
self.dataset = dataset
self.particleContainer = self.dataset.particleContainer
self.particleContainer = particleContainer
# self.particles = self.datastats.getParticleStats()
self.polymers = self.particleContainer.getListOfParticleAssignments
# self.additives = self.datastats.currentAdditives
......
......@@ -254,9 +254,6 @@ class ParticleContainer(object):
for index in sorted(indexList, reverse=True):
particle = self.getParticleOfIndex(index) #just for asserting to have the correct particle!
del self.particles[index]
# particle = self.getParticleOfIndex(index)
# print('removing particle of index', index)
# self.particles.remove(particle)
def resetParticleIndices(self):
for newIndex, particle in enumerate(self.particles):
......@@ -340,9 +337,9 @@ class Particle(object):
def getShortParticleSize(self):
if not np.isnan(self.shortSize_ellipse):
return round(self.shortSize_ellipse)
return self.shortSize_ellipse
elif not np.isnan(self.shortSize_box):
return round(self.shortSize_box)
return self.shortSize_box
else:
print(f'Error, particle size requested, but not yet set.\nParticle Index is {self.index}')
raise ValueError
......
......@@ -161,6 +161,7 @@ class ParticlePainter(QtWidgets.QGraphicsItem):
for poly in self.polygons:
painter.setBrush(QtGui.QColor(200, 200, 255, 128))
painter.drawPolygon(poly)
\ No newline at end of file
......@@ -35,6 +35,8 @@ class ParticleContextMenu(QtWidgets.QMenu):
combineParticlesSignal = QtCore.pyqtSignal(list, str)
reassignParticlesSignal = QtCore.pyqtSignal(list, str)
paintParticlesSignal = QtCore.pyqtSignal(list, str)
deleteParticlesSignal = QtCore.pyqtSignal(list)
def __init__(self, viewparent):
super(ParticleContextMenu, self).__init__()
self.viewparent = viewparent
......@@ -80,6 +82,7 @@ class ParticleContextMenu(QtWidgets.QMenu):
self.addMenu(self.combineMenu)
self.addMenu(self.reassignMenu)
self.addMenu(self.paintMenu)
self.deleteAct = self.addAction("Delete particle(s)")
action = self.exec_(screenPos)
......@@ -92,6 +95,8 @@ class ParticleContextMenu(QtWidgets.QMenu):
self.reassignParticlesSignal.emit(self.selectedParticleIndices, newAssignment)
elif action in self.paintActs:
self.paintParticlesSignal.emit(self.selectedParticleIndices, newAssignment)
elif action == self.deleteAct:
self.deleteParticlesSignal.emit(self.selectedParticleIndices)
def validifyAssignment(self, assignment):
if assignment == "other":
......@@ -105,7 +110,7 @@ class ParticleContextMenu(QtWidgets.QMenu):
class ParticleEditor(QtCore.QObject):
particleContoursChanged = QtCore.pyqtSignal()
# particleContoursChanged = QtCore.pyqtSignal()
particleAssignmentChanged = QtCore.pyqtSignal()
def __init__(self, viewparent, particleContainer):
super(ParticleEditor, self).__init__()
......@@ -122,6 +127,7 @@ class ParticleEditor(QtCore.QObject):
contextMenu.combineParticlesSignal.connect(self.combineParticles)
contextMenu.reassignParticlesSignal.connect(self.reassignParticles)
contextMenu.paintParticlesSignal.connect(self.paintParticles)
contextMenu.deleteParticlesSignal.connect(self.deleteParticles)
def createSafetyBackup(self):
self.actionCounter += 1
......@@ -146,6 +152,7 @@ class ParticleEditor(QtCore.QObject):
self.viewparent.resetContourIndices()
self.viewparent.addParticleContour(newContour, len(self.viewparent.contourItems))
self.particleAssignmentChanged.emit()
#TODO: INCLUDE SANITY CHECK!!!!!!!!!
@QtCore.pyqtSlot(list, str)
......@@ -177,6 +184,7 @@ class ParticleEditor(QtCore.QObject):
for ind in self.storedIndices:
self.viewparent.removeParticleContour(ind)
self.particleAssignmentChanged.emit()
self.viewparent.resetContourIndices()
self.viewparent.addParticleContour(newContour, len(self.viewparent.contourItems))
......@@ -246,7 +254,20 @@ class ParticleEditor(QtCore.QObject):
return long, short, longellipse, shortellipse, cv2.contourArea(cnt)
@QtCore.pyqtSlot(list)
def deleteParticles(self, contourIndices):
reply = QtWidgets.QMessageBox.question(self, f'About to delete {len(contourIndices)} particles.',
"Are you sure to permanantly delete these particles?",
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No, QtWidgets.QMessageBox.No)
if reply == QtWidgets.QMessageBox.Yes:
for partIndex in sorted(contourIndices, reverse=True):
self.viewparent.removeParticleContour(partIndex)
self.viewparent.dataset.particleContainer.removeParticles([partIndex])
self.viewparent.dataset.particleContainer.resetParticleIndices()
self.viewparent.resetContourIndices()
self.viewparent.analysiswidget.updateHistogramsAndContours()
\ No newline at end of file
......@@ -21,9 +21,11 @@ class SQLExport(QtWidgets.QDialog):
self.particleContainer = particleContainer
# self.polymerList = self.datastats.particleContainer
particlestats = self.datastats.getParticleStats()
self.longSizes = np.round(np.array([i[0] if np.isnan(i[2]) else i[2] for i in particlestats]), 1)
self.shortSize = np.round(np.array([i[1] if np.isnan(i[3]) else i[3] for i in particlestats]), 1)
# particlestats = self.datastats.getParticleStats()
self.longSizes = self.particleContainer.getSizesOfAllParticles()
self.shortSize = self.particleContainer.getShortSizesOfAllParticles()
# self.longSizes = np.round(np.array([i[0] if np.isnan(i[2]) else i[2] for i in particlestats]), 1)
# self.shortSize = np.round(np.array([i[1] if np.isnan(i[3]) else i[3] for i in particlestats]), 1)
#spectra can be quite some data size, they are not copied here but referenced later on...
......@@ -48,7 +50,6 @@ class SQLExport(QtWidgets.QDialog):
self.cnx = None
self.createInterface()
def createInterface(self):
layout = QtWidgets.QVBoxLayout()
self.setLayout(layout)
......@@ -110,7 +111,8 @@ class SQLExport(QtWidgets.QDialog):
for index, entry in enumerate(['Detected Result*', 'DB Polymer Category*', 'DB Categorized Result', 'DB Paint Remark', 'Comment']):
typeLayout.addWidget(QtWidgets.QLabel(entry), 0, index+1)
self.polymerTypes = np.unique(self.polymerList)
# self.polymerTypes = np.unique(self.polymerList)
self.polymerTypes = self.particleContainer.getUniquePolymers()
self.polymerCheckboxes = []
self.db_polyms = []
self.db_categs = []
......@@ -180,8 +182,8 @@ class SQLExport(QtWidgets.QDialog):
for index, polymerType in enumerate(self.polymerTypes):
if self.polymerCheckboxes[index].isChecked():
polymIndices = np.where(self.polymerList == polymerType)[0]
# polymIndices = np.where(self.polymerList == polymerType)[0]
polymIndices = self.particleContainer.getIndicesOfParticleType(polymerType)
particleCols = self.getEntireTable('particles')[0]
sizeCols = [i for i in particleCols if i.startswith('Size') and i.endswith(']')]
......@@ -213,7 +215,7 @@ class SQLExport(QtWidgets.QDialog):
cursor.execute(sql_command)
except:
print(sql_command)
self.cnx.commit()
# self.cnx.commit()
newIndices = self.getPartIndicesOfSample(self.sampleSelector.currentText())
addedParticleIndex = list(set(newIndices) - set(currentParticleInd))[0]
......@@ -244,7 +246,7 @@ class SQLExport(QtWidgets.QDialog):
cursor.execute(sql_command)
except:
print(sql_command)
self.cnx.commit()
# self.cnx.commit()
#remove spectrum for log...
sql_command = format_str.format(method=method, lib=lib, hqi=hqi, spec='SpecFile', res=res, com=com)
self.log.append(sql_command)
......@@ -255,15 +257,14 @@ class SQLExport(QtWidgets.QDialog):
particles2analasyses[addedParticleIndex].append(addedAnalysisIndex)
##upload particles2analyses:
for particleInd in particles2analasyses:
for anaInd in particles2analasyses[particleInd]:
sql_command = """INSERT INTO particles2analysis (IDParticles, IDAnalysis) VALUES ("{}", "{}");""".format(particleInd, anaInd)
cursor.execute(sql_command)
self.log.append(sql_command)
self.cnx.commit()
# ##upload particles2analyses:
# for particleInd in particles2analasyses:
# for anaInd in particles2analasyses[particleInd]:
# sql_command = """INSERT INTO particles2analysis (IDParticles, IDAnalysis) VALUES ("{}", "{}");""".format(particleInd, anaInd)
# cursor.execute(sql_command)
# self.log.append(sql_command)
# self.cnx.commit()
for index, polymType in enumerate(self.polymerTypes):
if self.polymerCheckboxes[index].isChecked():
......
......@@ -270,14 +270,14 @@ class SampleView(QtWidgets.QGraphicsView):
if self.particleEditor is None:
self.particleEditor = ParticleEditor(self, self.dataset.particleContainer)
#try disconnecting the signals. If they are connected multiple times, the functions will run accordingly...
tryDisconnectingSignal(self.particleEditor.particleContoursChanged)
# tryDisconnectingSignal(self.particleEditor.particleContoursChanged)
tryDisconnectingSignal(self.particleEditor.particleAssignmentChanged)
self.particleEditor.particleContoursChanged.connect(self.resetParticleContours)
# self.particleEditor.particleContoursChanged.connect(self.resetParticleContours)
if self.analysiswidget is not None:
self.particleEditor.particleContoursChanged.connect(self.analysiswidget.updateDisplays)
self.particleEditor.particleAssignmentChanged.connect(self.analysiswidget.updateDisplays)
# self.particleEditor.particleContoursChanged.connect(self.analysiswidget.updateHistogramsAndContours)
self.particleEditor.particleAssignmentChanged.connect(self.analysiswidget.updateHistogramsAndContours)
def setMicroscopeMode(self):
if self.ramanSwitchNeeded:
......@@ -320,7 +320,7 @@ class SampleView(QtWidgets.QGraphicsView):
if event.button()==QtCore.Qt.MiddleButton:
self.drag = event.pos()
elif self.particlePainter is None:
if self.particlePainter is None:
if event.button()==QtCore.Qt.LeftButton:
self.checkForContourSelection(event)
......@@ -336,7 +336,7 @@ class SampleView(QtWidgets.QGraphicsView):
p0 = self.mapToScene(event.pos())
super(SampleView, self).mousePressEvent(event)
elif self.particlePainter is not None:
else:
self.particlePainter.mousePressEvent(event)
def mouseMoveEvent(self, event):
......@@ -397,7 +397,8 @@ class SampleView(QtWidgets.QGraphicsView):
I would prefer having it in the viewitems themselves, but somehow the sampleview has to check
for already selected indices and also check when nothing is hit...
'''
def addContourToSelection(cnt):
def acceptSelection(cnt):
self.analysiswidget.setWidgetsToNewParticleIndex(cnt.particleIndex)
cnt.isSelected = True
cnt.update()
self.selectedParticleIndices.append(cnt.particleIndex)
......@@ -412,14 +413,11 @@ class SampleView(QtWidgets.QGraphicsView):
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)
self.analysiswidget.selectParticleOfIndex(cnt.particleIndex, centerOn=False)
acceptSelection(cnt)
else:
if cnt.particleIndex not in self.selectedParticleIndices:
addContourToSelection(cnt)
self.analysiswidget.selectParticleOfIndex(cnt.particleIndex, centerOn=False)
acceptSelection(cnt)
elif cnt.particleIndex in self.selectedParticleIndices:
removeContourFromSelection(cnt)
......@@ -587,13 +585,6 @@ class SampleView(QtWidgets.QGraphicsView):
if self.dataset is not None:
for particleIndex, contour in enumerate(self.dataset.particleContainer.getParticleContours()):
self.addParticleContour(contour, particleIndex)
# newCnt = SegmentationContour(self, contour)
# newCnt.setIndex(particleIndex)
# assignment = self.dataset.particleContainer.getParticleAssignmentByIndex(particleIndex)
# color = getColorFromNameWithSeed(assignment, self.dataset.colorSeed)
# newCnt.setColor(QtGui.QColor(color[0], color[1], color[2], 255))
# self.contourItems.append(newCnt)
# self.scene().addItem(newCnt)
self.update()
print('resetted contours: {} ms'.format(round((time.time()-t0)*1000)))
......@@ -624,10 +615,16 @@ class SampleView(QtWidgets.QGraphicsView):
item.setHighLight(False)
self.ramanscanitems[index].setHighLight(True)
def centerOnRamanIndex(self, index, centerOn=True, highlightContour=True):
def highLightContour(self, index):
print('highlighting contour', index)
for contour in self.contourItems:
contour.isSelected = False
self.contourItems[index].isSelected = True
def centerOnRamanIndex(self, index, centerOn=True, highlightIndex=True):
if centerOn:
self.centerOn(self.ramanscanitems[index])
if highlightContour:
if highlightIndex:
self.highLightRamanIndex(index)
def clearItems(self):
......