[Sketcher] Add knot insertion command in Sketcher workbench

This commit is contained in:
Ajinkya Dahale
2021-12-29 02:51:55 -05:00
committed by abdullahtahiriyo
parent 07cad4ab64
commit 37e93cc167
4 changed files with 634 additions and 3 deletions

View File

@@ -28,7 +28,7 @@
# include <Precision.hxx>
# include <QApplication>
# include <Standard_Version.hxx>
# include <QMessageBox>
# include <QInputDialog>
#endif
#include <Base/Console.h>
@@ -971,6 +971,145 @@ bool CmdSketcherCompModifyKnotMultiplicity::isActive(void)
return isSketcherBSplineActive(getActiveGuiDocument(), false);
}
DEF_STD_CMD_A(CmdSketcherInsertKnot)
CmdSketcherInsertKnot::CmdSketcherInsertKnot()
: Command("Sketcher_BSplineInsertKnot")
{
sAppModule = "Sketcher";
sGroup = "Sketcher";
sMenuText = QT_TR_NOOP("Insert knot");
sToolTipText = QT_TR_NOOP("Inserts knot at given parameter with the given multiplicity. If a knot already exists at that parameter, it's multiplicity is increased by the value.");
sWhatsThis = "Sketcher_BSplineInsertKnot";
sStatusTip = sToolTipText;
sPixmap = "Sketcher_BSplineInsertKnot";
sAccel = "";
eType = ForEdit;
}
void CmdSketcherInsertKnot::activated(int iMsg)
{
Q_UNUSED(iMsg);
#if OCC_VERSION_HEX < 0x060900
QMessageBox::warning(Gui::getMainWindow(),
QObject::tr("Wrong OCE/OCC version"),
QObject::tr("This version of OCE/OCC "
"does not support knot operation. "
"You need 6.9.0 or higher"));
return;
#endif
// get the selection
std::vector<Gui::SelectionObject> selection;
selection = getSelection().getSelectionEx(0, Sketcher::SketchObject::getClassTypeId());
// TODO: let user click on a curve after pressing command.
// only one sketch with its subelements are allowed to be selected
if (selection.size() != 1) {
return;
}
// get the needed lists and objects
const std::vector<std::string> &SubNames = selection[0].getSubNames();
if (SubNames.size() == 0) {
// Check that only one object is selected,
// as we need only one object to get the new GeoId after multiplicity change
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Selection is empty"),
QObject::tr("Nothing is selected. Please select a b-spline."));
return;
}
Sketcher::SketchObject* Obj = static_cast<Sketcher::SketchObject*>(selection[0].getObject());
openCommand(QT_TRANSLATE_NOOP("Command", "Insert knot (incomplete)"));
bool applied = false;
// TODO: Ensure GeoId is for the BSpline and not for it's internal geometry
int GeoId = std::atoi(SubNames[0].substr(4,4000).c_str()) - 1;
boost::uuids::uuid bsplinetag = Obj->getGeometry(GeoId)->getTag();
try {
// TODO: Get param from user input by clicking on desired spot
// Get param from user input into a box
bool paramPicked;
// TODO: get min/max values from the BSpline
double param = QInputDialog::getDouble(
Gui::getMainWindow(), QObject::tr("Knot parameter"),
QObject::tr("Please provide the parameter where the knot is to be inserted."),
0.5, -DBL_MAX, DBL_MAX, 8, &paramPicked);
if (paramPicked) {
Gui::cmdAppObjectArgs(selection[0].getObject(),
"insertBSplineKnot(%d, %lf, %d) ",
GeoId, param, 1);
applied = true;
// Warning: GeoId list might have changed
// as the consequence of deleting pole circles and
// particularly B-spline GeoID might have changed.
}
}
catch (const Base::CADKernelError& e) {
e.ReportException();
if (e.getTranslatable()) {
QMessageBox::warning(Gui::getMainWindow(),
QObject::tr("CAD Kernel Error"),
QObject::tr(e.getMessage().c_str()));
}
getSelection().clearSelection();
}
catch (const Base::Exception& e) {
e.ReportException();
if (e.getTranslatable()) {
QMessageBox::warning(Gui::getMainWindow(),
QObject::tr("Input Error"),
QObject::tr(e.getMessage().c_str()));
}
getSelection().clearSelection();
}
if (applied)
{
// find new geoid for B-spline as GeoId might have changed
const std::vector< Part::Geometry * > &gvals = Obj->getInternalGeometry();
int ngeoid = 0;
bool ngfound = false;
for (std::vector<Part::Geometry *>::const_iterator geo = gvals.begin(); geo != gvals.end(); geo++, ngeoid++) {
if ((*geo) && (*geo)->getTag() == bsplinetag) {
ngfound = true;
break;
}
}
if (ngfound) {
try {
// add internalalignment for new pole
Gui::cmdAppObjectArgs(selection[0].getObject(), "exposeInternalGeometry(%d)", ngeoid);
}
catch (const Base::Exception& e) {
Base::Console().Error("%s\n", e.what());
getSelection().clearSelection();
}
}
}
if (applied)
commitCommand();
else
abortCommand();
tryAutoRecomputeIfNotSolve(Obj);
getSelection().clearSelection();
}
bool CmdSketcherInsertKnot::isActive(void)
{
return isSketcherBSplineActive(getActiveGuiDocument(), true);
}
void CreateSketcherCommandsBSpline(void)
{
Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager();
@@ -987,4 +1126,5 @@ void CreateSketcherCommandsBSpline(void)
rcCmdMgr.addCommand(new CmdSketcherIncreaseKnotMultiplicity());
rcCmdMgr.addCommand(new CmdSketcherDecreaseKnotMultiplicity());
rcCmdMgr.addCommand(new CmdSketcherCompModifyKnotMultiplicity());
rcCmdMgr.addCommand(new CmdSketcherInsertKnot());
}

