X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchSolver%2FSketchSolver_Constraint.cpp;h=bbf00518aa95c1e1f57ec7f12aaa4f7c65e23612;hb=4f565b2204d3fba046aa8c851abada2a5a17bf6c;hp=96051c3d01128d11ef79f375f255acb67cfaaabd;hpb=c48541d1114c5cc388db22ea73af8950de2ffa7b;p=modules%2Fshaper.git diff --git a/src/SketchSolver/SketchSolver_Constraint.cpp b/src/SketchSolver/SketchSolver_Constraint.cpp index 96051c3d0..bbf00518a 100644 --- a/src/SketchSolver/SketchSolver_Constraint.cpp +++ b/src/SketchSolver/SketchSolver_Constraint.cpp @@ -1,3 +1,5 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + #include #include #include @@ -10,10 +12,12 @@ #include #include +#include #include #include #include #include +#include #include #include #include @@ -79,6 +83,10 @@ SketchSolver_ConstraintType SketchSolver_Constraint::TYPE(ConstraintPtr theConst return CONSTRAINT_RADIUS; else if (aType == SketchPlugin_ConstraintTangent::ID()) return CONSTRAINT_TANGENT; + else if (aType == SketchPlugin_ConstraintCollinear::ID()) + return CONSTRAINT_COLLINEAR; + else if (aType == SketchPlugin_ConstraintMiddle::ID()) + return CONSTRAINT_MIDDLE_POINT; return CONSTRAINT_UNKNOWN; } @@ -115,14 +123,67 @@ void SketchSolver_Constraint::process() void SketchSolver_Constraint::update() { cleanErrorMsg(); - std::list aWrapper = myStorage->constraint(myBaseConstraint); + std::list::iterator aWIt = aWrapper.begin(); + + // Check if attributes of constraint are changed, rebuild constraint + std::set anAttributes; + std::set::iterator aFoundAttr; + std::set aFeatures; + std::set::iterator aFoundFeat; + for (int anEntIndex = 0; anEntIndex < 4; ++anEntIndex) { + AttributePtr anAttr = + myBaseConstraint->attribute(SketchPlugin_Constraint::ATTRIBUTE(anEntIndex)); + if (!anAttr) + continue; + + AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast(anAttr); + if (aRefAttr) { + if (aRefAttr->isObject()) { + FeaturePtr aFeat = ModelAPI_Feature::feature(aRefAttr->object()); + if (myBaseConstraint->getKind() != SketchPlugin_ConstraintLength::ID()) + aFeatures.insert(aFeat); + else { + // Workaround for the Length constraint: add points of line, not line itself + anAttributes.insert(aFeat->attribute(SketchPlugin_Line::START_ID())); + anAttributes.insert(aFeat->attribute(SketchPlugin_Line::END_ID())); + } + } else + anAttributes.insert(aRefAttr->attr()); + } else + anAttributes.insert(anAttr); + } + bool hasNewAttr = !(anAttributes.empty() && aFeatures.empty()); + for (; hasNewAttr && aWIt != aWrapper.end(); ++ aWIt) { + const std::list& aSubs = (*aWIt)->entities(); + std::list::const_iterator aSIt = aSubs.begin(); + for (; hasNewAttr && aSIt != aSubs.end(); ++aSIt) { + if ((*aSIt)->baseAttribute()) { + aFoundAttr = anAttributes.find((*aSIt)->baseAttribute()); + if (aFoundAttr != anAttributes.end()) + anAttributes.erase(aFoundAttr); + } else { + aFoundFeat = aFeatures.find((*aSIt)->baseFeature()); + if (aFoundFeat != aFeatures.end()) + aFeatures.erase(aFoundFeat); + } + hasNewAttr = !(anAttributes.empty() && aFeatures.empty()); + } + } + if (hasNewAttr) { + remove(); + process(); + return; + } + AttributeDoublePtr aValueAttr = std::dynamic_pointer_cast( myBaseConstraint->attribute(SketchPlugin_Constraint::VALUE())); if (aValueAttr) { - std::list::iterator aWIt = aWrapper.begin(); - for (; aWIt != aWrapper.end(); ++aWIt) - (*aWIt)->setValue(aValueAttr->value()); + for (aWIt = aWrapper.begin(); aWIt != aWrapper.end(); ++aWIt) + if (fabs((*aWIt)->value() - aValueAttr->value()) > tolerance) { + (*aWIt)->setValue(aValueAttr->value()); + myStorage->setNeedToResolve(true); + } } myStorage->addConstraint(myBaseConstraint, aWrapper); @@ -132,6 +193,7 @@ void SketchSolver_Constraint::update() bool SketchSolver_Constraint::remove() { cleanErrorMsg(); + myType = CONSTRAINT_UNKNOWN; return myStorage->removeConstraint(myBaseConstraint); } @@ -141,6 +203,7 @@ void SketchSolver_Constraint::getAttributes( { static const int anInitNbOfAttr = 4; theAttributes.assign(anInitNbOfAttr, EntityWrapperPtr()); + myAttributes.clear(); DataPtr aData = myBaseConstraint->data(); BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder(); @@ -165,6 +228,12 @@ void SketchSolver_Constraint::getAttributes( myStorage->update(*anIter/*, myGroupID*/); EntityWrapperPtr anEntity = myStorage->entity(*anIter); + if (!anEntity) { + // Force creation of an entity + myStorage->update(*anIter, GID_UNKNOWN, true); + anEntity = myStorage->entity(*anIter); + } + myAttributes.push_back(anEntity); SketchSolver_EntityType aType = anEntity->type(); if (aType == ENTITY_UNKNOWN) @@ -189,7 +258,8 @@ bool SketchSolver_Constraint::isUsed(FeaturePtr theFeature) const if ((*aCIt)->isUsed(theFeature)) return true; - std::list anAttrList = theFeature->data()->attributes(GeomDataAPI_Point2D::typeId()); + std::list anAttrList = + theFeature->data()->attributes(GeomDataAPI_Point2D::typeId()); std::list::const_iterator anAttrIt = anAttrList.begin(); for (; anAttrIt != anAttrList.end(); ++ anAttrIt) if (isUsed(*anAttrIt)) @@ -217,9 +287,3 @@ bool SketchSolver_Constraint::isUsed(AttributePtr theAttribute) const return true; return false; } - -void SketchSolver_Constraint::makeTemporary() const -{ - myStorage->setTemporary(myBaseConstraint); -} -