]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue 812:
authornds <nds@opencascade.com>
Wed, 13 Jan 2016 10:36:24 +0000 (13:36 +0300)
committerdbv <dbv@opencascade.com>
Tue, 16 Feb 2016 14:03:02 +0000 (17:03 +0300)
"In the Sketcher, it is required to be able to display or not separatly the dimensional and geometrical constraints. For that, a check button must be added in the panel of the Sketcher, by default both (""Show dimensional contraints"", ""Show geometrical contraints"") checked."

src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Module.h
src/PartSet/PartSet_SketcherMgr.cpp
src/PartSet/PartSet_SketcherMgr.h
src/PartSet/PartSet_Tools.h
src/PartSet/PartSet_WidgetSketchLabel.cpp
src/PartSet/PartSet_WidgetSketchLabel.h

index 5baf6b713997ab2ebc691e7491f6b1f4e41a5627..7883d527907c1939ad3abe19cf838d55646aa02b 100755 (executable)
@@ -110,7 +110,7 @@ extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop*
 
 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
 : ModuleBase_IModule(theWshop),
-  myVisualLayerId(0), myHasConstraintShown(true)
+  myVisualLayerId(0)
 {
   new PartSet_IconFactory();
 
@@ -139,6 +139,9 @@ PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
 
   mySelectionFilters.Append(new PartSet_GlobalFilter(myWorkshop));
   mySelectionFilters.Append(new PartSet_FilterInfinite(myWorkshop));
+
+  myHasConstraintShown[PartSet_Tools::Geometrical] = true;
+  myHasConstraintShown[PartSet_Tools::Dimensional] = true;
 }
 
 PartSet_Module::~PartSet_Module()
@@ -283,7 +286,13 @@ void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
     XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
     aDisplayer->updateViewer();
   }
-  mySketchMgr->onShowConstraintsToggle(myHasConstraintShown);
+
+  QMap<PartSet_Tools::ConstraintVisibleState, bool>::const_iterator anIt = myHasConstraintShown.begin(),
+                                                                    aLast = myHasConstraintShown.end();
+  for (; anIt != aLast; anIt++) {
+    myHasConstraintShown[anIt.key()];
+    mySketchMgr->onShowConstraintsToggle(anIt.value(), myHasConstraintShown[anIt.key()]);
+  }
 }
 
 ModuleBase_Operation* PartSet_Module::currentOperation() const
@@ -487,11 +496,11 @@ ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& th
   ModuleBase_ModelWidget* aWgt = NULL;
   if (theType == "sketch-start-label") {
     PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, aWorkshop,
-      theWidgetApi, theParentId, mySketchMgr->isConstraintsShown());
+      theWidgetApi, theParentId, mySketchMgr->showConstraintStates());
     connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
       mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
-    connect(aLabelWgt, SIGNAL(showConstraintToggled(bool)),
-      mySketchMgr, SLOT(onShowConstraintsToggle(bool)));
+    connect(aLabelWgt, SIGNAL(showConstraintToggled(bool, int)),
+      mySketchMgr, SLOT(onShowConstraintsToggle(bool, int)));
     aWgt = aLabelWgt;
   } else if (theType == "sketch-2dpoint_selector") {
     PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, aWorkshop,
@@ -638,11 +647,14 @@ void PartSet_Module::onFeatureTriggered()
 void PartSet_Module::launchOperation(const QString& theCmdId)
 {
   if (myWorkshop->currentOperation() && 
-      myWorkshop->currentOperation()->id().toStdString() == SketchPlugin_Sketch::ID())
-    myHasConstraintShown = mySketchMgr->isConstraintsShown();
+      myWorkshop->currentOperation()->id().toStdString() == SketchPlugin_Sketch::ID()) {
+      const QMap<PartSet_Tools::ConstraintVisibleState, bool>& aShownStates = mySketchMgr->showConstraintStates();
+      myHasConstraintShown = aShownStates;
+  }
   if (PartSet_SketcherMgr::constraintsIdList().contains(theCmdId)) {
     // Show constraints if a constraint was anOperation
-    mySketchMgr->onShowConstraintsToggle(true);
+    mySketchMgr->onShowConstraintsToggle(true, PartSet_Tools::Geometrical);
+    mySketchMgr->onShowConstraintsToggle(true, PartSet_Tools::Dimensional);
   }
   ModuleBase_IModule::launchOperation(theCmdId);
 }
