[Sketcher] Run clang-format on DrawSketchHandlerBSplineByInterpolation.h
This commit is contained in:
committed by
abdullahtahiriyo
parent
c66ed794f9
commit
7446c19c08
@@ -23,25 +23,26 @@
|
||||
#ifndef SKETCHERGUI_DrawSketchHandlerBSplineByInterpolation_H
|
||||
#define SKETCHERGUI_DrawSketchHandlerBSplineByInterpolation_H
|
||||
|
||||
#include <QInputDialog>
|
||||
#include <Inventor/events/SoKeyboardEvent.h>
|
||||
#include <QInputDialog>
|
||||
|
||||
#include "GeometryCreationMode.h"
|
||||
|
||||
|
||||
namespace SketcherGui {
|
||||
namespace SketcherGui
|
||||
{
|
||||
|
||||
extern GeometryCreationMode geometryCreationMode; // defined in CommandCreateGeo.cpp
|
||||
extern GeometryCreationMode geometryCreationMode;// defined in CommandCreateGeo.cpp
|
||||
|
||||
class DrawSketchHandlerBSplineByInterpolation: public DrawSketchHandler
|
||||
{
|
||||
public:
|
||||
explicit DrawSketchHandlerBSplineByInterpolation(int constructionMethod)
|
||||
: Mode(STATUS_SEEK_FIRST_POINT)
|
||||
, MousePressMode(MOUSE_NOT_PRESSED)
|
||||
, ConstrMethod(constructionMethod)
|
||||
, SplineDegree(3)
|
||||
, IsClosed(false)
|
||||
: Mode(STATUS_SEEK_FIRST_POINT),
|
||||
MousePressMode(MOUSE_NOT_PRESSED),
|
||||
ConstrMethod(constructionMethod),
|
||||
SplineDegree(3),
|
||||
IsClosed(false)
|
||||
{
|
||||
addSugConstraint();
|
||||
applyCursor();
|
||||
@@ -50,7 +51,8 @@ public:
|
||||
virtual ~DrawSketchHandlerBSplineByInterpolation() = default;
|
||||
|
||||
/// modes
|
||||
enum SELECT_MODE {
|
||||
enum SELECT_MODE
|
||||
{
|
||||
STATUS_SEEK_FIRST_POINT,
|
||||
STATUS_SEEK_ADDITIONAL_POINTS,
|
||||
STATUS_CLOSE
|
||||
@@ -59,7 +61,8 @@ public:
|
||||
// TODO: this kind of behavior will be useful in a superclass
|
||||
// when LMB is pressed it's a transitional state so some undos can't be done
|
||||
// (like delete last knot)
|
||||
enum MOUSE_PRESS_MODE {
|
||||
enum MOUSE_PRESS_MODE
|
||||
{
|
||||
MOUSE_PRESSED,
|
||||
MOUSE_NOT_PRESSED
|
||||
};
|
||||
@@ -68,21 +71,21 @@ public:
|
||||
{
|
||||
prevCursorPosition = onSketchPos;
|
||||
|
||||
if (Mode==STATUS_SEEK_FIRST_POINT) {
|
||||
if (Mode == STATUS_SEEK_FIRST_POINT) {
|
||||
setPositionText(onSketchPos);
|
||||
|
||||
if (seekAutoConstraint(sugConstr.back(), onSketchPos, Base::Vector2d(0.f,0.f))) {
|
||||
if (seekAutoConstraint(sugConstr.back(), onSketchPos, Base::Vector2d(0.f, 0.f))) {
|
||||
renderSuggestConstraintsCursor(sugConstr.back());
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (Mode==STATUS_SEEK_ADDITIONAL_POINTS) {
|
||||
else if (Mode == STATUS_SEEK_ADDITIONAL_POINTS) {
|
||||
|
||||
drawControlPolygonToPosition(onSketchPos);
|
||||
|
||||
drawCursorToPosition(onSketchPos);
|
||||
|
||||
if (seekAutoConstraint(sugConstr.back(), onSketchPos, Base::Vector2d(0.f,0.f))) {
|
||||
if (seekAutoConstraint(sugConstr.back(), onSketchPos, Base::Vector2d(0.f, 0.f))) {
|
||||
renderSuggestConstraintsCursor(sugConstr.back());
|
||||
return;
|
||||
}
|
||||
@@ -97,7 +100,7 @@ public:
|
||||
|
||||
if (Mode == STATUS_SEEK_FIRST_POINT) {
|
||||
BSplineKnots.push_back(onSketchPos);
|
||||
BSplineMults.push_back(1); // NOTE: not strictly true for end-points
|
||||
BSplineMults.push_back(1);// NOTE: not strictly true for end-points
|
||||
|
||||
Mode = STATUS_SEEK_ADDITIONAL_POINTS;
|
||||
|
||||
@@ -105,9 +108,11 @@ public:
|
||||
try {
|
||||
Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Add Knot Point"));
|
||||
|
||||
//Add knot
|
||||
Gui::cmdAppObjectArgs(sketchgui->getObject(), "addGeometry(Part.Point(App.Vector(%f,%f,0)),True)",
|
||||
BSplineKnots.back().x, BSplineKnots.back().y);
|
||||
// Add knot
|
||||
Gui::cmdAppObjectArgs(sketchgui->getObject(),
|
||||
"addGeometry(Part.Point(App.Vector(%f,%f,0)),True)",
|
||||
BSplineKnots.back().x,
|
||||
BSplineKnots.back().y);
|
||||
|
||||
knotGeoIds.push_back(getHighestCurveIndex());
|
||||
}
|
||||
@@ -115,28 +120,29 @@ public:
|
||||
Base::Console().Error("%s\n", e.what());
|
||||
Gui::Command::abortCommand();
|
||||
|
||||
static_cast<Sketcher::SketchObject *>(sketchgui->getObject())->solve();
|
||||
static_cast<Sketcher::SketchObject*>(sketchgui->getObject())->solve();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// add auto constraints on knot
|
||||
if (!sugConstr.back().empty()) {
|
||||
createAutoConstraints(sugConstr.back(), knotGeoIds.back(), Sketcher::PointPos::start, false);
|
||||
createAutoConstraints(
|
||||
sugConstr.back(), knotGeoIds.back(), Sketcher::PointPos::start, false);
|
||||
}
|
||||
|
||||
static_cast<Sketcher::SketchObject *>(sketchgui->getObject())->solve();
|
||||
static_cast<Sketcher::SketchObject*>(sketchgui->getObject())->solve();
|
||||
|
||||
addSugConstraint();
|
||||
|
||||
}
|
||||
else if (Mode == STATUS_SEEK_ADDITIONAL_POINTS) {
|
||||
BSplineKnots.push_back(onSketchPos);
|
||||
BSplineMults.push_back(1); // NOTE: not strictly true for end-points
|
||||
BSplineMults.push_back(1);// NOTE: not strictly true for end-points
|
||||
|
||||
// check if coincident with first knot
|
||||
for(auto & ac : sugConstr.back()) {
|
||||
if( ac.Type == Sketcher::Coincident && ac.GeoId == knotGeoIds[0] && ac.PosId == Sketcher::PointPos::start ) {
|
||||
for (auto& ac : sugConstr.back()) {
|
||||
if (ac.Type == Sketcher::Coincident && ac.GeoId == knotGeoIds[0]
|
||||
&& ac.PosId == Sketcher::PointPos::start) {
|
||||
IsClosed = true;
|
||||
}
|
||||
}
|
||||
@@ -144,7 +150,7 @@ public:
|
||||
if (IsClosed) {
|
||||
Mode = STATUS_CLOSE;
|
||||
|
||||
if (ConstrMethod == 1) { // if periodic we do not need the last pole
|
||||
if (ConstrMethod == 1) {// if periodic we do not need the last pole
|
||||
BSplineKnots.pop_back();
|
||||
sugConstr.pop_back();
|
||||
|
||||
@@ -156,9 +162,11 @@ public:
|
||||
try {
|
||||
|
||||
|
||||
//Add knot
|
||||
Gui::cmdAppObjectArgs(sketchgui->getObject(), "addGeometry(Part.Point(App.Vector(%f,%f,0)),True)",
|
||||
BSplineKnots.back().x,BSplineKnots.back().y);
|
||||
// Add knot
|
||||
Gui::cmdAppObjectArgs(sketchgui->getObject(),
|
||||
"addGeometry(Part.Point(App.Vector(%f,%f,0)),True)",
|
||||
BSplineKnots.back().x,
|
||||
BSplineKnots.back().y);
|
||||
|
||||
knotGeoIds.push_back(getHighestCurveIndex());
|
||||
}
|
||||
@@ -166,20 +174,20 @@ public:
|
||||
Base::Console().Error("%s\n", e.what());
|
||||
Gui::Command::abortCommand();
|
||||
|
||||
static_cast<Sketcher::SketchObject *>(sketchgui->getObject())->solve();
|
||||
static_cast<Sketcher::SketchObject*>(sketchgui->getObject())->solve();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// add auto constraints on knot
|
||||
if (!sugConstr.back().empty()) {
|
||||
createAutoConstraints(sugConstr.back(), knotGeoIds.back(), Sketcher::PointPos::start, false);
|
||||
createAutoConstraints(
|
||||
sugConstr.back(), knotGeoIds.back(), Sketcher::PointPos::start, false);
|
||||
}
|
||||
|
||||
if (!IsClosed) {
|
||||
addSugConstraint();
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -198,8 +206,7 @@ public:
|
||||
// SplineDegree = QInputDialog::getInt(
|
||||
// Gui::getMainWindow(),
|
||||
// QObject::tr("B-Spline Degree"),
|
||||
// QObject::tr("NOTE: For construction by interpolation, this degree is ignored for now.\n"
|
||||
// "Define B-Spline Degree, between 1 and %1:")
|
||||
// QObject::tr("Define B-Spline Degree, between 1 and %1:")
|
||||
// .arg(QString::number(Geom_BSplineCurve::MaxDegree())),
|
||||
// SplineDegree, 1, Geom_BSplineCurve::MaxDegree(), 1);
|
||||
// // FIXME: Pressing Esc here also finishes the B-Spline creation.
|
||||
@@ -230,8 +237,7 @@ public:
|
||||
return;
|
||||
|
||||
// can only delete last knot if it exists
|
||||
if (STATUS_SEEK_FIRST_POINT == Mode ||
|
||||
STATUS_CLOSE == Mode)
|
||||
if (STATUS_SEEK_FIRST_POINT == Mode || STATUS_CLOSE == Mode)
|
||||
return;
|
||||
|
||||
// if only first knot exists it's equivalent to canceling current spline
|
||||
@@ -245,23 +251,25 @@ public:
|
||||
try {
|
||||
// already ensured that CurrentConstraint == EditCurve.size() > 1
|
||||
const int delGeoId = knotGeoIds.back();
|
||||
const auto& constraints = static_cast<Sketcher::SketchObject *>(sketchgui->getObject())->Constraints.getValues();
|
||||
const auto& constraints =
|
||||
static_cast<Sketcher::SketchObject*>(sketchgui->getObject())
|
||||
->Constraints.getValues();
|
||||
for (int i = constraints.size() - 1; i >= 0; --i) {
|
||||
if (delGeoId == constraints[i]->First ||
|
||||
delGeoId == constraints[i]->Second ||
|
||||
delGeoId == constraints[i]->Third)
|
||||
if (delGeoId == constraints[i]->First || delGeoId == constraints[i]->Second
|
||||
|| delGeoId == constraints[i]->Third)
|
||||
Gui::cmdAppObjectArgs(sketchgui->getObject(), "delConstraint(%d)", i);
|
||||
}
|
||||
|
||||
// Remove knot
|
||||
Gui::cmdAppObjectArgs(sketchgui->getObject(), "delGeometry(%d)", delGeoId);
|
||||
|
||||
static_cast<Sketcher::SketchObject *>(sketchgui->getObject())->solve();
|
||||
static_cast<Sketcher::SketchObject*>(sketchgui->getObject())->solve();
|
||||
|
||||
knotGeoIds.pop_back();
|
||||
BSplineKnots.pop_back();
|
||||
|
||||
// last entry is kept, as it corresponds to the current knot, but the one corresponding to the erased knot is removed
|
||||
// last entry is kept, as it corresponds to the current knot, but the one
|
||||
// corresponding to the erased knot is removed
|
||||
sugConstr.erase(std::prev(std::prev(sugConstr.end())));
|
||||
|
||||
|
||||
@@ -271,10 +279,11 @@ public:
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
Base::Console().Error("%s\n", e.what());
|
||||
// some commands might have already deleted some constraints/geometries but not others
|
||||
// some commands might have already deleted some constraints/geometries but not
|
||||
// others
|
||||
Gui::Command::abortCommand();
|
||||
|
||||
static_cast<Sketcher::SketchObject *>(sketchgui->getObject())->solve();
|
||||
static_cast<Sketcher::SketchObject*>(sketchgui->getObject())->solve();
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -288,24 +297,27 @@ public:
|
||||
// We must see if we need to create a B-spline before cancelling everything
|
||||
// and now just like any other Handler,
|
||||
|
||||
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher");
|
||||
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath(
|
||||
"User parameter:BaseApp/Preferences/Mod/Sketcher");
|
||||
|
||||
bool continuousMode = hGrp->GetBool("ContinuousCreationMode",true);
|
||||
bool continuousMode = hGrp->GetBool("ContinuousCreationMode", true);
|
||||
|
||||
if (knotGeoIds.size() > 1) {
|
||||
// create B-spline from existing knots
|
||||
Mode=STATUS_CLOSE;
|
||||
finishCommand(Base::Vector2d(0.f,0.f));
|
||||
Mode = STATUS_CLOSE;
|
||||
finishCommand(Base::Vector2d(0.f, 0.f));
|
||||
}
|
||||
else if(knotGeoIds.size() == 1) {
|
||||
// if we just have one point and we can not close anything, then cancel this creation but continue according to continuous mode
|
||||
//sketchgui->getDocument()->undo(1);
|
||||
else if (knotGeoIds.size() == 1) {
|
||||
// if we just have one point and we can not close anything, then cancel this creation
|
||||
// but continue according to continuous mode
|
||||
// sketchgui->getDocument()->undo(1);
|
||||
|
||||
Gui::Command::abortCommand();
|
||||
|
||||
tryAutoRecomputeIfNotSolve(static_cast<Sketcher::SketchObject *>(sketchgui->getObject()));
|
||||
tryAutoRecomputeIfNotSolve(
|
||||
static_cast<Sketcher::SketchObject*>(sketchgui->getObject()));
|
||||
|
||||
if(!continuousMode){
|
||||
if (!continuousMode) {
|
||||
DrawSketchHandler::quit();
|
||||
}
|
||||
else {
|
||||
@@ -313,7 +325,8 @@ public:
|
||||
resetHandlerState();
|
||||
}
|
||||
}
|
||||
else { // we have no data (CurrentConstraint == 0) so user when right-clicking really wants to exit
|
||||
else {// we have no data (CurrentConstraint == 0) so user when right-clicking really wants
|
||||
// to exit
|
||||
DrawSketchHandler::quit();
|
||||
}
|
||||
}
|
||||
@@ -363,12 +376,13 @@ private:
|
||||
{
|
||||
if (!BSplineKnots.empty()) {
|
||||
float length = (position - BSplineKnots.back()).Length();
|
||||
float angle = (position - BSplineKnots.back()).GetAngle(Base::Vector2d(1.f,0.f));
|
||||
float angle = (position - BSplineKnots.back()).GetAngle(Base::Vector2d(1.f, 0.f));
|
||||
|
||||
if (showCursorCoords()) {
|
||||
SbString text;
|
||||
std::string lengthString = lengthToDisplayFormat(length, 1);
|
||||
std::string angleString = angleToDisplayFormat((angle != -FLOAT_MAX) ? angle * 180 / M_PI : 0, 1);
|
||||
std::string angleString =
|
||||
angleToDisplayFormat((angle != -FLOAT_MAX) ? angle * 180 / M_PI : 0, 1);
|
||||
text.sprintf(" (%s, %s)", lengthString.c_str(), angleString.c_str());
|
||||
setPositionText(position, text);
|
||||
}
|
||||
@@ -382,15 +396,17 @@ private:
|
||||
|
||||
bool finishCommand(Base::Vector2d position)
|
||||
{
|
||||
if (Mode==STATUS_CLOSE) {
|
||||
if (Mode == STATUS_CLOSE) {
|
||||
unsetCursor();
|
||||
resetPositionText();
|
||||
|
||||
unsigned int myDegree = 3;
|
||||
|
||||
if (ConstrMethod == 0) {
|
||||
BSplineMults.front() = myDegree + 1; // FIXME: This is hardcoded until degree can be changed
|
||||
BSplineMults.back() = myDegree + 1; // FIXME: This is hardcoded until degree can be changed
|
||||
BSplineMults.front() =
|
||||
myDegree + 1;// FIXME: This is hardcoded until degree can be changed
|
||||
BSplineMults.back() =
|
||||
myDegree + 1;// FIXME: This is hardcoded until degree can be changed
|
||||
}
|
||||
|
||||
std::vector<std::stringstream> streams;
|
||||
@@ -398,40 +414,45 @@ private:
|
||||
// Create subsets of points between C0 knots.
|
||||
// The first point
|
||||
streams.emplace_back();
|
||||
streams.back() << "App.Vector(" << BSplineKnots.front().x << "," << BSplineKnots.front().y << "),";
|
||||
streams.back() << "App.Vector(" << BSplineKnots.front().x << ","
|
||||
<< BSplineKnots.front().y << "),";
|
||||
// Middle points
|
||||
for (size_t i = 1; i < BSplineKnots.size() - 1; ++i) {
|
||||
streams.back() << "App.Vector(" << BSplineKnots[i].x << "," << BSplineKnots[i].y << "),";
|
||||
streams.back() << "App.Vector(" << BSplineKnots[i].x << "," << BSplineKnots[i].y
|
||||
<< "),";
|
||||
if (BSplineMults[i] >= myDegree) {
|
||||
streams.emplace_back();
|
||||
streams.back() << "App.Vector(" << BSplineKnots[i].x << "," << BSplineKnots[i].y << "),";
|
||||
streams.back()
|
||||
<< "App.Vector(" << BSplineKnots[i].x << "," << BSplineKnots[i].y << "),";
|
||||
}
|
||||
}
|
||||
// The last point
|
||||
streams.back() << "App.Vector(" << BSplineKnots.back().x << "," << BSplineKnots.back().y << "),";
|
||||
streams.back() << "App.Vector(" << BSplineKnots.back().x << "," << BSplineKnots.back().y
|
||||
<< "),";
|
||||
|
||||
// Note the plural of plurals. Each element is a separate sequence.
|
||||
std::vector<std::string> controlpointses;
|
||||
controlpointses.reserve(streams.size());
|
||||
for (auto & stream: streams) {
|
||||
for (auto& stream : streams) {
|
||||
controlpointses.emplace_back(stream.str());
|
||||
|
||||
|
||||
|
||||
|
||||
auto& controlpoints = controlpointses.back();
|
||||
|
||||
// remove last comma and add brackets
|
||||
int index = controlpoints.rfind(',');
|
||||
controlpoints.resize(index);
|
||||
|
||||
|
||||
controlpoints.insert(0,1,'[');
|
||||
controlpoints.insert(0, 1, '[');
|
||||
controlpoints.append(1, ']');
|
||||
}
|
||||
|
||||
// With just 3 points provided OCCT gives a quadratic spline where
|
||||
// the middle point is NOT a knot. This needs to be treated differently.
|
||||
// FIXME: Decide whether to force a knot or not.
|
||||
std::vector<bool> isBetweenC0Points(BSplineKnots.size(), false);
|
||||
std::vector<bool> isBetweenC0Points(BSplineKnots.size(), false);
|
||||
for (size_t i = 1; i < BSplineKnots.size()-1; ++i) {
|
||||
for (size_t i = 1; i < BSplineKnots.size() - 1; ++i) {
|
||||
if (BSplineMults[i - 1] >= myDegree && BSplineMults[i + 1] >= myDegree)
|
||||
isBetweenC0Points[i] = true;
|
||||
}
|
||||
|
||||
@@ -444,36 +465,50 @@ private:
|
||||
Gui::Command::runCommand(Gui::Command::Gui, "_finalbsp_knots = []");
|
||||
Gui::Command::runCommand(Gui::Command::Gui, "_finalbsp_mults = []");
|
||||
Gui::Command::runCommand(Gui::Command::Gui, "_bsps = []");
|
||||
Gui::Command::runCommand(Gui::Command::Gui, "_bsps = []");
|
||||
for (auto& controlpoints : controlpointses) {
|
||||
// TODO: variable degrees?
|
||||
// TODO: variable degrees?
|
||||
QString cmdstr = QString::fromLatin1("_bsps.append(Part.BSplineCurve())\n"
|
||||
"_bsps[-1].interpolate(%1, PeriodicFlag=%2)\n"
|
||||
"_bsps[-1].increaseDegree(%3)")
|
||||
.arg(QString::fromLatin1(controlpoints.c_str()))
|
||||
.arg(QString::fromLatin1(ConstrMethod == 0 ?"False":"True"))
|
||||
QString cmdstr =
|
||||
QString::fromLatin1("_bsps.append(Part.BSplineCurve())\n"
|
||||
"_bsps[-1].interpolate(%1, PeriodicFlag=%2)\n"
|
||||
"_bsps[-1].increaseDegree(%3)")
|
||||
.arg(QString::fromLatin1(controlpoints.c_str()))
|
||||
.arg(QString::fromLatin1(ConstrMethod == 0 ? "False" : "True"))
|
||||
.arg(myDegree);
|
||||
Gui::Command::runCommand(Gui::Command::Gui, cmdstr.toLatin1());
|
||||
// Adjust internal knots here (raise multiplicity)
|
||||
// How this contributes to the final B-spline
|
||||
if (controlpoints == controlpointses.front()) {
|
||||
if (controlpoints == controlpointses.front()) {
|
||||
Gui::Command::runCommand(Gui::Command::Gui, "_finalbsp_poles.extend(_bsps[-1].getPoles())");
|
||||
Gui::Command::runCommand(Gui::Command::Gui, "_finalbsp_knots.extend(_bsps[-1].getKnots())");
|
||||
Gui::Command::runCommand(Gui::Command::Gui,
|
||||
"_finalbsp_poles.extend(_bsps[-1].getPoles())");
|
||||
Gui::Command::runCommand(Gui::Command::Gui,
|
||||
"_finalbsp_knots.extend(_bsps[-1].getKnots())");
|
||||
Gui::Command::runCommand(
|
||||
Gui::Command::Gui,
|
||||
"_finalbsp_mults.extend(_bsps[-1].getMultiplicities())");
|
||||
}
|
||||
else {
|
||||
else {
|
||||
Gui::Command::runCommand(Gui::Command::Gui, "_finalbsp_poles.extend(_bsps[-1].getPoles()[1:])");
|
||||
Gui::Command::runCommand(Gui::Command::Gui, "_finalbsp_knots.extend([_finalbsp_knots[-1] + i for i in _bsps[-1].getKnots()[1:]])");
|
||||
Gui::Command::runCommand(Gui::Command::Gui, "_finalbsp_mults[-1] = 3"); // FIXME: Hardcoded
|
||||
Gui::Command::runCommand(
|
||||
Gui::Command::Gui, "_finalbsp_poles.extend(_bsps[-1].getPoles()[1:])");
|
||||
Gui::Command::runCommand(Gui::Command::Gui,
|
||||
"_finalbsp_knots.extend([_finalbsp_knots[-1] + i "
|
||||
"for i in _bsps[-1].getKnots()[1:]])");
|
||||
Gui::Command::runCommand(Gui::Command::Gui,
|
||||
"_finalbsp_mults[-1] = 3");// FIXME: Hardcoded
|
||||
Gui::Command::runCommand(
|
||||
Gui::Command::Gui,
|
||||
"_finalbsp_mults.extend(_bsps[-1].getMultiplicities()[1:])");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// {"poles", "mults", "knots", "periodic", "degree", "weights", "CheckRational", NULL};
|
||||
Gui::cmdAppObjectArgs(sketchgui->getObject(), "addGeometry(Part.BSplineCurve"
|
||||
"(_finalbsp_poles,_finalbsp_mults,_finalbsp_knots,%s,%d,None,False),%s)",
|
||||
ConstrMethod == 0 ?"False":"True",
|
||||
myDegree,
|
||||
// {"poles", "mults", "knots", "periodic", "degree", "weights", "CheckRational",
|
||||
// NULL};
|
||||
Gui::cmdAppObjectArgs(
|
||||
sketchgui->getObject(),
|
||||
"addGeometry(Part.BSplineCurve"
|
||||
"(_finalbsp_poles,_finalbsp_mults,_finalbsp_knots,%s,%d,None,False),%s)",
|
||||
ConstrMethod == 0 ? "False" : "True",
|
||||
myDegree,
|
||||
geometryCreationMode == Construction ? "True" : "False");
|
||||
currentgeoid++;
|
||||
|
||||
// TODO: Confirm we do not need to delete individual elements
|
||||
@@ -483,17 +518,22 @@ private:
|
||||
Gui::Command::runCommand(Gui::Command::Gui, "del(_finalbsp_mults)\n");
|
||||
|
||||
// autoconstraints were added to the knots, which is ok because they must go to the
|
||||
// autoconstraints were added to the knots, which is ok because they must go to the
|
||||
// right position, or the user will freak-out if they appear out of the autoconstrained position.
|
||||
// However, autoconstraints on the first and last knot, in non-periodic b-splines (with appropriate endpoint knot multiplicity)
|
||||
// as the ones created by this tool are intended for the b-spline endpoints, and not for the knots,
|
||||
// right position, or the user will freak-out if they appear out of the
|
||||
// autoconstrained position. However, autoconstraints on the first and last knot, in
|
||||
// non-periodic b-splines (with appropriate endpoint knot multiplicity) as the ones
|
||||
// created by this tool are intended for the b-spline endpoints, and not for the
|
||||
// knots, so here we retrieve any autoconstraint on those knots and mangle it to the
|
||||
// endpoint.
|
||||
if (ConstrMethod == 0) {
|
||||
if (ConstrMethod == 0) {
|
||||
for(auto & constr : static_cast<Sketcher::SketchObject *>(sketchgui->getObject())->Constraints.getValues()) {
|
||||
for (auto& constr : static_cast<Sketcher::SketchObject*>(sketchgui->getObject())
|
||||
->Constraints.getValues()) {
|
||||
if (constr->First == knotGeoIds[0]
|
||||
&& constr->FirstPos == Sketcher::PointPos::start) {
|
||||
constr->First = currentgeoid;
|
||||
constr->FirstPos = Sketcher::PointPos::start;
|
||||
}
|
||||
}
|
||||
else if (constr->First == knotGeoIds.back()
|
||||
&& constr->FirstPos == Sketcher::PointPos::start) {
|
||||
constr->First = currentgeoid;
|
||||
constr->FirstPos = Sketcher::PointPos::end;
|
||||
}
|
||||
@@ -509,49 +549,62 @@ private:
|
||||
for (size_t i = 0; i < knotGeoIds.size(); i++) {
|
||||
if (isBetweenC0Points[i]) {
|
||||
// Constraint point on curve
|
||||
// Constraint point on curve
|
||||
cstream << "conList.append(Sketcher.Constraint('PointOnObject'," << knotGeoIds[0] + i
|
||||
cstream << "conList.append(Sketcher.Constraint('PointOnObject',"
|
||||
<< knotGeoIds[0] + i << ","
|
||||
<< static_cast<int>(Sketcher::PointPos::start) << ","
|
||||
<< currentgeoid << "))\n";
|
||||
}
|
||||
else {
|
||||
else {
|
||||
cstream << "conList.append(Sketcher.Constraint('InternalAlignment:Sketcher::BSplineKnotPoint'," << knotGeoIds[0] + i
|
||||
<< "," << static_cast<int>(Sketcher::PointPos::start) << "," << currentgeoid << "," << knotNumber << "))\n";
|
||||
cstream << "conList.append(Sketcher.Constraint('InternalAlignment:Sketcher:"
|
||||
":BSplineKnotPoint',"
|
||||
<< knotGeoIds[0] + i << ","
|
||||
<< static_cast<int>(Sketcher::PointPos::start) << ","
|
||||
<< currentgeoid << "," << knotNumber << "))\n";
|
||||
// NOTE: Assume here that the spline shape doesn't change on increasing knot
|
||||
// multiplicity.
|
||||
// Change the knot multiplicity here because the user asked and it's not C0
|
||||
// NOTE: The knot number here has to be provided in the OCCT ordering.
|
||||
if (BSplineMults[i] > 1 && BSplineMults[i] < myDegree) {
|
||||
Gui::cmdAppObjectArgs(sketchgui->getObject(),
|
||||
"modifyBSplineKnotMultiplicity(%d, %d, %d) ",
|
||||
"modifyBSplineKnotMultiplicity(%d, %d, %d) ",
|
||||
currentgeoid,
|
||||
knotNumber + 1,
|
||||
BSplineMults[i] - 1);
|
||||
}
|
||||
knotNumber++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
cstream << Gui::Command::getObjectCmd(sketchgui->getObject())
|
||||
<< ".addConstraint(conList)\n";
|
||||
cstream << "del conList\n";
|
||||
|
||||
Gui::Command::doCommand(Gui::Command::Doc, cstream.str().c_str());
|
||||
|
||||
// for showing the rest of internal geometry on creation
|
||||
// for showing the rest of internal geometry on creation
|
||||
Gui::cmdAppObjectArgs(
|
||||
sketchgui->getObject(), "exposeInternalGeometry(%d)", currentgeoid);
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
Base::Console().Error("%s\n", e.what());
|
||||
Gui::Command::abortCommand();
|
||||
|
||||
|
||||
tryAutoRecomputeIfNotSolve(
|
||||
static_cast<Sketcher::SketchObject*>(sketchgui->getObject()));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Gui::Command::commitCommand();
|
||||
|
||||
|
||||
tryAutoRecomputeIfNotSolve(
|
||||
static_cast<Sketcher::SketchObject*>(sketchgui->getObject()));
|
||||
|
||||
|
||||
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher");
|
||||
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath(
|
||||
"User parameter:BaseApp/Preferences/Mod/Sketcher");
|
||||
bool continuousMode = hGrp->GetBool("ContinuousCreationMode", true);
|
||||
|
||||
|
||||
if (continuousMode) {
|
||||
// This code enables the continuous creation mode.
|
||||
resetHandlerState();
|
||||
|
||||
@@ -562,8 +615,9 @@ private:
|
||||
* handler is destroyed by the quit() method on pressing the
|
||||
* right button of the mouse */
|
||||
}
|
||||
}
|
||||
else{
|
||||
else {
|
||||
sketchgui
|
||||
->purgeHandler();// no code after this line, Handler get deleted in ViewProvider
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -593,7 +647,7 @@ protected:
|
||||
};
|
||||
|
||||
|
||||
|
||||
}// namespace SketcherGui
|
||||
|
||||
|
||||
|
||||
#endif// SKETCHERGUI_DrawSketchHandlerBSplineByInterpolation_H
|
||||
|
||||
Reference in New Issue
Block a user