]> Shamusworld >> Repos - architektonas/blob - src/widgets/qg_dialogfactory.cpp
b5093ceed36a5d899ca325a28969ffbe280762bb
[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 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
9 //
10 // JLH = James L. Hammons <jlhamm@acm.org>
11 //
12 // Who  When        What
13 // ---  ----------  -----------------------------------------------------------
14 // JLH  05/10/2010  Added this text. :-)
15 //
16
17 #include "qg_dialogfactory.h"
18
19 #include "graphicview.h"
20 #include "layerwidget.h"
21 #include "qg_mainwindowinterface.h"
22 #include "actiondimlinear.h"
23 #include "actioninterface.h"
24 #include "rs_blocklist.h"
25 #include "rs_document.h"
26 #include "rs_hatch.h"
27 #include "rs_layerlist.h"
28 #include "rs_patternlist.h"
29 #include "settings.h"
30 #include "rs_system.h"
31 #include "rs_text.h"
32
33 #include "arcoptions.h"
34 #include "arctangentialoptions.h"
35 #include "beveloptions.h"
36 #include "blockdialog.h"
37 #include "cadtoolbar.h"
38 #include "circleoptions.h"
39 #include "commandwidget.h"
40 #include "coordinatewidget.h"
41 #include "dimlinearoptions.h"
42 #include "dimoptions.h"
43 #include "dlgarc.h"
44 #include "dlgattributes.h"
45 #include "dlgcircle.h"
46 #include "dlgdimension.h"
47 #include "dlgdimlinear.h"
48 #include "dlgellipse.h"
49 #include "dlghatch.h"
50 #include "dlginsert.h"
51 #include "dlgline.h"
52 #include "dlgmirror.h"
53 #include "dlgmove.h"
54 #include "dlgmoverotate.h"
55 #include "dlgoptionsdrawing.h"
56 #include "dlgoptionsgeneral.h"
57 #include "dlgpoint.h"
58 #include "dlgrotate.h"
59 #include "dlgrotate2.h"
60 #include "dlgscale.h"
61 #include "dlgspline.h"
62 #include "dlgtext.h"
63 #include "libraryinsertoptions.h"
64 #include "imageoptions.h"
65 #include "insertoptions.h"
66 #include "layerdialog.h"
67 #include "lineangleoptions.h"
68 #include "linebisectoroptions.h"
69 #include "lineoptions.h"
70 #include "lineparalleloptions.h"
71 #include "lineparallelthroughoptions.h"
72 #include "linepolygon2options.h"
73 #include "linepolygonoptions.h"
74 #include "linerelangleoptions.h"
75 #include "mousewidget.h"
76 #include "moverotateoptions.h"
77 #include "printpreviewoptions.h"
78 #include "roundoptions.h"
79 #include "selectionwidget.h"
80 #include "snapdistoptions.h"
81 #include "splineoptions.h"
82 #include "textoptions.h"
83 #include "trimamountoptions.h"
84
85 #ifdef RS_PROF
86 #include "qg_polylineoptions.h"
87 #endif
88
89 #ifdef RS_CAM
90 #include "rs_camdialog.h"
91 #endif
92
93 //QG_DialogFactory* QG_DialogFactory::uniqueInstance = NULL;
94
95 /**
96  * Constructor.
97  *
98  * @param parent Pointer to parent widget which can host dialogs.
99  * @param ow Pointer to widget that can host option widgets.
100  */
101 //QG_DialogFactory::QG_DialogFactory(QWidget * parent, QWidget * ow):
102 QG_DialogFactory::QG_DialogFactory(QWidget * parent, QToolBar * ow):
103         RS_DialogFactoryInterface()
104 {
105         RS_DEBUG->print("QG_DialogFactory::QG_DialogFactory");
106
107         this->parent = parent;
108         setOptionWidget(ow);
109
110         coordinateWidget = NULL;
111         mouseWidget = NULL;
112         selectionWidget = NULL;
113         cadToolBar = NULL;
114         commandWidget = NULL;
115         mainWindow = NULL;
116         RS_DEBUG->print("QG_DialogFactory::QG_DialogFactory: OK");
117 }
118
119 /**
120  * Destructor
121  */
122 QG_DialogFactory::~QG_DialogFactory()
123 {
124         RS_DEBUG->print("QG_DialogFactory::~QG_DialogFactory");
125         RS_DEBUG->print("QG_DialogFactory::~QG_DialogFactory: OK");
126 }
127
128 /**
129  * Links factory to a widget that can host tool options.
130  */
131 ///*virtual*/ void QG_DialogFactory::setOptionWidget(QWidget * ow)
132 /*virtual*/ void QG_DialogFactory::setOptionWidget(QToolBar * ow)
133 {
134         RS_DEBUG->print("QG_DialogFactory::setOptionWidget");
135         optionWidget = ow;
136         RS_DEBUG->print("QG_DialogFactory::setOptionWidget: OK");
137 }
138
139 /**
140  * Links this dialog factory to a coordinate widget.
141  */
142 /*virtual*/ void QG_DialogFactory::setCoordinateWidget(CoordinateWidget * cw)
143 {
144         coordinateWidget = cw;
145 }
146
147 /**
148  * Links this dialog factory to a mouse widget.
149  */
150 /*virtual*/ void QG_DialogFactory::setMouseWidget(MouseWidget * mw)
151 {
152         mouseWidget = mw;
153 }
154
155 /**
156  * Links this dialog factory to a selection widget.
157  */
158 /*virtual*/ void QG_DialogFactory::setSelectionWidget(SelectionWidget * sw)
159 {
160         selectionWidget = sw;
161 }
162
163 /**
164  * Links this dialog factory to the cad tool bar.
165  */
166 /*virtual*/ void QG_DialogFactory::setCadToolBar(CadToolBar * ctb)
167 {
168         cadToolBar = ctb;
169 }
170
171 /**
172  * @return cad tool bar or NULL.
173  */
174 CadToolBar * QG_DialogFactory::getCadToolBar()
175 {
176         return cadToolBar;
177 }
178
179 /**
180  * Links this dialog factory to a command widget.
181  */
182 /*virtual*/ void QG_DialogFactory::setCommandWidget(CommandWidget * cw)
183 {
184         commandWidget = cw;
185 }
186
187 /**
188  * @return command widget or NULL.
189  */
190 CommandWidget * QG_DialogFactory::getCommandWidget()
191 {
192         return commandWidget;
193 }
194
195 /**
196  * Links the dialog factory to a main app window.
197  */
198 /*virtual*/ void QG_DialogFactory::setMainWindow(QG_MainWindowInterface * mw)
199 {
200         mainWindow = mw;
201 }
202
203 /**
204  * Shows a message dialog.
205  */
206 void QG_DialogFactory::requestWarningDialog(const QString & warning)
207 {
208         QMessageBox::information(parent, QMessageBox::tr("Warning"),
209                 warning, QMessageBox::Ok);
210 }
211
212 /**
213  * Requests a new document from the main window.
214  */
215 GraphicView * QG_DialogFactory::requestNewDocument(const QString & fileName, RS_Document * doc)
216 {
217         if (mainWindow != NULL)
218         {
219                 mainWindow->createNewDocument(fileName, doc);
220                 return mainWindow->getGraphicView();
221         }
222
223         return NULL;
224 }
225
226 /**
227  * Requests the simulation controls.
228  */
229 void QG_DialogFactory::requestSimulationControls()
230 {
231         if (mainWindow != NULL)
232         {
233                 mainWindow->showSimulationControls();
234         }
235 }
236
237 /**
238  * Shows a dialog for adding a layer. Doesn't add the layer.
239  * This is up to the caller.
240  *
241  * @return a pointer to the newly created layer that
242  * should be added.
243  */
244 RS_Layer * QG_DialogFactory::requestNewLayerDialog(RS_LayerList * layerList)
245 {
246         RS_Layer * layer = NULL;
247         QString layer_name = "noname";
248         int i = 2;
249
250         if (layerList != NULL)
251         {
252                 while (layerList->find(layer_name) > 0)
253                         layer_name.sprintf("noname%d", i++);
254         }
255
256         // Layer for parameter livery
257         layer = new RS_Layer(layer_name);
258
259 //      QG_LayerDialog dlg(parent, "Layer Dialog");
260         LayerDialog dlg(parent);
261         dlg.setLayer(layer);
262         dlg.setLayerList(layerList);
263
264         if (dlg.exec())
265                 dlg.updateLayer();
266         else
267         {
268                 delete layer;
269                 layer = NULL;
270         }
271
272         return layer;
273 }
274
275 /**
276  * Shows a dialog that asks the user if the selected layer
277  * can be removed. Doesn't remove the layer. This is up to the caller.
278  *
279  * @return a pointer to the layer that should be removed.
280  */
281 RS_Layer * QG_DialogFactory::requestLayerRemovalDialog(RS_LayerList * layerList)
282 {
283     RS_Layer * layer = NULL;
284
285         if (layerList == NULL)
286         {
287         RS_DEBUG->print(RS_Debug::D_WARNING,
288                 "QG_DialogFactory::requestLayerRemovalDialog(): layerList is NULL");
289
290         return NULL;
291     }
292     /*
293        if (layerList==NULL) {
294            if (container!=NULL && container->rtti()==RS2::EntityGraphic) {
295                layerList = (RS_LayerList*)container;
296            } else {
297                return NULL;
298            }
299        }*/
300
301         // Layer for parameter livery
302         layer = layerList->getActive();
303
304         if (layer != NULL)
305         {
306                 if (layer->getName() != "0")
307                 {
308                         int remove = QMessageBox::information(parent, QMessageBox::tr("Remove Layer"),
309                                 QMessageBox::tr("Layer \"%1\" and all entities on it will be removed.").arg(layer->getName()),
310                                 QMessageBox::Ok, QMessageBox::Cancel);
311
312                         if (remove == 1)
313                         {
314                         }
315                         else
316                         {
317                                 layer = NULL;
318                         }
319                 }
320                 else
321                 {
322                         QMessageBox::information(parent, QMessageBox::tr("Remove Layer"),
323                                 QMessageBox::tr("Layer \"%1\" can never be removed.").arg(layer->getName()),
324                                 QMessageBox::Ok);
325                 }
326         }
327
328         return layer;
329 }
330
331 /**
332  * Shows a dialog for editing a layer. A new layer is created and
333  * returned. Modifying the layer is up to the caller.
334  *
335  * @return A pointer to a new layer with the changed attributes
336  *         or NULL if the dialog was cancelled.
337  */
338 RS_Layer * QG_DialogFactory::requestEditLayerDialog(RS_LayerList * layerList)
339 {
340         RS_DEBUG->print("QG_DialogFactory::requestEditLayerDialog");
341         RS_Layer * layer = NULL;
342
343         if (!layerList)
344         {
345                 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestEditLayerDialog(): "
346                         "layerList is NULL");
347                 return NULL;
348         }
349
350         // Layer for parameter livery
351         if (layerList->getActive())
352         {
353                 layer = new RS_Layer(*layerList->getActive());
354
355 //        QG_LayerDialog dlg(parent, QMessageBox::tr("Layer Dialog"));
356                 LayerDialog dlg(parent);
357                 dlg.setLayer(layer);
358                 dlg.setLayerList(layerList);
359                 dlg.setEditLayer(true);
360
361                 if (dlg.exec())
362                         dlg.updateLayer();
363                 else
364                 {
365                         delete layer;
366                         layer = NULL;
367                 }
368         }
369
370         return layer;
371 }
372
373 /**
374  * Shows a dialog for adding a block. Doesn't add the block.
375  * This is up to the caller.
376  *
377  * @return a pointer to the newly created block that
378  * should be added.
379  */
380 RS_BlockData QG_DialogFactory::requestNewBlockDialog(RS_BlockList * blockList)
381 {
382         //RS_Block* block = NULL;
383         RS_BlockData ret;
384         ret = RS_BlockData("", Vector(false), false);
385
386         if (blockList == NULL)
387         {
388                 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestNewBlockDialog(): "
389                         "blockList is NULL");
390                 return ret;
391         }
392
393         // Block for parameter livery
394         //block = new RS_Block(container, "noname", Vector(0.0,0.0));
395
396         BlockDialog dlg(parent);
397         dlg.setBlockList(blockList);
398
399         if (dlg.exec())
400                 ret = dlg.getBlockData();
401
402         return ret;
403 }
404
405 /**
406  * Shows a dialog for renaming the currently active block.
407  *
408  * @return a pointer to the modified block or NULL on cancellation.
409  */
410 RS_BlockData QG_DialogFactory::requestBlockAttributesDialog(RS_BlockList * blockList)
411 {
412         //RS_Block* block = NULL;
413         RS_BlockData ret;
414         ret = RS_BlockData("", Vector(false), false);
415
416         if (blockList == NULL)
417         {
418                 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestBlockAttributesDialog(): "
419                         "blockList is NULL");
420                 return ret;
421         }
422         /*
423                 if (blockList==NULL) {
424                         if (container!=NULL && container->rtti()==RS2::EntityGraphic) {
425                                 blockList = (RS_BlockList*)container;
426                         } else {
427                                 return NULL;
428                         }
429                 }*/
430
431         // Block for parameter livery
432         //block = blockList->getActive();
433
434         BlockDialog dlg(parent);//WAS:, "Rename Block");
435 #warning "!!! WTF !!! WHY DO WE HAVE TO PREFIX tr WITH QObject:: ???"
436         dlg.setWindowTitle(QObject::tr("Rename Block"));
437         dlg.setBlockList(blockList);
438
439         if (dlg.exec())
440         {
441                 //dlg.updateBlock();
442                 //block->setData();
443                 ret = dlg.getBlockData();
444         }
445         //else {
446         //      ret = RS_BlockData("", Vector(false));
447         //}
448
449         return ret;
450 }
451
452 /*virtual*/ void QG_DialogFactory::requestEditBlockWindow(RS_BlockList * /*blockList*/)
453 {
454 }
455
456 /*virtual*/ void QG_DialogFactory::closeEditBlockWindow(RS_Block * /*blockList*/)
457 {
458 }
459
460 /**
461  * Shows a dialog that asks the user if the selected block
462  * can be removed. Doesn't remove the block. This is up to the caller.
463  *
464  * @return a pointer to the block that should be removed.
465  */
466 RS_Block * QG_DialogFactory::requestBlockRemovalDialog(RS_BlockList * blockList)
467 {
468         RS_Block * block = NULL;
469
470         if (blockList == NULL)
471         {
472                 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestBlockRemovalDialog(): "
473                         "blockList is NULL");
474                 return NULL;
475         }
476
477         // Block for parameter livery
478         block = blockList->getActive();
479
480         if (block != NULL)
481         {
482                 int remove = QMessageBox::information(parent, QMessageBox::tr("Remove Block"),
483                         QMessageBox::tr("Block \"%1\" and all its entities will be removed.").arg(block->getName()),
484                         QMessageBox::Ok, QMessageBox::Cancel);
485
486                 if (remove == 1)
487                 {
488                 }
489                 else
490                 {
491                         block = NULL;
492                 }
493         }
494
495         return block;
496 }
497
498 /**
499  * Shows a dialog for choosing a file name. Saving the file is up to
500  * the caller.
501  *
502  * @return File name with path and extension to determine the file type
503  *         or an empty string if the dialog was cancelled.
504  */
505 /*
506 QString QG_DialogFactory::requestFileSaveAsDialog() {
507     // read default settings:
508     RS_SETTINGS->beginGroup("/Paths");
509     QString defDir = RS_SETTINGS->readEntry("/Save",
510                        RS_SYSTEM->getHomeDir());
511     QString defFilter = RS_SETTINGS->readEntry("/SaveFilter",
512                           "Drawing Exchange (*.dxf)");
513     RS_SETTINGS->endGroup();
514
515     // prepare file save as dialog:
516     QFileDialog fileDlg(this,0,true);
517     QStringList filters;
518     bool done = false;
519     bool cancel = false;
520     QString fn = "";
521
522     filters.append("Drawing Exchange (*.dxf)");
523     filters.append("Font (*.cxf)");
524     fileDlg.setFilters(filters);
525     fileDlg.setMode(QFileDialog::AnyFile);
526     fileDlg.setCaption(tr("Save Drawing As"));
527     fileDlg.setDir(defDir);
528     fileDlg.setSelectedFilter(defFilter);
529
530     // run dialog:
531     do {
532         // accepted:
533         if (fileDlg.exec()==QDialog::Accepted) {
534                 fn = fileDlg.selectedFile();
535                         cancel = false;
536
537             // append default extension:
538             if (fn.find('.')==-1) {
539                 if (fileDlg.selectedFilter()=="Font (*.cxf)") {
540                     fn+=".cxf";
541                 } else {
542                     fn+=".dxf";
543                 }
544             }
545
546             // overwrite warning:
547             if(QFileInfo(fn).exists()) {
548                 int choice =
549                     QMessageBox::warning(this, tr("Save Drawing As"),
550                                          tr("%1 already exists.\n"
551                                             "Do you want to replace it?")
552                                          .arg(fn),
553                                          tr("Yes"), tr("No"),
554                                          tr("Cancel"), 0, 1 );
555
556                 switch (choice) {
557                 case 0:
558                     done = true;
559                     break;
560                 case 1:
561                 case 2:
562                 default:
563                     done = false;
564                     break;
565                 }
566             } else {
567                 done = true;
568             }
569         }
570                 else {
571             done = true;
572             cancel = true;
573                         fn = "";
574         }
575     } while(!done);
576
577     // store new default settings:
578     if (!cancel) {
579         RS_SETTINGS->beginGroup("/Paths");
580         RS_SETTINGS->writeEntry("/Save", QFileInfo(fn).dirPath(true));
581         RS_SETTINGS->writeEntry("/SaveFilter", fileDlg.selectedFilter());
582         RS_SETTINGS->endGroup();
583     }
584
585     return fn;
586 }
587 */
588
589 /**
590  * Shows a dialog for choosing a file name. Opening the file is up to
591  * the caller.
592  *
593  * @return File name with path and extension to determine the file type
594  *         or an empty string if the dialog was cancelled.
595  */
596 QString QG_DialogFactory::requestImageOpenDialog()
597 {
598         QString fn = "";
599
600         // read default settings:
601         settings.beginGroup("Paths");
602         QString defDir = settings.value("OpenImage", RS_SYSTEM->getHomeDir()).toString();
603         QString defFilter = settings.value("ImageFilter", "Portable Network Graphic (*.png)").toString();
604         settings.endGroup();
605
606         bool cancel = false;
607
608 //      Q3FileDialog fileDlg(NULL, "", true);
609         QFileDialog fileDlg(NULL, "");
610
611 #if 0
612 //      Q3StrList f = QImageIO::inputFormats();
613 //      QStringList formats = QStringList::fromStrList(f);
614         QList<QByteArray> f = QImageReader::supportedImageFormats();
615         QStringList formats = ???
616 #else
617 #warning "Needs porting to Qt4... !!! FIX !!!"
618 #endif
619
620         QStringList filters;
621         QString all = "";
622         //filters = QStringList::fromStrList(formats);
623
624 #if 0
625         for (QStringList::Iterator it=formats.begin(); it!=formats.end(); ++it)
626         {
627                 QString ext = (*it);
628
629                 QString st;
630
631                 if (ext == "JPEG")
632                 {
633                         st = QString("%1 (*.%2 *.jpg)").arg(extToFormat(*it)).arg(QString(*it).lower());
634                 }
635                 else
636                 {
637                         st = QString("%1 (*.%2)").arg(extToFormat(*it)).arg(QString(*it).lower());
638                 }
639
640                 filters.append(st);
641
642                 if (!all.isEmpty())
643                         all += " ";
644
645                 if (ext == "JPEG")
646                 {
647                         all += QString("*.%1 *.jpg").arg(QString(*it).lower());
648                 }
649                 else
650                 {
651                         all += QString("*.%1").arg(QString(*it).lower());
652                 }
653         }
654 #endif
655
656         filters.append(QObject::tr("All Image Files (%1)").arg(all));
657         filters.append(QObject::tr("All Files (*.*)"));
658
659         //filters.append("Drawing Exchange (*.)");
660         //filters.append("Font (*.cxf)");
661
662         fileDlg.setFilters(filters);
663 //      fileDlg.setMode(Q3FileDialog::ExistingFile);
664         fileDlg.setFileMode(QFileDialog::ExistingFile);
665 //      fileDlg.setCaption(QObject::tr("Open Image"));
666         fileDlg.setWindowTitle(QObject::tr("Open Image"));
667 //      fileDlg.setDir(defDir);
668         fileDlg.setDirectory(defDir);
669 //      fileDlg.setSelectedFilter(defFilter);
670         fileDlg.selectFilter(defFilter);
671
672         cancel = true;
673
674         if (fileDlg.exec() == QDialog::Accepted)
675         {
676 //              fn = fileDlg.selectedFile();
677                 QStringList files = fileDlg.selectedFiles();
678
679                 if (!files.isEmpty())
680                         fn = files[0];
681
682                 cancel = false;
683         }
684
685         // store new default settings:
686         if (!cancel)
687         {
688                 QStringList files = fileDlg.selectedFiles();
689                 QString selected = "";
690
691                 if (!files.isEmpty())
692                         selected = files[0];
693
694                 settings.beginGroup("Paths");
695 //              RS_SETTINGS->writeEntry("/OpenImage", QFileInfo(fn).dirPath(true));
696                 settings.setValue("OpenImage", QFileInfo(fn).absolutePath());
697                 settings.setValue("ImageFilter", selected);
698                 settings.endGroup();
699         }
700
701         return fn;
702 }
703
704 void QG_DialogFactory::requestOptions(ActionInterface * action, bool on, bool update)
705 {
706         RS_DEBUG->print("QG_DialogFactory::requestOptions");
707
708     if (action == NULL)
709         {
710         RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestOptions: action is NULL");
711         return;
712     }
713
714     switch (action->rtti())
715         {
716     case RS2::ActionPrintPreview:
717         requestPrintPreviewOptions(action, on, update);
718         break;
719
720     case RS2::ActionDrawLine:
721                 RS_DEBUG->print("QG_DialogFactory::requestOptions: line");
722         requestLineOptions(action, on);
723                 RS_DEBUG->print("QG_DialogFactory::requestOptions: line: OK");
724         break;
725
726     case RS2::ActionDrawPolyline:
727         requestPolylineOptions(action, on, update);
728         break;
729
730     case RS2::ActionDrawLineAngle:
731         requestLineAngleOptions(action, on, update);
732         break;
733
734     case RS2::ActionDrawLineParallel:
735         requestLineParallelOptions(action, on, update);
736         break;
737
738     case RS2::ActionDrawLineParallelThrough:
739         requestLineParallelThroughOptions(action, on, update);
740         break;
741
742     case RS2::ActionDrawLineBisector:
743         requestLineBisectorOptions(action, on, update);
744         break;
745
746     case RS2::ActionDrawLineRelAngle:
747         requestLineRelAngleOptions(action, on, update);
748         break;
749
750     case RS2::ActionDrawLinePolygon:
751         requestLinePolygonOptions(action, on, update);
752         break;
753
754     case RS2::ActionDrawLinePolygon2:
755         requestLinePolygon2Options(action, on, update);
756         break;
757
758     case RS2::ActionDrawArc:
759         requestArcOptions(action, on, update);
760         break;
761
762         case RS2::ActionDrawArcTangential:
763         requestArcTangentialOptions(action, on, update);
764         break;
765
766     case RS2::ActionDrawCircleCR:
767         requestCircleOptions(action, on, update);
768         break;
769
770     case RS2::ActionDrawSpline:
771         requestSplineOptions(action, on, update);
772         break;
773
774     case RS2::ActionDrawText:
775         requestTextOptions(action, on, update);
776         break;
777
778     case RS2::ActionBlocksInsert:
779         requestInsertOptions(action, on, update);
780         break;
781
782     case RS2::ActionDrawImage:
783         requestImageOptions(action, on, update);
784         break;
785
786     case RS2::ActionDimAligned:
787         requestDimensionOptions(action, on, update);
788         break;
789
790     case RS2::ActionDimLinear:
791         requestDimensionOptions(action, on, update);
792
793                 if (((ActionDimLinear *)action)->hasFixedAngle() == false)
794             requestDimLinearOptions(action, on, update);
795
796                 break;
797
798     case RS2::ActionDimRadial:
799         requestDimensionOptions(action, on, update);
800         break;
801
802     case RS2::ActionDimDiametric:
803         requestDimensionOptions(action, on, update);
804         break;
805
806     case RS2::ActionDimAngular:
807         requestDimensionOptions(action, on, update);
808         break;
809
810     case RS2::ActionModifyTrimAmount:
811         requestTrimAmountOptions(action, on, update);
812         break;
813
814     case RS2::ActionModifyMoveRotate:
815         requestMoveRotateOptions(action, on, update);
816         break;
817
818     case RS2::ActionModifyBevel:
819         requestBevelOptions(action, on, update);
820         break;
821
822     case RS2::ActionModifyRound:
823         requestRoundOptions(action, on, update);
824         break;
825
826     case RS2::ActionLibraryInsert:
827         requestLibraryInsertOptions(action, on, update);
828         break;
829
830     default:
831         break;
832     }
833
834         RS_DEBUG->print("QG_DialogFactory::requestOptions: OK");
835 }
836
837 /**
838  * Shows a widget for options for the action: "print preview"
839  */
840 void QG_DialogFactory::requestPrintPreviewOptions(ActionInterface * action, bool on, bool update)
841 {
842         static PrintPreviewOptions * toolWidget = NULL;
843
844         if (!optionWidget)
845                 return;
846
847         if (toolWidget)
848         {
849                 delete toolWidget;
850                 toolWidget = NULL;
851         }
852
853         if (on)
854         {
855                 toolWidget = new PrintPreviewOptions(optionWidget);
856                 toolWidget->setAction(action, update);
857         }
858 }
859
860 /**
861  * Shows a widget for options for the action: "draw line"
862  */
863 void QG_DialogFactory::requestLineOptions(ActionInterface * action, bool on)
864 {
865 /*
866 The way I see it, this is failure. We're constantly creating & deleting
867 these objects all the time when we could create them once, and then reuse
868 them over and over. May need to do some more refactoring based on this idea...
869 */
870         //ugh.
871         static LineOptions * toolWidget = NULL;
872
873         if (!optionWidget)
874                 return;
875
876         // Get rid of the LineOptions object if it exists...
877         if (toolWidget)
878         {
879                 delete toolWidget;
880                 toolWidget = NULL;
881         }
882
883         // Create a new one for the passed in action
884         if (on)
885         {
886                 toolWidget = new LineOptions(optionWidget);
887                 toolWidget->setAction(action);
888         }
889
890         RS_DEBUG->print("QG_DialogFactory::requestLineOptions: OK");
891 }
892
893 /**
894  * Shows a widget for options for the action: "draw polyline"
895  */
896 void QG_DialogFactory::requestPolylineOptions(ActionInterface * action, bool on, bool update)
897 {
898 #ifdef RS_PROF
899         static PolylineOptions * toolWidget = NULL;
900
901         if (!optionWidget)
902                 return;
903
904         if (toolWidget)
905         {
906                 delete toolWidget;
907                 toolWidget = NULL;
908         }
909
910         if (on)
911         {
912                 toolWidget = new PolylineOptions(optionWidget);
913                 toolWidget->setAction(action, update);
914         }
915 #endif
916 }
917
918 /**
919  * Shows a widget for options for the action: "draw line parallel"
920  */
921 void QG_DialogFactory::requestLineParallelOptions(ActionInterface * action, bool on, bool update)
922 {
923     static LineParallelOptions * toolWidget = NULL;
924
925     if (optionWidget!=NULL)
926         {
927         if (toolWidget!=NULL)
928                 {
929             delete toolWidget;
930             toolWidget = NULL;
931         }
932         if (on==true && toolWidget==NULL)
933                 {
934             toolWidget = new LineParallelOptions(optionWidget);
935             toolWidget->setAction(action, update);
936         }
937     }
938 }
939
940 /**
941  * Shows a widget for options for the action: "draw line parallel through"
942  */
943 void QG_DialogFactory::requestLineParallelThroughOptions(ActionInterface * action, bool on, bool update)
944 {
945     static LineParallelThroughOptions * toolWidget = NULL;
946
947     if (optionWidget!=NULL) {
948         if (toolWidget!=NULL) {
949             delete toolWidget;
950             toolWidget = NULL;
951         }
952         if (on==true && toolWidget==NULL) {
953             toolWidget = new LineParallelThroughOptions(optionWidget);
954             toolWidget->setAction(action, update);
955         }
956     }
957 }
958
959 /**
960  * Shows a widget for options for the action: "line angle"
961  */
962 void QG_DialogFactory::requestLineAngleOptions(ActionInterface * action, bool on, bool update)
963 {
964         static LineAngleOptions * toolWidget = NULL;
965
966         if (!optionWidget)
967                 return;
968
969         if (toolWidget)
970         {
971                 delete toolWidget;
972                 toolWidget = NULL;
973         }
974
975         if (on)
976         {
977                 toolWidget = new LineAngleOptions(optionWidget);
978                 toolWidget->setAction(action, update);
979         }
980 }
981
982 /**
983  * Shows a widget for options for the action: "line relative angle"
984  */
985 void QG_DialogFactory::requestLineRelAngleOptions(ActionInterface * action, bool on, bool update)
986 {
987         static LineRelAngleOptions * toolWidget = NULL;
988
989         if (!optionWidget)
990                 return;
991
992         if (toolWidget)
993         {
994                 delete toolWidget;
995                 toolWidget = NULL;
996         }
997
998         if (on)
999         {
1000                 toolWidget = new LineRelAngleOptions(optionWidget);
1001                 toolWidget->setAction(action, update);
1002         }
1003 }
1004
1005 /**
1006  * Shows a widget for options for the action: "line angle"
1007  */
1008 void QG_DialogFactory::requestLineBisectorOptions(ActionInterface * action, bool on, bool update)
1009 {
1010     static LineBisectorOptions * toolWidget = NULL;
1011
1012     if (optionWidget!=NULL) {
1013         if (toolWidget!=NULL) {
1014             delete toolWidget;
1015             toolWidget = NULL;
1016         }
1017         if (on==true && toolWidget==NULL) {
1018             toolWidget = new LineBisectorOptions(optionWidget);
1019             toolWidget->setAction(action, update);
1020         }
1021     }
1022 }
1023
1024 /**
1025  * Shows a widget for options for the action: "draw polygon"
1026  */
1027 void QG_DialogFactory::requestLinePolygonOptions(ActionInterface * action, bool on, bool update)
1028 {
1029     static LinePolygonOptions * toolWidget = NULL;
1030
1031     if (optionWidget!=NULL) {
1032         if (toolWidget!=NULL) {
1033             delete toolWidget;
1034             toolWidget = NULL;
1035         }
1036         if (on==true && toolWidget==NULL) {
1037             toolWidget = new LinePolygonOptions(optionWidget);
1038             toolWidget->setAction(action, update);
1039         }
1040     }
1041 }
1042
1043 /**
1044  * Shows a widget for options for the action: "draw polygon2"
1045  */
1046 void QG_DialogFactory::requestLinePolygon2Options(ActionInterface * action, bool on, bool update)
1047 {
1048     static LinePolygon2Options * toolWidget = NULL;
1049
1050     if (optionWidget!=NULL) {
1051         if (toolWidget!=NULL) {
1052             delete toolWidget;
1053             toolWidget = NULL;
1054         }
1055         if (on==true && toolWidget==NULL) {
1056             toolWidget = new LinePolygon2Options(optionWidget);
1057             toolWidget->setAction(action, update);
1058         }
1059     }
1060 }
1061
1062 /**
1063  * Shows a widget for arc options.
1064  */
1065 void QG_DialogFactory::requestArcOptions(ActionInterface * action, bool on, bool update)
1066 {
1067         static ArcOptions * toolWidget = NULL;
1068
1069         if (optionWidget != NULL)
1070         {
1071                 if (toolWidget != NULL)
1072                 {
1073                         delete toolWidget;
1074                         toolWidget = NULL;
1075                 }
1076
1077                 if (on && toolWidget == NULL)
1078                 {
1079                         toolWidget = new ArcOptions(optionWidget);
1080                         toolWidget->setAction(action, update);
1081                         //toolWidget->setData(&data);
1082                 }
1083         }
1084 }
1085
1086 /**
1087  * Shows a widget for tangential arc options.
1088  */
1089 void QG_DialogFactory::requestArcTangentialOptions(ActionInterface * action, bool on, bool update)
1090 {
1091         static ArcTangentialOptions * toolWidget = NULL;
1092
1093         if (!optionWidget)
1094                 return;
1095
1096         if (toolWidget)
1097         {
1098                 delete toolWidget;
1099                 toolWidget = NULL;
1100         }
1101
1102         if (on)
1103         {
1104                 toolWidget = new ArcTangentialOptions(optionWidget);
1105                 toolWidget->setAction(action, update);
1106                 //toolWidget->setData(&data);
1107         }
1108 }
1109
1110 /**
1111  * Shows a widget for circle options.
1112  */
1113 void QG_DialogFactory::requestCircleOptions(ActionInterface * action, bool on, bool update)
1114 {
1115     static CircleOptions * toolWidget = NULL;
1116
1117     if (optionWidget)
1118         {
1119         if (toolWidget)
1120                 {
1121             delete toolWidget;
1122             toolWidget = NULL;
1123         }
1124
1125         if (on && toolWidget == NULL)
1126                 {
1127             toolWidget = new CircleOptions(optionWidget);
1128             toolWidget->setAction(action, update);
1129         }
1130     }
1131 }
1132
1133 /**
1134  * Shows a widget for spline options.
1135  */
1136 void QG_DialogFactory::requestSplineOptions(ActionInterface * action, bool on, bool update)
1137 {
1138         static SplineOptions * toolWidget = NULL;
1139
1140         if (!optionWidget)
1141                 return;
1142
1143         if (toolWidget)
1144         {
1145                 delete toolWidget;
1146                 toolWidget = NULL;
1147         }
1148
1149         if (on)
1150         {
1151                 toolWidget = new SplineOptions(optionWidget);
1152                 toolWidget->setAction(action, update);
1153         }
1154 }
1155
1156 /**
1157  * Shows a widget for text options.
1158  */
1159 void QG_DialogFactory::requestTextOptions(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(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(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(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(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(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(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(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(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(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)
1403                 cadToolBar->showToolBar(id);
1404 }
1405
1406 /**
1407  * Shows the select toolbar with the given action to launch.
1408  */
1409 void QG_DialogFactory::requestToolBarSelect(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)
1838                 mouseWidget->setHelp(left, right);
1839
1840         if (commandWidget)
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 }