X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchPlugin%2FSketchPlugin_ConstraintLength.cpp;h=da91dc5835cbead17fa834bec2c063fc18536912;hb=51889d235a27d0ee4b3c3237d21d1ea621063580;hp=224ea32b5239cb53b2c8bc06a945a1f17b2aaca6;hpb=f1cd93fd02a54259f72e3191d037323a496b2bef;p=modules%2Fshaper.git diff --git a/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp b/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp index 224ea32b5..da91dc583 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp @@ -50,9 +50,39 @@ void SketchPlugin_ConstraintLength::execute() //if(!aValueAttr->isInitialized()) { // aValueAttr->setValue(aLenght); //} + + // the value should to be computed here, not in the getAISObject in order to change the model value + // inside the object transaction. This is important for creating a constraint by preselection. + // The display of the presentation in this case happens after the transaction commit + AttributePtr aFlyOutAttribute = data()->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()); + if (!aFlyOutAttribute->isInitialized()) { + compute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()); + } } } +bool SketchPlugin_ConstraintLength::compute(const std::string& theAttributeId) +{ + if (theAttributeId != SketchPlugin_Constraint::FLYOUT_VALUE_PNT()) + return false; + + std::shared_ptr aPoint1, aPoint2; + std::shared_ptr aStartPoint, anEndPoint; + if (!getPoints(aPoint1, aPoint2, aStartPoint, anEndPoint)) + return false; + + std::shared_ptr aFlyOutAttr = std::dynamic_pointer_cast< + GeomDataAPI_Point2D>(data()->attribute(theAttributeId)); + + std::shared_ptr aLine = + std::shared_ptr(new GeomAPI_Lin2d(aStartPoint->pnt(), anEndPoint->pnt())); + double aDist = aPoint1->distance(aPoint2)/5.; + std::shared_ptr aFPnt = aLine->shiftedLocation(aDist); + aFlyOutAttr->setValue(aFPnt); + + return true; +} + bool SketchPlugin_ConstraintLength::getPoints( std::shared_ptr& thePoint1, std::shared_ptr& thePoint2, std::shared_ptr& theStartPoint, @@ -85,20 +115,13 @@ AISObjectPtr SketchPlugin_ConstraintLength::getAISObject(AISObjectPtr thePreviou if (!getPoints(aPoint1, aPoint2, aStartPoint, anEndPoint)) return thePrevious; // not possible to show length because points are not defined - std::shared_ptr aPlane = sketch()->plane(); - std::shared_ptr aFlyOutAttr = std::dynamic_pointer_cast< - GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); - std::shared_ptr aFlyoutPnt = std::shared_ptr(); - if (aFlyOutAttr->isInitialized()) { - aFlyoutPnt = sketch()->to3D(aFlyOutAttr->x(), aFlyOutAttr->y()); - } else { - std::shared_ptr aLine = - std::shared_ptr(new GeomAPI_Lin2d(aStartPoint->pnt(), anEndPoint->pnt())); - double aDist = aPoint1->distance(aPoint2)/5.; - std::shared_ptr aFPnt = aLine->shiftedLocation(aDist); - aFlyOutAttr->setValue(aFPnt); - aFlyoutPnt = sketch()->to3D(aFPnt->x(), aFPnt->y()); + AttributePtr aFlyOutAttribute = data()->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()); + if (!aFlyOutAttribute->isInitialized()) { + return thePrevious; // not possible to show length because points are not defined } + std::shared_ptr aFlyOutAttr = std::dynamic_pointer_cast< + GeomDataAPI_Point2D>(aFlyOutAttribute); + std::shared_ptr aFlyoutPnt = sketch()->to3D(aFlyOutAttr->x(), aFlyOutAttr->y()); // value calculation // TODO: has to be calculated on definition of reference object double aDistance = aPoint1->distance(aPoint2); @@ -114,11 +137,12 @@ AISObjectPtr SketchPlugin_ConstraintLength::getAISObject(AISObjectPtr thePreviou AISObjectPtr anAIS = thePrevious; if (!anAIS) anAIS = AISObjectPtr(new GeomAPI_AISObject); + std::shared_ptr aPlane = sketch()->plane(); anAIS->createDistance(aPoint1, aPoint2, aFlyoutPnt, aPlane, aValue); // Set color from preferences - std::vector aRGB = - Config_PropManager::color("Visualization", "length_color", LENGTH_COLOR); + std::vector aRGB = Config_PropManager::color("Visualization", "sketch_dimension_color", + SKETCH_DIMENSION_COLOR); anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]); return anAIS; }