Salome HOME
updated copyright message
[modules/geom.git] / src / MeasureGUI / MeasureGUI_DimensionCreateTool.h
1 // Copyright (C) 2007-2023  CEA, EDF, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File   : MeasureGUI_DimensionCreateTool.h
25 // Author : Anton POLETAEV, Open CASCADE S.A.S.
26 //
27 #ifndef MEASUREGUI_DIMENSIONCREATETOOL_H
28 #define MEASUREGUI_DIMENSIONCREATETOOL_H
29
30 // GEOM includes
31 #include <GeometryGUI.h>
32 #include <GEOM_GenericObjPtr.h>
33
34 // OCCT includes
35 #include <AIS_LengthDimension.hxx>
36 #include <AIS_DiameterDimension.hxx>
37 #include <AIS_AngleDimension.hxx>
38 #include <Bnd_Box.hxx>
39 #include <gp_Dir.hxx>
40 #include <TopoDS_Face.hxx>
41 #include <TopoDS_Edge.hxx>
42 #include <TColgp_SequenceOfDir.hxx>
43 #include <V3d_View.hxx>
44
45 //=================================================================================
46 // class    : MeasureGUI_DimensionCreateTool
47 // purpose  :
48 //=================================================================================
49 class MeasureGUI_DimensionCreateTool
50 {
51  public:
52   struct Segment
53   {
54     gp_Pnt First;
55     gp_Pnt Last;
56   };
57   typedef NCollection_Sequence<gp_Dir>  SeqOfDirs;
58   typedef NCollection_Sequence<gp_Pln>  SeqOfPlanes;
59   typedef NCollection_Sequence<Segment> SeqOfSegments;
60
61   MeasureGUI_DimensionCreateTool();
62
63   struct
64   {
65     Standard_Real DefaultFlyout;
66     Handle(V3d_View) ActiveView;
67   } Settings;
68
69 /* construction methods */
70 public:
71   Handle(AIS_LengthDimension)   LengthOnEdge( const GEOM::GeomObjPtr& ) const;
72
73   Handle(AIS_LengthDimension)   LengthByPoints( const GEOM::GeomObjPtr&,
74                                                 const GEOM::GeomObjPtr& ) const;
75
76   Handle(AIS_LengthDimension)   LengthByParallelEdges( const GEOM::GeomObjPtr&,
77                                                        const GEOM::GeomObjPtr& ) const;
78
79   Handle(AIS_DiameterDimension) Diameter( const GEOM::GeomObjPtr& ) const;
80
81   Handle(AIS_AngleDimension)    AngleByTwoEdges( const GEOM::GeomObjPtr&,
82                                                  const GEOM::GeomObjPtr& ) const;
83
84   Handle(AIS_AngleDimension)    AngleByThreePoints( const GEOM::GeomObjPtr&,
85                                                     const GEOM::GeomObjPtr&,
86                                                     const GEOM::GeomObjPtr& ) const;
87
88
89 /* selecting flyout direction for length dimensions */
90 protected:
91
92   void   ChooseLengthFlyoutsFromBnd( SeqOfDirs&,
93                                      const gp_Pnt&,
94                                      const gp_Pnt&,
95                                      const Bnd_Box& ) const;
96
97   gp_Dir ChooseDirFromBnd( const SeqOfDirs&,
98                            const gp_Pnt&,
99                            const Bnd_Box& ) const;
100
101 /* selecting best flyout direction taking into account view projection */
102 protected:
103
104   template <typename TPlane>
105   TPlane SelectPlaneForProjection( const NCollection_Sequence<TPlane>&,
106                                    const Handle(V3d_View)& ) const;
107
108 /* positioning */
109 protected:
110
111   void PositionLength( const Bnd_Box&,
112                        const gp_Vec&,
113                        const gp_Vec&,
114                        const gp_Vec&,
115                        const gp_Vec&,
116                        const gp_Pnt&,
117                        const gp_Pnt&,
118                        gp_Pln& ) const;
119
120   void PositionDiameter( const Bnd_Box&,
121                          const gp_Vec&,
122                          const gp_Circ&,
123                          gp_Pnt&,
124                          gp_Pnt&,
125                          gp_Pln& ) const;
126
127   void PositionDiameter( const Bnd_Box&,
128                          const gp_Vec&,
129                          const gp_Circ&,
130                          const Standard_Real&,
131                          gp_Pln& ) const;
132
133 /* utility */
134 protected:
135   GEOM::GeomObjPtr              GetMainShape( const GEOM::GeomObjPtr& ) const;
136   bool                          GetFaceSide( const TopoDS_Face&,
137                                              const TopoDS_Edge&,
138                                              gp_Dir& ) const;
139   SeqOfSegments                 GetInPlaneSegments( const gp_Circ&,
140                                                     const SeqOfDirs& ) const;
141 };
142
143 #endif