Improvements to contextual right click menu in Sketcher.
Consider preselection, external geo and copy/cut/paste commands.
This commit is contained in:
committed by
Chris Hennes
parent
47005e837f
commit
4164919e58
@@ -968,14 +968,7 @@ bool ViewProviderSketch::mouseButtonPressed(int Button, bool pressed, const SbVe
|
||||
std::stringstream ss;
|
||||
ss << "Vertex" << preselection.getPreselectionVertexIndex();
|
||||
|
||||
if (isSelected(ss.str())) {
|
||||
rmvSelection(ss.str());
|
||||
}
|
||||
else {
|
||||
addSelection2(
|
||||
ss.str(), pp->getPoint()[0], pp->getPoint()[1], pp->getPoint()[2]);
|
||||
drag.resetIds();
|
||||
}
|
||||
preselectToSelection(ss, pp, true);
|
||||
}
|
||||
Mode = STATUS_NONE;
|
||||
return true;
|
||||
@@ -988,16 +981,7 @@ bool ViewProviderSketch::mouseButtonPressed(int Button, bool pressed, const SbVe
|
||||
else// external geometry
|
||||
ss << "ExternalEdge" << preselection.getPreselectionExternalEdgeIndex();
|
||||
|
||||
// If edge already selected move from selection
|
||||
if (isSelected(ss.str())) {
|
||||
rmvSelection(ss.str());
|
||||
}
|
||||
else {
|
||||
// Add edge to the selection
|
||||
addSelection2(
|
||||
ss.str(), pp->getPoint()[0], pp->getPoint()[1], pp->getPoint()[2]);
|
||||
drag.resetIds();
|
||||
}
|
||||
preselectToSelection(ss, pp, true);
|
||||
}
|
||||
Mode = STATUS_NONE;
|
||||
return true;
|
||||
@@ -1019,16 +1003,7 @@ bool ViewProviderSketch::mouseButtonPressed(int Button, bool pressed, const SbVe
|
||||
break;
|
||||
}
|
||||
|
||||
// If cross already selected move from selection
|
||||
if (isSelected(ss.str())) {
|
||||
rmvSelection(ss.str());
|
||||
}
|
||||
else {
|
||||
// Add cross to the selection
|
||||
addSelection2(
|
||||
ss.str(), pp->getPoint()[0], pp->getPoint()[1], pp->getPoint()[2]);
|
||||
drag.resetIds();
|
||||
}
|
||||
preselectToSelection(ss, pp, true);
|
||||
}
|
||||
Mode = STATUS_NONE;
|
||||
return true;
|
||||
@@ -1044,18 +1019,7 @@ bool ViewProviderSketch::mouseButtonPressed(int Button, bool pressed, const SbVe
|
||||
std::stringstream ss;
|
||||
ss << Sketcher::PropertyConstraintList::getConstraintName(id);
|
||||
|
||||
// If the constraint already selected remove
|
||||
if (isSelected(ss.str())) {
|
||||
rmvSelection(ss.str());
|
||||
}
|
||||
else {
|
||||
// Add constraint to current selection
|
||||
addSelection2(ss.str(),
|
||||
pp->getPoint()[0],
|
||||
pp->getPoint()[1],
|
||||
pp->getPoint()[2]);
|
||||
drag.resetIds();
|
||||
}
|
||||
preselectToSelection(ss, pp, true);
|
||||
}
|
||||
}
|
||||
Mode = STATUS_NONE;
|
||||
@@ -1210,17 +1174,100 @@ bool ViewProviderSketch::mouseButtonPressed(int Button, bool pressed, const SbVe
|
||||
}
|
||||
// Right mouse button ****************************************************
|
||||
else if (Button == 2) {
|
||||
if (!pressed) {
|
||||
if (pressed) {
|
||||
// Do things depending on the mode of the user interaction
|
||||
switch (Mode) {
|
||||
case STATUS_NONE: {
|
||||
if (preselection.isPreselectPointValid()) {
|
||||
// Base::Console().Log("start dragging, point:%d\n",this->DragPoint);
|
||||
Mode = STATUS_SELECT_Point;
|
||||
}
|
||||
else if (preselection.isPreselectCurveValid()) {
|
||||
// Base::Console().Log("start dragging, point:%d\n",this->DragPoint);
|
||||
Mode = STATUS_SELECT_Edge;
|
||||
}
|
||||
else if (preselection.isCrossPreselected()) {
|
||||
// Base::Console().Log("start dragging, point:%d\n",this->DragPoint);
|
||||
Mode = STATUS_SELECT_Cross;
|
||||
}
|
||||
else if (!preselection.PreselectConstraintSet.empty()) {
|
||||
// Base::Console().Log("start dragging, point:%d\n",this->DragPoint);
|
||||
Mode = STATUS_SELECT_Constraint;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!pressed) {
|
||||
switch (Mode) {
|
||||
case STATUS_SKETCH_UseHandler:
|
||||
// delegate to handler whether to quit or do otherwise
|
||||
sketchHandler->pressRightButton(Base::Vector2d(x, y));
|
||||
return true;
|
||||
case STATUS_NONE:
|
||||
generateContextMenu();
|
||||
return true;
|
||||
case STATUS_SELECT_Point:
|
||||
if (pp) {
|
||||
// Base::Console().Log("Select Point:%d\n",this->DragPoint);
|
||||
// Do selection
|
||||
std::stringstream ss;
|
||||
ss << "Vertex" << preselection.getPreselectionVertexIndex();
|
||||
|
||||
preselectToSelection(ss, pp, false);
|
||||
}
|
||||
Mode = STATUS_NONE;
|
||||
generateContextMenu();
|
||||
return true;
|
||||
case STATUS_SELECT_Edge:
|
||||
if (pp) {
|
||||
// Base::Console().Log("Select Point:%d\n",this->DragPoint);
|
||||
std::stringstream ss;
|
||||
if (preselection.isEdge()) {
|
||||
ss << "Edge" << preselection.getPreselectionEdgeIndex();
|
||||
}
|
||||
else { // external geometry
|
||||
ss << "ExternalEdge" << preselection.getPreselectionExternalEdgeIndex();
|
||||
}
|
||||
|
||||
preselectToSelection(ss, pp, false);
|
||||
}
|
||||
Mode = STATUS_NONE;
|
||||
generateContextMenu();
|
||||
return true;
|
||||
case STATUS_SELECT_Cross:
|
||||
if (pp) {
|
||||
// Base::Console().Log("Select Point:%d\n",this->DragPoint);
|
||||
std::stringstream ss;
|
||||
switch (preselection.PreselectCross) {
|
||||
case Preselection::Axes::RootPoint:
|
||||
ss << "RootPoint";
|
||||
break;
|
||||
case Preselection::Axes::HorizontalAxis:
|
||||
ss << "H_Axis";
|
||||
break;
|
||||
case Preselection::Axes::VerticalAxis:
|
||||
ss << "V_Axis";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
preselectToSelection(ss, pp, false);
|
||||
}
|
||||
Mode = STATUS_NONE;
|
||||
generateContextMenu();
|
||||
return true;
|
||||
case STATUS_SELECT_Constraint: {
|
||||
if (pp) {
|
||||
auto sels = preselection.PreselectConstraintSet;
|
||||
for (int id : sels) {
|
||||
std::stringstream ss;
|
||||
ss << Sketcher::PropertyConstraintList::getConstraintName(id);
|
||||
|
||||
preselectToSelection(ss, pp, false);
|
||||
}
|
||||
}
|
||||
Mode = STATUS_NONE;
|
||||
generateContextMenu();
|
||||
return true;
|
||||
}
|
||||
@@ -3907,7 +3954,7 @@ void ViewProviderSketch::generateContextMenu()
|
||||
for (auto& name : SubNames) {
|
||||
int geoId = std::atoi(name.substr(4, 4000).c_str()) - 1;
|
||||
const Part::Geometry* geo = getSketchObject()->getGeometry(geoId);
|
||||
if (name.substr(0, 4) == "Edge") {
|
||||
if (name.substr(0, 4) == "Edge" || name.substr(0, 12) == "ExternalEdge") {
|
||||
++selectedEdges;
|
||||
|
||||
if (geoId >= 0) {
|
||||
@@ -4049,9 +4096,9 @@ void ViewProviderSketch::generateContextMenu()
|
||||
menu << "Separator"
|
||||
<< "Sketcher_ToggleConstruction"
|
||||
<< "Separator"
|
||||
<< "Sketcher_CreatePointFillet"
|
||||
<< "Sketcher_Trimming"
|
||||
<< "Sketcher_Extend"
|
||||
<< "Sketcher_CopyClipboard"
|
||||
<< "Sketcher_Cut"
|
||||
<< "Sketcher_Paste"
|
||||
<< "Sketcher_Offset"
|
||||
<< "Sketcher_Rotate"
|
||||
<< "Separator"
|
||||
@@ -4090,6 +4137,8 @@ void ViewProviderSketch::generateContextMenu()
|
||||
<< "Sketcher_DeleteAllGeometry"
|
||||
<< "Sketcher_DeleteAllConstraints"
|
||||
<< "Separator"
|
||||
<< "Sketcher_Paste"
|
||||
<< "Separator"
|
||||
<< "Sketcher_LeaveSketch";
|
||||
}
|
||||
// create context menu
|
||||
@@ -4099,4 +4148,19 @@ void ViewProviderSketch::generateContextMenu()
|
||||
Gui::MenuManager::getInstance()->setupContextMenu(&menu, contextMenu);
|
||||
contextMenu.exec(QCursor::pos());
|
||||
}
|
||||
|
||||
void ViewProviderSketch::preselectToSelection(const std::stringstream& ss,
|
||||
boost::scoped_ptr<SoPickedPoint>& pp,
|
||||
bool toggle)
|
||||
{
|
||||
// If toggle true and preselection already selected remove from selection
|
||||
if (toggle && isSelected(ss.str())) {
|
||||
rmvSelection(ss.str());
|
||||
}
|
||||
// add to selection
|
||||
else {
|
||||
addSelection2(ss.str(), pp->getPoint()[0], pp->getPoint()[1], pp->getPoint()[2]);
|
||||
drag.resetIds();
|
||||
}
|
||||
}
|
||||
// clang-format on
|
||||
|
||||
@@ -795,6 +795,9 @@ private:
|
||||
void rmvSelection(const std::string& subNameSuffix);
|
||||
bool addSelection(const std::string& subNameSuffix, float x = 0, float y = 0, float z = 0);
|
||||
bool addSelection2(const std::string& subNameSuffix, float x = 0, float y = 0, float z = 0);
|
||||
void preselectToSelection(const std::stringstream& ss,
|
||||
boost::scoped_ptr<SoPickedPoint>& pp,
|
||||
bool toggle);
|
||||
//@}
|
||||
|
||||
/** @name miscelanea utilities */
|
||||
|
||||
Reference in New Issue
Block a user