~ubuntu-branches/ubuntu/raring/kstars/raring

« back to all changes in this revision

Viewing changes to kstars/fov.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell, Jonathan Riddell, Harald Sitter
  • Date: 2012-11-19 16:07:49 UTC
  • mfrom: (1.1.16)
  • Revision ID: package-import@ubuntu.com-20121119160749-v7vdmo0iswx66dn8
Tags: 4:4.9.80-0ubuntu1
[ Jonathan Riddell ]
* New upstream beta release

[ Harald Sitter ]
* Build dep on wcslib-dev (new dep)
* Build dep on libindi-dev >= 0.9.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
    return (s >= FOV::UNKNOWN || s < 0) ? FOV::UNKNOWN : static_cast<FOV::Shape>(s);
32
32
33
33
 
34
 
FOV::FOV( const QString &n, float a, float b, Shape sh, const QString &col ) :
35
 
    m_name( n ), m_color( col ), m_sizeX( a ), m_shape( sh )
 
34
FOV::FOV( const QString &n, float a, float b, float xoffset, float yoffset, float rot, Shape sh, const QString &col )
36
35
 
36
    m_name = n;
 
37
    m_sizeX = a;
37
38
    m_sizeY = (b < 0.0) ? a : b;
 
39
 
 
40
    m_offsetX     = xoffset;
 
41
    m_offsetY     = yoffset;
 
42
    m_rotation    = rot;
 
43
    m_shape       = sh;
 
44
    m_color       = col;
38
45
39
46
 
40
 
FOV::FOV() :
41
 
    m_name( i18n( "No FOV" ) ), m_color( "#FFFFFF" ), m_sizeX( 0.0 ), m_sizeY( 0.0 ), m_shape( SQUARE )
42
 
{}
 
47
FOV::FOV()
 
48
{
 
49
    m_name  = i18n( "No FOV" );
 
50
    m_color = "#FFFFFF";
 
51
 
 
52
    m_sizeX = m_sizeY = 0;
 
53
    m_shape = SQUARE;
 
54
    m_offsetX=m_offsetY=m_rotation=0;
 
55
}
43
56
 
44
57
void FOV::draw( QPainter &p, float zoomFactor ) {
45
58
    p.setPen( QColor( color() ) );
47
60
    
48
61
    p.setRenderHint( QPainter::Antialiasing, Options::useAntialias() );
49
62
 
 
63
 
50
64
    float pixelSizeX = sizeX() * zoomFactor / 57.3 / 60.0;
51
65
    float pixelSizeY = sizeY() * zoomFactor / 57.3 / 60.0;
52
 
    QPointF center = p.viewport().center();
53
 
    switch ( shape() ) {
 
66
 
 
67
    float offsetXPixelSize = offsetX() * zoomFactor / 57.3 / 60.0;
 
68
    float offsetYPixelSize = offsetY() * zoomFactor / 57.3 / 60.0;
 
69
 
 
70
    p.save();
 
71
    p.translate(p.viewport().center());
 
72
 
 
73
    p.translate(offsetXPixelSize,  offsetYPixelSize);
 
74
    p.rotate(rotation());
 
75
 
 
76
    QPointF center(0,0);
 
77
 
 
78
    switch ( shape() )
 
79
    {
54
80
    case SQUARE: 
55
81
        p.drawRect( center.x() - pixelSizeX/2, center.y() - pixelSizeY/2, pixelSizeX, pixelSizeY);
56
82
        break;
86
112
    }
87
113
    default: ; 
88
114
    }
 
115
 
 
116
    p.restore();
89
117
}
90
118
 
91
119
void FOV::draw(QPainter &p, float x, float y)
111
139
{
112
140
    QList<FOV*> fovs;
113
141
    fovs << new FOV(i18nc("use field-of-view for binoculars", "7x35 Binoculars" ),
114
 
                    558,  558,  CIRCLE,"#AAAAAA")
 
142
                    558,  558, 0,0,0, CIRCLE,"#AAAAAA")
