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>
16 #define COMPILATION_CORRECTION
19 // it is not possible to use 0x2211 as summ symbol because it is not supported by
20 // debian Linux platform
21 static const Standard_ExtCharacter MyEmptySymbol(' ');
22 static const Standard_ExtCharacter MySigmaSymbol('=');//0x03A3); // using equal instead of sigma
24 SketcherPrs_DimensionStyleListener::DimensionValue::DimensionValue(double theDoubleValue,
25 bool theHasParameters, const std::string& theTextValue)
26 : myDoubleValue(theDoubleValue),
27 myHasParameters(theHasParameters),
28 myTextValue(theTextValue)
32 void SketcherPrs_DimensionStyleListener::DimensionValue::init(
33 const AttributeDoublePtr& theAttributeValue)
35 myDoubleValue = theAttributeValue->value();
36 myHasParameters = theAttributeValue->usedParameters().size() > 0;
37 myTextValue = theAttributeValue->text();
40 SketcherPrs_DimensionStyleListener::SketcherPrs_DimensionStyleListener()
42 Events_Loop* aLoop = Events_Loop::loop();
43 const Events_ID kDocCreatedEvent =
44 SketcherPrs_ParameterStyleMessage::eventId();
45 aLoop->registerListener(this, kDocCreatedEvent, NULL, false);
48 SketcherPrs_DimensionStyleListener::~SketcherPrs_DimensionStyleListener()
50 Events_Loop* aLoop = Events_Loop::loop();
51 aLoop->removeListener(this);
54 void SketcherPrs_DimensionStyleListener::processEvent(const std::shared_ptr<Events_Message>& theMessage)
56 const Events_ID kParameterStyleEvent = SketcherPrs_ParameterStyleMessage::eventId();
57 if (theMessage->eventID() == kParameterStyleEvent) {
58 std::shared_ptr<SketcherPrs_ParameterStyleMessage> aMessage = std::dynamic_pointer_cast<
59 SketcherPrs_ParameterStyleMessage>(theMessage);
60 myStyle = aMessage->style();
64 void SketcherPrs_DimensionStyleListener::updateDimensions(AIS_Dimension* theDimension,
65 const SketcherPrs_DimensionStyleListener::DimensionValue& theDimensionValue)
69 updateDimensions(theDimension, theDimensionValue.myHasParameters,
70 theDimensionValue.myTextValue, theDimensionValue.myDoubleValue);
73 void SketcherPrs_DimensionStyleListener::updateDimensions(AIS_Dimension* theDimension,
74 const bool theHasParameters,
75 const std::string& theTextValue,
76 const double theDoubleValue)
81 /// do not show special symbols of dimension: previous implementation did not allow to unite them
82 theDimension->SetSpecialSymbol(MyEmptySymbol);
83 theDimension->SetDisplaySpecialSymbol(AIS_DSS_No);
85 TCollection_ExtendedString aCustomValue;
86 if (theHasParameters) {
87 bool isParameterTextStyle = myStyle == SketcherPrs_ParameterStyleMessage::ParameterText;
89 if (isParameterTextStyle)
90 aCustomValue = theTextValue.c_str();
92 // format value string using "sprintf"
93 TCollection_AsciiString aFormatStr = theDimension->Attributes()->DimensionAspect()->ValueStringFormat();
95 sprintf (aFmtBuffer, aFormatStr.ToCString(), theDoubleValue);
96 aCustomValue = TCollection_ExtendedString (aFmtBuffer);
98 aCustomValue.Insert (1, MySigmaSymbol);
102 // format value string using "sprintf"
103 TCollection_AsciiString aFormatStr = theDimension->Attributes()->DimensionAspect()->ValueStringFormat();
104 char aFmtBuffer[256];
105 sprintf (aFmtBuffer, aFormatStr.ToCString(), theDoubleValue);
106 aCustomValue = TCollection_ExtendedString (aFmtBuffer);
108 #ifdef COMPILATION_CORRECTION
109 theDimension->SetCustomValue(theDoubleValue);
111 theDimension->SetCustomValue(aCustomValue);