From e6634dd2b141eee24922df31851f3c390e427ac0 Mon Sep 17 00:00:00 2001 From: azv Date: Wed, 17 Aug 2016 09:30:24 +0300 Subject: [PATCH] Revision of unit tests for Sketcher --- .../SketchPlugin_ConstraintMirror.cpp | 5 ++--- src/SketchPlugin/SketchPlugin_MultiRotation.cpp | 13 +++---------- .../SketchPlugin_MultiTranslation.cpp | 16 +++++----------- src/SketchPlugin/Test/TestConstraintDistance.py | 8 ++++++++ 4 files changed, 18 insertions(+), 24 deletions(-) diff --git a/src/SketchPlugin/SketchPlugin_ConstraintMirror.cpp b/src/SketchPlugin/SketchPlugin_ConstraintMirror.cpp index d63c196a4..42ed4d5b4 100755 --- a/src/SketchPlugin/SketchPlugin_ConstraintMirror.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintMirror.cpp @@ -229,7 +229,6 @@ void SketchPlugin_ConstraintMirror::erase() SketchPlugin_ConstraintBase::erase(); } -#include void SketchPlugin_ConstraintMirror::attributeChanged(const std::string& theID) { if (theID == MIRROR_LIST_ID()) { @@ -240,8 +239,8 @@ void SketchPlugin_ConstraintMirror::attributeChanged(const std::string& theID) AttributeRefListPtr aRefListOfMirrored = std::dynamic_pointer_cast( data()->attribute(SketchPlugin_Constraint::ENTITY_C())); std::list aTargetList = aRefListOfMirrored->list(); - std::list::reverse_iterator aTargetIter = aTargetList.rbegin(); - for (; aTargetIter != aTargetList.rend(); aTargetIter++) { + std::list::iterator aTargetIter = aTargetList.begin(); + for (; aTargetIter != aTargetList.end(); aTargetIter++) { FeaturePtr aFeature = ModelAPI_Feature::feature(*aTargetIter); if (aFeature) aDoc->removeFeature(aFeature); diff --git a/src/SketchPlugin/SketchPlugin_MultiRotation.cpp b/src/SketchPlugin/SketchPlugin_MultiRotation.cpp index 0ef30f7a1..6ae033dec 100755 --- a/src/SketchPlugin/SketchPlugin_MultiRotation.cpp +++ b/src/SketchPlugin/SketchPlugin_MultiRotation.cpp @@ -332,8 +332,7 @@ void SketchPlugin_MultiRotation::attributeChanged(const std::string& theID) return; // Clear list of objects - AttributeRefListPtr aRefListOfRotated = std::dynamic_pointer_cast( - data()->attribute(SketchPlugin_Constraint::ENTITY_B())); + AttributeRefListPtr aRefListOfRotated = reflist(SketchPlugin_Constraint::ENTITY_B()); std::list aTargetList = aRefListOfRotated->list(); std::list::iterator aTargetIter = aTargetList.begin(); std::set aFeaturesToBeRemoved; @@ -342,10 +341,7 @@ void SketchPlugin_MultiRotation::attributeChanged(const std::string& theID) for (int i = 0; i < aNbCopies && aTargetIter != aTargetList.end(); i++, aTargetIter++) { aRefListOfRotated->remove(*aTargetIter); // remove the corresponding feature from the sketch - ResultConstructionPtr aRC = - std::dynamic_pointer_cast(*aTargetIter); - DocumentPtr aDoc = aRC ? aRC->document() : DocumentPtr(); - FeaturePtr aFeature = aDoc ? aDoc->feature(aRC) : FeaturePtr(); + FeaturePtr aFeature = ModelAPI_Feature::feature(*aTargetIter); if (aFeature) aFeaturesToBeRemoved.insert(aFeature); } @@ -353,10 +349,7 @@ void SketchPlugin_MultiRotation::attributeChanged(const std::string& theID) ModelAPI_Tools::removeFeaturesAndReferences(aFeaturesToBeRemoved); aRefListOfRotated->clear(); - std::dynamic_pointer_cast( - data()->attribute(SketchPlugin_Constraint::ENTITY_A()))->clear(); - std::dynamic_pointer_cast( - data()->attribute(SketchPlugin_Constraint::ENTITY_B()))->clear(); + reflist(SketchPlugin_Constraint::ENTITY_A())->clear(); } } } diff --git a/src/SketchPlugin/SketchPlugin_MultiTranslation.cpp b/src/SketchPlugin/SketchPlugin_MultiTranslation.cpp index d6e1d5dd2..34e26377b 100755 --- a/src/SketchPlugin/SketchPlugin_MultiTranslation.cpp +++ b/src/SketchPlugin/SketchPlugin_MultiTranslation.cpp @@ -274,29 +274,23 @@ void SketchPlugin_MultiTranslation::attributeChanged(const std::string& theID) int aNbCopies = integer(NUMBER_OF_OBJECTS_ID())->value()-1; if (aNbCopies <= 0) return; + + DocumentPtr aDoc = document(); // Clear list of objects - AttributeRefListPtr aRefListOfTranslated = std::dynamic_pointer_cast( - data()->attribute(SketchPlugin_Constraint::ENTITY_B())); + AttributeRefListPtr aRefListOfTranslated = reflist(SketchPlugin_Constraint::ENTITY_B()); std::list aTargetList = aRefListOfTranslated->list(); std::list::iterator aTargetIter = aTargetList.begin(); while (aTargetIter != aTargetList.end()) { aTargetIter++; for (int i = 0; i < aNbCopies && aTargetIter != aTargetList.end(); i++, aTargetIter++) { aRefListOfTranslated->remove(*aTargetIter); - // remove the corresponding feature from the sketch - ResultConstructionPtr aRC = - std::dynamic_pointer_cast(*aTargetIter); - DocumentPtr aDoc = aRC ? aRC->document() : DocumentPtr(); - FeaturePtr aFeature = aDoc ? aDoc->feature(aRC) : FeaturePtr(); + FeaturePtr aFeature = ModelAPI_Feature::feature(*aTargetIter); if (aFeature) aDoc->removeFeature(aFeature); } } aRefListOfTranslated->clear(); - std::dynamic_pointer_cast( - data()->attribute(SketchPlugin_Constraint::ENTITY_A()))->clear(); - std::dynamic_pointer_cast( - data()->attribute(SketchPlugin_Constraint::ENTITY_B()))->clear(); + reflist(SketchPlugin_Constraint::ENTITY_A())->clear(); } } } diff --git a/src/SketchPlugin/Test/TestConstraintDistance.py b/src/SketchPlugin/Test/TestConstraintDistance.py index 9f64238c7..75f4d3fbb 100644 --- a/src/SketchPlugin/Test/TestConstraintDistance.py +++ b/src/SketchPlugin/Test/TestConstraintDistance.py @@ -104,9 +104,13 @@ assert (aLineResult is not None) aConstraint.execute() refattrA.setAttr(aSketchPointCoords) refattrB.setAttr(aLineAStartPoint) +aSession.finishOperation() +# set flyout point then abort operation, after that check the Distance is correct +aSession.startOperation() aFlyoutPoint = geomDataAPI_Point2D(aConstraint.attribute("ConstraintFlyoutValuePnt")) aFlyoutPoint.setValue(50.0, 100.0) aSession.finishOperation() +aSession.abortOperation() assert (refattrA.isInitialized()) assert (refattrB.isInitialized()) assert (aDistance.isInitialized()) @@ -154,9 +158,13 @@ aLineResult = aSketchLine.firstResult() assert (aLineResult is not None) refattrA.setObject(aLineResult) refattrB.setAttr(aSketchPointCoords) +aSession.finishOperation() +# set flyout point then abort operation, after that check the Distance is correct +aSession.startOperation() aFlyoutPoint = geomDataAPI_Point2D(aConstraint.attribute("ConstraintFlyoutValuePnt")) aFlyoutPoint.setValue(50.0, 100.0) aSession.finishOperation() +aSession.abortOperation() assert (refattrA.isInitialized()) assert (refattrB.isInitialized()) assert (aDistance.isInitialized()) -- 2.39.2