1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 #include <SketchSolver_ConstraintCoincidence.h>
4 #include <SketchSolver_Error.h>
5 #include <SketchSolver_Manager.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 BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
27 mySolverConstraint = aBuilder->createConstraint(
28 myBaseConstraint, getType(),
29 aValue, anAttributes[0], anAttributes[1], anAttributes[2], anAttributes[3]);
31 myStorage->subscribeUpdates(this, PlaneGCSSolver_UpdateCoincidence::GROUP());
32 myStorage->notify(myBaseConstraint);
35 bool SketchSolver_ConstraintCoincidence::remove()
38 return SketchSolver_Constraint::remove();
41 void SketchSolver_ConstraintCoincidence::getAttributes(
42 EntityWrapperPtr& theValue,
43 std::vector<EntityWrapperPtr>& theAttributes)
45 SketchSolver_Constraint::getAttributes(theValue, theAttributes);
46 if (!myErrorMsg.empty() || !theAttributes[0]) {
47 theAttributes.clear();
52 myType = CONSTRAINT_PT_PT_COINCIDENT;
53 else if (theAttributes[2]) {
54 // check the type of entity (line or circle)
55 SketchSolver_EntityType anEntType = theAttributes[2]->type();
56 if (anEntType == ENTITY_LINE)
57 myType = CONSTRAINT_PT_ON_LINE;
58 else if (anEntType == ENTITY_CIRCLE || anEntType == ENTITY_ARC)
59 myType = CONSTRAINT_PT_ON_CIRCLE;
61 myErrorMsg = SketchSolver_Error::INCORRECT_ATTRIBUTE();
63 myErrorMsg = SketchSolver_Error::INCORRECT_ATTRIBUTE();
66 void SketchSolver_ConstraintCoincidence::notify(const FeaturePtr& theFeature,
67 PlaneGCSSolver_Update* theUpdater)
69 PlaneGCSSolver_UpdateCoincidence* anUpdater =
70 static_cast<PlaneGCSSolver_UpdateCoincidence*>(theUpdater);
71 bool isAccepted = anUpdater->checkCoincidence(myAttributes.front(), myAttributes.back());
75 myStorage->addConstraint(myBaseConstraint, mySolverConstraint);
80 myStorage->removeConstraint(myBaseConstraint);