view_link.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // package view_link -- отображение связи между объектами
  2. package view_link
  3. import (
  4. svg "github.com/ajstarks/svgo"
  5. "gitp78su.ipnodns.ru/svi/kern/v3"
  6. "gitp78su.ipnodns.ru/svi/goarch/lev0/types"
  7. "gitp78su.ipnodns.ru/svi/goarch/lev1/arch_link"
  8. )
  9. // ViewLink -- отображение связи между объектами
  10. type ViewLink struct {
  11. *arch_link.ArchLink
  12. Coord_ types.IViewCoord
  13. CoordEnd_ types.IViewCoord
  14. Offset_ types.IViewOffset
  15. }
  16. var (
  17. hassert = kern.GetFnHassert()
  18. )
  19. // NewViewLink -- возвращает новое отображение связи
  20. func NewViewLink(archLink *arch_link.ArchLink, coord, coordEnd types.IViewCoord,
  21. offset types.IViewOffset) *ViewLink {
  22. hassert(archLink != nil, "NewViewLink: archLink == nil")
  23. hassert(coord != nil, "NewViewLink: coord == nil")
  24. hassert(offset != nil, "NewViewLink: offset == nil")
  25. sf := &ViewLink{
  26. ArchLink: archLink,
  27. Coord_: coord,
  28. CoordEnd_: coordEnd,
  29. Offset_: offset,
  30. }
  31. return sf
  32. }
  33. // Draw -- рисует связь между объектами
  34. func (sf *ViewLink) Draw(canvas *svg.SVG) {
  35. x, y := sf.Coord_.Int()
  36. x1, y1 := sf.CoordEnd_.Int()
  37. offX, offY := sf.Offset_.Int()
  38. // Линия
  39. canvas.Line(x, y, x1, y1, "stroke:black;stroke-width:1")
  40. strLabel := sf.String()
  41. if strLabel != "" {
  42. canvas.Text(x+offX, y+offY, strLabel, "font-size: 12px; font-family: Courier; fill: black")
  43. }
  44. if sf.TypeLink() != "" {
  45. canvas.Text(x+offX, y+offY+12, "<<"+sf.TypeLink()+">>", "font-size: 12px; font-family: Courier; fill: black")
  46. }
  47. if msgErr := sf.Check(); msgErr != "" { // Проверка на правильность
  48. canvas.Group("Ошибка")
  49. canvas.Title(msgErr)
  50. canvas.Image(x-20+offX, y-20+offY, 16, 16, "/static/img/warning.png")
  51. }
  52. canvas.Gend() // Group end
  53. }
  54. // CoordEnd -- координаты конца связи
  55. //
  56. //go:fix inline
  57. func (sf *ViewLink) CoordEnd() types.IViewCoord {
  58. return sf.CoordEnd_
  59. }