From 898fa9eae2250439ede697e78e9cb23b1c8bf849 Mon Sep 17 00:00:00 2001 From: azv Date: Tue, 23 Aug 2016 11:12:36 +0300 Subject: [PATCH] Take into account context of selection for sketch features if the selected shape is null (simple construction is selected) --- src/SketchAPI/SketchAPI_Arc.cpp | 2 +- src/SketchAPI/SketchAPI_Circle.cpp | 2 +- src/SketchAPI/SketchAPI_Line.cpp | 2 +- src/SketchAPI/SketchAPI_Point.cpp | 2 +- src/SketchPlugin/SketchPlugin_Arc.cpp | 6 ++++++ src/SketchPlugin/SketchPlugin_Circle.cpp | 6 ++++++ src/SketchPlugin/SketchPlugin_Line.cpp | 8 +++++++- src/SketchPlugin/SketchPlugin_Point.cpp | 8 +++++++- src/SketchPlugin/SketchPlugin_Sketch.cpp | 2 +- 9 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/SketchAPI/SketchAPI_Arc.cpp b/src/SketchAPI/SketchAPI_Arc.cpp index ba8e4cb8b..628e43238 100644 --- a/src/SketchAPI/SketchAPI_Arc.cpp +++ b/src/SketchAPI/SketchAPI_Arc.cpp @@ -244,7 +244,7 @@ void SketchAPI_Arc::dump(ModelHighAPI_Dumper& theDumper) const const std::string& aSketchName = theDumper.parentName(aBase); AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID()); - if (anExternal->value()) { + if (anExternal->context()) { // arc is external theDumper << aBase << " = " << aSketchName << ".addArc(" << anExternal << ")" << std::endl; } else { diff --git a/src/SketchAPI/SketchAPI_Circle.cpp b/src/SketchAPI/SketchAPI_Circle.cpp index 8403b5896..9cac0bd31 100644 --- a/src/SketchAPI/SketchAPI_Circle.cpp +++ b/src/SketchAPI/SketchAPI_Circle.cpp @@ -247,7 +247,7 @@ void SketchAPI_Circle::dump(ModelHighAPI_Dumper& theDumper) const const std::string& aSketchName = theDumper.parentName(aBase); AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID()); - if (anExternal->value()) { + if (anExternal->context()) { // circle is external theDumper << aBase << " = " << aSketchName << ".addCircle(" << anExternal << ")" << std::endl; } else { diff --git a/src/SketchAPI/SketchAPI_Line.cpp b/src/SketchAPI/SketchAPI_Line.cpp index e06448ecd..1e5a2da04 100644 --- a/src/SketchAPI/SketchAPI_Line.cpp +++ b/src/SketchAPI/SketchAPI_Line.cpp @@ -137,7 +137,7 @@ void SketchAPI_Line::dump(ModelHighAPI_Dumper& theDumper) const const std::string& aSketchName = theDumper.parentName(aBase); AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID()); - if (anExternal->value()) { + if (anExternal->context()) { // line is external theDumper << aBase << " = " << aSketchName << ".addLine(" << anExternal << ")" << std::endl; } else { diff --git a/src/SketchAPI/SketchAPI_Point.cpp b/src/SketchAPI/SketchAPI_Point.cpp index 4e44f259c..346ae4442 100644 --- a/src/SketchAPI/SketchAPI_Point.cpp +++ b/src/SketchAPI/SketchAPI_Point.cpp @@ -107,7 +107,7 @@ void SketchAPI_Point::dump(ModelHighAPI_Dumper& theDumper) const const std::string& aSketchName = theDumper.parentName(aBase); AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID()); - if (anExternal->value()) { + if (anExternal->context()) { // point is external theDumper << aBase << " = " << aSketchName << ".addPoint(" << anExternal << ")" << std::endl; } else { diff --git a/src/SketchPlugin/SketchPlugin_Arc.cpp b/src/SketchPlugin/SketchPlugin_Arc.cpp index 9873f01af..ab27bbbe8 100644 --- a/src/SketchPlugin/SketchPlugin_Arc.cpp +++ b/src/SketchPlugin/SketchPlugin_Arc.cpp @@ -338,6 +338,12 @@ void SketchPlugin_Arc::attributeChanged(const std::string& theID) // the second condition for unability to move external segments anywhere if (theID == EXTERNAL_ID() || isFixed()) { std::shared_ptr aSelection = data()->selection(EXTERNAL_ID())->value(); + if (!aSelection) { + // empty shape in selection shows that the shape is equal to context + ResultPtr anExtRes = selection(EXTERNAL_ID())->context(); + if (anExtRes) + aSelection = anExtRes->shape(); + } // update arguments due to the selection value if (aSelection && !aSelection->isNull() && aSelection->isEdge()) { std::shared_ptr anEdge( new GeomAPI_Edge(aSelection)); diff --git a/src/SketchPlugin/SketchPlugin_Circle.cpp b/src/SketchPlugin/SketchPlugin_Circle.cpp index ccb1a6efe..babdd6f14 100644 --- a/src/SketchPlugin/SketchPlugin_Circle.cpp +++ b/src/SketchPlugin/SketchPlugin_Circle.cpp @@ -189,6 +189,12 @@ void SketchPlugin_Circle::attributeChanged(const std::string& theID) { // the second condition for unability to move external segments anywhere if (theID == EXTERNAL_ID() || isFixed()) { std::shared_ptr aSelection = data()->selection(EXTERNAL_ID())->value(); + if (!aSelection) { + // empty shape in selection shows that the shape is equal to context + ResultPtr anExtRes = selection(EXTERNAL_ID())->context(); + if (anExtRes) + aSelection = anExtRes->shape(); + } // update arguments due to the selection value if (aSelection && !aSelection->isNull() && aSelection->isEdge()) { std::shared_ptr anEdge( new GeomAPI_Edge(aSelection)); diff --git a/src/SketchPlugin/SketchPlugin_Line.cpp b/src/SketchPlugin/SketchPlugin_Line.cpp index 2d2c6bc4a..782f99a24 100644 --- a/src/SketchPlugin/SketchPlugin_Line.cpp +++ b/src/SketchPlugin/SketchPlugin_Line.cpp @@ -123,7 +123,13 @@ void SketchPlugin_Line::attributeChanged(const std::string& theID) { // to be removed after debug if ((theID == EXTERNAL_ID() || isFixed()) && !isCopy()) { std::shared_ptr aSelection = data()->selection(EXTERNAL_ID())->value(); - // update arguments due to the selection value + if (!aSelection) { + // empty shape in selection shows that the shape is equal to context + ResultPtr anExtRes = selection(EXTERNAL_ID())->context(); + if (anExtRes) + aSelection = anExtRes->shape(); + } + // update arguments due to the selection value if (aSelection && !aSelection->isNull() && aSelection->isEdge()) { std::shared_ptr anEdge( new GeomAPI_Edge(aSelection)); std::shared_ptr aStartAttr = diff --git a/src/SketchPlugin/SketchPlugin_Point.cpp b/src/SketchPlugin/SketchPlugin_Point.cpp index afa84bf13..4ee1f8984 100644 --- a/src/SketchPlugin/SketchPlugin_Point.cpp +++ b/src/SketchPlugin/SketchPlugin_Point.cpp @@ -69,7 +69,13 @@ void SketchPlugin_Point::attributeChanged(const std::string& theID) { // the second condition for unability to move external point anywhere if (theID == EXTERNAL_ID() || isFixed()) { std::shared_ptr aSelection = data()->selection(EXTERNAL_ID())->value(); - // update arguments due to the selection value + if (!aSelection) { + // empty shape in selection shows that the shape is equal to context + ResultPtr anExtRes = selection(EXTERNAL_ID())->context(); + if (anExtRes) + aSelection = anExtRes->shape(); + } + // update arguments due to the selection value if (aSelection && !aSelection->isNull() && aSelection->isVertex()) { std::shared_ptr aVertex(new GeomAPI_Vertex(aSelection)); std::shared_ptr aCoordAttr = diff --git a/src/SketchPlugin/SketchPlugin_Sketch.cpp b/src/SketchPlugin/SketchPlugin_Sketch.cpp index ef2ef9c69..189c0c3df 100755 --- a/src/SketchPlugin/SketchPlugin_Sketch.cpp +++ b/src/SketchPlugin/SketchPlugin_Sketch.cpp @@ -91,7 +91,7 @@ void SketchPlugin_Sketch::execute() aFeature->setSketch(this); // do not include the external edges into the result if (aFeature->data()->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID())) { - if (aFeature->data()->selection(SketchPlugin_SketchEntity::EXTERNAL_ID())->value()) + if (aFeature->data()->selection(SketchPlugin_SketchEntity::EXTERNAL_ID())->context()) continue; } // do not include the construction entities in the result -- 2.39.2