From 1acf349f743d8a8f5d82acc05b82dff320eeb101 Mon Sep 17 00:00:00 2001 From: vsv Date: Tue, 23 Jun 2020 17:09:12 +0300 Subject: [PATCH] Issue #3222: 1D fillet Send the message about failed vertices when creation method is changed. --- .../FeaturesPlugin_Fillet1D.cpp | 22 ++++++++-- src/FeaturesPlugin/FeaturesPlugin_Fillet1D.h | 4 ++ src/ModelAPI/ModelAPI_Events.cpp | 14 +++---- src/ModelAPI/ModelAPI_Events.h | 18 ++++---- src/PartSet/PartSet_CustomPrs.cpp | 42 +++++++++++++++++++ src/PartSet/PartSet_CustomPrs.h | 5 +++ src/PartSet/PartSet_OperationPrs.cpp | 30 ++++++------- 7 files changed, 98 insertions(+), 37 deletions(-) diff --git a/src/FeaturesPlugin/FeaturesPlugin_Fillet1D.cpp b/src/FeaturesPlugin/FeaturesPlugin_Fillet1D.cpp index d62fdee30..c19cfa34d 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Fillet1D.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Fillet1D.cpp @@ -34,6 +34,14 @@ #include #include +void sendMessageWithFailedShapes(const ListOfShape& theVertices) +{ + std::shared_ptr aMessage( + new ModelAPI_ShapesFailedMessage(Events_Loop::eventByName(EVENT_OPERATION_SHAPES_FAILED))); + aMessage->setShapes(theVertices); + Events_Loop::loop()->send(aMessage); +} + FeaturesPlugin_Fillet1D::FeaturesPlugin_Fillet1D() { } @@ -60,6 +68,15 @@ void FeaturesPlugin_Fillet1D::execute() removeResults(aResultIndex); } +void FeaturesPlugin_Fillet1D::attributeChanged(const std::string& theID) +{ + if (theID == CREATION_METHOD()) { + // creation method is changed, drop failed vertices and send the message + removeResults(0); + sendMessageWithFailedShapes(ListOfShape()); + } +} + bool FeaturesPlugin_Fillet1D::baseShapes(ListOfShape& theWires, MapShapeSubs& theWireVertices) { std::set aProcessedWires; @@ -164,10 +181,7 @@ bool FeaturesPlugin_Fillet1D::performFillet(const GeomShapePtr& theWire, if (isSendMessage) { // send message to highlight the failed vertices - std::shared_ptr aMessage( - new ModelAPI_Fillet1DFailedMessage(Events_Loop::eventByName(EVENT_1DFILLET_FAILED))); - aMessage->setVertices(myFailedVertices); - Events_Loop::loop()->send(aMessage); + sendMessageWithFailedShapes(myFailedVertices); } static const std::string THE_PREFIX = "Fillet1D"; diff --git a/src/FeaturesPlugin/FeaturesPlugin_Fillet1D.h b/src/FeaturesPlugin/FeaturesPlugin_Fillet1D.h index 7cf37cc23..074d03ce4 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Fillet1D.h +++ b/src/FeaturesPlugin/FeaturesPlugin_Fillet1D.h @@ -91,6 +91,10 @@ public: /// Request for initialization of data model of the feature: adding all attributes. FEATURESPLUGIN_EXPORT virtual void initAttributes(); + /// Called on change of any argument-attribute of this object + /// \param theID identifier of changed attribute + FEATURESPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID); + /// Performs the fillet algorithm and stores it in the data structure. FEATURESPLUGIN_EXPORT virtual void execute(); diff --git a/src/ModelAPI/ModelAPI_Events.cpp b/src/ModelAPI/ModelAPI_Events.cpp index 19e664f81..bf05de24f 100644 --- a/src/ModelAPI/ModelAPI_Events.cpp +++ b/src/ModelAPI/ModelAPI_Events.cpp @@ -387,21 +387,21 @@ void ModelAPI_ObjectMovedMessage::setCurrentPosition( } -// ===== ModelAPI_Fillet1DFailedMessage ===== -ModelAPI_Fillet1DFailedMessage::ModelAPI_Fillet1DFailedMessage(const Events_ID theID, +// ===== ModelAPI_ShapesFailedMessage ===== +ModelAPI_ShapesFailedMessage::ModelAPI_ShapesFailedMessage(const Events_ID theID, const void* theSender) : Events_Message(theID, theSender) {} -ModelAPI_Fillet1DFailedMessage::~ModelAPI_Fillet1DFailedMessage() +ModelAPI_ShapesFailedMessage::~ModelAPI_ShapesFailedMessage() {} -void ModelAPI_Fillet1DFailedMessage::setVertices(const ListOfShape& theVertices) +void ModelAPI_ShapesFailedMessage::setShapes(const ListOfShape& theShapes) { - myVertices = theVertices; + myShapes = theShapes; } -const ListOfShape& ModelAPI_Fillet1DFailedMessage::vertices() const +const ListOfShape& ModelAPI_ShapesFailedMessage::shapes() const { - return myVertices; + return myShapes; } diff --git a/src/ModelAPI/ModelAPI_Events.h b/src/ModelAPI/ModelAPI_Events.h index 2a63ab671..68af75b1b 100644 --- a/src/ModelAPI/ModelAPI_Events.h +++ b/src/ModelAPI/ModelAPI_Events.h @@ -120,8 +120,8 @@ MAYBE_UNUSED static const char * EVENT_DOF_OBJECTS = "DoFObjects"; MAYBE_UNUSED static const char * EVENT_VISUAL_ATTRIBUTES = "UpdateVisualAttributes"; -/// Event ID that 1D-fillet failed (comes with ModelAPI_Fillet1DFailedMessage) -static const char * EVENT_1DFILLET_FAILED = "1DFilletFailed"; +/// Event ID that 1D-fillet failed (comes with ModelAPI_ShapesFailedMessage) +static const char * EVENT_OPERATION_SHAPES_FAILED = "OperationShapesFailed"; /// Message that feature was changed (used for Object Browser update): moved, updated and deleted class MODELAPI_EXPORT ModelAPI_ObjectUpdatedMessage : public Events_MessageGroup @@ -545,26 +545,26 @@ public: }; /// Message that sends the failed vertices of 1D-fillet to highlight them in 3D viewer -class ModelAPI_Fillet1DFailedMessage : public Events_Message +class ModelAPI_ShapesFailedMessage : public Events_Message { public: /// Creates an message - MODELAPI_EXPORT ModelAPI_Fillet1DFailedMessage(const Events_ID theID, const void* theSender = 0); + MODELAPI_EXPORT ModelAPI_ShapesFailedMessage(const Events_ID theID, const void* theSender = 0); /// Default destructor - MODELAPI_EXPORT virtual ~ModelAPI_Fillet1DFailedMessage(); + MODELAPI_EXPORT virtual ~ModelAPI_ShapesFailedMessage(); /// Static. Returns EventID of the message. MODELAPI_EXPORT static Events_ID eventId() { - return Events_Loop::eventByName(EVENT_1DFILLET_FAILED); + return Events_Loop::eventByName(EVENT_OPERATION_SHAPES_FAILED); } /// Sets list of failed vertices - MODELAPI_EXPORT void setVertices(const std::list< std::shared_ptr >& theVertices); + MODELAPI_EXPORT void setShapes(const std::list< std::shared_ptr >& theVertices); /// Returns list of failed vertices - MODELAPI_EXPORT const std::list< std::shared_ptr >& vertices() const; + MODELAPI_EXPORT const std::list< std::shared_ptr >& shapes() const; private: - std::list< std::shared_ptr > myVertices; + std::list< std::shared_ptr > myShapes; }; #endif diff --git a/src/PartSet/PartSet_CustomPrs.cpp b/src/PartSet/PartSet_CustomPrs.cpp index c61227cb0..7b98ee619 100644 --- a/src/PartSet/PartSet_CustomPrs.cpp +++ b/src/PartSet/PartSet_CustomPrs.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -50,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); @@ -99,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; } @@ -244,12 +248,50 @@ 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); + } } 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); + } + } + } } void PartSet_CustomPrs::initPresentation( diff --git a/src/PartSet/PartSet_CustomPrs.h b/src/PartSet/PartSet_CustomPrs.h index 11f635666..117af4a14 100644 --- a/src/PartSet/PartSet_CustomPrs.h +++ b/src/PartSet/PartSet_CustomPrs.h @@ -151,6 +151,9 @@ private: /// \return theShapeColor a color Quantity_Color getShapeColor(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag); + /// Removes error shapes presentation + void clearErrorShape(); + private: ModuleBase_IWorkshop* myWorkshop; /// current workshop FeaturePtr myFeature; /// Reference to a feature object @@ -161,6 +164,8 @@ private: QMap myIsActive; int myDisabledMode; + + Handle(AIS_Shape) myErrorShapes; }; #endif diff --git a/src/PartSet/PartSet_OperationPrs.cpp b/src/PartSet/PartSet_OperationPrs.cpp index 07faae3c4..78b6430bc 100644 --- a/src/PartSet/PartSet_OperationPrs.cpp +++ b/src/PartSet/PartSet_OperationPrs.cpp @@ -242,24 +242,20 @@ void PartSet_OperationPrs::appendShapeIfVisible(ModuleBase_IWorkshop* theWorksho GeomShapePtr theGeomShape, QMap >& theObjectShapes) { - //XGUI_Displayer* aDisplayer = XGUI_Tools::workshop(theWorkshop)->displayer(); - //// VSV: Do not use isVisible checking because it can be used when state "Show Only" is ON - //if (XGUI_Displayer::isVisible(aDisplayer, theObject)) { - if (theGeomShape.get()) { - if (theObjectShapes.contains(theObject)) - theObjectShapes[theObject].append(theGeomShape); - else { - QList aShapes; - aShapes.append(theGeomShape); - theObjectShapes[theObject] = aShapes; - } - } else { - #ifdef DEBUG_EMPTY_SHAPE - qDebug(QString("Empty shape in result, result: %1") - .arg(ModuleBase_Tools::objectInfo(theObject)).toStdString().c_str()); - #endif + if (theGeomShape.get()) { + if (theObjectShapes.contains(theObject)) + theObjectShapes[theObject].append(theGeomShape); + else { + QList aShapes; + aShapes.append(theGeomShape); + theObjectShapes[theObject] = aShapes; } - //} + } else { +#ifdef DEBUG_EMPTY_SHAPE + qDebug(QString("Empty shape in result, result: %1") + .arg(ModuleBase_Tools::objectInfo(theObject)).toStdString().c_str()); +#endif + } } void PartSet_OperationPrs::getFeatureShapes(const FeaturePtr& theFeature, -- 2.39.2