implemented edge splitting when a new temp level is inserted

This commit is contained in:
Stefan Kögl 2012-11-28 20:34:45 +01:00
parent ef6298cc44
commit fbb9e3d849
5 changed files with 46 additions and 31 deletions

View File

@ -11,6 +11,11 @@ class Edge(QtCore.QObject):
self.duration = duration self.duration = duration
self.rate = rate self.rate = rate
def contains(self, temp_level):
return (
(self.from_tl.temp < temp_level.temp < self.to_tl.temp) or
(self.from_tl.temp > temp_level.temp > self.to_tl.temp))
def __repr__(self): def __repr__(self):
return "Edge(%r, %r, %r, %r)" % (self.from_tl, self.to_tl, self.duration, self.rate) return "Edge(%r, %r, %r, %r)" % (self.from_tl, self.to_tl, self.duration, self.rate)
@ -141,19 +146,33 @@ class ConstraintWidget(QtGui.QWidget):
print self.temp_level_added print self.temp_level_added
self.edge_changed.emit() self.edge_changed.emit()
def temp_level_added(self, old_tl, new_tl): def temp_level_added(self, new_tl):
print self.temp_level_added, len(self.edge_model.edges) print self.temp_level_added, len(self.edge_model.edges)
new_edge = None new_edges = list()
ix = 0 ix = 0
for ix, edge in enumerate(self.edge_model.edges): batch = list()
print ix, edge for edge in self.edge_model.edges:
if edge.from_tl == old_tl: if edge.contains(new_tl):
batch.append(edge)
for edge in batch:
if edge.from_tl < new_tl:
duration = None if edge.duration is None else edge.duration / 2 duration = None if edge.duration is None else edge.duration / 2
new_edge = Edge(new_tl, edge.to_tl, duration, edge.rate) new_edge = Edge(new_tl, edge.to_tl, duration, edge.rate)
edge.duration = duration edge.duration = duration
edge.to_tl = new_tl edge.to_tl = new_tl
break ix = self.edge_model.edges.index(edge)
self.edge_model.edges.insert(ix+1, new_edge)
else:
duration = None if edge.duration is None else edge.duration / 2
new_edge = Edge(new_tl, edge.to_tl, duration, edge.rate)
edge.duration = duration
edge.to_tl = new_tl
ix = self.edge_model.edges.index(edge)
self.edge_model.edges.insert(ix+1, new_edge) self.edge_model.edges.insert(ix+1, new_edge)
self.edge_model.reset()
print "end", self.temp_level_added
#for i in new_edges:
#print repr(i)
#for edge, new_edge in new_edges:
self.edge_model.reset()

View File

@ -100,12 +100,9 @@ class Plotter(FigureCanvas):
self.y = list() self.y = list()
try: try:
(self.x, self.y, self.xmin, self.xmax, self.ymin, self.ymax, (self.x, self.y, self.xmin, self.xmax, self.ymin, self.ymax) = self.solder.calc_profile()
self.used, self.unused) = self.solder.calc_profile()
except ValueError: except ValueError:
(self.x, self.y, self.xmin, self.xmax, self.ymin, self.ymax, (self.x, self.y, self.xmin, self.xmax, self.ymin, self.ymax) = ([], [], 0., 300., 0., 300.)
self.used, self.unused) = ([], [], 0., 300., 0., 300., [],
self.solder.temp_levels)
self.plot_data.set_xdata(self.x) self.plot_data.set_xdata(self.x)
self.plot_data.set_ydata(self.y) self.plot_data.set_ydata(self.y)
@ -363,6 +360,8 @@ class ApplicationWindow(QtGui.QMainWindow):
self.plotter_splitter.addWidget(self.plotter) self.plotter_splitter.addWidget(self.plotter)
self.plotter_splitter.addWidget(self.profile_log) self.plotter_splitter.addWidget(self.profile_log)
self.plotter_splitter.setStretchFactor(0, 8)
self.plotter_splitter.setStretchFactor(1, 2)
self.splitter.addWidget(self.settings_widget) self.splitter.addWidget(self.settings_widget)
self.splitter.addWidget(self.controls_widget) self.splitter.addWidget(self.controls_widget)
@ -374,7 +373,7 @@ class ApplicationWindow(QtGui.QMainWindow):
self.setCentralWidget(self.splitter) self.setCentralWidget(self.splitter)
self.statusBar().showMessage("Reflow GORE!1!", 10000) self.statusBar().showMessage("Reflow GORE!1!", 10000)
self.plotter.solder_changed() self.plotter.update_figure()
def getPlotter(self): def getPlotter(self):
return self.plotter return self.plotter
@ -386,6 +385,8 @@ class ApplicationWindow(QtGui.QMainWindow):
self.constraint_widget.setData(solder) self.constraint_widget.setData(solder)
self.plotter.setData(solder) self.plotter.setData(solder)
solder.log_message.connect(self.profile_log.setPlainText) solder.log_message.connect(self.profile_log.setPlainText)
if not self.plotter.started:
self.plotter.update_figure()
def edge_picked(self, ix): def edge_picked(self, ix):
if self.tab_widget.currentIndex() != 1: if self.tab_widget.currentIndex() != 1:

View File