index 956d0954474c662c827673932ab666d4ff6a9662..7135b7c9ba1695e8ede67ef25c6a5528afd99ead 100755 (executable)
@@ -4,6 +4,7 @@
 #define PartSet_Module_H
 
 #include "PartSet.h"
+#include "PartSet_Tools.h"
 
 #include <ModuleBase_IModule.h>
 #include <ModuleBase_Definitions.h>
@@ -305,7 +306,8 @@ protected:
   PartSet_CustomPrs* myCustomPrs;
   int myVisualLayerId;
 
-  bool myHasConstraintShown;
+  /// backup of the visible state to restore them by operation stop
+  QMap<PartSet_Tools::ConstraintVisibleState, bool> myHasConstraintShown;
 
   QModelIndex aActivePartIndex;
 };
index eddc693bd300bd910d6388d00baa65facc5cbfa0..d9d19a2cfa03cdf025d189c8e8f8cf97a7cb3821 100755 (executable)
@@ -159,7 +159,7 @@ PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule)
   : QObject(theModule), myModule(theModule), myIsDragging(false), myDragDone(false),
     myIsMouseOverWindow(false),
     myIsMouseOverViewProcessed(true), myPreviousUpdateViewerEnabled(true),
-    myIsPopupMenuActive(false), myIsConstraintsShown(true)
+    myIsPopupMenuActive(false)
 {
   ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
   ModuleBase_IViewer* aViewer = anIWorkshop->viewer();
@@ -181,6 +181,9 @@ PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule)
   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
   XGUI_Workshop* aWorkshop = aConnector->workshop();
   connect(aWorkshop, SIGNAL(applicationStarted()), this, SLOT(onApplicationStarted()));
+
+  myIsConstraintsShown[PartSet_Tools::Geometrical] = true;
+  myIsConstraintsShown[PartSet_Tools::Dimensional] = true;
 }
 
 PartSet_SketcherMgr::~PartSet_SketcherMgr()
@@ -806,12 +809,17 @@ bool PartSet_SketcherMgr::isEntity(const std::string& theId)
 
 bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation)
 {
-  std::string aId = theOperation ? theOperation->id().toStdString() : "";
+  std::string anId = theOperation ? theOperation->id().toStdString() : "";
 
-  return (aId == SketchPlugin_ConstraintLength::ID()) ||
-         (aId == SketchPlugin_ConstraintDistance::ID()) ||
-         (aId == SketchPlugin_ConstraintRadius::ID()) ||
-         (aId == SketchPlugin_ConstraintAngle::ID());
+  return isDistanceKind(anId);
+}
+
+bool PartSet_SketcherMgr::isDistanceKind(std::string& theKind)
+{
+  return (theKind == SketchPlugin_ConstraintLength::ID()) ||
+         (theKind == SketchPlugin_ConstraintDistance::ID()) ||
+         (theKind == SketchPlugin_ConstraintRadius::ID()) ||
+         (theKind == SketchPlugin_ConstraintAngle::ID());
 }
 
 void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
@@ -872,7 +880,8 @@ void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
 {
   myIsMouseOverWindow = false;
-  myIsConstraintsShown = true;
+  myIsConstraintsShown[PartSet_Tools::Geometrical] = true;
+  myIsConstraintsShown[PartSet_Tools::Dimensional] = true;
 
   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
 
@@ -1173,6 +1182,11 @@ bool PartSet_SketcherMgr::canChangeCursor(ModuleBase_Operation* theOperation) co
          myModule->sketchReentranceMgr()->isInternalEditActive();
 }
 
