ViewProviderDocumentObjectGroup.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2006 Werner Mayer <wmayer[at]users.sourceforge.net>     *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
00020  *                                                                         *
00021  ***************************************************************************/
00022 
00023 
00024 #include "PreCompiled.h"
00025 
00026 #ifndef _PreComp_
00027 # include <QApplication>
00028 # include <QPixmap>
00029 #endif
00030 
00031 #include <App/DocumentObjectGroup.h>
00032 #include <App/Document.h>
00033 
00035 #include "ViewProviderDocumentObjectGroup.h"
00036 #include "Application.h"
00037 #include "Command.h"
00038 #include "BitmapFactory.h"
00039 #include "Document.h"
00040 #include "Tree.h"
00041 #include "View3DInventor.h"
00042 #include "View3DInventorViewer.h"
00043 
00044 
00045 using namespace Gui;
00046 
00047 
00048 PROPERTY_SOURCE(Gui::ViewProviderDocumentObjectGroup, Gui::ViewProviderDocumentObject)
00049 
00050 
00051 
00054 ViewProviderDocumentObjectGroup::ViewProviderDocumentObjectGroup() : visible(false)
00055 {
00056 #if 0
00057     setDefaultMode(SO_SWITCH_ALL);
00058 #endif
00059 }
00060 
00061 ViewProviderDocumentObjectGroup::~ViewProviderDocumentObjectGroup()
00062 {
00063 }
00064 
00069 void ViewProviderDocumentObjectGroup::onChanged(const App::Property* prop)
00070 {
00071     ViewProviderDocumentObject::onChanged(prop);
00072 }
00073 
00074 void ViewProviderDocumentObjectGroup::attach(App::DocumentObject *pcObj)
00075 {
00076     ViewProviderDocumentObject::attach(pcObj);
00077 }
00078 
00079 void ViewProviderDocumentObjectGroup::updateData(const App::Property* prop)
00080 {
00081 #if 0
00082     if (prop->getTypeId() == App::PropertyLinkList::getClassTypeId()) {
00083         std::vector<App::DocumentObject*> obj =
00084             static_cast<const App::PropertyLinkList*>(prop)->getValues();
00085         Gui::Document* doc = Gui::Application::Instance->getDocument
00086             (&this->getObject()->getDocument());
00087         MDIView* mdi = doc->getActiveView();
00088         if (mdi && mdi->isDerivedFrom(View3DInventor::getClassTypeId())) {
00089             View3DInventorViewer* view = static_cast<View3DInventor*>(mdi)->getViewer();
00090             SoSeparator* scene_graph = static_cast<SoSeparator*>(view->getSceneGraph());
00091             std::vector<ViewProvider*> current_nodes;
00092             for (std::vector<App::DocumentObject*>::iterator it = obj.begin(); it != obj.end(); ++it)
00093                 current_nodes.push_back(doc->getViewProvider(*it));
00094             std::sort(current_nodes.begin(), current_nodes.end());
00095             std::sort(this->nodes.begin(), this->nodes.end());
00096             // get the removed views
00097             std::vector<ViewProvider*> diff_1, diff_2;
00098             std::back_insert_iterator<std::vector<ViewProvider*> > biit(diff_2);
00099             std::set_difference(this->nodes.begin(), this->nodes.end(), 
00100                                 current_nodes.begin(), current_nodes.end(), biit);
00101             diff_1 = diff_2;
00102             diff_2.clear();
00103             // get the added views
00104             std::set_difference(current_nodes.begin(), current_nodes.end(),
00105                                 this->nodes.begin(), this->nodes.end(), biit);
00106             this->nodes = current_nodes;
00107             // move from root node to switch
00108             for (std::vector<ViewProvider*>::iterator it = diff_1.begin(); it != diff_1.end(); ++it) {
00109                 view->addViewProviderToGroup(*it, scene_graph);
00110                 view->removeViewProviderFromGroup(*it, this->pcModeSwitch);
00111             }
00112             // move from switch node to root node
00113             for (std::vector<ViewProvider*>::iterator it = diff_2.begin(); it != diff_2.end(); ++it) {
00114                 view->addViewProviderToGroup(*it, this->pcModeSwitch);
00115                 view->removeViewProviderFromGroup(*it, scene_graph);
00116             }
00117         }
00118     }
00119 #endif
00120 }
00121 
00122 std::vector<App::DocumentObject*> ViewProviderDocumentObjectGroup::claimChildren(void)const
00123 {
00124     return std::vector<App::DocumentObject*>(static_cast<App::DocumentObjectGroup*>(getObject())->Group.getValues());
00125 }
00126 
00127 std::vector<std::string> ViewProviderDocumentObjectGroup::getDisplayModes(void) const
00128 {
00129     // empty
00130     return std::vector<std::string>();
00131 }
00132 bool ViewProviderDocumentObjectGroup::onDelete(const std::vector<std::string> &)
00133 {
00134     Gui::Command::doCommand(Gui::Command::Doc,"App.getDocument(\"%s\").getObject(\"%s\").removeObjectsFromDocument()"
00135                                      ,getObject()->getDocument()->getName(), getObject()->getNameInDocument());
00136     return true;
00137 }
00138 
00139 
00140 void ViewProviderDocumentObjectGroup::hide(void)
00141 {
00142     // when reading the Visibility property from file then do not hide the
00143     // objects of this group because they have stored their visibility status, too
00144     if (!Visibility.StatusBits.test(9) && this->visible) {
00145         App::DocumentObject * group = getObject();
00146         if (group && group->getTypeId().isDerivedFrom(App::DocumentObjectGroup::getClassTypeId())) {
00147             const std::vector<App::DocumentObject*> & links = static_cast<App::DocumentObjectGroup*>
00148                 (group)->Group.getValues();
00149             Gui::Document* doc = Application::Instance->getDocument(group->getDocument());
00150             for (std::vector<App::DocumentObject*>::const_iterator it = links.begin(); it != links.end(); ++it) {
00151                 ViewProvider* view = doc->getViewProvider(*it);
00152                 if (view) view->hide();
00153             }
00154         }
00155     }
00156 
00157     ViewProviderDocumentObject::hide();
00158     this->visible = false;
00159 }
00160 
00161 void ViewProviderDocumentObjectGroup::show(void)
00162 {
00163     // when reading the Visibility property from file then do not hide the
00164     // objects of this group because they have stored their visibility status, too
00165     if (!Visibility.StatusBits.test(9) && !this->visible) {
00166         App::DocumentObject * group = getObject();
00167         if (group && group->getTypeId().isDerivedFrom(App::DocumentObjectGroup::getClassTypeId())) {
00168             const std::vector<App::DocumentObject*> & links = static_cast<App::DocumentObjectGroup*>
00169                 (group)->Group.getValues();
00170             Gui::Document* doc = Application::Instance->getDocument(group->getDocument());
00171             for (std::vector<App::DocumentObject*>::const_iterator it = links.begin(); it != links.end(); ++it) {
00172                 ViewProvider* view = doc->getViewProvider(*it);
00173                 if (view) view->show();
00174             }
00175         }
00176     }
00177 
00178     ViewProviderDocumentObject::show();
00179     this->visible = true;
00180 }
00181 
00182 bool ViewProviderDocumentObjectGroup::isShow(void) const
00183 {
00184     return Visibility.getValue();
00185 }
00186 
00187 void ViewProviderDocumentObjectGroup::Restore(Base::XMLReader &reader)
00188 {
00189     Visibility.StatusBits.set(9); // tmp. set
00190     ViewProviderDocumentObject::Restore(reader);
00191     Visibility.StatusBits.reset(9); // unset
00192 }
00193 
00197 void ViewProviderDocumentObjectGroup::getViewProviders(std::vector<ViewProviderDocumentObject*>& vp) const
00198 {
00199     App::DocumentObject* doc = getObject();
00200     if (doc->getTypeId().isDerivedFrom(App::DocumentObjectGroup::getClassTypeId())) {
00201         Gui::Document* gd = Application::Instance->getDocument(doc->getDocument());
00202         App::DocumentObjectGroup* grp = (App::DocumentObjectGroup*)doc;
00203         std::vector<App::DocumentObject*> obj = grp->getObjects();
00204         for (std::vector<App::DocumentObject*>::iterator it = obj.begin(); it != obj.end(); ++it) {
00205             ViewProvider* v = gd->getViewProvider(*it);
00206             if (v && v->getTypeId().isDerivedFrom(ViewProviderDocumentObject::getClassTypeId()))
00207                 vp.push_back((ViewProviderDocumentObject*)v);
00208         }
00209     }
00210 }
00211 
00215 QIcon ViewProviderDocumentObjectGroup::getIcon() const
00216 {
00217     QIcon groupIcon;
00218     groupIcon.addPixmap(QApplication::style()->standardPixmap(QStyle::SP_DirClosedIcon),
00219                         QIcon::Normal, QIcon::Off);
00220     groupIcon.addPixmap(QApplication::style()->standardPixmap(QStyle::SP_DirOpenIcon),
00221                         QIcon::Normal, QIcon::On);
00222     return groupIcon;
00223 }

Generated on Wed Nov 23 19:00:58 2011 for FreeCAD by  doxygen 1.6.1