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 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
10 // JLH = James L. Hammons <jlhamm@acm.org>
13 // --- ---------- -----------------------------------------------------------
14 // JLH 05/10/2010 Added this text. :-)
17 #include "qg_dialogfactory.h"
19 #include "graphicview.h"
20 #include "layerwidget.h"
21 #include "qg_mainwindowinterface.h"
22 #include "actiondimlinear.h"
23 #include "actioninterface.h"
24 #include "blocklist.h"
27 #include "layerlist.h"
28 #include "patternlist.h"
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"
44 #include "dlgattributes.h"
45 #include "dlgcircle.h"
46 #include "dlgdimension.h"
47 #include "dlgdimlinear.h"
48 #include "dlgellipse.h"
50 #include "dlginsert.h"
52 #include "dlgmirror.h"
54 #include "dlgmoverotate.h"
55 #include "dlgoptionsdrawing.h"
56 #include "dlgoptionsgeneral.h"
58 #include "dlgrotate.h"
59 #include "dlgrotate2.h"
61 #include "dlgspline.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 "polylineoptions.h"
78 #include "printpreviewoptions.h"
79 #include "roundoptions.h"
80 #include "selectionwidget.h"
81 #include "snapdistoptions.h"
82 #include "splineoptions.h"
83 #include "textoptions.h"
84 #include "trimamountoptions.h"
87 #include "camdialog.h"
90 //QG_DialogFactory* QG_DialogFactory::uniqueInstance = NULL;
95 * @param parent Pointer to parent widget which can host dialogs.
96 * @param ow Pointer to widget that can host option widgets.
98 //QG_DialogFactory::QG_DialogFactory(QWidget * parent, QWidget * ow):
99 QG_DialogFactory::QG_DialogFactory(QWidget * parent, QToolBar * ow):
100 DialogFactoryInterface()
102 DEBUG->print("QG_DialogFactory::QG_DialogFactory");
104 this->parent = parent;
107 coordinateWidget = NULL;
109 selectionWidget = NULL;
111 commandWidget = NULL;
112 mainWindowIntf = NULL;
113 DEBUG->print("QG_DialogFactory::QG_DialogFactory: OK");
119 QG_DialogFactory::~QG_DialogFactory()
121 DEBUG->print("QG_DialogFactory::~QG_DialogFactory");
122 DEBUG->print("QG_DialogFactory::~QG_DialogFactory: OK");
126 * Links factory to a widget that can host tool options.
128 ///*virtual*/ void QG_DialogFactory::setOptionWidget(QWidget * ow)
129 /*virtual*/ void QG_DialogFactory::setOptionWidget(QToolBar * ow)
131 DEBUG->print("QG_DialogFactory::setOptionWidget");
133 DEBUG->print("QG_DialogFactory::setOptionWidget: OK");
137 * Links this dialog factory to a coordinate widget.
139 /*virtual*/ void QG_DialogFactory::setCoordinateWidget(CoordinateWidget * cw)
141 coordinateWidget = cw;
145 * Links this dialog factory to a mouse widget.
147 /*virtual*/ void QG_DialogFactory::setMouseWidget(MouseWidget * mw)
153 * Links this dialog factory to a selection widget.
155 /*virtual*/ void QG_DialogFactory::setSelectionWidget(SelectionWidget * sw)
157 selectionWidget = sw;
161 * Links this dialog factory to the cad tool bar.
163 /*virtual*/ void QG_DialogFactory::setCadToolBar(CadToolBar * ctb)
169 * @return cad tool bar or NULL.
171 CadToolBar * QG_DialogFactory::getCadToolBar()
177 * Links this dialog factory to a command widget.
179 /*virtual*/ void QG_DialogFactory::setCommandWidget(CommandWidget * cw)
185 * @return command widget or NULL.
187 CommandWidget * QG_DialogFactory::getCommandWidget()
189 return commandWidget;
193 * Links the dialog factory to a main app window.
195 /*virtual*/ void QG_DialogFactory::setMainWindow(QG_MainWindowInterface * mwi)
197 mainWindowIntf = mwi;
201 * Shows a message dialog.
203 void QG_DialogFactory::requestWarningDialog(const QString & warning)
205 QMessageBox::information(parent, QMessageBox::tr("Warning"),
206 warning, QMessageBox::Ok);
210 * Requests a new document from the main window.
212 GraphicView * QG_DialogFactory::requestNewDocument(const QString & fileName, Document * doc)
214 if (mainWindowIntf != NULL)
216 mainWindowIntf->createNewDocument(fileName, doc);
217 return mainWindowIntf->getGraphicView();
224 * Requests the simulation controls.
226 void QG_DialogFactory::requestSimulationControls()
228 if (mainWindowIntf != NULL)
230 mainWindowIntf->showSimulationControls();
235 * Shows a dialog for adding a layer. Doesn't add the layer.
236 * This is up to the caller.
238 * @return a pointer to the newly created layer that
241 Layer * QG_DialogFactory::requestNewLayerDialog(LayerList * layerList)
243 Layer * layer = NULL;
244 QString layer_name = "noname";
247 if (layerList != NULL)
249 while (layerList->find(layer_name) > 0)
250 layer_name.sprintf("noname%d", i++);
253 // Layer for parameter livery
254 layer = new Layer(layer_name);
256 // QG_LayerDialog dlg(parent, "Layer Dialog");
257 LayerDialog dlg(parent);
259 dlg.setLayerList(layerList);
273 * Shows a dialog that asks the user if the selected layer
274 * can be removed. Doesn't remove the layer. This is up to the caller.
276 * @return a pointer to the layer that should be removed.
278 Layer * QG_DialogFactory::requestLayerRemovalDialog(LayerList * layerList)
280 Layer * layer = NULL;
282 if (layerList == NULL)
284 DEBUG->print(Debug::D_WARNING,
285 "QG_DialogFactory::requestLayerRemovalDialog(): layerList is NULL");
290 if (layerList==NULL) {
291 if (container!=NULL && container->rtti()==RS2::EntityDrawing) {
292 layerList = (LayerList*)container;
298 // Layer for parameter livery
299 layer = layerList->getActive();
303 if (layer->getName() != "0")
305 int remove = QMessageBox::information(parent, QMessageBox::tr("Remove Layer"),
306 QMessageBox::tr("Layer \"%1\" and all entities on it will be removed.").arg(layer->getName()),
307 QMessageBox::Ok, QMessageBox::Cancel);
319 QMessageBox::information(parent, QMessageBox::tr("Remove Layer"),
320 QMessageBox::tr("Layer \"%1\" can never be removed.").arg(layer->getName()),
329 * Shows a dialog for editing a layer. A new layer is created and
330 * returned. Modifying the layer is up to the caller.
332 * @return A pointer to a new layer with the changed attributes
333 * or NULL if the dialog was cancelled.
335 Layer * QG_DialogFactory::requestEditLayerDialog(LayerList * layerList)
337 DEBUG->print("QG_DialogFactory::requestEditLayerDialog");
338 Layer * layer = NULL;
342 DEBUG->print(Debug::D_WARNING, "QG_DialogFactory::requestEditLayerDialog(): "
343 "layerList is NULL");
347 // Layer for parameter livery
348 if (layerList->getActive())
350 layer = new Layer(*layerList->getActive());
352 // QG_LayerDialog dlg(parent, QMessageBox::tr("Layer Dialog"));
353 LayerDialog dlg(parent);
355 dlg.setLayerList(layerList);
356 dlg.setEditLayer(true);
371 * Shows a dialog for adding a block. Doesn't add the block.
372 * This is up to the caller.
374 * @return a pointer to the newly created block that
377 BlockData QG_DialogFactory::requestNewBlockDialog(BlockList * blockList)
379 //Block* block = NULL;
381 ret = BlockData("", Vector(false), false);
383 if (blockList == NULL)
385 DEBUG->print(Debug::D_WARNING, "QG_DialogFactory::requestNewBlockDialog(): "
386 "blockList is NULL");
390 // Block for parameter livery
391 //block = new Block(container, "noname", Vector(0.0,0.0));
393 BlockDialog dlg(parent);
394 dlg.setBlockList(blockList);
397 ret = dlg.getBlockData();
403 * Shows a dialog for renaming the currently active block.
405 * @return a pointer to the modified block or NULL on cancellation.
407 BlockData QG_DialogFactory::requestBlockAttributesDialog(BlockList * blockList)
409 BlockData ret("", Vector(false), false);
410 // ret = BlockData("", Vector(false), false);
412 if (blockList == NULL)
414 DEBUG->print(Debug::D_WARNING, "QG_DialogFactory::requestBlockAttributesDialog(): "
415 "blockList is NULL");
419 BlockDialog dlg(parent);//WAS:, "Rename Block");
420 #warning "!!! WTF !!! WHY DO WE HAVE TO PREFIX tr WITH QObject:: ???"
421 dlg.setWindowTitle(QObject::tr("Rename Block"));
422 dlg.setBlockList(blockList);
426 ret = dlg.getBlockData();
432 /*virtual*/ void QG_DialogFactory::requestEditBlockWindow(BlockList * /*blockList*/)
436 /*virtual*/ void QG_DialogFactory::closeEditBlockWindow(Block * /*blockList*/)
441 * Shows a dialog that asks the user if the selected block
442 * can be removed. Doesn't remove the block. This is up to the caller.
444 * @return a pointer to the block that should be removed.
446 Block * QG_DialogFactory::requestBlockRemovalDialog(BlockList * blockList)
448 Block * block = NULL;
450 if (blockList == NULL)
452 DEBUG->print(Debug::D_WARNING, "QG_DialogFactory::requestBlockRemovalDialog(): "
453 "blockList is NULL");
457 // Block for parameter livery
458 block = blockList->getActive();
462 int remove = QMessageBox::information(parent, QMessageBox::tr("Remove Block"),
463 QMessageBox::tr("Block \"%1\" and all its entities will be removed.").arg(block->getName()),
464 QMessageBox::Ok, QMessageBox::Cancel);
479 * Shows a dialog for choosing a file name. Saving the file is up to
482 * @return File name with path and extension to determine the file type
483 * or an empty string if the dialog was cancelled.
486 QString QG_DialogFactory::requestFileSaveAsDialog() {
487 // read default settings:
488 RS_SETTINGS->beginGroup("/Paths");
489 QString defDir = RS_SETTINGS->readEntry("/Save",
490 SYSTEM->getHomeDir());
491 QString defFilter = RS_SETTINGS->readEntry("/SaveFilter",
492 "Drawing Exchange (*.dxf)");
493 RS_SETTINGS->endGroup();
495 // prepare file save as dialog:
496 QFileDialog fileDlg(this,0,true);
502 filters.append("Drawing Exchange (*.dxf)");
503 filters.append("Font (*.cxf)");
504 fileDlg.setFilters(filters);
505 fileDlg.setMode(QFileDialog::AnyFile);
506 fileDlg.setCaption(tr("Save Drawing As"));
507 fileDlg.setDir(defDir);
508 fileDlg.setSelectedFilter(defFilter);
513 if (fileDlg.exec()==QDialog::Accepted) {
514 fn = fileDlg.selectedFile();
517 // append default extension:
518 if (fn.find('.')==-1) {
519 if (fileDlg.selectedFilter()=="Font (*.cxf)") {
526 // overwrite warning:
527 if(QFileInfo(fn).exists()) {
529 QMessageBox::warning(this, tr("Save Drawing As"),
530 tr("%1 already exists.\n"
531 "Do you want to replace it?")
534 tr("Cancel"), 0, 1 );
557 // store new default settings:
559 RS_SETTINGS->beginGroup("/Paths");
560 RS_SETTINGS->writeEntry("/Save", QFileInfo(fn).dirPath(true));
561 RS_SETTINGS->writeEntry("/SaveFilter", fileDlg.selectedFilter());
562 RS_SETTINGS->endGroup();
570 * Shows a dialog for choosing a file name. Opening the file is up to
573 * @return File name with path and extension to determine the file type
574 * or an empty string if the dialog was cancelled.
576 QString QG_DialogFactory::requestImageOpenDialog()
580 // read default settings:
581 settings.beginGroup("Paths");
582 QString defDir = settings.value("OpenImage", SYSTEM->getHomeDir()).toString();
583 QString defFilter = settings.value("ImageFilter", "Portable Network Graphic (*.png)").toString();
588 // Q3FileDialog fileDlg(NULL, "", true);
589 QFileDialog fileDlg(NULL, "");
592 // Q3StrList f = QImageIO::inputFormats();
593 // QStringList formats = QStringList::fromStrList(f);
594 QList<QByteArray> f = QImageReader::supportedImageFormats();
595 QStringList formats = ???
597 #warning "Needs porting to Qt4... !!! FIX !!!"
602 //filters = QStringList::fromStrList(formats);
605 for (QStringList::Iterator it=formats.begin(); it!=formats.end(); ++it)
613 st = QString("%1 (*.%2 *.jpg)").arg(extToFormat(*it)).arg(QString(*it).lower());
617 st = QString("%1 (*.%2)").arg(extToFormat(*it)).arg(QString(*it).lower());
627 all += QString("*.%1 *.jpg").arg(QString(*it).lower());
631 all += QString("*.%1").arg(QString(*it).lower());
636 filters.append(QObject::tr("All Image Files (%1)").arg(all));
637 filters.append(QObject::tr("All Files (*.*)"));
639 //filters.append("Drawing Exchange (*.)");
640 //filters.append("Font (*.cxf)");
642 fileDlg.setFilters(filters);
643 // fileDlg.setMode(Q3FileDialog::ExistingFile);
644 fileDlg.setFileMode(QFileDialog::ExistingFile);
645 // fileDlg.setCaption(QObject::tr("Open Image"));
646 fileDlg.setWindowTitle(QObject::tr("Open Image"));
647 // fileDlg.setDir(defDir);
648 fileDlg.setDirectory(defDir);
649 // fileDlg.setSelectedFilter(defFilter);
650 fileDlg.selectFilter(defFilter);
654 if (fileDlg.exec() == QDialog::Accepted)
656 // fn = fileDlg.selectedFile();
657 QStringList files = fileDlg.selectedFiles();
659 if (!files.isEmpty())
665 // store new default settings:
668 QStringList files = fileDlg.selectedFiles();
669 QString selected = "";
671 if (!files.isEmpty())
674 settings.beginGroup("Paths");
675 // RS_SETTINGS->writeEntry("/OpenImage", QFileInfo(fn).dirPath(true));
676 settings.setValue("OpenImage", QFileInfo(fn).absolutePath());
677 settings.setValue("ImageFilter", selected);
684 void QG_DialogFactory::requestOptions(ActionInterface * action, bool on, bool update)
686 DEBUG->print("QG_DialogFactory::requestOptions");
690 DEBUG->print(Debug::D_WARNING, "QG_DialogFactory::requestOptions: action is NULL");
694 switch (action->rtti())
696 case RS2::ActionPrintPreview:
697 requestPrintPreviewOptions(action, on, update);
700 case RS2::ActionDrawLine:
701 DEBUG->print("QG_DialogFactory::requestOptions: line");
702 requestLineOptions(action, on);
703 DEBUG->print("QG_DialogFactory::requestOptions: line: OK");
706 case RS2::ActionDrawPolyline:
707 requestPolylineOptions(action, on, update);
710 case RS2::ActionDrawLineAngle:
711 requestLineAngleOptions(action, on, update);
714 case RS2::ActionDrawLineParallel:
715 requestLineParallelOptions(action, on, update);
718 case RS2::ActionDrawLineParallelThrough:
719 requestLineParallelThroughOptions(action, on, update);
722 case RS2::ActionDrawLineBisector:
723 requestLineBisectorOptions(action, on, update);
726 case RS2::ActionDrawLineRelAngle:
727 requestLineRelAngleOptions(action, on, update);
730 case RS2::ActionDrawLinePolygon:
731 requestLinePolygonOptions(action, on, update);
734 case RS2::ActionDrawLinePolygon2:
735 requestLinePolygon2Options(action, on, update);
738 case RS2::ActionDrawArc:
739 requestArcOptions(action, on, update);
742 case RS2::ActionDrawArcTangential:
743 requestArcTangentialOptions(action, on, update);
746 case RS2::ActionDrawCircleCR:
747 requestCircleOptions(action, on, update);
750 case RS2::ActionDrawSpline:
751 requestSplineOptions(action, on, update);
754 case RS2::ActionDrawText:
755 requestTextOptions(action, on, update);
758 case RS2::ActionBlocksInsert:
759 requestInsertOptions(action, on, update);
762 case RS2::ActionDrawImage:
763 requestImageOptions(action, on, update);
766 case RS2::ActionDimAligned:
767 requestDimensionOptions(action, on, update);
770 case RS2::ActionDimLinear:
771 requestDimensionOptions(action, on, update);
773 if (((ActionDimLinear *)action)->hasFixedAngle() == false)
774 requestDimLinearOptions(action, on, update);
778 case RS2::ActionDimRadial:
779 requestDimensionOptions(action, on, update);
782 case RS2::ActionDimDiametric:
783 requestDimensionOptions(action, on, update);
786 case RS2::ActionDimAngular:
787 requestDimensionOptions(action, on, update);
790 case RS2::ActionModifyTrimAmount:
791 requestTrimAmountOptions(action, on, update);
794 case RS2::ActionModifyMoveRotate:
795 requestMoveRotateOptions(action, on, update);
798 case RS2::ActionModifyBevel:
799 requestBevelOptions(action, on, update);
802 case RS2::ActionModifyRound:
803 requestRoundOptions(action, on, update);
806 case RS2::ActionLibraryInsert:
807 requestLibraryInsertOptions(action, on, update);
814 DEBUG->print("QG_DialogFactory::requestOptions: OK");
818 * Shows a widget for options for the action: "print preview"
820 void QG_DialogFactory::requestPrintPreviewOptions(ActionInterface * action, bool on, bool update)
822 static PrintPreviewOptions * toolWidget = NULL;
835 toolWidget = new PrintPreviewOptions(optionWidget);
836 toolWidget->setAction(action, update);
841 * Shows a widget for options for the action: "draw line"
843 void QG_DialogFactory::requestLineOptions(ActionInterface * action, bool on)
846 The way I see it, this is failure. We're constantly creating & deleting
847 these objects all the time when we could create them once, and then reuse
848 them over and over. May need to do some more refactoring based on this idea...
851 static LineOptions * toolWidget = NULL;
856 // Get rid of the LineOptions object if it exists...
863 // Create a new one for the passed in action
866 toolWidget = new LineOptions(optionWidget);
867 toolWidget->setAction(action);
870 DEBUG->print("QG_DialogFactory::requestLineOptions: OK");
874 * Shows a widget for options for the action: "draw polyline"
876 void QG_DialogFactory::requestPolylineOptions(ActionInterface * action, bool on, bool update)
878 static PolylineOptions * toolWidget = NULL;
891 toolWidget = new PolylineOptions(optionWidget);
892 toolWidget->setAction(action, update);
897 * Shows a widget for options for the action: "draw line parallel"
899 void QG_DialogFactory::requestLineParallelOptions(ActionInterface * action, bool on, bool update)
901 static LineParallelOptions * toolWidget = NULL;
903 if (optionWidget!=NULL)
905 if (toolWidget!=NULL)
910 if (on==true && toolWidget==NULL)
912 toolWidget = new LineParallelOptions(optionWidget);
913 toolWidget->setAction(action, update);
919 * Shows a widget for options for the action: "draw line parallel through"
921 void QG_DialogFactory::requestLineParallelThroughOptions(ActionInterface * action, bool on, bool update)
923 static LineParallelThroughOptions * toolWidget = NULL;
925 if (optionWidget!=NULL) {
926 if (toolWidget!=NULL) {
930 if (on==true && toolWidget==NULL) {
931 toolWidget = new LineParallelThroughOptions(optionWidget);
932 toolWidget->setAction(action, update);
938 * Shows a widget for options for the action: "line angle"
940 void QG_DialogFactory::requestLineAngleOptions(ActionInterface * action, bool on, bool update)
942 static LineAngleOptions * toolWidget = NULL;
955 toolWidget = new LineAngleOptions(optionWidget);
956 toolWidget->setAction(action, update);
961 * Shows a widget for options for the action: "line relative angle"
963 void QG_DialogFactory::requestLineRelAngleOptions(ActionInterface * action, bool on, bool update)
965 static LineRelAngleOptions * toolWidget = NULL;
978 toolWidget = new LineRelAngleOptions(optionWidget);
979 toolWidget->setAction(action, update);
984 * Shows a widget for options for the action: "line angle"
986 void QG_DialogFactory::requestLineBisectorOptions(ActionInterface * action, bool on, bool update)
988 static LineBisectorOptions * toolWidget = NULL;
990 if (optionWidget!=NULL) {
991 if (toolWidget!=NULL) {
995 if (on==true && toolWidget==NULL) {
996 toolWidget = new LineBisectorOptions(optionWidget);
997 toolWidget->setAction(action, update);
1003 * Shows a widget for options for the action: "draw polygon"
1005 void QG_DialogFactory::requestLinePolygonOptions(ActionInterface * action, bool on, bool update)
1007 static LinePolygonOptions * toolWidget = NULL;
1009 if (optionWidget!=NULL) {
1010 if (toolWidget!=NULL) {
1014 if (on==true && toolWidget==NULL) {
1015 toolWidget = new LinePolygonOptions(optionWidget);
1016 toolWidget->setAction(action, update);
1022 * Shows a widget for options for the action: "draw polygon2"
1024 void QG_DialogFactory::requestLinePolygon2Options(ActionInterface * action, bool on, bool update)
1026 static LinePolygon2Options * toolWidget = NULL;
1028 if (optionWidget!=NULL) {
1029 if (toolWidget!=NULL) {
1033 if (on==true && toolWidget==NULL) {
1034 toolWidget = new LinePolygon2Options(optionWidget);
1035 toolWidget->setAction(action, update);
1041 * Shows a widget for arc options.
1043 void QG_DialogFactory::requestArcOptions(ActionInterface * action, bool on, bool update)
1045 static ArcOptions * toolWidget = NULL;
1047 if (optionWidget != NULL)
1049 if (toolWidget != NULL)
1055 if (on && toolWidget == NULL)
1057 toolWidget = new ArcOptions(optionWidget);
1058 toolWidget->setAction(action, update);
1059 //toolWidget->setData(&data);
1065 * Shows a widget for tangential arc options.
1067 void QG_DialogFactory::requestArcTangentialOptions(ActionInterface * action, bool on, bool update)
1069 static ArcTangentialOptions * toolWidget = NULL;
1082 toolWidget = new ArcTangentialOptions(optionWidget);
1083 toolWidget->setAction(action, update);
1084 //toolWidget->setData(&data);
1089 * Shows a widget for circle options.
1091 void QG_DialogFactory::requestCircleOptions(ActionInterface * action, bool on, bool update)
1093 static CircleOptions * toolWidget = NULL;
1103 if (on && toolWidget == NULL)
1105 toolWidget = new CircleOptions(optionWidget);
1106 toolWidget->setAction(action, update);
1112 * Shows a widget for spline options.
1114 void QG_DialogFactory::requestSplineOptions(ActionInterface * action, bool on, bool update)
1116 static SplineOptions * toolWidget = NULL;
1129 toolWidget = new SplineOptions(optionWidget);
1130 toolWidget->setAction(action, update);
1135 * Shows a widget for text options.
1137 void QG_DialogFactory::requestTextOptions(ActionInterface * action, bool on, bool update)
1139 static TextOptions * toolWidget = NULL;
1152 toolWidget = new TextOptions(optionWidget);
1153 toolWidget->setAction(action, update);
1158 * Shows a widget for insert options.
1160 void QG_DialogFactory::requestInsertOptions(ActionInterface * action, bool on, bool update)
1162 static InsertOptions * toolWidget = NULL;
1164 if (optionWidget!=NULL) {
1165 if (toolWidget!=NULL) {
1169 if (on==true && toolWidget==NULL) {
1170 toolWidget = new InsertOptions(optionWidget);
1171 toolWidget->setAction(action, update);
1177 * Shows a widget for image options.
1179 void QG_DialogFactory::requestImageOptions(ActionInterface * action, bool on, bool update)
1181 static ImageOptions * toolWidget = NULL;
1183 if (optionWidget!=NULL) {
1184 if (toolWidget!=NULL) {
1188 if (on==true && toolWidget==NULL) {
1189 toolWidget = new ImageOptions(optionWidget);
1190 toolWidget->setAction(action, update);
1196 * Shows a widget for dimension options.
1198 void QG_DialogFactory::requestDimensionOptions(ActionInterface * action, bool on, bool update)
1200 static DimOptions * toolWidget = NULL;
1202 if (optionWidget!=NULL) {
1203 if (toolWidget!=NULL) {
1207 if (on==true && toolWidget==NULL) {
1208 toolWidget = new DimOptions(optionWidget);
1209 toolWidget->setAction(action, update);
1215 * Shows a widget for linear dimension options.
1217 void QG_DialogFactory::requestDimLinearOptions(ActionInterface * action, bool on, bool update)
1219 static DimLinearOptions * toolWidget = NULL;
1232 toolWidget = new DimLinearOptions(optionWidget);
1233 toolWidget->setAction(action, update);
1238 * Shows a widget for 'snap to a point with a given distance' options.
1240 void QG_DialogFactory::requestSnapDistOptions(double & dist, bool on)
1242 static SnapDistOptions * toolWidget = NULL;
1255 toolWidget = new SnapDistOptions(optionWidget);
1256 toolWidget->setDist(&dist);
1261 * Shows a widget for 'snap to a point with a given distance' options.
1263 void QG_DialogFactory::requestMoveRotateOptions(ActionInterface * action, bool on, bool update)
1265 static MoveRotateOptions * toolWidget = NULL;
1278 toolWidget = new MoveRotateOptions(optionWidget);
1279 toolWidget->setAction(action, update);
1284 * Shows a widget for 'trim amount' options.
1286 void QG_DialogFactory::requestTrimAmountOptions(ActionInterface * action, bool on, bool update)
1288 static TrimAmountOptions * toolWidget = NULL;
1301 toolWidget = new TrimAmountOptions(optionWidget);
1302 toolWidget->setAction(action, update);
1307 * Shows a widget for beveling options.
1309 void QG_DialogFactory::requestBevelOptions(ActionInterface * action, bool on, bool update)
1311 static BevelOptions * toolWidget = NULL;
1313 if (optionWidget != NULL)
1315 if (toolWidget != NULL)
1321 if (on && toolWidget == NULL)
1323 toolWidget = new BevelOptions(optionWidget);
1324 toolWidget->setAction(action, update);
1330 * Shows a widget for rounding options.
1332 void QG_DialogFactory::requestRoundOptions(ActionInterface * action, bool on, bool update)
1334 static RoundOptions * toolWidget = NULL;
1347 toolWidget = new RoundOptions(optionWidget);
1348 toolWidget->setAction(action, update);
1353 * Shows a widget for library insert options.
1355 void QG_DialogFactory::requestLibraryInsertOptions(ActionInterface * action, bool on, bool update)
1357 static LibraryInsertOptions * toolWidget = NULL;
1370 toolWidget = new LibraryInsertOptions(optionWidget);
1371 toolWidget->setAction(action, update);
1376 * Shows the given toolbar.
1378 void QG_DialogFactory::requestToolBar(RS2::ToolBarId id)
1381 cadToolBar->showToolBar(id);
1385 * Shows the select toolbar with the given action to launch.
1387 void QG_DialogFactory::requestToolBarSelect(ActionInterface * selectAction,
1388 RS2::ActionType nextAction)
1390 if (cadToolBar != NULL)
1391 cadToolBar->showToolBarSelect(selectAction, nextAction);
1395 * Shows a dialog to edit the attributes of the given dimension entity.
1398 bool QG_DialogFactory::requestDimAlignedDialog(DimAligned* dim) {
1403 QG_DlgDimAligned dlg(parent);
1404 dlg.setDim(*dim, true);
1415 * Shows attributes options dialog presenting the given data.
1417 bool QG_DialogFactory::requestAttributesDialog(AttributesData & data, LayerList & layerList)
1419 DlgAttributes dlg(parent);
1420 dlg.setData(&data, layerList);
1432 * Shows move options dialog presenting the given data.
1434 bool QG_DialogFactory::requestMoveDialog(MoveData & data)
1436 DlgMove dlg(parent);
1449 * Shows rotate options dialog presenting the given data.
1451 bool QG_DialogFactory::requestRotateDialog(RotateData & data)
1453 DlgRotate dlg(parent);
1466 * Shows scale options dialog presenting the given data.
1468 bool QG_DialogFactory::requestScaleDialog(ScaleData & data)
1470 DlgScale dlg(parent);
1483 * Shows mirror options dialog presenting the given data.
1485 bool QG_DialogFactory::requestMirrorDialog(MirrorData & data)
1487 DlgMirror dlg(parent);
1500 * Shows move/rotate options dialog presenting the given data.
1502 bool QG_DialogFactory::requestMoveRotateDialog(MoveRotateData & data)
1504 DlgMoveRotate dlg(parent);
1517 * Shows rotate around two centers options dialog presenting the given data.
1519 bool QG_DialogFactory::requestRotate2Dialog(Rotate2Data & data)
1521 DlgRotate2 dlg(parent);
1534 * Shows a dialog to edit the given entity.
1536 bool QG_DialogFactory::requestModifyEntityDialog(Entity * entity)
1543 switch (entity->rtti())
1545 case RS2::EntityPoint:
1547 DlgPoint dlg(parent);
1548 dlg.setPoint(*((Point *)entity));
1558 case RS2::EntityLine:
1560 DlgLine dlg(parent);
1561 dlg.setLine(*((Line *)entity));
1571 case RS2::EntityArc:
1574 dlg.setArc(*((Arc *)entity));
1584 case RS2::EntityCircle:
1586 DlgCircle dlg(parent);
1587 dlg.setCircle(*((Circle *)entity));
1597 case RS2::EntityEllipse:
1599 DlgEllipse dlg(parent);
1600 dlg.setEllipse(*((Ellipse *)entity));
1604 dlg.updateEllipse();
1610 case RS2::EntitySpline:
1612 DlgSpline dlg(parent);
1613 dlg.setSpline(*((Spline *)entity));
1623 case RS2::EntityInsert:
1625 DlgInsert dlg(parent);
1626 dlg.setInsert(*((Insert *)entity));
1637 case RS2::EntityDimAligned:
1638 case RS2::EntityDimAngular:
1639 case RS2::EntityDimDiametric:
1640 case RS2::EntityDimRadial:
1642 DlgDimension dlg(parent);
1643 dlg.setDim(*((Dimension *)entity));
1649 ((Dimension *)entity)->update(true);
1654 case RS2::EntityDimLinear:
1656 DlgDimLinear dlg(parent);
1657 dlg.setDim(*((DimLinear *)entity));
1663 ((DimLinear *)entity)->update(true);
1668 case RS2::EntityText:
1670 DlgText dlg(parent);
1671 dlg.setText(*((Text *)entity), false);
1677 ((Text *)entity)->update();
1682 case RS2::EntityHatch:
1684 DlgHatch dlg(parent);
1685 dlg.setHatch(*((Hatch *)entity), false);
1691 ((Hatch *)entity)->update();
1704 bool QG_DialogFactory::requestDimAlignedDialog(DimAligned* dim) {
1710 * Shows a dialog to edit the attributes of the given text entity.
1712 bool QG_DialogFactory::requestTextDialog(Text * text)
1717 DlgText dlg(parent);
1718 dlg.setText(*text, true);
1730 * Shows a dialog to edit pattern / hatch attributes of the given entity.
1732 bool QG_DialogFactory::requestHatchDialog(Hatch * hatch)
1737 PATTERNLIST->init();
1739 DlgHatch dlg(parent);
1740 dlg.setHatch(*hatch, true);
1753 * Shows a dialog for CAM options.
1755 bool QG_DialogFactory::requestCamOptionsDialog(Drawing& graphic)
1757 DEBUG->print("QG_DialogFactory::requestCamOptionsDialog");
1758 RS_CamDialog dlg(graphic, parent);
1759 DEBUG->print("QG_DialogFactory::requestCamOptionsDialog: exec");
1763 DEBUG->print("QG_DialogFactory::requestCamOptionsDialog: OK");
1767 DEBUG->print("QG_DialogFactory::requestCamOptionsDialog: Cancel");
1773 * Shows dialog for general application options.
1775 void QG_DialogFactory::requestOptionsGeneralDialog()
1777 DlgOptionsGeneral dlg(parent);
1782 * Shows dialog for drawing options.
1784 void QG_DialogFactory::requestOptionsDrawingDialog(Drawing & graphic)
1786 DlgOptionsDrawing dlg(parent);
1787 dlg.setGraphic(&graphic);
1792 * Back to last menu in cad toolbar.
1794 void QG_DialogFactory::requestPreviousMenu()
1796 if (cadToolBar != NULL)
1797 cadToolBar->showToolBarMain();
1801 * Called whenever the mouse position changed.
1803 void QG_DialogFactory::updateCoordinateWidget(const Vector & abs,
1804 const Vector & rel, bool updateFormat)
1806 if (coordinateWidget != NULL)
1807 coordinateWidget->setCoordinates(abs, rel, updateFormat);
1811 * Called when an action has a mouse hint.
1813 void QG_DialogFactory::updateMouseWidget(const QString & left, const QString & right)
1816 mouseWidget->setHelp(left, right);
1819 commandWidget->setCommand(left);
1823 * Called whenever the selection changed.
1825 void QG_DialogFactory::updateSelectionWidget(int num)
1827 if (selectionWidget != NULL)
1828 selectionWidget->setNumber(num);
1832 * Called when an action needs to communicate 'message' to the user.
1834 void QG_DialogFactory::commandMessage(const QString& message)
1836 DEBUG->print("QG_DialogFactory::commandMessage");
1838 if (commandWidget != NULL)
1839 commandWidget->appendHistory(message);
1841 DEBUG->print("QG_DialogFactory::commandMessage: OK");
1844 /*virtual*/ bool QG_DialogFactory::isAdapter()
1850 * Converts an extension to a format description.
1851 * e.g. "PNG" to "Portable Network Graphic"
1854 * @return Format description
1856 QString QG_DialogFactory::extToFormat(const QString & ext)
1858 QString e = ext.toLower();
1861 return QObject::tr("Windows Bitmap");
1862 else if (e == "jpeg" || e == "jpg")
1863 return QObject::tr("Joint Photographic Experts Group");
1864 else if (e == "gif")
1865 return QObject::tr("Graphics Interchange Format");
1866 else if (e == "mng")
1867 return QObject::tr("Multiple-image Network Graphics");
1868 else if (e == "pbm")
1869 return QObject::tr("Portable Bit Map");
1870 else if (e == "pgm")
1871 return QObject::tr("Portable Grey Map");
1872 else if (e == "png")
1873 return QObject::tr("Portable Network Graphic");
1874 else if (e == "ppm")
1875 return QObject::tr("Portable Pixel Map");
1876 else if (e == "xbm")
1877 return QObject::tr("X Bitmap Format");
1878 else if (e == "xpm")
1879 return QObject::tr("X Pixel Map");
1881 return ext.toUpper();