1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 #include <SketchSolver_ConstraintCoincidence.h>
4 #include <SketchSolver_Error.h>
5 #include <PlaneGCSSolver_Tools.h>
6 #include <PlaneGCSSolver_UpdateCoincidence.h>
8 void SketchSolver_ConstraintCoincidence::process()
11 if (!myBaseConstraint || !myStorage) {
12 // Not enough parameters are assigned
16 EntityWrapperPtr aValue;
17 std::vector<EntityWrapperPtr> anAttributes;
18 getAttributes(aValue, anAttributes);
19 if (!myErrorMsg.empty())
21 if (anAttributes.empty()) {
22 myErrorMsg = SketchSolver_Error::INCORRECT_ATTRIBUTE();
26 mySolverConstraint = PlaneGCSSolver_Tools::createConstraint(
27 myBaseConstraint, getType(),
28 aValue, anAttributes[0], anAttributes[1], anAttributes[2], anAttributes[3]);
30 myStorage->subscribeUpdates(this, PlaneGCSSolver_UpdateCoincidence::GROUP());
31 myStorage->notify(myBaseConstraint);
34 bool SketchSolver_ConstraintCoincidence::remove()
37 return SketchSolver_Constraint::remove();
40 void SketchSolver_ConstraintCoincidence::getAttributes(
41 EntityWrapperPtr& theValue,
42 std::vector<EntityWrapperPtr>& theAttributes)
44 SketchSolver_Constraint::getAttributes(theValue, theAttributes);
45 if (!myErrorMsg.empty() || !theAttributes[0]) {
46 theAttributes.clear();
51 myType = CONSTRAINT_PT_PT_COINCIDENT;
52 else if (theAttributes[2]) {
53 // check the type of entity (line or circle)
54 SketchSolver_EntityType anEntType = theAttributes[2]->type();
55 if (anEntType == ENTITY_LINE)
56 myType = CONSTRAINT_PT_ON_LINE;
57 else if (anEntType == ENTITY_CIRCLE || anEntType == ENTITY_ARC)
58 myType = CONSTRAINT_PT_ON_CIRCLE;
60 myErrorMsg = SketchSolver_Error::INCORRECT_ATTRIBUTE();
62 myErrorMsg = SketchSolver_Error::INCORRECT_ATTRIBUTE();
65 void SketchSolver_ConstraintCoincidence::notify(const FeaturePtr& theFeature,
66 PlaneGCSSolver_Update* theUpdater)
68 PlaneGCSSolver_UpdateCoincidence* anUpdater =
69 static_cast<PlaneGCSSolver_UpdateCoincidence*>(theUpdater);
70 bool isAccepted = anUpdater->checkCoincidence(myAttributes.front(), myAttributes.back());
74 myStorage->addConstraint(myBaseConstraint, mySolverConstraint);
79 myStorage->removeConstraint(myBaseConstraint);