ViewProviderVRMLObject.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2009 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 <Inventor/SoDB.h>
00028 # include <Inventor/SoInput.h>
00029 # include <Inventor/nodes/SoSeparator.h>
00030 # include <QFile>
00031 #endif
00032 
00033 #include "ViewProviderVRMLObject.h"
00034 #include "SoFCSelection.h"
00035 #include <App/VRMLObject.h>
00036 #include <App/Document.h>
00037 #include <Base/FileInfo.h>
00038 #include <Base/Stream.h>
00039 #include <sstream>
00040 
00041 using namespace Gui;
00042 
00043 PROPERTY_SOURCE(Gui::ViewProviderVRMLObject, Gui::ViewProviderDocumentObject)
00044 
00045 ViewProviderVRMLObject::ViewProviderVRMLObject()
00046 {
00047     pcVRML = new SoFCSelection();
00048     pcVRML->highlightMode = Gui::SoFCSelection::OFF;
00049     pcVRML->selectionMode = Gui::SoFCSelection::SEL_OFF;
00050     //pcVRML->style = Gui::SoFCSelection::BOX;
00051     pcVRML->ref();
00052 }
00053 
00054 ViewProviderVRMLObject::~ViewProviderVRMLObject()
00055 {
00056     pcVRML->unref();
00057 }
00058 
00059 void ViewProviderVRMLObject::attach(App::DocumentObject *pcObj)
00060 {
00061     ViewProviderDocumentObject::attach(pcObj);
00062     addDisplayMaskMode(pcVRML, "VRML");
00063     pcVRML->objectName = pcObj->getNameInDocument();
00064     pcVRML->documentName = pcObj->getDocument()->getName();
00065     pcVRML->subElementName = "Main";
00066 }
00067 
00068 void ViewProviderVRMLObject::setDisplayMode(const char* ModeName)
00069 {
00070     if ( strcmp("VRML",ModeName)==0 )
00071         setDisplayMaskMode("VRML");
00072     ViewProviderDocumentObject::setDisplayMode( ModeName );
00073 }
00074 
00075 std::vector<std::string> ViewProviderVRMLObject::getDisplayModes(void) const
00076 {
00077     std::vector<std::string> StrList;
00078     StrList.push_back("VRML");
00079     return StrList;
00080 }
00081 
00082 void ViewProviderVRMLObject::updateData(const App::Property* prop)
00083 {
00084     App::VRMLObject* ivObj = static_cast<App::VRMLObject*>(pcObject);
00085     if (prop == &ivObj->VrmlFile) {
00086         // read also from file
00087         const char* filename = ivObj->VrmlFile.getValue();
00088         QString fn = QString::fromUtf8(filename);
00089         QFile file(fn);
00090         SoInput in;
00091         pcVRML->removeAllChildren();
00092         if (!fn.isEmpty() && file.open(QFile::ReadOnly)) {
00093             QByteArray buffer = file.readAll();
00094             in.setBuffer((void *)buffer.constData(), buffer.length());
00095             SoSeparator * node = SoDB::readAll(&in);
00096             if (node) pcVRML->addChild(node);
00097         }
00098     }
00099 }

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