+// Copyright (C) 2014-2024 CEA, EDF
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
#include <SketchSolver_ConstraintLength.h>
-#include <SketchSolver_Group.h>
#include <SketchSolver_Error.h>
+#include <SketchPlugin_Line.h>
+
-void SketchSolver_ConstraintLength::process()
+void SketchSolver_ConstraintLength::getAttributes(
+ EntityWrapperPtr& theValue,
+ std::vector<EntityWrapperPtr>& theAttributes)
{
- cleanErrorMsg();
- if (!myBaseConstraint || !myStorage || myGroup == 0) {
- /// TODO: Put error message here
+ SketchSolver_Constraint::getAttributes(theValue, theAttributes);
+ if (!myErrorMsg.empty() || !theAttributes[2] ||
+ theAttributes[2]->type() != ENTITY_LINE) {
+ theAttributes.clear();
return;
}
- if (!mySlvsConstraints.empty()) // some data is changed, update constraint
- update(myBaseConstraint);
- double aValue;
- std::vector<Slvs_hEntity> anEntities;
- getAttributes(aValue, anEntities);
- if (!myErrorMsg.empty())
- return;
+ AttributeRefAttrPtr aRefAttr = myBaseConstraint->refattr(SketchPlugin_Constraint::ENTITY_A());
+ FeaturePtr aLine = ModelAPI_Feature::feature(aRefAttr->object());
- // Check the entity is a line
- Slvs_Entity aLine = myStorage->getEntity(anEntities[2]);
- if (aLine.type != SLVS_E_LINE_SEGMENT){
- myErrorMsg = SketchSolver_Error::INCORRECT_ATTRIBUTE();
- return;
- }
+ theAttributes[0] = myStorage->entity(aLine->attribute(SketchPlugin_Line::START_ID()));
+ theAttributes[1] = myStorage->entity(aLine->attribute(SketchPlugin_Line::END_ID()));
- Slvs_Constraint aConstraint = Slvs_MakeConstraint(SLVS_C_UNKNOWN, myGroup->getId(),
- getType(), myGroup->getWorkplaneId(), aValue,
- aLine.point[0], aLine.point[1], SLVS_E_UNKNOWN, SLVS_E_UNKNOWN);
- aConstraint.h = myStorage->addConstraint(aConstraint);
- mySlvsConstraints.push_back(aConstraint.h);
- adjustConstraint();
+ myType = CONSTRAINT_PT_PT_DISTANCE;
}