X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPartSet%2FPartSet_CustomPrs.cpp;h=7b4ab82a290d555e4557e58159807d81eaf29a4c;hb=3cae3b732cbc48455adeef43b3efd6dfc1cac81d;hp=ab96e5538938eebb6f9024a3ff652baf211002cd;hpb=1b93f1881c5fec599aa79707f93c84dd9c287bc0;p=modules%2Fshaper.git diff --git a/src/PartSet/PartSet_CustomPrs.cpp b/src/PartSet/PartSet_CustomPrs.cpp old mode 100755 new mode 100644 index ab96e5538..7b4ab82a2 --- a/src/PartSet/PartSet_CustomPrs.cpp +++ b/src/PartSet/PartSet_CustomPrs.cpp @@ -1,12 +1,26 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: PartSet_CustomPrs.cpp -// Created: 30 Jun 2015 -// Author: Natalia ERMOLAEVA +// Copyright (C) 2014-2019 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// #include #include #include "PartSet_OperationPrs.h" +#include "PartSet_OverconstraintListener.h" #include #include @@ -14,149 +28,248 @@ #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), myIsActive(false) + : myWorkshop(theWorkshop), myFeature(FeaturePtr()), myPresentationIsEmpty(false) { - initPrs(); -} + Events_Loop* aLoop = Events_Loop::loop(); + aLoop->registerListener(this, Events_Loop::eventByName(EVENT_EMPTY_OPERATION_PRESENTATION)); -bool PartSet_CustomPrs::isActive() -{ - return myIsActive; - /*Handle(PartSet_OperationPrs) anOperationPrs = getPresentation(); - Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); + initPresentation(ModuleBase_IModule::CustomizeArguments); + initPresentation(ModuleBase_IModule::CustomizeResults); + initPresentation(ModuleBase_IModule::CustomizeHighlightedObjects); - return !aContext.IsNull() && aContext->IsDisplayed(anOperationPrs);*/ + myIsActive[ModuleBase_IModule::CustomizeArguments] = false; + myIsActive[ModuleBase_IModule::CustomizeResults] = false; + myIsActive[ModuleBase_IModule::CustomizeHighlightedObjects] = false; } -bool PartSet_CustomPrs::activate(const FeaturePtr& theFeature, const bool theUpdateViewer) +bool PartSet_CustomPrs::isActive(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag) { - bool isModified = false; - Handle(PartSet_OperationPrs) anOperationPrs = getPresentation(); - - if (anOperationPrs->canActivate(theFeature)) { - myIsActive = true; - anOperationPrs->setFeature(theFeature); - if (theFeature.get()) { - displayPresentation(theUpdateViewer); - isModified = true; - } - } - return isModified; + return myIsActive[theFlag]; } -bool PartSet_CustomPrs::deactivate(const bool theUpdateViewer) +bool PartSet_CustomPrs::activate(const FeaturePtr& theFeature, + const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag, + const bool theUpdateViewer) { - myIsActive = false; - bool isModified = false; +#ifdef DO_NOT_VISUALIZE_CUSTOM_PRESENTATION + return false; +#endif - Handle(PartSet_OperationPrs) anOperationPrs = getPresentation(); - anOperationPrs->setFeature(FeaturePtr()); + myIsActive[theFlag] = true; + myFeature = theFeature; - Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); - if (!aContext.IsNull() && aContext->IsDisplayed(anOperationPrs)) { - erasePresentation(theUpdateViewer); + bool isModified = false; + if (theFeature.get()) { + displayPresentation(theFlag, theUpdateViewer); isModified = true; } - return isModified; } +bool PartSet_CustomPrs::deactivate(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag, + const bool theUpdateViewer) +{ + myIsActive[theFlag] = false; + erasePresentation(theFlag, theUpdateViewer); + return true; +} -void PartSet_CustomPrs::displayPresentation(const bool theUpdateViewer) +bool PartSet_CustomPrs::displayPresentation( + const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag, + const bool theUpdateViewer) { - Handle(PartSet_OperationPrs) anOperationPrs = getPresentation(); + 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); + + // 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); + PartSet_OperationPrs::getPresentationShapes(myFeature, myWorkshop, aFeatureShapes, false); + 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)) { - if (anOperationPrs->hasShapes()) { + // 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(); - aWorkshop->displayer()->displayAIS(myOperationPrs, false/*load object in selection*/, theUpdateViewer); + aRedisplayed = aWorkshop->displayer()->displayAIS(myPresentations[theFlag], + false/*load object in selection*/, false); aContext->SetZLayer(anOperationPrs, aModule->getVisualLayerId()); + isModified = true; } } else { - if (!anOperationPrs->hasShapes()) - erasePresentation(theUpdateViewer); + // 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(); - if (theUpdateViewer) - workshop()->displayer()->updateViewer(); + isModified = true; + aRedisplayed = true; } } + if (myPresentationIsEmpty) { + aRedisplayed = erasePresentation(theFlag, false); + } + if (aRedisplayed && theUpdateViewer) + workshop()->displayer()->updateViewer(); + + return isModified; } -void PartSet_CustomPrs::erasePresentation(const bool theUpdateViewer) +bool PartSet_CustomPrs::erasePresentation( + const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag, + const bool theUpdateViewer) { + bool isErased = false; XGUI_Workshop* aWorkshop = workshop(); - aWorkshop->displayer()->eraseAIS(myOperationPrs, theUpdateViewer); + if (myPresentations.contains(theFlag)) + isErased = aWorkshop->displayer()->eraseAIS(myPresentations[theFlag], theUpdateViewer); + return isErased; } -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); + AISObjectPtr aPresentation = getPresentation(theFlag, false); + if (aPresentation.get()) { + Handle(AIS_InteractiveObject) anAISIO = aPresentation->impl(); + Handle(PartSet_OperationPrs) anOperationPrs = Handle(PartSet_OperationPrs)::DownCast(anAISIO); + + anOperationPrs->shapesMap().Clear(); + if (!anOperationPrs.IsNull()) + anOperationPrs.Nullify(); + myPresentations.remove(theFlag); + } } -bool PartSet_CustomPrs::redisplay(const ObjectPtr& theObject, const bool theUpdateViewer) +AISObjectPtr PartSet_CustomPrs::getPresentation( + const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag, + const bool theToCreate) { - bool isModified = false; - // 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.IsNull()) { - if (aContext->IsDisplayed(anOperationPrs)) { - // if there are performance poblems, to improve them, the necessity of redisplay can be checked - //bool aChanged = anOperationPrs->dependOn(theObject); - anOperationPrs->updateShapes(); - //aChanged = aChanged || anOperationPrs->dependOn(theObject); - //if (aChanged) - anOperationPrs->Redisplay(); - isModified = true; - if (theUpdateViewer) - workshop()->displayer()->updateViewer(); - } - else { - anOperationPrs->updateShapes(); - displayPresentation(theUpdateViewer); - } + Handle(PartSet_OperationPrs) aPresentation; + + AISObjectPtr anOperationPrs; + if (myPresentations.contains(theFlag)) + anOperationPrs = myPresentations[theFlag]; + + if (!anOperationPrs.get() && theToCreate) { + initPresentation(theFlag); + anOperationPrs = myPresentations[theFlag]; } - return isModified; + + return anOperationPrs; +} + +bool PartSet_CustomPrs::redisplay(const ObjectPtr& theObject, + const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag, + const bool theUpdateViewer) +{ +#ifdef DO_NOT_VISUALIZE_CUSTOM_PRESENTATION + return false; +#endif + bool aRedisplayed = false; + if (myIsActive[theFlag]) + aRedisplayed = displayPresentation(theFlag, theUpdateViewer); + + return aRedisplayed; } void PartSet_CustomPrs::clearPrs() { - Handle(PartSet_OperationPrs) anOperationPrs = getPresentation(); - if (!anOperationPrs.IsNull()) - anOperationPrs.Nullify(); + clearPresentation(ModuleBase_IModule::CustomizeArguments); + clearPresentation(ModuleBase_IModule::CustomizeResults); + clearPresentation(ModuleBase_IModule::CustomizeHighlightedObjects); +} - myOperationPrs.reset(); +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 } -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))); + 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); + } + else if (theFlag == ModuleBase_IModule::CustomizeHighlightedObjects) + anAISPrs->useAISWidth(); - std::vector aColor = Config_PropManager::color("Visualization", "operation_parameter_color", - OPERATION_PARAMETER_COLOR); - myOperationPrs->setColor(aColor[0], aColor[1], aColor[2]); + if (anOperationPrs.get()) + myPresentations[theFlag] = anOperationPrs; +} - myOperationPrs->setPointMarker(5, 2.); - myOperationPrs->setWidth(1); +Quantity_Color PartSet_CustomPrs::getShapeColor( + const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag) +{ + Quantity_Color aColor; + switch(theFlag) { + case ModuleBase_IModule::CustomizeArguments: + aColor = ModuleBase_Tools::color("Visualization", "operation_parameter_color"); + break; + case ModuleBase_IModule::CustomizeResults: + aColor = ModuleBase_Tools::color("Visualization", "operation_result_color"); + break; + case ModuleBase_IModule::CustomizeHighlightedObjects: + aColor = ModuleBase_Tools::color("Visualization", "operation_highlight_color"); + break; + default: + break; + } + return aColor; } XGUI_Workshop* PartSet_CustomPrs::workshop() const