X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchSolver%2FSketchSolver_ConstraintMultiRotation.cpp;h=fba148a7ae0f015dae4258fae73ebb465979af88;hb=6b48364b1da91a4958ce92d392e8bc49a3cbd7a2;hp=2a91c6285cf281479c864bea6bd7e0406e407923;hpb=42394362cfec9b39f7def70c83e99c77a48fdfe5;p=modules%2Fshaper.git diff --git a/src/SketchSolver/SketchSolver_ConstraintMultiRotation.cpp b/src/SketchSolver/SketchSolver_ConstraintMultiRotation.cpp index 2a91c6285..fba148a7a 100644 --- a/src/SketchSolver/SketchSolver_ConstraintMultiRotation.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintMultiRotation.cpp @@ -1,4 +1,22 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D +// Copyright (C) 2014-2017 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 #include @@ -16,12 +34,13 @@ #include void SketchSolver_ConstraintMultiRotation::getAttributes( - EntityWrapperPtr& theCenter, EntityWrapperPtr& theAngle, - bool& theFullValue, std::list& theEntities) + EntityWrapperPtr& theCenter, ScalarWrapperPtr& theAngle, + bool& theFullValue, bool& theReversed, std::list& theEntities) { AttributePtr anAngleAttr = myBaseConstraint->attribute(SketchPlugin_MultiRotation::ANGLE_ID()); PlaneGCSSolver_AttributeBuilder aValueBuilder; - theAngle = aValueBuilder.createAttribute(anAngleAttr); + theAngle = std::dynamic_pointer_cast( + aValueBuilder.createAttribute(anAngleAttr)); myStorage->addEntity(anAngleAttr, theAngle); AttributeRefAttrPtr aCenterAttr = @@ -40,12 +59,14 @@ void SketchSolver_ConstraintMultiRotation::getAttributes( myBaseConstraint->string(SketchPlugin_MultiRotation::ANGLE_TYPE()); theFullValue = aMethodTypeAttr->value() != "SingleAngle"; + theReversed = myBaseConstraint->boolean(SketchPlugin_MultiRotation::REVERSED_ID())->value(); + getEntities(theEntities); // add owner of central point of Multi-Rotation to the list of monitored features FeaturePtr anOwner = ModelAPI_Feature::feature(aCenterAttr->attr()->owner()); if (anOwner) - myFeatures.insert(anOwner); + myOriginalFeatures.insert(anOwner); } void SketchSolver_ConstraintMultiRotation::process() @@ -56,15 +77,12 @@ void SketchSolver_ConstraintMultiRotation::process() return; } - EntityWrapperPtr anAngle; EntityWrapperPtr aRotationCenter; std::list aBaseEntities; - getAttributes(aRotationCenter, anAngle, myIsFullValue, aBaseEntities); + getAttributes(aRotationCenter, myAngle, myIsFullValue, myIsRevered, aBaseEntities); if (!myErrorMsg.empty()) return; - ScalarWrapperPtr anAngleVal = std::dynamic_pointer_cast(anAngle); - myAngle = anAngleVal->value(); myAdjusted = false; adjustConstraint(); @@ -74,10 +92,12 @@ void SketchSolver_ConstraintMultiRotation::process() void SketchSolver_ConstraintMultiRotation::updateLocal() { double aValue = myBaseConstraint->real(SketchPlugin_MultiRotation::ANGLE_ID())->value(); - if (fabs(myAngle - aValue) > tolerance) + bool isReversed = myBaseConstraint->boolean(SketchPlugin_MultiRotation::REVERSED_ID())->value(); + if (fabs(myAngle->value() - aValue) > tolerance || isReversed != myIsRevered) myAdjusted = false; // update angle value - myAngle = aValue; + myAngle->setValue(aValue); + myIsRevered = isReversed; // update center DataPtr aData = myBaseConstraint->data(); @@ -102,22 +122,43 @@ void SketchSolver_ConstraintMultiRotation::adjustConstraint() if (myAdjusted) return; - if (fabs(myAngle) < tolerance) { + double anAngleValue = myAngle->value(); + if (fabs(anAngleValue) < tolerance) { myStorage->setNeedToResolve(false); return; } + if (myIsRevered) + anAngleValue *= -1.0; // Obtain coordinates of rotation center + AttributeRefAttrPtr aCenterAttr = + myBaseConstraint->refattr(SketchPlugin_MultiRotation::CENTER_ID()); std::shared_ptr aRotCenter = - std::dynamic_pointer_cast(myStorage->entity( - myBaseConstraint->attribute(SketchPlugin_MultiRotation::CENTER_ID()))); - GCSPointPtr aCenterPoint = aRotCenter->point(); - myCenterCoord[0] = *(aCenterPoint->x); - myCenterCoord[1] = *(aCenterPoint->y); + std::dynamic_pointer_cast( + myStorage->entity(AttributePtr(aCenterAttr))); + if (aRotCenter) + { + GCSPointPtr aCenterPoint = aRotCenter->point(); + myCenterCoord[0] = *(aCenterPoint->x); + myCenterCoord[1] = *(aCenterPoint->y); + } + else + { + AttributePoint2DPtr aCenterPnt = + std::dynamic_pointer_cast(aCenterAttr->attr()); + myCenterCoord[0] = aCenterPnt->x(); + myCenterCoord[1] = aCenterPnt->y(); + } - double anAngleValue = myAngle; if (myIsFullValue && myNumberOfCopies > 0) - anAngleValue /= myNumberOfCopies; + { + // if the full angle value is equal to 360, then distribute rotated items + // to avoid superposition of original feature and last copy + if (fabs(anAngleValue - 360.0) < 1.e-7) + anAngleValue /= (myNumberOfCopies + 1); + else + anAngleValue /= myNumberOfCopies; + } myRotationVal[0] = sin(anAngleValue * PI / 180.0); myRotationVal[1] = cos(anAngleValue * PI / 180.0);