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;
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 * mw)
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 (mainWindow != NULL)
216 mainWindow->createNewDocument(fileName, doc);
217 return mainWindow->getGraphicView();
224 * Requests the simulation controls.
226 void QG_DialogFactory::requestSimulationControls()
228 if (mainWindow != NULL)
230 mainWindow->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::EntityGraphic) {
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 //Block* block = NULL;
411 ret = BlockData("", Vector(false), false);
413 if (blockList == NULL)
415 DEBUG->print(Debug::D_WARNING, "QG_DialogFactory::requestBlockAttributesDialog(): "
416 "blockList is NULL");
420 if (blockList==NULL) {
421 if (container!=NULL && container->rtti()==RS2::EntityGraphic) {
422 blockList = (BlockList*)container;
428 // Block for parameter livery
429 //block = blockList->getActive();
431 BlockDialog dlg(parent);//WAS:, "Rename Block");
432 #warning "!!! WTF !!! WHY DO WE HAVE TO PREFIX tr WITH QObject:: ???"
433 dlg.setWindowTitle(QObject::tr("Rename Block"));
434 dlg.setBlockList(blockList);
440 ret = dlg.getBlockData();
443 // ret = BlockData("", Vector(false));
449 /*virtual*/ void QG_DialogFactory::requestEditBlockWindow(BlockList * /*blockList*/)
453 /*virtual*/ void QG_DialogFactory::closeEditBlockWindow(Block * /*blockList*/)
458 * Shows a dialog that asks the user if the selected block
459 * can be removed. Doesn't remove the block. This is up to the caller.
461 * @return a pointer to the block that should be removed.
463 Block * QG_DialogFactory::requestBlockRemovalDialog(BlockList * blockList)
465 Block * block = NULL;
467 if (blockList == NULL)
469 DEBUG->print(Debug::D_WARNING, "QG_DialogFactory::requestBlockRemovalDialog(): "
470 "blockList is NULL");
474 // Block for parameter livery
475 block = blockList->getActive();
479 int remove = QMessageBox::information(parent, QMessageBox::tr("Remove Block"),
480 QMessageBox::tr("Block \"%1\" and all its entities will be removed.").arg(block->getName()),
481 QMessageBox::Ok, QMessageBox::Cancel);
496 * Shows a dialog for choosing a file name. Saving the file is up to
499 * @return File name with path and extension to determine the file type
500 * or an empty string if the dialog was cancelled.
503 QString QG_DialogFactory::requestFileSaveAsDialog() {
504 // read default settings:
505 RS_SETTINGS->beginGroup("/Paths");
506 QString defDir = RS_SETTINGS->readEntry("/Save",
507 SYSTEM->getHomeDir());
508 QString defFilter = RS_SETTINGS->readEntry("/SaveFilter",
509 "Drawing Exchange (*.dxf)");
510 RS_SETTINGS->endGroup();
512 // prepare file save as dialog:
513 QFileDialog fileDlg(this,0,true);
519 filters.append("Drawing Exchange (*.dxf)");
520 filters.append("Font (*.cxf)");
521 fileDlg.setFilters(filters);
522 fileDlg.setMode(QFileDialog::AnyFile);
523 fileDlg.setCaption(tr("Save Drawing As"));
524 fileDlg.setDir(defDir);
525 fileDlg.setSelectedFilter(defFilter);
530 if (fileDlg.exec()==QDialog::Accepted) {
531 fn = fileDlg.selectedFile();
534 // append default extension:
535 if (fn.find('.')==-1) {
536 if (fileDlg.selectedFilter()=="Font (*.cxf)") {
543 // overwrite warning:
544 if(QFileInfo(fn).exists()) {
546 QMessageBox::warning(this, tr("Save Drawing As"),
547 tr("%1 already exists.\n"
548 "Do you want to replace it?")
551 tr("Cancel"), 0, 1 );
574 // store new default settings:
576 RS_SETTINGS->beginGroup("/Paths");
577 RS_SETTINGS->writeEntry("/Save", QFileInfo(fn).dirPath(true));
578 RS_SETTINGS->writeEntry("/SaveFilter", fileDlg.selectedFilter());
579 RS_SETTINGS->endGroup();
587 * Shows a dialog for choosing a file name. Opening the file is up to
590 * @return File name with path and extension to determine the file type
591 * or an empty string if the dialog was cancelled.
593 QString QG_DialogFactory::requestImageOpenDialog()
597 // read default settings:
598 settings.beginGroup("Paths");
599 QString defDir = settings.value("OpenImage", SYSTEM->getHomeDir()).toString();
600 QString defFilter = settings.value("ImageFilter", "Portable Network Graphic (*.png)").toString();
605 // Q3FileDialog fileDlg(NULL, "", true);
606 QFileDialog fileDlg(NULL, "");
609 // Q3StrList f = QImageIO::inputFormats();
610 // QStringList formats = QStringList::fromStrList(f);
611 QList<QByteArray> f = QImageReader::supportedImageFormats();
612 QStringList formats = ???
614 #warning "Needs porting to Qt4... !!! FIX !!!"
619 //filters = QStringList::fromStrList(formats);
622 for (QStringList::Iterator it=formats.begin(); it!=formats.end(); ++it)
630 st = QString("%1 (*.%2 *.jpg)").arg(extToFormat(*it)).arg(QString(*it).lower());
634 st = QString("%1 (*.%2)").arg(extToFormat(*it)).arg(QString(*it).lower());
644 all += QString("*.%1 *.jpg").arg(QString(*it).lower());
648 all += QString("*.%1").arg(QString(*it).lower());
653 filters.append(QObject::tr("All Image Files (%1)").arg(all));
654 filters.append(QObject::tr("All Files (*.*)"));
656 //filters.append("Drawing Exchange (*.)");
657 //filters.append("Font (*.cxf)");
659 fileDlg.setFilters(filters);
660 // fileDlg.setMode(Q3FileDialog::ExistingFile);
661 fileDlg.setFileMode(QFileDialog::ExistingFile);
662 // fileDlg.setCaption(QObject::tr("Open Image"));
663 fileDlg.setWindowTitle(QObject::tr("Open Image"));
664 // fileDlg.setDir(defDir);
665 fileDlg.setDirectory(defDir);
666 // fileDlg.setSelectedFilter(defFilter);
667 fileDlg.selectFilter(defFilter);
671 if (fileDlg.exec() == QDialog::Accepted)
673 // fn = fileDlg.selectedFile();
674 QStringList files = fileDlg.selectedFiles();
676 if (!files.isEmpty())
682 // store new default settings:
685 QStringList files = fileDlg.selectedFiles();
686 QString selected = "";
688 if (!files.isEmpty())
691 settings.beginGroup("Paths");
692 // RS_SETTINGS->writeEntry("/OpenImage", QFileInfo(fn).dirPath(true));
693 settings.setValue("OpenImage", QFileInfo(fn).absolutePath());
694 settings.setValue("ImageFilter", selected);
701 void QG_DialogFactory::requestOptions(ActionInterface * action, bool on, bool update)
703 DEBUG->print("QG_DialogFactory::requestOptions");
707 DEBUG->print(Debug::D_WARNING, "QG_DialogFactory::requestOptions: action is NULL");
711 switch (action->rtti())
713 case RS2::ActionPrintPreview:
714 requestPrintPreviewOptions(action, on, update);
717 case RS2::ActionDrawLine:
718 DEBUG->print("QG_DialogFactory::requestOptions: line");
719 requestLineOptions(action, on);
720 DEBUG->print("QG_DialogFactory::requestOptions: line: OK");
723 case RS2::ActionDrawPolyline:
724 requestPolylineOptions(action, on, update);
727 case RS2::ActionDrawLineAngle:
728 requestLineAngleOptions(action, on, update);
731 case RS2::ActionDrawLineParallel:
732 requestLineParallelOptions(action, on, update);
735 case RS2::ActionDrawLineParallelThrough:
736 requestLineParallelThroughOptions(action, on, update);
739 case RS2::ActionDrawLineBisector:
740 requestLineBisectorOptions(action, on, update);
743 case RS2::ActionDrawLineRelAngle:
744 requestLineRelAngleOptions(action, on, update);
747 case RS2::ActionDrawLinePolygon:
748 requestLinePolygonOptions(action, on, update);
751 case RS2::ActionDrawLinePolygon2:
752 requestLinePolygon2Options(action, on, update);
755 case RS2::ActionDrawArc:
756 requestArcOptions(action, on, update);
759 case RS2::ActionDrawArcTangential:
760 requestArcTangentialOptions(action, on, update);
763 case RS2::ActionDrawCircleCR:
764 requestCircleOptions(action, on, update);
767 case RS2::ActionDrawSpline:
768 requestSplineOptions(action, on, update);
771 case RS2::ActionDrawText:
772 requestTextOptions(action, on, update);
775 case RS2::ActionBlocksInsert:
776 requestInsertOptions(action, on, update);
779 case RS2::ActionDrawImage:
780 requestImageOptions(action, on, update);
783 case RS2::ActionDimAligned:
784 requestDimensionOptions(action, on, update);
787 case RS2::ActionDimLinear:
788 requestDimensionOptions(action, on, update);
790 if (((ActionDimLinear *)action)->hasFixedAngle() == false)
791 requestDimLinearOptions(action, on, update);
795 case RS2::ActionDimRadial:
796 requestDimensionOptions(action, on, update);
799 case RS2::ActionDimDiametric:
800 requestDimensionOptions(action, on, update);
803 case RS2::ActionDimAngular:
804 requestDimensionOptions(action, on, update);
807 case RS2::ActionModifyTrimAmount:
808 requestTrimAmountOptions(action, on, update);
811 case RS2::ActionModifyMoveRotate:
812 requestMoveRotateOptions(action, on, update);
815 case RS2::ActionModifyBevel:
816 requestBevelOptions(action, on, update);
819 case RS2::ActionModifyRound:
820 requestRoundOptions(action, on, update);
823 case RS2::ActionLibraryInsert:
824 requestLibraryInsertOptions(action, on, update);
831 DEBUG->print("QG_DialogFactory::requestOptions: OK");
835 * Shows a widget for options for the action: "print preview"
837 void QG_DialogFactory::requestPrintPreviewOptions(ActionInterface * action, bool on, bool update)
839 static PrintPreviewOptions * toolWidget = NULL;
852 toolWidget = new PrintPreviewOptions(optionWidget);
853 toolWidget->setAction(action, update);
858 * Shows a widget for options for the action: "draw line"
860 void QG_DialogFactory::requestLineOptions(ActionInterface * action, bool on)
863 The way I see it, this is failure. We're constantly creating & deleting
864 these objects all the time when we could create them once, and then reuse
865 them over and over. May need to do some more refactoring based on this idea...
868 static LineOptions * toolWidget = NULL;
873 // Get rid of the LineOptions object if it exists...
880 // Create a new one for the passed in action
883 toolWidget = new LineOptions(optionWidget);
884 toolWidget->setAction(action);
887 DEBUG->print("QG_DialogFactory::requestLineOptions: OK");
891 * Shows a widget for options for the action: "draw polyline"
893 void QG_DialogFactory::requestPolylineOptions(ActionInterface * action, bool on, bool update)
895 static PolylineOptions * toolWidget = NULL;
908 toolWidget = new PolylineOptions(optionWidget);
909 toolWidget->setAction(action, update);
914 * Shows a widget for options for the action: "draw line parallel"
916 void QG_DialogFactory::requestLineParallelOptions(ActionInterface * action, bool on, bool update)
918 static LineParallelOptions * toolWidget = NULL;
920 if (optionWidget!=NULL)
922 if (toolWidget!=NULL)
927 if (on==true && toolWidget==NULL)
929 toolWidget = new LineParallelOptions(optionWidget);
930 toolWidget->setAction(action, update);
936 * Shows a widget for options for the action: "draw line parallel through"
938 void QG_DialogFactory::requestLineParallelThroughOptions(ActionInterface * action, bool on, bool update)
940 static LineParallelThroughOptions * toolWidget = NULL;
942 if (optionWidget!=NULL) {
943 if (toolWidget!=NULL) {
947 if (on==true && toolWidget==NULL) {
948 toolWidget = new LineParallelThroughOptions(optionWidget);
949 toolWidget->setAction(action, update);
955 * Shows a widget for options for the action: "line angle"
957 void QG_DialogFactory::requestLineAngleOptions(ActionInterface * action, bool on, bool update)
959 static LineAngleOptions * toolWidget = NULL;
972 toolWidget = new LineAngleOptions(optionWidget);
973 toolWidget->setAction(action, update);
978 * Shows a widget for options for the action: "line relative angle"
980 void QG_DialogFactory::requestLineRelAngleOptions(ActionInterface * action, bool on, bool update)
982 static LineRelAngleOptions * toolWidget = NULL;
995 toolWidget = new LineRelAngleOptions(optionWidget);
996 toolWidget->setAction(action, update);
1001 * Shows a widget for options for the action: "line angle"
1003 void QG_DialogFactory::requestLineBisectorOptions(ActionInterface * action, bool on, bool update)
1005 static LineBisectorOptions * toolWidget = NULL;
1007 if (optionWidget!=NULL) {
1008 if (toolWidget!=NULL) {
1012 if (on==true && toolWidget==NULL) {
1013 toolWidget = new LineBisectorOptions(optionWidget);
1014 toolWidget->setAction(action, update);
1020 * Shows a widget for options for the action: "draw polygon"
1022 void QG_DialogFactory::requestLinePolygonOptions(ActionInterface * action, bool on, bool update)
1024 static LinePolygonOptions * toolWidget = NULL;
1026 if (optionWidget!=NULL) {
1027 if (toolWidget!=NULL) {
1031 if (on==true && toolWidget==NULL) {
1032 toolWidget = new LinePolygonOptions(optionWidget);
1033 toolWidget->setAction(action, update);
1039 * Shows a widget for options for the action: "draw polygon2"
1041 void QG_DialogFactory::requestLinePolygon2Options(ActionInterface * action, bool on, bool update)
1043 static LinePolygon2Options * toolWidget = NULL;
1045 if (optionWidget!=NULL) {
1046 if (toolWidget!=NULL) {
1050 if (on==true && toolWidget==NULL) {
1051 toolWidget = new LinePolygon2Options(optionWidget);
1052 toolWidget->setAction(action, update);
1058 * Shows a widget for arc options.
1060 void QG_DialogFactory::requestArcOptions(ActionInterface * action, bool on, bool update)
1062 static ArcOptions * toolWidget = NULL;
1064 if (optionWidget != NULL)
1066 if (toolWidget != NULL)
1072 if (on && toolWidget == NULL)
1074 toolWidget = new ArcOptions(optionWidget);
1075 toolWidget->setAction(action, update);
1076 //toolWidget->setData(&data);
1082 * Shows a widget for tangential arc options.
1084 void QG_DialogFactory::requestArcTangentialOptions(ActionInterface * action, bool on, bool update)
1086 static ArcTangentialOptions * toolWidget = NULL;
1099 toolWidget = new ArcTangentialOptions(optionWidget);
1100 toolWidget->setAction(action, update);
1101 //toolWidget->setData(&data);
1106 * Shows a widget for circle options.
1108 void QG_DialogFactory::requestCircleOptions(ActionInterface * action, bool on, bool update)
1110 static CircleOptions * toolWidget = NULL;
1120 if (on && toolWidget == NULL)
1122 toolWidget = new CircleOptions(optionWidget);
1123 toolWidget->setAction(action, update);
1129 * Shows a widget for spline options.
1131 void QG_DialogFactory::requestSplineOptions(ActionInterface * action, bool on, bool update)
1133 static SplineOptions * toolWidget = NULL;
1146 toolWidget = new SplineOptions(optionWidget);
1147 toolWidget->setAction(action, update);
1152 * Shows a widget for text options.
1154 void QG_DialogFactory::requestTextOptions(ActionInterface * action, bool on, bool update)
1156 static TextOptions * toolWidget = NULL;
1169 toolWidget = new TextOptions(optionWidget);
1170 toolWidget->setAction(action, update);
1175 * Shows a widget for insert options.
1177 void QG_DialogFactory::requestInsertOptions(ActionInterface * action, bool on, bool update)
1179 static InsertOptions * toolWidget = NULL;
1181 if (optionWidget!=NULL) {
1182 if (toolWidget!=NULL) {
1186 if (on==true && toolWidget==NULL) {
1187 toolWidget = new InsertOptions(optionWidget);
1188 toolWidget->setAction(action, update);
1194 * Shows a widget for image options.
1196 void QG_DialogFactory::requestImageOptions(ActionInterface * action, bool on, bool update)
1198 static ImageOptions * toolWidget = NULL;
1200 if (optionWidget!=NULL) {
1201 if (toolWidget!=NULL) {
1205 if (on==true && toolWidget==NULL) {
1206 toolWidget = new ImageOptions(optionWidget);
1207 toolWidget->setAction(action, update);
1213 * Shows a widget for dimension options.
1215 void QG_DialogFactory::requestDimensionOptions(ActionInterface * action, bool on, bool update)
1217 static DimOptions * toolWidget = NULL;
1219 if (optionWidget!=NULL) {
1220 if (toolWidget!=NULL) {
1224 if (on==true && toolWidget==NULL) {
1225 toolWidget = new DimOptions(optionWidget);
1226 toolWidget->setAction(action, update);
1232 * Shows a widget for linear dimension options.
1234 void QG_DialogFactory::requestDimLinearOptions(ActionInterface * action, bool on, bool update)
1236 static DimLinearOptions * toolWidget = NULL;
1249 toolWidget = new DimLinearOptions(optionWidget);
1250 toolWidget->setAction(action, update);
1255 * Shows a widget for 'snap to a point with a given distance' options.
1257 void QG_DialogFactory::requestSnapDistOptions(double & dist, bool on)
1259 static SnapDistOptions * toolWidget = NULL;
1272 toolWidget = new SnapDistOptions(optionWidget);
1273 toolWidget->setDist(&dist);
1278 * Shows a widget for 'snap to a point with a given distance' options.
1280 void QG_DialogFactory::requestMoveRotateOptions(ActionInterface * action, bool on, bool update)
1282 static MoveRotateOptions * toolWidget = NULL;
1295 toolWidget = new MoveRotateOptions(optionWidget);
1296 toolWidget->setAction(action, update);
1301 * Shows a widget for 'trim amount' options.
1303 void QG_DialogFactory::requestTrimAmountOptions(ActionInterface * action, bool on, bool update)
1305 static TrimAmountOptions * toolWidget = NULL;
1318 toolWidget = new TrimAmountOptions(optionWidget);
1319 toolWidget->setAction(action, update);
1324 * Shows a widget for beveling options.
1326 void QG_DialogFactory::requestBevelOptions(ActionInterface * action, bool on, bool update)
1328 static BevelOptions * toolWidget = NULL;
1330 if (optionWidget != NULL)
1332 if (toolWidget != NULL)
1338 if (on && toolWidget == NULL)
1340 toolWidget = new BevelOptions(optionWidget);
1341 toolWidget->setAction(action, update);
1347 * Shows a widget for rounding options.
1349 void QG_DialogFactory::requestRoundOptions(ActionInterface * action, bool on, bool update)
1351 static RoundOptions * toolWidget = NULL;
1364 toolWidget = new RoundOptions(optionWidget);
1365 toolWidget->setAction(action, update);
1370 * Shows a widget for library insert options.
1372 void QG_DialogFactory::requestLibraryInsertOptions(ActionInterface * action, bool on, bool update)
1374 static LibraryInsertOptions * toolWidget = NULL;
1387 toolWidget = new LibraryInsertOptions(optionWidget);
1388 toolWidget->setAction(action, update);
1393 * Shows the given toolbar.
1395 void QG_DialogFactory::requestToolBar(RS2::ToolBarId id)
1398 cadToolBar->showToolBar(id);
1402 * Shows the select toolbar with the given action to launch.
1404 void QG_DialogFactory::requestToolBarSelect(ActionInterface * selectAction,
1405 RS2::ActionType nextAction)
1407 if (cadToolBar != NULL)
1408 cadToolBar->showToolBarSelect(selectAction, nextAction);
1412 * Shows a dialog to edit the attributes of the given dimension entity.
1415 bool QG_DialogFactory::requestDimAlignedDialog(DimAligned* dim) {
1420 QG_DlgDimAligned dlg(parent);
1421 dlg.setDim(*dim, true);
1432 * Shows attributes options dialog presenting the given data.
1434 bool QG_DialogFactory::requestAttributesDialog(AttributesData & data, LayerList & layerList)
1436 DlgAttributes dlg(parent);
1437 dlg.setData(&data, layerList);
1449 * Shows move options dialog presenting the given data.
1451 bool QG_DialogFactory::requestMoveDialog(MoveData & data)
1453 DlgMove dlg(parent);
1466 * Shows rotate options dialog presenting the given data.
1468 bool QG_DialogFactory::requestRotateDialog(RotateData & data)
1470 DlgRotate dlg(parent);
1483 * Shows scale options dialog presenting the given data.
1485 bool QG_DialogFactory::requestScaleDialog(ScaleData & data)
1487 DlgScale dlg(parent);
1500 * Shows mirror options dialog presenting the given data.
1502 bool QG_DialogFactory::requestMirrorDialog(MirrorData & data)
1504 DlgMirror dlg(parent);
1517 * Shows move/rotate options dialog presenting the given data.
1519 bool QG_DialogFactory::requestMoveRotateDialog(MoveRotateData & data)
1521 DlgMoveRotate dlg(parent);
1534 * Shows rotate around two centers options dialog presenting the given data.
1536 bool QG_DialogFactory::requestRotate2Dialog(Rotate2Data & data)
1538 DlgRotate2 dlg(parent);
1551 * Shows a dialog to edit the given entity.
1553 bool QG_DialogFactory::requestModifyEntityDialog(Entity * entity)
1560 switch (entity->rtti())
1562 case RS2::EntityPoint:
1564 DlgPoint dlg(parent);
1565 dlg.setPoint(*((Point *)entity));
1575 case RS2::EntityLine:
1577 DlgLine dlg(parent);
1578 dlg.setLine(*((Line *)entity));
1588 case RS2::EntityArc:
1591 dlg.setArc(*((Arc *)entity));
1601 case RS2::EntityCircle:
1603 DlgCircle dlg(parent);
1604 dlg.setCircle(*((Circle *)entity));
1614 case RS2::EntityEllipse:
1616 DlgEllipse dlg(parent);
1617 dlg.setEllipse(*((Ellipse *)entity));
1621 dlg.updateEllipse();
1627 case RS2::EntitySpline:
1629 DlgSpline dlg(parent);
1630 dlg.setSpline(*((Spline *)entity));
1640 case RS2::EntityInsert:
1642 DlgInsert dlg(parent);
1643 dlg.setInsert(*((Insert *)entity));
1654 case RS2::EntityDimAligned:
1655 case RS2::EntityDimAngular:
1656 case RS2::EntityDimDiametric:
1657 case RS2::EntityDimRadial:
1659 DlgDimension dlg(parent);
1660 dlg.setDim(*((Dimension *)entity));
1666 ((Dimension *)entity)->update(true);
1671 case RS2::EntityDimLinear:
1673 DlgDimLinear dlg(parent);
1674 dlg.setDim(*((DimLinear *)entity));
1680 ((DimLinear *)entity)->update(true);
1685 case RS2::EntityText:
1687 DlgText dlg(parent);
1688 dlg.setText(*((Text *)entity), false);
1694 ((Text *)entity)->update();
1699 case RS2::EntityHatch:
1701 DlgHatch dlg(parent);
1702 dlg.setHatch(*((Hatch *)entity), false);
1708 ((Hatch *)entity)->update();
1721 bool QG_DialogFactory::requestDimAlignedDialog(DimAligned* dim) {
1727 * Shows a dialog to edit the attributes of the given text entity.
1729 bool QG_DialogFactory::requestTextDialog(Text * text)
1734 DlgText dlg(parent);
1735 dlg.setText(*text, true);
1747 * Shows a dialog to edit pattern / hatch attributes of the given entity.
1749 bool QG_DialogFactory::requestHatchDialog(Hatch * hatch)
1754 PATTERNLIST->init();
1756 DlgHatch dlg(parent);
1757 dlg.setHatch(*hatch, true);
1770 * Shows a dialog for CAM options.
1772 bool QG_DialogFactory::requestCamOptionsDialog(Drawing& graphic)
1774 DEBUG->print("QG_DialogFactory::requestCamOptionsDialog");
1775 RS_CamDialog dlg(graphic, parent);
1776 DEBUG->print("QG_DialogFactory::requestCamOptionsDialog: exec");
1780 DEBUG->print("QG_DialogFactory::requestCamOptionsDialog: OK");
1784 DEBUG->print("QG_DialogFactory::requestCamOptionsDialog: Cancel");
1790 * Shows dialog for general application options.
1792 void QG_DialogFactory::requestOptionsGeneralDialog()
1794 DlgOptionsGeneral dlg(parent);
1799 * Shows dialog for drawing options.
1801 void QG_DialogFactory::requestOptionsDrawingDialog(Drawing & graphic)
1803 DlgOptionsDrawing dlg(parent);
1804 dlg.setGraphic(&graphic);
1809 * Back to last menu in cad toolbar.
1811 void QG_DialogFactory::requestPreviousMenu()
1813 if (cadToolBar != NULL)
1814 cadToolBar->showToolBarMain();
1818 * Called whenever the mouse position changed.
1820 void QG_DialogFactory::updateCoordinateWidget(const Vector & abs,
1821 const Vector & rel, bool updateFormat)
1823 if (coordinateWidget != NULL)
1824 coordinateWidget->setCoordinates(abs, rel, updateFormat);
1828 * Called when an action has a mouse hint.
1830 void QG_DialogFactory::updateMouseWidget(const QString & left, const QString & right)
1833 mouseWidget->setHelp(left, right);
1836 commandWidget->setCommand(left);
1840 * Called whenever the selection changed.
1842 void QG_DialogFactory::updateSelectionWidget(int num)
1844 if (selectionWidget != NULL)
1845 selectionWidget->setNumber(num);
1849 * Called when an action needs to communicate 'message' to the user.
1851 void QG_DialogFactory::commandMessage(const QString& message)
1853 DEBUG->print("QG_DialogFactory::commandMessage");
1855 if (commandWidget != NULL)
1856 commandWidget->appendHistory(message);
1858 DEBUG->print("QG_DialogFactory::commandMessage: OK");
1861 /*virtual*/ bool QG_DialogFactory::isAdapter()
1867 * Converts an extension to a format description.
1868 * e.g. "PNG" to "Portable Network Graphic"
1871 * @return Format description
1873 QString QG_DialogFactory::extToFormat(const QString & ext)
1875 QString e = ext.toLower();
1878 return QObject::tr("Windows Bitmap");
1879 else if (e == "jpeg" || e == "jpg")
1880 return QObject::tr("Joint Photographic Experts Group");
1881 else if (e == "gif")
1882 return QObject::tr("Graphics Interchange Format");
1883 else if (e == "mng")
1884 return QObject::tr("Multiple-image Network Graphics");
1885 else if (e == "pbm")
1886 return QObject::tr("Portable Bit Map");
1887 else if (e == "pgm")
1888 return QObject::tr("Portable Grey Map");
1889 else if (e == "png")
1890 return QObject::tr("Portable Network Graphic");
1891 else if (e == "ppm")
1892 return QObject::tr("Portable Pixel Map");
1893 else if (e == "xbm")
1894 return QObject::tr("X Bitmap Format");
1895 else if (e == "xpm")
1896 return QObject::tr("X Pixel Map");
1898 return ext.toUpper();