1
/***************************************************************************
2
* Copyright (c) 2010 Juergen 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"
25
#include <App/Document.h>
28
#include "BodyBasePy.h"
33
PROPERTY_SOURCE_WITH_EXTENSIONS(Part::BodyBase, Part::Feature)
37
ADD_PROPERTY(Tip , (nullptr) );
38
Tip.setScope(App::LinkScope::Child);
40
ADD_PROPERTY(BaseFeature , (nullptr) );
42
App::OriginGroupExtension::initExtension(this);
45
BodyBase* BodyBase::findBodyOf(const App::DocumentObject* f)
47
App::Document* doc = f->getDocument();
49
std::vector<App::DocumentObject*> bodies = doc->getObjectsOfType(BodyBase::getClassTypeId());
50
for (auto it : bodies) {
51
BodyBase* body = static_cast<BodyBase*>(it);
52
if (body->hasObject(f))
60
bool BodyBase::isAfter(const App::DocumentObject *feature, const App::DocumentObject* target) const {
63
if (feature == target) {
67
if (!target || target == BaseFeature.getValue() ) {
68
return hasObject (feature);
71
const std::vector<App::DocumentObject *> & features = Group.getValues();
72
auto featureIt = std::find(features.begin(), features.end(), feature);
73
auto targetIt = std::find(features.begin(), features.end(), target);
75
if (featureIt == features.end()) {
78
return featureIt > targetIt;
82
void BodyBase::onBeforeChange (const App::Property* prop) {
84
//Tip can't point outside the body, hence no base feature tip
85
/*// If we are changing the base feature and tip point to it reset it
86
if ( prop == &BaseFeature && BaseFeature.getValue() == Tip.getValue() && BaseFeature.getValue() ) {
87
Tip.setValue( nullptr );
89
Part::Feature::onBeforeChange ( prop );
92
void BodyBase::onChanged (const App::Property* prop) {
93
//Tip can't point outside the body, hence no base feature tip
94
/*// If the tip is zero and we are adding a base feature to the body set it to be the tip
95
if ( prop == &BaseFeature && !Tip.getValue() && BaseFeature.getValue() ) {
96
Tip.setValue( BaseFeature.getValue () );
98
Part::Feature::onChanged ( prop );
101
void BodyBase::handleChangedPropertyName(Base::XMLReader &reader,
102
const char * TypeName,
103
const char *PropName)
105
// The App::PropertyLinkList property was Model in the past (#0002642)
106
Base::Type type = Base::Type::fromName(TypeName);
107
if (Group.getClassTypeId() == type && strcmp(PropName, "Model") == 0) {
108
Group.Restore(reader);
111
Part::Feature::handleChangedPropertyName(reader, TypeName, PropName);
115
PyObject* BodyBase::getPyObject()
117
if (PythonObject.is(Py::_None())){
118
// ref counter is set to 1
119
PythonObject = Py::Object(new BodyBasePy(this),true);
121
return Py::new_reference_to(PythonObject);