1
/***************************************************************************
2
* Copyright (c) 2009 Jürgen Riegel <FreeCAD@juergen-riegel.net> *
4
* This file is part of the FreeCAD CAx development system. *
6
* This library is free software; you can redistribute it and/or *
7
* modify it under the terms of the GNU Library General Public *
8
* License as published by the Free Software Foundation; either *
9
* version 2 of the License, or (at your option) any later version. *
11
* This library is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU Library General Public License for more details. *
16
* You should have received a copy of the GNU Library General Public *
17
* License along with this library; see the file COPYING.LIB. If not, *
18
* write to the Free Software Foundation, Inc., 59 Temple Place, *
19
* Suite 330, Boston, MA 02111-1307, USA *
21
***************************************************************************/
23
#include "PreCompiled.h"
27
#include <App/Application.h>
28
#include <App/Document.h>
29
#include <App/DocumentObject.h>
30
#include <Gui/SelectionObjectPy.h>
32
#include "SelectionObject.h"
34
#include "Application.h"
41
TYPESYSTEM_SOURCE_ABSTRACT(Gui::SelectionObject, Base::BaseClass)
43
SelectionObject::SelectionObject() = default;
45
SelectionObject::SelectionObject(const Gui::SelectionChanges& msg)
47
FeatName = msg.pObjectName ? msg.pObjectName : "";
48
DocName = msg.pDocName ? msg.pDocName : "";
49
TypeName = msg.pTypeName ? msg.pTypeName : "";
51
SubNames.emplace_back(msg.pSubName);
52
SelPoses.emplace_back(msg.x, msg.y, msg.z);
56
SelectionObject::SelectionObject(const App::DocumentObject* obj)
58
FeatName = obj->getNameInDocument();
59
DocName = obj->getDocument()->getName();
60
TypeName = obj->getTypeId().getName();
63
SelectionObject::~SelectionObject() = default;
65
const App::DocumentObject * SelectionObject::getObject() const
67
if (!DocName.empty()) {
68
App::Document *doc = App::GetApplication().getDocument(DocName.c_str());
69
if (doc && !FeatName.empty())
70
return doc->getObject(FeatName.c_str());
75
App::DocumentObject * SelectionObject::getObject()
77
if (!DocName.empty()) {
78
App::Document *doc = App::GetApplication().getDocument(DocName.c_str());
79
if (doc && !FeatName.empty())
80
return doc->getObject(FeatName.c_str());
85
bool SelectionObject::isObjectTypeOf(const Base::Type& typeId) const
87
const App::DocumentObject* obj = getObject();
88
return (obj && obj->getTypeId().isDerivedFrom(typeId));
91
std::string SelectionObject::getAsPropertyLinkSubString()const
93
std::ostringstream str;
94
str << "(" << Gui::Command::getObjectCmd(getObject()) << ",[";
95
for(const auto & it : SubNames)
96
str << "'" << it << "',";
101
PyObject* SelectionObject::getPyObject()
103
return new SelectionObjectPy(new SelectionObject(*this));