From 420f162058764633fc40f6e3a99206ff3abf74c2 Mon Sep 17 00:00:00 2001 From: nds Date: Wed, 4 Mar 2015 12:52:23 +0300 Subject: [PATCH] Construction elements are auxiliary entities: Construction change through a context popup menu. Customize presentation by redisplay feature --- src/PartSet/PartSet_Module.cpp | 27 +++++++++-- src/PartSet/PartSet_SketcherMgr.cpp | 62 +++++++++++++++++++++++-- src/PartSet/PartSet_SketcherMgr.h | 26 ++++++++--- src/PartSet/PartSet_WidgetPoint2d.cpp | 4 ++ src/SketchPlugin/SketchPlugin_Feature.h | 2 + src/XGUI/XGUI_Displayer.cpp | 16 ++++++- 6 files changed, 121 insertions(+), 16 deletions(-) diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index d31bf8f7c..ec85146bc 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include @@ -293,8 +294,19 @@ void PartSet_Module::addViewerItems(QMenu* theMenu) const hasFeature = true; } } - if (hasFeature) + if (hasFeature) { + XGUI_ModuleConnector* aConnector = dynamic_cast(workshop()); + XGUI_Workshop* aWorkshop = aConnector->workshop(); + QAction* anAction = aWorkshop->contextMenuMgr()->action("DELETE_CMD"); + theMenu->addAction(anAction); theMenu->addAction(action("DELETE_PARTSET_CMD")); + } + } + bool isConstruction; + if (mySketchMgr->canChangeConstruction(isConstruction)) { + QAction* anAction = action("CONSTRUCTION_CMD"); + theMenu->addAction(anAction); + anAction->setChecked(isConstruction); } } @@ -478,8 +490,14 @@ QWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* void PartSet_Module::createActions() { - QAction* aAction = new QAction(QIcon(":pictures/delete.png"), tr("Delete"), this); - addAction("DELETE_PARTSET_CMD", aAction); + QAction* anAction; + + anAction = new QAction(QIcon(":pictures/delete.png"), tr("Delete"), this); + addAction("DELETE_PARTSET_CMD", anAction); + + anAction = new QAction(tr("Construction"), this); + anAction->setCheckable(true); + addAction("CONSTRUCTION_CMD", anAction); } QAction* PartSet_Module::action(const QString& theId) const @@ -506,6 +524,9 @@ void PartSet_Module::onAction(bool isChecked) if (anId == "DELETE_PARTSET_CMD") { deleteObjects(); } + if (anId == "CONSTRUCTION_CMD") { + mySketchMgr->setConstruction(isChecked); + } } void PartSet_Module::deleteObjects() diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index 30f1523b9..1cfe39ac0 100644 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -572,6 +572,21 @@ bool PartSet_SketcherMgr::isNestedSketchOperation(ModuleBase_Operation* theOpera PartSet_SketcherMgr::sketchOperationIdList().contains(theOperation->id()); } +bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOperation) +{ + return theOperation && !theOperation->isEditOperation() && isNestedSketchOperation(theOperation); +} + +bool PartSet_SketcherMgr::isEntityOperation(ModuleBase_Operation* theOperation) +{ + std::string aId = theOperation ? theOperation->id().toStdString() : ""; + + return (aId == SketchPlugin_Line::ID()) || + (aId == SketchPlugin_Point::ID()) || + (aId == SketchPlugin_Arc::ID()) || + (aId == SketchPlugin_Circle::ID()); +} + bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation) { std::string aId = theOperation ? theOperation->id().toStdString() : ""; @@ -717,6 +732,48 @@ bool PartSet_SketcherMgr::canDisplayObject() const return aCanDisplay; } +bool PartSet_SketcherMgr::canChangeConstruction(bool& isConstruction) const +{ + ModuleBase_Operation* anOperation = getCurrentOperation(); + + bool anEnabled = PartSet_SketcherMgr::isNestedCreateOperation(anOperation) && + PartSet_SketcherMgr::isEntityOperation(anOperation); + if (anEnabled) { + std::shared_ptr aSketchFeature = + std::dynamic_pointer_cast(anOperation->feature()); + if (aSketchFeature.get() != NULL) { + std::string anAttribute = SketchPlugin_Feature::CONSTRUCTION_ID(); + + std::shared_ptr aConstructionAttr = + std::dynamic_pointer_cast(aSketchFeature->data()->attribute(anAttribute)); + + isConstruction = aConstructionAttr->value(); + } + } + return anEnabled; +} + +void PartSet_SketcherMgr::setConstruction(const bool isChecked) +{ + ModuleBase_Operation* anOperation = getCurrentOperation(); + std::shared_ptr aSketchFeature = + std::dynamic_pointer_cast(anOperation->feature()); + if (aSketchFeature.get() != NULL) { + std::string anAttribute = SketchPlugin_Feature::CONSTRUCTION_ID(); + + std::shared_ptr aConstructionAttr = + std::dynamic_pointer_cast(aSketchFeature->data()->attribute(anAttribute)); + aConstructionAttr->setValue(isChecked); + + // ModuleBase_ModelWidget::updateObject + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); + + static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY); + ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, anEvent); + Events_Loop::loop()->flush(anEvent); + } +} + void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr& thePln) { myPlaneFilter->setPlane(thePln->impl()); @@ -877,11 +934,6 @@ ModuleBase_Operation* PartSet_SketcherMgr::getCurrentOperation() const return myModule->workshop()->currentOperation(); } -bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOperation) const -{ - return theOperation && !theOperation->isEditOperation() && isNestedSketchOperation(theOperation); -} - void PartSet_SketcherMgr::visualizeFeature(ModuleBase_Operation* theOperation, const bool isToDisplay) { diff --git a/src/PartSet/PartSet_SketcherMgr.h b/src/PartSet/PartSet_SketcherMgr.h index 9f2f81051..57f17840f 100644 --- a/src/PartSet/PartSet_SketcherMgr.h +++ b/src/PartSet/PartSet_SketcherMgr.h @@ -87,7 +87,17 @@ public: /// \return the boolean result static bool isNestedSketchOperation(ModuleBase_Operation* theOperation); - /// Returns whethe the current operation is a sketch distance - lenght, distance or radius + /// Returns true if the operation is a create nested feature one + /// \param theOperation a checked operation + //// \return boolean value + static bool isNestedCreateOperation(ModuleBase_Operation* theOperation); + + /// Returns whether the current operation is a sketch entity - line, point, arc or circle + /// \param the operation + /// \return a boolean value + static bool isEntityOperation(ModuleBase_Operation* theOperation); + + /// Returns whether the current operation is a sketch distance - lenght, distance or radius /// \param the operation /// \return a boolean value static bool isDistanceOperation(ModuleBase_Operation* theOperation); @@ -127,6 +137,15 @@ public: /// \param theObject a model object bool canDisplayObject() const; + /// Returns true if the current operation is sketch entity create operation + /// \param isConstruction the current construction state + /// \return the boolean result + bool canChangeConstruction(bool& isConstruction) const; + + /// Changes the sketcher entity construction argument value + /// \param isChecked if true, the feature is a construction + void setConstruction(const bool isChecked); + public slots: /// Process sketch plane selected event void onPlaneSelected(const std::shared_ptr& thePln); @@ -211,11 +230,6 @@ private: /// \return an operation ModuleBase_Operation* getCurrentOperation() const; - /// Returns true if the operation is a create nested feature one - /// \param theOperation a checked operation - //// \return boolean value - bool isNestedCreateOperation(ModuleBase_Operation* theOperation) const; - /// Erase or display the feature of the current operation. If the mouse over the active view or /// a current value is changed by property panel, the feature is displayed otherwise it is hidden /// \param theOperation an operation which feature is to be displayed, it is nested create operation diff --git a/src/PartSet/PartSet_WidgetPoint2d.cpp b/src/PartSet/PartSet_WidgetPoint2d.cpp index a81a7f2c5..4915eec35 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.cpp +++ b/src/PartSet/PartSet_WidgetPoint2d.cpp @@ -241,6 +241,10 @@ bool PartSet_WidgetPoint2D::getPoint2d(const Handle(V3d_View)& theView, void PartSet_WidgetPoint2D::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent) { + // the contex menu release by the right button should not be processed by this widget + if (theEvent->button() != Qt::LeftButton) + return; + XGUI_Selection* aSelection = myWorkshop->selector()->selection(); Handle(V3d_View) aView = theWnd->v3dView(); // TODO: This fragment doesn't work because bug in OCC Viewer. It can be used after fixing. diff --git a/src/SketchPlugin/SketchPlugin_Feature.h b/src/SketchPlugin/SketchPlugin_Feature.h index 9e22b9ce8..607f66725 100644 --- a/src/SketchPlugin/SketchPlugin_Feature.h +++ b/src/SketchPlugin/SketchPlugin_Feature.h @@ -92,11 +92,13 @@ class SketchPlugin_Feature : public ModelAPI_Feature, public GeomAPI_ICustomPrs if (aShapeType == 6) { // if this is an edge if (isConstruction) { thePrs->setWidth(1); + thePrs->setLineStyle(3); aRGB = Config_PropManager::color("Visualization", "sketch_construction_color", SKETCH_CONSTRUCTION_COLOR); } else { thePrs->setWidth(3); + thePrs->setLineStyle(0); if (isExternal()) { // Set color from preferences aRGB = Config_PropManager::color("Visualization", "sketch_external_color", diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index 401d1d3ca..6fc47e170 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -222,8 +222,12 @@ void XGUI_Displayer::redisplay(ObjectPtr theObject, bool isUpdateViewer) // Check that the visualized shape is the same and the redisplay is not necessary // Redisplay of AIS object leads to this object selection compute and the selection // in the browser is lost - // become - ResultPtr aResult = std::dynamic_pointer_cast(theObject); + + // this check is not necessary anymore because the selection store/restore is realized + // before and after the values modification. + // Moreother, this check avoids customize and redisplay presentation if the presentable + // parameter is changed. + /*ResultPtr aResult = std::dynamic_pointer_cast(theObject); if (aResult.get() != NULL) { Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aAISIO); if (!aShapePrs.IsNull()) { @@ -237,7 +241,15 @@ void XGUI_Displayer::redisplay(ObjectPtr theObject, bool isUpdateViewer) return; } } + }*/ + // Customization of presentation + FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); + if (aFeature.get() != NULL) { + GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast(aFeature); + if (aCustPrs.get() != NULL) + aCustPrs->customisePresentation(aAISObj); } + aContext->Redisplay(aAISIO, false); if (isUpdateViewer) updateViewer(); -- 2.39.2