Salome HOME
Task #2997: Show objects with DoF
[modules/shaper.git] / src / PartSet / PartSet_WidgetSketchLabel.cpp
index 960429f713e9fc098117195161d2d9c49fcc738a..1f969d0ebd6ccb0ae0ba447d60fe17ea7d4d2353 100644 (file)
@@ -37,6 +37,8 @@
 
 #include <ModelAPI_ResultBody.h>
 #include <ModelAPI_Tools.h>
+#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_Events.h>
 
 #include <ModuleBase_Operation.h>
 #include <ModuleBase_ViewerPrs.h>
@@ -173,6 +175,7 @@ myIsSelection(false)
   aLayout->addWidget(myShowPoints);
 
   myAutoConstraints = new QCheckBox(tr("Automatic constraints"), this);
+  myAutoConstraints->setToolTip(tr("Automatic vertical and horizontal constraints"));
   connect(myAutoConstraints, SIGNAL(toggled(bool)), this, SIGNAL(autoConstraints(bool)));
   aLayout->addWidget(myAutoConstraints);
 
@@ -180,6 +183,16 @@ myIsSelection(false)
   connect(aPlaneBtn, SIGNAL(clicked(bool)), SLOT(onChangePlane()));
   aLayout->addWidget(aPlaneBtn);
 
+  aLayout->addSpacing(15);
+
+  myDoFLabel = new QLabel("", aSecondWgt);
+  aLayout->addWidget(myDoFLabel);
+
+  myShowDOFBtn = new QPushButton(tr("Show remaining DoFs"), aSecondWgt);
+  aLayout->addWidget(myShowDOFBtn);
+  myShowDOFBtn->hide();
+  connect(myShowDOFBtn, SIGNAL(clicked(bool)), SLOT(onShowDOF()));
+
   myStackWidget->addWidget(aSecondWgt);
   //setLayout(aLayout);
 
@@ -730,3 +743,46 @@ void PartSet_WidgetSketchLabel::setShowPointsState(bool theState)
   myShowPoints->setChecked(theState);
   myShowPoints->blockSignals(aBlock);
 }
+
+bool PartSet_WidgetSketchLabel::restoreValueCustom()
+{
+  if (myFeature.get()) {
+    CompositeFeaturePtr aSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
+    if (aSketch.get() && (aSketch->numberOfSubs() > 0)) {
+      AttributeStringPtr aDOFStr = aSketch->string("SolverDOF");
+      if (aDOFStr.get()) {
+        QString aVal(aDOFStr->value().c_str());
+        if (aVal.contains('=')) {
+          // to support old data
+          aVal = aVal.right(aVal.length() - aVal.lastIndexOf('='));
+        }
+        int aDoF = aVal.toInt();
+        if (aDoF == 0) {
+          myDoFLabel->setText(tr("Sketch is fully fixed (DoF = 0)"));
+          myShowDOFBtn->hide();
+        } else {
+          myDoFLabel->setText(tr("DoF (degrees of freedom) = ") + aVal);
+          CompositeFeaturePtr aCompFeature = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
+          if (aCompFeature.get() && aCompFeature->numberOfSubs() > 1)
+            myShowDOFBtn->show();
+        }
+      }
+    }
+    else {
+      myDoFLabel->setText("");
+      myShowDOFBtn->hide();
+    }
+  }
+  return true;
+}
+
+
+void PartSet_WidgetSketchLabel::onShowDOF()
+{
+  CompositeFeaturePtr aCompFeature = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
+  if (aCompFeature.get() && aCompFeature->numberOfSubs() > 1) {
+    static const Events_ID anEvent = Events_Loop::eventByName(EVENT_GET_DOF_OBJECTS);
+    ModelAPI_EventCreator::get()->sendUpdated(aCompFeature->subFeature(0), anEvent);
+    Events_Loop::loop()->flush(anEvent);
+  }
+}