1
/***************************************************************************
2
* Copyright (c) 2002 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/GeoFeaturePy.h>
28
#include "ComplexGeoData.h"
29
#include "GeoFeature.h"
30
#include "GeoFeatureGroupExtension.h"
31
#include "ElementNamingUtils.h"
37
PROPERTY_SOURCE(App::GeoFeature, App::DocumentObject)
40
//===========================================================================
42
//===========================================================================
44
GeoFeature::GeoFeature()
46
ADD_PROPERTY_TYPE(Placement,(Base::Placement()),nullptr,Prop_NoRecompute,nullptr);
49
GeoFeature::~GeoFeature() = default;
51
void GeoFeature::transformPlacement(const Base::Placement &transform)
53
Base::Placement plm = this->Placement.getValue();
54
plm = transform * plm;
55
this->Placement.setValue(plm);
58
Base::Placement GeoFeature::globalPlacement() const
60
auto* group = GeoFeatureGroupExtension::getGroupOfObject(this);
62
auto ext = group->getExtensionByType<GeoFeatureGroupExtension>();
63
return ext->globalGroupPlacement() * Placement.getValue();
65
return Placement.getValue();
68
const PropertyComplexGeoData* GeoFeature::getPropertyOfGeometry() const
73
PyObject* GeoFeature::getPyObject()
75
if (PythonObject.is(Py::_None())) {
76
// ref counter is set to 1
77
PythonObject = Py::Object(new GeoFeaturePy(this),true);
79
return Py::new_reference_to(PythonObject);
82
std::pair<std::string,std::string>
83
GeoFeature::getElementName(const char *name, ElementNameType type) const
87
std::pair<std::string,std::string> ret;
90
auto prop = getPropertyOfGeometry();
92
return std::make_pair("", name);
95
auto geo = prop->getComplexData();
97
return std::make_pair("", name);
100
return _getElementName(name, geo->getElementName(name));
103
std::pair<std::string, std::string>
104
GeoFeature::_getElementName(const char* name, const Data::MappedElement& mapped) const
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);
113
else if (mapped.name) {
114
// FC_TRACE("element mapped name " << name << " not found in " << getFullName());
116
const char* dot = strrchr(name, '.');
118
// deliberately mangle the old style element name to signal a
120
ret.second = Data::MISSING_PREFIX;
121
ret.second += dot + 1;
125
mapped.index.appendToStringBuffer(ret.second);
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)
136
if(!obj || !obj->isAttachedToDocument())
140
const char *element = Data::findElementName(subname);
141
if(_element) *_element = element;
142
auto sobj = obj->getSubObject(subname);
145
obj = sobj->getLinkedObject(true);
146
auto geo = dynamic_cast<GeoFeature*>(obj);
149
if(!obj || (filter && obj!=filter))
151
if(!element || !element[0]) {
153
elementName.second = Data::oldElementName(subname);
157
if(!geo || hasHiddenMarker(element)) {
159
elementName.second = element;
161
elementName.second = Data::oldElementName(subname);
165
elementName = geo->getElementName(element,type);
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;