/*************************************************************************** * Copyright (c) Jürgen Riegel (juergen.riegel@web.de) 2002 * * * * 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 #endif #include #include #include "DrawPage.h" #include "DrawViewCollection.h" using namespace TechDraw; //=========================================================================== // DrawViewCollection //=========================================================================== PROPERTY_SOURCE(TechDraw::DrawViewCollection, TechDraw::DrawView) DrawViewCollection::DrawViewCollection() { static const char *group = "Drawing view"; ADD_PROPERTY_TYPE(Source ,(0), group, App::Prop_None,"Shape to view"); ADD_PROPERTY_TYPE(Views ,(0), group, App::Prop_None,"Attached Views"); } DrawViewCollection::~DrawViewCollection() { } int DrawViewCollection::addView(DrawView *view) { // Add the new view to the collection std::vector newViews(Views.getValues()); newViews.push_back(view); Views.setValues(newViews); touch(); //TODO: also have to touch the parent page's views to get repaint?? DrawPage* page = findParentPage(); if (page) { page->Views.touch(); } return Views.getSize(); } short DrawViewCollection::mustExecute() const { // If Tolerance Property is touched if (Views.isTouched() || Source.isTouched()) { return 1; } else { return TechDraw::DrawView::mustExecute(); } } int DrawViewCollection::countChildren() { //Count the children recursively if needed int numChildren = 0; const std::vector &views = Views.getValues(); for(std::vector::const_iterator it = views.begin(); it != views.end(); ++it) { App::DocumentObject *docObj = dynamic_cast(*it); if(docObj->getTypeId().isDerivedFrom(TechDraw::DrawViewCollection::getClassTypeId())) { TechDraw::DrawViewCollection *viewCollection = dynamic_cast(*it); numChildren += viewCollection->countChildren() + 1; } else { numChildren += 1; } } return numChildren; } void DrawViewCollection::onDocumentRestored() { // Rebuild the view execute(); } /// get called by the container when a Property was changed void DrawViewCollection::onChanged(const App::Property* prop) { TechDraw::DrawView::onChanged(prop); if (prop == &Source || prop == &Views){ if (!isRestoring()) { std::vector parent = getInList(); for (std::vector::iterator it = parent.begin(); it != parent.end(); ++it) { if ((*it)->getTypeId().isDerivedFrom(DrawPage::getClassTypeId())) { TechDraw::DrawPage *page = static_cast(*it); page->Views.touch(); } } } } } App::DocumentObjectExecReturn *DrawViewCollection::execute(void) { if (ScaleType.isValue("Document")) { const std::vector &views = Views.getValues(); for(std::vector::const_iterator it = views.begin(); it != views.end(); ++it) { App::DocumentObject *docObj = *it; if(docObj->getTypeId().isDerivedFrom(TechDraw::DrawView::getClassTypeId())) { TechDraw::DrawView *view = dynamic_cast(*it); // Set scale factor of each view view->ScaleType.setValue("Document"); view->touch(); } } } else if(strcmp(ScaleType.getValueAsString(), "Custom") == 0) { // Rebuild the views const std::vector &views = Views.getValues(); for(std::vector::const_iterator it = views.begin(); it != views.end(); ++it) { App::DocumentObject *docObj = *it; if(docObj->getTypeId().isDerivedFrom(TechDraw::DrawView::getClassTypeId())) { TechDraw::DrawView *view = dynamic_cast(*it); view->ScaleType.setValue("Custom"); // Set scale factor of each view view->Scale.setValue(Scale.getValue()); view->touch(); } } } return DrawView::execute(); }