From: azv Date: Fri, 3 Apr 2015 08:36:06 +0000 (+0300) Subject: Verification of constraint attributes to be objects, not features X-Git-Tag: V_1.1.0~57^2~11 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=11573ab14113256d9e93228cd2310f78d08e2b4e;p=modules%2Fshaper.git Verification of constraint attributes to be objects, not features --- diff --git a/src/SketchPlugin/SketchPlugin_ConstraintFillet.cpp b/src/SketchPlugin/SketchPlugin_ConstraintFillet.cpp index e51c22129..41bb37388 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintFillet.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintFillet.cpp @@ -121,16 +121,14 @@ void SketchPlugin_ConstraintFillet::execute() FeaturePtr aNewFeatureA = sketch()->addFeature(aFeatureA->getKind()); aFeatureA->data()->copyTo(aNewFeatureA->data()); aNewFeatureA->execute(); - aRefListOfFillet->append(aNewFeatureA); + aRefListOfFillet->append(aNewFeatureA->firstResult()); // copy aFeatureB FeaturePtr aNewFeatureB = sketch()->addFeature(aFeatureB->getKind()); aFeatureB->data()->copyTo(aNewFeatureB->data()); aNewFeatureB->execute(); - aRefListOfFillet->append(aNewFeatureB); - // create filleting arc + aRefListOfFillet->append(aNewFeatureB->firstResult()); + // create filleting arc (it will be attached to the list later) FeaturePtr aNewArc = sketch()->addFeature(SketchPlugin_Arc::ID()); - aRefListOfFillet->append(aNewArc); - aRefListOfFillet->setInitialized(); // Wait all constraints being created, then send update events static Events_ID anUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED); @@ -221,6 +219,9 @@ void SketchPlugin_ConstraintFillet::execute() aNewArc->attribute(SketchPlugin_Arc::END_ID()))->setValue( aCenter->x() + aStep->y(), aCenter->y() - aStep->x()); aNewArc->execute(); + // attach new arc to the list + aRefListOfFillet->append(aNewArc->lastResult()); + aRefListOfFillet->setInitialized(); // Create list of additional constraints: // 1. Coincidence of boundary points of features and fillet arc diff --git a/src/SketchSolver/SketchSolver_Builder.cpp b/src/SketchSolver/SketchSolver_Builder.cpp index c46ec2c95..82cf9669c 100644 --- a/src/SketchSolver/SketchSolver_Builder.cpp +++ b/src/SketchSolver/SketchSolver_Builder.cpp @@ -13,11 +13,13 @@ #include #include #include +#include #include #include #include #include +#include #include #include #include @@ -61,6 +63,35 @@ SolverConstraintPtr SketchSolver_Builder::createConstraint(ConstraintPtr theCons if (!aData || !aData->isValid()) return aResult; +#ifdef _DEBUG + // Verify attributes of constraint and generate errors + std::list anAttrList = aData->attributes(std::string()); + std::list::iterator anIter = anAttrList.begin(); + for (; anIter != anAttrList.end(); anIter++) { + AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast(*anIter); + if (aRefAttr) { + if (aRefAttr->isObject() && aRefAttr->object()) { + ResultConstructionPtr aRC = + std::dynamic_pointer_cast(aRefAttr->object()); + if (!aRC) + Events_Error::send(SketchSolver_Error::NEED_OBJECT_NOT_FEATURE(), this); + } + continue; + } + AttributeRefListPtr aRefList = std::dynamic_pointer_cast(*anIter); + if (aRefList) { + std::list aList = aRefList->list(); + std::list::iterator aListIter = aList.begin(); + for (; aListIter != aList.end(); aListIter++) { + ResultConstructionPtr aRC = + std::dynamic_pointer_cast(*aListIter); + if (*aListIter && !aRC) + Events_Error::send(SketchSolver_Error::NEED_OBJECT_NOT_FEATURE(), this); + } + } + } +#endif + if (theConstraint->getKind() == SketchPlugin_ConstraintCoincidence::ID()) { return SolverConstraintPtr(new SketchSolver_ConstraintCoincidence(theConstraint)); } else if (theConstraint->getKind() == SketchPlugin_ConstraintDistance::ID()) { diff --git a/src/SketchSolver/SketchSolver_Error.h b/src/SketchSolver/SketchSolver_Error.h index 1a5718a8d..3623354b1 100644 --- a/src/SketchSolver/SketchSolver_Error.h +++ b/src/SketchSolver/SketchSolver_Error.h @@ -23,6 +23,12 @@ class SketchSolver_Error static const std::string MY_ERROR_VALUE("Conflicting constraints"); return MY_ERROR_VALUE; } + /// Constraints should use objects instead of features as attributes + inline static const std::string& NEED_OBJECT_NOT_FEATURE() + { + static const std::string MY_ERROR_VALUE("Constraint should be based on object instead of feature"); + return MY_ERROR_VALUE; + } /// The entities need to have shared point, but they have not inline static const std::string& NO_COINCIDENT_POINTS() {