#include <SketchPlugin_Feature.h>
#include <SketchPlugin_Sketch.h>
#include <SketchPlugin_Line.h>
+#include <SketchPlugin_Point.h>
#include <SketchPlugin_ConstraintDistance.h>
#include <GeomDataAPI_Point2D.h>
#include <GeomAPI_Pnt2d.h>
#include <GeomAPI_Lin2d.h>
+#include <GeomAPI_Pln.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_Document.h>
#include <ModelAPI_AttributeDouble.h>
#include <AIS_InteractiveObject.hxx>
+#include <AIS_LengthDimension.hxx>
+
#include <Precision.hxx>
+#include <gp_Pln.hxx>
using namespace std;
PartSet_SelectionMode PartSet_ConstraintDistancePrs::setFeature(FeaturePtr theFeature, const PartSet_SelectionMode& theMode)
{
PartSet_SelectionMode aMode = theMode;
- if (feature() && theFeature && theFeature->getKind() == SKETCH_LINE_KIND && theMode == SM_FirstPoint)
+ if (!feature() || !theFeature)
+ return aMode;
+
+ std::string anArgument;
+ if (theMode == SM_FirstPoint) {
+ anArgument = CONSTRAINT_ATTR_ENTITY_A;
+ aMode = SM_SecondPoint;
+ }
+ else if (theMode == SM_SecondPoint) {
+ anArgument = CONSTRAINT_ATTR_ENTITY_B;
+ aMode = SM_LastPoint;
+ }
+ if (theFeature->getKind() == SKETCH_POINT_KIND)
{
// set length feature
boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
- boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
+ boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(anArgument));
aRef->setFeature(theFeature);
+ }
+ if (theMode == SM_SecondPoint) {
// set length value
- aData = theFeature->data();
- boost::shared_ptr<GeomDataAPI_Point2D> aPoint1 =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_START));
- boost::shared_ptr<GeomDataAPI_Point2D> aPoint2 =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_END));
-
- double aLenght = aPoint1->pnt()->distance(aPoint2->pnt());
- PartSet_Tools::setFeatureValue(feature(), aLenght, CONSTRAINT_ATTR_VALUE);
- aMode = SM_SecondPoint;
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint_A = getFeaturePoint(feature(), CONSTRAINT_ATTR_ENTITY_A);
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint_B = getFeaturePoint(feature(), CONSTRAINT_ATTR_ENTITY_B);
+
+ if (aPoint_A && aPoint_B) {
+ double aLenght = aPoint_A->pnt()->distance(aPoint_B->pnt());
+ PartSet_Tools::setFeatureValue(feature(), aLenght, CONSTRAINT_ATTR_VALUE);
+ }
}
+
return aMode;
}
switch (theMode)
{
case SM_LastPoint: {
- boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
- boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr =
- boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
- FeaturePtr aFeature;
- if (anAttr) {
- aFeature = anAttr->feature();
- if (aFeature->getKind() != SKETCH_LINE_KIND) {
- aFeature = FeaturePtr();
- }
- }
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint_A = getFeaturePoint(feature(),
+ CONSTRAINT_ATTR_ENTITY_A);
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint_B = getFeaturePoint(feature(),
+ CONSTRAINT_ATTR_ENTITY_B);
+
boost::shared_ptr<GeomAPI_Pnt2d> aPoint = boost::shared_ptr<GeomAPI_Pnt2d>
(new GeomAPI_Pnt2d(theX, theY));
- boost::shared_ptr<GeomAPI_Lin2d> aFeatureLin = PartSet_FeatureLinePrs::createLin2d(aFeature);
+ boost::shared_ptr<GeomAPI_Lin2d> aFeatureLin = boost::shared_ptr<GeomAPI_Lin2d>
+ (new GeomAPI_Lin2d(aPoint_A->x(), aPoint_A->y(),
+ aPoint_B->x(), aPoint_B->y()));
boost::shared_ptr<GeomAPI_Pnt2d> aResult = aFeatureLin->project(aPoint);
double aDistance = aPoint->distance(aResult);
- double aStartX, aStartY;
- PartSet_FeatureLinePrs::getLinePoint(aFeature, LINE_ATTR_START, aStartX, aStartY);
-
if (!aFeatureLin->isRight(aPoint))
aDistance = -aDistance;
- AttributeDoublePtr aFlyoutAttr =
- boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE));
+ AttributeDoublePtr aFlyoutAttr = boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>
+ (feature()->data()->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE));
aFlyoutAttr->setValue(aDistance);
aMode = SM_DonePoint;
Handle(AIS_InteractiveObject) anAIS = thePreviuos;
if (!theFeature || !theSketch)
return anAIS;
- /*
boost::shared_ptr<GeomAPI_Pln> aGPlane = PartSet_Tools::sketchPlane(theSketch);
gp_Pln aPlane = aGPlane->impl<gp_Pln>();
- boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
- boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr =
- boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
- if (!anAttr)
- return thePreviuos;
- FeaturePtr aFeature = anAttr->feature();
- if (!aFeature || aFeature->getKind() != SKETCH_LINE_KIND)
- return thePreviuos;
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint_A = getFeaturePoint(theFeature, CONSTRAINT_ATTR_ENTITY_A);
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint_B = getFeaturePoint(theFeature, CONSTRAINT_ATTR_ENTITY_B);
+ if (!aPoint_A || !aPoint_B)
+ return anAIS;
+ boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
boost::shared_ptr<ModelAPI_AttributeDouble> aFlyoutAttr =
boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE));
double aFlyout = aFlyoutAttr->value();
- aData = aFeature->data();
- if (!aData->isValid())
- return thePreviuos;
-
- boost::shared_ptr<GeomDataAPI_Point2D> aPointStart =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_START));
- boost::shared_ptr<GeomDataAPI_Point2D> aPointEnd =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_END));
+ boost::shared_ptr<ModelAPI_AttributeDouble> aValueAttr =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_VALUE));
+ double aValue = aValueAttr->value();
gp_Pnt aPoint1, aPoint2;
- PartSet_Tools::convertTo3D(aPointStart->x(), aPointStart->y(), theSketch, aPoint1);
- PartSet_Tools::convertTo3D(aPointEnd->x(), aPointEnd->y(), theSketch, aPoint2);
+ PartSet_Tools::convertTo3D(aPoint_A->x(), aPoint_A->y(), theSketch, aPoint1);
+ PartSet_Tools::convertTo3D(aPoint_B->x(), aPoint_B->y(), theSketch, aPoint2);
//Build dimension here
gp_Pnt aP1 = aPoint1;
aP2 = aPoint1;
}
- Handle(AIS_InteractiveObject) anAIS = thePreviuos;
if (anAIS.IsNull())
{
- Handle(AIS_LengthDimension) aDimAIS = new AIS_LengthDimension (aP1, aP2, aPlane);
+ Handle(AIS_LengthDimension) aDimAIS = new AIS_LengthDimension(aP1, aP2, aPlane);
+ aDimAIS->SetCustomValue(aValue);
Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect();
anAspect->MakeArrows3d (Standard_False);
anAspect->TextAspect()->SetHeight(CONSTRAINT_TEXT_HEIGHT);
anAspect->MakeTextShaded(false);
aDimAIS->DimensionAspect()->MakeUnitsDisplayed(false);
- //if (isUnitsDisplayed)
- //{
- // aDimAIS->SetDisplayUnits (aDimDlg->GetUnits ());
- //}
aDimAIS->SetDimensionAspect (anAspect);
aDimAIS->SetFlyout(aFlyout);
aDimAIS->SetSelToleranceForText2d(CONSTRAINT_TEXT_SELECTION_TOLERANCE);
Handle(AIS_LengthDimension) aDimAIS = Handle(AIS_LengthDimension)::DownCast(anAIS);
if (!aDimAIS.IsNull()) {
aDimAIS->SetMeasuredGeometry(aPoint1, aPoint2, aPlane);
+ aDimAIS->SetCustomValue(aValue);
aDimAIS->SetFlyout(aFlyout);
aDimAIS->Redisplay(Standard_True);
}
}
-*/
return anAIS;
}
+boost::shared_ptr<GeomDataAPI_Point2D> PartSet_ConstraintDistancePrs::getFeaturePoint
+ (FeaturePtr theFeature,
+ const std::string& theAttribute)
+{
+ boost::shared_ptr<GeomDataAPI_Point2D> aPointAttr;
+
+ FeaturePtr aFeature = PartSet_Tools::feature(theFeature, theAttribute, SKETCH_POINT_KIND);
+ if (aFeature)
+ aPointAttr = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
+ (aFeature->data()->attribute(POINT_ATTR_COORD));
+ return aPointAttr;
+}
+
std::string PartSet_ConstraintDistancePrs::getAttribute(const PartSet_SelectionMode& theMode) const
{
return "";