diff --git a/src/Gui/CommandView.cpp b/src/Gui/CommandView.cpp index 89ca6dcd0f..bf648a4ce8 100644 --- a/src/Gui/CommandView.cpp +++ b/src/Gui/CommandView.cpp @@ -1353,229 +1353,6 @@ void StdCmdViewTop::activated(int iMsg) } -//=============================================================================== -// StdCmdSelectFilter (dropdown toolbar button for Vertex, Edge & Face Selection) -//=============================================================================== - -DEF_STD_CMD_ACL(StdCmdSelectFilter) - -StdCmdSelectFilter::StdCmdSelectFilter() - : Command("Std_SelectFilter") -{ - sGroup = "Standard-View"; - sMenuText = QT_TR_NOOP("Selection filter"); - sToolTipText = QT_TR_NOOP("Change the Selection filter"); - sStatusTip = QT_TR_NOOP("Change the Selection filter"); - sWhatsThis = "Std_SelectFilter"; - sPixmap = "selection-filter"; - eType = Alter3DView; -} - -void StdCmdSelectFilter::activated(int iMsg) -{ - Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager(); - if (iMsg==0) - rcCmdMgr.runCommandByName("Std_VertexSelection"); - else if (iMsg==1) - rcCmdMgr.runCommandByName("Std_EdgeSelection"); - else if (iMsg==2) - rcCmdMgr.runCommandByName("Std_FaceSelection"); - else if (iMsg==3) - rcCmdMgr.runCommandByName("Std_RemoveSelectionGate"); - else - return; - - // Since the default icon is reset when enabling/disabling the command we have - // to explicitly set the icon of the used command. - Gui::ActionGroup* pcAction = qobject_cast(_pcAction); - QList a = pcAction->actions(); - - assert(iMsg < a.size()); - pcAction->setIcon(a[iMsg]->icon()); -} - -Gui::Action * StdCmdSelectFilter::createAction() -{ - Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow()); - pcAction->setDropDownMenu(true); - applyCommandData(this->className(), pcAction); - - QAction* cmd0 = pcAction->addAction(QString()); - cmd0->setIcon(Gui::BitmapFactory().iconFromTheme("vertex-selection")); - cmd0->setShortcut(QKeySequence(QString::fromUtf8("X,S"))); - QAction* cmd1 = pcAction->addAction(QString()); - cmd1->setIcon(Gui::BitmapFactory().iconFromTheme("edge-selection")); - cmd1->setShortcut(QKeySequence(QString::fromUtf8("E,S"))); - QAction* cmd2 = pcAction->addAction(QString()); - cmd2->setIcon(Gui::BitmapFactory().iconFromTheme("face-selection")); - cmd2->setShortcut(QKeySequence(QString::fromUtf8("F,S"))); - QAction* cmd3 = pcAction->addAction(QString()); - cmd3->setIcon(Gui::BitmapFactory().iconFromTheme("clear-selection")); - cmd3->setShortcut(QKeySequence(QString::fromUtf8("C,S"))); - - _pcAction = pcAction; - languageChange(); - - pcAction->setIcon(Gui::BitmapFactory().iconFromTheme("selection-filter")); - int defaultId = 3; - pcAction->setProperty("defaultAction", QVariant(defaultId)); - - return pcAction; -} - -void StdCmdSelectFilter::languageChange() -{ - Command::languageChange(); - - if (!_pcAction) - return; - - Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager(); - - Gui::ActionGroup* pcAction = qobject_cast(_pcAction); - QList a = pcAction->actions(); - - Gui::Command* vertexSelection = rcCmdMgr.getCommandByName("Std_VertexSelection"); - if (vertexSelection) { - QAction* cmd0 = a[0]; - cmd0->setText(QApplication::translate("View_SelectionFilter", vertexSelection->getMenuText())); - cmd0->setToolTip(QApplication::translate("View_SelectionFilter", vertexSelection->getToolTipText())); - cmd0->setStatusTip(QApplication::translate("View_SelectionFilter", vertexSelection->getStatusTip())); - } - - Gui::Command* edgeSelection = rcCmdMgr.getCommandByName("Std_EdgeSelection"); - if (edgeSelection) { - QAction* cmd1 = a[1]; - cmd1->setText(QApplication::translate("View_SelectionFilter", edgeSelection->getMenuText())); - cmd1->setToolTip(QApplication::translate("View_SelectionFilter", edgeSelection->getToolTipText())); - cmd1->setStatusTip(QApplication::translate("View_SelectionFilter", edgeSelection->getStatusTip())); - } - - Gui::Command* faceSelection = rcCmdMgr.getCommandByName("Std_FaceSelection"); - if (faceSelection) { - QAction* cmd1 = a[2]; - cmd1->setText(QApplication::translate("View_SelectionFilter", faceSelection->getMenuText())); - cmd1->setToolTip(QApplication::translate("View_SelectionFilter", faceSelection->getToolTipText())); - cmd1->setStatusTip(QApplication::translate("View_SelectionFilter", faceSelection->getStatusTip())); - } - - Gui::Command* removeSelection = rcCmdMgr.getCommandByName("Std_RemoveSelectionGate"); - if (removeSelection) { - QAction* cmd2 = a[3]; - cmd2->setText(QApplication::translate("View_SelectionFilter", removeSelection->getMenuText())); - cmd2->setToolTip(QApplication::translate("View_SelectionFilter", removeSelection->getToolTipText())); - cmd2->setStatusTip(QApplication::translate("View_SelectionFilter", removeSelection->getStatusTip())); - } -} - -bool StdCmdSelectFilter::isActive() -{ - Gui::MDIView* view = Gui::getMainWindow()->activeWindow(); - return view && view->isDerivedFrom(Gui::View3DInventor::getClassTypeId()); -} - - -//=========================================================================== -// Std_VertexSelection -//=========================================================================== -DEF_3DV_CMD(StdCmdVertexSelection) - -StdCmdVertexSelection::StdCmdVertexSelection() - : Command("Std_VertexSelection") -{ - sGroup = "Standard-View"; - sMenuText = QT_TR_NOOP("Vertex Selection"); - sToolTipText = QT_TR_NOOP("Select a Vertex/Vertices"); - sWhatsThis = "Std_VertexSelection"; - sStatusTip = QT_TR_NOOP("Select a Vertex/Vertices"); - sPixmap = "vertex-selection"; - sAccel = "X, S"; - eType = Alter3DView; -} - -void StdCmdVertexSelection::activated(int iMsg) -{ - Q_UNUSED(iMsg); - doCommand(Command::Gui,"Gui.Selection.addSelectionGate('SELECT Part::Feature SUBELEMENT Vertex')"); -} - - -//=========================================================================== -// Std_EdgeSelection -//=========================================================================== -DEF_3DV_CMD(StdCmdEdgeSelection) - -StdCmdEdgeSelection::StdCmdEdgeSelection() - : Command("Std_EdgeSelection") -{ - sGroup = "Standard-View"; - sMenuText = QT_TR_NOOP("Edge Selection"); - sToolTipText = QT_TR_NOOP("Select Edge(s)"); - sWhatsThis = "Std_EdgeSelection"; - sStatusTip = QT_TR_NOOP("Select Edge(s)"); - sPixmap = "edge-selection"; - sAccel = "E, S"; - eType = Alter3DView; -} - -void StdCmdEdgeSelection::activated(int iMsg) -{ - Q_UNUSED(iMsg); - doCommand(Command::Gui,"Gui.Selection.addSelectionGate('SELECT Part::Feature SUBELEMENT Edge')"); -} - - -//=========================================================================== -// Std_FaceSelection -//=========================================================================== -DEF_3DV_CMD(StdCmdFaceSelection) - -StdCmdFaceSelection::StdCmdFaceSelection() - : Command("Std_FaceSelection") -{ - sGroup = "Standard-View"; - sMenuText = QT_TR_NOOP("Face Selection"); - sToolTipText = QT_TR_NOOP("Select Face(s)"); - sWhatsThis = "Std_FaceSelection"; - sStatusTip = QT_TR_NOOP("Select Face(s)"); - sPixmap = "face-selection"; - sAccel = "F, S"; - eType = Alter3DView; -} - -void StdCmdFaceSelection::activated(int iMsg) -{ - Q_UNUSED(iMsg); - doCommand(Command::Gui,"Gui.Selection.addSelectionGate('SELECT Part::Feature SUBELEMENT Face')"); -} - - - -//=========================================================================== -// Std_RemoveSelectionGate -//=========================================================================== -DEF_3DV_CMD(StdCmdRemoveSelectionGate) - -StdCmdRemoveSelectionGate::StdCmdRemoveSelectionGate() - : Command("Std_RemoveSelectionGate") -{ - sGroup = "Standard-View"; - sMenuText = QT_TR_NOOP("All selection filters cleared"); - sToolTipText = QT_TR_NOOP("All selection filters cleared"); - sWhatsThis = "Std_RemoveSelectionGate"; - sStatusTip = QT_TR_NOOP("All selection filters cleared"); - sPixmap = "clear-selection"; - sAccel = "C, S"; - eType = Alter3DView; -} - -void StdCmdRemoveSelectionGate::activated(int iMsg) -{ - Q_UNUSED(iMsg); - doCommand(Command::Gui,"Gui.Selection.removeSelectionGate()"); -} - - //=========================================================================== // Std_ViewIsometric //=========================================================================== @@ -4020,11 +3797,6 @@ void CreateViewStdCommands() rcCmdMgr.addCommand(new StdCmdViewRear()); rcCmdMgr.addCommand(new StdCmdViewRight()); rcCmdMgr.addCommand(new StdCmdViewTop()); - rcCmdMgr.addCommand(new StdCmdSelectFilter()); - rcCmdMgr.addCommand(new StdCmdVertexSelection()); - rcCmdMgr.addCommand(new StdCmdEdgeSelection()); - rcCmdMgr.addCommand(new StdCmdFaceSelection()); - rcCmdMgr.addCommand(new StdCmdRemoveSelectionGate()); rcCmdMgr.addCommand(new StdCmdViewIsometric()); rcCmdMgr.addCommand(new StdCmdViewDimetric()); rcCmdMgr.addCommand(new StdCmdViewTrimetric()); diff --git a/src/Mod/Part/Gui/AppPartGui.cpp b/src/Mod/Part/Gui/AppPartGui.cpp index 739b1ffc07..90af3b7a20 100644 --- a/src/Mod/Part/Gui/AppPartGui.cpp +++ b/src/Mod/Part/Gui/AppPartGui.cpp @@ -84,6 +84,7 @@ void CreatePartCommands(); void CreateSimplePartCommands(); void CreateParamPartCommands(); +void CreatePartSelectCommands(); void loadPartResource() { @@ -222,6 +223,7 @@ PyMOD_INIT_FUNC(PartGui) CreatePartCommands(); CreateSimplePartCommands(); CreateParamPartCommands(); + CreatePartSelectCommands(); try{ Py::Object ae = Base::Interpreter().runStringObject("__import__('AttachmentEditor.Commands').Commands"); Py::Module(partGuiModule).setAttr(std::string("AttachmentEditor"),ae); diff --git a/src/Mod/Part/Gui/CMakeLists.txt b/src/Mod/Part/Gui/CMakeLists.txt index ea1c2eee9e..46505f716a 100644 --- a/src/Mod/Part/Gui/CMakeLists.txt +++ b/src/Mod/Part/Gui/CMakeLists.txt @@ -78,6 +78,7 @@ SET(PartGui_SRCS BoxSelection.cpp BoxSelection.h Command.cpp + CommandFilter.cpp CommandSimple.cpp CommandParametric.cpp CrossSections.cpp diff --git a/src/Mod/Part/Gui/CommandFilter.cpp b/src/Mod/Part/Gui/CommandFilter.cpp new file mode 100644 index 0000000000..8146922e0c --- /dev/null +++ b/src/Mod/Part/Gui/CommandFilter.cpp @@ -0,0 +1,273 @@ +/*************************************************************************** + * Copyright (c) 2002 Jürgen Riegel * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" +#ifndef _PreComp_ +#include +#include +#endif + +#include +#include +#include +#include +#include + +//=============================================================================== +// PartCmdSelectFilter (dropdown toolbar button for Vertex, Edge & Face Selection) +//=============================================================================== + +DEF_STD_CMD_ACL(PartCmdSelectFilter) + +PartCmdSelectFilter::PartCmdSelectFilter() + : Command("Part_SelectFilter") +{ + sGroup = "Standard-View"; + sMenuText = QT_TR_NOOP("Selection filter"); + sToolTipText = QT_TR_NOOP("Change the Selection filter"); + sStatusTip = QT_TR_NOOP("Change the Selection filter"); + sWhatsThis = "Part_SelectFilter"; + sPixmap = "selection-filter"; + eType = Alter3DView; +} + +void PartCmdSelectFilter::activated(int iMsg) +{ + Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager(); + if (iMsg==0) { + rcCmdMgr.runCommandByName("Part_VertexSelection"); + } + else if (iMsg==1) { + rcCmdMgr.runCommandByName("Part_EdgeSelection"); + } + else if (iMsg==2) { + rcCmdMgr.runCommandByName("Part_FaceSelection"); + } + else if (iMsg==3) { + rcCmdMgr.runCommandByName("Part_RemoveSelectionGate"); + } + else { + return; + } + + // Since the default icon is reset when enabling/disabling the command we have + // to explicitly set the icon of the used command. + auto pcAction = qobject_cast(_pcAction); + QList act = pcAction->actions(); + + assert(iMsg < act.size()); + pcAction->setIcon(act[iMsg]->icon()); +} + +Gui::Action * PartCmdSelectFilter::createAction() +{ + auto pcAction = new Gui::ActionGroup(this, Gui::getMainWindow()); + pcAction->setDropDownMenu(true); + applyCommandData(this->className(), pcAction); + + QAction* cmd0 = pcAction->addAction(QString()); + cmd0->setIcon(Gui::BitmapFactory().iconFromTheme("vertex-selection")); + cmd0->setShortcut(QKeySequence(QString::fromUtf8("X,S"))); + QAction* cmd1 = pcAction->addAction(QString()); + cmd1->setIcon(Gui::BitmapFactory().iconFromTheme("edge-selection")); + cmd1->setShortcut(QKeySequence(QString::fromUtf8("E,S"))); + QAction* cmd2 = pcAction->addAction(QString()); + cmd2->setIcon(Gui::BitmapFactory().iconFromTheme("face-selection")); + cmd2->setShortcut(QKeySequence(QString::fromUtf8("F,S"))); + QAction* cmd3 = pcAction->addAction(QString()); + cmd3->setIcon(Gui::BitmapFactory().iconFromTheme("clear-selection")); + cmd3->setShortcut(QKeySequence(QString::fromUtf8("C,S"))); + + _pcAction = pcAction; + languageChange(); + + pcAction->setIcon(Gui::BitmapFactory().iconFromTheme("selection-filter")); + int defaultId = 3; + pcAction->setProperty("defaultAction", QVariant(defaultId)); + + return pcAction; +} + +void PartCmdSelectFilter::languageChange() +{ + Command::languageChange(); + + if (!_pcAction) { + return; + } + + Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager(); + + auto pcAction = qobject_cast(_pcAction); + QList act = pcAction->actions(); + + Gui::Command* vertexSelection = rcCmdMgr.getCommandByName("Part_VertexSelection"); + if (vertexSelection) { + QAction* cmd0 = act[0]; + cmd0->setText(QApplication::translate("View_SelectionFilter", vertexSelection->getMenuText())); + cmd0->setToolTip(QApplication::translate("View_SelectionFilter", vertexSelection->getToolTipText())); + cmd0->setStatusTip(QApplication::translate("View_SelectionFilter", vertexSelection->getStatusTip())); + } + + Gui::Command* edgeSelection = rcCmdMgr.getCommandByName("Part_EdgeSelection"); + if (edgeSelection) { + QAction* cmd1 = act[1]; + cmd1->setText(QApplication::translate("View_SelectionFilter", edgeSelection->getMenuText())); + cmd1->setToolTip(QApplication::translate("View_SelectionFilter", edgeSelection->getToolTipText())); + cmd1->setStatusTip(QApplication::translate("View_SelectionFilter", edgeSelection->getStatusTip())); + } + + Gui::Command* faceSelection = rcCmdMgr.getCommandByName("Part_FaceSelection"); + if (faceSelection) { + QAction* cmd1 = act[2]; + cmd1->setText(QApplication::translate("View_SelectionFilter", faceSelection->getMenuText())); + cmd1->setToolTip(QApplication::translate("View_SelectionFilter", faceSelection->getToolTipText())); + cmd1->setStatusTip(QApplication::translate("View_SelectionFilter", faceSelection->getStatusTip())); + } + + Gui::Command* removeSelection = rcCmdMgr.getCommandByName("Part_RemoveSelectionGate"); + if (removeSelection) { + QAction* cmd2 = act[3]; + cmd2->setText(QApplication::translate("View_SelectionFilter", removeSelection->getMenuText())); + cmd2->setToolTip(QApplication::translate("View_SelectionFilter", removeSelection->getToolTipText())); + cmd2->setStatusTip(QApplication::translate("View_SelectionFilter", removeSelection->getStatusTip())); + } +} + +bool PartCmdSelectFilter::isActive() +{ + Gui::MDIView* view = Gui::getMainWindow()->activeWindow(); + return view && view->isDerivedFrom(Gui::View3DInventor::getClassTypeId()); +} + + +//=========================================================================== +// Part_VertexSelection +//=========================================================================== +DEF_3DV_CMD(PartCmdVertexSelection) + +PartCmdVertexSelection::PartCmdVertexSelection() + : Command("Part_VertexSelection") +{ + sGroup = "Standard-View"; + sMenuText = QT_TR_NOOP("Vertex Selection"); + sToolTipText = QT_TR_NOOP("Select a Vertex/Vertices"); + sWhatsThis = "Part_VertexSelection"; + sStatusTip = QT_TR_NOOP("Select a Vertex/Vertices"); + sPixmap = "vertex-selection"; + sAccel = "X, S"; + eType = Alter3DView; +} + +void PartCmdVertexSelection::activated(int iMsg) +{ + Q_UNUSED(iMsg); + doCommand(Command::Gui,"Gui.Selection.addSelectionGate('SELECT Part::Feature SUBELEMENT Vertex')"); +} + + +//=========================================================================== +// Part_EdgeSelection +//=========================================================================== +DEF_3DV_CMD(PartCmdEdgeSelection) + +PartCmdEdgeSelection::PartCmdEdgeSelection() + : Command("Part_EdgeSelection") +{ + sGroup = "Standard-View"; + sMenuText = QT_TR_NOOP("Edge Selection"); + sToolTipText = QT_TR_NOOP("Select Edge(s)"); + sWhatsThis = "Part_EdgeSelection"; + sStatusTip = QT_TR_NOOP("Select Edge(s)"); + sPixmap = "edge-selection"; + sAccel = "E, S"; + eType = Alter3DView; +} + +void PartCmdEdgeSelection::activated(int iMsg) +{ + Q_UNUSED(iMsg); + doCommand(Command::Gui,"Gui.Selection.addSelectionGate('SELECT Part::Feature SUBELEMENT Edge')"); +} + + +//=========================================================================== +// Part_FaceSelection +//=========================================================================== +DEF_3DV_CMD(PartCmdFaceSelection) + +PartCmdFaceSelection::PartCmdFaceSelection() + : Command("Part_FaceSelection") +{ + sGroup = "Standard-View"; + sMenuText = QT_TR_NOOP("Face Selection"); + sToolTipText = QT_TR_NOOP("Select Face(s)"); + sWhatsThis = "Part_FaceSelection"; + sStatusTip = QT_TR_NOOP("Select Face(s)"); + sPixmap = "face-selection"; + sAccel = "F, S"; + eType = Alter3DView; +} + +void PartCmdFaceSelection::activated(int iMsg) +{ + Q_UNUSED(iMsg); + doCommand(Command::Gui,"Gui.Selection.addSelectionGate('SELECT Part::Feature SUBELEMENT Face')"); +} + + +//=========================================================================== +// Part_RemoveSelectionGate +//=========================================================================== +DEF_3DV_CMD(PartCmdRemoveSelectionGate) + +PartCmdRemoveSelectionGate::PartCmdRemoveSelectionGate() + : Command("Part_RemoveSelectionGate") +{ + sGroup = "Standard-View"; + sMenuText = QT_TR_NOOP("All selection filters cleared"); + sToolTipText = QT_TR_NOOP("All selection filters cleared"); + sWhatsThis = "Part_RemoveSelectionGate"; + sStatusTip = QT_TR_NOOP("All selection filters cleared"); + sPixmap = "clear-selection"; + sAccel = "C, S"; + eType = Alter3DView; +} + +void PartCmdRemoveSelectionGate::activated(int iMsg) +{ + Q_UNUSED(iMsg); + doCommand(Command::Gui,"Gui.Selection.removeSelectionGate()"); +} + +void CreatePartSelectCommands() +{ + Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager(); + // NOLINTBEGIN + rcCmdMgr.addCommand(new PartCmdSelectFilter()); + rcCmdMgr.addCommand(new PartCmdVertexSelection()); + rcCmdMgr.addCommand(new PartCmdEdgeSelection()); + rcCmdMgr.addCommand(new PartCmdFaceSelection()); + rcCmdMgr.addCommand(new PartCmdRemoveSelectionGate()); + // NOLINTEND +}