Salome HOME
Issue #2325 impossible to select center of cylinder in sketch
[modules/shaper.git] / src / PartSet / PartSet_ExternalObjectsMgr.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_ExternalObjectsMgr_H
22 #define PartSet_ExternalObjectsMgr_H
23
24 #include "PartSet.h"
25
26 #include <ModelAPI_CompositeFeature.h>
27 #include <ModelAPI_Object.h>
28 #include <GeomAPI_Shape.h>
29
30 #include <ModuleBase_Definitions.h>
31
32 #include <string>
33
34 class ModuleBase_IWorkshop;
35 class ModuleBase_ViewerPrs;
36 class XGUI_Workshop;
37
38 /**
39 * \ingroup Modules
40 * Customosation of ModuleBase_WidgetShapeSelector in order to provide 
41 * working with sketch specific objects.
42 */
43 class PARTSET_EXPORT PartSet_ExternalObjectsMgr
44 {
45  public:
46   /// Constructor
47   /// \param theExternal the external state
48   /// \param theCanCreateExternal the state if it can and should create external features
49   /// \param theDefaultValue the default value for the external object using
50   PartSet_ExternalObjectsMgr(const std::string& theExternal,
51                              const std::string& theCanCreateExternal,
52                              const bool theDefaultValue);
53
54   virtual ~PartSet_ExternalObjectsMgr() {}
55
56   /// Returns the state whether the external object is used
57   bool useExternal() const { return myUseExternal; }
58
59   /// Returns if new external objects can be created
60   /// \return boolean value
61   bool canCreateExternal() { return myCanCreateExternal;}
62
63   /// Checks validity of the given object
64   /// \param theObject an object to check
65   /// \return valid or not valid
66   bool isValidObject(const ObjectPtr& theObject);
67
68   /// Finds or create and external object
69   /// \param theSelectedObject an object
70   /// \param theShape a selected shape, which is used in the selection attribute
71   /// \param theSketch a current sketch
72   /// \param theTemporary the created external object is temporary, execute is not performed for it
73   /// \return the object
74   ObjectPtr externalObject(const ObjectPtr& theSelectedObject, const GeomShapePtr& theShape,
75                            const CompositeFeaturePtr& theSketch, const bool theTemporary = false);
76
77   /// Finds or create and external object by selected circle center (PartSet_CenterPrs)
78   /// \param thePrs a selection
79   /// \param theSketch a current sketch
80   /// \param theTemporary the created external object is temporary, execute is not performed for it
81   /// \return the object
82   ObjectPtr externalCenterObject(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs,
83                                  const CompositeFeaturePtr& theSketch,
84                                  const bool theTemporary);
85
86   // Removes the external presentation from the model
87   /// \param theSketch a current sketch
88   /// \param theFeature a current feature
89   /// \param theWorkshop a current workshop
90   /// \param theTemporary if true, a temporary external object is removed overwise all ext objects
91   void removeExternal(const CompositeFeaturePtr& theSketch,
92                       const FeaturePtr& theFeature,
93                       ModuleBase_IWorkshop* theWorkshop,
94                       const bool theTemporary);
95
96   /// Return an object and geom shape by the viewer presentation
97   /// \param thePrs a selection
98   /// \param theObject an output object
99   /// \param theShape a shape of the selection
100   virtual void getGeomSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs,
101                                 ObjectPtr& theObject,
102                                 GeomShapePtr& theShape,
103                                 ModuleBase_IWorkshop* theWorkshop,
104                                 const CompositeFeaturePtr& theSketch,
105                                 const bool isInValidate);
106
107 protected:
108   /// Delete from the document the feature of the object. It deletes all objects, which refers to
109   /// the deleted one. The parameter feature is ignored even it refer to the deleted object.
110   /// \param theObject a removed object
111   /// \param theSketch a current sketch
112   /// \param theFeature a current feature
113   /// \param theWorkshop a current workshop
114   void removeExternalObject(const ObjectPtr& theObject,
115                             const CompositeFeaturePtr& theSketch,
116                             const FeaturePtr& theFeature,
117                             ModuleBase_IWorkshop* theWorkshop);
118
119   /// Returns the workshop
120   static XGUI_Workshop* workshop(ModuleBase_IWorkshop* theWorkshop);
121
122 protected:
123   /// An external object
124   ObjectPtr myExternalObjectValidated;
125
126   /// Boolean value about the neccessity of the external object use
127   bool myUseExternal;
128   /// Boolean value about the necessity of a new external object creation
129   bool myCanCreateExternal;
130 };
131
132 #endif