1 // qg_dialogfactory.cpp
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
8 // JLH = James L. Hammons <jlhamm@acm.org>
11 // --- ---------- -----------------------------------------------------------
12 // JLH 05/10/2010 Added this text. :-)
15 #include "qg_dialogfactory.h"
17 #include "rs_patternlist.h"
19 #include "rs_system.h"
20 #include "rs_actioninterface.h"
21 #include "rs_document.h"
22 #include "rs_actiondimlinear.h"
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"
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"
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"
94 #include "qg_polylineoptions.h"
98 #include "rs_camdialog.h"
101 #include "qg_layerwidget.h"
102 #include "qg_mainwindowinterface.h"
104 //QG_DialogFactory* QG_DialogFactory::uniqueInstance = NULL;
109 * @param parent Pointer to parent widget which can host dialogs.
110 * @param ow Pointer to widget that can host option widgets.
112 QG_DialogFactory::QG_DialogFactory(QWidget * parent, QWidget * ow):
113 RS_DialogFactoryInterface()
115 RS_DEBUG->print("QG_DialogFactory::QG_DialogFactory");
117 this->parent = parent;
120 coordinateWidget = NULL;
122 selectionWidget = NULL;
124 commandWidget = NULL;
126 RS_DEBUG->print("QG_DialogFactory::QG_DialogFactory: OK");
132 QG_DialogFactory::~QG_DialogFactory()
134 RS_DEBUG->print("QG_DialogFactory::~QG_DialogFactory");
135 RS_DEBUG->print("QG_DialogFactory::~QG_DialogFactory: OK");
139 * Links factory to a widget that can host tool options.
141 /*virtual*/ void QG_DialogFactory::setOptionWidget(QWidget * ow)
143 RS_DEBUG->print("QG_DialogFactory::setOptionWidget");
145 RS_DEBUG->print("QG_DialogFactory::setOptionWidget: OK");
149 * Links this dialog factory to a coordinate widget.
151 /*virtual*/ void QG_DialogFactory::setCoordinateWidget(CoordinateWidget * cw)
153 coordinateWidget = cw;
157 * Links this dialog factory to a mouse widget.
159 /*virtual*/ void QG_DialogFactory::setMouseWidget(MouseWidget * mw)
165 * Links this dialog factory to a selection widget.
167 /*virtual*/ void QG_DialogFactory::setSelectionWidget(SelectionWidget * sw)
169 selectionWidget = sw;
173 * Links this dialog factory to the cad tool bar.
175 /*virtual*/ void QG_DialogFactory::setCadToolBar(CadToolBar * ctb)
181 * @return cad tool bar or NULL.
183 CadToolBar * QG_DialogFactory::getCadToolBar()
189 * Links this dialog factory to a command widget.
191 /*virtual*/ void QG_DialogFactory::setCommandWidget(CommandWidget * cw)
197 * @return command widget or NULL.
199 CommandWidget * QG_DialogFactory::getCommandWidget()
201 return commandWidget;
205 * Links the dialog factory to a main app window.
207 /*virtual*/ void QG_DialogFactory::setMainWindow(QG_MainWindowInterface * mw)
213 * Shows a message dialog.
215 void QG_DialogFactory::requestWarningDialog(const QString & warning)
217 QMessageBox::information(parent, QMessageBox::tr("Warning"),
218 warning, QMessageBox::Ok);
222 * Requests a new document from the main window.
224 RS_GraphicView * QG_DialogFactory::requestNewDocument(const QString & fileName, RS_Document * doc)
226 if (mainWindow != NULL)
228 mainWindow->createNewDocument(fileName, doc);
229 return mainWindow->getGraphicView();
236 * Requests the simulation controls.
238 void QG_DialogFactory::requestSimulationControls()
240 if (mainWindow != NULL)
242 mainWindow->showSimulationControls();
247 * Shows a dialog for adding a layer. Doesn't add the layer.
248 * This is up to the caller.
250 * @return a pointer to the newly created layer that
253 RS_Layer * QG_DialogFactory::requestNewLayerDialog(RS_LayerList * layerList)
255 RS_Layer * layer = NULL;
256 QString layer_name = "noname";
259 if (layerList != NULL)
261 while (layerList->find(layer_name) > 0)
262 layer_name.sprintf("noname%d", i++);
265 // Layer for parameter livery
266 layer = new RS_Layer(layer_name);
268 // QG_LayerDialog dlg(parent, "Layer Dialog");
269 LayerDialog dlg(parent);
271 dlg.setLayerList(layerList);
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.
288 * @return a pointer to the layer that should be removed.
290 RS_Layer * QG_DialogFactory::requestLayerRemovalDialog(RS_LayerList * layerList)
292 RS_Layer * layer = NULL;
294 if (layerList == NULL)
296 RS_DEBUG->print(RS_Debug::D_WARNING,
297 "QG_DialogFactory::requestLayerRemovalDialog(): layerList is NULL");
302 if (layerList==NULL) {
303 if (container!=NULL && container->rtti()==RS2::EntityGraphic) {
304 layerList = (RS_LayerList*)container;
310 // Layer for parameter livery
311 layer = layerList->getActive();
315 if (layer->getName() != "0")
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);
331 QMessageBox::information(parent, QMessageBox::tr("Remove Layer"),
332 QMessageBox::tr("Layer \"%1\" can never be removed.").arg(layer->getName()),
341 * Shows a dialog for editing a layer. A new layer is created and
342 * returned. Modifying the layer is up to the caller.
344 * @return A pointer to a new layer with the changed attributes
345 * or NULL if the dialog was cancelled.
347 RS_Layer * QG_DialogFactory::requestEditLayerDialog(RS_LayerList * layerList)
349 RS_DEBUG->print("QG_DialogFactory::requestEditLayerDialog");
350 RS_Layer * layer = NULL;
352 if (layerList==NULL) {
353 if (container!=NULL && container->rtti()==RS2::EntityGraphic) {
354 layerList = (RS_LayerList*)container;
361 if (layerList == NULL)
363 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestEditLayerDialog(): "
364 "layerList is NULL");
368 // Layer for parameter livery
369 if (layerList->getActive() != NULL)
371 layer = new RS_Layer(*layerList->getActive());
373 // QG_LayerDialog dlg(parent, QMessageBox::tr("Layer Dialog"));
374 LayerDialog dlg(parent);
376 dlg.setLayerList(layerList);
377 dlg.setEditLayer(true);
392 * Shows a dialog for adding a block. Doesn't add the block.
393 * This is up to the caller.
395 * @return a pointer to the newly created block that
398 RS_BlockData QG_DialogFactory::requestNewBlockDialog(RS_BlockList * blockList)
400 //RS_Block* block = NULL;
402 ret = RS_BlockData("", Vector(false), false);
404 if (blockList == NULL)
406 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestNewBlockDialog(): "
407 "blockList is NULL");
411 // Block for parameter livery
412 //block = new RS_Block(container, "noname", Vector(0.0,0.0));
414 BlockDialog dlg(parent);
415 dlg.setBlockList(blockList);
418 ret = dlg.getBlockData();
424 * Shows a dialog for renaming the currently active block.
426 * @return a pointer to the modified block or NULL on cancellation.
428 RS_BlockData QG_DialogFactory::requestBlockAttributesDialog(RS_BlockList * blockList)
430 //RS_Block* block = NULL;
432 ret = RS_BlockData("", Vector(false), false);
434 if (blockList == NULL)
436 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestBlockAttributesDialog(): "
437 "blockList is NULL");
441 if (blockList==NULL) {
442 if (container!=NULL && container->rtti()==RS2::EntityGraphic) {
443 blockList = (RS_BlockList*)container;
449 // Block for parameter livery
450 //block = blockList->getActive();
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);
461 ret = dlg.getBlockData();
464 // ret = RS_BlockData("", Vector(false));
470 /*virtual*/ void QG_DialogFactory::requestEditBlockWindow(RS_BlockList * /*blockList*/)
474 /*virtual*/ void QG_DialogFactory::closeEditBlockWindow(RS_Block * /*blockList*/)
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.
482 * @return a pointer to the block that should be removed.
484 RS_Block * QG_DialogFactory::requestBlockRemovalDialog(RS_BlockList * blockList)
486 RS_Block * block = NULL;
488 if (blockList == NULL)
490 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestBlockRemovalDialog(): "
491 "blockList is NULL");
495 // Block for parameter livery
496 block = blockList->getActive();
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);
517 * Shows a dialog for choosing a file name. Saving the file is up to
520 * @return File name with path and extension to determine the file type
521 * or an empty string if the dialog was cancelled.
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();
533 // prepare file save as dialog:
534 QFileDialog fileDlg(this,0,true);
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);
551 if (fileDlg.exec()==QDialog::Accepted) {
552 fn = fileDlg.selectedFile();
555 // append default extension:
556 if (fn.find('.')==-1) {
557 if (fileDlg.selectedFilter()=="Font (*.cxf)") {
564 // overwrite warning:
565 if(QFileInfo(fn).exists()) {
567 QMessageBox::warning(this, tr("Save Drawing As"),
568 tr("%1 already exists.\n"
569 "Do you want to replace it?")
572 tr("Cancel"), 0, 1 );
595 // store new default settings:
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();
608 * Shows a dialog for choosing a file name. Opening the file is up to
611 * @return File name with path and extension to determine the file type
612 * or an empty string if the dialog was cancelled.
614 QString QG_DialogFactory::requestImageOpenDialog()
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();
626 // Q3FileDialog fileDlg(NULL, "", true);
627 QFileDialog fileDlg(NULL, "");
630 // Q3StrList f = QImageIO::inputFormats();
631 // QStringList formats = QStringList::fromStrList(f);
632 QList<QByteArray> f = QImageReader::supportedImageFormats();
633 QStringList formats = ???
635 #warning "Needs porting to Qt4... !!! FIX !!!"
640 //filters = QStringList::fromStrList(formats);
643 for (QStringList::Iterator it=formats.begin(); it!=formats.end(); ++it)
651 st = QString("%1 (*.%2 *.jpg)").arg(extToFormat(*it)).arg(QString(*it).lower());
655 st = QString("%1 (*.%2)").arg(extToFormat(*it)).arg(QString(*it).lower());
665 all += QString("*.%1 *.jpg").arg(QString(*it).lower());
669 all += QString("*.%1").arg(QString(*it).lower());
674 filters.append(QObject::tr("All Image Files (%1)").arg(all));
675 filters.append(QObject::tr("All Files (*.*)"));
677 //filters.append("Drawing Exchange (*.)");
678 //filters.append("Font (*.cxf)");
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);
692 if (fileDlg.exec() == QDialog::Accepted)
694 // fn = fileDlg.selectedFile();
695 QStringList files = fileDlg.selectedFiles();
697 if (!files.isEmpty())
703 // store new default settings:
706 QStringList files = fileDlg.selectedFiles();
707 QString selected = "";
709 if (!files.isEmpty())
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);
722 void QG_DialogFactory::requestOptions(RS_ActionInterface * action, bool on, bool update)
724 RS_DEBUG->print("QG_DialogFactory::requestOptions");
728 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestOptions: action is NULL");
732 switch (action->rtti())
734 case RS2::ActionPrintPreview:
735 requestPrintPreviewOptions(action, on, update);
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");
744 case RS2::ActionDrawPolyline:
745 requestPolylineOptions(action, on, update);
748 case RS2::ActionDrawLineAngle:
749 requestLineAngleOptions(action, on, update);
752 case RS2::ActionDrawLineParallel:
753 requestLineParallelOptions(action, on, update);
756 case RS2::ActionDrawLineParallelThrough:
757 requestLineParallelThroughOptions(action, on, update);
760 case RS2::ActionDrawLineBisector:
761 requestLineBisectorOptions(action, on, update);
764 case RS2::ActionDrawLineRelAngle:
765 requestLineRelAngleOptions(action, on, update);
768 case RS2::ActionDrawLinePolygon:
769 requestLinePolygonOptions(action, on, update);
772 case RS2::ActionDrawLinePolygon2:
773 requestLinePolygon2Options(action, on, update);
776 case RS2::ActionDrawArc:
777 requestArcOptions(action, on, update);
780 case RS2::ActionDrawArcTangential:
781 requestArcTangentialOptions(action, on, update);
784 case RS2::ActionDrawCircleCR:
785 requestCircleOptions(action, on, update);
788 case RS2::ActionDrawSpline:
789 requestSplineOptions(action, on, update);
792 case RS2::ActionDrawText:
793 requestTextOptions(action, on, update);
796 case RS2::ActionBlocksInsert:
797 requestInsertOptions(action, on, update);
800 case RS2::ActionDrawImage:
801 requestImageOptions(action, on, update);
804 case RS2::ActionDimAligned:
805 requestDimensionOptions(action, on, update);
808 case RS2::ActionDimLinear:
809 requestDimensionOptions(action, on, update);
811 if (((RS_ActionDimLinear *)action)->hasFixedAngle() == false)
812 requestDimLinearOptions(action, on, update);
816 case RS2::ActionDimRadial:
817 requestDimensionOptions(action, on, update);
820 case RS2::ActionDimDiametric:
821 requestDimensionOptions(action, on, update);
824 case RS2::ActionDimAngular:
825 requestDimensionOptions(action, on, update);
828 case RS2::ActionModifyTrimAmount:
829 requestTrimAmountOptions(action, on, update);
832 case RS2::ActionModifyMoveRotate:
833 requestMoveRotateOptions(action, on, update);
836 case RS2::ActionModifyBevel:
837 requestBevelOptions(action, on, update);
840 case RS2::ActionModifyRound:
841 requestRoundOptions(action, on, update);
844 case RS2::ActionLibraryInsert:
845 requestLibraryInsertOptions(action, on, update);
852 RS_DEBUG->print("QG_DialogFactory::requestOptions: OK");
856 * Shows a widget for options for the action: "print preview"
858 void QG_DialogFactory::requestPrintPreviewOptions(RS_ActionInterface * action, bool on, bool update)
860 static PrintPreviewOptions * toolWidget = NULL;
862 if (optionWidget != NULL)
864 if (toolWidget != NULL)
869 if (on && toolWidget == NULL)
871 toolWidget = new PrintPreviewOptions(optionWidget);
872 toolWidget->setAction(action, update);
878 * Shows a widget for options for the action: "draw line"
880 void QG_DialogFactory::requestLineOptions(RS_ActionInterface * action, bool on)
882 static LineOptions * toolWidget = NULL;
884 if (optionWidget != NULL)
886 if (toolWidget != NULL)
892 if (on == true && toolWidget == NULL)
894 toolWidget = new LineOptions(optionWidget);
895 toolWidget->setAction(action);
899 RS_DEBUG->print("QG_DialogFactory::requestLineOptions: OK");
903 * Shows a widget for options for the action: "draw polyline"
905 void QG_DialogFactory::requestPolylineOptions(RS_ActionInterface * action, bool on, bool update)
908 static QG_PolylineOptions * toolWidget = NULL;
910 if (optionWidget != NULL)
912 if (toolWidget != NULL)
917 if (on && toolWidget == NULL)
919 toolWidget = new QG_PolylineOptions(optionWidget);
920 toolWidget->setAction(action, update);
928 * Shows a widget for options for the action: "draw line parallel"
930 void QG_DialogFactory::requestLineParallelOptions(RS_ActionInterface * action, bool on, bool update)
932 static QG_LineParallelOptions* toolWidget = NULL;
934 if (optionWidget!=NULL) {
935 if (toolWidget!=NULL) {
939 if (on==true && toolWidget==NULL) {
940 toolWidget = new QG_LineParallelOptions(optionWidget);
941 toolWidget->setAction(action, update);
947 * Shows a widget for options for the action: "draw line parallel through"
949 void QG_DialogFactory::requestLineParallelThroughOptions(RS_ActionInterface* action,
950 bool on, bool update)
952 static QG_LineParallelThroughOptions* toolWidget = NULL;
954 if (optionWidget!=NULL) {
955 if (toolWidget!=NULL) {
959 if (on==true && toolWidget==NULL) {
960 toolWidget = new QG_LineParallelThroughOptions(optionWidget);
961 toolWidget->setAction(action, update);
967 * Shows a widget for options for the action: "line angle"
969 void QG_DialogFactory::requestLineAngleOptions(RS_ActionInterface* action,
970 bool on, bool update)
972 static QG_LineAngleOptions* toolWidget = NULL;
974 if (optionWidget!=NULL) {
975 if (toolWidget!=NULL) {
979 if (on==true && toolWidget==NULL) {
980 toolWidget = new QG_LineAngleOptions(optionWidget);
981 toolWidget->setAction(action, update);
982 //toolWidget->setData(&angle, &length, fixedAngle, update);
988 * Shows a widget for options for the action: "line relative angle"
990 void QG_DialogFactory::requestLineRelAngleOptions(RS_ActionInterface* action,
991 bool on, bool update)
993 static QG_LineRelAngleOptions* toolWidget = NULL;
995 if (optionWidget!=NULL) {
996 if (toolWidget!=NULL) {
1000 if (on==true && toolWidget==NULL) {
1001 toolWidget = new QG_LineRelAngleOptions(optionWidget);
1002 toolWidget->setAction(action, update);
1003 //toolWidget->setData(&angle, &length, fixedAngle, update);
1009 * Shows a widget for options for the action: "line angle"
1011 void QG_DialogFactory::requestLineBisectorOptions(RS_ActionInterface* action,
1012 bool on, bool update)
1014 static QG_LineBisectorOptions* toolWidget = NULL;
1016 if (optionWidget!=NULL) {
1017 if (toolWidget!=NULL) {
1021 if (on==true && toolWidget==NULL) {
1022 toolWidget = new QG_LineBisectorOptions(optionWidget);
1023 toolWidget->setAction(action, update);
1029 * Shows a widget for options for the action: "draw polygon"
1031 void QG_DialogFactory::requestLinePolygonOptions(RS_ActionInterface* action,
1032 bool on, bool update)
1034 static QG_LinePolygonOptions* toolWidget = NULL;
1036 if (optionWidget!=NULL) {
1037 if (toolWidget!=NULL) {
1041 if (on==true && toolWidget==NULL) {
1042 toolWidget = new QG_LinePolygonOptions(optionWidget);
1043 toolWidget->setAction(action, update);
1049 * Shows a widget for options for the action: "draw polygon2"
1051 void QG_DialogFactory::requestLinePolygon2Options(RS_ActionInterface* action,
1052 bool on, bool update)
1054 static QG_LinePolygon2Options* toolWidget = NULL;
1056 if (optionWidget!=NULL) {
1057 if (toolWidget!=NULL) {
1061 if (on==true && toolWidget==NULL) {
1062 toolWidget = new QG_LinePolygon2Options(optionWidget);
1063 toolWidget->setAction(action, update);
1069 * Shows a widget for arc options.
1071 void QG_DialogFactory::requestArcOptions(RS_ActionInterface* action,
1072 bool on, bool update)
1074 static QG_ArcOptions* toolWidget = NULL;
1076 if (optionWidget!=NULL) {
1077 if (toolWidget!=NULL) {
1081 if (on==true && toolWidget==NULL) {
1082 toolWidget = new QG_ArcOptions(optionWidget);
1083 toolWidget->setAction(action, update);
1084 //toolWidget->setData(&data);
1090 * Shows a widget for tangential arc options.
1092 void QG_DialogFactory::requestArcTangentialOptions(RS_ActionInterface* action,
1093 bool on, bool update)
1095 static QG_ArcTangentialOptions* toolWidget = NULL;
1097 if (optionWidget!=NULL) {
1098 if (toolWidget!=NULL) {
1102 if (on==true && toolWidget==NULL) {
1103 toolWidget = new QG_ArcTangentialOptions(optionWidget);
1104 toolWidget->setAction(action, update);
1105 //toolWidget->setData(&data);
1111 * Shows a widget for arc options.
1113 void QG_DialogFactory::requestCircleOptions(RS_ActionInterface* action,
1114 bool on, bool update)
1116 static QG_CircleOptions* toolWidget = NULL;
1118 if (optionWidget!=NULL) {
1119 if (toolWidget!=NULL) {
1123 if (on==true && toolWidget==NULL) {
1124 toolWidget = new QG_CircleOptions(optionWidget);
1125 toolWidget->setAction(action, update);
1131 * Shows a widget for spline options.
1133 void QG_DialogFactory::requestSplineOptions(RS_ActionInterface* action,
1134 bool on, bool update)
1136 static QG_SplineOptions* toolWidget = NULL;
1138 if (optionWidget!=NULL) {
1139 if (toolWidget!=NULL) {
1143 if (on==true && toolWidget==NULL) {
1144 toolWidget = new QG_SplineOptions(optionWidget);
1145 toolWidget->setAction(action, update);
1151 * Shows a widget for text options.
1153 void QG_DialogFactory::requestTextOptions(RS_ActionInterface* action,
1154 bool on, bool update)
1156 static QG_TextOptions* toolWidget = NULL;
1158 if (optionWidget!=NULL) {
1159 if (toolWidget!=NULL) {
1163 if (on==true && toolWidget==NULL) {
1164 toolWidget = new QG_TextOptions(optionWidget);
1165 toolWidget->setAction(action, update);
1171 * Shows a widget for insert options.
1173 void QG_DialogFactory::requestInsertOptions(RS_ActionInterface* action,
1174 bool on, bool update)
1176 static QG_InsertOptions* toolWidget = NULL;
1178 if (optionWidget!=NULL) {
1179 if (toolWidget!=NULL) {
1183 if (on==true && toolWidget==NULL) {
1184 toolWidget = new QG_InsertOptions(optionWidget);
1185 toolWidget->setAction(action, update);
1191 * Shows a widget for image options.
1193 void QG_DialogFactory::requestImageOptions(RS_ActionInterface* action,
1194 bool on, bool update)
1196 static QG_ImageOptions* toolWidget = NULL;
1198 if (optionWidget!=NULL) {
1199 if (toolWidget!=NULL) {
1203 if (on==true && toolWidget==NULL) {
1204 toolWidget = new QG_ImageOptions(optionWidget);
1205 toolWidget->setAction(action, update);
1211 * Shows a widget for dimension options.
1213 void QG_DialogFactory::requestDimensionOptions(RS_ActionInterface* action,
1214 bool on, bool update)
1216 //static QLabel* l = NULL;
1217 static QG_DimOptions* toolWidget = NULL;
1219 if (optionWidget!=NULL) {
1220 if (toolWidget!=NULL) {
1224 if (on==true && toolWidget==NULL) {
1225 toolWidget = new QG_DimOptions(optionWidget);
1226 toolWidget->setAction(action, update);
1232 * Shows a widget for linear dimension options.
1234 void QG_DialogFactory::requestDimLinearOptions(RS_ActionInterface* action,
1235 bool on, bool update)
1237 //static QLabel* l = NULL;
1238 static QG_DimLinearOptions* toolWidget = NULL;
1240 if (optionWidget!=NULL) {
1241 if (toolWidget!=NULL) {
1245 if (on==true && toolWidget==NULL) {
1246 toolWidget = new QG_DimLinearOptions(optionWidget);
1247 toolWidget->setAction(action, update);
1253 * Shows a widget for 'snap to a point with a given distance' options.
1255 void QG_DialogFactory::requestSnapDistOptions(double& dist, bool on)
1257 static QG_SnapDistOptions* toolWidget = NULL;
1259 if (optionWidget!=NULL) {
1260 if (toolWidget!=NULL) {
1264 if (on==true && toolWidget==NULL) {
1265 toolWidget = new QG_SnapDistOptions(optionWidget);
1266 toolWidget->setDist(&dist);
1272 * Shows a widget for 'snap to a point with a given distance' options.
1274 void QG_DialogFactory::requestMoveRotateOptions(RS_ActionInterface* action,
1275 bool on, bool update)
1277 static QG_MoveRotateOptions* toolWidget = NULL;
1279 if (optionWidget!=NULL) {
1280 if (toolWidget!=NULL) {
1284 if (on==true && toolWidget==NULL) {
1285 toolWidget = new QG_MoveRotateOptions(optionWidget);
1286 toolWidget->setAction(action, update);
1292 * Shows a widget for 'trim amount' options.
1294 void QG_DialogFactory::requestTrimAmountOptions(RS_ActionInterface* action,
1295 bool on, bool update)
1297 static QG_TrimAmountOptions* toolWidget = NULL;
1299 if (optionWidget!=NULL) {
1300 if (toolWidget!=NULL) {
1304 if (on==true && toolWidget==NULL) {
1305 toolWidget = new QG_TrimAmountOptions(optionWidget);
1306 toolWidget->setAction(action, update);
1312 * Shows a widget for beveling options.
1314 void QG_DialogFactory::requestBevelOptions(RS_ActionInterface* action,
1315 bool on, bool update)
1317 static QG_BevelOptions* toolWidget = NULL;
1319 if (optionWidget!=NULL) {
1320 if (toolWidget!=NULL) {
1324 if (on==true && toolWidget==NULL) {
1325 toolWidget = new QG_BevelOptions(optionWidget);
1326 toolWidget->setAction(action, update);
1332 * Shows a widget for rounding options.
1334 void QG_DialogFactory::requestRoundOptions(RS_ActionInterface* action,
1335 bool on, bool update)
1337 static QG_RoundOptions* toolWidget = NULL;
1339 if (optionWidget!=NULL) {
1340 if (toolWidget!=NULL) {
1344 if (on==true && toolWidget==NULL) {
1345 toolWidget = new QG_RoundOptions(optionWidget);
1346 toolWidget->setAction(action, update);
1352 * Shows a widget for library insert options.
1354 void QG_DialogFactory::requestLibraryInsertOptions(RS_ActionInterface* action,
1355 bool on, bool update)
1357 static QG_LibraryInsertOptions* toolWidget = NULL;
1359 if (optionWidget!=NULL) {
1360 if (toolWidget!=NULL) {
1364 if (on==true && toolWidget==NULL) {
1365 toolWidget = new QG_LibraryInsertOptions(optionWidget);
1366 toolWidget->setAction(action, update);
1371 void QG_DialogFactory::requestLineParallelOptions(RS_ActionInterface * action, bool on, bool update)
1375 void QG_DialogFactory::requestLineParallelThroughOptions(RS_ActionInterface* action, bool on, bool update)
1379 void QG_DialogFactory::requestLineAngleOptions(RS_ActionInterface* action, bool on, bool update)
1383 void QG_DialogFactory::requestLineRelAngleOptions(RS_ActionInterface* action, bool on, bool update)
1387 void QG_DialogFactory::requestLineBisectorOptions(RS_ActionInterface* action, bool on, bool update)
1391 void QG_DialogFactory::requestLinePolygonOptions(RS_ActionInterface* action, bool on, bool update)
1395 void QG_DialogFactory::requestLinePolygon2Options(RS_ActionInterface* action, bool on, bool update)
1399 void QG_DialogFactory::requestArcOptions(RS_ActionInterface* action, bool on, bool update)
1403 void QG_DialogFactory::requestArcTangentialOptions(RS_ActionInterface* action, bool on, bool update)
1407 void QG_DialogFactory::requestCircleOptions(RS_ActionInterface* action, bool on, bool update)
1411 void QG_DialogFactory::requestSplineOptions(RS_ActionInterface* action, bool on, bool update)
1416 * Shows a widget for text options.
1418 void QG_DialogFactory::requestTextOptions(RS_ActionInterface * action, bool on, bool update)
1420 static TextOptions * toolWidget = NULL;
1422 if (optionWidget != NULL)
1424 if (toolWidget != NULL)
1430 if (on == true && toolWidget == NULL)
1432 toolWidget = new TextOptions(optionWidget);
1433 toolWidget->setAction(action, update);
1438 void QG_DialogFactory::requestInsertOptions(RS_ActionInterface* action, bool on, bool update)
1442 void QG_DialogFactory::requestImageOptions(RS_ActionInterface* action, bool on, bool update)
1446 void QG_DialogFactory::requestDimensionOptions(RS_ActionInterface* action, bool on, bool update)
1450 void QG_DialogFactory::requestDimLinearOptions(RS_ActionInterface* action, bool on, bool update)
1454 void QG_DialogFactory::requestSnapDistOptions(double& dist, bool on)
1458 void QG_DialogFactory::requestMoveRotateOptions(RS_ActionInterface* action, bool on, bool update)
1462 void QG_DialogFactory::requestTrimAmountOptions(RS_ActionInterface* action, bool on, bool update)
1466 void QG_DialogFactory::requestBevelOptions(RS_ActionInterface* action, bool on, bool update)
1470 void QG_DialogFactory::requestRoundOptions(RS_ActionInterface* action, bool on, bool update)
1474 void QG_DialogFactory::requestLibraryInsertOptions(RS_ActionInterface* action, bool on, bool update)
1480 * Shows the given toolbar.
1482 void QG_DialogFactory::requestToolBar(RS2::ToolBarId id)
1484 if (cadToolBar != NULL)
1485 cadToolBar->showToolBar(id);
1489 * Shows the select toolbar with the given action to launch.
1491 void QG_DialogFactory::requestToolBarSelect(RS_ActionInterface * selectAction,
1492 RS2::ActionType nextAction)
1494 if (cadToolBar != NULL)
1495 cadToolBar->showToolBarSelect(selectAction, nextAction);
1500 * Shows move options dialog presenting the given data.
1502 bool QG_DialogFactory::requestMoveDialog(RS_MoveData & data)
1504 QG_DlgMove dlg(parent);
1517 * Shows rotate options dialog presenting the given data.
1519 bool QG_DialogFactory::requestRotateDialog(RS_RotateData & data)
1521 QG_DlgRotate dlg(parent);
1534 * Shows scale options dialog presenting the given data.
1536 bool QG_DialogFactory::requestScaleDialog(RS_ScaleData & data)
1538 QG_DlgScale dlg(parent);
1551 * Shows mirror options dialog presenting the given data.
1553 bool QG_DialogFactory::requestMirrorDialog(RS_MirrorData & data)
1555 QG_DlgMirror dlg(parent);
1568 * Shows move/rotate options dialog presenting the given data.
1570 bool QG_DialogFactory::requestMoveRotateDialog(RS_MoveRotateData & data)
1572 QG_DlgMoveRotate dlg(parent);
1585 * Shows rotate around two centers options dialog presenting the given data.
1587 bool QG_DialogFactory::requestRotate2Dialog(RS_Rotate2Data & data)
1589 QG_DlgRotate2 dlg(parent);
1602 * Shows a dialog to edit the given entity.
1604 bool QG_DialogFactory::requestModifyEntityDialog(RS_Entity * entity)
1611 switch (entity->rtti())
1613 case RS2::EntityPoint:
1615 QG_DlgPoint dlg(parent);
1616 dlg.setPoint(*((RS_Point *)entity));
1626 case RS2::EntityLine:
1628 QG_DlgLine dlg(parent);
1629 dlg.setLine(*((RS_Line *)entity));
1639 case RS2::EntityArc:
1641 QG_DlgArc dlg(parent);
1642 dlg.setArc(*((RS_Arc *)entity));
1652 case RS2::EntityCircle:
1654 QG_DlgCircle dlg(parent);
1655 dlg.setCircle(*((RS_Circle *)entity));
1665 case RS2::EntityEllipse:
1667 QG_DlgEllipse dlg(parent);
1668 dlg.setEllipse(*((RS_Ellipse *)entity));
1672 dlg.updateEllipse();
1678 case RS2::EntitySpline:
1680 QG_DlgSpline dlg(parent);
1681 dlg.setSpline(*((RS_Spline *)entity));
1691 case RS2::EntityInsert:
1693 QG_DlgInsert dlg(parent);
1694 dlg.setInsert(*((RS_Insert *)entity));
1705 case RS2::EntityDimAligned:
1706 case RS2::EntityDimAngular:
1707 case RS2::EntityDimDiametric:
1708 case RS2::EntityDimRadial:
1710 QG_DlgDimension dlg(parent);
1711 dlg.setDim(*((RS_Dimension *)entity));
1717 ((RS_Dimension *)entity)->update(true);
1722 case RS2::EntityDimLinear:
1724 QG_DlgDimLinear dlg(parent);
1725 dlg.setDim(*((RS_DimLinear *)entity));
1731 ((RS_DimLinear *)entity)->update(true);
1736 case RS2::EntityText:
1738 QG_DlgText dlg(parent);
1739 dlg.setText(*((RS_Text *)entity), false);
1745 ((RS_Text *)entity)->update();
1750 case RS2::EntityHatch:
1752 QG_DlgHatch dlg(parent);
1753 dlg.setHatch(*((RS_Hatch *)entity), false);
1759 ((RS_Hatch *)entity)->update();
1772 * Shows a dialog to edit the attributes of the given dimension entity.
1775 bool QG_DialogFactory::requestDimAlignedDialog(RS_DimAligned* dim) {
1780 QG_DlgDimAligned dlg(parent);
1781 dlg.setDim(*dim, true);
1792 * Shows a dialog to edit the attributes of the given text entity.
1794 bool QG_DialogFactory::requestTextDialog(RS_Text * text)
1799 QG_DlgText dlg(parent);
1800 dlg.setText(*text, true);
1812 * Shows a dialog to edit pattern / hatch attributes of the given entity.
1814 bool QG_DialogFactory::requestHatchDialog(RS_Hatch * hatch)
1819 RS_PATTERNLIST->init();
1821 QG_DlgHatch dlg(parent);
1822 dlg.setHatch(*hatch, true);
1834 * Shows attributes options dialog presenting the given data.
1836 bool QG_DialogFactory::requestAttributesDialog(RS_AttributesData & data, RS_LayerList & layerList)
1838 DlgAttributes dlg(parent);
1839 dlg.setData(&data, layerList);
1850 bool QG_DialogFactory::requestMoveDialog(RS_MoveData & data)
1855 bool QG_DialogFactory::requestRotateDialog(RS_RotateData & data)
1860 bool QG_DialogFactory::requestScaleDialog(RS_ScaleData & data)
1865 bool QG_DialogFactory::requestMirrorDialog(RS_MirrorData & data)
1870 bool QG_DialogFactory::requestMoveRotateDialog(RS_MoveRotateData & data)
1875 bool QG_DialogFactory::requestRotate2Dialog(RS_Rotate2Data & data)
1880 bool QG_DialogFactory::requestModifyEntityDialog(RS_Entity * entity)
1886 bool QG_DialogFactory::requestDimAlignedDialog(RS_DimAligned* dim) {
1892 * Shows a dialog to edit the attributes of the given text entity.
1894 bool QG_DialogFactory::requestTextDialog(RS_Text * text)
1899 DlgText dlg(parent);
1900 dlg.setText(*text, true);
1911 bool QG_DialogFactory::requestHatchDialog(RS_Hatch * hatch)
1919 * Shows a dialog for CAM options.
1921 bool QG_DialogFactory::requestCamOptionsDialog(RS_Graphic& graphic)
1923 RS_DEBUG->print("QG_DialogFactory::requestCamOptionsDialog");
1924 RS_CamDialog dlg(graphic, parent);
1925 RS_DEBUG->print("QG_DialogFactory::requestCamOptionsDialog: exec");
1929 RS_DEBUG->print("QG_DialogFactory::requestCamOptionsDialog: OK");
1933 RS_DEBUG->print("QG_DialogFactory::requestCamOptionsDialog: Cancel");
1939 * Shows dialog for general application options.
1941 void QG_DialogFactory::requestOptionsGeneralDialog()
1943 DlgOptionsGeneral dlg(parent);
1948 * Shows dialog for drawing options.
1950 void QG_DialogFactory::requestOptionsDrawingDialog(RS_Graphic & graphic)
1952 DlgOptionsDrawing dlg(parent);
1953 dlg.setGraphic(&graphic);
1958 * Back to last menu in cad toolbar.
1960 void QG_DialogFactory::requestPreviousMenu()
1962 if (cadToolBar != NULL)
1963 cadToolBar->showToolBarMain();
1967 * Called whenever the mouse position changed.
1969 void QG_DialogFactory::updateCoordinateWidget(const Vector & abs,
1970 const Vector & rel, bool updateFormat)
1972 if (coordinateWidget != NULL)
1973 coordinateWidget->setCoordinates(abs, rel, updateFormat);
1977 * Called when an action has a mouse hint.
1979 void QG_DialogFactory::updateMouseWidget(const QString & left, const QString & right)
1981 if (mouseWidget != NULL)
1982 mouseWidget->setHelp(left, right);
1984 if (commandWidget != NULL)
1985 commandWidget->setCommand(left);
1989 * Called whenever the selection changed.
1991 void QG_DialogFactory::updateSelectionWidget(int num)
1993 if (selectionWidget != NULL)
1994 selectionWidget->setNumber(num);
1998 * Called when an action needs to communicate 'message' to the user.
2000 void QG_DialogFactory::commandMessage(const QString& message)
2002 RS_DEBUG->print("QG_DialogFactory::commandMessage");
2004 if (commandWidget != NULL)
2005 commandWidget->appendHistory(message);
2007 RS_DEBUG->print("QG_DialogFactory::commandMessage: OK");
2010 /*virtual*/ bool QG_DialogFactory::isAdapter()
2016 * Converts an extension to a format description.
2017 * e.g. "PNG" to "Portable Network Graphic"
2020 * @return Format description
2022 QString QG_DialogFactory::extToFormat(const QString & ext)
2024 QString e = ext.toLower();
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");
2047 return ext.toUpper();