From 02e8faa19268200bdbd5533bc6ac33e63aa7655d Mon Sep 17 00:00:00 2001 From: nds Date: Mon, 23 Jun 2014 22:42:45 +0400 Subject: [PATCH] refs #80 - Sketch base GUI: create/draw point, circle and arc Move setConstraint method to the feature. --- src/ModuleBase/ModuleBase_ModelWidget.cpp | 5 ---- src/ModuleBase/ModuleBase_ModelWidget.h | 13 ++++---- .../ModuleBase_WidgetDoubleValue.cpp | 2 +- src/PartSet/PartSet_FeaturePrs.cpp | 23 -------------- src/PartSet/PartSet_FeaturePrs.h | 6 ---- .../PartSet_OperationCreateFeature.cpp | 2 +- .../PartSet_OperationFeatureCreate.cpp | 4 ++- src/PartSet/PartSet_Tools.cpp | 30 ++++++++++++++++++- src/PartSet/PartSet_Tools.h | 9 ++++++ 9 files changed, 48 insertions(+), 46 deletions(-) diff --git a/src/ModuleBase/ModuleBase_ModelWidget.cpp b/src/ModuleBase/ModuleBase_ModelWidget.cpp index dbac446a1..a15c0edcc 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.cpp +++ b/src/ModuleBase/ModuleBase_ModelWidget.cpp @@ -36,8 +36,3 @@ std::string ModuleBase_ModelWidget::attributeID() const { return myAttributeID; } - -void ModuleBase_ModelWidget::setHasDefaultValue(const bool& theHasDefaultValue) -{ - myHasDefaultValue = theHasDefaultValue; -} diff --git a/src/ModuleBase/ModuleBase_ModelWidget.h b/src/ModuleBase/ModuleBase_ModelWidget.h index 0f2cd543f..b7b3de3b8 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.h +++ b/src/ModuleBase/ModuleBase_ModelWidget.h @@ -58,6 +58,10 @@ public: /// \return a boolean value bool hasDefaultValue() const { return myHasDefaultValue; } + /// Returns the attribute name + /// \returns the string value + std::string attributeID() const; + signals: /// The signal about widget values changed void valuesChanged(); @@ -67,16 +71,9 @@ signals: void keyReleased(const std::string& theAttributeName, QKeyEvent* theEvent); protected: - /// Returns the attribute name - /// \returns the string value - std::string attributeID() const; - - /// Sets the has default value state to the widget - /// \param theHasDefaultValue the boolean value - void setHasDefaultValue(const bool& theHasDefaultValue); + bool myHasDefaultValue; /// the boolean state whether the control has a default value private: - bool myHasDefaultValue; /// the boolean state whether the control has a default value std::string myAttributeID; /// the attribute name of the model feature }; diff --git a/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp b/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp index aac859c49..36ebe04f1 100644 --- a/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp +++ b/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp @@ -67,7 +67,7 @@ ModuleBase_WidgetDoubleValue::ModuleBase_WidgetDoubleValue(QWidget* theParent, c aProp = theData->getProperty(DOUBLE_WDG_DFLT); double aDefVal = QString::fromStdString(aProp).toDouble(&isOk); - setHasDefaultValue(isOk); + myHasDefaultValue = isOk; if (isOk) { mySpinBox->setValue(aDefVal); } diff --git a/src/PartSet/PartSet_FeaturePrs.cpp b/src/PartSet/PartSet_FeaturePrs.cpp index 7e9d12f02..dfbad61ab 100644 --- a/src/PartSet/PartSet_FeaturePrs.cpp +++ b/src/PartSet/PartSet_FeaturePrs.cpp @@ -48,26 +48,3 @@ PartSet_SelectionMode PartSet_FeaturePrs::setFeature(FeaturePtr theFeature, { return SM_FirstPoint; } - -void PartSet_FeaturePrs::setConstraints(double theX, double theY, - const PartSet_SelectionMode& theMode) -{ - // find a feature point by the selection mode - boost::shared_ptr aPoint = featurePoint(theMode); - - // get all sketch features. If the point with the given coordinates belong to any sketch feature, - // the constraint is created between the feature point and the found sketch point - boost::shared_ptr aData = sketch()->data(); - boost::shared_ptr aRefList = - boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_FEATURES)); - - std::list aFeatures = aRefList->list(); - std::list::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end(); - for (; anIt != aLast; anIt++) - { - FeaturePtr aFeature = *anIt; - boost::shared_ptr aFPoint = PartSet_Tools::findPoint(aFeature, theX, theY); - if (aFPoint) - PartSet_Tools::createConstraint(sketch(), aFPoint, aPoint); - } -} diff --git a/src/PartSet/PartSet_FeaturePrs.h b/src/PartSet/PartSet_FeaturePrs.h index eeaa0b851..87fd3693b 100644 --- a/src/PartSet/PartSet_FeaturePrs.h +++ b/src/PartSet/PartSet_FeaturePrs.h @@ -66,12 +66,6 @@ public: virtual boost::shared_ptr findPoint(FeaturePtr theFeature, double theX, double theY) = 0; - /// Creates constrains of the current - /// \param theX the horizontal coordnate of the point - /// \param theY the vertical coordnate of the point - /// \param theMode the current operation selection mode. The feature attribute depends on the mode - void setConstraints(double theX, double theY, const PartSet_SelectionMode& theMode); - protected: /// Returns the operation feature /// \return the feature diff --git a/src/PartSet/PartSet_OperationCreateFeature.cpp b/src/PartSet/PartSet_OperationCreateFeature.cpp index da80e62b2..5fa63f4fa 100644 --- a/src/PartSet/PartSet_OperationCreateFeature.cpp +++ b/src/PartSet/PartSet_OperationCreateFeature.cpp @@ -117,7 +117,7 @@ void PartSet_OperationCreateFeature::mouseReleased(QMouseEvent* theEvent, Handle aPoint = BRep_Tool::Pnt(aVertex); PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY); - myFeaturePrs->setConstraints(aX, anY, myPointSelectionMode); + //myFeaturePrs->setConstraints(aX, anY, myPointSelectionMode); } } else if (aShape.ShapeType() == TopAbs_EDGE) // the line is selected diff --git a/src/PartSet/PartSet_OperationFeatureCreate.cpp b/src/PartSet/PartSet_OperationFeatureCreate.cpp index 0830639a7..a20398897 100644 --- a/src/PartSet/PartSet_OperationFeatureCreate.cpp +++ b/src/PartSet/PartSet_OperationFeatureCreate.cpp @@ -117,7 +117,8 @@ void PartSet_OperationFeatureCreate::mouseReleased(QMouseEvent* theEvent, Handle aPoint = BRep_Tool::Pnt(aVertex); PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY); - //myFeaturePrs->setConstraints(aX, anY, myPointSelectionMode); + PartSet_Tools::setConstraints(sketch(), feature(), myActiveWidget->attributeID(), + aX, anY); } } else if (aShape.ShapeType() == TopAbs_EDGE) // the line is selected @@ -190,6 +191,7 @@ void PartSet_OperationFeatureCreate::onWidgetActivated(ModuleBase_ModelWidget* t // TODO: to be realized in the custom point selector. The last point values of the init feature // should be to to the start point of a new feature //myActiveWidget->init(myInitFeature); + //PartSet_FeatureLinePrs::setFeature(myInitFeature, SM_FirstPoint); myInitFeature = FeaturePtr(); emit activateNextWidget(myActiveWidget); } diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index 8d1329046..17f5be33b 100644 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -300,6 +301,33 @@ void PartSet_Tools::createConstraint(FeaturePtr theSketch, aFeature->execute(); } +void PartSet_Tools::setConstraints(FeaturePtr theSketch, FeaturePtr theFeature, + const std::string& theAttribute, double theX, double theY) +{ + // find a feature point by the selection mode + //boost::shared_ptr aPoint = featurePoint(theMode); + boost::shared_ptr aPoint = + boost::dynamic_pointer_cast(theFeature->data()->attribute(theAttribute)); + if (!aPoint) + return; + + // get all sketch features. If the point with the given coordinates belong to any sketch feature, + // the constraint is created between the feature point and the found sketch point + boost::shared_ptr aData = theSketch->data(); + boost::shared_ptr aRefList = + boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_FEATURES)); + + std::list aFeatures = aRefList->list(); + std::list::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end(); + for (; anIt != aLast; anIt++) + { + FeaturePtr aFeature = *anIt; + boost::shared_ptr aFPoint;// = aFeature->findPoint(theX, theY); + if (aFPoint) + PartSet_Tools::createConstraint(theSketch, aFPoint, aPoint); + } +} + boost::shared_ptr PartSet_Tools::findPoint(FeaturePtr theFeature, double theX, double theY) { @@ -355,4 +383,4 @@ bool PartSet_Tools::isConstraintFeature(const std::string& theKind) return theKind == PartSet_ConstraintLengthPrs::getKind() || theKind == PartSet_ConstraintDistancePrs::getKind() || theKind == PartSet_ConstraintRadiusPrs::getKind(); -} \ No newline at end of file +} diff --git a/src/PartSet/PartSet_Tools.h b/src/PartSet/PartSet_Tools.h index f4e4ae62b..7f407ac8c 100644 --- a/src/PartSet/PartSet_Tools.h +++ b/src/PartSet/PartSet_Tools.h @@ -110,6 +110,15 @@ public: boost::shared_ptr thePoint1, boost::shared_ptr thePoint2); + /// Creates constrains of the current + /// \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 + 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 -- 2.39.2