From e32f95642855a63da2727cb324ce2a75632a712f Mon Sep 17 00:00:00 2001 From: azv Date: Wed, 27 Apr 2016 14:05:20 +0300 Subject: [PATCH] Update SketchPlugin_Projection feature (issue #1459) --- src/SketchPlugin/SketchPlugin_Projection.cpp | 28 ++++++++++++++++---- src/SketchPlugin/plugin-Sketch.xml | 1 + 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/SketchPlugin/SketchPlugin_Projection.cpp b/src/SketchPlugin/SketchPlugin_Projection.cpp index 9adacbb67..6240c933b 100644 --- a/src/SketchPlugin/SketchPlugin_Projection.cpp +++ b/src/SketchPlugin/SketchPlugin_Projection.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -55,7 +56,7 @@ void SketchPlugin_Projection::execute() if (!lastResult().get()) { ResultConstructionPtr aConstr = document()->createConstruction(data()); - aConstr->setShape(std::shared_ptr()); + aConstr->setShape(aProjection->lastResult()->shape()); aConstr->setIsInHistory(false); setResult(aConstr); @@ -75,6 +76,16 @@ void SketchPlugin_Projection::attributeChanged(const std::string& theID) computeProjection(theID); myIsComputing = false; } + else if (theID == AUXILIARY_ID()) + { + AttributeRefAttrPtr aRefAttr = data()->refattr(PROJECTED_FEATURE_ID()); + if (!aRefAttr || !aRefAttr->isInitialized()) + return; + FeaturePtr aProjection = ModelAPI_Feature::feature(aRefAttr->object()); + if (!aProjection) + return; + aProjection->boolean(AUXILIARY_ID())->setValue(boolean(AUXILIARY_ID())->value()); + } } void SketchPlugin_Projection::computeProjection(const std::string& theID) @@ -97,7 +108,8 @@ void SketchPlugin_Projection::computeProjection(const std::string& theID) aProjection = ModelAPI_Feature::feature(aRefAttr->object()); // if the type of feature differs with already selected, remove it and create once again - if (aProjection) { + bool hasPrevProj = aProjection.get() != 0; + if (hasPrevProj) { if ((anEdge->isLine() && aProjection->getKind() != SketchPlugin_Line::ID()) || (anEdge->isCircle() && aProjection->getKind() != SketchPlugin_Circle::ID()) || (anEdge->isArc() && aProjection->getKind() != SketchPlugin_Arc::ID())) { @@ -119,7 +131,7 @@ void SketchPlugin_Projection::computeProjection(const std::string& theID) if (aFirstInSketch->distance(aLastInSketch) < tolerance) return; // line is semi-orthogonal to the sketch plane - if (!aProjection) + if (!hasPrevProj) aProjection = sketch()->addFeature(SketchPlugin_Line::ID()); // update attributes of projection @@ -137,7 +149,7 @@ void SketchPlugin_Projection::computeProjection(const std::string& theID) std::shared_ptr aCenter = aSketchPlane->project(aCircle->center()); std::shared_ptr aCenterInSketch = sketch()->to2D(aCenter); - if (!aProjection) + if (!hasPrevProj) aProjection = sketch()->addFeature(SketchPlugin_Circle::ID()); // update attributes of projection @@ -156,7 +168,7 @@ void SketchPlugin_Projection::computeProjection(const std::string& theID) std::shared_ptr aCenter = aSketchPlane->project(aCircle->center()); std::shared_ptr aCenterInSketch = sketch()->to2D(aCenter); - if (!aProjection) + if (!hasPrevProj) aProjection = sketch()->addFeature(SketchPlugin_Arc::ID()); // update attributes of projection @@ -174,6 +186,12 @@ void SketchPlugin_Projection::computeProjection(const std::string& theID) aProjection->execute(); aRefAttr->setObject(aProjection); + if (!hasPrevProj) { + FeaturePtr aFixed = sketch()->addFeature(SketchPlugin_ConstraintRigid::ID()); + aFixed->refattr(SketchPlugin_Constraint::ENTITY_A())->setObject(aProjection->lastResult()); + aFixed->execute(); + } + if (theID == EXTERNAL_FEATURE_ID()) selection(EXTERNAL_ID())->setValue(aExtFeature->context(), aExtFeature->context()->shape()); } diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 592f7503d..dab490931 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -139,6 +139,7 @@ label="Edge" tooltip="Select external edge." shape_types="edge" + use_external="false" use_sketch_plane="false"> -- 2.39.2