Fix #2692 TaskProjectGroup cancel button
This commit is contained in:
@@ -242,17 +242,6 @@ App::DocumentObject * DrawProjGroup::getProjObj(const char *viewProjType) const
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool DrawProjGroup::hasProjection(const char *viewProjType) const
|
||||
{
|
||||
for( const auto it : Views.getValues() ) {
|
||||
auto view( dynamic_cast<TechDraw::DrawProjGroupItem *>(it) );
|
||||
if( view && strcmp(viewProjType, view->Type.getValueAsString()) == 0 ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DrawProjGroup::checkViewProjType(const char *in)
|
||||
{
|
||||
if ( strcmp(in, "Front") == 0 ||
|
||||
@@ -270,13 +259,27 @@ bool DrawProjGroup::checkViewProjType(const char *in)
|
||||
return false;
|
||||
}
|
||||
|
||||
//********************************
|
||||
// ProjectionItem A/D/I
|
||||
//********************************
|
||||
bool DrawProjGroup::hasProjection(const char *viewProjType) const
|
||||
{
|
||||
for( const auto it : Views.getValues() ) {
|
||||
auto view( dynamic_cast<TechDraw::DrawProjGroupItem *>(it) );
|
||||
if( view && strcmp(viewProjType, view->Type.getValueAsString()) == 0 ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
App::DocumentObject * DrawProjGroup::addProjection(const char *viewProjType)
|
||||
{
|
||||
DrawProjGroupItem *view( nullptr );
|
||||
|
||||
if ( checkViewProjType(viewProjType) && !hasProjection(viewProjType) ) {
|
||||
std::string FeatName = getDocument()->getUniqueObjectName("ProjItem");
|
||||
auto docObj( getDocument()->addObject( "TechDraw::DrawProjGroupItem",
|
||||
auto docObj( getDocument()->addObject( "TechDraw::DrawProjGroupItem", //add to Document
|
||||
FeatName.c_str() ) );
|
||||
|
||||
view = static_cast<TechDraw::DrawProjGroupItem *>( docObj );
|
||||
@@ -287,13 +290,50 @@ App::DocumentObject * DrawProjGroup::addProjection(const char *viewProjType)
|
||||
view->Label.setValue( viewProjType );
|
||||
setViewOrientation( view, viewProjType );
|
||||
|
||||
addView(view); //from DrawViewCollection
|
||||
addView(view); //from DrawViewCollection - add to ProjGroup Views
|
||||
moveToCentre();
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
int DrawProjGroup::removeProjection(const char *viewProjType)
|
||||
{
|
||||
if ( checkViewProjType(viewProjType) ) {
|
||||
if( !hasProjection(viewProjType) ) {
|
||||
throw Base::Exception("The projection doesn't exist in the group");
|
||||
}
|
||||
|
||||
// Iterate through the child views and find the projection type
|
||||
for( auto it : Views.getValues() ) {
|
||||
auto projPtr( dynamic_cast<TechDraw::DrawProjGroupItem *>(it) );
|
||||
if( projPtr ) {
|
||||
if ( strcmp(viewProjType, projPtr->Type.getValueAsString()) == 0 ) {
|
||||
removeView(projPtr); // Remove from collection
|
||||
getDocument()->remObject( it->getNameInDocument() ); // Remove from the document
|
||||
moveToCentre();
|
||||
return Views.getValues().size();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int DrawProjGroup::purgeProjections()
|
||||
{
|
||||
while (!Views.getValues().empty()) {
|
||||
std::vector<DocumentObject*> views = Views.getValues();
|
||||
DrawProjGroupItem* dpgi;
|
||||
DocumentObject* dObj = views.back();
|
||||
dpgi = dynamic_cast<DrawProjGroupItem*>(dObj);
|
||||
std::string itemName = dpgi->Type.getValueAsString();
|
||||
removeProjection(itemName.c_str());
|
||||
}
|
||||
return Views.getValues().size();
|
||||
}
|
||||
|
||||
void DrawProjGroup::setViewOrientation(DrawProjGroupItem *v, const char *projType) const
|
||||
{
|
||||
Base::Vector3d dir, xDir;
|
||||
@@ -351,30 +391,6 @@ void DrawProjGroup::setViewOrientation(DrawProjGroupItem *v, const char *projTyp
|
||||
v->XAxisDirection.setValue(xDir);
|
||||
}
|
||||
|
||||
int DrawProjGroup::removeProjection(const char *viewProjType)
|
||||
{
|
||||
if ( checkViewProjType(viewProjType) ) {
|
||||
if( !hasProjection(viewProjType) ) {
|
||||
throw Base::Exception("The projection doesn't exist in the group");
|
||||
}
|
||||
|
||||
// Iterate through the child views and find the projection type
|
||||
for( auto it : Views.getValues() ) {
|
||||
auto projPtr( dynamic_cast<TechDraw::DrawProjGroupItem *>(it) );
|
||||
if( projPtr ) {
|
||||
if ( strcmp(viewProjType, projPtr->Type.getValueAsString()) == 0 ) {
|
||||
// Remove from the document
|
||||
getDocument()->remObject( it->getNameInDocument() );
|
||||
moveToCentre();
|
||||
return Views.getValues().size();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void DrawProjGroup::arrangeViewPointers(DrawProjGroupItem *viewPtrs[10]) const
|
||||
{
|
||||
for (int i=0; i<10; ++i) {
|
||||
|
||||
@@ -83,6 +83,7 @@ public:
|
||||
*/
|
||||
int removeProjection(const char *viewProjType);
|
||||
|
||||
int purgeProjections();
|
||||
/// Automatically position child views
|
||||
bool distributeProjections(void);
|
||||
void resetPositions(void);
|
||||
|
||||
@@ -57,8 +57,8 @@ DrawProjGroupItem::DrawProjGroupItem(void)
|
||||
ADD_PROPERTY(Type, ((long)0));
|
||||
|
||||
//projection group controls these
|
||||
Direction.setStatus(App::Property::Hidden,true);
|
||||
XAxisDirection.setStatus(App::Property::Hidden,true);
|
||||
Direction.setStatus(App::Property::ReadOnly,true);
|
||||
XAxisDirection.setStatus(App::Property::ReadOnly,true);
|
||||
Scale.setStatus(App::Property::ReadOnly,true);
|
||||
ScaleType.setStatus(App::Property::ReadOnly,true);
|
||||
}
|
||||
|
||||
@@ -31,8 +31,6 @@
|
||||
namespace TechDraw
|
||||
{
|
||||
|
||||
/** Base class of all View Features in the drawing module
|
||||
*/
|
||||
class TechDrawExport DrawProjGroupItem : public TechDraw::DrawViewPart
|
||||
{
|
||||
PROPERTY_HEADER(TechDraw::DrawProjGroupItem);
|
||||
|
||||
@@ -23,6 +23,11 @@
|
||||
<UserDocu>removeProjection(string projectionType) - Remove specified Projection Item from this Group. Returns int number of views in Group.</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="purgeProjections">
|
||||
<Documentation>
|
||||
<UserDocu>purgeProjections() - Remove all Projection Items from this Group. Returns int number of views in Group (0).</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="getItemByLabel">
|
||||
<Documentation>
|
||||
<UserDocu>getItemByLabel(string projectionType) - return specified Projection Item</UserDocu>
|
||||
|
||||
@@ -50,6 +50,14 @@ PyObject* DrawProjGroupPy::removeProjection(PyObject* args)
|
||||
return PyInt_FromLong((long) i);;
|
||||
}
|
||||
|
||||
PyObject* DrawProjGroupPy::purgeProjections(PyObject* args)
|
||||
{
|
||||
DrawProjGroup* projGroup = getDrawProjGroupPtr();
|
||||
int i = projGroup->purgeProjections();
|
||||
|
||||
return PyInt_FromLong((long) i);;
|
||||
}
|
||||
|
||||
PyObject* DrawProjGroupPy::getItemByLabel(PyObject* args)
|
||||
{
|
||||
const char* projType;
|
||||
|
||||
@@ -68,6 +68,54 @@ int DrawViewCollection::addView(DrawView *view)
|
||||
return Views.getSize();
|
||||
}
|
||||
|
||||
int DrawViewCollection::removeView(DrawView *view)
|
||||
{
|
||||
// Remove the view from the the collection
|
||||
const std::vector<App::DocumentObject*> currViews = Views.getValues();
|
||||
std::vector<App::DocumentObject*> newViews;
|
||||
std::vector<App::DocumentObject*>::const_iterator it = currViews.begin();
|
||||
for (; it != currViews.end(); it++) {
|
||||
std::string viewName = view->getNameInDocument();
|
||||
if (viewName.compare((*it)->getNameInDocument()) != 0) {
|
||||
newViews.push_back((*it));
|
||||
}
|
||||
}
|
||||
Views.setValues(newViews);
|
||||
|
||||
//TODO: also have to touch the parent page's views to get repaint??
|
||||
DrawPage* page = findParentPage();
|
||||
if (page) {
|
||||
page->Views.touch();
|
||||
}
|
||||
return Views.getSize();
|
||||
}
|
||||
|
||||
//make sure everything in View list represents a real DrawView docObj and occurs only once
|
||||
void DrawViewCollection::rebuildViewList()
|
||||
{
|
||||
const std::vector<App::DocumentObject*> currViews = Views.getValues();
|
||||
std::vector<App::DocumentObject*> newViews;
|
||||
std::vector<App::DocumentObject*> children = getOutList();
|
||||
for (std::vector<App::DocumentObject*>::iterator it = children.begin(); it != children.end(); ++it) {
|
||||
if ((*it)->getTypeId().isDerivedFrom(DrawView::getClassTypeId())) {
|
||||
//TechDraw::DrawView* view = static_cast<TechDraw::DrawView *>(*it);
|
||||
bool found = false;
|
||||
for (auto& v:currViews) {
|
||||
if (v == (*it)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found) {
|
||||
newViews.push_back((*it));
|
||||
}
|
||||
}
|
||||
} // newViews contains only valid items, but may have duplicates
|
||||
sort( newViews.begin(), newViews.end() );
|
||||
newViews.erase( unique( newViews.begin(), newViews.end() ), newViews.end() );
|
||||
Views.setValues(newViews);
|
||||
}
|
||||
|
||||
short DrawViewCollection::mustExecute() const
|
||||
{
|
||||
// If Tolerance Property is touched
|
||||
|
||||
@@ -48,6 +48,8 @@ public:
|
||||
short mustExecute() const;
|
||||
|
||||
int addView(DrawView *view);
|
||||
int removeView(DrawView *view);
|
||||
void rebuildViewList(void);
|
||||
|
||||
int countChildren();
|
||||
/** @name methods overide Feature */
|
||||
|
||||
@@ -13,6 +13,16 @@
|
||||
<Author Licence="LGPL" Name="WandererFan" EMail="wandererfan@gmail.com" />
|
||||
<UserDocu>Feature for creating and manipulating Technical Drawing View Collections</UserDocu>
|
||||
</Documentation>
|
||||
<Methode Name="addView">
|
||||
<Documentation>
|
||||
<UserDocu>addView(DrawView object) - Add a new View to this Group. Returns count of views.</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="removeView">
|
||||
<Documentation>
|
||||
<UserDocu>removeView(DrawView object) - Remove specified Viewfrom this Group. Returns count of views in Group.</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<CustomAttributes />
|
||||
</PythonExport>
|
||||
</GenerateModel>
|
||||
|
||||
@@ -14,6 +14,41 @@ std::string DrawViewCollectionPy::representation(void) const
|
||||
{
|
||||
return std::string("<DrawViewCollection object>");
|
||||
}
|
||||
PyObject* DrawViewCollectionPy::addView(PyObject* args)
|
||||
{
|
||||
PyObject *pcDocObj;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "O!", &(App::DocumentObjectPy::Type), &pcDocObj)) {
|
||||
Base::Console().Error("Error: DrawViewClipPy::addView - Bad Arg - not DocumentObject\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DrawViewCollection* collect = getDrawViewCollectionPtr();
|
||||
DrawViewPy* pyView = static_cast<TechDraw::DrawViewPy*>(pcDocObj);
|
||||
DrawView* view = pyView->getDrawViewPtr(); //get DrawView for pyView
|
||||
|
||||
int i = collect->addView(view);
|
||||
|
||||
return PyInt_FromLong((long) i);
|
||||
}
|
||||
|
||||
PyObject* DrawViewCollectionPy::removeView(PyObject* args)
|
||||
{
|
||||
PyObject *pcDocObj;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "O!", &(App::DocumentObjectPy::Type), &pcDocObj)) {
|
||||
Base::Console().Error("Error: DrawViewClipPy::addView - Bad Arg - not DocumentObject\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DrawViewCollection* collect = getDrawViewCollectionPtr();
|
||||
DrawViewPy* pyView = static_cast<TechDraw::DrawViewPy*>(pcDocObj);
|
||||
DrawView* view = pyView->getDrawViewPtr(); //get DrawView for pyView
|
||||
|
||||
int i = collect->removeView(view);
|
||||
|
||||
return PyInt_FromLong((long) i);
|
||||
}
|
||||
|
||||
|
||||
PyObject *DrawViewCollectionPy::getCustomAttributes(const char* /*attr*/) const
|
||||
|
||||
Reference in New Issue
Block a user