ViewProviderPage.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2004 Jürgen Riegel <juergen.riegel@web.de>              *
00003  *                                                                         *
00004  *   This file is Drawing 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 DrawingICULAR 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 # ifdef FC_OS_WIN32
00028 #  include <windows.h>
00029 # endif
00030 # include <QAction>
00031 # include <QMenu>
00032 # include <QTimer>
00033 #endif
00034 
00036 #include <Base/Console.h>
00037 #include <Base/Parameter.h>
00038 #include <Base/Exception.h>
00039 #include <Base/Sequencer.h>
00040 #include <App/Application.h>
00041 #include <App/Document.h>
00042 #include <App/DocumentObject.h>
00043 #include <Gui/SoFCSelection.h>
00044 #include <Gui/Selection.h>
00045 #include <Gui/MainWindow.h>
00046 #include <Gui/BitmapFactory.h>
00047 #include <Gui/ViewProviderDocumentObjectGroup.h>
00048 
00049 
00050 #include "ViewProviderPage.h"
00051 #include <Mod/Drawing/App/FeaturePage.h>
00052 
00053 using namespace DrawingGui;
00054 
00055 PROPERTY_SOURCE(DrawingGui::ViewProviderDrawingPage, Gui::ViewProviderDocumentObjectGroup)
00056 
00057 
00058 //**************************************************************************
00059 // Construction/Destruction
00060 
00061 ViewProviderDrawingPage::ViewProviderDrawingPage()
00062   : view(0)
00063 {
00064     sPixmap = "Page";
00065     ADD_PROPERTY(HintScale,(10.0));
00066     ADD_PROPERTY(HintOffsetX,(10.0));
00067     ADD_PROPERTY(HintOffsetY,(10.0));
00068 }
00069 
00070 ViewProviderDrawingPage::~ViewProviderDrawingPage()
00071 {
00072 }
00073 
00074 void ViewProviderDrawingPage::attach(App::DocumentObject *pcFeat)
00075 {
00076     // call parent attach method
00077     ViewProviderDocumentObject::attach(pcFeat);
00078 }
00079 
00080 void ViewProviderDrawingPage::setDisplayMode(const char* ModeName)
00081 {
00082     ViewProviderDocumentObject::setDisplayMode(ModeName);
00083 }
00084 
00085 std::vector<std::string> ViewProviderDrawingPage::getDisplayModes(void) const
00086 {
00087     // get the modes of the father
00088     std::vector<std::string> StrList = ViewProviderDocumentObject::getDisplayModes();
00089     StrList.push_back("Drawing");
00090     return StrList;
00091 }
00092 
00093 void ViewProviderDrawingPage::updateData(const App::Property* prop)
00094 {
00095     Gui::ViewProviderDocumentObjectGroup::updateData(prop);
00096     if (prop->getTypeId() == App::PropertyFileIncluded::getClassTypeId()) {
00097         if (std::string(getPageObject()->PageResult.getValue()) != "") {
00098             DrawingView* view = showDrawingView();
00099             view->load(QString::fromUtf8(getPageObject()->PageResult.getValue()));
00100             if (view->isHidden())
00101                 QTimer::singleShot(300, view, SLOT(viewAll()));
00102             else
00103                 view->viewAll();
00104         }
00105     }
00106 }
00107 
00108 void ViewProviderDrawingPage::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
00109 {
00110     QAction* act;
00111     act = menu->addAction(QObject::tr("Show drawing"), receiver, member);
00112 }
00113 
00114 bool ViewProviderDrawingPage::setEdit(int ModNum)
00115 {
00116     doubleClicked();
00117     return false;
00118 }
00119 
00120 bool ViewProviderDrawingPage::doubleClicked(void)
00121 {
00122     if (!this->view) {
00123         showDrawingView();
00124         this->view->load(QString::fromUtf8(getPageObject()->PageResult.getValue()));
00125         view->viewAll();
00126     }
00127     Gui::getMainWindow()->setActiveWindow(this->view);
00128     return true;
00129 }
00130 
00131 DrawingView* ViewProviderDrawingPage::showDrawingView()
00132 {
00133     if (!view){
00134         view = new DrawingView(Gui::getMainWindow());
00135         view->setWindowIcon(Gui::BitmapFactory().pixmap("actions/drawing-landscape"));
00136         view->setWindowTitle(QObject::tr("Drawing viewer"));
00137         Gui::getMainWindow()->addWindow(view);
00138     }
00139 
00140     return view;
00141 }
00142 
00143 Drawing::FeaturePage* ViewProviderDrawingPage::getPageObject() const
00144 {
00145     return dynamic_cast<Drawing::FeaturePage*>(pcObject);
00146 }

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