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 void SketchSolver_ConstraintCoincidence::getAttributes(
36 EntityWrapperPtr& theValue,
37 std::vector<EntityWrapperPtr>& theAttributes)
39 SketchSolver_Constraint::getAttributes(theValue, theAttributes);
40 if (!myErrorMsg.empty() || !theAttributes[0]) {
41 theAttributes.clear();
46 myType = CONSTRAINT_PT_PT_COINCIDENT;
47 else if (theAttributes[2]) {
48 // check the type of entity (line or circle)
49 SketchSolver_EntityType anEntType = theAttributes[2]->type();
50 if (anEntType == ENTITY_LINE)
51 myType = CONSTRAINT_PT_ON_LINE;
52 else if (anEntType == ENTITY_CIRCLE || anEntType == ENTITY_ARC)
53 myType = CONSTRAINT_PT_ON_CIRCLE;
55 myErrorMsg = SketchSolver_Error::INCORRECT_ATTRIBUTE();
57 myErrorMsg = SketchSolver_Error::INCORRECT_ATTRIBUTE();
60 void SketchSolver_ConstraintCoincidence::notify(const FeaturePtr& theFeature,
61 PlaneGCSSolver_Update* theUpdater)
63 PlaneGCSSolver_UpdateCoincidence* anUpdater =
64 static_cast<PlaneGCSSolver_UpdateCoincidence*>(theUpdater);
65 bool isAccepted = anUpdater->checkCoincidence(myAttributes.front(), myAttributes.back());
69 myStorage->addConstraint(myBaseConstraint, mySolverConstraint);
74 myStorage->removeConstraint(myBaseConstraint);