QCAD
Open Source 2D CAD
RLinetypePattern.h
Go to the documentation of this file.
1 
20 #ifndef RLINETYPEPATTERN_H
21 #define RLINETYPEPATTERN_H
22 
23 #include "core_global.h"
24 
25 #include <stdarg.h>
26 #include <math.h>
27 
28 #include <QCoreApplication>
29 #include <QMetaType>
30 #include <QString>
31 #include <QPair>
32 #include <QList>
33 #include <QVector>
34 #include <QMap>
35 
36 #include "RPainterPath.h"
37 
46  Q_DECLARE_TR_FUNCTIONS(RLinetypePattern);
47 
48  friend class RLinetype;
49 
50 public:
54  RLinetypePattern(bool metric, const QString& name, const QString& description, int num...);
55 
56  RLinetypePattern(bool metric, const QString& name, const QString& description, const QList<double>& dashes);
57 
58  void set(const QList<double>& dashes);
59 
60  static QList<QPair<QString, RLinetypePattern*> > loadAllFrom(bool metric, const QString& fileName);
61 
63  RLinetypePattern(bool metric, const QString& name, const QString& description);
64  RLinetypePattern(const RLinetypePattern& other);
66 
67  bool isValid() const;
68  int getNumDashes() const;
69  QString getName() const;
70  void setName(const QString& n);
71  QString getDescription() const;
72  void setDescription(const QString& d);
73  double getScreenScale() const;
74  void setScreenScale(double s);
75 
76  QString getLabel() const;
77  bool isMetric() const {
78  return metric;
79  }
80  void setMetric(bool on) {
81  metric = on;
82  }
83 
84  bool setPatternString(const QString& patternString);
85  QString getPatternString() const;
86  QList<double> getPattern() const;
87  double getPatternLength() const;
88  double getDashLengthAt(int i) const;
89  double getDashOffsetAt(const QList<double>& dashes, int i) const;
90 
91  bool hasShapeNumberAt(int i) const;
92  int getShapeNumberAt(int i) const;
93  void setShapeNumberAt(int i, int num);
94 
95  bool hasShapeScaleAt(int i) const;
96  double getShapeScaleAt(int i) const;
97  void setShapeScaleAt(int i, double s);
98 
99  bool hasShapeRotationAt(int i) const;
100  double getShapeRotationAt(int i) const;
101  void setShapeRotationAt(int i, double r);
102 
103  bool hasShapeOffsetAt(int i) const;
104  RVector getShapeOffsetAt(int i) const;
105  void setShapeOffsetAt(int i, const RVector& offset);
106 
107  bool hasShapeTextAt(int i) const;
108  QString getShapeTextAt(int i) const;
109  void setShapeTextAt(int i, const QString& s);
110 
111  bool hasShapeTextStyleAt(int i) const;
112  QString getShapeTextStyleAt(int i) const;
113  void setShapeTextStyleAt(int i, const QString& s);
114 
115  QList<int> getShapeIndices() const;
116  bool hasShapes() const;
117  bool hasShapeAt(int i) const;
118  QList<RPainterPath> getShapeAt(int i) const;
119  void updateShapes();
120  double getLargestGap() const;
121  bool hasDashAt(double pos) const;
122  double getDelta(double pos) const;
123  double getPatternOffset(double length);
124  QList<double> getSymmetries() const {
125  return symmetries;
126  }
127 
131  double getPatternOffsetAt(double length, double symmetryPos, double* gap = NULL, bool end = false);
132  void scale(double factor);
133 
134  QVector<qreal> getScreenBasedLinetype();
135 
136  RLinetypePattern& operator=(const RLinetypePattern& other);
137  bool operator==(const RLinetypePattern& other) const;
138  bool operator<(const RLinetypePattern& other) const;
139 
140  bool isLoaded() { return true; }
141  void load() {}
142 
143  static void initNameMap();
144 
145 private:
146  bool metric;
147  QString name;
148  QString description;
149  double screenScale;
150  mutable QString patternString;
151 
152  QList<double> pattern;
153 
154  QMap<int, QList<RPainterPath> > shapes;
155  QMap<int, QString> shapeTexts;
156  QMap<int, QString> shapeTextStyles;
157  QMap<int, int> shapeNumbers;
158  QMap<int, double> shapeScales;
159  QMap<int, double> shapeRotations;
160  QMap<int, RVector> shapeOffsets;
161 
162  // internal info about segments at which the pattern is symmetrical:
163  QList<double> symmetries;
164 
165  static QMap<QString, QString> nameMap;
166 };
167 
168 QCADCORE_EXPORT QDebug operator<<(QDebug dbg, const RLinetypePattern& p);
169 
174 Q_DECLARE_METATYPE(_RMapQStringRLinetypePattern*)
175 Q_DECLARE_METATYPE(_RMapQStringRLinetypePattern)
176 
177 #endif
void setName(const QString &n)
Definition: RLinetype.h:80
QString getPatternString() const
Definition: RLinetype.h:104
Represents a 3d vector (x/y/z).
Definition: RVector.h:46
QString patternString
Definition: RLinetypePattern.h:150
void setDescription(const QString &d)
Definition: RLinetype.h:96
QMap< int, QString > shapeTexts
Definition: RLinetypePattern.h:155
QList< double > symmetries
Definition: RLinetypePattern.h:163
QMap< int, QList< RPainterPath > > shapes
Definition: RLinetypePattern.h:154
#define QCADCORE_EXPORT
Definition: core_global.h:10
bool isLoaded()
Definition: RLinetypePattern.h:140
QString getName() const
Definition: RLinetype.h:76
QList< double > pattern
Definition: RLinetypePattern.h:152
QList< double > getSymmetries() const
Definition: RLinetypePattern.h:124
bool metric
Definition: RLinetypePattern.h:146
bool operator==(const RLinetype &linetype) const
Definition: RLinetype.cpp:39
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RLinetypePattern.h:45
bool isValid() const
Definition: RLinetype.cpp:99
QMap< int, double > shapeRotations
Definition: RLinetypePattern.h:159
double screenScale
Definition: RLinetypePattern.h:149
QString description
Definition: RLinetypePattern.h:148
Q_DECLARE_METATYPE(RMath *)
bool operator<(const RPainterPath &p1, const RPainterPath &p2)
This operator allows us to sort painter paths based on z-level.
Definition: RPainterPath.cpp:609
QMap< QString, RLinetypePattern > _RMapQStringRLinetypePattern
Definition: RLinetypePattern.h:173
bool isMetric() const
Definition: RLinetypePattern.h:77
void scale(void e, void factor, void focusPoint)
Scales the given entity or shape by the given factor with the given focus point.
Definition: simple_modify.js:95
void load()
Definition: RLinetypePattern.h:141
QString name
Definition: RLinetypePattern.h:147
QMap< int, RVector > shapeOffsets
Definition: RLinetypePattern.h:160
void setPatternString(const QString &s)
Definition: RLinetype.h:108
QString getDescription() const
Definition: RLinetype.h:92
Represents a linetype in a drawing.
Definition: RLinetype.h:50
static QMap< QString, QString > nameMap
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RLinetypePattern.h:165
void setMetric(bool on)
Definition: RLinetypePattern.h:80
RLinetypePattern getPattern() const
Definition: RLinetype.cpp:103
QCADCORE_EXPORT QDebug operator<<(QDebug dbg, const RLinetypePattern &p)
Stream operator for QDebug.
Definition: RLinetypePattern.cpp:923
QString getLabel() const
Definition: RLinetype.h:100
QMap< int, int > shapeNumbers
Definition: RLinetypePattern.h:157
QMap< int, double > shapeScales
Definition: RLinetypePattern.h:158
QMap< int, QString > shapeTextStyles
Definition: RLinetypePattern.h:156