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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include <SketchSolver_ConstraintDistance.h>
22 #include <SketchSolver_Error.h>
23 #include <SketchSolver_Manager.h>
25 #include <GeomAPI_Dir2d.h>
26 #include <GeomAPI_Lin2d.h>
27 #include <GeomAPI_Pnt2d.h>
28 #include <GeomAPI_XY.h>
33 void SketchSolver_ConstraintDistance::getAttributes(
34 EntityWrapperPtr& theValue,
35 std::vector<EntityWrapperPtr>& theAttributes)
37 SketchSolver_Constraint::getAttributes(theValue, theAttributes);
38 if (!myErrorMsg.empty() || !theAttributes[0]) {
39 theAttributes.clear();
44 myType = CONSTRAINT_PT_PT_DISTANCE;
45 else if (theAttributes[2] && theAttributes[2]->type() == ENTITY_LINE)
46 myType = CONSTRAINT_PT_LINE_DISTANCE;
48 theAttributes.clear();
53 void SketchSolver_ConstraintDistance::adjustConstraint()
55 ConstraintWrapperPtr aConstraint = myStorage->constraint(myBaseConstraint);
57 // Adjust point-point distance if the points are equal
58 if (getType() == CONSTRAINT_PT_PT_DISTANCE) {
59 //// AttributePtr aPt1 = myBaseConstraint->attribute(SketchPlugin_Constraint::ENTITY_A());
60 //// AttributePtr aPt2 = myBaseConstraint->attribute(SketchPlugin_Constraint::ENTITY_B());
62 //// BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
63 //// std::shared_ptr<GeomAPI_Pnt2d> aPoint1 = aBuilder->point(myStorage->entity(aPt1));
64 //// EntityWrapperPtr anEntity2 = myStorage->entity(aPt2);
65 //// std::shared_ptr<GeomAPI_Pnt2d> aPoint2 = aBuilder->point(anEntity2);
67 //////// if (aPoint1->distance(aPoint2) < tolerance) {
68 //////// // Change X coordinate of second point to eliminate coincidence
69 //////// ParameterWrapperPtr aX = aSubs.back()->parameters().front();
70 //////// aX->setValue(aX->value() + 1.0);
71 //////// myStorage->update(aX);
76 // Adjust point-line distance
77 if (fabs(myPrevValue) == fabs(aConstraint->value())) {
78 // sign of distance is not changed
79 //// aConstraint->setValue(myPrevValue);
80 //// myStorage->addConstraint(myBaseConstraint, aConstraint);
84 //// // Adjust the sign of constraint value
85 //// BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
87 //// std::shared_ptr<GeomAPI_Lin2d> aLine;
88 //// std::shared_ptr<GeomAPI_Pnt2d> aPoint;
89 //// for (int i = 0; i < 2; ++i) {
90 //// AttributePtr anAttr = myBaseConstraint->attribute(SketchPlugin_Constraint::ATTRIBUTE(i));
91 //// EntityWrapperPtr anEntity = myStorage->entity(anAttr);
92 //// if (anEntity->type() == ENTITY_POINT)
93 //// aPoint = aBuilder->point(anEntity);
94 //// else if (anEntity->type() == ENTITY_LINE)
95 //// aLine = aBuilder->line(anEntity);
98 //// std::shared_ptr<GeomAPI_XY> aLineVec = aLine->direction()->xy();
99 //// std::shared_ptr<GeomAPI_XY> aPtLineVec = aPoint->xy()->decreased(aLine->location()->xy());
100 //// if (aLineVec->cross(aPtLineVec) * aConstraint->value() < 0.0)
101 //// aConstraint->setValue(aConstraint->value() * (-1.0));
104 void SketchSolver_ConstraintDistance::update()
106 ConstraintWrapperPtr aConstraint = myStorage->constraint(myBaseConstraint);
107 myPrevValue = aConstraint->value();
109 SketchSolver_Constraint::update();