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 <Prs3d_DimensionAspect.hxx>
9 #include "SketcherPrs_Tools.h"
11 #include <Events_Loop.h>
13 #include <AIS_Dimension.hxx>
14 #include <TCollection_ExtendedString.hxx>
17 // #define COMPILATION_CORRECTION
20 // it is not possible to use 0x2211 as summ symbol because it is not supported by
21 // debian Linux platform
22 static const Standard_ExtCharacter MyEmptySymbol(' ');
23 static const Standard_ExtCharacter MySigmaSymbol('=');//0x03A3); // using equal instead of sigma
25 SketcherPrs_DimensionStyleListener::DimensionValue::DimensionValue(double theDoubleValue,
26 bool theHasParameters, const std::string& theTextValue)
27 : myDoubleValue(theDoubleValue),
28 myHasParameters(theHasParameters),
29 myTextValue(theTextValue)
33 void SketcherPrs_DimensionStyleListener::DimensionValue::init(
34 const AttributeDoublePtr& theAttributeValue)
36 myDoubleValue = theAttributeValue->value();
37 myHasParameters = theAttributeValue->usedParameters().size() > 0;
38 myTextValue = theAttributeValue->text();
41 SketcherPrs_DimensionStyleListener::SketcherPrs_DimensionStyleListener()
43 Events_Loop* aLoop = Events_Loop::loop();
44 const Events_ID kDocCreatedEvent =
45 SketcherPrs_ParameterStyleMessage::eventId();
46 aLoop->registerListener(this, kDocCreatedEvent, NULL, false);
49 SketcherPrs_DimensionStyleListener::~SketcherPrs_DimensionStyleListener()
51 Events_Loop* aLoop = Events_Loop::loop();
52 aLoop->removeListener(this);
55 void SketcherPrs_DimensionStyleListener::processEvent(
56 const std::shared_ptr<Events_Message>& theMessage)
58 const Events_ID kParameterStyleEvent = SketcherPrs_ParameterStyleMessage::eventId();
59 if (theMessage->eventID() == kParameterStyleEvent) {
60 std::shared_ptr<SketcherPrs_ParameterStyleMessage> aMessage = std::dynamic_pointer_cast<
61 SketcherPrs_ParameterStyleMessage>(theMessage);
62 myStyle = aMessage->style();
66 void SketcherPrs_DimensionStyleListener::updateDimensions(AIS_Dimension* theDimension,
67 const SketcherPrs_DimensionStyleListener::DimensionValue& theDimensionValue)
71 updateDimensions(theDimension, theDimensionValue.myHasParameters,
72 theDimensionValue.myTextValue, theDimensionValue.myDoubleValue);
75 void SketcherPrs_DimensionStyleListener::updateDimensions(AIS_Dimension* theDimension,
76 const bool theHasParameters,
77 const std::string& theTextValue,
78 const double theDoubleValue)
83 /// do not show special symbols of dimension: previous implementation did not allow to unite them
84 theDimension->SetSpecialSymbol(MyEmptySymbol);
85 theDimension->SetDisplaySpecialSymbol(AIS_DSS_No);
87 TCollection_ExtendedString aCustomValue;
88 if (theHasParameters) {
89 bool isParameterTextStyle = myStyle == SketcherPrs_ParameterStyleMessage::ParameterText;
91 if (isParameterTextStyle)
92 aCustomValue = theTextValue.c_str();
94 // format value string using "sprintf"
95 TCollection_AsciiString aFormatStr =
96 theDimension->Attributes()->DimensionAspect()->ValueStringFormat();
98 sprintf (aFmtBuffer, aFormatStr.ToCString(), theDoubleValue);
99 aCustomValue = TCollection_ExtendedString (aFmtBuffer);
101 aCustomValue.Insert (1, MySigmaSymbol);
105 // format value string using "sprintf"
106 TCollection_AsciiString aFormatStr =
107 theDimension->Attributes()->DimensionAspect()->ValueStringFormat();
108 char aFmtBuffer[256];
109 sprintf (aFmtBuffer, aFormatStr.ToCString(), theDoubleValue);
110 aCustomValue = TCollection_ExtendedString (aFmtBuffer);
112 #ifdef COMPILATION_CORRECTION
113 theDimension->SetCustomValue(theDoubleValue);
115 theDimension->SetCustomValue(aCustomValue);