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 email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
20 #include <SketchSolver_ConstraintEqual.h>
21 #include <SketchSolver_Error.h>
22 #include <PlaneGCSSolver_AttributeBuilder.h>
24 #include <ModelAPI_AttributeRefAttr.h>
25 #include <SketchPlugin_Line.h>
27 void SketchSolver_ConstraintEqual::getAttributes(
28 EntityWrapperPtr& theValue,
29 std::vector<EntityWrapperPtr>& theAttributes)
31 SketchSolver_Constraint::getAttributes(theValue, theAttributes);
32 if (!myErrorMsg.empty() || !theAttributes[2] || !theAttributes[3]) {
33 theAttributes.clear();
37 // Check the quantity of entities of each type
41 bool isArcFirst = false; // in line-arc equivalence, the line should be first
42 std::vector<EntityWrapperPtr>::iterator anAttrIt = theAttributes.begin() + 2;
43 for (; anAttrIt != theAttributes.end(); ++anAttrIt) {
44 SketchSolver_EntityType aType = (*anAttrIt)->type();
45 if (aType == ENTITY_LINE)
47 else if (aType == ENTITY_CIRCLE)
49 else if (aType == ENTITY_ARC) {
51 isArcFirst = (aNbLines == 0);
55 if (aNbLines + aNbArcs + aNbCircs != 2 ||
56 (aNbLines == aNbCircs && aNbArcs == 0)) {
57 myErrorMsg = SketchSolver_Error::INCORRECT_ATTRIBUTE();
63 myType = CONSTRAINT_EQUAL_RADIUS;
66 myType = CONSTRAINT_EQUAL_LINE_ARC;
67 if (isArcFirst) { // change the order of arc and line
68 EntityWrapperPtr aTmp = theAttributes[2];
69 theAttributes[2] = theAttributes[3];
70 theAttributes[3] = aTmp;
74 myType = CONSTRAINT_EQUAL_LINES;
76 AttributeRefAttrPtr aRefLine1 =
77 myBaseConstraint->refattr(SketchPlugin_Constraint::ENTITY_A());
78 FeaturePtr aLine1 = ModelAPI_Feature::feature(aRefLine1->object());
80 PlaneGCSSolver_AttributeBuilder aBuilder(myStorage);
81 // store length of first line as a value for constraint
82 // (will be used to make equal lengths of lines)
83 theValue = aBuilder.createAttribute(aLine1->attribute(SketchPlugin_Line::LENGTH_ID()));