| |
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| |
|
| | #include <Gui/Action.h>
|
| | #include <Gui/Application.h>
|
| | #include <Gui/BitmapFactory.h>
|
| | #include <Gui/CommandT.h>
|
| | #include <Gui/Document.h>
|
| | #include <Gui/MainWindow.h>
|
| | #include <Gui/Notifications.h>
|
| | #include <Gui/Selection/Selection.h>
|
| | #include <Gui/Selection/SelectionObject.h>
|
| | #include <Mod/Sketcher/App/SketchObject.h>
|
| |
|
| | #include "GeometryCreationMode.h"
|
| | #include "Utils.h"
|
| | #include "ViewProviderSketch.h"
|
| |
|
| |
|
| | using namespace std;
|
| | using namespace SketcherGui;
|
| | using namespace Sketcher;
|
| |
|
| | bool isAlterGeoActive(Gui::Document* doc)
|
| | {
|
| | if (doc) {
|
| |
|
| | if (doc->getInEdit() && doc->getInEdit()->isDerivedFrom<SketcherGui::ViewProviderSketch>()) {
|
| | return true;
|
| | }
|
| | }
|
| |
|
| | return false;
|
| | }
|
| |
|
| | namespace SketcherGui
|
| | {
|
| |
|
| | extern GeometryCreationMode geometryCreationMode;
|
| |
|
| |
|
| | DEF_STD_CMD_AU(CmdSketcherToggleConstruction)
|
| |
|
| | CmdSketcherToggleConstruction::CmdSketcherToggleConstruction()
|
| | : Command("Sketcher_ToggleConstruction")
|
| | {
|
| | sAppModule = "Sketcher";
|
| | sGroup = "Sketcher";
|
| | sMenuText = QT_TR_NOOP("Toggle Construction Geometry");
|
| | sToolTipText = QT_TR_NOOP("Toggles between defining geometry and construction geometry modes");
|
| | sWhatsThis = "Sketcher_ToggleConstruction";
|
| | sStatusTip = sToolTipText;
|
| | sPixmap = "Sketcher_ToggleConstruction";
|
| | sAccel = "G, N";
|
| | eType = ForEdit;
|
| |
|
| |
|
| | Gui::CommandManager& rcCmdMgr = Gui::Application::Instance->commandManager();
|
| | rcCmdMgr.addCommandMode("ToggleConstruction", "Sketcher_CreateLine");
|
| | rcCmdMgr.addCommandMode("ToggleConstruction", "Sketcher_CreatePolyline");
|
| | rcCmdMgr.addCommandMode("ToggleConstruction", "Sketcher_CompLine");
|
| | rcCmdMgr.addCommandMode("ToggleConstruction", "Sketcher_CreateRectangle");
|
| | rcCmdMgr.addCommandMode("ToggleConstruction", "Sketcher_CreateRectangle_Center");
|
| | rcCmdMgr.addCommandMode("ToggleConstruction", "Sketcher_CreateOblong");
|
| | rcCmdMgr.addCommandMode("ToggleConstruction", "Sketcher_CompCreateRectangles");
|
| | rcCmdMgr.addCommandMode("ToggleConstruction", "Sketcher_CreateArcSlot");
|
| | rcCmdMgr.addCommandMode("ToggleConstruction", "Sketcher_CreateSlot");
|
| | rcCmdMgr.addCommandMode("ToggleConstruction", "Sketcher_CompSlot");
|
| | rcCmdMgr.addCommandMode("ToggleConstruction", "Sketcher_CreateArc");
|
| | rcCmdMgr.addCommandMode("ToggleConstruction", "Sketcher_Create3PointArc");
|
| | rcCmdMgr.addCommandMode("ToggleConstruction", "Sketcher_CreateEllipseByCenter");
|
| | rcCmdMgr.addCommandMode("ToggleConstruction", "Sketcher_CreateEllipseBy3Points");
|
| | rcCmdMgr.addCommandMode("ToggleConstruction", "Sketcher_CreateArcOfEllipse");
|
| | rcCmdMgr.addCommandMode("ToggleConstruction", "Sketcher_CreateArcOfHyperbola");
|
| | rcCmdMgr.addCommandMode("ToggleConstruction", "Sketcher_CreateArcOfParabola");
|
| | rcCmdMgr.addCommandMode("ToggleConstruction", "Sketcher_CompCreateArc");
|
| | rcCmdMgr.addCommandMode("ToggleConstruction", "Sketcher_CreateCircle");
|
| | rcCmdMgr.addCommandMode("ToggleConstruction", "Sketcher_Create3PointCircle");
|
| | rcCmdMgr.addCommandMode("ToggleConstruction", "Sketcher_CompCreateConic");
|
| | rcCmdMgr.addCommandMode("ToggleConstruction", "Sketcher_CreateTriangle");
|
| | rcCmdMgr.addCommandMode("ToggleConstruction", "Sketcher_CreateSquare");
|
| | rcCmdMgr.addCommandMode("ToggleConstruction", "Sketcher_CreatePentagon");
|
| | rcCmdMgr.addCommandMode("ToggleConstruction", "Sketcher_CreateHexagon");
|
| | rcCmdMgr.addCommandMode("ToggleConstruction", "Sketcher_CreateHeptagon");
|
| | rcCmdMgr.addCommandMode("ToggleConstruction", "Sketcher_CreateOctagon");
|
| | rcCmdMgr.addCommandMode("ToggleConstruction", "Sketcher_CreateRegularPolygon");
|
| | rcCmdMgr.addCommandMode("ToggleConstruction", "Sketcher_CompCreateRegularPolygon");
|
| | rcCmdMgr.addCommandMode("ToggleConstruction", "Sketcher_CreateBSpline");
|
| | rcCmdMgr.addCommandMode("ToggleConstruction", "Sketcher_CreatePeriodicBSpline");
|
| | rcCmdMgr.addCommandMode("ToggleConstruction", "Sketcher_CreateBSplineByInterpolation");
|
| | rcCmdMgr.addCommandMode("ToggleConstruction", "Sketcher_CreatePeriodicBSplineByInterpolation");
|
| | rcCmdMgr.addCommandMode("ToggleConstruction", "Sketcher_CompCreateBSpline");
|
| | rcCmdMgr.addCommandMode("ToggleConstruction", "Sketcher_CarbonCopy");
|
| | rcCmdMgr.addCommandMode("ToggleConstruction", "Sketcher_CompExternal");
|
| | rcCmdMgr.addCommandMode("ToggleConstruction", "Sketcher_Projection");
|
| | rcCmdMgr.addCommandMode("ToggleConstruction", "Sketcher_Intersection");
|
| | rcCmdMgr.addCommandMode("ToggleConstruction", "Sketcher_ToggleConstruction");
|
| | }
|
| |
|
| | void CmdSketcherToggleConstruction::updateAction(int mode)
|
| | {
|
| | auto act = getAction();
|
| | if (act) {
|
| | switch (static_cast<GeometryCreationMode>(mode)) {
|
| | case GeometryCreationMode::Normal:
|
| | act->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_ToggleConstruction"));
|
| | break;
|
| | case GeometryCreationMode::Construction:
|
| | act->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_ToggleConstruction_Constr"));
|
| | break;
|
| | }
|
| | }
|
| | }
|
| |
|
| | void CmdSketcherToggleConstruction::activated(int iMsg)
|
| | {
|
| | Q_UNUSED(iMsg);
|
| |
|
| | if (Gui::Selection().countObjectsOfType<Sketcher::SketchObject>() == 0) {
|
| |
|
| | Gui::CommandManager& rcCmdMgr = Gui::Application::Instance->commandManager();
|
| |
|
| | if (geometryCreationMode == GeometryCreationMode::Construction) {
|
| | geometryCreationMode = GeometryCreationMode::Normal;
|
| | }
|
| | else {
|
| | geometryCreationMode = GeometryCreationMode::Construction;
|
| | }
|
| |
|
| | rcCmdMgr.updateCommands("ToggleConstruction", static_cast<int>(geometryCreationMode));
|
| | }
|
| | else
|
| | {
|
| |
|
| | std::vector<Gui::SelectionObject> selection;
|
| | selection = getSelection().getSelectionEx(nullptr, Sketcher::SketchObject::getClassTypeId());
|
| |
|
| | auto* Obj = static_cast<Sketcher::SketchObject*>(selection[0].getObject());
|
| |
|
| |
|
| | if (selection.size() != 1) {
|
| | Gui::TranslatedUserWarning(
|
| | Obj,
|
| | QObject::tr("Wrong selection"),
|
| | QObject::tr("Select edges from the sketch")
|
| | );
|
| | return;
|
| | }
|
| |
|
| |
|
| | const std::vector<std::string>& SubNames = selection[0].getSubNames();
|
| | if (SubNames.empty()) {
|
| | Gui::TranslatedUserWarning(
|
| | Obj,
|
| | QObject::tr("Wrong selection"),
|
| | QObject::tr("Select edges from the sketch")
|
| | );
|
| | return;
|
| | }
|
| |
|
| |
|
| | openCommand(QT_TRANSLATE_NOOP("Command", "Toggle construction geometry"));
|
| |
|
| |
|
| | bool verticesonly = true;
|
| |
|
| | for (const auto& subname : SubNames) {
|
| | if ((subname.size() > 4 && subname.substr(0, 4) == "Edge")
|
| | || (subname.size() > 12 && subname.substr(0, 12) == "ExternalEdge")) {
|
| | verticesonly = false;
|
| | }
|
| | }
|
| |
|
| | for (const auto& subname : SubNames) {
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| | if (subname.size() > 4 && subname.substr(0, 4) == "Edge") {
|
| | int geoId = std::atoi(subname.substr(4, 4000).c_str()) - 1;
|
| |
|
| | Gui::cmdAppObjectArgs(Obj, "toggleConstruction(%d) ", geoId);
|
| | }
|
| | else if (subname.size() > 12 && subname.substr(0, 12) == "ExternalEdge") {
|
| | int geoId = GeoEnum::RefExt - std::atoi(subname.substr(12, 4000).c_str()) + 1;
|
| | Gui::cmdAppObjectArgs(Obj, "toggleConstruction(%d) ", geoId);
|
| | }
|
| | else if (verticesonly && subname.size() > 6 && subname.substr(0, 6) == "Vertex") {
|
| | int vertexId = std::atoi(subname.substr(6, 4000).c_str()) - 1;
|
| |
|
| | int geoId;
|
| | PointPos pos;
|
| | Obj->getGeoVertexIndex(vertexId, geoId, pos);
|
| |
|
| | auto geo = Obj->getGeometry(geoId);
|
| |
|
| | if (geo && geo->is<Part::GeomPoint>()) {
|
| |
|
| | Gui::cmdAppObjectArgs(Obj, "toggleConstruction(%d) ", geoId);
|
| | }
|
| | }
|
| | }
|
| |
|
| | commitCommand();
|
| |
|
| | tryAutoRecompute(Obj);
|
| |
|
| |
|
| | getSelection().clearSelection();
|
| | }
|
| | }
|
| |
|
| | bool CmdSketcherToggleConstruction::isActive()
|
| | {
|
| | return isAlterGeoActive(getActiveGuiDocument());
|
| | }
|
| |
|
| | }
|
| |
|
| | void CreateSketcherCommandsAlterGeo()
|
| | {
|
| | Gui::CommandManager& rcCmdMgr = Gui::Application::Instance->commandManager();
|
| |
|
| | rcCmdMgr.addCommand(new CmdSketcherToggleConstruction());
|
| | }
|
| |
|