#include <GeomDataAPI_Point2D.h>
#include <GeomDataAPI_Dir.h>
-#include <AIS_InteractiveObject.hxx>
-#include <AIS_RadiusDimension.hxx>
-
SketchPlugin_ConstraintRadius::SketchPlugin_ConstraintRadius()
{
}
}
}
-Handle(AIS_InteractiveObject) SketchPlugin_ConstraintRadius::getAISShape(
- Handle_AIS_InteractiveObject thePrevious)
+boost::shared_ptr<GeomAPI_AISObject> SketchPlugin_ConstraintRadius::getAISObject(
+ boost::shared_ptr<GeomAPI_AISObject> thePrevious)
{
- Handle(AIS_InteractiveObject) anAIS = thePrevious;
if (!sketch())
- return anAIS;
+ return thePrevious;
boost::shared_ptr<ModelAPI_Data> aData = data();
boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr =
boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
if (!anAttr)
- return anAIS;
+ return thePrevious;
FeaturePtr aFeature = anAttr->feature();
std::string aKind = aFeature ? aFeature->getKind() : "";
if (aKind != SKETCH_CIRCLE_KIND && aKind != SKETCH_ARC_KIND)
- return anAIS;
-
- boost::shared_ptr<ModelAPI_AttributeDouble> aValueAttr =
- boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_VALUE));
- double aValue = aValueAttr->value();
+ return thePrevious;
- // an anchor point
- boost::shared_ptr<GeomDataAPI_Point2D> aAnchorAttr =
+ // Flyout point
+ boost::shared_ptr<GeomDataAPI_Point2D> aFlyoutAttr =
boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT));
- if (!aAnchorAttr->isInitialized())
- return anAIS;
- boost::shared_ptr<GeomAPI_Pnt2d> anAnchor2D = aAnchorAttr->pnt();
- boost::shared_ptr<GeomAPI_Pnt> anAnchor = sketch()->to3D(anAnchor2D->x(), anAnchor2D->y());
+ if (!aFlyoutAttr->isInitialized())
+ return thePrevious;
+ boost::shared_ptr<GeomAPI_Pnt> aFlyoutPnt = sketch()->to3D(aFlyoutAttr->x(), aFlyoutAttr->y());
+ // Prepare a circle
aData = aFeature->data();
boost::shared_ptr<GeomDataAPI_Point2D> aCenterAttr;
double aRadius;
aRadius = aCenterAttr->pnt()->distance(aStartAttr->pnt());
}
- // a circle
boost::shared_ptr<GeomAPI_Pnt> aCenter = sketch()->to3D(aCenterAttr->x(), aCenterAttr->y());
-
boost::shared_ptr<GeomDataAPI_Dir> aNDir =
boost::dynamic_pointer_cast<GeomDataAPI_Dir>(sketch()->data()->attribute(SKETCH_ATTR_NORM));
boost::shared_ptr<GeomAPI_Dir> aNormal = aNDir->dir();
-
boost::shared_ptr<GeomAPI_Circ> aCircle(new GeomAPI_Circ(aCenter, aNormal, aRadius));
- anAnchor = aCircle->project(anAnchor);
- // TODO: a bug in AIS_RadiusDimension:
- // The anchor point can't be myCirc.Location() - an exception is raised.
- // But we need exactly this case...
- // We want to show a radius dimension starting from the circle centre and
- // ending at the user-defined point.
- // Also, if anchor point coincides with myP2, the radius dimension is not displayed at all.
- boost::shared_ptr<GeomAPI_XYZ> anAnchorXYZ = anAnchor->xyz();
- anAnchorXYZ = anAnchorXYZ->decreased(aCenter->xyz());
- boost::shared_ptr<GeomAPI_Dir> aDeltaDir(new GeomAPI_Dir(anAnchorXYZ));
- const double aDelta = 1e-3;
- anAnchor->setX(anAnchor->x() + aDelta * aDeltaDir->x());
- anAnchor->setY(anAnchor->y() + aDelta * aDeltaDir->y());
- anAnchor->setZ(anAnchor->z() + aDelta * aDeltaDir->z());
-
- if (anAIS.IsNull())
- {
- Handle(AIS_RadiusDimension) aDimAIS =
- new AIS_RadiusDimension(aCircle->impl<gp_Circ>(), anAnchor->impl<gp_Pnt>());
- aDimAIS->SetCustomValue(aValue);
-
- Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect();
- anAspect->MakeArrows3d (Standard_False);
- anAspect->MakeText3d(false);
- anAspect->TextAspect()->SetHeight(CONSTRAINT_TEXT_HEIGHT);
- anAspect->MakeTextShaded(false);
- aDimAIS->DimensionAspect()->MakeUnitsDisplayed(false);
- aDimAIS->SetDimensionAspect (anAspect);
- aDimAIS->SetSelToleranceForText2d(CONSTRAINT_TEXT_SELECTION_TOLERANCE);
-
- anAIS = aDimAIS;
- }
- else
- {
- // update presentation
- Handle(AIS_RadiusDimension) aDimAIS = Handle(AIS_RadiusDimension)::DownCast(anAIS);
- if (!aDimAIS.IsNull())
- {
- aDimAIS->SetMeasuredGeometry(aCircle->impl<gp_Circ>(), anAnchor->impl<gp_Pnt>());
- aDimAIS->SetCustomValue(aValue);
- aDimAIS->Redisplay(Standard_True);
- }
- }
+ // Value
+ boost::shared_ptr<ModelAPI_AttributeDouble> aValueAttr =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_VALUE));
+ double aValue = aRadius;
+ if (aValueAttr && aValueAttr->isInitialized())
+ aValue = aValueAttr->value();
+
+ boost::shared_ptr<GeomAPI_AISObject> anAIS = thePrevious;
+ if (!anAIS)
+ anAIS = boost::shared_ptr<GeomAPI_AISObject>(new GeomAPI_AISObject);
+ anAIS->createRadius(aCircle, aFlyoutPnt, aValue);
return anAIS;
}