diff --git a/src/Mod/TechDraw/Gui/Command.cpp b/src/Mod/TechDraw/Gui/Command.cpp index 15ef3085c8..0ef6802b3c 100644 --- a/src/Mod/TechDraw/Gui/Command.cpp +++ b/src/Mod/TechDraw/Gui/Command.cpp @@ -24,6 +24,8 @@ #include #include #include +#include +#include #include #endif @@ -294,7 +296,9 @@ CmdTechDrawView::CmdTechDrawView() : Command("TechDraw_View") sAppModule = "TechDraw"; sGroup = QT_TR_NOOP("TechDraw"); sMenuText = QT_TR_NOOP("Insert View"); - sToolTipText = QT_TR_NOOP("Insert a View in current page. You can select Shapes, SpreadSheets or Section Plane from Arch Workbench objects."); + sToolTipText = QT_TR_NOOP("Insert a View in current page.\n" + "Selected objects, spreadsheets or Arch WB section planes will be added with the current camera orientation.\n" + "Without a selection, a file browser lets you select a SVG or image file."); sWhatsThis = "TechDraw_View"; sStatusTip = sToolTipText; sPixmap = "actions/TechDraw_View"; @@ -403,15 +407,68 @@ void CmdTechDrawView::activated(int iMsg) } } + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/TechDraw"); if (shapes.empty() && xShapes.empty()) { if (!viewCreated) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("No Suitable objects in this selection")); + // If nothing was selected, then we offer to insert SVG or Images files. + bool dontShowAgain = hGrp->GetBool("DontShowInsertFileMessage", false); + if (!dontShowAgain) { + QMessageBox msgBox; + msgBox.setText(msgBox.tr("Note: If you want to insert a shape you need to select it before starting the tool, else it opens a file browser to insert SVG or Images.")); + QCheckBox dontShowCheckBox(msgBox.tr("Do not show this message again"), &msgBox); + msgBox.setCheckBox(&dontShowCheckBox); + QPushButton* okButton = msgBox.addButton(QMessageBox::Ok); + + msgBox.exec(); + + if (msgBox.clickedButton() == okButton && dontShowCheckBox.isChecked()) { + // Save the preference to not show the message again + hGrp->SetBool("DontShowInsertFileMessage", true); + } + } + + QString filename = Gui::FileDialog::getOpenFileName(Gui::getMainWindow(), + QObject::tr("Select a SVG or Image file to open"), QString(), + QString::fromLatin1("%1 (*.svg *.svgz *.jpg *.jpeg *.png *.bmp);;%2 (*.*)") + .arg(QObject::tr("SVG or Image files"), QObject::tr("All Files"))); + + if (!filename.isEmpty()) { + if (filename.endsWith(QString::fromLatin1(".svg"), Qt::CaseInsensitive) + || filename.endsWith(QString::fromLatin1(".svgz"), Qt::CaseInsensitive)) { + std::string FeatName = getUniqueObjectName("Symbol"); + filename = Base::Tools::escapeEncodeFilename(filename); + openCommand(QT_TRANSLATE_NOOP("Command", "Create Symbol")); + doCommand(Doc, "f = open(\"%s\", 'r')", (const char*)filename.toUtf8()); + doCommand(Doc, "svg = f.read()"); + doCommand(Doc, "f.close()"); + doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawViewSymbol', '%s')", + FeatName.c_str()); + doCommand(Doc, "App.activeDocument().%s.translateLabel('DrawViewSymbol', 'Symbol', '%s')", + FeatName.c_str(), FeatName.c_str()); + doCommand(Doc, "App.activeDocument().%s.Symbol = svg", FeatName.c_str()); + doCommand(Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", PageName.c_str(), + FeatName.c_str()); + } + else { + std::string FeatName = getUniqueObjectName("Image"); + filename = Base::Tools::escapeEncodeFilename(filename); + openCommand(QT_TRANSLATE_NOOP("Command", "Create Image")); + doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawViewImage', '%s')", FeatName.c_str()); + doCommand(Doc, "App.activeDocument().%s.translateLabel('DrawViewImage', 'Image', '%s')", + FeatName.c_str(), FeatName.c_str()); + doCommand(Doc, "App.activeDocument().%s.ImageFile = '%s'", FeatName.c_str(), filename.toUtf8().constData()); + doCommand(Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", PageName.c_str(), FeatName.c_str()); + updateActive(); + commitCommand(); + } + + updateActive(); + commitCommand(); + } } return; } - Base::Vector3d projDir; Gui::WaitCursor wc; openCommand(QT_TRANSLATE_NOOP("Command", "Create view")); diff --git a/src/Mod/TechDraw/Gui/Resources/icons/actions/TechDraw_View.svg b/src/Mod/TechDraw/Gui/Resources/icons/actions/TechDraw_View.svg index 1756706e19..598b329cb6 100644 --- a/src/Mod/TechDraw/Gui/Resources/icons/actions/TechDraw_View.svg +++ b/src/Mod/TechDraw/Gui/Resources/icons/actions/TechDraw_View.svg @@ -1,372 +1,68 @@ + + - - - - + id="defs2871"> + id="linearGradient5"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + id="stop19" /> + id="stop20" /> + + + + + + + + + + + + + + + gradientTransform="matrix(0.86186705,0,0,0.89755344,-75.697779,-13.617255)" /> - - - - - - - - - - - - - - - + gradientTransform="matrix(0.86186705,0,0,0.89755344,-75.697779,-13.617255)" /> + id="linearGradient4029"> - - - - - - - - - - + style="stop-color:#06989a;stop-opacity:1" /> - + style="stop-color:#16d0d2;stop-opacity:1" /> - - - - - - - + id="metadata2874"> @@ -612,156 +133,103 @@ rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> - [agryson] Alexander Gryson + [maxwxyz] - http://agryson.net - - TechDraw_View - 2016-01-14 https://www.freecad.org/wiki/index.php?title=Artwork FreeCAD - FreeCAD/src/Mod/TechDraw/Gui/Resources/icons/actions/TechDraw_View.svg + FreeCAD/src/ FreeCAD LGPL2+ - - - [agryson] Alexander Gryson - - + 2024 - - - - - - - - - - - - - - - - - - + id="layer3" + style="display:inline"> + style="fill:url(#linearGradient4001);fill-opacity:1;stroke:#042a2a;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1;stroke-dasharray:none" + d="M 2.7321186,26.119882 V 9.1479626 L 17.58275,13.390943 v 16.971918 z" + id="path3185" /> + style="fill:#34e0e2;stroke:#042a2a;stroke-width:2;stroke-linecap:butt;stroke-linejoin:round;stroke-opacity:1;stroke-dasharray:none" + d="M 2.7321186,9.1479626 15.461232,2.7834937 30.311865,7.0264734 17.58275,13.390943 Z" + id="path3973" /> + style="fill:url(#linearGradient4027);fill-opacity:1;stroke:#042a2a;stroke-width:2;stroke-linecap:butt;stroke-linejoin:round;stroke-opacity:1;stroke-dasharray:none" + d="M 17.58275,13.390943 V 30.362861 L 30.311865,23.998393 V 7.0264734 Z" + id="path3975" /> - - + style="fill:none;stroke:#34e0e2;stroke-width:1.68721;stroke-linecap:round;stroke-linejoin:miter;stroke-opacity:1" + d="M 4.3544558,24.885332 V 11.33044 l 11.5383362,3.245562 0.07098,13.641827 z" + id="path3185-7" /> + style="fill:none;stroke:#16d0d2;stroke-width:1.68721;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" + d="m 19.190762,14.387266 -0.01437,13.542121 9.51313,-4.666242 -0.03206,-13.4974003 z" + id="path3975-4" /> + + + + + + + + + id="path6" + style="fill:none;stroke:#0b1e23;stroke-width:6;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:1.8;stroke-opacity:1" + d="M 23.331615,34.789022 H 17.87336 m 17.458255,0 H 29.87336 M 23.331615,58.69951 H 17.87336 M 42.789873,34.929018 h 4.005096 v 4.26789 m 0,5.078236 v 5.078235 m 0,5.078235 V 58.69951 H 42.78987 m -7.458255,0 H 29.87336 m -19.458255,0 H 6.4100098 v -4.26789 m 0,-5.078235 V 44.27515 m 0,-5.078236 v -4.267896 h 4.0050982" /> + + + + + diff --git a/src/Mod/TechDraw/Gui/Workbench.cpp b/src/Mod/TechDraw/Gui/Workbench.cpp index 9da46e3014..08bb9fd11c 100644 --- a/src/Mod/TechDraw/Gui/Workbench.cpp +++ b/src/Mod/TechDraw/Gui/Workbench.cpp @@ -362,8 +362,6 @@ Gui::ToolBarItem* Workbench::setupToolBars() const decor->setCommand("TechDraw Decoration"); *decor << "TechDraw_Hatch"; *decor << "TechDraw_GeometricHatch"; - *decor << "TechDraw_Symbol"; - *decor << "TechDraw_Image"; *decor << "TechDraw_ToggleFrame"; Gui::ToolBarItem* anno = new Gui::ToolBarItem(root); @@ -467,8 +465,6 @@ Gui::ToolBarItem* Workbench::setupCommandBars() const decor->setCommand("TechDraw Decoration"); *decor << "TechDraw_Hatch"; *decor << "TechDraw_GeometricHatch"; - *decor << "TechDraw_Symbol"; - *decor << "TechDraw_Image"; *decor << "TechDraw_ToggleFrame"; Gui::ToolBarItem* anno = new Gui::ToolBarItem(root);