Salome HOME
5e623994341b7c21564f8362da9b96b8a0806a05
[modules/shaper.git] / src / SketcherPrs / SketcherPrs_DimensionStyleListener.h
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 #ifndef SketcherPrs_DimensionStyleListener_H
21 #define SketcherPrs_DimensionStyleListener_H
22
23 #include <Events_Listener.h>
24
25 #include <ModelAPI_AttributeDouble.h>
26
27 #include "SketcherPrs_Tools.h"
28
29 #include <Standard.hxx>
30
31 #include <string>
32
33 /**
34 * \class SketcherPrs_DimensionStyleListener
35 * \ingroup GUI
36 * A class for representation of linear dimension constraint.
37 * It supports SketchPlugin_ConstraintLength and SketchPlugin_ConstraintDistance features.
38 */
39 class SketcherPrs_DimensionStyleListener : public Events_Listener
40 {
41 public:
42   class DimensionValue {
43   public:
44     DimensionValue(double theDoubleValue, bool theHasParameters, const std::string& theTextValue);
45     /// Fills internal fields by the given attribute
46     /// \param theAttributeValue a model attribute
47     void init(const AttributeDoublePtr& theAttributeValue);
48
49   public:
50     double myDoubleValue; ///< the angle value to be shown as custom value of presentation
51     bool myHasParameters; ///< true if the atrribute value has used parameters
52     std::string myTextValue; ///< the angle value depending on angle type
53   };
54
55 public:
56   /// Constructor
57   Standard_EXPORT SketcherPrs_DimensionStyleListener();
58
59   /// Destructor
60   Standard_EXPORT ~SketcherPrs_DimensionStyleListener();
61
62   /// Process the ModelAPI_DocumentCreatedMessage to fulfill a document
63   /// from the message with origin and planes
64   virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
65
66   /// Visualizes the dimension text or dimension value depending on the has parameters state
67   /// \param theDimension a modified dimension
68   /// \param theDimensionValue container filled by the model double attribute
69   Standard_EXPORT void updateDimensions(AIS_Dimension* theDimension,
70                                         const DimensionValue& theDimensionValue);
71
72 private:
73   /// Visualizes the dimension text or dimension value depending on the has parameters state
74   /// \param theDimension a modified dimension
75   /// \param theHasParameters if true, the text is shown, else digit
76   /// \param theTextValue a dimension text value
77   /// \param theDoubleValue a dimension digit value
78   void updateDimensions(AIS_Dimension* theDimension,
79                         const bool theHasParameters,
80                         const std::string& theTextValue,
81                         const double theDoubleValue);
82 private:
83   /// Style how the parameter of dimension should be visualized
84   SketcherPrs_ParameterStyleMessage::ParameterStyle myStyle;
85 };
86
87 #endif