SketchSolver_ConstraintDistance.h
SketchSolver_ConstraintEqual.h
SketchSolver_ConstraintLength.h
+ SketchSolver_ConstraintMiddle.h
SketchSolver_ConstraintMirror.h
SketchSolver_ConstraintFixed.h
SketchSolver_ConstraintFixedArcRadius.h
SketchSolver_ConstraintDistance.cpp
SketchSolver_ConstraintEqual.cpp
SketchSolver_ConstraintLength.cpp
+ SketchSolver_ConstraintMiddle.cpp
SketchSolver_ConstraintMirror.cpp
SketchSolver_ConstraintFixed.cpp
SketchSolver_ConstraintFixedArcRadius.cpp
/// \brief Return list of constraints
const std::list<GCSConstraintPtr>& constraints() const
{ return myGCSConstraints; }
+ /// \brief Change list of constraints
+ void setConstraints(const std::list<GCSConstraintPtr>& theConstraints)
+ { myGCSConstraints = theConstraints; }
/// \brief Return ID of current entity
virtual ConstraintID id() const
for (; anIt != anEntities.end(); ++anIt)
isUpdated = update(*anIt) || isUpdated;
- // Change ID of constraints
- if (aConstraint->id() == CID_UNKNOWN)
+ if (aConstraint->id() == CID_UNKNOWN) {
+ const std::list<EntityWrapperPtr>& aSubs = aConstraint->entities();
+ // check middle-point constraint conflicts with point-on-line
+ if (aConstraint->type() == CONSTRAINT_MIDDLE_POINT) {
+ std::map<ConstraintPtr, std::list<ConstraintWrapperPtr> >::const_iterator
+ anIt = myConstraintMap.begin();
+ for (; anIt != myConstraintMap.end(); ++anIt) {
+ EntityWrapperPtr aPoint, aLine;
+ ConstraintWrapperPtr aCurrentConstr = anIt->second.front();
+ if (aCurrentConstr->type() != CONSTRAINT_PT_ON_LINE)
+ continue;
+ const std::list<EntityWrapperPtr>& aCurSubs = aCurrentConstr->entities();
+ std::list<EntityWrapperPtr>::const_iterator aSIt1, aSIt2;
+ for (aSIt1 = aSubs.begin(); aSIt1 != aSubs.end(); ++aSIt1) {
+ if ((*aSIt1)->type() == ENTITY_POINT)
+ aPoint = *aSIt1;
+ else if((*aSIt1)->type() == ENTITY_LINE)
+ aLine = *aSIt1;
+ else
+ continue;
+ for (aSIt2 = aCurSubs.begin(); aSIt2 != aCurSubs.end(); ++aSIt2)
+ if ((*aSIt1)->id() == (*aSIt2)->id())
+ break;
+ if (aSIt2 == aCurSubs.end())
+ break;
+ }
+ // point-on-line found, change it to bisector
+ if (aSIt1 == aSubs.end()) {
+ std::list<GCSConstraintPtr> aConstrList = aConstraint->constraints();
+ aConstrList.pop_front();
+ aConstraint->setConstraints(aConstrList);
+ break;
+ }
+ }
+ }
+
+ // Change ID of constraints
aConstraint->setId(++myConstraintLastID);
+ }
return isUpdated;
}
#include <SketchSolver_ConstraintFixed.h>
#include <SketchSolver_ConstraintFixedArcRadius.h>
#include <SketchSolver_ConstraintLength.h>
+#include <SketchSolver_ConstraintMiddle.h>
#include <SketchSolver_ConstraintMirror.h>
#include <SketchSolver_ConstraintTangent.h>
#include <SketchSolver_ConstraintMultiRotation.h>
#include <SketchPlugin_ConstraintDistance.h>
#include <SketchPlugin_ConstraintEqual.h>
#include <SketchPlugin_ConstraintLength.h>
+#include <SketchPlugin_ConstraintMiddle.h>
#include <SketchPlugin_ConstraintMirror.h>
#include <SketchPlugin_ConstraintRigid.h>
#include <SketchPlugin_ConstraintTangent.h>
return SolverConstraintPtr(new SketchSolver_ConstraintEqual(theConstraint));
} else if (theConstraint->getKind() == SketchPlugin_ConstraintLength::ID()) {
return SolverConstraintPtr(new SketchSolver_ConstraintLength(theConstraint));
+ } else if (theConstraint->getKind() == SketchPlugin_ConstraintMiddle::ID()) {
+ return SolverConstraintPtr(new SketchSolver_ConstraintMiddle(theConstraint));
} else if (theConstraint->getKind() == SketchPlugin_ConstraintMirror::ID()) {
return SolverConstraintPtr(new SketchSolver_ConstraintMirror(theConstraint));
} else if (theConstraint->getKind() == SketchPlugin_ConstraintTangent::ID()) {
--- /dev/null
+#include <SketchSolver_ConstraintMiddle.h>
+
+SketchSolver_ConstraintMiddle::SketchSolver_ConstraintMiddle(ConstraintPtr theConstraint)
+ : SketchSolver_Constraint(theConstraint)
+{
+}
+
+void SketchSolver_ConstraintMiddle::notifyCoincidenceChanged(
+ EntityWrapperPtr theCoincAttr1,
+ EntityWrapperPtr theCoincAttr2)
+{
+ // Check the coincidence between point and line has been changed
+ AttributePtr aPoint;
+ FeaturePtr aLine;
+ EntityWrapperPtr anEntities[2] = {theCoincAttr1, theCoincAttr2};
+ for (int i = 0; i < 2; ++i) {
+ if (anEntities[i]->type() == ENTITY_POINT)
+ aPoint = anEntities[i]->baseAttribute();
+ else if (anEntities[i]->type() == ENTITY_LINE)
+ aLine = anEntities[i]->baseFeature();
+ }
+ if (!aPoint || !aLine)
+ return;
+
+ // Check the attributes of middle-point constraint are the same point and line
+ bool isSameAttr = true;
+ for (int i = 0; i < 2 && isSameAttr; ++i) {
+ AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+ myBaseConstraint->attribute(SketchPlugin_Constraint::ATTRIBUTE(i)));
+ if (aRefAttr->isObject()) {
+ FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object());
+ isSameAttr = (aFeature == aLine);
+ } else
+ isSameAttr = (aRefAttr->attr() == aPoint);
+ }
+
+ if (isSameAttr) {
+ remove();
+ process();
+ }
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: SketchSolver_ConstraintMiddle.h
+// Created: 03 March 2016
+// Author: Artem ZHIDKOV
+
+#ifndef SketchSolver_ConstraintMiddle_H_
+#define SketchSolver_ConstraintMiddle_H_
+
+#include <SketchSolver_Constraint.h>
+
+/** \class SketchSolver_ConstraintMiddle
+ * \ingroup Plugins
+ * \brief Converts middle-point constraint to the constraint applicable for solver
+ */
+class SketchSolver_ConstraintMiddle : public SketchSolver_Constraint
+{
+public:
+ /// Constructor based on SketchPlugin constraint
+ SKETCHSOLVER_EXPORT SketchSolver_ConstraintMiddle(ConstraintPtr theConstraint);
+
+ virtual ~SketchSolver_ConstraintMiddle() {}
+
+ /// \brief Notify constraint, that coincidence appears or removed
+ virtual void notifyCoincidenceChanged(EntityWrapperPtr theCoincAttr1, EntityWrapperPtr theCoincAttr2);
+};
+
+#endif
// Constraint is not found, add new one
Slvs_Constraint aConstraint = theConstraint;
aConstraint.h = 0;
+
+ // Firstly, check middle-point constraint conflicts with point-on-line
+ if (aConstraint.type == SLVS_C_AT_MIDPOINT) {
+ std::vector<Slvs_Constraint>::const_iterator anIt = myConstraints.begin();
+ for (; anIt != myConstraints.end(); ++anIt)
+ if (anIt->type == SLVS_C_PT_ON_LINE &&
+ anIt->ptA == aConstraint.ptA &&
+ anIt->entityA == aConstraint.entityA)
+ break;
+ if (anIt != myConstraints.end()) {
+ // change the constraint to the lengths equality to avoid conflicts
+ Slvs_Entity aLine = getEntity(aConstraint.entityA);
+ Slvs_Entity aNewLine1 = Slvs_MakeLineSegment(SLVS_E_UNKNOWN, myGroupID,
+ myWorkplaneID, aLine.point[0], aConstraint.ptA);
+ aNewLine1.h = addEntity(aNewLine1);
+ Slvs_Entity aNewLine2 = Slvs_MakeLineSegment(SLVS_E_UNKNOWN, myGroupID,
+ myWorkplaneID, aLine.point[1], aConstraint.ptA);
+ aNewLine2.h = addEntity(aNewLine2);
+ aConstraint = Slvs_MakeConstraint(SLVS_E_UNKNOWN, myGroupID, SLVS_C_EQUAL_LENGTH_LINES,
+ myWorkplaneID, 0.0, SLVS_E_UNKNOWN, SLVS_E_UNKNOWN, aNewLine1.h, aNewLine2.h);
+ }
+ }
+
return addConstraint(aConstraint);
}