X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPartSet%2FPartSet_FeatureLinePrs.cpp;h=ac173167f1e4c0e50df38abc4cd98b5010ad31f7;hb=23b712002a59e78673d8fce54c24aa4a7ab9ee51;hp=ae85a3d88b730f0e81ae7150f4a4e552aab6395f;hpb=ceebcac17ac262e957107c61a8962d1e8a87c70a;p=modules%2Fshaper.git diff --git a/src/PartSet/PartSet_FeatureLinePrs.cpp b/src/PartSet/PartSet_FeatureLinePrs.cpp index ae85a3d88..ac173167f 100644 --- a/src/PartSet/PartSet_FeatureLinePrs.cpp +++ b/src/PartSet/PartSet_FeatureLinePrs.cpp @@ -35,24 +35,6 @@ std::string PartSet_FeatureLinePrs::getKind() return SKETCH_LINE_KIND; } -void PartSet_FeatureLinePrs::initFeature(FeaturePtr theFeature) -{ - if (feature() && theFeature) - { - // use the last point of the previous feature as the first of the new one - boost::shared_ptr aData = theFeature->data(); - boost::shared_ptr anInitPoint = boost::dynamic_pointer_cast - (aData->attribute(LINE_ATTR_END)); - PartSet_Tools::setFeaturePoint(feature(), anInitPoint->x(), anInitPoint->y(), LINE_ATTR_START); - PartSet_Tools::setFeaturePoint(feature(), anInitPoint->x(), anInitPoint->y(), LINE_ATTR_END); - - aData = feature()->data(); - boost::shared_ptr aPoint = boost::dynamic_pointer_cast - (aData->attribute(LINE_ATTR_START)); - PartSet_Tools::createConstraint(sketch(), anInitPoint, aPoint); - } -} - PartSet_SelectionMode PartSet_FeatureLinePrs::setPoint(double theX, double theY, const PartSet_SelectionMode& theMode) { @@ -76,6 +58,27 @@ PartSet_SelectionMode PartSet_FeatureLinePrs::setPoint(double theX, double theY, return aMode; } +PartSet_SelectionMode PartSet_FeatureLinePrs::setFeature(FeaturePtr theFeature, const PartSet_SelectionMode& theMode) +{ + PartSet_SelectionMode aMode = theMode; + if (feature() && theFeature && theMode == SM_FirstPoint) + { + // use the last point of the previous feature as the first of the new one + boost::shared_ptr aData = theFeature->data(); + boost::shared_ptr anInitPoint = boost::dynamic_pointer_cast + (aData->attribute(LINE_ATTR_END)); + PartSet_Tools::setFeaturePoint(feature(), anInitPoint->x(), anInitPoint->y(), LINE_ATTR_START); + PartSet_Tools::setFeaturePoint(feature(), anInitPoint->x(), anInitPoint->y(), LINE_ATTR_END); + + aData = feature()->data(); + boost::shared_ptr aPoint = boost::dynamic_pointer_cast + (aData->attribute(LINE_ATTR_START)); + PartSet_Tools::createConstraint(sketch(), anInitPoint, aPoint); + aMode = SM_SecondPoint; + } + return aMode; +} + std::string PartSet_FeatureLinePrs::getAttribute(const PartSet_SelectionMode& theMode) const { std::string aAttribute; @@ -104,36 +107,19 @@ PartSet_SelectionMode PartSet_FeatureLinePrs::getNextMode(const std::string& the return aMode; } -void PartSet_FeatureLinePrs::move(double theDeltaX, double theDeltaY) -{ - boost::shared_ptr aData = feature()->data(); - if (!aData->isValid()) - return; - - boost::shared_ptr aPoint1 = - boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_START)); - aPoint1->setValue(aPoint1->x() + theDeltaX, aPoint1->y() + theDeltaY); - - boost::shared_ptr aPoint2 = - boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_END)); - aPoint2->setValue(aPoint2->x() + theDeltaX, aPoint2->y() + theDeltaY); -} - void PartSet_FeatureLinePrs::projectPointOnLine(FeaturePtr theFeature, const PartSet_SelectionMode& theMode, const gp_Pnt& thePoint, Handle(V3d_View) theView, double& theX, double& theY) { if (theFeature && theFeature->getKind() == getKind()) { - double X0, X1, X2, X3; - double Y0, Y1, Y2, Y3; - getLinePoint(theFeature, LINE_ATTR_START, X2, Y2); - getLinePoint(theFeature, LINE_ATTR_END, X3, Y3); + double X0, X1; + double Y0, Y1; PartSet_Tools::convertTo2D(thePoint, sketch(), theView, X1, Y1); boost::shared_ptr aPoint = boost::shared_ptr(new GeomAPI_Pnt2d(X1, Y1)); - boost::shared_ptr aFeatureLin = boost::shared_ptr - (new GeomAPI_Lin2d(X2, Y2, X3, Y3)); + boost::shared_ptr aFeatureLin = PartSet_FeatureLinePrs::createLin2d(theFeature); + switch (theMode) { case SM_FirstPoint: { boost::shared_ptr aResult = aFeatureLin->project(aPoint); @@ -211,6 +197,21 @@ boost::shared_ptr PartSet_FeatureLinePrs::findPoint(Feature return aPoint2D; } +boost::shared_ptr PartSet_FeatureLinePrs::createLin2d(FeaturePtr theFeature) +{ + boost::shared_ptr aFeatureLin; + if (!theFeature || theFeature->getKind() != PartSet_FeatureLinePrs::getKind()) + return aFeatureLin; + + double aStartX, aStartY, anEndX, anEndY; + getLinePoint(theFeature, LINE_ATTR_START, aStartX, aStartY); + getLinePoint(theFeature, LINE_ATTR_END, anEndX, anEndY); + + aFeatureLin = boost::shared_ptr + (new GeomAPI_Lin2d(aStartX, aStartY, anEndX, anEndY)); + return aFeatureLin; +} + boost::shared_ptr PartSet_FeatureLinePrs::featurePoint (const PartSet_SelectionMode& theMode) {