]> SALOME platform Git repositories - modules/shaper.git/blobdiff - src/XGUI/XGUI_Workshop.cpp
Salome HOME
Issue #3140: Modify Iso-lines of a shape presentation
[modules/shaper.git] / src / XGUI / XGUI_Workshop.cpp
index c1598b82984a957edf34ca9ffef6a2e70d6b2562..799f5c00f172d71a5e96d06d435cd5b7b6381204 100644 (file)
 #include <QDesktopWidget>
 #include <QProcess>
 #include <QDesktopServices>
+#include <QFormLayout>
+#include <QSpinBox>
+#include <QDialogButtonBox>
 
 #include <iterator>
 
@@ -1676,6 +1679,8 @@ void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
     moveObjects(theId == "MOVE_SPLIT_CMD");
   else if (theId == "COLOR_CMD")
     changeColor(aObjects);
+  else if (theId == "ISOLINES_CMD")
+    changeIsoLines(aObjects);
   else if (theId == "DEFLECTION_CMD")
     changeDeflection(aObjects);
   else if (theId == "TRANSPARENCY_CMD")
@@ -2357,22 +2362,6 @@ bool XGUI_Workshop::canChangeProperty(const QString& theActionName) const
   return false;
 }
 
-//******************************************************
-void setColor(ResultPtr theResult, const std::vector<int>& theColor)
-{
-  if (!theResult.get())
-    return;
-
-  AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID());
-  if (aColorAttr.get() != NULL) {
-    if (!aColorAttr->size()) {
-      aColorAttr->setSize(3);
-    }
-    aColorAttr->setValue(0, theColor[0]);
-    aColorAttr->setValue(1, theColor[1]);
-    aColorAttr->setValue(2, theColor[2]);
-  }
-}
 
 //**************************************************************
 void getDefaultColor(ObjectPtr theObject, const bool isEmptyColorValid,
@@ -2455,10 +2444,10 @@ void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
         std::list<ResultPtr> allRes;
         ModelAPI_Tools::allSubs(aBodyResult, allRes);
         for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
-          setColor(*aRes, !isRandomColor ? aColorResult : aDlg->getRandomColor());
+          ModelAPI_Tools::setColor(*aRes, !isRandomColor ? aColorResult : aDlg->getRandomColor());
         }
       }
-      setColor(aResult, !isRandomColor ? aColorResult : aDlg->getRandomColor());
+      ModelAPI_Tools::setColor(aResult, !isRandomColor ? aColorResult : aDlg->getRandomColor());
     }
   }
   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
@@ -2467,30 +2456,6 @@ void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
   myViewerProxy->update();
 }
 
-//**************************************************************
-void setDeflection(ResultPtr theResult, const double theDeflection)
-{
-  if (!theResult.get())
-    return;
-
-  AttributeDoublePtr aDeflectionAttr = theResult->data()->real(ModelAPI_Result::DEFLECTION_ID());
-  if (aDeflectionAttr.get() != NULL) {
-    aDeflectionAttr->setValue(theDeflection);
-  }
-}
-
-//**************************************************************
-void setTransparency(ResultPtr theResult, double theTransparency)
-{
-  if (!theResult.get())
-    return;
-
-  AttributeDoublePtr anAttribute = theResult->data()->real(ModelAPI_Result::TRANSPARENCY_ID());
-  if (anAttribute.get() != NULL) {
-    anAttribute->setValue(theTransparency);
-  }
-}
-
 //**************************************************************
 void setTransparency(double theTransparency, const QObjectPtrList& theObjects)
 {
@@ -2503,10 +2468,10 @@ void setTransparency(double theTransparency, const QObjectPtrList& theObjects)
         ModelAPI_Tools::allSubs(aBodyResult, allRes);
         std::list<ResultPtr>::iterator aRes;
         for(aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
-          setTransparency(*aRes, theTransparency);
+          ModelAPI_Tools::setTransparency(*aRes, theTransparency);
         }
       }
-      setTransparency(aResult, theTransparency);
+      ModelAPI_Tools::setTransparency(aResult, theTransparency);
     }
   }
 }
@@ -2594,10 +2559,10 @@ void XGUI_Workshop::changeDeflection(const QObjectPtrList& theObjects)
         std::list<ResultPtr> allRes;
         ModelAPI_Tools::allSubs(aBodyResult, allRes);
         for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
-          setDeflection(*aRes, aDeflection);
+          ModelAPI_Tools::setDeflection(*aRes, aDeflection);
         }
       }
-      setDeflection(aResult, aDeflection);
+      ModelAPI_Tools::setDeflection(aResult, aDeflection);
     }
   }
   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
@@ -3197,3 +3162,62 @@ void XGUI_Workshop::deactivateCurrentSelector()
 {
   myActiveControlMgr->deactivateSelector(myActiveControlMgr->activeSelector());
 }
+
+void XGUI_Workshop::changeIsoLines(const QObjectPtrList& theObjects)
+{
+  if (theObjects.isEmpty())
+    return;
+
+  std::vector<int> aValues;
+  if (theObjects.size() == 1) {
+    ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(theObjects.first());
+    if (aRes.get())
+      ModelAPI_Tools::getIsoLines(aRes, aValues);
+    else
+      return;
+  }
+  if (aValues.size() == 0) {
+    aValues.push_back(1);
+    aValues.push_back(1);
+  }
+
+  if (!abortAllOperations())
+    return;
+
+  QDialog aDlg;
+  aDlg.setWindowTitle(tr("Number of Iso-lines"));
+  QFormLayout* aLayout = new QFormLayout(&aDlg);
+
+  QSpinBox* aUNb = new QSpinBox(&aDlg);
+  aUNb->setValue(aValues[0]);
+  aLayout->addRow("U:", aUNb);
+
+  QSpinBox* aVNb = new QSpinBox(&aDlg);
+  aVNb->setValue(aValues[1]);
+  aLayout->addRow("V:", aVNb);
+
+  QDialogButtonBox* aButtons =
+    new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, &aDlg);
+  connect(aButtons, SIGNAL(accepted()), &aDlg, SLOT(accept()));
+  connect(aButtons, SIGNAL(rejected()), &aDlg, SLOT(reject()));
+  aLayout->addRow(aButtons);
+
+  if (aDlg.exec() == QDialog::Accepted) {
+    SessionPtr aMgr = ModelAPI_Session::get();
+    QString aDescription = contextMenuMgr()->action("ISOLINES_CMD")->text();
+    aMgr->startOperation(aDescription.toStdString());
+
+    aValues[0] = aUNb->value();
+    aValues[1] = aVNb->value();
+    ResultPtr aRes;
+    foreach(ObjectPtr aObj, theObjects) {
+      aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
+      if (aRes.get()) {
+        ModelAPI_Tools::setIsoLines(aRes, aValues);
+      }
+    }
+    Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
+    aMgr->finishOperation();
+    updateCommandStatus();
+  }
+}
\ No newline at end of file