1 // Copyright (C) 2014-2019 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
20 #include <SketchSolver_ConstraintMiddle.h>
21 #include <PlaneGCSSolver_ConstraintWrapper.h>
22 #include <PlaneGCSSolver_UpdateCoincidence.h>
24 void SketchSolver_ConstraintMiddle::getAttributes(
25 EntityWrapperPtr& theValue,
26 std::vector<EntityWrapperPtr>& theAttributes)
28 SketchSolver_Constraint::getAttributes(theValue, theAttributes);
31 void SketchSolver_ConstraintMiddle::notify(const FeaturePtr& theFeature,
32 PlaneGCSSolver_Update* theUpdater)
34 if (theFeature == myBaseConstraint && myInSolver)
35 return; // the constraint is already being updated
37 PlaneGCSSolver_UpdateCoincidence* anUpdater =
38 static_cast<PlaneGCSSolver_UpdateCoincidence*>(theUpdater);
39 bool isAccepted = anUpdater->addCoincidence(myAttributes.front(), myAttributes.back());
45 // remove previously adde constraint
46 myStorage->removeConstraint(myBaseConstraint);
47 // merge divided constraints into single object
48 std::list<GCSConstraintPtr> aGCSConstraints;
49 std::shared_ptr<PlaneGCSSolver_ConstraintWrapper> aConstraint =
50 std::dynamic_pointer_cast<PlaneGCSSolver_ConstraintWrapper>(myMiddle);
51 aGCSConstraints.push_back(aConstraint->constraints().front());
53 std::dynamic_pointer_cast<PlaneGCSSolver_ConstraintWrapper>(mySolverConstraint);
54 aGCSConstraints.push_back(aConstraint->constraints().front());
56 myMiddle = ConstraintWrapperPtr();
57 mySolverConstraint = ConstraintWrapperPtr(
58 new PlaneGCSSolver_ConstraintWrapper(aGCSConstraints, CONSTRAINT_MIDDLE_POINT));
61 myStorage->addConstraint(myBaseConstraint, mySolverConstraint);
65 myStorage->removeConstraint(myBaseConstraint);
70 // divide solver constraints to the middle point and point-line coincidence
71 std::shared_ptr<PlaneGCSSolver_ConstraintWrapper> aConstraint =
72 std::dynamic_pointer_cast<PlaneGCSSolver_ConstraintWrapper>(mySolverConstraint);
73 std::list<GCSConstraintPtr> aGCSConstraints = aConstraint->constraints();
75 myMiddle = ConstraintWrapperPtr(
76 new PlaneGCSSolver_ConstraintWrapper(aGCSConstraints.front(), CONSTRAINT_MIDDLE_POINT));
77 mySolverConstraint = ConstraintWrapperPtr(
78 new PlaneGCSSolver_ConstraintWrapper(aGCSConstraints.back(), CONSTRAINT_MIDDLE_POINT));
80 // send middle constraint only
81 myStorage->addConstraint(myBaseConstraint, myMiddle);