File indexing completed on 2024-04-28 03:44:24
0001 /* 0002 SPDX-FileCopyrightText: 2016 Artem Fedoskin <afedoskin3@gmail.com> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #include "deepskynode.h" 0007 0008 #include "deepskyobject.h" 0009 #include "dsosymbolnode.h" 0010 #include "labelnode.h" 0011 #include "Options.h" 0012 #include "skyobject.h" 0013 #include "trixelnode.h" 0014 #include "nodes/pointnode.h" 0015 #include "../rootnode.h" 0016 #include "../labelsitem.h" 0017 0018 #include <QSGSimpleTextureNode> 0019 #include <QQuickWindow> 0020 0021 0022 DeepSkyNode::DeepSkyNode(DeepSkyObject *skyObject, DSOSymbolNode *symbol, LabelsItem::label_t labelType, short trixel) 0023 : m_trixel(trixel), m_labelType(labelType), m_dso(skyObject), m_symbol(symbol) 0024 { 0025 m_symbol->hide(); 0026 } 0027 0028 DeepSkyNode::~DeepSkyNode() 0029 { 0030 if (m_label) 0031 SkyMapLite::rootNode()->labelsItem()->deleteLabel(m_label); 0032 } 0033 0034 void DeepSkyNode::changePos(QPointF pos) 0035 { 0036 QSizeF size = m_objImg->rect().size(); 0037 QMatrix4x4 m(1, 0, 0, pos.x(), 0, 1, 0, pos.y(), 0, 0, 1, 0, 0, 0, 0, 1); 0038 //FIXME: this is probably incorrect (inherited from drawDeepSkyImage()) 0039 m.rotate(m_angle, 0, 0, 1); 0040 m.translate(-0.5 * size.width(), -0.5 * size.height()); 0041 0042 setMatrix(m); 0043 markDirty(QSGNode::DirtyMatrix); 0044 } 0045 0046 void DeepSkyNode::setColor(QColor color, TrixelNode *symbolTrixel) 0047 { 0048 if (m_symbol->getColor() != color) 0049 { 0050 delete m_symbol; 0051 m_symbol = new DSOSymbolNode(m_dso, color); 0052 symbolTrixel->appendChildNode(m_symbol); 0053 } 0054 0055 //m_label->setColor 0056 } 0057 0058 void DeepSkyNode::update(bool drawImage, bool drawLabel, QPointF pos) 0059 { 0060 if (pos.x() == -1 && pos.y() == -1) 0061 { 0062 const Projector *proj = projector(); 0063 if (!proj->checkVisibility(m_dso)) 0064 { 0065 hide(); 0066 return; 0067 } 0068 0069 bool visible = false; 0070 pos = proj->toScreen(m_dso, true, &visible); 0071 if (!visible || !proj->onScreen(pos)) 0072 { 0073 hide(); 0074 return; 0075 } 0076 } 0077 show(); 0078 0079 // if size is 0.0 set it to 1.0, this are normally stars (type 0 and 1) 0080 // if we use size 0.0 the star wouldn't be drawn 0081 float majorAxis = m_dso->a(); 0082 if (majorAxis == 0.0) 0083 { 0084 majorAxis = 1.0; 0085 } 0086 0087 float size = majorAxis * dms::PI * Options::zoomFactor() / 10800.0; 0088 0089 double zoom = Options::zoomFactor(); 0090 double w = m_dso->a() * dms::PI * zoom / 10800.0; 0091 double h = m_dso->e() * w; 0092 0093 m_angle = projector()->findPA(m_dso, pos.x(), pos.y()); 0094 0095 if (drawImage && Options::zoomFactor() > 5. * MINZOOM) 0096 { 0097 if (!(m_dso->image().isNull())) 0098 { 0099 if (!m_objImg) 0100 { 0101 m_objImg = new QSGSimpleTextureNode; 0102 m_objImg->setTexture(SkyMapLite::Instance()->window()->createTextureFromImage( 0103 m_dso->image(), QQuickWindow::TextureCanUseAtlas)); 0104 m_objImg->setOwnsTexture(true); 0105 m_opacity->appendChildNode(m_objImg); 0106 } 0107 0108 m_objImg->setRect(0, 0, w, h); 0109 changePos(pos); 0110 } 0111 } 0112 else 0113 { 0114 hide(); 0115 } 0116 0117 //Draw symbol 0118 m_symbol->update(size, pos, m_angle); 0119 0120 // Draw label 0121 if (drawLabel) 0122 { 0123 if (!m_label) 0124 { 0125 if (m_trixel != -1) 0126 { 0127 m_label = SkyMapLite::rootNode()->labelsItem()->addLabel(m_dso, m_labelType, m_trixel); 0128 } 0129 else 0130 { 0131 m_label = SkyMapLite::rootNode()->labelsItem()->addLabel(m_dso, m_labelType); 0132 } 0133 } 0134 m_label->setLabelPos(pos); 0135 } 0136 else if (m_label) 0137 { 0138 m_label->hide(); 0139 } 0140 } 0141 0142 void DeepSkyNode::hide() 0143 { 0144 SkyNode::hide(); 0145 if (m_label) 0146 m_label->hide(); 0147 m_symbol->hide(); 0148 }