Attacher: make positionBySupport return if attached or not

Needed as reliable way of testing if attachment is working or not.
This commit is contained in:
DeepSOIC 2016-05-06 00:29:03 +03:00 committed by wmayer
parent 2f6aaf3742
commit 651be3dcd1
4 changed files with 19 additions and 12 deletions

View File

@ -70,15 +70,17 @@ void AttachableObject::setAttacher(AttachEngine* attacher)
updateAttacherVals();
}
void AttachableObject::positionBySupport()
bool AttachableObject::positionBySupport()
{
if (!_attacher)
throw Base::Exception("AttachableObject: can't positionBySupport, because no AttachEngine is set.");
updateAttacherVals();
try{
this->Placement.setValue(_attacher->calculateAttachedPlacement(this->Placement.getValue()));
return true;
} catch (ExceptionCancel) {
//disabled, don't do anything
return false;
};
}
@ -107,6 +109,7 @@ void setReadonlyness(App::Property &prop, bool on)
void AttachableObject::onChanged(const App::Property* prop)
{
if(! this->isRestoring()){
bool bAttached = false;
try{
if ((prop == &Support
|| prop == &MapMode
@ -114,11 +117,7 @@ void AttachableObject::onChanged(const App::Property* prop)
|| prop == &MapReversed
|| prop == &superPlacement)){
eMapMode mmode = eMapMode(this->MapMode.getValue());
setReadonlyness(this->superPlacement, mmode == mmDeactivated);
setReadonlyness(this->Placement, mmode != mmDeactivated && mmode != mmTranslate);
positionBySupport();
bAttached = positionBySupport();
}
} catch (Base::Exception &e) {
this->setError();
@ -128,6 +127,11 @@ void AttachableObject::onChanged(const App::Property* prop)
this->setError();
Base::Console().Error("PositionBySupport: %s",e.GetMessageString());
}
eMapMode mmode = eMapMode(this->MapMode.getValue());
setReadonlyness(this->superPlacement, !bAttached);
setReadonlyness(this->Placement, bAttached && mmode != mmTranslate); //for mmTranslate, orientation should remain editable even when attached.
}
Part::Feature::onChanged(prop);
}

View File

@ -84,9 +84,10 @@ public:
App::PropertyFloat MapPathParameter;
/** calculate and update the Placement property based on the Support, and
* mode. Can throw FreeCAD and OCC exceptions.
* mode. Can throw FreeCAD and OCC exceptions. Returns true if attached,
* false if not, throws if attachment failed.
*/
virtual void positionBySupport(void);
virtual bool positionBySupport(void);
virtual bool isTouched_Mapping()
{return true; /*support.isTouched isn't true when linked objects are changed... why?..*/};

View File

@ -15,7 +15,9 @@
</Documentation>
<Methode Name="positionBySupport">
<Documentation>
<UserDocu>Reposition object based on Support, MapMode and MapPathParameter properties.</UserDocu>
<UserDocu>positionBySupport(): Reposition object based on Support, MapMode and MapPathParameter properties.
Returns True if attachment calculation was successful, false if object is not attached and Placement wasn't updated,
and raises an exception if attachment calculation fails.</UserDocu>
</Documentation>
</Methode>
</PythonExport>

View File

@ -20,8 +20,9 @@ PyObject* Part2DObjectPy::positionBySupport(PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
return 0;
bool bAttached = false;
try{
this->getPart2DObjectPtr()->positionBySupport();
bAttached = this->getPart2DObjectPtr()->positionBySupport();
} catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
PyErr_SetString(PartExceptionOCCError, e->GetMessageString());
@ -30,8 +31,7 @@ PyObject* Part2DObjectPy::positionBySupport(PyObject *args)
PyErr_SetString(Base::BaseExceptionFreeCADError, e.what());
return NULL;
}
Py_INCREF(Py_None);
return Py_None;
return Py::new_reference_to(Py::Boolean(bAttached));
}