Sketcher: UI toolbar/menu remove axes alignment
This commit is contained in:
@@ -90,6 +90,8 @@ void ActivateAcceleratorHandler(Gui::Document *doc, DrawSketchHandler *handler)
|
||||
}
|
||||
}
|
||||
|
||||
// ================================================================================
|
||||
|
||||
// Close Shape Command
|
||||
DEF_STD_CMD_A(CmdSketcherCloseShape)
|
||||
|
||||
@@ -200,6 +202,7 @@ bool CmdSketcherCloseShape::isActive(void)
|
||||
return isSketcherAcceleratorActive(getActiveGuiDocument(), true);
|
||||
}
|
||||
|
||||
// ================================================================================
|
||||
|
||||
// Connect Edges Command
|
||||
DEF_STD_CMD_A(CmdSketcherConnect)
|
||||
@@ -286,6 +289,8 @@ bool CmdSketcherConnect::isActive(void)
|
||||
return isSketcherAcceleratorActive(getActiveGuiDocument(), true);
|
||||
}
|
||||
|
||||
// ================================================================================
|
||||
|
||||
// Select Constraints of selected elements
|
||||
DEF_STD_CMD_A(CmdSketcherSelectConstraints)
|
||||
|
||||
@@ -358,6 +363,8 @@ bool CmdSketcherSelectConstraints::isActive(void)
|
||||
return isSketcherAcceleratorActive(getActiveGuiDocument(), true);
|
||||
}
|
||||
|
||||
// ================================================================================
|
||||
|
||||
// Select Origin
|
||||
DEF_STD_CMD_A(CmdSketcherSelectOrigin)
|
||||
|
||||
@@ -402,6 +409,8 @@ bool CmdSketcherSelectOrigin::isActive(void)
|
||||
return isSketcherAcceleratorActive(getActiveGuiDocument(), false);
|
||||
}
|
||||
|
||||
// ================================================================================
|
||||
|
||||
// Select Vertical Axis
|
||||
DEF_STD_CMD_A(CmdSketcherSelectVerticalAxis)
|
||||
|
||||
@@ -444,6 +453,8 @@ bool CmdSketcherSelectVerticalAxis::isActive(void)
|
||||
return isSketcherAcceleratorActive(getActiveGuiDocument(), false);
|
||||
}
|
||||
|
||||
// ================================================================================
|
||||
|
||||
// Select Horizontal Axis
|
||||
DEF_STD_CMD_A(CmdSketcherSelectHorizontalAxis)
|
||||
|
||||
@@ -486,6 +497,8 @@ bool CmdSketcherSelectHorizontalAxis::isActive(void)
|
||||
return isSketcherAcceleratorActive(getActiveGuiDocument(), false);
|
||||
}
|
||||
|
||||
// ================================================================================
|
||||
|
||||
DEF_STD_CMD_A(CmdSketcherSelectRedundantConstraints)
|
||||
|
||||
CmdSketcherSelectRedundantConstraints::CmdSketcherSelectRedundantConstraints()
|
||||
@@ -538,6 +551,8 @@ bool CmdSketcherSelectRedundantConstraints::isActive(void)
|
||||
return isSketcherAcceleratorActive(getActiveGuiDocument(), false);
|
||||
}
|
||||
|
||||
// ================================================================================
|
||||
|
||||
DEF_STD_CMD_A(CmdSketcherSelectMalformedConstraints)
|
||||
|
||||
CmdSketcherSelectMalformedConstraints::CmdSketcherSelectMalformedConstraints()
|
||||
@@ -590,6 +605,8 @@ bool CmdSketcherSelectMalformedConstraints::isActive(void)
|
||||
return isSketcherAcceleratorActive(getActiveGuiDocument(), false);
|
||||
}
|
||||
|
||||
// ================================================================================
|
||||
|
||||
DEF_STD_CMD_A(CmdSketcherSelectPartiallyRedundantConstraints)
|
||||
|
||||
CmdSketcherSelectPartiallyRedundantConstraints::CmdSketcherSelectPartiallyRedundantConstraints()
|
||||
@@ -642,6 +659,7 @@ bool CmdSketcherSelectPartiallyRedundantConstraints::isActive(void)
|
||||
return isSketcherAcceleratorActive(getActiveGuiDocument(), false);
|
||||
}
|
||||
|
||||
// ================================================================================
|
||||
|
||||
DEF_STD_CMD_A(CmdSketcherSelectConflictingConstraints)
|
||||
|
||||
@@ -693,6 +711,8 @@ bool CmdSketcherSelectConflictingConstraints::isActive(void)
|
||||
return isSketcherAcceleratorActive(getActiveGuiDocument(), false);
|
||||
}
|
||||
|
||||
// ================================================================================
|
||||
|
||||
DEF_STD_CMD_A(CmdSketcherSelectElementsAssociatedWithConstraints)
|
||||
|
||||
CmdSketcherSelectElementsAssociatedWithConstraints::CmdSketcherSelectElementsAssociatedWithConstraints()
|
||||
@@ -813,6 +833,8 @@ bool CmdSketcherSelectElementsAssociatedWithConstraints::isActive(void)
|
||||
return isSketcherAcceleratorActive(getActiveGuiDocument(), true);
|
||||
}
|
||||
|
||||
// ================================================================================
|
||||
|
||||
DEF_STD_CMD_A(CmdSketcherSelectElementsWithDoFs)
|
||||
|
||||
CmdSketcherSelectElementsWithDoFs::CmdSketcherSelectElementsWithDoFs()
|
||||
@@ -896,6 +918,8 @@ bool CmdSketcherSelectElementsWithDoFs::isActive(void)
|
||||
return isSketcherAcceleratorActive(getActiveGuiDocument(), false);
|
||||
}
|
||||
|
||||
// ================================================================================
|
||||
|
||||
DEF_STD_CMD_A(CmdSketcherRestoreInternalAlignmentGeometry)
|
||||
|
||||
CmdSketcherRestoreInternalAlignmentGeometry::CmdSketcherRestoreInternalAlignmentGeometry()
|
||||
@@ -989,6 +1013,8 @@ bool CmdSketcherRestoreInternalAlignmentGeometry::isActive(void)
|
||||
return isSketcherAcceleratorActive(getActiveGuiDocument(), true);
|
||||
}
|
||||
|
||||
// ================================================================================
|
||||
|
||||
DEF_STD_CMD_A(CmdSketcherSymmetry)
|
||||
|
||||
CmdSketcherSymmetry::CmdSketcherSymmetry()
|
||||
@@ -1189,6 +1215,7 @@ bool CmdSketcherSymmetry::isActive(void)
|
||||
return isSketcherAcceleratorActive(getActiveGuiDocument(), true);
|
||||
}
|
||||
|
||||
// ================================================================================
|
||||
|
||||
class SketcherCopy : public Gui::Command {
|
||||
public:
|
||||
@@ -1536,6 +1563,8 @@ bool CmdSketcherCopy::isActive(void)
|
||||
return isSketcherAcceleratorActive(getActiveGuiDocument(), true);
|
||||
}
|
||||
|
||||
// ================================================================================
|
||||
|
||||
class CmdSketcherClone : public SketcherCopy
|
||||
{
|
||||
public:
|
||||
@@ -1622,6 +1651,8 @@ bool CmdSketcherMove::isActive(void)
|
||||
return isSketcherAcceleratorActive(getActiveGuiDocument(), true);
|
||||
}
|
||||
|
||||
// ================================================================================
|
||||
|
||||
DEF_STD_CMD_ACL(CmdSketcherCompCopy)
|
||||
|
||||
CmdSketcherCompCopy::CmdSketcherCompCopy()
|
||||
@@ -1720,6 +1751,7 @@ bool CmdSketcherCompCopy::isActive(void)
|
||||
return isSketcherAcceleratorActive( getActiveGuiDocument(), true );
|
||||
}
|
||||
|
||||
// ================================================================================
|
||||
|
||||
// TODO: replace XPM cursor with SVG file
|
||||
/* XPM */
|
||||
@@ -1883,7 +1915,6 @@ protected:
|
||||
std::vector<AutoConstraint> sugConstr1;
|
||||
};
|
||||
|
||||
|
||||
DEF_STD_CMD_A(CmdSketcherRectangularArray)
|
||||
|
||||
CmdSketcherRectangularArray::CmdSketcherRectangularArray()
|
||||
@@ -2022,6 +2053,8 @@ bool CmdSketcherRectangularArray::isActive(void)
|
||||
return isSketcherAcceleratorActive(getActiveGuiDocument(), true);
|
||||
}
|
||||
|
||||
// ================================================================================
|
||||
|
||||
DEF_STD_CMD_A(CmdSketcherDeleteAllGeometry)
|
||||
|
||||
CmdSketcherDeleteAllGeometry::CmdSketcherDeleteAllGeometry()
|
||||
@@ -2083,6 +2116,8 @@ bool CmdSketcherDeleteAllGeometry::isActive(void)
|
||||
return isSketcherAcceleratorActive(getActiveGuiDocument(), false);
|
||||
}
|
||||
|
||||
// ================================================================================
|
||||
|
||||
DEF_STD_CMD_A(CmdSketcherDeleteAllConstraints)
|
||||
|
||||
CmdSketcherDeleteAllConstraints::CmdSketcherDeleteAllConstraints()
|
||||
@@ -2144,6 +2179,124 @@ bool CmdSketcherDeleteAllConstraints::isActive(void)
|
||||
return isSketcherAcceleratorActive(getActiveGuiDocument(), false);
|
||||
}
|
||||
|
||||
// ================================================================================
|
||||
|
||||
|
||||
DEF_STD_CMD_A(CmdSketcherRemoveAxesAlignment)
|
||||
|
||||
CmdSketcherRemoveAxesAlignment::CmdSketcherRemoveAxesAlignment()
|
||||
:Command("Sketcher_RemoveAxesAlignment")
|
||||
{
|
||||
sAppModule = "Sketcher";
|
||||
sGroup = QT_TR_NOOP("Sketcher");
|
||||
sMenuText = QT_TR_NOOP("Remove Axes Alignment");
|
||||
sToolTipText = QT_TR_NOOP("Modifies constraints to remove axes alignment while trying to preserve the constraint relationship of the selection");
|
||||
sWhatsThis = "Sketcher_RemoveAxesAlignment";
|
||||
sStatusTip = sToolTipText;
|
||||
sPixmap = "Sketcher_RemoveAxesAlignment";
|
||||
sAccel = "";
|
||||
eType = ForEdit;
|
||||
}
|
||||
|
||||
void CmdSketcherRemoveAxesAlignment::activated(int iMsg)
|
||||
{
|
||||
Q_UNUSED(iMsg);
|
||||
// get the selection
|
||||
std::vector<Gui::SelectionObject> selection;
|
||||
selection = getSelection().getSelectionEx(0, Sketcher::SketchObject::getClassTypeId());
|
||||
|
||||
// only one sketch with its subelements are allowed to be selected
|
||||
if (selection.size() != 1) {
|
||||
QMessageBox::warning(Gui::getMainWindow(),
|
||||
QObject::tr("Wrong selection"),
|
||||
QObject::tr("Select elements from a single sketch."));
|
||||
return;
|
||||
}
|
||||
|
||||
// get the needed lists and objects
|
||||
const std::vector<std::string> &SubNames = selection[0].getSubNames();
|
||||
if (SubNames.empty()) {
|
||||
QMessageBox::warning(Gui::getMainWindow(),
|
||||
QObject::tr("Wrong selection"),
|
||||
QObject::tr("Select elements from a single sketch."));
|
||||
return;
|
||||
}
|
||||
|
||||
Sketcher::SketchObject* Obj = static_cast<Sketcher::SketchObject*>(selection[0].getObject());
|
||||
|
||||
getSelection().clearSelection();
|
||||
|
||||
int LastGeoId = 0;
|
||||
|
||||
// create python command with list of elements
|
||||
std::stringstream stream;
|
||||
int geoids = 0;
|
||||
|
||||
for (std::vector<std::string>::const_iterator it=SubNames.begin(); it != SubNames.end(); ++it) {
|
||||
// only handle non-external edges
|
||||
if (it->size() > 4 && it->substr(0,4) == "Edge") {
|
||||
LastGeoId = std::atoi(it->substr(4,4000).c_str()) - 1;
|
||||
|
||||
// lines to copy
|
||||
if (LastGeoId >= 0) {
|
||||
geoids++;
|
||||
stream << LastGeoId << ",";
|
||||
}
|
||||
}
|
||||
else if (it->size() > 6 && it->substr(0,6) == "Vertex") {
|
||||
// only if it is a GeomPoint
|
||||
int VtId = std::atoi(it->substr(6,4000).c_str()) - 1;
|
||||
int GeoId;
|
||||
Sketcher::PointPos PosId;
|
||||
Obj->getGeoVertexIndex(VtId, GeoId, PosId);
|
||||
if (Obj->getGeometry(GeoId)->getTypeId() == Part::GeomPoint::getClassTypeId()) {
|
||||
LastGeoId = GeoId;
|
||||
// points to copy
|
||||
if (LastGeoId >= 0) {
|
||||
geoids++;
|
||||
stream << LastGeoId << ",";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (geoids < 1) {
|
||||
QMessageBox::warning(Gui::getMainWindow(),
|
||||
QObject::tr("Wrong selection"),
|
||||
QObject::tr("Removal of axes alignment requires at least one selected non-external geometric element"));
|
||||
return;
|
||||
}
|
||||
|
||||
std::string geoIdList = stream.str();
|
||||
|
||||
// remove the last added comma and brackets to make the python list
|
||||
int index = geoIdList.rfind(',');
|
||||
geoIdList.resize(index);
|
||||
geoIdList.insert(0, 1, '[');
|
||||
geoIdList.append(1, ']');
|
||||
|
||||
Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Remove Axes Alignment"));
|
||||
|
||||
try {
|
||||
Gui::cmdAppObjectArgs( Obj,
|
||||
"removeAxesAlignment(%s)",
|
||||
geoIdList.c_str());
|
||||
Gui::Command::commitCommand();
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
Base::Console().Error("%s\n", e.what());
|
||||
Gui::Command::abortCommand();
|
||||
}
|
||||
|
||||
tryAutoRecomputeIfNotSolve(static_cast<Sketcher::SketchObject *>(Obj));
|
||||
|
||||
}
|
||||
|
||||
bool CmdSketcherRemoveAxesAlignment::isActive(void)
|
||||
{
|
||||
return isSketcherAcceleratorActive(getActiveGuiDocument(), true);
|
||||
}
|
||||
|
||||
void CreateSketcherCommandsConstraintAccel(void)
|
||||
{
|
||||
Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager();
|
||||
@@ -2169,4 +2322,5 @@ void CreateSketcherCommandsConstraintAccel(void)
|
||||
rcCmdMgr.addCommand(new CmdSketcherRectangularArray());
|
||||
rcCmdMgr.addCommand(new CmdSketcherDeleteAllGeometry());
|
||||
rcCmdMgr.addCommand(new CmdSketcherDeleteAllConstraints());
|
||||
rcCmdMgr.addCommand(new CmdSketcherRemoveAxesAlignment());
|
||||
}
|
||||
|
||||
@@ -374,6 +374,7 @@ inline void SketcherAddWorkbenchTools<Gui::MenuItem>(Gui::MenuItem& consaccel)
|
||||
<< "Sketcher_Copy"
|
||||
<< "Sketcher_Move"
|
||||
<< "Sketcher_RectangularArray"
|
||||
<< "Sketcher_RemoveAxesAlignment"
|
||||
<< "Separator"
|
||||
<< "Sketcher_DeleteAllGeometry"
|
||||
<< "Sketcher_DeleteAllConstraints";
|
||||
@@ -393,6 +394,7 @@ inline void SketcherAddWorkbenchTools<Gui::ToolBarItem>(Gui::ToolBarItem& consac
|
||||
<< "Sketcher_Symmetry"
|
||||
<< "Sketcher_CompCopy"
|
||||
<< "Sketcher_RectangularArray"
|
||||
<< "Sketcher_RemoveAxesAlignment"
|
||||
<< "Sketcher_DeleteAllConstraints";
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user