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