- boost::shared_ptr<GeomAPI_Pln> aPlane = sketch()->plane();
-
- DataPtr aData = data();
- boost::shared_ptr<GeomDataAPI_Point2D> aPoint_A = getFeaturePoint(
- aData, SketchPlugin_Constraint::ENTITY_A());
- boost::shared_ptr<GeomDataAPI_Point2D> aPoint_B = getFeaturePoint(
- aData, SketchPlugin_Constraint::ENTITY_B());
-
- boost::shared_ptr<GeomAPI_Pnt2d> aPnt_A;
- boost::shared_ptr<GeomAPI_Pnt2d> aPnt_B;
-
- if (aPoint_A && aPoint_B) {
- aPnt_A = aPoint_A->pnt();
- aPnt_B = aPoint_B->pnt();
- } else if (!aPoint_A && aPoint_B) {
- boost::shared_ptr<SketchPlugin_Line> aLine = getFeatureLine(
- aData, SketchPlugin_Constraint::ENTITY_A());
- if (aLine) {
- aPnt_B = aPoint_B->pnt();
- aPnt_A = getProjectionPoint(aLine, aPnt_B);
- }
- } else if (aPoint_A && !aPoint_B) {
- boost::shared_ptr<SketchPlugin_Line> aLine = getFeatureLine(
- aData, SketchPlugin_Constraint::ENTITY_B());
- if (aLine) {
- aPnt_A = aPoint_A->pnt();
- aPnt_B = getProjectionPoint(aLine, aPnt_A);
- }
- }
- if (!aPnt_A || !aPnt_B)
- return AISObjectPtr();
-
- boost::shared_ptr<GeomDataAPI_Point2D> aFlyOutAttr = boost::dynamic_pointer_cast<
- GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
-
- boost::shared_ptr<GeomAPI_Pnt> aPoint1 = sketch()->to3D(aPnt_A->x(), aPnt_A->y());
- boost::shared_ptr<GeomAPI_Pnt> aPoint2 = sketch()->to3D(aPnt_B->x(), aPnt_B->y());
- boost::shared_ptr<GeomAPI_Pnt> aFlyoutPnt = boost::shared_ptr<GeomAPI_Pnt>();
- if(aFlyOutAttr->isInitialized()) {
- aFlyoutPnt = sketch()->to3D(aFlyOutAttr->x(), aFlyOutAttr->y());
- } else {
- boost::shared_ptr<GeomAPI_Lin2d> aLine = boost::shared_ptr<GeomAPI_Lin2d>(new GeomAPI_Lin2d(aPnt_A, aPnt_B));
- double aDist = aPoint1->distance(aPoint2)/5.;
- boost::shared_ptr<GeomAPI_Pnt2d> aFPnt = aLine->shiftedLocation(aDist);
- aFlyOutAttr->setValue(aFPnt);
- aFlyoutPnt = sketch()->to3D(aFPnt->x(), aFPnt->y());
- }
- // value calculation
- boost::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = boost::dynamic_pointer_cast<
- ModelAPI_AttributeDouble>(aData->attribute(SketchPlugin_Constraint::VALUE()));
- double aValue = aValueAttr->value();
- // Issue #196: checking the positivity of the distance constraint
- // there is a validator for a distance constraint, that the value should be positive
- // in case if an invalid value is set, the current distance value is shown
- if (aValue <= 0)
- aValue = calculateCurrentDistance();
-
- AISObjectPtr anAIS = thePrevious;
- if (!anAIS)
- anAIS = AISObjectPtr(new GeomAPI_AISObject);
- anAIS->createDistance(aPoint1, aPoint2, aFlyoutPnt, aPlane, aValue);
-
- // Set color from preferences
- std::vector<int> aRGB = Config_PropManager::color("Visualization", "distance_color",
- DISTANCE_COLOR);
- anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]);