]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
refs #80 - Sketch base GUI: create/draw point, circle and arc
authornds <natalia.donis@opencascade.com>
Tue, 24 Jun 2014 08:58:23 +0000 (12:58 +0400)
committernds <natalia.donis@opencascade.com>
Tue, 24 Jun 2014 08:58:23 +0000 (12:58 +0400)
Double editor for the constraint value.

src/Config/Config_Keywords.h
src/ModuleBase/CMakeLists.txt
src/ModuleBase/ModuleBase_ModelWidget.h
src/ModuleBase/ModuleBase_WidgetEditor.cpp [new file with mode: 0644]
src/ModuleBase/ModuleBase_WidgetEditor.h [new file with mode: 0644]
src/ModuleBase/ModuleBase_WidgetFactory.cpp
src/ModuleBase/ModuleBase_WidgetFactory.h
src/PartSet/PartSet_OperationFeatureCreate.cpp
src/SketchPlugin/plugin-Sketch.xml
src/XGUI/XGUI_PropertyPanel.cpp

index 0d16ad4321ad648738a79fc89a13046f39e7b1b3..08614013bc16061713bbb2c7dc836a8647609862 100644 (file)
@@ -31,8 +31,8 @@ const static char* WDG_SELECTOR = "selector";
 
 //Specific widget containers
 const static char* WDG_POINT_SELECTOR = "point_selector";
-
 const static char* WDG_FEATURE_SELECTOR = "feature_selector";
+const static char* WDG_DOUBLEVALUE_EDITOR = "doublevalue_editor";
 
 const static char* _ID = "id";
 //const static char* WORKBENCH_ID = "id";
