Salome HOME
Merge branch 'Dev_1.1.0' of newgeom:newgeom into Dev_1.1.0
authorvsv <vitaly.smetannikov@opencascade.com>
Fri, 17 Apr 2015 15:45:48 +0000 (18:45 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Fri, 17 Apr 2015 15:45:48 +0000 (18:45 +0300)
14 files changed:
src/ConstructionPlugin/ConstructionPlugin_Plane.cpp
src/NewGeom/CMakeLists.txt
src/NewGeom/NewGeom_Module.cpp
src/NewGeom/NewGeom_Module.h
src/NewGeom/NewGeom_NestedButton.cpp [new file with mode: 0644]
src/NewGeom/NewGeom_NestedButton.h [new file with mode: 0644]
src/NewGeom/resources/LightApp.xml
src/NewGeom/resources/SalomeApp.xml
src/PartSet/PartSet_WidgetSketchLabel.cpp
src/PartSet/PartSet_WidgetSketchLabel.h
src/XGUI/XGUI_ActionsMgr.cpp
src/XGUI/XGUI_OperationMgr.cpp
src/XGUI/XGUI_SalomeConnector.h
src/XGUI/XGUI_Workshop.cpp

index c206ff4d55b1a24f7aee3ba87fcf686966f10815..13ae2b36d65cb7fe6ca22bcdeb2f398b22172352 100644 (file)
@@ -13,6 +13,8 @@
 #include <ModelAPI_ResultConstruction.h>
 #include <ModelAPI_AttributeIntArray.h>
 #include <ModelAPI_AttributeString.h>
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Validator.h>
 #include <GeomAlgoAPI_FaceBuilder.h>
 
 #include <GeomAPI_Pnt2d.h>
@@ -32,6 +34,11 @@ void ConstructionPlugin_Plane::initAttributes()
   data()->addAttribute(ConstructionPlugin_Plane::B(),  ModelAPI_AttributeDouble::typeId());
   data()->addAttribute(ConstructionPlugin_Plane::C(),  ModelAPI_AttributeDouble::typeId());
   data()->addAttribute(ConstructionPlugin_Plane::D(),  ModelAPI_AttributeDouble::typeId());
+
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), ConstructionPlugin_Plane::A());
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), ConstructionPlugin_Plane::B());
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), ConstructionPlugin_Plane::C());
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), ConstructionPlugin_Plane::D());
 }
 
 void ConstructionPlugin_Plane::execute()
