From: vsv Date: Fri, 21 Aug 2015 12:32:13 +0000 (+0300) Subject: Added Angle constraint symbol X-Git-Tag: V_1.4.0_beta4~294 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a8ed41e2ed5a9528335f0a5d1a2203f35048620e;p=modules%2Fshaper.git Added Angle constraint symbol --- diff --git a/src/GeomAPI/GeomAPI_Lin.cpp b/src/GeomAPI/GeomAPI_Lin.cpp index 79db6e186..dba5834ab 100644 --- a/src/GeomAPI/GeomAPI_Lin.cpp +++ b/src/GeomAPI/GeomAPI_Lin.cpp @@ -74,10 +74,10 @@ const std::shared_ptr GeomAPI_Lin::intersect( gp_Lin2d aPrjLine1 = ProjLib::Project(aPlane, *MY_LIN); gp_Lin2d aPrjLine2 = ProjLib::Project(aPlane, theLine->impl()); - IntAna2d_AnaIntersection anInter(aPrjLine1, aPrjLine1); + IntAna2d_AnaIntersection anInter(aPrjLine1, aPrjLine2); if (!anInter.IsDone() || anInter.IsEmpty()) return std::shared_ptr(); - const gp_Pnt2d& anIntPnt2d = anInter.Point(0).Value(); + const gp_Pnt2d& anIntPnt2d = anInter.Point(1).Value(); gp_Pnt aResult = ElSLib::Value(anIntPnt2d.X(), anIntPnt2d.Y(), aPlane); return std::shared_ptr( diff --git a/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp b/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp index c298122ba..fc2df7237 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp @@ -24,6 +24,7 @@ const double tolerance = 1.e-7; SketchPlugin_ConstraintAngle::SketchPlugin_ConstraintAngle() { + myFlyoutUpdate = false; } void SketchPlugin_ConstraintAngle::initAttributes() @@ -31,6 +32,7 @@ void SketchPlugin_ConstraintAngle::initAttributes() data()->addAttribute(SketchPlugin_Constraint::VALUE(), ModelAPI_AttributeDouble::typeId()); data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::typeId()); data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::typeId()); + data()->addAttribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT(), GeomDataAPI_Point2D::typeId()); } void SketchPlugin_ConstraintAngle::execute() @@ -55,6 +57,11 @@ AISObjectPtr SketchPlugin_ConstraintAngle::getAISObject(AISObjectPtr thePrevious if (!anAIS) { anAIS = SketcherPrs_Factory::angleConstraint(this, sketch()->coordinatePlane()); } + + // Set color from preferences + std::vector aRGB = Config_PropManager::color("Visualization", "sketch_dimension_color", + SKETCH_DIMENSION_COLOR); + anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]); return anAIS; } @@ -76,6 +83,10 @@ void SketchPlugin_ConstraintAngle::attributeChanged(const std::string& theID) double anAngle = calculateAngle(); aValueAttr->setValue(anAngle); } + } else if (theID == SketchPlugin_Constraint::FLYOUT_VALUE_PNT() && !myFlyoutUpdate) { + // Recalculate flyout point in local coordinates + std::shared_ptr aFlyoutAttr = + std::dynamic_pointer_cast(attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); } } @@ -124,3 +135,16 @@ double SketchPlugin_ConstraintAngle::calculateAngle() anAngle = aDirA->angle(aDirB) * 180.0 / PI; return anAngle; } + +void SketchPlugin_ConstraintAngle::move(double theDeltaX, double theDeltaY) +{ + std::shared_ptr aData = data(); + if (!aData->isValid()) + return; + + myFlyoutUpdate = true; + std::shared_ptr aFlyoutAttr = std::dynamic_pointer_cast< + GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); + aFlyoutAttr->setValue(aFlyoutAttr->x() + theDeltaX, aFlyoutAttr->y() + theDeltaY); + myFlyoutUpdate = false; +} diff --git a/src/SketchPlugin/SketchPlugin_ConstraintAngle.h b/src/SketchPlugin/SketchPlugin_ConstraintAngle.h index 92f5057fb..29f37f82f 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintAngle.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintAngle.h @@ -47,11 +47,19 @@ class SketchPlugin_ConstraintAngle : public SketchPlugin_ConstraintBase /// Returns the AIS preview SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious); + /// Moves the feature + /// \param theDeltaX the delta for X coordinate is moved + /// \param theDeltaY the delta for Y coordinate is moved + SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY); + /// Calculate current value of the angle double calculateAngle(); /// \brief Use plugin manager for features creation SketchPlugin_ConstraintAngle(); + +private: + bool myFlyoutUpdate; ///< to avoid cyclic dependencies on automatic updates of flyout point }; #endif diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 3c529f688..8418520a8 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -233,6 +233,7 @@ + diff --git a/src/SketcherPrs/CMakeLists.txt b/src/SketcherPrs/CMakeLists.txt index 692fc2205..dac2c7bb5 100644 --- a/src/SketcherPrs/CMakeLists.txt +++ b/src/SketcherPrs/CMakeLists.txt @@ -18,6 +18,7 @@ SET(PROJECT_HEADERS SketcherPrs_LengthDimension.h SketcherPrs_Mirror.h SketcherPrs_Transformation.h + SketcherPrs_Angle.h ) SET(PROJECT_SOURCES @@ -37,6 +38,7 @@ SET(PROJECT_SOURCES SketcherPrs_LengthDimension.cpp SketcherPrs_Mirror.cpp SketcherPrs_Transformation.cpp + SketcherPrs_Angle.cpp ) SET(PROJECT_LIBRARIES diff --git a/src/SketcherPrs/SketcherPrs_Angle.cpp b/src/SketcherPrs/SketcherPrs_Angle.cpp new file mode 100644 index 000000000..085aa754c --- /dev/null +++ b/src/SketcherPrs/SketcherPrs_Angle.cpp @@ -0,0 +1,139 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: SketcherPrs_Angle.cpp +// Created: 20 August 2015 +// Author: Vitaly SMETANNIKOV + +#include "SketcherPrs_Angle.h" +#include "SketcherPrs_Tools.h" + +#include +#include + +#include +#include +#include + +#include +#include + +#include +#include + +#define PI 3.1415926535897932 + +IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Angle, AIS_AngleDimension); +IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Angle, AIS_AngleDimension); + + + + + +SketcherPrs_Angle::SketcherPrs_Angle(ModelAPI_Feature* theConstraint, + const std::shared_ptr& thePlane) +: AIS_AngleDimension(gp_Pnt(0,0,0), gp_Pnt(1,0,0), gp_Pnt(0,1,0)), myConstraint(theConstraint), myPlane(thePlane) +{ + myAspect = new Prs3d_DimensionAspect(); + myAspect->MakeArrows3d(false); + myAspect->MakeText3d(false); + myAspect->MakeTextShaded(false); + myAspect->MakeUnitsDisplayed(false); + myAspect->TextAspect()->SetHeight(SketcherPrs_Tools::getDefaultTextHeight()); + myAspect->ArrowAspect()->SetLength(SketcherPrs_Tools::getArrowSize()); + + SetDimensionAspect(myAspect); + SetSelToleranceForText2d(SketcherPrs_Tools::getDefaultTextHeight()); +} + +void SketcherPrs_Angle::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, + const Handle(Prs3d_Presentation)& thePresentation, + const Standard_Integer theMode) +{ + DataPtr aData = myConstraint->data(); + + // Flyout point + std::shared_ptr aFlyoutAttr = + std::dynamic_pointer_cast + (aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); + if (!aFlyoutAttr->isInitialized()) + return; // can not create a good presentation + + std::shared_ptr aFlyoutPnt = myPlane->to3D(aFlyoutAttr->x(), aFlyoutAttr->y()); + + AttributeRefAttrPtr anAttr1 = aData->refattr(SketchPlugin_Constraint::ENTITY_A()); + if (!anAttr1->isInitialized()) + return; + + AttributeRefAttrPtr anAttr2 = aData->refattr(SketchPlugin_Constraint::ENTITY_B()); + if (!anAttr2->isInitialized()) + return; + + // Get angle edges + ObjectPtr aObj1 = anAttr1->object(); + ObjectPtr aObj2 = anAttr2->object(); + + std::shared_ptr aShape1 = SketcherPrs_Tools::getShape(aObj1); + std::shared_ptr aShape2 = SketcherPrs_Tools::getShape(aObj2); + + if (!aShape1 && !aShape2) + return; + + TopoDS_Shape aTEdge1 = aShape1->impl(); + TopoDS_Shape aTEdge2 = aShape2->impl(); + + TopoDS_Edge aEdge1 = TopoDS::Edge(aTEdge1); + TopoDS_Edge aEdge2 = TopoDS::Edge(aTEdge2); + SetMeasuredGeometry(aEdge1, aEdge2); + + // Compute intersection point + TopoDS_Vertex aV1, aV2; + TopExp::Vertices(aEdge1, aV1, aV2); + gp_Pnt aPnt1 = BRep_Tool::Pnt(aV1); + gp_Pnt aPnt2 = BRep_Tool::Pnt(aV2); + std::shared_ptr aL1(new GeomAPI_Lin(aPnt1.X(), aPnt1.Y(), aPnt1.Z(), + aPnt2.X(), aPnt2.Y(), aPnt2.Z())); + TopExp::Vertices(aEdge2, aV1, aV2); + aPnt1 = BRep_Tool::Pnt(aV1); + aPnt2 = BRep_Tool::Pnt(aV2); + std::shared_ptr aL2(new GeomAPI_Lin(aPnt1.X(), aPnt1.Y(), aPnt1.Z(), + aPnt2.X(), aPnt2.Y(), aPnt2.Z())); + + std::shared_ptr aInter = aL1->intersect(aL2); + gp_Pnt aCenter = aInter->impl(); + + gp_Pnt aFLyPnt(aFlyoutPnt->x(), aFlyoutPnt->y(), aFlyoutPnt->z()); + double aDist = aCenter.Distance(aFLyPnt); + SetFlyout(aDist); + + // Angle value is in degrees + AttributeDoublePtr aVal = aData->real(SketchPlugin_Constraint::VALUE()); + SetCustomValue(aVal->value() * PI / 180.0); + + AIS_AngleDimension::Compute(thePresentationManager, thePresentation, theMode); +} + +void SketcherPrs_Angle::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, + const Standard_Integer theMode) +{ + Standard_Integer aMode; + switch (theMode) { + case 0: // we should use selection of all objects + aMode = 0; + break; + case SketcherPrs_Tools::Sel_Dimension_All: + aMode = 0; + break; + case SketcherPrs_Tools::Sel_Dimension_Line: + aMode = 1; + break; + case SketcherPrs_Tools::Sel_Dimension_Text: + aMode = 2; + break; + default: { + // there are own selection modes, so the others should be ignored + // otherwise, the text selection appears in the viewer + return; + } + } + AIS_AngleDimension::ComputeSelection(aSelection, aMode); +} diff --git a/src/SketcherPrs/SketcherPrs_Angle.h b/src/SketcherPrs/SketcherPrs_Angle.h index 365e82bc2..d540dbbf5 100644 --- a/src/SketcherPrs/SketcherPrs_Angle.h +++ b/src/SketcherPrs/SketcherPrs_Angle.h @@ -1,13 +1,53 @@ // Copyright (C) 2014-20xx CEA/DEN, EDF R&D // File: SketcherPrs_Angle.h -// Created: 26 March 2015 +// Created: 20 August 2015 // Author: Vitaly SMETANNIKOV #ifndef SketcherPrs_Angle_H #define SketcherPrs_Angle_H +#include +#include +#include +#include -#endif \ No newline at end of file +DEFINE_STANDARD_HANDLE(SketcherPrs_Angle, AIS_AngleDimension) + +/** +* \ingroup GUI +* A class for representation of angle constraint +*/ +class SketcherPrs_Angle : public AIS_AngleDimension +{ +public: + /// Constructor + /// \param theConstraint a constraint feature + /// \param thePlane a coordinate plane of current sketch + Standard_EXPORT SketcherPrs_Angle(ModelAPI_Feature* theConstraint, + const std::shared_ptr& thePlane); + + DEFINE_STANDARD_RTTI(SketcherPrs_Angle) +protected: + /// Redefinition of virtual function + Standard_EXPORT virtual void Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, + const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode = 0); + + /// Redefinition of virtual function + Standard_EXPORT virtual void ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, + const Standard_Integer aMode); + +private: + /// Constraint feature + ModelAPI_Feature* myConstraint; + + /// Plane of the current sketcher + std::shared_ptr myPlane; + + Handle(Prs3d_DimensionAspect) myAspect; +}; + + +#endif diff --git a/src/SketcherPrs/SketcherPrs_Factory.cpp b/src/SketcherPrs/SketcherPrs_Factory.cpp index 6a8672dac..6971d7826 100644 --- a/src/SketcherPrs/SketcherPrs_Factory.cpp +++ b/src/SketcherPrs/SketcherPrs_Factory.cpp @@ -17,6 +17,7 @@ #include "SketcherPrs_LengthDimension.h" #include "SketcherPrs_Mirror.h" #include "SketcherPrs_Transformation.h" +#include "SketcherPrs_Angle.h" #define CONSTRAINT_PRS_IMPL(NAME, CLASS) \ AISObjectPtr SketcherPrs_Factory::NAME(ModelAPI_Feature* theConstraint, \ @@ -37,6 +38,7 @@ CONSTRAINT_PRS_IMPL(tangentConstraint, SketcherPrs_Tangent); CONSTRAINT_PRS_IMPL(radiusConstraint, SketcherPrs_Radius); CONSTRAINT_PRS_IMPL(lengthDimensionConstraint, SketcherPrs_LengthDimension); CONSTRAINT_PRS_IMPL(mirrorConstraint, SketcherPrs_Mirror); +CONSTRAINT_PRS_IMPL(angleConstraint, SketcherPrs_Angle); AISObjectPtr SketcherPrs_Factory::horisontalConstraint(ModelAPI_Feature* theConstraint, @@ -74,9 +76,3 @@ AISObjectPtr SketcherPrs_Factory::rotateConstraint(ModelAPI_Feature* theConstrai aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aPrs)); return aAISObj; } - -AISObjectPtr SketcherPrs_Factory::angleConstraint(ModelAPI_Feature* theConstraint, - const std::shared_ptr& thePlane) -{ - return AISObjectPtr(new GeomAPI_AISObject()); -} diff --git a/src/SketcherPrs/SketcherPrs_LengthDimension.cpp b/src/SketcherPrs/SketcherPrs_LengthDimension.cpp index 6e3db9291..ea58e6515 100644 --- a/src/SketcherPrs/SketcherPrs_LengthDimension.cpp +++ b/src/SketcherPrs/SketcherPrs_LengthDimension.cpp @@ -55,36 +55,6 @@ void SketcherPrs_LengthDimension::Compute(const Handle(PrsMgr_PresentationManage gp_Pnt aPnt1, aPnt2; if (!getPoints(aPnt1, aPnt2)) return; - //DataPtr aData = myConstraint->data(); - - //AttributePtr aFlyOutAttribute = aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()); - //if (!aFlyOutAttribute->isInitialized()) { - // return; // not possible to show length because points are not defined - //} - //std::shared_ptr aFlyOutAttr = - // std::dynamic_pointer_cast(aFlyOutAttribute); - //std::shared_ptr aFlyoutPnt = myPlane->to3D(aFlyOutAttr->x(), aFlyOutAttr->y()); - //gp_Pnt aFlyPnt = aFlyoutPnt->impl(); - - //double aDistance = aPnt1.Distance(aPnt2); - - //double aFlyout = 0; - //double aDist = 0.0; - //if (aDistance < Precision::Confusion()) - // aDist = aPnt1.Distance(aFlyPnt); - //else { - // gp_Lin aLine(aPnt1, gp_Vec(aPnt1, aPnt2)); - // aDist = aLine.Distance(aFlyPnt); - //} - - //gp_XYZ aLineDir = aPnt2.XYZ().Subtracted(aPnt1.XYZ()); - //gp_XYZ aFOutDir = aFlyPnt.XYZ().Subtracted(aPnt1.XYZ()); - //gp_XYZ aNorm = myPlane->norm()->xyz()->impl(); - //if (aLineDir.Crossed(aFOutDir).Dot(aNorm) < 0) - // aDist = -aDist; - //aFlyout = aDist; - - //SetFlyout(aFlyout); SetFlyout(SketcherPrs_Tools::getFlyoutDistance(myConstraint)); SetMeasuredGeometry(aPnt1, aPnt2, myPlane->impl()); AIS_LengthDimension::Compute(thePresentationManager, thePresentation, theMode); diff --git a/src/SketcherPrs/SketcherPrs_Radius.cpp b/src/SketcherPrs/SketcherPrs_Radius.cpp index c08d7ab94..a99bdc9af 100644 --- a/src/SketcherPrs/SketcherPrs_Radius.cpp +++ b/src/SketcherPrs/SketcherPrs_Radius.cpp @@ -53,8 +53,6 @@ void SketcherPrs_Radius::Compute(const Handle(PrsMgr_PresentationManager3d)& the if (!aFlyoutAttr->isInitialized()) return; // can not create a good presentation - std::shared_ptr aFlyoutPnt = myPlane->to3D(aFlyoutAttr->x(), aFlyoutAttr->y()); - // Get circle std::shared_ptr anAttr = std::dynamic_pointer_cast @@ -85,14 +83,6 @@ void SketcherPrs_Radius::Compute(const Handle(PrsMgr_PresentationManager3d)& the GeomAPI_Circ aCircle(aCenter, aNormal, aRadius); std::shared_ptr anAnchor = SketcherPrs_Tools::getAnchorPoint(myConstraint, myPlane); - //std::shared_ptr anAnchor = aCircle.project(aFlyoutPnt); - //std::shared_ptr anAnchorXYZ = anAnchor->xyz(); - //anAnchorXYZ = anAnchorXYZ->decreased(aCenter->xyz()); - //std::shared_ptr 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()); SetMeasuredGeometry(aCircle.impl(), anAnchor->impl()); SetCustomValue(aRadius);