/****************************************************************************** * Copyright (c)2012 Jan Rheinlaender * * * * This file is part of the FreeCAD CAx development system. * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Library General Public * * License as published by the Free Software Foundation; either * * version 2 of the License, or (at your option) any later version. * * * * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU Library General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this library; see the file COPYING.LIB. If not, * * write to the Free Software Foundation, Inc., 59 Temple Place, * * Suite 330, Boston, MA 02111-1307, USA * * * ******************************************************************************/ #include "PreCompiled.h" #ifndef _PreComp_ # include # include # include #endif #include #include #include #include #include #include "ViewProviderGroove.h" #include "TaskGrooveParameters.h" using namespace PartDesignGui; PROPERTY_SOURCE(PartDesignGui::ViewProviderGroove,PartDesignGui::ViewProvider) ViewProviderGroove::ViewProviderGroove() { sPixmap = "PartDesign_Groove.svg"; } ViewProviderGroove::~ViewProviderGroove() { } std::vector ViewProviderGroove::claimChildren(void)const { std::vector temp; temp.push_back(static_cast(getObject())->Sketch.getValue()); return temp; } void ViewProviderGroove::setupContextMenu(QMenu* menu, QObject* receiver, const char* member) { QAction* act; act = menu->addAction(QObject::tr("Edit Groove"), receiver, member); act->setData(QVariant((int)ViewProvider::Default)); PartGui::ViewProviderPart::setupContextMenu(menu, receiver, member); } bool ViewProviderGroove::setEdit(int ModNum) { if (ModNum == ViewProvider::Default ) { PartDesign::Groove* pcGroove = static_cast(getObject()); if (pcGroove->getSketchAxisCount() < 0) { QMessageBox msgBox; msgBox.setIcon(QMessageBox::Critical); msgBox.setWindowTitle(QObject::tr("Lost link to base sketch")); msgBox.setText(QObject::tr("The object can't be edited because the link to the the base sketch is lost.")); msgBox.setStandardButtons(QMessageBox::Ok); msgBox.exec(); return false; } // When double-clicking on the item for this pad the // object unsets and sets its edit mode without closing // the task panel Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog(); TaskDlgGrooveParameters *padDlg = qobject_cast(dlg); if (padDlg && padDlg->getGrooveView() != this) padDlg = 0; // another pad left open its task panel if (dlg && !padDlg) { QMessageBox msgBox; msgBox.setText(QObject::tr("A dialog is already open in the task panel")); msgBox.setInformativeText(QObject::tr("Do you want to close this dialog?")); msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); msgBox.setDefaultButton(QMessageBox::Yes); int ret = msgBox.exec(); if (ret == QMessageBox::Yes) Gui::Control().reject(); else return false; } // clear the selection (convenience) Gui::Selection().clearSelection(); //if (ModNum == 1) // Gui::Command::openCommand("Change Groove parameters"); // start the edit dialog if (padDlg) Gui::Control().showDialog(padDlg); else Gui::Control().showDialog(new TaskDlgGrooveParameters(this)); return true; } else { return PartGui::ViewProviderPart::setEdit(ModNum); } } void ViewProviderGroove::unsetEdit(int ModNum) { if (ModNum == ViewProvider::Default) { // and update the pad //getSketchObject()->getDocument()->recompute(); // when pressing ESC make sure to close the dialog Gui::Control().closeDialog(); } else { PartGui::ViewProviderPart::unsetEdit(ModNum); } } bool ViewProviderGroove::onDelete(const std::vector &) { // get the support and Sketch PartDesign::Groove* pcGroove = static_cast(getObject()); Sketcher::SketchObject *pcSketch = 0; App::DocumentObject *pcSupport = 0; if (pcGroove->Sketch.getValue()){ pcSketch = static_cast(pcGroove->Sketch.getValue()); pcSupport = pcSketch->Support.getValue(); } // if abort command deleted the object the support is visible again if (pcSketch && Gui::Application::Instance->getViewProvider(pcSketch)) Gui::Application::Instance->getViewProvider(pcSketch)->show(); if (pcSupport && Gui::Application::Instance->getViewProvider(pcSupport)) Gui::Application::Instance->getViewProvider(pcSupport)->show(); return true; }