From: azv Date: Tue, 24 Jun 2014 12:29:11 +0000 (+0400) Subject: Merge remote-tracking branch 'remotes/origin/master' into SketchSolver X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2FSketchSolver;p=modules%2Fshaper.git Merge remote-tracking branch 'remotes/origin/master' into SketchSolver --- f7991e68aa62680f63a488848b8a4dc12e4e25b1 diff --cc src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp index b6ddb808a,d6e2b0075..599cb72e9 --- a/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp @@@ -36,102 -24,29 +36,120 @@@ void SketchPlugin_ConstraintDistance::i void SketchPlugin_ConstraintDistance::execute() { + boost::shared_ptr aData = data(); + + boost::shared_ptr anAttr_A = + boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_ENTITY_A)); + boost::shared_ptr anAttr_B = + boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_ENTITY_B)); + + AttributeDoublePtr anAttribute = + boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_VALUE)); + + if (anAttr_A && anAttr_B && anAttribute->value() == 0) + { + FeaturePtr aFeature_A = anAttr_A->feature(); + FeaturePtr aFeature_B = anAttr_B->feature(); + + double aValue = 40; // TODO + anAttribute->setValue(aValue); + } } -const boost::shared_ptr& SketchPlugin_ConstraintDistance::preview() +Handle(AIS_InteractiveObject) SketchPlugin_ConstraintDistance::getAISShape( + Handle_AIS_InteractiveObject thePrevious) { - /// \todo Preview for distance constraint - return getPreview(); + if (!sketch()) + return thePrevious; + + boost::shared_ptr aPlane = sketch()->plane(); + + DataPtr aData = data(); + boost::shared_ptr aPoint_A = getFeaturePoint(aData, CONSTRAINT_ATTR_ENTITY_A); + boost::shared_ptr aPoint_B = getFeaturePoint(aData, CONSTRAINT_ATTR_ENTITY_B); + if (!aPoint_A || !aPoint_B) + return thePrevious; + + // fly out calculation + boost::shared_ptr aFlyOutAttr = + boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT)); + boost::shared_ptr aFlyOutPnt = aFlyOutAttr->pnt(); + + boost::shared_ptr aFeatureLin = + boost::shared_ptr(new GeomAPI_Lin2d(aPoint_A->x(), aPoint_A->y(), + aPoint_B->x(), aPoint_B->y())); + boost::shared_ptr aResult = aFeatureLin->project(aFlyOutPnt); + double aDistance = aFlyOutPnt->distance(aResult); + + if (!aFeatureLin->isRight(aFlyOutPnt)) + aDistance = -aDistance; + double aFlyout = aDistance; + + //Build dimension here + boost::shared_ptr aPoint1 = sketch()->to3D(aPoint_A->x(), aPoint_A->y()); + boost::shared_ptr aPoint2 = sketch()->to3D(aPoint_B->x(), aPoint_B->y()); + if (aFlyout < 0) + aPoint1.swap(aPoint2); + + // value calculation + boost::shared_ptr aValueAttr = + boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_VALUE)); + double aValue = aValueAttr->value(); + if (aValue == 0) { // TODO! the default value + aValue = aPoint1->distance(aPoint2); + } + + Handle(AIS_InteractiveObject) anAIS = thePrevious; + if (anAIS.IsNull()) + { + Handle(AIS_LengthDimension) aDimAIS = + new AIS_LengthDimension(aPoint1->impl(), aPoint2->impl(), aPlane->impl()); + 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->SetFlyout(aFlyout); + aDimAIS->SetSelToleranceForText2d(CONSTRAINT_TEXT_SELECTION_TOLERANCE); + + anAIS = aDimAIS; + } + else { + // update presentation + Handle(AIS_LengthDimension) aDimAIS = Handle(AIS_LengthDimension)::DownCast(anAIS); + if (!aDimAIS.IsNull()) { + aDimAIS->SetMeasuredGeometry(aPoint1->impl(), aPoint2->impl(), aPlane->impl()); + aDimAIS->SetCustomValue(aValue); + aDimAIS->SetFlyout(aFlyout); + + aDimAIS->Redisplay(Standard_True); + } + } + return anAIS; +} + + +boost::shared_ptr getFeaturePoint(DataPtr theData, + const std::string& theAttribute) +{ + boost::shared_ptr aPointAttr; + + if (!theData) + return aPointAttr; + + FeaturePtr aFeature; + boost::shared_ptr anAttr = + boost::dynamic_pointer_cast(theData->attribute(theAttribute)); + if (anAttr) + aFeature = anAttr->feature(); + + if (aFeature && aFeature->getKind() == SKETCH_POINT_KIND) + aPointAttr = boost::dynamic_pointer_cast + (aFeature->data()->attribute(POINT_ATTR_COORD)); + return aPointAttr; }