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