@ -50,13 +50,7 @@ class Solder(QtCore.QObject):
return i return i
return None return None
#def get_temp_level(self, ix):
#assert isinstance(ix, int)
#return self.temp_levels[ix]
def calc_profile(self): def calc_profile(self):
print self.calc_profile
self.log = list() self.log = list()
x = list() x = list()
y = list() y = list()
@ -69,16 +63,17 @@ class Solder(QtCore.QObject):
return time + edge.duration return time + edge.duration
elif edge.rate: elif edge.rate:
return time + (edge.to_tl.temp - edge.from_tl.temp) / edge.rate return time + (edge.to_tl.temp - edge.from_tl.temp) / edge.rate
else:
raise Exception("edge %r has neither duration nor rate set" % edge)
for _edge in self.edges: for _edge in self.edges:
x.append(time) x.append(float(time))
y.append(_edge.from_tl.temp) y.append(float(_edge.from_tl.temp))
time = calc(_edge) time = calc(_edge)
x.append(time) x.append(time)
y.append(_edge.to_tl.temp) y.append(_edge.to_tl.temp)
print "end", self.calc_profile return array(x), array(y), min(x), max(x), min(y), max(y)
return array(map(float, x)), array(map(float, y)), min(x), max(x), min(y), max(y), set(), set()
@staticmethod @staticmethod
@ -223,8 +218,8 @@ class SolderWidget(QtGui.QWidget):
self.solder_controls = AddRemoveWidget(self) self.solder_controls = AddRemoveWidget(self)
layout = QtGui.QHBoxLayout(self) layout = QtGui.QHBoxLayout(self)
layout.addWidget(self.solder_view, 3) layout.addWidget(self.solder_view)
layout.addWidget(self.solder_controls, 1) layout.addWidget(self.solder_controls)
self.connect( self.connect(
self.solder_controls.add_button, self.solder_controls.add_button,

View File

@ -1,2 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?> <?xml version='1.0' encoding='UTF-8'?>
<xml><solder_type description="" name="lead noclean"><state name="environment temp" temperature="$ENV" /><state name="preheat start" temperature="150" /><state name="preheat end" temperature="185" /><state name="tal" temperature="230" /><state name="peak" temperature="260" /><edge duration="None" from="environment temp" rate="1.0" to="preheat start" /><edge duration="100.0" from="preheat start" rate="1.0" to="preheat end" /><edge duration="None" from="preheat end" rate="1.0" to="tal" /><edge duration="50.0" from="tal" rate="1.0" to="peak" /><edge duration="50.0" from="peak" rate="-1.0" to="tal" /><edge duration="None" from="tal" rate="-2.0" to="preheat end" /><edge duration="None" from="preheat end" rate="-2.0" to="preheat start" /><edge duration="None" from="preheat start" rate="-2.0" to="environment temp" /></solder_type></xml> <xml><solder_type description="" name="lead noclean"><state name="environment temp" temperature="$ENV" /><state name="preheat start" temperature="150" /><state name="preheat end" temperature="185" /><state name="tal" temperature="230" /><state name="peak-5°C" temperature="255" /><state name="peak" temperature="260" /><edge duration="None" from="environment temp" rate="1.0" to="preheat start" /><edge duration="100.0" from="preheat start" rate="1.0" to="preheat end" /><edge duration="None" from="preheat end" rate="1.0" to="tal" /><edge duration="25.0" from="tal" rate="1.0" to="peak-5°C" /><edge duration="25.0" from="peak-5°C" rate="1.0" to="peak" /><edge duration="25.0" from="peak" rate="-1.0" to="peak-5°C" /><edge duration="25.0" from="peak-5°C" rate="-1.0" to="tal" /><edge duration="None" from="tal" rate="-3.0" to="preheat end" /><edge duration="None" from="preheat end" rate="-2.0" to="preheat start" /><edge duration="None" from="preheat start" rate="-2.0" to="environment temp" /></solder_type></xml>

View File

@ -140,7 +140,7 @@ class TempLevelModel(QtCore.QAbstractTableModel):
if index.isValid() and role == QtCore.Qt.EditRole: if index.isValid() and role == QtCore.Qt.EditRole:
col = index.column() col = index.column()
if col == 0: if col == 0:
self.temp_levels[index.row()].name = str(variant.toString()) self.temp_levels[index.row()].name = unicode(variant.toString())
elif col == 1: elif col == 1:
temp, res = variant.toInt() temp, res = variant.toInt()
tl = self.temp_levels[index.row()] tl = self.temp_levels[index.row()]
@ -195,7 +195,7 @@ class TempLevelModel(QtCore.QAbstractTableModel):
class TempLevelWidget(QtGui.QWidget): class TempLevelWidget(QtGui.QWidget):
temp_level_removed = QtCore.pyqtSignal(TempLevel) temp_level_removed = QtCore.pyqtSignal(TempLevel)
temp_level_added = QtCore.pyqtSignal(TempLevel, TempLevel) temp_level_added = QtCore.pyqtSignal(TempLevel)
temp_levels_changed = QtCore.pyqtSignal() temp_levels_changed = QtCore.pyqtSignal()
solder_changed = QtCore.pyqtSignal() solder_changed = QtCore.pyqtSignal()
@ -260,7 +260,7 @@ class TempLevelWidget(QtGui.QWidget):
self.temp_level_view.setCurrentIndex(self.temp_level_model.index(index.row() + 1, 0)) self.temp_level_view.setCurrentIndex(self.temp_level_model.index(index.row() + 1, 0))
self.temp_levels_changed.emit() self.temp_levels_changed.emit()
print "TempLevelWidget.add_temp_level 1", old_tl, new_tl print "TempLevelWidget.add_temp_level 1", old_tl, new_tl
self.temp_level_added.emit(old_tl, new_tl) self.temp_level_added.emit(new_tl)
print "TempLevelWidget.add_temp_level 2" print "TempLevelWidget.add_temp_level 2"