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_EdgeWrapper.h>
23 #include <PlaneGCSSolver_PointWrapper.h>
24 #include <PlaneGCSSolver_Storage.h>
25 #include <PlaneGCSSolver_Tools.h>
26 #include <PlaneGCSSolver_UpdateCoincidence.h>
28 void SketchSolver_ConstraintMiddle::getAttributes(
29 EntityWrapperPtr& theValue,
30 std::vector<EntityWrapperPtr>& theAttributes)
32 SketchSolver_Constraint::getAttributes(theValue, theAttributes);
34 // create auxiliary point if middle point on arc is specified
35 if (theAttributes[2]->type() == ENTITY_ARC) {
36 std::shared_ptr<PlaneGCSSolver_Storage> aStorage =
37 std::dynamic_pointer_cast<PlaneGCSSolver_Storage>(myStorage);
39 myOddPoint = GCSPointPtr(new GCS::Point);
40 myOddPoint->x = aStorage->createParameter();
41 myOddPoint->y = aStorage->createParameter();
42 theAttributes[1] = PointWrapperPtr(new PlaneGCSSolver_PointWrapper(myOddPoint));
46 bool SketchSolver_ConstraintMiddle::remove()
49 std::shared_ptr<PlaneGCSSolver_Storage> aStorage =
50 std::dynamic_pointer_cast<PlaneGCSSolver_Storage>(myStorage);
53 aParams.insert(myOddPoint->x);
54 aParams.insert(myOddPoint->y);
55 aStorage->removeParameters(aParams);
57 return SketchSolver_ConstraintCoincidence::remove();
60 void SketchSolver_ConstraintMiddle::notify(const FeaturePtr& theFeature,
61 PlaneGCSSolver_Update* theUpdater)
63 if (theFeature == myBaseConstraint && myInSolver) {
64 // the constraint is already being updated,
65 // update the middle point parameter if the constraint is "point-on-arc".
67 EntityWrapperPtr anArcEntity =
68 myAttributes.front()->type() == ENTITY_ARC ? myAttributes.front() : myAttributes.back();
69 EdgeWrapperPtr anArcEdge =
70 std::dynamic_pointer_cast<PlaneGCSSolver_EdgeWrapper>(anArcEntity);
71 std::shared_ptr<GCS::Arc> anArc;
73 anArc = std::dynamic_pointer_cast<GCS::Arc>(anArcEdge->entity());
75 // recalculate parameters of middle point according to arc
76 *myOddPoint->x = (*anArc->startAngle + *anArc->endAngle) * 0.5;
77 *myOddPoint->y = (*anArc->endAngle - *anArc->startAngle) * 0.5;
83 PlaneGCSSolver_UpdateCoincidence* anUpdater =
84 static_cast<PlaneGCSSolver_UpdateCoincidence*>(theUpdater);
85 bool isAccepted = anUpdater->addCoincidence(myAttributes.front(), myAttributes.back());
91 // remove previously adde constraint
92 myStorage->removeConstraint(myBaseConstraint);
93 // merge divided constraints into single object
94 std::list<GCSConstraintPtr> aGCSConstraints = myMiddle->constraints();
95 aGCSConstraints.push_front(mySolverConstraint->constraints().front());
97 myMiddle = ConstraintWrapperPtr();
98 mySolverConstraint = ConstraintWrapperPtr(
99 new PlaneGCSSolver_ConstraintWrapper(aGCSConstraints, CONSTRAINT_MIDDLE_POINT));
102 myStorage->addConstraint(myBaseConstraint, mySolverConstraint);
106 myStorage->removeConstraint(myBaseConstraint);
111 // divide solver constraints to the middle point and point-line coincidence
112 std::shared_ptr<PlaneGCSSolver_ConstraintWrapper> aConstraint =
113 std::dynamic_pointer_cast<PlaneGCSSolver_ConstraintWrapper>(mySolverConstraint);
114 std::list<GCSConstraintPtr> aGCSConstraints = aConstraint->constraints();
116 mySolverConstraint = ConstraintWrapperPtr(
117 new PlaneGCSSolver_ConstraintWrapper(aGCSConstraints.front(), CONSTRAINT_MIDDLE_POINT));
118 aGCSConstraints.pop_front();
119 myMiddle = ConstraintWrapperPtr(
120 new PlaneGCSSolver_ConstraintWrapper(aGCSConstraints, CONSTRAINT_MIDDLE_POINT));
122 // send middle constraint only
123 myStorage->addConstraint(myBaseConstraint, myMiddle);