FreeCAD

Форк
0
/
GeoFeature.cpp 
174 строки · 6.0 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2002 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/GeoFeaturePy.h>
27

28
#include "ComplexGeoData.h"
29
#include "GeoFeature.h"
30
#include "GeoFeatureGroupExtension.h"
31
#include "ElementNamingUtils.h"
32

33

34
using namespace App;
35

36

37
PROPERTY_SOURCE(App::GeoFeature, App::DocumentObject)
38

39

40
//===========================================================================
41
// Feature
42
//===========================================================================
43

44
GeoFeature::GeoFeature()
45
{
46
    ADD_PROPERTY_TYPE(Placement,(Base::Placement()),nullptr,Prop_NoRecompute,nullptr);
47
}
48

49
GeoFeature::~GeoFeature() = default;
50

51
void GeoFeature::transformPlacement(const Base::Placement &transform)
52
{
53
    Base::Placement plm = this->Placement.getValue();
54
    plm = transform * plm;
55
    this->Placement.setValue(plm);
56
}
57

58
Base::Placement GeoFeature::globalPlacement() const
59
{
60
    auto* group = GeoFeatureGroupExtension::getGroupOfObject(this);
61
    if (group) {
62
        auto ext = group->getExtensionByType<GeoFeatureGroupExtension>();
63
        return ext->globalGroupPlacement() * Placement.getValue();
64
    }
65
    return Placement.getValue();    
66
}
67

68
const PropertyComplexGeoData* GeoFeature::getPropertyOfGeometry() const
69
{
70
    return nullptr;
71
}
72

73
PyObject* GeoFeature::getPyObject()
74
{
75
    if (PythonObject.is(Py::_None())) {
76
        // ref counter is set to 1
77
        PythonObject = Py::Object(new GeoFeaturePy(this),true);
78
    }
79
    return Py::new_reference_to(PythonObject);
80
}
81

82
std::pair<std::string,std::string>
83
GeoFeature::getElementName(const char *name, ElementNameType type) const
84
{
85
    (void)type;
86

87
    std::pair<std::string,std::string> ret;
88
    if(!name)
89
        return ret;
90
    auto prop = getPropertyOfGeometry();
91
    if (!prop) {
92
        return std::make_pair("", name);
93
    }
94

95
    auto geo = prop->getComplexData();
96
    if (!geo) {
97
        return std::make_pair("", name);
98
    }
99

100
    return _getElementName(name, geo->getElementName(name));
101
}
102

103
std::pair<std::string, std::string>
104
GeoFeature::_getElementName(const char* name, const Data::MappedElement& mapped) const
105
{
106
    std::pair<std::string, std::string> ret;
107
    if (mapped.index && mapped.name) {
108
        std::ostringstream ss;
109
        ss << Data::ComplexGeoData::elementMapPrefix() << mapped.name << '.' << mapped.index;
110
        ret.first = ss.str();
111
        mapped.index.appendToStringBuffer(ret.second);
112
    }
113
    else if (mapped.name) {
114
        //        FC_TRACE("element mapped name " << name << " not found in " << getFullName());
115
        ret.first = name;
116
        const char* dot = strrchr(name, '.');
117
        if (dot) {
118
            // deliberately mangle the old style element name to signal a
119
            // missing reference
120
            ret.second = Data::MISSING_PREFIX;
121
            ret.second += dot + 1;
122
        }
123
    }
124
    else {
125
        mapped.index.appendToStringBuffer(ret.second);
126
    }
127

128
    return ret;
129
}
130

131
DocumentObject *GeoFeature::resolveElement(DocumentObject *obj, const char *subname, 
132
        std::pair<std::string,std::string> &elementName, bool append, 
133
        ElementNameType type, const DocumentObject *filter, 
134
        const char **_element, GeoFeature **geoFeature)
135
{
136
    if(!obj || !obj->isAttachedToDocument())
137
        return nullptr;
138
    if(!subname)
139
        subname = "";
140
    const char *element = Data::findElementName(subname);
141
    if(_element) *_element = element;
142
    auto sobj = obj->getSubObject(subname);
143
    if(!sobj)
144
        return nullptr;
145
    obj = sobj->getLinkedObject(true);
146
    auto geo = dynamic_cast<GeoFeature*>(obj);
147
    if(geoFeature) 
148
        *geoFeature = geo;
149
    if(!obj || (filter && obj!=filter))
150
        return nullptr;
151
    if(!element || !element[0]) {
152
        if(append) 
153
            elementName.second = Data::oldElementName(subname);
154
        return sobj;
155
    }
156

157
    if(!geo || hasHiddenMarker(element)) {
158
        if(!append) 
159
            elementName.second = element;
160
        else
161
            elementName.second = Data::oldElementName(subname);
162
        return sobj;
163
    }
164
    if(!append) 
165
        elementName = geo->getElementName(element,type);
166
    else{
167
        const auto &names = geo->getElementName(element,type);
168
        std::string prefix(subname,element-subname);
169
        if(!names.first.empty())
170
            elementName.first = prefix + names.first;
171
        elementName.second = prefix + names.second;
172
    }
173
    return sobj;
174
}
175

176

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

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

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

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