"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."
PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
: ModuleBase_IModule(theWshop),
- myVisualLayerId(0), myHasConstraintShown(true)
+ myVisualLayerId(0)
{
new PartSet_IconFactory();
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()
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
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,
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);
}
#define PartSet_Module_H
#include "PartSet.h"
+#include "PartSet_Tools.h"
#include <ModuleBase_IModule.h>
#include <ModuleBase_Definitions.h>
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;
};
: 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();
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()
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)
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());
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;
}
}
-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);
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));
#include "PartSet.h"
+#include "PartSet_Tools.h"
+
#include <ModelAPI_Feature.h>
#include <ModelAPI_Attribute.h>
#include <ModelAPI_CompositeFeature.h>
/// \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; }
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
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
FeatureToSelectionMap myCurrentSelection;
bool myPreviousUpdateViewerEnabled;
- bool myIsConstraintsShown;
+ QMap<PartSet_Tools::ConstraintVisibleState, bool> myIsConstraintsShown;
};
*/
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
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)
{
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);
}
}
+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
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);
#include "PartSet.h"
+#include "PartSet_Tools.h"
+
#include <ModuleBase_WidgetValidated.h>
#include <ModuleBase_ViewerFilters.h>
#include <TopoDS_Shape.hxx>
+#include <QMap>
+
class QLabel;
class XGUI_OperationMgr;
class XGUI_Workshop;
class PARTSET_EXPORT PartSet_WidgetSketchLabel : public ModuleBase_WidgetValidated
{
Q_OBJECT
- public:
+
+public:
/// Constructor
/// \param theParent the parent object
/// \param theWorkshop a reference to workshop
/// \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();
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
/// 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
AISObjectPtr myXYPlane;
bool myPreviewDisplayed;
- QCheckBox* myShowConstraints;
QCheckBox* myViewInverted;
+ QMap<PartSet_Tools::ConstraintVisibleState, QCheckBox*> myShowConstraints;
+
QStackedWidget* myStackWidget;
};