X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPartSet%2FPartSet_CustomPrs.cpp;h=604e593c2d711f41d2dadf84d650090edde09517;hb=64f8bd887acebdba2dfa6d5e26f0ee969ae33772;hp=a90b634ac4b71ed3399f5c8d5903dc9e2f4fdb80;hpb=9ddba1caf0817c1e95c55d4c5b8ae6de23cbe6d5;p=modules%2Fshaper.git diff --git a/src/PartSet/PartSet_CustomPrs.cpp b/src/PartSet/PartSet_CustomPrs.cpp index a90b634ac..604e593c2 100755 --- a/src/PartSet/PartSet_CustomPrs.cpp +++ b/src/PartSet/PartSet_CustomPrs.cpp @@ -7,6 +7,7 @@ #include #include #include "PartSet_OperationPrs.h" +#include "PartSet_OverconstraintListener.h" #include #include @@ -14,110 +15,251 @@ #include #include - -#include - -#include -#include +#include #include +#include +#include #include #include #include -#define OPERATION_PARAMETER_COLOR "255, 255, 0" +//#define DO_NOT_VISUALIZE_CUSTOM_PRESENTATION PartSet_CustomPrs::PartSet_CustomPrs(ModuleBase_IWorkshop* theWorkshop) - : myWorkshop(theWorkshop) + : myWorkshop(theWorkshop), myFeature(FeaturePtr()), myPresentationIsEmpty(false) { - myOperationPrs = AISObjectPtr(new GeomAPI_AISObject()); - myOperationPrs->setImpl(new Handle(AIS_InteractiveObject)(new PartSet_OperationPrs(theWorkshop))); + Events_Loop* aLoop = Events_Loop::loop(); + aLoop->registerListener(this, Events_Loop::eventByName(EVENT_EMPTY_OPERATION_PRESENTATION)); - std::vector aColor = Config_PropManager::color("Visualization", "operation_parameter_color", - OPERATION_PARAMETER_COLOR); - myOperationPrs->setColor(aColor[0], aColor[1], aColor[2]); + initPresentation(ModuleBase_IModule::CustomizeArguments); + initPresentation(ModuleBase_IModule::CustomizeResults); + initPresentation(ModuleBase_IModule::CustomizeHighlightedObjects); - myOperationPrs->setPointMarker(5, 2.); - myOperationPrs->setWidth(1); + myIsActive[ModuleBase_IModule::CustomizeArguments] = false; + myIsActive[ModuleBase_IModule::CustomizeResults] = false; + myIsActive[ModuleBase_IModule::CustomizeHighlightedObjects] = false; } -bool PartSet_CustomPrs::isActive() const +bool PartSet_CustomPrs::isActive(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag) { - Handle(PartSet_OperationPrs) anOperationPrs = getPresentation(); - Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); - - return aContext->IsDisplayed(anOperationPrs); + return myIsActive[theFlag]; } -void PartSet_CustomPrs::activate(const FeaturePtr& theFeature) +bool PartSet_CustomPrs::activate(const FeaturePtr& theFeature, + const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag, + const bool theUpdateViewer) { - Handle(PartSet_OperationPrs) anOperationPrs = getPresentation(); +#ifdef DO_NOT_VISUALIZE_CUSTOM_PRESENTATION + return false; +#endif - if (anOperationPrs->canActivate(theFeature)) { - anOperationPrs->setFeature(theFeature); - if (theFeature.get()) - displayPresentation(); + myIsActive[theFlag] = true; + myFeature = theFeature; + + bool isModified = false; + if (theFeature.get()) { + displayPresentation(theFlag, theUpdateViewer); + isModified = true; } + return isModified; } -void PartSet_CustomPrs::deactivate() +bool PartSet_CustomPrs::deactivate(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag, + const bool theUpdateViewer) { - Handle(PartSet_OperationPrs) anOperationPrs = getPresentation(); - anOperationPrs->setFeature(FeaturePtr()); + myIsActive[theFlag] = false; + erasePresentation(theFlag, theUpdateViewer); + return true; +} + +bool PartSet_CustomPrs::displayPresentation( + const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag, + const bool theUpdateViewer) +{ + bool isModified = false; + + // update the AIS objects content + AISObjectPtr aPresentation = getPresentation(theFlag, true); + Handle(AIS_InteractiveObject) anAISIO = aPresentation->impl(); + Handle(PartSet_OperationPrs) anOperationPrs = Handle(PartSet_OperationPrs)::DownCast(anAISIO); - erasePresentation(); + // do nothing if the feature can not be displayed [is moved from presentation, to be checked] + if (!myFeature.get()) + return isModified; + + QMap > aFeatureShapes; + switch (theFlag) { + case ModuleBase_IModule::CustomizeArguments: + PartSet_OperationPrs::getFeatureShapes(myFeature, myWorkshop, aFeatureShapes); + break; + case ModuleBase_IModule::CustomizeResults: + PartSet_OperationPrs::getResultShapes(myFeature, myWorkshop, aFeatureShapes); + break; + case ModuleBase_IModule::CustomizeHighlightedObjects: + PartSet_OperationPrs::getHighlightedShapes(myWorkshop, aFeatureShapes); + break; + default: + return isModified; + } + NCollection_DataMap& aShapeMap = + anOperationPrs->shapesMap(); + PartSet_OperationPrs::fillShapeList(aFeatureShapes, myWorkshop, aShapeMap); + + myPresentationIsEmpty = false; + // redisplay AIS objects + bool aRedisplayed = false; + Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); + if (!aContext.IsNull() && !aContext->IsDisplayed(anOperationPrs)) { + // when the feature can not be visualized in the module, the operation preview should not + // be visualized also + if (anOperationPrs->hasShapes() && myWorkshop->module()->canDisplayObject(myFeature)) { + // set color here because it can be changed in preferences + Quantity_Color aShapeColor = getShapeColor(theFlag); + anOperationPrs->setShapeColor(aShapeColor); + + PartSet_Module* aModule = dynamic_cast(myWorkshop->module()); + XGUI_Workshop* aWorkshop = workshop(); + aRedisplayed = aWorkshop->displayer()->displayAIS(myPresentations[theFlag], + false/*load object in selection*/, false); + aContext->SetZLayer(anOperationPrs, aModule->getVisualLayerId()); + isModified = true; + } + } + else { + // when the feature can not be visualized in the module, the operation preview should not + // be visualized also + if (!anOperationPrs->hasShapes() || !myWorkshop->module()->canDisplayObject(myFeature)) { + aRedisplayed = erasePresentation(theFlag, false); + isModified = true; + } + else { + anOperationPrs->Redisplay(); + isModified = true; + aRedisplayed = true; + } + } + if (myPresentationIsEmpty) { + aRedisplayed = erasePresentation(theFlag, false); + } + if (aRedisplayed && theUpdateViewer) + workshop()->displayer()->updateViewer(); + + return isModified; } +bool PartSet_CustomPrs::erasePresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag, + const bool theUpdateViewer) +{ + bool isErased = false; + XGUI_Workshop* aWorkshop = workshop(); + if (myPresentations.contains(theFlag)) + isErased = aWorkshop->displayer()->eraseAIS(myPresentations[theFlag], theUpdateViewer); + return isErased; +} -void PartSet_CustomPrs::displayPresentation() +void PartSet_CustomPrs::clearPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag) { - Handle(PartSet_OperationPrs) anOperationPrs = getPresentation(); + AISObjectPtr aPresentation = getPresentation(theFlag, false); + if (aPresentation.get()) { + Handle(AIS_InteractiveObject) anAISIO = aPresentation->impl(); + Handle(PartSet_OperationPrs) anOperationPrs = Handle(PartSet_OperationPrs)::DownCast(anAISIO); - Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); - if (!aContext->IsDisplayed(anOperationPrs)) { - PartSet_Module* aModule = dynamic_cast(myWorkshop->module()); - aContext->Display(anOperationPrs); - aContext->SetZLayer(anOperationPrs, aModule->getVisualLayerId()); + anOperationPrs->shapesMap().Clear(); + if (!anOperationPrs.IsNull()) + anOperationPrs.Nullify(); + myPresentations.remove(theFlag); } - else - anOperationPrs->Redisplay(); } -void PartSet_CustomPrs::erasePresentation() +AISObjectPtr PartSet_CustomPrs::getPresentation( + const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag, + const bool theToCreate) { - Handle(AIS_InteractiveObject) anOperationPrs = myOperationPrs->impl(); - Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); - if (aContext->IsDisplayed(anOperationPrs)) - aContext->Remove(anOperationPrs); + Handle(PartSet_OperationPrs) aPresentation; + + AISObjectPtr anOperationPrs; + if (myPresentations.contains(theFlag)) + anOperationPrs = myPresentations[theFlag]; + + if (!anOperationPrs.get() && theToCreate) { + initPresentation(theFlag); + anOperationPrs = myPresentations[theFlag]; + } + + return anOperationPrs; } -Handle(PartSet_OperationPrs) PartSet_CustomPrs::getPresentation() const +bool PartSet_CustomPrs::redisplay(const ObjectPtr& theObject, + const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag, + const bool theUpdateViewer) { - Handle(AIS_InteractiveObject) anAISIO = myOperationPrs->impl(); - return Handle(PartSet_OperationPrs)::DownCast(anAISIO); +#ifdef DO_NOT_VISUALIZE_CUSTOM_PRESENTATION + return false; +#endif + bool aRedisplayed = false; + if (myIsActive[theFlag]) + aRedisplayed = displayPresentation(theFlag, theUpdateViewer); + + return aRedisplayed; } -bool PartSet_CustomPrs::customize(const ObjectPtr& theObject) +void PartSet_CustomPrs::clearPrs() { - // the presentation should be recomputed if the previous AIS depend on the result - // [it should be hiddend] or the new AIS depend on it [it should be visualized] - Handle(PartSet_OperationPrs) anOperationPrs = getPresentation(); - Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); - if (aContext->IsDisplayed(anOperationPrs)) { - bool aChanged = anOperationPrs->dependOn(theObject); + clearPresentation(ModuleBase_IModule::CustomizeArguments); + clearPresentation(ModuleBase_IModule::CustomizeResults); + clearPresentation(ModuleBase_IModule::CustomizeHighlightedObjects); +} - anOperationPrs->updateShapes(); - aChanged = aChanged || anOperationPrs->dependOn(theObject); +void PartSet_CustomPrs::processEvent(const std::shared_ptr& theMessage) +{ + if (theMessage->eventID() == Events_Loop::eventByName(EVENT_EMPTY_OPERATION_PRESENTATION)) + myPresentationIsEmpty = true; /// store state to analize it after display/erase is finished +} - //if (aChanged) - anOperationPrs->Redisplay(); +void PartSet_CustomPrs::initPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag) +{ + 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::CustomizeArguments || + theFlag == ModuleBase_IModule::CustomizeResults) { + anOperationPrs->setPointMarker(5, 2.); + anOperationPrs->setWidth(1); } - return false; + else if (theFlag == ModuleBase_IModule::CustomizeHighlightedObjects) + anAISPrs->useAISWidth(); + + if (anOperationPrs.get()) + myPresentations[theFlag] = anOperationPrs; } -bool PartSet_CustomPrs::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs, - std::shared_ptr theCustomPrs) +Quantity_Color PartSet_CustomPrs::getShapeColor( + const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag) { - return false; + 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 +{ + XGUI_ModuleConnector* aConnector = dynamic_cast(myWorkshop); + return aConnector->workshop(); }