PartSet_Filters.h
PartSet_FilterSketchEntity.h
PartSet_SketcherMgr.h
+ PartSet_MenuMgr.h
)
SET(PROJECT_SOURCES
PartSet_Filters.cpp
PartSet_FilterSketchEntity.cpp
PartSet_SketcherMgr.cpp
+ PartSet_MenuMgr.cpp
)
SET(PROJECT_RESOURCES
--- /dev/null
+// 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 <GeomAPI_Pnt2d.h>
+#include <GeomDataAPI_Point2D.h>
+
+#include <SketchPlugin_ConstraintCoincidence.h>
+#include <SketchPlugin_Line.h>
+#include <SketchPlugin_Circle.h>
+#include <SketchPlugin_Point.h>
+
+#include <ModuleBase_ISelection.h>
+#include <ModuleBase_Operation.h>
+
+#include <XGUI_ModuleConnector.h>
+#include <XGUI_Workshop.h>
+#include <XGUI_Displayer.h>
+
+#include <Events_Loop.h>
+#include <ModelAPI_Events.h>
+#include <ModelAPI_Session.h>
+
+#include <QAction>
+#include <QMenu>
+
+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<QAction*>(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<GeomAPI_Pnt2d> getPoint(std::shared_ptr<ModelAPI_Feature>& theFeature,
+ const std::string& theAttribute)
+{
+ std::shared_ptr<GeomDataAPI_Point2D> aPointAttr;
+
+ if (!theFeature->data())
+ return std::shared_ptr<GeomAPI_Pnt2d>();
+
+ FeaturePtr aFeature;
+ std::shared_ptr<ModelAPI_AttributeRefAttr> 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<GeomDataAPI_Point2D>(
+ aFeature->data()->attribute(SketchPlugin_Point::COORD_ID()));
+
+ else if (aFeature && aFeature->getKind() == SketchPlugin_Circle::ID())
+ aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ aFeature->data()->attribute(SketchPlugin_Circle::CENTER_ID()));
+
+ else if (anAttr->attr()) {
+ aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr->attr());
+ }
+ if (aPointAttr.get() != NULL)
+ return aPointAttr->pnt();
+ return std::shared_ptr<GeomAPI_Pnt2d>();
+}
+
+/// 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<FeaturePtr>& theList, std::string theAttr)
+{
+ AttributeRefAttrPtr aPnt = theStartCoin->refattr(theAttr);
+ FeaturePtr aObj = ModelAPI_Feature::feature(aPnt->object());
+ if (!theList.contains(aObj)) {
+ std::shared_ptr<GeomAPI_Pnt2d> aOrig = getPoint(theStartCoin, theAttr);
+ theList.append(aObj);
+ const std::set<AttributePtr> aRefsList = aObj->data()->refsToMe();
+ std::set<AttributePtr>::const_iterator aIt;
+ for (aIt = aRefsList.cbegin(); aIt != aRefsList.cend(); ++aIt) {
+ std::shared_ptr<ModelAPI_Attribute> aAttr = (*aIt);
+ FeaturePtr aConstrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
+ if (aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) {
+ std::shared_ptr<GeomAPI_Pnt2d> 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<QString, QAction*>& 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<XGUI_ModuleConnector*>(myModule->workshop());
+ XGUI_Workshop* aWorkshop = aConnector->workshop();
+ XGUI_Displayer* aDisplayer = aWorkshop->displayer();
+
+ FeaturePtr aLine = myCoinsideLines.at(myPrevId);
+ std::list<ResultPtr>::const_iterator aIt;
+ const std::list<ResultPtr>& 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<GeomAPI_Pnt2d> aOrig = getPoint(mySelectedFeature, SketchPlugin_ConstraintCoincidence::ENTITY_A());
+ gp_Pnt aOr = aOrig->impl<gp_Pnt>();
+ const std::set<AttributePtr>& aRefsList = aLine->data()->refsToMe();
+
+ QObjectPtrList aToDelFeatures;
+ std::set<AttributePtr>::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<ModelAPI_Attribute> aAttr = (*aIt);
+ FeaturePtr aConstrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
+ if (aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) {
+ std::shared_ptr<GeomAPI_Pnt2d> aPnt = getPoint(aConstrFeature, SketchPlugin_ConstraintCoincidence::ENTITY_A());
+ gp_Pnt aP = aPnt->impl<gp_Pnt>();
+ if (aOrig->isEqual(aPnt)) {
+ aToDelFeatures.append(aConstrFeature);
+ } else {
+ aPnt = getPoint(aConstrFeature, SketchPlugin_ConstraintCoincidence::ENTITY_B());
+ aP = aPnt->impl<gp_Pnt>();
+ if (aOrig->isEqual(aPnt)) {
+ aToDelFeatures.append(aConstrFeature);
+ break;
+ }
+ }
+ }
+ }
+ if (aToDelFeatures.size() > 0) {
+ XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(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<FeaturePtr> 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<SketchPlugin_Feature> aSketchFeature =
+ std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
+ if (aSketchFeature.get() != NULL) {
+ std::string anAttribute = SketchPlugin_SketchEntity::AUXILIARY_ID();
+
+ std::shared_ptr<ModelAPI_AttributeBoolean> anAuxiliaryAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(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<SketchPlugin_Feature> aSketchFeature =
+ std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
+ if (aSketchFeature.get() != NULL) {
+ std::string anAttribute = SketchPlugin_SketchEntity::AUXILIARY_ID();
+
+ std::shared_ptr<ModelAPI_AttributeBoolean> anAuxiliaryAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(aSketchFeature->data()->attribute(anAttribute));
+ if (anAuxiliaryAttr)
+ isNotAuxiliaryFound = !anAuxiliaryAttr->value();
+ }
+ }
+ }
+ }
+ theValue = anObjects.size() && !isNotAuxiliaryFound;
+ return anEnabled;
+}
--- /dev/null
+// 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 <ModelAPI_Feature.h>
+
+#include <QObject>
+#include <QMap>
+#include <QString>
+#include <QList>
+#include <QColor>
+
+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<QString, QAction*>& 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<QString, QAction*> myActions;
+
+ /// List of lines coincided in a one point
+ mutable QList<FeaturePtr> 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
#include <PartSet_WidgetShapeSelector.h>
#include <PartSet_WidgetConstraintShapeSelector.h>
#include <PartSet_WidgetEditor.h>
-#include <PartSet_SketcherMgr.h>
+#include "PartSet_SketcherMgr.h"
+#include "PartSet_MenuMgr.h"
#include <ModuleBase_Operation.h>
#include <ModuleBase_IViewer.h>
#include <SketchPlugin_Feature.h>
#include <SketchPlugin_Sketch.h>
#include <SketchPlugin_Line.h>
-//#include <SketchPlugin_Arc.h>
-//#include <SketchPlugin_Circle.h>
+#include <SketchPlugin_Arc.h>
+#include <SketchPlugin_Circle.h>
+#include <SketchPlugin_Point.h>
#include <SketchPlugin_ConstraintLength.h>
#include <SketchPlugin_ConstraintDistance.h>
#include <SketchPlugin_ConstraintParallel.h>
connect(aViewer, SIGNAL(viewTransformed(int)),
SLOT(onViewTransformed(int)));
- createActions();
+ myMenuMgr = new PartSet_MenuMgr(this);
}
PartSet_Module::~PartSet_Module()
return mySketchMgr->canDisplayObject(theObject);
}
+
bool PartSet_Module::addViewerItems(QMenu* theMenu, const QMap<QString, QAction*>& 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()
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<QAction*>(sender());
- QString anId = aAction->data().toString();
-
- if (anId == "AUXILIARY_CMD") {
- mySketchMgr->setAuxiliary(isChecked);
- }
-}
bool PartSet_Module::deleteObjects()
{
#include "PartSet.h"
#include "PartSet_Filters.h"
-#include "PartSet_SketcherMgr.h"
#include <ModuleBase_IModule.h>
#include <ModuleBase_Definitions.h>
class ModuleBase_Operation;
class ModuleBase_IViewWindow;
+class PartSet_MenuMgr;
+class PartSet_SketcherMgr;
class QAction;
/// \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;
/// \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
/// 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();
PartSet_SketcherMgr* mySketchMgr;
- QMap<QString, QAction*> myActions; // the popup menu actions
+ PartSet_MenuMgr* myMenuMgr;
int myVisualLayerId;
};
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<SketchPlugin_Feature> aSketchFeature =
- std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
- if (aSketchFeature.get() != NULL) {
- std::string anAttribute = SketchPlugin_SketchEntity::AUXILIARY_ID();
-
- std::shared_ptr<ModelAPI_AttributeBoolean> anAuxiliaryAttr =
- std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(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<SketchPlugin_Feature> aSketchFeature =
- std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
- if (aSketchFeature.get() != NULL) {
- std::string anAttribute = SketchPlugin_SketchEntity::AUXILIARY_ID();
-
- std::shared_ptr<ModelAPI_AttributeBoolean> anAuxiliaryAttr =
- std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(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<GeomAPI_Pln>& thePln)
{
/// \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();
/// \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;
}
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);
+}
#include <QString>
#include <QMap>
#include <QObject>
+#include <QColor>
class ModelAPI_Feature;
class XGUI_Workshop;
/// \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