From 1a4903cfcc3cf1d3a5408c1699f5781ca32f0add Mon Sep 17 00:00:00 2001 From: nds Date: Tue, 24 Jun 2014 16:58:41 +0400 Subject: [PATCH] refs #80 - Sketch base GUI: create/draw point, circle and arc Move for line constraint. Do not build line preview until both points are initialized. --- src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp | 7 +++---- src/SketchPlugin/SketchPlugin_ConstraintLength.cpp | 11 +++++++++++ src/SketchPlugin/SketchPlugin_ConstraintLength.h | 5 +++++ src/SketchPlugin/SketchPlugin_Line.cpp | 12 +++++++----- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp b/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp index d6e2b0075..1ff92e3fd 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp @@ -31,16 +31,15 @@ void SketchPlugin_ConstraintDistance::execute() boost::shared_ptr anAttr_B = boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_ENTITY_B)); - AttributeDoublePtr anAttribute = + AttributeDoublePtr anAttr_Value = boost::dynamic_pointer_cast(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); } } diff --git a/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp b/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp index 7218a5341..76563c003 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp @@ -31,3 +31,14 @@ const boost::shared_ptr& SketchPlugin_ConstraintLength::preview( return getPreview(); } +void SketchPlugin_ConstraintLength::move(double theDeltaX, double theDeltaY) +{ + boost::shared_ptr aData = data(); + if (!aData->isValid()) + return; + + boost::shared_ptr aPoint1 = + boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT)); + aPoint1->setValue(aPoint1->x() + theDeltaX, aPoint1->y() + theDeltaY); +} + diff --git a/src/SketchPlugin/SketchPlugin_ConstraintLength.h b/src/SketchPlugin/SketchPlugin_ConstraintLength.h index 57a5dbcc6..52719e765 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintLength.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintLength.h @@ -41,6 +41,11 @@ public: /// \brief Returns the sketch preview SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr& 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(); }; diff --git a/src/SketchPlugin/SketchPlugin_Line.cpp b/src/SketchPlugin/SketchPlugin_Line.cpp index 245440e22..f6d97fa21 100644 --- a/src/SketchPlugin/SketchPlugin_Line.cpp +++ b/src/SketchPlugin/SketchPlugin_Line.cpp @@ -40,14 +40,16 @@ const boost::shared_ptr& SketchPlugin_Line::preview() // compute a start point in 3D view boost::shared_ptr aStartAttr = boost::dynamic_pointer_cast(data()->attribute(LINE_ATTR_START)); - boost::shared_ptr aStart(aSketch->to3D(aStartAttr->x(), aStartAttr->y())); // compute an end point in 3D view boost::shared_ptr anEndAttr = boost::dynamic_pointer_cast(data()->attribute(LINE_ATTR_END)); - boost::shared_ptr anEnd(aSketch->to3D(anEndAttr->x(), anEndAttr->y())); - // make linear edge - boost::shared_ptr anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, anEnd); - setPreview(anEdge); + if (aStartAttr->isInitialized() && anEndAttr->isInitialized()) { + boost::shared_ptr aStart(aSketch->to3D(aStartAttr->x(), aStartAttr->y())); + boost::shared_ptr anEnd(aSketch->to3D(anEndAttr->x(), anEndAttr->y())); + // make linear edge + boost::shared_ptr anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, anEnd); + setPreview(anEdge); + } } return getPreview(); } -- 2.39.2