summaryrefslogtreecommitdiffstats
path: root/tksao/frame/baseline.C
blob: a1c5598010a763f11519af77c902c4066b8df23d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Copyright (C) 1999-2018
// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
// For conditions of distribution and use, see copyright notice in "copyright"

#include <tk.h>

#include "baseline.h"
#include "fitsimage.h"

BaseLine::BaseLine(Base* p, const Vector& ptr1, const Vector& ptr2)
  : Marker(p, ptr1, 0)
{
  p1 = ptr1;
  p2 = ptr2;
}

BaseLine::BaseLine(Base* p, const Vector& ptr1, const Vector& ptr2,
		   const char* clr, int* dsh, 
		   int wth, const char* fnt, const char* txt,
		   unsigned short prop, const char* cmt, 
		   const List<Tag>& tg, const List<CallBack>& cb) 
  : Marker(p, ptr1, 0, clr, dsh, wth, fnt, txt, prop, cmt, tg, cb)
{
  p1 = ptr1;
  p2 = ptr2;
}

BaseLine::BaseLine(const BaseLine& a) : Marker(a)
{
  p1 = a.p1;
  p2 = a.p2;
}

void BaseLine::updateCoords(const Matrix& mx)
{
  p1*=mx;
  p2*=mx;

  Marker::updateCoords(mx);
}

void BaseLine::centroid()
{
  p1 = parent->centroid(p1);
  p2 = parent->centroid(p2);

  updateBBox();
  doCallBack(CallBack::MOVECB);
}

void BaseLine::move(const Vector& v)
{
  p1+=v;
  p2+=v;

  updateBBox();
  doCallBack(CallBack::MOVECB);
}

void BaseLine::moveTo(const Vector& v)
{
  // v is the new location of the center
  Vector diff = v - center;
  p1+=diff;
  p2+=diff;

  updateBBox();
  doCallBack(CallBack::MOVECB);
}

int BaseLine::isIn(const Vector& v)
{
  // do this in canvas coords, not ref coords
  Vector l1 = parent->mapFromRef(p1,Coord::CANVAS);
  Vector l2 = parent->mapFromRef(p2,Coord::CANVAS);
  double a = (l2-l1).angle();

  Matrix m = Translate(-l1) * Rotate(a);
  Vector vv = v*m;
  Vector end = l2*m;
  return (vv[0]>0 && vv[0]<end[0] && 
	  vv[1]>-parent->markerEpsilon && vv[1]<parent->markerEpsilon);
}

void BaseLine::edit(const Vector& v, int h)
{
  switch (h) {
  case 1:
    p1 = v;
    break;
  case 2:
    p2 = v;
    break;
  }

  updateBBox();
  doCallBack(CallBack::EDITCB);
}

void BaseLine::setPoints(const Vector& v1, const Vector& v2)
{
  p1 = v1;
  p2 = v2;

  updateBBox();
  doCallBack(CallBack::EDITCB);
}

// special composite funtionallity

void BaseLine::setComposite(const Matrix& mx, double aa)
{
  p1 *= mx;
  p2 *= mx;

  updateBBox();
}