X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchSolver%2FSketchSolver_ConstraintMulti.cpp;h=a86ab8b5fbd51731f26d30fdade40e31a67a402d;hb=4f565b2204d3fba046aa8c851abada2a5a17bf6c;hp=d2135179c35538fe52fe63c8f0c779218fafa86e;hpb=fd7266e083c3fb837b8b195b1db746fdbd7b2be8;p=modules%2Fshaper.git diff --git a/src/SketchSolver/SketchSolver_ConstraintMulti.cpp b/src/SketchSolver/SketchSolver_ConstraintMulti.cpp index d2135179c..a86ab8b5f 100644 --- a/src/SketchSolver/SketchSolver_ConstraintMulti.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintMulti.cpp @@ -1,3 +1,5 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + #include #include #include @@ -7,7 +9,10 @@ #include #include #include +#include #include +#include +#include void SketchSolver_ConstraintMulti::getEntities(std::list& theEntities) { @@ -32,7 +37,8 @@ void SketchSolver_ConstraintMulti::getEntities(std::list& theE FeaturePtr aFeature; std::list anObjectList = aRefList->list(); std::list::iterator anObjIt = anObjectList.begin(); - if ((myNumberOfCopies + 1) * myNumberOfObjects != aRefList->size()) // execute for the feature is not called yet + // execute for the feature is not called yet + if ((myNumberOfCopies + 1) * myNumberOfObjects != aRefList->size()) myNumberOfCopies = aRefList->size() / myNumberOfObjects - 1; while (anObjIt != anObjectList.end()) { @@ -40,26 +46,60 @@ void SketchSolver_ConstraintMulti::getEntities(std::list& theE if (!aFeature) continue; - myStorage->update(aFeature); + // the entity is not created, so it is a copy in "multi" constraint, force its creation + if (!myStorage->update(aFeature)) + myStorage->update(aFeature, myGroupID, true); theEntities.push_back(myStorage->entity(aFeature)); - for (int i = 0; i < myNumberOfCopies && anObjIt != anObjectList.end(); ++i, ++anObjIt) - ; // just skip copied features + myFeatures.insert(aFeature); + for (int i = 0; i < myNumberOfCopies && anObjIt != anObjectList.end(); ++i, ++anObjIt) { + // just add copied features into the list of objects + aFeature = ModelAPI_Feature::feature(*anObjIt); + if (aFeature) + myFeatures.insert(aFeature); + } } } +bool SketchSolver_ConstraintMulti::remove() +{ + myFeatures.clear(); + return SketchSolver_Constraint::remove(); +} + void SketchSolver_ConstraintMulti::update() { update(false); } - void SketchSolver_ConstraintMulti::update(bool isForce) { cleanErrorMsg(); AttributeRefListPtr anInitialRefList = std::dynamic_pointer_cast( myBaseConstraint->attribute(SketchPlugin_Constraint::ENTITY_A())); AttributeIntegerPtr aNbObjects = myBaseConstraint->integer(nameNbObjects()); - if (anInitialRefList->size() != myNumberOfObjects || aNbObjects->value()-1 != myNumberOfCopies) { + if (!anInitialRefList || !aNbObjects) + return; // the "Multi" constraint is in queue to remove + bool isUpdated = + anInitialRefList->size() != myNumberOfObjects || aNbObjects->value()-1 != myNumberOfCopies; + if (!isUpdated) { + // additional check that the features and their copies are changed + AttributeRefListPtr aRefList = std::dynamic_pointer_cast( + myBaseConstraint->attribute(SketchPlugin_Constraint::ENTITY_B())); + if (aRefList && aRefList->size() != 0) { + FeaturePtr aFeature; + std::list anObjectList = aRefList->list(); + std::list::iterator anObjIt = anObjectList.begin(); + for (; anObjIt != anObjectList.end(); ++anObjIt) { + aFeature = ModelAPI_Feature::feature(*anObjIt); + if (aFeature && myFeatures.find(aFeature) == myFeatures.end()) { + isUpdated = true; + break; + } + } + } else + isUpdated = true; + } + if (isUpdated) { remove(); process(); return; @@ -69,8 +109,7 @@ void SketchSolver_ConstraintMulti::update(bool isForce) updateLocal(); if (isForce) myAdjusted = false; - // update parent object - SketchSolver_Constraint::update(); + adjustConstraint(); } void SketchSolver_ConstraintMulti::adjustConstraint() @@ -82,27 +121,34 @@ void SketchSolver_ConstraintMulti::adjustConstraint() return; } - FeaturePtr aFeature; + FeaturePtr anOriginal, aFeature; std::list anObjectList = aRefList->list(); std::list::iterator anObjIt = anObjectList.begin(); while (anObjIt != anObjectList.end()) { - aFeature = ModelAPI_Feature::feature(*anObjIt++); - if (!aFeature) + anOriginal = ModelAPI_Feature::feature(*anObjIt++); + if (!anOriginal) continue; // Fill lists of coordinates of points composing a feature std::list aX, aY; std::list::iterator aXIt, aYIt; double aXCoord, aYCoord; - EntityWrapperPtr anEntity = myStorage->entity(aFeature); + EntityWrapperPtr anEntity = myStorage->entity(anOriginal); std::list aSubs = anEntity->subEntities(); std::list::const_iterator aSIt = aSubs.begin(); for (; aSIt != aSubs.end(); ++aSIt) { if ((*aSIt)->type() != ENTITY_POINT) continue; - std::list aParameters = (*aSIt)->parameters(); - aXCoord = aParameters.front()->value(); - aYCoord = aParameters.back()->value(); + AttributePoint2DPtr aPoint = + std::dynamic_pointer_cast((*aSIt)->baseAttribute()); + if (aPoint) { + aXCoord = aPoint->x(); + aYCoord = aPoint->y(); + } else { + std::list aParameters = (*aSIt)->parameters(); + aXCoord = aParameters.front()->value(); + aYCoord = aParameters.back()->value(); + } getRelative(aXCoord, aYCoord, aXCoord, aYCoord); aX.push_back(aXCoord); aY.push_back(aYCoord); @@ -115,8 +161,9 @@ void SketchSolver_ConstraintMulti::adjustConstraint() continue; anEntity = myStorage->entity(aFeature); + bool aWasBlocked = false; if (!anEntity || !myStorage->isEventsBlocked()) - aFeature->data()->blockSendAttributeUpdated(true); + aWasBlocked = aFeature->data()->blockSendAttributeUpdated(true); std::list aPoints; if (aFeature->getKind() == SketchPlugin_Arc::ID()) { @@ -126,8 +173,14 @@ void SketchSolver_ConstraintMulti::adjustConstraint() } else if (aFeature->getKind() == SketchPlugin_Line::ID()) { aPoints.push_back(aFeature->attribute(SketchPlugin_Line::START_ID())); aPoints.push_back(aFeature->attribute(SketchPlugin_Line::END_ID())); - } else - aPoints = aFeature->data()->attributes(GeomDataAPI_Point2D::typeId()); + } else if (aFeature->getKind() == SketchPlugin_Circle::ID()) { + aPoints.push_back(aFeature->attribute(SketchPlugin_Circle::CENTER_ID())); + // update circle's radius + aFeature->real(SketchPlugin_Circle::RADIUS_ID())->setValue( + anOriginal->real(SketchPlugin_Circle::RADIUS_ID())->value()); + } else if (aFeature->getKind() == SketchPlugin_Point::ID() || + aFeature->getKind() == SketchPlugin_IntersectionPoint::ID()) + aPoints.push_back(aFeature->attribute(SketchPlugin_Point::COORD_ID())); std::list::iterator aPtIt = aPoints.begin(); for (aXIt = aX.begin(), aYIt = aY.begin(); aPtIt != aPoints.end(); ++aXIt, ++aYIt, ++aPtIt) { @@ -142,11 +195,42 @@ void SketchSolver_ConstraintMulti::adjustConstraint() // update feature in the storage if it is used by another constraints if (anEntity) myStorage->update(aFeature); + else { // update attributes, if they exist in the storage + for (aPtIt = aPoints.begin(); aPtIt != aPoints.end(); ++aPtIt) { + EntityWrapperPtr aPntEnt = myStorage->entity(*aPtIt); + if (aPntEnt) + myStorage->update(*aPtIt); + } + } if (!anEntity || !myStorage->isEventsBlocked()) - aFeature->data()->blockSendAttributeUpdated(false); + aFeature->data()->blockSendAttributeUpdated(aWasBlocked); } } myAdjusted = true; } + +bool SketchSolver_ConstraintMulti::isUsed(FeaturePtr theFeature) const +{ + return theFeature && (myFeatures.find(theFeature) != myFeatures.end() || + SketchSolver_Constraint::isUsed(theFeature)); +} + +bool SketchSolver_ConstraintMulti::isUsed(AttributePtr theAttribute) const +{ + AttributePtr anAttribute = theAttribute; + AttributeRefAttrPtr aRefAttr = + std::dynamic_pointer_cast(anAttribute); + if (aRefAttr) { + if (aRefAttr->isObject()) + return isUsed(ModelAPI_Feature::feature(aRefAttr->object())); + else + anAttribute = aRefAttr->attr(); + } + if (!anAttribute) + return false; + + FeaturePtr anOwner = ModelAPI_Feature::feature(anAttribute->owner()); + return myFeatures.find(anOwner) != myFeatures.end(); +}