From: nds Date: Sat, 21 Jun 2014 11:51:23 +0000 (+0400) Subject: refs #80 - Sketch base GUI: create/draw point, circle and arc X-Git-Tag: V_0.4.4~268 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=d727f40573f7a71044fea24b6af43b419ac19e51;p=modules%2Fshaper.git refs #80 - Sketch base GUI: create/draw point, circle and arc 1. Distance constraint between points. --- diff --git a/src/PartSet/PartSet_ConstraintDistancePrs.cpp b/src/PartSet/PartSet_ConstraintDistancePrs.cpp index 8ad377696..809ea8c3c 100644 --- a/src/PartSet/PartSet_ConstraintDistancePrs.cpp +++ b/src/PartSet/PartSet_ConstraintDistancePrs.cpp @@ -10,11 +10,13 @@ #include #include #include +#include #include #include #include #include +#include #include #include @@ -23,7 +25,10 @@ #include #include +#include + #include +#include using namespace std; @@ -40,25 +45,38 @@ std::string PartSet_ConstraintDistancePrs::getKind() PartSet_SelectionMode PartSet_ConstraintDistancePrs::setFeature(FeaturePtr theFeature, const PartSet_SelectionMode& theMode) { PartSet_SelectionMode aMode = theMode; - if (feature() && theFeature && theFeature->getKind() == SKETCH_LINE_KIND && theMode == SM_FirstPoint) + if (!feature() || !theFeature) + return aMode; + + std::string anArgument; + if (theMode == SM_FirstPoint) { + anArgument = CONSTRAINT_ATTR_ENTITY_A; + aMode = SM_SecondPoint; + } + else if (theMode == SM_SecondPoint) { + anArgument = CONSTRAINT_ATTR_ENTITY_B; + aMode = SM_LastPoint; + } + if (theFeature->getKind() == SKETCH_POINT_KIND) { // set length feature boost::shared_ptr aData = feature()->data(); boost::shared_ptr aRef = - boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_ENTITY_A)); + boost::dynamic_pointer_cast(aData->attribute(anArgument)); aRef->setFeature(theFeature); + } + if (theMode == SM_SecondPoint) { // 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()); - PartSet_Tools::setFeatureValue(feature(), aLenght, CONSTRAINT_ATTR_VALUE); - aMode = SM_SecondPoint; + boost::shared_ptr aPoint_A = getFeaturePoint(feature(), CONSTRAINT_ATTR_ENTITY_A); + boost::shared_ptr aPoint_B = getFeaturePoint(feature(), CONSTRAINT_ATTR_ENTITY_B); + + if (aPoint_A && aPoint_B) { + double aLenght = aPoint_A->pnt()->distance(aPoint_B->pnt()); + PartSet_Tools::setFeatureValue(feature(), aLenght, CONSTRAINT_ATTR_VALUE); + } } + return aMode; } @@ -69,30 +87,24 @@ PartSet_SelectionMode PartSet_ConstraintDistancePrs::setPoint(double theX, doubl switch (theMode) { case SM_LastPoint: { - 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_A = getFeaturePoint(feature(), + CONSTRAINT_ATTR_ENTITY_A); + boost::shared_ptr aPoint_B = getFeaturePoint(feature(), + CONSTRAINT_ATTR_ENTITY_B); + boost::shared_ptr aPoint = boost::shared_ptr (new GeomAPI_Pnt2d(theX, theY)); - boost::shared_ptr aFeatureLin = PartSet_FeatureLinePrs::createLin2d(aFeature); + boost::shared_ptr aFeatureLin = boost::shared_ptr + (new GeomAPI_Lin2d(aPoint_A->x(), aPoint_A->y(), + aPoint_B->x(), aPoint_B->y())); boost::shared_ptr aResult = aFeatureLin->project(aPoint); double aDistance = aPoint->distance(aResult); - double aStartX, aStartY; - PartSet_FeatureLinePrs::getLinePoint(aFeature, LINE_ATTR_START, aStartX, aStartY); - if (!aFeatureLin->isRight(aPoint)) aDistance = -aDistance; - AttributeDoublePtr aFlyoutAttr = - boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE)); + AttributeDoublePtr aFlyoutAttr = boost::dynamic_pointer_cast + (feature()->data()->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE)); aFlyoutAttr->setValue(aDistance); aMode = SM_DonePoint; @@ -111,35 +123,26 @@ Handle(AIS_InteractiveObject) PartSet_ConstraintDistancePrs::createPresentation( Handle(AIS_InteractiveObject) anAIS = thePreviuos; if (!theFeature || !theSketch) return anAIS; - /* 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) - return thePreviuos; - FeaturePtr aFeature = anAttr->feature(); - if (!aFeature || aFeature->getKind() != SKETCH_LINE_KIND) - return thePreviuos; + boost::shared_ptr aPoint_A = getFeaturePoint(theFeature, CONSTRAINT_ATTR_ENTITY_A); + boost::shared_ptr aPoint_B = getFeaturePoint(theFeature, CONSTRAINT_ATTR_ENTITY_B); + if (!aPoint_A || !aPoint_B) + return anAIS; + boost::shared_ptr aData = theFeature->data(); 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)); + boost::shared_ptr aValueAttr = + boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_VALUE)); + double aValue = aValueAttr->value(); gp_Pnt aPoint1, aPoint2; - PartSet_Tools::convertTo3D(aPointStart->x(), aPointStart->y(), theSketch, aPoint1); - PartSet_Tools::convertTo3D(aPointEnd->x(), aPointEnd->y(), theSketch, aPoint2); + PartSet_Tools::convertTo3D(aPoint_A->x(), aPoint_A->y(), theSketch, aPoint1); + PartSet_Tools::convertTo3D(aPoint_B->x(), aPoint_B->y(), theSketch, aPoint2); //Build dimension here gp_Pnt aP1 = aPoint1; @@ -149,10 +152,10 @@ Handle(AIS_InteractiveObject) PartSet_ConstraintDistancePrs::createPresentation( aP2 = aPoint1; } - Handle(AIS_InteractiveObject) anAIS = thePreviuos; if (anAIS.IsNull()) { - Handle(AIS_LengthDimension) aDimAIS = new AIS_LengthDimension (aP1, aP2, aPlane); + Handle(AIS_LengthDimension) aDimAIS = new AIS_LengthDimension(aP1, aP2, aPlane); + aDimAIS->SetCustomValue(aValue); Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect(); anAspect->MakeArrows3d (Standard_False); @@ -160,10 +163,6 @@ Handle(AIS_InteractiveObject) PartSet_ConstraintDistancePrs::createPresentation( 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->SetSelToleranceForText2d(CONSTRAINT_TEXT_SELECTION_TOLERANCE); @@ -175,15 +174,28 @@ Handle(AIS_InteractiveObject) PartSet_ConstraintDistancePrs::createPresentation( 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); } } -*/ return anAIS; } +boost::shared_ptr PartSet_ConstraintDistancePrs::getFeaturePoint + (FeaturePtr theFeature, + const std::string& theAttribute) +{ + boost::shared_ptr aPointAttr; + + FeaturePtr aFeature = PartSet_Tools::feature(theFeature, theAttribute, SKETCH_POINT_KIND); + if (aFeature) + aPointAttr = boost::dynamic_pointer_cast + (aFeature->data()->attribute(POINT_ATTR_COORD)); + return aPointAttr; +} + std::string PartSet_ConstraintDistancePrs::getAttribute(const PartSet_SelectionMode& theMode) const { return ""; diff --git a/src/PartSet/PartSet_ConstraintDistancePrs.h b/src/PartSet/PartSet_ConstraintDistancePrs.h index 89cfb9051..7bac945e6 100644 --- a/src/PartSet/PartSet_ConstraintDistancePrs.h +++ b/src/PartSet/PartSet_ConstraintDistancePrs.h @@ -85,6 +85,14 @@ protected: /// Returns the feature point in the selection mode position. /// \param theMode the current operation selection mode. The feature attribute depends on the mode virtual boost::shared_ptr featurePoint(const PartSet_SelectionMode& theMode); + +private: + /// Find the feature point + /// \param theFeature the constraint feature + /// \param theAttribute a distance constraint attribute name of feature + /// \return the point in the feature + static boost::shared_ptr getFeaturePoint(FeaturePtr theFeature, + const std::string& theAttribute); }; #endif diff --git a/src/PartSet/PartSet_ConstraintLengthPrs.cpp b/src/PartSet/PartSet_ConstraintLengthPrs.cpp index 2f9c1d15c..a594bc6d3 100644 --- a/src/PartSet/PartSet_ConstraintLengthPrs.cpp +++ b/src/PartSet/PartSet_ConstraintLengthPrs.cpp @@ -94,9 +94,6 @@ PartSet_SelectionMode PartSet_ConstraintLengthPrs::setPoint(double theX, double boost::shared_ptr aResult = aFeatureLin->project(aPoint); double aDistance = aPoint->distance(aResult); - double aStartX, aStartY; - PartSet_FeatureLinePrs::getLinePoint(aFeature, LINE_ATTR_START, aStartX, aStartY); - if (!aFeatureLin->isRight(aPoint)) aDistance = -aDistance; diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index 8829dce4f..58ed85bb2 100644 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -272,6 +272,25 @@ double PartSet_Tools::featureValue(FeaturePtr theFeature, const std::string& the return aValue; } +FeaturePtr PartSet_Tools::feature(FeaturePtr theFeature, const std::string& theAttribute, + const std::string& theKind) +{ + FeaturePtr aFeature; + if (!theFeature) + return aFeature; + + boost::shared_ptr aData = theFeature->data(); + boost::shared_ptr anAttr = + boost::dynamic_pointer_cast(aData->attribute(theAttribute)); + if (anAttr) { + aFeature = anAttr->feature(); + if (!theKind.empty() && aFeature && aFeature->getKind() != theKind) { + aFeature = FeaturePtr(); + } + } + return aFeature; +} + void PartSet_Tools::createConstraint(FeaturePtr theSketch, boost::shared_ptr thePoint1, boost::shared_ptr thePoint2) diff --git a/src/PartSet/PartSet_Tools.h b/src/PartSet/PartSet_Tools.h index deb4b4910..7b81b3f10 100644 --- a/src/PartSet/PartSet_Tools.h +++ b/src/PartSet/PartSet_Tools.h @@ -100,6 +100,15 @@ public: static double featureValue(FeaturePtr theFeature, const std::string& theAttribute, bool& isValid); + /// Find a feature in the attribute of the given feature. If the kind is not empty, + /// the return feature should be this type. Otherwise it is null + /// \param theFeature a source feature + /// \param theAttribute a name of the requried attribute attribute + /// \param theKind an output feature kind + /// \return the feature + static FeaturePtr feature(FeaturePtr theFeature, const std::string& theAttribute, + const std::string& theKind); + /// Creates a constraint on two points /// \param thePoint1 the first point /// \param thePoint1 the second point