]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Provide editing of parameters
authorvsv <vitaly.smetannikov@opencascade.com>
Wed, 15 Apr 2015 08:55:16 +0000 (11:55 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Wed, 15 Apr 2015 08:55:16 +0000 (11:55 +0300)
src/ParametersPlugin/ParametersPlugin_Parameter.cpp
src/PartSet/PartSet_WidgetPoint2dDistance.cpp
src/PartSet/PartSet_WidgetPoint2dDistance.h
src/XGUI/XGUI_ContextMenuMgr.cpp
src/XGUI/XGUI_ObjectsBrowser.cpp
src/XGUI/XGUI_PartDataModel.cpp
src/XGUI/XGUI_Workshop.cpp

index 413e7dc9bcacf220e88d7737843b866cdf1cde7f..ece600bcddd493160514769d14f839a4dbe6b18d 100644 (file)
@@ -56,7 +56,7 @@ void ParametersPlugin_Parameter::attributeChanged(const std::string&)
   std::ostringstream sstream;
   sstream << aValue;
   std::string aParamValue = sstream.str();
-  data()->setName(aName + " ("+ aParamValue + ")");
+  data()->setName(aName);
   aParam->data()->setName(aName);
   // Error
   std::string aStateMsg;
index e8d24eb51421f612c0b514c7d61b8263a460a667..9da73baae95e48448ac950f7da75148ff736f551 100644 (file)
@@ -41,14 +41,15 @@ PartSet_WidgetPoint2dDistance::~PartSet_WidgetPoint2dDistance()
 {
 }
 
-void PartSet_WidgetPoint2dDistance::reset()
-{
-  bool isOk;
-  double aDefValue = QString::fromStdString(getDefaultValue()).toDouble(&isOk);
-
-  ModuleBase_Tools::setSpinValue(mySpinBox, isOk ? aDefValue : 0.0);
-  storeValueCustom();
-}
+// It is not clear a necesity of this method also it contradicts to scenario defined in parent class
+//void PartSet_WidgetPoint2dDistance::reset()
+//{
+//  bool isOk;
+//  double aDefValue = QString::fromStdString(getDefaultValue()).toDouble(&isOk);
+//
+//  ModuleBase_Tools::setSpinValue(mySpinBox, isOk ? aDefValue : 0.0);
+//  storeValueCustom();
+//}
 
 void PartSet_WidgetPoint2dDistance::setPoint(FeaturePtr theFeature,
                                              const std::shared_ptr<GeomAPI_Pnt2d>& thePnt)
index 7d6a497c6058f55a89af09552decfa518f6ce373..95fc0ed19c450222bb2239c8c81d63f33cfcc7e4 100644 (file)
@@ -48,7 +48,7 @@ Q_OBJECT
   virtual ~PartSet_WidgetPoint2dDistance();
 
   /// Fills the widget with default values
-  virtual void reset();
+  //virtual void reset();
 
   /// The methiod called when widget is deactivated
   virtual void deactivate();
index 1051298f4b9bdb2765a919e517b7fa117f29a790..868da0552900f20958902a229ee81dd13f4a7446 100644 (file)
@@ -19,6 +19,7 @@
 #include <ModelAPI_ResultPart.h>
 #include <ModelAPI_Session.h>
 #include <ModelAPI_ResultGroup.h>
+#include <ModelAPI_ResultParameter.h>
 
 #include <ModuleBase_IModule.h>
 
@@ -142,15 +143,17 @@ QMenu* XGUI_ContextMenuMgr::objectBrowserMenu() const
     XGUI_Displayer* aDisplayer = myWorkshop->displayer();
     bool hasResult = false;
     bool hasFeature = false;
+    bool hasParameter = false;
     foreach(ObjectPtr aObj, aObjects)
     {
       FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
       ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
-      if (aResult)
-        hasResult = true;
-      if (aFeature)
-        hasFeature = true;
-      if (hasFeature && hasResult) // && hasGroup)
+      ResultParameterPtr aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultParameter>(aResult);
+
+      hasResult = (aResult.get() != NULL);
+      hasFeature = (aFeature.get() != NULL);
+      hasParameter = (aConstruction.get() != NULL);
+      if (hasFeature && hasResult  && hasParameter)
         break;
     }
     //Process Feature
@@ -175,17 +178,20 @@ QMenu* XGUI_ContextMenuMgr::objectBrowserMenu() const
             }
             aMenu->addSeparator();
             aMenu->addAction(action("HIDE_CMD"));
-          } else {
+          } else if (!hasParameter) {
             aMenu->addAction(action("SHOW_CMD"));
           }
-          aMenu->addAction(action("SHOW_ONLY_CMD"));
+          if (hasParameter)
+            aMenu->addAction(action("EDIT_CMD"));
+          else
+            aMenu->addAction(action("SHOW_ONLY_CMD"));
         }
       } else {  // If feature is 0 the it means that selected root object (document)
         if (aMgr->activeDocument() != aMgr->moduleDocument())
           aMenu->addAction(action("ACTIVATE_PART_CMD"));
       }
     } else {
-      if (hasResult) {
+      if (hasResult && (!hasParameter)) {
         aMenu->addAction(action("SHOW_CMD"));
         aMenu->addAction(action("HIDE_CMD"));
         aMenu->addAction(action("SHOW_ONLY_CMD"));
@@ -194,7 +200,7 @@ QMenu* XGUI_ContextMenuMgr::objectBrowserMenu() const
         aMenu->addAction(action("WIREFRAME_CMD"));
       }
     }
-    if (hasFeature)
+    if (hasFeature || hasParameter)
       aMenu->addAction(action("DELETE_CMD"));
   }
   if (myWorkshop->canChangeColor())
