From a9ca8332c76ae1e75c67bf18078408a6c2c49ce7 Mon Sep 17 00:00:00 2001 From: nds Date: Fri, 15 Jan 2016 18:41:43 +0300 Subject: [PATCH] Imrove multi-selector control to provide items multi-selection. Division of the operation presentation in two parts: shape+result and multi-selector highlighted. For better performance: by multi-selector control selection, the shape+result should not be recomputed and redisplayed. --- src/ModuleBase/ModuleBase_IModule.h | 3 +- .../ModuleBase_WidgetMultiSelector.cpp | 1 - src/PartSet/PartSet_CustomPrs.cpp | 126 +++++++++++------ src/PartSet/PartSet_CustomPrs.h | 42 ++++-- src/PartSet/PartSet_Module.cpp | 10 ++ src/PartSet/PartSet_OperationPrs.cpp | 133 +++++++++++------- src/PartSet/PartSet_OperationPrs.h | 38 ++++- src/XGUI/XGUI_WorkshopListener.cpp | 7 +- 8 files changed, 249 insertions(+), 111 deletions(-) diff --git a/src/ModuleBase/ModuleBase_IModule.h b/src/ModuleBase/ModuleBase_IModule.h index 45c895ded..55a0e8b5c 100755 --- a/src/ModuleBase/ModuleBase_IModule.h +++ b/src/ModuleBase/ModuleBase_IModule.h @@ -35,8 +35,7 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject /// enumeration to know which objects should be customized enum ModuleBase_CustomizeFlag { CustomizeDependedAndResults = 0x00000000, - CustomizeHighlightedObjects = 0x00000001, - CustomizeAllObjects = CustomizeDependedAndResults | CustomizeHighlightedObjects + CustomizeHighlightedObjects = 0x00000001 }; /// Constructor diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp index 090715361..38bc5c9c8 100755 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp @@ -357,7 +357,6 @@ bool ModuleBase_WidgetMultiSelector::processDelete() restoreValue(); myWorkshop->setSelected(getAttributeSelection()); - myWorkshop->module()->customizeObject(myFeature, ModuleBase_IModule::CustomizeAllObjects, true); } return aDone; } diff --git a/src/PartSet/PartSet_CustomPrs.cpp b/src/PartSet/PartSet_CustomPrs.cpp index e43ccc980..a449d8da6 100755 --- a/src/PartSet/PartSet_CustomPrs.cpp +++ b/src/PartSet/PartSet_CustomPrs.cpp @@ -14,6 +14,7 @@ #include #include +#include #include @@ -23,21 +24,16 @@ //#define DO_NOT_VISUALIZE_CUSTOM_PRESENTATION -#define OPERATION_PARAMETER_COLOR "255, 255, 0" - PartSet_CustomPrs::PartSet_CustomPrs(ModuleBase_IWorkshop* theWorkshop) : myWorkshop(theWorkshop), myIsActive(false) { - initPrs(); + initPresentation(ModuleBase_IModule::CustomizeDependedAndResults); + initPresentation(ModuleBase_IModule::CustomizeHighlightedObjects); } bool PartSet_CustomPrs::isActive() { return myIsActive; - /*Handle(PartSet_OperationPrs) anOperationPrs = getPresentation(); - Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); - - return !aContext.IsNull() && aContext->IsDisplayed(anOperationPrs);*/ } bool PartSet_CustomPrs::activate(const FeaturePtr& theFeature, const bool theUpdateViewer) @@ -46,13 +42,15 @@ bool PartSet_CustomPrs::activate(const FeaturePtr& theFeature, const bool theUpd return false; #endif - bool isModified = false; - Handle(PartSet_OperationPrs) anOperationPrs = getPresentation(); - myIsActive = true; - anOperationPrs->setFeature(theFeature); + + + bool isModified = false; + getPresentation(ModuleBase_IModule::CustomizeDependedAndResults)->setFeature(theFeature); + getPresentation(ModuleBase_IModule::CustomizeHighlightedObjects)->setFeature(theFeature); if (theFeature.get()) { - displayPresentation(theUpdateViewer); + displayPresentation(ModuleBase_IModule::CustomizeDependedAndResults, theUpdateViewer); + displayPresentation(ModuleBase_IModule::CustomizeHighlightedObjects, theUpdateViewer); isModified = true; } return isModified; @@ -63,37 +61,44 @@ bool PartSet_CustomPrs::deactivate(const bool theUpdateViewer) myIsActive = false; bool isModified = false; - Handle(PartSet_OperationPrs) anOperationPrs = getPresentation(); - anOperationPrs->setFeature(FeaturePtr()); + getPresentation(ModuleBase_IModule::CustomizeDependedAndResults)->setFeature(FeaturePtr()); + getPresentation(ModuleBase_IModule::CustomizeHighlightedObjects)->setFeature(FeaturePtr()); - Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); - if (!aContext.IsNull() && aContext->IsDisplayed(anOperationPrs)) { - erasePresentation(theUpdateViewer); - isModified = true; - } + erasePresentation(ModuleBase_IModule::CustomizeDependedAndResults, theUpdateViewer); + erasePresentation(ModuleBase_IModule::CustomizeHighlightedObjects, theUpdateViewer); + isModified = true; return isModified; } -bool PartSet_CustomPrs::displayPresentation(const bool theUpdateViewer) +bool PartSet_CustomPrs::displayPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag, + const bool theUpdateViewer) { bool isModified = false; - Handle(PartSet_OperationPrs) anOperationPrs = getPresentation(); - anOperationPrs->updateShapes(); + Handle(PartSet_OperationPrs) anOperationPrs = getPresentation(theFlag); + if (theFlag == ModuleBase_IModule::CustomizeDependedAndResults) { + PartSet_OperationPrs::getFeatureShapes(anOperationPrs->getFeature(), myWorkshop, + anOperationPrs->featureShapes()); + anOperationPrs->updateShapes(); + } + else if (theFlag == ModuleBase_IModule::CustomizeHighlightedObjects) { + PartSet_OperationPrs::getHighlightedShapes(myWorkshop, anOperationPrs->featureShapes()); + } Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); if (!aContext.IsNull() && !aContext->IsDisplayed(anOperationPrs)) { if (anOperationPrs->hasShapes()) { PartSet_Module* aModule = dynamic_cast(myWorkshop->module()); XGUI_Workshop* aWorkshop = workshop(); - aWorkshop->displayer()->displayAIS(myOperationPrs, false/*load object in selection*/, theUpdateViewer); + aWorkshop->displayer()->displayAIS(myPresentations[theFlag], false/*load object in selection*/, + theUpdateViewer); aContext->SetZLayer(anOperationPrs, aModule->getVisualLayerId()); isModified = true; } } else { if (!anOperationPrs->hasShapes()) { - erasePresentation(theUpdateViewer); + erasePresentation(theFlag, theUpdateViewer); isModified = true; } else { @@ -106,18 +111,33 @@ bool PartSet_CustomPrs::displayPresentation(const bool theUpdateViewer) return isModified; } -void PartSet_CustomPrs::erasePresentation(const bool theUpdateViewer) +void PartSet_CustomPrs::erasePresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag, + const bool theUpdateViewer) { XGUI_Workshop* aWorkshop = workshop(); - aWorkshop->displayer()->eraseAIS(myOperationPrs, theUpdateViewer); + aWorkshop->displayer()->eraseAIS(myPresentations[theFlag], theUpdateViewer); } -Handle(PartSet_OperationPrs) PartSet_CustomPrs::getPresentation() +void PartSet_CustomPrs::clearPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag) { - if (!myOperationPrs.get()) - initPrs(); - Handle(AIS_InteractiveObject) anAISIO = myOperationPrs->impl(); - return Handle(PartSet_OperationPrs)::DownCast(anAISIO); + Handle(PartSet_OperationPrs) anOperationPrs = getPresentation(theFlag); + if (!anOperationPrs.IsNull()) + anOperationPrs.Nullify(); +} + +Handle(PartSet_OperationPrs) PartSet_CustomPrs::getPresentation( + const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag) +{ + Handle(PartSet_OperationPrs) aPresentation; + + if (myPresentations.contains(theFlag)) { + AISObjectPtr anOperationPrs = myPresentations[theFlag]; + if (!anOperationPrs.get()) + initPresentation(theFlag); + Handle(AIS_InteractiveObject) anAISIO = anOperationPrs->impl(); + aPresentation = Handle(PartSet_OperationPrs)::DownCast(anAISIO); + } + return aPresentation; } bool PartSet_CustomPrs::redisplay(const ObjectPtr& theObject, @@ -127,29 +147,43 @@ bool PartSet_CustomPrs::redisplay(const ObjectPtr& theObject, #ifdef DO_NOT_VISUALIZE_CUSTOM_PRESENTATION return false; #endif - return displayPresentation(theUpdateViewer); + return displayPresentation(theFlag, theUpdateViewer); } void PartSet_CustomPrs::clearPrs() { - Handle(PartSet_OperationPrs) anOperationPrs = getPresentation(); - if (!anOperationPrs.IsNull()) - anOperationPrs.Nullify(); - - myOperationPrs.reset(); + clearPresentation(ModuleBase_IModule::CustomizeDependedAndResults); + clearPresentation(ModuleBase_IModule::CustomizeHighlightedObjects); } -void PartSet_CustomPrs::initPrs() +void PartSet_CustomPrs::initPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag) { - myOperationPrs = AISObjectPtr(new GeomAPI_AISObject()); - myOperationPrs->setImpl(new Handle(AIS_InteractiveObject)(new PartSet_OperationPrs(myWorkshop))); - - std::vector aColor = Config_PropManager::color("Visualization", "operation_parameter_color", - OPERATION_PARAMETER_COLOR); - myOperationPrs->setColor(aColor[0], aColor[1], aColor[2]); + AISObjectPtr anOperationPrs = AISObjectPtr(new GeomAPI_AISObject()); + Handle(PartSet_OperationPrs) anAISPrs = new PartSet_OperationPrs(myWorkshop); + anOperationPrs->setImpl(new Handle(AIS_InteractiveObject)(anAISPrs)); + if (theFlag == ModuleBase_IModule::CustomizeDependedAndResults) { + Quantity_Color aShapeColor = ModuleBase_Tools::color("Visualization", "operation_parameter_color", + OPERATION_PARAMETER_COLOR()); + Quantity_Color aResultColor = ModuleBase_Tools::color("Visualization", "operation_result_color", + OPERATION_RESULT_COLOR()); + anAISPrs->setColors(aShapeColor, aResultColor); + + anOperationPrs->setPointMarker(5, 2.); + anOperationPrs->setWidth(1); + } + else if (theFlag == ModuleBase_IModule::CustomizeHighlightedObjects) { + Quantity_Color aShapeColor = ModuleBase_Tools::color("Visualization", "operation_highlight_color", + OPERATION_HIGHLIGHT_COLOR()); + Quantity_Color aResultColor = ModuleBase_Tools::color("Visualization", "operation_result_color", + OPERATION_RESULT_COLOR()); + anAISPrs->setColors(aShapeColor, aResultColor); + //in this presentation we show the shapes wireframe similar to their highlight by OCCT + //so, we need to use the source AIS object width for the presentation width + anAISPrs->useAISWidth(); + } - myOperationPrs->setPointMarker(5, 2.); - myOperationPrs->setWidth(1); + if (anOperationPrs.get()) + myPresentations[theFlag] = anOperationPrs; } XGUI_Workshop* PartSet_CustomPrs::workshop() const diff --git a/src/PartSet/PartSet_CustomPrs.h b/src/PartSet/PartSet_CustomPrs.h index ab82997a7..b235e19c0 100755 --- a/src/PartSet/PartSet_CustomPrs.h +++ b/src/PartSet/PartSet_CustomPrs.h @@ -29,6 +29,15 @@ class XGUI_Workshop; */ class PartSet_CustomPrs { +public: + /// Returns yellow color + static const std::string OPERATION_PARAMETER_COLOR() { return "255, 255, 0"; } + /// Returns green color + static const std::string OPERATION_RESULT_COLOR() { return "0,225, 0"; } + /// Returns color between white and color of highlight + /// highlight color is equal Quantity_Color(0.5,1,1) or QColor(122, 255,255) // 188 + static const std::string OPERATION_HIGHLIGHT_COLOR() { return "188, 255, 255"; } + public: /// Constructor /// \param theWorkshop a reference to workshop @@ -52,38 +61,55 @@ public: /// If the presentation is active[displayed], the shapes of the presentation is recomputed /// and the presentation is redisplayed. /// \param theObject an object to redisplay + /// \param theFlag an object AIS presentation type /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly /// \returns true if the presentation is redisplayed bool redisplay(const ObjectPtr& theObject, - const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag, const bool theUpdateViewer); + const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag, + const bool theUpdateViewer); - /// Nullify the operation presentation. For example, it can be useful when the viewer/context + /// Nullify all internal presentations. For example, it can be useful when the viewer/context /// is closed. If this is not performed and the presentation is assigned in another context, /// it caused erroneus case because the presentation has linkage to the previous context. void clearPrs(); private: /// Creates the AIS operation presentation - void initPrs(); + /// \param theFlag an object AIS presentation type + void initPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag); - /// Returns the AIS presentation - Handle(PartSet_OperationPrs) getPresentation(); + /// Gets an AIS presentation by the flag + /// \param theFlag an object AIS presentation type + /// \return the AIS prsentation + Handle(PartSet_OperationPrs) getPresentation( + const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag); //! Returns workshop XGUI_Workshop* workshop() const; /// Displays the internal presentation in the viewer of workshop + /// \param theFlag an object AIS presentation type /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly - bool displayPresentation(const bool theUpdateViewer); + /// \param returns whether the presentation is displayed/redisplayed + bool displayPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag, + const bool theUpdateViewer); /// Erases the internal presentation from the viewer of workshop + /// \param theFlag an object AIS presentation type /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly - void erasePresentation(const bool theUpdateViewer); + void erasePresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag, + const bool theUpdateViewer); + + /// Nullify the operation presentation. For example, it can be useful when the viewer/context + /// is closed. If this is not performed and the presentation is assigned in another context, + /// it caused erroneus case because the presentation has linkage to the previous context. + void clearPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag); private: bool myIsActive; ModuleBase_IWorkshop* myWorkshop; /// current workshop - AISObjectPtr myOperationPrs; /// the AIS presentation, which is displayed/erased in the viewer + /// map of presentation type to AIS object + QMap myPresentations; }; #endif diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 7883d5279..ea2740d62 100755 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -142,6 +142,16 @@ PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop) myHasConstraintShown[PartSet_Tools::Geometrical] = true; myHasConstraintShown[PartSet_Tools::Dimensional] = true; + + Config_PropManager::registerProp("Visualization", "operation_parameter_color", + "Reference shape wireframe color in operation", Config_Prop::Color, + PartSet_CustomPrs::OPERATION_PARAMETER_COLOR()); + Config_PropManager::registerProp("Visualization", "operation_result_color", + "Result shape wireframe color in operation", Config_Prop::Color, + PartSet_CustomPrs::OPERATION_RESULT_COLOR()); + Config_PropManager::registerProp("Visualization", "operation_highlight_color", + "Multi selector item color in operation", Config_Prop::Color, + PartSet_CustomPrs::OPERATION_HIGHLIGHT_COLOR()); } PartSet_Module::~PartSet_Module() diff --git a/src/PartSet/PartSet_OperationPrs.cpp b/src/PartSet/PartSet_OperationPrs.cpp index af1f3ae4b..6858e0a14 100755 --- a/src/PartSet/PartSet_OperationPrs.cpp +++ b/src/PartSet/PartSet_OperationPrs.cpp @@ -37,7 +37,8 @@ IMPLEMENT_STANDARD_HANDLE(PartSet_OperationPrs, ViewerData_AISShape); IMPLEMENT_STANDARD_RTTIEXT(PartSet_OperationPrs, ViewerData_AISShape); PartSet_OperationPrs::PartSet_OperationPrs(ModuleBase_IWorkshop* theWorkshop) - : ViewerData_AISShape(TopoDS_Shape()), myFeature(FeaturePtr()), myWorkshop(theWorkshop) +: ViewerData_AISShape(TopoDS_Shape()), myFeature(FeaturePtr()), myWorkshop(theWorkshop), + myUseAISWidth(false) { myShapeColor = ModuleBase_Tools::color("Visualization", "construction_plane_color", "1,1,0"); myResultColor = ModuleBase_Tools::color("Visualization", "construction_plane_color", "0,1,0"); @@ -50,9 +51,6 @@ void PartSet_OperationPrs::setFeature(const FeaturePtr& theFeature) void PartSet_OperationPrs::updateShapes() { - myFeatureShapes.clear(); - getFeatureShapes(myFeatureShapes); - myFeatureResults.clear(); if (myFeature) myFeatureResults = myFeature->results(); @@ -83,6 +81,17 @@ bool PartSet_OperationPrs::hasShapes() return aHasShapes; } +void PartSet_OperationPrs::setColors(const Quantity_Color& theShapeColor, const Quantity_Color& theResultColor) +{ + myShapeColor = theShapeColor; + myResultColor = theResultColor; +} + +void PartSet_OperationPrs::useAISWidth() +{ + myUseAISWidth = true; +} + void PartSet_OperationPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode) @@ -94,15 +103,13 @@ void PartSet_OperationPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& t if (!myWorkshop->module()->canDisplayObject(myFeature)) return; - Quantity_Color aColor(1., 1., 0., Quantity_TOC_RGB); // yellow - SetColor(aColor); - + SetColor(myShapeColor); thePresentation->Clear(); XGUI_Displayer* aDisplayer = workshop()->displayer(); - // create presentations on the base of the shapes Handle(Prs3d_Drawer) aDrawer = Attributes(); + // create presentations on the base of the shapes QMap >::const_iterator anIt = myFeatureShapes.begin(), aLast = myFeatureShapes.end(); for (; anIt != aLast; anIt++) { @@ -118,13 +125,21 @@ void PartSet_OperationPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& t TopoDS_Shape aShape = aGeomShape->impl(); // change deviation coefficient to provide more precise circle ModuleBase_Tools::setDefaultDeviationCoefficient(aShape, aDrawer); + + if (myUseAISWidth) { + AISObjectPtr anAISPtr = aDisplayer->getAISObject(anObject); + if (anAISPtr.get()) { + Handle(AIS_InteractiveObject) anIO = anAISPtr->impl(); + if (!anIO.IsNull()) + setWidth(aDrawer, anIO->Width()); + } + } StdPrs_WFDeflectionShape::Add(thePresentation, aShape, aDrawer); } } - aColor = Quantity_Color(0., 1., 0., Quantity_TOC_RGB); // green - SetColor(aColor); - + // create presentations on the base of the results + SetColor(myResultColor); std::list::const_iterator aRIt = myFeatureResults.begin(), aRLast = myFeatureResults.end(); for (; aRIt != aRLast; aRIt++) { @@ -147,37 +162,6 @@ void PartSet_OperationPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& t aWidget->getHighlighted(aValues); } } - - Standard_Real aPreviousWidth = Width(); - setWidth(aDrawer, aPreviousWidth+3); - Handle(AIS_InteractiveContext) aContext = GetContext(); - Quantity_NameOfColor anHColor = aContext->HilightColor(); - - aColor = Quantity_Color(anHColor); - aColor = Quantity_Color((1. + aColor.Red())/2., (1. + aColor.Green())/2., - (1. + aColor.Blue())/2., Quantity_TOC_RGB); - SetColor(aColor); - - QList::const_iterator anIIt = aValues.begin(), - aILast = aValues.end(); - for (; anIIt != aILast; anIIt++) { - ModuleBase_ViewerPrs aPrs = *anIIt; - ObjectPtr anObject = aPrs.object(); - TopoDS_Shape aShape = aPrs.shape(); - if (aShape.IsNull()) { - ResultPtr aResult = std::dynamic_pointer_cast(anObject); - if (aResult.get()) { - GeomShapePtr aGeomShape = aResult->shape(); - if (aGeomShape.get()) - aShape = aGeomShape->impl(); - } - } - if (!aShape.IsNull()) { - ModuleBase_Tools::setDefaultDeviationCoefficient(aShape, aDrawer); - StdPrs_WFDeflectionShape::Add(thePresentation, aShape, aDrawer); - } - } - setWidth(aDrawer, aPreviousWidth); } void PartSet_OperationPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, @@ -255,22 +239,25 @@ void addValue(const ObjectPtr& theObject, const GeomShapePtr& theShape, } } -void PartSet_OperationPrs::getFeatureShapes(QMap >& theObjectShapes) +void PartSet_OperationPrs::getFeatureShapes(const FeaturePtr& theFeature, + ModuleBase_IWorkshop* theWorkshop, + QMap >& theObjectShapes) { - if (!myFeature.get()) + theObjectShapes.clear(); + if (!theFeature.get()) return; ModelAPI_ValidatorsFactory* aValidators = ModelAPI_Session::get()->validators(); QList aShapes; - std::list anAttributes = myFeature->data()->attributes(""); + std::list anAttributes = theFeature->data()->attributes(""); std::list::const_iterator anIt = anAttributes.begin(), aLast = anAttributes.end(); for (; anIt != aLast; anIt++) { AttributePtr anAttribute = *anIt; if (!isSelectionAttribute(anAttribute)) continue; - if (!aValidators->isCase(myFeature, anAttribute->id())) + if (!aValidators->isCase(theFeature, anAttribute->id())) continue; // this attribute is not participated in the current case std::string anAttrType = anAttribute->attributeType(); @@ -282,7 +269,7 @@ void PartSet_OperationPrs::getFeatureShapes(QMap std::shared_ptr aSelAttribute = aCurSelList->value(i); ResultPtr aResult = aSelAttribute->context(); GeomShapePtr aShape = aSelAttribute->value(); - addValue(aResult, aShape, myFeature, theObjectShapes); + addValue(aResult, aShape, theFeature, theObjectShapes); } } if (anAttrType == ModelAPI_AttributeRefList::typeId()) { @@ -290,7 +277,7 @@ void PartSet_OperationPrs::getFeatureShapes(QMap std::dynamic_pointer_cast(anAttribute); for (int i = 0; i < aCurSelList->size(); i++) { GeomShapePtr aShape; - addValue(aCurSelList->object(i), aShape, myFeature, theObjectShapes); + addValue(aCurSelList->object(i), aShape, theFeature, theObjectShapes); } } else { @@ -302,7 +289,7 @@ void PartSet_OperationPrs::getFeatureShapes(QMap anObject = anAttr->object(); } else { - aShape = PartSet_Tools::findShapeBy2DPoint(anAttr, myWorkshop); + aShape = PartSet_Tools::findShapeBy2DPoint(anAttr, theWorkshop); // the distance point is not found if the point is selected in the 2nd time // TODO: after debug, this check can be removed if (!aShape.get()) @@ -319,11 +306,57 @@ void PartSet_OperationPrs::getFeatureShapes(QMap AttributeReferencePtr anAttr = std::dynamic_pointer_cast(anAttribute); anObject = anAttr->value(); } - addValue(anObject, aShape, myFeature, theObjectShapes); + addValue(anObject, aShape, theFeature, theObjectShapes); } } } +void PartSet_OperationPrs::getHighlightedShapes(ModuleBase_IWorkshop* theWorkshop, + QMap >& theObjectShapes) +{ + theObjectShapes.clear(); + + QList aValues; + ModuleBase_IPropertyPanel* aPanel = theWorkshop->propertyPanel(); + if (aPanel) { + ModuleBase_ModelWidget* aWidget = aPanel->activeWidget(); + if (aWidget) { + aWidget->getHighlighted(aValues); + } + } + + QList aShapes; + QList::const_iterator anIIt = aValues.begin(), + aILast = aValues.end(); + for (; anIIt != aILast; anIIt++) { + ModuleBase_ViewerPrs aPrs = *anIIt; + ObjectPtr anObject = aPrs.object(); + + GeomShapePtr aGeomShape; + + TopoDS_Shape aShape = aPrs.shape(); + if (!aShape.IsNull()) { + aGeomShape = GeomShapePtr(new GeomAPI_Shape()); + aGeomShape->setImpl(new TopoDS_Shape(aShape)); + } + else { + ResultPtr aResult = std::dynamic_pointer_cast(anObject); + if (aResult.get()) { + aGeomShape = aResult->shape(); + } + } + + if (theObjectShapes.contains(anObject)) + theObjectShapes[anObject].append(aGeomShape); + else { + QList aShapes; + aShapes.append(aGeomShape); + theObjectShapes[anObject] = aShapes; + } + } +} + + bool PartSet_OperationPrs::isSelectionAttribute(const AttributePtr& theAttribute) { std::string anAttrType = theAttribute->attributeType(); diff --git a/src/PartSet/PartSet_OperationPrs.h b/src/PartSet/PartSet_OperationPrs.h index 8bb9d36c8..89d2c252e 100755 --- a/src/PartSet/PartSet_OperationPrs.h +++ b/src/PartSet/PartSet_OperationPrs.h @@ -57,6 +57,14 @@ public: /// Returns true if the feature contains shapes or results bool hasShapes(); + /// Sets the colors for the presentation compute + /// \param theShapeColor an argument shapes color + /// \param theResultColor a color for operation result + void setColors(const Quantity_Color& theShapeColor, const Quantity_Color& theResultColor); + + /// Switch on using of the AIS presentation with of the shape object increased on the delta + void useAISWidth(); + DEFINE_STANDARD_RTTI(PartSet_OperationPrs) protected: @@ -68,6 +76,15 @@ protected: /// Redefinition of virtual function Standard_EXPORT virtual void ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, const Standard_Integer aMode) ; + +protected: + /// Reference to a feature object + FeaturePtr getFeature() { return myFeature; } + + /// Returns map of feature shapes to be able to fill it outside this class, e.g. in friend + /// \return a map of object to shape + QMap >& featureShapes() { return myFeatureShapes; } + private: /// Return true if the object is visible. If the object is feature, it returns true /// if all results of the feature are shown @@ -77,9 +94,22 @@ private: bool isVisible(XGUI_Displayer* theDislayer, const ObjectPtr& theObject); /// Fills the map by the feature object and shapes, which should be visuaziled - /// Gets the feature attribute, collect objects to whom the attribute refers + /// Gets feature attributes, collect objects to whom the attributes refer + /// \param theFeature a current feature + /// \param theWorkshop a current workshop + /// \param theObjectShapes an output map /// \param theObjectShape an output map of objects - void getFeatureShapes(QMap >& theObjectShapes); + static void getFeatureShapes(const FeaturePtr& theFeature, + ModuleBase_IWorkshop* theWorkshop, + QMap >& theObjectShapes); + + /// Fills the map by the feature object and shapes, which should be visuaziled + /// Gets the active widget, obtain the highlighted presentations if it has such and + /// fill map by object and shapes + /// \param theWorkshop a current workshop + /// \param theObjectShapes an output map of objects + static void getHighlightedShapes(ModuleBase_IWorkshop* theWorkshop, + QMap >& theObjectShapes); /// Returns true if the attribute type belong to reference attribute /// \param theAttribute an attribute @@ -98,6 +128,10 @@ private: Quantity_Color myShapeColor; /// color of feature depended shapes Quantity_Color myResultColor; /// color of feature result + + bool myUseAISWidth; /// flag if the width of a shape object should be used for the shape visualization + + friend class PartSet_CustomPrs; }; diff --git a/src/XGUI/XGUI_WorkshopListener.cpp b/src/XGUI/XGUI_WorkshopListener.cpp index f9c006199..d8934f2da 100755 --- a/src/XGUI/XGUI_WorkshopListener.cpp +++ b/src/XGUI/XGUI_WorkshopListener.cpp @@ -581,9 +581,12 @@ bool XGUI_WorkshopListener::customizeCurrentObject(const std::set& th // if a list of message objects contains the operation feature for case when // the feature is hidden, but arguments of the feature are modified // e.g. extrusion is hidden(h=0) but sketch is chosen - if (theForceRedisplay || theObjects.find(aCurrentFeature) != theObjects.end()) + if (theForceRedisplay || theObjects.find(aCurrentFeature) != theObjects.end()) { aCustomized = myWorkshop->module()->customizeObject(aCurrentFeature, - ModuleBase_IModule::CustomizeAllObjects, false); + ModuleBase_IModule::CustomizeDependedAndResults, false); + aCustomized = myWorkshop->module()->customizeObject(aCurrentFeature, + ModuleBase_IModule::CustomizeHighlightedObjects, false); + } } return aCustomized; } -- 2.39.2