[Sketcher] Scale DSH : adds a tool to scale geometries. (#11265)
* Scale DSH : sketcher tool to scale geometries. * Sketcher: Rotate and Scale : Move indexInVec to Utils.h as indexOfGeoId --------- Co-authored-by: Paddle <PaddleStroke@users.noreply.github.com>
This commit is contained in:
@@ -78,6 +78,7 @@ SET(SketcherGui_SRCS
|
||||
DrawSketchHandlerSlot.h
|
||||
DrawSketchHandlerOffset.h
|
||||
DrawSketchHandlerRotate.h
|
||||
DrawSketchHandlerScale.h
|
||||
CommandCreateGeo.cpp
|
||||
CommandConstraints.h
|
||||
CommandConstraints.cpp
|
||||
|
||||
@@ -56,6 +56,7 @@
|
||||
|
||||
#include "DrawSketchHandlerOffset.h"
|
||||
#include "DrawSketchHandlerRotate.h"
|
||||
#include "DrawSketchHandlerScale.h"
|
||||
|
||||
// Hint: this is to prevent to re-format big parts of the file. Remove it later again.
|
||||
// clang-format off
|
||||
@@ -2587,6 +2588,39 @@ bool CmdSketcherRotate::isActive()
|
||||
return isCommandActive(getActiveGuiDocument(), true);
|
||||
}
|
||||
|
||||
// Scale tool =====================================================================
|
||||
|
||||
DEF_STD_CMD_A(CmdSketcherScale)
|
||||
|
||||
CmdSketcherScale::CmdSketcherScale()
|
||||
: Command("Sketcher_Scale")
|
||||
{
|
||||
sAppModule = "Sketcher";
|
||||
sGroup = "Sketcher";
|
||||
sMenuText = QT_TR_NOOP("Scale transform");
|
||||
sToolTipText = QT_TR_NOOP("Scale selected geometries. After selecting the center point you can either enter the scale factor, or select two reference points then scale factor = length(p2-center) / length(p1-center).");
|
||||
sWhatsThis = "Sketcher_Scale";
|
||||
sStatusTip = sToolTipText;
|
||||
sPixmap = "Sketcher_Scale";
|
||||
sAccel = "Z, P, S";
|
||||
eType = ForEdit;
|
||||
}
|
||||
|
||||
void CmdSketcherScale::activated(int iMsg)
|
||||
{
|
||||
Q_UNUSED(iMsg);
|
||||
std::vector<int> listOfGeoIds = getListOfSelectedGeoIds(true);
|
||||
|
||||
if (!listOfGeoIds.empty()) {
|
||||
ActivateHandler(getActiveGuiDocument(), new DrawSketchHandlerScale(listOfGeoIds));
|
||||
}
|
||||
getSelection().clearSelection();
|
||||
}
|
||||
|
||||
bool CmdSketcherScale::isActive()
|
||||
{
|
||||
return isCommandActive(getActiveGuiDocument(), true);
|
||||
}
|
||||
|
||||
|
||||
void CreateSketcherCommandsConstraintAccel()
|
||||
@@ -2606,6 +2640,7 @@ void CreateSketcherCommandsConstraintAccel()
|
||||
rcCmdMgr.addCommand(new CmdSketcherRestoreInternalAlignmentGeometry());
|
||||
rcCmdMgr.addCommand(new CmdSketcherOffset());
|
||||
rcCmdMgr.addCommand(new CmdSketcherRotate());
|
||||
rcCmdMgr.addCommand(new CmdSketcherScale());
|
||||
rcCmdMgr.addCommand(new CmdSketcherSymmetry());
|
||||
rcCmdMgr.addCommand(new CmdSketcherCopy());
|
||||
rcCmdMgr.addCommand(new CmdSketcherClone());
|
||||
|
||||
@@ -345,9 +345,9 @@ private:
|
||||
std::vector<int> geoIdsWhoAlreadyHasEqual = {};
|
||||
|
||||
for (auto& cstr : vals) {
|
||||
int firstIndex = indexInVec(listOfGeoIds, cstr->First);
|
||||
int secondIndex = indexInVec(listOfGeoIds, cstr->Second);
|
||||
int thirdIndex = indexInVec(listOfGeoIds, cstr->Third);
|
||||
int firstIndex = indexOfGeoId(listOfGeoIds, cstr->First);
|
||||
int secondIndex = indexOfGeoId(listOfGeoIds, cstr->Second);
|
||||
int thirdIndex = indexOfGeoId(listOfGeoIds, cstr->Third);
|
||||
|
||||
for (int i = 0; i < numberOfCopiesToMake; i++) {
|
||||
int firstIndexi = firstCurveCreated + firstIndex + static_cast<int>(size) * i;
|
||||
@@ -389,7 +389,7 @@ private:
|
||||
&& firstIndex >= 0 && secondIndex >= 0) {
|
||||
if (!deleteOriginal && cloneConstraints
|
||||
&& cstr->First == cstr->Second) { // only line distances
|
||||
if (indexInVec(geoIdsWhoAlreadyHasEqual, secondIndexi) != -1) {
|
||||
if (indexOfGeoId(geoIdsWhoAlreadyHasEqual, secondIndexi) != -1) {
|
||||
continue;
|
||||
}
|
||||
newConstr->Type = Equal;
|
||||
@@ -414,19 +414,6 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
int indexInVec(const std::vector<int>& vec, int elem) const
|
||||
{
|
||||
if (elem == GeoEnum::GeoUndef) {
|
||||
return GeoEnum::GeoUndef;
|
||||
}
|
||||
for (size_t i = 0; i < vec.size(); i++) {
|
||||
if (vec[i] == elem) {
|
||||
return static_cast<int>(i);
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
Base::Vector3d
|
||||
getRotatedPoint(Base::Vector3d&& pointToRotate, const Base::Vector2d& centerPoint, double angle)
|
||||
{
|
||||
|
||||
516
src/Mod/Sketcher/Gui/DrawSketchHandlerScale.h
Normal file
516
src/Mod/Sketcher/Gui/DrawSketchHandlerScale.h
Normal file
@@ -0,0 +1,516 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2022 Boyer Pierre-Louis <pierrelouis.boyer@gmail.com> *
|
||||
* *
|
||||
* 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 *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef SKETCHERGUI_DrawSketchHandlerScale_H
|
||||
#define SKETCHERGUI_DrawSketchHandlerScale_H
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
#include <Gui/BitmapFactory.h>
|
||||
#include <Gui/Notifications.h>
|
||||
#include <Gui/Command.h>
|
||||
#include <Gui/CommandT.h>
|
||||
|
||||
#include <Mod/Sketcher/App/GeometryFacade.h>
|
||||
#include <Mod/Sketcher/App/SketchObject.h>
|
||||
|
||||
#include "DrawSketchDefaultWidgetController.h"
|
||||
#include "DrawSketchControllableHandler.h"
|
||||
|
||||
#include "GeometryCreationMode.h"
|
||||
#include "Utils.h"
|
||||
|
||||
using namespace Sketcher;
|
||||
|
||||
namespace SketcherGui
|
||||
{
|
||||
|
||||
extern GeometryCreationMode geometryCreationMode; // defined in CommandCreateGeo.cpp
|
||||
|
||||
class DrawSketchHandlerScale;
|
||||
|
||||
using DSHScaleController =
|
||||
DrawSketchDefaultWidgetController<DrawSketchHandlerScale,
|
||||
StateMachines::ThreeSeekEnd,
|
||||
/*PAutoConstraintSize =*/0,
|
||||
/*OnViewParametersT =*/OnViewParameters<3>,
|
||||
/*WidgetParametersT =*/WidgetParameters<0>,
|
||||
/*WidgetCheckboxesT =*/WidgetCheckboxes<1>,
|
||||
/*WidgetComboboxesT =*/WidgetComboboxes<0>>;
|
||||
|
||||
using DSHScaleControllerBase = DSHScaleController::ControllerBase;
|
||||
|
||||
using DrawSketchHandlerScaleBase = DrawSketchControllableHandler<DSHScaleController>;
|
||||
|
||||
class DrawSketchHandlerScale: public DrawSketchHandlerScaleBase
|
||||
{
|
||||
friend DSHScaleController;
|
||||
friend DSHScaleControllerBase;
|
||||
|
||||
public:
|
||||
explicit DrawSketchHandlerScale(std::vector<int> listOfGeoIds)
|
||||
: listOfGeoIds(listOfGeoIds)
|
||||
, deleteOriginal(true)
|
||||
, refLength(0.0)
|
||||
, length(0.0)
|
||||
, scaleFactor(0.0)
|
||||
{}
|
||||
|
||||
DrawSketchHandlerScale(const DrawSketchHandlerScale&) = delete;
|
||||
DrawSketchHandlerScale(DrawSketchHandlerScale&&) = delete;
|
||||
DrawSketchHandlerScale& operator=(const DrawSketchHandlerScale&) = delete;
|
||||
DrawSketchHandlerScale& operator=(DrawSketchHandlerScale&&) = delete;
|
||||
|
||||
~DrawSketchHandlerScale() override = default;
|
||||
|
||||
private:
|
||||
void updateDataAndDrawToPosition(Base::Vector2d onSketchPos) override
|
||||
{
|
||||
switch (state()) {
|
||||
case SelectMode::SeekFirst: {
|
||||
referencePoint = onSketchPos;
|
||||
} break;
|
||||
case SelectMode::SeekSecond: {
|
||||
refLength = (onSketchPos - referencePoint).Length();
|
||||
|
||||
startPoint = onSketchPos;
|
||||
|
||||
CreateAndDrawShapeGeometry();
|
||||
} break;
|
||||
case SelectMode::SeekThird: {
|
||||
length = (onSketchPos - referencePoint).Length();
|
||||
endPoint = onSketchPos;
|
||||
scaleFactor = length / refLength;
|
||||
|
||||
CreateAndDrawShapeGeometry();
|
||||
} break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void executeCommands() override
|
||||
{
|
||||
try {
|
||||
Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Scale geometries"));
|
||||
|
||||
createShape(false);
|
||||
|
||||
commandAddShapeGeometryAndConstraints();
|
||||
|
||||
if (deleteOriginal) {
|
||||
deleteOriginalGeos();
|
||||
}
|
||||
|
||||
Gui::Command::commitCommand();
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
e.ReportException();
|
||||
Gui::NotifyError(sketchgui,
|
||||
QT_TRANSLATE_NOOP("Notifications", "Error"),
|
||||
QT_TRANSLATE_NOOP("Notifications", "Failed to scale"));
|
||||
|
||||
Gui::Command::abortCommand();
|
||||
THROWM(Base::RuntimeError,
|
||||
QT_TRANSLATE_NOOP(
|
||||
"Notifications",
|
||||
"Tool execution aborted") "\n") // This prevents constraints from being
|
||||
// applied on non existing geometry
|
||||
}
|
||||
}
|
||||
|
||||
void createAutoConstraints() override
|
||||
{
|
||||
// none
|
||||
}
|
||||
|
||||
std::string getToolName() const override
|
||||
{
|
||||
return "DSH_Scale";
|
||||
}
|
||||
|
||||
QString getCrosshairCursorSVGName() const override
|
||||
{
|
||||
return QString::fromLatin1("Sketcher_Pointer_Create_Scale");
|
||||
}
|
||||
|
||||
std::unique_ptr<QWidget> createWidget() const override
|
||||
{
|
||||
return std::make_unique<SketcherToolDefaultWidget>();
|
||||
}
|
||||
|
||||
bool isWidgetVisible() const override
|
||||
{
|
||||
return true;
|
||||
};
|
||||
|
||||
QPixmap getToolIcon() const override
|
||||
{
|
||||
return Gui::BitmapFactory().pixmap("Sketcher_Scale");
|
||||
}
|
||||
|
||||
QString getToolWidgetText() const override
|
||||
{
|
||||
return QString(QObject::tr("Scale parameters"));
|
||||
}
|
||||
|
||||
void activated() override
|
||||
{
|
||||
DrawSketchDefaultHandler::activated();
|
||||
continuousMode = false;
|
||||
}
|
||||
|
||||
bool canGoToNextMode() override
|
||||
{
|
||||
if (state() == SelectMode::SeekThird && scaleFactor < Precision::Confusion()) {
|
||||
// Prevent validation zero scale.
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void angleSnappingControl() override
|
||||
{
|
||||
if (state() == SelectMode::SeekSecond || state() == SelectMode::SeekThird) {
|
||||
setAngleSnapping(true, referencePoint);
|
||||
}
|
||||
|
||||
else {
|
||||
setAngleSnapping(false);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<int> listOfGeoIds;
|
||||
Base::Vector2d referencePoint, startPoint, endPoint;
|
||||
bool deleteOriginal;
|
||||
double refLength, length, scaleFactor;
|
||||
|
||||
void deleteOriginalGeos()
|
||||
{
|
||||
std::stringstream stream;
|
||||
for (size_t j = 0; j < listOfGeoIds.size() - 1; j++) {
|
||||
stream << listOfGeoIds[j] << ",";
|
||||
}
|
||||
stream << listOfGeoIds[listOfGeoIds.size() - 1];
|
||||
try {
|
||||
Gui::cmdAppObjectArgs(sketchgui->getObject(),
|
||||
"delGeometries([%s])",
|
||||
stream.str().c_str());
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
Base::Console().Error("%s\n", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
void createShape(bool onlyeditoutline) override
|
||||
{
|
||||
SketchObject* Obj = sketchgui->getSketchObject();
|
||||
|
||||
ShapeGeometry.clear();
|
||||
|
||||
if (state() == SelectMode::SeekSecond) {
|
||||
if (refLength > Precision::Confusion()) {
|
||||
addLineToShapeGeometry(toVector3d(referencePoint), toVector3d(startPoint), true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (fabs(scaleFactor) < Precision::Confusion()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto& geoId : listOfGeoIds) {
|
||||
const Part::Geometry* pGeo = Obj->getGeometry(geoId);
|
||||
auto geoUniquePtr = std::unique_ptr<Part::Geometry>(pGeo->copy());
|
||||
Part::Geometry* geo = geoUniquePtr.get();
|
||||
|
||||
if (isCircle(*geo)) {
|
||||
auto* circle = static_cast<Part::GeomCircle*>(geo); // NOLINT
|
||||
circle->setRadius(circle->getRadius() * scaleFactor);
|
||||
circle->setCenter(getScaledPoint(circle->getCenter(), referencePoint, scaleFactor));
|
||||
}
|
||||
else if (isArcOfCircle(*geo)) {
|
||||
auto* arcOfCircle = static_cast<Part::GeomArcOfCircle*>(geo); // NOLINT
|
||||
arcOfCircle->setRadius(arcOfCircle->getRadius() * scaleFactor);
|
||||
arcOfCircle->setCenter(
|
||||
getScaledPoint(arcOfCircle->getCenter(), referencePoint, scaleFactor));
|
||||
}
|
||||
else if (isLineSegment(*geo)) {
|
||||
auto* line = static_cast<Part::GeomLineSegment*>(geo); // NOLINT
|
||||
line->setPoints(getScaledPoint(line->getStartPoint(), referencePoint, scaleFactor),
|
||||
getScaledPoint(line->getEndPoint(), referencePoint, scaleFactor));
|
||||
}
|
||||
else if (isEllipse(*geo)) {
|
||||
auto* ellipse = static_cast<Part::GeomEllipse*>(geo); // NOLINT
|
||||
ellipse->setMajorRadius(ellipse->getMajorRadius() * scaleFactor);
|
||||
ellipse->setMinorRadius(ellipse->getMinorRadius() * scaleFactor);
|
||||
ellipse->setCenter(
|
||||
getScaledPoint(ellipse->getCenter(), referencePoint, scaleFactor));
|
||||
}
|
||||
else if (isArcOfEllipse(*geo)) {
|
||||
auto* arcOfEllipse = static_cast<Part::GeomArcOfEllipse*>(geo); // NOLINT
|
||||
arcOfEllipse->setMajorRadius(arcOfEllipse->getMajorRadius() * scaleFactor);
|
||||
arcOfEllipse->setMinorRadius(arcOfEllipse->getMinorRadius() * scaleFactor);
|
||||
arcOfEllipse->setCenter(
|
||||
getScaledPoint(arcOfEllipse->getCenter(), referencePoint, scaleFactor));
|
||||
}
|
||||
else if (isArcOfHyperbola(*geo)) {
|
||||
auto* arcOfHyperbola = static_cast<Part::GeomArcOfHyperbola*>(geo); // NOLINT
|
||||
arcOfHyperbola->setMajorRadius(arcOfHyperbola->getMajorRadius() * scaleFactor);
|
||||
arcOfHyperbola->setMinorRadius(arcOfHyperbola->getMinorRadius() * scaleFactor);
|
||||
arcOfHyperbola->setCenter(
|
||||
getScaledPoint(arcOfHyperbola->getCenter(), referencePoint, scaleFactor));
|
||||
}
|
||||
else if (isArcOfParabola(*geo)) {
|
||||
auto* arcOfParabola = static_cast<Part::GeomArcOfParabola*>(geo); // NOLINT
|
||||
arcOfParabola->setFocal(arcOfParabola->getFocal() * scaleFactor);
|
||||
double start, end;
|
||||
arcOfParabola->getRange(start, end, true);
|
||||
arcOfParabola->setRange(start * scaleFactor, end * scaleFactor, true);
|
||||
arcOfParabola->setCenter(
|
||||
getScaledPoint(arcOfParabola->getCenter(), referencePoint, scaleFactor));
|
||||
}
|
||||
else if (isBSplineCurve(*geo)) {
|
||||
auto* bSpline = static_cast<Part::GeomBSplineCurve*>(geo); // NOLINT
|
||||
std::vector<Base::Vector3d> poles = bSpline->getPoles();
|
||||
for (size_t p = 0; p < poles.size(); p++) {
|
||||
poles[p] = getScaledPoint(std::move(poles[p]), referencePoint, scaleFactor);
|
||||
}
|
||||
bSpline->setPoles(poles);
|
||||
}
|
||||
else if (isPoint(*geo)) {
|
||||
auto* point = static_cast<Part::GeomPoint*>(geo);
|
||||
point->setPoint(getScaledPoint(point->getPoint(), referencePoint, scaleFactor));
|
||||
}
|
||||
|
||||
ShapeGeometry.emplace_back(std::move(geoUniquePtr));
|
||||
}
|
||||
|
||||
if (onlyeditoutline) {
|
||||
// Add the lines to show lengths
|
||||
addLineToShapeGeometry(toVector3d(referencePoint), toVector3d(startPoint), true);
|
||||
|
||||
addLineToShapeGeometry(toVector3d(referencePoint), toVector3d(endPoint), true);
|
||||
}
|
||||
else {
|
||||
int firstCurveCreated = getHighestCurveIndex() + 1;
|
||||
|
||||
const std::vector<Constraint*>& vals = Obj->Constraints.getValues();
|
||||
// avoid applying equal several times if cloning distanceX and distanceY of the
|
||||
// same part.
|
||||
std::vector<int> geoIdsWhoAlreadyHasEqual = {};
|
||||
|
||||
for (auto& cstr : vals) {
|
||||
int firstIndex = indexOfGeoId(listOfGeoIds, cstr->First);
|
||||
int secondIndex = indexOfGeoId(listOfGeoIds, cstr->Second);
|
||||
int thirdIndex = indexOfGeoId(listOfGeoIds, cstr->Third);
|
||||
|
||||
auto newConstr = std::unique_ptr<Constraint>(cstr->copy());
|
||||
newConstr->First = firstCurveCreated + firstIndex;
|
||||
|
||||
if ((cstr->Type == Symmetric || cstr->Type == Tangent || cstr->Type == Perpendicular
|
||||
|| cstr->Type == Angle)
|
||||
&& firstIndex >= 0 && secondIndex >= 0 && thirdIndex >= 0) {
|
||||
newConstr->Second = firstCurveCreated + secondIndex;
|
||||
newConstr->Third = firstCurveCreated + thirdIndex;
|
||||
}
|
||||
else if ((cstr->Type == Coincident || cstr->Type == Tangent
|
||||
|| cstr->Type == Symmetric || cstr->Type == Perpendicular
|
||||
|| cstr->Type == Parallel || cstr->Type == Equal || cstr->Type == Angle
|
||||
|| cstr->Type == PointOnObject || cstr->Type == InternalAlignment)
|
||||
&& firstIndex >= 0 && secondIndex >= 0
|
||||
&& thirdIndex == GeoEnum::GeoUndef) {
|
||||
newConstr->Second = firstCurveCreated + secondIndex;
|
||||
}
|
||||
else if ((cstr->Type == Radius || cstr->Type == Diameter) && firstIndex >= 0) {
|
||||
newConstr->setValue(newConstr->getValue() * scaleFactor);
|
||||
}
|
||||
else if ((cstr->Type == Distance || cstr->Type == DistanceX
|
||||
|| cstr->Type == DistanceY)
|
||||
&& firstIndex >= 0 && secondIndex >= 0) {
|
||||
newConstr->Second = firstCurveCreated + secondIndex;
|
||||
newConstr->setValue(newConstr->getValue() * scaleFactor);
|
||||
}
|
||||
else if ((cstr->Type == Block || cstr->Type == Weight) && firstIndex >= 0) {
|
||||
newConstr->First = firstCurveCreated + firstIndex;
|
||||
}
|
||||
else {
|
||||
continue;
|
||||
}
|
||||
|
||||
ShapeConstraints.push_back(std::move(newConstr));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Base::Vector3d getScaledPoint(Base::Vector3d&& pointToScale,
|
||||
const Base::Vector2d& referencePoint,
|
||||
double scaleFactor)
|
||||
{
|
||||
Base::Vector2d pointToScale2D;
|
||||
pointToScale2D.x = pointToScale.x;
|
||||
pointToScale2D.y = pointToScale.y;
|
||||
pointToScale2D = (pointToScale2D - referencePoint) * scaleFactor + referencePoint;
|
||||
|
||||
pointToScale.x = pointToScale2D.x;
|
||||
pointToScale.y = pointToScale2D.y;
|
||||
|
||||
return pointToScale;
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
auto DSHScaleControllerBase::getState(int labelindex) const
|
||||
{
|
||||
switch (labelindex) {
|
||||
case OnViewParameter::First:
|
||||
case OnViewParameter::Second:
|
||||
return SelectMode::SeekFirst;
|
||||
break;
|
||||
case OnViewParameter::Third:
|
||||
return SelectMode::SeekThird;
|
||||
break;
|
||||
default:
|
||||
THROWM(Base::ValueError, "OnViewParameter index without an associated machine state")
|
||||
}
|
||||
}
|
||||
|
||||
template<>
|
||||
void DSHScaleController::configureToolWidget()
|
||||
{
|
||||
if (!init) { // Code to be executed only upon initialisation
|
||||
toolWidget->setCheckboxLabel(
|
||||
WCheckbox::FirstBox,
|
||||
QApplication::translate("TaskSketcherTool_c1_scale", "Keep original geometries (U)"));
|
||||
}
|
||||
|
||||
onViewParameters[OnViewParameter::First]->setLabelType(Gui::SoDatumLabel::DISTANCEX);
|
||||
onViewParameters[OnViewParameter::Second]->setLabelType(Gui::SoDatumLabel::DISTANCEY);
|
||||
onViewParameters[OnViewParameter::Third]->setLabelType(
|
||||
Gui::SoDatumLabel::DISTANCE,
|
||||
Gui::EditableDatumLabel::Function::Dimensioning);
|
||||
}
|
||||
|
||||
template<>
|
||||
void DSHScaleController::adaptDrawingToCheckboxChange(int checkboxindex, bool value)
|
||||
{
|
||||
switch (checkboxindex) {
|
||||
case WCheckbox::FirstBox: {
|
||||
handler->deleteOriginal = !value;
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
template<>
|
||||
void DSHScaleControllerBase::doEnforceControlParameters(Base::Vector2d& onSketchPos)
|
||||
{
|
||||
switch (handler->state()) {
|
||||
case SelectMode::SeekFirst: {
|
||||
if (onViewParameters[OnViewParameter::First]->isSet) {
|
||||
onSketchPos.x = onViewParameters[OnViewParameter::First]->getValue();
|
||||
}
|
||||
|
||||
if (onViewParameters[OnViewParameter::Second]->isSet) {
|
||||
onSketchPos.y = onViewParameters[OnViewParameter::Second]->getValue();
|
||||
}
|
||||
} break;
|
||||
case SelectMode::SeekThird: {
|
||||
if (onViewParameters[OnViewParameter::Third]->isSet) {
|
||||
double scaleFactor = onViewParameters[OnViewParameter::Third]->getValue();
|
||||
handler->refLength = 1.0;
|
||||
handler->startPoint = handler->referencePoint + Base::Vector2d(1.0, 0.0);
|
||||
handler->endPoint = handler->referencePoint + Base::Vector2d(scaleFactor, 0.0);
|
||||
|
||||
onSketchPos = handler->endPoint;
|
||||
}
|
||||
} break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
template<>
|
||||
void DSHScaleController::adaptParameters(Base::Vector2d onSketchPos)
|
||||
{
|
||||
switch (handler->state()) {
|
||||
case SelectMode::SeekFirst: {
|
||||
if (!onViewParameters[OnViewParameter::First]->isSet) {
|
||||
setOnViewParameterValue(OnViewParameter::First, onSketchPos.x);
|
||||
}
|
||||
|
||||
if (!onViewParameters[OnViewParameter::Second]->isSet) {
|
||||
setOnViewParameterValue(OnViewParameter::Second, onSketchPos.y);
|
||||
}
|
||||
|
||||
bool sameSign = onSketchPos.x * onSketchPos.y > 0.;
|
||||
onViewParameters[OnViewParameter::First]->setLabelAutoDistanceReverse(!sameSign);
|
||||
onViewParameters[OnViewParameter::Second]->setLabelAutoDistanceReverse(sameSign);
|
||||
onViewParameters[OnViewParameter::First]->setPoints(Base::Vector3d(),
|
||||
toVector3d(onSketchPos));
|
||||
onViewParameters[OnViewParameter::Second]->setPoints(Base::Vector3d(),
|
||||
toVector3d(onSketchPos));
|
||||
} break;
|
||||
case SelectMode::SeekThird: {
|
||||
if (!onViewParameters[OnViewParameter::Third]->isSet) {
|
||||
onViewParameters[OnViewParameter::Third]->setSpinboxValue(handler->scaleFactor,
|
||||
Base::Unit());
|
||||
}
|
||||
|
||||
Base::Vector3d start = toVector3d(handler->referencePoint);
|
||||
Base::Vector3d end = toVector3d(handler->endPoint);
|
||||
onViewParameters[OnViewParameter::Third]->setPoints(start, end);
|
||||
} break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
template<>
|
||||
void DSHScaleController::doChangeDrawSketchHandlerMode()
|
||||
{
|
||||
switch (handler->state()) {
|
||||
case SelectMode::SeekFirst: {
|
||||
if (onViewParameters[OnViewParameter::First]->isSet
|
||||
&& onViewParameters[OnViewParameter::Second]->isSet) {
|
||||
|
||||
handler->setState(SelectMode::SeekSecond);
|
||||
}
|
||||
} break;
|
||||
case SelectMode::SeekThird: {
|
||||
if (onViewParameters[OnViewParameter::Third]->isSet) {
|
||||
|
||||
handler->setState(SelectMode::End);
|
||||
}
|
||||
} break;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace SketcherGui
|
||||
|
||||
|
||||
#endif // SKETCHERGUI_DrawSketchHandlerScale_H
|
||||
@@ -241,6 +241,7 @@
|
||||
<file>icons/pointers/Sketcher_Pointer_Create_PointFillet.svg</file>
|
||||
<file>icons/pointers/Sketcher_Pointer_Create_Offset.svg</file>
|
||||
<file>icons/pointers/Sketcher_Pointer_Create_Rotate.svg</file>
|
||||
<file>icons/pointers/Sketcher_Pointer_Create_Scale.svg</file>
|
||||
<file>icons/pointers/Sketcher_Pointer_Extension.svg</file>
|
||||
<file>icons/pointers/Sketcher_Pointer_External.svg</file>
|
||||
<file>icons/pointers/Sketcher_Pointer_Heptagon.svg</file>
|
||||
@@ -297,6 +298,7 @@
|
||||
<file>icons/tools/Sketcher_SelectVerticalAxis.svg</file>
|
||||
<file>icons/tools/Sketcher_Symmetry.svg</file>
|
||||
<file>icons/tools/Sketcher_Rotate.svg</file>
|
||||
<file>icons/tools/Sketcher_Scale.svg</file>
|
||||
<file>icons/tools/Sketcher_Offset.svg</file>
|
||||
<file>icons/tools/Sketcher_OffsetArc.svg</file>
|
||||
<file>icons/tools/Sketcher_OffsetIntersection.svg</file>
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg
|
||||
version="1.1"
|
||||
height="64"
|
||||
width="64"
|
||||
id="svg12"
|
||||
sodipodi:docname="Sketcher_Pointer_Create_Scale.svg"
|
||||
inkscape:version="1.1-beta1 (77e7b44db3, 2021-03-28)"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:svg="http://www.w3.org/2000/svg">
|
||||
<sodipodi:namedview
|
||||
id="namedview10"
|
||||
pagecolor="#505050"
|
||||
bordercolor="#eeeeee"
|
||||
borderopacity="1"
|
||||
objecttolerance="10.0"
|
||||
gridtolerance="10.0"
|
||||
guidetolerance="10.0"
|
||||
inkscape:pageshadow="0"
|
||||
inkscape:pageopacity="0"
|
||||
inkscape:pagecheckerboard="0"
|
||||
showgrid="false"
|
||||
inkscape:zoom="4.1597766"
|
||||
inkscape:cx="-42.910958"
|
||||
inkscape:cy="55.772226"
|
||||
inkscape:window-width="3840"
|
||||
inkscape:window-height="1570"
|
||||
inkscape:window-x="-9"
|
||||
inkscape:window-y="-9"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="svg12" />
|
||||
<defs
|
||||
id="defs16" />
|
||||
<g
|
||||
id="crosshair"
|
||||
style="stroke:#ffffff;stroke-width:2.5;stroke-linecap:round;stroke-linejoin:miter">
|
||||
<path
|
||||
d="m16,3v9m0,8v9m-13-13h9m8,0h9"
|
||||
id="path9" />
|
||||
</g>
|
||||
<path
|
||||
style="fill:none;stroke:#cc0000;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
|
||||
d="m 22.888154,42.864836 17.016228,-0.113176 0.0425,17.338645 H 22.905711 Z"
|
||||
id="path2999" />
|
||||
<path
|
||||
style="fill:none;stroke:#cc0000;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
|
||||
d="m 44.908088,59.438245 h 6.016235"
|
||||
id="path3001" />
|
||||
<path
|
||||
style="fill:none;stroke:#cc0000;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
|
||||
d="m 55.193068,59.607592 4.599761,-0.06974 -0.08226,-4.58558"
|
||||
id="path3003" />
|
||||
<path
|
||||
style="fill:none;stroke:#cc0000;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
|
||||
d="M 59.694456,49.867503 V 43.851268"
|
||||
id="path3005" />
|
||||
<path
|
||||
style="fill:none;stroke:#cc0000;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
|
||||
d="M 59.684324,38.95543 V 32.939195"
|
||||
id="path3007" />
|
||||
<path
|
||||
style="fill:none;stroke:#cc0000;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
|
||||
d="m 59.830078,27.852141 -0.07975,-4.43647 -4.575577,-0.08103"
|
||||
id="path3011" />
|
||||
<path
|
||||
style="fill:none;stroke:#cc0000;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
|
||||
d="M 49.961606,23.307857 H 43.945371"
|
||||
id="path3013" />
|
||||
<path
|
||||
style="fill:none;stroke:#cc0000;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
|
||||
d="M 39.049534,23.317989 H 33.033299"
|
||||
id="path3015" />
|
||||
<path
|
||||
style="fill:none;stroke:#cc0000;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
|
||||
d="m 28.200415,23.188346 -4.529764,-0.07015 0.01226,4.725475"
|
||||
id="path3017" />
|
||||
<path
|
||||
style="fill:none;stroke:#cc0000;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
|
||||
d="m 23.667914,31.723623 v 6.016235"
|
||||
id="path3019" />
|
||||
<path
|
||||
style="fill:none;stroke:#cc0000;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
|
||||
d="m 43.729084,39.266932 0.679947,-0.594953 9.009296,-9.179283 -5.439575,0.339973"
|
||||
id="path3021" />
|
||||
<path
|
||||
style="fill:none;stroke:#cc0000;stroke-width:2.28656;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
d="m 54.681493,28.504588 -1.355282,5.694468"
|
||||
id="path3023" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 4.1 KiB |
1004
src/Mod/Sketcher/Gui/Resources/icons/tools/Sketcher_Scale.svg
Normal file
1004
src/Mod/Sketcher/Gui/Resources/icons/tools/Sketcher_Scale.svg
Normal file
File diff suppressed because it is too large
Load Diff
|
After Width: | Height: | Size: 34 KiB |
@@ -865,3 +865,16 @@ bool SketcherGui::areColinear(const Base::Vector2d& p1,
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int SketcherGui::indexOfGeoId(const std::vector<int>& vec, int elem)
|
||||
{
|
||||
if (elem == GeoEnum::GeoUndef) {
|
||||
return GeoEnum::GeoUndef;
|
||||
}
|
||||
for (size_t i = 0; i < vec.size(); i++) {
|
||||
if (vec[i] == elem) {
|
||||
return static_cast<int>(i);
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -208,6 +208,8 @@ std::string angleToDisplayFormat(double value, int digits);
|
||||
|
||||
bool areColinear(const Base::Vector2d& p1, const Base::Vector2d& p2, const Base::Vector2d& p3);
|
||||
|
||||
int indexOfGeoId(const std::vector<int>& vec, int elem);
|
||||
|
||||
} // namespace SketcherGui
|
||||
|
||||
/// converts a 2D vector into a 3D vector in the XY plane
|
||||
|
||||
@@ -535,6 +535,7 @@ inline void SketcherAddWorkbenchTools<Gui::MenuItem>(Gui::MenuItem& consaccel)
|
||||
<< "Separator"
|
||||
<< "Sketcher_Offset"
|
||||
<< "Sketcher_Rotate"
|
||||
<< "Sketcher_Scale"
|
||||
<< "Sketcher_Symmetry"
|
||||
<< "Sketcher_Clone"
|
||||
<< "Sketcher_Copy"
|
||||
@@ -564,6 +565,7 @@ inline void SketcherAddWorkbenchTools<Gui::ToolBarItem>(Gui::ToolBarItem& consac
|
||||
<< "Sketcher_RestoreInternalAlignmentGeometry"
|
||||
<< "Sketcher_Offset"
|
||||
<< "Sketcher_Rotate"
|
||||
<< "Sketcher_Scale"
|
||||
<< "Sketcher_Symmetry"
|
||||
<< "Sketcher_CompCopy"
|
||||
<< "Sketcher_RectangularArray"
|
||||
|
||||
Reference in New Issue
Block a user