115
143
         << new FOV(i18nc("use a Telrad field-of-view indicator", "Telrad" ),
116
 
                    30,   30,   BULLSEYE,"#AA0000")
 
144
                    30,   30, 0,0,0,   BULLSEYE,"#AA0000")
117
145
         << new FOV(i18nc("use 1-degree field-of-view indicator", "One Degree"),
118
 
                    60,   60,   CIRCLE,"#AAAAAA")
 
146
                    60,   60, 0,0,0,  CIRCLE,"#AAAAAA")
119
147
         << new FOV(i18nc("use HST field-of-view indicator", "HST WFPC2"),
120
 
                    2.4,  2.4,  SQUARE,"#AAAAAA")
 
148
                    2.4,  2.4, 0,0,0, SQUARE,"#AAAAAA")
121
149
         << new FOV(i18nc("use Radiotelescope HPBW", "30m at 1.3cm" ),
122
 
                    1.79, 1.79, SQUARE,"#AAAAAA");
 
150
                    1.79, 1.79, 0,0,0, SQUARE,"#AAAAAA");
123
151
    return fovs;
124
152
}
125
153
 
137
165
        ostream << fov->name()  << ':'
138
166
                << fov->sizeX() << ':'
139
167
                << fov->sizeY() << ':'
 
168
                << fov->offsetX() << ':'
 
169
                << fov->offsetY() << ':'
 
170
                << fov->rotation() << ':'
140
171
                << QString::number( fov->shape() ) << ':' //FIXME: is this needed???
141
172
                << fov->color() << endl;
142
173
    }
162
193
            QStringList fields = istream.readLine().split(':');
163
194
            bool ok;
164
195
            QString name, color;
165
 
            float   sizeX, sizeY;
 
196
            float   sizeX, sizeY, xoffset, yoffset, rot, orient;
166
197
            Shape   shape;
167
 
            if( fields.count() == 4 ) {
168
 
                name = fields[0];
169
 
                sizeX = fields[1].toFloat(&ok);
170
 
                if( !ok ) {
171
 
                    return QList<FOV*>();
172
 
                }
173
 
                sizeY = sizeX;
174
 
                shape = intToShape( fields[2].toInt(&ok) );
175
 
                if( !ok ) {
176
 
                    return QList<FOV*>();
177
 
                }
178
 
                color = fields[3];
179
 
            } else if( fields.count() == 5 ) {
 
198
            if( fields.count() == 8 )
 
199
            {
180
200
                name = fields[0];
181
201
                sizeX = fields[1].toFloat(&ok);
182
202
                if( !ok ) {
186
206
                if( !ok ) {
187
207
                    return QList<FOV*>();
188
208
                }
189
 
                shape = intToShape( fields[3].toInt(&ok) );
190
 
                if( !ok ) {
191
 
                    return QList<FOV*>();
192
 
                }
193
 
                color = fields[4];
 
209
                xoffset = fields[3].toFloat(&ok);
 
210
                if( !ok ) {
 
211
                    return QList<FOV*>();
 
212
                }
 
213
 
 
214
                yoffset = fields[4].toFloat(&ok);
 
215
                if( !ok ) {
 
216
                    return QList<FOV*>();
 
217
                }
 
218
 
 
219
                rot = fields[5].toFloat(&ok);
 
220
                if( !ok ) {
 
221
                    return QList<FOV*>();
 
222
                }
 
223
 
 
224
                shape = intToShape( fields[6].toInt(&ok) );
 
225
                if( !ok ) {
 
226
                    return QList<FOV*>();
 
227
                }
 
228
                color = fields[7];
194
229
            } else {
195
230
                continue;
196
231
            }
197
 
            fovs.append( new FOV(name, sizeX, sizeY, shape, color) );
 
232
            fovs.append( new FOV(name, sizeX, sizeY, xoffset, yoffset, rot, shape, color) );
198
233
        }
199
234
    }
200
235
    return fovs;