FreeCAD

Форк
0
/
BodyBase.cpp 
124 строки · 4.6 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2010 Juergen 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 <App/Document.h>
26

27
#include "BodyBase.h"
28
#include "BodyBasePy.h"
29

30

31
namespace Part {
32

33
PROPERTY_SOURCE_WITH_EXTENSIONS(Part::BodyBase, Part::Feature)
34

35
BodyBase::BodyBase()
36
{
37
    ADD_PROPERTY(Tip         , (nullptr) );
38
    Tip.setScope(App::LinkScope::Child);
39

40
    ADD_PROPERTY(BaseFeature , (nullptr) );
41

42
    App::OriginGroupExtension::initExtension(this);
43
}
44

45
BodyBase* BodyBase::findBodyOf(const App::DocumentObject* f)
46
{
47
    App::Document* doc = f->getDocument();
48
    if (doc) {
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))
53
                return body;
54
        }
55
    }
56

57
    return nullptr;
58
}
59

60
bool BodyBase::isAfter(const App::DocumentObject *feature, const App::DocumentObject* target) const {
61
    assert (feature);
62

63
    if (feature == target) {
64
        return false;
65
    }
66

67
    if (!target || target == BaseFeature.getValue() ) {
68
        return hasObject (feature);
69
    }
70

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);
74

75
    if (featureIt == features.end()) {
76
        return false;
77
    } else {
78
        return featureIt > targetIt;
79
    }
80
}
81

82
void BodyBase::onBeforeChange (const App::Property* prop) {
83

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 );
88
    }*/
89
    Part::Feature::onBeforeChange ( prop );
90
}
91

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 () );
97
    }*/
98
    Part::Feature::onChanged ( prop );
99
}
100

101
void BodyBase::handleChangedPropertyName(Base::XMLReader &reader,
102
                                         const char * TypeName,
103
                                         const char *PropName)
104
{
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);
109
    }
110
    else {
111
        Part::Feature::handleChangedPropertyName(reader, TypeName, PropName);
112
    }
113
}
114

115
PyObject* BodyBase::getPyObject()
116
{
117
    if (PythonObject.is(Py::_None())){
118
        // ref counter is set to 1
119
        PythonObject = Py::Object(new BodyBasePy(this),true);
120
    }
121
    return Py::new_reference_to(PythonObject);
122
}
123

124
} /* Part */
125

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

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

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

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