Salome HOME
Issue #2293 Size of the view of a sketch is lost when pressing Set Plane View
[modules/shaper.git] / src / PartSet / PartSet_PreviewSketchPlane.h
1 // Copyright (C) 2014-2017  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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #ifndef PartSet_PreviewSketchPlane_H
22 #define PartSet_PreviewSketchPlane_H
23
24 #include <GeomAPI_Pnt.h>
25
26 class GeomAPI_AISObject;
27 class GeomAPI_Shape;
28
29 class ModuleBase_IWorkshop;
30 class ModelAPI_CompositeFeature;
31
32 #include <memory>
33
34 /**
35 * \class PartSet_PreviewSketchPlane
36 * \ingroup Modules
37 * A class to show/hide sketch preview plane
38 */
39 class PartSet_PreviewSketchPlane
40 {
41 public:
42   /// Constructor
43   PartSet_PreviewSketchPlane();
44
45   ~PartSet_PreviewSketchPlane() {};
46
47   /// Erase preview planes
48   /// \param theWorkshop the application workshop
49   /// \param isClearPlane flag whether the plane, origin and normal should be nullified
50   void eraseSketchPlane(ModuleBase_IWorkshop* theWorkshop, const bool isClearPlane = true);
51
52   /// Show preview planes
53   /// \param theSketch source sketch to initialize plane
54   /// \param theWorkshop the application workshop
55   void createSketchPlane(const std::shared_ptr<ModelAPI_CompositeFeature>& theSketch,
56                          ModuleBase_IWorkshop* theWorkshop);
57
58   /// Returns bounding box size covered the sketch sub-elements.
59   /// If the sketch uses extenal face, it will not have default size and returns false.
60   /// \param theSketch sources sketch
61   /// \param [out] theSizeOfView maximum value in X, Y or Z direction
62   /// \param theCentralPoint central point of the sketch sub features
63   /// \return boolean value
64   bool getDefaultSizeOfView(const std::shared_ptr<ModelAPI_CompositeFeature>& theSketch,
65                             double& theSizeOfView,
66                             std::shared_ptr<GeomAPI_Pnt>& theCentralPnt);
67
68   /// Returns whether custom size of view is set
69   /// \return boolean value
70   bool isUseSizeOfView() const { return myIsUseSizeOfView; }
71
72   /// Sets the size of default created face
73   /// \param theSizeOfView value
74   /// \param isUseSizeOfView state whether the size should be used
75   void setSizeOfView(double theSizeOfView, bool isUseSizeOfView,
76     const std::shared_ptr<GeomAPI_Pnt>& theCentralPoint = std::shared_ptr<GeomAPI_Pnt>());
77
78 private:
79   /// Create a square face by parameters
80   std::shared_ptr<GeomAPI_AISObject> createPreviewPlane();
81
82 private:
83   bool myPreviewIsDisplayed;
84   std::shared_ptr<GeomAPI_AISObject> myPlane; //! visualized presentation
85   std::shared_ptr<GeomAPI_Shape> myShape; //! current shape to be displayed
86   std::shared_ptr<GeomAPI_Pnt> myViewCentralPoint; //! central point of the default view
87
88   double mySizeOfView; //! size that should be used by creating a default face
89   bool myIsUseSizeOfView; //! state if the size is custom or from preferences
90   std::shared_ptr<GeomAPI_Pnt> myViewOrigin; //! origin point of sketch if default view is used
91 };
92
93 #endif