From: vsv Date: Fri, 27 Mar 2015 14:14:07 +0000 (+0300) Subject: Create dimension presentations X-Git-Tag: V_1.1.0~76 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6aad051f35d9c375d4727ce5f4d1cbfe24fd3838;p=modules%2Fshaper.git Create dimension presentations --- diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp b/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp index 89bc7e429..59ca35b02 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp @@ -9,6 +9,9 @@ #include #include +#include +#include + #include #include #include @@ -20,6 +23,7 @@ const double tolerance = 1e-7; + SketchPlugin_ConstraintDistance::SketchPlugin_ConstraintDistance() { } @@ -66,9 +70,9 @@ bool SketchPlugin_ConstraintDistance::compute(const std::string& theAttributeId) return false; DataPtr aData = data(); - std::shared_ptr aPoint_A = getFeaturePoint( + std::shared_ptr aPoint_A = SketcherPrs_Tools::getFeaturePoint( aData, SketchPlugin_Constraint::ENTITY_A()); - std::shared_ptr aPoint_B = getFeaturePoint( + std::shared_ptr aPoint_B = SketcherPrs_Tools::getFeaturePoint( aData, SketchPlugin_Constraint::ENTITY_B()); std::shared_ptr aPnt_A; @@ -78,18 +82,18 @@ bool SketchPlugin_ConstraintDistance::compute(const std::string& theAttributeId) aPnt_A = aPoint_A->pnt(); aPnt_B = aPoint_B->pnt(); } else if (!aPoint_A && aPoint_B) { - std::shared_ptr aLine = getFeatureLine( + std::shared_ptr aLine = SketcherPrs_Tools::getFeatureLine( aData, SketchPlugin_Constraint::ENTITY_A()); if (aLine) { aPnt_B = aPoint_B->pnt(); - aPnt_A = getProjectionPoint(aLine, aPnt_B); + aPnt_A = SketcherPrs_Tools::getProjectionPoint(aLine, aPnt_B); } } else if (aPoint_A && !aPoint_B) { - std::shared_ptr aLine = getFeatureLine( + std::shared_ptr aLine = SketcherPrs_Tools::getFeatureLine( aData, SketchPlugin_Constraint::ENTITY_B()); if (aLine) { aPnt_A = aPoint_A->pnt(); - aPnt_B = getProjectionPoint(aLine, aPnt_A); + aPnt_B = SketcherPrs_Tools::getProjectionPoint(aLine, aPnt_A); } } if (!aPnt_A || !aPnt_B) @@ -118,61 +122,10 @@ AISObjectPtr SketchPlugin_ConstraintDistance::getAISObject(AISObjectPtr thePrevi if (!sketch()) return thePrevious; - std::shared_ptr aPlane = sketch()->plane(); - - DataPtr aData = data(); - std::shared_ptr aPoint_A = getFeaturePoint( - aData, SketchPlugin_Constraint::ENTITY_A()); - std::shared_ptr aPoint_B = getFeaturePoint( - aData, SketchPlugin_Constraint::ENTITY_B()); - - std::shared_ptr aPnt_A; - std::shared_ptr aPnt_B; - - if (aPoint_A && aPoint_B) { - aPnt_A = aPoint_A->pnt(); - aPnt_B = aPoint_B->pnt(); - } else if (!aPoint_A && aPoint_B) { - std::shared_ptr aLine = getFeatureLine( - aData, SketchPlugin_Constraint::ENTITY_A()); - if (aLine) { - aPnt_B = aPoint_B->pnt(); - aPnt_A = getProjectionPoint(aLine, aPnt_B); - } - } else if (aPoint_A && !aPoint_B) { - std::shared_ptr aLine = getFeatureLine( - aData, SketchPlugin_Constraint::ENTITY_B()); - if (aLine) { - aPnt_A = aPoint_A->pnt(); - aPnt_B = getProjectionPoint(aLine, aPnt_A); - } - } - if (!aPnt_A || !aPnt_B) - return AISObjectPtr(); - - std::shared_ptr aFlyOutAttr = std::dynamic_pointer_cast< - GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); - - std::shared_ptr aPoint1 = sketch()->to3D(aPnt_A->x(), aPnt_A->y()); - std::shared_ptr aPoint2 = sketch()->to3D(aPnt_B->x(), aPnt_B->y()); - if(!aFlyOutAttr->isInitialized()) - return AISObjectPtr(); - std::shared_ptr aFlyoutPnt = sketch()->to3D(aFlyOutAttr->x(), aFlyOutAttr->y()/*aFPnt->x(), aFPnt->y()*/); - - // value calculation - std::shared_ptr aValueAttr = std::dynamic_pointer_cast< - ModelAPI_AttributeDouble>(aData->attribute(SketchPlugin_Constraint::VALUE())); - double aValue = 0; - // Issue #196: checking the positivity of the distance constraint - // there is a validator for a distance constraint, that the value should be positive - // in case if an invalid value is set, the current distance value is shown - if (aValueAttr->isInitialized()) - aValue = aValueAttr->value(); - AISObjectPtr anAIS = thePrevious; - if (!anAIS) - anAIS = AISObjectPtr(new GeomAPI_AISObject); - anAIS->createDistance(aPoint1, aPoint2, aFlyoutPnt, aPlane, aValue); + if (!anAIS) { + anAIS = SketcherPrs_Factory::lengthDimensionConstraint(this, sketch()->coordinatePlane()); + } // Set color from preferences std::vector aRGB = Config_PropManager::color("Visualization", "sketch_dimension_color", @@ -199,22 +152,22 @@ double SketchPlugin_ConstraintDistance::calculateCurrentDistance() const std::shared_ptr aData = data(); std::shared_ptr aPointA = - getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_A()); + SketcherPrs_Tools::getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_A()); std::shared_ptr aPointB = - getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_B()); + SketcherPrs_Tools::getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_B()); if (aPointA && aPointB) { // both points aDistance = aPointA->pnt()->distance(aPointB->pnt()); } else { if (!aPointA && aPointB) { //Line and point std::shared_ptr aLine = - getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_A()); + SketcherPrs_Tools::getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_A()); if (aLine) { aDistance = aLine->distanceToPoint(aPointB->pnt()); } } else if (aPointA && !aPointB) { // Point and line std::shared_ptr aLine = - getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_B()); + SketcherPrs_Tools::getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_B()); if (aLine) { aDistance = aLine->distanceToPoint(aPointA->pnt()); } @@ -238,63 +191,3 @@ void SketchPlugin_ConstraintDistance::attributeChanged(const std::string& theID) } } -//************************************************************************************* -std::shared_ptr getFeaturePoint(DataPtr theData, - const std::string& theAttribute) -{ - std::shared_ptr aPointAttr; - - if (!theData) - return aPointAttr; - - FeaturePtr aFeature; - std::shared_ptr anAttr = std::dynamic_pointer_cast< - ModelAPI_AttributeRefAttr>(theData->attribute(theAttribute)); - if (anAttr) - aFeature = ModelAPI_Feature::feature(anAttr->object()); - - if (aFeature && aFeature->getKind() == SketchPlugin_Point::ID()) - aPointAttr = std::dynamic_pointer_cast( - aFeature->data()->attribute(SketchPlugin_Point::COORD_ID())); - else if (aFeature && aFeature->getKind() == SketchPlugin_Circle::ID()) - aPointAttr = std::dynamic_pointer_cast( - aFeature->data()->attribute(SketchPlugin_Circle::CENTER_ID())); - else if (anAttr->attr()) { - aPointAttr = std::dynamic_pointer_cast(anAttr->attr()); - } - return aPointAttr; -} - -//************************************************************************************* -std::shared_ptr getFeatureLine(DataPtr theData, - const std::string& theAttribute) -{ - std::shared_ptr aLine; - if (!theData) - return aLine; - - std::shared_ptr anAttr = std::dynamic_pointer_cast< - ModelAPI_AttributeRefAttr>(theData->attribute(theAttribute)); - if (anAttr) { - FeaturePtr aFeature = ModelAPI_Feature::feature(anAttr->object()); - if (aFeature && aFeature->getKind() == SketchPlugin_Line::ID()) { - aLine = std::dynamic_pointer_cast(aFeature); - } - } - return aLine; -} - -//************************************************************************************* -std::shared_ptr getProjectionPoint( - const std::shared_ptr& theLine, - const std::shared_ptr& thePoint) -{ - std::shared_ptr aData = theLine->data(); - std::shared_ptr aPoint1 = std::dynamic_pointer_cast( - aData->attribute(SketchPlugin_Line::START_ID())); - std::shared_ptr aPoint2 = std::dynamic_pointer_cast( - aData->attribute(SketchPlugin_Line::END_ID())); - - GeomAPI_Lin2d aLin2d(aPoint1->x(), aPoint1->y(), aPoint2->x(), aPoint2->y()); - return aLin2d.project(thePoint); -} diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistance.h b/src/SketchPlugin/SketchPlugin_ConstraintDistance.h index 9bc3d5d06..3529ace3c 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintDistance.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintDistance.h @@ -72,15 +72,4 @@ class SketchPlugin_ConstraintDistance : public SketchPlugin_ConstraintBase SketchPlugin_ConstraintDistance(); }; -/// Obtain the point object from specified constraint parameter -std::shared_ptr getFeaturePoint(DataPtr theData, - const std::string& theAttribute); - -std::shared_ptr getFeatureLine(DataPtr theData, - const std::string& theAttribute); - -std::shared_ptr getProjectionPoint( - const std::shared_ptr& theLine, - const std::shared_ptr& thePoint); - #endif diff --git a/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp b/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp index 06cf90cb7..8162b5c61 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp @@ -9,6 +9,8 @@ #include +#include + #include #include #include @@ -110,35 +112,13 @@ bool SketchPlugin_ConstraintLength::getPoints( AISObjectPtr SketchPlugin_ConstraintLength::getAISObject(AISObjectPtr thePrevious) { - std::shared_ptr aPoint1, aPoint2; - std::shared_ptr aStartPoint, anEndPoint; - if (!getPoints(aPoint1, aPoint2, aStartPoint, anEndPoint)) - return thePrevious; // not possible to show length because points are not defined - - AttributePtr aFlyOutAttribute = data()->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()); - if (!aFlyOutAttribute->isInitialized()) { - return thePrevious; // not possible to show length because points are not defined - } - std::shared_ptr aFlyOutAttr = std::dynamic_pointer_cast< - GeomDataAPI_Point2D>(aFlyOutAttribute); - std::shared_ptr aFlyoutPnt = sketch()->to3D(aFlyOutAttr->x(), aFlyOutAttr->y()); - // value calculation - // TODO: has to be calculated on definition of reference object - double aDistance = aPoint1->distance(aPoint2); - std::shared_ptr aValueAttr = std::dynamic_pointer_cast< - ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_Constraint::VALUE())); - double aValue = aDistance; - if (aValueAttr->isInitialized()) - aValue = aValueAttr->value(); - else - aValueAttr->setValue(aValue); - // End TODO + if (!sketch()) + return thePrevious; AISObjectPtr anAIS = thePrevious; - if (!anAIS) - anAIS = AISObjectPtr(new GeomAPI_AISObject); - std::shared_ptr aPlane = sketch()->plane(); - anAIS->createDistance(aPoint1, aPoint2, aFlyoutPnt, aPlane, aValue); + if (!anAIS) { + anAIS = SketcherPrs_Factory::lengthDimensionConstraint(this, sketch()->coordinatePlane()); + } // Set color from preferences std::vector aRGB = Config_PropManager::color("Visualization", "sketch_dimension_color", diff --git a/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp b/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp index f9532a620..af53efa5d 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp @@ -10,6 +10,8 @@ #include #include +#include + #include #include @@ -135,42 +137,13 @@ double SketchPlugin_ConstraintRadius::circleRadius(std::shared_ptr aCyrcFeature; - double aRadius = circleRadius(aCyrcFeature); - if (aRadius < 0) - return thePrevious; // can not create a good presentation - - // Flyout point - std::shared_ptr aFlyoutAttr = std::dynamic_pointer_cast< - GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); - if (!aFlyoutAttr->isInitialized()) - return thePrevious; // can not create a good presentation - std::shared_ptr aFlyoutPnt = sketch()->to3D(aFlyoutAttr->x(), aFlyoutAttr->y()); + if (!sketch()) + return thePrevious; - // Prepare a circle - std::shared_ptr aCenterAttr; - if (aCyrcFeature->getKind() == SketchPlugin_Circle::ID()) { // circle - aCenterAttr = std::dynamic_pointer_cast( - aCyrcFeature->data()->attribute(SketchPlugin_Circle::CENTER_ID())); - } else { // arc - aCenterAttr = std::dynamic_pointer_cast( - aCyrcFeature->data()->attribute(SketchPlugin_Arc::CENTER_ID())); - } - std::shared_ptr aCenter = sketch()->to3D(aCenterAttr->x(), aCenterAttr->y()); - std::shared_ptr aNDir = std::dynamic_pointer_cast( - sketch()->data()->attribute(SketchPlugin_Sketch::NORM_ID())); - std::shared_ptr aNormal = aNDir->dir(); - std::shared_ptr aCircle(new GeomAPI_Circ(aCenter, aNormal, aRadius)); - - // Value - std::shared_ptr aValueAttr = std::dynamic_pointer_cast< - ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_Constraint::VALUE())); - if (aValueAttr->isInitialized()) - aRadius = aValueAttr->value(); AISObjectPtr anAIS = thePrevious; - if (!anAIS) - anAIS = AISObjectPtr(new GeomAPI_AISObject); - anAIS->createRadius(aCircle, aFlyoutPnt, aRadius); + if (!anAIS) { + anAIS = SketcherPrs_Factory::radiusConstraint(this, sketch()->coordinatePlane()); + } // Set color from preferences std::vector aRGB = Config_PropManager::color("Visualization", "sketch_dimension_color", diff --git a/src/SketchPlugin/SketchPlugin_Validators.cpp b/src/SketchPlugin/SketchPlugin_Validators.cpp index a61362076..7fb075307 100644 --- a/src/SketchPlugin/SketchPlugin_Validators.cpp +++ b/src/SketchPlugin/SketchPlugin_Validators.cpp @@ -10,6 +10,8 @@ #include "SketchPlugin_Line.h" #include "SketchPlugin_Arc.h" +#include "SketcherPrs_Tools.h" + #include #include #include @@ -20,6 +22,7 @@ #include + bool SketchPlugin_DistanceAttrValidator::isValid( const AttributePtr& theAttribute, const std::list& theArguments ) const { @@ -58,7 +61,7 @@ bool SketchPlugin_DistanceAttrValidator::isValid( FeaturePtr aFeature = std::dynamic_pointer_cast(theAttribute->owner()); // If it is a line then we have to check that first attribute id not a line - std::shared_ptr aPoint = getFeaturePoint(aFeature->data(), aParamA); + std::shared_ptr aPoint = SketcherPrs_Tools::getFeaturePoint(aFeature->data(), aParamA); if (aPoint) return true; } diff --git a/src/SketcherPrs/CMakeLists.txt b/src/SketcherPrs/CMakeLists.txt index 4af59f94d..be597690d 100644 --- a/src/SketcherPrs/CMakeLists.txt +++ b/src/SketcherPrs/CMakeLists.txt @@ -14,6 +14,8 @@ SET(PROJECT_HEADERS SketcherPrs_Equal.h SketcherPrs_Tangent.h SketcherPrs_SensitivePoint.h + SketcherPrs_Radius.h + SketcherPrs_LengthDimension.h ) SET(PROJECT_SOURCES @@ -29,6 +31,8 @@ SET(PROJECT_SOURCES SketcherPrs_Equal.cpp SketcherPrs_Tangent.cpp SketcherPrs_SensitivePoint.cpp + SketcherPrs_Radius.cpp + SketcherPrs_LengthDimension.cpp ) SET(PROJECT_LIBRARIES diff --git a/src/SketcherPrs/SketcherPrs_Factory.cpp b/src/SketcherPrs/SketcherPrs_Factory.cpp index b46070694..04f9bf3b7 100644 --- a/src/SketcherPrs/SketcherPrs_Factory.cpp +++ b/src/SketcherPrs/SketcherPrs_Factory.cpp @@ -13,6 +13,8 @@ #include "SketcherPrs_HVDirection.h" #include "SketcherPrs_Equal.h" #include "SketcherPrs_Tangent.h" +#include "SketcherPrs_Radius.h" +#include "SketcherPrs_LengthDimension.h" #define CONSTRAINT_PRS_IMPL(NAME, CLASS) \ AISObjectPtr SketcherPrs_Factory::NAME(SketchPlugin_Constraint* theConstraint, \ @@ -30,6 +32,8 @@ CONSTRAINT_PRS_IMPL(perpendicularConstraint, SketcherPrs_Perpendicular); CONSTRAINT_PRS_IMPL(rigidConstraint, SketcherPrs_Rigid); CONSTRAINT_PRS_IMPL(equalConstraint, SketcherPrs_Equal); CONSTRAINT_PRS_IMPL(tangentConstraint, SketcherPrs_Tangent); +CONSTRAINT_PRS_IMPL(radiusConstraint, SketcherPrs_Radius); +CONSTRAINT_PRS_IMPL(lengthDimensionConstraint, SketcherPrs_LengthDimension); AISObjectPtr SketcherPrs_Factory::horisontalConstraint(SketchPlugin_Constraint* theConstraint, diff --git a/src/SketcherPrs/SketcherPrs_Factory.h b/src/SketcherPrs/SketcherPrs_Factory.h index b6feedebc..d416644f9 100644 --- a/src/SketcherPrs/SketcherPrs_Factory.h +++ b/src/SketcherPrs/SketcherPrs_Factory.h @@ -64,6 +64,16 @@ public: /// \param theConstraint the constraint /// \param thePlane the current sketch plane GET_CONSTRAINT_PRS(tangentConstraint) + + /// Creates coincedent perpendicular presentation + /// \param theConstraint the constraint + /// \param thePlane the current sketch plane + GET_CONSTRAINT_PRS(radiusConstraint) + + /// Creates coincedent perpendicular presentation + /// \param theConstraint the constraint + /// \param thePlane the current sketch plane + GET_CONSTRAINT_PRS(lengthDimensionConstraint) }; #endif diff --git a/src/SketcherPrs/SketcherPrs_LengthDimension.cpp b/src/SketcherPrs/SketcherPrs_LengthDimension.cpp new file mode 100644 index 000000000..0f5d2b8f0 --- /dev/null +++ b/src/SketcherPrs/SketcherPrs_LengthDimension.cpp @@ -0,0 +1,161 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: SketcherPrs_LengthDimension.cpp +// Created: 27 March 2015 +// Author: Vitaly SMETANNIKOV + +#include "SketcherPrs_LengthDimension.h" +#include "SketcherPrs_Tools.h" + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + + +const int CONSTRAINT_TEXT_HEIGHT = 20; /// the text height of the constraint +const int CONSTRAINT_TEXT_SELECTION_TOLERANCE = 20; /// the text selection tolerance + + +static const gp_Pnt MyDefStart(0,0,0); +static const gp_Pnt MyDefEnd(1,0,0); +static const gp_Pln MyDefPln(gp_Pnt(0,0,0), gp_Dir(0,0,1)); + + + + +IMPLEMENT_STANDARD_HANDLE(SketcherPrs_LengthDimension, AIS_LengthDimension); +IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_LengthDimension, AIS_LengthDimension); + +SketcherPrs_LengthDimension::SketcherPrs_LengthDimension(SketchPlugin_Constraint* theConstraint, + const std::shared_ptr& thePlane) +: AIS_LengthDimension(MyDefStart, MyDefEnd, MyDefPln), +myConstraint(theConstraint), myPlane(thePlane) +{ + myAspect = new Prs3d_DimensionAspect(); + myAspect->MakeArrows3d(false); + myAspect->MakeText3d(false); + myAspect->MakeTextShaded(false); + myAspect->MakeUnitsDisplayed(false); + + SetDimensionAspect(myAspect); + SetSelToleranceForText2d(CONSTRAINT_TEXT_SELECTION_TOLERANCE); +} + + +void SketcherPrs_LengthDimension::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, + const Handle(Prs3d_Presentation)& thePresentation, + const Standard_Integer theMode) +{ + 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); + myAspect->TextAspect()->SetHeight(CONSTRAINT_TEXT_HEIGHT); + myAspect->ArrowAspect()->SetLength(CONSTRAINT_TEXT_HEIGHT * 2); + + SetMeasuredGeometry(aPnt1, aPnt2, myPlane->impl()); + AIS_LengthDimension::Compute(thePresentationManager, thePresentation, theMode); +} + +bool SketcherPrs_LengthDimension::getPoints(gp_Pnt& thePnt1, gp_Pnt& thePnt2) const +{ + DataPtr aData = myConstraint->data(); + if (myConstraint->getKind() == SketchPlugin_ConstraintLength::ID()) { + std::shared_ptr anAttr = + std::dynamic_pointer_cast + (aData->attribute(SketchPlugin_Constraint::ENTITY_A())); + if (!anAttr) + return false; + + FeaturePtr aFeature = ModelAPI_Feature::feature(anAttr->object()); + if (!aFeature || aFeature->getKind() != SketchPlugin_Line::ID()) + return false; + + DataPtr aLineData = aFeature->data(); + std::shared_ptr aStartPoint = + std::dynamic_pointer_cast + (aLineData->attribute(SketchPlugin_Line::START_ID())); + std::shared_ptr aEndPoint = + std::dynamic_pointer_cast + (aLineData->attribute(SketchPlugin_Line::END_ID())); + thePnt1 = myPlane->to3D(aStartPoint->x(), aStartPoint->y())->impl(); + thePnt2 = myPlane->to3D(aEndPoint->x(), aEndPoint->y())->impl(); + return true; + + } else if (myConstraint->getKind() == SketchPlugin_ConstraintDistance::ID()) { + std::shared_ptr aPoint_A = SketcherPrs_Tools::getFeaturePoint( + aData, SketchPlugin_Constraint::ENTITY_A()); + std::shared_ptr aPoint_B = SketcherPrs_Tools::getFeaturePoint( + aData, SketchPlugin_Constraint::ENTITY_B()); + + std::shared_ptr aPnt_A; + std::shared_ptr aPnt_B; + if (aPoint_A && aPoint_B) { + aPnt_A = aPoint_A->pnt(); + aPnt_B = aPoint_B->pnt(); + } else if (!aPoint_A && aPoint_B) { + std::shared_ptr aLine = SketcherPrs_Tools::getFeatureLine( + aData, SketchPlugin_Constraint::ENTITY_A()); + if (aLine) { + aPnt_B = aPoint_B->pnt(); + aPnt_A = SketcherPrs_Tools::getProjectionPoint(aLine, aPnt_B); + } + } else if (aPoint_A && !aPoint_B) { + std::shared_ptr aLine = SketcherPrs_Tools::getFeatureLine( + aData, SketchPlugin_Constraint::ENTITY_B()); + if (aLine) { + aPnt_A = aPoint_A->pnt(); + aPnt_B = SketcherPrs_Tools::getProjectionPoint(aLine, aPnt_A); + } + } + if (!aPnt_A || !aPnt_B) + return false; + + std::shared_ptr aPoint1 = myPlane->to3D(aPnt_A->x(), aPnt_A->y()); + std::shared_ptr aPoint2 = myPlane->to3D(aPnt_B->x(), aPnt_B->y()); + thePnt1 = aPoint1->impl(); + thePnt2 = aPoint2->impl(); + return true; + } + return false; +} diff --git a/src/SketcherPrs/SketcherPrs_LengthDimension.h b/src/SketcherPrs/SketcherPrs_LengthDimension.h new file mode 100644 index 000000000..94bd89c46 --- /dev/null +++ b/src/SketcherPrs/SketcherPrs_LengthDimension.h @@ -0,0 +1,54 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: SketcherPrs_LengthDimension.h +// Created: 27 March 2015 +// Author: Vitaly SMETANNIKOV + + +#ifndef SketcherPrs_LinearDimension_H +#define SketcherPrs_LinearDimension_H + +#include +#include +#include + + +class SketchPlugin_Constraint; + +DEFINE_STANDARD_HANDLE(SketcherPrs_LengthDimension, AIS_LengthDimension) + +/** +* \ingroup GUI +* A class for representation of linear dimension constraint. +* It supports SketchPlugin_ConstraintLength and SketchPlugin_ConstraintDistance features. +*/ +class SketcherPrs_LengthDimension : public AIS_LengthDimension +{ +public: + /// Constructor + /// \param theConstraint a constraint feature + /// \param thePlane a coordinate plane of current sketch + Standard_EXPORT SketcherPrs_LengthDimension(SketchPlugin_Constraint* theConstraint, + const std::shared_ptr& thePlane); + + std::string constraintType() const; + + DEFINE_STANDARD_RTTI(SketcherPrs_LengthDimension) +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); + +private: + bool getPoints(gp_Pnt& thePnt1, gp_Pnt& thePnt2) const; + + /// Constraint feature + SketchPlugin_Constraint* myConstraint; + + /// Plane of the current sketcher + std::shared_ptr myPlane; + + Handle(Prs3d_DimensionAspect) myAspect; +}; + +#endif \ No newline at end of file diff --git a/src/SketcherPrs/SketcherPrs_Radius.cpp b/src/SketcherPrs/SketcherPrs_Radius.cpp new file mode 100644 index 000000000..bdefd5187 --- /dev/null +++ b/src/SketcherPrs/SketcherPrs_Radius.cpp @@ -0,0 +1,103 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: SketcherPrs_Radius.cpp +// Created: 26 March 2015 +// Author: Vitaly SMETANNIKOV + +#include "SketcherPrs_Radius.h" + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +const int CONSTRAINT_TEXT_HEIGHT = 20; /// the text height of the constraint +const int CONSTRAINT_TEXT_SELECTION_TOLERANCE = 20; /// the text selection tolerance + +static gp_Circ MyDefCirc(gp_Ax2(gp_Pnt(0,0,0), gp_Dir(0,0,1)), 1); + +IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Radius, AIS_RadiusDimension); +IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Radius, AIS_RadiusDimension); + +SketcherPrs_Radius::SketcherPrs_Radius(SketchPlugin_Constraint* theConstraint, + const std::shared_ptr& thePlane) +: AIS_RadiusDimension(MyDefCirc), myConstraint(theConstraint), myPlane(thePlane) +{ + myAspect = new Prs3d_DimensionAspect(); + myAspect->MakeArrows3d(false); + myAspect->MakeText3d(false); + myAspect->MakeTextShaded(false); + myAspect->MakeUnitsDisplayed(false); + + SetDimensionAspect(myAspect); + SetSelToleranceForText2d(CONSTRAINT_TEXT_SELECTION_TOLERANCE); +} + + +void SketcherPrs_Radius::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()); + + // Get circle + std::shared_ptr anAttr = + std::dynamic_pointer_cast + (aData->attribute(SketchPlugin_Constraint::ENTITY_A())); + if (!anAttr) return; + + std::shared_ptr aCyrcFeature = ModelAPI_Feature::feature(anAttr->object()); + double aRadius = 1; + std::shared_ptr aCenterAttr; + if (aCyrcFeature->getKind() == SketchPlugin_Circle::ID()) { // circle + aCenterAttr = std::dynamic_pointer_cast( + aCyrcFeature->data()->attribute(SketchPlugin_Circle::CENTER_ID())); + AttributeDoublePtr aCircRadius = + std::dynamic_pointer_cast( + aCyrcFeature->data()->attribute(SketchPlugin_Circle::RADIUS_ID())); + aRadius = aCircRadius->value(); + } else { // arc + aCenterAttr = std::dynamic_pointer_cast( + aCyrcFeature->data()->attribute(SketchPlugin_Arc::CENTER_ID())); + std::shared_ptr aStartAttr = + std::dynamic_pointer_cast + (aCyrcFeature->data()->attribute(SketchPlugin_Arc::START_ID())); + aRadius = aCenterAttr->pnt()->distance(aStartAttr->pnt()); + } + std::shared_ptr aCenter = myPlane->to3D(aCenterAttr->x(), aCenterAttr->y()); + std::shared_ptr aNormal = myPlane->norm(); + + GeomAPI_Circ aCircle(aCenter, aNormal, aRadius); + //gp_Circ aCircle(gp_Ax2(aCenter->impl(), aNormal->impl()), aRadius); + + 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); + + myAspect->TextAspect()->SetHeight(CONSTRAINT_TEXT_HEIGHT); + myAspect->ArrowAspect()->SetLength(CONSTRAINT_TEXT_HEIGHT * 2.); + AIS_RadiusDimension::Compute(thePresentationManager, thePresentation, theMode); +} diff --git a/src/SketcherPrs/SketcherPrs_Radius.h b/src/SketcherPrs/SketcherPrs_Radius.h new file mode 100644 index 000000000..0b32639b7 --- /dev/null +++ b/src/SketcherPrs/SketcherPrs_Radius.h @@ -0,0 +1,49 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: SketcherPrs_Radius.h +// Created: 26 March 2015 +// Author: Vitaly SMETANNIKOV + + +#ifndef SketcherPrs_Radius_H +#define SketcherPrs_Radius_H + +#include + +#include +#include + +class SketchPlugin_Constraint; + +DEFINE_STANDARD_HANDLE(SketcherPrs_Radius, AIS_RadiusDimension) + +/** +* \ingroup GUI +* A class for representation of radius constraint +*/ +class SketcherPrs_Radius : public AIS_RadiusDimension +{ +public: + /// Constructor + /// \param theConstraint a constraint feature + /// \param thePlane a coordinate plane of current sketch + Standard_EXPORT SketcherPrs_Radius(SketchPlugin_Constraint* theConstraint, + const std::shared_ptr& thePlane); + + DEFINE_STANDARD_RTTI(SketcherPrs_Radius) +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); + +private: + /// Constraint feature + SketchPlugin_Constraint* myConstraint; + + /// Plane of the current sketcher + std::shared_ptr myPlane; + + Handle(Prs3d_DimensionAspect) myAspect; +}; + +#endif \ No newline at end of file diff --git a/src/SketcherPrs/SketcherPrs_Tools.cpp b/src/SketcherPrs/SketcherPrs_Tools.cpp index 2c575e1a3..7fb7bf949 100644 --- a/src/SketcherPrs/SketcherPrs_Tools.cpp +++ b/src/SketcherPrs/SketcherPrs_Tools.cpp @@ -9,10 +9,13 @@ #include #include #include +#include + #include #include #include +#include namespace SketcherPrs_Tools { @@ -67,5 +70,67 @@ std::shared_ptr getPoint(SketchPlugin_Constraint* theFeature, return std::shared_ptr(); } +//************************************************************************************* +std::shared_ptr getFeaturePoint(DataPtr theData, + const std::string& theAttribute) +{ + std::shared_ptr aPointAttr; + + if (!theData) + return aPointAttr; + + FeaturePtr aFeature; + std::shared_ptr anAttr = std::dynamic_pointer_cast< + ModelAPI_AttributeRefAttr>(theData->attribute(theAttribute)); + if (anAttr) + aFeature = ModelAPI_Feature::feature(anAttr->object()); + + if (aFeature && aFeature->getKind() == SketchPlugin_Point::ID()) + aPointAttr = std::dynamic_pointer_cast( + aFeature->data()->attribute(SketchPlugin_Point::COORD_ID())); + + else if (aFeature && aFeature->getKind() == SketchPlugin_Circle::ID()) + aPointAttr = std::dynamic_pointer_cast( + aFeature->data()->attribute(SketchPlugin_Circle::CENTER_ID())); + + else if (anAttr->attr()) { + aPointAttr = std::dynamic_pointer_cast(anAttr->attr()); + } + return aPointAttr; +} + +//************************************************************************************* +std::shared_ptr getFeatureLine(DataPtr theData, + const std::string& theAttribute) +{ + std::shared_ptr aLine; + if (!theData) + return aLine; + + std::shared_ptr anAttr = std::dynamic_pointer_cast< + ModelAPI_AttributeRefAttr>(theData->attribute(theAttribute)); + if (anAttr) { + FeaturePtr aFeature = ModelAPI_Feature::feature(anAttr->object()); + if (aFeature && aFeature->getKind() == SketchPlugin_Line::ID()) { + aLine = std::dynamic_pointer_cast(aFeature); + } + } + return aLine; +} + +//************************************************************************************* +std::shared_ptr getProjectionPoint( + const std::shared_ptr& theLine, + const std::shared_ptr& thePoint) +{ + std::shared_ptr aData = theLine->data(); + std::shared_ptr aPoint1 = std::dynamic_pointer_cast( + aData->attribute(SketchPlugin_Line::START_ID())); + std::shared_ptr aPoint2 = std::dynamic_pointer_cast( + aData->attribute(SketchPlugin_Line::END_ID())); + + GeomAPI_Lin2d aLin2d(aPoint1->x(), aPoint1->y(), aPoint2->x(), aPoint2->y()); + return aLin2d.project(thePoint); +} }; \ No newline at end of file diff --git a/src/SketcherPrs/SketcherPrs_Tools.h b/src/SketcherPrs/SketcherPrs_Tools.h index 3cde3ea2a..46f9fa4fc 100644 --- a/src/SketcherPrs/SketcherPrs_Tools.h +++ b/src/SketcherPrs/SketcherPrs_Tools.h @@ -14,17 +14,30 @@ #include class SketchPlugin_Constraint; +class SketchPlugin_Line; +class GeomDataAPI_Point2D; namespace SketcherPrs_Tools { - ObjectPtr getResult(SketchPlugin_Constraint* theFeature, + SKETCHERPRS_EXPORT ObjectPtr getResult(SketchPlugin_Constraint* theFeature, const std::string& theAttrName); - std::shared_ptr getShape(ObjectPtr theObject); + SKETCHERPRS_EXPORT std::shared_ptr getShape(ObjectPtr theObject); - std::shared_ptr getPoint(SketchPlugin_Constraint* theFeature, + SKETCHERPRS_EXPORT std::shared_ptr getPoint(SketchPlugin_Constraint* theFeature, const std::string& theAttrName); + SKETCHERPRS_EXPORT std::shared_ptr getProjectionPoint( + const std::shared_ptr& theLine, + const std::shared_ptr& thePoint); + + SKETCHERPRS_EXPORT std::shared_ptr getFeatureLine(DataPtr theData, + const std::string& theAttribute); + + /// Obtain the point object from specified constraint parameter + SKETCHERPRS_EXPORT std::shared_ptr getFeaturePoint(DataPtr theData, + const std::string& theAttribute); + }; #endif \ No newline at end of file