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