File indexing completed on 2024-04-28 15:10:48
0001 /* 0002 SPDX-FileCopyrightText: 2016 Artem Fedoskin <afedoskin3@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 #include "skyobject.h" 0007 #include "Options.h" 0008 0009 #include <QSGSimpleTextureNode> 0010 0011 #include "pointsourcenode.h" 0012 #include "nodes/pointnode.h" 0013 0014 #include "../rootnode.h" 0015 #include "../labelsitem.h" 0016 #include "labelnode.h" 0017 0018 PointSourceNode::PointSourceNode(SkyObject *skyObject, RootNode *parentNode, LabelsItem::label_t labelType, 0019 char spType, float size, short trixel) 0020 : SkyNode(skyObject), m_rootNode(parentNode), m_spType(spType), m_size(size), 0021 m_labelType(labelType), m_trixel(trixel) 0022 { 0023 } 0024 0025 float PointSourceNode::starWidth(float mag) const 0026 { 0027 //adjust maglimit for ZoomLevel 0028 const double maxSize = 10.0; 0029 0030 double lgmin = log10(MINZOOM); 0031 // double lgmax = log10(MAXZOOM); 0032 double lgz = log10(Options::zoomFactor()); 0033 0034 float sizeFactor = maxSize + (lgz - lgmin); 0035 0036 float m_sizeMagLim = map()->sizeMagLim(); 0037 0038 float size = (sizeFactor * (m_sizeMagLim - mag) / m_sizeMagLim) + 1.; 0039 if (size <= 1.0) 0040 size = 1.0; 0041 if (size > maxSize) 0042 size = maxSize; 0043 0044 return size; 0045 } 0046 0047 PointSourceNode::~PointSourceNode() 0048 { 0049 if (m_label && 0050 (m_labelType == LabelsItem::label_t::STAR_LABEL || m_labelType == LabelsItem::label_t::CATALOG_STAR_LABEL)) 0051 { 0052 m_rootNode->labelsItem()->deleteLabel(m_label); 0053 } 0054 } 0055 0056 void PointSourceNode::updatePoint() 0057 { 0058 if (!m_point) 0059 { 0060 m_point = new PointNode(m_rootNode, m_spType, starWidth(m_size)); 0061 addChildNode(m_point); 0062 } 0063 show(); 0064 m_point->setSize(starWidth(m_skyObject->mag())); //Set points size base on the magnitude of object 0065 } 0066 0067 void PointSourceNode::changePos(QPointF pos) 0068 { 0069 QSizeF size = m_point->size(); 0070 QMatrix4x4 m(1, 0, 0, pos.x(), 0, 1, 0, pos.y(), 0, 0, 1, 0, 0, 0, 0, 1); 0071 m.translate(-0.5 * size.width(), -0.5 * size.height()); 0072 0073 setMatrix(m); 0074 markDirty(QSGNode::DirtyMatrix); 0075 } 0076 0077 void PointSourceNode::update() 0078 { 0079 if (!projector()->checkVisibility(m_skyObject)) 0080 { 0081 hide(); 0082 return; 0083 } 0084 0085 bool visible = false; 0086 pos = projector()->toScreen(m_skyObject, true, &visible); 0087 if (visible && 0088 projector()->onScreen( 0089 pos)) // FIXME: onScreen here should use canvas size rather than SkyMap size, especially while printing in portrait mode! (Inherited from SkyMap) 0090 { 0091 updatePos(pos, m_drawLabel); 0092 } 0093 else 0094 { 0095 hide(); 0096 } 0097 } 0098 0099 void PointSourceNode::updatePos(QPointF pos, bool drawLabel) 0100 { 0101 updatePoint(); 0102 changePos(pos); 0103 0104 m_drawLabel = drawLabel; 0105 0106 if (m_drawLabel && m_labelType != LabelsItem::label_t::NO_LABEL) 0107 { 0108 if (!m_label) //This way labels will be created only when they are needed 0109 { 0110 if (m_trixel != -1) 0111 { 0112 m_label = m_rootNode->labelsItem()->addLabel(m_skyObject, m_labelType, m_trixel); 0113 } 0114 else 0115 { 0116 m_label = m_rootNode->labelsItem()->addLabel(m_skyObject, m_labelType); 0117 } 0118 } 0119 m_label->setLabelPos(pos); 0120 } 0121 else 0122 { 0123 if (m_label) 0124 m_label->hide(); 0125 } 0126 } 0127 0128 void PointSourceNode::hide() 0129 { 0130 if (m_label) 0131 m_label->hide(); 0132 SkyNode::hide(); 0133 }