Move for line constraint. Do not build line preview until both points are initialized.
boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr_B =
boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_B));
- AttributeDoublePtr anAttribute =
+ AttributeDoublePtr anAttr_Value =
boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_VALUE));
-
- if (anAttr_A && anAttr_B && anAttribute->value() == 0)
+ if (anAttr_A && anAttr_B && !anAttr_Value->isInitialized())
{
FeaturePtr aFeature_A = anAttr_A->feature();
FeaturePtr aFeature_B = anAttr_B->feature();
double aValue = 40; // TODO
- anAttribute->setValue(aValue);
+ anAttr_Value->setValue(aValue);
}
}
return getPreview();
}
+void SketchPlugin_ConstraintLength::move(double theDeltaX, double theDeltaY)
+{
+ boost::shared_ptr<ModelAPI_Data> aData = data();
+ if (!aData->isValid())
+ return;
+
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint1 =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT));
+ aPoint1->setValue(aPoint1->x() + theDeltaX, aPoint1->y() + theDeltaY);
+}
+
/// \brief Returns the sketch preview
SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr<GeomAPI_Shape>& preview();
+ /// Moves the feature
+ /// \param theDeltaX the delta for X coordinate is moved
+ /// \param theDeltaY the delta for Y coordinate is moved
+ SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY);
+
/// \brief Use plugin manager for features creation
SketchPlugin_ConstraintLength();
};
// compute a start point in 3D view
boost::shared_ptr<GeomDataAPI_Point2D> aStartAttr =
boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(LINE_ATTR_START));
- boost::shared_ptr<GeomAPI_Pnt> aStart(aSketch->to3D(aStartAttr->x(), aStartAttr->y()));
// compute an end point in 3D view
boost::shared_ptr<GeomDataAPI_Point2D> anEndAttr =
boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(LINE_ATTR_END));
- boost::shared_ptr<GeomAPI_Pnt> anEnd(aSketch->to3D(anEndAttr->x(), anEndAttr->y()));
- // make linear edge
- boost::shared_ptr<GeomAPI_Shape> anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, anEnd);
- setPreview(anEdge);
+ if (aStartAttr->isInitialized() && anEndAttr->isInitialized()) {
+ boost::shared_ptr<GeomAPI_Pnt> aStart(aSketch->to3D(aStartAttr->x(), aStartAttr->y()));
+ boost::shared_ptr<GeomAPI_Pnt> anEnd(aSketch->to3D(anEndAttr->x(), anEndAttr->y()));
+ // make linear edge
+ boost::shared_ptr<GeomAPI_Shape> anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, anEnd);
+ setPreview(anEdge);
+ }
}
return getPreview();
}