X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchSolver%2FSketchSolver_ConstraintMultiRotation.cpp;h=cf2cac48aab28cee9cf02c1e0e9a49e9574ff8d0;hb=11e506a02bbd919d5977b3a25cd4cd84ba54fda4;hp=5fc487e120e199815f7fae6f6b9486fbbaa03603;hpb=29f1c8ff3eb53f7ba5dd54ead45d3e55775e5968;p=modules%2Fshaper.git diff --git a/src/SketchSolver/SketchSolver_ConstraintMultiRotation.cpp b/src/SketchSolver/SketchSolver_ConstraintMultiRotation.cpp index 5fc487e12..cf2cac48a 100644 --- a/src/SketchSolver/SketchSolver_ConstraintMultiRotation.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintMultiRotation.cpp @@ -1,23 +1,49 @@ +// Copyright (C) 2014-2019 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 #include +#include +#include +#include +#include + #include #include -#include +#include void SketchSolver_ConstraintMultiRotation::getAttributes( - EntityWrapperPtr& theCenter, double& theAngle, - bool& theFullValue, - std::list< std::list >& theEntities) + EntityWrapperPtr& theCenter, ScalarWrapperPtr& theAngle, + bool& theFullValue, bool& theReversed, std::list& theEntities) { - DataPtr aData = myBaseConstraint->data(); - theAngle = std::dynamic_pointer_cast( - aData->attribute(SketchPlugin_MultiRotation::ANGLE_ID()))->value(); - - AttributePtr aCenterAttr = aData->attribute(SketchPlugin_MultiRotation::CENTER_ID()); + AttributePtr anAngleAttr = myBaseConstraint->attribute(SketchPlugin_MultiRotation::ANGLE_ID()); + PlaneGCSSolver_AttributeBuilder aValueBuilder; + theAngle = std::dynamic_pointer_cast( + aValueBuilder.createAttribute(anAngleAttr)); + myStorage->addEntity(anAngleAttr, theAngle); + + AttributeRefAttrPtr aCenterAttr = + myBaseConstraint->refattr(SketchPlugin_MultiRotation::CENTER_ID()); if (!aCenterAttr || !aCenterAttr->isInitialized()) { myErrorMsg = SketchSolver_Error::NOT_INITIALIZED(); return; @@ -25,54 +51,52 @@ void SketchSolver_ConstraintMultiRotation::getAttributes( myType = CONSTRAINT_MULTI_ROTATION; - myStorage->update(aCenterAttr, GID_OUTOFGROUP); - theCenter = myStorage->entity(aCenterAttr); + myStorage->update(AttributePtr(aCenterAttr)); + theCenter = myStorage->entity(AttributePtr(aCenterAttr)); - AttributeStringPtr aMethodTypeAttr = aData->string(SketchPlugin_MultiRotation::ANGLE_TYPE()); + AttributeStringPtr aMethodTypeAttr = + myBaseConstraint->string(SketchPlugin_MultiRotation::ANGLE_TYPE()); theFullValue = aMethodTypeAttr->value() != "SingleAngle"; - getEntitiesAndCopies(theEntities); + 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) + myOriginalFeatures.insert(anOwner); } void SketchSolver_ConstraintMultiRotation::process() { cleanErrorMsg(); - if (!myBaseConstraint || !myStorage || myGroupID == GID_UNKNOWN) { - /// TODO: Put error message here + if (!myBaseConstraint || !myStorage) { + // Not enough parameters are assigned return; } EntityWrapperPtr aRotationCenter; - bool isFullValue; - std::list > anEntitiesAndCopies; - getAttributes(aRotationCenter, myAngle, isFullValue, anEntitiesAndCopies); + std::list aBaseEntities; + getAttributes(aRotationCenter, myAngle, myIsFullValue, myIsRevered, aBaseEntities); if (!myErrorMsg.empty()) return; - BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder(); - std::list aRotConstraints; - - std::list< std::list >::iterator anEntIt = anEntitiesAndCopies.begin(); - for (; anEntIt != anEntitiesAndCopies.end(); ++anEntIt) { - std::list aNewConstraints = - aBuilder->createConstraint(myBaseConstraint, myGroupID, mySketchID, myType, - myAngle, isFullValue, aRotationCenter, EntityWrapperPtr(), *anEntIt); - aRotConstraints.insert(aRotConstraints.end(), aNewConstraints.begin(), aNewConstraints.end()); - } - myStorage->addConstraint(myBaseConstraint, aRotConstraints); - myAdjusted = false; adjustConstraint(); + + myStorage->subscribeUpdates(this, PlaneGCSSolver_UpdateFeature::GROUP()); } void SketchSolver_ConstraintMultiRotation::updateLocal() { - double aValue = std::dynamic_pointer_cast( - myBaseConstraint->attribute(SketchPlugin_MultiRotation::ANGLE_ID()))->value(); - if (fabs(myAngle - aValue) > tolerance) + double aValue = myBaseConstraint->real(SketchPlugin_MultiRotation::ANGLE_ID())->value(); + 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(); @@ -88,55 +112,82 @@ void SketchSolver_ConstraintMultiRotation::updateLocal() if (isMethodChanged) myIsFullValue = aFullValue; - if (aCenterPointChanged || isMethodChanged) { - DataPtr aData = myBaseConstraint->data(); - std::list aConstraints = myStorage->constraint(myBaseConstraint); - std::list::const_iterator anIt = aConstraints.begin(), - aLast = aConstraints.end(); - std::list anEntities; - for (; anIt != aLast; anIt++) { - ConstraintWrapperPtr aConstraint = *anIt; - aConstraint->setIsFullValue(myIsFullValue); - if (aCenterPointChanged) { - anEntities.clear(); - const std::list& aConstraintEntities = aConstraint->entities(); - std::list::const_iterator aSIt = aConstraintEntities.begin(), - aSLast = aConstraintEntities.end(); - EntityWrapperPtr aCenterPointEntity = *aSIt++; - if (aCenterPointChanged) { - AttributePtr aCenterPointAttr = aData->attribute(SketchPlugin_MultiRotation::CENTER_ID()); - myStorage->update(aCenterPointAttr); - aCenterPointEntity = myStorage->entity(aCenterPointAttr); - } - anEntities.push_back(aCenterPointEntity); - - for (; aSIt != aSLast; ++aSIt) - anEntities.push_back(*aSIt); - - aConstraint->setEntities(anEntities); - } - } - myStorage->addConstraint(myBaseConstraint, aConstraints); - + if (aCenterPointChanged || isMethodChanged) myAdjusted = false; - } } void SketchSolver_ConstraintMultiRotation::adjustConstraint() { - if (fabs(myAngle) < tolerance) { + if (myAdjusted) + return; + + 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(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(); + } - const std::list& aConstraints = myStorage->constraint(myBaseConstraint); - std::list::const_iterator aCIt = aConstraints.begin(); - for (; aCIt != aConstraints.end(); ++aCIt) - (*aCIt)->setValue(myAngle); + if (myIsFullValue && myNumberOfCopies > 0) + { + // 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); SketchSolver_ConstraintMulti::adjustConstraint(); } +void SketchSolver_ConstraintMultiRotation::getRelative( + double theAbsX, double theAbsY, double& theRelX, double& theRelY) +{ + theRelX = theAbsX - myCenterCoord[0]; + theRelY = theAbsY - myCenterCoord[1]; +} + +void SketchSolver_ConstraintMultiRotation::getAbsolute( + double theRelX, double theRelY, double& theAbsX, double& theAbsY) +{ + theAbsX = theRelX + myCenterCoord[0]; + theAbsY = theRelY + myCenterCoord[1]; +} + +void SketchSolver_ConstraintMultiRotation::transformRelative(double& theX, double& theY) +{ + // rotate direction + // myRotationVal[0] = sinA, myRotationVal[1] = cosA + double aTemp = theX * myRotationVal[1] - theY * myRotationVal[0]; + theY = theX * myRotationVal[0] + theY * myRotationVal[1]; + theX = aTemp; +} + const std::string& SketchSolver_ConstraintMultiRotation::nameNbObjects() { return SketchPlugin_MultiRotation::NUMBER_OF_OBJECTS_ID();