Commit 1bf60c7ba0143a9a91c8d5de12e1e51521d1ccc1
1 parent
4ce5fa49
Exists in
measure_placement_test
Rotating the measurement textbox
Showing
2 changed files
with
32 additions
and
5 deletions
Show diff stats
invesalius/data/measures.py
| ... | ... | @@ -584,8 +584,16 @@ class LinearMeasure(object): |
| 584 | 584 | r, g, b = self.colour |
| 585 | 585 | canvas.draw_line(p0, p1, colour=(r*255, g*255, b*255, 255)) |
| 586 | 586 | |
| 587 | + v = np.array(p1) - np.array(p0) | |
| 588 | + t = np.linalg.norm(v) | |
| 589 | + nv = v / t | |
| 590 | + m = (np.array(p1) + np.array(p0)) / 2.0 | |
| 591 | + angle = np.arctan2(v[1], v[0]) | |
| 587 | 592 | txt = u"%.3f mm" % self.GetValue() |
| 588 | - canvas.draw_text_box(txt, ((points[0][0]+points[1][0])/2.0, (points[0][1]+points[1][1])/2.0), txt_colour=MEASURE_TEXT_COLOUR, bg_colour=MEASURE_TEXTBOX_COLOUR) | |
| 593 | + w, h = canvas.calc_text_size(txt) | |
| 594 | + d = t/2.0 - w/2.0 | |
| 595 | + p = np.array(p0) + nv*d | |
| 596 | + canvas.draw_text_box(txt, p, angle=angle, txt_colour=MEASURE_TEXT_COLOUR, bg_colour=MEASURE_TEXTBOX_COLOUR) | |
| 589 | 597 | |
| 590 | 598 | def GetNumberOfPoints(self): |
| 591 | 599 | return len(self.points) | ... | ... |
invesalius/data/viewer_slice.py
| ... | ... | @@ -217,7 +217,7 @@ class CanvasRendererCTX: |
| 217 | 217 | self.image.SetAlphaBuffer(self.alpha) |
| 218 | 218 | self.image.Clear() |
| 219 | 219 | gc = wx.GraphicsContext.Create(self.image) |
| 220 | - gc.SetAntialiasMode(0) | |
| 220 | + gc.SetAntialiasMode(1) | |
| 221 | 221 | |
| 222 | 222 | self.gc = gc |
| 223 | 223 | |
| ... | ... | @@ -389,7 +389,7 @@ class CanvasRendererCTX: |
| 389 | 389 | px, py = pos |
| 390 | 390 | gc.DrawText(text, px, py) |
| 391 | 391 | |
| 392 | - def draw_text_box(self, text, pos, font=None, txt_colour=(255, 255, 255), bg_colour=(128, 128, 128, 128), border=5): | |
| 392 | + def draw_text_box(self, text, pos, angle=0.0, font=None, txt_colour=(255, 255, 255), bg_colour=(128, 128, 128, 128), border=5): | |
| 393 | 393 | """ |
| 394 | 394 | Draw text inside a text box. |
| 395 | 395 | |
| ... | ... | @@ -415,13 +415,19 @@ class CanvasRendererCTX: |
| 415 | 415 | px, py = pos |
| 416 | 416 | py = -py |
| 417 | 417 | |
| 418 | + gc.PushState() | |
| 419 | + gc.Translate(px, py) | |
| 420 | + gc.Rotate(-angle) | |
| 421 | + | |
| 418 | 422 | # Drawing the box |
| 419 | 423 | cw, ch = w + border * 2, h + border * 2 |
| 420 | - self.draw_rectangle((px, py), cw, ch, bg_colour, bg_colour) | |
| 424 | + self.draw_rectangle((0, 0), cw, ch, bg_colour, bg_colour) | |
| 421 | 425 | |
| 422 | 426 | # Drawing the text |
| 423 | 427 | tpx, tpy = px + border, py + border |
| 424 | - self.draw_text(text, (tpx, tpy), font, txt_colour) | |
| 428 | + self.draw_text(text, (border, border), font, txt_colour) | |
| 429 | + | |
| 430 | + gc.PopState() | |
| 425 | 431 | |
| 426 | 432 | def draw_arc(self, center, p0, p1, line_colour=(255, 0, 0, 128), width=2): |
| 427 | 433 | """ |
| ... | ... | @@ -465,6 +471,19 @@ class CanvasRendererCTX: |
| 465 | 471 | path.AddArc((c[0], c[1]), min(s0, s1), sa, ea) |
| 466 | 472 | gc.StrokePath(path) |
| 467 | 473 | |
| 474 | + def calc_text_size(self, text, font=None): | |
| 475 | + if self.gc is None: | |
| 476 | + return None | |
| 477 | + gc = self.gc | |
| 478 | + | |
| 479 | + if font is None: | |
| 480 | + font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT) | |
| 481 | + | |
| 482 | + _font = gc.CreateFont(font) | |
| 483 | + gc.SetFont(_font) | |
| 484 | + w, h = gc.GetTextExtent(text) | |
| 485 | + return w, h | |
| 486 | + | |
| 468 | 487 | |
| 469 | 488 | class Viewer(wx.Panel): |
| 470 | 489 | ... | ... |