From: nds Date: Thu, 31 Mar 2016 12:32:05 +0000 (+0300) Subject: Issue #805 In the sketch presentation, show both the parameter and its value: dimensi... X-Git-Tag: V_2.3.0~354 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=2889060fd2abac5e77f0a680f815b3fa0c2a41e5;p=modules%2Fshaper.git Issue #805 In the sketch presentation, show both the parameter and its value: dimension style listener is moved out of AIS presentation in order to be reused in radius/angle/dimension constrains. --- diff --git a/src/SketcherPrs/CMakeLists.txt b/src/SketcherPrs/CMakeLists.txt index acdb1d7ee..e060ad325 100644 --- a/src/SketcherPrs/CMakeLists.txt +++ b/src/SketcherPrs/CMakeLists.txt @@ -9,6 +9,7 @@ SET(PROJECT_HEADERS SketcherPrs.h SketcherPrs_Coincident.h SketcherPrs_Collinear.h + SketcherPrs_DimensionStyleListener.h SketcherPrs_Factory.h SketcherPrs_Parallel.h SketcherPrs_Tools.h @@ -32,6 +33,7 @@ SET(PROJECT_HEADERS SET(PROJECT_SOURCES SketcherPrs_Coincident.cpp SketcherPrs_Collinear.cpp + SketcherPrs_DimensionStyleListener.cpp SketcherPrs_Factory.cpp SketcherPrs_Parallel.cpp SketcherPrs_Tools.cpp diff --git a/src/SketcherPrs/SketcherPrs_DimensionStyleListener.cpp b/src/SketcherPrs/SketcherPrs_DimensionStyleListener.cpp new file mode 100755 index 000000000..ffb2a8d4c --- /dev/null +++ b/src/SketcherPrs/SketcherPrs_DimensionStyleListener.cpp @@ -0,0 +1,53 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: SketcherPrs_DimensionStyleListener.cpp +// Created: 31 March 2016 +// Author: Natalia ERMOLAEVA + +#include "SketcherPrs_DimensionStyleListener.h" +#include "SketcherPrs_Tools.h" + +#include +#include + +SketcherPrs_DimensionStyleListener::SketcherPrs_DimensionStyleListener() +{ + Events_Loop* aLoop = Events_Loop::loop(); + const Events_ID kDocCreatedEvent = + SketcherPrs_ParameterStyleMessage::eventId(); + aLoop->registerListener(this, kDocCreatedEvent, NULL, false); +} + +SketcherPrs_DimensionStyleListener::~SketcherPrs_DimensionStyleListener() +{ + Events_Loop* aLoop = Events_Loop::loop(); + aLoop->removeListener(this); +} + +void SketcherPrs_DimensionStyleListener::processEvent(const std::shared_ptr& theMessage) +{ + const Events_ID kParameterStyleEvent = SketcherPrs_ParameterStyleMessage::eventId(); + if (theMessage->eventID() == kParameterStyleEvent) { + std::shared_ptr aMessage = std::dynamic_pointer_cast< + SketcherPrs_ParameterStyleMessage>(theMessage); + myStyle = aMessage->style(); + } +} + +void SketcherPrs_DimensionStyleListener::updateDimensions(AIS_Dimension* theDimension, + const AttributeDoublePtr& theAttributeValue) +{ + if (!theDimension || !theAttributeValue.get()) + return; + + bool aHasParameters = theAttributeValue->usedParameters().size() > 0; + if (aHasParameters) { + bool isParameterValueStyle = myStyle == SketcherPrs_ParameterStyleMessage::ParameterValue; + SketcherPrs_Tools::setDisplaySpecialSymbol(theDimension, isParameterValueStyle); + SketcherPrs_Tools::setDisplayParameter(theDimension, theAttributeValue->text(), !isParameterValueStyle); + } + else { + SketcherPrs_Tools::setDisplaySpecialSymbol(theDimension, false); + SketcherPrs_Tools::setDisplayParameter(theDimension, theAttributeValue->text(), false); + } +} diff --git a/src/SketcherPrs/SketcherPrs_DimensionStyleListener.h b/src/SketcherPrs/SketcherPrs_DimensionStyleListener.h new file mode 100755 index 000000000..03e92957c --- /dev/null +++ b/src/SketcherPrs/SketcherPrs_DimensionStyleListener.h @@ -0,0 +1,47 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: SketcherPrs_DimensionStyleListener.h +// Created: 31 March 2016 +// Author: Natalia ERMOLAEVA + +#ifndef SketcherPrs_DimensionStyleListener_H +#define SketcherPrs_DimensionStyleListener_H + +#include + +#include + +#include "SketcherPrs_Tools.h" + +#include + +/** +* \ingroup GUI +* A class for representation of linear dimension constraint. +* It supports SketchPlugin_ConstraintLength and SketchPlugin_ConstraintDistance features. +*/ +class SketcherPrs_DimensionStyleListener : public Events_Listener +{ +public: + /// Constructor + /// \param theConstraint a constraint feature + /// \param thePlane a coordinate plane of current sketch + Standard_EXPORT SketcherPrs_DimensionStyleListener(); + + /// Destructor + Standard_EXPORT ~SketcherPrs_DimensionStyleListener(); + + /// Process the ModelAPI_DocumentCreatedMessage to fulfill a document + /// from the message with origin and planes + virtual void processEvent(const std::shared_ptr& theMessage); + + /// Redefinition of virtual function + Standard_EXPORT void updateDimensions(AIS_Dimension* theDimension, + const AttributeDoublePtr& theAttributeValue); + +private: + /// Style how the parameter of dimension should be visualized + SketcherPrs_ParameterStyleMessage::ParameterStyle myStyle; +}; + +#endif \ No newline at end of file diff --git a/src/SketcherPrs/SketcherPrs_LengthDimension.cpp b/src/SketcherPrs/SketcherPrs_LengthDimension.cpp index 0ec0382e4..a61a6cb40 100644 --- a/src/SketcherPrs/SketcherPrs_LengthDimension.cpp +++ b/src/SketcherPrs/SketcherPrs_LengthDimension.cpp @@ -15,6 +15,7 @@ #include #include +#include #include #include @@ -55,26 +56,12 @@ SketcherPrs_LengthDimension::SketcherPrs_LengthDimension(ModelAPI_Feature* theCo SetSelToleranceForText2d(SketcherPrs_Tools::getTextHeight()); SetDimensionAspect(myAspect); - Events_Loop* aLoop = Events_Loop::loop(); - const Events_ID kDocCreatedEvent = - SketcherPrs_ParameterStyleMessage::eventId(); - aLoop->registerListener(this, kDocCreatedEvent, NULL, false); + myStyleListener = new SketcherPrs_DimensionStyleListener(); } SketcherPrs_LengthDimension::~SketcherPrs_LengthDimension() { - Events_Loop* aLoop = Events_Loop::loop(); - aLoop->removeListener(this); -} - -void SketcherPrs_LengthDimension::processEvent(const std::shared_ptr& theMessage) -{ - const Events_ID kParameterStyleEvent = SketcherPrs_ParameterStyleMessage::eventId(); - if (theMessage->eventID() == kParameterStyleEvent) { - std::shared_ptr aMessage = std::dynamic_pointer_cast< - SketcherPrs_ParameterStyleMessage>(theMessage); - myStyle = aMessage->style(); - } + delete myStyleListener; } bool SketcherPrs_LengthDimension::IsReadyToDisplay(ModelAPI_Feature* theConstraint, @@ -126,16 +113,9 @@ void SketcherPrs_LengthDimension::Compute(const Handle(PrsMgr_PresentationManage myAspect->TextAspect()->SetVerticalJustification(Graphic3d_VTA_CENTER); AttributeDoublePtr aValue = myConstraint->data()->real(SketchPlugin_Constraint::VALUE()); - bool aHasParameters = aValue->usedParameters().size() > 0; - if (aHasParameters) { - bool isParameterValueStyle = myStyle == SketcherPrs_ParameterStyleMessage::ParameterValue; - SketcherPrs_Tools::setDisplaySpecialSymbol(this, isParameterValueStyle); - SketcherPrs_Tools::setDisplayParameter(this, aValue->text(), !isParameterValueStyle); - } - else { - SketcherPrs_Tools::setDisplaySpecialSymbol(this, false); - SketcherPrs_Tools::setDisplayParameter(this, aValue->text(), false); - } + + myStyleListener->updateDimensions(this, aValue); + AIS_LengthDimension::Compute(thePresentationManager, thePresentation, theMode); } diff --git a/src/SketcherPrs/SketcherPrs_LengthDimension.h b/src/SketcherPrs/SketcherPrs_LengthDimension.h index c0716bc58..59d302ae5 100644 --- a/src/SketcherPrs/SketcherPrs_LengthDimension.h +++ b/src/SketcherPrs/SketcherPrs_LengthDimension.h @@ -15,8 +15,7 @@ #include -#include - +class SketcherPrs_DimensionStyleListener; DEFINE_STANDARD_HANDLE(SketcherPrs_LengthDimension, AIS_LengthDimension) @@ -25,7 +24,7 @@ DEFINE_STANDARD_HANDLE(SketcherPrs_LengthDimension, AIS_LengthDimension) * A class for representation of linear dimension constraint. * It supports SketchPlugin_ConstraintLength and SketchPlugin_ConstraintDistance features. */ -class SketcherPrs_LengthDimension : public AIS_LengthDimension, public Events_Listener +class SketcherPrs_LengthDimension : public AIS_LengthDimension { public: /// Constructor @@ -39,10 +38,6 @@ public: DEFINE_STANDARD_RTTI(SketcherPrs_LengthDimension) - /// Process the ModelAPI_DocumentCreatedMessage to fulfill a document - /// from the message with origin and planes - virtual void processEvent(const std::shared_ptr& theMessage); - /// Returns true if the constraint feature arguments are correcly filled to build AIS presentation /// \param theConstraint a constraint feature /// \param thePlane a coordinate plane of current sketch @@ -71,8 +66,8 @@ private: Handle(Prs3d_DimensionAspect) myAspect; - /// Style how the parameter of dimension should be visualized - SketcherPrs_ParameterStyleMessage::ParameterStyle myStyle; + /// Listener to update dimension visualization style + SketcherPrs_DimensionStyleListener* myStyleListener; }; #endif \ No newline at end of file