From: azv Date: Fri, 26 Aug 2016 06:11:12 +0000 (+0300) Subject: Checking isInitialized for attributes is SketchPlugin and SketchSolver X-Git-Tag: V_2.5.0~128 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1505ea1fd541e828172211dc064560d5e247b2b6;p=modules%2Fshaper.git Checking isInitialized for attributes is SketchPlugin and SketchSolver --- diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index 70a6138dc..6639c3aa9 100755 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -917,6 +917,8 @@ AttributePtr PartSet_Tools::findAttributeBy2dPoint(ObjectPtr theObj, for (; anIt != aLast && !anAttribute; anIt++) { std::shared_ptr aCurPoint = std::dynamic_pointer_cast(*anIt); + if (!aCurPoint->isInitialized()) + continue; std::shared_ptr aPnt = convertTo3D(aCurPoint->x(), aCurPoint->y(), theSketch); if (aPnt && (aPnt->distance(aValue) < Precision::Confusion())) { diff --git a/src/PythonAddons/macros/rectangle/feature.py b/src/PythonAddons/macros/rectangle/feature.py index 8ce3a4b4f..3fa05afc1 100644 --- a/src/PythonAddons/macros/rectangle/feature.py +++ b/src/PythonAddons/macros/rectangle/feature.py @@ -82,6 +82,7 @@ class SketchPlugin_Rectangle(model.Feature): for i in range (0, 3): aLine = self.__sketch.addFeature("SketchLine") aLinesList.append(aLine) + self.updateLines() aNbLines = aLinesList.size() # Create constraints to keep the rectangle for i in range (0, aNbLines): diff --git a/src/SketchPlugin/SketchPlugin_Arc.cpp b/src/SketchPlugin/SketchPlugin_Arc.cpp index ab27bbbe8..aa1d29096 100644 --- a/src/SketchPlugin/SketchPlugin_Arc.cpp +++ b/src/SketchPlugin/SketchPlugin_Arc.cpp @@ -272,21 +272,25 @@ void SketchPlugin_Arc::move(double theDeltaX, double theDeltaY) myEndUpdate = true; std::shared_ptr aPoint2 = std::dynamic_pointer_cast( aData->attribute(SketchPlugin_Arc::START_ID())); - aPoint2->move(theDeltaX, theDeltaY); + if (aPoint2->isInitialized()) + aPoint2->move(theDeltaX, theDeltaY); std::shared_ptr aPoint3 = std::dynamic_pointer_cast( aData->attribute(SketchPlugin_Arc::END_ID())); - aPoint3->move(theDeltaX, theDeltaY); + if (aPoint3->isInitialized()) + aPoint3->move(theDeltaX, theDeltaY); myStartUpdate = false; myEndUpdate = false; std::shared_ptr aPoint1 = std::dynamic_pointer_cast( aData->attribute(SketchPlugin_Arc::CENTER_ID())); - aPoint1->move(theDeltaX, theDeltaY); + if (aPoint1->isInitialized()) + aPoint1->move(theDeltaX, theDeltaY); std::shared_ptr aPassedPoint = std::dynamic_pointer_cast(aData->attribute(PASSED_POINT_ID())); - aPassedPoint->move(theDeltaX, theDeltaY); + if (aPassedPoint->isInitialized()) + aPassedPoint->move(theDeltaX, theDeltaY); aData->blockSendAttributeUpdated(false); } diff --git a/src/SketchPlugin/SketchPlugin_Circle.cpp b/src/SketchPlugin/SketchPlugin_Circle.cpp index babdd6f14..cc8a992bc 100644 --- a/src/SketchPlugin/SketchPlugin_Circle.cpp +++ b/src/SketchPlugin/SketchPlugin_Circle.cpp @@ -171,14 +171,18 @@ void SketchPlugin_Circle::move(double theDeltaX, double theDeltaY) std::shared_ptr aPoint = std::dynamic_pointer_cast( aData->attribute(CENTER_ID())); - aPoint->move(theDeltaX, theDeltaY); + if (aPoint->isInitialized()) + aPoint->move(theDeltaX, theDeltaY); aPoint = std::dynamic_pointer_cast(aData->attribute(FIRST_POINT_ID())); - aPoint->move(theDeltaX, theDeltaY); + if (aPoint->isInitialized()) + aPoint->move(theDeltaX, theDeltaY); aPoint = std::dynamic_pointer_cast(aData->attribute(SECOND_POINT_ID())); - aPoint->move(theDeltaX, theDeltaY); + if (aPoint->isInitialized()) + aPoint->move(theDeltaX, theDeltaY); aPoint = std::dynamic_pointer_cast(aData->attribute(THIRD_POINT_ID())); - aPoint->move(theDeltaX, theDeltaY); + if (aPoint->isInitialized()) + aPoint->move(theDeltaX, theDeltaY); } bool SketchPlugin_Circle::isFixed() { @@ -281,7 +285,11 @@ void SketchPlugin_Circle::adjustThreePoints() std::dynamic_pointer_cast(attribute(THIRD_POINT_ID())); double aRadius = aRadiusAttr->value(); - if (fabs(aFirstPnt->pnt()->distance(aCenterAttr->pnt()) - aRadius) > tolerance || + bool isInitialized = aFirstPnt->isInitialized() && + aSecondPnt->isInitialized() && aThirdPnt->isInitialized(); + + if (!isInitialized || + fabs(aFirstPnt->pnt()->distance(aCenterAttr->pnt()) - aRadius) > tolerance || fabs(aSecondPnt->pnt()->distance(aCenterAttr->pnt()) - aRadius) > tolerance || fabs(aThirdPnt->pnt()->distance(aCenterAttr->pnt()) - aRadius) > tolerance) { aFirstPnt->setValue(aCenterAttr->x() + aRadius, aCenterAttr->y()); diff --git a/src/SketchSolver/SketchSolver_Constraint.cpp b/src/SketchSolver/SketchSolver_Constraint.cpp index c402ec7dd..eeabd7478 100644 --- a/src/SketchSolver/SketchSolver_Constraint.cpp +++ b/src/SketchSolver/SketchSolver_Constraint.cpp @@ -224,12 +224,12 @@ void SketchSolver_Constraint::getAttributes( return; } - myStorage->update(*anIter/*, myGroupID*/); - EntityWrapperPtr anEntity = myStorage->entity(*anIter); + myStorage->update(aRefAttr/*, myGroupID*/); + EntityWrapperPtr anEntity = myStorage->entity(aRefAttr); if (!anEntity) { // Force creation of an entity - myStorage->update(*anIter, GID_UNKNOWN, true); - anEntity = myStorage->entity(*anIter); + myStorage->update(aRefAttr, GID_UNKNOWN, true); + anEntity = myStorage->entity(aRefAttr); } myAttributes.push_back(anEntity); diff --git a/src/SketchSolver/SketchSolver_Storage.cpp b/src/SketchSolver/SketchSolver_Storage.cpp index 4dc1800d1..88f56124e 100644 --- a/src/SketchSolver/SketchSolver_Storage.cpp +++ b/src/SketchSolver/SketchSolver_Storage.cpp @@ -190,6 +190,8 @@ bool SketchSolver_Storage::update(FeaturePtr theFeature, const GroupID& theGroup std::list anAttrs = pointAttributes(theFeature); std::list::const_iterator anIt = anAttrs.begin(); for (; anIt != anAttrs.end(); ++anIt) { + if (!(*anIt)->isInitialized()) + return false; isUpdated = update(*anIt, theGroup, theForce) || isUpdated; aSubs.push_back(entity(*anIt)); } @@ -222,14 +224,20 @@ bool SketchSolver_Storage::update(FeaturePtr theFeature, const GroupID& theGroup bool SketchSolver_Storage::update(AttributePtr theAttribute, const GroupID& theGroup, bool theForce) { + if (!theAttribute->isInitialized()) + return false; + AttributePtr anAttribute = theAttribute; AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast(anAttribute); if (aRefAttr) { if (aRefAttr->isObject()) { FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object()); return update(aFeature, theGroup, theForce); - } else + } else { anAttribute = aRefAttr->attr(); + if (!anAttribute->isInitialized()) + return false; + } } EntityWrapperPtr aRelated = entity(anAttribute);