Implement periodic B-spline curves.
if (theKnots.empty() || theMults.empty())
return newBSpline2d(thePoles, theWeights, theDegree, thePeriodic);
+ int anAuxPole = 0;
+ if (thePeriodic && thePoles.front()->distance(thePoles.back()) > Precision::Confusion())
+ anAuxPole = 1;
+
// collect arrays of poles, weights, knots and multiplicities
- TColgp_Array1OfPnt2d aPoles(1, (int)thePoles.size());
- TColStd_Array1OfReal aWeights(1, (int)theWeights.size());
+ TColgp_Array1OfPnt2d aPoles(1, (int)thePoles.size() + anAuxPole);
+ TColStd_Array1OfReal aWeights(1, (int)theWeights.size() + anAuxPole);
TColStd_Array1OfReal aKnots(1, (int)theKnots.size());
TColStd_Array1OfInteger aMults(1, (int)theMults.size());
aMIt != theMults.end(); ++aMIt, ++anIndex)
aMults.SetValue(anIndex, *aMIt);
+ if (thePeriodic) {
+ aPoles.ChangeLast() = aPoles.First();
+ aWeights.ChangeLast() = aWeights.First();
+ }
+
Handle(Geom2d_BSplineCurve) aCurve =
new Geom2d_BSplineCurve(aPoles, aWeights, aKnots, aMults, theDegree, thePeriodic);
return new Handle_Geom2d_BSplineCurve(aCurve);
const int theDegree,
const bool thePeriodic)
{
+ std::list<std::shared_ptr<GeomAPI_Pnt2d> > aPoles = thePoles;
+ std::list<double> aWeights = theWeights;
+ int aMult = theDegree + 1;
int aNbKnots = (int)thePoles.size() - theDegree + 1;
+ if (thePeriodic) {
+ if (aPoles.front()->distance(aPoles.back()) < Precision::Confusion()) {
+ aPoles.pop_back();
+ aWeights.pop_back();
+ }
+ aPoles.push_back(aPoles.front());
+ aWeights.push_back(aWeights.front());
+ aMult = 1;
+ aNbKnots = (int)aPoles.size() + 1;
+ }
+
if (aNbKnots < 2)
return new Handle_Geom2d_BSplineCurve();
aKnots.push_back(aEndParam);
std::list<int> aMults(aNbKnots - 2, 1);
- aMults.push_front(theDegree + 1);
- aMults.push_back(theDegree + 1);
+ aMults.push_front(aMult);
+ aMults.push_back(aMult);
- return newBSpline2d(thePoles, theWeights, aKnots, aMults, theDegree, thePeriodic);
+ return newBSpline2d(aPoles, aWeights, aKnots, aMults, theDegree, thePeriodic);
}
static Handle_Geom2d_BSplineCurve* newBSpline2d(
SketchPlugin.h
SketchPlugin_Arc.h
SketchPlugin_BSpline.h
+ SketchPlugin_BSplinePeriodic.h
SketchPlugin_Circle.h
SketchPlugin_Constraint.h
SketchPlugin_ConstraintAngle.h
SET(PROJECT_SOURCES
SketchPlugin_Arc.cpp
SketchPlugin_BSpline.cpp
+ SketchPlugin_BSplinePeriodic.cpp
SketchPlugin_Circle.cpp
SketchPlugin_Constraint.cpp
SketchPlugin_ConstraintAngle.cpp
std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
attribute(END_ID()))->setValue(aPolesArray->pnt(aPolesArray->size() - 1));
}
-//// else if (theID == REVERSED_ID() && myParamDelta == 0.0)
-//// myParamDelta = 2.0 * PI;
}
--- /dev/null
+// Copyright (C) 2019-2020 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 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
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include <SketchPlugin_BSplinePeriodic.h>
+#include <SketchPlugin_Sketch.h>
+
+#include <GeomAlgoAPI_EdgeBuilder.h>
+
+#include <GeomAPI_Pnt2d.h>
+
+#include <GeomDataAPI_Point2D.h>
+#include <GeomDataAPI_Point2DArray.h>
+
+#include <ModelAPI_AttributeDoubleArray.h>
+#include <ModelAPI_AttributeIntArray.h>
+#include <ModelAPI_AttributeInteger.h>
+#include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Validator.h>
+
+
+SketchPlugin_BSplinePeriodic::SketchPlugin_BSplinePeriodic()
+ : SketchPlugin_SketchEntity()
+{
+}
+
+void SketchPlugin_BSplinePeriodic::initDerivedClassAttributes()
+{
+ data()->addAttribute(POLES_ID(), GeomDataAPI_Point2DArray::typeId());
+ data()->addAttribute(WEIGHTS_ID(), ModelAPI_AttributeDoubleArray::typeId());
+ data()->addAttribute(KNOTS_ID(), ModelAPI_AttributeDoubleArray::typeId());
+ data()->addAttribute(MULTS_ID(), ModelAPI_AttributeIntArray::typeId());
+ data()->addAttribute(DEGREE_ID(), ModelAPI_AttributeInteger::typeId());
+
+ data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::typeId());
+ ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EXTERNAL_ID());
+}
+
+void SketchPlugin_BSplinePeriodic::execute()
+{
+ SketchPlugin_Sketch* aSketch = sketch();
+ if(!aSketch) {
+ return;
+ }
+
+ AttributePoint2DArrayPtr aPolesArray =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2DArray>(attribute(POLES_ID()));
+ AttributeDoubleArrayPtr aWeightsArray = data()->realArray(WEIGHTS_ID());
+ AttributeDoubleArrayPtr aKnotsArray = data()->realArray(KNOTS_ID());
+ AttributeIntArrayPtr aMultsArray = data()->intArray(MULTS_ID());
+ AttributeIntegerPtr aDegreeAttr = data()->integer(DEGREE_ID());
+
+ // collect poles
+ std::list<GeomPnt2dPtr> aPoles2D;
+ for (int anIndex = 0; anIndex < aPolesArray->size(); ++anIndex) {
+ GeomPnt2dPtr aPole = aPolesArray->pnt(anIndex);
+ aPoles2D.push_back(aPole);
+ }
+ // collect weights
+ std::list<double> aWeights;
+ for (int anIndex = 0; anIndex < aWeightsArray->size(); ++anIndex)
+ aWeights.push_back(aWeightsArray->value(anIndex));
+ // collect knots
+ std::list<double> aKnots;
+ for (int anIndex = 0; anIndex < aKnotsArray->size(); ++anIndex)
+ aKnots.push_back(aKnotsArray->value(anIndex));
+ // collect multiplicities
+ std::list<int> aMults;
+ for (int anIndex = 0; anIndex < aMultsArray->size(); ++anIndex)
+ aMults.push_back(aMultsArray->value(anIndex));
+
+ // create result non-periodic B-spline curve
+ GeomShapePtr anEdge = GeomAlgoAPI_EdgeBuilder::bsplineOnPlane(aSketch->coordinatePlane(),
+ aPoles2D, aWeights, aKnots, aMults, aDegreeAttr->value(), true);
+
+ ResultConstructionPtr aResult = document()->createConstruction(data(), 0);
+ aResult->setShape(anEdge);
+ aResult->setIsInHistory(false);
+ setResult(aResult, 0);
+}
+
+bool SketchPlugin_BSplinePeriodic::isFixed() {
+ return data()->selection(EXTERNAL_ID())->context().get() != NULL;
+}
+
+void SketchPlugin_BSplinePeriodic::attributeChanged(const std::string& theID) {
+ // the second condition for unability to move external segments anywhere
+ if (theID == EXTERNAL_ID() || isFixed()) {
+ std::shared_ptr<GeomAPI_Shape> aSelection = data()->selection(EXTERNAL_ID())->value();
+ if (!aSelection) {
+ // empty shape in selection shows that the shape is equal to context
+ ResultPtr anExtRes = selection(EXTERNAL_ID())->context();
+ if (anExtRes)
+ aSelection = anExtRes->shape();
+ }
+//// // update arguments due to the selection value
+//// if (aSelection && !aSelection->isNull() && aSelection->isEdge()) {
+//// std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(aSelection));
+//// std::shared_ptr<GeomAPI_Ellipse> anEllipse = anEdge->ellipse();
+////
+//// bool aWasBlocked = data()->blockSendAttributeUpdated(true);
+//// std::shared_ptr<GeomDataAPI_Point2D> aCenterAttr =
+//// std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(CENTER_ID()));
+//// aCenterAttr->setValue(sketch()->to2D(anEllipse->center()));
+////
+//// std::shared_ptr<GeomDataAPI_Point2D> aFocusAttr =
+//// std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(FIRST_FOCUS_ID()));
+//// aFocusAttr->setValue(sketch()->to2D(anEllipse->firstFocus()));
+////
+//// std::shared_ptr<GeomDataAPI_Point2D> aStartAttr =
+//// std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(START_POINT_ID()));
+//// aStartAttr->setValue(sketch()->to2D(anEdge->firstPoint()));
+////
+//// std::shared_ptr<GeomDataAPI_Point2D> aEndAttr =
+//// std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(END_POINT_ID()));
+//// aEndAttr->setValue(sketch()->to2D(anEdge->lastPoint()));
+////
+//// real(MAJOR_RADIUS_ID())->setValue(anEllipse->majorRadius());
+//// real(MINOR_RADIUS_ID())->setValue(anEllipse->minorRadius());
+////
+//// double aStartParam, aMidParam, aEndParam;
+//// anEllipse->parameter(anEdge->firstPoint(), tolerance, aStartParam);
+//// anEllipse->parameter(anEdge->middlePoint(), tolerance, aMidParam);
+//// anEllipse->parameter(anEdge->lastPoint(), tolerance, aEndParam);
+//// if (aEndParam < aStartParam)
+//// aEndParam += 2.0 * PI;
+//// if (aMidParam < aStartParam)
+//// aMidParam += 2.0 * PI;
+//// boolean(REVERSED_ID())->setValue(aMidParam > aEndParam);
+////
+//// data()->blockSendAttributeUpdated(aWasBlocked, false);
+////
+//// fillCharacteristicPoints();
+//// }
+ }
+}
--- /dev/null
+// Copyright (C) 2019-2020 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 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
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef SketchPlugin_BSplinePeriodic_H_
+#define SketchPlugin_BSplinePeriodic_H_
+
+#include <SketchPlugin.h>
+#include <SketchPlugin_SketchEntity.h>
+
+/**\class SketchPlugin_BSplinePeriodic
+ * \ingroup Plugins
+ * \brief Feature for creation of the periodic B-spline curve in the sketch.
+ */
+class SketchPlugin_BSplinePeriodic : public SketchPlugin_SketchEntity
+{
+public:
+ /// Ellipse feature kind
+ inline static const std::string& ID()
+ {
+ static const std::string ID("SketchBSplinePeriodic");
+ return ID;
+ }
+
+ /// list of B-spline poles
+ inline static const std::string& POLES_ID()
+ {
+ static const std::string ID("poles");
+ return ID;
+ }
+
+ /// list of B-spline weights
+ inline static const std::string& WEIGHTS_ID()
+ {
+ static const std::string ID("weights");
+ return ID;
+ }
+
+ /// attribute to store the degree of B-spline
+ inline static const std::string& DEGREE_ID()
+ {
+ static const std::string ID("degree");
+ return ID;
+ }
+
+ /// list of B-spline knots
+ inline static const std::string& KNOTS_ID()
+ {
+ static const std::string ID("knots");
+ return ID;
+ }
+
+ /// list of B-spline multiplicities
+ inline static const std::string& MULTS_ID()
+ {
+ static const std::string ID("multiplicities");
+ return ID;
+ }
+
+ /// Returns the kind of a feature
+ SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
+ {
+ static std::string MY_KIND = SketchPlugin_BSplinePeriodic::ID();
+ return MY_KIND;
+ }
+
+ /// Returns true is sketch element is under the rigid constraint
+ SKETCHPLUGIN_EXPORT virtual bool isFixed();
+
+ /// Called on change of any argument-attribute of this object
+ SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
+
+ /// Creates a new part document if needed
+ SKETCHPLUGIN_EXPORT virtual void execute();
+
+ /// Use plugin manager for features creation
+ SketchPlugin_BSplinePeriodic();
+
+protected:
+ /// \brief Initializes attributes of derived class.
+ virtual void initDerivedClassAttributes();
+};
+
+#endif
#include <SketchPlugin_MacroBSpline.h>
#include <SketchPlugin_BSpline.h>
+#include <SketchPlugin_BSplinePeriodic.h>
#include <SketchPlugin_ConstraintCoincidenceInternal.h>
#include <SketchPlugin_Line.h>
#include <SketchPlugin_Point.h>
{
}
+SketchPlugin_MacroBSpline::SketchPlugin_MacroBSpline(bool isPeriodic)
+ : SketchPlugin_SketchEntity(),
+ myDegree(3),
+ myIsPeriodic(isPeriodic)
+{
+}
+
void SketchPlugin_MacroBSpline::initAttributes()
{
data()->addAttribute(POLES_ID(), GeomDataAPI_Point2DArray::typeId());
FeaturePtr SketchPlugin_MacroBSpline::createBSplineFeature()
{
- FeaturePtr aBSpline = sketch()->addFeature(SketchPlugin_BSpline::ID());
+ FeaturePtr aBSpline = sketch()->addFeature(
+ myIsPeriodic ? SketchPlugin_BSplinePeriodic::ID() : SketchPlugin_BSpline::ID());
- aBSpline->integer(SketchPlugin_BSpline::DEGREE_ID())->setValue(myDegree);
+ aBSpline->integer(myIsPeriodic ? SketchPlugin_BSplinePeriodic::DEGREE_ID()
+ : SketchPlugin_BSpline::DEGREE_ID())->setValue(myDegree);
AttributePoint2DArrayPtr aPoles = std::dynamic_pointer_cast<GeomDataAPI_Point2DArray>(
- aBSpline->attribute(SketchPlugin_BSpline::POLES_ID()));
+ aBSpline->attribute(myIsPeriodic ? SketchPlugin_BSplinePeriodic::POLES_ID()
+ : SketchPlugin_BSpline::POLES_ID()));
AttributePoint2DArrayPtr aPolesMacro =
std::dynamic_pointer_cast<GeomDataAPI_Point2DArray>(attribute(POLES_ID()));
aPoles->assign(aPolesMacro);
- AttributeDoubleArrayPtr aWeights =
- aBSpline->data()->realArray(SketchPlugin_BSpline::WEIGHTS_ID());
+ AttributeDoubleArrayPtr aWeights = aBSpline->data()->realArray(
+ myIsPeriodic ? SketchPlugin_BSplinePeriodic::WEIGHTS_ID()
+ : SketchPlugin_BSpline::WEIGHTS_ID());
AttributeDoubleArrayPtr aWeightsMacro = data()->realArray(WEIGHTS_ID());
int aSize = aWeightsMacro->size();
aWeights->setSize(aSize);
for (int index = 0; index < aSize; ++index)
aWeights->setValue(index, aWeightsMacro->value(index));
- AttributeDoubleArrayPtr aKnots =
- aBSpline->data()->realArray(SketchPlugin_BSpline::KNOTS_ID());
+ AttributeDoubleArrayPtr aKnots = aBSpline->data()->realArray(
+ myIsPeriodic ? SketchPlugin_BSplinePeriodic::KNOTS_ID() : SketchPlugin_BSpline::KNOTS_ID());
aSize = (int)myKnots.size();
aKnots->setSize(aSize);
std::list<double>::iterator aKIt = myKnots.begin();
for (int index = 0; index < aSize; ++index, ++aKIt)
aKnots->setValue(index, *aKIt);
- AttributeIntArrayPtr aMults =
- aBSpline->data()->intArray(SketchPlugin_BSpline::MULTS_ID());
+ AttributeIntArrayPtr aMults = aBSpline->data()->intArray(
+ myIsPeriodic ? SketchPlugin_BSplinePeriodic::MULTS_ID() : SketchPlugin_BSpline::MULTS_ID());
aSize = (int)myMultiplicities.size();
aMults->setSize(aSize);
std::list<int>::iterator aMIt = myMultiplicities.begin();
for (int index = 0; index < aSize; ++index, ++aMIt)
aMults->setValue(index, *aMIt);
- SketchPlugin_Sketch* aSketch =
- std::dynamic_pointer_cast<SketchPlugin_Feature>(aBSpline)->sketch();
-
- AttributePoint2DPtr aStartPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- aBSpline->attribute(SketchPlugin_BSpline::START_ID()));
- aStartPoint->setValue(aPoles->pnt(0));
+ if (!myIsPeriodic) {
+ AttributePoint2DPtr aStartPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ aBSpline->attribute(SketchPlugin_BSpline::START_ID()));
+ aStartPoint->setValue(aPoles->pnt(0));
- AttributePoint2DPtr aEndPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- aBSpline->attribute(SketchPlugin_BSpline::END_ID()));
- aEndPoint->setValue(aPoles->pnt(aPoles->size() - 1));
+ AttributePoint2DPtr aEndPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ aBSpline->attribute(SketchPlugin_BSpline::END_ID()));
+ aEndPoint->setValue(aPoles->pnt(aPoles->size() - 1));
+ }
- aBSpline->boolean(SketchPlugin_BSpline::AUXILIARY_ID())->setValue(
+ aBSpline->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->setValue(
boolean(AUXILIARY_ID())->value());
aBSpline->execute();
// segments
for (int index = 1; index < aSize; ++index)
createAuxiliarySegment(theBSpline, aPoles, index - 1, index);
+ if (myIsPeriodic) {
+ // additional segment to close the control polygon
+ createAuxiliarySegment(theBSpline, aPoles, aSize - 1, 0);
+ }
}
void SketchPlugin_MacroBSpline::constraintsForPoles(const std::list<FeaturePtr>& thePoles)
if (!aSketch)
return AISObjectPtr();
- static const bool PERIODIC = false;
-
AttributePoint2DArrayPtr aPolesArray =
std::dynamic_pointer_cast<GeomDataAPI_Point2DArray>(attribute(POLES_ID()));
AttributeDoubleArrayPtr aWeightsArray = data()->realArray(WEIGHTS_ID());
// create result non-periodic B-spline curve
std::shared_ptr<GeomAPI_BSpline2d> aBSplineCurve;
try {
- aBSplineCurve.reset(new GeomAPI_BSpline2d(aPoles2D, aWeights, PERIODIC));
+ aBSplineCurve.reset(new GeomAPI_BSpline2d(aPoles2D, aWeights, myIsPeriodic));
} catch (...) {
// cannot build a B-spline curve
return AISObjectPtr();
/// Use plugin manager for features creation
SketchPlugin_MacroBSpline();
+protected:
+ SketchPlugin_MacroBSpline(bool isPeriodic);
+
private:
FeaturePtr createBSplineFeature();
bool myIsPeriodic;
};
+
+/**\class SketchPlugin_MacroBSpline
+* \ingroup Plugins
+* \brief Feature for creation of the new B-spline in Sketch.
+*/
+class SketchPlugin_MacroBSplinePeriodic : public SketchPlugin_MacroBSpline
+{
+public:
+ /// B-spline macro feature kind
+ inline static const std::string& ID()
+ {
+ static const std::string ID("SketchMacroBSplinePeriodic");
+ return ID;
+ }
+
+ /// Returns the kind of a feature
+ SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
+ {
+ return SketchPlugin_MacroBSpline::ID();
+ }
+
+ /// Use plugin manager for features creation
+ SketchPlugin_MacroBSplinePeriodic() : SketchPlugin_MacroBSpline(true) {}
+};
+
#endif
#include <SketchPlugin_Circle.h>
#include <SketchPlugin_Arc.h>
#include <SketchPlugin_BSpline.h>
+#include <SketchPlugin_BSplinePeriodic.h>
#include <SketchPlugin_Projection.h>
#include <SketchPlugin_ConstraintAngle.h>
#include <SketchPlugin_ConstraintCoincidence.h>
return FeaturePtr(new SketchPlugin_Arc);
} else if (theFeatureID == SketchPlugin_BSpline::ID()) {
return FeaturePtr(new SketchPlugin_BSpline);
+ } else if (theFeatureID == SketchPlugin_BSplinePeriodic::ID()) {
+ return FeaturePtr(new SketchPlugin_BSplinePeriodic);
} else if (theFeatureID == SketchPlugin_Projection::ID()) {
return FeaturePtr(new SketchPlugin_Projection);
} else if (theFeatureID == SketchPlugin_ConstraintCoincidence::ID()) {
return FeaturePtr(new SketchPlugin_MacroArc);
} else if (theFeatureID == SketchPlugin_MacroBSpline::ID()) {
return FeaturePtr(new SketchPlugin_MacroBSpline);
+ } else if (theFeatureID == SketchPlugin_MacroBSplinePeriodic::ID()) {
+ return FeaturePtr(new SketchPlugin_MacroBSplinePeriodic);
} else if (theFeatureID == SketchPlugin_MacroCircle::ID()) {
return FeaturePtr(new SketchPlugin_MacroCircle);
} else if (theFeatureID == SketchPlugin_Ellipse::ID()) {
aMsg->setState(SketchPlugin_Circle::ID(), aHasSketchPlane);
aMsg->setState(SketchPlugin_Arc::ID(), aHasSketchPlane);
aMsg->setState(SketchPlugin_BSpline::ID(), aHasSketchPlane);
+ aMsg->setState(SketchPlugin_BSplinePeriodic::ID(), aHasSketchPlane);
aMsg->setState(SketchPlugin_Ellipse::ID(), aHasSketchPlane);
aMsg->setState(SketchPlugin_EllipticArc::ID(), aHasSketchPlane);
aMsg->setState(SketchPlugin_Projection::ID(), aHasSketchPlane);
aMsg->setState(SketchPlugin_Trim::ID(), aHasSketchPlane);
aMsg->setState(SketchPlugin_MacroArc::ID(), aHasSketchPlane);
aMsg->setState(SketchPlugin_MacroBSpline::ID(), aHasSketchPlane);
+ aMsg->setState(SketchPlugin_MacroBSplinePeriodic::ID(), aHasSketchPlane);
aMsg->setState(SketchPlugin_MacroCircle::ID(), aHasSketchPlane);
aMsg->setState(SketchPlugin_MacroEllipse::ID(), aHasSketchPlane);
aMsg->setState(SketchPlugin_MacroEllipticArc::ID(), aHasSketchPlane);
nested="SketchPoint SketchIntersectionPoint SketchLine
SketchCircle SketchMacroCircle SketchArc SketchMacroArc
SketchEllipse SketchMacroEllipse SketchEllipticArc SketchMacroEllipticArc
- SketchBSpline SketchMacroBSpline
+ SketchBSpline SketchMacroBSpline SketchMacroBSplinePeriodic
SketchRectangle
SketchProjection
SketchConstraintLength SketchConstraintRadius SketchConstraintDistance SketchConstraintDistanceHorizontal SketchConstraintDistanceVertical
change_visual_attributes="true"/>
</feature>
+ <!-- SketchBSplinePeriodic is a hidden feature. It is created inside SketchMacroBSplinePeriodic. -->
+ <feature id="SketchBSplinePeriodic"
+ title="Periodic B-spline"
+ tooltip="Create periodic B-spline curve"
+ icon="icons/Sketch/bspline_p.png"
+ helpfile="bsplineFeature.html"
+ internal="1">
+ <bspline-panel id="poles"
+ weights="weights"
+ title="Poles and weights"
+ tooltip="B-spline poles and weights"
+ enable_value="enable_by_preferences">
+ <validator id="SketchPlugin_BSplineValidator"/>
+ </bspline-panel>
+ <boolvalue id="Auxiliary"
+ label="Auxiliary"
+ default="false"
+ tooltip="Construction element"
+ obligatory="0"
+ change_visual_attributes="true"/>
+ </feature>
+
<!-- SketchMacroBSpline -->
<feature id="SketchMacroBSpline"
title="B-spline"
obligatory="0"
change_visual_attributes="true"/>
</feature>
+
+ <!-- SketchMacroBSplinePeriodic -->
+ <feature id="SketchMacroBSplinePeriodic"
+ title="Periodic B-spline"
+ tooltip="Create periodic B-spline curve"
+ icon="icons/Sketch/bspline_p.png"
+ helpfile="bsplineFeature.html">
+ <sketch-bspline_selector id="poles"
+ weights="weights"
+ reference_attribute="poles_ref"
+ title="Poles and weights"
+ tooltip="B-spline poles and weights"
+ enable_value="enable_by_preferences">
+ <validator id="SketchPlugin_BSplineValidator"/>
+ </sketch-bspline_selector>
+ <boolvalue id="need_control_poly"
+ label="Create control polygon"
+ default="true"
+ tooltip="Specify if the control polygon should be created"/>
+ <boolvalue id="Auxiliary"
+ label="Auxiliary"
+ default="false"
+ tooltip="Construction element"
+ obligatory="0"
+ change_visual_attributes="true"/>
+ </feature>
</group>
<group id="Segmentation">
#include <ModelAPI_AttributeDoubleArray.h>
#include <ModelAPI_AttributeInteger.h>
#include <SketchPlugin_BSpline.h>
+#include <SketchPlugin_BSplinePeriodic.h>
#include <SketchPlugin_ConstraintAngle.h>
#include <SketchPlugin_MultiRotation.h>
(theAttribute->id() == SketchPlugin_MultiRotation::ANGLE_ID() &&
anOwner->getKind() == SketchPlugin_MultiRotation::ID()))
aWrapper = ScalarWrapperPtr(new PlaneGCSSolver_AngleWrapper(createParameter(theStorage)));
- else if (anOwner->getKind() == SketchPlugin_BSpline::ID() &&
- theAttribute->id() == SketchPlugin_BSpline::DEGREE_ID())
+ else if ((anOwner->getKind() == SketchPlugin_BSpline::ID() &&
+ theAttribute->id() == SketchPlugin_BSpline::DEGREE_ID()) ||
+ (anOwner->getKind() == SketchPlugin_BSplinePeriodic::ID() &&
+ theAttribute->id() == SketchPlugin_BSplinePeriodic::DEGREE_ID()))
// Degree of B-spline is not processed by the solver
aWrapper = ScalarWrapperPtr(new PlaneGCSSolver_ScalarWrapper(createParameter(nullptr)));
else
return aWrapper;
}
+template <typename TYPE>
+static bool nonSolverAttribute(const FeaturePtr theOwner, const std::string& theAttrId)
+{
+ return theOwner->getKind() == TYPE::ID() && (theAttrId == TYPE::WEIGHTS_ID()
+ || theAttrId == TYPE::KNOTS_ID() || theAttrId == TYPE::MULTS_ID());
+}
+
static EntityWrapperPtr createScalarArray(const AttributePtr& theAttribute,
PlaneGCSSolver_Storage* theStorage)
{
PlaneGCSSolver_Storage* aStorage = theStorage;
// Weights, knots and multiplicities of B-spline curve are not processed by the solver
FeaturePtr anOwner = ModelAPI_Feature::feature(theAttribute->owner());
- if (anOwner->getKind() == SketchPlugin_BSpline::ID() &&
- (theAttribute->id() == SketchPlugin_BSpline::WEIGHTS_ID() ||
- theAttribute->id() == SketchPlugin_BSpline::KNOTS_ID() ||
- theAttribute->id() == SketchPlugin_BSpline::MULTS_ID()))
+ if (nonSolverAttribute<SketchPlugin_BSpline>(anOwner, theAttribute->id()) ||
+ nonSolverAttribute<SketchPlugin_BSplinePeriodic>(anOwner, theAttribute->id()))
aStorage = 0;
int aSize = anArray.size();
#include <SketchPlugin_Arc.h>
#include <SketchPlugin_BSpline.h>
+#include <SketchPlugin_BSplinePeriodic.h>
#include <SketchPlugin_Circle.h>
#include <SketchPlugin_Ellipse.h>
#include <SketchPlugin_EllipticArc.h>
static EntityWrapperPtr createEllipse(const AttributeEntityMap& theAttributes);
static EntityWrapperPtr createEllipticArc(const AttributeEntityMap& theAttributes,
PlaneGCSSolver_Storage* theStorage);
+template <typename TYPE>
static EntityWrapperPtr createBSpline(const AttributeEntityMap& theAttributes);
aResult = createEllipticArc(myAttributes, myStorage);
// B-spline curve
else if (aFeatureKind == SketchPlugin_BSpline::ID())
- aResult = createBSpline(myAttributes);
+ aResult = createBSpline<SketchPlugin_BSpline>(myAttributes);
+ else if (aFeatureKind == SketchPlugin_BSplinePeriodic::ID())
+ aResult = createBSpline<SketchPlugin_BSplinePeriodic>(myAttributes);
// Point (it has low probability to be an attribute of constraint, so it is checked at the end)
else if (aFeatureKind == SketchPlugin_Point::ID() ||
aFeatureKind == SketchPlugin_IntersectionPoint::ID()) {
return anEllipseWrapper;
}
+template <typename TYPE>
EntityWrapperPtr createBSpline(const AttributeEntityMap& theAttributes)
{
std::shared_ptr<GCS::BSplineImpl> aNewSpline(new GCS::BSplineImpl);
aNewSpline->degree = 3;
- aNewSpline->periodic = false;
+ aNewSpline->periodic = std::is_same<TYPE, SketchPlugin_BSplinePeriodic>();
std::map<std::string, EntityWrapperPtr> anAdditionalAttributes;
AttributeEntityMap::const_iterator anIt = theAttributes.begin();
for (; anIt != theAttributes.end(); ++anIt) {
const std::string& anAttrID = anIt->first->id();
- if (anAttrID == SketchPlugin_BSpline::POLES_ID()) {
+ if (anAttrID == TYPE::POLES_ID()) {
PointArrayWrapperPtr anArray =
std::dynamic_pointer_cast<PlaneGCSSolver_PointArrayWrapper>(anIt->second);
aNewSpline->start = aNewSpline->poles.front();
aNewSpline->end = aNewSpline->poles.back();
}
- else if (anAttrID == SketchPlugin_BSpline::DEGREE_ID()) {
+ else if (anAttrID == TYPE::DEGREE_ID()) {
ScalarWrapperPtr aScalar =
std::dynamic_pointer_cast<PlaneGCSSolver_ScalarWrapper>(anIt->second);
aNewSpline->degree = (int)aScalar->value();
else {
ScalarArrayWrapperPtr anArray =
std::dynamic_pointer_cast<PlaneGCSSolver_ScalarArrayWrapper>(anIt->second);
- if (anAttrID == SketchPlugin_BSpline::WEIGHTS_ID())
+ if (anAttrID == TYPE::WEIGHTS_ID())
aNewSpline->weights = anArray->array();
- else if (anAttrID == SketchPlugin_BSpline::KNOTS_ID())
+ else if (anAttrID == TYPE::KNOTS_ID())
aNewSpline->knots = anArray->array();
- else if (anAttrID == SketchPlugin_BSpline::MULTS_ID()) {
+ else if (anAttrID == TYPE::MULTS_ID()) {
const GCS::VEC_pD& aValues = anArray->array();
aNewSpline->mult.reserve(aValues.size());
for (GCS::VEC_pD::const_iterator anIt = aValues.begin(); anIt != aValues.end(); ++anIt)
EdgeWrapperPtr anEdge = std::dynamic_pointer_cast<PlaneGCSSolver_EdgeWrapper>(theCurve);
std::shared_ptr<GCS::BSpline> aBSpline =
std::dynamic_pointer_cast<GCS::BSpline>(anEdge->entity());
+ if (aBSpline->periodic)
+ return; // additional constraints are not necessary
std::list<GCSConstraintPtr> aBSplineConstraints;
#include <SketchPlugin_Arc.h>
#include <SketchPlugin_BSpline.h>
+#include <SketchPlugin_BSplinePeriodic.h>
#include <SketchPlugin_Circle.h>
#include <SketchPlugin_ConstraintAngle.h>
#include <SketchPlugin_ConstraintCoincidence.h>
theAttrName == SketchPlugin_BSpline::START_ID() ||
theAttrName == SketchPlugin_BSpline::END_ID();
}
+ else if (theOwnerName == SketchPlugin_BSplinePeriodic::ID()) {
+ return theAttrName == SketchPlugin_BSplinePeriodic::POLES_ID() ||
+ theAttrName == SketchPlugin_BSplinePeriodic::WEIGHTS_ID() ||
+ theAttrName == SketchPlugin_BSplinePeriodic::KNOTS_ID() ||
+ theAttrName == SketchPlugin_BSplinePeriodic::MULTS_ID() ||
+ theAttrName == SketchPlugin_BSplinePeriodic::DEGREE_ID();
+ }
// suppose that all remaining features are points
return theAttrName == SketchPlugin_Point::COORD_ID();