+const QMap<PartSet_Tools::ConstraintVisibleState, bool>& PartSet_SketcherMgr::showConstraintStates()
+{
+  return myIsConstraintsShown;
+}
+
 bool PartSet_SketcherMgr::isObjectOfSketch(const ObjectPtr& theObject) const
 {
   bool isFoundObject = false;
@@ -1440,14 +1454,15 @@ void PartSet_SketcherMgr::restoreSelection()
   }
 }
 
-void PartSet_SketcherMgr::onShowConstraintsToggle(bool theOn)
+void PartSet_SketcherMgr::onShowConstraintsToggle(bool theState, int theType)
 {
-  if (myIsConstraintsShown == theOn)
+  PartSet_Tools::ConstraintVisibleState aType = (PartSet_Tools::ConstraintVisibleState)theType;
+  if (myIsConstraintsShown.contains(aType) && myIsConstraintsShown[aType] == theState)
     return;
   if (myCurrentSketch.get() == NULL)
     return;
 
-  myIsConstraintsShown = theOn;
+  myIsConstraintsShown[aType] = theState;
 
   ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
@@ -1455,11 +1470,21 @@ void PartSet_SketcherMgr::onShowConstraintsToggle(bool theOn)
   const QStringList& aConstrIds = constraintsIdList();
   for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
     FeaturePtr aSubFeature = myCurrentSketch->subFeature(i);
-    if (aConstrIds.contains(QString(aSubFeature->getKind().c_str()))) {
-      if (myIsConstraintsShown) 
-        aSubFeature->setDisplayed(true);
+    std::string aKind = aSubFeature->getKind();
+    if (aConstrIds.contains(QString(aKind.c_str()))) {
+      bool isTypedConstraint = false;
+      if (aType == PartSet_Tools::Dimensional) {
+        isTypedConstraint = isDistanceKind(aKind);
+      }
       else
-        aSubFeature->setDisplayed(false);
+        isTypedConstraint = !isDistanceKind(aKind);
+
+      if (isTypedConstraint) {
+        if (theState)
+          aSubFeature->setDisplayed(true);
+        else
+          aSubFeature->setDisplayed(false);
+      }
     }
   }
   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
index 71ba10312df149bec88947b6d5bb2cb2e3536c80..3b0a868c93e5f57cb9ab896b1a204cc23eaba857 100644 (file)
@@ -9,6 +9,8 @@
 
 #include "PartSet.h"
 
+#include "PartSet_Tools.h"
+
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_Attribute.h>
 #include <ModelAPI_CompositeFeature.h>
@@ -109,6 +111,11 @@ public:
   /// \return a boolean value
   static bool isDistanceOperation(ModuleBase_Operation* theOperation);
 
+  /// Returns whether the feature kind is a sketch distance - lenght, distance or radius
+  /// \param theKind the feature kind
+  /// \return a boolean value
+  static bool isDistanceKind(std::string& theKind);
+
   /// Returns true if a mouse cursor is over viewer window
   bool isMouseOverWindow() { return myIsMouseOverWindow; }
 
@@ -169,7 +176,7 @@ public:
   bool canChangeCursor(ModuleBase_Operation* theOperation) const;
 
   /// Returns state of constraints showing flag 
-  bool isConstraintsShown() const { return myIsConstraintsShown; }
+  const QMap<PartSet_Tools::ConstraintVisibleState, bool>& showConstraintStates();
 
   /// Returns true if the object is a current sketch sub feature of a result of the feature
   /// \param theObject an object
@@ -222,7 +229,7 @@ public slots:
   void onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
 
   /// Toggle show constraints
-  void onShowConstraintsToggle(bool);
+  void onShowConstraintsToggle(bool theState, int theType);
 
 private slots:
   /// Process the enter mouse to the view port. If the current operation is a create of
@@ -329,7 +336,7 @@ private:
   FeatureToSelectionMap myCurrentSelection;
   bool myPreviousUpdateViewerEnabled;
 
-  bool myIsConstraintsShown;
+  QMap<PartSet_Tools::ConstraintVisibleState, bool> myIsConstraintsShown;
 };
 
 
