]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchSolver/SketchSolver_ConstraintMiddle.cpp
Salome HOME
Merge branch 'Dev_GroupsRevision'
[modules/shaper.git] / src / SketchSolver / SketchSolver_ConstraintMiddle.cpp
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #include <SketchSolver_ConstraintMiddle.h>
22 #include <PlaneGCSSolver_ConstraintWrapper.h>
23 #include <PlaneGCSSolver_UpdateCoincidence.h>
24
25 void SketchSolver_ConstraintMiddle::getAttributes(
26     EntityWrapperPtr& theValue,
27     std::vector<EntityWrapperPtr>& theAttributes)
28 {
29   SketchSolver_Constraint::getAttributes(theValue, theAttributes);
30 }
31
32 void SketchSolver_ConstraintMiddle::notify(const FeaturePtr&      theFeature,
33                                            PlaneGCSSolver_Update* theUpdater)
34 {
35   if (theFeature == myBaseConstraint && myInSolver)
36     return; // the constraint is already being updated
37
38   PlaneGCSSolver_UpdateCoincidence* anUpdater =
39       static_cast<PlaneGCSSolver_UpdateCoincidence*>(theUpdater);
40   bool isAccepted = anUpdater->addCoincidence(myAttributes.front(), myAttributes.back());
41   if (isAccepted) {
42     if (!myInSolver) {
43       myInSolver = true;
44
45       if (myMiddle) {
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());
53         aConstraint =
54             std::dynamic_pointer_cast<PlaneGCSSolver_ConstraintWrapper>(mySolverConstraint);
55         aGCSConstraints.push_back(aConstraint->constraints().front());
56
57         myMiddle = ConstraintWrapperPtr();
58         mySolverConstraint = ConstraintWrapperPtr(
59             new PlaneGCSSolver_ConstraintWrapper(aGCSConstraints, CONSTRAINT_MIDDLE_POINT));
60       }
61
62       myStorage->addConstraint(myBaseConstraint, mySolverConstraint);
63     }
64   } else {
65     if (myInSolver) {
66       myStorage->removeConstraint(myBaseConstraint);
67       myInSolver = false;
68     }
69
70     if (!myMiddle) {
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();
75
76       myMiddle = ConstraintWrapperPtr(
77           new PlaneGCSSolver_ConstraintWrapper(aGCSConstraints.front(), CONSTRAINT_MIDDLE_POINT));
78       mySolverConstraint = ConstraintWrapperPtr(
79           new PlaneGCSSolver_ConstraintWrapper(aGCSConstraints.back(), CONSTRAINT_MIDDLE_POINT));
80
81       // send middle constraint only
82       myStorage->addConstraint(myBaseConstraint, myMiddle);
83     }
84   }
85 }