1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
20 #include "SketcherPrs_DimensionStyleListener.h"
21 #include <Prs3d_DimensionAspect.hxx>
22 #include "SketcherPrs_Tools.h"
24 #include <Events_Loop.h>
26 #include <AIS_Dimension.hxx>
27 #include <TCollection_ExtendedString.hxx>
30 // #define COMPILATION_CORRECTION
33 // it is not possible to use 0x2211 as summ symbol because it is not supported by
34 // debian Linux platform
35 static const Standard_ExtCharacter MyEmptySymbol(' ');
36 static const Standard_ExtCharacter MySigmaSymbol('=');//0x03A3); // using equal instead of sigma
38 SketcherPrs_DimensionStyleListener::DimensionValue::DimensionValue(double theDoubleValue,
39 bool theHasParameters, const std::string& theTextValue)
40 : myDoubleValue(theDoubleValue),
41 myHasParameters(theHasParameters),
42 myTextValue(theTextValue)
46 void SketcherPrs_DimensionStyleListener::DimensionValue::init(
47 const AttributeDoublePtr& theAttributeValue)
49 myDoubleValue = theAttributeValue->value();
50 myHasParameters = theAttributeValue->usedParameters().size() > 0;
51 myTextValue = theAttributeValue->text();
54 SketcherPrs_DimensionStyleListener::SketcherPrs_DimensionStyleListener()
56 Events_Loop* aLoop = Events_Loop::loop();
57 const Events_ID kDocCreatedEvent =
58 SketcherPrs_ParameterStyleMessage::eventId();
59 aLoop->registerListener(this, kDocCreatedEvent, NULL, false);
62 SketcherPrs_DimensionStyleListener::~SketcherPrs_DimensionStyleListener()
64 Events_Loop* aLoop = Events_Loop::loop();
65 aLoop->removeListener(this);
68 void SketcherPrs_DimensionStyleListener::processEvent(
69 const std::shared_ptr<Events_Message>& theMessage)
71 const Events_ID kParameterStyleEvent = SketcherPrs_ParameterStyleMessage::eventId();
72 if (theMessage->eventID() == kParameterStyleEvent) {
73 std::shared_ptr<SketcherPrs_ParameterStyleMessage> aMessage = std::dynamic_pointer_cast<
74 SketcherPrs_ParameterStyleMessage>(theMessage);
75 myStyle = aMessage->style();
79 void SketcherPrs_DimensionStyleListener::updateDimensions(AIS_Dimension* theDimension,
80 const SketcherPrs_DimensionStyleListener::DimensionValue& theDimensionValue)
84 updateDimensions(theDimension, theDimensionValue.myHasParameters,
85 theDimensionValue.myTextValue, theDimensionValue.myDoubleValue);
88 void SketcherPrs_DimensionStyleListener::updateDimensions(AIS_Dimension* theDimension,
89 const bool theHasParameters,
90 const std::string& theTextValue,
91 const double theDoubleValue)
96 /// do not show special symbols of dimension: previous implementation did not allow to unite them
97 theDimension->SetSpecialSymbol(MyEmptySymbol);
98 theDimension->SetDisplaySpecialSymbol(AIS_DSS_No);
100 TCollection_ExtendedString aCustomValue;
101 if (theHasParameters) {
102 bool isParameterTextStyle = myStyle == SketcherPrs_ParameterStyleMessage::ParameterText;
104 if (isParameterTextStyle)
105 aCustomValue = theTextValue.c_str();
107 // format value string using "sprintf"
108 TCollection_AsciiString aFormatStr =
109 theDimension->Attributes()->DimensionAspect()->ValueStringFormat();
110 char aFmtBuffer[256];
111 sprintf (aFmtBuffer, aFormatStr.ToCString(), theDoubleValue);
112 aCustomValue = TCollection_ExtendedString (aFmtBuffer);
114 aCustomValue.Insert (1, MySigmaSymbol);
118 // format value string using "sprintf"
119 TCollection_AsciiString aFormatStr =
120 theDimension->Attributes()->DimensionAspect()->ValueStringFormat();
121 char aFmtBuffer[256];
122 sprintf (aFmtBuffer, aFormatStr.ToCString(), theDoubleValue);
123 aCustomValue = TCollection_ExtendedString (aFmtBuffer);
125 #ifdef COMPILATION_CORRECTION
126 theDimension->SetCustomValue(theDoubleValue);
128 theDimension->SetCustomValue(aCustomValue);