Seamly2D
Code documentation
visualization.h
Go to the documentation of this file.
1 /**************************************************************************
2  **
3  ** @file visualization.h
4  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
5  ** @date 15 8, 2014
6  **
7  ** @author Douglas S Caskey
8  ** @date 7.23.2022
9  **
10  ** @brief
11  ** @copyright
12  ** Copyright (C) 2013-2022 Seamly2D project.
13  ** This source code is part of the Seamly2D project, a pattern making
14  ** program, whose allow create and modeling patterns of clothing.
15  **
16  ** <https://github.com/fashionfreedom/seamly2d> All Rights Reserved.
17  **
18  ** Seamly2D is free software: you can redistribute it and/or modify
19  ** it under the terms of the GNU General Public License as published
20  ** by the Free Software Foundation, either version 3 of the License,
21  ** or (at your option) any later version.
22  **
23  ** Seamly2D is distributed in the hope that it will be useful,
24  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
25  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26  ** GNU General Public License for more details.
27  **
28  ** You should have received a copy of the GNU General Public License
29  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
30  **
31  *************************************************************************/
32 
33 #ifndef VISUALIZATION_H
34 #define VISUALIZATION_H
35 
37 #include "../vgeometry/vabstractcurve.h"
38 #include "../vmisc/def.h"
39 #include "../vmisc/logging.h"
40 #include "../vmisc/vabstractapplication.h"
41 #include "../vwidgets/global.h"
42 #include "../vwidgets/scalesceneitems.h"
43 #include "../vwidgets/vcurvepathitem.h"
44 #include "../vwidgets/vmaingraphicsscene.h"
45 
46 #include <qcompilerdetection.h>
47 #include <QGraphicsItem>
48 #include <QObject>
49 #include <QtGlobal>
50 
51 Q_DECLARE_LOGGING_CATEGORY(vVis)
52 
53 class VScaledEllipse;
54 class VScaledLine;
55 class ArrowedLineItem;
56 class VContainer;
57 //class VInternalVariable;
58 
59 enum class Mode : char {Creation, Show};
60 
61 class Visualization : public QObject
62 {
63  Q_OBJECT
64 public:
65  explicit Visualization(const VContainer *data);
66  virtual ~Visualization() Q_DECL_EQ_DEFAULT;
67 
68  virtual void RefreshGeometry()=0;
69 
70  void setObject1Id(const quint32 &value);
71  void setLineStyle(const Qt::PenStyle &value);
72  void setLineWeight(const QString &value);
73  void setScenePos(const QPointF &value);
74  virtual void VisualMode(const quint32 &pointId);
75  void setMainColor(const QColor &value);
76 
77  const VContainer *getData() const;
78  void setData(const VContainer *data);
79 
80  Mode GetMode() const;
81  void SetMode(const Mode &value);
82 
83  static qreal FindLength(const QString &expression, const QHash<QString,
85  static qreal FindVal(const QString &expression, const QHash<QString,
87 
88  QString CurrentToolTip() const {return toolTip;}
89 
90 signals:
91  void ToolTip(const QString &toolTip);
92 
93 public slots:
94  void mousePos(const QPointF &scenePos);
95 
96 protected:
97  const VContainer *data;
98  QPointF scenePos;
99  QColor mainColor;
100  QColor supportColor;
101  Qt::PenStyle lineStyle;
102  qreal lineWeight;
103  quint32 object1Id;
104  QString toolTip;
106 
107  virtual void initPen()=0;
108  virtual void AddOnScene()=0;
109 
110  VScaledEllipse *InitPoint(const QColor &color, QGraphicsItem *parent, qreal z = 0) const;
111  void DrawPoint(QGraphicsEllipseItem *point, const QPointF &pos, const QColor &color,
112  Qt::PenStyle style = Qt::SolidLine);
113  virtual void DrawLine(VScaledLine *lineItem, const QLineF &line, const QColor &color,
114  const qreal &lineWeight, Qt::PenStyle style = Qt::SolidLine);
115  void DrawPath(VCurvePathItem *pathItem, const QPainterPath &path, const QColor &color,
116  Qt::PenStyle style = Qt::SolidLine, const qreal &weight = 0.35,
117  Qt::PenCapStyle cap = Qt::SquareCap);
118  void DrawPath(VCurvePathItem *pathItem, const QPainterPath &path,
119  const QVector<DirectionArrow> &directionArrows, const QColor &color,
120  Qt::PenStyle style = Qt::SolidLine, const qreal &weight = 0.35,
121  Qt::PenCapStyle cap = Qt::SquareCap);
122 
123  void drawArrowedLine(ArrowedLineItem *item, const QLineF &line, const QColor &color,
124  Qt::PenStyle style = Qt::SolidLine);
125  void drawArrow(const QLineF &axis, QPainterPath &path, const qreal &arrow_size);
126 
127  template <typename Item>
128  void addItem(Item *item);
129 
130  template <class Item>
131  Item *InitItem(const QColor &color, QGraphicsItem *parent);
132 
133  static VScaledEllipse *GetPointItem(QVector<VScaledEllipse *> &points, quint32 i, const QColor &color,
134  QGraphicsItem *parent);
135 private:
136  Q_DISABLE_COPY(Visualization)
137 
138  static VScaledEllipse *initPointItem(const QColor &color, QGraphicsItem *parent, qreal z = 0);
139 };
140 
141 //---------------------------------------------------------------------------------------------------------------------
142 template <typename Item>
143 inline void Visualization::addItem(Item *item)
144 {
145  SCASSERT(item != nullptr)
146  VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
147  SCASSERT(scene != nullptr)
148 
149  scene->addItem(item);
151 }
152 
153 //---------------------------------------------------------------------------------------------------------------------
154 template <class Item>
155 inline Item *Visualization::InitItem(const QColor &color, QGraphicsItem *parent)
156 {
157  Item *item = new Item(parent);
158 
159  QPen pen = item->pen();
160  pen.setColor(color);
161 
162  item->setPen(pen);
163  item->setZValue(1);
164  item->setFlags(QGraphicsItem::ItemStacksBehindParent);
165  item->setVisible(false);
166  return item;
167 }
168 
169 #endif // VISUALIZATION_H
The VContainer class container of all variables.
Definition: vcontainer.h:141
The VMainGraphicsScene class main scene.
void mouseMove(const QPointF &scenePos)
mouseMove send new mouse position.
QString CurrentToolTip() const
Definition: visualization.h:88
QColor supportColor
void mousePos(const QPointF &scenePos)
void ToolTip(const QString &toolTip)
QColor mainColor
Definition: visualization.h:99
Visualization(const VContainer *data)
void setScenePos(const QPointF &value)
void DrawPoint(QGraphicsEllipseItem *point, const QPointF &pos, const QColor &color, Qt::PenStyle style=Qt::SolidLine)
void setLineWeight(const QString &value)
Item * InitItem(const QColor &color, QGraphicsItem *parent)
static qreal FindLength(const QString &expression, const QHash< QString, QSharedPointer< VInternalVariable > > *vars)
void drawArrow(const QLineF &axis, QPainterPath &path, const qreal &arrow_size)
void SetMode(const Mode &value)
const VContainer * data
Definition: visualization.h:97
virtual void VisualMode(const quint32 &pointId)
static VScaledEllipse * initPointItem(const QColor &color, QGraphicsItem *parent, qreal z=0)
void setData(const VContainer *data)
void DrawPath(VCurvePathItem *pathItem, const QPainterPath &path, const QColor &color, Qt::PenStyle style=Qt::SolidLine, const qreal &weight=0.35, Qt::PenCapStyle cap=Qt::SquareCap)
void setObject1Id(const quint32 &value)
static VScaledEllipse * GetPointItem(QVector< VScaledEllipse * > &points, quint32 i, const QColor &color, QGraphicsItem *parent)
const VContainer * getData() const
virtual void initPen()=0
QPointF scenePos
Definition: visualization.h:98
void drawArrowedLine(ArrowedLineItem *item, const QLineF &line, const QColor &color, Qt::PenStyle style=Qt::SolidLine)
virtual void RefreshGeometry()=0
virtual void DrawLine(VScaledLine *lineItem, const QLineF &line, const QColor &color, const qreal &lineWeight, Qt::PenStyle style=Qt::SolidLine)
VScaledEllipse * InitPoint(const QColor &color, QGraphicsItem *parent, qreal z=0) const
virtual void AddOnScene()=0
virtual ~Visualization() Q_DECL_EQ_DEFAULT
Mode GetMode() const
quint32 object1Id
void setLineStyle(const Qt::PenStyle &value)
void setMainColor(const QColor &value)
static qreal FindVal(const QString &expression, const QHash< QString, QSharedPointer< VInternalVariable > > *vars)
Qt::PenStyle lineStyle
void addItem(Item *item)
#define SCASSERT(cond)
Definition: def.h:317
#define qApp
Definition: vapplication.h:67
Mode
Definition: visualization.h:59
@ Creation