ViewProviderRevolution.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2011 Juergen Riegel <FreeCAD@juergen-riegel.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 #endif
00028 
00029 #include <Mod/PartDesign/App/FeatureRevolution.h>
00030 #include <Mod/Sketcher/App/SketchObject.h>
00031 #include <Gui/Control.h>
00032 #include <Gui/Command.h>
00033 #include <Gui/Application.h>
00034 
00035 #include "ViewProviderRevolution.h"
00036 #include "TaskRevolutionParameters.h"
00037 
00038 using namespace PartDesignGui;
00039 
00040 PROPERTY_SOURCE(PartDesignGui::ViewProviderRevolution,PartDesignGui::ViewProvider)
00041 
00042 ViewProviderRevolution::ViewProviderRevolution()
00043 {
00044 }
00045 
00046 ViewProviderRevolution::~ViewProviderRevolution()
00047 {
00048 }
00049 
00050 std::vector<App::DocumentObject*> ViewProviderRevolution::claimChildren(void)const
00051 {
00052     std::vector<App::DocumentObject*> temp;
00053     temp.push_back(static_cast<PartDesign::Revolution*>(getObject())->Sketch.getValue());
00054 
00055     return temp;
00056 }
00057 
00058 void ViewProviderRevolution::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
00059 {
00060     QAction* act;
00061     act = menu->addAction(QObject::tr("Edit revolution"), receiver, member);
00062     act->setData(QVariant((int)ViewProvider::Default));
00063     PartGui::ViewProviderPart::setupContextMenu(menu, receiver, member);
00064 }
00065 
00066 bool ViewProviderRevolution::setEdit(int ModNum)
00067 {
00068     if (ModNum == ViewProvider::Default ) {
00069         // When double-clicking on the item for this pad the
00070         // object unsets and sets its edit mode without closing
00071         // the task panel
00072         Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
00073         TaskDlgRevolutionParameters *padDlg = qobject_cast<TaskDlgRevolutionParameters *>(dlg);
00074         if (padDlg && padDlg->getRevolutionView() != this)
00075             padDlg = 0; // another pad left open its task panel
00076         if (dlg && !padDlg) {
00077             QMessageBox msgBox;
00078             msgBox.setText(QObject::tr("A dialog is already open in the task panel"));
00079             msgBox.setInformativeText(QObject::tr("Do you want to close this dialog?"));
00080             msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
00081             msgBox.setDefaultButton(QMessageBox::Yes);
00082             int ret = msgBox.exec();
00083             if (ret == QMessageBox::Yes)
00084                 Gui::Control().closeDialog();
00085             else
00086                 return false;
00087         }
00088 
00089         // clear the selection (convenience)
00090         Gui::Selection().clearSelection();
00091         //if (ModNum == 1)
00092         //    Gui::Command::openCommand("Change revolution parameters");
00093 
00094         // start the edit dialog
00095         if (padDlg)
00096             Gui::Control().showDialog(padDlg);
00097         else
00098             Gui::Control().showDialog(new TaskDlgRevolutionParameters(this));
00099 
00100         return true;
00101     }
00102     else {
00103         return PartGui::ViewProviderPart::setEdit(ModNum);
00104     }
00105 }
00106 
00107 void ViewProviderRevolution::unsetEdit(int ModNum)
00108 {
00109     if (ModNum == ViewProvider::Default) {
00110         // and update the pad
00111         //getSketchObject()->getDocument()->recompute();
00112 
00113         // when pressing ESC make sure to close the dialog
00114         Gui::Control().closeDialog();
00115     }
00116     else {
00117         PartGui::ViewProviderPart::unsetEdit(ModNum);
00118     }
00119 }
00120 
00121 bool ViewProviderRevolution::onDelete(const std::vector<std::string> &)
00122 {
00123     // get the support and Sketch
00124     PartDesign::Revolution* pcRevolution = static_cast<PartDesign::Revolution*>(getObject()); 
00125     Sketcher::SketchObject *pcSketch;
00126     App::DocumentObject    *pcSupport;
00127     if (pcRevolution->Sketch.getValue()){
00128         pcSketch = static_cast<Sketcher::SketchObject*>(pcRevolution->Sketch.getValue()); 
00129         pcSupport = pcSketch->Support.getValue();
00130     }
00131 
00132     // if abort command deleted the object the support is visible again
00133     if (pcSketch && Gui::Application::Instance->getViewProvider(pcSketch))
00134         Gui::Application::Instance->getViewProvider(pcSketch)->show();
00135     if (pcSupport && Gui::Application::Instance->getViewProvider(pcSupport))
00136         Gui::Application::Instance->getViewProvider(pcSupport)->show();
00137 
00138     return true;
00139 }
00140 
00141 

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