ViewProviderPad.cpp

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

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