1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
20 #include <SketchSolver_ConstraintDistance.h>
21 #include <SketchSolver_Error.h>
22 #include <SketchSolver_Manager.h>
24 #include <GeomAPI_Dir2d.h>
25 #include <GeomAPI_Lin2d.h>
26 #include <GeomAPI_Pnt2d.h>
27 #include <GeomAPI_XY.h>
32 void SketchSolver_ConstraintDistance::getAttributes(
33 EntityWrapperPtr& theValue,
34 std::vector<EntityWrapperPtr>& theAttributes)
36 SketchSolver_Constraint::getAttributes(theValue, theAttributes);
37 if (!myErrorMsg.empty() || !theAttributes[0]) {
38 theAttributes.clear();
43 myType = CONSTRAINT_PT_PT_DISTANCE;
44 else if (theAttributes[2] && theAttributes[2]->type() == ENTITY_LINE)
45 myType = CONSTRAINT_PT_LINE_DISTANCE;
47 theAttributes.clear();
52 void SketchSolver_ConstraintDistance::adjustConstraint()
54 ConstraintWrapperPtr aConstraint = myStorage->constraint(myBaseConstraint);
56 // Adjust point-point distance if the points are equal
57 if (getType() == CONSTRAINT_PT_PT_DISTANCE) {
58 //// AttributePtr aPt1 = myBaseConstraint->attribute(SketchPlugin_Constraint::ENTITY_A());
59 //// AttributePtr aPt2 = myBaseConstraint->attribute(SketchPlugin_Constraint::ENTITY_B());
61 //// BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
62 //// std::shared_ptr<GeomAPI_Pnt2d> aPoint1 = aBuilder->point(myStorage->entity(aPt1));
63 //// EntityWrapperPtr anEntity2 = myStorage->entity(aPt2);
64 //// std::shared_ptr<GeomAPI_Pnt2d> aPoint2 = aBuilder->point(anEntity2);
66 //////// if (aPoint1->distance(aPoint2) < tolerance) {
67 //////// // Change X coordinate of second point to eliminate coincidence
68 //////// ParameterWrapperPtr aX = aSubs.back()->parameters().front();
69 //////// aX->setValue(aX->value() + 1.0);
70 //////// myStorage->update(aX);
75 // Adjust point-line distance
76 if (fabs(myPrevValue) == fabs(aConstraint->value())) {
77 // sign of distance is not changed
78 //// aConstraint->setValue(myPrevValue);
79 //// myStorage->addConstraint(myBaseConstraint, aConstraint);
83 //// // Adjust the sign of constraint value
84 //// BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
86 //// std::shared_ptr<GeomAPI_Lin2d> aLine;
87 //// std::shared_ptr<GeomAPI_Pnt2d> aPoint;
88 //// for (int i = 0; i < 2; ++i) {
89 //// AttributePtr anAttr = myBaseConstraint->attribute(SketchPlugin_Constraint::ATTRIBUTE(i));
90 //// EntityWrapperPtr anEntity = myStorage->entity(anAttr);
91 //// if (anEntity->type() == ENTITY_POINT)
92 //// aPoint = aBuilder->point(anEntity);
93 //// else if (anEntity->type() == ENTITY_LINE)
94 //// aLine = aBuilder->line(anEntity);
97 //// std::shared_ptr<GeomAPI_XY> aLineVec = aLine->direction()->xy();
98 //// std::shared_ptr<GeomAPI_XY> aPtLineVec = aPoint->xy()->decreased(aLine->location()->xy());
99 //// if (aLineVec->cross(aPtLineVec) * aConstraint->value() < 0.0)
100 //// aConstraint->setValue(aConstraint->value() * (-1.0));
103 void SketchSolver_ConstraintDistance::update()
105 ConstraintWrapperPtr aConstraint = myStorage->constraint(myBaseConstraint);
106 myPrevValue = aConstraint->value();
108 SketchSolver_Constraint::update();