src/toolsets/viewtoolset.cpp

changeset 1217
314e12e23c3a
parent 1215
77a0270352a3
child 1222
34def2630300
equal deleted inserted replaced
1216:12f9ea615cbc 1217:314e12e23c3a
27 #include "../dialogs.h" 27 #include "../dialogs.h"
28 #include "../glCompiler.h" 28 #include "../glCompiler.h"
29 #include "../documentmanager.h" 29 #include "../documentmanager.h"
30 #include "viewtoolset.h" 30 #include "viewtoolset.h"
31 31
32 ViewToolset::ViewToolset (MainWindow *parent) : 32 ViewToolset::ViewToolset(MainWindow *parent) :
33 Toolset (parent) {} 33 Toolset(parent) {}
34 34
35 void ViewToolset::selectAll() 35 void ViewToolset::selectAll()
36 { 36 {
37 for (LDObject* obj : currentDocument()->objects()) 37 for (LDObject* obj : currentDocument()->objects())
38 obj->select(); 38 obj->select();
49 { 49 {
50 if (obj->isColored()) 50 if (obj->isColored())
51 colors << obj->color(); 51 colors << obj->color();
52 } 52 }
53 53
54 removeDuplicates (colors); 54 removeDuplicates(colors);
55 currentDocument()->clearSelection(); 55 currentDocument()->clearSelection();
56 56
57 for (LDObject* obj : currentDocument()->objects()) 57 for (LDObject* obj : currentDocument()->objects())
58 { 58 {
59 if (colors.contains (obj->color())) 59 if (colors.contains(obj->color()))
60 obj->select(); 60 obj->select();
61 } 61 }
62 } 62 }
63 63
64 void ViewToolset::selectByType() 64 void ViewToolset::selectByType()
72 for (LDObject* obj : selectedObjects()) 72 for (LDObject* obj : selectedObjects())
73 { 73 {
74 types << obj->type(); 74 types << obj->type();
75 75
76 if (types.last() == OBJ_SubfileReference) 76 if (types.last() == OBJ_SubfileReference)
77 subfilenames << static_cast<LDSubfileReference*> (obj)->fileInfo()->name(); 77 subfilenames << static_cast<LDSubfileReference*>(obj)->fileInfo()->name();
78 } 78 }
79 79
80 removeDuplicates (types); 80 removeDuplicates(types);
81 removeDuplicates (subfilenames); 81 removeDuplicates(subfilenames);
82 currentDocument()->clearSelection(); 82 currentDocument()->clearSelection();
83 83
84 for (LDObject* obj : currentDocument()->objects()) 84 for (LDObject* obj : currentDocument()->objects())
85 { 85 {
86 LDObjectType type = obj->type(); 86 LDObjectType type = obj->type();
87 87
88 if (not types.contains (type)) 88 if (not types.contains(type))
89 continue; 89 continue;
90 90
91 // For subfiles, type check is not enough, we check the name of the document as well. 91 // For subfiles, type check is not enough, we check the name of the document as well.
92 if (type == OBJ_SubfileReference and not subfilenames.contains (static_cast<LDSubfileReference*> (obj)->fileInfo()->name())) 92 if (type == OBJ_SubfileReference and not subfilenames.contains(static_cast<LDSubfileReference*>(obj)->fileInfo()->name()))
93 continue; 93 continue;
94 94
95 obj->select(); 95 obj->select();
96 } 96 }
97 } 97 }
102 m_window->renderer()->update(); 102 m_window->renderer()->update();
103 } 103 }
104 104
105 void ViewToolset::screenshot() 105 void ViewToolset::screenshot()
106 { 106 {
107 const char* imageformats = "PNG images (*.png);;JPG images (*.jpg);;BMP images (*.bmp);;" 107 const char* imageformats = "PNG images(*.png);;JPG images(*.jpg);;BMP images(*.bmp);;"
108 "PPM images (*.ppm);;X11 Bitmaps (*.xbm);;X11 Pixmaps (*.xpm);;All Files (*.*)"; 108 "PPM images(*.ppm);;X11 Bitmaps(*.xbm);;X11 Pixmaps(*.xpm);;All Files(*.*)";
109 int width = m_window->renderer()->width(); 109 int width = m_window->renderer()->width();
110 int height = m_window->renderer()->height(); 110 int height = m_window->renderer()->height();
111 QByteArray capture = m_window->renderer()->capturePixels(); 111 QByteArray capture = m_window->renderer()->capturePixels();
112 const uchar* imagedata = reinterpret_cast<const uchar*> (capture.constData()); 112 const uchar* imagedata = reinterpret_cast<const uchar*>(capture.constData());
113 // GL and Qt formats have R and B swapped. Also, GL flips Y - correct it as well. 113 // GL and Qt formats have R and B swapped. Also, GL flips Y - correct it as well.
114 QImage image = QImage (imagedata, width, height, QImage::Format_ARGB32).rgbSwapped().mirrored(); 114 QImage image = QImage(imagedata, width, height, QImage::Format_ARGB32).rgbSwapped().mirrored();
115 QString root = Basename (currentDocument()->name()); 115 QString root = Basename(currentDocument()->name());
116 116
117 if (root.right (4) == ".dat") 117 if (root.right(4) == ".dat")
118 root.chop (4); 118 root.chop(4);
119 119
120 QString defaultname = (root.length() > 0) ? format ("%1.png", root) : ""; 120 QString defaultname = (root.length() > 0) ? format("%1.png", root) : "";
121 QString filename = QFileDialog::getSaveFileName (m_window, "Save Screencap", defaultname, imageformats); 121 QString filename = QFileDialog::getSaveFileName(m_window, "Save Screencap", defaultname, imageformats);
122 122
123 if (not filename.isEmpty() and not image.save (filename)) 123 if (not filename.isEmpty() and not image.save(filename))
124 Critical (format ("Couldn't open %1 for writing to save screencap: %2", filename, strerror (errno))); 124 Critical(format("Couldn't open %1 for writing to save screencap: %2", filename, strerror(errno)));
125 } 125 }
126 126
127 void ViewToolset::axes() 127 void ViewToolset::axes()
128 { 128 {
129 config.setDrawAxes (not config.drawAxes()); 129 config.setDrawAxes(not config.drawAxes());
130 m_window->updateActions(); 130 m_window->updateActions();
131 m_window->renderer()->update(); 131 m_window->renderer()->update();
132 } 132 }
133 133
134 void ViewToolset::visibilityToggle() 134 void ViewToolset::visibilityToggle()
135 { 135 {
136 for (LDObject* obj : selectedObjects()) 136 for (LDObject* obj : selectedObjects())
137 obj->setHidden (not obj->isHidden()); 137 obj->setHidden(not obj->isHidden());
138 } 138 }
139 139
140 void ViewToolset::visibilityHide() 140 void ViewToolset::visibilityHide()
141 { 141 {
142 for (LDObject* obj : selectedObjects()) 142 for (LDObject* obj : selectedObjects())
143 obj->setHidden (true); 143 obj->setHidden(true);
144 } 144 }
145 145
146 void ViewToolset::visibilityReveal() 146 void ViewToolset::visibilityReveal()
147 { 147 {
148 for (LDObject* obj : selectedObjects()) 148 for (LDObject* obj : selectedObjects())
149 obj->setHidden (false); 149 obj->setHidden(false);
150 } 150 }
151 151
152 void ViewToolset::wireframe() 152 void ViewToolset::wireframe()
153 { 153 {
154 config.setDrawWireframe (not config.drawWireframe()); 154 config.setDrawWireframe(not config.drawWireframe());
155 m_window->renderer()->refresh(); 155 m_window->renderer()->refresh();
156 } 156 }
157 157
158 void ViewToolset::setOverlay() 158 void ViewToolset::setOverlay()
159 { 159 {
160 OverlayDialog dlg; 160 OverlayDialog dlg;
161 161
162 if (not dlg.exec()) 162 if (not dlg.exec())
163 return; 163 return;
164 164
165 m_window->renderer()->setupOverlay ((ECamera) dlg.camera(), dlg.fpath(), dlg.ofsx(), 165 m_window->renderer()->setupOverlay((ECamera) dlg.camera(), dlg.fpath(), dlg.ofsx(),
166 dlg.ofsy(), dlg.lwidth(), dlg.lheight()); 166 dlg.ofsy(), dlg.lwidth(), dlg.lheight());
167 } 167 }
168 168
169 void ViewToolset::clearOverlay() 169 void ViewToolset::clearOverlay()
170 { 170 {
171 m_window->renderer()->clearOverlay(); 171 m_window->renderer()->clearOverlay();
172 } 172 }
173 173
174 void ViewToolset::drawAngles() 174 void ViewToolset::drawAngles()
175 { 175 {
176 config.setDrawAngles (not config.drawAngles()); 176 config.setDrawAngles(not config.drawAngles());
177 m_window->renderer()->refresh(); 177 m_window->renderer()->refresh();
178 } 178 }
179 179
180 void ViewToolset::setDrawDepth() 180 void ViewToolset::setDrawDepth()
181 { 181 {
182 if (m_window->renderer()->camera() == EFreeCamera) 182 if (m_window->renderer()->camera() == EFreeCamera)
183 return; 183 return;
184 184
185 bool ok; 185 bool ok;
186 double depth = QInputDialog::getDouble (m_window, "Set Draw Depth", 186 double depth = QInputDialog::getDouble(m_window, "Set Draw Depth",
187 format ("Depth value for %1:", m_window->renderer()->currentCameraName()), 187 format("Depth value for %1:", m_window->renderer()->currentCameraName()),
188 m_window->renderer()->getDepthValue(), -10000.0f, 10000.0f, 3, &ok); 188 m_window->renderer()->getDepthValue(), -10000.0f, 10000.0f, 3, &ok);
189 189
190 if (ok) 190 if (ok)
191 m_window->renderer()->setDepthValue (depth); 191 m_window->renderer()->setDepthValue(depth);
192 } 192 }
193 193
194 #if 0 194 #if 0
195 // This is a test to draw a dummy axle. Meant to be used as a primitive gallery, 195 // This is a test to draw a dummy axle. Meant to be used as a primitive gallery,
196 // but I can't figure how to generate these pictures properly. Multi-threading 196 // but I can't figure how to generate these pictures properly. Multi-threading
197 // these is an immense pain. 197 // these is an immense pain.
198 void ViewToolset::testpic() 198 void ViewToolset::testpic()
199 { 199 {
200 LDDocument* file = getFile ("axle.dat"); 200 LDDocument* file = getFile("axle.dat");
201 setlocale (LC_ALL, "C"); 201 setlocale(LC_ALL, "C");
202 202
203 if (not file) 203 if (not file)
204 { 204 {
205 critical ("couldn't load axle.dat"); 205 critical("couldn't load axle.dat");
206 return; 206 return;
207 } 207 }
208 208
209 int w, h; 209 int w, h;
210 210
211 GLRenderer* rend = new GLRenderer; 211 GLRenderer* rend = new GLRenderer;
212 rend->resize (64, 64); 212 rend->resize(64, 64);
213 rend->setAttribute (Qt::WA_DontShowOnScreen); 213 rend->setAttribute(Qt::WA_DontShowOnScreen);
214 rend->show(); 214 rend->show();
215 rend->setFile (file); 215 rend->setFile(file);
216 rend->setDrawOnly (true); 216 rend->setDrawOnly(true);
217 rend->compileAllObjects(); 217 rend->compileAllObjects();
218 rend->initGLData(); 218 rend->initGLData();
219 rend->drawGLScene(); 219 rend->drawGLScene();
220 220
221 uchar* imgdata = rend->screencap (w, h); 221 uchar* imgdata = rend->screencap(w, h);
222 QImage img = imageFromScreencap (imgdata, w, h); 222 QImage img = imageFromScreencap(imgdata, w, h);
223 223
224 if (img.isNull()) 224 if (img.isNull())
225 { 225 {
226 critical ("Failed to create the image!\n"); 226 critical("Failed to create the image!\n");
227 } 227 }
228 else 228 else
229 { 229 {
230 QLabel* label = new QLabel; 230 QLabel* label = new QLabel;
231 QDialog* dlg = new QDialog; 231 QDialog* dlg = new QDialog;
232 label->setPixmap (QPixmap::fromImage (img)); 232 label->setPixmap(QPixmap::fromImage(img));
233 QVBoxLayout* layout = new QVBoxLayout (dlg); 233 QVBoxLayout* layout = new QVBoxLayout(dlg);
234 layout->addWidget (label); 234 layout->addWidget(label);
235 dlg->exec(); 235 dlg->exec();
236 } 236 }
237 237
238 delete[] imgdata; 238 delete[] imgdata;
239 rend->deleteLater(); 239 rend->deleteLater();
240 } 240 }
241 #endif 241 #endif
242 242
243 void ViewToolset::bfcView() 243 void ViewToolset::bfcView()
244 { 244 {
245 config.setBfcRedGreenView (not config.bfcRedGreenView()); 245 config.setBfcRedGreenView(not config.bfcRedGreenView());
246 246
247 if (config.bfcRedGreenView()) 247 if (config.bfcRedGreenView())
248 config.setRandomColors (false); 248 config.setRandomColors(false);
249 249
250 m_window->updateActions(); 250 m_window->updateActions();
251 m_window->renderer()->refresh(); 251 m_window->renderer()->refresh();
252 } 252 }
253 253
258 LDObject* obj; 258 LDObject* obj;
259 259
260 if (selectedObjects().size() == 1) 260 if (selectedObjects().size() == 1)
261 defval = selectedObjects()[0]->lineNumber(); 261 defval = selectedObjects()[0]->lineNumber();
262 262
263 int idx = QInputDialog::getInt (nullptr, "Go to line", "Go to line:", defval, 263 int idx = QInputDialog::getInt(nullptr, "Go to line", "Go to line:", defval,
264 1, currentDocument()->getObjectCount(), 1, &ok); 264 1, currentDocument()->getObjectCount(), 1, &ok);
265 265
266 if (not ok or (obj = currentDocument()->getObject (idx - 1)) == nullptr) 266 if (not ok or(obj = currentDocument()->getObject(idx - 1)) == nullptr)
267 return; 267 return;
268 268
269 currentDocument()->clearSelection(); 269 currentDocument()->clearSelection();
270 obj->select(); 270 obj->select();
271 m_window->updateSelection(); 271 m_window->updateSelection();
272 } 272 }
273 273
274 void ViewToolset::randomColors() 274 void ViewToolset::randomColors()
275 { 275 {
276 config.setRandomColors (not config.randomColors()); 276 config.setRandomColors(not config.randomColors());
277 277
278 if (config.randomColors()) 278 if (config.randomColors())
279 config.setBfcRedGreenView (false); 279 config.setBfcRedGreenView(false);
280 280
281 m_window->updateActions(); 281 m_window->updateActions();
282 m_window->renderer()->refresh(); 282 m_window->renderer()->refresh();
283 } 283 }
284 284
285 void ViewToolset::drawSurfaces() 285 void ViewToolset::drawSurfaces()
286 { 286 {
287 config.setDrawSurfaces (not config.drawSurfaces()); 287 config.setDrawSurfaces(not config.drawSurfaces());
288 m_window->updateActions(); 288 m_window->updateActions();
289 } 289 }
290 290
291 void ViewToolset::drawEdgeLines() 291 void ViewToolset::drawEdgeLines()
292 { 292 {
293 config.setDrawEdgeLines (not config.drawEdgeLines()); 293 config.setDrawEdgeLines(not config.drawEdgeLines());
294 m_window->updateActions(); 294 m_window->updateActions();
295 } 295 }
296 296
297 void ViewToolset::drawConditionalLines() 297 void ViewToolset::drawConditionalLines()
298 { 298 {
299 config.setDrawConditionalLines (not config.drawConditionalLines()); 299 config.setDrawConditionalLines(not config.drawConditionalLines());
300 m_window->updateActions(); 300 m_window->updateActions();
301 } 301 }

mercurial