View File

@@ -214,6 +214,7 @@
<file>icons/splines/Sketcher_BSplineDegree.svg</file>
<file>icons/splines/Sketcher_BSplineIncreaseDegree.svg</file>
<file>icons/splines/Sketcher_BSplineIncreaseKnotMultiplicity.svg</file>
<file>icons/splines/Sketcher_BSplineInsertKnot.svg</file>
<file>icons/splines/Sketcher_BSplineKnotMultiplicity.svg</file>
<file>icons/splines/Sketcher_BSplinePoleWeight.svg</file>
<file>icons/splines/Sketcher_BSplinePolygon.svg</file>

View File

@@ -0,0 +1,488 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
width="64px"
height="64px"
id="svg2918"
version="1.1"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/">
<title
id="title928">Sketcher_BSplineIncreaseKnotMultiplicity</title>
<defs
id="defs2920">
<linearGradient
id="linearGradient3144">
<stop
style="stop-color:#ffffff;stop-opacity:1"
offset="0"
id="stop3146" />
<stop
style="stop-color:#ffffff;stop-opacity:0"
offset="1"
id="stop3148" />
</linearGradient>
<linearGradient
id="linearGradient3144-3">
<stop
style="stop-color:#ffffff;stop-opacity:1"
offset="0"
id="stop3146-1" />
<stop
style="stop-color:#ffffff;stop-opacity:0"
offset="1"
id="stop3148-5" />
</linearGradient>
<radialGradient
xlink:href="#linearGradient3144"
id="radialGradient3958"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(1,0,0,0.6985294,0,202.82863)"
cx="225.26402"
cy="672.79736"
fx="225.26402"
fy="672.79736"
r="34.345188" />
<radialGradient
xlink:href="#linearGradient3144-3"
id="radialGradient3960"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(1,0,0,0.6985294,0,202.82863)"
cx="225.26402"
cy="672.79736"
fx="225.26402"
fy="672.79736"
r="34.345188" />
<radialGradient
xlink:href="#linearGradient3144"
id="radialGradient3042"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(1,0,0,0.6985294,0,202.82863)"
cx="225.26402"
cy="672.79736"
fx="225.26402"
fy="672.79736"
r="34.345188" />
<radialGradient
xlink:href="#linearGradient3144"
id="radialGradient3068"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(1,0,0,0.6985294,0,202.82863)"
cx="225.26402"
cy="672.79736"
fx="225.26402"
fy="672.79736"
r="34.345188" />
<radialGradient
xlink:href="#linearGradient3144"
id="radialGradient3880"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(1,0,0,0.6985294,0,202.82863)"
cx="225.26402"
cy="672.79736"
fx="225.26402"
fy="672.79736"
r="34.345188" />
<radialGradient
xlink:href="#linearGradient3144"
id="radialGradient4654"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(1,0,0,0.6985294,0,202.82863)"
cx="225.26402"
cy="672.79736"
fx="225.26402"
fy="672.79736"
r="34.345188" />
<radialGradient
xlink:href="#linearGradient3144"
id="radialGradient4693"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(1,0,0,0.6985294,0,202.82863)"
cx="225.26402"
cy="672.79736"
fx="225.26402"
fy="672.79736"
r="34.345188" />
<linearGradient
y2="5"
x2="-22"
y1="18"
x1="-18"
gradientUnits="userSpaceOnUse"
id="linearGradient3131-2"
xlink:href="#linearGradient3836-9-3-9" />
<linearGradient
id="linearGradient3836-9-3-9">
<stop
style="stop-color:#a40000;stop-opacity:1"
offset="0"
id="stop3838-8-5-1" />
<stop
style="stop-color:#ef2929;stop-opacity:1"
offset="1"
id="stop3840-1-6-2" />
</linearGradient>
<linearGradient
y2="5"
x2="-22"
y1="18"
x1="-18"
gradientUnits="userSpaceOnUse"
id="linearGradient3171-7"
xlink:href="#linearGradient3836-9-3-6-0" />
<linearGradient
id="linearGradient3836-9-3-6-0">
<stop
style="stop-color:#a40000;stop-opacity:1"
offset="0"
id="stop3838-8-5-7-9" />
<stop
style="stop-color:#ef2929;stop-opacity:1"
offset="1"
id="stop3840-1-6-5-3" />
</linearGradient>
<linearGradient
xlink:href="#linearGradient3836-9-3"
id="linearGradient3262"
gradientUnits="userSpaceOnUse"
x1="-18"
y1="18"
x2="-22"
y2="5" />
<linearGradient
id="linearGradient3836-9-3">
<stop
style="stop-color:#a40000;stop-opacity:1"
offset="0"
id="stop3838-8-5" />
<stop
style="stop-color:#ef2929;stop-opacity:1"
offset="1"
id="stop3840-1-6" />
</linearGradient>
<linearGradient
id="linearGradient3836-9-3-6">
<stop
style="stop-color:#a40000;stop-opacity:1"
offset="0"
id="stop3838-8-5-7" />
<stop
style="stop-color:#ef2929;stop-opacity:1"
offset="1"
id="stop3840-1-6-5" />
</linearGradient>
<linearGradient
xlink:href="#linearGradient3836-9-3-6-7"
id="linearGradient3264-1"
gradientUnits="userSpaceOnUse"
x1="-18"
y1="18"
x2="-22"
y2="5"
gradientTransform="matrix(0.93724177,0,0,0.93725692,-1.2227671,0.70650014)" />
<linearGradient
id="linearGradient3836-9-3-6-7">
<stop
style="stop-color:#a40000;stop-opacity:1"
offset="0"
id="stop3838-8-5-7-4" />
<stop
style="stop-color:#ef2929;stop-opacity:1"
offset="1"
id="stop3840-1-6-5-0" />
</linearGradient>
<linearGradient
xlink:href="#linearGradient3836-9-3-6-4"
id="linearGradient3264-9"
gradientUnits="userSpaceOnUse"
x1="-18"
y1="18"
x2="-22"
y2="5"
gradientTransform="matrix(0.93724177,0,0,0.93725692,-1.2227671,0.70650014)" />
<linearGradient
id="linearGradient3836-9-3-6-4">
<stop
style="stop-color:#a40000;stop-opacity:1"
offset="0"
id="stop3838-8-5-7-8" />
<stop
style="stop-color:#ef2929;stop-opacity:1"
offset="1"
id="stop3840-1-6-5-8" />
</linearGradient>
<linearGradient
xlink:href="#linearGradient3836-9-3-6-1"
id="linearGradient3264-17"
gradientUnits="userSpaceOnUse"
x1="-18"
y1="18"
x2="-22"
y2="5"
gradientTransform="matrix(0.93724177,0,0,0.93725692,-1.2227671,0.70650014)" />
<linearGradient
id="linearGradient3836-9-3-6-1">
<stop
style="stop-color:#a40000;stop-opacity:1"
offset="0"
id="stop3838-8-5-7-1" />
<stop
style="stop-color:#ef2929;stop-opacity:1"
offset="1"
id="stop3840-1-6-5-5" />
</linearGradient>
<linearGradient
xlink:href="#linearGradient3836-9-3-6-2"
id="linearGradient3264-3"
gradientUnits="userSpaceOnUse"
x1="-18"
y1="18"
x2="-22"
y2="5"
gradientTransform="matrix(0.93724177,0,0,0.93725692,-1.2227671,0.70650014)" />
<linearGradient
id="linearGradient3836-9-3-6-2">
<stop
style="stop-color:#a40000;stop-opacity:1"
offset="0"
id="stop3838-8-5-7-2" />
<stop
style="stop-color:#ef2929;stop-opacity:1"
offset="1"
id="stop3840-1-6-5-1" />
</linearGradient>
<linearGradient
xlink:href="#linearGradient3836-9-3-3"
id="linearGradient3262-5"
gradientUnits="userSpaceOnUse"
x1="-18"
y1="18"
x2="-22"
y2="5" />
<linearGradient
id="linearGradient3836-9-3-3">
<stop
style="stop-color:#a40000;stop-opacity:1"
offset="0"
id="stop3838-8-5-5" />
<stop
style="stop-color:#ef2929;stop-opacity:1"
offset="1"
id="stop3840-1-6-6" />
</linearGradient>
<linearGradient
xlink:href="#linearGradient3836-9-3-6-29"
id="linearGradient3264"
gradientUnits="userSpaceOnUse"
x1="-18"
y1="18"
x2="-22"
y2="5" />
<linearGradient
id="linearGradient3836-9-3-6-29">
<stop
style="stop-color:#a40000;stop-opacity:1"
offset="0"
id="stop3838-8-5-7-12" />
<stop
style="stop-color:#ef2929;stop-opacity:1"
offset="1"
id="stop3840-1-6-5-7" />
</linearGradient>
<linearGradient
y2="5"
x2="-22"
y1="18"
x1="-18"
gradientUnits="userSpaceOnUse"
id="linearGradient3131-2-0"
xlink:href="#linearGradient3836-9-3-9-9" />
<linearGradient
id="linearGradient3836-9-3-9-9">
<stop
style="stop-color:#a40000;stop-opacity:1"
offset="0"
id="stop3838-8-5-1-3" />
<stop
style="stop-color:#ef2929;stop-opacity:1"
offset="1"
id="stop3840-1-6-2-6" />
</linearGradient>
<linearGradient
y2="5"
x2="-22"
y1="18"
x1="-18"
gradientUnits="userSpaceOnUse"
id="linearGradient3171-7-0"
xlink:href="#linearGradient3836-9-3-6-0-6" />
<linearGradient
id="linearGradient3836-9-3-6-0-6">
<stop
style="stop-color:#a40000;stop-opacity:1"
offset="0"
id="stop3838-8-5-7-9-2" />
<stop
style="stop-color:#ef2929;stop-opacity:1"
offset="1"
id="stop3840-1-6-5-3-6" />
</linearGradient>
<linearGradient
xlink:href="#linearGradient3836-9-3-6-29-8"
id="linearGradient3937-1"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(0.71441909,0,0,0.71408544,-5.531259,3.2604792)"
x1="-18"
y1="18"
x2="-22"
y2="5" />
<linearGradient
id="linearGradient3836-9-3-6-29-8">
<stop
style="stop-color:#a40000;stop-opacity:1"
offset="0"
id="stop3838-8-5-7-12-7" />
<stop
style="stop-color:#ef2929;stop-opacity:1"
offset="1"
id="stop3840-1-6-5-7-9" />
</linearGradient>
<linearGradient
id="linearGradient3836-9-3-6-29-7">
<stop
style="stop-color:#a40000;stop-opacity:1"
offset="0"
id="stop3838-8-5-7-12-5" />
<stop
style="stop-color:#ef2929;stop-opacity:1"
offset="1"
id="stop3840-1-6-5-7-92" />
</linearGradient>
<linearGradient
id="linearGradient3836-9-3-6-29-1">
<stop
style="stop-color:#a40000;stop-opacity:1"
offset="0"
id="stop3838-8-5-7-12-2" />
<stop
style="stop-color:#ef2929;stop-opacity:1"
offset="1"
id="stop3840-1-6-5-7-93" />
</linearGradient>
<linearGradient
xlink:href="#linearGradient3836"
id="linearGradient3850"
x1="164.4444"
y1="161.22015"
x2="154.4444"
y2="131.22015"
gradientUnits="userSpaceOnUse" />
<linearGradient
id="linearGradient3836">
<stop
style="stop-color:#3465a4;stop-opacity:1"
offset="0"
id="stop3838" />
<stop
style="stop-color:#729fcf;stop-opacity:1"
offset="1"
id="stop3840" />
</linearGradient>
<linearGradient
xlink:href="#linearGradient3836"
id="linearGradient3112"
gradientUnits="userSpaceOnUse"
gradientTransform="translate(-188.44439,-101.22016)"
x1="164.4444"
y1="161.22015"
x2="154.4444"
y2="131.22015" />
</defs>
<metadata
id="metadata2923">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title>Sketcher_BSplineIncreaseKnotMultiplicity</dc:title>
<dc:creator>
<cc:Agent>
<dc:title>[bitacovir]</dc:title>
</cc:Agent>
</dc:creator>
<dc:title>Sketcher_Create_Periodic_BSpline</dc:title>
<dc:date>22-03-2021</dc:date>
<dc:relation>http://www.freecadweb.org/wiki/index.php?title=Artwork</dc:relation>
<dc:publisher>
<cc:Agent>
<dc:title>FreeCAD</dc:title>
</cc:Agent>
</dc:publisher>
<dc:identifier />
<dc:rights>
<cc:Agent>
<dc:title>FreeCAD LGPL2+</dc:title>
</cc:Agent>
</dc:rights>
<cc:license>https://www.gnu.org/copyleft/lesser.html</cc:license>
<dc:contributor>
<cc:Agent>
<dc:title />
</cc:Agent>
</dc:contributor>
</cc:Work>
</rdf:RDF>
</metadata>
<g
id="layer1">
<path
id="path3266"
d="M 55.618776,14.550317 C 53.081884,47.579198 16.970778,30.589727 8.323225,55.603448"
style="fill:none;stroke:#2e3436;stroke-width:12.5366;stroke-linecap:round;stroke-linejoin:miter;stroke-opacity:1" />
<path
id="path3266-9"
d="M 55.709838,8.2901619 C 58.067368,48.425294 17.268578,29.608783 8.323225,55.603448"
style="fill:none;stroke:#d3d7cf;stroke-width:6.2683;stroke-linecap:round;stroke-linejoin:miter;stroke-opacity:1" />
<path
id="path3266-9-2"
d="M 54.084648,8.2901619 C 57.674608,46.816893 15.240583,27.738484 6.698041,55.754384"
style="fill:none;stroke:#ffffff;stroke-width:3.13415;stroke-linecap:round;stroke-linejoin:miter;stroke-opacity:1" />
<g
transform="matrix(-0.14137236,0.07774155,-0.01888492,-0.10633123,99.823869,75.569613)"
id="g3177" />
<g
transform="matrix(-0.14109247,0.07923086,-0.02087339,-0.10522619,77.138226,86.686164)"
id="g3185" />
<g
id="g3108"
transform="translate(47,-27)">
<path
id="rect3558"
d="m -34,30 v 10 h -10 v 10 h 10 v 10 h 10 V 50 h 10 V 40 H -24 V 30 Z"
style="color:#000000;display:inline;overflow:visible;visibility:visible;fill:url(#linearGradient3112);fill-opacity:1;fill-rule:evenodd;stroke:#0b1521;stroke-width:2;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
<path
id="path3826"
d="m -42,42 h 10 V 32 h 6 v 10 h 10 v 6 h -10 v 10 h -6 V 48 h -10 z"
style="fill:none;stroke:#729fcf;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
</g>
<circle
r="13.203125"
cy="15.206594"
cx="49.803802"
id="path945"
style="fill:#ffffff;fill-rule:evenodd;stroke:none;stroke-width:1.3629;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;paint-order:markers stroke fill" />
<path
style="fill:#ef2929;stroke:#4e9a06;stroke-width:3.89444;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path4250-6-9-5-3-3"
d="M 42.456289,8.909865 A 9.7328242,9.7322726 0 1 1 57.241316,21.570677 9.7328242,9.7322726 0 1 1 42.456289,8.909865 Z" />
<path
style="fill:#172a04;fill-opacity:1;stroke:#73d216;stroke-width:3.89444;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path4250-7-0-1-6-5-4"
d="m 45.410125,11.442545 a 5.8416276,5.8416209 0 1 1 8.873925,7.599458 5.8416276,5.8416209 0 0 1 -8.873925,-7.599458 z" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 15 KiB

View File

@@ -412,7 +412,8 @@ inline void SketcherAddWorkbenchBSplines<Gui::MenuItem>(Gui::MenuItem& bspline)
<< "Sketcher_BSplineIncreaseDegree"
<< "Sketcher_BSplineDecreaseDegree"
<< "Sketcher_BSplineIncreaseKnotMultiplicity"
<< "Sketcher_BSplineDecreaseKnotMultiplicity";
<< "Sketcher_BSplineDecreaseKnotMultiplicity"
<< "Sketcher_BSplineInsertKnot";
}
template <>
@@ -422,7 +423,8 @@ inline void SketcherAddWorkbenchBSplines<Gui::ToolBarItem>(Gui::ToolBarItem& bsp
<< "Sketcher_BSplineConvertToNURB"
<< "Sketcher_BSplineIncreaseDegree"
<< "Sketcher_BSplineDecreaseDegree"
<< "Sketcher_CompModifyKnotMultiplicity";
<< "Sketcher_CompModifyKnotMultiplicity"
<< "Sketcher_BSplineInsertKnot";
}
template <typename T>