From b1f57156c63df5b18ade2209c843f902c394d695 Mon Sep 17 00:00:00 2001 From: nds Date: Tue, 24 Jun 2014 18:08:25 +0400 Subject: [PATCH] refs #80 - Sketch base GUI: create/draw point, circle and arc It replaces findPoint() method by using attributes(type) data model method. --- src/Model/Model_Data.cpp | 1 + src/PartSet/PartSet_ConstraintDistancePrs.cpp | 7 ---- src/PartSet/PartSet_ConstraintDistancePrs.h | 6 --- src/PartSet/PartSet_ConstraintLengthPrs.cpp | 7 ---- src/PartSet/PartSet_ConstraintLengthPrs.h | 6 --- src/PartSet/PartSet_ConstraintRadiusPrs.cpp | 7 ---- src/PartSet/PartSet_ConstraintRadiusPrs.h | 6 --- src/PartSet/PartSet_FeatureArcPrs.cpp | 29 --------------- src/PartSet/PartSet_FeatureArcPrs.h | 7 ---- src/PartSet/PartSet_FeatureCirclePrs.cpp | 16 -------- src/PartSet/PartSet_FeatureCirclePrs.h | 6 --- src/PartSet/PartSet_FeatureLinePrs.cpp | 22 ----------- src/PartSet/PartSet_FeatureLinePrs.h | 7 ---- src/PartSet/PartSet_FeaturePointPrs.cpp | 16 -------- src/PartSet/PartSet_FeaturePointPrs.h | 7 ---- src/PartSet/PartSet_FeaturePrs.h | 7 ---- src/PartSet/PartSet_Tools.cpp | 37 ++++++++++--------- src/PartSet/PartSet_Tools.h | 13 ++----- 18 files changed, 23 insertions(+), 184 deletions(-) diff --git a/src/Model/Model_Data.cpp b/src/Model/Model_Data.cpp index 60b7b540e..80eba05b0 100644 --- a/src/Model/Model_Data.cpp +++ b/src/Model/Model_Data.cpp @@ -213,6 +213,7 @@ list > Model_Data::attributes(const string map >::iterator anAttrsIter = myAttrs.begin(); for(; anAttrsIter != myAttrs.end(); anAttrsIter++) { if (theType.empty() || anAttrsIter->second->attributeType() == theType) { + aResult.push_back(anAttrsIter->second); } } return aResult; diff --git a/src/PartSet/PartSet_ConstraintDistancePrs.cpp b/src/PartSet/PartSet_ConstraintDistancePrs.cpp index de3310431..8dc195a94 100644 --- a/src/PartSet/PartSet_ConstraintDistancePrs.cpp +++ b/src/PartSet/PartSet_ConstraintDistancePrs.cpp @@ -125,13 +125,6 @@ PartSet_SelectionMode PartSet_ConstraintDistancePrs::getNextMode(const std::stri return SM_FirstPoint; } -boost::shared_ptr PartSet_ConstraintDistancePrs::findPoint(FeaturePtr theFeature, - double theX, double theY) -{ - boost::shared_ptr aPoint2D; - return aPoint2D; -} - boost::shared_ptr PartSet_ConstraintDistancePrs::featurePoint (const PartSet_SelectionMode& theMode) { diff --git a/src/PartSet/PartSet_ConstraintDistancePrs.h b/src/PartSet/PartSet_ConstraintDistancePrs.h index 30c6923a5..8d711540b 100644 --- a/src/PartSet/PartSet_ConstraintDistancePrs.h +++ b/src/PartSet/PartSet_ConstraintDistancePrs.h @@ -55,12 +55,6 @@ public: /// \return next attribute selection mode virtual PartSet_SelectionMode getNextMode(const std::string& theAttribute) const; - /// Find a point in the line with given coordinates - /// \param theFeature the line feature - /// \param theX the horizontal point coordinate - /// \param theY the vertical point coordinate - virtual boost::shared_ptr findPoint(FeaturePtr theFeature, 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_ConstraintLengthPrs.cpp b/src/PartSet/PartSet_ConstraintLengthPrs.cpp index 67b989c3b..4607b732b 100644 --- a/src/PartSet/PartSet_ConstraintLengthPrs.cpp +++ b/src/PartSet/PartSet_ConstraintLengthPrs.cpp @@ -120,13 +120,6 @@ PartSet_SelectionMode PartSet_ConstraintLengthPrs::getNextMode(const std::string return SM_FirstPoint; } -boost::shared_ptr PartSet_ConstraintLengthPrs::findPoint(FeaturePtr theFeature, - double theX, double theY) -{ - boost::shared_ptr aPoint2D; - return aPoint2D; -} - boost::shared_ptr PartSet_ConstraintLengthPrs::featurePoint (const PartSet_SelectionMode& theMode) { diff --git a/src/PartSet/PartSet_ConstraintLengthPrs.h b/src/PartSet/PartSet_ConstraintLengthPrs.h index ba1db99f4..e00b5494a 100644 --- a/src/PartSet/PartSet_ConstraintLengthPrs.h +++ b/src/PartSet/PartSet_ConstraintLengthPrs.h @@ -55,12 +55,6 @@ public: /// \return next attribute selection mode virtual PartSet_SelectionMode getNextMode(const std::string& theAttribute) const; - /// Find a point in the line with given coordinates - /// \param theFeature the line feature - /// \param theX the horizontal point coordinate - /// \param theY the vertical point coordinate - virtual boost::shared_ptr findPoint(FeaturePtr theFeature, 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_ConstraintRadiusPrs.cpp b/src/PartSet/PartSet_ConstraintRadiusPrs.cpp index a5430b8da..b8f2a8010 100644 --- a/src/PartSet/PartSet_ConstraintRadiusPrs.cpp +++ b/src/PartSet/PartSet_ConstraintRadiusPrs.cpp @@ -243,13 +243,6 @@ PartSet_SelectionMode PartSet_ConstraintRadiusPrs::getNextMode(const std::string return SM_FirstPoint; } -boost::shared_ptr PartSet_ConstraintRadiusPrs::findPoint(FeaturePtr theFeature, - double theX, double theY) -{ - boost::shared_ptr aPoint2D; - return aPoint2D; -} - boost::shared_ptr PartSet_ConstraintRadiusPrs::featurePoint (const PartSet_SelectionMode& theMode) { diff --git a/src/PartSet/PartSet_ConstraintRadiusPrs.h b/src/PartSet/PartSet_ConstraintRadiusPrs.h index 5e87a5fee..e316ab1f0 100644 --- a/src/PartSet/PartSet_ConstraintRadiusPrs.h +++ b/src/PartSet/PartSet_ConstraintRadiusPrs.h @@ -67,12 +67,6 @@ public: /// \return next attribute selection mode virtual PartSet_SelectionMode getNextMode(const std::string& theAttribute) const; - /// Find a point in the line with given coordinates - /// \param theFeature the line feature - /// \param theX the horizontal point coordinate - /// \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 diff --git a/src/PartSet/PartSet_FeatureArcPrs.cpp b/src/PartSet/PartSet_FeatureArcPrs.cpp index ac90bf557..440f5624e 100644 --- a/src/PartSet/PartSet_FeatureArcPrs.cpp +++ b/src/PartSet/PartSet_FeatureArcPrs.cpp @@ -94,35 +94,6 @@ PartSet_SelectionMode PartSet_FeatureArcPrs::getNextMode(const std::string& theA return aMode; } -boost::shared_ptr PartSet_FeatureArcPrs::findPoint(FeaturePtr theFeature, - double theX, double theY) -{ - boost::shared_ptr aPoint2D; - if (!theFeature || theFeature->getKind() != getKind()) - return aPoint2D; - - boost::shared_ptr aData = theFeature->data(); - boost::shared_ptr aPoint = - boost::dynamic_pointer_cast(aData->attribute(ARC_ATTR_CENTER)); - if (fabs(aPoint->x() - theX) < Precision::Confusion() && - fabs(aPoint->y() - theY) < Precision::Confusion()) { - aPoint2D = aPoint; - } - if (!aPoint2D) { - aPoint = boost::dynamic_pointer_cast(aData->attribute(ARC_ATTR_START)); - if (fabs(aPoint->x() - theX) < Precision::Confusion() && - fabs(aPoint->y() - theY) < Precision::Confusion()) - aPoint2D = aPoint; - } - if (!aPoint2D) { - aPoint = boost::dynamic_pointer_cast(aData->attribute(ARC_ATTR_END)); - if (fabs(aPoint->x() - theX) < Precision::Confusion() && - fabs(aPoint->y() - theY) < Precision::Confusion()) - aPoint2D = aPoint; - } - return aPoint2D; -} - void PartSet_FeatureArcPrs::projectPointOnFeature(FeaturePtr theFeature, FeaturePtr theSketch, gp_Pnt& thePoint, Handle(V3d_View) theView, double& theX, double& theY) diff --git a/src/PartSet/PartSet_FeatureArcPrs.h b/src/PartSet/PartSet_FeatureArcPrs.h index a34a08d6f..fd0bff9c3 100644 --- a/src/PartSet/PartSet_FeatureArcPrs.h +++ b/src/PartSet/PartSet_FeatureArcPrs.h @@ -61,13 +61,6 @@ public: static void projectPointOnFeature(FeaturePtr theFeature, FeaturePtr theSketch, gp_Pnt& thePoint, Handle_V3d_View theView, double& theX, double& theY); - /// Find a point in the line with given coordinates - /// \param theFeature the line feature - /// \param theX the horizontal point coordinate - /// \param theY the vertical point coordinate - virtual boost::shared_ptr findPoint(FeaturePtr theFeature, double theX, - double theY); - /// Computes the feature's radius /// \param theFeature an arc feature /// \return the double value diff --git a/src/PartSet/PartSet_FeatureCirclePrs.cpp b/src/PartSet/PartSet_FeatureCirclePrs.cpp index 56e4f93b6..426d9f1e5 100644 --- a/src/PartSet/PartSet_FeatureCirclePrs.cpp +++ b/src/PartSet/PartSet_FeatureCirclePrs.cpp @@ -92,22 +92,6 @@ PartSet_SelectionMode PartSet_FeatureCirclePrs::getNextMode(const std::string& t return aMode; } -boost::shared_ptr PartSet_FeatureCirclePrs::findPoint(FeaturePtr theFeature, - double theX, double theY) -{ - boost::shared_ptr aPoint2D; - if (!theFeature || theFeature->getKind() != getKind()) - return aPoint2D; - - boost::shared_ptr aData = theFeature->data(); - boost::shared_ptr aPoint = - boost::dynamic_pointer_cast(aData->attribute(CIRCLE_ATTR_CENTER)); - if (fabs(aPoint->x() - theX) < Precision::Confusion() && fabs(aPoint->y() - theY) < Precision::Confusion() ) - aPoint2D = aPoint; - - return aPoint2D; -} - void PartSet_FeatureCirclePrs::projectPointOnFeature(FeaturePtr theFeature, FeaturePtr theSketch, gp_Pnt& thePoint, Handle(V3d_View) theView, double& theX, double& theY) diff --git a/src/PartSet/PartSet_FeatureCirclePrs.h b/src/PartSet/PartSet_FeatureCirclePrs.h index 546fb5eb0..f9688b103 100644 --- a/src/PartSet/PartSet_FeatureCirclePrs.h +++ b/src/PartSet/PartSet_FeatureCirclePrs.h @@ -51,12 +51,6 @@ public: /// \return next attribute selection mode virtual PartSet_SelectionMode getNextMode(const std::string& theAttribute) const; - /// Find a point in the line with given coordinates - /// \param theFeature the line feature - /// \param theX the horizontal point coordinate - /// \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 diff --git a/src/PartSet/PartSet_FeatureLinePrs.cpp b/src/PartSet/PartSet_FeatureLinePrs.cpp index 4aa747a99..fe4c3a5c5 100644 --- a/src/PartSet/PartSet_FeatureLinePrs.cpp +++ b/src/PartSet/PartSet_FeatureLinePrs.cpp @@ -148,28 +148,6 @@ void PartSet_FeatureLinePrs::projectPointOnLine(FeaturePtr theFeature, } } -boost::shared_ptr PartSet_FeatureLinePrs::findPoint(FeaturePtr theFeature, - double theX, double theY) -{ - boost::shared_ptr aPoint2D; - if (!theFeature || theFeature->getKind() != getKind()) - return aPoint2D; - - boost::shared_ptr aData = theFeature->data(); - boost::shared_ptr aPoint = - boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_START)); - if (fabs(aPoint->x() - theX) < Precision::Confusion() && - fabs(aPoint->y() - theY) < Precision::Confusion()) - aPoint2D = aPoint; - else { - aPoint = boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_END)); - if (fabs(aPoint->x() - theX) < Precision::Confusion() && - fabs(aPoint->y() - theY) < Precision::Confusion()) - aPoint2D = aPoint; - } - return aPoint2D; -} - boost::shared_ptr PartSet_FeatureLinePrs::createLin2d(FeaturePtr theFeature) { boost::shared_ptr aFeatureLin; diff --git a/src/PartSet/PartSet_FeatureLinePrs.h b/src/PartSet/PartSet_FeatureLinePrs.h index b4a16dc5c..b9f2cfa42 100644 --- a/src/PartSet/PartSet_FeatureLinePrs.h +++ b/src/PartSet/PartSet_FeatureLinePrs.h @@ -69,13 +69,6 @@ public: const gp_Pnt& thePoint, Handle_V3d_View theView, double& theX, double& theY); - /// Find a point in the line with given coordinates - /// \param theFeature the line feature - /// \param theX the horizontal point coordinate - /// \param theY the vertical point coordinate - virtual boost::shared_ptr findPoint(FeaturePtr theFeature, double theX, - double theY); - /// Creates a lin 2d object on a base of the line feature /// \param theFeature the line feature static boost::shared_ptr createLin2d(FeaturePtr theFeature); diff --git a/src/PartSet/PartSet_FeaturePointPrs.cpp b/src/PartSet/PartSet_FeaturePointPrs.cpp index fa33cd40a..818206b47 100644 --- a/src/PartSet/PartSet_FeaturePointPrs.cpp +++ b/src/PartSet/PartSet_FeaturePointPrs.cpp @@ -71,22 +71,6 @@ PartSet_SelectionMode PartSet_FeaturePointPrs::getNextMode(const std::string& th return aMode; } -boost::shared_ptr PartSet_FeaturePointPrs::findPoint(FeaturePtr theFeature, - double theX, double theY) -{ - boost::shared_ptr aPoint2D; - if (!theFeature || theFeature->getKind() != getKind()) - return aPoint2D; - - boost::shared_ptr aData = theFeature->data(); - boost::shared_ptr aPoint = - boost::dynamic_pointer_cast(aData->attribute(POINT_ATTR_COORD)); - if (fabs(aPoint->x() - theX) < Precision::Confusion() && fabs(aPoint->y() - theY) < Precision::Confusion() ) - aPoint2D = aPoint; - - return aPoint2D; -} - boost::shared_ptr PartSet_FeaturePointPrs::featurePoint (const PartSet_SelectionMode& theMode) { diff --git a/src/PartSet/PartSet_FeaturePointPrs.h b/src/PartSet/PartSet_FeaturePointPrs.h index d43a82272..7fec84807 100644 --- a/src/PartSet/PartSet_FeaturePointPrs.h +++ b/src/PartSet/PartSet_FeaturePointPrs.h @@ -48,13 +48,6 @@ public: /// \return next attribute selection mode virtual PartSet_SelectionMode getNextMode(const std::string& theAttribute) const; - /// Find a point in the line with given coordinates - /// \param theFeature the line feature - /// \param theX the horizontal point coordinate - /// \param theY the vertical point coordinate - virtual boost::shared_ptr findPoint(FeaturePtr theFeature, 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_FeaturePrs.h b/src/PartSet/PartSet_FeaturePrs.h index 87fd3693b..9adf4a0a2 100644 --- a/src/PartSet/PartSet_FeaturePrs.h +++ b/src/PartSet/PartSet_FeaturePrs.h @@ -59,13 +59,6 @@ public: /// \return next attribute selection mode virtual PartSet_SelectionMode getNextMode(const std::string& theAttribute) const = 0; - /// Find a point in the line with given coordinates - /// \param theFeature the line feature - /// \param theX the horizontal point coordinate - /// \param theY the vertical point coordinate - virtual boost::shared_ptr findPoint(FeaturePtr theFeature, double theX, - double theY) = 0; - protected: /// Returns the operation feature /// \return the feature diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index 17f5be33b..8c6f38832 100644 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -302,13 +302,14 @@ void PartSet_Tools::createConstraint(FeaturePtr theSketch, } void PartSet_Tools::setConstraints(FeaturePtr theSketch, FeaturePtr theFeature, - const std::string& theAttribute, double theX, double theY) + const std::string& theAttribute, + double theClickedX, double theClickedY) { // find a feature point by the selection mode //boost::shared_ptr aPoint = featurePoint(theMode); - boost::shared_ptr aPoint = + boost::shared_ptr aFeaturePoint = boost::dynamic_pointer_cast(theFeature->data()->attribute(theAttribute)); - if (!aPoint) + if (!aFeaturePoint) return; // get all sketch features. If the point with the given coordinates belong to any sketch feature, @@ -319,28 +320,28 @@ void PartSet_Tools::setConstraints(FeaturePtr theSketch, FeaturePtr theFeature, std::list aFeatures = aRefList->list(); std::list::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end(); + std::list > anAttiributes; + boost::shared_ptr aClickedPoint = boost::shared_ptr + (new GeomAPI_Pnt2d(theClickedX, theClickedY)); for (; anIt != aLast; anIt++) { FeaturePtr aFeature = *anIt; - boost::shared_ptr aFPoint;// = aFeature->findPoint(theX, theY); + // find the given point in the feature attributes + anAttiributes = aFeature->data()->attributes(GeomDataAPI_Point2D::type()); + std::list >::const_iterator anIt = anAttiributes.begin(), + aLast = anAttiributes.end(); + boost::shared_ptr aFPoint; + for (;anIt!=aLast && !aFPoint; anIt++) { + boost::shared_ptr aCurPoint = + boost::dynamic_pointer_cast(*anIt); + if (aCurPoint && aCurPoint->pnt()->distance(aClickedPoint) < Precision::Confusion()) + aFPoint = aCurPoint; + } if (aFPoint) - PartSet_Tools::createConstraint(theSketch, aFPoint, aPoint); + PartSet_Tools::createConstraint(theSketch, aFPoint, aFeaturePoint); } } -boost::shared_ptr PartSet_Tools::findPoint(FeaturePtr theFeature, - double theX, double theY) -{ - boost::shared_ptr aFeaturePrs = PartSet_Tools::createFeaturePrs( - theFeature->getKind(), FeaturePtr(), theFeature); - - boost::shared_ptr aPoint2D; - if (aFeaturePrs) - aPoint2D = aFeaturePrs->findPoint(theFeature, theX, theY); - - return aPoint2D; -} - boost::shared_ptr PartSet_Tools::sketchPlane(FeaturePtr theSketch) { boost::shared_ptr aPlane; diff --git a/src/PartSet/PartSet_Tools.h b/src/PartSet/PartSet_Tools.h index 7f407ac8c..6aebb1032 100644 --- a/src/PartSet/PartSet_Tools.h +++ b/src/PartSet/PartSet_Tools.h @@ -114,17 +114,10 @@ public: /// \param theSketch a sketch feature /// \param theFeature a source feature /// \param theAttribute a name of the requried attribute attribute - /// \param theX the horizontal coordnate of the point - /// \param theY the vertical coordnate of the point + /// \param theClickedX the horizontal coordnate of the point + /// \param theClickedY the vertical coordnate of the point static void setConstraints(FeaturePtr theSketch, FeaturePtr theFeature, - const std::string& theAttribute, double theX, double theY); - - /// Find a point in the line with given coordinates - /// \param theFeature the line feature - /// \param theX the horizontal point coordinate - /// \param theY the vertical point coordinate - static boost::shared_ptr findPoint(FeaturePtr theFeature, double theX, - double theY); + const std::string& theAttribute, double theClickedX, double theClickedY); /// Create a sketch plane instance /// \param theSketch a sketch feature -- 2.39.2