Add getAllViews() method to DrawPagePy

This commit is contained in:
wandererfan
2018-03-21 09:35:06 -04:00
committed by wmayer
parent 2d4865bb11
commit dd3cc51818
7 changed files with 138 additions and 7 deletions

View File

@@ -42,6 +42,7 @@ generate_from_xml(DrawGeomHatchPy)
generate_from_xml(DrawViewCollectionPy)
generate_from_xml(DrawProjGroupPy)
generate_from_xml(DrawProjGroupItemPy)
generate_from_xml(DrawViewAnnotationPy)
SET(Draw_SRCS
DrawPage.cpp
@@ -143,7 +144,9 @@ SET(Python_SRCS
DrawProjGroupPy.xml
DrawProjGroupPyImp.cpp
DrawProjGroupItemPy.xml
DrawProjGroupItemPyImp.cpp)
DrawProjGroupItemPyImp.cpp
DrawViewAnnotationPy.xml
DrawViewAnnotationPyImp.cpp)
SOURCE_GROUP("Mod" FILES ${TechDraw_SRCS})
SOURCE_GROUP("Features" FILES ${Draw_SRCS})

View File

@@ -318,28 +318,44 @@ void DrawPage::onDocumentRestored()
bool autoUpdate = hGrp->GetBool("KeepPagesUpToDate", 1l);
KeepUpdated.setValue(autoUpdate);
std::vector<App::DocumentObject*> featViews = Views.getValues();
std::vector<App::DocumentObject*> featViews = getAllViews();
std::vector<App::DocumentObject*>::const_iterator it = featViews.begin();
//first, make sure all the Parts have been executed so GeometryObjects exist
for(; it != featViews.end(); ++it) {
TechDraw::DrawViewPart *part = dynamic_cast<TechDraw::DrawViewPart *>(*it);
if (part != nullptr &&
!part->hasGeometry()) {
part->touch();
part->recomputeFeature();
}
}
//second, make sure all the Dimensions have been executed so Measurements have References
for(it = featViews.begin(); it != featViews.end(); ++it) {
TechDraw::DrawViewDimension *dim = dynamic_cast<TechDraw::DrawViewDimension *>(*it);
if (dim != nullptr &&
!dim->has2DReferences()) {
dim->touch();
if (dim != nullptr) {
dim->recomputeFeature();
}
}
recompute();
App::DocumentObject::onDocumentRestored();
}
std::vector<App::DocumentObject*> DrawPage::getAllViews(void)
{
auto views = Views.getValues(); //list of docObjects
std::vector<App::DocumentObject*> allViews;
for (auto& v: views) {
if (v->isDerivedFrom(TechDraw::DrawProjGroup::getClassTypeId())) {
TechDraw::DrawProjGroup* dpg = static_cast<TechDraw::DrawProjGroup*>(v);
if (dpg != nullptr) { //can't really happen!
std::vector<App::DocumentObject*> pgViews = dpg->Views.getValues();
allViews.insert(allViews.end(),pgViews.begin(),pgViews.end());
}
} else {
allViews.push_back(v);
}
}
return allViews;
}
void DrawPage::unsetupObject()
{
nowUnsetting = true;

View File

@@ -88,6 +88,7 @@ public:
const char* getPageOrientation() const;
bool isUnsetting(void) { return nowUnsetting; }
void requestPaint(void);
std::vector<App::DocumentObject*> getAllViews(void) ;
protected:

View File

@@ -23,6 +23,11 @@
<UserDocu>removeView(DrawView) - Remove a View to this Page</UserDocu>
</Documentation>
</Methode>
<Methode Name="getAllViews">
<Documentation>
<UserDocu>getAllViews() - returns a list of all the views on page including Views inside Collections</UserDocu>
</Documentation>
</Methode>
<Methode Name="getPageWidth">
<Documentation>
<UserDocu>Return the width of this page</UserDocu>

View File

@@ -6,9 +6,15 @@
#include "DrawPage.h"
#include "DrawView.h"
#include "DrawViewPart.h"
#include "DrawProjGroup.h"
#include "DrawProjGroupItem.h"
// inclusion of the generated files
#include <Mod/TechDraw/App/DrawViewPy.h>
#include <Mod/TechDraw/App/DrawViewPartPy.h>
#include <Mod/TechDraw/App/DrawProjGroupItemPy.h>
#include <Mod/TechDraw/App/DrawViewAnnotationPy.h>
#include <Mod/TechDraw/App/DrawPagePy.h>
#include <Mod/TechDraw/App/DrawPagePy.cpp>
@@ -70,6 +76,30 @@ PyObject* DrawPagePy::removeView(PyObject* args)
#endif
}
PyObject* DrawPagePy::getAllViews(PyObject* args)
{
(void) args;
DrawPage* page = getDrawPagePtr();
std::vector<App::DocumentObject*> allViews = page->getAllViews();
PyObject* ret = PyList_New(0);
for (auto&v: allViews) {
if (v->isDerivedFrom(TechDraw::DrawProjGroupItem::getClassTypeId())) {
TechDraw::DrawProjGroupItem* dpgi = static_cast<TechDraw::DrawProjGroupItem*>(v);
PyList_Append(ret,new TechDraw::DrawProjGroupItemPy(dpgi)); //is this legit? or need to make new copy of dv?
} else if (v->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) {
TechDraw::DrawViewPart* dvp = static_cast<TechDraw::DrawViewPart*>(v);
PyList_Append(ret,new TechDraw::DrawViewPartPy(dvp));
} else if (v->isDerivedFrom(TechDraw::DrawViewAnnotation::getClassTypeId())) {
TechDraw::DrawViewAnnotation* dva = static_cast<TechDraw::DrawViewAnnotation*>(v);
PyList_Append(ret,new TechDraw::DrawViewAnnotationPy(dva));
} else {
TechDraw::DrawView* dv = static_cast<TechDraw::DrawView*>(v);
PyList_Append(ret,new TechDraw::DrawViewPy(dv));
}
}
return ret;
}
// double getPageWidth() const;
PyObject* DrawPagePy::getPageWidth(PyObject *)

