Salome HOME
Copyright update 2022
[modules/shaper.git] / src / SketcherPrs / SketcherPrs_DimensionStyle.cpp
1 // Copyright (C) 2014-2022  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 <PrsDim_Dimension.hxx>
29 #include <TCollection_ExtendedString.hxx>
30 #include <Standard_Version.hxx>
31
32 //#ifndef WNT
33 //  #define COMPILATION_CORRECTION
34 //#endif
35
36 // it is not possible to use 0x2211 as summ symbol because it is not supported by
37 // debian Linux platform
38 static const Standard_ExtCharacter MyEmptySymbol(' ');
39 static const Standard_ExtCharacter MySigmaSymbol('=');//0x03A3); // using equal instead of sigma
40
41
42 SketcherPrs_DimensionStyle::DimensionValue::DimensionValue(double theDoubleValue,
43                                      bool theHasParameters, const std::string& theTextValue)
44 : myDoubleValue(theDoubleValue),
45   myHasParameters(theHasParameters),
46   myTextValue(theTextValue)
47 {
48 }
49
50 void SketcherPrs_DimensionStyle::DimensionValue::init(
51                                                 const AttributeDoublePtr& theAttributeValue)
52 {
53   myDoubleValue = theAttributeValue->value();
54   myHasParameters = theAttributeValue->usedParameters().size() > 0;
55   myTextValue = Locale::Convert::toString(theAttributeValue->text());
56 }
57
58 SketcherPrs_DimensionStyle::SketcherPrs_DimensionStyle()
59 {
60 }
61
62 SketcherPrs_DimensionStyle::~SketcherPrs_DimensionStyle()
63 {
64 }
65
66 void SketcherPrs_DimensionStyle::updateDimensions(PrsDim_Dimension* theDimension,
67           const SketcherPrs_DimensionStyle::DimensionValue& theDimensionValue)
68 {
69   if (!theDimension)
70     return;
71   updateDimensions(theDimension, theDimensionValue.myHasParameters,
72                    theDimensionValue.myTextValue, theDimensionValue.myDoubleValue);
73 }
74
75 void SketcherPrs_DimensionStyle::updateDimensions(PrsDim_Dimension* theDimension,
76                                                   const bool theHasParameters,
77                                                   const std::string& theTextValue,
78                                                   const double theDoubleValue)
79 {
80   if (!theDimension)
81     return;
82
83   /// do not show special symbols of dimension:
84   ///   previous implementation did not allow to unite them
85   theDimension->SetSpecialSymbol(MyEmptySymbol);
86 #if OCC_VERSION_HEX > 0x070400
87   theDimension->SetDisplaySpecialSymbol(PrsDim_DisplaySpecialSymbol_No);
88 #else
89   theDimension->SetDisplaySpecialSymbol(AIS_DSS_No);
90 #endif
91
92   TCollection_ExtendedString aCustomValue;
93   if (theHasParameters) {
94     //bool isParameterTextStyle = myStyle == SketcherPrs_ParameterStyleMessage::ParameterText;
95     bool isParameterTextStyle =
96       SketcherPrs_Tools::parameterStyle() == SketcherPrs_Tools::ParameterText;
97
98     if (isParameterTextStyle)
99       aCustomValue = theTextValue.c_str();
100     else {
101       // format value string using "sprintf"
102       TCollection_AsciiString aFormatStr =
103         theDimension->Attributes()->DimensionAspect()->ValueStringFormat();
104       char aFmtBuffer[256];
105       sprintf (aFmtBuffer, aFormatStr.ToCString(), theDoubleValue);
106       aCustomValue = TCollection_ExtendedString (aFmtBuffer);
107
108       aCustomValue.Insert (1, MySigmaSymbol);
109     }
110   }
111   else {
112     // format value string using "sprintf"
113     TCollection_AsciiString aFormatStr =
114       theDimension->Attributes()->DimensionAspect()->ValueStringFormat();
115     char aFmtBuffer[256];
116     sprintf (aFmtBuffer, aFormatStr.ToCString(), theDoubleValue);
117     aCustomValue = TCollection_ExtendedString (aFmtBuffer);
118   }
119 #ifdef COMPILATION_CORRECTION
120   theDimension->SetCustomValue(theDoubleValue);
121 #else
122   theDimension->SetCustomValue(aCustomValue);
123 #endif
124 }