Allow ProgGroup Item AutoPosition from Python

This commit is contained in:
WandererFan
2018-02-09 12:04:09 -05:00
committed by wmayer
parent 1909466241
commit 4f291f7305
9 changed files with 70 additions and 27 deletions

View File

@@ -174,6 +174,11 @@ App::DocumentObjectExecReturn *DrawProjGroup::execute(void)
updateChildren();
}
for (auto& item: getViewsAsDPGI()) {
item->autoPosition();
item->purgeTouched();
}
if (page != nullptr) {
page->requestPaint();
}
@@ -697,7 +702,9 @@ void DrawProjGroup::makeViewBbs(DrawProjGroupItem *viewPtrs[10],
}
}
//! tell children DPGIs that parent DPG has changed ?Scale?
/*!
* tell children DPGIs that parent DPG has changed ?Scale?
*/
void DrawProjGroup::updateChildren(void)
{
for( const auto it : Views.getValues() ) {
@@ -709,7 +716,9 @@ void DrawProjGroup::updateChildren(void)
}
}
//!check if ProjectionGroup fits on Page
/*!
* check if ProjectionGroup fits on Page
*/
bool DrawProjGroup::checkFit(TechDraw::DrawPage* p) const
{
bool result = true;
@@ -915,7 +924,20 @@ void DrawProjGroup::spinCCW()
}
//dumps the current iso DPGI's
std::vector<DrawProjGroupItem*> DrawProjGroup::getViewsAsDPGI()
{
std::vector<DrawProjGroupItem*> result;
auto views = Views.getValues();
for (auto& v:views) {
DrawProjGroupItem* item = static_cast<DrawProjGroupItem*>(v);
result.push_back(item);
}
return result;
}
/*!
*dumps the current iso DPGI's
*/
void DrawProjGroup::dumpISO(char * title)
{
Base::Console().Message("DPG ISO: %s\n", title);

View File

@@ -128,6 +128,7 @@ public:
void spinCCW(void);
void dumpISO(char * title);
std::vector<DrawProjGroupItem*> getViewsAsDPGI();
protected:
void onChanged(const App::Property* prop) override;

View File

@@ -99,17 +99,23 @@ App::DocumentObjectExecReturn *DrawProjGroupItem::execute(void)
App::DocumentObjectExecReturn * ret = DrawViewPart::execute();
delete ret;
autoPosition();
requestPaint();
return App::DocumentObject::StdReturn;
}
void DrawProjGroupItem::autoPosition()
{
auto pgroup = getPGroup();
Base::Vector3d newPos;
if ((pgroup != nullptr) &&
(pgroup->AutoDistribute.getValue())) {
newPos = pgroup->getXYPosition(Type.getValueAsString());
X.setValue(newPos.x);
Y.setValue(newPos.y);
requestPaint();
(pgroup->AutoDistribute.getValue()) &&
(!LockPosition.getValue())) {
newPos = pgroup->getXYPosition(Type.getValueAsString());
X.setValue(newPos.x);
Y.setValue(newPos.y);
}
return App::DocumentObject::StdReturn;
}
void DrawProjGroupItem::onDocumentRestored()

View File

@@ -77,6 +77,7 @@ public:
const bool flip=true) const override;
virtual double getScale(void) const override;
void autoPosition(void);
protected:

View File

@@ -13,6 +13,11 @@
<Author Licence="LGPL" Name="WandererFan" EMail="wandererfan@gmail.com" />
<UserDocu>Feature for creating and manipulating component Views Technical Drawing Projection Groups</UserDocu>
</Documentation>
<Methode Name="autoPosition">
<Documentation>
<UserDocu>autoPosition() - Move to AutoDistribute/Unlocked position on Page. Returns none.</UserDocu>
</Documentation>
</Methode>
<CustomAttributes />
</PythonExport>
</GenerateModel>

View File

@@ -15,6 +15,15 @@ std::string DrawProjGroupItemPy::representation(void) const
return std::string("<DrawProjGroupItem object>");
}
PyObject* DrawProjGroupItemPy::autoPosition(PyObject *args)
{
(void) args;
DrawProjGroupItem* item = getDrawProjGroupItemPtr();
item->autoPosition();
Py_INCREF(Py_None);
return Py_None;
}
PyObject *DrawProjGroupItemPy::getCustomAttributes(const char* /*attr*/) const
{
return 0;

View File

@@ -33,9 +33,9 @@
<UserDocu>getItemByLabel(string projectionType) - return specified Projection Item</UserDocu>
</Documentation>
</Methode>
<Methode Name="setViewOrientation">
<Methode Name="getXYPosition">
<Documentation>
<UserDocu>setViewOrientation(DrawProjGroupItem item, string projectionType) - sets item's view Direction according to projectionType</UserDocu>
<UserDocu>getXYPosition(string projectionType) - return the AutoDistribute position for specified Projection Item</UserDocu>
</Documentation>
</Methode>
<CustomAttributes />

View File

@@ -2,6 +2,7 @@
#include "PreCompiled.h"
#include <App/DocumentObject.h>
#include <Base/Vector3D.h>
#include "DrawProjGroup.h"
#include "DrawProjGroupItem.h"
@@ -10,6 +11,7 @@
#include <Mod/TechDraw/App/DrawProjGroupPy.h>
#include <Mod/TechDraw/App/DrawProjGroupPy.cpp>
#include <Mod/TechDraw/App/DrawProjGroupItemPy.h>
#include <Base/VectorPy.h>
using namespace TechDraw;
@@ -87,28 +89,21 @@ PyObject* DrawProjGroupPy::getItemByLabel(PyObject* args)
return new DrawProjGroupItemPy(newProj);
}
//TODO: this is no longer required?
PyObject* DrawProjGroupPy::setViewOrientation(PyObject* args)
PyObject* DrawProjGroupPy::getXYPosition(PyObject* args)
{
char* projType;
PyObject* pcObj;
if (!PyArg_ParseTuple(args, "Os", &pcObj,&projType))
if (!PyArg_ParseTuple(args, "s", &projType)) {
throw Py::Exception();
}
// App::DocumentObject* obj = static_cast<App::DocumentObjectPy*>(pcObj)->getDocumentObjectPtr();
// if (obj->getTypeId().isDerivedFrom(TechDraw::DrawProjGroupItem::getClassTypeId())) {
// TechDraw::DrawProjGroupItem* view = static_cast<TechDraw::DrawProjGroupItem*>(obj);
// TechDraw::DrawProjGroup* projGroup = getDrawProjGroupPtr();
// projGroup->setViewOrientation( view, projType );
// } else {
// Base::Console().Message("'%s' is not a DrawProjGroup Item, it will be ignored.\n", obj->Label.getValue());
// }
return Py_None;
DrawProjGroup* projGroup = getDrawProjGroupPtr();
Base::Vector3d v = projGroup->getXYPosition(projType);
return new Base::VectorPy(v);
}
PyObject *DrawProjGroupPy::getCustomAttributes(const char* /*attr*/) const
{
return 0;

View File

@@ -69,6 +69,10 @@ def DProjGroupTest():
print("recomputing document")
FreeCAD.ActiveDocument.recompute()
for v in group.Views:
print ("View: " + v.Label + " " + v.TypeId)
v.autoPosition()
rc = False
if ("Up-to-date" in group.State):
rc = True