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.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):
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
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)
new_edge = None
new_edges = list()
ix = 0
for ix, edge in enumerate(self.edge_model.edges):
print ix, edge
if edge.from_tl == old_tl:
batch = list()
for edge in self.edge_model.edges:
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
new_edge = Edge(new_tl, edge.to_tl, duration, edge.rate)
edge.duration = duration
edge.to_tl = new_tl
break
self.edge_model.edges.insert(ix+1, new_edge)
self.edge_model.reset()
print "end", self.temp_level_added
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)
#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()
try:
(self.x, self.y, self.xmin, self.xmax, self.ymin, self.ymax,
self.used, self.unused) = self.solder.calc_profile()
(self.x, self.y, self.xmin, self.xmax, self.ymin, self.ymax) = self.solder.calc_profile()
except ValueError:
(self.x, self.y, self.xmin, self.xmax, self.ymin, self.ymax,
self.used, self.unused) = ([], [], 0., 300., 0., 300., [],
self.solder.temp_levels)
(self.x, self.y, self.xmin, self.xmax, self.ymin, self.ymax) = ([], [], 0., 300., 0., 300.)
self.plot_data.set_xdata(self.x)
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.profile_log)
self.plotter_splitter.setStretchFactor(0, 8)
self.plotter_splitter.setStretchFactor(1, 2)
self.splitter.addWidget(self.settings_widget)
self.splitter.addWidget(self.controls_widget)
@ -374,7 +373,7 @@ class ApplicationWindow(QtGui.QMainWindow):
self.setCentralWidget(self.splitter)
self.statusBar().showMessage("Reflow GORE!1!", 10000)
self.plotter.solder_changed()
self.plotter.update_figure()
def getPlotter(self):
return self.plotter
@ -386,6 +385,8 @@ class ApplicationWindow(QtGui.QMainWindow):
self.constraint_widget.setData(solder)
self.plotter.setData(solder)
solder.log_message.connect(self.profile_log.setPlainText)
if not self.plotter.started:
self.plotter.update_figure()
def edge_picked(self, ix):
if self.tab_widget.currentIndex() != 1:

View File

@ -50,13 +50,7 @@ class Solder(QtCore.QObject):
return i
return None
#def get_temp_level(self, ix):
#assert isinstance(ix, int)
#return self.temp_levels[ix]
def calc_profile(self):
print self.calc_profile
self.log = list()
x = list()
y = list()
@ -69,16 +63,17 @@ class Solder(QtCore.QObject):
return time + edge.duration
elif 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:
x.append(time)
y.append(_edge.from_tl.temp)
x.append(float(time))
y.append(float(_edge.from_tl.temp))
time = calc(_edge)
x.append(time)
y.append(_edge.to_tl.temp)
print "end", self.calc_profile
return array(map(float, x)), array(map(float, y)), min(x), max(x), min(y), max(y), set(), set()
return array(x), array(y), min(x), max(x), min(y), max(y)
@staticmethod
@ -223,8 +218,8 @@ class SolderWidget(QtGui.QWidget):
self.solder_controls = AddRemoveWidget(self)
layout = QtGui.QHBoxLayout(self)
layout.addWidget(self.solder_view, 3)
layout.addWidget(self.solder_controls, 1)
layout.addWidget(self.solder_view)
layout.addWidget(self.solder_controls)
self.connect(
self.solder_controls.add_button,

View File

@ -1,2 +1,2 @@
<?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:
col = index.column()
if col == 0:
self.temp_levels[index.row()].name = str(variant.toString())
self.temp_levels[index.row()].name = unicode(variant.toString())
elif col == 1:
temp, res = variant.toInt()
tl = self.temp_levels[index.row()]
@ -195,7 +195,7 @@ class TempLevelModel(QtCore.QAbstractTableModel):
class TempLevelWidget(QtGui.QWidget):
temp_level_removed = QtCore.pyqtSignal(TempLevel)
temp_level_added = QtCore.pyqtSignal(TempLevel, TempLevel)
temp_level_added = QtCore.pyqtSignal(TempLevel)
temp_levels_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_levels_changed.emit()
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"