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 } |