X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchSolver%2FSketchSolver_ConstraintMultiRotation.cpp;h=910bdaf4f4db6894182828111ca9954b712deec1;hb=4f565b2204d3fba046aa8c851abada2a5a17bf6c;hp=89448c0a936e73187a24df09b1dcb28b7797237c;hpb=37c59d59b17e4a7e304588fb647488457a0c7283;p=modules%2Fshaper.git diff --git a/src/SketchSolver/SketchSolver_ConstraintMultiRotation.cpp b/src/SketchSolver/SketchSolver_ConstraintMultiRotation.cpp index 89448c0a9..910bdaf4f 100644 --- a/src/SketchSolver/SketchSolver_ConstraintMultiRotation.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintMultiRotation.cpp @@ -1,24 +1,18 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + #include #include #include -////#include #include -////#include -////#include -////#include -////#include -////#include -//// -////#include -////#include -//// -////#include +#include + +#include void SketchSolver_ConstraintMultiRotation::getAttributes( EntityWrapperPtr& theCenter, double& theAngle, - std::list< std::list >& theEntities) + bool& theFullValue, std::list& theEntities) { DataPtr aData = myBaseConstraint->data(); theAngle = std::dynamic_pointer_cast( @@ -32,76 +26,13 @@ void SketchSolver_ConstraintMultiRotation::getAttributes( myType = CONSTRAINT_MULTI_ROTATION; - myStorage->update(aCenterAttr, GID_OUTOFGROUP); + myStorage->update(aCenterAttr); theCenter = myStorage->entity(aCenterAttr); - getEntitiesAndCopies(theEntities); - -//// // Lists of objects and number of copies -//// AttributeRefListPtr anInitialRefList = std::dynamic_pointer_cast( -//// aData->attribute(SketchPlugin_Constraint::ENTITY_A())); -//// myNumberOfObjects = anInitialRefList->size(); -//// myNumberOfCopies = (size_t) aData->integer(SketchPlugin_MultiRotation::NUMBER_OF_OBJECTS_ID())->value() - 1; -//// if (myNumberOfCopies <= 0) -//// return; -//// AttributeRefListPtr aRefList = std::dynamic_pointer_cast( -//// myBaseConstraint->attribute(SketchPlugin_Constraint::ENTITY_B())); -//// if (!aRefList) { -//// myErrorMsg = SketchSolver_Error::INCORRECT_ATTRIBUTE(); -//// return; -//// } -//// -//// // Obtain all points of initial features and store them into separate lists -//// // containing their translated copies. -//// // Also all circles and arc collected too, because they will be constrained by equal radii. -//// FeaturePtr aFeature; -//// ResultConstructionPtr aRC; -//// static const size_t MAX_POINTS = 3; -//// std::vector aPoints[MAX_POINTS]; // lists of points of features -//// std::vector anEntities; -//// std::list anObjectList = aRefList->list(); -//// std::list::iterator anObjectIter = anObjectList.begin(); -//// while (anObjectIter != anObjectList.end()) { -//// for (size_t i = 0; i < MAX_POINTS; ++i) -//// aPoints[i].clear(); -//// anEntities.clear(); -//// -//// for (size_t i = 0; i <= myNumberOfCopies && anObjectIter != anObjectList.end(); i++, anObjectIter++) { -//// aFeature = ModelAPI_Feature::feature(*anObjectIter); -//// if (!aFeature) -//// continue; -//// anEntityID = changeEntity(aFeature, aType); -//// anEntities.push_back(anEntityID); -//// Slvs_Entity anEntity = myStorage->getEntity(anEntityID); -//// switch (aType) { -//// case SLVS_E_POINT_IN_2D: -//// case SLVS_E_POINT_IN_3D: -//// aPoints[0].push_back(anEntityID); -//// break; -//// case SLVS_E_LINE_SEGMENT: -//// aPoints[0].push_back(anEntity.point[0]); // start point of line -//// aPoints[1].push_back(anEntity.point[1]); // end point of line -//// break; -//// case SLVS_E_CIRCLE: -//// aPoints[0].push_back(anEntity.point[0]); // center of circle -//// break; -//// case SLVS_E_ARC_OF_CIRCLE: -//// aPoints[0].push_back(anEntity.point[0]); // center of arc -//// aPoints[1].push_back(anEntity.point[1]); // start point of arc -//// aPoints[2].push_back(anEntity.point[2]); // end point of arc -//// break; -//// default: -//// myErrorMsg = SketchSolver_Error::INCORRECT_ATTRIBUTE(); -//// return; -//// } -//// } -//// -//// for (size_t i = 0; i < MAX_POINTS; ++i) -//// if (!aPoints[i].empty()) -//// thePoints.push_back(aPoints[i]); -//// if (!anEntities.empty()) -//// theEntities.push_back(anEntities); -//// } + AttributeStringPtr aMethodTypeAttr = aData->string(SketchPlugin_MultiRotation::ANGLE_TYPE()); + theFullValue = aMethodTypeAttr->value() != "SingleAngle"; + + getEntities(theEntities); } void SketchSolver_ConstraintMultiRotation::process() @@ -111,39 +42,28 @@ void SketchSolver_ConstraintMultiRotation::process() /// TODO: Put error message here return; } -//// if (!mySlvsConstraints.empty()) // some data is changed, update constraint -//// update(myBaseConstraint); EntityWrapperPtr aRotationCenter; - std::list > anEntitiesAndCopies; - getAttributes(aRotationCenter, myAngle, anEntitiesAndCopies); + bool isFullValue; + std::list aBaseEntities; + getAttributes(aRotationCenter, myAngle, isFullValue, aBaseEntities); if (!myErrorMsg.empty()) return; -//// // Set the rotation center unchanged during constraint recalculation -//// Slvs_Constraint aConstraint; -//// if (!myStorage->isPointFixed(myRotationCenter, aConstraint.h, true)) { -//// aConstraint = Slvs_MakeConstraint( -//// SLVS_E_UNKNOWN, myGroup->getId(), SLVS_C_WHERE_DRAGGED, myGroup->getWorkplaneId(), 0.0, -//// myRotationCenter, SLVS_E_UNKNOWN, SLVS_E_UNKNOWN, SLVS_E_UNKNOWN); -//// aConstraint.h = myStorage->addConstraint(aConstraint); -//// mySlvsConstraints.push_back(aConstraint.h); -//// } - BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder(); std::list aRotConstraints; - std::list< std::list >::iterator anEntIt = anEntitiesAndCopies.begin(); - for (; anEntIt != anEntitiesAndCopies.end(); ++anEntIt) { + std::list::iterator anEntIt = aBaseEntities.begin(); + for (; anEntIt != aBaseEntities.end(); ++anEntIt) { std::list aNewConstraints = aBuilder->createConstraint(myBaseConstraint, myGroupID, mySketchID, myType, - myAngle, aRotationCenter, EntityWrapperPtr(), *anEntIt); + myAngle, isFullValue, aRotationCenter, EntityWrapperPtr(), + std::list(1, *anEntIt)); aRotConstraints.insert(aRotConstraints.end(), aNewConstraints.begin(), aNewConstraints.end()); } myStorage->addConstraint(myBaseConstraint, aRotConstraints); myAdjusted = false; -//// processEntities(anEntitiesAndCopies); adjustConstraint(); } @@ -157,82 +77,107 @@ void SketchSolver_ConstraintMultiRotation::updateLocal() myAngle = aValue; // update center - AttributePtr aCenterAttr = myBaseConstraint->attribute(SketchPlugin_MultiRotation::CENTER_ID()); - if (myStorage->update(aCenterAttr, myGroupID)) { - myStorage->update(aCenterAttr, GID_UNKNOWN); + DataPtr aData = myBaseConstraint->data(); + AttributePoint2DPtr aCenterPointAttribute = GeomDataAPI_Point2D::getPoint2D(aData, + SketchPlugin_MultiRotation::CENTER_ID()); + bool aCenterPointChanged = aCenterPointAttribute != myCenterPointAttribute; + if (aCenterPointChanged) + myCenterPointAttribute = aCenterPointAttribute; + + AttributeStringPtr aMethodTypeAttr = aData->string(SketchPlugin_MultiRotation::ANGLE_TYPE()); + bool aFullValue = aMethodTypeAttr->value() != "SingleAngle"; + bool isMethodChanged = aFullValue != myIsFullValue; + 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); + myAdjusted = false; } } void SketchSolver_ConstraintMultiRotation::adjustConstraint() { + if (myAdjusted) + return; + if (fabs(myAngle) < tolerance) { myStorage->setNeedToResolve(false); return; } -//// if (myAdjusted) -//// return; -//// -//// std::list aCoincident = myStorage->getConstraintsByType(SLVS_C_POINTS_COINCIDENT); -//// std::list::const_iterator aCoIt; -//// -//// // Check overconstrained on rotation center (if it is coincident with other fixed point) -//// Slvs_hConstraint aFixedCenter; -//// if (myStorage->isPointFixed(myRotationCenter, aFixedCenter, false)) { -//// Slvs_hConstraint aFixed; -//// for (aCoIt = aCoincident.begin(); aCoIt != aCoincident.end(); ++aCoIt) -//// if ((aCoIt->ptA == myRotationCenter && myStorage->isPointFixed(aCoIt->ptB, aFixed, true)) || -//// (aCoIt->ptB == myRotationCenter && myStorage->isPointFixed(aCoIt->ptA, aFixed, true))) { -//// // Un-fix the center -//// myStorage->removeConstraint(aFixedCenter); -//// std::vector::iterator aSCIt = mySlvsConstraints.begin(); -//// for (; aSCIt != mySlvsConstraints.end(); ++aSCIt) -//// if (*aSCIt == aFixedCenter) { -//// mySlvsConstraints.erase(aSCIt); -//// break; -//// } -//// } -//// } -//// -//// // Obtain coordinates of rotation center -//// Slvs_Entity aRotCenter = myStorage->getEntity(myRotationCenter); -//// myCenterCoord[0] = myStorage->getParameter(aRotCenter.param[0]).val; -//// myCenterCoord[1] = myStorage->getParameter(aRotCenter.param[1]).val; -//// -//// myRotationVal[0] = sin(myAngle * PI / 180.0); -//// myRotationVal[1] = cos(myAngle * PI / 180.0); -//// const std::list& aConstraints = myStorage->constraint(myBaseConstraint); std::list::const_iterator aCIt = aConstraints.begin(); for (; aCIt != aConstraints.end(); ++aCIt) (*aCIt)->setValue(myAngle); + // Obtain coordinates of rotation center + EntityWrapperPtr aRotCenter = myStorage->entity( + myBaseConstraint->attribute(SketchPlugin_MultiRotation::CENTER_ID())); + std::list aParams = aRotCenter->parameters(); + myCenterCoord[0] = aParams.front()->value(); + myCenterCoord[1] = aParams.back()->value(); + + double anAngleValue = myAngle; + if (myIsFullValue && myNumberOfCopies > 0) + 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; -////} +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() {