sketcher: create contextual right click menu
This commit is contained in:
committed by
WandererFan
parent
5ba5e798bf
commit
476089a2ad
@@ -129,6 +129,7 @@ Marosh
|
||||
Masaya Ootsuki
|
||||
Mateusz Skowroński (f3nix)
|
||||
Mattis M
|
||||
Max Wilfinger (maxwxyz)
|
||||
mdinger
|
||||
Meme2704
|
||||
Michael Hansen
|
||||
|
||||
@@ -1167,14 +1167,14 @@ public:
|
||||
|
||||
addCommand("Sketcher_Dimension");
|
||||
addCommand(); //separator
|
||||
addCommand("Sketcher_ConstrainLock");
|
||||
addCommand("Sketcher_ConstrainDistanceX");
|
||||
addCommand("Sketcher_ConstrainDistanceY");
|
||||
addCommand("Sketcher_ConstrainDistance");
|
||||
addCommand("Sketcher_ConstrainRadiam");
|
||||
addCommand("Sketcher_ConstrainRadius");
|
||||
addCommand("Sketcher_ConstrainDiameter");
|
||||
addCommand("Sketcher_ConstrainRadiam");
|
||||
addCommand("Sketcher_ConstrainAngle");
|
||||
addCommand("Sketcher_ConstrainLock");
|
||||
}
|
||||
|
||||
void updateAction(int mode) override
|
||||
@@ -1219,6 +1219,37 @@ public:
|
||||
const char* className() const override { return "CmdSketcherCompDimensionTools"; }
|
||||
};
|
||||
|
||||
// Comp for constrain tools =============================================
|
||||
|
||||
class CmdSketcherCompConstrainTools : public Gui::GroupCommand
|
||||
{
|
||||
public:
|
||||
CmdSketcherCompConstrainTools()
|
||||
: GroupCommand("Sketcher_CompConstrainTools")
|
||||
{
|
||||
sAppModule = "Sketcher";
|
||||
sGroup = "Sketcher";
|
||||
sMenuText = QT_TR_NOOP("Constrain");
|
||||
sToolTipText = QT_TR_NOOP("Constrain tools.");
|
||||
sWhatsThis = "Sketcher_CompConstrainTools";
|
||||
sStatusTip = sToolTipText;
|
||||
eType = ForEdit;
|
||||
|
||||
setCheckable(false);
|
||||
setRememberLast(false);
|
||||
|
||||
addCommand("Sketcher_ConstrainCoincidentUnified");
|
||||
addCommand("Sketcher_ConstrainHorVer");
|
||||
addCommand("Sketcher_ConstrainParallel");
|
||||
addCommand("Sketcher_ConstrainPerpendicular");
|
||||
addCommand("Sketcher_ConstrainTangent");
|
||||
addCommand("Sketcher_ConstrainEqual");
|
||||
addCommand("Sketcher_ConstrainSymmetric");
|
||||
addCommand("Sketcher_ConstrainBlock");
|
||||
}
|
||||
const char* className() const override { return "CmdSketcherCompConstrainTools"; }
|
||||
};
|
||||
|
||||
// Dimension tool =======================================================
|
||||
|
||||
class GeomSelectionSizes
|
||||
@@ -9923,5 +9954,6 @@ void CreateSketcherCommandsConstraints()
|
||||
rcCmdMgr.addCommand(new CmdSketcherToggleDrivingConstraint());
|
||||
rcCmdMgr.addCommand(new CmdSketcherToggleActiveConstraint());
|
||||
rcCmdMgr.addCommand(new CmdSketcherCompDimensionTools());
|
||||
rcCmdMgr.addCommand(new CmdSketcherCompConstrainTools());
|
||||
}
|
||||
// clang-format on
|
||||
|
||||
@@ -1535,8 +1535,8 @@ Gui::Action* CmdSketcherCompCreateFillets::createAction()
|
||||
_pcAction = pcAction;
|
||||
languageChange();
|
||||
|
||||
pcAction->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_CreateFillet"));
|
||||
int defaultId = 0;
|
||||
pcAction->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_CreatePointFillet"));
|
||||
int defaultId = 1;
|
||||
pcAction->setProperty("defaultAction", QVariant(defaultId));
|
||||
|
||||
return pcAction;
|
||||
|
||||
@@ -1210,106 +1210,14 @@ bool ViewProviderSketch::mouseButtonPressed(int Button, bool pressed, const SbVe
|
||||
// delegate to handler whether to quit or do otherwise
|
||||
sketchHandler->pressRightButton(Base::Vector2d(x, y));
|
||||
return true;
|
||||
case STATUS_NONE: {
|
||||
// A right click shouldn't change the Edit Mode
|
||||
if (preselection.isPreselectPointValid()) {
|
||||
return true;
|
||||
}
|
||||
else if (preselection.isPreselectCurveValid()) {
|
||||
return true;
|
||||
}
|
||||
else if (!preselection.PreselectConstraintSet.empty()) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
Gui::MenuItem geom;
|
||||
geom.setCommand("Sketcher geoms");
|
||||
geom << "Sketcher_CreatePoint"
|
||||
<< "Sketcher_CreateArc"
|
||||
<< "Sketcher_Create3PointArc"
|
||||
<< "Sketcher_CreateCircle"
|
||||
<< "Sketcher_Create3PointCircle"
|
||||
<< "Sketcher_CreateLine"
|
||||
<< "Sketcher_CreatePolyline"
|
||||
<< "Sketcher_CreateRectangle"
|
||||
<< "Sketcher_CreateHexagon"
|
||||
<< "Sketcher_CreateFillet"
|
||||
<< "Sketcher_CreatePointFillet"
|
||||
<< "Sketcher_Trimming"
|
||||
<< "Sketcher_Extend"
|
||||
<< "Sketcher_External"
|
||||
<< "Sketcher_ToggleConstruction"
|
||||
/*<< "Sketcher_CreateText"*/
|
||||
/*<< "Sketcher_CreateDraftLine"*/
|
||||
<< "Separator";
|
||||
|
||||
Gui::Application::Instance->setupContextMenu("View", &geom);
|
||||
// Create the Context Menu using the Main View Qt Widget
|
||||
QMenu contextMenu(viewer->getGLWidget());
|
||||
Gui::MenuManager::getInstance()->setupContextMenu(&geom, contextMenu);
|
||||
contextMenu.exec(QCursor::pos());
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
case STATUS_NONE:
|
||||
case STATUS_SELECT_Point:
|
||||
break;
|
||||
case STATUS_SELECT_Edge: {
|
||||
Gui::MenuItem geom;
|
||||
geom.setCommand("Sketcher constraints");
|
||||
geom << "Sketcher_ConstrainVertical"
|
||||
<< "Sketcher_ConstrainHorizontal";
|
||||
|
||||
// Gets a selection vector
|
||||
std::vector<Gui::SelectionObject> selection = Gui::Selection().getSelectionEx();
|
||||
|
||||
bool rightClickOnSelectedLine = false;
|
||||
|
||||
/*
|
||||
* Add Multiple Line Constraints to the menu
|
||||
*/
|
||||
// only one sketch with its subelements are allowed to be selected
|
||||
if (selection.size() == 1) {
|
||||
// get the needed lists and objects
|
||||
const std::vector<std::string>& SubNames = selection[0].getSubNames();
|
||||
|
||||
// Two Objects are selected
|
||||
if (SubNames.size() == 2) {
|
||||
// go through the selected subelements
|
||||
for (std::vector<std::string>::const_iterator it = SubNames.begin();
|
||||
it != SubNames.end();
|
||||
++it) {
|
||||
|
||||
// If the object selected is of type edge
|
||||
if (it->size() > 4 && it->substr(0, 4) == "Edge") {
|
||||
// Get the index of the object selected
|
||||
int GeoId = std::atoi(it->substr(4, 4000).c_str()) - 1;
|
||||
if (preselection.PreselectCurve == GeoId)
|
||||
rightClickOnSelectedLine = true;
|
||||
}
|
||||
else {
|
||||
// The selection is not exclusively edges
|
||||
rightClickOnSelectedLine = false;
|
||||
}
|
||||
}// End of Iteration
|
||||
}
|
||||
}
|
||||
|
||||
if (rightClickOnSelectedLine) {
|
||||
geom << "Sketcher_ConstrainParallel"
|
||||
<< "Sketcher_ConstrainPerpendicular";
|
||||
}
|
||||
|
||||
Gui::Application::Instance->setupContextMenu("View", &geom);
|
||||
// Create the Context Menu using the Main View Qt Widget
|
||||
QMenu contextMenu(viewer->getGLWidget());
|
||||
Gui::MenuManager::getInstance()->setupContextMenu(&geom, contextMenu);
|
||||
contextMenu.exec(QCursor::pos());
|
||||
|
||||
case STATUS_SELECT_Edge:
|
||||
case STATUS_SELECT_Cross:
|
||||
case STATUS_SELECT_Constraint: {
|
||||
generateContextMenu();
|
||||
return true;
|
||||
}
|
||||
case STATUS_SELECT_Cross:
|
||||
case STATUS_SELECT_Constraint:
|
||||
case STATUS_SKETCH_DragPoint:
|
||||
case STATUS_SKETCH_DragCurve:
|
||||
case STATUS_SKETCH_DragConstraint:
|
||||
@@ -3899,4 +3807,169 @@ bool ViewProviderSketch::isInEditMode() const
|
||||
{
|
||||
return editCoinManager != nullptr;
|
||||
}
|
||||
void ViewProviderSketch::generateContextMenu()
|
||||
{
|
||||
int selectedEdges = 0;
|
||||
int selectedLines = 0;
|
||||
int selectedConics = 0;
|
||||
int selectedPoints = 0;
|
||||
int selectedConstraints = 0;
|
||||
|
||||
Gui::MenuItem menu;
|
||||
menu.setCommand("Sketcher context");
|
||||
|
||||
std::vector<Gui::SelectionObject> selection =
|
||||
Gui::Selection().getSelectionEx(0, Sketcher::SketchObject::getClassTypeId());
|
||||
|
||||
// if something is selected, count different elements in the current selection
|
||||
if (selection.size() > 0) {
|
||||
const std::vector<std::string> SubNames = selection[0].getSubNames();
|
||||
|
||||
for (auto& name : SubNames) {
|
||||
if (name.substr(0, 4) == "Edge") {
|
||||
++selectedEdges;
|
||||
|
||||
int geoId = std::atoi(name.substr(4, 4000).c_str()) - 1;
|
||||
if (geoId >= 0) {
|
||||
const Part::Geometry* geo = getSketchObject()->getGeometry(geoId);
|
||||
if (isLineSegment(*geo)) {
|
||||
++selectedLines;
|
||||
}
|
||||
else {
|
||||
++selectedConics;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (name.substr(0, 4) == "Vert") {
|
||||
++selectedPoints;
|
||||
}
|
||||
else if (name.substr(0, 4) == "Cons") {
|
||||
++selectedConstraints;
|
||||
}
|
||||
}
|
||||
// build context menu items depending on the selection
|
||||
if (selectedEdges >= 1 && selectedPoints == 0) {
|
||||
menu << "Sketcher_Dimension";
|
||||
if (selectedConics == 0) {
|
||||
menu << "Sketcher_ConstrainHorVer"
|
||||
<< "Sketcher_ConstrainVertical"
|
||||
<< "Sketcher_ConstrainHorizontal";
|
||||
|
||||
if (selectedLines > 1) {
|
||||
menu << "Sketcher_ConstrainParallel";
|
||||
|
||||
if (selectedLines == 2) {
|
||||
menu << "Sketcher_ConstrainPerpendicular"
|
||||
<< "Sketcher_ConstrainTangent";
|
||||
}
|
||||
|
||||
menu << "Sketcher_ConstrainEqual";
|
||||
}
|
||||
menu << "Sketcher_ConstrainBlock";
|
||||
}
|
||||
else if (selectedConics > 1 && selectedLines == 0) {
|
||||
menu << "Sketcher_ConstrainCoincidentUnified"
|
||||
<< "Sketcher_ConstrainTangent"
|
||||
<< "Sketcher_ConstrainEqual";
|
||||
}
|
||||
else if (selectedConics == 1 && selectedLines == 1) {
|
||||
menu << "Sketcher_ConstrainTangent";
|
||||
}
|
||||
}
|
||||
else if (selectedEdges == 1 && selectedPoints >= 1) {
|
||||
menu << "Sketcher_Dimension";
|
||||
if (selectedConics == 0) {
|
||||
menu << "Sketcher_ConstrainCoincidentUnified"
|
||||
<< "Sketcher_ConstrainHorVer"
|
||||
<< "Sketcher_ConstrainVertical"
|
||||
<< "Sketcher_ConstrainHorizontal";
|
||||
if (selectedPoints == 2) {
|
||||
menu << "Sketcher_ConstrainSymmetric";
|
||||
}
|
||||
}
|
||||
else {
|
||||
menu << "Sketcher_ConstrainCoincidentUnified"
|
||||
<< "Sketcher_ConstrainPerpendicular"
|
||||
<< "Sketcher_ConstrainTangent";
|
||||
}
|
||||
}
|
||||
else if (selectedEdges == 0 && selectedPoints >= 1) {
|
||||
menu << "Sketcher_Dimension";
|
||||
|
||||
if (selectedPoints > 1) {
|
||||
menu << "Sketcher_ConstrainCoincidentUnified"
|
||||
<< "Sketcher_ConstrainHorVer"
|
||||
<< "Sketcher_ConstrainVertical"
|
||||
<< "Sketcher_ConstrainHorizontal";
|
||||
}
|
||||
}
|
||||
else if (selectedLines >= 1 && selectedPoints >= 1) {
|
||||
menu << "Sketcher_Dimension"
|
||||
<< "Sketcher_ConstrainHorVer"
|
||||
<< "Sketcher_ConstrainVertical"
|
||||
<< "Sketcher_ConstrainHorizontal";
|
||||
}
|
||||
// context menu if only constraints are selected
|
||||
else if (selectedConstraints >= 1) {
|
||||
menu << "Sketcher_ToggleDrivingConstraint"
|
||||
<< "Sketcher_ToggleActiveConstraint"
|
||||
<< "Sketcher_SelectElementsAssociatedWithConstraints"
|
||||
<< "Separator"
|
||||
<< "Std_Delete";
|
||||
}
|
||||
// add the rest of the context menu if geometry is selected
|
||||
if (selectedPoints != 0 || selectedEdges != 0) {
|
||||
menu << "Separator"
|
||||
<< "Sketcher_ToggleConstruction"
|
||||
<< "Separator"
|
||||
<< "Sketcher_CreatePointFillet"
|
||||
<< "Sketcher_Trimming"
|
||||
<< "Sketcher_Extend"
|
||||
<< "Sketcher_Offset"
|
||||
<< "Sketcher_Rotate"
|
||||
<< "Separator"
|
||||
<< "Sketcher_CompDimensionTools"
|
||||
<< "Sketcher_CompConstrainTools"
|
||||
<< "Sketcher_SelectConstraints"
|
||||
<< "Separator"
|
||||
<< "Std_Delete";
|
||||
}
|
||||
}
|
||||
// context menu without a selection
|
||||
else {
|
||||
menu << "Sketcher_ViewSketch"
|
||||
<< "Sketcher_ViewSection"
|
||||
<< "Std_ViewFitAll"
|
||||
<< "Separator"
|
||||
<< "Sketcher_CreatePoint"
|
||||
<< "Sketcher_CreatePolyline"
|
||||
<< "Sketcher_CreateArc"
|
||||
<< "Sketcher_CreateCircle"
|
||||
<< "Sketcher_CreateRectangle"
|
||||
<< "Sketcher_CreateHexagon"
|
||||
<< "Sketcher_CreateBSpline"
|
||||
<< "Separator"
|
||||
<< "Sketcher_ToggleConstruction"
|
||||
<< "Separator"
|
||||
<< "Sketcher_CreatePointFillet"
|
||||
<< "Sketcher_Trimming"
|
||||
<< "Sketcher_Extend"
|
||||
<< "Separator"
|
||||
<< "Sketcher_External"
|
||||
<< "Separator"
|
||||
<< "Sketcher_CompDimensionTools"
|
||||
<< "Sketcher_CompConstrainTools"
|
||||
<< "Separator"
|
||||
<< "Sketcher_DeleteAllGeometry"
|
||||
<< "Sketcher_DeleteAllConstraints"
|
||||
<< "Separator"
|
||||
<< "Sketcher_LeaveSketch";
|
||||
}
|
||||
// create context menu
|
||||
Gui::Application::Instance->setupContextMenu("Sketch", &menu);
|
||||
QMenu contextMenu(
|
||||
qobject_cast<Gui::View3DInventor*>(this->getActiveView())->getViewer()->getGLWidget());
|
||||
Gui::MenuManager::getInstance()->setupContextMenu(&menu, contextMenu);
|
||||
contextMenu.exec(QCursor::pos());
|
||||
}
|
||||
// clang-format on
|
||||
|
||||
@@ -567,6 +567,10 @@ public:
|
||||
{
|
||||
return Mode;
|
||||
}
|
||||
|
||||
// create right click context menu based on selection in the 3D view
|
||||
void generateContextMenu();
|
||||
|
||||
//@}
|
||||
|
||||
/** @name Drawing functions */
|
||||
|
||||
@@ -374,8 +374,8 @@ void SketcherAddWorkspaceFillets(T& geom);
|
||||
template<>
|
||||
inline void SketcherAddWorkspaceFillets<Gui::MenuItem>(Gui::MenuItem& geom)
|
||||
{
|
||||
geom << "Sketcher_CreateFillet"
|
||||
<< "Sketcher_CreatePointFillet";
|
||||
geom << "Sketcher_CreatePointFillet"
|
||||
<< "Sketcher_CreateFillet";
|
||||
}
|
||||
|
||||
template<>
|
||||
|
||||
Reference in New Issue
Block a user