From: nds Date: Fri, 15 Jan 2016 17:29:51 +0000 (+0300) Subject: Imrove multi-selector control to provide items multi-selection. Preferences color... X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=d3e51c4ee080e0b0936dbf954760e30d6e4878da;p=modules%2Fshaper.git Imrove multi-selector control to provide items multi-selection. Preferences color should be applyed by the next presentations visualization. --- diff --git a/src/ModuleBase/ModuleBase_IModule.h b/src/ModuleBase/ModuleBase_IModule.h index 55a0e8b5c..94b2ff98c 100755 --- a/src/ModuleBase/ModuleBase_IModule.h +++ b/src/ModuleBase/ModuleBase_IModule.h @@ -34,8 +34,9 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject public: /// enumeration to know which objects should be customized enum ModuleBase_CustomizeFlag { - CustomizeDependedAndResults = 0x00000000, - CustomizeHighlightedObjects = 0x00000001 + CustomizeArguments = 0, /// references of other objects referenced to the current feature + CustomizeResults, /// results of the current feature + CustomizeHighlightedObjects /// highlighted objects of the active widget }; /// Constructor diff --git a/src/PartSet/PartSet_CustomPrs.cpp b/src/PartSet/PartSet_CustomPrs.cpp index b466171c3..54298f76d 100755 --- a/src/PartSet/PartSet_CustomPrs.cpp +++ b/src/PartSet/PartSet_CustomPrs.cpp @@ -25,9 +25,10 @@ //#define DO_NOT_VISUALIZE_CUSTOM_PRESENTATION PartSet_CustomPrs::PartSet_CustomPrs(ModuleBase_IWorkshop* theWorkshop) - : myWorkshop(theWorkshop), myIsActive(false) + : myWorkshop(theWorkshop), myIsActive(false), myFeature(FeaturePtr()) { - initPresentation(ModuleBase_IModule::CustomizeDependedAndResults); + initPresentation(ModuleBase_IModule::CustomizeArguments); + initPresentation(ModuleBase_IModule::CustomizeResults); initPresentation(ModuleBase_IModule::CustomizeHighlightedObjects); } @@ -43,13 +44,12 @@ bool PartSet_CustomPrs::activate(const FeaturePtr& theFeature, const bool theUpd #endif myIsActive = true; - + myFeature = theFeature; bool isModified = false; - getPresentation(ModuleBase_IModule::CustomizeDependedAndResults)->setFeature(theFeature); - getPresentation(ModuleBase_IModule::CustomizeHighlightedObjects)->setFeature(theFeature); if (theFeature.get()) { - displayPresentation(ModuleBase_IModule::CustomizeDependedAndResults, theUpdateViewer); + displayPresentation(ModuleBase_IModule::CustomizeArguments, theUpdateViewer); + displayPresentation(ModuleBase_IModule::CustomizeResults, theUpdateViewer); displayPresentation(ModuleBase_IModule::CustomizeHighlightedObjects, theUpdateViewer); isModified = true; } @@ -61,37 +61,47 @@ bool PartSet_CustomPrs::deactivate(const bool theUpdateViewer) myIsActive = false; bool isModified = false; - getPresentation(ModuleBase_IModule::CustomizeDependedAndResults)->setFeature(FeaturePtr()); - getPresentation(ModuleBase_IModule::CustomizeHighlightedObjects)->setFeature(FeaturePtr()); - - erasePresentation(ModuleBase_IModule::CustomizeDependedAndResults, theUpdateViewer); + erasePresentation(ModuleBase_IModule::CustomizeArguments, theUpdateViewer); + erasePresentation(ModuleBase_IModule::CustomizeResults, theUpdateViewer); erasePresentation(ModuleBase_IModule::CustomizeHighlightedObjects, theUpdateViewer); isModified = true; return isModified; } -bool PartSet_CustomPrs::displayPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag, - const bool theUpdateViewer) +bool PartSet_CustomPrs::displayPresentation( + const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag, + const bool theUpdateViewer) { bool isModified = false; + + // update the AIS objects content 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()); + // do nothing if the feature can not be displayed [is moved from presentation, to be checked] + if (!myFeature.get() || !myWorkshop->module()->canDisplayObject(myFeature)) + return isModified; + + switch (theFlag) { + case ModuleBase_IModule::CustomizeArguments: + PartSet_OperationPrs::getFeatureShapes(myFeature, myWorkshop, anOperationPrs->featureShapes()); + break; + case ModuleBase_IModule::CustomizeResults: + PartSet_OperationPrs::getResultShapes(myFeature, myWorkshop, anOperationPrs->featureShapes()); + break; + case ModuleBase_IModule::CustomizeHighlightedObjects: + PartSet_OperationPrs::getHighlightedShapes(myWorkshop, anOperationPrs->featureShapes()); + break; + default: + return isModified; } + // redisplay AIS objects Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); if (!aContext.IsNull() && !aContext->IsDisplayed(anOperationPrs)) { if (anOperationPrs->hasShapes()) { // set color here because it can be changed in preferences - Quantity_Color aShapeColor, aResultColor; - getAISColors(theFlag, aShapeColor, aResultColor); - anOperationPrs->setColors(aShapeColor, aResultColor); + Quantity_Color aShapeColor = getShapeColor(theFlag); + anOperationPrs->setShapeColor(aShapeColor); PartSet_Module* aModule = dynamic_cast(myWorkshop->module()); XGUI_Workshop* aWorkshop = workshop(); @@ -157,7 +167,8 @@ bool PartSet_CustomPrs::redisplay(const ObjectPtr& theObject, void PartSet_CustomPrs::clearPrs() { - clearPresentation(ModuleBase_IModule::CustomizeDependedAndResults); + clearPresentation(ModuleBase_IModule::CustomizeArguments); + clearPresentation(ModuleBase_IModule::CustomizeResults); clearPresentation(ModuleBase_IModule::CustomizeHighlightedObjects); } @@ -166,33 +177,39 @@ void PartSet_CustomPrs::initPresentation(const ModuleBase_IModule::ModuleBase_Cu 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) { + if (theFlag == ModuleBase_IModule::CustomizeArguments || + theFlag == ModuleBase_IModule::CustomizeResults) { anOperationPrs->setPointMarker(5, 2.); anOperationPrs->setWidth(1); } - else if (theFlag == ModuleBase_IModule::CustomizeHighlightedObjects) { + else if (theFlag == ModuleBase_IModule::CustomizeHighlightedObjects) anAISPrs->useAISWidth(); - } if (anOperationPrs.get()) myPresentations[theFlag] = anOperationPrs; } -void PartSet_CustomPrs::getAISColors(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag, - Quantity_Color& theShapeColor, Quantity_Color& theResultColor) +Quantity_Color PartSet_CustomPrs::getShapeColor( + const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag) { - if (theFlag == ModuleBase_IModule::CustomizeDependedAndResults) { - theShapeColor = ModuleBase_Tools::color("Visualization", "operation_parameter_color", - OPERATION_PARAMETER_COLOR()); - theResultColor = ModuleBase_Tools::color("Visualization", "operation_result_color", - OPERATION_RESULT_COLOR()); - } - else if (theFlag == ModuleBase_IModule::CustomizeHighlightedObjects) { - theShapeColor = ModuleBase_Tools::color("Visualization", "operation_highlight_color", - OPERATION_HIGHLIGHT_COLOR()); - theResultColor = ModuleBase_Tools::color("Visualization", "operation_result_color", - OPERATION_RESULT_COLOR()); + Quantity_Color aColor; + switch(theFlag) { + case ModuleBase_IModule::CustomizeArguments: + aColor = ModuleBase_Tools::color("Visualization", "operation_parameter_color", + OPERATION_PARAMETER_COLOR()); + break; + case ModuleBase_IModule::CustomizeResults: + aColor = ModuleBase_Tools::color("Visualization", "operation_result_color", + OPERATION_RESULT_COLOR()); + break; + case ModuleBase_IModule::CustomizeHighlightedObjects: + aColor = ModuleBase_Tools::color("Visualization", "operation_highlight_color", + OPERATION_HIGHLIGHT_COLOR()); + break; + default: + break; } + return aColor; } XGUI_Workshop* PartSet_CustomPrs::workshop() const diff --git a/src/PartSet/PartSet_CustomPrs.h b/src/PartSet/PartSet_CustomPrs.h index 1785818b9..8a27f041c 100755 --- a/src/PartSet/PartSet_CustomPrs.h +++ b/src/PartSet/PartSet_CustomPrs.h @@ -106,15 +106,14 @@ private: /// \param theFlag an object AIS presentation type void clearPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag); - /// Returns presentation colors according to the flag + /// Returns presentation color according to the flag /// \param theFlag an object AIS presentation type - /// \param theShapeColor a color for shapes - /// \param theShapeColor a color for results - void getAISColors(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag, - Quantity_Color& theShapeColor, Quantity_Color& theResultColor); + /// \return theShapeColor a color + Quantity_Color getShapeColor(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag); private: - bool myIsActive; + bool myIsActive; /// State whether the presentation is activated/deactivated + FeaturePtr myFeature; /// Reference to a feature object ModuleBase_IWorkshop* myWorkshop; /// current workshop /// map of presentation type to AIS object QMap myPresentations; diff --git a/src/PartSet/PartSet_OperationPrs.cpp b/src/PartSet/PartSet_OperationPrs.cpp index 6858e0a14..22b5ec243 100755 --- a/src/PartSet/PartSet_OperationPrs.cpp +++ b/src/PartSet/PartSet_OperationPrs.cpp @@ -33,58 +33,25 @@ #include +static const int AIS_DEFAULT_WIDTH = 2; + 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), - myUseAISWidth(false) -{ - myShapeColor = ModuleBase_Tools::color("Visualization", "construction_plane_color", "1,1,0"); - myResultColor = ModuleBase_Tools::color("Visualization", "construction_plane_color", "0,1,0"); -} - -void PartSet_OperationPrs::setFeature(const FeaturePtr& theFeature) -{ - myFeature = theFeature; -} - -void PartSet_OperationPrs::updateShapes() +: ViewerData_AISShape(TopoDS_Shape()), myWorkshop(theWorkshop), myUseAISWidth(false) { - myFeatureResults.clear(); - if (myFeature) - myFeatureResults = myFeature->results(); + myShapeColor = Quantity_Color(1, 1, 1, Quantity_TOC_RGB); } bool PartSet_OperationPrs::hasShapes() { - bool aHasShapes = !myFeatureShapes.empty(); - - // find a result which contains a shape - if (!aHasShapes && !myFeatureResults.empty()) { - std::list::const_iterator aRIt = myFeatureResults.begin(), - aRLast = myFeatureResults.end(); - XGUI_Displayer* aDisplayer = workshop()->displayer(); - for (; aRIt != aRLast; aRIt++) { - ResultPtr aResult = *aRIt; - if (!isVisible(aDisplayer, aResult)) - continue; - GeomShapePtr aGeomShape = aResult->shape(); - if (!aGeomShape.get()) - continue; - TopoDS_Shape aShape = aGeomShape->impl(); - if (!aShape.IsNull()) - aHasShapes = true; - } - } - - return aHasShapes; + return !myFeatureShapes.empty(); } -void PartSet_OperationPrs::setColors(const Quantity_Color& theShapeColor, const Quantity_Color& theResultColor) +void PartSet_OperationPrs::setShapeColor(const Quantity_Color& theColor) { - myShapeColor = theShapeColor; - myResultColor = theResultColor; + myShapeColor = theColor; } void PartSet_OperationPrs::useAISWidth() @@ -96,17 +63,10 @@ void PartSet_OperationPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& t const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode) { - if (!hasShapes()) - return; - // when the feature can not be visualized in the module, the operation preview should not - // be visualized also - if (!myWorkshop->module()->canDisplayObject(myFeature)) - return; - SetColor(myShapeColor); thePresentation->Clear(); - XGUI_Displayer* aDisplayer = workshop()->displayer(); + XGUI_Displayer* aDisplayer = workshop(myWorkshop)->displayer(); Handle(Prs3d_Drawer) aDrawer = Attributes(); // create presentations on the base of the shapes @@ -130,38 +90,20 @@ void PartSet_OperationPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& t AISObjectPtr anAISPtr = aDisplayer->getAISObject(anObject); if (anAISPtr.get()) { Handle(AIS_InteractiveObject) anIO = anAISPtr->impl(); - if (!anIO.IsNull()) - setWidth(aDrawer, anIO->Width()); + if (!anIO.IsNull()) { + int aWidth = anIO->Width(); + /// workaround for zero width. Else, there will be a crash + if (aWidth == 0) { // width returns of TSolid shape is zero + bool isDisplayed = !anIO->GetContext().IsNull(); + aWidth = AIS_DEFAULT_WIDTH;// default width value + } + setWidth(aDrawer, aWidth); + } } } StdPrs_WFDeflectionShape::Add(thePresentation, aShape, aDrawer); } } - - // create presentations on the base of the results - SetColor(myResultColor); - std::list::const_iterator aRIt = myFeatureResults.begin(), - aRLast = myFeatureResults.end(); - for (; aRIt != aRLast; aRIt++) { - ResultPtr aResult = *aRIt; - if (!isVisible(aDisplayer, aResult)) - continue; - GeomShapePtr aGeomShape = aResult->shape(); - if (!aGeomShape.get()) - continue; - TopoDS_Shape aShape = aGeomShape->impl(); - // change deviation coefficient to provide more precise circle - ModuleBase_Tools::setDefaultDeviationCoefficient(aShape, aDrawer); - StdPrs_WFDeflectionShape::Add(thePresentation, aShape, aDrawer); - } - QList aValues; - ModuleBase_IPropertyPanel* aPanel = myWorkshop->propertyPanel(); - if (aPanel) { - ModuleBase_ModelWidget* aWidget = aPanel->activeWidget(); - if (aWidget) { - aWidget->getHighlighted(aValues); - } - } } void PartSet_OperationPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, @@ -311,6 +253,38 @@ void PartSet_OperationPrs::getFeatureShapes(const FeaturePtr& theFeature, } } +void PartSet_OperationPrs::getResultShapes(const FeaturePtr& theFeature, + ModuleBase_IWorkshop* theWorkshop, + QMap >& theObjectShapes) +{ + theObjectShapes.clear(); + + if (!theFeature.get()) + return; + + XGUI_Displayer* aDisplayer = workshop(theWorkshop)->displayer(); + + std::list aFeatureResults = theFeature->results(); + std::list::const_iterator aRIt = aFeatureResults.begin(), + aRLast = aFeatureResults.end(); + for (; aRIt != aRLast; aRIt++) { + ResultPtr aResult = *aRIt; + if (!isVisible(aDisplayer, aResult)) + continue; + GeomShapePtr aGeomShape = aResult->shape(); + if (!aGeomShape.get()) + continue; + + if (theObjectShapes.contains(aResult)) + theObjectShapes[aResult].append(aGeomShape); + else { + QList aShapes; + aShapes.append(aGeomShape); + theObjectShapes[aResult] = aShapes; + } + } +} + void PartSet_OperationPrs::getHighlightedShapes(ModuleBase_IWorkshop* theWorkshop, QMap >& theObjectShapes) { @@ -368,8 +342,8 @@ bool PartSet_OperationPrs::isSelectionAttribute(const AttributePtr& theAttribute anAttrType == ModelAPI_AttributeReference::typeId(); } -XGUI_Workshop* PartSet_OperationPrs::workshop() const +XGUI_Workshop* PartSet_OperationPrs::workshop(ModuleBase_IWorkshop* theWorkshop) { - XGUI_ModuleConnector* aConnector = dynamic_cast(myWorkshop); + XGUI_ModuleConnector* aConnector = dynamic_cast(theWorkshop); return aConnector->workshop(); } diff --git a/src/PartSet/PartSet_OperationPrs.h b/src/PartSet/PartSet_OperationPrs.h index 89d2c252e..bf1e5a2bc 100755 --- a/src/PartSet/PartSet_OperationPrs.h +++ b/src/PartSet/PartSet_OperationPrs.h @@ -47,20 +47,12 @@ public: /// Constructor Standard_EXPORT PartSet_OperationPrs(ModuleBase_IWorkshop* theWorkshop); - /// Sets the operation feature. It is used in Compute method to group the feature parameter shapes - /// theFeature a feature - void setFeature(const FeaturePtr& theFeature); - - // Recompute internal list of shaped dependent on the current feature - void updateShapes(); - /// 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); + /// \param theColor an argument shapes color + void setShapeColor(const Quantity_Color& theColor); /// Switch on using of the AIS presentation with of the shape object increased on the delta void useAISWidth(); @@ -78,9 +70,6 @@ protected: 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; } @@ -91,7 +80,7 @@ private: /// \param theDisplayer a displayer /// \param theObject an object /// \return a boolean value - bool isVisible(XGUI_Displayer* theDislayer, const ObjectPtr& theObject); + static bool isVisible(XGUI_Displayer* theDislayer, const ObjectPtr& theObject); /// Fills the map by the feature object and shapes, which should be visuaziled /// Gets feature attributes, collect objects to whom the attributes refer @@ -103,6 +92,16 @@ private: ModuleBase_IWorkshop* theWorkshop, QMap >& theObjectShapes); + /// Fills the map by the feature object and shapes, which should be visuaziled + /// 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 + static void getResultShapes(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 @@ -117,18 +116,15 @@ private: static bool isSelectionAttribute(const AttributePtr& theAttribute); /// Converts the current workshop to XGUI workshop + /// \param theWorkshop an interface workshop /// \return a workshop instance - XGUI_Workshop* workshop() const; + static XGUI_Workshop* workshop(ModuleBase_IWorkshop* theWorkshop); private: - ModuleBase_IWorkshop* myWorkshop; - FeaturePtr myFeature; /// Reference to a feature object QMap > myFeatureShapes; /// visualized shapes - std::list myFeatureResults; /// visualized feature results + ModuleBase_IWorkshop* myWorkshop; /// current workshop 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 d8934f2da..c87f0aa3d 100755 --- a/src/XGUI/XGUI_WorkshopListener.cpp +++ b/src/XGUI/XGUI_WorkshopListener.cpp @@ -583,7 +583,9 @@ bool XGUI_WorkshopListener::customizeCurrentObject(const std::set& th // e.g. extrusion is hidden(h=0) but sketch is chosen if (theForceRedisplay || theObjects.find(aCurrentFeature) != theObjects.end()) { aCustomized = myWorkshop->module()->customizeObject(aCurrentFeature, - ModuleBase_IModule::CustomizeDependedAndResults, false); + ModuleBase_IModule::CustomizeArguments, false); + aCustomized = myWorkshop->module()->customizeObject(aCurrentFeature, + ModuleBase_IModule::CustomizeResults, false); aCustomized = myWorkshop->module()->customizeObject(aCurrentFeature, ModuleBase_IModule::CustomizeHighlightedObjects, false); }