X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchSolver%2FPlaneGCSSolver%2FPlaneGCSSolver_Tools.cpp;h=ab382114e65799f92e7002d125de1ee7dc11df1f;hb=06e7f5859095193fc7f498bd89a7d28009794f53;hp=35cbb4d722daca0db3431ee468d7bd03919e922f;hpb=f5086eebab1d538a0e8b2b655ed6729fcba0da86;p=modules%2Fshaper.git diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Tools.cpp b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Tools.cpp index 35cbb4d72..ab382114e 100644 --- a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Tools.cpp +++ b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Tools.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2019 CEA/DEN, EDF R&D +// Copyright (C) 2014-2023 CEA, EDF // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -19,7 +19,9 @@ #include #include +#include #include +#include #include #include @@ -34,10 +36,16 @@ #include #include #include +#include #include #include #include +#include +#include +#include +#include +#include #include #include #include @@ -49,17 +57,26 @@ #include #include #include +#include #include +#include +#include #include #include #include +#include +#include +#include #include #include #include #include #include +#include +#include + #include @@ -75,7 +92,12 @@ static ConstraintWrapperPtr static ConstraintWrapperPtr createConstraintPointOnEntity(const SketchSolver_ConstraintType& theType, std::shared_ptr thePoint, - std::shared_ptr theEntity); + std::shared_ptr theEntity, + std::shared_ptr theValue); +static ConstraintWrapperPtr + createConstraintPointsCollinear(std::shared_ptr thePoint1, + std::shared_ptr thePoint2, + std::shared_ptr thePoint3); static ConstraintWrapperPtr createConstraintDistancePointPoint(std::shared_ptr theValue, std::shared_ptr thePoint1, @@ -115,17 +137,22 @@ static ConstraintWrapperPtr createConstraintMiddlePoint(std::shared_ptr thePoint, std::shared_ptr theEntity, std::shared_ptr theAuxParameters); +static ConstraintWrapperPtr + createConstraintAngleBetweenCurves(std::shared_ptr theValue, + std::shared_ptr thePoint, + std::shared_ptr theEntity1, + std::shared_ptr theEntity2); static GCS::SET_pD scalarParameters(const ScalarWrapperPtr& theScalar); +static GCS::SET_pD scalarArrayParameters(const EntityWrapperPtr& theArray); static GCS::SET_pD pointParameters(const PointWrapperPtr& thePoint); +static GCS::SET_pD pointArrayParameters(const EntityWrapperPtr& theArray); static GCS::SET_pD lineParameters(const EdgeWrapperPtr& theLine); static GCS::SET_pD circleParameters(const EdgeWrapperPtr& theCircle); static GCS::SET_pD arcParameters(const EdgeWrapperPtr& theArc); static GCS::SET_pD ellipseParameters(const EdgeWrapperPtr& theEllipse); static GCS::SET_pD ellipticArcParameters(const EdgeWrapperPtr& theEllipticArc); - -static double distance(const GCS::Point& thePnt1, const GCS::Point& thePnt2); - +static GCS::SET_pD bsplineParameters(const EdgeWrapperPtr& theEdge); @@ -159,6 +186,10 @@ SolverConstraintPtr PlaneGCSSolver_Tools::createConstraint(ConstraintPtr theCons return SolverConstraintPtr(new SketchSolver_ConstraintMultiRotation(theConstraint)); } else if (theConstraint->getKind() == SketchPlugin_ConstraintAngle::ID()) { return SolverConstraintPtr(new SketchSolver_ConstraintAngle(theConstraint)); + } else if (theConstraint->getKind() == SketchPlugin_ConstraintPerpendicular::ID()) { + return SolverConstraintPtr(new SketchSolver_ConstraintPerpendicular(theConstraint)); + } else if (theConstraint->getKind() == SketchPlugin_Offset::ID()) { + return SolverConstraintPtr(new SketchSolver_ConstraintOffset(theConstraint)); } // All other types of constraints return SolverConstraintPtr(new SketchSolver_Constraint(theConstraint)); @@ -178,6 +209,13 @@ std::shared_ptr PlaneGCSSolver_Tools::createMov new SketchSolver_ConstraintMovement(theMovedAttribute)); } +std::shared_ptr PlaneGCSSolver_Tools::createMovementConstraint( + const std::pair& theMovedPointInArray) +{ + return std::shared_ptr( + new SketchSolver_ConstraintMovement(theMovedPointInArray.first, theMovedPointInArray.second)); +} + ConstraintWrapperPtr PlaneGCSSolver_Tools::createConstraint( @@ -194,13 +232,16 @@ ConstraintWrapperPtr PlaneGCSSolver_Tools::createConstraint( std::shared_ptr aPoint1 = GCS_POINT_WRAPPER(thePoint1); std::shared_ptr aPoint2 = GCS_POINT_WRAPPER(thePoint2); + std::shared_ptr anEntity1 = GCS_EDGE_WRAPPER(theEntity1); switch (theType) { case CONSTRAINT_PT_PT_COINCIDENT: aResult = createConstraintCoincidence(aPoint1, aPoint2); break; case CONSTRAINT_PT_ON_CURVE: - aResult = createConstraintPointOnEntity(theType, aPoint1, GCS_EDGE_WRAPPER(theEntity1)); + aResult = anEntity1 ? + createConstraintPointOnEntity(theType, aPoint1, anEntity1, GCS_SCALAR_WRAPPER(theValue)) : + createConstraintPointsCollinear(aPoint1, aPoint2, GCS_POINT_WRAPPER(theEntity1)); break; case CONSTRAINT_MIDDLE_POINT: aResult = createConstraintMiddlePoint(aPoint1, GCS_EDGE_WRAPPER(theEntity1), aPoint2); @@ -211,34 +252,35 @@ ConstraintWrapperPtr PlaneGCSSolver_Tools::createConstraint( case CONSTRAINT_PT_LINE_DISTANCE: aResult = createConstraintDistancePointLine(GCS_SCALAR_WRAPPER(theValue), aPoint1, - GCS_EDGE_WRAPPER(theEntity1)); + anEntity1); break; case CONSTRAINT_HORIZONTAL_DISTANCE: case CONSTRAINT_VERTICAL_DISTANCE: aResult = createConstraintHVDistance(theType, GCS_SCALAR_WRAPPER(theValue), aPoint1, aPoint2); break; case CONSTRAINT_RADIUS: - aResult = createConstraintRadius(GCS_SCALAR_WRAPPER(theValue), - GCS_EDGE_WRAPPER(theEntity1)); + aResult = createConstraintRadius(GCS_SCALAR_WRAPPER(theValue), anEntity1); break; case CONSTRAINT_ANGLE: aResult = createConstraintAngle(theConstraint, GCS_SCALAR_WRAPPER(theValue), - GCS_EDGE_WRAPPER(theEntity1), GCS_EDGE_WRAPPER(theEntity2)); + anEntity1, GCS_EDGE_WRAPPER(theEntity2)); break; case CONSTRAINT_FIXED: break; case CONSTRAINT_HORIZONTAL: case CONSTRAINT_VERTICAL: - aResult = createConstraintHorizVert(theType, GCS_EDGE_WRAPPER(theEntity1)); + aResult = createConstraintHorizVert(theType, anEntity1); break; case CONSTRAINT_PARALLEL: - aResult = createConstraintParallel(GCS_EDGE_WRAPPER(theEntity1), - GCS_EDGE_WRAPPER(theEntity2)); + aResult = createConstraintParallel(anEntity1, GCS_EDGE_WRAPPER(theEntity2)); break; case CONSTRAINT_PERPENDICULAR: - aResult = createConstraintPerpendicular(GCS_EDGE_WRAPPER(theEntity1), - GCS_EDGE_WRAPPER(theEntity2)); + aResult = createConstraintPerpendicular(anEntity1, GCS_EDGE_WRAPPER(theEntity2)); + break; + case CONSTRAINT_PERPENDICULAR_CURVES: + aResult = createConstraintAngleBetweenCurves(GCS_SCALAR_WRAPPER(theValue), + aPoint1, anEntity1, GCS_EDGE_WRAPPER(theEntity2)); break; case CONSTRAINT_EQUAL_LINES: case CONSTRAINT_EQUAL_ELLIPSES: @@ -246,7 +288,7 @@ ConstraintWrapperPtr PlaneGCSSolver_Tools::createConstraint( case CONSTRAINT_EQUAL_LINE_ARC: case CONSTRAINT_EQUAL_RADIUS: aResult = createConstraintEqual(theType, - GCS_EDGE_WRAPPER(theEntity1), + anEntity1, GCS_EDGE_WRAPPER(theEntity2), anIntermediate); break; @@ -325,6 +367,37 @@ std::shared_ptr PlaneGCSSolver_Tools::ellipse(EntityWrapperPt new GeomAPI_Ellipse2d(aCenter, anAxis, anEllipse->getRadMaj(), *anEllipse->radmin)); } +std::shared_ptr PlaneGCSSolver_Tools::bspline(EntityWrapperPtr theEntity) +{ + if (theEntity->type() != ENTITY_BSPLINE) + return std::shared_ptr(); + + std::shared_ptr anEntity = + std::dynamic_pointer_cast(theEntity); + std::shared_ptr aSpline = + std::dynamic_pointer_cast(anEntity->entity()); + + std::list aPoles; + for (GCS::VEC_P::iterator anIt = aSpline->poles.begin(); anIt != aSpline->poles.end(); ++anIt) + aPoles.push_back(GeomPnt2dPtr(new GeomAPI_Pnt2d(*anIt->x, *anIt->y))); + + std::list aWeights; + for (GCS::VEC_pD::iterator anIt = aSpline->weights.begin(); + anIt != aSpline->weights.end(); ++anIt) + aWeights.push_back(**anIt); + + std::list aKnots; + for (GCS::VEC_pD::iterator anIt = aSpline->knots.begin(); anIt != aSpline->knots.end(); ++anIt) + aKnots.push_back(**anIt); + + std::list aMultiplicities; + aMultiplicities.assign(aSpline->mult.begin(), aSpline->mult.end()); + + return std::shared_ptr( + new GeomAPI_BSpline2d(aSpline->degree, aPoles, aWeights, + aKnots, aMultiplicities, aSpline->periodic)); +} + void PlaneGCSSolver_Tools::recalculateArcParameters(EntityWrapperPtr theArc) { std::shared_ptr anEdge = @@ -373,8 +446,12 @@ GCS::SET_pD PlaneGCSSolver_Tools::parameters(const EntityWrapperPtr& theEntity) case ENTITY_SCALAR: case ENTITY_ANGLE: return scalarParameters(GCS_SCALAR_WRAPPER(theEntity)); + case ENTITY_SCALAR_ARRAY: + return scalarArrayParameters(theEntity); case ENTITY_POINT: return pointParameters(GCS_POINT_WRAPPER(theEntity)); + case ENTITY_POINT_ARRAY: + return pointArrayParameters(theEntity); case ENTITY_LINE: return lineParameters(GCS_EDGE_WRAPPER(theEntity)); case ENTITY_CIRCLE: @@ -385,11 +462,119 @@ GCS::SET_pD PlaneGCSSolver_Tools::parameters(const EntityWrapperPtr& theEntity) return ellipseParameters(GCS_EDGE_WRAPPER(theEntity)); case ENTITY_ELLIPTIC_ARC: return ellipticArcParameters(GCS_EDGE_WRAPPER(theEntity)); + case ENTITY_BSPLINE: + return bsplineParameters(GCS_EDGE_WRAPPER(theEntity)); default: break; } return GCS::SET_pD(); } +bool PlaneGCSSolver_Tools::isAttributeApplicable(const std::string& theAttrName, + const std::string& theOwnerName) +{ + if (theOwnerName == SketchPlugin_Arc::ID()) { + return theAttrName == SketchPlugin_Arc::CENTER_ID() || + theAttrName == SketchPlugin_Arc::START_ID() || + theAttrName == SketchPlugin_Arc::END_ID() || + theAttrName == SketchPlugin_Arc::REVERSED_ID(); + } + else if (theOwnerName == SketchPlugin_Circle::ID()) { + return theAttrName == SketchPlugin_Circle::CENTER_ID() || + theAttrName == SketchPlugin_Circle::RADIUS_ID(); + } + else if (theOwnerName == SketchPlugin_Line::ID()) { + return theAttrName == SketchPlugin_Line::START_ID() || + theAttrName == SketchPlugin_Line::END_ID(); + } + else if (theOwnerName == SketchPlugin_Ellipse::ID()) { + return theAttrName == SketchPlugin_Ellipse::CENTER_ID() || + theAttrName == SketchPlugin_Ellipse::FIRST_FOCUS_ID() || + theAttrName == SketchPlugin_Ellipse::SECOND_FOCUS_ID() || + theAttrName == SketchPlugin_Ellipse::MAJOR_AXIS_START_ID() || + theAttrName == SketchPlugin_Ellipse::MAJOR_AXIS_END_ID() || + theAttrName == SketchPlugin_Ellipse::MINOR_AXIS_START_ID() || + theAttrName == SketchPlugin_Ellipse::MINOR_AXIS_END_ID() || + theAttrName == SketchPlugin_Ellipse::MAJOR_RADIUS_ID() || + theAttrName == SketchPlugin_Ellipse::MINOR_RADIUS_ID(); + } + else if (theOwnerName == SketchPlugin_EllipticArc::ID()) { + return theAttrName == SketchPlugin_EllipticArc::CENTER_ID() || + theAttrName == SketchPlugin_EllipticArc::FIRST_FOCUS_ID() || + theAttrName == SketchPlugin_EllipticArc::SECOND_FOCUS_ID() || + theAttrName == SketchPlugin_EllipticArc::MAJOR_AXIS_START_ID() || + theAttrName == SketchPlugin_EllipticArc::MAJOR_AXIS_END_ID() || + theAttrName == SketchPlugin_EllipticArc::MINOR_AXIS_START_ID() || + theAttrName == SketchPlugin_EllipticArc::MINOR_AXIS_END_ID() || + theAttrName == SketchPlugin_EllipticArc::MAJOR_RADIUS_ID() || + theAttrName == SketchPlugin_EllipticArc::MINOR_RADIUS_ID() || + theAttrName == SketchPlugin_EllipticArc::START_POINT_ID() || + theAttrName == SketchPlugin_EllipticArc::END_POINT_ID() || + theAttrName == SketchPlugin_EllipticArc::REVERSED_ID(); + } + else if (theOwnerName == SketchPlugin_BSpline::ID()) { + return theAttrName == SketchPlugin_BSpline::POLES_ID() || + theAttrName == SketchPlugin_BSpline::WEIGHTS_ID() || + theAttrName == SketchPlugin_BSpline::KNOTS_ID() || + theAttrName == SketchPlugin_BSpline::MULTS_ID() || + theAttrName == SketchPlugin_BSpline::DEGREE_ID() || + 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(); +} + +/// \brief Update value +bool PlaneGCSSolver_Tools::updateValue(const double& theSource, double& theDest, + const double theTolerance) +{ + bool isUpdated = fabs(theSource - theDest) > theTolerance; + if (isUpdated) + theDest = theSource; + return isUpdated; +} + + +double PlaneGCSSolver_Tools::distance(const GCS::Point& thePnt1, const GCS::Point& thePnt2) +{ + double x = *thePnt1.x - *thePnt2.x; + double y = *thePnt1.y - *thePnt2.y; + return sqrt(x*x + y*y); +} + + + + +// ================ AttributeArray methods ========================== +PlaneGCSSolver_Tools::AttributeArray::AttributeArray(AttributePtr theAttribute) +{ + myDouble = std::dynamic_pointer_cast(theAttribute); + myInteger = std::dynamic_pointer_cast(theAttribute); +} + +bool PlaneGCSSolver_Tools::AttributeArray::isInitialized() const +{ + return (myDouble && myDouble->isInitialized()) || (myInteger && myInteger->isInitialized()); +} + +int PlaneGCSSolver_Tools::AttributeArray::size() const +{ + return myDouble.get() ? myDouble->size() : myInteger->size(); +} + +double PlaneGCSSolver_Tools::AttributeArray::value(const int theIndex) const +{ + return myDouble.get() ? myDouble->value(theIndex) : myInteger->value(theIndex); +} + @@ -417,7 +602,8 @@ ConstraintWrapperPtr createConstraintCoincidence( ConstraintWrapperPtr createConstraintPointOnEntity( const SketchSolver_ConstraintType& theType, std::shared_ptr thePoint, - std::shared_ptr theEntity) + std::shared_ptr theEntity, + std::shared_ptr theValue) { GCSConstraintPtr aNewConstr; @@ -443,6 +629,14 @@ ConstraintWrapperPtr createConstraintPointOnEntity( new GCS::ConstraintPointOnEllipse(*(thePoint->point()), *anEllipse)); break; } + case ENTITY_BSPLINE: { + std::list aConstraints; + aConstraints.push_back(GCSConstraintPtr(new GCS::ConstraintCurveValue( + *thePoint->point(), thePoint->point()->x, *theEntity->entity(), theValue->scalar()))); + aConstraints.push_back(GCSConstraintPtr(new GCS::ConstraintCurveValue( + *thePoint->point(), thePoint->point()->y, *theEntity->entity(), theValue->scalar()))); + return ConstraintWrapperPtr(new PlaneGCSSolver_ConstraintWrapper(aConstraints, theType)); + } default: return ConstraintWrapperPtr(); } @@ -450,6 +644,38 @@ ConstraintWrapperPtr createConstraintPointOnEntity( return ConstraintWrapperPtr(new PlaneGCSSolver_ConstraintWrapper(aNewConstr, theType)); } +ConstraintWrapperPtr createConstraintPointsCollinear( + std::shared_ptr thePoint1, + std::shared_ptr thePoint2, + std::shared_ptr thePoint3) +{ + GCSConstraintPtr aNewConstr(new GCS::ConstraintPointOnLine( + *(thePoint1->point()), *(thePoint2->point()), *(thePoint3->point()))); + return ConstraintWrapperPtr( + new PlaneGCSSolver_ConstraintWrapper(aNewConstr, CONSTRAINT_PT_ON_CURVE)); +} + +template +void createConstraintMiddlePointOnArc(ARCTYPE theArc, + GCSPointPtr thePoint, + std::shared_ptr theAuxParameters, + std::list& theConstraints) +{ + double* u = theAuxParameters->point()->x; + double* diff = theAuxParameters->point()->y; + *u = (*theArc->startAngle + *theArc->endAngle) * 0.5; + *diff = (*theArc->endAngle - *theArc->startAngle) * 0.5; + + theConstraints.push_back(GCSConstraintPtr( + new GCS::ConstraintCurveValue(*thePoint, thePoint->x, *theArc, u))); + theConstraints.push_back(GCSConstraintPtr( + new GCS::ConstraintCurveValue(*thePoint, thePoint->y, *theArc, u))); + theConstraints.push_back(GCSConstraintPtr( + new GCS::ConstraintDifference(theArc->startAngle, u, diff))); + theConstraints.push_back(GCSConstraintPtr( + new GCS::ConstraintDifference(u, theArc->endAngle, diff))); +} + ConstraintWrapperPtr createConstraintMiddlePoint( std::shared_ptr thePoint, std::shared_ptr theEntity, @@ -466,20 +692,13 @@ ConstraintWrapperPtr createConstraintMiddlePoint( } else { std::shared_ptr anArc = std::dynamic_pointer_cast(theEntity->entity()); - if (anArc) { - double* u = theAuxParameters->point()->x; - double* diff = theAuxParameters->point()->y; - *u = (*anArc->startAngle + *anArc->endAngle) * 0.5; - *diff = (*anArc->endAngle - *anArc->startAngle) * 0.5; - - aConstrList.push_back(GCSConstraintPtr( - new GCS::ConstraintCurveValue(*aPoint, aPoint->x, *anArc, u))); - aConstrList.push_back(GCSConstraintPtr( - new GCS::ConstraintCurveValue(*aPoint, aPoint->y, *anArc, u))); - aConstrList.push_back(GCSConstraintPtr( - new GCS::ConstraintDifference(anArc->startAngle, u, diff))); - aConstrList.push_back(GCSConstraintPtr( - new GCS::ConstraintDifference(u, anArc->endAngle, diff))); + if (anArc) + createConstraintMiddlePointOnArc(anArc, aPoint, theAuxParameters, aConstrList); + else { + std::shared_ptr aEllArc = + std::dynamic_pointer_cast(theEntity->entity()); + if (aEllArc) + createConstraintMiddlePointOnArc(aEllArc, aPoint, theAuxParameters, aConstrList); } } @@ -561,19 +780,10 @@ ConstraintWrapperPtr createConstraintAngle( std::shared_ptr theEntity2) { std::shared_ptr aLine1 = std::dynamic_pointer_cast(theEntity1->entity()); - bool isLine1Rev = theConstraint->boolean( - SketchPlugin_ConstraintAngle::ANGLE_REVERSED_FIRST_LINE_ID())->value(); - GCS::Point aLine1Pt1 = isLine1Rev ? aLine1->p2 : aLine1->p1; - GCS::Point aLine1Pt2 = isLine1Rev ? aLine1->p1 : aLine1->p2; - std::shared_ptr aLine2 = std::dynamic_pointer_cast(theEntity2->entity()); - bool isLine2Rev = theConstraint->boolean( - SketchPlugin_ConstraintAngle::ANGLE_REVERSED_SECOND_LINE_ID())->value(); - GCS::Point aLine2Pt1 = isLine2Rev ? aLine2->p2 : aLine2->p1; - GCS::Point aLine2Pt2 = isLine2Rev ? aLine2->p1 : aLine2->p2; GCSConstraintPtr aNewConstr(new GCS::ConstraintL2LAngle( - aLine1Pt1, aLine1Pt2, aLine2Pt1, aLine2Pt2, theValue->scalar())); + aLine1->p1, aLine1->p2, aLine2->p1, aLine2->p2, theValue->scalar())); std::shared_ptr aResult( new PlaneGCSSolver_ConstraintWrapper(aNewConstr, CONSTRAINT_ANGLE)); @@ -635,6 +845,18 @@ ConstraintWrapperPtr createConstraintPerpendicular( new PlaneGCSSolver_ConstraintWrapper(aNewConstr, CONSTRAINT_PERPENDICULAR)); } +ConstraintWrapperPtr createConstraintAngleBetweenCurves( + std::shared_ptr theValue, + std::shared_ptr thePoint, + std::shared_ptr theEntity1, + std::shared_ptr theEntity2) +{ + GCSConstraintPtr aNewConstr(new GCS::ConstraintAngleViaPoint( + *theEntity1->entity(), *theEntity2->entity(), *thePoint->point(), theValue->scalar())); + return ConstraintWrapperPtr( + new PlaneGCSSolver_ConstraintWrapper(aNewConstr, CONSTRAINT_PERPENDICULAR_CURVES)); +} + ConstraintWrapperPtr createConstraintEqual( const SketchSolver_ConstraintType& theType, std::shared_ptr theEntity1, @@ -654,7 +876,7 @@ ConstraintWrapperPtr createConstraintEqual( aConstrList.push_back(GCSConstraintPtr( new GCS::ConstraintP2PDistance(aLine2->p1, aLine2->p2, theIntermed->scalar()))); // update value of intermediate parameter - theIntermed->setValue(distance(aLine1->p1, aLine1->p2)); + theIntermed->setValue(PlaneGCSSolver_Tools::distance(aLine1->p1, aLine1->p2)); } else if (theType == CONSTRAINT_EQUAL_ELLIPSES) { std::shared_ptr anEllipse1 = @@ -669,7 +891,7 @@ ConstraintWrapperPtr createConstraintEqual( aConstrList.push_back(GCSConstraintPtr(new GCS::ConstraintP2PDistance( anEllipse2->center, anEllipse2->focus1, theIntermed->scalar()))); // update value of intermediate parameter - theIntermed->setValue(distance(anEllipse1->center, anEllipse1->focus1)); + theIntermed->setValue(PlaneGCSSolver_Tools::distance(anEllipse1->center, anEllipse1->focus1)); } else { std::shared_ptr aCirc1 = @@ -693,6 +915,13 @@ GCS::SET_pD scalarParameters(const ScalarWrapperPtr& theScalar) return aParams; } +GCS::SET_pD scalarArrayParameters(const EntityWrapperPtr& theArray) +{ + ScalarArrayWrapperPtr anArray = + std::dynamic_pointer_cast(theArray); + return GCS::SET_pD(anArray->array().begin(), anArray->array().end()); +} + GCS::SET_pD pointParameters(const PointWrapperPtr& thePoint) { GCS::SET_pD aParams; @@ -701,6 +930,19 @@ GCS::SET_pD pointParameters(const PointWrapperPtr& thePoint) return aParams; } +GCS::SET_pD pointArrayParameters(const EntityWrapperPtr& theArray) +{ + GCS::SET_pD aParams; + PointArrayWrapperPtr aPoints = + std::dynamic_pointer_cast(theArray); + for (std::vector::const_iterator anIt = aPoints->array().begin(); + anIt != aPoints->array().end(); ++anIt) { + GCS::SET_pD aPointParams = PlaneGCSSolver_Tools::parameters(*anIt); + aParams.insert(aPointParams.begin(), aPointParams.end()); + } + return aParams; +} + GCS::SET_pD lineParameters(const EdgeWrapperPtr& theLine) { GCS::SET_pD aParams; @@ -762,9 +1004,19 @@ GCS::SET_pD ellipticArcParameters(const EdgeWrapperPtr& theEllipticArc) return aParams; } -double distance(const GCS::Point& thePnt1, const GCS::Point& thePnt2) +GCS::SET_pD bsplineParameters(const EdgeWrapperPtr& theEdge) { - double x = *thePnt1.x - *thePnt2.x; - double y = *thePnt1.y - *thePnt2.y; - return sqrt(x*x + y*y); + GCS::SET_pD aParams; + + std::shared_ptr aBSpline = + std::dynamic_pointer_cast(theEdge->entity()); + + for (GCS::VEC_P::iterator it = aBSpline->poles.begin(); it != aBSpline->poles.end(); ++it) { + aParams.insert(it->x); + aParams.insert(it->y); + } + for (GCS::VEC_pD::iterator it = aBSpline->weights.begin(); it != aBSpline->weights.end(); ++it) + aParams.insert(*it); + + return aParams; }