Sat, 13 Jul 2013 19:02:48 +0300
Appended 'Object' to the names of all LDObject derivatives so even though the LD prefix isn't reserved for just LDObjects anymore, these classes remain distinct
230
43d722c255d3
Added support for overpaint-less mode since I'm having serious trouble with that
Santeri Piippo <crimsondusk64@gmail.com>
parents:
219
diff
changeset
|
1 | /* |
43d722c255d3
Added support for overpaint-less mode since I'm having serious trouble with that
Santeri Piippo <crimsondusk64@gmail.com>
parents:
219
diff
changeset
|
2 | * LDForge: LDraw parts authoring CAD |
43d722c255d3
Added support for overpaint-less mode since I'm having serious trouble with that
Santeri Piippo <crimsondusk64@gmail.com>
parents:
219
diff
changeset
|
3 | * Copyright (C) 2013 Santeri Piippo |
358 | 4 | * |
230
43d722c255d3
Added support for overpaint-less mode since I'm having serious trouble with that
Santeri Piippo <crimsondusk64@gmail.com>
parents:
219
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
43d722c255d3
Added support for overpaint-less mode since I'm having serious trouble with that
Santeri Piippo <crimsondusk64@gmail.com>
parents:
219
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
43d722c255d3
Added support for overpaint-less mode since I'm having serious trouble with that
Santeri Piippo <crimsondusk64@gmail.com>
parents:
219
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
43d722c255d3
Added support for overpaint-less mode since I'm having serious trouble with that
Santeri Piippo <crimsondusk64@gmail.com>
parents:
219
diff
changeset
|
8 | * (at your option) any later version. |
358 | 9 | * |
230
43d722c255d3
Added support for overpaint-less mode since I'm having serious trouble with that
Santeri Piippo <crimsondusk64@gmail.com>
parents:
219
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
43d722c255d3
Added support for overpaint-less mode since I'm having serious trouble with that
Santeri Piippo <crimsondusk64@gmail.com>
parents:
219
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
43d722c255d3
Added support for overpaint-less mode since I'm having serious trouble with that
Santeri Piippo <crimsondusk64@gmail.com>
parents:
219
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
43d722c255d3
Added support for overpaint-less mode since I'm having serious trouble with that
Santeri Piippo <crimsondusk64@gmail.com>
parents:
219
diff
changeset
|
13 | * GNU General Public License for more details. |
358 | 14 | * |
230
43d722c255d3
Added support for overpaint-less mode since I'm having serious trouble with that
Santeri Piippo <crimsondusk64@gmail.com>
parents:
219
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
43d722c255d3
Added support for overpaint-less mode since I'm having serious trouble with that
Santeri Piippo <crimsondusk64@gmail.com>
parents:
219
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
43d722c255d3
Added support for overpaint-less mode since I'm having serious trouble with that
Santeri Piippo <crimsondusk64@gmail.com>
parents:
219
diff
changeset
|
17 | */ |
43d722c255d3
Added support for overpaint-less mode since I'm having serious trouble with that
Santeri Piippo <crimsondusk64@gmail.com>
parents:
219
diff
changeset
|
18 | |
286
7a562bf3d829
Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
270
diff
changeset
|
19 | #include <QObject> |
7a562bf3d829
Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
270
diff
changeset
|
20 | #include <QStringList> |
287
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
21 | #include <QTextStream> |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
22 | #include <qfile.h> |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
23 | #include <assert.h> |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
24 | #include "common.h" |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
25 | #include "types.h" |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
26 | #include "misc.h" |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
27 | |
288
2980d7fd948e
Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents:
287
diff
changeset
|
28 | const File nullfile; |
287
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
29 | |
358 | 30 | str DoFormat( vector<StringFormatArg> args ) |
31 | { | |
32 | assert( args.size() >= 1 ); | |
33 | str text = args[0].value(); | |
286
7a562bf3d829
Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
270
diff
changeset
|
34 | |
358 | 35 | for( uchar i = 1; i < args.size(); ++i ) |
36 | text = text.arg( args[i].value() ); | |
286
7a562bf3d829
Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
270
diff
changeset
|
37 | |
7a562bf3d829
Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
270
diff
changeset
|
38 | return text; |
7a562bf3d829
Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
270
diff
changeset
|
39 | } |
7a562bf3d829
Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
270
diff
changeset
|
40 | |
358 | 41 | vertex::vertex( double x, double y, double z ) |
42 | { | |
191
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
43 | m_coords[X] = x; |
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
44 | m_coords[Y] = y; |
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
45 | m_coords[Z] = z; |
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
46 | } |
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
47 | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
48 | // ============================================================================= |
358 | 49 | void vertex::move( const vertex& other ) |
50 | { | |
51 | for( const Axis ax : g_Axes ) | |
191
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
52 | m_coords[ax] += other[ax]; |
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
53 | } |
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
54 | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
55 | // ============================================================================= |
358 | 56 | vertex vertex::midpoint( const vertex& other ) |
57 | { | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
58 | vertex mid; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
59 | |
358 | 60 | for( const Axis ax : g_Axes ) |
61 | mid[ax] = ( m_coords[ax] + other[ax] ) / 2; | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
62 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
63 | return mid; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
64 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
65 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
66 | // ============================================================================= |
358 | 67 | str vertex::stringRep( bool mangled ) const |
68 | { | |
69 | str fmtstr = "%1 %2 %3"; | |
70 | if( mangled ) | |
71 | fmtstr = "(%1, %2, %3)"; | |
286
7a562bf3d829
Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
270
diff
changeset
|
72 | |
358 | 73 | return fmt( fmtstr, coord( X ), coord( Y ), coord( Z )); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
74 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
75 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
76 | // ============================================================================= |
358 | 77 | void vertex::transform( matrix matr, vertex pos ) |
78 | { | |
79 | double x2 = ( matr[0] * x()) + ( matr[1] * y()) + ( matr[2] * z()) + pos[X]; | |
80 | double y2 = ( matr[3] * x()) + ( matr[4] * y()) + ( matr[5] * z()) + pos[Y]; | |
81 | double z2 = ( matr[6] * x()) + ( matr[7] * y()) + ( matr[8] * z()) + pos[Z]; | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
82 | |
358 | 83 | x() = x2; |
84 | y() = y2; | |
85 | z() = z2; | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
86 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
87 | |
358 | 88 | vertex vertex::operator-() const |
89 | { | |
90 | return vertex( -m_coords[X], -m_coords[Y], -m_coords[Z] ); | |
191
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
91 | } |
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
92 | |
358 | 93 | bool vertex::operator!= ( const vertex& other ) const |
94 | { | |
95 | return !operator== ( other ); | |
96 | } | |
97 | ||
98 | double& vertex::operator[]( const Axis ax ) | |
99 | { | |
100 | return coord( ( ushort ) ax ); | |
191
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
101 | } |
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
102 | |
358 | 103 | const double& vertex::operator[]( const Axis ax ) const |
104 | { | |
105 | return coord( ( ushort ) ax ); | |
191
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
106 | } |
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
107 | |
358 | 108 | double& vertex::operator[]( const int ax ) |
109 | { | |
110 | return coord( ax ); | |
219
70eb948a2b02
Added ability to set the depth value to something else than 0.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
211
diff
changeset
|
111 | } |
70eb948a2b02
Added ability to set the depth value to something else than 0.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
211
diff
changeset
|
112 | |
358 | 113 | const double& vertex::operator[]( const int ax ) const |
114 | { | |
115 | return coord( ax ); | |
219
70eb948a2b02
Added ability to set the depth value to something else than 0.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
211
diff
changeset
|
116 | } |
70eb948a2b02
Added ability to set the depth value to something else than 0.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
211
diff
changeset
|
117 | |
358 | 118 | bool vertex::operator== ( const vertex& other ) const |
119 | { | |
120 | return coord( X ) == other[X] && | |
121 | coord( Y ) == other[Y] && | |
122 | coord( Z ) == other[Z]; | |
191
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
123 | } |
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
124 | |
358 | 125 | vertex& vertex::operator/= ( const double d ) |
126 | { | |
127 | for( const Axis ax : g_Axes ) | |
191
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
128 | m_coords[ax] /= d; |
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
129 | |
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
130 | return *this; |
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
131 | } |
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
132 | |
358 | 133 | vertex vertex::operator/ ( const double d ) const |
134 | { | |
135 | vertex other( *this ); | |
191
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
136 | return other /= d; |
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
137 | } |
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
138 | |
358 | 139 | vertex& vertex::operator+= ( const vertex& other ) |
140 | { | |
141 | move( other ); | |
191
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
142 | return *this; |
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
143 | } |
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
144 | |
358 | 145 | vertex vertex::operator+ ( const vertex& other ) const |
146 | { | |
147 | vertex newvert( *this ); | |
148 | newvert.move( other ); | |
268
778eed342ee4
Make LDMatrixObject's transform and pos members properties
Santeri Piippo <crimsondusk64@gmail.com>
parents:
261
diff
changeset
|
149 | return newvert; |
778eed342ee4
Make LDMatrixObject's transform and pos members properties
Santeri Piippo <crimsondusk64@gmail.com>
parents:
261
diff
changeset
|
150 | } |
778eed342ee4
Make LDMatrixObject's transform and pos members properties
Santeri Piippo <crimsondusk64@gmail.com>
parents:
261
diff
changeset
|
151 | |
358 | 152 | int vertex::operator< ( const vertex& other ) const |
153 | { | |
154 | if( operator==( other )) | |
261
c4ad4e3c6839
Added ability to snap to pre-existing vertices while drawing, added changelog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
230
diff
changeset
|
155 | return false; |
c4ad4e3c6839
Added ability to snap to pre-existing vertices while drawing, added changelog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
230
diff
changeset
|
156 | |
358 | 157 | if( coord( X ) < other[X] ) |
261
c4ad4e3c6839
Added ability to snap to pre-existing vertices while drawing, added changelog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
230
diff
changeset
|
158 | return true; |
c4ad4e3c6839
Added ability to snap to pre-existing vertices while drawing, added changelog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
230
diff
changeset
|
159 | |
358 | 160 | if( coord( X ) > other[X] ) |
261
c4ad4e3c6839
Added ability to snap to pre-existing vertices while drawing, added changelog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
230
diff
changeset
|
161 | return false; |
c4ad4e3c6839
Added ability to snap to pre-existing vertices while drawing, added changelog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
230
diff
changeset
|
162 | |
358 | 163 | if( coord( Y ) < other[Y] ) |
261
c4ad4e3c6839
Added ability to snap to pre-existing vertices while drawing, added changelog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
230
diff
changeset
|
164 | return true; |
c4ad4e3c6839
Added ability to snap to pre-existing vertices while drawing, added changelog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
230
diff
changeset
|
165 | |
358 | 166 | if( coord( Y ) > other[Y] ) |
261
c4ad4e3c6839
Added ability to snap to pre-existing vertices while drawing, added changelog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
230
diff
changeset
|
167 | return false; |
c4ad4e3c6839
Added ability to snap to pre-existing vertices while drawing, added changelog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
230
diff
changeset
|
168 | |
358 | 169 | return coord( Z ) < other[Z]; |
261
c4ad4e3c6839
Added ability to snap to pre-existing vertices while drawing, added changelog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
230
diff
changeset
|
170 | } |
c4ad4e3c6839
Added ability to snap to pre-existing vertices while drawing, added changelog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
230
diff
changeset
|
171 | |
c4ad4e3c6839
Added ability to snap to pre-existing vertices while drawing, added changelog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
230
diff
changeset
|
172 | // ============================================================================= |
358 | 173 | matrix::matrix( double vals[] ) |
174 | { | |
175 | for( short i = 0; i < 9; ++i ) | |
191
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
176 | m_vals[i] = vals[i]; |
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
177 | } |
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
178 | |
358 | 179 | matrix::matrix( double fillval ) |
180 | { | |
181 | for( short i = 0; i < 9; ++i ) | |
191
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
182 | m_vals[i] = fillval; |
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
183 | } |
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
184 | |
358 | 185 | matrix::matrix( initlist<double> vals ) |
186 | { | |
187 | assert( vals.size() == 9 ); | |
188 | memcpy( &m_vals[0], &( *vals.begin() ), sizeof m_vals ); | |
191
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
189 | } |
358 | 190 | |
191 | void matrix::puts() const | |
192 | { | |
193 | for( short i = 0; i < 3; ++i ) | |
194 | { | |
195 | for( short j = 0; j < 3; ++j ) | |
196 | print( "%1\t", m_vals[( i * 3 ) + j] ); | |
191
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
197 | |
358 | 198 | print( "\n" ); |
191
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
199 | } |
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
200 | } |
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
201 | |
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
202 | // ============================================================================= |
358 | 203 | str matrix::stringRep() const |
204 | { | |
191
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
205 | str val; |
358 | 206 | |
207 | for( short i = 0; i < 9; ++i ) | |
208 | { | |
209 | if( i > 0 ) | |
191
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
210 | val += ' '; |
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
211 | |
358 | 212 | val += ftoa( m_vals[i] ); |
191
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
213 | } |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
214 | |
310
c62edce5668c
Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents:
288
diff
changeset
|
215 | return val; |
191
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
216 | } |
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
217 | |
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
218 | // ============================================================================= |
358 | 219 | void matrix::zero() |
220 | { | |
221 | memset( &m_vals[0], 0, sizeof( double ) * 9 ); | |
191
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
222 | } |
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
223 | |
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
224 | // ============================================================================= |
358 | 225 | matrix matrix::mult( matrix other ) const |
226 | { | |
191
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
227 | matrix val; |
358 | 228 | val.zero(); |
211
8d35e631bef3
Added dialog for rotation points
Santeri Piippo <crimsondusk64@gmail.com>
parents:
191
diff
changeset
|
229 | |
358 | 230 | for( short i = 0; i < 3; ++i ) |
231 | for( short j = 0; j < 3; ++j ) | |
232 | for( short k = 0; k < 3; ++k ) | |
233 | val[( i * 3 ) + j] += m_vals[( i * 3 ) + k] * other[( k * 3 ) + j]; | |
234 | ||
191
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
235 | return val; |
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
236 | } |
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
237 | |
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
238 | // ============================================================================= |
358 | 239 | matrix& matrix::operator= ( matrix other ) |
240 | { | |
241 | memcpy( &m_vals[0], &other.m_vals[0], sizeof( double ) * 9 ); | |
242 | return *this; | |
243 | } | |
244 | ||
245 | // ============================================================================= | |
246 | double matrix::determinant() const | |
247 | { | |
248 | return ( val( 0 ) * val( 4 ) * val( 8 )) + | |
249 | ( val( 1 ) * val( 5 ) * val( 6 )) + | |
250 | ( val( 2 ) * val( 3 ) * val( 7 )) - | |
251 | ( val( 2 ) * val( 4 ) * val( 6 )) - | |
252 | ( val( 1 ) * val( 3 ) * val( 8 )) - | |
253 | ( val( 0 ) * val( 5 ) * val( 7 )); | |
191
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
254 | } |
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
255 | |
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
256 | // ============================================================================= |
358 | 257 | StringFormatArg::StringFormatArg( const str& v ) |
258 | { | |
286
7a562bf3d829
Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
270
diff
changeset
|
259 | m_val = v; |
7a562bf3d829
Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
270
diff
changeset
|
260 | } |
7a562bf3d829
Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
270
diff
changeset
|
261 | |
358 | 262 | StringFormatArg::StringFormatArg( const char& v ) |
263 | { | |
286
7a562bf3d829
Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
270
diff
changeset
|
264 | m_val = v; |
7a562bf3d829
Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
270
diff
changeset
|
265 | } |
7a562bf3d829
Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
270
diff
changeset
|
266 | |
358 | 267 | StringFormatArg::StringFormatArg( const uchar& v ) |
268 | { | |
269 | m_val = v; | |
270 | } | |
271 | ||
272 | StringFormatArg::StringFormatArg( const qchar& v ) | |
273 | { | |
286
7a562bf3d829
Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
270
diff
changeset
|
274 | m_val = v; |
7a562bf3d829
Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
270
diff
changeset
|
275 | } |
7a562bf3d829
Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
270
diff
changeset
|
276 | |
358 | 277 | StringFormatArg::StringFormatArg( const float& v ) |
278 | { | |
279 | m_val = ftoa( v ); | |
280 | } | |
281 | ||
282 | StringFormatArg::StringFormatArg( const double& v ) | |
283 | { | |
284 | m_val = ftoa( v ); | |
285 | } | |
286 | ||
287 | StringFormatArg::StringFormatArg( const vertex& v ) | |
288 | { | |
289 | m_val = v.stringRep( false ); | |
290 | } | |
291 | ||
292 | StringFormatArg::StringFormatArg( const matrix& v ) | |
293 | { | |
294 | m_val = v.stringRep(); | |
295 | } | |
296 | ||
297 | StringFormatArg::StringFormatArg( const char* v ) | |
298 | { | |
286
7a562bf3d829
Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
270
diff
changeset
|
299 | m_val = v; |
7a562bf3d829
Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
270
diff
changeset
|
300 | } |
7a562bf3d829
Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
270
diff
changeset
|
301 | |
358 | 302 | StringFormatArg::StringFormatArg( const strconfig& v ) |
303 | { | |
286
7a562bf3d829
Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
270
diff
changeset
|
304 | m_val = v.value; |
7a562bf3d829
Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
270
diff
changeset
|
305 | } |
7a562bf3d829
Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
270
diff
changeset
|
306 | |
358 | 307 | StringFormatArg::StringFormatArg( const intconfig& v ) |
308 | { | |
309 | m_val.number( v.value ); | |
286
7a562bf3d829
Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
270
diff
changeset
|
310 | } |
7a562bf3d829
Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
270
diff
changeset
|
311 | |
358 | 312 | StringFormatArg::StringFormatArg( const floatconfig& v ) |
313 | { | |
314 | m_val.number( v.value ); | |
287
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
315 | } |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
316 | |
322
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
317 | StringFormatArg::StringFormatArg( const void* v ) |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
318 | { |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
319 | m_val.sprintf( "%p", v ); |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
320 | } |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
310
diff
changeset
|
321 | |
287
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
322 | // ============================================================================= |
358 | 323 | File::File() |
324 | { | |
287
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
325 | // Make a null file |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
326 | m_file = null; |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
327 | m_textstream = null; |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
328 | } |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
329 | |
358 | 330 | File::File( str path, OpenType rtype ) |
331 | { | |
287
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
332 | m_file = null; |
358 | 333 | open( path, rtype ); |
287
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
334 | } |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
335 | |
358 | 336 | File::File( FILE* fp, OpenType rtype ) |
337 | { | |
287
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
338 | m_file = null; |
358 | 339 | open( fp, rtype ); |
287
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
340 | } |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
341 | |
358 | 342 | File::~File() |
343 | { | |
344 | if( m_file ) | |
345 | { | |
346 | m_file->close(); | |
287
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
347 | delete m_file; |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
348 | |
358 | 349 | if( m_textstream ) |
287
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
350 | delete m_textstream; |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
351 | } |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
352 | } |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
353 | |
358 | 354 | bool File::open( FILE* fp, OpenType rtype ) |
355 | { | |
356 | return open( "", rtype, fp ); | |
287
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
357 | } |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
358 | |
358 | 359 | bool File::open( str path, OpenType rtype, FILE* fp ) |
360 | { | |
361 | close(); | |
287
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
362 | |
358 | 363 | if( !m_file ) |
287
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
364 | m_file = new QFile; |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
365 | |
358 | 366 | m_file->setFileName( path ); |
287
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
367 | |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
368 | bool result; |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
369 | |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
370 | QIODevice::OpenMode mode = |
358 | 371 | ( rtype == Read ) ? QIODevice::ReadOnly : |
372 | ( rtype == Write ) ? QIODevice::WriteOnly : QIODevice::Append; | |
287
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
373 | |
358 | 374 | if( fp ) |
375 | result = m_file->open( fp, mode ); | |
287
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
376 | else |
358 | 377 | result = m_file->open( mode ); |
287
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
378 | |
358 | 379 | if( result ) |
380 | { | |
381 | m_textstream = new QTextStream( m_file ); | |
287
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
382 | return true; |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
383 | } |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
384 | |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
385 | delete m_file; |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
386 | m_file = null; |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
387 | return false; |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
388 | } |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
389 | |
358 | 390 | File::iterator File::begin() |
391 | { | |
392 | return iterator( this ); | |
287
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
393 | } |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
394 | |
358 | 395 | File::iterator& File::end() |
396 | { | |
287
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
397 | return m_endIterator; |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
398 | } |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
399 | |
358 | 400 | void File::write( str msg ) |
401 | { | |
402 | m_file->write( msg.toUtf8(), msg.length() ); | |
287
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
403 | } |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
404 | |
358 | 405 | bool File::readLine( str& line ) |
406 | { | |
407 | if( !m_textstream || m_textstream->atEnd() ) | |
288
2980d7fd948e
Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents:
287
diff
changeset
|
408 | return false; |
2980d7fd948e
Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents:
287
diff
changeset
|
409 | |
358 | 410 | line = m_textstream->readLine(); |
288
2980d7fd948e
Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents:
287
diff
changeset
|
411 | return true; |
287
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
412 | } |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
413 | |
358 | 414 | bool File::atEnd() const |
415 | { | |
416 | if( !m_textstream ) | |
417 | fatal( "cannot use atEnd on a null file" ); | |
288
2980d7fd948e
Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents:
287
diff
changeset
|
418 | |
358 | 419 | return m_textstream->atEnd(); |
287
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
420 | } |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
421 | |
358 | 422 | bool File::isNull() const |
423 | { | |
287
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
424 | return m_file == null; |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
425 | } |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
426 | |
358 | 427 | bool File::operator!() const |
428 | { | |
429 | return isNull(); | |
287
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
430 | } |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
431 | |
358 | 432 | void File::close() |
433 | { | |
434 | if( !m_file ) | |
287
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
435 | return; |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
436 | |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
437 | delete m_file; |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
438 | m_file = null; |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
439 | |
358 | 440 | if( m_textstream ) |
441 | { | |
287
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
442 | delete m_textstream; |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
443 | m_textstream = null; |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
444 | } |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
445 | } |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
446 | |
358 | 447 | bool File::flush() |
448 | { | |
449 | return m_file->flush(); | |
287
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
450 | } |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
451 | |
358 | 452 | File::operator bool () const |
453 | { | |
454 | return !isNull(); | |
288
2980d7fd948e
Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents:
287
diff
changeset
|
455 | } |
2980d7fd948e
Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents:
287
diff
changeset
|
456 | |
358 | 457 | void File::rewind() |
458 | { | |
459 | m_file->seek( 0 ); | |
287
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
460 | } |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
461 | |
358 | 462 | File::iterator::iterator( File* f ) : m_file( f ) |
463 | { | |
288
2980d7fd948e
Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents:
287
diff
changeset
|
464 | operator++ (); |
2980d7fd948e
Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents:
287
diff
changeset
|
465 | } |
2980d7fd948e
Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents:
287
diff
changeset
|
466 | |
358 | 467 | void File::iterator::operator++ () |
468 | { | |
469 | m_gotdata = m_file->readLine( m_text ); | |
288
2980d7fd948e
Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents:
287
diff
changeset
|
470 | } |
2980d7fd948e
Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents:
287
diff
changeset
|
471 | |
358 | 472 | str File::iterator::operator* () |
473 | { | |
287
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
474 | return m_text; |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
475 | } |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
476 | |
288
2980d7fd948e
Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents:
287
diff
changeset
|
477 | // The prime contestant for the weirdest operator== 2013 award? |
358 | 478 | bool File::iterator::operator== ( File::iterator& other ) |
479 | { | |
480 | return ( other.m_file == null && !m_gotdata ); | |
287
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
481 | } |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
482 | |
358 | 483 | bool File::iterator::operator!= ( File::iterator& other ) |
484 | { | |
485 | return !operator== ( other ); | |
486 | } |