From 1110c1ba786ea0de6b0e987dce93790868e8ad14 Mon Sep 17 00:00:00 2001 From: nds Date: Wed, 13 Jan 2016 13:36:24 +0300 Subject: [PATCH] Issue 812: "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 | 28 ++++++++---- src/PartSet/PartSet_Module.h | 4 +- src/PartSet/PartSet_SketcherMgr.cpp | 53 +++++++++++++++++------ src/PartSet/PartSet_SketcherMgr.h | 13 ++++-- src/PartSet/PartSet_Tools.h | 9 ++++ src/PartSet/PartSet_WidgetSketchLabel.cpp | 53 +++++++++++++++++------ src/PartSet/PartSet_WidgetSketchLabel.h | 27 ++++++++---- 7 files changed, 138 insertions(+), 49 deletions(-) diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 5baf6b713..7883d5279 100755 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -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::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&)), mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr&))); - 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& 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); } diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index 956d09544..7135b7c9b 100755 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -4,6 +4,7 @@ #define PartSet_Module_H #include "PartSet.h" +#include "PartSet_Tools.h" #include #include @@ -305,7 +306,8 @@ protected: PartSet_CustomPrs* myCustomPrs; int myVisualLayerId; - bool myHasConstraintShown; + /// backup of the visible state to restore them by operation stop + QMap myHasConstraintShown; QModelIndex aActivePartIndex; }; diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index eddc693bd..d9d19a2cf 100755 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -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(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(myModule->workshop()); @@ -1173,6 +1182,11 @@ bool PartSet_SketcherMgr::canChangeCursor(ModuleBase_Operation* theOperation) co myModule->sketchReentranceMgr()->isInternalEditActive(); } +const QMap& 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(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)); diff --git a/src/PartSet/PartSet_SketcherMgr.h b/src/PartSet/PartSet_SketcherMgr.h index 71ba10312..3b0a868c9 100644 --- a/src/PartSet/PartSet_SketcherMgr.h +++ b/src/PartSet/PartSet_SketcherMgr.h @@ -9,6 +9,8 @@ #include "PartSet.h" +#include "PartSet_Tools.h" + #include #include #include @@ -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& 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& 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 myIsConstraintsShown; }; diff --git a/src/PartSet/PartSet_Tools.h b/src/PartSet/PartSet_Tools.h index b7a31b4ac..310ac57a7 100755 --- a/src/PartSet/PartSet_Tools.h +++ b/src/PartSet/PartSet_Tools.h @@ -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 diff --git a/src/PartSet/PartSet_WidgetSketchLabel.cpp b/src/PartSet/PartSet_WidgetSketchLabel.cpp index a9496370b..d64f10952 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.cpp +++ b/src/PartSet/PartSet_WidgetSketchLabel.cpp @@ -55,10 +55,10 @@ 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& 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 aStates; + aStates[PartSet_Tools::Geometrical] = tr("Show geometrical constraints"); + aStates[PartSet_Tools::Dimensional] = tr("Show dimensional constraints"); + + QMap::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(sender()); + + QMap::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 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(myWorkshop); diff --git a/src/PartSet/PartSet_WidgetSketchLabel.h b/src/PartSet/PartSet_WidgetSketchLabel.h index 709c57efa..9d9092253 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.h +++ b/src/PartSet/PartSet_WidgetSketchLabel.h @@ -9,6 +9,8 @@ #include "PartSet.h" +#include "PartSet_Tools.h" + #include #include @@ -18,6 +20,8 @@ #include +#include + 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& 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& 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 myShowConstraints; + QStackedWidget* myStackWidget; }; -- 2.39.2