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 
74  QString getLabel() const;
75  bool isMetric() const {
76  return metric;
77  }
78  void setMetric(bool on) {
79  metric = on;
80  }
81 
82  bool setPatternString(const QString& patternString);
83  QString getPatternString() const;
84  QList<double> getPattern() const;
85  double getPatternLength() const;
86  double getDashLengthAt(int i) const;
87  double getDashOffsetAt(const QList<double>& dashes, int i) const;
88 
89  bool hasShapeNumberAt(int i) const;
90  int getShapeNumberAt(int i) const;
91  void setShapeNumberAt(int i, int num);
92 
93  bool hasShapeScaleAt(int i) const;
94  double getShapeScaleAt(int i) const;
95  void setShapeScaleAt(int i, double s);
96 
97  bool hasShapeRotationAt(int i) const;
98  double getShapeRotationAt(int i) const;
99  void setShapeRotationAt(int i, double r);
100 
101  bool hasShapeOffsetAt(int i) const;
102  RVector getShapeOffsetAt(int i) const;
103  void setShapeOffsetAt(int i, const RVector& offset);
104 
105  bool hasShapeTextAt(int i) const;
106  QString getShapeTextAt(int i) const;
107  void setShapeTextAt(int i, const QString& s);
108 
109  bool hasShapeTextStyleAt(int i) const;
110  QString getShapeTextStyleAt(int i) const;
111  void setShapeTextStyleAt(int i, const QString& s);
112 
113  QList<int> getShapeIndices() const;
114  bool hasShapes() const;
115  bool hasShapeAt(int i) const;
116  QList<RPainterPath> getShapeAt(int i) const;
117  void updateShapes();
118  double getLargestGap() const;
119  bool hasDashAt(double pos) const;
120  double getDelta(double pos) const;
121  double getPatternOffset(double length);
122  QList<double> getSymmetries() const {
123  return symmetries;
124  }
125 
129  double getPatternOffsetAt(double length, double symmetryPos, double* gap = NULL, bool end = false);
130  void scale(double factor);
131 
132  QVector<qreal> getScreenBasedLinetype();
133 
134  RLinetypePattern& operator=(const RLinetypePattern& other);
135  bool operator==(const RLinetypePattern& other) const;
136  bool operator<(const RLinetypePattern& other) const;
137 
138  bool isLoaded() { return true; }
139  void load() {}
140 
141  static void initNameMap();
142 
143 private:
144  bool metric;
145  QString name;
146  QString description;
147  mutable QString patternString;
148 
149  QList<double> pattern;
150 
151  QMap<int, QList<RPainterPath> > shapes;
152  QMap<int, QString> shapeTexts;
153  QMap<int, QString> shapeTextStyles;
154  QMap<int, int> shapeNumbers;
155  QMap<int, double> shapeScales;
156  QMap<int, double> shapeRotations;
157  QMap<int, RVector> shapeOffsets;
158 
159  // internal info about segments at which the pattern is symmetrical:
160  QList<double> symmetries;
161 
162  static QMap<QString, QString> nameMap;
163 };
164 
165 QCADCORE_EXPORT QDebug operator<<(QDebug dbg, const RLinetypePattern& p);
166 
171 Q_DECLARE_METATYPE(_RMapQStringRLinetypePattern*)
172 Q_DECLARE_METATYPE(_RMapQStringRLinetypePattern)
173 
174 #endif
void setName(const QString &n)
Definition: RLinetype.h:76
QString getPatternString() const
Definition: RLinetype.h:100
Represents a 3d vector (x/y/z).
Definition: RVector.h:46
QString patternString
Definition: RLinetypePattern.h:147
void setDescription(const QString &d)
Definition: RLinetype.h:92
QMap< int, QString > shapeTexts
Definition: RLinetypePattern.h:152
QList< double > symmetries
Definition: RLinetypePattern.h:160
QMap< int, QList< RPainterPath > > shapes
Definition: RLinetypePattern.h:151
#define QCADCORE_EXPORT
Definition: core_global.h:10
bool isLoaded()
Definition: RLinetypePattern.h:138
QString getName() const
Definition: RLinetype.h:72
QList< double > pattern
Definition: RLinetypePattern.h:149
QList< double > getSymmetries() const
Definition: RLinetypePattern.h:122
bool metric
Definition: RLinetypePattern.h:144
bool operator==(const RLinetype &linetype) const
Definition: RLinetype.cpp:39
Copyright (c) 2011-2015 by Andrew Mustun.
Definition: RLinetypePattern.h:45
bool isValid() const
Definition: RLinetype.cpp:99
QMap< int, double > shapeRotations
Definition: RLinetypePattern.h:156
QString description
Definition: RLinetypePattern.h:146
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:498
QMap< QString, RLinetypePattern > _RMapQStringRLinetypePattern
Definition: RLinetypePattern.h:170
bool isMetric() const
Definition: RLinetypePattern.h:75
void load()
Definition: RLinetypePattern.h:139
QString name
Definition: RLinetypePattern.h:145
QMap< int, RVector > shapeOffsets
Definition: RLinetypePattern.h:157
void setPatternString(const QString &s)
Definition: RLinetype.h:104
QString getDescription() const
Definition: RLinetype.h:88
Represents a linetype in a drawing.
Definition: RLinetype.h:50
static QMap< QString, QString > nameMap
Copyright (c) 2011-2015 by Andrew Mustun.
Definition: RLinetypePattern.h:162
void setMetric(bool on)
Definition: RLinetypePattern.h:78
RLinetypePattern getPattern() const
Definition: RLinetype.cpp:103
QCADCORE_EXPORT QDebug operator<<(QDebug dbg, const RLinetypePattern &p)
Stream operator for QDebug.
Definition: RLinetypePattern.cpp:911
QString getLabel() const
Definition: RLinetype.h:96
QMap< int, int > shapeNumbers
Definition: RLinetypePattern.h:154
QMap< int, double > shapeScales
Definition: RLinetypePattern.h:155
QMap< int, QString > shapeTextStyles
Definition: RLinetypePattern.h:153