1
/***************************************************************************
2
* Copyright (c) 2014 Jürgen Riegel <juergen.riegel@web.de> *
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
***************************************************************************/
24
#include "PreCompiled.h"
26
#include <App/DocumentObject.h>
35
PROPERTY_SOURCE_WITH_EXTENSIONS(App::Part, App::GeoFeature)
38
//===========================================================================
40
//===========================================================================
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");
49
// create the uuid for the document
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");
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
60
GroupExtension::initExtension(this);
63
Part::~Part() = default;
65
static App::Part *_getPartOfObject(const DocumentObject *obj,
66
std::set<const DocumentObject*> *objset)
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
72
for (auto inObj : obj->getInList()) {
73
if (objset && !objset->insert(inObj).second)
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);
80
return _getPartOfObject(inObj, objset);
81
// Only one parent geofeature group per object, so break
89
App::Part *Part::getPartOfObject (const DocumentObject* obj, bool recursive) {
91
return _getPartOfObject(obj, nullptr);
92
std::set<const DocumentObject *> objset;
94
return _getPartOfObject(obj, &objset);
98
PyObject *Part::getPyObject()
100
if (PythonObject.is(Py::_None())){
101
// ref counter is set to 1
102
PythonObject = Py::Object(new PartPy(this),true);
104
return Py::new_reference_to(PythonObject);
107
void Part::handleChangedPropertyType(Base::XMLReader &reader, const char *TypeName, App::Property *prop)
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());
118
App::GeoFeature::handleChangedPropertyType(reader, TypeName, prop);
122
// Python feature ---------------------------------------------------------
124
// Not quite sure yet making Part derivable in Python is good Idea!
129
//PROPERTY_SOURCE_TEMPLATE(App::PartPython, App::Part)
130
//template<> const char* App::PartPython::getViewProviderName(void) const {
131
// return "Gui::ViewProviderPartPython";
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);
138
// return Py::new_reference_to(PythonObject);
142
//// explicit template instantiation
143
//template class AppExport FeaturePythonT<App::Part>;