1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: PlaneGCSSolver_Solver.cpp
4 // Created: 14 Dec 2014
5 // Author: Artem ZHIDKOV
7 #include "PlaneGCSSolver_Solver.h"
8 #include <Events_LongOp.h>
11 PlaneGCSSolver_Solver::~PlaneGCSSolver_Solver()
16 void PlaneGCSSolver_Solver::clear()
18 std::set<GCS::Constraint*>::const_iterator anIt = myConstraints.begin();
19 for (; anIt != myConstraints.end(); ++anIt)
20 myEquationSystem.removeConstraint(*anIt);
21 myConstraints.clear();
25 void PlaneGCSSolver_Solver::addConstraint(GCSConstraintPtr theConstraint)
27 GCS::Constraint* aConstraint = theConstraint.get();
28 if (myConstraints.find(aConstraint) != myConstraints.end())
29 return; // constraint already exists, no need to add it again
31 myEquationSystem.addConstraint(aConstraint);
32 myConstraints.insert(aConstraint);
35 void PlaneGCSSolver_Solver::removeConstraint(GCSConstraintPtr theConstraint)
37 GCS::Constraint* aConstraint = theConstraint.get();
38 if (myConstraints.find(aConstraint) == myConstraints.end())
39 return; // no constraint, no need to remove it
41 myEquationSystem.removeConstraint(aConstraint);
42 myConstraints.erase(aConstraint);
45 SketchSolver_SolveStatus PlaneGCSSolver_Solver::solve()
47 // clear list of conflicting constraints
48 if (myConfCollected) {
49 myConflictingIDs.clear();
50 myConfCollected = false;
53 if (myConstraints.empty())
54 return STATUS_EMPTYSET;
55 if (myParameters.empty())
56 return STATUS_INCONSISTENT;
58 Events_LongOp::start(this);
59 GCS::SolveStatus aResult = (GCS::SolveStatus)myEquationSystem.solve(myParameters);
60 Events_LongOp::end(this);
62 SketchSolver_SolveStatus aStatus;
63 if (aResult == GCS::Success) {
64 myEquationSystem.applySolution();
67 aStatus = STATUS_FAILED;
72 void PlaneGCSSolver_Solver::undo()
74 myEquationSystem.undoSolution();
77 bool PlaneGCSSolver_Solver::isConflicting(const ConstraintID& theConstraint) const
80 const_cast<PlaneGCSSolver_Solver*>(this)->collectConflicting();
82 GCS::VEC_I::const_iterator anIt = myConflictingIDs.begin();
83 for (; anIt != myConflictingIDs.end(); ++anIt)
84 if (*anIt == (int)theConstraint)
89 void PlaneGCSSolver_Solver::collectConflicting()
91 myEquationSystem.getConflicting(myConflictingIDs);
93 GCS::VEC_I aRedundantID;
94 myEquationSystem.getRedundant(aRedundantID);
95 myConflictingIDs.insert(myConflictingIDs.end(), aRedundantID.begin(), aRedundantID.end());
97 myConfCollected = true;