From: vsv Date: Mon, 20 Jan 2020 16:28:17 +0000 (+0300) Subject: Update B-Spline GUI X-Git-Tag: V9_5_0a1~54^2~22 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3d4040199faaa10d515ad758873e051af5654771;p=modules%2Fshaper.git Update B-Spline GUI --- diff --git a/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp b/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp index 637e37b4e..e4f47673e 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp @@ -60,6 +60,8 @@ ConstructionPlugin_Plugin::ConstructionPlugin_Plugin() Config_Prop::IntSpin, SKETCH_WIDTH); Config_PropManager::registerProp(SKETCH_TAB_NAME, "angular_tolerance", "Angular tolerance", Config_Prop::DblSpin, "0.04"); + Config_PropManager::registerProp(SKETCH_TAB_NAME, "spline_weight", "Default spline weight", + Config_Prop::DblSpin, "1.0"); Config_PropManager::registerProp(SKETCH_TAB_NAME, "rotate_to_plane", "Rotate to plane when selected", Config_Prop::Boolean, "false"); diff --git a/src/PartSet/CMakeLists.txt b/src/PartSet/CMakeLists.txt index 0384951d6..9f87f6c3f 100644 --- a/src/PartSet/CMakeLists.txt +++ b/src/PartSet/CMakeLists.txt @@ -62,6 +62,7 @@ SET(PROJECT_HEADERS PartSet_TreeNodes.h PartSet_FieldStepPrs.h PartSet_WidgetBSplinePoints.h + PartSet_BSplineWidget.h ) SET(PROJECT_MOC_HEADERS @@ -81,6 +82,7 @@ SET(PROJECT_MOC_HEADERS PartSet_WidgetSketchLabel.h PartSet_WidgetBSplinePoints.h PartSet_ExternalPointsMgr.h + PartSet_BSplineWidget.h ) SET(PROJECT_SOURCES @@ -114,6 +116,7 @@ SET(PROJECT_SOURCES PartSet_TreeNodes.cpp PartSet_FieldStepPrs.cpp PartSet_WidgetBSplinePoints.cpp + PartSet_BSplineWidget.cpp ) SET(PROJECT_RESOURCES diff --git a/src/PartSet/PartSet_BSplineWidget.cpp b/src/PartSet/PartSet_BSplineWidget.cpp new file mode 100644 index 000000000..7093c28fd --- /dev/null +++ b/src/PartSet/PartSet_BSplineWidget.cpp @@ -0,0 +1,181 @@ +// Copyright (C) 2019-2020 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include + +#include + +#include + +#include + +#include + +#include + +#include +#include +#include +#include + + +PartSet_BSplineWidget::PartSet_BSplineWidget( + QWidget* theParent, + const Config_WidgetAPI* theData) + : ModuleBase_ModelWidget(theParent, theData) +{ + QVBoxLayout* aMainLayout = new QVBoxLayout(this); + ModuleBase_Tools::adjustMargins(aMainLayout); + + // GroupBox to keep widgets for B-spline poles and weights + myPolesGroupBox = new QGroupBox(tr("Poles and weights"), theParent); + aMainLayout->addWidget(myPolesGroupBox); + // layout of GroupBox + QGridLayout* aGroupLayout = new QGridLayout(myPolesGroupBox); + aGroupLayout->setSpacing(4); + aGroupLayout->setColumnStretch(1, 1); + ModuleBase_Tools::adjustMargins(aGroupLayout); + + restoreValueCustom(); +} + +void PartSet_BSplineWidget::setFeature(const FeaturePtr& theFeature, + const bool theToStoreValue, + const bool isUpdateFlushed) +{ + ModuleBase_ModelWidget::setFeature(theFeature, theToStoreValue, isUpdateFlushed); + restoreValueCustom(); +} + +void PartSet_BSplineWidget::deactivate() +{ + ModuleBase_ModelWidget::deactivate(); + storeValueCustom(); +} + + +QList PartSet_BSplineWidget::getControls() const +{ + QList aControls; + std::list::const_iterator anIt = myPoles.begin(); + for (; anIt != myPoles.end(); ++anIt) { + aControls.append(anIt->myWeight); + } + return aControls; +} + +void PartSet_BSplineWidget::storePolesAndWeights() const +{ + std::shared_ptr aData = myFeature->data(); + //AttributePoint2DArrayPtr aPointArray = std::dynamic_pointer_cast( + // aData->attribute(SketchPlugin_BSpline::POLES_ID())); + AttributeDoubleArrayPtr aWeightsArray = aData->realArray(SketchPlugin_BSpline::WEIGHTS_ID()); + + //aPointArray->setSize((int)myPoles.size()); + //aWeightsArray->setSize((int)myPoles.size()); + + std::list::const_iterator anIt = myPoles.begin(); + for (int anIndex = 0; anIt != myPoles.end(); ++anIndex, ++anIt) { + //aPointArray->setPnt(anIndex, anIt->myX->value(), anIt->myY->value()); + aWeightsArray->setValue(anIndex, anIt->myWeight->value()); + } +} + +bool PartSet_BSplineWidget::storeValueCustom() +{ + std::shared_ptr aData = myFeature->data(); + if (!aData || !aData->isValid()) // can be on abort of sketcher element + return false; + + //AttributePoint2DArrayPtr aPoles = std::dynamic_pointer_cast( + // aData->attribute(SketchPlugin_BSpline::POLES_ID())); + AttributeDoubleArrayPtr aWeights = aData->realArray(SketchPlugin_BSpline::WEIGHTS_ID()); + + bool isBlocked = blockSignals(true); + //bool isImmutable = aPoles->setImmutable(true); + + storePolesAndWeights(); + ModuleBase_Tools::flushUpdated(myFeature); + + //aPoles->setImmutable(isImmutable); + blockSignals(isBlocked); + + updateObject(myFeature); + return true; +} + +bool PartSet_BSplineWidget::restoreValueCustom() +{ + if (!myFeature) + return false; + + DataPtr aData = myFeature->data(); + + AttributePoint2DArrayPtr aPoles = std::dynamic_pointer_cast( + aData->attribute(SketchPlugin_BSpline::POLES_ID())); + AttributeDoubleArrayPtr aWeights = aData->realArray(SketchPlugin_BSpline::WEIGHTS_ID()); + + while (myPoles.size() < aPoles->size()) + addPoleWidget(); + + std::list::iterator anIt = myPoles.begin(); + for (int anIndex = 0; anIt != myPoles.end(); ++anIt, ++anIndex) { + GeomPnt2dPtr aPoint = aPoles->pnt(anIndex); + anIt->myX->setValue(aPoint->x()); + anIt->myY->setValue(aPoint->y()); + bool isBlocked = anIt->myWeight->blockSignals(true); + anIt->myWeight->setValue(aWeights->value(anIndex)); + anIt->myWeight->blockSignals(isBlocked); + } + + return true; +} + +void PartSet_BSplineWidget::addPoleWidget() +{ + QGridLayout* aGroupLay = dynamic_cast(myPolesGroupBox->layout()); + ModuleBase_Tools::adjustMargins(aGroupLay); + + int aNbPoles = (int)myPoles.size(); + + QString aPoleStr = tr("Pole %1"); + aPoleStr = aPoleStr.arg(aNbPoles + 1); + + QGroupBox* aPoleGroupBox = new QGroupBox(aPoleStr, myPolesGroupBox); + QFormLayout* aPoleLay = new QFormLayout(aPoleGroupBox); + ModuleBase_Tools::adjustMargins(aPoleLay); + aPoleLay->setSpacing(2); + + myPoles.push_back(BSplinePoleWidgets()); + BSplinePoleWidgets& aPoleWidgets = myPoles.back(); + + aPoleWidgets.myX = new ModuleBase_LabelValue(aPoleGroupBox, tr("X")); + aPoleLay->addRow(aPoleWidgets.myX); + aPoleWidgets.myY = new ModuleBase_LabelValue(aPoleGroupBox, tr("Y")); + aPoleLay->addRow(aPoleWidgets.myY); + aPoleWidgets.myWeight = new ModuleBase_ParamSpinBox(aPoleGroupBox); + aPoleWidgets.myWeight->setMinimum(0.0); + aPoleLay->addRow(tr("Weight") + " : ", aPoleWidgets.myWeight); + + aGroupLay->addWidget(aPoleGroupBox, aNbPoles, 1); + + // we should listen textChanged signal as valueChanged do not send when text is modified + connect(aPoleWidgets.myWeight, SIGNAL(textChanged(const QString&)), + this, SIGNAL(valuesChanged())); +} diff --git a/src/PartSet/PartSet_BSplineWidget.h b/src/PartSet/PartSet_BSplineWidget.h new file mode 100644 index 000000000..29a5fea88 --- /dev/null +++ b/src/PartSet/PartSet_BSplineWidget.h @@ -0,0 +1,89 @@ +// Copyright (C) 2019-2020 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef PartSet_BSplineWidget_H +#define PartSet_BSplineWidget_H + + +#include + +#include + +#include +#include +#include + +class QGroupBox; + + +/** \brief Represent a content of the property panel to show/modify parameters of B-spline curve. + * \ingroup GUI + */ +class PartSet_BSplineWidget : public ModuleBase_ModelWidget +{ +Q_OBJECT +public: + /// Constructor + /// \param theParent the parent object + /// \param theData the widget configuation. The attribute of the model widget is obtained from + PartSet_BSplineWidget(QWidget* theParent, + const Config_WidgetAPI* theData); + + virtual ~PartSet_BSplineWidget() {} + + /// The methiod called when widget is deactivated + virtual void deactivate(); + + /// Returns list of widget controls + /// \return a control list + virtual QList getControls() const; + + /// Set feature which is processing by active operation + /// \param theFeature a feature object + /// \param theToStoreValue a value about necessity to store the widget value to the feature + /// \param isUpdateFlushed a flag if update should be flushed on store value + virtual void setFeature(const FeaturePtr& theFeature, const bool theToStoreValue = false, + const bool isUpdateFlushed = true); + +protected: + /// Saves the internal parameters to the given feature + /// \return True in success + virtual bool storeValueCustom(); + + /// Restore value from attribute data to the widget's control + virtual bool restoreValueCustom(); + + /// Create group of widgets related to coordinates of pole and its weight + void addPoleWidget(); + + /// Update attributes of B-spline feature + void storePolesAndWeights() const; + +private: + struct BSplinePoleWidgets { + ModuleBase_LabelValue* myX; + ModuleBase_LabelValue* myY; + ModuleBase_ParamSpinBox* myWeight; + }; + + QGroupBox* myPolesGroupBox; ///< widget to show poles and weights of B-spline curve + std::list myPoles; ///< list of B-spline poles and their weights +}; + +#endif \ No newline at end of file diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 26a02f0d9..24070e7a7 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -40,6 +40,7 @@ #include "PartSet_OverconstraintListener.h" #include "PartSet_TreeNodes.h" #include "PartSet_FieldStepPrs.h" +#include "PartSet_BSplineWidget.h" #include "PartSet_Filters.h" #include "PartSet_FilterInfinite.h" @@ -928,10 +929,15 @@ ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& th aWgt = new PartSet_WidgetFileSelector(theParent, aWorkshop, theWidgetApi); } else if (theType == "sketch_launcher") { aWgt = new PartSet_WidgetSketchCreator(theParent, this, theWidgetApi); - } else if (theType == "module_choice") { + } + else if (theType == "module_choice") { aWgt = new ModuleBase_WidgetChoice(theParent, theWidgetApi); connect(aWgt, SIGNAL(itemSelected(ModuleBase_ModelWidget*, int)), - this, SLOT(onChoiceChanged(ModuleBase_ModelWidget*, int))); + this, SLOT(onChoiceChanged(ModuleBase_ModelWidget*, int))); + } else if (theType == "bspline-panel") { + PartSet_BSplineWidget* aPanel = new PartSet_BSplineWidget(theParent, theWidgetApi); + //aPanel->setFeature(theFeature); + aWgt = aPanel; } return aWgt; } diff --git a/src/PartSet/PartSet_WidgetBSplinePoints.cpp b/src/PartSet/PartSet_WidgetBSplinePoints.cpp index 2cc9ee1ff..6a18e7e5b 100644 --- a/src/PartSet/PartSet_WidgetBSplinePoints.cpp +++ b/src/PartSet/PartSet_WidgetBSplinePoints.cpp @@ -52,12 +52,14 @@ #include #include +#include -#include +#include #include #include #include +#include static const double MaxCoordinate = 1e12; @@ -103,7 +105,7 @@ void PartSet_WidgetBSplinePoints::createNextPoint() storeCurentValue(); QGridLayout* aGroupLay = dynamic_cast(myGroupBox->layout()); - int row = (int)(myXSpin.size() + myWeightSpin.size()); + int row = (int)myXSpin.size(); QString aPoleStr = tr("Pole %1"); aPoleStr = aPoleStr.arg(myXSpin.size() + 1); @@ -121,18 +123,12 @@ void PartSet_WidgetBSplinePoints::createNextPoint() aGroupLay->addWidget(aPoleGroupBox, row, 1); - QString aWeightStr = tr("Weight %1"); - aWeightStr = aWeightStr.arg(myWeightSpin.size() + 1); - - myWeightSpin.push_back(new ModuleBase_LabelValue(myGroupBox, aWeightStr)); - aGroupLay->addWidget(myWeightSpin.back(), ++row, 1); + setHighlighted(true); } void PartSet_WidgetBSplinePoints::removeLastPoint() { QGridLayout* aGroupLay = dynamic_cast(myGroupBox->layout()); - aGroupLay->removeWidget(myWeightSpin.back()); - myWeightSpin.pop_back(); aGroupLay->removeWidget(myYSpin.back()); aGroupLay->removeWidget(myXSpin.back()); aGroupLay->removeWidget(myXSpin.back()->parentWidget()); @@ -246,7 +242,6 @@ bool PartSet_WidgetBSplinePoints::resetCustom() // locking of the validating state. fillLabels(myXSpin, 0.0); fillLabels(myYSpin, 0.0); - fillLabels(myWeightSpin, 1.0); storeValueCustom(); aDone = true; @@ -267,7 +262,6 @@ bool PartSet_WidgetBSplinePoints::setPoint(double theX, double theY) myXSpin.back()->setValue(theX); myYSpin.back()->setValue(theY); - myWeightSpin.back()->setValue(1.0); storeValue(); return true; @@ -280,17 +274,18 @@ void PartSet_WidgetBSplinePoints::storePolesAndWeights() const aData->attribute(attributeID())); AttributeDoubleArrayPtr aWeightsArray = aData->realArray(myWeightsAttr); - aPointArray->setSize((int)myXSpin.size()); - aWeightsArray->setSize((int)myWeightSpin.size()); + int aSize = (int)myXSpin.size(); + aPointArray->setSize(aSize); + aWeightsArray->setSize(aSize); std::vector::const_iterator aXIt = myXSpin.begin(); std::vector::const_iterator aYIt = myYSpin.begin(); for (int anIndex = 0; aXIt != myXSpin.end() && aYIt != myYSpin.end(); ++anIndex, ++aXIt, ++aYIt) aPointArray->setPnt(anIndex, (*aXIt)->value(), (*aYIt)->value()); - std::vector::const_iterator aWIt = myWeightSpin.begin(); - for (int anIndex = 0; aWIt != myWeightSpin.end(); ++anIndex, ++aWIt) - aWeightsArray->setValue(anIndex, (*aWIt)->value()); + double aWeight = Config_PropManager::real(SKETCH_TAB_NAME, "spline_weight"); + for (int anIndex = 0; anIndex < aSize; ++anIndex) + aWeightsArray->setValue(anIndex, aWeight); } bool PartSet_WidgetBSplinePoints::storeValueCustom() @@ -349,10 +344,6 @@ bool PartSet_WidgetBSplinePoints::restoreValueCustom() (*aXIt)->setValue(aPoint->x()); (*aYIt)->setValue(aPoint->y()); } - - std::vector::iterator aWIt = myWeightSpin.begin(); - for (int anIndex = 0; aWIt != myWeightSpin.end(); ++anIndex, ++aWIt) - (*aWIt)->setValue(aWeightsArray->value(anIndex)); } else { if (myXSpin.empty()) @@ -360,7 +351,6 @@ bool PartSet_WidgetBSplinePoints::restoreValueCustom() myXSpin.back()->setValue(0.0); myYSpin.back()->setValue(0.0); - myWeightSpin.back()->setValue(0.0); } return true; @@ -384,7 +374,6 @@ void PartSet_WidgetBSplinePoints::storeCurentValue() storeArray(myXSpin, myXValueInCash); storeArray(myYSpin, myYValueInCash); - storeArray(myWeightSpin, myWeightInCash); } static void restoreArray(std::vector& theCacheValues, @@ -412,7 +401,6 @@ bool PartSet_WidgetBSplinePoints::restoreCurentValue() // fill the control widgets by the cashed value restoreArray(myXValueInCash, myXSpin); restoreArray(myYValueInCash, myYSpin); - restoreArray(myWeightInCash, myWeightSpin); // store value to the model storeValueCustom(); @@ -431,13 +419,20 @@ QList PartSet_WidgetBSplinePoints::getControls() const QList aControls; std::vector::const_iterator aXIt = myXSpin.begin(); std::vector::const_iterator aYIt = myYSpin.begin(); - std::vector::const_iterator aWIt = myWeightSpin.begin(); - for (; aXIt != myXSpin.end() && aYIt != myYSpin.end() && aWIt != myWeightSpin.end(); - ++aXIt, ++aYIt, ++aWIt) { - aControls.append(*aXIt); - aControls.append(*aYIt); - aControls.append(*aWIt); + for (; (*aXIt) != myXSpin.back() && (*aYIt) != myYSpin.back(); ++aXIt, ++aYIt) { + //aControls.append(*aXIt); + //aControls.append(*aYIt); + QGraphicsEffect* anEffect = (*aXIt)->graphicsEffect(); + if (anEffect) + anEffect->deleteLater(); + anEffect = (*aYIt)->graphicsEffect(); + if (anEffect) + anEffect->deleteLater(); + (*aXIt)->setGraphicsEffect(0); + (*aYIt)->setGraphicsEffect(0); } + aControls.append(myXSpin.back()); + aControls.append(myYSpin.back()); return aControls; } diff --git a/src/PartSet/PartSet_WidgetBSplinePoints.h b/src/PartSet/PartSet_WidgetBSplinePoints.h index f537dc866..360af3580 100644 --- a/src/PartSet/PartSet_WidgetBSplinePoints.h +++ b/src/PartSet/PartSet_WidgetBSplinePoints.h @@ -161,7 +161,6 @@ private: QGroupBox* myGroupBox; ///< the parent group box for all intenal widgets std::vector myXSpin; ///< the label for the X coordinate std::vector myYSpin; ///< the label for the Y coordinate - std::vector myWeightSpin; ///< the label for the weight PartSet_ExternalObjectsMgr* myExternalObjectMgr; ///< reference to external objects manager /// value used as selection in mouse release method diff --git a/src/SketchPlugin/CMakeLists.txt b/src/SketchPlugin/CMakeLists.txt index e2ad2a043..d3fbe20bf 100644 --- a/src/SketchPlugin/CMakeLists.txt +++ b/src/SketchPlugin/CMakeLists.txt @@ -24,7 +24,6 @@ SET(PROJECT_HEADERS SketchPlugin.h SketchPlugin_Arc.h SketchPlugin_BSpline.h - SketchPlugin_BSplineWidget.h SketchPlugin_Circle.h SketchPlugin_Constraint.h SketchPlugin_ConstraintAngle.h @@ -72,17 +71,11 @@ SET(PROJECT_HEADERS SketchPlugin_Tools.h SketchPlugin_Trim.h SketchPlugin_Validators.h - SketchPlugin_WidgetCreator.h -) - -SET(PROJECT_MOC_HEADERS - SketchPlugin_BSplineWidget.h ) SET(PROJECT_SOURCES SketchPlugin_Arc.cpp SketchPlugin_BSpline.cpp - SketchPlugin_BSplineWidget.cpp SketchPlugin_Circle.cpp SketchPlugin_Constraint.cpp SketchPlugin_ConstraintAngle.cpp @@ -128,7 +121,6 @@ SET(PROJECT_SOURCES SketchPlugin_Tools.cpp SketchPlugin_Trim.cpp SketchPlugin_Validators.cpp - SketchPlugin_WidgetCreator.cpp ) SET(PROJECT_LIBRARIES diff --git a/src/SketchPlugin/SketchPlugin_BSplineWidget.cpp b/src/SketchPlugin/SketchPlugin_BSplineWidget.cpp deleted file mode 100644 index 259891a12..000000000 --- a/src/SketchPlugin/SketchPlugin_BSplineWidget.cpp +++ /dev/null @@ -1,177 +0,0 @@ -// Copyright (C) 2019-2020 CEA/DEN, EDF R&D -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#include - -#include - -#include - -#include - -#include - -#include - -#include -#include -#include -#include - - -SketchPlugin_BSplineWidget::SketchPlugin_BSplineWidget( - QWidget* theParent, - const Config_WidgetAPI* theData) - : ModuleBase_ModelWidget(theParent, theData) -{ - QVBoxLayout* aMainLayout = new QVBoxLayout(this); - - // GroupBox to keep widgets for B-spline poles and weights - myPolesGroupBox = new QGroupBox(tr("Poles and weights"), theParent); - aMainLayout->addWidget(myPolesGroupBox); - // layout of GroupBox - QGridLayout* aGroupLayout = new QGridLayout(myPolesGroupBox); - aGroupLayout->setSpacing(4); - aGroupLayout->setColumnStretch(1, 1); - - restoreValueCustom(); -} - -void SketchPlugin_BSplineWidget::setFeature(const FeaturePtr& theFeature, - const bool theToStoreValue, - const bool isUpdateFlushed) -{ - ModuleBase_ModelWidget::setFeature(theFeature, theToStoreValue, isUpdateFlushed); - restoreValueCustom(); -} - -void SketchPlugin_BSplineWidget::deactivate() -{ - ModuleBase_ModelWidget::deactivate(); - storeValueCustom(); -} - - -QList SketchPlugin_BSplineWidget::getControls() const -{ - QList aControls; - std::list::const_iterator anIt = myPoles.begin(); - for (; anIt != myPoles.end(); ++anIt) { - aControls.append(anIt->myX); - aControls.append(anIt->myY); - aControls.append(anIt->myWeight); - } - return aControls; -} - -void SketchPlugin_BSplineWidget::storePolesAndWeights() const -{ - std::shared_ptr aData = myFeature->data(); - AttributePoint2DArrayPtr aPointArray = std::dynamic_pointer_cast( - aData->attribute(SketchPlugin_BSpline::POLES_ID())); - AttributeDoubleArrayPtr aWeightsArray = aData->realArray(SketchPlugin_BSpline::WEIGHTS_ID()); - - aPointArray->setSize((int)myPoles.size()); - aWeightsArray->setSize((int)myPoles.size()); - - std::list::const_iterator anIt = myPoles.begin(); - for (int anIndex = 0; anIt != myPoles.end(); ++anIndex, ++anIt) { - aPointArray->setPnt(anIndex, anIt->myX->value(), anIt->myY->value()); - aWeightsArray->setValue(anIndex, anIt->myWeight->value()); - } -} - -bool SketchPlugin_BSplineWidget::storeValueCustom() -{ - std::shared_ptr aData = myFeature->data(); - if (!aData || !aData->isValid()) // can be on abort of sketcher element - return false; - - AttributePoint2DArrayPtr aPoles = std::dynamic_pointer_cast( - aData->attribute(SketchPlugin_BSpline::POLES_ID())); - AttributeDoubleArrayPtr aWeights = aData->realArray(SketchPlugin_BSpline::WEIGHTS_ID()); - - bool isBlocked = blockSignals(true); - bool isImmutable = aPoles->setImmutable(true); - - storePolesAndWeights(); - ModuleBase_Tools::flushUpdated(myFeature); - - aPoles->setImmutable(isImmutable); - blockSignals(isBlocked); - - return true; -} - -bool SketchPlugin_BSplineWidget::restoreValueCustom() -{ - if (!myFeature) - return false; - - DataPtr aData = myFeature->data(); - - AttributePoint2DArrayPtr aPoles = std::dynamic_pointer_cast( - aData->attribute(SketchPlugin_BSpline::POLES_ID())); - AttributeDoubleArrayPtr aWeights = aData->realArray(SketchPlugin_BSpline::WEIGHTS_ID()); - - while (myPoles.size() < aPoles->size()) - addPoleWidget(); - - std::list::iterator anIt = myPoles.begin(); - for (int anIndex = 0; anIt != myPoles.end(); ++anIt, ++anIndex) { - GeomPnt2dPtr aPoint = aPoles->pnt(anIndex); - anIt->myX->setValue(aPoint->x()); - anIt->myY->setValue(aPoint->y()); - anIt->myWeight->setValue(aWeights->value(anIndex)); - } - - return true; -} - -void SketchPlugin_BSplineWidget::addPoleWidget() -{ - QGridLayout* aGroupLay = dynamic_cast(myPolesGroupBox->layout()); - - int aNbPoles = (int)myPoles.size(); - - QString aPoleStr = tr("Pole %1"); - aPoleStr = aPoleStr.arg(aNbPoles + 1); - - QGroupBox* aPoleGroupBox = new QGroupBox(aPoleStr, myPolesGroupBox); - QFormLayout* aPoleLay = new QFormLayout(aPoleGroupBox); - ModuleBase_Tools::adjustMargins(aPoleLay); - aPoleLay->setSpacing(2); - - myPoles.push_back(BSplinePoleWidgets()); - BSplinePoleWidgets& aPoleWidgets = myPoles.back(); - - aPoleWidgets.myX = new ModuleBase_LabelValue(aPoleGroupBox, tr("X")); - aPoleLay->addRow(aPoleWidgets.myX); - aPoleWidgets.myY = new ModuleBase_LabelValue(aPoleGroupBox, tr("Y")); - aPoleLay->addRow(aPoleWidgets.myY); - aPoleWidgets.myWeight = new ModuleBase_ParamSpinBox(aPoleGroupBox); - aPoleWidgets.myWeight->setMinimum(0.0); - aPoleLay->addRow(tr("Weight") + " : ", aPoleWidgets.myWeight); - - aGroupLay->addWidget(aPoleGroupBox, aNbPoles, 1); - - // we should listen textChanged signal as valueChanged do not send when text is modified - connect(aPoleWidgets.myWeight, SIGNAL(textChanged(const QString&)), - this, SIGNAL(valuesModified())); -} diff --git a/src/SketchPlugin/SketchPlugin_BSplineWidget.h b/src/SketchPlugin/SketchPlugin_BSplineWidget.h deleted file mode 100644 index 30fa4c6f0..000000000 --- a/src/SketchPlugin/SketchPlugin_BSplineWidget.h +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright (C) 2019-2020 CEA/DEN, EDF R&D -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#ifndef SketchPlugin_BSplineWidget_H -#define SketchPlugin_BSplineWidget_H - - -#include - -#include - -#include -#include -#include - -class QGroupBox; - - -/** \brief Represent a content of the property panel to show/modify parameters of B-spline curve. - * \ingroup GUI - */ -class SketchPlugin_BSplineWidget : public ModuleBase_ModelWidget -{ -Q_OBJECT -public: - /// Constructor - /// \param theParent the parent object - /// \param theData the widget configuation. The attribute of the model widget is obtained from - SketchPlugin_BSplineWidget(QWidget* theParent, - const Config_WidgetAPI* theData); - - virtual ~SketchPlugin_BSplineWidget() {} - - /// The methiod called when widget is deactivated - virtual void deactivate(); - - /// Returns list of widget controls - /// \return a control list - virtual QList getControls() const; - - /// Set feature which is processing by active operation - /// \param theFeature a feature object - /// \param theToStoreValue a value about necessity to store the widget value to the feature - /// \param isUpdateFlushed a flag if update should be flushed on store value - virtual void setFeature(const FeaturePtr& theFeature, const bool theToStoreValue = false, - const bool isUpdateFlushed = true); - -protected: - /// Saves the internal parameters to the given feature - /// \return True in success - virtual bool storeValueCustom(); - - /// Restore value from attribute data to the widget's control - virtual bool restoreValueCustom(); - - /// Create group of widgets related to coordinates of pole and its weight - void addPoleWidget(); - - /// Update attributes of B-spline feature - void storePolesAndWeights() const; - -private: - struct BSplinePoleWidgets { - ModuleBase_LabelValue* myX; - ModuleBase_LabelValue* myY; - ModuleBase_ParamSpinBox* myWeight; - }; - - QGroupBox* myPolesGroupBox; ///< widget to show poles and weights of B-spline curve - std::list myPoles; ///< list of B-spline poles and their weights -}; - -#endif \ No newline at end of file diff --git a/src/SketchPlugin/SketchPlugin_Plugin.cpp b/src/SketchPlugin/SketchPlugin_Plugin.cpp index b48e6cfef..a6ef2a190 100644 --- a/src/SketchPlugin/SketchPlugin_Plugin.cpp +++ b/src/SketchPlugin/SketchPlugin_Plugin.cpp @@ -59,7 +59,6 @@ #include #include #include -#include #include @@ -71,8 +70,6 @@ #include #include -#include - #include #include @@ -95,10 +92,6 @@ static SketchPlugin_Plugin* MY_SKETCH_INSTANCE = new SketchPlugin_Plugin(); SketchPlugin_Plugin::SketchPlugin_Plugin() { - WidgetCreatorFactoryPtr aWidgetCreatorFactory = ModuleBase_WidgetCreatorFactory::get(); - aWidgetCreatorFactory->registerCreator( - std::shared_ptr(new SketchPlugin_WidgetCreator())); - SessionPtr aMgr = ModelAPI_Session::get(); ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); aFactory->registerValidator("SketchPlugin_DistanceAttr", diff --git a/src/SketchPlugin/SketchPlugin_WidgetCreator.cpp b/src/SketchPlugin/SketchPlugin_WidgetCreator.cpp deleted file mode 100644 index 37da438b9..000000000 --- a/src/SketchPlugin/SketchPlugin_WidgetCreator.cpp +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (C) 2019-2020 CEA/DEN, EDF R&D -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#include -#include - - -SketchPlugin_WidgetCreator::SketchPlugin_WidgetCreator() - : ModuleBase_IWidgetCreator() -{ - myPanelTypes.insert("bspline-panel"); -} - -void SketchPlugin_WidgetCreator::panelTypes(std::set& theTypes) -{ - theTypes = myPanelTypes; -} - -QWidget* SketchPlugin_WidgetCreator::createPanelByType( - const std::string& theType, - QWidget* theParent, - const FeaturePtr& theFeature, - Config_WidgetAPI* theWidgetApi) -{ - QWidget* aWidget = 0; - if (theType == "bspline-panel") { - SketchPlugin_BSplineWidget* aPanel = new SketchPlugin_BSplineWidget(theParent, theWidgetApi); - aPanel->setFeature(theFeature); - aWidget = aPanel; - } - return aWidget; -} diff --git a/src/SketchPlugin/SketchPlugin_WidgetCreator.h b/src/SketchPlugin/SketchPlugin_WidgetCreator.h deleted file mode 100644 index 9b1a9bac1..000000000 --- a/src/SketchPlugin/SketchPlugin_WidgetCreator.h +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (C) 2019-2020 CEA/DEN, EDF R&D -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#ifndef SketchPlugin_WidgetCreator_H -#define SketchPlugin_WidgetCreator_H - - -#include -#include - -#include -#include - -class QWidget; - -/** - * \ingroup GUI - * Interface to WidgetCreator which can create specific widgets by type - */ -class SketchPlugin_WidgetCreator : public ModuleBase_IWidgetCreator -{ -public: - /// Default constructor - SketchPlugin_WidgetCreator(); - - /// Virtual destructor - virtual ~SketchPlugin_WidgetCreator() {} - - /// Returns a container of possible page types, which this creator can process - /// \param theTypes a list of type names - virtual void panelTypes(std::set& theTypes); - - /// Create panel control by its type. - /// The default implementation is empty - /// \param theType a panel type - /// \param theParent a parent widget - /// \param theFeature a feature modified in the panel - /// \return created widget or null - virtual QWidget* createPanelByType(const std::string& theType, - QWidget* theParent, - const FeaturePtr& theFeature, - Config_WidgetAPI* theWidgetApi); -private: - std::set myPanelTypes; ///< types of panels -}; - -#endif \ No newline at end of file diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 241c30de0..368f3d602 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -602,14 +602,9 @@ - -