Salome HOME
Issue #2206 Avoid the ability to cancel the current sketch when saving,
[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_AISObject.h>
25
26 #include <GeomAPI_Pnt.h>
27 #include <GeomAPI_Dir.h>
28 #include <GeomAPI_AISObject.h>
29
30 class ModuleBase_IWorkshop;
31 class ModelAPI_CompositeFeature;
32
33 /**
34 * \class PartSet_PreviewSketchPlane
35 * \ingroup Modules
36 * A class to show/hide sketch preview plane
37 */
38 class PartSet_PreviewSketchPlane
39 {
40 public:
41   /// Constructor
42   PartSet_PreviewSketchPlane();
43
44   ~PartSet_PreviewSketchPlane() {};
45
46   /// Returns if the sketch plane was displayed
47   /// \return boolean value
48   bool isSketchDisplayed() const { return mySketchDisplayed; }
49
50   /// Sets parameters of another sketch to be used in createSketchPlane().
51   /// \param theOtherSketchFace a shape of other selected sketch. It is a planar face.
52   void setOtherSketchParameters(const std::shared_ptr<GeomAPI_Shape>& theOtherSketchFace);
53
54   /// Erase preview planes
55   /// \param theWorkshop the application workshop
56   /// \param isClearPlane flag whether the plane, origin and normal should be nullified
57   void eraseSketchPlane(ModuleBase_IWorkshop* theWorkshop, const bool isClearPlane = true);
58
59   /// Show preview planes
60   /// \param theSketch source sketch to initialize plane
61   /// \param theWorkshop the application workshop
62   void createSketchPlane(const std::shared_ptr<ModelAPI_CompositeFeature>& theSketch,
63                          ModuleBase_IWorkshop* theWorkshop);
64
65   /// Resize plane size by sketch content
66   /// \param theSketch source sketch to build sketch sub features bounding box
67   /// \param theWorkshop the application workshop
68   void updatePlaneSize(const std::shared_ptr<ModelAPI_CompositeFeature>& theSketch,
69                        ModuleBase_IWorkshop* theWorkshop);
70
71 private:
72   /// Create a square face by parameters
73   /// \param theSize a size of created square
74   AISObjectPtr createPreviewPlane(double theSize);
75
76   /// Finds origin and maximum size of the shape
77   /// \param theShape source shape
78   /// \param theOrigin a shape center of mass
79   /// \param theSize maximum of delta X, Y or Z
80   void getShapeParameters(const std::shared_ptr<GeomAPI_Shape>& theShape,
81                           std::shared_ptr<GeomAPI_Pnt>& theOrigin,
82                           double& theSize);
83
84   /// Calculate maximum bounding box size of sketch sub features
85   /// \param theSketch source sketch to build sketch sub features bounding box
86   /// \param theCentralPoint central point of the sketch sub features
87   /// \return double value
88   double getSketchBoundingBoxSize(const std::shared_ptr<ModelAPI_CompositeFeature>& theSketch,
89                                   std::shared_ptr<GeomAPI_Pnt>& theCentralPnt);
90
91 private:
92   bool mySketchDisplayed;
93   AISObjectPtr myPlane;
94   std::shared_ptr<GeomAPI_Pnt> myOrigin; //! an origin of the plane
95   std::shared_ptr<GeomAPI_Dir> myNormal; //! a normal vector of the plane
96
97   std::shared_ptr<GeomAPI_Pnt> myOtherSketchOrigin;
98   double myOtherSketchSize;
99 };
100
101 #endif