From f96597c41d8ae0949c8bb72d54e2d9c2e7f49914 Mon Sep 17 00:00:00 2001 From: vsv Date: Thu, 12 Dec 2019 18:48:49 +0300 Subject: [PATCH] Issue #3108: Take into account current parameters style for new dimensions. --- src/PartSet/PartSet_SketcherMgr.cpp | 5 ++- src/SketcherPrs/CMakeLists.txt | 4 +- src/SketcherPrs/SketcherPrs_Angle.cpp | 4 +- src/SketcherPrs/SketcherPrs_Angle.h | 6 +-- ...ner.cpp => SketcherPrs_DimensionStyle.cpp} | 42 +++++++------------ ...istener.h => SketcherPrs_DimensionStyle.h} | 15 ++----- .../SketcherPrs_LengthDimension.cpp | 4 +- src/SketcherPrs/SketcherPrs_LengthDimension.h | 6 +-- src/SketcherPrs/SketcherPrs_Radius.cpp | 4 +- src/SketcherPrs/SketcherPrs_Radius.h | 6 +-- src/SketcherPrs/SketcherPrs_Tools.cpp | 23 +++++----- src/SketcherPrs/SketcherPrs_Tools.h | 38 +++-------------- 12 files changed, 56 insertions(+), 101 deletions(-) rename src/SketcherPrs/{SketcherPrs_DimensionStyleListener.cpp => SketcherPrs_DimensionStyle.cpp} (68%) rename src/SketcherPrs/{SketcherPrs_DimensionStyleListener.h => SketcherPrs_DimensionStyle.h} (83%) diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index e82577145..a0e1b7efa 100644 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -2019,8 +2019,9 @@ void PartSet_SketcherMgr::updateBySketchParameters( if (aPrevState != theState) { /// call all sketch features redisplay, the expression state will be corrected in customize /// of distance presentation - SketcherPrs_Tools:: - sendExpressionShownEvent(myIsConstraintsShown[PartSet_Tools::Expressions]); + SketcherPrs_Tools::ParameterStyle aStyle = myIsConstraintsShown[PartSet_Tools::Expressions] ? + SketcherPrs_Tools::ParameterText : SketcherPrs_Tools::ParameterValue; + SketcherPrs_Tools::setParameterStyle(aStyle); Events_ID anEventId = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY); PartSet_Tools::sendSubFeaturesEvent(myCurrentSketch, anEventId); } diff --git a/src/SketcherPrs/CMakeLists.txt b/src/SketcherPrs/CMakeLists.txt index f84bb4322..51a7b9f8b 100644 --- a/src/SketcherPrs/CMakeLists.txt +++ b/src/SketcherPrs/CMakeLists.txt @@ -26,7 +26,7 @@ SET(PROJECT_HEADERS SketcherPrs.h SketcherPrs_Coincident.h SketcherPrs_Collinear.h - SketcherPrs_DimensionStyleListener.h + SketcherPrs_DimensionStyle.h SketcherPrs_Factory.h SketcherPrs_Parallel.h SketcherPrs_Tools.h @@ -49,7 +49,7 @@ SET(PROJECT_HEADERS SET(PROJECT_SOURCES SketcherPrs_Coincident.cpp SketcherPrs_Collinear.cpp - SketcherPrs_DimensionStyleListener.cpp + SketcherPrs_DimensionStyle.cpp SketcherPrs_Factory.cpp SketcherPrs_Parallel.cpp SketcherPrs_Tools.cpp diff --git a/src/SketcherPrs/SketcherPrs_Angle.cpp b/src/SketcherPrs/SketcherPrs_Angle.cpp index 9edc95a76..f09c4a933 100644 --- a/src/SketcherPrs/SketcherPrs_Angle.cpp +++ b/src/SketcherPrs/SketcherPrs_Angle.cpp @@ -18,7 +18,7 @@ // #include "SketcherPrs_Angle.h" -#include "SketcherPrs_DimensionStyleListener.h" +#include "SketcherPrs_DimensionStyle.h" #include "SketcherPrs_Tools.h" #include @@ -70,7 +70,7 @@ SketcherPrs_Angle::SketcherPrs_Angle(ModelAPI_Feature* theConstraint, SetDimensionAspect(myAspect); - myStyleListener = new SketcherPrs_DimensionStyleListener(); + myStyleListener = new SketcherPrs_DimensionStyle(); } SketcherPrs_Angle::~SketcherPrs_Angle() diff --git a/src/SketcherPrs/SketcherPrs_Angle.h b/src/SketcherPrs/SketcherPrs_Angle.h index 75d0c37d8..009a482a8 100644 --- a/src/SketcherPrs/SketcherPrs_Angle.h +++ b/src/SketcherPrs/SketcherPrs_Angle.h @@ -27,7 +27,7 @@ #include #include -#include +#include DEFINE_STANDARD_HANDLE(SketcherPrs_Angle, AIS_AngleDimension) @@ -99,7 +99,7 @@ private: Handle(Prs3d_DimensionAspect) myAspect; /// Listener to update dimension visualization style - SketcherPrs_DimensionStyleListener* myStyleListener; + SketcherPrs_DimensionStyle* myStyleListener; /// container of values obtained from the constraint, which are necessary to fill the presentation gp_Pnt myFirstPoint; ///< the dimension first point for measured geometry @@ -107,7 +107,7 @@ private: gp_Pnt myCenterPoint; ///< the dimension center point for measured geometry gp_Pnt myFlyOutPoint; ///< the dimension fly out point for measured geometry - SketcherPrs_DimensionStyleListener::DimensionValue myValue; /// the structure filled by constraint + SketcherPrs_DimensionStyle::DimensionValue myValue; /// the structure filled by constraint }; diff --git a/src/SketcherPrs/SketcherPrs_DimensionStyleListener.cpp b/src/SketcherPrs/SketcherPrs_DimensionStyle.cpp similarity index 68% rename from src/SketcherPrs/SketcherPrs_DimensionStyleListener.cpp rename to src/SketcherPrs/SketcherPrs_DimensionStyle.cpp index e00f81acb..fb82eb40b 100644 --- a/src/SketcherPrs/SketcherPrs_DimensionStyleListener.cpp +++ b/src/SketcherPrs/SketcherPrs_DimensionStyle.cpp @@ -17,7 +17,7 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -#include "SketcherPrs_DimensionStyleListener.h" +#include "SketcherPrs_DimensionStyle.h" #include #include "SketcherPrs_Tools.h" @@ -35,7 +35,8 @@ static const Standard_ExtCharacter MyEmptySymbol(' '); static const Standard_ExtCharacter MySigmaSymbol('=');//0x03A3); // using equal instead of sigma -SketcherPrs_DimensionStyleListener::DimensionValue::DimensionValue(double theDoubleValue, + +SketcherPrs_DimensionStyle::DimensionValue::DimensionValue(double theDoubleValue, bool theHasParameters, const std::string& theTextValue) : myDoubleValue(theDoubleValue), myHasParameters(theHasParameters), @@ -43,7 +44,7 @@ SketcherPrs_DimensionStyleListener::DimensionValue::DimensionValue(double theDou { } -void SketcherPrs_DimensionStyleListener::DimensionValue::init( +void SketcherPrs_DimensionStyle::DimensionValue::init( const AttributeDoublePtr& theAttributeValue) { myDoubleValue = theAttributeValue->value(); @@ -51,33 +52,16 @@ void SketcherPrs_DimensionStyleListener::DimensionValue::init( myTextValue = theAttributeValue->text(); } -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() +SketcherPrs_DimensionStyle::SketcherPrs_DimensionStyle() { - Events_Loop* aLoop = Events_Loop::loop(); - aLoop->removeListener(this); } -void SketcherPrs_DimensionStyleListener::processEvent( - const std::shared_ptr& theMessage) +SketcherPrs_DimensionStyle::~SketcherPrs_DimensionStyle() { - 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 SketcherPrs_DimensionStyleListener::DimensionValue& theDimensionValue) +void SketcherPrs_DimensionStyle::updateDimensions(AIS_Dimension* theDimension, + const SketcherPrs_DimensionStyle::DimensionValue& theDimensionValue) { if (!theDimension) return; @@ -85,7 +69,7 @@ void SketcherPrs_DimensionStyleListener::updateDimensions(AIS_Dimension* theDime theDimensionValue.myTextValue, theDimensionValue.myDoubleValue); } -void SketcherPrs_DimensionStyleListener::updateDimensions(AIS_Dimension* theDimension, +void SketcherPrs_DimensionStyle::updateDimensions(AIS_Dimension* theDimension, const bool theHasParameters, const std::string& theTextValue, const double theDoubleValue) @@ -93,13 +77,16 @@ void SketcherPrs_DimensionStyleListener::updateDimensions(AIS_Dimension* theDime if (!theDimension) return; - /// do not show special symbols of dimension: previous implementation did not allow to unite them + /// do not show special symbols of dimension: + /// previous implementation did not allow to unite them theDimension->SetSpecialSymbol(MyEmptySymbol); theDimension->SetDisplaySpecialSymbol(AIS_DSS_No); TCollection_ExtendedString aCustomValue; if (theHasParameters) { - bool isParameterTextStyle = myStyle == SketcherPrs_ParameterStyleMessage::ParameterText; + //bool isParameterTextStyle = myStyle == SketcherPrs_ParameterStyleMessage::ParameterText; + bool isParameterTextStyle = + SketcherPrs_Tools::parameterStyle() == SketcherPrs_Tools::ParameterText; if (isParameterTextStyle) aCustomValue = theTextValue.c_str(); @@ -128,4 +115,3 @@ void SketcherPrs_DimensionStyleListener::updateDimensions(AIS_Dimension* theDime theDimension->SetCustomValue(aCustomValue); #endif } - diff --git a/src/SketcherPrs/SketcherPrs_DimensionStyleListener.h b/src/SketcherPrs/SketcherPrs_DimensionStyle.h similarity index 83% rename from src/SketcherPrs/SketcherPrs_DimensionStyleListener.h rename to src/SketcherPrs/SketcherPrs_DimensionStyle.h index 5e6239943..47be050d3 100644 --- a/src/SketcherPrs/SketcherPrs_DimensionStyleListener.h +++ b/src/SketcherPrs/SketcherPrs_DimensionStyle.h @@ -20,7 +20,7 @@ #ifndef SketcherPrs_DimensionStyleListener_H #define SketcherPrs_DimensionStyleListener_H -#include +//#include #include @@ -36,7 +36,7 @@ * A class for representation of linear dimension constraint. * It supports SketchPlugin_ConstraintLength and SketchPlugin_ConstraintDistance features. */ -class SketcherPrs_DimensionStyleListener : public Events_Listener +class SketcherPrs_DimensionStyle { public: class DimensionValue { @@ -54,14 +54,10 @@ public: public: /// Constructor - Standard_EXPORT SketcherPrs_DimensionStyleListener(); + Standard_EXPORT SketcherPrs_DimensionStyle(); /// 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); + Standard_EXPORT ~SketcherPrs_DimensionStyle(); /// Visualizes the dimension text or dimension value depending on the has parameters state /// \param theDimension a modified dimension @@ -79,9 +75,6 @@ private: const bool theHasParameters, const std::string& theTextValue, const double theDoubleValue); -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 b15f0d05f..de9d7e752 100644 --- a/src/SketcherPrs/SketcherPrs_LengthDimension.cpp +++ b/src/SketcherPrs/SketcherPrs_LengthDimension.cpp @@ -19,7 +19,7 @@ #include "SketcherPrs_LengthDimension.h" #include "SketcherPrs_Tools.h" -#include "SketcherPrs_DimensionStyleListener.h" +#include "SketcherPrs_DimensionStyle.h" #include #include @@ -120,7 +120,7 @@ SketcherPrs_LengthDimension::SketcherPrs_LengthDimension(ModelAPI_Feature* theCo myValue(0., false, "") { SetDimensionAspect(createDimensionAspect()); - myStyleListener = new SketcherPrs_DimensionStyleListener(); + myStyleListener = new SketcherPrs_DimensionStyle(); setDirection(theConstraint, plane()); } diff --git a/src/SketcherPrs/SketcherPrs_LengthDimension.h b/src/SketcherPrs/SketcherPrs_LengthDimension.h index 43a27c717..b737488fa 100644 --- a/src/SketcherPrs/SketcherPrs_LengthDimension.h +++ b/src/SketcherPrs/SketcherPrs_LengthDimension.h @@ -30,7 +30,7 @@ #include #include -#include +#include DEFINE_STANDARD_HANDLE(SketcherPrs_LengthDimension, AIS_LengthDimension) @@ -96,7 +96,7 @@ private: //Handle(Prs3d_DimensionAspect) myAspect; /// Listener to update dimension visualization style - SketcherPrs_DimensionStyleListener* myStyleListener; + SketcherPrs_DimensionStyle* myStyleListener; /// container of values obtained from the constraint, which are necessary /// to fill the presentation @@ -106,7 +106,7 @@ private: double myDistance; ///< the flyout distance /// the structure filled by constraint - SketcherPrs_DimensionStyleListener::DimensionValue myValue; + SketcherPrs_DimensionStyle::DimensionValue myValue; }; #endif \ No newline at end of file diff --git a/src/SketcherPrs/SketcherPrs_Radius.cpp b/src/SketcherPrs/SketcherPrs_Radius.cpp index bd10874fc..5b94a63de 100644 --- a/src/SketcherPrs/SketcherPrs_Radius.cpp +++ b/src/SketcherPrs/SketcherPrs_Radius.cpp @@ -19,7 +19,7 @@ #include "SketcherPrs_Radius.h" #include "SketcherPrs_Tools.h" -#include "SketcherPrs_DimensionStyleListener.h" +#include "SketcherPrs_DimensionStyle.h" #include #include @@ -59,7 +59,7 @@ SketcherPrs_Radius::SketcherPrs_Radius(ModelAPI_Feature* theConstraint, myValue(1, false, "") { SetDimensionAspect(createDimensionAspect()); - myStyleListener = new SketcherPrs_DimensionStyleListener(); + myStyleListener = new SketcherPrs_DimensionStyle(); } SketcherPrs_Radius::~SketcherPrs_Radius() diff --git a/src/SketcherPrs/SketcherPrs_Radius.h b/src/SketcherPrs/SketcherPrs_Radius.h index a6fbe75e9..e675e24e0 100644 --- a/src/SketcherPrs/SketcherPrs_Radius.h +++ b/src/SketcherPrs/SketcherPrs_Radius.h @@ -27,7 +27,7 @@ #include #include -#include +#include DEFINE_STANDARD_HANDLE(SketcherPrs_Radius, AIS_RadiusDimension) @@ -91,13 +91,13 @@ private: SketchPlugin_Sketch* mySketcher; /// Listener to update dimension visualization style - SketcherPrs_DimensionStyleListener* myStyleListener; + SketcherPrs_DimensionStyle* myStyleListener; /// container of values obtained from the constraint, which are necessary to fill the presentation gp_Circ myCircle; ///< the radius circle gp_Pnt myAnchorPoint; ///< an ancor for the radius value visualization - SketcherPrs_DimensionStyleListener::DimensionValue myValue; /// the structure filled by constraint + SketcherPrs_DimensionStyle::DimensionValue myValue; /// the structure filled by constraint }; #endif \ No newline at end of file diff --git a/src/SketcherPrs/SketcherPrs_Tools.cpp b/src/SketcherPrs/SketcherPrs_Tools.cpp index 8b32e6944..2de9b6c82 100644 --- a/src/SketcherPrs/SketcherPrs_Tools.cpp +++ b/src/SketcherPrs/SketcherPrs_Tools.cpp @@ -51,6 +51,18 @@ namespace SketcherPrs_Tools { +static ParameterStyle MyStyle = ParameterValue; + +void setParameterStyle(ParameterStyle theStyle) +{ + MyStyle = theStyle; +} + +ParameterStyle parameterStyle() +{ + return MyStyle; +} + AttributePtr getAttribute(ModelAPI_Feature* theFeature, const std::string& theAttrName) { AttributePtr anAttribute; @@ -369,17 +381,6 @@ std::shared_ptr getAnchorPoint(const ModelAPI_Feature* theConstrain return thePlane->to3D(aFlyoutPnt->x(), aFlyoutPnt->y()); } -void sendExpressionShownEvent(const bool& theState) -{ - static Events_ID anId = SketcherPrs_ParameterStyleMessage::eventId(); - std::shared_ptr aMessage = std::shared_ptr - (new SketcherPrs_ParameterStyleMessage(anId, 0)); - aMessage->setStyle(theState ? SketcherPrs_ParameterStyleMessage::ParameterText - : SketcherPrs_ParameterStyleMessage::ParameterValue); - Events_Loop::loop()->send(aMessage); - Events_Loop::loop()->flush(anId); -} - void sendEmptyPresentationError(ModelAPI_Feature* theFeature, const std::string theError) { Events_InfoMessage("SketcherPrs_Tools", diff --git a/src/SketcherPrs/SketcherPrs_Tools.h b/src/SketcherPrs/SketcherPrs_Tools.h index 5a719646c..0b075f581 100644 --- a/src/SketcherPrs/SketcherPrs_Tools.h +++ b/src/SketcherPrs/SketcherPrs_Tools.h @@ -37,41 +37,20 @@ class GeomDataAPI_Point2D; class AIS_Dimension; -//#define MyTextHeight 20 +namespace SketcherPrs_Tools { -/// Message that style of visualization of parameter is changed. -/// It will be shown as expression or value -class SketcherPrs_ParameterStyleMessage : public Events_Message -{ -public: /// \enum ParameterStyle lists styles of parameter enum ParameterStyle { ParameterValue, ///< using symbol with the parameter value ParameterText ///< using parameter text }; -public: - /// Creates an empty message - SKETCHERPRS_EXPORT SketcherPrs_ParameterStyleMessage(const Events_ID theID, - const void* theSender = 0) - : Events_Message(theID, theSender) {} - /// The virtual destructor - SKETCHERPRS_EXPORT virtual ~SketcherPrs_ParameterStyleMessage() {} - /// Static. Returns EventID of the message. - SKETCHERPRS_EXPORT static Events_ID eventId() - { - static const char * MY_EVENT_PARAMETER_STYLE_ID("ParameterStyle"); - return Events_Loop::eventByName(MY_EVENT_PARAMETER_STYLE_ID); - } - /// Returns a document stored in the message - SKETCHERPRS_EXPORT ParameterStyle style() const { return myStyle; } - /// Sets a document to the message - SKETCHERPRS_EXPORT void setStyle(ParameterStyle theStyle) { myStyle = theStyle; } -private: - ParameterStyle myStyle; /// style of the parameter visualization -}; + /// Set dimensions parameters style + /// \param theStyle new style + SKETCHERPRS_EXPORT void setParameterStyle(ParameterStyle theStyle); -namespace SketcherPrs_Tools { + /// Return dimensions parameters style + SKETCHERPRS_EXPORT ParameterStyle parameterStyle(); /// Enumeration with modes for activation of selection custom presentations enum SelectionModes { @@ -196,11 +175,6 @@ namespace SketcherPrs_Tools { const ModelAPI_Feature* theConstraint, const std::shared_ptr& thePlane); - /// Sends event about expression visualization type is changed for dimension presentations - /// Sends event to redisplay all sub-features of composite feature - /// \param theState a new state - SKETCHERPRS_EXPORT void sendExpressionShownEvent(const bool& theState); - /// Throws an exception(in debug mode) and sends a signal about necessity to hide the object /// \param theFeature a feature where AIS presentation is empty /// \param theError a debug error information -- 2.39.2