From: azv Date: Tue, 24 Jun 2014 13:52:25 +0000 (+0400) Subject: Move generation of AIS presentation into SketchPlugin X-Git-Tag: V_0.4.4~254^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a0366082107c7651476fa984d9f238556ba34d05;p=modules%2Fshaper.git Move generation of AIS presentation into SketchPlugin Presentation of Radius constraint --- diff --git a/src/GeomAPI/CMakeLists.txt b/src/GeomAPI/CMakeLists.txt index b268a83b6..28187984c 100644 --- a/src/GeomAPI/CMakeLists.txt +++ b/src/GeomAPI/CMakeLists.txt @@ -5,6 +5,7 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) SET(PROJECT_HEADERS GeomAPI.h + GeomAPI_Circ.h GeomAPI_Circ2d.h GeomAPI_Interface.h GeomAPI_XY.h @@ -20,6 +21,7 @@ SET(PROJECT_HEADERS ) SET(PROJECT_SOURCES + GeomAPI_Circ.cpp GeomAPI_Circ2d.cpp GeomAPI_Interface.cpp GeomAPI_XY.cpp diff --git a/src/GeomAPI/GeomAPI_Circ.cpp b/src/GeomAPI/GeomAPI_Circ.cpp new file mode 100644 index 000000000..811ef698b --- /dev/null +++ b/src/GeomAPI/GeomAPI_Circ.cpp @@ -0,0 +1,63 @@ +// File: GeomAPI_Circ2cpp +// Created: 24 Jun 2014 +// Author: Artem ZHIDKOV + +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +#define MY_CIRC static_cast(myImpl) + +static gp_Circ* newCirc(const gp_Pnt& theCenter, + const gp_Dir& theDir, + const double theRadius) +{ + return new gp_Circ(gp_Ax2(theCenter, theDir), theRadius); +} + +GeomAPI_Circ::GeomAPI_Circ(const boost::shared_ptr& theCenter, + const boost::shared_ptr& theDir, + double theRadius) + : GeomAPI_Interface(newCirc(theCenter->impl(), + theDir->impl(), theRadius)) +{ +} + +const boost::shared_ptr GeomAPI_Circ::project(const boost::shared_ptr& thePoint) const +{ + boost::shared_ptr aResult; + if (!MY_CIRC) + return aResult; + + Handle(Geom_Circle) aCircle = new Geom_Circle(*MY_CIRC); + + const gp_Pnt& aPoint = thePoint->impl(); + + GeomAPI_ProjectPointOnCurve aProj(aPoint, aCircle); + Standard_Integer aNbPoint = aProj.NbPoints(); + if (aNbPoint > 0) + { + double aMinDistance = 0, aDistance; + for (Standard_Integer j = 1; j <= aNbPoint; j++) + { + gp_Pnt aNewPoint = aProj.Point(j); + aDistance = aNewPoint.Distance(aPoint); + if (!aMinDistance || aDistance < aMinDistance) + { + aMinDistance = aDistance; + aResult = boost::shared_ptr( + new GeomAPI_Pnt(aNewPoint.X(), aNewPoint.Y(), aNewPoint.Z())); + } + } + } + return aResult; +} + diff --git a/src/GeomAPI/GeomAPI_Circ.h b/src/GeomAPI/GeomAPI_Circ.h new file mode 100644 index 000000000..c1a23bbf6 --- /dev/null +++ b/src/GeomAPI/GeomAPI_Circ.h @@ -0,0 +1,32 @@ +// File: GeomAPI_Circ.h +// Created: 24 Jun 2014 +// Author: Artem ZHIDKOV + +#ifndef GeomAPI_Circ_HeaderFile +#define GeomAPI_Circ_HeaderFile + +#include +#include + +class GeomAPI_Pnt; +class GeomAPI_Dir; + +/**\class GeomAPI_Circ + * \ingroup DataModel + * \brief Circle in 3D + */ + +class GEOMAPI_EXPORT GeomAPI_Circ: public GeomAPI_Interface +{ +public: + /// Creation of circle defined by center point, direction and circle radius + GeomAPI_Circ(const boost::shared_ptr& theCenter, + const boost::shared_ptr& theDir, + double theRadius); + + /// Project point on circle + const boost::shared_ptr project(const boost::shared_ptr& thePoint) const; +}; + +#endif + diff --git a/src/GeomAPI/GeomAPI_Circ2d.h b/src/GeomAPI/GeomAPI_Circ2d.h index 1870cbba8..11d18f6b6 100644 --- a/src/GeomAPI/GeomAPI_Circ2d.h +++ b/src/GeomAPI/GeomAPI_Circ2d.h @@ -13,7 +13,7 @@ class GeomAPI_Dir2d; /**\class GeomAPI_Circ2d * \ingroup DataModel - * \brief Line in 2D + * \brief Circle in 2D */ class GEOMAPI_EXPORT GeomAPI_Circ2d: public GeomAPI_Interface diff --git a/src/PartSet/PartSet_ConstraintRadiusPrs.cpp b/src/PartSet/PartSet_ConstraintRadiusPrs.cpp index a5430b8da..634a44bb6 100644 --- a/src/PartSet/PartSet_ConstraintRadiusPrs.cpp +++ b/src/PartSet/PartSet_ConstraintRadiusPrs.cpp @@ -106,101 +106,6 @@ PartSet_SelectionMode PartSet_ConstraintRadiusPrs::setPoint(double theX, double return aMode; } -Handle(AIS_InteractiveObject) PartSet_ConstraintRadiusPrs::createPresentation(FeaturePtr theFeature, - FeaturePtr theSketch, - Handle(AIS_InteractiveObject) thePreviuos) -{ - Handle(AIS_InteractiveObject) anAIS = thePreviuos; - if (!theFeature || !theSketch) - return anAIS; - - boost::shared_ptr aData = theFeature->data(); - boost::shared_ptr anAttr = - boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_ENTITY_A)); - if (!anAttr) - return anAIS; - FeaturePtr aFeature = anAttr->feature(); - std::string aKind = aFeature ? aFeature->getKind() : ""; - if (aKind != SKETCH_CIRCLE_KIND && aKind != SKETCH_ARC_KIND) - return anAIS; - - //boost::shared_ptr aFlyoutAttr = - // boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE)); - //double aFlyout = aFlyoutAttr->value(); - boost::shared_ptr aValueAttr = - boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_VALUE)); - double aValue = aValueAttr->value(); - - // an anchor point - boost::shared_ptr aAnchorAttr = - boost::dynamic_pointer_cast(theFeature->data()->attribute - (SKETCH_CONSTRAINT_ATTR_CIRCLE_POINT)); - boost::shared_ptr anAnchor2D = aAnchorAttr->pnt(); - boost::shared_ptr anAnchor = PartSet_Tools::point3D(anAnchor2D, theSketch); - gp_Pnt anAnchorPoint = anAnchor->impl(); - - std::string aCenterArgument; - double aRadius; - if (aKind == SKETCH_CIRCLE_KIND) { - aCenterArgument = CIRCLE_ATTR_CENTER; - bool isValid; - aRadius = PartSet_Tools::featureValue(aFeature, CIRCLE_ATTR_RADIUS, isValid); - } - else if (aKind == SKETCH_ARC_KIND) { - aCenterArgument = ARC_ATTR_CENTER; - aRadius = PartSet_FeatureArcPrs::radius(aFeature); - } - - // a circle - boost::shared_ptr aCenterAttr = - boost::dynamic_pointer_cast(aFeature->data()->attribute(aCenterArgument)); - boost::shared_ptr aCenter2D = aCenterAttr->pnt(); - boost::shared_ptr aCenter = PartSet_Tools::point3D(aCenter2D, theSketch); - - boost::shared_ptr aNDir = - boost::dynamic_pointer_cast(theSketch->data()->attribute(SKETCH_ATTR_NORM)); - boost::shared_ptr aNormal(new GeomAPI_Dir(aNDir->x(), aNDir->y(), aNDir->z())); - const gp_Dir& aDir = aNormal->impl(); - - gp_Circ aCircle = gp_Circ(gp_Ax2(aCenter->impl(), aDir), aRadius); - //boost::shared_ptr aShape; - //aShape = GeomAlgoAPI_EdgeBuilder::line(aCenter, anAnchor); - //boost::shared_ptr theStart, boost::shared_ptr theEnd) - - if (anAIS.IsNull()) - { - Handle(AIS_RadiusDimension) aDimAIS = new AIS_RadiusDimension(aCircle, anAnchorPoint); - aDimAIS->SetCustomValue(aValue); - //Handle(AIS_RadiusDimension) aDimAIS = new AIS_RadiusDimension(aShape->impl()); - - 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_RadiusDimension) aDimAIS = Handle(AIS_RadiusDimension)::DownCast(anAIS); - if (!aDimAIS.IsNull()) { - gp_Pnt anAPoint(anAnchorPoint.X(),anAnchorPoint.Y(),anAnchorPoint.Z()); - - aDimAIS->SetMeasuredGeometry(aCircle, anAnchorPoint); - aDimAIS->SetCustomValue(aValue); - //aDimAIS->SetMeasuredGeometry(aShape->impl()); - //aDimAIS->SetFlyout(aFlyout); - aDimAIS->Redisplay(Standard_True); - } - } - return anAIS; -} - void PartSet_ConstraintRadiusPrs::projectPointOnFeature(FeaturePtr theFeature, FeaturePtr theSketch, gp_Pnt& thePoint, Handle(V3d_View) theView, double& theX, double& theY) diff --git a/src/PartSet/PartSet_ConstraintRadiusPrs.h b/src/PartSet/PartSet_ConstraintRadiusPrs.h index 5e87a5fee..2d1ad727c 100644 --- a/src/PartSet/PartSet_ConstraintRadiusPrs.h +++ b/src/PartSet/PartSet_ConstraintRadiusPrs.h @@ -49,15 +49,6 @@ public: virtual PartSet_SelectionMode setPoint(double theX, double theY, const PartSet_SelectionMode& theMode); - /// Creates an AIS presentation if the previous is null or update the given one - /// \param theFeature a feature - /// \param theSketch a feature sketch - /// \param thePrevious a previuos AIS presentation - /// \return a created/changed AIS object with the feature parameters - static Handle_AIS_InteractiveObject createPresentation(FeaturePtr theFeature, - FeaturePtr theSketch, - Handle_AIS_InteractiveObject thePreviuos); - /// Returns the feature attribute name for the selection mode /// \param theMode the current operation selection mode. The feature attribute depends on the mode virtual std::string getAttribute(const PartSet_SelectionMode& theMode) const; diff --git a/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp b/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp index f46792385..a57df918b 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp @@ -4,12 +4,20 @@ #include "SketchPlugin_ConstraintRadius.h" +#include +#include +#include + #include #include + +#include +#include #include -#include +#include #include +#include SketchPlugin_ConstraintRadius::SketchPlugin_ConstraintRadius() { @@ -31,7 +39,83 @@ void SketchPlugin_ConstraintRadius::execute() Handle(AIS_InteractiveObject) SketchPlugin_ConstraintRadius::getAISShape( Handle_AIS_InteractiveObject thePrevious) { - /// \todo Preview for diameter constraint - return thePrevious; + Handle(AIS_InteractiveObject) anAIS = thePrevious; + if (!sketch()) + return anAIS; + + boost::shared_ptr aData = data(); + boost::shared_ptr anAttr = + boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_ENTITY_A)); + if (!anAttr) + return anAIS; + FeaturePtr aFeature = anAttr->feature(); + std::string aKind = aFeature ? aFeature->getKind() : ""; + if (aKind != SKETCH_CIRCLE_KIND && aKind != SKETCH_ARC_KIND) + return anAIS; + + boost::shared_ptr aValueAttr = + boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_VALUE)); + double aValue = aValueAttr->value(); + + // an anchor point + boost::shared_ptr aAnchorAttr = + boost::dynamic_pointer_cast(aData->attribute(SKETCH_CONSTRAINT_ATTR_CIRCLE_POINT)); + boost::shared_ptr anAnchor2D = aAnchorAttr->pnt(); + boost::shared_ptr anAnchor = sketch()->to3D(anAnchor2D->x(), anAnchor2D->y()); + + aData = aFeature->data(); + boost::shared_ptr aCenterAttr; + double aRadius; + if (aKind == SKETCH_CIRCLE_KIND) { + aCenterAttr = boost::dynamic_pointer_cast(aData->attribute(CIRCLE_ATTR_CENTER)); + AttributeDoublePtr aCircRadius = + boost::dynamic_pointer_cast(aData->attribute(CIRCLE_ATTR_RADIUS)); + aRadius = aCircRadius->value(); + } + else if (aKind == SKETCH_ARC_KIND) { + aCenterAttr = boost::dynamic_pointer_cast(aData->attribute(ARC_ATTR_CENTER)); + boost::shared_ptr aStartAttr = + boost::dynamic_pointer_cast(aData->attribute(ARC_ATTR_START)); + aRadius = aCenterAttr->pnt()->distance(aStartAttr->pnt()); + } + + // a circle + boost::shared_ptr aCenter = sketch()->to3D(aCenterAttr->x(), aCenterAttr->y()); + + boost::shared_ptr aNDir = + boost::dynamic_pointer_cast(sketch()->data()->attribute(SKETCH_ATTR_NORM)); + boost::shared_ptr aNormal = aNDir->dir(); + + boost::shared_ptr aCircle(new GeomAPI_Circ(aCenter, aNormal, aRadius)); + + if (anAIS.IsNull()) + { + Handle(AIS_RadiusDimension) aDimAIS = + new AIS_RadiusDimension(aCircle->impl(), anAnchor->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->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(), anAnchor->impl()); + aDimAIS->SetCustomValue(aValue); + aDimAIS->Redisplay(Standard_True); + } + } + return anAIS; }