index b617a50628ed4c310002de87182b9138a0d0f23c..77a30bbad8f13be1f1bd7b5f015da3d92045d9a4 100644 (file)
@@ -9,6 +9,7 @@ SET(PROJECT_HEADERS
        ModuleBase_ModelWidget.h
        ModuleBase_WidgetBoolValue.h
        ModuleBase_WidgetDoubleValue.h
+       ModuleBase_WidgetEditor.h
        ModuleBase_WidgetFactory.h
        ModuleBase_WidgetFeature.h
        ModuleBase_WidgetPoint2D.h
@@ -24,6 +25,7 @@ SET(PROJECT_SOURCES
        ModuleBase_ModelWidget.cpp
        ModuleBase_WidgetBoolValue.cpp
        ModuleBase_WidgetDoubleValue.cpp
+       ModuleBase_WidgetEditor.cpp
        ModuleBase_WidgetFactory.cpp
        ModuleBase_WidgetFeature.cpp
        ModuleBase_WidgetPoint2D.cpp
index b7b3de3b89d9e613abfc1070d8467a9f2badd95f..5a13b4cc08d4d7f8f506246adacd95f5b7b57aa1 100644 (file)
@@ -69,6 +69,9 @@ signals:
   /// \param theAttributeName a name of the attribute
   /// \param theEvent key release event
   void keyReleased(const std::string& theAttributeName, QKeyEvent* theEvent);
+  /// The signal about the widget is lost focus
+  /// \param theWidget the model base widget
+  void focusOutWidget(ModuleBase_ModelWidget* theWidget);
 
 protected:
   bool myHasDefaultValue; /// the boolean state whether the control has a default value
diff --git a/src/ModuleBase/ModuleBase_WidgetEditor.cpp b/src/ModuleBase/ModuleBase_WidgetEditor.cpp
new file mode 100644 (file)
index 0000000..84b63cf
--- /dev/null
@@ -0,0 +1,93 @@
+// File:        ModuleBase_WidgetEditor.cpp
+// Created:     25 Apr 2014
+// Author:      Natalia ERMOLAEVA
+
+#include <ModuleBase_WidgetEditor.h>
+
+#include <Config_Keywords.h>
+#include <Config_WidgetAPI.h>
+
+#include <Events_Loop.h>
+#include <Model_Events.h>
+
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Object.h>
+#include <ModelAPI_AttributeDouble.h>
+
+#include <GeomDataAPI_Point2D.h>
+
+#include <QWidget>
+#include <QLineEdit>
+
+ModuleBase_WidgetEditor::ModuleBase_WidgetEditor(QWidget* theParent,
+                                                 const Config_WidgetAPI* theData)
+: ModuleBase_ModelWidget(theParent, theData)
+{
+  myEditor = new QLineEdit(0);
+  myEditor->setWindowFlags(Qt::ToolTip);
+  myEditor->setFocusPolicy(Qt::StrongFocus);
+
+  connect(myEditor, SIGNAL(returnPressed()), this, SLOT(onStopEditing()));
+  connect(myEditor, SIGNAL(textChanged(const QString&)), this, SIGNAL(valuesChanged()));
+}
+
+ModuleBase_WidgetEditor::~ModuleBase_WidgetEditor()
+{
+  delete myEditor;
+}
+
+bool ModuleBase_WidgetEditor::storeValue(FeaturePtr theFeature) const
+{
+  DataPtr aData = theFeature->data();
+  AttributeDoublePtr aReal = aData->real(attributeID());
+  bool isOk;
+  double aValue = myEditor->text().toDouble(&isOk);
+  if (isOk && aReal->value() != aValue) {
+    //ModuleBase_WidgetPoint2D* that = (ModuleBase_WidgetPoint2D*) this;
+    //bool isBlocked = that->blockSignals(true);
+    aReal->setValue(aValue);
+    Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
+    //that->blockSignals(isBlocked);
+  }
+  return true;
+}
+
+bool ModuleBase_WidgetEditor::restoreValue(FeaturePtr theFeature)
+{
+  boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+  AttributeDoublePtr aRef = aData->real(attributeID());
+
+  //bool isBlocked = this->blockSignals(true);
+  myEditor->setText(QString::number(aRef->value()));
+  //this->blockSignals(isBlocked);
+  return true;
+}
+
+void ModuleBase_WidgetEditor::focusTo()
+{
+  QPoint aPoint = QCursor::pos();
+
+  myEditor->move(aPoint);
+  myEditor->show();
+
+  myEditor->selectAll();
+  myEditor->setFocus();
+}
+
+QWidget* ModuleBase_WidgetEditor::getControl() const
+{
+  return 0;
+}
+
+QList<QWidget*> ModuleBase_WidgetEditor::getControls() const
+{
+  QList<QWidget*> aControls;
+  return aControls;
+}
+
+void ModuleBase_WidgetEditor::onStopEditing()
+{
+  myEditor->hide();
+  emit focusOutWidget(this);
+}
diff --git a/src/ModuleBase/ModuleBase_WidgetEditor.h b/src/ModuleBase/ModuleBase_WidgetEditor.h
new file mode 100644 (file)
index 0000000..e2f67a0
--- /dev/null
@@ -0,0 +1,61 @@
+// File:        ModuleBase_WidgetEditor.h
+// Created:     25 Apr 2014
+// Author:      Natalia ERMOLAEVA
+
+#ifndef ModuleBase_WidgetEditor_H
+#define ModuleBase_WidgetEditor_H
+
+#include <ModuleBase.h>
+#include "ModuleBase_ModelWidget.h"
+
+#include <QObject>
+#include <QStringList>
+
+class ModelAPI_Feature;
+class QLineEdit;
+
+/**\class ModuleBase_WidgetEditor
+ * \ingroup GUI
+ * \brief Custom widget. An abstract class to be redefined to fill with some GUI controls
+ */
+class MODULEBASE_EXPORT ModuleBase_WidgetEditor : public ModuleBase_ModelWidget
+{
+  Q_OBJECT
+public:
+  /// Constructor
+  /// \theParent the parent object
+  /// \theParent the parent object
+  /// \theData the widget configuation. The attribute of the model widget is obtained from
+  ModuleBase_WidgetEditor(QWidget* theParent, const Config_WidgetAPI* theData);
+  /// Destructor
+  virtual ~ModuleBase_WidgetEditor();
+
+  /// Saves the internal parameters to the given feature
+  /// \param theFeature a model feature to be changed
+  virtual bool storeValue(FeaturePtr theFeature) const;
+
+  virtual bool restoreValue(FeaturePtr theFeature);
+
+  /// Set focus to the first control of the current widget. The focus policy of the control is checked.
+  /// If the widget has the NonFocus focus policy, it is skipped.
+  virtual void focusTo();
+
+  /// Returns the internal parent wiget control, that can be shown anywhere
+  /// \returns the widget
+  QWidget* getControl() const;
+
+  /// Returns list of widget controls
+  /// \return a control list
+  virtual QList<QWidget*> getControls() const;
+
+protected slots:
+  /// Slot to check the editing stop
+  void onStopEditing();
+
+private:
+  QLineEdit* myEditor;
+  FeaturePtr myFeature; ///< the current widget feature
+  QStringList myFeatureKinds; ///< the kinds of possible features
+};
+
+#endif
index 1c372fd670b897986767d3b7caf24ce135fc50a9..e651ba7d362fbf3d8dbba99b07b4bd78fa7493dd 100644 (file)
@@ -11,6 +11,7 @@
 #include <ModuleBase_OperationDescription.h>
 #include <ModuleBase_WidgetPoint2D.h>
 #include <ModuleBase_WidgetFeature.h>
+#include <ModuleBase_WidgetEditor.h>
 #include <ModuleBase_WidgetSwitch.h>
 #include <ModuleBase_WidgetSelector.h>
 #include <ModuleBase_WidgetDoubleValue.h>
@@ -123,6 +124,9 @@ QWidget* ModuleBase_WidgetFactory::createWidgetByType(const std::string& theType
   } else if (theType == WDG_FEATURE_SELECTOR) {
     result = featureSelectorControl(theParent);
 
+  } else if (theType == WDG_DOUBLEVALUE_EDITOR) {
+    result = doubleValueEditor(theParent);
+
   }
   else if (myWidgetApi->isContainerWidget() || myWidgetApi->isPagedWidget()) {
     result = createContainer(theType, theParent);
@@ -175,6 +179,13 @@ QWidget* ModuleBase_WidgetFactory::featureSelectorControl(QWidget* theParent)
   return aWidget->getControl();
 }
 
+QWidget* ModuleBase_WidgetFactory::doubleValueEditor(QWidget* theParent)
+{
+  ModuleBase_WidgetEditor* aWidget = new ModuleBase_WidgetEditor(theParent, myWidgetApi);
+  myModelWidgets.append(aWidget);
+  return 0;
+}
+
 QString ModuleBase_WidgetFactory::qs(const std::string& theStdString) const
 {
   return QString::fromStdString(theStdString);
index e2162872cdce5d040f655feff688a0e94aa03227..b51c4bc32ef8986de58fcc91a15bb81add4f9f07 100644 (file)
@@ -39,6 +39,7 @@ protected:
   QWidget* doubleSpinBoxControl(QWidget* theParent);
   QWidget* pointSelectorControl(QWidget* theParent);
   QWidget* featureSelectorControl(QWidget* theParent);
+  QWidget* doubleValueEditor(QWidget* theParent);
   QWidget* createContainer(const std::string& theType, QWidget* theParent = NULL);
   QWidget* selectorControl(QWidget* theParent);
   QWidget* booleanControl(QWidget* theParent);
index a318a128085fe285a719288dcd83c9d7edcb1e1a..bd5529244be6770994993bb8d189a491ff155c3d 100644 (file)
@@ -53,7 +53,7 @@ PartSet_OperationFeatureCreate::~PartSet_OperationFeatureCreate()
 
 bool PartSet_OperationFeatureCreate::canProcessKind(const std::string& theId)
 {
-  return theId == SKETCH_LINE_KIND || theId == SKETCH_POINT_KIND /*||
+  return theId == SKETCH_LINE_KIND || theId == SKETCH_POINT_KIND ||
          theId == SKETCH_CONSTRAINT_DISTANCE_KIND/*|| theId == SKETCH_CIRCLE_KIND ||
          theId == SKETCH_ARC_KIND*/;
 }
index f1d354e4601378786820f5584759b0e6318e1ed6..de1152c92986cd50c20ccec1098ce5111806030f 100644 (file)
@@ -27,7 +27,7 @@
         <feature_selector id="ConstraintEntityA" keysequence="SketchPoint"/>
         <feature_selector id="ConstraintEntityB" keysequence="SketchPoint"/>
         <point_selector id="ConstraintFlyoutValuePnt" title="Flyout point" tooltip="Flyout"/>
-        <doublevalue id="ConstraintValue" label="Value:" min="0" step="1.0" default="0" icon=":icons/radius.png" tooltip="Constraint value"/>
+        <doublevalue_editor id="ConstraintValue" min="0" step="1.0" tooltip="Constraint value"/>
       </feature>
       <feature id="SketchConstraintLength" title="Length of a line" tooltip="Create constraint for the given length of a line segment">
         <label title="Select a line entity on which to calculate lenght" tooltip="Select a line entity on which to calculate lenght"/>
index d82244211d37b9134bcd0fe8da212552e87ac5b8..83de5b27d792671585cfa538f5340433a05686be 100644 (file)
@@ -92,6 +92,9 @@ void XGUI_PropertyPanel::setModelWidgets(const QList<ModuleBase_ModelWidget*>& t
     for (; anIt != aLast; anIt++) {
       connect(*anIt, SIGNAL(keyReleased(const std::string&, QKeyEvent*)),
               this, SIGNAL(keyReleased(const std::string&, QKeyEvent*)));
+
+      connect(*anIt, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*)),
+              this, SLOT(onActivateNextWidget(ModuleBase_ModelWidget*)));
     }
     ModuleBase_ModelWidget* aLastWidget = theWidgets.last();
     if (aLastWidget) {