The procedure of movement is changed. Any part of object can be moved separately.
SketchSolver_ConstraintTangent.h
SketchSolver_ConstraintMultiRotation.h
SketchSolver_ConstraintMultiTranslation.h
+ SketchSolver_ConstraintMovement.h
SketchSolver_Builder.h
SketchSolver_Group.h
SketchSolver_ConstraintManager.h
SketchSolver_ConstraintTangent.cpp
SketchSolver_ConstraintMultiRotation.cpp
SketchSolver_ConstraintMultiTranslation.cpp
+ SketchSolver_ConstraintMovement.cpp
SketchSolver_Builder.cpp
SketchSolver_Group.cpp
SketchSolver_ConstraintManager.cpp
#include <SketchSolver_ConstraintTangent.h>
#include <SketchSolver_ConstraintMultiRotation.h>
#include <SketchSolver_ConstraintMultiTranslation.h>
+#include <SketchSolver_ConstraintMovement.h>
#include <SketchSolver_Error.h>
#include <GeomAPI_Edge.h>
return SolverConstraintPtr(new SketchSolver_ConstraintRigid(theFixedFeature));
}
+SolverConstraintPtr SketchSolver_Builder::createMovementConstraint(FeaturePtr theFixedFeature)
+{
+ DataPtr aData = theFixedFeature->data();
+ if (!aData || !aData->isValid())
+ return SolverConstraintPtr();
+ return SolverConstraintPtr(new SketchSolver_ConstraintMovement(theFixedFeature));
+}
+
bool SketchSolver_Builder::createWorkplane(
/// \brief Creates temporary constraint to fix the placement of the feature
SolverConstraintPtr createRigidConstraint(FeaturePtr theFixedFeature);
+ /// \brief Creates temporary constraint to fix the feature after movement
+ SolverConstraintPtr createMovementConstraint(FeaturePtr theFixedFeature);
+
/// \brief Converts sketch parameters to the list of SolveSpace entities.
/// Identifiers of entities and parameters are local. They should be changed while adding into storage.
/// The sketch entity goes last.
--- /dev/null
+#include <SketchSolver_ConstraintMovement.h>
+#include <SketchSolver_Error.h>
+#include <SketchSolver_Group.h>
+
+#include <GeomDataAPI_Point2D.h>
+
+SketchSolver_ConstraintMovement::SketchSolver_ConstraintMovement(FeaturePtr theFeature)
+ : SketchSolver_ConstraintRigid(theFeature)
+{
+ process();
+}
+
+void SketchSolver_ConstraintMovement::process()
+{
+ cleanErrorMsg();
+ if (!myBaseFeature || !myStorage || myGroup == 0) {
+ /// TODO: Put error message here
+ return;
+ }
+ if (!mySlvsConstraints.empty()) // some data is changed, update constraint
+ update(myBaseConstraint);
+
+ double aValue;
+ std::vector<Slvs_hEntity> anEntities;
+ bool isFullyMoved;
+ getAttributes(aValue, anEntities, isFullyMoved);
+ if (!myErrorMsg.empty() || (myFeatureMap.empty() && myAttributeMap.empty()))
+ return;
+
+ if (isFullyMoved)
+ fixFeature();
+ else {
+ std::vector<Slvs_hEntity>::iterator anEntIt = anEntities.begin();
+ for (; anEntIt != anEntities.end(); ++anEntIt)
+ fixPoint(*anEntIt);
+ }
+}
+
+
+void SketchSolver_ConstraintMovement::getAttributes(
+ double& theValue,
+ std::vector<Slvs_hEntity>& theAttributes,
+ bool& theIsFullyMoved)
+{
+ theValue = 0.0;
+ theIsFullyMoved = true;
+ int aType = SLVS_E_UNKNOWN; // type of created entity
+ Slvs_hEntity anEntityID = SLVS_E_UNKNOWN;
+ anEntityID = myGroup->getFeatureId(myBaseFeature);
+ if (anEntityID == SLVS_E_UNKNOWN) {
+ anEntityID = changeEntity(myBaseFeature, aType);
+ if (anEntityID == SLVS_E_UNKNOWN) {
+ myErrorMsg = SketchSolver_Error::NOT_INITIALIZED();
+ return;
+ }
+
+ // Check the entity is complex
+ Slvs_Entity anEntity = myStorage->getEntity(anEntityID);
+ if (anEntity.point[0] != SLVS_E_UNKNOWN) {
+ for (int i = 0; i < 4 && anEntity.point[i]; i++)
+ theAttributes.push_back(anEntity.point[i]);
+ } else // simple entity
+ theAttributes.push_back(anEntityID);
+ }
+ else {
+ myFeatureMap[myBaseFeature] = anEntityID;
+
+ std::list<AttributePtr> aPoints =
+ myBaseFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
+ std::list<AttributePtr>::iterator anIt = aPoints.begin();
+ for (; anIt != aPoints.end(); ++anIt) {
+ Slvs_hEntity anAttr = myGroup->getAttributeId(*anIt);
+
+ // Check the attribute changes coordinates
+ Slvs_Entity anAttrEnt = myStorage->getEntity(anAttr);
+ double aDeltaX = myStorage->getParameter(anAttrEnt.param[0]).val;
+ double aDeltaY = myStorage->getParameter(anAttrEnt.param[1]).val;
+ std::shared_ptr<GeomDataAPI_Point2D> aPt =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(*anIt);
+ aDeltaX -= aPt->x();
+ aDeltaY -= aPt->y();
+ if (aDeltaX * aDeltaX + aDeltaY * aDeltaY >= tolerance * tolerance)
+ theAttributes.push_back(anAttr);
+ else
+ theIsFullyMoved = false;
+ }
+ }
+}
+
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: SketchSolver_ConstraintMovement.h
+// Created: 15 Jun 2015
+// Author: Artem ZHIDKOV
+
+#ifndef SketchSolver_ConstraintMovement_H_
+#define SketchSolver_ConstraintMovement_H_
+
+#include "SketchSolver.h"
+#include <SketchSolver_ConstraintRigid.h>
+
+/** \class SketchSolver_ConstraintMovement
+ * \ingroup Plugins
+ * \brief Stores data of Rigid (Fixed) constraint for the moved feature only
+ */
+class SketchSolver_ConstraintMovement : public SketchSolver_ConstraintRigid
+{
+private:
+ /// Creates constraint to manage the given constraint from plugin
+ SketchSolver_ConstraintMovement(ConstraintPtr theConstraint)
+ : SketchSolver_ConstraintRigid(theConstraint)
+ {}
+
+public:
+ /// Creates temporary constraint based on feature
+ SketchSolver_ConstraintMovement(FeaturePtr theFeature);
+
+protected:
+ /// \brief Converts SketchPlugin constraint to a list of SolveSpace constraints
+ virtual void process();
+
+ /// \brief Generate list of attributes of constraint in order useful for SolveSpace constraints
+ /// \param[out] theValue numerical characteristic of constraint (e.g. distance)
+ /// \param[out] theAttributes list of attributes to be filled
+ /// \param[out] theIsFullyMoved shows that the feature is moved, in other case only one point of the feature is shifted
+ virtual void getAttributes(double& theValue, std::vector<Slvs_hEntity>& theAttributes, bool& theIsFullyMoved);
+};
+
+#endif
getAttributes(aValue, anEntities);
if (!myErrorMsg.empty() || (myFeatureMap.empty() && myAttributeMap.empty()))
return;
+ fixFeature();
+}
- Slvs_hEntity anEntID;
+void SketchSolver_ConstraintRigid::fixFeature()
+{
+ Slvs_hEntity anEntID;
if (!myFeatureMap.empty())
anEntID = myFeatureMap.begin()->second;
else
/// E.g. the distance between line and point may be signed.
virtual void adjustConstraint();
+ /// \brief Fixed feature basing on its type
+ void fixFeature();
+
+ /// \brief Fix given point
+ void fixPoint(const Slvs_hEntity& thePointID);
+
private:
/// \brief Fixing line position (start and end points)
void fixLine(const Slvs_Entity& theLine);
/// There will be fixed start and end points and the radius of the arc.
void fixArc(const Slvs_Entity& theArc);
- /// \brief Fix given point
- void fixPoint(const Slvs_hEntity& thePointID);
-
/// \brief Verifies the entity is used in any equal constraint
/// \param[in] theEntity entity to be found
/// \param[out] theEqual constraint, which uses the entity
{
// Firstly, create temporary rigid constraint
SolverConstraintPtr aConstraint =
- SketchSolver_Builder::getInstance()->createRigidConstraint(theFeature);
+ SketchSolver_Builder::getInstance()->createMovementConstraint(theFeature);
if (!aConstraint)
return;
aConstraint->setGroup(this);