]> Shamusworld >> Repos - architektonas/blob - src/widgets/qg_dialogfactory.cpp
1238d8e054e7dbb310fc2905ca6d04ecf63befeb
[architektonas] / src / widgets / qg_dialogfactory.cpp
1 // qg_dialogfactory.cpp
2 //
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 // (C) 2010 Underground Software
7 //
8 // JLH = James L. Hammons <jlhamm@acm.org>
9 //
10 // Who  When        What
11 // ---  ----------  -----------------------------------------------------------
12 // JLH  05/10/2010  Added this text. :-)
13 //
14
15 #include "qg_dialogfactory.h"
16
17 #include "qg_layerwidget.h"
18 #include "qg_mainwindowinterface.h"
19 #include "rs_actiondimlinear.h"
20 #include "rs_actioninterface.h"
21 #include "rs_document.h"
22 #include "rs_patternlist.h"
23 #include "settings.h"
24 #include "rs_system.h"
25 #include "rs_text.h"
26
27 #if 0
28         #include "ui/qg_arcoptions.h"
29         #include "ui/qg_arctangentialoptions.h"
30         #include "ui/qg_beveloptions.h"
31         #include "ui/qg_blockdialog.h"
32         #include "ui/qg_cadtoolbar.h"
33         #include "ui/qg_circleoptions.h"
34         #include "ui/qg_commandwidget.h"
35         #include "ui/qg_coordinatewidget.h"
36         #include "ui/qg_dimlinearoptions.h"
37         #include "ui/qg_dimoptions.h"
38 #include "ui/qg_dlgarc.h"
39         #include "ui/qg_dlgattributes.h"
40 #include "ui/qg_dlgcircle.h"
41 #include "ui/qg_dlgdimension.h"
42 #include "ui/qg_dlgdimlinear.h"
43 #include "ui/qg_dlgellipse.h"
44 #include "ui/qg_dlghatch.h"
45 #include "ui/qg_dlginsert.h"
46 #include "ui/qg_dlgline.h"
47 #include "ui/qg_dlgmirror.h"
48 #include "ui/qg_dlgmove.h"
49 #include "ui/qg_dlgmoverotate.h"
50         #include "ui/qg_dlgoptionsdrawing.h"
51         #include "ui/qg_dlgoptionsgeneral.h"
52 #include "ui/qg_dlgpoint.h"
53 #include "ui/qg_dlgrotate.h"
54 #include "ui/qg_dlgrotate2.h"
55 #include "ui/qg_dlgscale.h"
56 #include "ui/qg_dlgspline.h"
57         #include "ui/qg_dlgtext.h"
58         #include "ui/qg_imageoptions.h"
59 #include "ui/qg_insertoptions.h"
60         #include "ui/qg_layerdialog.h"
61 #include "ui/qg_libraryinsertoptions.h"
62 #include "ui/qg_lineangleoptions.h"
63 #include "ui/qg_linebisectoroptions.h"
64         #include "ui/qg_lineoptions.h"
65 #include "ui/qg_lineparalleloptions.h"
66 #include "ui/qg_lineparallelthroughoptions.h"
67 #include "ui/qg_linepolygon2options.h"
68 #include "ui/qg_linepolygonoptions.h"
69 #include "ui/qg_linerelangleoptions.h"
70         #include "ui/qg_mousewidget.h"
71 #include "ui/qg_moverotateoptions.h"
72         #include "ui/qg_printpreviewoptions.h"
73 #include "ui/qg_roundoptions.h"
74         #include "ui/qg_selectionwidget.h"
75 #include "ui/qg_snapdistoptions.h"
76         #include "ui/qg_splineoptions.h"
77         #include "ui/qg_textoptions.h"
78         #include "ui/qg_trimamountoptions.h"
79 #endif
80 #include "arcoptions.h"
81 #include "arctangentialoptions.h"
82 #include "beveloptions.h"
83 #include "blockdialog.h"
84 #include "cadtoolbar.h"
85 #include "circleoptions.h"
86 #include "commandwidget.h"
87 #include "coordinatewidget.h"
88 #include "dimlinearoptions.h"
89 #include "dimoptions.h"
90 #include "dlgattributes.h"
91 #include "dlgoptionsdrawing.h"
92 #include "dlgoptionsgeneral.h"
93 #include "dlgtext.h"
94 #include "imageoptions.h"
95 #include "layerdialog.h"
96 #include "lineoptions.h"
97 #include "mousewidget.h"
98 #include "printpreviewoptions.h"
99 #include "selectionwidget.h"
100 #include "splineoptions.h"
101 #include "textoptions.h"
102 #include "trimamountoptions.h"
103
104 #ifdef RS_PROF
105 #include "qg_polylineoptions.h"
106 #endif
107
108 #ifdef RS_CAM
109 #include "rs_camdialog.h"
110 #endif
111
112 //QG_DialogFactory* QG_DialogFactory::uniqueInstance = NULL;
113
114 /**
115  * Constructor.
116  *
117  * @param parent Pointer to parent widget which can host dialogs.
118  * @param ow Pointer to widget that can host option widgets.
119  */
120 //QG_DialogFactory::QG_DialogFactory(QWidget * parent, QWidget * ow):
121 QG_DialogFactory::QG_DialogFactory(QWidget * parent, QToolBar * ow):
122         RS_DialogFactoryInterface()
123 {
124         RS_DEBUG->print("QG_DialogFactory::QG_DialogFactory");
125
126         this->parent = parent;
127         setOptionWidget(ow);
128
129         coordinateWidget = NULL;
130         mouseWidget = NULL;
131         selectionWidget = NULL;
132         cadToolBar = NULL;
133         commandWidget = NULL;
134         mainWindow = NULL;
135         RS_DEBUG->print("QG_DialogFactory::QG_DialogFactory: OK");
136 }
137
138 /**
139  * Destructor
140  */
141 QG_DialogFactory::~QG_DialogFactory()
142 {
143         RS_DEBUG->print("QG_DialogFactory::~QG_DialogFactory");
144         RS_DEBUG->print("QG_DialogFactory::~QG_DialogFactory: OK");
145 }
146
147 /**
148  * Links factory to a widget that can host tool options.
149  */
150 ///*virtual*/ void QG_DialogFactory::setOptionWidget(QWidget * ow)
151 /*virtual*/ void QG_DialogFactory::setOptionWidget(QToolBar * ow)
152 {
153         RS_DEBUG->print("QG_DialogFactory::setOptionWidget");
154         optionWidget = ow;
155         RS_DEBUG->print("QG_DialogFactory::setOptionWidget: OK");
156 }
157
158 /**
159  * Links this dialog factory to a coordinate widget.
160  */
161 /*virtual*/ void QG_DialogFactory::setCoordinateWidget(CoordinateWidget * cw)
162 {
163         coordinateWidget = cw;
164 }
165
166 /**
167  * Links this dialog factory to a mouse widget.
168  */
169 /*virtual*/ void QG_DialogFactory::setMouseWidget(MouseWidget * mw)
170 {
171         mouseWidget = mw;
172 }
173
174 /**
175  * Links this dialog factory to a selection widget.
176  */
177 /*virtual*/ void QG_DialogFactory::setSelectionWidget(SelectionWidget * sw)
178 {
179         selectionWidget = sw;
180 }
181
182 /**
183  * Links this dialog factory to the cad tool bar.
184  */
185 /*virtual*/ void QG_DialogFactory::setCadToolBar(CadToolBar * ctb)
186 {
187         cadToolBar = ctb;
188 }
189
190 /**
191  * @return cad tool bar or NULL.
192  */
193 CadToolBar * QG_DialogFactory::getCadToolBar()
194 {
195         return cadToolBar;
196 }
197
198 /**
199  * Links this dialog factory to a command widget.
200  */
201 /*virtual*/ void QG_DialogFactory::setCommandWidget(CommandWidget * cw)
202 {
203         commandWidget = cw;
204 }
205
206 /**
207  * @return command widget or NULL.
208  */
209 CommandWidget * QG_DialogFactory::getCommandWidget()
210 {
211         return commandWidget;
212 }
213
214 /**
215  * Links the dialog factory to a main app window.
216  */
217 /*virtual*/ void QG_DialogFactory::setMainWindow(QG_MainWindowInterface * mw)
218 {
219         mainWindow = mw;
220 }
221
222 /**
223  * Shows a message dialog.
224  */
225 void QG_DialogFactory::requestWarningDialog(const QString & warning)
226 {
227         QMessageBox::information(parent, QMessageBox::tr("Warning"),
228                 warning, QMessageBox::Ok);
229 }
230
231 /**
232  * Requests a new document from the main window.
233  */
234 RS_GraphicView * QG_DialogFactory::requestNewDocument(const QString & fileName, RS_Document * doc)
235 {
236         if (mainWindow != NULL)
237         {
238                 mainWindow->createNewDocument(fileName, doc);
239                 return mainWindow->getGraphicView();
240         }
241
242         return NULL;
243 }
244
245 /**
246  * Requests the simulation controls.
247  */
248 void QG_DialogFactory::requestSimulationControls()
249 {
250         if (mainWindow != NULL)
251         {
252                 mainWindow->showSimulationControls();
253         }
254 }
255
256 /**
257  * Shows a dialog for adding a layer. Doesn't add the layer.
258  * This is up to the caller.
259  *
260  * @return a pointer to the newly created layer that
261  * should be added.
262  */
263 RS_Layer * QG_DialogFactory::requestNewLayerDialog(RS_LayerList * layerList)
264 {
265         RS_Layer * layer = NULL;
266         QString layer_name = "noname";
267         int i = 2;
268
269         if (layerList != NULL)
270         {
271                 while (layerList->find(layer_name) > 0)
272                         layer_name.sprintf("noname%d", i++);
273         }
274
275         // Layer for parameter livery
276         layer = new RS_Layer(layer_name);
277
278 //      QG_LayerDialog dlg(parent, "Layer Dialog");
279         LayerDialog dlg(parent);
280         dlg.setLayer(layer);
281         dlg.setLayerList(layerList);
282
283         if (dlg.exec())
284                 dlg.updateLayer();
285         else
286         {
287                 delete layer;
288                 layer = NULL;
289         }
290
291         return layer;
292 }
293
294 /**
295  * Shows a dialog that asks the user if the selected layer
296  * can be removed. Doesn't remove the layer. This is up to the caller.
297  *
298  * @return a pointer to the layer that should be removed.
299  */
300 RS_Layer * QG_DialogFactory::requestLayerRemovalDialog(RS_LayerList * layerList)
301 {
302     RS_Layer * layer = NULL;
303
304         if (layerList == NULL)
305         {
306         RS_DEBUG->print(RS_Debug::D_WARNING,
307                 "QG_DialogFactory::requestLayerRemovalDialog(): layerList is NULL");
308
309         return NULL;
310     }
311     /*
312        if (layerList==NULL) {
313            if (container!=NULL && container->rtti()==RS2::EntityGraphic) {
314                layerList = (RS_LayerList*)container;
315            } else {
316                return NULL;
317            }
318        }*/
319
320         // Layer for parameter livery
321         layer = layerList->getActive();
322
323         if (layer != NULL)
324         {
325                 if (layer->getName() != "0")
326                 {
327                         int remove = QMessageBox::information(parent, QMessageBox::tr("Remove Layer"),
328                                 QMessageBox::tr("Layer \"%1\" and all entities on it will be removed.").arg(layer->getName()),
329                                 QMessageBox::Ok, QMessageBox::Cancel);
330
331                         if (remove == 1)
332                         {
333                         }
334                         else
335                         {
336                                 layer = NULL;
337                         }
338                 }
339                 else
340                 {
341                         QMessageBox::information(parent, QMessageBox::tr("Remove Layer"),
342                                 QMessageBox::tr("Layer \"%1\" can never be removed.").arg(layer->getName()),
343                                 QMessageBox::Ok);
344                 }
345         }
346
347         return layer;
348 }
349
350 /**
351  * Shows a dialog for editing a layer. A new layer is created and
352  * returned. Modifying the layer is up to the caller.
353  *
354  * @return A pointer to a new layer with the changed attributes
355  *         or NULL if the dialog was cancelled.
356  */
357 RS_Layer * QG_DialogFactory::requestEditLayerDialog(RS_LayerList * layerList)
358 {
359         RS_DEBUG->print("QG_DialogFactory::requestEditLayerDialog");
360         RS_Layer * layer = NULL;
361         /*
362         if (layerList==NULL) {
363                 if (container!=NULL && container->rtti()==RS2::EntityGraphic) {
364                         layerList = (RS_LayerList*)container;
365                 } else {
366                         return NULL;
367                 }
368         }
369         */
370
371         if (layerList == NULL)
372         {
373                 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestEditLayerDialog(): "
374                         "layerList is NULL");
375                 return NULL;
376         }
377
378         // Layer for parameter livery
379         if (layerList->getActive() != NULL)
380         {
381                 layer = new RS_Layer(*layerList->getActive());
382
383 //        QG_LayerDialog dlg(parent, QMessageBox::tr("Layer Dialog"));
384                 LayerDialog dlg(parent);
385                 dlg.setLayer(layer);
386                 dlg.setLayerList(layerList);
387                 dlg.setEditLayer(true);
388
389                 if (dlg.exec())
390                         dlg.updateLayer();
391                 else
392                 {
393                         delete layer;
394                         layer = NULL;
395                 }
396         }
397
398         return layer;
399 }
400
401 /**
402  * Shows a dialog for adding a block. Doesn't add the block.
403  * This is up to the caller.
404  *
405  * @return a pointer to the newly created block that
406  * should be added.
407  */
408 RS_BlockData QG_DialogFactory::requestNewBlockDialog(RS_BlockList * blockList)
409 {
410         //RS_Block* block = NULL;
411         RS_BlockData ret;
412         ret = RS_BlockData("", Vector(false), false);
413
414         if (blockList == NULL)
415         {
416                 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestNewBlockDialog(): "
417                         "blockList is NULL");
418                 return ret;
419         }
420
421         // Block for parameter livery
422         //block = new RS_Block(container, "noname", Vector(0.0,0.0));
423
424         BlockDialog dlg(parent);
425         dlg.setBlockList(blockList);
426
427         if (dlg.exec())
428                 ret = dlg.getBlockData();
429
430         return ret;
431 }
432
433 /**
434  * Shows a dialog for renaming the currently active block.
435  *
436  * @return a pointer to the modified block or NULL on cancellation.
437  */
438 RS_BlockData QG_DialogFactory::requestBlockAttributesDialog(RS_BlockList * blockList)
439 {
440         //RS_Block* block = NULL;
441         RS_BlockData ret;
442         ret = RS_BlockData("", Vector(false), false);
443
444         if (blockList == NULL)
445         {
446                 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestBlockAttributesDialog(): "
447                         "blockList is NULL");
448                 return ret;
449         }
450         /*
451                 if (blockList==NULL) {
452                         if (container!=NULL && container->rtti()==RS2::EntityGraphic) {
453                                 blockList = (RS_BlockList*)container;
454                         } else {
455                                 return NULL;
456                         }
457                 }*/
458
459         // Block for parameter livery
460         //block = blockList->getActive();
461
462         BlockDialog dlg(parent);//WAS:, "Rename Block");
463 #warning "!!! WTF !!! WHY DO WE HAVE TO PREFIX tr WITH QObject:: ???"
464         dlg.setWindowTitle(QObject::tr("Rename Block"));
465         dlg.setBlockList(blockList);
466
467         if (dlg.exec())
468         {
469                 //dlg.updateBlock();
470                 //block->setData();
471                 ret = dlg.getBlockData();
472         }
473         //else {
474         //      ret = RS_BlockData("", Vector(false));
475         //}
476
477         return ret;
478 }
479
480 /*virtual*/ void QG_DialogFactory::requestEditBlockWindow(RS_BlockList * /*blockList*/)
481 {
482 }
483
484 /*virtual*/ void QG_DialogFactory::closeEditBlockWindow(RS_Block * /*blockList*/)
485 {
486 }
487
488 /**
489  * Shows a dialog that asks the user if the selected block
490  * can be removed. Doesn't remove the block. This is up to the caller.
491  *
492  * @return a pointer to the block that should be removed.
493  */
494 RS_Block * QG_DialogFactory::requestBlockRemovalDialog(RS_BlockList * blockList)
495 {
496         RS_Block * block = NULL;
497
498         if (blockList == NULL)
499         {
500                 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestBlockRemovalDialog(): "
501                         "blockList is NULL");
502                 return NULL;
503         }
504
505         // Block for parameter livery
506         block = blockList->getActive();
507
508         if (block != NULL)
509         {
510                 int remove = QMessageBox::information(parent, QMessageBox::tr("Remove Block"),
511                         QMessageBox::tr("Block \"%1\" and all its entities will be removed.").arg(block->getName()),
512                         QMessageBox::Ok, QMessageBox::Cancel);
513
514                 if (remove == 1)
515                 {
516                 }
517                 else
518                 {
519                         block = NULL;
520                 }
521         }
522
523         return block;
524 }
525
526 /**
527  * Shows a dialog for choosing a file name. Saving the file is up to
528  * the caller.
529  *
530  * @return File name with path and extension to determine the file type
531  *         or an empty string if the dialog was cancelled.
532  */
533 /*
534 QString QG_DialogFactory::requestFileSaveAsDialog() {
535     // read default settings:
536     RS_SETTINGS->beginGroup("/Paths");
537     QString defDir = RS_SETTINGS->readEntry("/Save",
538                        RS_SYSTEM->getHomeDir());
539     QString defFilter = RS_SETTINGS->readEntry("/SaveFilter",
540                           "Drawing Exchange (*.dxf)");
541     RS_SETTINGS->endGroup();
542
543     // prepare file save as dialog:
544     QFileDialog fileDlg(this,0,true);
545     QStringList filters;
546     bool done = false;
547     bool cancel = false;
548     QString fn = "";
549
550     filters.append("Drawing Exchange (*.dxf)");
551     filters.append("Font (*.cxf)");
552     fileDlg.setFilters(filters);
553     fileDlg.setMode(QFileDialog::AnyFile);
554     fileDlg.setCaption(tr("Save Drawing As"));
555     fileDlg.setDir(defDir);
556     fileDlg.setSelectedFilter(defFilter);
557
558     // run dialog:
559     do {
560         // accepted:
561         if (fileDlg.exec()==QDialog::Accepted) {
562                 fn = fileDlg.selectedFile();
563                         cancel = false;
564
565             // append default extension:
566             if (fn.find('.')==-1) {
567                 if (fileDlg.selectedFilter()=="Font (*.cxf)") {
568                     fn+=".cxf";
569                 } else {
570                     fn+=".dxf";
571                 }
572             }
573
574             // overwrite warning:
575             if(QFileInfo(fn).exists()) {
576                 int choice =
577                     QMessageBox::warning(this, tr("Save Drawing As"),
578                                          tr("%1 already exists.\n"
579                                             "Do you want to replace it?")
580                                          .arg(fn),
581                                          tr("Yes"), tr("No"),
582                                          tr("Cancel"), 0, 1 );
583
584                 switch (choice) {
585                 case 0:
586                     done = true;
587                     break;
588                 case 1:
589                 case 2:
590                 default:
591                     done = false;
592                     break;
593                 }
594             } else {
595                 done = true;
596             }
597         }
598                 else {
599             done = true;
600             cancel = true;
601                         fn = "";
602         }
603     } while(!done);
604
605     // store new default settings:
606     if (!cancel) {
607         RS_SETTINGS->beginGroup("/Paths");
608         RS_SETTINGS->writeEntry("/Save", QFileInfo(fn).dirPath(true));
609         RS_SETTINGS->writeEntry("/SaveFilter", fileDlg.selectedFilter());
610         RS_SETTINGS->endGroup();
611     }
612
613     return fn;
614 }
615 */
616
617 /**
618  * Shows a dialog for choosing a file name. Opening the file is up to
619  * the caller.
620  *
621  * @return File name with path and extension to determine the file type
622  *         or an empty string if the dialog was cancelled.
623  */
624 QString QG_DialogFactory::requestImageOpenDialog()
625 {
626         QString fn = "";
627
628         // read default settings:
629         settings.beginGroup("Paths");
630         QString defDir = settings.value("OpenImage", RS_SYSTEM->getHomeDir()).toString();
631         QString defFilter = settings.value("ImageFilter", "Portable Network Graphic (*.png)").toString();
632         settings.endGroup();
633
634         bool cancel = false;
635
636 //      Q3FileDialog fileDlg(NULL, "", true);
637         QFileDialog fileDlg(NULL, "");
638
639 #if 0
640 //      Q3StrList f = QImageIO::inputFormats();
641 //      QStringList formats = QStringList::fromStrList(f);
642         QList<QByteArray> f = QImageReader::supportedImageFormats();
643         QStringList formats = ???
644 #else
645 #warning "Needs porting to Qt4... !!! FIX !!!"
646 #endif
647
648         QStringList filters;
649         QString all = "";
650         //filters = QStringList::fromStrList(formats);
651
652 #if 0
653         for (QStringList::Iterator it=formats.begin(); it!=formats.end(); ++it)
654         {
655                 QString ext = (*it);
656
657                 QString st;
658
659                 if (ext == "JPEG")
660                 {
661                         st = QString("%1 (*.%2 *.jpg)").arg(extToFormat(*it)).arg(QString(*it).lower());
662                 }
663                 else
664                 {
665                         st = QString("%1 (*.%2)").arg(extToFormat(*it)).arg(QString(*it).lower());
666                 }
667
668                 filters.append(st);
669
670                 if (!all.isEmpty())
671                         all += " ";
672
673                 if (ext == "JPEG")
674                 {
675                         all += QString("*.%1 *.jpg").arg(QString(*it).lower());
676                 }
677                 else
678                 {
679                         all += QString("*.%1").arg(QString(*it).lower());
680                 }
681         }
682 #endif
683
684         filters.append(QObject::tr("All Image Files (%1)").arg(all));
685         filters.append(QObject::tr("All Files (*.*)"));
686
687         //filters.append("Drawing Exchange (*.)");
688         //filters.append("Font (*.cxf)");
689
690         fileDlg.setFilters(filters);
691 //      fileDlg.setMode(Q3FileDialog::ExistingFile);
692         fileDlg.setFileMode(QFileDialog::ExistingFile);
693 //      fileDlg.setCaption(QObject::tr("Open Image"));
694         fileDlg.setWindowTitle(QObject::tr("Open Image"));
695 //      fileDlg.setDir(defDir);
696         fileDlg.setDirectory(defDir);
697 //      fileDlg.setSelectedFilter(defFilter);
698         fileDlg.selectFilter(defFilter);
699
700         cancel = true;
701
702         if (fileDlg.exec() == QDialog::Accepted)
703         {
704 //              fn = fileDlg.selectedFile();
705                 QStringList files = fileDlg.selectedFiles();
706
707                 if (!files.isEmpty())
708                         fn = files[0];
709
710                 cancel = false;
711         }
712
713         // store new default settings:
714         if (!cancel)
715         {
716                 QStringList files = fileDlg.selectedFiles();
717                 QString selected = "";
718
719                 if (!files.isEmpty())
720                         selected = files[0];
721
722                 settings.beginGroup("Paths");
723 //              RS_SETTINGS->writeEntry("/OpenImage", QFileInfo(fn).dirPath(true));
724                 settings.setValue("OpenImage", QFileInfo(fn).absolutePath());
725                 settings.setValue("ImageFilter", selected);
726                 settings.endGroup();
727         }
728
729         return fn;
730 }
731
732 void QG_DialogFactory::requestOptions(RS_ActionInterface * action, bool on, bool update)
733 {
734         RS_DEBUG->print("QG_DialogFactory::requestOptions");
735
736     if (action == NULL)
737         {
738         RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestOptions: action is NULL");
739         return;
740     }
741
742     switch (action->rtti())
743         {
744     case RS2::ActionPrintPreview:
745         requestPrintPreviewOptions(action, on, update);
746         break;
747
748     case RS2::ActionDrawLine:
749                 RS_DEBUG->print("QG_DialogFactory::requestOptions: line");
750         requestLineOptions(action, on);
751                 RS_DEBUG->print("QG_DialogFactory::requestOptions: line: OK");
752         break;
753
754     case RS2::ActionDrawPolyline:
755         requestPolylineOptions(action, on, update);
756         break;
757
758     case RS2::ActionDrawLineAngle:
759         requestLineAngleOptions(action, on, update);
760         break;
761
762     case RS2::ActionDrawLineParallel:
763         requestLineParallelOptions(action, on, update);
764         break;
765
766     case RS2::ActionDrawLineParallelThrough:
767         requestLineParallelThroughOptions(action, on, update);
768         break;
769
770     case RS2::ActionDrawLineBisector:
771         requestLineBisectorOptions(action, on, update);
772         break;
773
774     case RS2::ActionDrawLineRelAngle:
775         requestLineRelAngleOptions(action, on, update);
776         break;
777
778     case RS2::ActionDrawLinePolygon:
779         requestLinePolygonOptions(action, on, update);
780         break;
781
782     case RS2::ActionDrawLinePolygon2:
783         requestLinePolygon2Options(action, on, update);
784         break;
785
786     case RS2::ActionDrawArc:
787         requestArcOptions(action, on, update);
788         break;
789
790         case RS2::ActionDrawArcTangential:
791         requestArcTangentialOptions(action, on, update);
792         break;
793
794     case RS2::ActionDrawCircleCR:
795         requestCircleOptions(action, on, update);
796         break;
797
798     case RS2::ActionDrawSpline:
799         requestSplineOptions(action, on, update);
800         break;
801
802     case RS2::ActionDrawText:
803         requestTextOptions(action, on, update);
804         break;
805
806     case RS2::ActionBlocksInsert:
807         requestInsertOptions(action, on, update);
808         break;
809
810     case RS2::ActionDrawImage:
811         requestImageOptions(action, on, update);
812         break;
813
814     case RS2::ActionDimAligned:
815         requestDimensionOptions(action, on, update);
816         break;
817
818     case RS2::ActionDimLinear:
819         requestDimensionOptions(action, on, update);
820
821                 if (((RS_ActionDimLinear *)action)->hasFixedAngle() == false)
822             requestDimLinearOptions(action, on, update);
823
824                 break;
825
826     case RS2::ActionDimRadial:
827         requestDimensionOptions(action, on, update);
828         break;
829
830     case RS2::ActionDimDiametric:
831         requestDimensionOptions(action, on, update);
832         break;
833
834     case RS2::ActionDimAngular:
835         requestDimensionOptions(action, on, update);
836         break;
837
838     case RS2::ActionModifyTrimAmount:
839         requestTrimAmountOptions(action, on, update);
840         break;
841
842     case RS2::ActionModifyMoveRotate:
843         requestMoveRotateOptions(action, on, update);
844         break;
845
846     case RS2::ActionModifyBevel:
847         requestBevelOptions(action, on, update);
848         break;
849
850     case RS2::ActionModifyRound:
851         requestRoundOptions(action, on, update);
852         break;
853
854     case RS2::ActionLibraryInsert:
855         requestLibraryInsertOptions(action, on, update);
856         break;
857
858     default:
859         break;
860     }
861
862         RS_DEBUG->print("QG_DialogFactory::requestOptions: OK");
863 }
864
865 /**
866  * Shows a widget for options for the action: "print preview"
867  */
868 void QG_DialogFactory::requestPrintPreviewOptions(RS_ActionInterface * action, bool on, bool update)
869 {
870         static PrintPreviewOptions * toolWidget = NULL;
871
872         if (!optionWidget)
873                 return;
874
875         if (toolWidget)
876         {
877                 delete toolWidget;
878                 toolWidget = NULL;
879         }
880
881         if (on)
882         {
883                 toolWidget = new PrintPreviewOptions(optionWidget);
884                 toolWidget->setAction(action, update);
885         }
886 }
887
888 /**
889  * Shows a widget for options for the action: "draw line"
890  */
891 void QG_DialogFactory::requestLineOptions(RS_ActionInterface * action, bool on)
892 {
893 /*
894 The way I see it, this is failure. We're constantly creating & deleting
895 these objects all the time when we could create them once, and then reuse
896 them over and over. May need to do some more refactoring based on this idea...
897 */
898         //ugh.
899         static LineOptions * toolWidget = NULL;
900
901         if (!optionWidget)
902                 return;
903
904         // Get rid of the LineOptions object if it exists...
905         if (toolWidget)
906         {
907                 delete toolWidget;
908                 toolWidget = NULL;
909         }
910
911         // Create a new one for the passed in action
912         if (on)
913         {
914                 toolWidget = new LineOptions(optionWidget);
915                 toolWidget->setAction(action);
916         }
917
918         RS_DEBUG->print("QG_DialogFactory::requestLineOptions: OK");
919 }
920
921 /**
922  * Shows a widget for options for the action: "draw polyline"
923  */
924 void QG_DialogFactory::requestPolylineOptions(RS_ActionInterface * action, bool on, bool update)
925 {
926 #ifdef RS_PROF
927         static QG_PolylineOptions * toolWidget = NULL;
928
929         if (optionWidget != NULL)
930         {
931                 if (toolWidget != NULL)
932                 {
933                         delete toolWidget;
934                         toolWidget = NULL;
935                 }
936                 if (on && toolWidget == NULL)
937                 {
938                         toolWidget = new QG_PolylineOptions(optionWidget);
939                         toolWidget->setAction(action, update);
940                 }
941         }
942 #endif
943 }
944
945 #if 0
946 /**
947  * Shows a widget for options for the action: "draw line parallel"
948  */
949 void QG_DialogFactory::requestLineParallelOptions(RS_ActionInterface * action, bool on, bool update)
950 {
951     static QG_LineParallelOptions* toolWidget = NULL;
952
953     if (optionWidget!=NULL) {
954         if (toolWidget!=NULL) {
955             delete toolWidget;
956             toolWidget = NULL;
957         }
958         if (on==true && toolWidget==NULL) {
959             toolWidget = new QG_LineParallelOptions(optionWidget);
960             toolWidget->setAction(action, update);
961         }
962     }
963 }
964
965 /**
966  * Shows a widget for options for the action: "draw line parallel through"
967  */
968 void QG_DialogFactory::requestLineParallelThroughOptions(RS_ActionInterface* action,
969     bool on, bool update)
970 {
971     static QG_LineParallelThroughOptions* toolWidget = NULL;
972
973     if (optionWidget!=NULL) {
974         if (toolWidget!=NULL) {
975             delete toolWidget;
976             toolWidget = NULL;
977         }
978         if (on==true && toolWidget==NULL) {
979             toolWidget = new QG_LineParallelThroughOptions(optionWidget);
980             toolWidget->setAction(action, update);
981         }
982     }
983 }
984
985 /**
986  * Shows a widget for options for the action: "line angle"
987  */
988 void QG_DialogFactory::requestLineAngleOptions(RS_ActionInterface* action,
989         bool on, bool update)
990 {
991     static QG_LineAngleOptions* toolWidget = NULL;
992
993     if (optionWidget!=NULL) {
994         if (toolWidget!=NULL) {
995             delete toolWidget;
996             toolWidget = NULL;
997         }
998         if (on==true && toolWidget==NULL) {
999             toolWidget = new QG_LineAngleOptions(optionWidget);
1000             toolWidget->setAction(action, update);
1001             //toolWidget->setData(&angle, &length, fixedAngle, update);
1002         }
1003     }
1004 }
1005
1006 /**
1007  * Shows a widget for options for the action: "line relative angle"
1008  */
1009 void QG_DialogFactory::requestLineRelAngleOptions(RS_ActionInterface* action,
1010         bool on, bool update)
1011 {
1012     static QG_LineRelAngleOptions* toolWidget = NULL;
1013
1014     if (optionWidget!=NULL) {
1015         if (toolWidget!=NULL) {
1016             delete toolWidget;
1017             toolWidget = NULL;
1018         }
1019         if (on==true && toolWidget==NULL) {
1020             toolWidget = new QG_LineRelAngleOptions(optionWidget);
1021             toolWidget->setAction(action, update);
1022             //toolWidget->setData(&angle, &length, fixedAngle, update);
1023         }
1024     }
1025 }
1026
1027 /**
1028  * Shows a widget for options for the action: "line angle"
1029  */
1030 void QG_DialogFactory::requestLineBisectorOptions(RS_ActionInterface* action,
1031         bool on, bool update)
1032 {
1033     static QG_LineBisectorOptions* toolWidget = NULL;
1034
1035     if (optionWidget!=NULL) {
1036         if (toolWidget!=NULL) {
1037             delete toolWidget;
1038             toolWidget = NULL;
1039         }
1040         if (on==true && toolWidget==NULL) {
1041             toolWidget = new QG_LineBisectorOptions(optionWidget);
1042             toolWidget->setAction(action, update);
1043         }
1044     }
1045 }
1046
1047 /**
1048  * Shows a widget for options for the action: "draw polygon"
1049  */
1050 void QG_DialogFactory::requestLinePolygonOptions(RS_ActionInterface* action,
1051         bool on, bool update)
1052 {
1053     static QG_LinePolygonOptions* toolWidget = NULL;
1054
1055     if (optionWidget!=NULL) {
1056         if (toolWidget!=NULL) {
1057             delete toolWidget;
1058             toolWidget = NULL;
1059         }
1060         if (on==true && toolWidget==NULL) {
1061             toolWidget = new QG_LinePolygonOptions(optionWidget);
1062             toolWidget->setAction(action, update);
1063         }
1064     }
1065 }
1066
1067 /**
1068  * Shows a widget for options for the action: "draw polygon2"
1069  */
1070 void QG_DialogFactory::requestLinePolygon2Options(RS_ActionInterface* action,
1071         bool on, bool update)
1072 {
1073     static QG_LinePolygon2Options* toolWidget = NULL;
1074
1075     if (optionWidget!=NULL) {
1076         if (toolWidget!=NULL) {
1077             delete toolWidget;
1078             toolWidget = NULL;
1079         }
1080         if (on==true && toolWidget==NULL) {
1081             toolWidget = new QG_LinePolygon2Options(optionWidget);
1082             toolWidget->setAction(action, update);
1083         }
1084     }
1085 }
1086
1087 /**
1088  * Shows a widget for insert options.
1089  */
1090 void QG_DialogFactory::requestInsertOptions(RS_ActionInterface* action,
1091         bool on, bool update)
1092 {
1093     static QG_InsertOptions* toolWidget = NULL;
1094
1095     if (optionWidget!=NULL) {
1096         if (toolWidget!=NULL) {
1097             delete toolWidget;
1098             toolWidget = NULL;
1099         }
1100         if (on==true && toolWidget==NULL) {
1101             toolWidget = new QG_InsertOptions(optionWidget);
1102             toolWidget->setAction(action, update);
1103         }
1104     }
1105 }
1106
1107 /**
1108  * Shows a widget for image options.
1109  */
1110 void QG_DialogFactory::requestImageOptions(RS_ActionInterface* action,
1111         bool on, bool update)
1112 {
1113     static QG_ImageOptions* toolWidget = NULL;
1114
1115     if (optionWidget!=NULL) {
1116         if (toolWidget!=NULL) {
1117             delete toolWidget;
1118             toolWidget = NULL;
1119         }
1120         if (on==true && toolWidget==NULL) {
1121             toolWidget = new QG_ImageOptions(optionWidget);
1122             toolWidget->setAction(action, update);
1123         }
1124     }
1125 }
1126
1127 /**
1128  * Shows a widget for 'snap to a point with a given distance' options.
1129  */
1130 void QG_DialogFactory::requestSnapDistOptions(double& dist, bool on)
1131 {
1132     static QG_SnapDistOptions* toolWidget = NULL;
1133
1134     if (optionWidget!=NULL) {
1135         if (toolWidget!=NULL) {
1136             delete toolWidget;
1137             toolWidget = NULL;
1138         }
1139         if (on==true && toolWidget==NULL) {
1140             toolWidget = new QG_SnapDistOptions(optionWidget);
1141             toolWidget->setDist(&dist);
1142         }
1143     }
1144 }
1145
1146 /**
1147  * Shows a widget for 'snap to a point with a given distance' options.
1148  */
1149 void QG_DialogFactory::requestMoveRotateOptions(RS_ActionInterface* action,
1150         bool on, bool update)
1151 {
1152     static QG_MoveRotateOptions* toolWidget = NULL;
1153
1154     if (optionWidget!=NULL) {
1155         if (toolWidget!=NULL) {
1156             delete toolWidget;
1157             toolWidget = NULL;
1158         }
1159         if (on==true && toolWidget==NULL) {
1160             toolWidget = new QG_MoveRotateOptions(optionWidget);
1161             toolWidget->setAction(action, update);
1162         }
1163     }
1164 }
1165
1166 /**
1167  * Shows a widget for rounding options.
1168  */
1169 void QG_DialogFactory::requestRoundOptions(RS_ActionInterface* action,
1170         bool on, bool update)
1171 {
1172     static QG_RoundOptions* toolWidget = NULL;
1173
1174     if (optionWidget!=NULL) {
1175         if (toolWidget!=NULL) {
1176             delete toolWidget;
1177             toolWidget = NULL;
1178         }
1179         if (on==true && toolWidget==NULL) {
1180             toolWidget = new QG_RoundOptions(optionWidget);
1181             toolWidget->setAction(action, update);
1182         }
1183     }
1184 }
1185
1186 /**
1187  * Shows a widget for library insert options.
1188  */
1189 void QG_DialogFactory::requestLibraryInsertOptions(RS_ActionInterface* action,
1190         bool on, bool update)
1191 {
1192     static QG_LibraryInsertOptions* toolWidget = NULL;
1193
1194     if (optionWidget!=NULL) {
1195         if (toolWidget!=NULL) {
1196             delete toolWidget;
1197             toolWidget = NULL;
1198         }
1199         if (on==true && toolWidget==NULL) {
1200             toolWidget = new QG_LibraryInsertOptions(optionWidget);
1201             toolWidget->setAction(action, update);
1202         }
1203     }
1204 }
1205 #else
1206 void QG_DialogFactory::requestLineParallelOptions(RS_ActionInterface * action, bool on, bool update)
1207 {
1208 }
1209
1210 void QG_DialogFactory::requestLineParallelThroughOptions(RS_ActionInterface* action, bool on, bool update)
1211 {
1212 }
1213
1214 void QG_DialogFactory::requestLineAngleOptions(RS_ActionInterface* action, bool on, bool update)
1215 {
1216 }
1217
1218 void QG_DialogFactory::requestLineRelAngleOptions(RS_ActionInterface* action, bool on, bool update)
1219 {
1220 }
1221
1222 void QG_DialogFactory::requestLineBisectorOptions(RS_ActionInterface* action, bool on, bool update)
1223 {
1224 }
1225
1226 void QG_DialogFactory::requestLinePolygonOptions(RS_ActionInterface* action, bool on, bool update)
1227 {
1228 }
1229
1230 void QG_DialogFactory::requestLinePolygon2Options(RS_ActionInterface* action, bool on, bool update)
1231 {
1232 }
1233
1234 /**
1235  * Shows a widget for arc options.
1236  */
1237 void QG_DialogFactory::requestArcOptions(RS_ActionInterface * action, bool on, bool update)
1238 {
1239         static ArcOptions * toolWidget = NULL;
1240
1241         if (optionWidget != NULL)
1242         {
1243                 if (toolWidget != NULL)
1244                 {
1245                         delete toolWidget;
1246                         toolWidget = NULL;
1247                 }
1248
1249                 if (on && toolWidget == NULL)
1250                 {
1251                         toolWidget = new ArcOptions(optionWidget);
1252                         toolWidget->setAction(action, update);
1253                         //toolWidget->setData(&data);
1254                 }
1255         }
1256 }
1257
1258 /**
1259  * Shows a widget for tangential arc options.
1260  */
1261 void QG_DialogFactory::requestArcTangentialOptions(RS_ActionInterface * action, bool on, bool update)
1262 {
1263         static ArcTangentialOptions * toolWidget = NULL;
1264
1265         if (!optionWidget)
1266                 return;
1267
1268         if (toolWidget)
1269         {
1270                 delete toolWidget;
1271                 toolWidget = NULL;
1272         }
1273
1274         if (on)
1275         {
1276                 toolWidget = new ArcTangentialOptions(optionWidget);
1277                 toolWidget->setAction(action, update);
1278                 //toolWidget->setData(&data);
1279         }
1280 }
1281
1282 /**
1283  * Shows a widget for circle options.
1284  */
1285 void QG_DialogFactory::requestCircleOptions(RS_ActionInterface * action, bool on, bool update)
1286 {
1287     static CircleOptions * toolWidget = NULL;
1288
1289     if (optionWidget)
1290         {
1291         if (toolWidget)
1292                 {
1293             delete toolWidget;
1294             toolWidget = NULL;
1295         }
1296
1297         if (on && toolWidget == NULL)
1298                 {
1299             toolWidget = new CircleOptions(optionWidget);
1300             toolWidget->setAction(action, update);
1301         }
1302     }
1303 }
1304
1305 /**
1306  * Shows a widget for spline options.
1307  */
1308 void QG_DialogFactory::requestSplineOptions(RS_ActionInterface * action, bool on, bool update)
1309 {
1310         static SplineOptions * toolWidget = NULL;
1311
1312         if (optionWidget!=NULL) {
1313                 if (toolWidget!=NULL) {
1314                         delete toolWidget;
1315                         toolWidget = NULL;
1316                 }
1317                 if (on==true && toolWidget==NULL) {
1318                         toolWidget = new SplineOptions(optionWidget);
1319                         toolWidget->setAction(action, update);
1320                 }
1321         }
1322 }
1323
1324 /**
1325  * Shows a widget for text options.
1326  */
1327 void QG_DialogFactory::requestTextOptions(RS_ActionInterface * action, bool on, bool update)
1328 {
1329         static TextOptions * toolWidget = NULL;
1330
1331         if (!optionWidget)
1332                 return;
1333
1334         if (toolWidget)
1335         {
1336                 delete toolWidget;
1337                 toolWidget = NULL;
1338         }
1339
1340         if (on)
1341         {
1342                 toolWidget = new TextOptions(optionWidget);
1343                 toolWidget->setAction(action, update);
1344         }
1345 }
1346
1347 void QG_DialogFactory::requestInsertOptions(RS_ActionInterface* action, bool on, bool update)
1348 {
1349 }
1350
1351 void QG_DialogFactory::requestImageOptions(RS_ActionInterface* action, bool on, bool update)
1352 {
1353 }
1354
1355 /**
1356  * Shows a widget for dimension options.
1357  */
1358 void QG_DialogFactory::requestDimensionOptions(RS_ActionInterface * action, bool on, bool update)
1359 {
1360     static DimOptions * toolWidget = NULL;
1361
1362     if (optionWidget!=NULL) {
1363         if (toolWidget!=NULL) {
1364             delete toolWidget;
1365             toolWidget = NULL;
1366         }
1367         if (on==true && toolWidget==NULL) {
1368             toolWidget = new DimOptions(optionWidget);
1369             toolWidget->setAction(action, update);
1370         }
1371     }
1372 }
1373
1374 /**
1375  * Shows a widget for linear dimension options.
1376  */
1377 void QG_DialogFactory::requestDimLinearOptions(RS_ActionInterface * action, bool on, bool update)
1378 {
1379         static DimLinearOptions * toolWidget = NULL;
1380
1381         if (!optionWidget)
1382                 return;
1383
1384         if (toolWidget)
1385         {
1386                 delete toolWidget;
1387                 toolWidget = NULL;
1388         }
1389
1390         if (on)
1391         {
1392                 toolWidget = new DimLinearOptions(optionWidget);
1393                 toolWidget->setAction(action, update);
1394         }
1395 }
1396
1397 void QG_DialogFactory::requestSnapDistOptions(double& dist, bool on)
1398 {
1399 }
1400
1401 void QG_DialogFactory::requestMoveRotateOptions(RS_ActionInterface* action, bool on, bool update)
1402 {
1403 }
1404
1405 /**
1406  * Shows a widget for 'trim amount' options.
1407  */
1408 void QG_DialogFactory::requestTrimAmountOptions(RS_ActionInterface * action, bool on, bool update)
1409 {
1410         static TrimAmountOptions * toolWidget = NULL;
1411
1412         if (!optionWidget)
1413                 return;
1414
1415         if (toolWidget)
1416         {
1417                 delete toolWidget;
1418                 toolWidget = NULL;
1419         }
1420
1421         if (on)
1422         {
1423                 toolWidget = new TrimAmountOptions(optionWidget);
1424                 toolWidget->setAction(action, update);
1425         }
1426 }
1427
1428 /**
1429  * Shows a widget for beveling options.
1430  */
1431 void QG_DialogFactory::requestBevelOptions(RS_ActionInterface * action, bool on, bool update)
1432 {
1433     static BevelOptions * toolWidget = NULL;
1434
1435     if (optionWidget != NULL)
1436         {
1437         if (toolWidget != NULL)
1438                 {
1439             delete toolWidget;
1440             toolWidget = NULL;
1441         }
1442
1443                 if (on && toolWidget == NULL)
1444                 {
1445             toolWidget = new BevelOptions(optionWidget);
1446             toolWidget->setAction(action, update);
1447         }
1448     }
1449 }
1450
1451 void QG_DialogFactory::requestRoundOptions(RS_ActionInterface* action, bool on, bool update)
1452 {
1453 }
1454
1455 void QG_DialogFactory::requestLibraryInsertOptions(RS_ActionInterface* action, bool on, bool update)
1456 {
1457 }
1458 #endif
1459
1460 /**
1461  * Shows the given toolbar.
1462  */
1463 void QG_DialogFactory::requestToolBar(RS2::ToolBarId id)
1464 {
1465         if (cadToolBar != NULL)
1466                 cadToolBar->showToolBar(id);
1467 }
1468
1469 /**
1470  * Shows the select toolbar with the given action to launch.
1471  */
1472 void QG_DialogFactory::requestToolBarSelect(RS_ActionInterface * selectAction,
1473         RS2::ActionType nextAction)
1474 {
1475         if (cadToolBar != NULL)
1476                 cadToolBar->showToolBarSelect(selectAction, nextAction);
1477 }
1478
1479 #if 0
1480 /**
1481  * Shows move options dialog presenting the given data.
1482  */
1483 bool QG_DialogFactory::requestMoveDialog(RS_MoveData & data)
1484 {
1485         QG_DlgMove dlg(parent);
1486         dlg.setData(&data);
1487
1488         if (dlg.exec())
1489         {
1490                 dlg.updateData();
1491                 return true;
1492         }
1493
1494         return false;
1495 }
1496
1497 /**
1498  * Shows rotate options dialog presenting the given data.
1499  */
1500 bool QG_DialogFactory::requestRotateDialog(RS_RotateData & data)
1501 {
1502         QG_DlgRotate dlg(parent);
1503         dlg.setData(&data);
1504
1505         if (dlg.exec())
1506         {
1507                 dlg.updateData();
1508                 return true;
1509         }
1510
1511         return false;
1512 }
1513
1514 /**
1515  * Shows scale options dialog presenting the given data.
1516  */
1517 bool QG_DialogFactory::requestScaleDialog(RS_ScaleData & data)
1518 {
1519         QG_DlgScale dlg(parent);
1520         dlg.setData(&data);
1521
1522         if (dlg.exec())
1523         {
1524                 dlg.updateData();
1525                 return true;
1526         }
1527
1528         return false;
1529 }
1530
1531 /**
1532  * Shows mirror options dialog presenting the given data.
1533  */
1534 bool QG_DialogFactory::requestMirrorDialog(RS_MirrorData & data)
1535 {
1536         QG_DlgMirror dlg(parent);
1537         dlg.setData(&data);
1538
1539         if (dlg.exec())
1540         {
1541                 dlg.updateData();
1542                 return true;
1543         }
1544
1545         return false;
1546 }
1547
1548 /**
1549  * Shows move/rotate options dialog presenting the given data.
1550  */
1551 bool QG_DialogFactory::requestMoveRotateDialog(RS_MoveRotateData & data)
1552 {
1553         QG_DlgMoveRotate dlg(parent);
1554         dlg.setData(&data);
1555
1556         if (dlg.exec())
1557         {
1558                 dlg.updateData();
1559                 return true;
1560         }
1561
1562         return false;
1563 }
1564
1565 /**
1566  * Shows rotate around two centers options dialog presenting the given data.
1567  */
1568 bool QG_DialogFactory::requestRotate2Dialog(RS_Rotate2Data & data)
1569 {
1570         QG_DlgRotate2 dlg(parent);
1571         dlg.setData(&data);
1572
1573         if (dlg.exec())
1574         {
1575                 dlg.updateData();
1576                 return true;
1577         }
1578
1579         return false;
1580 }
1581
1582 /**
1583  * Shows a dialog to edit the given entity.
1584  */
1585 bool QG_DialogFactory::requestModifyEntityDialog(RS_Entity * entity)
1586 {
1587         if (entity == NULL)
1588                 return false;
1589
1590         bool ret = false;
1591
1592         switch (entity->rtti())
1593         {
1594         case RS2::EntityPoint:
1595         {
1596                 QG_DlgPoint dlg(parent);
1597                 dlg.setPoint(*((RS_Point *)entity));
1598
1599                 if (dlg.exec())
1600                 {
1601                         dlg.updatePoint();
1602                         ret = true;
1603                 }
1604         }
1605                 break;
1606
1607         case RS2::EntityLine:
1608         {
1609                 QG_DlgLine dlg(parent);
1610                 dlg.setLine(*((RS_Line *)entity));
1611
1612                 if (dlg.exec())
1613                 {
1614                         dlg.updateLine();
1615                         ret = true;
1616                 }
1617         }
1618                 break;
1619
1620         case RS2::EntityArc:
1621         {
1622                 QG_DlgArc dlg(parent);
1623                 dlg.setArc(*((RS_Arc *)entity));
1624
1625                 if (dlg.exec())
1626                 {
1627                         dlg.updateArc();
1628                         ret = true;
1629                 }
1630         }
1631                 break;
1632
1633         case RS2::EntityCircle:
1634         {
1635                 QG_DlgCircle dlg(parent);
1636                 dlg.setCircle(*((RS_Circle *)entity));
1637
1638                 if (dlg.exec())
1639                 {
1640                         dlg.updateCircle();
1641                         ret = true;
1642                 }
1643         }
1644                 break;
1645
1646         case RS2::EntityEllipse:
1647         {
1648                 QG_DlgEllipse dlg(parent);
1649                 dlg.setEllipse(*((RS_Ellipse *)entity));
1650
1651                 if (dlg.exec())
1652                 {
1653                         dlg.updateEllipse();
1654                         ret = true;
1655                 }
1656         }
1657                 break;
1658
1659         case RS2::EntitySpline:
1660         {
1661                 QG_DlgSpline dlg(parent);
1662                 dlg.setSpline(*((RS_Spline *)entity));
1663
1664                 if (dlg.exec())
1665                 {
1666                         dlg.updateSpline();
1667                         ret = true;
1668                 }
1669         }
1670                 break;
1671
1672         case RS2::EntityInsert:
1673         {
1674                 QG_DlgInsert dlg(parent);
1675                 dlg.setInsert(*((RS_Insert *)entity));
1676
1677                 if (dlg.exec())
1678                 {
1679                         dlg.updateInsert();
1680                         ret = true;
1681                         entity->update();
1682                 }
1683         }
1684                 break;
1685
1686         case RS2::EntityDimAligned:
1687         case RS2::EntityDimAngular:
1688         case RS2::EntityDimDiametric:
1689         case RS2::EntityDimRadial:
1690         {
1691                 QG_DlgDimension dlg(parent);
1692                 dlg.setDim(*((RS_Dimension *)entity));
1693
1694                 if (dlg.exec())
1695                 {
1696                         dlg.updateDim();
1697                         ret = true;
1698                         ((RS_Dimension *)entity)->update(true);
1699                 }
1700         }
1701                 break;
1702
1703         case RS2::EntityDimLinear:
1704         {
1705                 QG_DlgDimLinear dlg(parent);
1706                 dlg.setDim(*((RS_DimLinear *)entity));
1707
1708                 if (dlg.exec())
1709                 {
1710                         dlg.updateDim();
1711                         ret = true;
1712                         ((RS_DimLinear *)entity)->update(true);
1713                 }
1714         }
1715                 break;
1716
1717         case RS2::EntityText:
1718         {
1719                 QG_DlgText dlg(parent);
1720                 dlg.setText(*((RS_Text *)entity), false);
1721
1722                 if (dlg.exec())
1723                 {
1724                         dlg.updateText();
1725                         ret = true;
1726                         ((RS_Text *)entity)->update();
1727                 }
1728         }
1729                 break;
1730
1731         case RS2::EntityHatch:
1732         {
1733                 QG_DlgHatch dlg(parent);
1734                 dlg.setHatch(*((RS_Hatch *)entity), false);
1735
1736                 if (dlg.exec())
1737                 {
1738                         dlg.updateHatch();
1739                         ret = true;
1740                         ((RS_Hatch *)entity)->update();
1741                 }
1742         }
1743                 break;
1744
1745         default:
1746                 break;
1747         }
1748
1749         return ret;
1750 }
1751
1752 /**
1753  * Shows a dialog to edit the attributes of the given dimension entity.
1754  */
1755  /*
1756 bool QG_DialogFactory::requestDimAlignedDialog(RS_DimAligned* dim) {
1757     if (dim==NULL) {
1758         return false;
1759     }
1760
1761     QG_DlgDimAligned dlg(parent);
1762     dlg.setDim(*dim, true);
1763     if (dlg.exec()) {
1764         dlg.updateDim();
1765         return true;
1766     }
1767
1768     return false;
1769 }
1770 */
1771
1772 /**
1773  * Shows a dialog to edit the attributes of the given text entity.
1774  */
1775 bool QG_DialogFactory::requestTextDialog(RS_Text * text)
1776 {
1777         if (text == NULL)
1778                 return false;
1779
1780         QG_DlgText dlg(parent);
1781         dlg.setText(*text, true);
1782
1783         if (dlg.exec())
1784         {
1785                 dlg.updateText();
1786                 return true;
1787         }
1788
1789         return false;
1790 }
1791
1792 /**
1793  * Shows a dialog to edit pattern / hatch attributes of the given entity.
1794  */
1795 bool QG_DialogFactory::requestHatchDialog(RS_Hatch * hatch)
1796 {
1797         if (hatch == NULL)
1798                 return false;
1799
1800         RS_PATTERNLIST->init();
1801
1802         QG_DlgHatch dlg(parent);
1803         dlg.setHatch(*hatch, true);
1804
1805         if (dlg.exec())
1806         {
1807                 dlg.updateHatch();
1808                 return true;
1809         }
1810
1811         return false;
1812 }
1813 #else
1814 /**
1815  * Shows attributes options dialog presenting the given data.
1816  */
1817 bool QG_DialogFactory::requestAttributesDialog(RS_AttributesData & data, RS_LayerList & layerList)
1818 {
1819         DlgAttributes dlg(parent);
1820         dlg.setData(&data, layerList);
1821
1822         if (dlg.exec())
1823         {
1824                 dlg.updateData();
1825                 return true;
1826         }
1827
1828         return false;
1829 }
1830
1831 bool QG_DialogFactory::requestMoveDialog(RS_MoveData & data)
1832 {
1833         return false;
1834 }
1835
1836 bool QG_DialogFactory::requestRotateDialog(RS_RotateData & data)
1837 {
1838         return false;
1839 }
1840
1841 bool QG_DialogFactory::requestScaleDialog(RS_ScaleData & data)
1842 {
1843         return false;
1844 }
1845
1846 bool QG_DialogFactory::requestMirrorDialog(RS_MirrorData & data)
1847 {
1848         return false;
1849 }
1850
1851 bool QG_DialogFactory::requestMoveRotateDialog(RS_MoveRotateData & data)
1852 {
1853         return false;
1854 }
1855
1856 bool QG_DialogFactory::requestRotate2Dialog(RS_Rotate2Data & data)
1857 {
1858         return false;
1859 }
1860
1861 /**
1862  * Shows a dialog to edit the given entity.
1863  */
1864 bool QG_DialogFactory::requestModifyEntityDialog(RS_Entity * entity)
1865 {
1866         if (entity == NULL)
1867                 return false;
1868
1869         bool ret = false;
1870
1871         switch (entity->rtti())
1872         {
1873 //NOTE: These #if 0's are put here until these missing dialogs can be ported to Qt4.
1874 #if 0
1875         case RS2::EntityPoint:
1876         {
1877                 QG_DlgPoint dlg(parent);
1878                 dlg.setPoint(*((RS_Point *)entity));
1879
1880                 if (dlg.exec())
1881                 {
1882                         dlg.updatePoint();
1883                         ret = true;
1884                 }
1885         }
1886                 break;
1887
1888         case RS2::EntityLine:
1889         {
1890                 QG_DlgLine dlg(parent);
1891                 dlg.setLine(*((RS_Line *)entity));
1892
1893                 if (dlg.exec())
1894                 {
1895                         dlg.updateLine();
1896                         ret = true;
1897                 }
1898         }
1899                 break;
1900
1901         case RS2::EntityArc:
1902         {
1903                 QG_DlgArc dlg(parent);
1904                 dlg.setArc(*((RS_Arc *)entity));
1905
1906                 if (dlg.exec())
1907                 {
1908                         dlg.updateArc();
1909                         ret = true;
1910                 }
1911         }
1912                 break;
1913
1914         case RS2::EntityCircle:
1915         {
1916                 QG_DlgCircle dlg(parent);
1917                 dlg.setCircle(*((RS_Circle *)entity));
1918
1919                 if (dlg.exec())
1920                 {
1921                         dlg.updateCircle();
1922                         ret = true;
1923                 }
1924         }
1925                 break;
1926
1927         case RS2::EntityEllipse:
1928         {
1929                 QG_DlgEllipse dlg(parent);
1930                 dlg.setEllipse(*((RS_Ellipse *)entity));
1931
1932                 if (dlg.exec())
1933                 {
1934                         dlg.updateEllipse();
1935                         ret = true;
1936                 }
1937         }
1938                 break;
1939
1940         case RS2::EntitySpline:
1941         {
1942                 QG_DlgSpline dlg(parent);
1943                 dlg.setSpline(*((RS_Spline *)entity));
1944
1945                 if (dlg.exec())
1946                 {
1947                         dlg.updateSpline();
1948                         ret = true;
1949                 }
1950         }
1951                 break;
1952
1953         case RS2::EntityInsert:
1954         {
1955                 QG_DlgInsert dlg(parent);
1956                 dlg.setInsert(*((RS_Insert *)entity));
1957
1958                 if (dlg.exec())
1959                 {
1960                         dlg.updateInsert();
1961                         ret = true;
1962                         entity->update();
1963                 }
1964         }
1965                 break;
1966
1967         case RS2::EntityDimAligned:
1968         case RS2::EntityDimAngular:
1969         case RS2::EntityDimDiametric:
1970         case RS2::EntityDimRadial:
1971         {
1972                 QG_DlgDimension dlg(parent);
1973                 dlg.setDim(*((RS_Dimension *)entity));
1974
1975                 if (dlg.exec())
1976                 {
1977                         dlg.updateDim();
1978                         ret = true;
1979                         ((RS_Dimension *)entity)->update(true);
1980                 }
1981         }
1982                 break;
1983
1984         case RS2::EntityDimLinear:
1985         {
1986                 QG_DlgDimLinear dlg(parent);
1987                 dlg.setDim(*((RS_DimLinear *)entity));
1988
1989                 if (dlg.exec())
1990                 {
1991                         dlg.updateDim();
1992                         ret = true;
1993                         ((RS_DimLinear *)entity)->update(true);
1994                 }
1995         }
1996                 break;
1997 #endif
1998
1999         case RS2::EntityText:
2000         {
2001                 DlgText dlg(parent);
2002                 dlg.setText(*((RS_Text *)entity), false);
2003
2004                 if (dlg.exec())
2005                 {
2006                         dlg.updateText();
2007                         ret = true;
2008                         ((RS_Text *)entity)->update();
2009                 }
2010         }
2011                 break;
2012
2013 #if 0
2014         case RS2::EntityHatch:
2015         {
2016                 QG_DlgHatch dlg(parent);
2017                 dlg.setHatch(*((RS_Hatch *)entity), false);
2018
2019                 if (dlg.exec())
2020                 {
2021                         dlg.updateHatch();
2022                         ret = true;
2023                         ((RS_Hatch *)entity)->update();
2024                 }
2025         }
2026                 break;
2027 #endif
2028
2029         default:
2030                 break;
2031         }
2032
2033         return ret;
2034 }
2035
2036  /*
2037 bool QG_DialogFactory::requestDimAlignedDialog(RS_DimAligned* dim) {
2038     return false;
2039 }
2040 */
2041
2042 /**
2043  * Shows a dialog to edit the attributes of the given text entity.
2044  */
2045 bool QG_DialogFactory::requestTextDialog(RS_Text * text)
2046 {
2047         if (text == NULL)
2048                 return false;
2049
2050         DlgText dlg(parent);
2051         dlg.setText(*text, true);
2052
2053         if (dlg.exec())
2054         {
2055                 dlg.updateText();
2056                 return true;
2057         }
2058
2059         return false;
2060 }
2061
2062 bool QG_DialogFactory::requestHatchDialog(RS_Hatch * hatch)
2063 {
2064         return false;
2065 }
2066 #endif
2067
2068 #ifdef RS_CAM
2069 /**
2070  * Shows a dialog for CAM options.
2071  */
2072 bool QG_DialogFactory::requestCamOptionsDialog(Drawing& graphic)
2073 {
2074         RS_DEBUG->print("QG_DialogFactory::requestCamOptionsDialog");
2075         RS_CamDialog dlg(graphic, parent);
2076         RS_DEBUG->print("QG_DialogFactory::requestCamOptionsDialog: exec");
2077
2078         if (dlg.exec())
2079         {
2080                 RS_DEBUG->print("QG_DialogFactory::requestCamOptionsDialog: OK");
2081                 return true;
2082         }
2083
2084         RS_DEBUG->print("QG_DialogFactory::requestCamOptionsDialog: Cancel");
2085         return false;
2086 }
2087 #endif
2088
2089 /**
2090  * Shows dialog for general application options.
2091  */
2092 void QG_DialogFactory::requestOptionsGeneralDialog()
2093 {
2094         DlgOptionsGeneral dlg(parent);
2095         dlg.exec();
2096 }
2097
2098 /**
2099  * Shows dialog for drawing options.
2100  */
2101 void QG_DialogFactory::requestOptionsDrawingDialog(Drawing & graphic)
2102 {
2103         DlgOptionsDrawing dlg(parent);
2104         dlg.setGraphic(&graphic);
2105         dlg.exec();
2106 }
2107
2108 /**
2109  * Back to last menu in cad toolbar.
2110  */
2111 void QG_DialogFactory::requestPreviousMenu()
2112 {
2113         if (cadToolBar != NULL)
2114                 cadToolBar->showToolBarMain();
2115 }
2116
2117 /**
2118  * Called whenever the mouse position changed.
2119  */
2120 void QG_DialogFactory::updateCoordinateWidget(const Vector & abs,
2121         const Vector & rel, bool updateFormat)
2122 {
2123         if (coordinateWidget != NULL)
2124                 coordinateWidget->setCoordinates(abs, rel, updateFormat);
2125 }
2126
2127 /**
2128  * Called when an action has a mouse hint.
2129  */
2130 void QG_DialogFactory::updateMouseWidget(const QString & left, const QString & right)
2131 {
2132         if (mouseWidget != NULL)
2133                 mouseWidget->setHelp(left, right);
2134
2135         if (commandWidget != NULL)
2136                 commandWidget->setCommand(left);
2137 }
2138
2139 /**
2140  * Called whenever the selection changed.
2141  */
2142 void QG_DialogFactory::updateSelectionWidget(int num)
2143 {
2144         if (selectionWidget != NULL)
2145                 selectionWidget->setNumber(num);
2146 }
2147
2148 /**
2149  * Called when an action needs to communicate 'message' to the user.
2150  */
2151 void QG_DialogFactory::commandMessage(const QString& message)
2152 {
2153         RS_DEBUG->print("QG_DialogFactory::commandMessage");
2154
2155         if (commandWidget != NULL)
2156                 commandWidget->appendHistory(message);
2157
2158         RS_DEBUG->print("QG_DialogFactory::commandMessage: OK");
2159 }
2160
2161 /*virtual*/ bool QG_DialogFactory::isAdapter()
2162 {
2163         return false;
2164 }
2165
2166 /**
2167  * Converts an extension to a format description.
2168  * e.g. "PNG" to "Portable Network Graphic"
2169  *
2170  * @param Extension
2171  * @return Format description
2172  */
2173 QString QG_DialogFactory::extToFormat(const QString & ext)
2174 {
2175         QString e = ext.toLower();
2176
2177         if (e == "bmp")
2178                 return QObject::tr("Windows Bitmap");
2179         else if (e == "jpeg" || e == "jpg")
2180                 return QObject::tr("Joint Photographic Experts Group");
2181         else if (e == "gif")
2182                 return QObject::tr("Graphics Interchange Format");
2183         else if (e == "mng")
2184                 return QObject::tr("Multiple-image Network Graphics");
2185         else if (e == "pbm")
2186                 return QObject::tr("Portable Bit Map");
2187         else if (e == "pgm")
2188                 return QObject::tr("Portable Grey Map");
2189         else if (e == "png")
2190                 return QObject::tr("Portable Network Graphic");
2191         else if (e == "ppm")
2192                 return QObject::tr("Portable Pixel Map");
2193         else if (e == "xbm")
2194                 return QObject::tr("X Bitmap Format");
2195         else if (e == "xpm")
2196                 return QObject::tr("X Pixel Map");
2197         else
2198                 return ext.toUpper();
2199 }