View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
<PythonExport
Father="DrawViewPy"
Name="DrawViewAnnotationPy"
Twin="DrawViewAnnotation"
TwinPointer="DrawViewAnnotation"
Include="Mod/TechDraw/App/DrawViewAnnotation.h"
Namespace="TechDraw"
FatherInclude="Mod/TechDraw/App/DrawViewPy.h"
FatherNamespace="TechDraw">
<Documentation>
<Author Licence="LGPL" Name="WandererFan" EMail="wandererfan@gmail.com" />
<UserDocu>Feature for creating and manipulating Technical Drawing Annotation Views</UserDocu>
</Documentation>
<CustomAttributes />
</PythonExport>
</GenerateModel>

View File

@@ -0,0 +1,58 @@
/***************************************************************************
* Copyright (c) 2018 WandererFan (wandererfan@gmail.com) *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
# include <sstream>
#endif
#include <App/DocumentObject.h>
#include <Base/Console.h>
#include "DrawPage.h"
#include "DrawView.h"
#include "DrawViewAnnotation.h"
// inclusion of the generated files
#include <Mod/TechDraw/App/DrawViewPy.h>
#include <Mod/TechDraw/App/DrawViewAnnotationPy.h>
#include <Mod/TechDraw/App/DrawViewAnnotationPy.cpp>
using namespace TechDraw;
// returns a string which represents the object e.g. when printed in python
std::string DrawViewAnnotationPy::representation(void) const
{
return std::string("<DrawViewAnnotation object>");
}
PyObject *DrawViewAnnotationPy::getCustomAttributes(const char* ) const
{
return 0;
}
int DrawViewAnnotationPy::setCustomAttributes(const char* , PyObject *)
{
return 0;
}