Attacher: Py: add interface for changing attacher type
Plus a mechanism to remember attacher type of AttachableObject through save-restore cycle.
This commit is contained in:
@@ -42,6 +42,9 @@ PROPERTY_SOURCE(Part::AttachableObject, Part::Feature);
|
||||
AttachableObject::AttachableObject()
|
||||
: _attacher(0)
|
||||
{
|
||||
ADD_PROPERTY_TYPE(AttacherType, ("Attacher::AttachEngine3D"), "Attachment",(App::PropertyType)(App::Prop_None),"Class name of attach engine object driving the attachment.");
|
||||
this->AttacherType.setStatus(App::Property::Status::Hidden, true);
|
||||
|
||||
ADD_PROPERTY_TYPE(Support, (0,0), "Attachment",(App::PropertyType)(App::Prop_None),"Support of the 2D geometry");
|
||||
|
||||
ADD_PROPERTY_TYPE(MapMode, (mmDeactivated), "Attachment", App::Prop_None, "Mode of attachment to other object");
|
||||
@@ -69,7 +72,44 @@ void AttachableObject::setAttacher(AttachEngine* attacher)
|
||||
if (_attacher)
|
||||
delete _attacher;
|
||||
_attacher = attacher;
|
||||
updateAttacherVals();
|
||||
if (_attacher){
|
||||
const char* typeName = attacher->getTypeId().getName();
|
||||
if(strcmp(this->AttacherType.getValue(),typeName)!=0) //make sure we need to change, to break recursive onChange->changeAttacherType->onChange...
|
||||
this->AttacherType.setValue(typeName);
|
||||
updateAttacherVals();
|
||||
} else {
|
||||
if (strlen(AttacherType.getValue()) != 0){ //make sure we need to change, to break recursive onChange->changeAttacherType->onChange...
|
||||
this->AttacherType.setValue("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool AttachableObject::changeAttacherType(const char* typeName)
|
||||
{
|
||||
//check if we need to actually change anything
|
||||
if (_attacher){
|
||||
if (strcmp(_attacher->getTypeId().getName(),typeName)==0){
|
||||
return false;
|
||||
}
|
||||
} else if (strlen(typeName) == 0){
|
||||
return false;
|
||||
}
|
||||
if (strlen(typeName) == 0){
|
||||
setAttacher(nullptr);
|
||||
return true;
|
||||
}
|
||||
Base::Type t = Base::Type::fromName(typeName);
|
||||
if (t.isDerivedFrom(AttachEngine::getClassTypeId())){
|
||||
AttachEngine* pNewAttacher = static_cast<Attacher::AttachEngine*>(Base::Type::createInstanceByName(typeName));
|
||||
this->setAttacher(pNewAttacher);
|
||||
return true;
|
||||
} else {
|
||||
std::stringstream errMsg;
|
||||
errMsg << "Object if this type is not derived from AttachEngine: " << typeName;
|
||||
throw Base::Exception(errMsg.str());
|
||||
}
|
||||
assert(false);//exec shouldn't ever get here
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AttachableObject::positionBySupport()
|
||||
@@ -138,6 +178,10 @@ void AttachableObject::onChanged(const App::Property* prop)
|
||||
|
||||
}
|
||||
|
||||
if(prop == &(this->AttacherType)){
|
||||
this->changeAttacherType(this->AttacherType.getValue());
|
||||
}
|
||||
|
||||
Part::Feature::onChanged(prop);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user