From: vsv Date: Tue, 24 Jun 2014 07:53:09 +0000 (+0400) Subject: Point2d Distance widget added X-Git-Tag: V_0.4.4~263^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3c6beade1b4575994f2d028b2a42b43d68415fe6;p=modules%2Fshaper.git Point2d Distance widget added --- diff --git a/src/Config/Config_Keywords.h b/src/Config/Config_Keywords.h index 125faa57a..050a947fe 100644 --- a/src/Config/Config_Keywords.h +++ b/src/Config/Config_Keywords.h @@ -31,6 +31,7 @@ const static char* WDG_SELECTOR = "selector"; //Specific widget containers const static char* WDG_POINT_SELECTOR = "point_selector"; +const static char* WDG_POINT2D_DISTANCE = "point2ddistance"; const static char* _ID = "id"; //const static char* WORKBENCH_ID = "id"; diff --git a/src/ModuleBase/CMakeLists.txt b/src/ModuleBase/CMakeLists.txt index b56c21791..e70f413c1 100644 --- a/src/ModuleBase/CMakeLists.txt +++ b/src/ModuleBase/CMakeLists.txt @@ -14,6 +14,7 @@ SET(PROJECT_HEADERS ModuleBase_WidgetSwitch.h ModuleBase_WidgetSelector.h ModuleBase_IWorkshop.h + ModuleBase_WidgetPoint2dDistance.h ) SET(PROJECT_SOURCES @@ -27,11 +28,13 @@ SET(PROJECT_SOURCES ModuleBase_WidgetPoint2D.cpp ModuleBase_WidgetSwitch.cpp ModuleBase_WidgetSelector.cpp + ModuleBase_WidgetPoint2dDistance.cpp ) SET(PROJECT_LIBRARIES Config ModelAPI + GeomAPI ${QT_LIBRARIES} ${CAS_VIEWER} ${CAS_KERNEL} diff --git a/src/ModuleBase/ModuleBase_WidgetDoubleValue.h b/src/ModuleBase/ModuleBase_WidgetDoubleValue.h index 70f6de58c..2a5b6c2a1 100644 --- a/src/ModuleBase/ModuleBase_WidgetDoubleValue.h +++ b/src/ModuleBase/ModuleBase_WidgetDoubleValue.h @@ -43,7 +43,7 @@ public: /// \param theEvent the processed event virtual bool eventFilter(QObject *theObject, QEvent *theEvent); -private: +protected: QWidget* myContainer; QLabel* myLabel; QDoubleSpinBox* mySpinBox; diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.cpp b/src/ModuleBase/ModuleBase_WidgetFactory.cpp index e83cd01fc..89b82bef4 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFactory.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -119,6 +120,9 @@ QWidget* ModuleBase_WidgetFactory::createWidgetByType(const std::string& theType } else if (theType == WDG_POINT_SELECTOR) { result = pointSelectorControl(theParent); + } else if (theType == WDG_POINT2D_DISTANCE) { + result = point2dDistanceControl(theParent); + } else if (myWidgetApi->isContainerWidget() || myWidgetApi->isPagedWidget()) { result = createContainer(theType, theParent); } @@ -183,4 +187,13 @@ QWidget* ModuleBase_WidgetFactory::booleanControl(QWidget* theParent) myModelWidgets.append(aBoolWgt); return aBoolWgt->getControl(); +} + + +QWidget* ModuleBase_WidgetFactory::point2dDistanceControl(QWidget* theParent) +{ + ModuleBase_WidgetPoint2dDistance* aDistWgt = new ModuleBase_WidgetPoint2dDistance(theParent, myWidgetApi); + myModelWidgets.append(aDistWgt); + + return aDistWgt->getControl(); } \ No newline at end of file diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.h b/src/ModuleBase/ModuleBase_WidgetFactory.h index aa7f6da76..f8f67a6e4 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.h +++ b/src/ModuleBase/ModuleBase_WidgetFactory.h @@ -41,6 +41,7 @@ protected: QWidget* createContainer(const std::string& theType, QWidget* theParent = NULL); QWidget* selectorControl(QWidget* theParent); QWidget* booleanControl(QWidget* theParent); + QWidget* point2dDistanceControl(QWidget* theParent); QString qs(const std::string& theStdString) const; diff --git a/src/ModuleBase/ModuleBase_WidgetPoint2dDistance.cpp b/src/ModuleBase/ModuleBase_WidgetPoint2dDistance.cpp new file mode 100644 index 000000000..53ebdea46 --- /dev/null +++ b/src/ModuleBase/ModuleBase_WidgetPoint2dDistance.cpp @@ -0,0 +1,37 @@ +// File: ModuleBase_WidgetPoint2dDistance.h +// Created: 23 June 2014 +// Author: Vitaly Smetannikov + +#include "ModuleBase_WidgetPoint2dDistance.h" + +#include +#include +#include + +#include +#include + +#include + +ModuleBase_WidgetPoint2dDistance::ModuleBase_WidgetPoint2dDistance(QWidget* theParent, const Config_WidgetAPI* theData) + : ModuleBase_WidgetDoubleValue(theParent, theData) +{ + myFirstPntName = theData->getProperty("first_point"); +} + +ModuleBase_WidgetPoint2dDistance::~ModuleBase_WidgetPoint2dDistance() +{ +} + +void ModuleBase_WidgetPoint2dDistance::setPoint(FeaturePtr theFeature, const boost::shared_ptr& thePnt) +{ + boost::shared_ptr aData = theFeature->data(); + boost::shared_ptr aPoint = boost::dynamic_pointer_cast + (aData->attribute(myFirstPntName)); + double aRadius = thePnt->distance(aPoint->pnt()); + AttributeDoublePtr aReal = aData->real(attributeID()); + if (aReal && aReal->value() != mySpinBox->value()) { + aReal->setValue(aRadius); + mySpinBox->setValue(aRadius); + } +} \ No newline at end of file diff --git a/src/ModuleBase/ModuleBase_WidgetPoint2dDistance.h b/src/ModuleBase/ModuleBase_WidgetPoint2dDistance.h new file mode 100644 index 000000000..a078b9b0c --- /dev/null +++ b/src/ModuleBase/ModuleBase_WidgetPoint2dDistance.h @@ -0,0 +1,33 @@ +// File: ModuleBase_WidgetPoint2dDistance.h +// Created: 23 June 2014 +// Author: Vitaly Smetannikov + + +#ifndef ModuleBase_WidgetPoint2dDistance_H +#define ModuleBase_WidgetPoint2dDistance_H + +#include "ModuleBase.h" +#include "ModuleBase_WidgetDoubleValue.h" + +class GeomAPI_Pnt2d; + +class MODULEBASE_EXPORT ModuleBase_WidgetPoint2dDistance: public ModuleBase_WidgetDoubleValue +{ + Q_OBJECT +public: + /// Constructor + /// \theParent the parent object + /// \theData the widget configuation. The attribute of the model widget is obtained from + ModuleBase_WidgetPoint2dDistance(QWidget* theParent, const Config_WidgetAPI* theData); + + virtual ~ModuleBase_WidgetPoint2dDistance(); + + /// Set the second point which defines a value in the widget as a distance with a first point defined by feature + void setPoint(FeaturePtr theFeature, const boost::shared_ptr& thePnt); + +private: + std::string myFirstPntName; +}; + + +#endif \ No newline at end of file diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 596879323..d81f6906f 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -14,7 +14,7 @@ - +