X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPartSet%2FPartSet_CustomPrs.cpp;h=e18ca5bb063b58a5716997908d3c8b078328ac4d;hb=8d623696a0aa115c52e14f5e326eb6cb64a16f0d;hp=bf4a8b8d69510de6c687584a9309113299e1d96d;hpb=424c4d0d681755b6901d769e1e93c5d749174ba0;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 bf4a8b8d6..e18ca5bb0 --- a/src/PartSet/PartSet_CustomPrs.cpp +++ b/src/PartSet/PartSet_CustomPrs.cpp @@ -1,13 +1,27 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: PartSet_CustomPrs.cpp -// Created: 30 Jun 2015 -// Author: Natalia ERMOLAEVA - -#include -#include +// 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 "PartSet_CustomPrs.h" +#include "PartSet_Module.h" #include "PartSet_OperationPrs.h" #include "PartSet_OverconstraintListener.h" +#include "PartSet_SketcherMgr.h" #include #include @@ -17,7 +31,12 @@ #include #include +#include +#include + #include +#include +#include #include #include @@ -26,8 +45,12 @@ //#define DO_NOT_VISUALIZE_CUSTOM_PRESENTATION PartSet_CustomPrs::PartSet_CustomPrs(ModuleBase_IWorkshop* theWorkshop) - : myWorkshop(theWorkshop), myFeature(FeaturePtr()) + : myWorkshop(theWorkshop), myFeature(FeaturePtr()), myPresentationIsEmpty(false), + myDisabledMode(-1) { + Events_Loop* aLoop = Events_Loop::loop(); + aLoop->registerListener(this, Events_Loop::eventByName(EVENT_EMPTY_OPERATION_PRESENTATION)); + initPresentation(ModuleBase_IModule::CustomizeArguments); initPresentation(ModuleBase_IModule::CustomizeResults); initPresentation(ModuleBase_IModule::CustomizeHighlightedObjects); @@ -49,15 +72,23 @@ bool PartSet_CustomPrs::activate(const FeaturePtr& theFeature, #ifdef DO_NOT_VISUALIZE_CUSTOM_PRESENTATION return false; #endif + bool isModified = false; + + // Do not call customisation for sketcher and all its sub-objects + if (theFeature->getKind() == SketchPlugin_Sketch::ID()) + return isModified; - myIsActive[theFlag] = true; - myFeature = theFeature; + FeaturePtr aParent = ModelAPI_Tools::compositeOwner(theFeature); + if (aParent.get()) { + std::string aType = aParent->getKind(); + if (aType == SketchPlugin_Sketch::ID()) + return isModified; + } - bool isModified = false; if (theFeature.get()) { - displayPresentation(ModuleBase_IModule::CustomizeArguments, theUpdateViewer); - displayPresentation(ModuleBase_IModule::CustomizeResults, theUpdateViewer); - displayPresentation(ModuleBase_IModule::CustomizeHighlightedObjects, theUpdateViewer); + myIsActive[theFlag] = true; + myFeature = theFeature; + displayPresentation(theFlag, theUpdateViewer); isModified = true; } return isModified; @@ -67,14 +98,8 @@ bool PartSet_CustomPrs::deactivate(const ModuleBase_IModule::ModuleBase_Customiz const bool theUpdateViewer) { myIsActive[theFlag] = false; - bool isModified = false; - - erasePresentation(ModuleBase_IModule::CustomizeArguments, theUpdateViewer); - erasePresentation(ModuleBase_IModule::CustomizeResults, theUpdateViewer); - erasePresentation(ModuleBase_IModule::CustomizeHighlightedObjects, theUpdateViewer); - isModified = true; - - return isModified; + erasePresentation(theFlag, theUpdateViewer); + return true; } bool PartSet_CustomPrs::displayPresentation( @@ -83,6 +108,9 @@ bool PartSet_CustomPrs::displayPresentation( { bool isModified = false; + if (myDisabledMode == theFlag) + return isModified; + // update the AIS objects content AISObjectPtr aPresentation = getPresentation(theFlag, true); Handle(AIS_InteractiveObject) anAISIO = aPresentation->impl(); @@ -92,21 +120,28 @@ bool PartSet_CustomPrs::displayPresentation( if (!myFeature.get()) return isModified; + QMap > aFeatureShapes; switch (theFlag) { case ModuleBase_IModule::CustomizeArguments: - PartSet_OperationPrs::getFeatureShapes(myFeature, myWorkshop, anOperationPrs->featureShapes()); + PartSet_OperationPrs::getFeatureShapes(myFeature, myWorkshop, aFeatureShapes); break; case ModuleBase_IModule::CustomizeResults: - PartSet_OperationPrs::getResultShapes(myFeature, myWorkshop, anOperationPrs->featureShapes()); + PartSet_OperationPrs::getResultShapes(myFeature, myWorkshop, aFeatureShapes); + PartSet_OperationPrs::getPresentationShapes(myFeature, myWorkshop, aFeatureShapes, false); break; case ModuleBase_IModule::CustomizeHighlightedObjects: - PartSet_OperationPrs::getHighlightedShapes(myWorkshop, anOperationPrs->featureShapes()); + 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 @@ -118,8 +153,8 @@ bool PartSet_CustomPrs::displayPresentation( PartSet_Module* aModule = dynamic_cast(myWorkshop->module()); XGUI_Workshop* aWorkshop = workshop(); - aWorkshop->displayer()->displayAIS(myPresentations[theFlag], false/*load object in selection*/, - theUpdateViewer); + aRedisplayed = aWorkshop->displayer()->displayAIS(myPresentations[theFlag], + false/*load object in selection*/, 0, false); aContext->SetZLayer(anOperationPrs, aModule->getVisualLayerId()); isModified = true; } @@ -128,35 +163,44 @@ bool PartSet_CustomPrs::displayPresentation( // 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)) { - erasePresentation(theFlag, theUpdateViewer); + aRedisplayed = erasePresentation(theFlag, false); isModified = true; } else { anOperationPrs->Redisplay(); isModified = true; - if (theUpdateViewer) - workshop()->displayer()->updateViewer(); + aRedisplayed = true; } } + if (myPresentationIsEmpty) { + aRedisplayed = erasePresentation(theFlag, false); + } + if (aRedisplayed && theUpdateViewer) + workshop()->displayer()->updateViewer(); + return isModified; } -void PartSet_CustomPrs::erasePresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag, - const bool theUpdateViewer) +bool PartSet_CustomPrs::erasePresentation( + const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag, + const bool theUpdateViewer) { + bool isErased = false; XGUI_Workshop* aWorkshop = workshop(); if (myPresentations.contains(theFlag)) - aWorkshop->displayer()->eraseAIS(myPresentations[theFlag], theUpdateViewer); + isErased = aWorkshop->displayer()->eraseAIS(myPresentations[theFlag], theUpdateViewer); + return isErased; } -void PartSet_CustomPrs::clearPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag) +void PartSet_CustomPrs::clearPresentation( + const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag) { AISObjectPtr aPresentation = getPresentation(theFlag, false); if (aPresentation.get()) { Handle(AIS_InteractiveObject) anAISIO = aPresentation->impl(); Handle(PartSet_OperationPrs) anOperationPrs = Handle(PartSet_OperationPrs)::DownCast(anAISIO); - anOperationPrs->featureShapes().clear(); + anOperationPrs->shapesMap().Clear(); if (!anOperationPrs.IsNull()) anOperationPrs.Nullify(); myPresentations.remove(theFlag); @@ -172,7 +216,7 @@ AISObjectPtr PartSet_CustomPrs::getPresentation( AISObjectPtr anOperationPrs; if (myPresentations.contains(theFlag)) anOperationPrs = myPresentations[theFlag]; - + if (!anOperationPrs.get() && theToCreate) { initPresentation(theFlag); anOperationPrs = myPresentations[theFlag]; @@ -191,7 +235,7 @@ bool PartSet_CustomPrs::redisplay(const ObjectPtr& theObject, bool aRedisplayed = false; if (myIsActive[theFlag]) aRedisplayed = displayPresentation(theFlag, theUpdateViewer); - + return aRedisplayed; } @@ -202,7 +246,14 @@ void PartSet_CustomPrs::clearPrs() clearPresentation(ModuleBase_IModule::CustomizeHighlightedObjects); } -void PartSet_CustomPrs::initPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag) +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::initPresentation( + const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag) { AISObjectPtr anOperationPrs = AISObjectPtr(new GeomAPI_AISObject()); Handle(PartSet_OperationPrs) anAISPrs = new PartSet_OperationPrs(myWorkshop); @@ -210,7 +261,7 @@ void PartSet_CustomPrs::initPresentation(const ModuleBase_IModule::ModuleBase_Cu if (theFlag == ModuleBase_IModule::CustomizeArguments || theFlag == ModuleBase_IModule::CustomizeResults) { anOperationPrs->setPointMarker(5, 2.); - anOperationPrs->setWidth(1); + anOperationPrs->setWidth((theFlag == ModuleBase_IModule::CustomizeHighlightedObjects)? 2 : 1); } else if (theFlag == ModuleBase_IModule::CustomizeHighlightedObjects) anAISPrs->useAISWidth(); @@ -225,16 +276,13 @@ Quantity_Color PartSet_CustomPrs::getShapeColor( Quantity_Color aColor; switch(theFlag) { case ModuleBase_IModule::CustomizeArguments: - aColor = ModuleBase_Tools::color("Visualization", "operation_parameter_color", - OPERATION_PARAMETER_COLOR()); + aColor = ModuleBase_Tools::color("Visualization", "operation_parameter_color"); break; case ModuleBase_IModule::CustomizeResults: - aColor = ModuleBase_Tools::color("Visualization", "operation_result_color", - OPERATION_RESULT_COLOR()); + aColor = ModuleBase_Tools::color("Visualization", "operation_result_color"); break; case ModuleBase_IModule::CustomizeHighlightedObjects: - aColor = ModuleBase_Tools::color("Visualization", "operation_highlight_color", - OPERATION_HIGHLIGHT_COLOR()); + aColor = ModuleBase_Tools::color("Visualization", "operation_highlight_color"); break; default: break;