From: nds Date: Sat, 21 Jun 2014 08:25:20 +0000 (+0400) Subject: refs #80 - Sketch base GUI: create/draw point, circle and arc X-Git-Tag: V_0.4.4~272 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=258a626d26271b93bae55eb0803de020e2b6f315;p=modules%2Fshaper.git refs #80 - Sketch base GUI: create/draw point, circle and arc 1. SetCustomValue for a dimension to show the model value, not a real one 2. Dir2d to add new costructor in Curc2d 3. Visualize Radius dimension 4. projectPointOnFeature for arc and circle (was projectPointOnArc) --- diff --git a/src/GeomAPI/CMakeLists.txt b/src/GeomAPI/CMakeLists.txt index e14d63fe3..b268a83b6 100644 --- a/src/GeomAPI/CMakeLists.txt +++ b/src/GeomAPI/CMakeLists.txt @@ -14,6 +14,7 @@ SET(PROJECT_HEADERS GeomAPI_Lin.h GeomAPI_Lin2d.h GeomAPI_Dir.h + GeomAPI_Dir2d.h GeomAPI_Pln.h GeomAPI_Shape.h ) @@ -28,6 +29,7 @@ SET(PROJECT_SOURCES GeomAPI_Lin.cpp GeomAPI_Lin2d.cpp GeomAPI_Dir.cpp + GeomAPI_Dir2d.cpp GeomAPI_Pln.cpp GeomAPI_Shape.cpp ) diff --git a/src/GeomAPI/GeomAPI_Circ2d.cpp b/src/GeomAPI/GeomAPI_Circ2d.cpp index 4985ae3f4..27854d2a9 100644 --- a/src/GeomAPI/GeomAPI_Circ2d.cpp +++ b/src/GeomAPI/GeomAPI_Circ2d.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -17,6 +18,13 @@ #define MY_CIRC2D static_cast(myImpl) +static gp_Circ2d* newCirc2d(const double theCenterX, const double theCenterY, + const gp_Dir2d theDir, const double theRadius) +{ + gp_Pnt2d aCenter(theCenterX, theCenterY); + return new gp_Circ2d(gp_Ax2d(aCenter, theDir), theRadius); +} + static gp_Circ2d* newCirc2d(const double theCenterX, const double theCenterY, const double thePointX, const double thePointY) { @@ -29,16 +37,25 @@ static gp_Circ2d* newCirc2d(const double theCenterX, const double theCenterY, return NULL; gp_Dir2d aDir(theCenterX - thePointX, theCenterY - thePointY); - return new gp_Circ2d(gp_Ax2d(aCenter, aDir), aRadius); + + return newCirc2d(theCenterX, theCenterY, aDir, aRadius); } - GeomAPI_Circ2d::GeomAPI_Circ2d(const boost::shared_ptr& theCenter, const boost::shared_ptr& theCirclePoint) : GeomAPI_Interface(newCirc2d(theCenter->x(), theCenter->y(), theCirclePoint->x(), theCirclePoint->y())) {} +GeomAPI_Circ2d::GeomAPI_Circ2d(const boost::shared_ptr& theCenter, + const boost::shared_ptr& theDir, + double theRadius) + : GeomAPI_Interface(newCirc2d(theCenter->x(), theCenter->y(), + theDir->impl(), theRadius)) +{ + +} + const boost::shared_ptr GeomAPI_Circ2d::project(const boost::shared_ptr& thePoint) const { boost::shared_ptr aResult; diff --git a/src/GeomAPI/GeomAPI_Circ2d.h b/src/GeomAPI/GeomAPI_Circ2d.h index 8b91d8332..1870cbba8 100644 --- a/src/GeomAPI/GeomAPI_Circ2d.h +++ b/src/GeomAPI/GeomAPI_Circ2d.h @@ -9,6 +9,7 @@ #include class GeomAPI_Pnt2d; +class GeomAPI_Dir2d; /**\class GeomAPI_Circ2d * \ingroup DataModel @@ -22,6 +23,11 @@ public: GeomAPI_Circ2d(const boost::shared_ptr& theCenter, const boost::shared_ptr& theCirclePoint); + /// Creation of circle defined by center point, direction and circle radius + GeomAPI_Circ2d(const boost::shared_ptr& theCenter, + const boost::shared_ptr& theDir, + double theRadius); + /// Project point on line const boost::shared_ptr project(const boost::shared_ptr& thePoint) const; }; diff --git a/src/GeomAPI/GeomAPI_Dir2d.cpp b/src/GeomAPI/GeomAPI_Dir2d.cpp new file mode 100644 index 000000000..fd795ab19 --- /dev/null +++ b/src/GeomAPI/GeomAPI_Dir2d.cpp @@ -0,0 +1,44 @@ +// File: GeomAPI_Dir2d.cpp +// Created: 23 Apr 2014 +// Author: Mikhail PONIKAROV + +#include +#include + +#include + +#define MY_DIR static_cast(myImpl) + +GeomAPI_Dir2d::GeomAPI_Dir2d(const double theX, const double theY) + : GeomAPI_Interface(new gp_Dir2d(theX, theY)) +{} + +GeomAPI_Dir2d::GeomAPI_Dir2d(const boost::shared_ptr& theCoords) + : GeomAPI_Interface(new gp_Dir2d(theCoords->x(), theCoords->y())) +{} + +double GeomAPI_Dir2d::x() const +{ + return MY_DIR->X(); +} + +double GeomAPI_Dir2d::y() const +{ + return MY_DIR->Y(); +} + +const boost::shared_ptr GeomAPI_Dir2d::xy() +{ + return boost::shared_ptr(new GeomAPI_XY(MY_DIR->X(), MY_DIR->Y())); +} + +double GeomAPI_Dir2d::dot(const boost::shared_ptr& theArg) const +{ + return MY_DIR->Dot(theArg->impl()); +} + +double GeomAPI_Dir2d::cross(const boost::shared_ptr& theArg) const +{ + return MY_DIR->XY().Crossed(theArg->impl().XY()); +} + diff --git a/src/GeomAPI/GeomAPI_Dir2d.h b/src/GeomAPI/GeomAPI_Dir2d.h new file mode 100644 index 000000000..4c9e6fc14 --- /dev/null +++ b/src/GeomAPI/GeomAPI_Dir2d.h @@ -0,0 +1,41 @@ +// File: GeomAPI_Dir2d.hxx +// Created: 23 Apr 2014 +// Author: Mikhail PONIKAROV + +#ifndef GeomAPI_Dir2d_HeaderFile +#define GeomAPI_Dir2d_HeaderFile + +#include +#include + +class GeomAPI_XY; + +/**\class GeomAPI_Dir2d + * \ingroup DataModel + * \brief 2D direction defined by three normalized coordinates + */ + +class GEOMAPI_EXPORT GeomAPI_Dir2d: public GeomAPI_Interface +{ +public: + /// Creation of direction by coordinates + GeomAPI_Dir2d(const double theX, const double theY); + /// Creation of direction by coordinates + GeomAPI_Dir2d(const boost::shared_ptr& theCoords); + + /// returns X coordinate + double x() const; + /// returns Y coordinate + double y() const; + + /// returns coordinates of the direction + const boost::shared_ptr xy(); + + /// result is a scalar product of directions + double dot(const boost::shared_ptr& theArg) const; + /// result is a cross product of two directions + double cross(const boost::shared_ptr& theArg) const; +}; + +#endif + diff --git a/src/GeomAPI/GeomAPI_Pnt2d.cpp b/src/GeomAPI/GeomAPI_Pnt2d.cpp index 1b4ee554b..e1cdf3d28 100644 --- a/src/GeomAPI/GeomAPI_Pnt2d.cpp +++ b/src/GeomAPI/GeomAPI_Pnt2d.cpp @@ -4,6 +4,9 @@ #include #include +#include +#include +#include #include @@ -37,6 +40,16 @@ void GeomAPI_Pnt2d::setY(const double theY) return MY_PNT2D->SetY(theY); } +boost::shared_ptr GeomAPI_Pnt2d::to3D(const boost::shared_ptr& theOrigin, + const boost::shared_ptr& theDirX, + const boost::shared_ptr& theDirY) +{ + boost::shared_ptr aSum = theOrigin->xyz()->added( + theDirX->xyz()->multiplied(x()))->added(theDirY->xyz()->multiplied(y())); + + return boost::shared_ptr(new GeomAPI_Pnt(aSum)); +} + const boost::shared_ptr GeomAPI_Pnt2d::xy() { return boost::shared_ptr(new GeomAPI_XY(MY_PNT2D->X(), MY_PNT2D->Y())); diff --git a/src/GeomAPI/GeomAPI_Pnt2d.h b/src/GeomAPI/GeomAPI_Pnt2d.h index a1faf626c..91aec7eee 100644 --- a/src/GeomAPI/GeomAPI_Pnt2d.h +++ b/src/GeomAPI/GeomAPI_Pnt2d.h @@ -9,6 +9,8 @@ #include class GeomAPI_XY; +class GeomAPI_Pnt; +class GeomAPI_Dir; /**\class GeomAPI_Pnt2d * \ingroup DataModel @@ -33,6 +35,11 @@ public: /// sets Y coordinate void setY(const double theY); + /// Returns the 3D point + boost::shared_ptr to3D(const boost::shared_ptr& theOrigin, + const boost::shared_ptr& theDirX, + const boost::shared_ptr& theDirY); + /// returns coordinates of the point const boost::shared_ptr xy(); diff --git a/src/PartSet/PartSet_ConstraintDistancePrs.cpp b/src/PartSet/PartSet_ConstraintDistancePrs.cpp index 29a0d19c2..d63e98c26 100644 --- a/src/PartSet/PartSet_ConstraintDistancePrs.cpp +++ b/src/PartSet/PartSet_ConstraintDistancePrs.cpp @@ -112,14 +112,10 @@ Handle(AIS_InteractiveObject) PartSet_ConstraintDistancePrs::createPresentation( if (!theFeature || !theSketch) return anAIS; /* - boost::shared_ptr aData = theSketch->data(); - boost::shared_ptr anOrigin = - boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_ORIGIN)); - boost::shared_ptr aNormal = - boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_NORM)); - gp_Pln aPlane(aNormal->x(), aNormal->y(), aNormal->z(), 0); - - aData = theFeature->data(); + boost::shared_ptr aGPlane = PartSet_Tools::sketchPlane(theSketch); + gp_Pln aPlane = aGPlane->impl(); + + boost::shared_ptr aData = theFeature->data(); boost::shared_ptr anAttr = boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_ENTITY_A)); if (!anAttr) diff --git a/src/PartSet/PartSet_ConstraintLengthPrs.cpp b/src/PartSet/PartSet_ConstraintLengthPrs.cpp index 716b435eb..67df7c4c7 100644 --- a/src/PartSet/PartSet_ConstraintLengthPrs.cpp +++ b/src/PartSet/PartSet_ConstraintLengthPrs.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -119,14 +120,10 @@ Handle(AIS_InteractiveObject) PartSet_ConstraintLengthPrs::createPresentation(Fe if (!theFeature || !theSketch) return thePreviuos; - boost::shared_ptr aData = theSketch->data(); - boost::shared_ptr anOrigin = - boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_ORIGIN)); - boost::shared_ptr aNormal = - boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_NORM)); - gp_Pln aPlane(aNormal->x(), aNormal->y(), aNormal->z(), 0/*D*/); + boost::shared_ptr aGPlane = PartSet_Tools::sketchPlane(theSketch); + gp_Pln aPlane = aGPlane->impl(); - aData = theFeature->data(); + boost::shared_ptr aData = theFeature->data(); boost::shared_ptr anAttr = boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_ENTITY_A)); if (!anAttr) @@ -139,6 +136,10 @@ Handle(AIS_InteractiveObject) PartSet_ConstraintLengthPrs::createPresentation(Fe 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(); + aData = aFeature->data(); if (!aData->isValid()) return thePreviuos; @@ -164,6 +165,7 @@ Handle(AIS_InteractiveObject) PartSet_ConstraintLengthPrs::createPresentation(Fe if (anAIS.IsNull()) { Handle(AIS_LengthDimension) aDimAIS = new AIS_LengthDimension (aP1, aP2, aPlane); + aDimAIS->SetCustomValue(aValue); Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect(); anAspect->MakeArrows3d (Standard_False); @@ -186,6 +188,7 @@ Handle(AIS_InteractiveObject) PartSet_ConstraintLengthPrs::createPresentation(Fe 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); diff --git a/src/PartSet/PartSet_ConstraintRadiusPrs.cpp b/src/PartSet/PartSet_ConstraintRadiusPrs.cpp index bee75f1c3..216f800fe 100644 --- a/src/PartSet/PartSet_ConstraintRadiusPrs.cpp +++ b/src/PartSet/PartSet_ConstraintRadiusPrs.cpp @@ -5,7 +5,8 @@ #include #include -#include +#include +#include #include #include @@ -14,9 +15,15 @@ #include #include +#include #include +#include #include #include +#include +#include + +#include #include #include @@ -25,7 +32,10 @@ #include #include +#include #include +#include +#include using namespace std; @@ -42,26 +52,31 @@ std::string PartSet_ConstraintRadiusPrs::getKind() bool PartSet_ConstraintRadiusPrs::setFeature(FeaturePtr theFeature, const PartSet_SelectionMode& theMode) { bool aResult = false; - if (feature() && theMode == SM_FirstPoint && - (theFeature && theFeature->getKind() == SKETCH_CIRCLE_KIND || - theFeature && theFeature->getKind() == SKETCH_ARC_KIND)) { + if (!feature() || theMode != SM_FirstPoint || !theFeature) { + return aResult; + } + std::string aKind = theFeature->getKind(); + if (aKind == SKETCH_CIRCLE_KIND || aKind == SKETCH_ARC_KIND) { // set length feature boost::shared_ptr aData = feature()->data(); boost::shared_ptr aRef = boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_ENTITY_A)); aRef->setFeature(theFeature); - // set length value - /*aData = theFeature->data(); - boost::shared_ptr aPoint1 = - boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_START)); - boost::shared_ptr aPoint2 = - boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_END)); - - double aLenght = aPoint1->pnt()->distance(aPoint2->pnt()); - */ - double aLenght = 50; - PartSet_Tools::setFeatureValue(feature(), aLenght, CONSTRAINT_ATTR_VALUE); + double aLength = 50; + bool isValid; + if (aKind == SKETCH_CIRCLE_KIND) { + aLength = PartSet_Tools::featureValue(theFeature, CIRCLE_ATTR_RADIUS, isValid); + } + else if (aKind == SKETCH_ARC_KIND) { + boost::shared_ptr aCenterAttr = + boost::dynamic_pointer_cast(theFeature->data()->attribute(ARC_ATTR_CENTER)); + boost::shared_ptr aStartAttr = + boost::dynamic_pointer_cast(theFeature->data()->attribute(ARC_ATTR_START)); + aLength = aCenterAttr->pnt()->distance(aStartAttr->pnt()); + } + + PartSet_Tools::setFeatureValue(feature(), aLength, CONSTRAINT_ATTR_VALUE); aResult = true; } return aResult; @@ -75,31 +90,16 @@ PartSet_SelectionMode PartSet_ConstraintRadiusPrs::setPoint(double theX, double { case SM_SecondPoint: { boost::shared_ptr aData = feature()->data(); - /*boost::shared_ptr anAttr = - boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_ENTITY_A)); - FeaturePtr aFeature; - if (anAttr) { - aFeature = anAttr->feature(); - if (aFeature->getKind() != SKETCH_LINE_KIND) { - aFeature = FeaturePtr(); - } - } + boost::shared_ptr aPoint = boost::shared_ptr (new GeomAPI_Pnt2d(theX, theY)); - boost::shared_ptr aFeatureLin = PartSet_FeatureLinePrs::createLin2d(aFeature); - boost::shared_ptr aResult = aFeatureLin->project(aPoint); - double aDistance = aPoint->distance(aResult); - double aStartX, aStartY; - PartSet_FeatureLinePrs::getLinePoint(aFeature, LINE_ATTR_START, aStartX, aStartY); + PartSet_Tools::setFeaturePoint(feature(), theX, theY, SKETCH_CONSTRAINT_ATTR_CIRCLE_POINT); - if (!aFeatureLin->isRight(aPoint)) - aDistance = -aDistance; - */ - double aDistance = 40; - AttributeDoublePtr aFlyoutAttr = - boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE)); - aFlyoutAttr->setValue(aDistance); + //double aDistance = 40; + //AttributeDoublePtr aFlyoutAttr = + // boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE)); + //aFlyoutAttr->setValue(aDistance); aMode = SM_DonePoint; } @@ -117,52 +117,61 @@ Handle(AIS_InteractiveObject) PartSet_ConstraintRadiusPrs::createPresentation(Fe Handle(AIS_InteractiveObject) anAIS = thePreviuos; if (!theFeature || !theSketch) return anAIS; - /* - boost::shared_ptr aData = theSketch->data(); - boost::shared_ptr anOrigin = - boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_ORIGIN)); - boost::shared_ptr aNormal = - boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_NORM)); - gp_Pln aPlane(aNormal->x(), aNormal->y(), aNormal->z(), 0); - - aData = theFeature->data(); + + boost::shared_ptr aData = theFeature->data(); boost::shared_ptr anAttr = boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_ENTITY_A)); if (!anAttr) - return thePreviuos; + return anAIS; FeaturePtr aFeature = anAttr->feature(); - if (!aFeature || aFeature->getKind() != SKETCH_LINE_KIND) - return thePreviuos; - - boost::shared_ptr aFlyoutAttr = - boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE)); - double aFlyout = aFlyoutAttr->value(); - - aData = aFeature->data(); - if (!aData->isValid()) - return thePreviuos; - - boost::shared_ptr aPointStart = - boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_START)); - boost::shared_ptr aPointEnd = - boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_END)); - - gp_Pnt aPoint1, aPoint2; - PartSet_Tools::convertTo3D(aPointStart->x(), aPointStart->y(), theSketch, aPoint1); - PartSet_Tools::convertTo3D(aPointEnd->x(), aPointEnd->y(), theSketch, aPoint2); - - //Build dimension here - gp_Pnt aP1 = aPoint1; - gp_Pnt aP2 = aPoint2; - if (aFlyout < 0) { - aP1 = aPoint2; - aP2 = aPoint1; - } + if (!aFeature || aFeature->getKind() != SKETCH_CIRCLE_KIND) + return anAIS; - Handle(AIS_InteractiveObject) anAIS = thePreviuos; + + //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(); + + gp_Circ aCircle; + gp_Pnt anAnchorPoint; + double aRadius; + //boost::shared_ptr aShape; + if (aFeature->getKind() == SKETCH_CIRCLE_KIND) { + boost::shared_ptr aData = aFeature->data(); + // a circle + boost::shared_ptr aCenterAttr = + boost::dynamic_pointer_cast(aData->attribute(CIRCLE_ATTR_CENTER)); + 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(); + bool isValid; + aRadius = PartSet_Tools::featureValue(aFeature, CIRCLE_ATTR_RADIUS, isValid); + aCircle = gp_Circ(gp_Ax2(aCenter->impl(), aDir), aRadius); + + // 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); + anAnchorPoint = anAnchor->impl(); + + //aShape = GeomAlgoAPI_EdgeBuilder::line(aCenter, anAnchor); + //boost::shared_ptr theStart, boost::shared_ptr theEnd) + } if (anAIS.IsNull()) { - Handle(AIS_LengthDimension) aDimAIS = new AIS_LengthDimension (aP1, aP2, aPlane); + 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); @@ -170,30 +179,60 @@ Handle(AIS_InteractiveObject) PartSet_ConstraintRadiusPrs::createPresentation(Fe 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->SetFlyout(aFlyout); aDimAIS->SetSelToleranceForText2d(CONSTRAINT_TEXT_SELECTION_TOLERANCE); anAIS = aDimAIS; } else { // update presentation - Handle(AIS_LengthDimension) aDimAIS = Handle(AIS_LengthDimension)::DownCast(anAIS); + Handle(AIS_RadiusDimension) aDimAIS = Handle(AIS_RadiusDimension)::DownCast(anAIS); if (!aDimAIS.IsNull()) { - aDimAIS->SetMeasuredGeometry(aPoint1, aPoint2, aPlane); - aDimAIS->SetFlyout(aFlyout); + 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) +{ + boost::shared_ptr aData = theFeature->data(); + boost::shared_ptr anAttr = + boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_ENTITY_A)); + if (!anAttr) + return; + FeaturePtr aFeature = anAttr->feature(); + if (!aFeature) + return; + + gp_Circ aCircle; + gp_Pnt anAnchorPoint; + if (aFeature->getKind() == SKETCH_CIRCLE_KIND) { + PartSet_FeatureCirclePrs::projectPointOnFeature(aFeature, theSketch, thePoint, theView, theX, theY); + } + else if (aFeature->getKind() == SKETCH_ARC_KIND) { + PartSet_FeatureArcPrs::projectPointOnFeature(aFeature, theSketch, thePoint, theView, theX, theY); + } + // TODO: a bug in AIS_RadiusDimension: + // The anchor point can't be myCirc.Location() - an exception is raised. + // But we need exactly this case... + // We want to show a radius dimension starting from the circle centre and + // ending at the user-defined point. + // Also, if anchor point coincides with myP2, the radius dimension is not displayed at all. + double aDelta = 1/1000.0; + theX += aDelta; + theY += aDelta; +} + std::string PartSet_ConstraintRadiusPrs::getAttribute(const PartSet_SelectionMode& theMode) const { return ""; diff --git a/src/PartSet/PartSet_ConstraintRadiusPrs.h b/src/PartSet/PartSet_ConstraintRadiusPrs.h index c71ac902b..754f2dadf 100644 --- a/src/PartSet/PartSet_ConstraintRadiusPrs.h +++ b/src/PartSet/PartSet_ConstraintRadiusPrs.h @@ -10,8 +10,11 @@ #include "PartSet_FeaturePrs.h" #include "PartSet_Constants.h" +#include + class GeomDataAPI_Point2D; class Handle_AIS_InteractiveObject; +class Handle_V3d_View; /*! \class PartSet_ConstraintRadiusPrs @@ -81,6 +84,16 @@ public: /// \param theY the vertical point coordinate virtual boost::shared_ptr findPoint(FeaturePtr theFeature, double theX, double theY); + /// Project the view point on the feature. The output coordinates belong to the feature + /// \param theFeature a feature + /// \param theSketch the sketch feature + /// \param thePoint a viewer point + /// \param theView the OCC view + /// \theX the output horizontal coordinate of a projected point + /// \theY the output vertical coordinate of a projected point + static void projectPointOnFeature(FeaturePtr theFeature, FeaturePtr theSketch, gp_Pnt& thePoint, + Handle_V3d_View theView, double& theX, double& theY); + protected: /// Returns the feature point in the selection mode position. /// \param theMode the current operation selection mode. The feature attribute depends on the mode diff --git a/src/PartSet/PartSet_FeatureArcPrs.cpp b/src/PartSet/PartSet_FeatureArcPrs.cpp index 0e76f6e8b..29d65a9cf 100644 --- a/src/PartSet/PartSet_FeatureArcPrs.cpp +++ b/src/PartSet/PartSet_FeatureArcPrs.cpp @@ -168,16 +168,17 @@ boost::shared_ptr PartSet_FeatureArcPrs::findPoint(FeatureP return aPoint2D; } -void PartSet_FeatureArcPrs::projectPointOnArc(gp_Pnt& thePoint, Handle(V3d_View) theView, - double& theX, double& theY) +void PartSet_FeatureArcPrs::projectPointOnFeature(FeaturePtr theFeature, FeaturePtr theSketch, + gp_Pnt& thePoint, Handle(V3d_View) theView, + double& theX, double& theY) { - FeaturePtr aSketch = sketch(); + FeaturePtr aSketch = theSketch; if (aSketch) { double aX, anY; PartSet_Tools::convertTo2D(thePoint, aSketch, theView, aX, anY); // circle origin point and radius - boost::shared_ptr aData = feature()->data(); + boost::shared_ptr aData = theFeature->data(); boost::shared_ptr aCenter = boost::dynamic_pointer_cast (aData->attribute(ARC_ATTR_CENTER)); boost::shared_ptr aStart = boost::dynamic_pointer_cast diff --git a/src/PartSet/PartSet_FeatureArcPrs.h b/src/PartSet/PartSet_FeatureArcPrs.h index 80d07e014..b06e0882b 100644 --- a/src/PartSet/PartSet_FeatureArcPrs.h +++ b/src/PartSet/PartSet_FeatureArcPrs.h @@ -51,8 +51,15 @@ public: /// \return next attribute selection mode virtual PartSet_SelectionMode getNextMode(const std::string& theAttribute) const; - void projectPointOnArc(gp_Pnt& thePoint, Handle_V3d_View theView, - double& theX, double& theY); + /// Project the view point on the feature. The output coordinates belong to the feature + /// \param theFeature a feature + /// \param theSketch the sketch feature + /// \param thePoint a viewer point + /// \param theView the OCC view + /// \theX the output horizontal coordinate of a projected point + /// \theY the output vertical coordinate of a projected point + static void projectPointOnFeature(FeaturePtr theFeature, FeaturePtr theSketch, gp_Pnt& thePoint, + Handle_V3d_View theView, double& theX, double& theY); /// \brief Move the full feature. /// \param theDeltaX the delta for X coordinate is moved diff --git a/src/PartSet/PartSet_FeatureCirclePrs.cpp b/src/PartSet/PartSet_FeatureCirclePrs.cpp index 71bd9721c..70f957134 100644 --- a/src/PartSet/PartSet_FeatureCirclePrs.cpp +++ b/src/PartSet/PartSet_FeatureCirclePrs.cpp @@ -10,13 +10,18 @@ #include #include +#include #include +#include +#include +#include #include #include #include #include +#include #include using namespace std; @@ -129,6 +134,33 @@ boost::shared_ptr PartSet_FeatureCirclePrs::findPoint(Featu return aPoint2D; } +void PartSet_FeatureCirclePrs::projectPointOnFeature(FeaturePtr theFeature, FeaturePtr theSketch, + gp_Pnt& thePoint, Handle(V3d_View) theView, + double& theX, double& theY) +{ + FeaturePtr aSketch = theSketch; + if (aSketch) { + double aX, anY; + PartSet_Tools::convertTo2D(thePoint, aSketch, theView, aX, anY); + + // circle origin point and radius + boost::shared_ptr aData = theFeature->data(); + boost::shared_ptr aCenter = boost::dynamic_pointer_cast + (aData->attribute(CIRCLE_ATTR_CENTER)); + bool isValid; + double aRadius = PartSet_Tools::featureValue(theFeature, CIRCLE_ATTR_RADIUS, isValid); + + boost::shared_ptr aNormal(new GeomAPI_Dir2d(aX, anY)); + boost::shared_ptr aCirc(new GeomAPI_Circ2d(aCenter->pnt(), aNormal, aRadius)); + boost::shared_ptr aGeomPoint2d(new GeomAPI_Pnt2d(aX, anY)); + boost::shared_ptr aPnt2d = aCirc->project(aGeomPoint2d); + if (aPnt2d) { + theX = aPnt2d->x(); + theY = aPnt2d->y(); + } + } +} + boost::shared_ptr PartSet_FeatureCirclePrs::featurePoint (const PartSet_SelectionMode& theMode) { diff --git a/src/PartSet/PartSet_FeatureCirclePrs.h b/src/PartSet/PartSet_FeatureCirclePrs.h index 72a3d4855..c3ec1c667 100644 --- a/src/PartSet/PartSet_FeatureCirclePrs.h +++ b/src/PartSet/PartSet_FeatureCirclePrs.h @@ -10,7 +10,10 @@ #include "PartSet_FeaturePrs.h" #include "PartSet_Constants.h" +#include + class GeomDataAPI_Point2D; +class Handle_V3d_View; /*! \class PartSet_FeatureCirclePrs @@ -65,6 +68,16 @@ public: /// \param theY the vertical point coordinate virtual boost::shared_ptr findPoint(FeaturePtr theFeature, double theX, double theY); + /// Project the view point on the feature. The output coordinates belong to the feature + /// \param theFeature a feature + /// \param theSketch the sketch feature + /// \param thePoint a viewer point + /// \param theView the OCC view + /// \theX the output horizontal coordinate of a projected point + /// \theY the output vertical coordinate of a projected point + static void projectPointOnFeature(FeaturePtr theFeature, FeaturePtr theSketch, gp_Pnt& thePoint, + Handle_V3d_View theView, double& theX, double& theY); + protected: /// Returns the feature point in the selection mode position. /// \param theMode the current operation selection mode. The feature attribute depends on the mode diff --git a/src/PartSet/PartSet_OperationCreateConstraint.cpp b/src/PartSet/PartSet_OperationCreateConstraint.cpp index 20558f3cb..576cf4009 100644 --- a/src/PartSet/PartSet_OperationCreateConstraint.cpp +++ b/src/PartSet/PartSet_OperationCreateConstraint.cpp @@ -127,8 +127,9 @@ void PartSet_OperationCreateConstraint::mouseReleased(QMouseEvent* theEvent, Han PartSet_SelectionMode aMode = myFeaturePrs->setPoint(aX, anY, myPointSelectionMode); // show value edit dialog - double aValue; - if (PartSet_Tools::featureValue(feature(), CONSTRAINT_ATTR_VALUE, aValue)) { + bool isValid; + double aValue = PartSet_Tools::featureValue(feature(), CONSTRAINT_ATTR_VALUE, isValid); + if (isValid) { showEditor(theEvent, aValue); setPointSelectionMode(SM_ThirdPoint/*aMode*/); } @@ -151,15 +152,13 @@ void PartSet_OperationCreateConstraint::mouseMoved(QMouseEvent* theEvent, Handle double aX, anY; gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView); PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY); - /*if (myPointSelectionMode == SM_ThirdPoint) { - if (feature()->getKind() == SKETCH_ARC_KIND) { - boost::shared_ptr anArcPrs = - boost::dynamic_pointer_cast(myFeaturePrs); - if (anArcPrs) { - anArcPrs->projectPointOnArc(aPoint, theView, aX, anY); - } + if (feature()->getKind() == PartSet_ConstraintRadiusPrs::getKind()) { + boost::shared_ptr anArcPrs = + boost::dynamic_pointer_cast(myFeaturePrs); + if (anArcPrs) { + anArcPrs->projectPointOnFeature(feature(), sketch(), aPoint, theView, aX, anY); } - }*/ + } myFeaturePrs->setPoint(aX, anY, myPointSelectionMode); flushUpdated(); diff --git a/src/PartSet/PartSet_OperationCreateFeature.cpp b/src/PartSet/PartSet_OperationCreateFeature.cpp index 23c746219..da80e62b2 100644 --- a/src/PartSet/PartSet_OperationCreateFeature.cpp +++ b/src/PartSet/PartSet_OperationCreateFeature.cpp @@ -145,7 +145,7 @@ void PartSet_OperationCreateFeature::mouseReleased(QMouseEvent* theEvent, Handle boost::shared_ptr anArcPrs = boost::dynamic_pointer_cast(myFeaturePrs); if (anArcPrs) { - anArcPrs->projectPointOnArc(aPoint, theView, aX, anY); + anArcPrs->projectPointOnFeature(feature(), sketch(), aPoint, theView, aX, anY); } } PartSet_SelectionMode aMode = myFeaturePrs->setPoint(aX, anY, myPointSelectionMode); @@ -174,7 +174,7 @@ void PartSet_OperationCreateFeature::mouseMoved(QMouseEvent* theEvent, Handle(V3 boost::shared_ptr anArcPrs = boost::dynamic_pointer_cast(myFeaturePrs); if (anArcPrs) { - anArcPrs->projectPointOnArc(aPoint, theView, aX, anY); + anArcPrs->projectPointOnFeature(feature(), sketch(), aPoint, theView, aX, anY); } } } diff --git a/src/PartSet/PartSet_OperationEditConstraint.cpp b/src/PartSet/PartSet_OperationEditConstraint.cpp index 97057d764..0fb85e986 100644 --- a/src/PartSet/PartSet_OperationEditConstraint.cpp +++ b/src/PartSet/PartSet_OperationEditConstraint.cpp @@ -188,9 +188,9 @@ void PartSet_OperationEditConstraint::mouseDoubleClick(QMouseEvent* theEvent, Ha { // changed if (!theSelected.empty()) { - - double aValue; - if(PartSet_Tools::featureValue(feature(), CONSTRAINT_ATTR_VALUE, aValue)) { + bool isValid; + double aValue = PartSet_Tools::featureValue(feature(), CONSTRAINT_ATTR_VALUE, isValid); + if (isValid) { QPoint aPos = theEvent->globalPos(); myEditor->start(aPos, aValue); } diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index 30bdc0b13..45b994e52 100644 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -11,6 +11,9 @@ #include #include #include +#include +#include +#include #include #include @@ -252,20 +255,21 @@ void PartSet_Tools::setFeatureValue(FeaturePtr theFeature, double theValue, anAttribute->setValue(theValue); } -bool PartSet_Tools::featureValue(FeaturePtr theFeature, const std::string& theAttribute, - double& theValue) +double PartSet_Tools::featureValue(FeaturePtr theFeature, const std::string& theAttribute, + bool& isValid) { - bool aResult = false; - if (!theFeature) - return aResult; - boost::shared_ptr aData = theFeature->data(); - AttributeDoublePtr anAttribute = - boost::dynamic_pointer_cast(aData->attribute(theAttribute)); - if (anAttribute) { - theValue = anAttribute->value(); - aResult = true; + isValid = false; + double aValue; + if (theFeature) { + boost::shared_ptr aData = theFeature->data(); + AttributeDoublePtr anAttribute = + boost::dynamic_pointer_cast(aData->attribute(theAttribute)); + if (anAttribute) { + aValue = anAttribute->value(); + isValid = true; + } } - return aResult; + return aValue; } void PartSet_Tools::createConstraint(FeaturePtr theSketch, @@ -307,3 +311,40 @@ boost::shared_ptr PartSet_Tools::findPoint(FeaturePtr theFe return aPoint2D; } + +boost::shared_ptr PartSet_Tools::sketchPlane(FeaturePtr theSketch) +{ + boost::shared_ptr aPlane; + double aA, aB, aC, aD; + + boost::shared_ptr aData = theSketch->data(); + boost::shared_ptr anOrigin = + boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_ORIGIN)); + boost::shared_ptr aNormal = + boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_NORM)); + aA = aNormal->x(); + aB = aNormal->y(); + aC = aNormal->z(); + aD = 0; + + aPlane = boost::shared_ptr(new GeomAPI_Pln(aA, aB, aC, aD)); + return aPlane; +} + +boost::shared_ptr PartSet_Tools::point3D( + boost::shared_ptr thePoint2D, + FeaturePtr theSketch) +{ + boost::shared_ptr aPoint; + if (!theSketch || !thePoint2D) + return aPoint; + + boost::shared_ptr aC = + boost::dynamic_pointer_cast(theSketch->data()->attribute(SKETCH_ATTR_ORIGIN)); + boost::shared_ptr aX = + boost::dynamic_pointer_cast(theSketch->data()->attribute(SKETCH_ATTR_DIRX)); + boost::shared_ptr aY = + boost::dynamic_pointer_cast(theSketch->data()->attribute(SKETCH_ATTR_DIRY)); + + return thePoint2D->to3D(aC->pnt(), aX->dir(), aY->dir()); +} diff --git a/src/PartSet/PartSet_Tools.h b/src/PartSet/PartSet_Tools.h index 0ddb45e7f..d43feb7bf 100644 --- a/src/PartSet/PartSet_Tools.h +++ b/src/PartSet/PartSet_Tools.h @@ -20,6 +20,9 @@ class Handle_V3d_View; class XGUI_ViewerPrs; class GeomDataAPI_Point2D; +class GeomAPI_Pln; +class GeomAPI_Pnt2d; +class GeomAPI_Pnt; class PartSet_FeaturePrs; /*! @@ -92,10 +95,10 @@ public: /// \brief Returns the feature double value if it is. /// \param theFeature the feature /// \param theAttribute the feature attribute - /// \param theValue the horizontal coordinate - /// \returns the state whether the value is correct - static bool featureValue(FeaturePtr theFeature, const std::string& theAttribute, - double& theValue); + /// \param isValid an output parameter whether the value is valid + /// \returns the feature value + static double featureValue(FeaturePtr theFeature, const std::string& theAttribute, + bool& isValid); /// Creates a constraint on two points /// \param thePoint1 the first point @@ -111,6 +114,17 @@ public: static boost::shared_ptr findPoint(FeaturePtr theFeature, double theX, double theY); + /// Create a sketch plane instance + /// \param theSketch a sketch feature + /// \return API object of geom plane + static boost::shared_ptr sketchPlane(FeaturePtr theSketch); + + /// Create a point 3D on a basis of point 2D and sketch feature + /// \param thePoint2D a point on a sketch + /// \param theSketch a sketch feature + /// \return API object of point 3D + static boost::shared_ptr point3D(boost::shared_ptr thePoint2D, + FeaturePtr theSketch); private: /// Return the distance between the feature and the point /// \param theFeature feature object