FreeCAD

Форк
0
/
Part.cpp 
144 строки · 5.6 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2014 Jürgen Riegel <juergen.riegel@web.de>              *
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

24
#include "PreCompiled.h"
25

26
#include <App/DocumentObject.h>
27

28
#include "Part.h"
29
#include "PartPy.h"
30

31

32
using namespace App;
33

34

35
PROPERTY_SOURCE_WITH_EXTENSIONS(App::Part, App::GeoFeature)
36

37

38
//===========================================================================
39
// Part
40
//===========================================================================
41

42

43
Part::Part()
44
{
45
    ADD_PROPERTY(Type,(""));
46
    ADD_PROPERTY_TYPE(Material, (nullptr), 0, App::Prop_None, "The Material for this Part");
47
    ADD_PROPERTY_TYPE(Meta, (), 0, App::Prop_None, "Map with additional meta information");
48

49
    // create the uuid for the document
50
    Base::Uuid id;
51
    ADD_PROPERTY_TYPE(Id, (""), 0, App::Prop_None, "ID (Part-Number) of the Item");
52
    ADD_PROPERTY_TYPE(Uid, (id), 0, App::Prop_None, "UUID of the Item");
53

54
    // license stuff (leave them empty to avoid confusion with imported 3rd party STEP/IGES files)
55
    ADD_PROPERTY_TYPE(License, (""), 0, App::Prop_None, "License string of the Item");
56
    ADD_PROPERTY_TYPE(LicenseURL, (""), 0, App::Prop_None, "URL to the license text/contract");
57
    // color and appearance
58
    ADD_PROPERTY(Color, (1.0, 1.0, 1.0, 1.0)); // set transparent -> not used
59

60
    GroupExtension::initExtension(this);
61
}
62

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

65
static App::Part *_getPartOfObject(const DocumentObject *obj,
66
                                   std::set<const DocumentObject*> *objset)
67
{
68
    // as a Part is a geofeaturegroup it must directly link to all
69
    // objects it contains, even if they are in additional groups etc.
70
    // But we still must call 'hasObject()' to exclude link brought in by
71
    // expressions.
72
    for (auto inObj : obj->getInList()) {
73
        if (objset && !objset->insert(inObj).second)
74
            continue;
75
        auto group = inObj->getExtensionByType<GeoFeatureGroupExtension>(true);
76
        if(group && group->hasObject(obj)) {
77
            if(inObj->isDerivedFrom(App::Part::getClassTypeId()))
78
                return static_cast<App::Part*>(inObj);
79
            else if (objset)
80
                return _getPartOfObject(inObj, objset);
81
            // Only one parent geofeature group per object, so break
82
            break;
83
        }
84
    }
85

86
    return nullptr;
87
}
88

89
App::Part *Part::getPartOfObject (const DocumentObject* obj, bool recursive) {
90
    if (!recursive)
91
        return _getPartOfObject(obj, nullptr);
92
    std::set<const DocumentObject *> objset;
93
    objset.insert(obj);
94
    return _getPartOfObject(obj, &objset);
95
}
96

97

98
PyObject *Part::getPyObject()
99
{
100
    if (PythonObject.is(Py::_None())){
101
        // ref counter is set to 1
102
        PythonObject = Py::Object(new PartPy(this),true);
103
    }
104
    return Py::new_reference_to(PythonObject);
105
}
106

107
void Part::handleChangedPropertyType(Base::XMLReader &reader, const char *TypeName, App::Property *prop)
108
{
109
    // Migrate Material from App::PropertyMap to App::PropertyLink
110
    if (!strcmp(TypeName, "App::PropertyMap")) {
111
        App::PropertyMap oldvalue;
112
        oldvalue.Restore(reader);
113
        if (oldvalue.getSize()) {
114
            auto oldprop = static_cast<App::PropertyMap*>(addDynamicProperty("App::PropertyMap", "Material_old", "Base"));
115
            oldprop->setValues(oldvalue.getValues());
116
        }
117
    } else {
118
        App::GeoFeature::handleChangedPropertyType(reader, TypeName, prop);
119
    }
120
}
121

122
// Python feature ---------------------------------------------------------
123

124
// Not quite sure yet making Part derivable in Python is good Idea!
125
// JR 2014
126

127
//namespace App {
128
///// @cond DOXERR
129
//PROPERTY_SOURCE_TEMPLATE(App::PartPython, App::Part)
130
//template<> const char* App::PartPython::getViewProviderName(void) const {
131
//    return "Gui::ViewProviderPartPython";
132
//}
133
//template<> PyObject* App::PartPython::getPyObject(void) {
134
//    if (PythonObject.is(Py::_None())) {
135
//        // ref counter is set to 1
136
//        PythonObject = Py::Object(new FeaturePythonPyT<App::PartPy>(this),true);
137
//    }
138
//    return Py::new_reference_to(PythonObject);
139
//}
140
///// @endcond
141
//
142
//// explicit template instantiation
143
//template class AppExport FeaturePythonT<App::Part>;
144
//}
145

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

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

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

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