From: vsv Date: Fri, 3 Apr 2015 16:44:42 +0000 (+0300) Subject: Create pop-up menu for lines detaching X-Git-Tag: V_1.1.0~57^2~6 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b4af7c209464c888a264ca5db5d2907fd2b6e189;p=modules%2Fshaper.git Create pop-up menu for lines detaching --- diff --git a/src/PartSet/CMakeLists.txt b/src/PartSet/CMakeLists.txt index 59affd8ca..8b85b15c6 100644 --- a/src/PartSet/CMakeLists.txt +++ b/src/PartSet/CMakeLists.txt @@ -19,6 +19,7 @@ SET(PROJECT_HEADERS PartSet_Filters.h PartSet_FilterSketchEntity.h PartSet_SketcherMgr.h + PartSet_MenuMgr.h ) SET(PROJECT_SOURCES @@ -34,6 +35,7 @@ SET(PROJECT_SOURCES PartSet_Filters.cpp PartSet_FilterSketchEntity.cpp PartSet_SketcherMgr.cpp + PartSet_MenuMgr.cpp ) SET(PROJECT_RESOURCES diff --git a/src/PartSet/PartSet_MenuMgr.cpp b/src/PartSet/PartSet_MenuMgr.cpp new file mode 100644 index 000000000..9b02aee05 --- /dev/null +++ b/src/PartSet/PartSet_MenuMgr.cpp @@ -0,0 +1,387 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: PartSet_MenuMgr.cpp +// Created: 03 April 2015 +// Author: Vitaly SMETANNIKOV + +#include "PartSet_MenuMgr.h" +#include "PartSet_Module.h" +#include "PartSet_SketcherMgr.h" + +#include +#include + +#include +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include +#include +#include + +#include +#include + +PartSet_MenuMgr::PartSet_MenuMgr(PartSet_Module* theModule) + : QObject(theModule), myModule(theModule), myPrevId(-1) +{ + createActions(); +} + + +QAction* PartSet_MenuMgr::action(const QString& theId) const +{ + if (myActions.contains(theId)) + return myActions[theId]; + return 0; +} + +void PartSet_MenuMgr::addAction(const QString& theId, QAction* theAction) +{ + if (myActions.contains(theId)) + qCritical("A command with Id = '%s' already defined!", qPrintable(theId)); + theAction->setData(theId); + connect(theAction, SIGNAL(triggered(bool)), this, SLOT(onAction(bool))); + myActions[theId] = theAction; +} + +void PartSet_MenuMgr::createActions() +{ + QAction* anAction; + + anAction = new QAction(tr("Auxiliary"), this); + anAction->setCheckable(true); + addAction("AUXILIARY_CMD", anAction); +} + + +void PartSet_MenuMgr::onAction(bool isChecked) +{ + QAction* aAction = static_cast(sender()); + QString anId = aAction->data().toString(); + + if (anId == "AUXILIARY_CMD") { + setAuxiliary(isChecked); + } +} + +/// Returns point of coincidence feature +/// \param theFeature the coincidence feature +/// \param theAttribute the attribute name +std::shared_ptr getPoint(std::shared_ptr& theFeature, + const std::string& theAttribute) +{ + std::shared_ptr aPointAttr; + + if (!theFeature->data()) + return std::shared_ptr(); + + FeaturePtr aFeature; + std::shared_ptr anAttr = std::dynamic_pointer_cast< + ModelAPI_AttributeRefAttr>(theFeature->data()->attribute(theAttribute)); + if (anAttr) + aFeature = ModelAPI_Feature::feature(anAttr->object()); + + if (aFeature && aFeature->getKind() == SketchPlugin_Point::ID()) + aPointAttr = std::dynamic_pointer_cast( + aFeature->data()->attribute(SketchPlugin_Point::COORD_ID())); + + else if (aFeature && aFeature->getKind() == SketchPlugin_Circle::ID()) + aPointAttr = std::dynamic_pointer_cast( + aFeature->data()->attribute(SketchPlugin_Circle::CENTER_ID())); + + else if (anAttr->attr()) { + aPointAttr = std::dynamic_pointer_cast(anAttr->attr()); + } + if (aPointAttr.get() != NULL) + return aPointAttr->pnt(); + return std::shared_ptr(); +} + +/// Returns list of features connected in a councedence feature point +/// \param theStartCoin the coincidence feature +/// \param theList a list which collects lines features +/// \param theAttr the attribute name +void findCoincidences(FeaturePtr theStartCoin, QList& theList, std::string theAttr) +{ + AttributeRefAttrPtr aPnt = theStartCoin->refattr(theAttr); + FeaturePtr aObj = ModelAPI_Feature::feature(aPnt->object()); + if (!theList.contains(aObj)) { + std::shared_ptr aOrig = getPoint(theStartCoin, theAttr); + theList.append(aObj); + const std::set aRefsList = aObj->data()->refsToMe(); + std::set::const_iterator aIt; + for (aIt = aRefsList.cbegin(); aIt != aRefsList.cend(); ++aIt) { + std::shared_ptr aAttr = (*aIt); + FeaturePtr aConstrFeature = std::dynamic_pointer_cast(aAttr->owner()); + if (aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) { + std::shared_ptr aPnt = getPoint(aConstrFeature, theAttr); + if (aOrig->isEqual(aPnt)) { + findCoincidences(aConstrFeature, theList, SketchPlugin_ConstraintCoincidence::ENTITY_A()); + findCoincidences(aConstrFeature, theList, SketchPlugin_ConstraintCoincidence::ENTITY_B()); + } + } + } + } +} + + +bool PartSet_MenuMgr::addViewerItems(QMenu* theMenu, const QMap& theStdActions) const +{ + ModuleBase_Operation* anOperation = myModule->workshop()->currentOperation(); + if (!PartSet_SketcherMgr::isSketchOperation(anOperation) && + !PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) + return false; + + myCoinsideLines.clear(); + ModuleBase_ISelection* aSelection = myModule->workshop()->selection(); + QObjectPtrList aObjects = aSelection->selectedPresentations(); + if (aObjects.size() > 0) { + bool hasFeature = false; + FeaturePtr aFeature; + foreach(ObjectPtr aObject, aObjects) { + aFeature = ModelAPI_Feature::feature(aObject); + if (aFeature.get() != NULL) { + hasFeature = true; + } + } + if (hasFeature) { + bool aIsDetach = false; + if (aObjects.size() == 1) { + if (aFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) { + /// If the feature is coincident then we use Detach command instead Delete + mySelectedFeature = aFeature; + findCoincidences(mySelectedFeature, myCoinsideLines, SketchPlugin_ConstraintCoincidence::ENTITY_A()); + findCoincidences(mySelectedFeature, myCoinsideLines, SketchPlugin_ConstraintCoincidence::ENTITY_B()); + if (myCoinsideLines.size() > 0) { + aIsDetach = true; + QMenu* aSubMenu = theMenu->addMenu(tr("Detach")); + QAction* aAction; + int i = 0; + foreach (FeaturePtr aCoins, myCoinsideLines) { + aAction = aSubMenu->addAction(aCoins->data()->name().c_str()); + aAction->setData(QVariant(i)); + i++; + } + connect(aSubMenu, SIGNAL(hovered(QAction*)), SLOT(onLineHighlighted(QAction*))); + connect(aSubMenu, SIGNAL(aboutToHide()), SLOT(onDetachMenuHide())); + connect(aSubMenu, SIGNAL(triggered(QAction*)), SLOT(onLineDetach(QAction*))); + } + } + } + if (!aIsDetach) + theMenu->addAction(theStdActions["DELETE_CMD"]); + } + } + bool isAuxiliary; + if (canSetAuxiliary(isAuxiliary)) { + QAction* anAction = action("AUXILIARY_CMD"); + theMenu->addAction(anAction); + anAction->setChecked(isAuxiliary); + } + return true; +} + +void PartSet_MenuMgr::onLineHighlighted(QAction* theAction) +{ + if (myPrevId != -1) { + // Restore color for previous object + setLineColor(myPrevId, myColor, false); + } + myPrevId = theAction->data().toInt(); + myColor = setLineColor(myPrevId, Qt::white, true); +} + +QColor PartSet_MenuMgr::setLineColor(int theId, const QColor theColor, bool theUpdate) +{ + XGUI_ModuleConnector* aConnector = dynamic_cast(myModule->workshop()); + XGUI_Workshop* aWorkshop = aConnector->workshop(); + XGUI_Displayer* aDisplayer = aWorkshop->displayer(); + + FeaturePtr aLine = myCoinsideLines.at(myPrevId); + std::list::const_iterator aIt; + const std::list& aResults = aLine->results(); + QColor aColor; + for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) { + aColor = aDisplayer->setObjectColor((*aIt), theColor, false); + } + if (theUpdate) + aDisplayer->updateViewer(); + return aColor; +} + + +void PartSet_MenuMgr::onLineDetach(QAction* theAction) +{ + int aId = theAction->data().toInt(); + FeaturePtr aLine = myCoinsideLines.at(aId); + std::shared_ptr aOrig = getPoint(mySelectedFeature, SketchPlugin_ConstraintCoincidence::ENTITY_A()); + gp_Pnt aOr = aOrig->impl(); + const std::set& aRefsList = aLine->data()->refsToMe(); + + QObjectPtrList aToDelFeatures; + std::set::const_iterator aIt; + // Find all coincedences corresponded to the selected line in the selected point + for (aIt = aRefsList.cbegin(); aIt != aRefsList.cend(); ++aIt) { + std::shared_ptr aAttr = (*aIt); + FeaturePtr aConstrFeature = std::dynamic_pointer_cast(aAttr->owner()); + if (aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) { + std::shared_ptr aPnt = getPoint(aConstrFeature, SketchPlugin_ConstraintCoincidence::ENTITY_A()); + gp_Pnt aP = aPnt->impl(); + if (aOrig->isEqual(aPnt)) { + aToDelFeatures.append(aConstrFeature); + } else { + aPnt = getPoint(aConstrFeature, SketchPlugin_ConstraintCoincidence::ENTITY_B()); + aP = aPnt->impl(); + if (aOrig->isEqual(aPnt)) { + aToDelFeatures.append(aConstrFeature); + break; + } + } + } + } + if (aToDelFeatures.size() > 0) { + XGUI_ModuleConnector* aConnector = dynamic_cast(myModule->workshop()); + XGUI_Workshop* aWorkshop = aConnector->workshop(); + ModuleBase_Operation* anOperation = myModule->workshop()->currentOperation(); + if (PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) + anOperation->abort(); + + SessionPtr aMgr = ModelAPI_Session::get(); + std::set anIgnoredFeatures; + anIgnoredFeatures.insert(myModule->sketchMgr()->activeSketch()); + + QString aName = tr("Detach %1").arg(aLine->data()->name().c_str()); + aMgr->startOperation(aName.toStdString()); + aWorkshop->deleteFeatures(aToDelFeatures, anIgnoredFeatures); + aMgr->finishOperation(); + } + myCoinsideLines.clear(); +} + + +void PartSet_MenuMgr::onDetachMenuHide() +{ + if (myPrevId != -1) { + // Restore color for previous object + setLineColor(myPrevId, myColor, false); + } + // Clear previous definitions + myPrevId = -1; +} + + +void PartSet_MenuMgr::setAuxiliary(const bool isChecked) +{ + ModuleBase_Operation* anOperation = myModule->workshop()->currentOperation(); + + bool isActiveSketch = PartSet_SketcherMgr::isSketchOperation(anOperation) || + PartSet_SketcherMgr::isNestedSketchOperation(anOperation); + if (!isActiveSketch) + return; + + QObjectPtrList anObjects; + bool isUseTransaction = false; + // 1. change auxiliary type of a created feature + if (PartSet_SketcherMgr::isNestedCreateOperation(anOperation) && + PartSet_SketcherMgr::isEntityOperation(anOperation) ) { + anObjects.append(anOperation->feature()); + } + else { + isUseTransaction = true; + // 2. change auxiliary type of selected sketch entities + ModuleBase_ISelection* aSelection = myModule->workshop()->selection(); + anObjects = aSelection->selectedPresentations(); + } + + QAction* anAction = action("AUXILIARY_CMD"); + SessionPtr aMgr = ModelAPI_Session::get(); + if (isUseTransaction) { + if (PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) + anOperation->abort(); + aMgr->startOperation(anAction->text().toStdString()); + } + myModule->sketchMgr()->storeSelection(); + + if (anObjects.size() > 0) { + QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end(); + for (; anIt != aLast; anIt++) { + FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt); + if (aFeature.get() != NULL) { + std::shared_ptr aSketchFeature = + std::dynamic_pointer_cast(aFeature); + if (aSketchFeature.get() != NULL) { + std::string anAttribute = SketchPlugin_SketchEntity::AUXILIARY_ID(); + + std::shared_ptr anAuxiliaryAttr = + std::dynamic_pointer_cast(aSketchFeature->data()->attribute(anAttribute)); + if (anAuxiliaryAttr) + anAuxiliaryAttr->setValue(isChecked); + } + } + } + } + if (isUseTransaction) { + aMgr->finishOperation(); + } + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); + myModule->sketchMgr()->restoreSelection(); +} + +bool PartSet_MenuMgr::canSetAuxiliary(bool& theValue) const +{ + bool anEnabled = false; + ModuleBase_Operation* anOperation = myModule->workshop()->currentOperation(); + + bool isActiveSketch = PartSet_SketcherMgr::isSketchOperation(anOperation) || + PartSet_SketcherMgr::isNestedSketchOperation(anOperation); + if (!isActiveSketch) + return anEnabled; + + QObjectPtrList anObjects; + // 1. change auxiliary type of a created feature + if (PartSet_SketcherMgr::isNestedCreateOperation(anOperation) && + PartSet_SketcherMgr::isEntityOperation(anOperation) ) { + anObjects.append(anOperation->feature()); + } + else { + /// The operation should not be aborted here, because the method does not changed + /// the auxilliary state, but checks the possibility to perform this + ///if (PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) + /// anOperation->abort(); + // 2. change auxiliary type of selected sketch entities + ModuleBase_ISelection* aSelection = myModule->workshop()->selection(); + anObjects = aSelection->selectedPresentations(); + } + anEnabled = anObjects.size() > 0; + + bool isNotAuxiliaryFound = false; + if (anObjects.size() > 0) { + QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end(); + for (; anIt != aLast && !isNotAuxiliaryFound; anIt++) { + FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt); + if (aFeature.get() != NULL) { + std::shared_ptr aSketchFeature = + std::dynamic_pointer_cast(aFeature); + if (aSketchFeature.get() != NULL) { + std::string anAttribute = SketchPlugin_SketchEntity::AUXILIARY_ID(); + + std::shared_ptr anAuxiliaryAttr = + std::dynamic_pointer_cast(aSketchFeature->data()->attribute(anAttribute)); + if (anAuxiliaryAttr) + isNotAuxiliaryFound = !anAuxiliaryAttr->value(); + } + } + } + } + theValue = anObjects.size() && !isNotAuxiliaryFound; + return anEnabled; +} diff --git a/src/PartSet/PartSet_MenuMgr.h b/src/PartSet/PartSet_MenuMgr.h new file mode 100644 index 000000000..117098644 --- /dev/null +++ b/src/PartSet/PartSet_MenuMgr.h @@ -0,0 +1,108 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: PartSet_MenuMgr.h +// Created: 03 April 2015 +// Author: Vitaly SMETANNIKOV + +#ifndef PartSet_MenuMgr_H +#define PartSet_MenuMgr_H + +#include + +#include +#include +#include +#include +#include + +class PartSet_Module; +class QAction; +class QMenu; + +/** +* \ingroup Modules +* A class for management of module specific menu +*/ +class PartSet_MenuMgr: public QObject +{ + Q_OBJECT +public: + /// Constructor + /// \param theModule a parent module + PartSet_MenuMgr(PartSet_Module* theModule); + + + /// Returns action according to the given ID + /// \param theId an action identifier, it should be uniqued in the bounds of the module + QAction* action(const QString& theId) const; + + /// Add menu atems for viewer into the given menu + /// \param theMenu a popup menu to be shown in the viewer + /// \param theStdActions a map of standard actions + /// \return true if items are added and there is no necessity to provide standard menu + bool addViewerItems(QMenu* theMenu, const QMap& theStdActions) const; + +public slots: + /// Processes the context menu action click + /// \param isChecked a state of toggle if the action is checkable + void onAction(bool isChecked); + +private slots: + + /// A slot which is called on selection of menu item coresponding to line with coincedence + /// \param theAction an action of the selected item + void onLineHighlighted(QAction* theAction); + + /// A slot which is called on hiding Detach menu + void onDetachMenuHide(); + + /// A slot which is called on selection an Item in Detach menu + /// \param theAction an action of the selected item + void onLineDetach(QAction* theAction); + +private: + /// Returns true if the current operation is sketch entity create operation + /// \param theValue the current auxiliary value + /// \return the boolean result + bool canSetAuxiliary(bool& theValue) const; + + /// Changes the sketcher entity construction argument value + /// \param isChecked if true, the feature is a construction + void setAuxiliary(const bool isChecked); + + /// Create all actions for context menus. It is called on creation of module + /// Put the created actions into an internal map + void createActions(); + + /// Add action to the internal map + /// \param theId - string ID of the item + /// \param theAction - action to add + void addAction(const QString& theId, QAction* theAction); + + /// Set color on presentation of result listed in myCoinsideLines + /// \param theId object Id in myCoinsideLines list + /// \param theColor a color which has to be set + /// \param theUpdate update viewer flag + /// \return previously defined color on the object + QColor setLineColor(int theId, const QColor theColor, bool theUpdate); + + /// Reference to a parent module + PartSet_Module* myModule; + + /// the popup menu actions + QMap myActions; + + /// List of lines coincided in a one point + mutable QList myCoinsideLines; + + /// A Coincedence feature selected by user for detaching + mutable FeaturePtr mySelectedFeature; + + /// Id of menu item in Detach menu previously selected + int myPrevId; + + /// Original color of highlighted line + QColor myColor; +}; + +#endif \ No newline at end of file diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index ee2f5727b..3d22b28a7 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -9,7 +9,8 @@ #include #include #include -#include +#include "PartSet_SketcherMgr.h" +#include "PartSet_MenuMgr.h" #include #include @@ -51,8 +52,9 @@ #include #include #include -//#include -//#include +#include +#include +#include #include #include #include @@ -114,7 +116,7 @@ PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop) connect(aViewer, SIGNAL(viewTransformed(int)), SLOT(onViewTransformed(int))); - createActions(); + myMenuMgr = new PartSet_MenuMgr(this); } PartSet_Module::~PartSet_Module() @@ -284,35 +286,10 @@ bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const return mySketchMgr->canDisplayObject(theObject); } + bool PartSet_Module::addViewerItems(QMenu* theMenu, const QMap& theStdActions) const { - ModuleBase_Operation* anOperation = myWorkshop->currentOperation(); - if (!PartSet_SketcherMgr::isSketchOperation(anOperation) && - !PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) - return false; - - ModuleBase_ISelection* aSelection = myWorkshop->selection(); - QObjectPtrList aObjects = aSelection->selectedPresentations(); - if (aObjects.size() > 0) { - bool hasFeature = false; - foreach(ObjectPtr aObject, aObjects) - { - FeaturePtr aFeature = ModelAPI_Feature::feature(aObject); - if (aFeature.get() != NULL) { - hasFeature = true; - } - } - if (hasFeature) { - theMenu->addAction(theStdActions["DELETE_CMD"]); - } - } - bool isAuxiliary; - if (mySketchMgr->canSetAuxiliary(isAuxiliary)) { - QAction* anAction = action("AUXILIARY_CMD"); - theMenu->addAction(anAction); - anAction->setChecked(isAuxiliary); - } - return true; + return myMenuMgr->addViewerItems(theMenu, theStdActions); } bool PartSet_Module::isMouseOverWindow() @@ -501,40 +478,6 @@ ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& th return aWgt; } -void PartSet_Module::createActions() -{ - QAction* anAction; - - anAction = new QAction(tr("Auxiliary"), this); - anAction->setCheckable(true); - addAction("AUXILIARY_CMD", anAction); -} - -QAction* PartSet_Module::action(const QString& theId) const -{ - if (myActions.contains(theId)) - return myActions[theId]; - return 0; -} - -void PartSet_Module::addAction(const QString& theId, QAction* theAction) -{ - if (myActions.contains(theId)) - qCritical("A command with Id = '%s' already defined!", qPrintable(theId)); - theAction->setData(theId); - connect(theAction, SIGNAL(triggered(bool)), this, SLOT(onAction(bool))); - myActions[theId] = theAction; -} - -void PartSet_Module::onAction(bool isChecked) -{ - QAction* aAction = static_cast(sender()); - QString anId = aAction->data().toString(); - - if (anId == "AUXILIARY_CMD") { - mySketchMgr->setAuxiliary(isChecked); - } -} bool PartSet_Module::deleteObjects() { diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index 904175b13..fe5387240 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -5,7 +5,6 @@ #include "PartSet.h" #include "PartSet_Filters.h" -#include "PartSet_SketcherMgr.h" #include #include @@ -26,6 +25,8 @@ class ModuleBase_Operation; class ModuleBase_IViewWindow; +class PartSet_MenuMgr; +class PartSet_SketcherMgr; class QAction; @@ -83,10 +84,6 @@ public: /// \param theOperation a started operation virtual ModuleBase_Operation* currentOperation() const; - /// Returns action according to the given ID - /// \param theId an action identifier, it should be uniqued in the bounds of the module - QAction* action(const QString& theId) const; - /// Returns True if there are available Undos and the sketch manager allows undo /// \return the boolean result virtual bool canUndo() const; @@ -111,15 +108,13 @@ public: /// \return true if items are added and there is no necessity to provide standard menu bool isMouseOverWindow(); + PartSet_SketcherMgr* sketchMgr() const { return mySketchMgr; } + public slots: /// SLOT, that is called by no more widget signal emitted by property panel /// Set a specific flag to restart the sketcher operation void onNoMoreWidgets(); - /// Processes the context menu action click - /// \param isChecked a state of toggle if the action is checkable - void onAction(bool isChecked); - /// Slolt called on object display /// \param theObject a data object /// \param theAIS a presentation object @@ -164,15 +159,6 @@ protected slots: /// Breaks sequense of automatically resterted operations void breakOperationSequence(); - /// Create all actions for context menus. It is called on creation of module - /// Put the created actions into an internal map - void createActions(); - - /// Add action to the internal map - /// \param theId - string ID of the item - /// \param theAction - action to add - void addAction(const QString& theId, QAction* theAction); - //! Delete features virtual bool deleteObjects(); @@ -188,7 +174,7 @@ protected slots: PartSet_SketcherMgr* mySketchMgr; - QMap myActions; // the popup menu actions + PartSet_MenuMgr* myMenuMgr; int myVisualLayerId; }; diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index 02c599ea9..359ee319e 100644 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -819,112 +819,6 @@ bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const return aCanDisplay; } -bool PartSet_SketcherMgr::canSetAuxiliary(bool& theValue) const -{ - bool anEnabled = false; - ModuleBase_Operation* anOperation = getCurrentOperation(); - - bool isActiveSketch = PartSet_SketcherMgr::isSketchOperation(anOperation) || - PartSet_SketcherMgr::isNestedSketchOperation(anOperation); - if (!isActiveSketch) - return anEnabled; - - QObjectPtrList anObjects; - // 1. change auxiliary type of a created feature - if (PartSet_SketcherMgr::isNestedCreateOperation(anOperation) && - PartSet_SketcherMgr::isEntityOperation(anOperation) ) { - anObjects.append(anOperation->feature()); - } - else { - /// The operation should not be aborted here, because the method does not changed - /// the auxilliary state, but checks the possibility to perform this - ///if (PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) - /// anOperation->abort(); - // 2. change auxiliary type of selected sketch entities - ModuleBase_ISelection* aSelection = myModule->workshop()->selection(); - anObjects = aSelection->selectedPresentations(); - } - anEnabled = anObjects.size() > 0; - - bool isNotAuxiliaryFound = false; - if (anObjects.size() > 0) { - QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end(); - for (; anIt != aLast && !isNotAuxiliaryFound; anIt++) { - FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt); - if (aFeature.get() != NULL) { - std::shared_ptr aSketchFeature = - std::dynamic_pointer_cast(aFeature); - if (aSketchFeature.get() != NULL) { - std::string anAttribute = SketchPlugin_SketchEntity::AUXILIARY_ID(); - - std::shared_ptr anAuxiliaryAttr = - std::dynamic_pointer_cast(aSketchFeature->data()->attribute(anAttribute)); - if (anAuxiliaryAttr) - isNotAuxiliaryFound = !anAuxiliaryAttr->value(); - } - } - } - } - theValue = anObjects.size() && !isNotAuxiliaryFound; - return anEnabled; -} - -void PartSet_SketcherMgr::setAuxiliary(const bool isChecked) -{ - ModuleBase_Operation* anOperation = getCurrentOperation(); - - bool isActiveSketch = PartSet_SketcherMgr::isSketchOperation(anOperation) || - PartSet_SketcherMgr::isNestedSketchOperation(anOperation); - if (!isActiveSketch) - return; - - QObjectPtrList anObjects; - bool isUseTransaction = false; - // 1. change auxiliary type of a created feature - if (PartSet_SketcherMgr::isNestedCreateOperation(anOperation) && - PartSet_SketcherMgr::isEntityOperation(anOperation) ) { - anObjects.append(anOperation->feature()); - } - else { - isUseTransaction = true; - // 2. change auxiliary type of selected sketch entities - ModuleBase_ISelection* aSelection = myModule->workshop()->selection(); - anObjects = aSelection->selectedPresentations(); - } - - QAction* anAction = myModule->action("AUXILIARY_CMD"); - SessionPtr aMgr = ModelAPI_Session::get(); - if (isUseTransaction) { - if (PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) - anOperation->abort(); - aMgr->startOperation(anAction->text().toStdString()); - } - storeSelection(); - - if (anObjects.size() > 0) { - QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end(); - for (; anIt != aLast; anIt++) { - FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt); - if (aFeature.get() != NULL) { - std::shared_ptr aSketchFeature = - std::dynamic_pointer_cast(aFeature); - if (aSketchFeature.get() != NULL) { - std::string anAttribute = SketchPlugin_SketchEntity::AUXILIARY_ID(); - - std::shared_ptr anAuxiliaryAttr = - std::dynamic_pointer_cast(aSketchFeature->data()->attribute(anAttribute)); - if (anAuxiliaryAttr) - anAuxiliaryAttr->setValue(isChecked); - } - } - } - } - if (isUseTransaction) { - aMgr->finishOperation(); - } - Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); - restoreSelection(); -} void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr& thePln) { diff --git a/src/PartSet/PartSet_SketcherMgr.h b/src/PartSet/PartSet_SketcherMgr.h index ed1ff7294..01789c136 100644 --- a/src/PartSet/PartSet_SketcherMgr.h +++ b/src/PartSet/PartSet_SketcherMgr.h @@ -139,18 +139,14 @@ public: /// \param theObject a model object bool canDisplayObject(const ObjectPtr& theObject) const; - /// Returns true if the current operation is sketch entity create operation - /// \param theValue the current auxiliary value - /// \return the boolean result - bool canSetAuxiliary(bool& theValue) const; - - /// Changes the sketcher entity construction argument value - /// \param isChecked if true, the feature is a construction - void setAuxiliary(const bool isChecked); - /// Returns state of constraints showing flag bool isConstraintsShown() const { return myIsConstraintsShown; } + /// Saves the current selection in the viewer into an internal container + /// It obtains the selected attributes. The highlighted objects can be processes as the selected ones + /// \param theHighlightedUse a boolean flag + void storeSelection(const bool theHighlightedOnly = false); + void restoreSelection(); /// Returns list of strings which contains id's of sketch operations static const QStringList& sketchOperationIdList(); @@ -250,12 +246,6 @@ private: /// \param isToDisplay a flag about the display or erase the feature void visualizeFeature(ModuleBase_Operation* theOperation, const bool isToDisplay); - /// Saves the current selection in the viewer into an internal container - /// It obtains the selected attributes. The highlighted objects can be processes as the selected ones - /// \param theHighlightedUse a boolean flag - void storeSelection(const bool theHighlightedOnly = false); - void restoreSelection(); - private: PartSet_Module* myModule; diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index fe6382c4b..e77247629 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -793,3 +793,18 @@ bool XGUI_Displayer::customizeObject(ObjectPtr theObject) } return aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs); } + + +QColor XGUI_Displayer::setObjectColor(ObjectPtr theObject, const QColor& theColor, bool toUpdate) +{ + if (!isVisible(theObject)) + return Qt::black; + + AISObjectPtr anAISObj = getAISObject(theObject); + int aR, aG, aB; + anAISObj->getColor(aR, aG, aB); + anAISObj->setColor(theColor.red(), theColor.green(), theColor.blue()); + if (toUpdate) + updateViewer(); + return QColor(aR, aG, aB); +} diff --git a/src/XGUI/XGUI_Displayer.h b/src/XGUI/XGUI_Displayer.h index d0153925a..6811bafdf 100644 --- a/src/XGUI/XGUI_Displayer.h +++ b/src/XGUI/XGUI_Displayer.h @@ -27,6 +27,7 @@ #include #include #include +#include class ModelAPI_Feature; class XGUI_Workshop; @@ -190,6 +191,12 @@ class XGUI_EXPORT XGUI_Displayer: public QObject /// \param theObject object to check bool canBeShaded(ObjectPtr theObject) const; + /// Set color on presentation of an object if it is displayed + /// \param theObject an object + /// \param theColor a color which has to be set + /// \param theUpdate update viewer flag + /// \return previously defined color on the object + QColor setObjectColor(ObjectPtr theObject, const QColor& theColor, bool toUpdate = true); signals: /// Signal on object display