Salome HOME
Updated copyright comment
[modules/shaper.git] / src / PartSet / PartSet_WidgetBSplinePoints.cpp
index 2cc9ee1ff91cace5a5c519f96b487e52cff244df..fe01d920f3e367f8e573ca158a407837f4a8c412 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2019-2020  CEA/DEN, EDF R&D
+// Copyright (C) 2019-2024  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 #include <GeomDataAPI_Point2DArray.h>
 
 #include <GeomAPI_Pnt2d.h>
+#include <GeomAPI_IPresentable.h>
 
-#include <SketchPlugin_ConstraintCoincidence.h>
+#include <SketchPlugin_Feature.h>
 
 #include <QGridLayout>
 #include <QGroupBox>
 #include <QMouseEvent>
+#include <QGraphicsEffect>
+#include <QScrollArea>
 
 static const double MaxCoordinate = 1e12;
 
+static bool IsPointCreated = false;
+
+
 PartSet_WidgetBSplinePoints::PartSet_WidgetBSplinePoints(QWidget* theParent,
                                              ModuleBase_IWorkshop* theWorkshop,
                                              const Config_WidgetAPI* theData)
@@ -70,28 +76,48 @@ PartSet_WidgetBSplinePoints::PartSet_WidgetBSplinePoints(QWidget* theParent,
   myPointIndex(0), myFinished(false)
 {
   myRefAttribute = theData->getProperty("reference_attribute");
+  QVBoxLayout* aMainLayout = new QVBoxLayout(this);
+  ModuleBase_Tools::zeroMargins(aMainLayout);
 
   // the control should accept the focus, so the boolean flag is corrected to be true
   myIsObligatory = true;
   QString aPageName = translate(theData->getProperty(CONTAINER_PAGE_NAME));
-  myGroupBox = new QGroupBox(aPageName, theParent);
-  myGroupBox->setFlat(false);
+  myBox = new QGroupBox(aPageName, theParent);
+  myBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+  myBox->setFlat(false);
+  aMainLayout->addWidget(myBox);
 
-  bool aAcceptVariables = theData->getBooleanAttribute(DOUBLE_WDG_ACCEPT_EXPRESSIONS, true);
+#ifdef _DEBUG
+  bool aAcceptVariables =
+#endif
+    theData->getBooleanAttribute(DOUBLE_WDG_ACCEPT_EXPRESSIONS, true);
 
   // B-spline weights attribute
   myWeightsAttr = theData->getProperty("weights");
 
+  QVBoxLayout* aLayout = new QVBoxLayout(myBox);
+  ModuleBase_Tools::adjustMargins(aLayout);
+
+  myScrollArea = new QScrollArea(myBox);
+  myScrollArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+  myScrollArea->setWidgetResizable(true);
+  myScrollArea->setFrameStyle(QFrame::NoFrame);
+  aLayout->addWidget(myScrollArea);
+
+  QWidget* aContainer = new QWidget(myScrollArea);
+  QVBoxLayout* aBoxLay = new QVBoxLayout(aContainer);
+  aBoxLay->setContentsMargins(0, 0, 0, 0);
+
+  myGroupBox = new QWidget(aContainer);
   QGridLayout* aGroupLay = new QGridLayout(myGroupBox);
   ModuleBase_Tools::adjustMargins(aGroupLay);
   aGroupLay->setSpacing(4);
   aGroupLay->setColumnStretch(1, 1);
   createNextPoint();
+  aBoxLay->addWidget(myGroupBox);
+  aBoxLay->addStretch(1);
 
-  QVBoxLayout* aLayout = new QVBoxLayout(this);
-  ModuleBase_Tools::zeroMargins(aLayout);
-  aLayout->addWidget(myGroupBox);
-  setLayout(aLayout);
+  myScrollArea->setWidget(aContainer);
 
   myWidgetValidator = new ModuleBase_WidgetValidator(this, myWorkshop);
   myExternalObjectMgr = new PartSet_ExternalObjectsMgr(theData->getProperty("use_external"),
@@ -103,9 +129,9 @@ void PartSet_WidgetBSplinePoints::createNextPoint()
   storeCurentValue();
 
   QGridLayout* aGroupLay = dynamic_cast<QGridLayout*>(myGroupBox->layout());
-  int row = (int)(myXSpin.size() + myWeightSpin.size());
+  int row = (int)myXSpin.size();
 
-  QString aPoleStr = tr("Pole %1");
+  QString aPoleStr = translate("Pole %1");
   aPoleStr = aPoleStr.arg(myXSpin.size() + 1);
 
   QGroupBox* aPoleGroupBox = new QGroupBox(aPoleStr, myGroupBox);
@@ -120,33 +146,30 @@ void PartSet_WidgetBSplinePoints::createNextPoint()
   aPoleLay->addWidget(myYSpin.back(), 1, 1);
 
   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);
+  IsPointCreated = true;
 }
 
 void PartSet_WidgetBSplinePoints::removeLastPoint()
 {
   QGridLayout* aGroupLay = dynamic_cast<QGridLayout*>(myGroupBox->layout());
-  aGroupLay->removeWidget(myWeightSpin.back());
-  myWeightSpin.pop_back();
-  aGroupLay->removeWidget(myYSpin.back());
-  aGroupLay->removeWidget(myXSpin.back());
-  aGroupLay->removeWidget(myXSpin.back()->parentWidget());
+  QWidget* aXSpin = myXSpin.back();
+  QWidget* aYSpin = myYSpin.back();
+  QWidget* aBox = myXSpin.back()->parentWidget();
   myYSpin.pop_back();
   myXSpin.pop_back();
 
+  aGroupLay->removeWidget(aXSpin);
+  aGroupLay->removeWidget(aYSpin);
+  aGroupLay->removeWidget(aBox);
+
+  aBox->deleteLater();
+
   // update B-spline feature attributes
   storeValueCustom();
 }
 
 bool PartSet_WidgetBSplinePoints::isValidSelectionCustom(const ModuleBase_ViewerPrsPtr& theValue)
 {
-  bool aValid = true;
-
   PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
   if (aModule->sketchReentranceMgr()->isInternalEditActive())
     return true; // when internal edit is started a new feature is created. I has not results, AIS
@@ -246,7 +269,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 +289,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 +301,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<ModuleBase_LabelValue*>::const_iterator aXIt = myXSpin.begin();
   std::vector<ModuleBase_LabelValue*>::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<ModuleBase_LabelValue*>::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()
@@ -338,7 +360,7 @@ bool PartSet_WidgetBSplinePoints::restoreValueCustom()
   AttributeDoubleArrayPtr aWeightsArray = aData->realArray(myWeightsAttr);
 
   if (aPointArray->isInitialized()) {
-    while (myXSpin.size() < aPointArray->size())
+    while ((int)myXSpin.size() < aPointArray->size())
       createNextPoint();
 
     std::vector<ModuleBase_LabelValue*>::iterator aXIt = myXSpin.begin();
@@ -349,10 +371,6 @@ bool PartSet_WidgetBSplinePoints::restoreValueCustom()
       (*aXIt)->setValue(aPoint->x());
       (*aYIt)->setValue(aPoint->y());
     }
-
-    std::vector<ModuleBase_LabelValue*>::iterator aWIt = myWeightSpin.begin();
-    for (int anIndex = 0; aWIt != myWeightSpin.end(); ++anIndex, ++aWIt)
-      (*aWIt)->setValue(aWeightsArray->value(anIndex));
   }
   else {
     if (myXSpin.empty())
@@ -360,7 +378,6 @@ bool PartSet_WidgetBSplinePoints::restoreValueCustom()
 
     myXSpin.back()->setValue(0.0);
     myYSpin.back()->setValue(0.0);
-    myWeightSpin.back()->setValue(0.0);
   }
 
   return true;
@@ -384,7 +401,6 @@ void PartSet_WidgetBSplinePoints::storeCurentValue()
 
   storeArray(myXSpin, myXValueInCash);
   storeArray(myYSpin, myYValueInCash);
-  storeArray(myWeightSpin, myWeightInCash);
 }
 
 static void restoreArray(std::vector<double>& theCacheValues,
@@ -412,7 +428,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();
@@ -429,15 +444,7 @@ bool PartSet_WidgetBSplinePoints::restoreCurentValue()
 QList<QWidget*> PartSet_WidgetBSplinePoints::getControls() const
 {
   QList<QWidget*> aControls;
-  std::vector<ModuleBase_LabelValue*>::const_iterator aXIt = myXSpin.begin();
-  std::vector<ModuleBase_LabelValue*>::const_iterator aYIt = myYSpin.begin();
-  std::vector<ModuleBase_LabelValue*>::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);
-  }
+  aControls.append(myScrollArea);
   return aControls;
 }
 
@@ -527,11 +534,7 @@ void PartSet_WidgetBSplinePoints::mouseReleased(ModuleBase_IViewWindow* theWindo
   }
 
   GeomPnt2dPtr aSelectedPoint = PartSet_Tools::getPnt2d(aView, aSelectedShape, mySketch);
-  if (aSelectedPoint) {
-    // nullify selected object to add reference to attribute instead of its owner
-    aSelectedObject = ObjectPtr();
-  }
-  else {
+  if (!aSelectedPoint) {
     aSelectedPoint = PartSet_Tools::getPnt2d(theEvent, theWindow, mySketch);
     setValueState(Stored); // in case of edge selection, Apply state should also be updated
   }
@@ -563,6 +566,12 @@ void PartSet_WidgetBSplinePoints::mouseMoved(ModuleBase_IViewWindow* theWindow,
   setPoint(aX, aY);
   blockValueState(isBlocked);
   setValueState(ModifiedInViewer);
+
+  if (IsPointCreated) {
+    QPoint aPnt = myGroupBox->geometry().bottomLeft();
+    myScrollArea->ensureVisible(aPnt.x(), aPnt.y());
+    IsPointCreated = false;
+  }
 }
 
 bool PartSet_WidgetBSplinePoints::processEscape()