Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[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   // Removes the external presentation from the model
78   /// \param theSketch a current sketch
79   /// \param theFeature a current feature
80   /// \param theWorkshop a current workshop
81   /// \param theTemporary if true, a temporary external object is removed overwise all ext objects
82   void removeExternal(const CompositeFeaturePtr& theSketch,
83                       const FeaturePtr& theFeature,
84                       ModuleBase_IWorkshop* theWorkshop,
85                       const bool theTemporary);
86
87   /// Return an object and geom shape by the viewer presentation
88   /// \param thePrs a selection
89   /// \param theObject an output object
90   /// \param theShape a shape of the selection
91   virtual void getGeomSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs,
92                                 ObjectPtr& theObject,
93                                 GeomShapePtr& theShape,
94                                 ModuleBase_IWorkshop* theWorkshop,
95                                 const CompositeFeaturePtr& theSketch,
96                                 const bool isInValidate);
97
98 protected:
99   /// Delete from the document the feature of the object. It deletes all objects, which refers to
100   /// the deleted one. The parameter feature is ignored even it refer to the deleted object.
101   /// \param theObject a removed object
102   /// \param theSketch a current sketch
103   /// \param theFeature a current feature
104   /// \param theWorkshop a current workshop
105   void removeExternalObject(const ObjectPtr& theObject,
106                             const CompositeFeaturePtr& theSketch,
107                             const FeaturePtr& theFeature,
108                             ModuleBase_IWorkshop* theWorkshop);
109
110   /// Returns the workshop
111   static XGUI_Workshop* workshop(ModuleBase_IWorkshop* theWorkshop);
112
113 protected:
114   /// An external object
115   ObjectPtr myExternalObjectValidated;
116
117   /// Boolean value about the neccessity of the external object use
118   bool myUseExternal;
119   /// Boolean value about the necessity of a new external object creation
120   bool myCanCreateExternal;
121 };
122
123 #endif