X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FSketchPlugin%2FSketchPlugin_BSpline.cpp;h=1772ecb639ecd342d3701d80254017e1307c8334;hb=cdbbde4803e9c320204d537d22af4ac7ef024962;hp=e8e84177d5480547fde7db0e3f2003408c9331d7;hpb=52b602cebc1184e09d86608510b0f14aff5d1d4b;p=modules%2Fshaper.git diff --git a/src/SketchPlugin/SketchPlugin_BSpline.cpp b/src/SketchPlugin/SketchPlugin_BSpline.cpp index e8e84177d..1772ecb63 100644 --- a/src/SketchPlugin/SketchPlugin_BSpline.cpp +++ b/src/SketchPlugin/SketchPlugin_BSpline.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2019-2020 CEA/DEN, EDF R&D +// Copyright (C) 2019-2021 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 @@ -18,25 +18,13 @@ // #include -#include - -#include - -#include #include #include -#include -#include -#include -#include -#include -#include - SketchPlugin_BSpline::SketchPlugin_BSpline() - : SketchPlugin_SketchEntity() + : SketchPlugin_BSplineBase() { } @@ -45,116 +33,18 @@ void SketchPlugin_BSpline::initDerivedClassAttributes() data()->addAttribute(START_ID(), GeomDataAPI_Point2D::typeId()); data()->addAttribute(END_ID(), GeomDataAPI_Point2D::typeId()); - 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_BSpline::execute() -{ - SketchPlugin_Sketch* aSketch = sketch(); - if(!aSketch) { - return; - } - - AttributePoint2DArrayPtr aPolesArray = - std::dynamic_pointer_cast(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 aPoles2D; - for (int anIndex = 0; anIndex < aPolesArray->size(); ++anIndex) { - GeomPnt2dPtr aPole = aPolesArray->pnt(anIndex); - aPoles2D.push_back(aPole); - } - // collect weights - std::list aWeights; - for (int anIndex = 0; anIndex < aWeightsArray->size(); ++anIndex) - aWeights.push_back(aWeightsArray->value(anIndex)); - // collect knots - std::list aKnots; - for (int anIndex = 0; anIndex < aKnotsArray->size(); ++anIndex) - aKnots.push_back(aKnotsArray->value(anIndex)); - // collect multiplicities - std::list 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(), false); - - ResultConstructionPtr aResult = document()->createConstruction(data(), 0); - aResult->setShape(anEdge); - aResult->setIsInHistory(false); - setResult(aResult, 0); -} - -bool SketchPlugin_BSpline::isFixed() { - return data()->selection(EXTERNAL_ID())->context().get() != NULL; + SketchPlugin_BSplineBase::initDerivedClassAttributes(); } void SketchPlugin_BSpline::attributeChanged(const std::string& theID) { - // the second condition for unability to move external segments anywhere - if (theID == EXTERNAL_ID() || isFixed()) { - std::shared_ptr 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 anEdge(new GeomAPI_Edge(aSelection)); -//// std::shared_ptr anEllipse = anEdge->ellipse(); -//// -//// bool aWasBlocked = data()->blockSendAttributeUpdated(true); -//// std::shared_ptr aCenterAttr = -//// std::dynamic_pointer_cast(attribute(CENTER_ID())); -//// aCenterAttr->setValue(sketch()->to2D(anEllipse->center())); -//// -//// std::shared_ptr aFocusAttr = -//// std::dynamic_pointer_cast(attribute(FIRST_FOCUS_ID())); -//// aFocusAttr->setValue(sketch()->to2D(anEllipse->firstFocus())); -//// -//// std::shared_ptr aStartAttr = -//// std::dynamic_pointer_cast(attribute(START_POINT_ID())); -//// aStartAttr->setValue(sketch()->to2D(anEdge->firstPoint())); -//// -//// std::shared_ptr aEndAttr = -//// std::dynamic_pointer_cast(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(); -//// } + if (theID == POLES_ID()) { + AttributePoint2DArrayPtr aPolesArray = + std::dynamic_pointer_cast(attribute(POLES_ID())); + std::dynamic_pointer_cast( + attribute(START_ID()))->setValue(aPolesArray->pnt(0)); + std::dynamic_pointer_cast( + attribute(END_ID()))->setValue(aPolesArray->pnt(aPolesArray->size() - 1)); } -//// else if (theID == CENTER_ID() || theID == FIRST_FOCUS_ID() || -//// theID == START_POINT_ID() || theID == END_POINT_ID()) -//// fillCharacteristicPoints(); -//// else if (theID == REVERSED_ID() && myParamDelta == 0.0) -//// myParamDelta = 2.0 * PI; + else + SketchPlugin_BSplineBase::attributeChanged(theID); }