1 // dlgoptionsdrawing.cpp
3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
10 // JLH = James L. Hammons <jlhamm@acm.org>
13 // --- ---------- -----------------------------------------------------------
14 // JLH 05/18/2010 Added this text. :-)
17 #include "dlgoptionsdrawing.h"
21 #include "filterdxf.h"
27 DlgOptionsDrawing::DlgOptionsDrawing(QWidget * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/):
28 QDialog(parent, flags)
38 for(int i=0; i<=8; i++)
40 format.sprintf("%%.0%df", i);
41 s.sprintf(format.toAscii().data(), 0.0);
46 for(int i=RS2::None; i<RS2::LastUnit; i++)
47 // ui.cbUnit->insertItem(Units::unitToString((RS2::Unit)i));
48 ui.cbUnit->addItem(Units::unitToString((RS2::Unit)i));
50 // init units combobox:
52 unitList << tr("Scientific")
55 << tr("Architectural")
57 // ui.cbLengthFormat->insertStringList(unitList);
58 ui.cbLengthFormat->addItems(unitList);
60 // init angle units combobox:
61 QStringList aunitList;
62 aunitList << tr("Decimal Degrees")
66 << tr("Surveyor's units");
67 // ui.cbAngleFormat->insertStringList(aunitList);
68 ui.cbAngleFormat->addItems(aunitList);
71 for(int i=RS2::Custom; i<=RS2::NPageSize; i++)
72 // ui.cbPaperFormat->insertItem(Units::paperFormatToString((RS2::PaperFormat)i));
73 ui.cbPaperFormat->addItem(Units::paperFormatToString((RS2::PaperFormat)i));
77 QStringList encodingList;
78 encodingList << "Latin1"
121 cbEncoding->insertStringList(encodingList);
125 DlgOptionsDrawing::~DlgOptionsDrawing()
130 * Sets the graphic and updates the GUI to match the drawing.
132 void DlgOptionsDrawing::setGraphic(Drawing * g)
139 // main drawing unit:
140 int insunits = graphic->getVariableInt("$INSUNITS", 0);
141 // ui.cbUnit->setCurrentText(Units::unitToString(FilterDXF::numberToUnit(insunits)));
142 ui.cbUnit->setItemText(ui.cbUnit->currentIndex(),
143 Units::unitToString(FilterDXF::numberToUnit(insunits)));
145 // units / length format:
146 int lunits = graphic->getVariableInt("$LUNITS", 2);
147 // ui.cbLengthFormat->setCurrentItem(lunits - 1);
148 ui.cbLengthFormat->setCurrentIndex(lunits - 1);
150 // units length precision:
151 int luprec = graphic->getVariableInt("$LUPREC", 4);
152 updateLengthPrecision();
153 // ui.cbLengthPrecision->setCurrentItem(luprec);
154 ui.cbLengthPrecision->setCurrentIndex(luprec);
156 // units / angle format:
157 int aunits = graphic->getVariableInt("$AUNITS", 0);
158 // ui.cbAngleFormat->setCurrentItem(aunits);
159 ui.cbAngleFormat->setCurrentIndex(aunits);
161 // units angle precision:
162 int auprec = graphic->getVariableInt("$AUPREC", 2);
163 updateAnglePrecision();
164 // ui.cbAnglePrecision->setCurrentItem(auprec);
165 ui.cbAnglePrecision->setCurrentIndex(auprec);
169 RS2::PaperFormat format = graphic->getPaperFormat(&landscape);
170 DEBUG->print("DlgOptionsDrawing::setGraphic: paper format is: %d", (int)format);
171 // ui.cbPaperFormat->setCurrentItem((int)format);
172 ui.cbPaperFormat->setCurrentIndex((int)format);
174 // paper orientation:
176 ui.rbLandscape->setChecked(true);
178 ui.rbPortrait->setChecked(true);
181 ui.cbGridOn->setChecked(graphic->isGridOn());
183 Vector spacing = graphic->getVariableVector("$GRIDUNIT", Vector(0.0, 0.0));
184 // ui.cbXSpacing->setCurrentText(QString("%1").arg(spacing.x));
185 // ui.cbYSpacing->setCurrentText(QString("%1").arg(spacing.y));
186 ui.cbXSpacing->setItemText(ui.cbXSpacing->currentIndex(), QString("%1").arg(spacing.x));
187 ui.cbYSpacing->setItemText(ui.cbYSpacing->currentIndex(), QString("%1").arg(spacing.y));
189 if (ui.cbXSpacing->currentText() == "0")
190 // ui.cbXSpacing->setCurrentText(tr("auto"));
191 ui.cbXSpacing->setItemText(ui.cbXSpacing->currentIndex(), tr("auto"));
193 if (ui.cbYSpacing->currentText() == "0")
194 // ui.cbYSpacing->setCurrentText(tr("auto"));
195 ui.cbYSpacing->setItemText(ui.cbYSpacing->currentIndex(), tr("auto"));
197 // dimension text height:
198 RS2::Unit unit = (RS2::Unit)ui.cbUnit->currentIndex();
200 double dimtxt = graphic->getVariableDouble("$DIMTXT", Units::convert(2.5, RS2::Millimeter, unit));
201 // ui.cbDimTextHeight->setCurrentText(QString("%1").arg(dimtxt));
202 ui.cbDimTextHeight->setItemText(ui.cbDimTextHeight->currentIndex(), QString("%1").arg(dimtxt));
204 // dimension extension line extension:
205 double dimexe = graphic->getVariableDouble("$DIMEXE", Units::convert(1.25, RS2::Millimeter, unit));
206 // ui.cbDimExe->setCurrentText(QString("%1").arg(dimexe));
207 ui.cbDimExe->setItemText(ui.cbDimExe->currentIndex(), QString("%1").arg(dimexe));
209 // dimension extension line offset:
210 double dimexo = graphic->getVariableDouble("$DIMEXO", Units::convert(0.625, RS2::Millimeter, unit));
211 // ui.cbDimExo->setCurrentText(QString("%1").arg(dimexo));
212 ui.cbDimExo->setItemText(ui.cbDimExo->currentIndex(), QString("%1").arg(dimexo));
214 // dimension line gap:
215 double dimgap = graphic->getVariableDouble("$DIMGAP", Units::convert(0.625, RS2::Millimeter, unit));
216 // ui.cbDimGap->setCurrentText(QString("%1").arg(dimgap));
217 ui.cbDimGap->setItemText(ui.cbDimGap->currentIndex(), QString("%1").arg(dimgap));
219 // dimension arrow size:
220 double dimasz = graphic->getVariableDouble("$DIMASZ", Units::convert(2.5, RS2::Millimeter, unit));
221 // ui.cbDimAsz->setCurrentText(QString("%1").arg(dimasz));
222 ui.cbDimAsz->setItemText(ui.cbDimAsz->currentIndex(), QString("%1").arg(dimasz));
224 // spline line segments per patch:
225 int splinesegs = graphic->getVariableInt("$SPLINESEGS", 8);
226 // ui.cbSplineSegs->setCurrentText(QString("%1").arg(splinesegs));
227 ui.cbSplineSegs->setItemText(ui.cbSplineSegs->currentIndex(), QString("%1").arg(splinesegs));
229 DEBUG->print("DlgOptionsDrawing::setGraphic: splinesegs is: %d", splinesegs);
233 QString encoding = graphic->getVariableString("$DWGCODEPAGE",
235 encoding=System::getEncoding(encoding);
236 cbEncoding->setCurrentText(encoding);
245 * Called when OK is clicked.
247 void DlgOptionsDrawing::validate()
249 RS2::LinearFormat f = (RS2::LinearFormat)ui.cbLengthFormat->currentIndex();
251 if (f == RS2::Engineering || f == RS2::Architectural)
253 if (Units::stringToUnit(ui.cbUnit->currentText()) != RS2::Inch)
255 QMessageBox::warning( this, tr("Options"),
256 tr("For the length formats 'Engineering' and 'Architectural', the unit must be set to Inch."), QMessageBox::Ok, Qt::NoButton);
264 graphic->setUnit((RS2::Unit)ui.cbUnit->currentIndex());
266 graphic->addVariable("$LUNITS", ui.cbLengthFormat->currentIndex() + 1, 70);
267 graphic->addVariable("$DIMLUNIT", ui.cbLengthFormat->currentIndex() + 1, 70);
268 graphic->addVariable("$LUPREC", ui.cbLengthPrecision->currentIndex(), 70);
270 graphic->addVariable("$AUNITS", ui.cbAngleFormat->currentIndex(), 70);
271 graphic->addVariable("$DIMAUNIT", ui.cbAngleFormat->currentIndex(), 70);
272 graphic->addVariable("$AUPREC", ui.cbAnglePrecision->currentIndex(), 70);
273 graphic->addVariable("$DIMADEC", ui.cbAnglePrecision->currentIndex(), 70);
276 graphic->setPaperFormat((RS2::PaperFormat)ui.cbPaperFormat->currentIndex(),
277 ui.rbLandscape->isChecked());
279 // custom paper size:
280 if ((RS2::PaperFormat)ui.cbPaperFormat->currentIndex() == RS2::Custom)
282 graphic->setPaperSize(Vector(Math::eval(ui.lePaperWidth->text()),
283 Math::eval(ui.lePaperHeight->text())));
287 //graphic->addVariable("$GRIDMODE", (int)cbGridOn->isChecked() , 70);
288 graphic->setGridOn(ui.cbGridOn->isChecked());
289 Vector spacing(0.0, 0.0, 0.0);
291 if (ui.cbXSpacing->currentText() == tr("auto"))
295 spacing.x = ui.cbXSpacing->currentText().toDouble();
298 if (ui.cbYSpacing->currentText() == tr("auto"))
302 spacing.y = ui.cbYSpacing->currentText().toDouble();
305 graphic->addVariable("$GRIDUNIT", spacing, 10);
308 graphic->addVariable("$DIMTXT", Math::eval(ui.cbDimTextHeight->currentText()), 40);
309 graphic->addVariable("$DIMEXE", Math::eval(ui.cbDimExe->currentText()), 40);
310 graphic->addVariable("$DIMEXO", Math::eval(ui.cbDimExo->currentText()), 40);
311 graphic->addVariable("$DIMGAP", Math::eval(ui.cbDimGap->currentText()), 40);
312 graphic->addVariable("$DIMASZ", Math::eval(ui.cbDimAsz->currentText()), 40);
315 graphic->addVariable("$SPLINESEGS", (int)Math::eval(ui.cbSplineSegs->currentText()), 70);
317 DEBUG->print("DlgOptionsDrawing::validate: splinesegs is: %s",
318 ui.cbSplineSegs->currentText().toLatin1().data());
320 // update all dimension and spline entities in the graphic to match the new settings:
321 graphic->updateDimensions();
322 graphic->updateSplines();
324 graphic->setModified(true);
331 * Updates the length precision combobox
333 void DlgOptionsDrawing::updateLengthPrecision()
335 int index = ui.cbLengthPrecision->currentIndex();
336 ui.cbLengthPrecision->clear();
338 switch (ui.cbLengthFormat->currentIndex())
342 ui.cbLengthPrecision->addItem("0E+01");
343 ui.cbLengthPrecision->addItem("0.0E+01");
344 ui.cbLengthPrecision->addItem("0.00E+01");
345 ui.cbLengthPrecision->addItem("0.000E+01");
346 ui.cbLengthPrecision->addItem("0.0000E+01");
347 ui.cbLengthPrecision->addItem("0.00000E+01");
348 ui.cbLengthPrecision->addItem("0.000000E+01");
349 ui.cbLengthPrecision->addItem("0.0000000E+01");
350 ui.cbLengthPrecision->addItem("0.00000000E+01");
354 // (0, 0.1, 0.01, ...)
356 ui.cbLengthPrecision->addItems(listPrec1);
361 ui.cbLengthPrecision->addItem("0'-0\"");
362 ui.cbLengthPrecision->addItem("0'-0 1/2\"");
363 ui.cbLengthPrecision->addItem("0'-0 1/4\"");
364 ui.cbLengthPrecision->addItem("0'-0 1/8\"");
365 ui.cbLengthPrecision->addItem("0'-0 1/16\"");
366 ui.cbLengthPrecision->addItem("0'-0 1/32\"");
367 ui.cbLengthPrecision->addItem("0'-0 1/64\"");
368 ui.cbLengthPrecision->addItem("0'-0 1/128\"");
373 ui.cbLengthPrecision->addItem("0'-0\"");
374 ui.cbLengthPrecision->addItem("0'-0.0\"");
375 ui.cbLengthPrecision->addItem("0'-0.00\"");
376 ui.cbLengthPrecision->addItem("0'-0.000\"");
377 ui.cbLengthPrecision->addItem("0'-0.0000\"");
378 ui.cbLengthPrecision->addItem("0'-0.00000\"");
379 ui.cbLengthPrecision->addItem("0'-0.000000\"");
380 ui.cbLengthPrecision->addItem("0'-0.0000000\"");
381 ui.cbLengthPrecision->addItem("0'-0.00000000\"");
386 ui.cbLengthPrecision->addItem("0");
387 ui.cbLengthPrecision->addItem("0 1/2");
388 ui.cbLengthPrecision->addItem("0 1/4");
389 ui.cbLengthPrecision->addItem("0 1/8");
390 ui.cbLengthPrecision->addItem("0 1/16");
391 ui.cbLengthPrecision->addItem("0 1/32");
392 ui.cbLengthPrecision->addItem("0 1/64");
393 ui.cbLengthPrecision->addItem("0 1/128");
397 DEBUG->print(Debug::D_ERROR,
398 "DlgOptionsDrawing::updateLengthPrecision: error");
402 // ui.cbLengthPrecision->setCurrentItem(index);
403 ui.cbLengthPrecision->setCurrentIndex(index);
407 * Updates the angle precision combobox
409 void DlgOptionsDrawing::updateAnglePrecision()
411 int index = ui.cbAnglePrecision->currentIndex();
412 ui.cbAnglePrecision->clear();
414 switch (ui.cbAngleFormat->currentIndex())
418 ui.cbAnglePrecision->addItems(listPrec1);
423 ui.cbAnglePrecision->addItem(QString("0%1").arg(QChar(0xB0)));
424 ui.cbAnglePrecision->addItem(QString("0%100'").arg(QChar(0xB0)));
425 ui.cbAnglePrecision->addItem(QString("0%100'00\"").arg(QChar(0xB0)));
426 ui.cbAnglePrecision->addItem(QString("0%100'00.0\"").arg(QChar(0xB0)));
427 ui.cbAnglePrecision->addItem(QString("0%100'00.00\"").arg(QChar(0xB0)));
428 ui.cbAnglePrecision->addItem(QString("0%100'00.000\"").arg(QChar(0xB0)));
429 ui.cbAnglePrecision->addItem(QString("0%100'00.0000\"").arg(QChar(0xB0)));
434 ui.cbAnglePrecision->addItem("0g");
435 ui.cbAnglePrecision->addItem("0.0g");
436 ui.cbAnglePrecision->addItem("0.00g");
437 ui.cbAnglePrecision->addItem("0.000g");
438 ui.cbAnglePrecision->addItem("0.0000g");
439 ui.cbAnglePrecision->addItem("0.00000g");
440 ui.cbAnglePrecision->addItem("0.000000g");
441 ui.cbAnglePrecision->addItem("0.0000000g");
442 ui.cbAnglePrecision->addItem("0.00000000g");
447 ui.cbAnglePrecision->addItem("0r");
448 ui.cbAnglePrecision->addItem("0.0r");
449 ui.cbAnglePrecision->addItem("0.00r");
450 ui.cbAnglePrecision->addItem("0.000r");
451 ui.cbAnglePrecision->addItem("0.0000r");
452 ui.cbAnglePrecision->addItem("0.00000r");
453 ui.cbAnglePrecision->addItem("0.000000r");
454 ui.cbAnglePrecision->addItem("0.0000000r");
455 ui.cbAnglePrecision->addItem("0.00000000r");
460 ui.cbAnglePrecision->addItem("N 0d E");
461 ui.cbAnglePrecision->addItem("N 0d00' E");
462 ui.cbAnglePrecision->addItem("N 0d00'00\" E");
463 ui.cbAnglePrecision->addItem("N 0d00'00.0\" E");
464 ui.cbAnglePrecision->addItem("N 0d00'00.00\" E");
465 ui.cbAnglePrecision->addItem("N 0d00'00.000\" E");
466 ui.cbAnglePrecision->addItem("N 0d00'00.0000\" E");
473 ui.cbAnglePrecision->setCurrentIndex(index);
477 * Updates the preview of unit display.
479 void DlgOptionsDrawing::updatePreview()
482 prev = Units::formatLinear(14.43112351,
483 (RS2::Unit)ui.cbUnit->currentIndex(),
484 (RS2::LinearFormat)(ui.cbLengthFormat->currentIndex()),
485 ui.cbLengthPrecision->currentIndex());
486 ui.lLinear->setText(prev);
488 prev = Units::formatAngle(0.5327714,
489 (RS2::AngleFormat)ui.cbAngleFormat->currentIndex(),
490 ui.cbAnglePrecision->currentIndex());
491 ui.lAngular->setText(prev);
495 * Updates the paper size. Called for initialisation as well as when the
496 * paper format changes.
498 void DlgOptionsDrawing::updatePaperSize()
500 RS2::PaperFormat format = (RS2::PaperFormat)ui.cbPaperFormat->currentIndex();
502 if (format == RS2::Custom)
504 Vector s = graphic->getPaperSize();
505 //Vector plimmin = graphic->getVariableVector("$PLIMMIN", Vector(0,0));
506 //Vector plimmax = graphic->getVariableVector("$PLIMMAX", Vector(100,100));
507 ui.lePaperWidth->setText(QString("%1").arg(s.x));
508 ui.lePaperHeight->setText(QString("%1").arg(s.y));
512 Vector s = Units::paperFormatToSize(format);
513 ui.lePaperWidth->setText(QString("%1").arg(s.x));
514 ui.lePaperHeight->setText(QString("%1").arg(s.y));
517 if (ui.cbPaperFormat->currentIndex() == 0)
519 ui.lePaperWidth->setEnabled(true);
520 ui.lePaperHeight->setEnabled(true);
524 ui.lePaperWidth->setEnabled(false);
525 ui.lePaperHeight->setEnabled(false);
530 * Updates all unit labels that depend on the global unit.
532 void DlgOptionsDrawing::updateUnitLabels()
534 RS2::Unit u = (RS2::Unit)ui.cbUnit->currentIndex();
535 QString sign = Units::unitToSign(u);
536 ui.lDimUnit1->setText(sign);
537 ui.lDimUnit2->setText(sign);
538 ui.lDimUnit3->setText(sign);
539 ui.lDimUnit4->setText(sign);
540 ui.lDimUnit5->setText(sign);