#include <SketchSolver_ConstraintCoincidence.h>
#include <SketchSolver_Error.h>
#include <SketchSolver_Manager.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;
+ }
+
+ BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
+ mySolverConstraint = aBuilder->createConstraint(
+ myBaseConstraint, getType(),
+ aValue, anAttributes[0], anAttributes[1], anAttributes[2], anAttributes[3]);
+
+ myStorage->subscribeUpdates(this, PlaneGCSSolver_UpdateCoincidence::GROUP());
+ myStorage->notify(myBaseConstraint);
+}
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;
- if (myStorage->isFixed(theAttributes[1]) && !myStorage->isFixed(theAttributes[0])) {
- // fixed point should go first
- EntityWrapperPtr aTemp = theAttributes[0];
- theAttributes[0] = theAttributes[1];
- theAttributes[1] = aTemp;
- }
- // 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();
} else
myErrorMsg = SketchSolver_Error::INCORRECT_ATTRIBUTE();
}
+
+void SketchSolver_ConstraintCoincidence::notify(const FeaturePtr& theFeature,
+ PlaneGCSSolver_Update* theUpdater)
+{
+ 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);
+ }
+ }
+}