Kstars

simplefovexporter.cpp
1/*
2 SPDX-FileCopyrightText: 2011 Rafał Kułaga <rl.kulaga@gmail.com>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "simplefovexporter.h"
8
9#include "kstars.h"
10#include "kstarsdata.h"
11#include "skymap.h"
12#include "skyqpainter.h"
13#include "fov.h"
14#include "skymapcomposite.h"
15#include "kstars/Options.h"
16
18 : m_KSData(KStarsData::Instance()), m_Map(KStars::Instance()->map()), m_StopClock(false), m_OverrideFovShape(false),
19 m_DrawFovSymbol(false), m_PrevClockState(false), m_PrevSlewing(false), m_PrevPoint(nullptr), m_PrevZoom(0)
20{
21}
22
24{
25 saveState(true);
26 pExportFov(point, fov, pd);
27 restoreState(true);
28}
29
31{
32 pExportFov(nullptr, fov, pd);
33}
34
36{
37 SkyQPainter painter(m_Map, pd);
38 painter.begin();
39
40 painter.drawSkyBackground();
41
42 // translate painter coordinates - it's necessary to extract only the area of interest (FOV)
43 int dx = (m_Map->width() - pd->width()) / 2;
44 int dy = (m_Map->height() - pd->height()) / 2;
45 painter.translate(-dx, -dy);
46
47 m_KSData->skyComposite()->draw(&painter);
48 m_Map->getSkyMapDrawAbstract()->drawOverlays(painter, false);
49}
50
53{
54 Q_ASSERT(points.size() == fovs.size() && fovs.size() == pds.size());
55
56 saveState(true);
57
58 for (int i = 0; i < points.size(); i++)
59 {
60 exportFov(points.value(i), fovs.at(i), pds.value(i));
61 }
62
63 restoreState(true);
64}
65
67{
68 Q_ASSERT(points.size() == pds.size());
69
70 saveState(true);
71
72 for (int i = 0; i < points.size(); i++)
73 {
74 exportFov(points.at(i), fov, pds.at(i));
75 }
76
77 restoreState(true);
78}
79
80void SimpleFovExporter::pExportFov(SkyPoint *point, FOV *fov, QPaintDevice *pd)
81{
82 if (point)
83 {
84 // center sky map on selected point
85 m_Map->setClickedPoint(point);
86 m_Map->slotCenter();
87 }
88
89 // this is temporary 'solution' that will be changed during the implementation of printing
90 // on large paper sizes (>A4), in which case it'll be desirable to export high-res FOV
91 // representations
92 if (pd->height() > m_Map->height() || pd->width() > m_Map->width())
93 {
94 return;
95 }
96
97 // calculate zoom factor
98 double zoom = 0;
99 QRegion region;
100 int regionX(0), regionY(0);
101 double fovSizeX(0), fovSizeY(0);
102 if (fov->sizeX() > fov->sizeY())
103 {
104 zoom = calculateZoomLevel(pd->width(), fov->sizeX());
105
106 // calculate clipping region size
107 fovSizeX = calculatePixelSize(fov->sizeX(), zoom);
108 fovSizeY = calculatePixelSize(fov->sizeY(), zoom);
109 regionX = 0;
110 regionY = 0.5 * (pd->height() - fovSizeY);
111 }
112
113 else
114 {
115 zoom = calculateZoomLevel(pd->height(), fov->sizeY());
116
117 // calculate clipping region size
118 fovSizeX = calculatePixelSize(fov->sizeX(), zoom);
119 fovSizeY = calculatePixelSize(fov->sizeY(), zoom);
120 regionX = 0.5 * (pd->width() - fovSizeX);
121 regionY = 0;
122 }
123
124 if (fov->shape() == FOV::SQUARE)
125 {
127 }
128
129 else
130 {
132 }
133
134 m_Map->setZoomFactor(zoom);
135
136 SkyQPainter painter(m_Map, pd);
137 painter.begin();
138
139 painter.drawSkyBackground();
140
141 if (!m_OverrideFovShape)
142 {
143 painter.setClipRegion(region);
144 }
145 // translate painter coordinates - it's necessary to extract only the area of interest (FOV)
146 int dx = (m_Map->width() - pd->width()) / 2;
147 int dy = (m_Map->height() - pd->height()) / 2;
148 painter.translate(-dx, -dy);
149
150 m_KSData->skyComposite()->draw(&painter);
151 m_Map->getSkyMapDrawAbstract()->drawOverlays(painter, false);
152
153 // reset painter coordinate transform to paint FOV symbol in the center
154 painter.resetTransform();
155
156 if (m_DrawFovSymbol)
157 {
158 fov->draw(painter, zoom);
159 }
160}
161
162void SimpleFovExporter::saveState(bool savePos)
163{
164 // stop simulation if it's not already stopped
165 m_PrevClockState = m_KSData->clock()->isActive();
166 if (m_StopClock && m_PrevClockState)
167 {
168 m_KSData->clock()->stop();
169 }
170
171 // disable useAnimatedSlewing option
172 m_PrevSlewing = Options::useAnimatedSlewing();
173 if (m_PrevSlewing)
174 {
175 Options::setUseAnimatedSlewing(false);
176 }
177
178 // save current central point and zoom level
179 m_PrevPoint = savePos ? m_Map->focusPoint() : nullptr;
180 m_PrevZoom = Options::zoomFactor();
181}
182
183void SimpleFovExporter::restoreState(bool restorePos)
184{
185 // restore previous useAnimatedSlewing option
186 if (m_PrevSlewing)
187 {
188 Options::setUseAnimatedSlewing(true);
189 }
190
191 if (restorePos)
192 {
193 // restore previous central point
194 m_Map->setClickedPoint(m_PrevPoint);
195 m_Map->slotCenter();
196 }
197 // restore previous zoom level
198 m_Map->setZoomFactor(m_PrevZoom);
199
200 // restore clock state (if it was stopped)
201 if (m_StopClock && m_PrevClockState)
202 {
203 m_KSData->clock()->start();
204 }
205}
A simple class encapsulating a Field-of-View symbol.
Definition fov.h:28
void draw(QPainter &p, float zoomFactor)
draw the FOV symbol on a QPainter
Definition fov.cpp:230
KStarsData is the backbone of KStars.
Definition kstarsdata.h:72
Q_INVOKABLE SimClock * clock()
Definition kstarsdata.h:218
SkyMapComposite * skyComposite()
Definition kstarsdata.h:166
This is the main window for KStars.
Definition kstars.h:91
Q_INVOKABLE bool isActive()
Whether the clock is active or not is a bit complicated by the introduction of "manual mode".
Definition simclock.cpp:96
Q_SCRIPTABLE Q_NOREPLY void start()
DBUS function to start the SimClock.
Definition simclock.cpp:120
Q_SCRIPTABLE Q_NOREPLY void stop()
DBUS function to stop the SimClock.
Definition simclock.cpp:104
static double calculatePixelSize(float degrees, double zoomLevel)
Calculate pixel size of given angular length at given zoom level.
SimpleFovExporter()
Constructor.
static double calculateZoomLevel(int pixelSize, float degrees)
Calculate zoom level at which given angular length will occupy given length in pixels.
void exportFov(SkyPoint *point, FOV *fov, QPaintDevice *pd)
Paint FOV representation on passed QPaintDevice subclass.
void draw(SkyPainter *skyp) override
Delegate draw requests to all sub components psky Reference to the QPainter on which to paint.
void drawOverlays(QPainter &p, bool drawFov=true)
Draw the overlays on top of the sky map.
SkyPoint * focusPoint()
retrieve the FocusPoint position.
Definition skymap.h:149
void setZoomFactor(double factor)
@ Set zoom factor.
Definition skymap.cpp:1167
void setClickedPoint(const SkyPoint *f)
Set the ClickedPoint to the skypoint given as an argument.
Definition skymap.cpp:1012
void slotCenter()
Center the display at the point ClickedPoint.
Definition skymap.cpp:380
The sky coordinates of a point in the sky.
Definition skypoint.h:45
The QPainter-based painting backend.
Definition skyqpainter.h:31
void drawSkyBackground() override
Draw the sky background.
void begin() override
Begin painting.
QAction * zoom(const QObject *recvr, const char *slot, QObject *parent)
void translate(const QPoint &offset)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:19:03 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.