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_ConstraintMiddle.h>
22 #include <PlaneGCSSolver_ConstraintWrapper.h>
23 #include <PlaneGCSSolver_UpdateCoincidence.h>
25 void SketchSolver_ConstraintMiddle::getAttributes(
26 EntityWrapperPtr& theValue,
27 std::vector<EntityWrapperPtr>& theAttributes)
29 SketchSolver_Constraint::getAttributes(theValue, theAttributes);
32 void SketchSolver_ConstraintMiddle::notify(const FeaturePtr& theFeature,
33 PlaneGCSSolver_Update* theUpdater)
35 if (theFeature == myBaseConstraint && myInSolver)
36 return; // the constraint is already being updated
38 PlaneGCSSolver_UpdateCoincidence* anUpdater =
39 static_cast<PlaneGCSSolver_UpdateCoincidence*>(theUpdater);
40 bool isAccepted = anUpdater->addCoincidence(myAttributes.front(), myAttributes.back());
46 // remove previously adde constraint
47 myStorage->removeConstraint(myBaseConstraint);
48 // merge divided constraints into single object
49 std::list<GCSConstraintPtr> aGCSConstraints;
50 std::shared_ptr<PlaneGCSSolver_ConstraintWrapper> aConstraint =
51 std::dynamic_pointer_cast<PlaneGCSSolver_ConstraintWrapper>(myMiddle);
52 aGCSConstraints.push_back(aConstraint->constraints().front());
54 std::dynamic_pointer_cast<PlaneGCSSolver_ConstraintWrapper>(mySolverConstraint);
55 aGCSConstraints.push_back(aConstraint->constraints().front());
57 myMiddle = ConstraintWrapperPtr();
58 mySolverConstraint = ConstraintWrapperPtr(
59 new PlaneGCSSolver_ConstraintWrapper(aGCSConstraints, CONSTRAINT_MIDDLE_POINT));
62 myStorage->addConstraint(myBaseConstraint, mySolverConstraint);
66 myStorage->removeConstraint(myBaseConstraint);
71 // divide solver constraints to the middle point and point-line coincidence
72 std::shared_ptr<PlaneGCSSolver_ConstraintWrapper> aConstraint =
73 std::dynamic_pointer_cast<PlaneGCSSolver_ConstraintWrapper>(mySolverConstraint);
74 std::list<GCSConstraintPtr> aGCSConstraints = aConstraint->constraints();
76 myMiddle = ConstraintWrapperPtr(
77 new PlaneGCSSolver_ConstraintWrapper(aGCSConstraints.front(), CONSTRAINT_MIDDLE_POINT));
78 mySolverConstraint = ConstraintWrapperPtr(
79 new PlaneGCSSolver_ConstraintWrapper(aGCSConstraints.back(), CONSTRAINT_MIDDLE_POINT));
81 // send middle constraint only
82 myStorage->addConstraint(myBaseConstraint, myMiddle);