| 1 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 2 |
/*************************************************************************** |
| 3 |
* Copyright (c) 2009 Jürgen Riegel <[email protected]> * |
| 4 |
* * |
| 5 |
* This file is part of the FreeCAD CAx development system. * |
| 6 |
* * |
| 7 |
* This library is free software; you can redistribute it and/or * |
| 8 |
* modify it under the terms of the GNU Library General Public * |
| 9 |
* License as published by the Free Software Foundation; either * |
| 10 |
* version 2 of the License, or (at your option) any later version. * |
| 11 |
* * |
| 12 |
* This library is distributed in the hope that it will be useful, * |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 15 |
* GNU Library General Public License for more details. * |
| 16 |
* * |
| 17 |
* You should have received a copy of the GNU Library General Public * |
| 18 |
* License along with this library; see the file COPYING.LIB. If not, * |
| 19 |
* write to the Free Software Foundation, Inc., 59 Temple Place, * |
| 20 |
* Suite 330, Boston, MA 02111-1307, USA * |
| 21 |
* * |
| 22 |
***************************************************************************/ |
| 23 |
|
| 24 |
|
| 25 |
#ifndef GUI_SelectionObject_H |
| 26 |
#define GUI_SelectionObject_H |
| 27 |
|
| 28 |
#include <Base/BaseClass.h> |
| 29 |
#include <Base/Vector3D.h> |
| 30 |
#include <FCGlobal.h> |
| 31 |
#include <string> |
| 32 |
|
| 33 |
namespace App |
| 34 |
{ |
| 35 |
class DocumentObject; |
| 36 |
} |
| 37 |
|
| 38 |
namespace Gui |
| 39 |
{ |
| 40 |
|
| 41 |
class SelectionChanges; |
| 42 |
|
| 43 |
/** |
| 44 |
* The Selection object class |
| 45 |
*/ |
| 46 |
class GuiExport SelectionObject: public Base::BaseClass |
| 47 |
{ |
| 48 |
TYPESYSTEM_HEADER_WITH_OVERRIDE(); |
| 49 |
|
| 50 |
public: |
| 51 |
/** Constructs a SelectionObject object. */ |
| 52 |
SelectionObject(); |
| 53 |
/*! Constructs a SelectionObject from the SelectionChanges structure. |
| 54 |
*/ |
| 55 |
explicit SelectionObject(const SelectionChanges& msg); |
| 56 |
explicit SelectionObject(const App::DocumentObject*); |
| 57 |
~SelectionObject() override; |
| 58 |
/** |
| 59 |
* The default implementation returns an instance of @ref SelectionObjectPy. |
| 60 |
*/ |
| 61 |
PyObject* getPyObject() override; |
| 62 |
|
| 63 |
/// get the SubElement name of this SelectionObject |
| 64 |
inline const std::vector<std::string>& getSubNames() const |
| 65 |
{ |
| 66 |
return SubNames; |
| 67 |
} |
| 68 |
/// are there any SubNames selected |
| 69 |
bool hasSubNames() const |
| 70 |
{ |
| 71 |
return !SubNames.empty(); |
| 72 |
} |
| 73 |
/// get the name of the Document of this SelctionObject |
| 74 |
inline const char* getDocName() const |
| 75 |
{ |
| 76 |
return DocName.c_str(); |
| 77 |
} |
| 78 |
/// get the name of the Document Object of this SelectionObject |
| 79 |
inline const char* getFeatName() const |
| 80 |
{ |
| 81 |
return FeatName.c_str(); |
| 82 |
} |
| 83 |
/// get the Type of the selected Object |
| 84 |
inline const char* getTypeName() const |
| 85 |
{ |
| 86 |
return TypeName.c_str(); |
| 87 |
} |
| 88 |
/// get the selection points |
| 89 |
inline const std::vector<Base::Vector3d> getPickedPoints() const |
| 90 |
{ |
| 91 |
return SelPoses; |
| 92 |
} |
| 93 |
|
| 94 |
/// returns the selected DocumentObject or NULL if the object is already deleted |
| 95 |
const App::DocumentObject* getObject() const; |
| 96 |
/// returns the selected DocumentObject or NULL if the object is already deleted |
| 97 |
template<class T> |
| 98 |
const T* getObject() const |
| 99 |
{ |
| 100 |
return freecad_cast<T*>(getObject()); |
| 101 |
}; |
| 102 |
/// returns the selected DocumentObject or NULL if the object is already deleted |
| 103 |
App::DocumentObject* getObject(); |
| 104 |
/// returns the selected DocumentObject if it is of T type or null otherwise |
| 105 |
template<class T> |
| 106 |
T* getObject() |
| 107 |
{ |
| 108 |
return freecad_cast<T*>(getObject()); |
| 109 |
} |
| 110 |
|
| 111 |
/// check the selected object is a special type or derived of |
| 112 |
bool isObjectTypeOf(const Base::Type& typeId) const; |
| 113 |
|
| 114 |
/// returns python expreasion sutably for assigning to a LinkSub property |
| 115 |
std::string getAsPropertyLinkSubString() const; |
| 116 |
|
| 117 |
friend class SelectionSingleton; |
| 118 |
|
| 119 |
protected: |
| 120 |
std::vector<std::string> SubNames; |
| 121 |
std::string DocName; |
| 122 |
std::string FeatName; |
| 123 |
std::string TypeName; |
| 124 |
std::vector<Base::Vector3d> SelPoses; |
| 125 |
|
| 126 |
private: |
| 127 |
/// to make sure no duplicates of subnames |
| 128 |
std::set<std::string> _SubNameSet; |
| 129 |
}; |
| 130 |
|
| 131 |
|
| 132 |
} // namespace Gui |
| 133 |
|
| 134 |
|
| 135 |
#endif // GUI_SelectionObject_H |