+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
#include <SketchSolver_ConstraintCoincidence.h>
#include <SketchSolver_Error.h>
-#include <SketchSolver_Manager.h>
+#include <PlaneGCSSolver_Tools.h>
+#include <PlaneGCSSolver_UpdateCoincidence.h>
+
+void SketchSolver_ConstraintCoincidence::process()
+{
+ cleanErrorMsg();
+ if (!myBaseConstraint || !myStorage) {
+ // Not enough parameters are assigned
+ return;
+ }
+
+ EntityWrapperPtr aValue;
+ std::vector<EntityWrapperPtr> anAttributes;
+ getAttributes(aValue, anAttributes);
+ if (!myErrorMsg.empty())
+ return;
+ if (anAttributes.empty()) {
+ myErrorMsg = SketchSolver_Error::INCORRECT_ATTRIBUTE();
+ return;
+ }
+
+ mySolverConstraint = PlaneGCSSolver_Tools::createConstraint(
+ myBaseConstraint, getType(),
+ aValue, anAttributes[0], anAttributes[1], anAttributes[2], anAttributes[3]);
+
+ myStorage->subscribeUpdates(this, PlaneGCSSolver_UpdateCoincidence::GROUP());
+ myStorage->notify(myBaseConstraint);
+}
+
+bool SketchSolver_ConstraintCoincidence::remove()
+{
+ myInSolver = false;
+ return SketchSolver_Constraint::remove();
+}
void SketchSolver_ConstraintCoincidence::getAttributes(
- double& theValue,
+ EntityWrapperPtr& theValue,
std::vector<EntityWrapperPtr>& theAttributes)
{
SketchSolver_Constraint::getAttributes(theValue, theAttributes);
return;
}
- if (theAttributes[1]) {
+ if (theAttributes[1])
myType = CONSTRAINT_PT_PT_COINCIDENT;
- // Set the slave (second) point the same as master (first) point.
- // This will allow to skip adding point-point coincidence to the set of constraints
- // and give us speed-up in solving the set of equations
- myStorage->addCoincidentPoints(theAttributes[0], theAttributes[1]);
- }
else if (theAttributes[2]) {
// check the type of entity (line or circle)
SketchSolver_EntityType anEntType = theAttributes[2]->type();
myErrorMsg = SketchSolver_Error::INCORRECT_ATTRIBUTE();
}
-
-static bool isBase(const std::list<ConstraintWrapperPtr>& theConstraints, AttributePtr theAttribute)
+void SketchSolver_ConstraintCoincidence::notify(const FeaturePtr& theFeature,
+ PlaneGCSSolver_Update* theUpdater)
{
- AttributePtr anAttribute = theAttribute;
- FeaturePtr aFeature;
- AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
- if (aRefAttr) {
- if (aRefAttr->isObject())
- aFeature = ModelAPI_Feature::feature(aRefAttr->object());
- else
- anAttribute = aRefAttr->attr();
- }
-
- std::list<ConstraintWrapperPtr>::const_iterator aCIt = theConstraints.begin();
- for (; aCIt != theConstraints.end(); ++aCIt) {
- std::list<EntityWrapperPtr> aSubs = (*aCIt)->entities();
- std::list<EntityWrapperPtr>::const_iterator aSIt = aSubs.begin();
- for (; aSIt != aSubs.end(); ++aSIt)
- if ((aFeature && (*aSIt)->isBase(aFeature)) ||
- (!aFeature && (*aSIt)->isBase(anAttribute)))
- return true;
+ PlaneGCSSolver_UpdateCoincidence* anUpdater =
+ static_cast<PlaneGCSSolver_UpdateCoincidence*>(theUpdater);
+ bool isAccepted = anUpdater->checkCoincidence(myAttributes.front(), myAttributes.back());
+ if (isAccepted) {
+ if (!myInSolver) {
+ myInSolver = true;
+ myStorage->addConstraint(myBaseConstraint, mySolverConstraint);
+ }
+ } else {
+ if (myInSolver) {
+ myInSolver = false;
+ myStorage->removeConstraint(myBaseConstraint);
+ }
}
- return false;
}