From 1f2a62003cac25a91d8517f3af1940c774f10433 Mon Sep 17 00:00:00 2001 From: nds Date: Tue, 24 Jun 2014 11:21:45 +0400 Subject: [PATCH] refs #80 - Sketch base GUI: create/draw point, circle and arc Widget controls for a constraint filling. --- src/Config/CMakeLists.txt | 1 + src/Config/Config_Keywords.h | 2 + src/ModuleBase/CMakeLists.txt | 2 + src/ModuleBase/ModuleBase_WidgetFactory.cpp | 14 +++- src/ModuleBase/ModuleBase_WidgetFactory.h | 1 + src/ModuleBase/ModuleBase_WidgetFeature.cpp | 80 +++++++++++++++++++ src/ModuleBase/ModuleBase_WidgetFeature.h | 55 +++++++++++++ src/PartSet/PartSet_ConstraintDistancePrs.cpp | 51 ++++++------ .../PartSet_OperationFeatureCreate.cpp | 41 ++++++++-- src/PartSet/PartSet_OperationFeatureCreate.h | 14 +++- src/SketchPlugin/SketchPlugin_Constraint.h | 2 + .../SketchPlugin_ConstraintDistance.cpp | 4 +- src/SketchPlugin/plugin-Sketch.xml | 4 + 13 files changed, 237 insertions(+), 34 deletions(-) create mode 100644 src/ModuleBase/ModuleBase_WidgetFeature.cpp create mode 100644 src/ModuleBase/ModuleBase_WidgetFeature.h diff --git a/src/Config/CMakeLists.txt b/src/Config/CMakeLists.txt index ebb5efb69..2e826fc24 100644 --- a/src/Config/CMakeLists.txt +++ b/src/Config/CMakeLists.txt @@ -9,6 +9,7 @@ SET(PROJECT_HEADERS Config_XMLReader.h Config_ModuleReader.h Config_FeatureReader.h + Config_Keywords.h Config_WidgetAPI.h Config_WidgetReader.h Config_PointerMessage.h diff --git a/src/Config/Config_Keywords.h b/src/Config/Config_Keywords.h index 125faa57a..0d16ad432 100644 --- a/src/Config/Config_Keywords.h +++ b/src/Config/Config_Keywords.h @@ -32,6 +32,8 @@ const static char* WDG_SELECTOR = "selector"; //Specific widget containers const static char* WDG_POINT_SELECTOR = "point_selector"; +const static char* WDG_FEATURE_SELECTOR = "feature_selector"; + const static char* _ID = "id"; //const static char* WORKBENCH_ID = "id"; //const static char* GROUP_ID = "id"; diff --git a/src/ModuleBase/CMakeLists.txt b/src/ModuleBase/CMakeLists.txt index 3a66ec0d5..b617a5062 100644 --- a/src/ModuleBase/CMakeLists.txt +++ b/src/ModuleBase/CMakeLists.txt @@ -10,6 +10,7 @@ SET(PROJECT_HEADERS ModuleBase_WidgetBoolValue.h ModuleBase_WidgetDoubleValue.h ModuleBase_WidgetFactory.h + ModuleBase_WidgetFeature.h ModuleBase_WidgetPoint2D.h ModuleBase_WidgetSwitch.h ModuleBase_WidgetSelector.h @@ -24,6 +25,7 @@ SET(PROJECT_SOURCES ModuleBase_WidgetBoolValue.cpp ModuleBase_WidgetDoubleValue.cpp ModuleBase_WidgetFactory.cpp + ModuleBase_WidgetFeature.cpp ModuleBase_WidgetPoint2D.cpp ModuleBase_WidgetSwitch.cpp ModuleBase_WidgetSelector.cpp diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.cpp b/src/ModuleBase/ModuleBase_WidgetFactory.cpp index e83cd01fc..1c372fd67 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFactory.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -119,7 +120,11 @@ QWidget* ModuleBase_WidgetFactory::createWidgetByType(const std::string& theType } else if (theType == WDG_POINT_SELECTOR) { result = pointSelectorControl(theParent); - } else if (myWidgetApi->isContainerWidget() || myWidgetApi->isPagedWidget()) { + } else if (theType == WDG_FEATURE_SELECTOR) { + result = featureSelectorControl(theParent); + + } + else if (myWidgetApi->isContainerWidget() || myWidgetApi->isPagedWidget()) { result = createContainer(theType, theParent); } #ifdef _DEBUG @@ -163,6 +168,13 @@ QWidget* ModuleBase_WidgetFactory::pointSelectorControl(QWidget* theParent) return aWidget->getControl(); } +QWidget* ModuleBase_WidgetFactory::featureSelectorControl(QWidget* theParent) +{ + ModuleBase_WidgetFeature* aWidget = new ModuleBase_WidgetFeature(theParent, myWidgetApi); + myModelWidgets.append(aWidget); + return aWidget->getControl(); +} + QString ModuleBase_WidgetFactory::qs(const std::string& theStdString) const { return QString::fromStdString(theStdString); diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.h b/src/ModuleBase/ModuleBase_WidgetFactory.h index aa7f6da76..e2162872c 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.h +++ b/src/ModuleBase/ModuleBase_WidgetFactory.h @@ -38,6 +38,7 @@ protected: QWidget* labelControl(QWidget* theParent); QWidget* doubleSpinBoxControl(QWidget* theParent); QWidget* pointSelectorControl(QWidget* theParent); + QWidget* featureSelectorControl(QWidget* theParent); QWidget* createContainer(const std::string& theType, QWidget* theParent = NULL); QWidget* selectorControl(QWidget* theParent); QWidget* booleanControl(QWidget* theParent); diff --git a/src/ModuleBase/ModuleBase_WidgetFeature.cpp b/src/ModuleBase/ModuleBase_WidgetFeature.cpp new file mode 100644 index 000000000..dd33700f0 --- /dev/null +++ b/src/ModuleBase/ModuleBase_WidgetFeature.cpp @@ -0,0 +1,80 @@ +// File: ModuleBase_WidgetFeature.cpp +// Created: 25 Apr 2014 +// Author: Natalia ERMOLAEVA + +#include + +#include +#include + +#include +#include + +#include +#include +#include +#include + +#include + +ModuleBase_WidgetFeature::ModuleBase_WidgetFeature(QWidget* theParent, + const Config_WidgetAPI* theData) +: ModuleBase_ModelWidget(theParent, theData) +{ + QString aKinds = QString::fromStdString(theData->getProperty(FEATURE_KEYSEQUENCE)); + myFeatureKinds = aKinds.split(" "); +} + +ModuleBase_WidgetFeature::~ModuleBase_WidgetFeature() +{ +} + +bool ModuleBase_WidgetFeature::setFeature(const FeaturePtr& theFeature) +{ + if (!theFeature && myFeatureKinds.contains(theFeature->getKind().c_str())) + return false; + + //bool isBlocked = this->blockSignals(true); + myFeature = theFeature; + //this->blockSignals(isBlocked); + emit valuesChanged(); + return true; +} + +bool ModuleBase_WidgetFeature::storeValue(FeaturePtr theFeature) const +{ + boost::shared_ptr aData = theFeature->data(); + boost::shared_ptr aRef = + boost::dynamic_pointer_cast(aData->attribute(attributeID())); + + ModuleBase_WidgetFeature* that = (ModuleBase_WidgetFeature*) this; + //bool isBlocked = that->blockSignals(true); + aRef->setFeature(myFeature); + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED)); + //that->blockSignals(isBlocked); + + return true; +} + +bool ModuleBase_WidgetFeature::restoreValue(FeaturePtr theFeature) +{ + boost::shared_ptr aData = theFeature->data(); + boost::shared_ptr aRef = + boost::dynamic_pointer_cast(aData->attribute(attributeID())); + + //bool isBlocked = this->blockSignals(true); + myFeature = aRef->feature(); + //this->blockSignals(isBlocked); + return true; +} + +QWidget* ModuleBase_WidgetFeature::getControl() const +{ + return 0; +} + +QList ModuleBase_WidgetFeature::getControls() const +{ + QList aControls; + return aControls; +} diff --git a/src/ModuleBase/ModuleBase_WidgetFeature.h b/src/ModuleBase/ModuleBase_WidgetFeature.h new file mode 100644 index 000000000..a429421f0 --- /dev/null +++ b/src/ModuleBase/ModuleBase_WidgetFeature.h @@ -0,0 +1,55 @@ +// File: ModuleBase_WidgetFeature.h +// Created: 25 Apr 2014 +// Author: Natalia ERMOLAEVA + +#ifndef ModuleBase_WidgetFeature_H +#define ModuleBase_WidgetFeature_H + +#include +#include "ModuleBase_ModelWidget.h" + +#include +#include + +class ModelAPI_Feature; + +/**\class ModuleBase_WidgetFeature + * \ingroup GUI + * \brief Custom widget. An abstract class to be redefined to fill with some GUI controls + */ +class MODULEBASE_EXPORT ModuleBase_WidgetFeature : public ModuleBase_ModelWidget +{ + Q_OBJECT +public: + /// Constructor + /// \theParent the parent object + /// \theParent the parent object + /// \theData the widget configuation. The attribute of the model widget is obtained from + ModuleBase_WidgetFeature(QWidget* theParent, const Config_WidgetAPI* theData); + /// Destructor + virtual ~ModuleBase_WidgetFeature(); + + /// Fill the widget values by given point + /// \param thePoint the point + bool setFeature(const FeaturePtr& theFeature); + + /// Saves the internal parameters to the given feature + /// \param theFeature a model feature to be changed + virtual bool storeValue(FeaturePtr theFeature) const; + + virtual bool restoreValue(FeaturePtr theFeature); + + /// Returns the internal parent wiget control, that can be shown anywhere + /// \returns the widget + QWidget* getControl() const; + + /// Returns list of widget controls + /// \return a control list + virtual QList getControls() const; + +private: + FeaturePtr myFeature; ///< the current widget feature + QStringList myFeatureKinds; ///< the kinds of possible features +}; + +#endif diff --git a/src/PartSet/PartSet_ConstraintDistancePrs.cpp b/src/PartSet/PartSet_ConstraintDistancePrs.cpp index 6bd7510c9..661061efd 100644 --- a/src/PartSet/PartSet_ConstraintDistancePrs.cpp +++ b/src/PartSet/PartSet_ConstraintDistancePrs.cpp @@ -87,25 +87,11 @@ PartSet_SelectionMode PartSet_ConstraintDistancePrs::setPoint(double theX, doubl switch (theMode) { case SM_LastPoint: { - 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 = 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); - - if (!aFeatureLin->isRight(aPoint)) - aDistance = -aDistance; - - AttributeDoublePtr aFlyoutAttr = boost::dynamic_pointer_cast - (feature()->data()->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE)); - aFlyoutAttr->setValue(aDistance); + boost::shared_ptr aFlyOutAttr = + boost::dynamic_pointer_cast(feature()->data()->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT)); + aFlyOutAttr->setValue(boost::shared_ptr(new GeomAPI_Pnt2d(theX, theY))); + + boost::shared_ptr aFlyOutPnt = aFlyOutAttr->pnt(); aMode = SM_DonePoint; } @@ -131,14 +117,21 @@ Handle(AIS_InteractiveObject) PartSet_ConstraintDistancePrs::createPresentation( if (!aPoint_A || !aPoint_B) return anAIS; + // fly out calculation boost::shared_ptr aData = theFeature->data(); - boost::shared_ptr aFlyoutAttr = - boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE)); - double aFlyout = aFlyoutAttr->value(); + boost::shared_ptr aFlyOutAttr = + boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT)); + boost::shared_ptr aFlyOutPnt = aFlyOutAttr->pnt(); - boost::shared_ptr aValueAttr = - boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_VALUE)); - double aValue = aValueAttr->value(); + 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(aFlyOutPnt); + double aDistance = aFlyOutPnt->distance(aResult); + + if (!aFeatureLin->isRight(aFlyOutPnt)) + aDistance = -aDistance; + double aFlyout = aDistance; gp_Pnt aPoint1, aPoint2; PartSet_Tools::convertTo3D(aPoint_A->x(), aPoint_A->y(), theSketch, aPoint1); @@ -152,6 +145,14 @@ Handle(AIS_InteractiveObject) PartSet_ConstraintDistancePrs::createPresentation( aP2 = aPoint1; } + // value calculation + boost::shared_ptr aValueAttr = + boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_VALUE)); + double aValue = aValueAttr->value(); + if (aValue == 0) { // TODO! the default value + aValue = aP1.Distance(aP2); + } + if (anAIS.IsNull()) { Handle(AIS_LengthDimension) aDimAIS = new AIS_LengthDimension(aP1, aP2, aPlane); diff --git a/src/PartSet/PartSet_OperationFeatureCreate.cpp b/src/PartSet/PartSet_OperationFeatureCreate.cpp index a20398897..a318a1280 100644 --- a/src/PartSet/PartSet_OperationFeatureCreate.cpp +++ b/src/PartSet/PartSet_OperationFeatureCreate.cpp @@ -16,11 +16,13 @@ #include #include #include +#include #include #include #include +#include #include #include @@ -40,7 +42,7 @@ using namespace std; PartSet_OperationFeatureCreate::PartSet_OperationFeatureCreate(const QString& theId, QObject* theParent, - FeaturePtr theFeature) + FeaturePtr theFeature) : PartSet_OperationSketchBase(theId, theParent), mySketch(theFeature), myActiveWidget(0) { } @@ -51,7 +53,8 @@ PartSet_OperationFeatureCreate::~PartSet_OperationFeatureCreate() bool PartSet_OperationFeatureCreate::canProcessKind(const std::string& theId) { - return theId == SKETCH_LINE_KIND || theId == SKETCH_POINT_KIND /*|| theId == SKETCH_CIRCLE_KIND || + return theId == SKETCH_LINE_KIND || theId == SKETCH_POINT_KIND /*|| + theId == SKETCH_CONSTRAINT_DISTANCE_KIND/*|| theId == SKETCH_CIRCLE_KIND || theId == SKETCH_ARC_KIND*/; } @@ -143,7 +146,17 @@ void PartSet_OperationFeatureCreate::mouseReleased(QMouseEvent* theEvent, Handle anArcPrs->projectPointOnFeature(feature(), sketch(), aPoint, theView, aX, anY); } }*/ - setWidgetPoint(aX, anY); + bool isApplyed = false; + if (isPointWidget()) + isApplyed = setWidgetPoint(aX, anY); + else { + if (!theSelected.empty()) { + XGUI_ViewerPrs aPrs = theSelected.front(); + FeaturePtr aFeature = aPrs.feature(); + if (aFeature) + isApplyed = setWidgetFeature(aFeature); + } + } flushUpdated(); emit activateNextWidget(myActiveWidget); } @@ -281,8 +294,26 @@ FeaturePtr PartSet_OperationFeatureCreate::createFeature(const bool theFlushMess } }*/ -void PartSet_OperationFeatureCreate::setWidgetPoint(double theX, double theY) +bool PartSet_OperationFeatureCreate::isPointWidget() const +{ + return dynamic_cast(myActiveWidget); +} + +bool PartSet_OperationFeatureCreate::setWidgetPoint(double theX, double theY) { ModuleBase_WidgetPoint2D* aWidget = dynamic_cast(myActiveWidget); + if (!aWidget) + return false; + aWidget->setPoint(boost::shared_ptr(new GeomAPI_Pnt2d(theX, theY))); -} \ No newline at end of file + return true; +} + +bool PartSet_OperationFeatureCreate::setWidgetFeature(const FeaturePtr& theFeature) +{ + ModuleBase_WidgetFeature* aWidget = dynamic_cast(myActiveWidget); + if (!aWidget) + return false; + + return aWidget->setFeature(theFeature); +} diff --git a/src/PartSet/PartSet_OperationFeatureCreate.h b/src/PartSet/PartSet_OperationFeatureCreate.h index 519c45e2f..606bdc3bf 100644 --- a/src/PartSet/PartSet_OperationFeatureCreate.h +++ b/src/PartSet/PartSet_OperationFeatureCreate.h @@ -120,10 +120,20 @@ protected: //void setPointSelectionMode(const PartSet_SelectionMode& theMode, // const bool isToEmitSignal = true); - /// Set the widget point + /// Returns true if the active widget is the point selector widget + /// \return the boolean value + bool isPointWidget() const; + + /// Set the point to the active widget /// \param theX the horizontal coordinate /// \param theY the vertical coordinate - void setWidgetPoint(double theX, double theY); + /// \return true if the point is set + bool setWidgetPoint(double theX, double theY); + + /// Set the feature to the active widget + /// \param theFeature a feature + /// \return true if the feature is set + bool setWidgetFeature(const FeaturePtr& theFeature); private: //boost::shared_ptr myFeaturePrs; ///< the feature presentation diff --git a/src/SketchPlugin/SketchPlugin_Constraint.h b/src/SketchPlugin/SketchPlugin_Constraint.h index fbc182c64..dbb66522a 100644 --- a/src/SketchPlugin/SketchPlugin_Constraint.h +++ b/src/SketchPlugin/SketchPlugin_Constraint.h @@ -26,6 +26,8 @@ */ /// The value parameter for the constraint const std::string CONSTRAINT_ATTR_VALUE("ConstraintValue"); +/// The 2D value parameter for the constraint +const std::string CONSTRAINT_ATTR_FLYOUT_VALUE_PNT("ConstraintFlyoutValuePnt"); /// The value parameter for the constraint const std::string CONSTRAINT_ATTR_FLYOUT_VALUE("ConstraintFlyoutValue"); /// First entity for the constraint diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp b/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp index 52c58e146..afb764a5d 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp @@ -4,6 +4,8 @@ #include "SketchPlugin_ConstraintDistance.h" +#include "GeomDataAPI_Point2D.h" + #include #include #include @@ -15,7 +17,7 @@ SketchPlugin_ConstraintDistance::SketchPlugin_ConstraintDistance() void SketchPlugin_ConstraintDistance::initAttributes() { data()->addAttribute(CONSTRAINT_ATTR_VALUE, ModelAPI_AttributeDouble::type()); - data()->addAttribute(CONSTRAINT_ATTR_FLYOUT_VALUE, ModelAPI_AttributeDouble::type()); + data()->addAttribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT, GeomDataAPI_Point2D::type()); data()->addAttribute(CONSTRAINT_ATTR_ENTITY_A, ModelAPI_AttributeRefAttr::type()); data()->addAttribute(CONSTRAINT_ATTR_ENTITY_B, ModelAPI_AttributeRefAttr::type()); } diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 596879323..f1d354e46 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -24,6 +24,10 @@