1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: SketcherPrs_DimensionStyleListener.cpp
4 // Created: 31 March 2016
5 // Author: Natalia ERMOLAEVA
7 #include "SketcherPrs_DimensionStyleListener.h"
8 #include "SketcherPrs_Tools.h"
10 #include <Events_Loop.h>
12 #include <AIS_Dimension.hxx>
13 #include <TCollection_ExtendedString.hxx>
15 #define COMPILATION_CORRECTION
17 // it is not possible to use 0x2211 as summ symbol because it is not supported by
18 // debian Linux platform
19 static const Standard_ExtCharacter MyEmptySymbol(' ');
20 static const Standard_ExtCharacter MySigmaSymbol('=');//0x03A3); // using equal instead of sigma
22 SketcherPrs_DimensionStyleListener::DimensionValue::DimensionValue(double theDoubleValue,
23 bool theHasParameters, const std::string& theTextValue)
24 : myDoubleValue(theDoubleValue),
25 myHasParameters(theHasParameters),
26 myTextValue(theTextValue)
30 void SketcherPrs_DimensionStyleListener::DimensionValue::init(
31 const AttributeDoublePtr& theAttributeValue)
33 myDoubleValue = theAttributeValue->value();
34 myHasParameters = theAttributeValue->usedParameters().size() > 0;
35 myTextValue = theAttributeValue->text();
38 SketcherPrs_DimensionStyleListener::SketcherPrs_DimensionStyleListener()
40 Events_Loop* aLoop = Events_Loop::loop();
41 const Events_ID kDocCreatedEvent =
42 SketcherPrs_ParameterStyleMessage::eventId();
43 aLoop->registerListener(this, kDocCreatedEvent, NULL, false);
46 SketcherPrs_DimensionStyleListener::~SketcherPrs_DimensionStyleListener()
48 Events_Loop* aLoop = Events_Loop::loop();
49 aLoop->removeListener(this);
52 void SketcherPrs_DimensionStyleListener::processEvent(const std::shared_ptr<Events_Message>& theMessage)
54 const Events_ID kParameterStyleEvent = SketcherPrs_ParameterStyleMessage::eventId();
55 if (theMessage->eventID() == kParameterStyleEvent) {
56 std::shared_ptr<SketcherPrs_ParameterStyleMessage> aMessage = std::dynamic_pointer_cast<
57 SketcherPrs_ParameterStyleMessage>(theMessage);
58 myStyle = aMessage->style();
62 void SketcherPrs_DimensionStyleListener::updateDimensions(AIS_Dimension* theDimension,
63 const SketcherPrs_DimensionStyleListener::DimensionValue& theDimensionValue)
67 updateDimensions(theDimension, theDimensionValue.myHasParameters,
68 theDimensionValue.myTextValue, theDimensionValue.myDoubleValue);
71 void SketcherPrs_DimensionStyleListener::updateDimensions(AIS_Dimension* theDimension,
72 const bool theHasParameters,
73 const std::string& theTextValue,
74 const double theDoubleValue)
79 /// do not show special symbols of dimension: previous implementation did not allow to unite them
80 theDimension->SetSpecialSymbol(MyEmptySymbol);
81 theDimension->SetDisplaySpecialSymbol(AIS_DSS_No);
83 TCollection_ExtendedString aCustomValue;
84 if (theHasParameters) {
85 bool isParameterTextStyle = myStyle == SketcherPrs_ParameterStyleMessage::ParameterText;
87 if (isParameterTextStyle)
88 aCustomValue = theTextValue.c_str();
90 // format value string using "sprintf"
91 TCollection_AsciiString aFormatStr = theDimension->Attributes()->DimensionAspect()->ValueStringFormat();
93 sprintf (aFmtBuffer, aFormatStr.ToCString(), theDoubleValue);
94 aCustomValue = TCollection_ExtendedString (aFmtBuffer);
96 aCustomValue.Insert (1, MySigmaSymbol);
100 // format value string using "sprintf"
101 TCollection_AsciiString aFormatStr = theDimension->Attributes()->DimensionAspect()->ValueStringFormat();
102 char aFmtBuffer[256];
103 sprintf (aFmtBuffer, aFormatStr.ToCString(), theDoubleValue);
104 aCustomValue = TCollection_ExtendedString (aFmtBuffer);
106 #ifdef COMPILATION_CORRECTION
107 theDimension->SetCustomValue(theDoubleValue);
109 theDimension->SetCustomValue(aCustomValue);