Itasca C++ Interface
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
basetoqt.h
Go to the documentation of this file.
1 #pragma once
2 
8 #include "base.h"
9 #include "avect.h"
10 
11 #ifdef _WIN32
12 #include <codeanalysis\warnings.h>
13 #pragma warning(push)
14 #pragma warning ( disable : ALL_CODE_ANALYSIS_WARNINGS )
15 #endif
16 #ifdef __INTEL_COMPILER
17 # pragma warning(disable:82)
18 # pragma warning(disable:111)
19 # pragma warning(disable:327)
20 # pragma warning(disable:1879)
21 # if __INTEL_COMPILER>=1210
22 # pragma warning(disable:3199)
23 # pragma warning(disable:3280)
24 # pragma warning(disable:1292)
25 # endif
26 # ifdef VS2017
27 # pragma warning(disable:4459)
28 # pragma warning(disable:1744)
29 # pragma warning(disable:3280)
30 # endif
31 #else
32 # pragma warning(disable:4251)
33 # pragma warning(disable:4244)
34 #endif
35 #include <QtCore>
36 #undef rad1
37 #undef rad2
38 #undef small
39 #undef near
40 #undef far
41 #undef grp1
42 #undef grp2
43 
44 #if QT_VERSION > 0x050000
45 # define QT5
46 #endif
47 
48 #ifndef DOXYGEN
49 // The following are commented since they should not be used with Qt anyway
50 //Q_DECLARE_METATYPE(quint64);
51 Q_DECLARE_METATYPE(String);
52 Q_DECLARE_METATYPE(Variant);
53 Q_DECLARE_METATYPE(IVect2);
54 Q_DECLARE_METATYPE(FVect2);
55 Q_DECLARE_METATYPE(DVect2);
56 Q_DECLARE_METATYPE(UVect2);
57 Q_DECLARE_METATYPE(DAVect2);
58 Q_DECLARE_METATYPE(FAVect2);
59 Q_DECLARE_METATYPE(IAVect2);
60 Q_DECLARE_METATYPE(UAVect2);
61 Q_DECLARE_METATYPE(IVect3);
62 Q_DECLARE_METATYPE(FVect3);
63 Q_DECLARE_METATYPE(DVect3);
64 Q_DECLARE_METATYPE(UVect3);
65 Q_DECLARE_METATYPE(DAVect3);
66 Q_DECLARE_METATYPE(FAVect3);
67 Q_DECLARE_METATYPE(IAVect3);
68 Q_DECLARE_METATYPE(UAVect3);
69 Q_DECLARE_METATYPE(Orientation2);
70 Q_DECLARE_METATYPE(Orientation3);
71 Q_DECLARE_METATYPE(Axes2D);
72 Q_DECLARE_METATYPE(Axes3D);
73 Q_DECLARE_METATYPE(Quat2);
74 Q_DECLARE_METATYPE(Quat3);
75 Q_DECLARE_METATYPE(SymTensor);
76 #endif
77 #pragma warning(pop)
78 
79 // Ensure always utf-8
80 class ItascaTextStream : public QTextStream {
81 public:
82  BASE_EXPORT ItascaTextStream() : QTextStream() {
83  setCodec("UTF-8");
84  }
85 
86  BASE_EXPORT ItascaTextStream(const QByteArray &array, QIODevice::OpenMode openMode = QIODevice::ReadOnly) : QTextStream(array,openMode) {
87  setCodec("UTF-8");
88  }
89 
90  BASE_EXPORT ItascaTextStream(QByteArray *array, QIODevice::OpenMode openMode = QIODevice::ReadWrite) : QTextStream(array,openMode) {
91  setCodec("UTF-8");
92  }
93 
94  BASE_EXPORT ItascaTextStream(QString *string, QIODevice::OpenMode openMode = QIODevice::ReadWrite) : QTextStream(string,openMode) {
95  setCodec("UTF-8");
96  }
97 
98  BASE_EXPORT ItascaTextStream(FILE *fileHandle, QIODevice::OpenMode openMode = QIODevice::ReadWrite) : QTextStream(fileHandle,openMode) {
99  setCodec("UTF-8");
100  }
101 
102  BASE_EXPORT ItascaTextStream(QIODevice *device) : QTextStream(device) {
103  setCodec("UTF-8");
104  }
105 };
106 
111 
112 // QDataStream functions
114 template <class T> inline QDataStream &operator<<(QDataStream &ds,const Vector2<T> &v) {
115  ds << v.x() << v.y();
116  return ds;
117 }
119 template <class T> inline QDataStream &operator>>(QDataStream &ds,Vector2<T> &v) {
120  ds >> v.rx() >> v.ry();
121  return ds;
122 }
124 template <class T> inline QDataStream &operator<<(QDataStream &ds,const Vector3<T> &v) {
125  ds << v.x() << v.y() << v.z();
126  return ds;
127 }
129 template <class T> inline QDataStream &operator>>(QDataStream &ds,Vector3<T> &v) {
130  ds >> v.rx() >> v.ry() >> v.rz();
131  return ds;
132 }
134 template <class T> inline QDataStream &operator<<(QDataStream &ds,const AVector2<T> &av) {
135  ds << av.z();
136  return ds;
137 }
139 template <class T> inline QDataStream &operator>>(QDataStream &ds,AVector2<T> &av) {
140  ds >> av.rz();
141  return ds;
142 }
143 
145 template <class T> inline QDataStream &operator<<(QDataStream &ds,const AVector3<T> &av) {
146  ds << av.x() << av.y() << av.z();
147  return ds;
148 }
150 template <class T> inline QDataStream &operator>>(QDataStream &ds,AVector3<T> &av) {
151  ds >> av.rx() >> av.ry() >> av.rz();
152  return ds;
153 }
154 
155 // Streaming Extent2 and Extent3
157 template <class T> inline QDataStream &operator<<(QDataStream &ds,const Extent2<T> &v) {
158  ds << v.x1() << v.x2() << v.y1() << v.y2();
159  return ds;
160 }
162 template <class T> inline QDataStream &operator>>(QDataStream &ds,Extent2<T> &v) {
163  ds >> v.rx1() >> v.rx2() >> v.ry1() >> v.ry2();
164  return ds;
165 }
167 template <class T> inline QDataStream &operator<<(QDataStream &ds,const Extent3<T> &v) {
168  ds << v.x1() << v.x2() << v.y1() << v.y2() << v.z1() << v.z2();
169  return ds;
170 }
172 template <class T> inline QDataStream &operator>>(QDataStream &ds,Extent3<T> &v) {
173  ds >> v.rx1() >> v.rx2() >> v.ry1() >> v.ry2() >> v.rz1() >> v.rz2();
174  return ds;
175 }
176 
177 // Data Streaming Orientation, Axes, Variant, string, and SymTensor classes.
179 BASE_EXPORT QDataStream &operator<<(QDataStream &ds,const Orientation2 &o);
180 BASE_EXPORT QDataStream &operator>>(QDataStream &ds,Orientation2 &o);
181 BASE_EXPORT QDataStream &operator<<(QDataStream &ds,const Orientation3 &o);
182 BASE_EXPORT QDataStream &operator>>(QDataStream &ds,Orientation3 &o);
183 BASE_EXPORT QDataStream &operator<<(QDataStream &ds,const Axes2D &v);
184 BASE_EXPORT QDataStream &operator>>(QDataStream &ds,Axes2D &v);
185 BASE_EXPORT QDataStream &operator<<(QDataStream &ds,const Axes3D &v);
186 BASE_EXPORT QDataStream &operator>>(QDataStream &ds,Axes3D &v);
187 BASE_EXPORT QDataStream &operator<<(QDataStream &ds,const CAxes2D &v);
188 BASE_EXPORT QDataStream &operator>>(QDataStream &ds,CAxes2D &v);
189 BASE_EXPORT QDataStream &operator<<(QDataStream &ds,const CAxes3D &v);
190 BASE_EXPORT QDataStream &operator>>(QDataStream &ds,CAxes3D &v);
191 BASE_EXPORT QDataStream &operator<<(QDataStream &ds,const Variant &v);
192 BASE_EXPORT QDataStream &operator>>(QDataStream &ds,Variant &v);
193 BASE_EXPORT QDataStream &operator<<(QDataStream &ds,const std::wstring &v);
194 BASE_EXPORT QDataStream &operator>>(QDataStream &ds,std::wstring &v);
195 BASE_EXPORT QDataStream &operator<<(QDataStream &ds,const string &v);
196 BASE_EXPORT QDataStream &operator>>(QDataStream &ds,string &v);
197 BASE_EXPORT QDataStream &operator<<(QDataStream &ds,const SymTensor &s);
198 BASE_EXPORT QDataStream &operator>>(QDataStream &ds,SymTensor &v);
199 BASE_EXPORT QDataStream &operator<<(QDataStream &ds,const Quat2 &o);
200 BASE_EXPORT QDataStream &operator>>(QDataStream &ds,Quat2 &o);
201 BASE_EXPORT QDataStream &operator<<(QDataStream &ds,const Quat3 &o);
202 BASE_EXPORT QDataStream &operator>>(QDataStream &ds,Quat3 &o);
203 
204 // QTextStream functions
207 template <class T> inline QTextStream &operator<<(QTextStream &ds,const Vector2<T> &v) {
208  int w = ds.fieldWidth();
209  w = std::max(0,w-3);
210  w /= 2;
211  ds << qSetFieldWidth(0) << "(" << qSetFieldWidth(w) << v.x();
212  ds << qSetFieldWidth(0) << "," << qSetFieldWidth(w) << v.y();
213  ds << qSetFieldWidth(0) << ")";
214  return ds;
215 }
218 template <class T> inline QTextStream &operator<<(QTextStream &ds,const Vector3<T> &v) {
219  int w = ds.fieldWidth();
220  w = std::max(0,w-4);
221  w /= 3;
222  ds << qSetFieldWidth(0) << "(" << qSetFieldWidth(w) << v.x();
223  ds << qSetFieldWidth(0) << "," << qSetFieldWidth(w) << v.y();
224  ds << qSetFieldWidth(0) << "," << qSetFieldWidth(w) << v.z();
225  ds << qSetFieldWidth(0) << ")";
226  return ds;
227 }
229 template <class T> inline QTextStream &operator<<(QTextStream &ds,const AVector2<T> &v) {
230  ds << v.z();
231  return ds;
232 }
233 
234 // Conversion to Qt Core 2D vector types
236 template <class T> inline QPoint toQPoint(const Vector2<T> &v) {
237  QPoint ret(to<int>(v.x()),to<int>(v.y()));
238  return ret;
239 }
241 template <class T> inline QPointF toQPointF(const Vector2<T> &v) {
242  QPointF ret(to<qreal>(v.x()),to<qreal>(v.y()));
243  return ret;
244 }
246 inline DVect2 toDVect2(const QPoint &p) {
247  DVect2 dv2(to<Double>(p.x()),to<Double>(p.y()));
248  return dv2;
249 }
251 inline DVect2 toDVect2(const QSize &p) {
252  DVect2 dv2(to<Double>(p.width()),to<Double>(p.height()));
253  return dv2;
254 }
256 inline FVect2 toFVect2(const QPoint &p) {
257  FVect2 fv2(to<Float>(p.x()),to<Float>(p.y()));
258  return fv2;
259 }
261 inline IVect2 toIVect2(const QPoint &p) {
262  IVect2 iv2(to<Int>(p.x()),to<Int>(p.y()));
263  return iv2;
264 }
266 inline UVect2 toUVect2(const QPoint &p) {
267  UVect2 uv2(to<UInt>(p.x()),to<UInt>(p.y()));
268  return uv2;
269 }
271 inline DVect2 toDVect2(const QPointF &p) {
272  DVect2 dv2(to<Double>(p.x()),to<Double>(p.y()));
273  return dv2;
274 }
276 inline FVect2 toFVect2(const QPointF &p) {
277  FVect2 fv2(to<Float>(p.x()),to<Float>(p.y()));
278  return fv2;
279 }
281 inline IVect2 toIVect2(const QPointF &p) {
282  IVect2 iv2(to<Int>(p.x()),to<Int>(p.y()));
283  return iv2;
284 }
286 inline UVect2 toUVect2(const QPointF &p) {
287  UVect2 uv2(to<UInt>(p.x()),to<UInt>(p.y()));
288  return uv2;
289 }
290 
292 inline bool checkQVariantTypes(const QVariant &v1, const QVariant &v2)
293 {
294  int type1 = static_cast<int>(v1.type());
295  int type2 = static_cast<int>(v2.type());
296  if (type1==QVariant::UserType)
297  {
298  type1 = v1.userType();
299  if (type2==QVariant::UserType)
300  type2 = v2.userType();
301  else
302  return false;
303  }
304  return type1 == type2;
305 }
306 
307 // Converts from QVariant to Variant and vice versa.
310 BASE_EXPORT QVariant toQVariant(const Variant &v);
314 BASE_EXPORT Variant toVariant(const QVariant &v);
315 
324 BASE_EXPORT bool isDirectoryProtected(const QDir &dir,const QString &registryString);
325 
332 BASE_EXPORT QString getInstallDirectory(const QString &registryString);
333 
341 BASE_EXPORT QString convertFilePath(const QString &filePath,const QDir &previousDir,const QDir &newDir);
342 
345 BASE_EXPORT bool setCurrentDirectory(const QString &dir);
346 
350 
355 
356 // EOF
Class for specifying a particular 2D cartesian axes system, and converting to and from it.
Definition: caxes.h:25
QDataStream & operator<<(QDataStream &ds, const Vector2< T > &v)
Allows a Base type to be written to, or read from, a QDataStream.
Definition: basetoqt.h:114
Vector2< Int > IVect2
Definition: vect.h:284
Class for specifying a particular 3D cartesian axes system, and converting to and from it.
Definition: caxes.h:103
AVector3< Double > DAVect3
Definition: avect.h:196
bool checkQVariantTypes(const QVariant &v1, const QVariant &v2)
returns true if Variants have the same type
Definition: basetoqt.h:292
const T & x2() const
Returns the upper bound of the extent in the x-direction.
Definition: extent3.h:43
2D quaternion-like utility class. In this case only the angle (in radians) is stored as opposed to th...
Definition: quat.h:20
const T & y1() const
Returns the lower y-bound.
Definition: extent2.h:36
DVect2 toDVect2(const Vector2< T > &v)
Definition: vect.h:299
QPoint toQPoint(const Vector2< T > &v)
Convert a Vector2 to a QPoint.
Definition: basetoqt.h:236
A simpler (and slightly faster) version of a QVariant, added for interfaces that do not use Qt.
Definition: variant.h:28
const T & z() const
Member access - returns the z component of the 2D angular vector.
Definition: avect.h:69
UVect2 toUVect2(const Vector2< T > &v)
Definition: vect.h:308
BASE_EXPORT QString convertFilePath(const QString &filePath, const QDir &previousDir, const QDir &newDir)
Definition: basetoqt.cpp:460
FVect2 toFVect2(const Vector2< T > &v)
Definition: vect.h:302
BASE_EXPORT bool setCurrentDirectory(const QString &dir)
Definition: basetoqt.cpp:496
T & rz()
Returns a reference to the z component, cannot reference access x or y.
Definition: avect.h:80
T & rx2()
Access reference to the maximum x extent.
Definition: extent2.h:126
QPointF toQPointF(const Vector2< T > &v)
Convert a Vector2 to a QPointF.
Definition: basetoqt.h:241
AVector2< Int > IAVect2
Definition: avect.h:193
AVector2< Float > FAVect2
Definition: avect.h:192
Class for specifying a particular 3D cartesian axes system, and converting to and from it.
Definition: axes.h:120
QDataStream & operator>>(QDataStream &ds, Vector2< T > &v)
Definition: basetoqt.h:119
Class for specifying a particular 2D cartesian axes system, and converting to and from it.
Definition: axes.h:20
T & ry1()
Access reference to the minimum y extent.
Definition: extent2.h:128
T & ry2()
Access reference to the maximum y extent.
Definition: extent2.h:130
Vector3< Float > FVect3
Definition: vect.h:290
T & rx()
Reference access to the x-component of the vector.
Definition: vect.h:190
AVector2< Double > DAVect2
Definition: avect.h:191
T & ry1()
Reference access to the minimum y extent.
Definition: extent3.h:171
Class for storing an "orientation", or a direction in 2D or 3D space.
Definition: orientation.h:94
BASE_EXPORT QVariant toQVariant(const Variant &v)
Definition: basetoqt.cpp:338
T & rz1()
Reference access to the minimum z extent.
Definition: extent3.h:173
Vector2< UInt > UVect2
Definition: vect.h:285
Definition: basetoqt.h:80
const T & y1() const
Returns the lower bound of the extent in the y-direction.
Definition: extent3.h:45
#define BASE_EXPORT
Definition: basedef.h:21
A symmetric 2nd order tensor.
Definition: symtensor.h:19
const T & y() const
Y component access.
Definition: vect.h:56
AVector2< UInt > UAVect2
Definition: avect.h:194
BASE_EXPORT Variant toVariant(const QVariant &v)
Definition: basetoqt.cpp:367
2D vector utility class.
Definition: vect.h:31
const T & z() const
The z-component of the vector.
Definition: vect.h:186
AVector3< UInt > UAVect3
Definition: avect.h:199
T & rx1()
Access reference to the minimum x extent.
Definition: extent2.h:124
T & rx1()
Reference access to the minimum x extent.
Definition: extent3.h:169
Angular Vectors.
BASE_EXPORT void initializeQtToBase()
Definition: basetoqt.cpp:8
const T & x1() const
Returns the lower bound of the extent in the x-direction.
Definition: extent3.h:41
Vector3< UInt > UVect3
Definition: vect.h:292
AVector3< Int > IAVect3
Definition: avect.h:198
const T & y2() const
Returns the upper y-bound.
Definition: extent2.h:38
T & ry()
Reference access to y-component.
Definition: vect.h:62
T & ry2()
Reference access to the maximum y extent.
Definition: extent3.h:172
T & rx2()
Reference access to the maximum x extent.
Definition: extent3.h:170
BASE_EXPORT bool isDirectoryProtected(const QDir &dir, const QString &registryString)
Definition: basetoqt.cpp:404
2D cartesian region in space.
Definition: extent2.h:12
One stop include for all objects defined as part of base interface.
3D vector utility class.
Definition: vect.h:161
IVect2 toIVect2(const Vector2< T > &v)
Definition: vect.h:305
BASE_EXPORT QString getInstallDirectory(const QString &registryString)
Definition: basetoqt.cpp:444
AVector3< Float > FAVect3
Definition: avect.h:197
Class for storing an "orientation", or a direction in 2D or 3D space.
Definition: orientation.h:45
Vector3< Double > DVect3
Definition: vect.h:289
Vector3< Int > IVect3
Definition: vect.h:291
const T & z1() const
Returns the lower bound of the extent in the y-direction.
Definition: extent3.h:49
const T & x() const
X component access.
Definition: vect.h:54
BASE_EXPORT QString getCurrentDirectory()
Definition: basetoqt.cpp:501
T & rz()
Reference access to the z-component of the vector.
Definition: vect.h:194
Vector2< Double > DVect2
Definition: vect.h:282
Vector2< Float > FVect2
Definition: vect.h:283
2D Angular vector class.
Definition: avect.h:43
const T & x2() const
Returns the upper x-bound.
Definition: extent2.h:34
3D quaternion utility class.
Definition: quat.h:103
3D Angular vector class.
Definition: avect.h:176
const T & x1() const
Returns the lower x-bound.
Definition: extent2.h:32
A Class representing a cartesian extent in 3D.
Definition: extent3.h:16
BASE_EXPORT QDir getCurrentDirectoryObject()
Definition: basetoqt.cpp:506
T & rx()
Reference access to x-component.
Definition: vect.h:60
const T & y() const
The y-component of the vector.
Definition: vect.h:184
T & ry()
Reference access to the y-component of the vector.
Definition: vect.h:192
const T & x() const
The x-component of the vector.
Definition: vect.h:182
const T & z2() const
Returns the upper bound of the extent in the y-direction.
Definition: extent3.h:51
const T & y2() const
Returns the upper bound of the extent in the y-direction.
Definition: extent3.h:47
T & rz2()
Definition: extent3.h:174