Skip to content

Commit

Permalink
Improvement about canvas function.
Browse files Browse the repository at this point in the history
  • Loading branch information
KmolYuan committed Aug 18, 2017
1 parent 998b6d3 commit 2207b1a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 25 deletions.
29 changes: 5 additions & 24 deletions core/graphics/Path_Solving_preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,8 @@ def paintEvent(self, event):
self.painter.translate(origin_x, origin_y)
expression = self.mechanism['mechanismParams']['Expression'].split(',')
expression_tag = tuple(tuple(expression[i+j] for j in range(5)) for i in range(0, len(expression), 5))
pen.setWidth(self.linkWidth+2)
pen.setColor(QColor(225, 140, 0))
self.painter.setPen(pen)
shaft_r = self.Paths[expression_tag[0][-1]][self.index]
self.painter.drawLine(QPointF(self.mechanism['Ax']*Tp, self.mechanism['Ay']*Tp*-1), QPointF(shaft_r[0]*Tp, shaft_r[1]*Tp*-1))
self.drawShaft(0, self.mechanism['Ax']*Tp, self.mechanism['Ay']*Tp*-1, shaft_r[0]*Tp, shaft_r[1]*Tp*-1)
for i, exp in enumerate(expression_tag[1:]):
p_l = list()
for i, k in enumerate([0, 3, -1]):
Expand All @@ -92,11 +89,8 @@ def paintEvent(self, event):
p_l.append(QPointF(self.mechanism['Ax']*Tp, self.mechanism['Ay']*Tp*-1))
else:
p_l.append(QPointF(self.mechanism['Dx']*Tp, self.mechanism['Dy']*Tp*-1))
pen.setWidth(self.linkWidth)
pen.setColor(Qt.darkGray)
self.painter.setPen(pen)
self.painter.drawLine(p_l[2], p_l[0])
self.painter.drawLine(p_l[2], p_l[1])
self.drawLink(0, p_l[2].x(), p_l[2].y(), p_l[0].x(), p_l[0].y(), str())
self.drawLink(0, p_l[2].x(), p_l[2].y(), p_l[1].x(), p_l[1].y(), str())
for i, tag in enumerate(sorted(list(self.Paths.keys()))):
pen.setWidth(self.linkWidth)
pen.setColor(self.Color['Green'] if i<len(self.Paths)-1 else self.Color['Brick-Red'])
Expand All @@ -112,17 +106,11 @@ def paintEvent(self, event):
for tag in ['A', 'D']:
x = self.mechanism[tag+'x']*Tp
y = self.mechanism[tag+'y']*Tp*-1
pen.setWidth(2)
pen.setColor(self.Color['Blue'])
self.painter.setPen(pen)
self.drawPoint(x, y, True)
self.drawPoint(0, x, y, True, self.Color['Blue'])
for i, tag in enumerate(sorted(list(self.Paths.keys()))):
x = self.Paths[tag][self.index][0]*Tp
y = self.Paths[tag][self.index][1]*Tp*-1
pen.setWidth(2)
pen.setColor(self.Color['Green'] if i<len(self.Paths)-1 else self.Color['Brick-Red'])
self.painter.setPen(pen)
self.drawPoint(x, y, False)
self.drawPoint(0, x, y, False, self.Color['Green'] if i<len(self.Paths)-1 else self.Color['Brick-Red'])
pathData = self.mechanism['mechanismParams']['targetPath']
pen.setWidth(self.pathWidth+3)
pen.setColor(QColor(69, 247, 232))
Expand All @@ -143,13 +131,6 @@ def paintEvent(self, event):
self.painter.drawText(QPoint(0, 0), "Error occurred!\nPlease check dimension data.")
self.painter.end()

def drawPoint(self, x, y, fix):
if fix:
self.painter.drawPolygon(QPointF(x, y), QPointF(x-10, y+20), QPointF(x+10, y+20))
self.painter.drawEllipse(QPointF(x, y), 10., 10.)
else:
self.painter.drawEllipse(QPointF(x, y), 5., 5.)

@pyqtSlot(int)
def change_index(self, i):
self.index = i
Expand Down
4 changes: 3 additions & 1 deletion core/graphics/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,15 @@ def __init__(self, parent=None):
self.linkWidth = 3
self.pathWidth = 3
self.Color = colorlist()
self.Point_mark = False
self.showDimension = False

def paintEvent(self, event):
self.painter = QPainter()
self.painter.begin(self)
self.painter.fillRect(event.rect(), QBrush(Qt.white))

def drawPoint(self, i, x, y, fix, color, cx, cy):
def drawPoint(self, i, x, y, fix, color, cx=0, cy=0):
pen = QPen()
pen.setWidth(2)
pen.setColor(color)
Expand Down

0 comments on commit 2207b1a

Please sign in to comment.