Improve working with coincident points.
SketchSolver_Constraint.h
SketchSolver_ConstraintAngle.h
SketchSolver_ConstraintCoincidence.h
+ SketchSolver_ConstraintCollinear.h
SketchSolver_ConstraintDistance.h
SketchSolver_ConstraintEqual.h
SketchSolver_ConstraintLength.h
SketchSolver_Constraint.cpp
SketchSolver_ConstraintAngle.cpp
SketchSolver_ConstraintCoincidence.cpp
+ SketchSolver_ConstraintCollinear.cpp
SketchSolver_ConstraintDistance.cpp
SketchSolver_ConstraintEqual.cpp
SketchSolver_ConstraintLength.cpp
#include <SketchSolver_Constraint.h>
#include <SketchSolver_ConstraintAngle.h>
#include <SketchSolver_ConstraintCoincidence.h>
+#include <SketchSolver_ConstraintCollinear.h>
#include <SketchSolver_ConstraintDistance.h>
#include <SketchSolver_ConstraintEqual.h>
#include <SketchSolver_ConstraintFixed.h>
#include <SketchPlugin_ConstraintAngle.h>
#include <SketchPlugin_ConstraintCoincidence.h>
+#include <SketchPlugin_ConstraintCollinear.h>
#include <SketchPlugin_ConstraintDistance.h>
#include <SketchPlugin_ConstraintEqual.h>
#include <SketchPlugin_ConstraintLength.h>
if (theConstraint->getKind() == SketchPlugin_ConstraintCoincidence::ID()) {
return SolverConstraintPtr(new SketchSolver_ConstraintCoincidence(theConstraint));
+ } else if (theConstraint->getKind() == SketchPlugin_ConstraintCollinear::ID()) {
+ return SolverConstraintPtr(new SketchSolver_ConstraintCollinear(theConstraint));
} else if (theConstraint->getKind() == SketchPlugin_ConstraintDistance::ID()) {
return SolverConstraintPtr(new SketchSolver_ConstraintDistance(theConstraint));
} else if (theConstraint->getKind() == SketchPlugin_ConstraintEqual::ID()) {
{
static const int anInitNbOfAttr = 4;
theAttributes.assign(anInitNbOfAttr, EntityWrapperPtr());
+ myAttributes.clear();
DataPtr aData = myBaseConstraint->data();
BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
myStorage->update(*anIter/*, myGroupID*/);
EntityWrapperPtr anEntity = myStorage->entity(*anIter);
+ myAttributes.push_back(anEntity);
SketchSolver_EntityType aType = anEntity->type();
if (aType == ENTITY_UNKNOWN)
virtual SketchSolver_ConstraintType getType() const
{ return myType; }
+ /// \brief Returns list of attributes of constraint
+ const std::list<EntityWrapperPtr>& attributes() const
+ { return myAttributes; }
+
/// \brief Verify the feature or any its attribute is used by constraint
virtual bool isUsed(FeaturePtr theFeature) const;
/// \brief Verify the attribute is used by constraint
virtual bool isUsed(AttributePtr theAttribute) const;
+ /// \brief Notify constraint, that coincidence appears or removed
+ virtual void notifyCoincidenceChanged(EntityWrapperPtr theCoincAttr1, EntityWrapperPtr theCoincAttr2)
+ { /* implement in derived class */ }
+
/// \brief Shows error message
const std::string& error() const
{ return myErrorMsg; }
ConstraintPtr myBaseConstraint; ///< base SketchPlugin constraint
StoragePtr myStorage; ///< storage, which contains all information about entities and constraints
SketchSolver_ConstraintType myType; ///< type of constraint
+ std::list<EntityWrapperPtr> myAttributes; ///< attributes of constraint
std::string myErrorMsg; ///< error message
};
--- /dev/null
+#include <SketchSolver_ConstraintCollinear.h>
+#include <SketchSolver_Manager.h>
+
+#include <SketchPlugin_Line.h>
+
+SketchSolver_ConstraintCollinear::SketchSolver_ConstraintCollinear(ConstraintPtr theConstraint)
+ : SketchSolver_Constraint(theConstraint)
+{
+}
+
+void SketchSolver_ConstraintCollinear::notifyCoincidenceChanged(
+ EntityWrapperPtr theCoincAttr1,
+ EntityWrapperPtr theCoincAttr2)
+{
+ bool used = true;
+
+ // obtain IDs of all boundary points of lines
+ EntityID aPointIDs[4];
+ for (int i = 0; i < 2; ++i) {
+ AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+ myBaseConstraint->attribute(SketchPlugin_Constraint::ATTRIBUTE(i)));
+ if (!aRefAttr->object())
+ continue;
+ FeaturePtr aLine = ModelAPI_Feature::feature(aRefAttr->object());
+ AttributePtr aLinePt = aLine->attribute(SketchPlugin_Line::START_ID());
+ aPointIDs[2*i] = myStorage->entity(aLinePt)->id();
+ aLinePt = aLine->attribute(SketchPlugin_Line::END_ID());
+ aPointIDs[2*i + 1] = myStorage->entity(aLinePt)->id();
+ }
+
+ EntityWrapperPtr anAttrs[2] = {theCoincAttr1, theCoincAttr2};
+ for (int i = 0; i < 2 && used; ++i) {
+ if (anAttrs[i]->baseAttribute())
+ used = used && isUsed(anAttrs[i]->baseAttribute());
+ else
+ used = used && isUsed(anAttrs[i]->baseFeature());
+
+ if (!used) {
+ if (anAttrs[i]->type() == ENTITY_POINT) {
+ EntityID anID = anAttrs[i]->id();
+ for (int j = 0; j < 4; ++j)
+ if (anID == aPointIDs[j]) {
+ used = true;
+ break;
+ }
+ }
+ }
+ }
+
+ if (used) {
+ remove();
+ process();
+ }
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: SketchSolver_ConstraintCollinear.h
+// Created: 27 May 2014
+// Author: Artem ZHIDKOV
+
+#ifndef SketchSolver_ConstraintCollinear_H_
+#define SketchSolver_ConstraintCollinear_H_
+
+#include <SketchSolver_Constraint.h>
+
+/** \class SketchSolver_ConstraintCollinear
+ * \ingroup Plugins
+ * \brief Converts collinear constraint to the constraint applicable for solver
+ */
+class SketchSolver_ConstraintCollinear : public SketchSolver_Constraint
+{
+public:
+ /// Constructor based on SketchPlugin constraint
+ SKETCHSOLVER_EXPORT SketchSolver_ConstraintCollinear(ConstraintPtr theConstraint);
+
+ virtual ~SketchSolver_ConstraintCollinear() {}
+
+ /// \brief Notify constraint, that coincidence appears or removed
+ virtual void notifyCoincidenceChanged(EntityWrapperPtr theCoincAttr1, EntityWrapperPtr theCoincAttr2);
+};
+
+#endif
Events_Error::send(aConstraint->error(), this);
}
myConstraints[theConstraint] = aConstraint;
+
+ if (theConstraint->getKind() == SketchPlugin_ConstraintCoincidence::ID())
+ notifyCoincidenceChanged(myConstraints[theConstraint]);
}
else
myConstraints[theConstraint]->update();
for (; aCIter != myConstraints.end(); aCIter++)
if (aCIter->first == theConstraint) {
aCIter->second->remove(); // the constraint is not fully removed
+ if (aCIter->first->getKind() == SketchPlugin_ConstraintCoincidence::ID())
+ notifyCoincidenceChanged(aCIter->second);
break;
}
if (aCIter != myConstraints.end())
return aResult;
}
+void SketchSolver_Group::notifyCoincidenceChanged(SolverConstraintPtr theCoincidence)
+{
+ const std::list<EntityWrapperPtr>& aCoincident = theCoincidence->attributes();
+ EntityWrapperPtr anAttr1 = aCoincident.front();
+ EntityWrapperPtr anAttr2 = aCoincident.back();
+
+ ConstraintConstraintMap::iterator anIt = myConstraints.begin();
+ for (; anIt != myConstraints.end(); ++anIt)
+ anIt->second->notifyCoincidenceChanged(anAttr1, anAttr2);
+}
/// \brief Verifies is the feature valid
bool checkFeatureValidity(FeaturePtr theFeature);
+ /// \brief Notify all interested constraints that coincidence appears or removed
+ /// \param[in] theCoincidence coincidence constraint
+ void notifyCoincidenceChanged(SolverConstraintPtr theCoincidence);
+
private:
GroupID myID; ///< Index of the group
EntityID myWorkplaneID; ///< Index of workplane, the group is based on