Salome HOME
Issue #3237: Allow usage of accented characters in ObjectBrowser
[modules/shaper.git] / src / SketcherPrs / SketcherPrs_DimensionStyle.cpp
1 // Copyright (C) 2014-2020  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "SketcherPrs_DimensionStyle.h"
21 #include <Prs3d_DimensionAspect.hxx>
22 #include "SketcherPrs_Tools.h"
23
24 #include <Events_Loop.h>
25
26 #include <Locale_Convert.h>
27
28 #include <AIS_Dimension.hxx>
29 #include <TCollection_ExtendedString.hxx>
30
31 //#ifndef WNT
32 //  #define COMPILATION_CORRECTION
33 //#endif
34
35 // it is not possible to use 0x2211 as summ symbol because it is not supported by
36 // debian Linux platform
37 static const Standard_ExtCharacter MyEmptySymbol(' ');
38 static const Standard_ExtCharacter MySigmaSymbol('=');//0x03A3); // using equal instead of sigma
39
40
41 SketcherPrs_DimensionStyle::DimensionValue::DimensionValue(double theDoubleValue,
42                                      bool theHasParameters, const std::string& theTextValue)
43 : myDoubleValue(theDoubleValue),
44   myHasParameters(theHasParameters),
45   myTextValue(theTextValue)
46 {
47 }
48
49 void SketcherPrs_DimensionStyle::DimensionValue::init(
50                                                 const AttributeDoublePtr& theAttributeValue)
51 {
52   myDoubleValue = theAttributeValue->value();
53   myHasParameters = theAttributeValue->usedParameters().size() > 0;
54   myTextValue = Locale::Convert::toString(theAttributeValue->text());
55 }
56
57 SketcherPrs_DimensionStyle::SketcherPrs_DimensionStyle()
58 {
59 }
60
61 SketcherPrs_DimensionStyle::~SketcherPrs_DimensionStyle()
62 {
63 }
64
65 void SketcherPrs_DimensionStyle::updateDimensions(AIS_Dimension* theDimension,
66           const SketcherPrs_DimensionStyle::DimensionValue& theDimensionValue)
67 {
68   if (!theDimension)
69     return;
70   updateDimensions(theDimension, theDimensionValue.myHasParameters,
71                    theDimensionValue.myTextValue, theDimensionValue.myDoubleValue);
72 }
73
74 void SketcherPrs_DimensionStyle::updateDimensions(AIS_Dimension* theDimension,
75                                                           const bool theHasParameters,
76                                                           const std::string& theTextValue,
77                                                           const double theDoubleValue)
78 {
79   if (!theDimension)
80     return;
81
82   /// do not show special symbols of dimension:
83   ///   previous implementation did not allow to unite them
84   theDimension->SetSpecialSymbol(MyEmptySymbol);
85   theDimension->SetDisplaySpecialSymbol(AIS_DSS_No);
86
87   TCollection_ExtendedString aCustomValue;
88   if (theHasParameters) {
89     //bool isParameterTextStyle = myStyle == SketcherPrs_ParameterStyleMessage::ParameterText;
90     bool isParameterTextStyle =
91       SketcherPrs_Tools::parameterStyle() == SketcherPrs_Tools::ParameterText;
92
93     if (isParameterTextStyle)
94       aCustomValue = theTextValue.c_str();
95     else {
96       // format value string using "sprintf"
97       TCollection_AsciiString aFormatStr =
98         theDimension->Attributes()->DimensionAspect()->ValueStringFormat();
99       char aFmtBuffer[256];
100       sprintf (aFmtBuffer, aFormatStr.ToCString(), theDoubleValue);
101       aCustomValue = TCollection_ExtendedString (aFmtBuffer);
102
103       aCustomValue.Insert (1, MySigmaSymbol);
104     }
105   }
106   else {
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);
113   }
114 #ifdef COMPILATION_CORRECTION
115   theDimension->SetCustomValue(theDoubleValue);
116 #else
117   theDimension->SetCustomValue(aCustomValue);
118 #endif
119 }