1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 #include <SketchSolver_ConstraintDistance.h>
4 #include <SketchSolver_Error.h>
5 #include <SketchSolver_Manager.h>
7 #include <GeomAPI_Dir2d.h>
8 #include <GeomAPI_Lin2d.h>
9 #include <GeomAPI_Pnt2d.h>
10 #include <GeomAPI_XY.h>
15 void SketchSolver_ConstraintDistance::getAttributes(
16 EntityWrapperPtr& theValue,
17 std::vector<EntityWrapperPtr>& theAttributes)
19 SketchSolver_Constraint::getAttributes(theValue, theAttributes);
20 if (!myErrorMsg.empty() || !theAttributes[0]) {
21 theAttributes.clear();
26 myType = CONSTRAINT_PT_PT_DISTANCE;
27 else if (theAttributes[2] && theAttributes[2]->type() == ENTITY_LINE)
28 myType = CONSTRAINT_PT_LINE_DISTANCE;
30 theAttributes.clear();
35 void SketchSolver_ConstraintDistance::adjustConstraint()
37 ConstraintWrapperPtr aConstraint = myStorage->constraint(myBaseConstraint);
39 // Adjust point-point distance if the points are equal
40 if (getType() == CONSTRAINT_PT_PT_DISTANCE) {
41 //// AttributePtr aPt1 = myBaseConstraint->attribute(SketchPlugin_Constraint::ENTITY_A());
42 //// AttributePtr aPt2 = myBaseConstraint->attribute(SketchPlugin_Constraint::ENTITY_B());
44 //// BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
45 //// std::shared_ptr<GeomAPI_Pnt2d> aPoint1 = aBuilder->point(myStorage->entity(aPt1));
46 //// EntityWrapperPtr anEntity2 = myStorage->entity(aPt2);
47 //// std::shared_ptr<GeomAPI_Pnt2d> aPoint2 = aBuilder->point(anEntity2);
49 //////// if (aPoint1->distance(aPoint2) < tolerance) {
50 //////// // Change X coordinate of second point to eliminate coincidence
51 //////// ParameterWrapperPtr aX = aSubs.back()->parameters().front();
52 //////// aX->setValue(aX->value() + 1.0);
53 //////// myStorage->update(aX);
58 // Adjust point-line distance
59 if (fabs(myPrevValue) == fabs(aConstraint->value())) {
60 // sign of distance is not changed
61 //// aConstraint->setValue(myPrevValue);
62 //// myStorage->addConstraint(myBaseConstraint, aConstraint);
66 //// // Adjust the sign of constraint value
67 //// BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
69 //// std::shared_ptr<GeomAPI_Lin2d> aLine;
70 //// std::shared_ptr<GeomAPI_Pnt2d> aPoint;
71 //// for (int i = 0; i < 2; ++i) {
72 //// AttributePtr anAttr = myBaseConstraint->attribute(SketchPlugin_Constraint::ATTRIBUTE(i));
73 //// EntityWrapperPtr anEntity = myStorage->entity(anAttr);
74 //// if (anEntity->type() == ENTITY_POINT)
75 //// aPoint = aBuilder->point(anEntity);
76 //// else if (anEntity->type() == ENTITY_LINE)
77 //// aLine = aBuilder->line(anEntity);
80 //// std::shared_ptr<GeomAPI_XY> aLineVec = aLine->direction()->xy();
81 //// std::shared_ptr<GeomAPI_XY> aPtLineVec = aPoint->xy()->decreased(aLine->location()->xy());
82 //// if (aLineVec->cross(aPtLineVec) * aConstraint->value() < 0.0)
83 //// aConstraint->setValue(aConstraint->value() * (-1.0));
86 void SketchSolver_ConstraintDistance::update()
88 ConstraintWrapperPtr aConstraint = myStorage->constraint(myBaseConstraint);
89 myPrevValue = aConstraint->value();
91 SketchSolver_Constraint::update();