]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Create Extrusion property panel.
authorvsv <vitaly.smetannikov@opencascade.com>
Tue, 3 Jun 2014 14:25:40 +0000 (18:25 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Tue, 3 Jun 2014 14:25:40 +0000 (18:25 +0400)
src/ConstructionPlugin/extrusion_widget.xml
src/ModelAPI/ModelAPI_Feature.h
src/ModuleBase/ModuleBase_SelectorWidget.cpp
src/ModuleBase/ModuleBase_SelectorWidget.h

index 52cf8622f8c4081aa7491443e8f4b6ca79f586ed..ed08edc353d3fadd680241539de7b81603ae7ca2 100644 (file)
@@ -3,6 +3,7 @@
     label="Select a face" 
     icon=":icons/sketch.png" 
     tooltip="Select a face for extrusion"
+       activate="true"
   />
   <doublevalue id="extrusion_size" label="Size" min="0" step="1.0" default="10" icon=":icons/dimension_v.png" tooltip="Set size of extrusion"/>
   <boolvalue id="extrusion_reverse" label="Reverse" default="false" tooltip="Reverse default direction"/>
index bd726461ff4194ecec2da0f35d4c5d65e63e80aa..6d7955f4b1dee713b9149faa581656770c1f5155 100644 (file)
@@ -58,7 +58,7 @@ public:
 
   /// Returns true if feature refers to the same model data instance
   MODELAPI_EXPORT virtual bool isSame(const boost::shared_ptr<ModelAPI_Feature>& theFeature)
-  {return true;}
+  {return theFeature.get() == this;}
 
   /// To virtually destroy the fields of successors
   virtual ~ModelAPI_Feature() {}
index 931c3be6c6f133293be10ef3d34efc5891c631a5..f47911d8394f4e990f9d2c8dd73f38453de6fe7a 100644 (file)
@@ -7,6 +7,7 @@
 #include "ModuleBase_IWorkshop.h"
 
 #include <ModelAPI_Data.h>
+#include <ModelAPI_Object.h>
 #include <ModelAPI_AttributeReference.h>
 #include <Config_WidgetAPI.h>
 
 #include <QLabel>
 #include <QLineEdit>
 #include <QToolButton>
+#include <QString>
+#include <QEvent>
 
 
 ModuleBase_SelectorWidget::ModuleBase_SelectorWidget(QWidget* theParent, 
                                                      ModuleBase_IWorkshop* theWorkshop, 
                                                      const Config_WidgetAPI* theData)
-: ModuleBase_ModelWidget(theParent), myWorkshop(theWorkshop)
+: ModuleBase_ModelWidget(theParent), myWorkshop(theWorkshop), myActivateOnStart(false)
 {
   myFeatureAttributeID = theData->widgetId();
 
@@ -39,6 +42,7 @@ ModuleBase_SelectorWidget::ModuleBase_SelectorWidget(QWidget* theParent,
   myTextLine = new QLineEdit(myContainer);
   myTextLine->setReadOnly(true);
   myTextLine->setToolTip(aToolTip);
+  myTextLine->installEventFilter(this);
 
   aLayout->addWidget(myTextLine);
 
@@ -46,10 +50,14 @@ ModuleBase_SelectorWidget::ModuleBase_SelectorWidget(QWidget* theParent,
   myActivateBtn->setIcon(QIcon(":icons/hand_point.png"));
   myActivateBtn->setCheckable(true);
   myActivateBtn->setToolTip(tr("Activate/Deactivate selection"));
+  connect(myActivateBtn, SIGNAL(toggled(bool)), this, SLOT(activateSelection(bool)));
 
   aLayout->addWidget(myActivateBtn);
 
-  connect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
+  QString aActivateTxt = QString::fromStdString(theData->getProperty("activate"));
+  if (!aActivateTxt.isNull()) {
+    myActivateOnStart = (aActivateTxt == "true");
+  }
 }
 
 //********************************************************************
@@ -64,6 +72,8 @@ bool ModuleBase_SelectorWidget::storeValue(FeaturePtr theFeature)
   boost::shared_ptr<ModelAPI_AttributeReference> aRef = 
     boost::dynamic_pointer_cast<ModelAPI_AttributeReference>(aData->attribute(myFeatureAttributeID));
 
+  aRef->setFeature(mySelectedFeature);
+
   return true;
 }
 
@@ -73,7 +83,9 @@ bool ModuleBase_SelectorWidget::restoreValue(FeaturePtr theFeature)
   DataPtr aData = theFeature->data();
   boost::shared_ptr<ModelAPI_AttributeReference> aRef = 
     boost::dynamic_pointer_cast<ModelAPI_AttributeReference>(aData->attribute(myFeatureAttributeID));
-  
+
+  mySelectedFeature = aRef->value();
+  updateSelectionName(); 
   return true;
 }
 
@@ -102,5 +114,73 @@ QList<QWidget*> ModuleBase_SelectorWidget::getControls() const
 void ModuleBase_SelectorWidget::onSelectionChanged()
 {
   QList<FeaturePtr> aFeatures = myWorkshop->selectedFeatures();
-  int aCount = aFeatures.size();
+  if (aFeatures.size() > 0) {
+    FeaturePtr aFeature = aFeatures.first();
+    if ((!mySelectedFeature) && (!aFeature))
+      return;
+    if (mySelectedFeature && aFeature && mySelectedFeature->isSame(aFeature))
+      return;
+
+    // TODO: Check that the selection corresponds to selection type
+    mySelectedFeature = aFeature;
+    if (mySelectedFeature) {
+      updateSelectionName();
+      activateSelection(false);
+    } else {
+      myTextLine->setText("");
+    }
+    emit valuesChanged();
+  }
+}
+
+//********************************************************************
+void ModuleBase_SelectorWidget::updateSelectionName()
+{
+  if (mySelectedFeature) {
+    std::string aName;
+    if (mySelectedFeature->data())
+      aName = mySelectedFeature->data()->getName();
+    else 
+      aName = boost::dynamic_pointer_cast<ModelAPI_Object>(mySelectedFeature)->getName();
+    myTextLine->setText(QString::fromStdString(aName));
+  } else 
+    myTextLine->setText("");
+}
+
+//********************************************************************
+bool ModuleBase_SelectorWidget::eventFilter(QObject* theObj, QEvent* theEvent)
+{
+  if (theObj == myTextLine) {
+    if (theEvent->type() == QEvent::Polish) {
+      activateSelection(myActivateOnStart);
+      onSelectionChanged();
+    }
+  }
+  return ModuleBase_ModelWidget::eventFilter(theObj, theEvent);
+}
+
+//********************************************************************
+void ModuleBase_SelectorWidget::enableOthersControls(bool toEnable)
+{
+  QWidget* aParent = myContainer->parentWidget();
+  QList<QWidget*> aChldList = aParent->findChildren<QWidget*>();
+  foreach(QWidget* aWgt, aChldList) {
+    if ((aWgt != myLabel) && (aWgt != myActivateBtn) && (aWgt != myTextLine) && (aWgt != myContainer))
+      aWgt->setEnabled(toEnable);
+  }
+}
+
+//********************************************************************
+void ModuleBase_SelectorWidget::activateSelection(bool toActivate)
+{
+  enableOthersControls(!toActivate);
+  myTextLine->setEnabled(toActivate);
+
+  if (toActivate)
+    connect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
+  else
+    disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
+
+  myActivateBtn->setDown(toActivate);
 }
\ No newline at end of file
index cf3468a3fa66aeafac3bd61ddc730eec7bee7d41..61d71c415320288d8ce6dbf1b17c8fe1cfa7e7dd 100644 (file)
@@ -49,10 +49,26 @@ public:
   /// \return a control list
   virtual QList<QWidget*> getControls() const;
 
+  void setActivationOnStart(bool toActivate) { myActivateOnStart = toActivate; }
+  bool activateOnStart() const { return myActivateOnStart; }
+
+  FeaturePtr selectedFeature() const { return mySelectedFeature; }
+
+public slots:
+
+  /// Activate or deactivate selection
+  void activateSelection(bool toActivate);
+
+protected:
+  bool eventFilter(QObject* theObj, QEvent* theEvent);
+
 private slots:
   void onSelectionChanged();
 
 private:
+  void enableOthersControls(bool toEnable);
+  void updateSelectionName();
+
   std::string myFeatureAttributeID;
 
   QWidget*     myContainer;
@@ -61,6 +77,10 @@ private:
   QToolButton* myActivateBtn;
 
   ModuleBase_IWorkshop* myWorkshop;
+
+  bool myActivateOnStart;
+
+  FeaturePtr mySelectedFeature;
 };
 
 #endif
\ No newline at end of file