index b7a31b4acabb4cf59ddcbc28b2eb2e627fe00044..310ac57a7ae929a9792bb6cddfa7665335b7d888 100755 (executable)
@@ -40,6 +40,15 @@ class GeomAPI_Vertex;
  */
 class PARTSET_EXPORT PartSet_Tools
 {
+public:
+  /// \enum ConstraintVisibleState types of constraints which visible state can be
+  /// changed in the sketch widget
+  enum ConstraintVisibleState
+  {
+    Geometrical = 0, // all constrains excepting dimensional
+    Dimensional // lenght, distance, radius and angle constraints
+  };
+
  public:
   /// Converts the 2D screen point to the 3D point on the view according to the point of view
   /// \param thePoint a screen point
index a9496370befd642c1546bc5f83205f52c47536e5..d64f10952c46dc8c4f8dd29cfc8d0d2b19369098 100644 (file)
 
 
 PartSet_WidgetSketchLabel::PartSet_WidgetSketchLabel(QWidget* theParent,
-                                                     ModuleBase_IWorkshop* theWorkshop,
-                                                     const Config_WidgetAPI* theData,
-                                                     const std::string& theParentId,
-                                                     bool toShowConstraints)
+                        ModuleBase_IWorkshop* theWorkshop,
+                        const Config_WidgetAPI* theData,
+                        const std::string& theParentId,
+                        const QMap<PartSet_Tools::ConstraintVisibleState, bool>& toShowConstraints)
 : ModuleBase_WidgetValidated(theParent, theWorkshop, theData, theParentId),
   myPreviewDisplayed(false)
 {
@@ -102,10 +102,23 @@ PartSet_WidgetSketchLabel::PartSet_WidgetSketchLabel(QWidget* theParent,
 
   aLayout->addWidget(aViewBox);
 
-  myShowConstraints = new QCheckBox(tr("Show constraints"), this);
-  connect(myShowConstraints, SIGNAL(toggled(bool)), this, SIGNAL(showConstraintToggled(bool)));
-  myShowConstraints->setChecked(toShowConstraints);
-  aLayout->addWidget(myShowConstraints);
+  QMap<PartSet_Tools::ConstraintVisibleState, QString> aStates;
+  aStates[PartSet_Tools::Geometrical] = tr("Show geometrical constraints");
+  aStates[PartSet_Tools::Dimensional] = tr("Show dimensional constraints");
+
+  QMap<PartSet_Tools::ConstraintVisibleState, QString>::const_iterator anIt = aStates.begin(),
+                                                        aLast = aStates.end();
+  for (; anIt != aLast; anIt++) {
+    QCheckBox* aShowConstraints = new QCheckBox(anIt.value(), this);
+    connect(aShowConstraints, SIGNAL(toggled(bool)), this, SLOT(onShowConstraint(bool)));
+    aLayout->addWidget(aShowConstraints);
+
+    PartSet_Tools::ConstraintVisibleState aState = anIt.key();
+    myShowConstraints[aState] = aShowConstraints;
+
+    if (toShowConstraints.contains(aState))
+      aShowConstraints->setChecked(toShowConstraints[aState]);
+  }
 
   myStackWidget->addWidget(aSecondWgt);
   //setLayout(aLayout);
@@ -154,6 +167,24 @@ void PartSet_WidgetSketchLabel::onSelectionChanged()
   }
 }
 
