FreeCAD

Форк
0
/
SelectionObject.cpp 
104 строки · 3.8 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2009 Jürgen Riegel <FreeCAD@juergen-riegel.net>         *
3
 *                                                                         *
4
 *   This file is part of the FreeCAD CAx development system.              *
5
 *                                                                         *
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.      *
10
 *                                                                         *
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.                  *
15
 *                                                                         *
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                                *
20
 *                                                                         *
21
 ***************************************************************************/
22

23
#include "PreCompiled.h"
24

25
#include <sstream>
26

27
#include <App/Application.h>
28
#include <App/Document.h>
29
#include <App/DocumentObject.h>
30
#include <Gui/SelectionObjectPy.h>
31

32
#include "SelectionObject.h"
33
#include "Selection.h"
34
#include "Application.h"
35
#include "Command.h"
36

37

38
using namespace Gui;
39

40

41
TYPESYSTEM_SOURCE_ABSTRACT(Gui::SelectionObject, Base::BaseClass)
42

43
SelectionObject::SelectionObject() = default;
44

45
SelectionObject::SelectionObject(const Gui::SelectionChanges& msg)
46
{
47
    FeatName = msg.pObjectName ? msg.pObjectName : "";
48
    DocName = msg.pDocName ? msg.pDocName : "";
49
    TypeName = msg.pTypeName ? msg.pTypeName : "";
50
    if (msg.pSubName) {
51
        SubNames.emplace_back(msg.pSubName);
52
        SelPoses.emplace_back(msg.x, msg.y, msg.z);
53
    }
54
}
55

56
SelectionObject::SelectionObject(const App::DocumentObject* obj)
57
{
58
    FeatName = obj->getNameInDocument();
59
    DocName = obj->getDocument()->getName();
60
    TypeName = obj->getTypeId().getName();
61
}
62

63
SelectionObject::~SelectionObject() = default;
64

65
const App::DocumentObject * SelectionObject::getObject() const
66
{
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());
71
    }
72
    return nullptr;
73
}
74

75
App::DocumentObject * SelectionObject::getObject()
76
{
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());
81
    }
82
    return nullptr;
83
}
84

85
bool SelectionObject::isObjectTypeOf(const Base::Type& typeId) const
86
{
87
    const App::DocumentObject* obj = getObject();
88
    return (obj && obj->getTypeId().isDerivedFrom(typeId));
89
}
90

91
std::string SelectionObject::getAsPropertyLinkSubString()const
92
{
93
    std::ostringstream str;
94
    str << "(" << Gui::Command::getObjectCmd(getObject()) << ",[";
95
    for(const auto & it : SubNames)
96
        str << "'" << it << "',";
97
    str << "])";
98
    return str.str();
99
}
100

101
PyObject* SelectionObject::getPyObject()
102
{
103
    return new SelectionObjectPy(new SelectionObject(*this));
104
}
105

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.