Salome HOME
088b75df06281d51298c08f9089bb839ce014bbe
[modules/shaper.git] / src / SketcherPrs / SketcherPrs_LengthDimension.h
1 // Copyright (C) 2014-2023  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_LinearDimension_H
21 #define SketcherPrs_LinearDimension_H
22
23 #include <GeomAPI_Ax3.h>
24 #include <ModelAPI_Feature.h>
25 #include <PrsDim_LengthDimension.hxx>
26 #include <Standard_DefineHandle.hxx>
27 #include <SketchPlugin_Sketch.h>
28
29 #include <gp_Pnt.hxx>
30 #include <gp_Pln.hxx>
31 #include <string>
32
33 #include <SketcherPrs_DimensionStyle.h>
34
35 DEFINE_STANDARD_HANDLE(SketcherPrs_LengthDimension, PrsDim_LengthDimension)
36
37 /**
38 * \ingroup GUI
39 * A class for representation of linear dimension constraint.
40 * It supports SketchPlugin_ConstraintLength and SketchPlugin_ConstraintDistance features.
41 */
42 class SketcherPrs_LengthDimension : public PrsDim_LengthDimension
43 {
44 public:
45   /// Constructor
46   /// \param theConstraint a constraint feature
47   /// \param thePlane a coordinate plane of current sketch
48   Standard_EXPORT SketcherPrs_LengthDimension(ModelAPI_Feature* theConstraint,
49     SketchPlugin_Sketch* theSketcher);
50
51   /// Destructor
52   Standard_EXPORT ~SketcherPrs_LengthDimension();
53
54   DEFINE_STANDARD_RTTIEXT(SketcherPrs_LengthDimension, PrsDim_LengthDimension)
55
56   /// Returns true if the constraint feature arguments are correcly filled
57   /// to build AIS presentation
58   /// \param theConstraint a constraint feature
59   /// \param thePlane a coordinate plane of current sketch
60   /// \return boolean result value
61   static bool IsReadyToDisplay(ModelAPI_Feature* theConstraint,
62                                const std::shared_ptr<GeomAPI_Ax3>& thePlane);
63
64   /// Returns sketcher plane
65   Standard_EXPORT std::shared_ptr<GeomAPI_Ax3> plane() const
66   {
67     return mySketcher->coordinatePlane();
68   }
69
70 protected:
71   /// Redefinition of virtual function
72   Standard_EXPORT virtual void Compute(
73     const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
74     const Handle(Prs3d_Presentation)& thePresentation,
75     const Standard_Integer theMode = 0);
76
77   /// Redefinition of virtual function
78   Standard_EXPORT virtual void ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
79     const Standard_Integer aMode);
80
81 private:
82   static bool readyToDisplay(ModelAPI_Feature* theConstraint,
83                              const std::shared_ptr<GeomAPI_Ax3>& thePlane,
84                              gp_Pnt2d& thePnt1, gp_Pnt2d& thePnt2);
85
86   /// Set the direction for horizontal/vertical constraint
87   void setDirection(ModelAPI_Feature* theConstraint,
88                     const std::shared_ptr<GeomAPI_Ax3>& thePlane);
89
90   /// Constraint feature
91   ModelAPI_Feature* myConstraint;
92
93   /// A current sketcher
94   SketchPlugin_Sketch* mySketcher;
95
96   //Handle(Prs3d_DimensionAspect) myAspect;
97
98   /// Listener to update dimension visualization style
99   SketcherPrs_DimensionStyle* myStyleListener;
100
101   /// container of values obtained from the constraint, which are necessary
102   /// to fill the presentation
103   gp_Pnt myFirstPoint; ///< the dimension first point for measured geometry
104   gp_Pnt mySecondPoint; ///< the dimension first point for measured geometry
105   gp_Pln myPlane; ///< the plane(plane of the sketch) for measured geometry
106   double myDistance; ///< the flyout distance
107
108   /// the structure filled by constraint
109   SketcherPrs_DimensionStyle::DimensionValue myValue;
110 };
111
112 #endif