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