Skip to content

Commit

Permalink
App: implement the private class OriginExtension to simulate a geomet…
Browse files Browse the repository at this point in the history
…ric group behaviour
  • Loading branch information
wwmayer committed Jun 5, 2020
1 parent db74aa8 commit 229e8dd
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/App/Origin.cpp
Expand Up @@ -48,11 +48,12 @@ PROPERTY_SOURCE(App::Origin, App::DocumentObject)
const char* Origin::AxisRoles[3] = {"X_Axis", "Y_Axis", "Z_Axis"};
const char* Origin::PlaneRoles[3] = {"XY_Plane", "XZ_Plane", "YZ_Plane"};

Origin::Origin(void) {
Origin::Origin(void) : extension(this) {
ADD_PROPERTY_TYPE ( OriginFeatures, (0), 0, App::Prop_Hidden,
"Axis and baseplanes controlled by the origin" );

setStatus(App::NoAutoExpand,true);
extension.GroupExtension::initExtension(this);
}


Expand Down Expand Up @@ -182,3 +183,31 @@ void Origin::unsetupObject () {
}
}
}

// ----------------------------------------------------------------------------

Origin::OriginExtension::OriginExtension(Origin* obj)
: obj(obj)
{
Group.setStatus(Property::Transient, true);
}

void Origin::OriginExtension::initExtension(ExtensionContainer* obj) {
App::GroupExtension::initExtension(obj);
}

bool Origin::OriginExtension::extensionGetSubObject(DocumentObject *&ret, const char *subname,
PyObject **, Base::Matrix4D *, bool, int) const {
const char* dot;
if (!subname || subname[0] == '\0') {
return false;
}

std::string name(subname);
if ((dot=strchr(subname,'.'))) {
name = std::string(subname,dot);
}

ret = obj->getOriginFeature(name.c_str());
return true;
}
10 changes: 10 additions & 0 deletions src/App/Origin.h
Expand Up @@ -28,6 +28,7 @@
#include "GeoFeature.h"

#include "OriginFeature.h"
#include "GeoFeatureGroupExtension.h"
#include "PropertyLinks.h"

namespace App
Expand Down Expand Up @@ -135,6 +136,15 @@ class AppExport Origin : public App::DocumentObject
struct SetupData;
void setupOriginFeature (App::PropertyLink &featProp, const SetupData &data);

class OriginExtension : public GeoFeatureGroupExtension {
Origin* obj;
public:
OriginExtension(Origin* obj);
void initExtension(ExtensionContainer* obj);
bool extensionGetSubObject(DocumentObject *&ret, const char *subname,
PyObject **, Base::Matrix4D *, bool, int) const;
};
OriginExtension extension;
};

} //namespace App
Expand Down

1 comment on commit 229e8dd

@realthunder
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wwmayer Can you please explain the purpose of adding GeoFeatureGroupExtension to Origin this way? It's quite unnatural, and will cause error when opening new file in older FreeCAD. Although forward compatibility is not a first priority, it shouldn't be broken so easily. I see you made a follow up commit to bypass ExtensionContainer::Save(), which can solve the error reporting (although it's kinda unnatural as well), but you reverted it somehow? The point is, I can't see the reason why you need GeoFeatureGroupExtension here.

Please sign in to comment.