1 // XDrawChem
2 // Copyright (C) 2004-2005 Bryan Herger <bherger@users.sourceforge.net>
3 // Copyright (C) 2020 Yaman Qalieh <ybq987@gmail.com>
4
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <https://www.gnu.org/licenses/>.
17
18 // drawable.h -- the class that is the parent of all drawable objects
19
20 #ifndef DRAWABLE_H
21 #define DRAWABLE_H
22
WPDNode(size_t length,const float * coefficients,size_t coefficients_length)23 #include <QColor>
24 #include <QList>
25 #include <QRect>
26 #include <QString>
27
28 #include "dpoint.h"
29
30 class Bond;
31 class Text;
32
33 class Drawable : public QObject {
34 Q_OBJECT
35
36 public:
~WPDNode()37 Drawable(QObject *parent = 0);
38 virtual Drawable *CloneTo(Drawable *target = nullptr) const; // Clone current data to target
Update(const float * parent_data,size_t parent_data_length)39 virtual void Render(); // draw this object
40 virtual void Edit(); // edit this object
41 virtual int Type(); // return type of object
42 virtual DPoint *FindNearestPoint(DPoint *, double &);
43 virtual Drawable *FindNearestObject(DPoint *, double &);
44 virtual bool Find(DPoint *);
45 virtual void addBond(DPoint *, DPoint *, int, int, QColor, bool hl = false);
46 virtual void addMolecule(Drawable *);
47 virtual void Highlight();
48 virtual void Highlight(bool);
49 virtual bool Highlighted();
50 virtual bool Erase(Drawable *);
51 virtual bool isWithinRect(QRect, bool);
52 virtual void SelectAll();
53 virtual void DeselectAll();
54 virtual void Move(double, double);
55 virtual void ForceMove(double, double);
56 virtual void Rotate(DPoint *, double);
57 virtual void Flip(DPoint *, int);
58 virtual void Resize(DPoint *, double);
59 virtual QRect BoundingBox();
60 virtual QList<DPoint *> AllPoints();
61 virtual QList<Drawable *> AllObjects();
62 virtual QString ToXML(QString);
set_data(const float * new_data,size_t length)63 virtual QString ToCDXML(QString);
64 virtual void FromXML(QString);
65 virtual int Members();
66 // needed only to merge Molecules; see molecule.cpp, addMolecule()
67 virtual Bond *bondsFirst() { return 0; }
68 virtual Bond *bondsNext() { return 0; }
69 virtual Text *labelsFirst() { return 0; }
70 virtual Text *labelsNext() { return 0; }
71 // stuff that all Drawables should know about
72 static double getAngle(DPoint *, DPoint *);
73 double DistanceToLine(DPoint *, DPoint *, DPoint *);
74 double DistanceBetween(QPointF, QPointF);
75 bool DPointInRect(DPoint *, QRect);
76 DPoint *Start() { return start; }
77 DPoint *End() { return end; }
78 void setStart(DPoint *ns) { start = ns; }
79 void setEnd(DPoint *ne) { end = ne; }
80 virtual void SetColorIfHighlighted(QColor);
81 void SetColor(QColor c) { color = c; }
82 QColor GetColor() { return color; }
83 QString getID() { return id; }
84 void setID(QString x) { id = x; }
85 QColor GetColorFromXML(QString);
86 void SetColorFromXML(QString);
87 void SetStartFromXML(QString);
88 void SetEndFromXML(QString);
89 bool isInGroup() { return ingroup; }
90 void setInGroup(bool x) { ingroup = x; }
91 int Thick() { return thick; }
92 void setThick(int t) { thick = t; }
93 // more or less everything must be protected so derived classes can use them
94
95 protected:
96 // highlighted?
97 bool highlighted;
98 // member of a group?
99 bool ingroup;
100 // points which define this Drawable (only start needed for TEXT)
101 DPoint *start, *end;
102 // color
103 QColor color;
104 // XML ID
105 QString id;
106 // arrow or bracket style
107 int style;
108 // which symbol or curvearrow to draw
109 QString which;
110 // thickness of bond/bracket/line
111 int thick;
112 };
113
114 #endif
115