+void PartSet_WidgetSketchLabel::onShowConstraint(bool theOn)
+{
+  QCheckBox* aSenderCheckBox = qobject_cast<QCheckBox*>(sender());
+
+  QMap<PartSet_Tools::ConstraintVisibleState, QCheckBox*>::const_iterator
+                          anIt = myShowConstraints.begin(), aLast = myShowConstraints.end();
+
+  PartSet_Tools::ConstraintVisibleState aState = PartSet_Tools::Geometrical;
+  bool aFound = false;
+  for (; anIt != aLast && !aFound; anIt++) {
+    aFound = anIt.value() == aSenderCheckBox;
+    if (aFound)
+      aState = anIt.key();
+  }
+  if (aFound)
+    emit showConstraintToggled(theOn, aState);
+}
+
 void PartSet_WidgetSketchLabel::updateByPlaneSelected(const ModuleBase_ViewerPrs& thePrs)
 {
   // 1. hide main planes if they have been displayed
@@ -473,12 +504,6 @@ std::shared_ptr<GeomAPI_Dir> PartSet_WidgetSketchLabel::setSketchPlane(const Top
   return aDir;
 }
 
-void PartSet_WidgetSketchLabel::showConstraints(bool theOn)
-{
-  myShowConstraints->setChecked(theOn);
-  emit showConstraintToggled(theOn);
-}
-
 XGUI_Workshop* PartSet_WidgetSketchLabel::workshop() const
 {
   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
index 709c57efa0f7ce68d0c78c5215b7bd855d3ec6d6..9d909225380c49293367ecce7f25c539455ef701 100644 (file)
@@ -9,6 +9,8 @@
 
 #include "PartSet.h"
 
+#include "PartSet_Tools.h"
+
 #include <ModuleBase_WidgetValidated.h>
 #include <ModuleBase_ViewerFilters.h>
 
@@ -18,6 +20,8 @@
 
 #include <TopoDS_Shape.hxx>
 
+#include <QMap>
+
 class QLabel;
 class XGUI_OperationMgr;
 class XGUI_Workshop;
@@ -38,7 +42,8 @@ class QStackedWidget;
 class PARTSET_EXPORT PartSet_WidgetSketchLabel : public ModuleBase_WidgetValidated
 {
 Q_OBJECT
- public:
+
+public:
   /// Constructor
   /// \param theParent the parent object
   /// \param theWorkshop a reference to workshop
@@ -46,8 +51,9 @@ Q_OBJECT
   /// \param theParentId is Id of a parent of the current attribute
   /// \param toShowConstraints a current show constraints state
   PartSet_WidgetSketchLabel(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
-                            const Config_WidgetAPI* theData,
-                            const std::string& theParentId, bool toShowConstraints);
+                      const Config_WidgetAPI* theData,
+                      const std::string& theParentId,
+                      const QMap<PartSet_Tools::ConstraintVisibleState, bool>& toShowConstraints);
 
   virtual ~PartSet_WidgetSketchLabel();
 
@@ -75,16 +81,14 @@ Q_OBJECT
   virtual void setHighlighted(bool) { /*do nothing*/ };
   virtual void enableFocusProcessing();
 
-  /// Set show constraints state
-  /// \param theOn a flag show constraints or not
-  void showConstraints(bool theOn);
-
 signals:
   /// Signal on plane selection
   void planeSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
 
   /// A show constraint toggled signal
-  void showConstraintToggled(bool);
+  /// \param theState a state of the check box
+  /// \param theType a ConstraintVisibleState value
+  void showConstraintToggled(bool theState, int theType);
 
 protected:
   /// Creates a backup of the current values of the attribute
@@ -132,6 +136,10 @@ protected:
   /// A slot called on set sketch plane view
   void onSetPlaneView();
 
+  /// Emits signal about check box state changed with information about ConstraintVisibleState
+  /// \param theOn a flag show constraints or not
+  void onShowConstraint(bool theOn);
+
  private:
    /// Create preview of planes for sketch plane selection
    /// \param theOrigin an origin of the plane
@@ -160,9 +168,10 @@ protected:
   AISObjectPtr myXYPlane;
   bool myPreviewDisplayed;
 
-  QCheckBox* myShowConstraints;
   QCheckBox* myViewInverted;
 
+  QMap<PartSet_Tools::ConstraintVisibleState, QCheckBox*> myShowConstraints;
+
   QStackedWidget* myStackWidget;
 };