Salome HOME
Issue #2605: Fix visibility state for complex objects with nesting more then 2
[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   /// Returns created external object or NULL
87   /// \return an object instance
88   ObjectPtr getExternalObjectValidated() const { return myExternalObjectValidated; }
89
90   // Removes the external presentation from the model
91   /// \param theSketch a current sketch
92   /// \param theFeature a current feature
93   /// \param theWorkshop a current workshop
94   /// \param theTemporary if true, a temporary external object is removed overwise all ext objects
95   void removeExternal(const CompositeFeaturePtr& theSketch,
96                       const FeaturePtr& theFeature,
97                       ModuleBase_IWorkshop* theWorkshop,
98                       const bool theTemporary);
99
100   /// Return an object and geom shape by the viewer presentation
101   /// \param thePrs a selection
102   /// \param theObject an output object
103   /// \param theShape a shape of the selection
104   virtual void getGeomSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs,
105                                 ObjectPtr& theObject,
106                                 GeomShapePtr& theShape,
107                                 ModuleBase_IWorkshop* theWorkshop,
108                                 const CompositeFeaturePtr& theSketch,
109                                 const bool isInValidate);
110
111 protected:
112   /// Delete from the document the feature of the object. It deletes all objects, which refers to
113   /// the deleted one. The parameter feature is ignored even it refer to the deleted object.
114   /// \param theObject a removed object
115   /// \param theSketch a current sketch
116   /// \param theFeature a current feature
117   /// \param theWorkshop a current workshop
118   void removeExternalObject(const ObjectPtr& theObject,
119                             const CompositeFeaturePtr& theSketch,
120                             const FeaturePtr& theFeature,
121                             ModuleBase_IWorkshop* theWorkshop);
122
123   /// Returns the workshop
124   static XGUI_Workshop* workshop(ModuleBase_IWorkshop* theWorkshop);
125
126 protected:
127   /// An external object
128   ObjectPtr myExternalObjectValidated;
129
130   /// Boolean value about the neccessity of the external object use
131   bool myUseExternal;
132   /// Boolean value about the necessity of a new external object creation
133   bool myCanCreateExternal;
134 };
135
136 #endif