Salome HOME
Increase the timeout for HDF test cases.
[modules/shaper.git] / src / SketcherPrs / SketcherPrs_DimensionStyle.cpp
1 // Copyright (C) 2014-2019  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 <AIS_Dimension.hxx>
27 #include <TCollection_ExtendedString.hxx>
28
29 //#ifndef WNT
30 //  #define COMPILATION_CORRECTION
31 //#endif
32
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
37
38
39 SketcherPrs_DimensionStyle::DimensionValue::DimensionValue(double theDoubleValue,
40                                      bool theHasParameters, const std::string& theTextValue)
41 : myDoubleValue(theDoubleValue),
42   myHasParameters(theHasParameters),
43   myTextValue(theTextValue)
44 {
45 }
46
47 void SketcherPrs_DimensionStyle::DimensionValue::init(
48                                                 const AttributeDoublePtr& theAttributeValue)
49 {
50   myDoubleValue = theAttributeValue->value();
51   myHasParameters = theAttributeValue->usedParameters().size() > 0;
52   myTextValue = theAttributeValue->text();
53 }
54
55 SketcherPrs_DimensionStyle::SketcherPrs_DimensionStyle()
56 {
57 }
58
59 SketcherPrs_DimensionStyle::~SketcherPrs_DimensionStyle()
60 {
61 }
62
63 void SketcherPrs_DimensionStyle::updateDimensions(AIS_Dimension* theDimension,
64           const SketcherPrs_DimensionStyle::DimensionValue& theDimensionValue)
65 {
66   if (!theDimension)
67     return;
68   updateDimensions(theDimension, theDimensionValue.myHasParameters,
69                    theDimensionValue.myTextValue, theDimensionValue.myDoubleValue);
70 }
71
72 void SketcherPrs_DimensionStyle::updateDimensions(AIS_Dimension* theDimension,
73                                                           const bool theHasParameters,
74                                                           const std::string& theTextValue,
75                                                           const double theDoubleValue)
76 {
77   if (!theDimension)
78     return;
79
80   /// do not show special symbols of dimension:
81   ///   previous implementation did not allow to unite them
82   theDimension->SetSpecialSymbol(MyEmptySymbol);
83   theDimension->SetDisplaySpecialSymbol(AIS_DSS_No);
84
85   TCollection_ExtendedString aCustomValue;
86   if (theHasParameters) {
87     //bool isParameterTextStyle = myStyle == SketcherPrs_ParameterStyleMessage::ParameterText;
88     bool isParameterTextStyle =
89       SketcherPrs_Tools::parameterStyle() == SketcherPrs_Tools::ParameterText;
90
91     if (isParameterTextStyle)
92       aCustomValue = theTextValue.c_str();
93     else {
94       // format value string using "sprintf"
95       TCollection_AsciiString aFormatStr =
96         theDimension->Attributes()->DimensionAspect()->ValueStringFormat();
97       char aFmtBuffer[256];
98       sprintf (aFmtBuffer, aFormatStr.ToCString(), theDoubleValue);
99       aCustomValue = TCollection_ExtendedString (aFmtBuffer);
100
101       aCustomValue.Insert (1, MySigmaSymbol);
102     }
103   }
104   else {
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);
111   }
112 #ifdef COMPILATION_CORRECTION
113   theDimension->SetCustomValue(theDoubleValue);
114 #else
115   theDimension->SetCustomValue(aCustomValue);
116 #endif
117 }