Part/Gui/ViewProviderPython.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2010 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 #include <Standard_math.hxx>
00027 #ifndef _PreComp_
00028 # include <Inventor/nodes/SoSeparator.h>
00029 #endif
00030 #include <Gui/ViewProviderBuilder.h>
00031 #include <Mod/Part/App/PartFeature.h>
00032 #include "ViewProviderPython.h"
00033 
00034 using namespace PartGui;
00035 
00036 PROPERTY_SOURCE(PartGui::ViewProviderCustom, PartGui::ViewProviderPart)
00037 
00038 ViewProviderCustom::ViewProviderCustom()
00039 {
00040 }
00041 
00042 ViewProviderCustom::~ViewProviderCustom()
00043 {
00044 }
00045 
00046 void ViewProviderCustom::onChanged(const App::Property* prop)
00047 {
00048     std::map<const App::Property*, Gui::ViewProvider*>::iterator it;
00049     for (it = propView.begin(); it != propView.end(); ++it) {
00050         App::Property* view = it->second->getPropertyByName(prop->getName());
00051         if (view) {
00052             App::Property* copy = prop->Copy();
00053             if (copy) {
00054                 view->Paste(*copy);
00055                 delete copy;
00056             }
00057         }
00058     }
00059     PartGui::ViewProviderPart::onChanged(prop);
00060 }
00061 
00062 void ViewProviderCustom::updateData(const App::Property* prop)
00063 {
00064     if (prop->getTypeId().isDerivedFrom(App::PropertyComplexGeoData::getClassTypeId())) {
00065         std::map<const App::Property*, Gui::ViewProvider*>::iterator it = propView.find(prop);
00066         if (it == propView.end()) {
00067             Gui::ViewProvider* view = Gui::ViewProviderBuilder::create(prop->getTypeId());
00068             if (view) {
00069                 if (view->getTypeId().isDerivedFrom(Gui::ViewProviderDocumentObject::getClassTypeId())) {
00070                     static_cast<Gui::ViewProviderDocumentObject*>(view)->attach(this->getObject());
00071                     static_cast<Gui::ViewProviderDocumentObject*>(view)->setDisplayMode(this->getActiveDisplayMode().c_str());
00072                 }
00073                 propView[prop] = view;
00074                 view->updateData(prop);
00075                 this->getRoot()->addChild(view->getRoot());
00076             }
00077         }
00078         else {
00079             it->second->updateData(prop);
00080         }
00081     }
00082 }
00083 
00084 // -----------------------------------------------------------------------
00085 
00086 namespace Gui {
00088 PROPERTY_SOURCE_TEMPLATE(PartGui::ViewProviderPython, PartGui::ViewProviderPart)
00090 
00091 // explicit template instantiation
00092 template class PartGuiExport ViewProviderPythonFeatureT<PartGui::ViewProviderPart>;
00093 
00095 PROPERTY_SOURCE_TEMPLATE(PartGui::ViewProviderCustomPython, PartGui::ViewProviderCustom)
00097 
00098 // explicit template instantiation
00099 template class PartGuiExport ViewProviderPythonFeatureT<PartGui::ViewProviderCustom>;
00100 }
00101 

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