X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FPartSet%2FPartSet_CustomPrs.cpp;h=05f8d9b725e8cf81fc65da83fd4ffc3865865a1d;hb=374a366d81778aa27ed32cc080c0f95bdb03f1c5;hp=21465eb1cb133887e2a96caf458beb7fe9b87fd6;hpb=a9f5309bd682fcf172c58d4ee25720d1633b0ea6;p=modules%2Fshaper.git diff --git a/src/PartSet/PartSet_CustomPrs.cpp b/src/PartSet/PartSet_CustomPrs.cpp index 21465eb1c..05f8d9b72 100644 --- a/src/PartSet/PartSet_CustomPrs.cpp +++ b/src/PartSet/PartSet_CustomPrs.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2019 CEA/DEN, EDF R&D +// Copyright (C) 2014-2021 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 @@ -17,10 +17,11 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -#include -#include +#include "PartSet_CustomPrs.h" +#include "PartSet_Module.h" #include "PartSet_OperationPrs.h" #include "PartSet_OverconstraintListener.h" +#include "PartSet_SketcherMgr.h" #include #include @@ -30,9 +31,13 @@ #include #include +#include +#include + #include #include #include +#include #include #include @@ -46,6 +51,7 @@ PartSet_CustomPrs::PartSet_CustomPrs(ModuleBase_IWorkshop* theWorkshop) { Events_Loop* aLoop = Events_Loop::loop(); aLoop->registerListener(this, Events_Loop::eventByName(EVENT_EMPTY_OPERATION_PRESENTATION)); + aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OPERATION_SHAPES_FAILED)); initPresentation(ModuleBase_IModule::CustomizeArguments); initPresentation(ModuleBase_IModule::CustomizeResults); @@ -68,12 +74,22 @@ bool PartSet_CustomPrs::activate(const FeaturePtr& theFeature, #ifdef DO_NOT_VISUALIZE_CUSTOM_PRESENTATION return false; #endif + bool isModified = false; - myIsActive[theFlag] = true; - myFeature = theFeature; + // Do not call customisation for sketcher and all its sub-objects + if (theFeature->getKind() == SketchPlugin_Sketch::ID()) + return isModified; + + 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()) { + myIsActive[theFlag] = true; + myFeature = theFeature; displayPresentation(theFlag, theUpdateViewer); isModified = true; } @@ -85,6 +101,8 @@ bool PartSet_CustomPrs::deactivate(const ModuleBase_IModule::ModuleBase_Customiz { myIsActive[theFlag] = false; erasePresentation(theFlag, theUpdateViewer); + if (theFlag == ModuleBase_IModule::CustomizeResults) + clearErrorShape(); return true; } @@ -153,6 +171,10 @@ bool PartSet_CustomPrs::displayPresentation( isModified = true; } else { + if (myFeature->firstResult().get() && myFeature->firstResult()->hasTextureFile()) + { + PartSet_Module::setTexture( myFeature->firstResult()->getTextureFile(), aPresentation); + } anOperationPrs->Redisplay(); isModified = true; aRedisplayed = true; @@ -230,12 +252,53 @@ void PartSet_CustomPrs::clearPrs() clearPresentation(ModuleBase_IModule::CustomizeArguments); clearPresentation(ModuleBase_IModule::CustomizeResults); clearPresentation(ModuleBase_IModule::CustomizeHighlightedObjects); + clearErrorShape(); +} + +void PartSet_CustomPrs::clearErrorShape() +{ + if (!myErrorShapes.IsNull()) { + Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); + if (aContext->IsDisplayed(myErrorShapes)) { + aContext->Remove(myErrorShapes, true); + myErrorShapes.Nullify(); + } + } } 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 + else if (theMessage->eventID() == Events_Loop::eventByName(EVENT_OPERATION_SHAPES_FAILED)) { + std::shared_ptr aErrMsg = + std::dynamic_pointer_cast(theMessage); + Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); + ListOfShape aShapes = aErrMsg->shapes(); + if (aShapes.size() > 0) { + GeomShapePtr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aShapes); + TopoDS_Shape aErrShape = aCompound->impl(); + if (myErrorShapes.IsNull()) { + myErrorShapes = new AIS_Shape(aErrShape); + myErrorShapes->SetColor(Quantity_NOC_RED); + Handle(Prs3d_Drawer) aDrawer = myErrorShapes->Attributes(); + aDrawer->SetPointAspect(new Prs3d_PointAspect(Aspect_TOM_RING1, Quantity_NOC_RED, 2.)); + aDrawer->SetLineAspect(new Prs3d_LineAspect(Quantity_NOC_RED, Aspect_TOL_SOLID, 2.)); + aContext->Display(myErrorShapes, true); + aContext->Deactivate(myErrorShapes); + } + else { + myErrorShapes->Set(aErrShape); + aContext->Redisplay(myErrorShapes, true); + } + } + else { + if (!myErrorShapes.IsNull()) { + aContext->Remove(myErrorShapes, true); + myErrorShapes.Nullify(); + } + } + } } void PartSet_CustomPrs::initPresentation(