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