index 2ff582bb7c70b08fa7024558839f717aa2a8eca3..df5625c890f267640dcf15f39a30c5225320f7ba 100644 (file)
 #include <QEvent>
 #include <QMouseEvent>
 #include <QAction>
+#include <QStyledItemDelegate>
+
+class XGUI_TreeViewItemDelegate: public QStyledItemDelegate
+{
+public:
+  XGUI_TreeViewItemDelegate(XGUI_DataTree* theParent):QStyledItemDelegate(theParent), myTreedView(theParent) {}
+
+  virtual void setEditorData ( QWidget* editor, const QModelIndex& index ) const
+  {
+    QLineEdit* aEditor = dynamic_cast<QLineEdit*>(editor);
+    if (aEditor) {
+      XGUI_DocumentDataModel* aModel = myTreedView->dataModel();
+      ObjectPtr aObj = aModel->object(index);
+      if (aObj.get() != NULL) {
+        aEditor->setText(aObj->data()->name().c_str());
+        return;
+      }
+    }
+    QStyledItemDelegate::setEditorData(editor, index);
+  }
+
+private:
+  XGUI_DataTree* myTreedView;
+};
+
 
 XGUI_DataTree::XGUI_DataTree(QWidget* theParent)
     : QTreeView(theParent)
@@ -28,6 +53,8 @@ XGUI_DataTree::XGUI_DataTree(QWidget* theParent)
   setSelectionBehavior(QAbstractItemView::SelectRows);
   setSelectionMode(QAbstractItemView::ExtendedSelection);
 
+  setItemDelegateForColumn(0, new XGUI_TreeViewItemDelegate(this));
+
   connect(selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
           this, SLOT(onSelectionChanged(const QItemSelection&, const QItemSelection&)));
 }
index 3faa7bd6db81fdf1c8c3ae5d152879123e827ee8..5ab5798468bb0bd2c999ddb1bc255a94e696fcf7 100644 (file)
@@ -15,6 +15,7 @@
 #include <ModelAPI_ResultParameter.h>
 #include <ModelAPI_ResultBody.h>
 #include <ModelAPI_ResultGroup.h>
+#include <ModelAPI_AttributeDouble.h>
 
 #include <QIcon>
 #include <QBrush>
@@ -47,8 +48,13 @@ QVariant XGUI_TopDataModel::data(const QModelIndex& theIndex, int theRole) const
         case ParamObject: {
           DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
           ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultParameter::group(), theIndex.row());
-          if (aObject)
-            return aObject->data()->name().c_str();
+          if (aObject) {
+            ResultParameterPtr aParam = std::dynamic_pointer_cast<ModelAPI_ResultParameter>(aObject);
+            AttributeDoublePtr aValueAttribute = aParam->data()->real(ModelAPI_ResultParameter::VALUE());
+            QString aVal = QString::number(aValueAttribute->value());
+            QString aTitle = QString(aObject->data()->name().c_str());
+            return aTitle + "=" + aVal;
+          }
         }
           break;
         case ConstructFolder:
@@ -274,8 +280,13 @@ QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) cons
         case ParamObject: {
           ObjectPtr aObject = partDocument()->object(ModelAPI_ResultParameter::group(),
                                                      theIndex.row());
-          if (aObject)
-            return std::dynamic_pointer_cast<ModelAPI_Object>(aObject)->data()->name().c_str();
+          if (aObject) {
+            ResultParameterPtr aParam = std::dynamic_pointer_cast<ModelAPI_ResultParameter>(aObject);
+            AttributeDoublePtr aValueAttribute = aParam->data()->real(ModelAPI_ResultParameter::VALUE());
+            QString aVal = QString::number(aValueAttribute->value());
+            QString aTitle = QString(aObject->data()->name().c_str());
+            return aTitle + "=" + aVal;
+          }
         }
           break;
         case ConstructObject: {
index 985f1f307e6b9ac67f19547c9f8fa9b35720b053..54815e0a430851a1691f7c330b7fce05ac2e610e 100644 (file)
@@ -40,6 +40,7 @@
 #include <ModelAPI_ResultConstruction.h>
 #include <ModelAPI_ResultBody.h>
 #include <ModelAPI_AttributeIntArray.h>
+#include <ModelAPI_ResultParameter.h>
 
 //#include <PartSetPlugin_Part.h>
 
@@ -1329,7 +1330,14 @@ void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
     myDisplayer->eraseAll();
   else if (theId == "EDIT_CMD") {
     FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObjects.first());
-    if (aFeature)
+    if (aFeature == NULL) {
+      ResultParameterPtr aParam = 
+        std::dynamic_pointer_cast<ModelAPI_ResultParameter>(aObjects.first());
+      if (aParam.get() != NULL) {
+        aFeature = ModelAPI_Feature::feature(aParam);
+      }
+    }
+    if (aFeature.get() != NULL)
       myModule->editFeature(aFeature);
   }
 }