summaryrefslogtreecommitdiffstats
path: root/tksao/frame/vect.C
blob: e9e9dff0f679d37219f8c8ddb054f26f7f774b8e (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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// Copyright (C) 1999-2016
// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
// For conditions of distribution and use, see copyright notice in "copyright"

#include <tk.h>

#include "vect.h"
#include "fitsimage.h"

Vect::Vect(Base* p, const Vector& pt, double mag, double ang)
  : Line(p, pt, pt)
{
  strcpy(type_,"vector");
  p2 = Vector(mag,0) * Rotate(ang) * FlipY() * Translate(p1);
  updateBBox();
}

Vect::Vect(Base* p, const Vector& pt,
	   double mag, double ang,
	   int arr,
	   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) 
  : Line(p, pt, pt, 0, arr, clr, dsh, wth, fnt, txt, prop, cmt, tg, cb)
{
  strcpy(type_,"vector");
  p2 = Vector(mag,0) * Rotate(ang) * FlipY() * Translate(p1);
  updateBBox();
}

Vect::Vect(Base* p, const Vector& ptr1,
	   const Vector& ptr2,
	   int arr,
	   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) 
  : Line(p, ptr1, ptr2, 0, arr, clr, dsh, wth, fnt, txt, prop, cmt, tg, cb)
{
  strcpy(type_,"vector");
}

void Vect::setPoints(const Vector& pt, double mag, double ang)
{
  p1 = pt;
  p2 = Vector(mag,0) * Rotate(ang) * FlipY() * Translate(p1);
  updateBBox();

  doCallBack(CallBack::EDITCB);
}

// list

void Vect::list(ostream& str, Coord::CoordSystem sys, Coord::SkyFrame sky, 
		Coord::SkyFormat format, int conj, int strip)
{
  if (!strip) {
    FitsImage* ptr = parent->findFits(sys,center);
    listPre(str, sys, sky, ptr, strip, 1);

    switch (sys) {
    case Coord::IMAGE:
    case Coord::PHYSICAL:
    case Coord::DETECTOR:
    case Coord::AMPLIFIER:
      listNonCel(ptr, str, sys);
      break;
    default:
      if (ptr->hasWCSCel(sys)) {
	double rr = ptr->mapLenFromRef((p2-p1).length(),sys,Coord::ARCSEC);
	double aa = parent->mapAngleFromRef((p2-p1).angle(),sys,sky);
	switch (format) {
	case Coord::DEGREES:
	  {
	    Vector v1 = ptr->mapFromRef(p1,sys,sky);
	    str << type_ << '(' << setprecision(10) << v1 << ','
		<< setprecision(3) << fixed << rr << '"' << ',';
	    str.unsetf(ios_base::floatfield);
	    str << setprecision(8) << radToDeg(aa) << ')';
	  }
	  break;
	case Coord::SEXAGESIMAL:
	  listRADEC(ptr,p1,sys,sky,format);
	  str << type_ << '(' << ra << ',' << dec << ',' 
	      << setprecision(3) << fixed << rr << '"' << ',';
	  str.unsetf(ios_base::floatfield);
	  str << setprecision(8) << radToDeg(aa) << ')';
	  break;
	}
      }
      else
	listNonCel(ptr, str, sys);
    }

    if (conj)
      str << " ||";

    str << " vector=" << p2Arrow;
    listProperties(str, 0);
  }
}

void Vect::listNonCel(FitsImage* ptr, ostream& str, Coord::CoordSystem sys)
{
  Vector v1 = ptr->mapFromRef(p1,sys);
  double rr = ptr->mapLenFromRef((p2-p1).length(),sys);
  double aa = parent->mapAngleFromRef((p2-p1).angle(),sys);
  str << type_ << '(' << setprecision(8) << v1 << ','
      << rr << ',' << radToDeg(aa) << ')';
}

void Vect::listXML(ostream& str, Coord::CoordSystem sys, Coord::SkyFrame sky, 
		   Coord::SkyFormat format)
{
  FitsImage* ptr = parent->findFits(sys,center);
  double rr = ptr->mapLenFromRef((p2-p1).length(),sys,Coord::ARCSEC);
  
  XMLRowInit();
  XMLRow(XMLSHAPE,type_);

  XMLRowPoint(ptr,sys,sky,format,p1);
  
  switch (sys) {
  case Coord::IMAGE:
  case Coord::PHYSICAL:
  case Coord::DETECTOR:
  case Coord::AMPLIFIER:
    XMLRow(XMLR,rr,8);
    break;
  default:
    if (ptr->hasWCS(sys)) {
      if (ptr->hasWCSCel(sys))
	XMLRowARCSEC(XMLR,rr);
      else
	XMLRow(XMLR,rr,8);
    }
    break;
  }

  XMLRowAng(sys,sky);
  XMLRow(XMLPARAM,p2Arrow);

  XMLRowProps(ptr,sys);
  XMLRowEnd(str);
}