From: vsv Date: Wed, 22 Aug 2018 12:52:28 +0000 (+0300) Subject: Issue #2601: Select any plane if a dimension is perpendicular to current screen X-Git-Tag: SHAPER_V9_1_0RC1~37 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=37141f9a9065d83d95ef314be1d7597d4e0d277b;p=modules%2Fshaper.git Issue #2601: Select any plane if a dimension is perpendicular to current screen --- diff --git a/src/FeaturesPlugin/FeaturesPlugin_Measurement.cpp b/src/FeaturesPlugin/FeaturesPlugin_Measurement.cpp index 56cc199db..c92896194 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Measurement.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Measurement.cpp @@ -360,26 +360,37 @@ AISObjectPtr FeaturesPlugin_Measurement::lengthDimension(AISObjectPtr thePreviou gp_Pnt aPnt2(aPoint2->impl()); double aLength = aPnt1.Distance(aPnt2); - gp_Pln aPlane = myScreenPlane->impl(); // gce_MP.Value(); - aPlane.SetLocation(aPnt1); + if (aLength > 0) { + gp_Pln aPlane = myScreenPlane->impl(); // gce_MP.Value(); + aPlane.SetLocation(aPnt1); + + gp_XYZ aNormal = aPlane.Axis().Direction().XYZ(); + gp_XYZ aVec(aPnt2.X() - aPnt1.X(), aPnt2.Y() - aPnt1.Y(), aPnt2.Z() - aPnt1.Z()); + double aDot = aNormal.Dot(aVec); + if (fabs(aDot - aLength) <= Precision::Confusion()) { + aPlane = gp_Pln(aPnt1, aPlane.XAxis().Direction()); + } - Handle(AIS_LengthDimension) aDim; - if (thePrevious.get()) { - aAISObj = thePrevious; - Handle(AIS_InteractiveObject) aAIS = aAISObj->impl(); - aDim = Handle(AIS_LengthDimension)::DownCast(aAIS); - if (aDim.IsNull()) { + Handle(AIS_LengthDimension) aDim; + if (thePrevious.get()) { + aAISObj = thePrevious; + Handle(AIS_InteractiveObject) aAIS = aAISObj->impl(); + aDim = Handle(AIS_LengthDimension)::DownCast(aAIS); + if (aDim.IsNull()) { + aDim = new AIS_LengthDimension(aTEdge, aPlane); + aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aDim)); + } + else { + aDim->SetMeasuredGeometry(aTEdge, aPlane); + } + } + else { aDim = new AIS_LengthDimension(aTEdge, aPlane); + aAISObj = AISObjectPtr(new GeomAPI_AISObject()); aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aDim)); - } else { - aDim->SetMeasuredGeometry(aTEdge, aPlane); } - } else { - aDim = new AIS_LengthDimension(aTEdge, aPlane); - aAISObj = AISObjectPtr(new GeomAPI_AISObject()); - aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aDim)); + aDim->SetFlyout(aLength / 3.); } - aDim->SetFlyout(aLength / 3.); } return aAISObj; } @@ -413,27 +424,38 @@ AISObjectPtr FeaturesPlugin_Measurement::distanceDimension(AISObjectPtr thePrevi gp_Pnt aPnt1 = aDist.PointOnShape1(1); gp_Pnt aPnt2 = aDist.PointOnShape2(1); double aDistance = aDist.Value(); - gp_Pln aPlane = myScreenPlane->impl(); - aPlane.SetLocation(aPnt1); - - Handle(AIS_LengthDimension) aDim; - if (thePrevious.get()) { - aAISObj = thePrevious; - Handle(AIS_InteractiveObject) aAIS = aAISObj->impl(); - aDim = Handle(AIS_LengthDimension)::DownCast(aAIS); - if (aDim.IsNull()) { + if (aDistance > 0) { + gp_Pln aPlane = myScreenPlane->impl(); + aPlane.SetLocation(aPnt1); + + gp_XYZ aNormal = aPlane.Axis().Direction().XYZ(); + gp_XYZ aVec(aPnt2.X() - aPnt1.X(), aPnt2.Y() - aPnt1.Y(), aPnt2.Z() - aPnt1.Z()); + double aDot = aNormal.Dot(aVec); + if (fabs(aDot - aDistance) <= Precision::Confusion()) { + aPlane = gp_Pln(aPnt1, aPlane.XAxis().Direction()); + } + + Handle(AIS_LengthDimension) aDim; + if (thePrevious.get()) { + aAISObj = thePrevious; + Handle(AIS_InteractiveObject) aAIS = aAISObj->impl(); + aDim = Handle(AIS_LengthDimension)::DownCast(aAIS); + if (aDim.IsNull()) { + aDim = new AIS_LengthDimension(aPnt1, aPnt2, aPlane); + aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aDim)); + } + else { + aDim->SetMeasuredGeometry(aPnt1, aPnt2, aPlane); + aDim->SetFlyout(aDistance / 3.); + } + } + else { + aAISObj = AISObjectPtr(new GeomAPI_AISObject()); aDim = new AIS_LengthDimension(aPnt1, aPnt2, aPlane); aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aDim)); - } else { - aDim->SetMeasuredGeometry(aPnt1, aPnt2, aPlane); - aDim->SetFlyout(aDistance / 3.); } - } else { - aAISObj = AISObjectPtr(new GeomAPI_AISObject()); - aDim = new AIS_LengthDimension(aPnt1, aPnt2, aPlane); - aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aDim)); + aDim->SetFlyout(aDistance / 3.); } - aDim->SetFlyout(aDistance / 3.); } } }