Sketcher: implement command to decrease degree of a B-spline
This commit is contained in:
@@ -5198,6 +5198,48 @@ bool SketchObject::increaseBSplineDegree(int GeoId, int degreeincrement /*= 1*/)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SketchObject::decreaseBSplineDegree(int GeoId, int degreedecrement /*= 1*/)
|
||||
{
|
||||
Base::StateLocker lock(managedoperation, true); // no need to check input data validity as this is an sketchobject managed operation.
|
||||
|
||||
if (GeoId < 0 || GeoId > getHighestCurveIndex())
|
||||
return false;
|
||||
|
||||
const Part::Geometry *geo = getGeometry(GeoId);
|
||||
|
||||
if (geo->getTypeId() != Part::GeomBSplineCurve::getClassTypeId())
|
||||
return false;
|
||||
|
||||
const Part::GeomBSplineCurve *bsp = static_cast<const Part::GeomBSplineCurve *>(geo);
|
||||
|
||||
const Handle(Geom_BSplineCurve) curve = Handle(Geom_BSplineCurve)::DownCast(bsp->handle());
|
||||
|
||||
std::unique_ptr<Part::GeomBSplineCurve> bspline(new Part::GeomBSplineCurve(curve));
|
||||
|
||||
try {
|
||||
int cdegree = bspline->getDegree();
|
||||
|
||||
bool ok = bspline->approximate(Precision::Confusion(), 20, cdegree-degreedecrement, 0);
|
||||
if (!ok)
|
||||
return false;
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
Base::Console().Error("%s\n", e.what());
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::vector< Part::Geometry * > &vals = getInternalGeometry();
|
||||
|
||||
std::vector< Part::Geometry * > newVals(vals);
|
||||
|
||||
newVals[GeoId] = bspline.release();
|
||||
|
||||
// AcceptGeometry called from onChanged
|
||||
Geometry.setValues(newVals);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SketchObject::modifyBSplineKnotMultiplicity(int GeoId, int knotIndex, int multiplicityincr)
|
||||
{
|
||||
Base::StateLocker lock(managedoperation, true); // no need to check input data validity as this is an sketchobject managed operation.
|
||||
|
||||
@@ -253,6 +253,14 @@ public:
|
||||
*/
|
||||
bool increaseBSplineDegree(int GeoId, int degreeincrement = 1);
|
||||
|
||||
/*!
|
||||
\brief Decreases the degree of a BSpline by degreedecrement, which defaults to 1
|
||||
\param GeoId - the geometry of type bspline to increase the degree
|
||||
\param degreedecrement - the decrement in number of degrees to effect
|
||||
\retval bool - returns true if the decrease in degree succeeded, or false if it did not succeed.
|
||||
*/
|
||||
bool decreaseBSplineDegree(int GeoId, int degreedecrement = 1);
|
||||
|
||||
/*!
|
||||
\brief Increases or Decreases the multiplicity of a BSpline knot by the multiplicityincr param, which defaults to 1, if the result is multiplicity zero, the knot is removed
|
||||
\param GeoId - the geometry of type bspline to increase the degree
|
||||
|
||||
@@ -257,6 +257,11 @@ If there is no such constraint an exception is raised.
|
||||
<UserDocu>Increases the given BSpline Degree by a number of degrees</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="decreaseBSplineDegree">
|
||||
<Documentation>
|
||||
<UserDocu>Decreases the given BSpline Degree by a number of degrees by approximating this curve</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="modifyBSplineKnotMultiplicity">
|
||||
<Documentation>
|
||||
<UserDocu>Increases or reduces the given BSpline knot multiplicity</UserDocu>
|
||||
|
||||
@@ -1396,6 +1396,24 @@ PyObject* SketchObjectPy::increaseBSplineDegree(PyObject *args)
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
PyObject* SketchObjectPy::decreaseBSplineDegree(PyObject *args)
|
||||
{
|
||||
int GeoId;
|
||||
int incr = 1;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "i|i", &GeoId, &incr))
|
||||
return 0;
|
||||
|
||||
if (this->getSketchObjectPtr()->decreaseBSplineDegree(GeoId, incr)==false) {
|
||||
std::stringstream str;
|
||||
str << "Degree decrease failed for: " << GeoId;
|
||||
PyErr_SetString(PyExc_ValueError, str.str().c_str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
PyObject* SketchObjectPy::modifyBSplineKnotMultiplicity(PyObject *args)
|
||||
{
|
||||
int GeoId;
|
||||
|
||||
@@ -479,8 +479,7 @@ CmdSketcherDecreaseDegree::CmdSketcherDecreaseDegree()
|
||||
sAppModule = "Sketcher";
|
||||
sGroup = QT_TR_NOOP("Sketcher");
|
||||
sMenuText = QT_TR_NOOP("Decrease B-spline degree");
|
||||
sToolTipText = QT_TR_NOOP("Decreases the degree of the B-spline.\n"
|
||||
"This command is currently NOT IMPLEMENTED.");
|
||||
sToolTipText = QT_TR_NOOP("Decreases the degree of the B-spline");
|
||||
sWhatsThis = "Sketcher_BSplineDecreaseDegree";
|
||||
sStatusTip = sToolTipText;
|
||||
sPixmap = "Sketcher_BSplineDecreaseDegree";
|
||||
@@ -488,12 +487,54 @@ CmdSketcherDecreaseDegree::CmdSketcherDecreaseDegree()
|
||||
eType = ForEdit;
|
||||
}
|
||||
|
||||
// TODO: fully implement this function to complement Sketcher_BSplineIncreaseDegree
|
||||
void CmdSketcherDecreaseDegree::activated(int iMsg)
|
||||
{
|
||||
Q_UNUSED(iMsg);
|
||||
Base::Console().Message("Decrease degree of spline. "
|
||||
"This command is currently NOT IMPLEMENTED.\n");
|
||||
|
||||
// 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) {
|
||||
return;
|
||||
}
|
||||
|
||||
// get the needed lists and objects
|
||||
const std::vector<std::string> &SubNames = selection[0].getSubNames();
|
||||
Sketcher::SketchObject* Obj = static_cast<Sketcher::SketchObject*>(selection[0].getObject());
|
||||
|
||||
openCommand("Decrease spline degree");
|
||||
|
||||
bool ignored = false;
|
||||
|
||||
for (size_t i=0; i < SubNames.size(); i++) {
|
||||
// only handle edges
|
||||
if (SubNames[i].size() > 4 && SubNames[i].substr(0,4) == "Edge") {
|
||||
int GeoId = std::atoi(SubNames[i].substr(4,4000).c_str()) - 1;
|
||||
const Part::Geometry * geo = Obj->getGeometry(GeoId);
|
||||
|
||||
if (geo->getTypeId() == Part::GeomBSplineCurve::getClassTypeId()) {
|
||||
Gui::cmdAppObjectArgs(selection[0].getObject(), "decreaseBSplineDegree(%d) ", GeoId);
|
||||
// add new control points
|
||||
//Gui::cmdAppObjectArgs(selection[0].getObject(), "exposeInternalGeometry(%d)", GeoId);
|
||||
}
|
||||
else {
|
||||
ignored = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ignored) {
|
||||
QMessageBox::warning(Gui::getMainWindow(),
|
||||
QObject::tr("Wrong selection"),
|
||||
QObject::tr("At least one of the selected "
|
||||
"objects was not a B-Spline and was ignored."));
|
||||
}
|
||||
|
||||
commitCommand();
|
||||
tryAutoRecomputeIfNotSolve(Obj);
|
||||
getSelection().clearSelection();
|
||||
}
|
||||
|
||||
bool CmdSketcherDecreaseDegree::isActive(void)
|
||||
@@ -902,7 +943,7 @@ void CreateSketcherCommandsBSpline(void)
|
||||
rcCmdMgr.addCommand(new CmdSketcherCompBSplineShowHideGeometryInformation());
|
||||
rcCmdMgr.addCommand(new CmdSketcherConvertToNURB());
|
||||
rcCmdMgr.addCommand(new CmdSketcherIncreaseDegree());
|
||||
rcCmdMgr.addCommand(new CmdSketcherDecreaseDegree()); // TODO: implement this function
|
||||
rcCmdMgr.addCommand(new CmdSketcherDecreaseDegree());
|
||||
rcCmdMgr.addCommand(new CmdSketcherIncreaseKnotMultiplicity());
|
||||
rcCmdMgr.addCommand(new CmdSketcherDecreaseKnotMultiplicity());
|
||||
rcCmdMgr.addCommand(new CmdSketcherCompModifyKnotMultiplicity());
|
||||
|
||||
@@ -373,7 +373,7 @@ inline void SketcherAddWorkbenchBSplines<Gui::MenuItem>(Gui::MenuItem& bspline)
|
||||
<< "Sketcher_BSplineKnotMultiplicity"
|
||||
<< "Sketcher_BSplineConvertToNURB"
|
||||
<< "Sketcher_BSplineIncreaseDegree"
|
||||
<< "Sketcher_BSplineDecreaseDegree" // TODO: implement this command
|
||||
<< "Sketcher_BSplineDecreaseDegree"
|
||||
<< "Sketcher_BSplineIncreaseKnotMultiplicity"
|
||||
<< "Sketcher_BSplineDecreaseKnotMultiplicity";
|
||||
}
|
||||
@@ -384,7 +384,7 @@ inline void SketcherAddWorkbenchBSplines<Gui::ToolBarItem>(Gui::ToolBarItem& bsp
|
||||
bspline << "Sketcher_CompBSplineShowHideGeometryInformation"
|
||||
<< "Sketcher_BSplineConvertToNURB"
|
||||
<< "Sketcher_BSplineIncreaseDegree"
|
||||
<< "Sketcher_BSplineDecreaseDegree" // TODO: implement this command
|
||||
<< "Sketcher_BSplineDecreaseDegree"
|
||||
<< "Sketcher_CompModifyKnotMultiplicity";
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user