index 979269418dfebfbf1c72e1cc791532872c0a6425..70f406e6f2382ef1a90a421d83e82b1efa380b93 100644 (file)
@@ -9,6 +9,7 @@ SET(PROJECT_HEADERS
        NewGeom_DataModel.h
        NewGeom_OCCSelector.h
        NewGeom_SalomeViewer.h
+       NewGeom_NestedButton.h
 )
 
 SET(PROJECT_AUTOMOC 
@@ -20,6 +21,7 @@ SET(PROJECT_SOURCES
        NewGeom_DataModel.cpp
        NewGeom_OCCSelector.cpp
        NewGeom_SalomeViewer.cpp
+       NewGeom_NestedButton.cpp
 )
 
 SET(PROJECT_RESOURCES
index a569af01598bb1939a8d8caf16033dc602fbc2cd..6e27289e38c5230b8e80f8ef95b9576339a65b2e 100644 (file)
@@ -4,6 +4,7 @@
 #include "NewGeom_Module.h"
 #include "NewGeom_DataModel.h"
 #include "NewGeom_OCCSelector.h"
+#include <NewGeom_NestedButton.h>
 
 #include <XGUI_Workshop.h>
 #include <XGUI_PropertyPanel.h>
@@ -14,6 +15,7 @@
 
 #include <ModuleBase_Operation.h>
 #include <ModuleBase_Preferences.h>
+#include <ModuleBase_ActionInfo.h>
 
 #include <LightApp_Application.h>
 #include <LightApp_SelectionMgr.h>
@@ -332,6 +334,16 @@ CAM_DataModel* NewGeom_Module::createDataModel()
   return aDataModel;
 }
 
+QAction* NewGeom_Module::addFeature(const QString& theWBName, const ActionInfo& theInfo)
+{
+  return addFeature(theWBName,
+                    theInfo.id,
+                    theInfo.text,
+                    theInfo.toolTip,
+                    theInfo.icon,
+                    theInfo.shortcut);
+}
+
 //******************************************************
 QAction* NewGeom_Module::addFeature(const QString& theWBName, const QString& theId,
                                     const QString& theTitle, const QString& theTip,
@@ -352,17 +364,37 @@ QAction* NewGeom_Module::addFeature(const QString& theWBName, const QString& the
   aAction->setData(theId);
   int aItemId = createMenu(aId, aMenu, -1, 10);
   int aToolId = createTool(aId, aTool);
+
   return aAction;
 }
 
-QAction* NewGeom_Module::addFeature(const QString& theWBName, const ActionInfo& theInfo)
+
+QAction* NewGeom_Module::addNestedFeature(const QString& theWBName,
+                                          const ActionInfo& theInfo,
+                                          const QList<QAction*>& theNestedActions)
 {
-  return addFeature(theWBName,
-                    theInfo.id,
-                    theInfo.text,
-                    theInfo.toolTip,
-                    theInfo.icon,
-                    theInfo.shortcut);
+  int aMenu = createMenu(theWBName, -1, -1, 50);
+  int aTool = createTool(theWBName);
+
+  int aId = myActionsList.size();
+  myActionsList.append(theInfo.id);
+  SUIT_Desktop* aDesk = application()->desktop();
+  NewGeom_NestedButton* anAction = new NewGeom_NestedButton(aDesk, theNestedActions);
+  anAction->setData(theInfo.id);
+  anAction->setCheckable(theInfo.checkable);
+  anAction->setChecked(theInfo.checked);
+  anAction->setEnabled(theInfo.enabled);
+  anAction->setVisible(theInfo.visible);
+  anAction->setIcon(theInfo.icon);
+  anAction->setText(theInfo.text);
+  anAction->setToolTip(theInfo.toolTip);
+  anAction->setShortcut(theInfo.shortcut);
+  anAction->setFont(theInfo.font);
+
+  //int aItemId = createMenu(aId, aMenu, -1, 10);
+  int aToolId = createTool(anAction, aTool, aId);
+
+  return anAction;
 }
 
 
index f8834b760f75057ea9fbd719700c914c7560a0b1..89cfc45a2b1930599685bfedb4dd86f7a5ba7633 100644 (file)
@@ -57,6 +57,10 @@ Q_OBJECT
   virtual QAction* addFeature(const QString& theWBName,
                               const ActionInfo& theInfo);
 
+  virtual QAction* addNestedFeature(const QString& theWBName,
+                                    const ActionInfo& theInfo,
+                                    const QList<QAction*>& theNestedActions);
+
   virtual QAction* addDesktopCommand(const QString& theId, const QString& theTitle,
                                      const QString& theTip, const QIcon& theIcon,
                                      const QKeySequence& theKeys, bool isCheckable,
diff --git a/src/NewGeom/NewGeom_NestedButton.cpp b/src/NewGeom/NewGeom_NestedButton.cpp
new file mode 100644 (file)
index 0000000..ff42227
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * NewGeom_NestedButton.cpp
+ *
+ *  Created on: Apr 13, 2015
+ *      Author: sbh
+ */
+
+#include <NewGeom_NestedButton.h>
+
+#include <QAction>
+#include <QFrame>
+#include <QHBoxLayout>
+#include <QToolButton>
+
+NewGeom_NestedButton::NewGeom_NestedButton(QObject* theParent,
+                                           const QList<QAction*>& theNestedActions)
+: QWidgetAction(theParent),
+  myNestedActions(theNestedActions),
+  myAdditionalButtonsWidget(0),
+  myButtonFrame(0),
+  myThisButton(0)
+{
+}
+
+NewGeom_NestedButton::~NewGeom_NestedButton()
+{
+}
+
+void NewGeom_NestedButton::showAdditionalButtons(bool isShow)
+{
+  myAdditionalButtonsWidget->setVisible(isShow);
+  if (isShow) {
+    myButtonFrame->setFrameStyle(QFrame::WinPanel);
+    myButtonFrame->setFrameShadow(QFrame::Sunken);
+    myThisButton->setAutoRaise(false);
+  } else {
+    myButtonFrame->setFrameStyle(QFrame::NoFrame);
+    myButtonFrame->setFrameShadow(QFrame::Plain);
+    myThisButton->setAutoRaise(true);
+  }
+}
+
+QWidget * NewGeom_NestedButton::createWidget(QWidget * theParent)
+{
+  myButtonFrame = new QFrame(theParent);
+  QHBoxLayout* aBoxLay = new QHBoxLayout(myButtonFrame);
+  aBoxLay->setContentsMargins(2, 0, 0, 0);
+  aBoxLay->setSpacing(1);
+
+  myThisButton = new QToolButton(myButtonFrame);
+  myThisButton->setDefaultAction(this);
+  myThisButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
+  aBoxLay->addWidget(myThisButton, 1);
+
+  myAdditionalButtonsWidget = new QWidget(myButtonFrame);
+  QHBoxLayout* aAdditionalBoxLay = new QHBoxLayout(myAdditionalButtonsWidget);
+  aAdditionalBoxLay->setContentsMargins(0, 0, 0, 0);
+  aAdditionalBoxLay->setSpacing(1);
+  foreach (QAction* eachAct, myNestedActions) {
+    QToolButton* aButton = new QToolButton(myButtonFrame);
+    aButton->setDefaultAction(eachAct);
+    aButton->setAutoRaise(true);
+    aAdditionalBoxLay->addWidget(aButton);
+  }
+  myAdditionalButtonsWidget->setLayout(aAdditionalBoxLay);
+  aBoxLay->addWidget(myAdditionalButtonsWidget);
+
+  myButtonFrame->setLayout(aBoxLay);
+
+  showAdditionalButtons(false);
+  connect(this, SIGNAL(toggled(bool)), this, SLOT(showAdditionalButtons(bool)));
+  connect(this, SIGNAL(changed()), this, SLOT(actionStateChanged()));
+  return myButtonFrame;
+}
+
+void NewGeom_NestedButton::actionStateChanged()
+{
+  if (isEnabled()) {
+    QString s = "true";
+  } else {
+    QString s = "false";
+  }
+  
+}
diff --git a/src/NewGeom/NewGeom_NestedButton.h b/src/NewGeom/NewGeom_NestedButton.h
new file mode 100644 (file)
index 0000000..7be12d4
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * NewGeom_NestedButton.h
+ *
+ *  Created on: Apr 13, 2015
+ *      Author: sbh
+ */
+
+#ifndef SRC_NEWGEOM_NEWGEOM_NESTEDBUTTON_H_
+#define SRC_NEWGEOM_NEWGEOM_NESTEDBUTTON_H_
+
+#include <QWidgetAction>
+
+class QFrame;
+class QAction;
+class QWidget;
+class QToolButton;
+
+/*!
+ * \ingroup Salome
+ * Custom (nested) button in salome mode.
+ */
+class NewGeom_NestedButton : public QWidgetAction
+{
+  Q_OBJECT
+ public:
+  NewGeom_NestedButton(QObject *parent, const QList<QAction*>& theNestedActions);
+  virtual ~NewGeom_NestedButton();
+
+ public slots:
+  /// Shows/hides the additional buttons widget
+  void showAdditionalButtons(bool);
+  void actionStateChanged();
+
+ protected:
+  /// Creates the button representation
+  virtual QWidget * createWidget(QWidget * theParent);
+
+ private:
+  QList<QAction*> myNestedActions; ///< list of nested actions
+  QWidget* myAdditionalButtonsWidget; ///< widget to precess additional buttons visibility
+  QFrame* myButtonFrame; ///< frame arround button representation
+  QToolButton* myThisButton; ///< main button
+};
+
+#endif /* SRC_NEWGEOM_NEWGEOM_NESTEDBUTTON_H_ */
index 7b1574183d7dce393e3870e0d5352010cfafe84e..0ce33510040f9673422b363b2d785e1cc3ac433b 100644 (file)
@@ -23,7 +23,7 @@
     <!-- Major module parameters -->
     <parameter name="name" value="NewGeom"/>
     <parameter name="icon" value="newgeom.png"/>
-    <parameter name="version" value="1.0.2"/>
+    <parameter name="version" value="1.1.0"/>
     <parameter name="documentation" value="newgeom_help"/>
   </section>
   <section name="newgeom_help" >
index 1c8b9e477bbc1eca2cb0b7b37c32b7e9791549b5..d5c820939df2b6bcbb3aa8619d3ba8d712cea163 100644 (file)
@@ -27,7 +27,7 @@
     <!-- Major module parameters -->
     <parameter name="name" value="NewGeom"/>
     <parameter name="icon" value="newgeom.png"/>
-    <parameter name="version" value="1.0.2"/>
+    <parameter name="version" value="1.1.0"/>
     <parameter name="documentation" value="newgeom_help"/>
   </section>
   <section name="newgeom_help" >
index 239aeb75ad18beec5d7b656c7b4f61110cf63136..ceeeb6bff17f662dd6d2367f90bc9fef00c53374 100644 (file)
@@ -85,6 +85,17 @@ PartSet_WidgetSketchLabel::~PartSet_WidgetSketchLabel()
   erasePreviewPlanes();
 }
 
+bool PartSet_WidgetSketchLabel::setSelection(ModuleBase_ViewerPrs theValue)
+{
+  // do not use the given selection if the plane of the sketch has been already set.
+  // If this check is absent, a selected plane in the viewer can be set in the sketch
+  // even if the sketch is built on another plane.
+  if (plane().get())
+    return true;
+
+  return ModuleBase_WidgetValidated::setSelection(theValue);
+}
+
 QList<QWidget*> PartSet_WidgetSketchLabel::getControls() const
 {
   QList<QWidget*> aResult;
index ab7cd18eb35737396accc48f7e5b4be2a0cb4471..eea79ea6d552119bf2d568384f6fdd64c2647de6 100644 (file)
@@ -48,6 +48,13 @@ Q_OBJECT
 
   virtual ~PartSet_WidgetSketchLabel();
 
+  /// Set the given wrapped value to the current widget
+  /// This value should be processed in the widget according to the needs
+  /// The method is called by the current operation to process the operation preselection.
+  /// It is redefined to do nothing if the plane of the sketch has been already set.
+  /// \param theValue the wrapped widget value
+  virtual bool setSelection(ModuleBase_ViewerPrs theValue);
+
   virtual bool restoreValue()
   {
     return true;
index 129fdb2cfd9db0b6c6fe493c8034fc8dc2ce25f9..bdc91203b025b8dea63c8956eaaeabbbfd8ed10f 100644 (file)
@@ -299,6 +299,7 @@ void XGUI_ActionsMgr::setNestedStackEnabled(ModuleBase_Operation* theOperation)
     return;
   FeaturePtr aFeature = theOperation->feature();
   QString aFeatureId = QString::fromStdString(aFeature->getKind());
+  setActionEnabled(aFeatureId, true);
   setNestedCommandsEnabled(true, aFeatureId);
 
   setNestedStackEnabled(myOperationMgr->previousOperation(theOperation));
index 1fe9717fb9bf9f6623b39514ea2c530153f43fa5..dacd82f21309e94748432d0812e3d88dc9c5e504 100644 (file)
@@ -235,9 +235,10 @@ void XGUI_OperationMgr::onAbortOperation()
 void XGUI_OperationMgr::onOperationStarted()
 {
   ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
-  if (myOperations.count() == 1) {
-    emit nestedStateChanged(false);
-  }
+  
+  bool isNestedOk = (myOperations.count() >= 1) && 
+                     myOperations.at(0)->isValid();
+  emit nestedStateChanged(isNestedOk);
   emit operationStarted(aSenderOperation);
 }
 
@@ -250,7 +251,7 @@ void XGUI_OperationMgr::onOperationAborted()
 void XGUI_OperationMgr::onOperationCommitted()
 {
   ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
-  emit nestedStateChanged(true);
+  emit nestedStateChanged(myOperations.count() >= 1);
   emit operationCommitted(aSenderOperation);
 }
 
index 414ac4d66d07c793251863a6c5d81c5847ddad4c..312342e14e149a74d59eb5db486851325061f79b 100644 (file)
@@ -40,6 +40,13 @@ class XGUI_EXPORT XGUI_SalomeConnector
   virtual QAction* addFeature(const QString& theWBName,
                               const ActionInfo& theInfo) = 0;
 
+  //! Creates a feature (command) in SALOME desktop
+  //! \param theWBName - name of toolbar (workbench)
+  //! \param theInfo - information about action (icon, text, etc)
+  virtual QAction* addNestedFeature(const QString& theWBName,
+                                    const ActionInfo& theInfo,
+                                    const QList<QAction*>& theNestedActions) = 0;
+
   //! Creates a command in Edit menu of SALOME desktop
   //! \param theId - an id of the feature
   //! \param theTitle - a menu item string
index 42aa97e3000859a3b259ef7c55413428a5ca42b6..2ce90358a4d39955c2befe66419f860d8324ebdc 100644 (file)
@@ -762,8 +762,29 @@ void XGUI_Workshop::addFeature(const std::shared_ptr<Config_FeatureMessage>& the
   QStringList aNestedFeatures =
       QString::fromStdString(theMessage->nestedFeatures()).split(" ", QString::SkipEmptyParts);
   QString aDocKind = QString::fromStdString(theMessage->documentKind());
+  QList<QAction*> aNestedActList;
+  bool isColumnButton = !aNestedFeatures.isEmpty();
+  if (isColumnButton) {
+    QString aNestedActions = QString::fromStdString(theMessage->actionsWhenNested());
+    if (aNestedActions.contains("accept")) {
+      QAction* anAction = myActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptAll, NULL);
+      connect(anAction, SIGNAL(triggered()), myOperationMgr, SLOT(commitAllOperations()));
+      aNestedActList << anAction;
+    }
+    if (aNestedActions.contains("abort")) {
+      QAction* anAction = myActionsMgr->operationStateAction(XGUI_ActionsMgr::AbortAll, NULL);
+      connect(anAction, SIGNAL(triggered()), myOperationMgr, SLOT(abortAllOperations()));
+      aNestedActList << anAction;
+    }
+  }
+
   if (isSalomeMode()) {
-    QAction* aAction = salomeConnector()->addFeature(aWchName, aFeatureInfo);
+    QAction* aAction;
+    if (isColumnButton) {
+      aAction = salomeConnector()->addNestedFeature(aWchName, aFeatureInfo, aNestedActList);
+    } else {
+      aAction = salomeConnector()->addFeature(aWchName, aFeatureInfo);
+    }
     salomeConnector()->setNestedActions(aFeatureInfo.id, aNestedFeatures);
     salomeConnector()->setDocumentKind(aFeatureInfo.id, aDocKind);
 
@@ -794,19 +815,7 @@ void XGUI_Workshop::addFeature(const std::shared_ptr<Config_FeatureMessage>& the
     // Enrich created button with accept/abort buttons if necessary
     AppElements_Button* aButton = aCommand->button();
     if (aButton->isColumnButton()) {
-      QString aNestedActions = QString::fromStdString(theMessage->actionsWhenNested());
-      QList<QAction*> anActList;
-      if (aNestedActions.contains("accept")) {
-        QAction* anAction = myActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptAll, aButton);
-        connect(anAction, SIGNAL(triggered()), myOperationMgr, SLOT(commitAllOperations()));
-        anActList << anAction;
-      }
-      if (aNestedActions.contains("abort")) {
-        QAction* anAction = myActionsMgr->operationStateAction(XGUI_ActionsMgr::AbortAll, aButton);
-        connect(anAction, SIGNAL(triggered()), myOperationMgr, SLOT(abortAllOperations()));
-        anActList << anAction;
-      }
-      aButton->setAdditionalButtons(anActList);
+      aButton->setAdditionalButtons(aNestedActList);
     }
     myActionsMgr->addCommand(aCommand);
     myModule->actionCreated(aCommand);