TaskFilletParameters.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 "ui_TaskFilletParameters.h"
00030 #include "TaskFilletParameters.h"
00031 #include <App/Application.h>
00032 #include <App/Document.h>
00033 #include <Gui/Application.h>
00034 #include <Gui/Document.h>
00035 #include <Gui/BitmapFactory.h>
00036 #include <Gui/ViewProvider.h>
00037 #include <Gui/WaitCursor.h>
00038 #include <Base/Console.h>
00039 #include <Gui/Selection.h>
00040 #include <Gui/Command.h>
00041 #include <Mod/PartDesign/App/FeatureFillet.h>
00042 #include <Mod/Sketcher/App/SketchObject.h>
00043 
00044 
00045 using namespace PartDesignGui;
00046 using namespace Gui;
00047 
00048 /* TRANSLATOR PartDesignGui::TaskFilletParameters */
00049 
00050 TaskFilletParameters::TaskFilletParameters(ViewProviderFillet *FilletView,QWidget *parent)
00051     : TaskBox(Gui::BitmapFactory().pixmap("Part_Fillet"),tr("Fillet parameters"),true, parent),FilletView(FilletView)
00052 {
00053     // we need a separate container widget to add all controls to
00054     proxy = new QWidget(this);
00055     ui = new Ui_TaskFilletParameters();
00056     ui->setupUi(proxy);
00057     QMetaObject::connectSlotsByName(this);
00058 
00059     connect(ui->doubleSpinBox, SIGNAL(valueChanged(double)),
00060             this, SLOT(onLengthChanged(double)));
00061 
00062     this->groupLayout()->addWidget(proxy);
00063 
00064     PartDesign::Fillet* pcFillet = static_cast<PartDesign::Fillet*>(FilletView->getObject());
00065     double r = pcFillet->Radius.getValue();
00066 
00067     ui->doubleSpinBox->setMaximum(INT_MAX);
00068     ui->doubleSpinBox->setValue(r);
00069     ui->doubleSpinBox->selectAll();
00070  
00071 
00072     setFocus ();
00073 }
00074 
00075 void TaskFilletParameters::onLengthChanged(double len)
00076 {
00077     PartDesign::Fillet* pcFillet = static_cast<PartDesign::Fillet*>(FilletView->getObject());
00078     pcFillet->Radius.setValue((float)len);
00079     pcFillet->getDocument()->recomputeFeature(pcFillet);
00080 }
00081 
00082 double TaskFilletParameters::getLength(void) const
00083 {
00084     return ui->doubleSpinBox->value();
00085 }
00086 
00087 
00088 TaskFilletParameters::~TaskFilletParameters()
00089 {
00090     delete ui;
00091 }
00092 
00093 void TaskFilletParameters::changeEvent(QEvent *e)
00094 {
00095     TaskBox::changeEvent(e);
00096     if (e->type() == QEvent::LanguageChange) {
00097         ui->retranslateUi(proxy);
00098     }
00099 }
00100 
00101 //**************************************************************************
00102 //**************************************************************************
00103 // TaskDialog
00104 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00105 
00106 TaskDlgFilletParameters::TaskDlgFilletParameters(ViewProviderFillet *FilletView)
00107     : TaskDialog(),FilletView(FilletView)
00108 {
00109     assert(FilletView);
00110     parameter  = new TaskFilletParameters(FilletView);
00111 
00112     Content.push_back(parameter);
00113 }
00114 
00115 TaskDlgFilletParameters::~TaskDlgFilletParameters()
00116 {
00117 
00118 }
00119 
00120 //==== calls from the TaskView ===============================================================
00121 
00122 
00123 void TaskDlgFilletParameters::open()
00124 {
00125     
00126 }
00127 
00128 void TaskDlgFilletParameters::clicked(int)
00129 {
00130     
00131 }
00132 
00133 bool TaskDlgFilletParameters::accept()
00134 {
00135     std::string name = FilletView->getObject()->getNameInDocument();
00136 
00137     //Gui::Command::openCommand("Fillet changed");
00138     Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Radius = %f",name.c_str(),parameter->getLength());
00139     Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()");
00140     Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
00141     Gui::Command::commitCommand();
00142 
00143     return true;
00144 }
00145 
00146 bool TaskDlgFilletParameters::reject()
00147 {
00148     // get the support and Sketch
00149     PartDesign::Fillet* pcFillet = static_cast<PartDesign::Fillet*>(FilletView->getObject()); 
00150     App::DocumentObject    *pcSupport;
00151     pcSupport = pcFillet->Base.getValue();
00152 
00153     // role back the done things
00154     Gui::Command::abortCommand();
00155     Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
00156     
00157     // if abort command deleted the object the support is visible again
00158     if (!Gui::Application::Instance->getViewProvider(pcFillet)) {
00159         if (pcSupport && Gui::Application::Instance->getViewProvider(pcSupport))
00160             Gui::Application::Instance->getViewProvider(pcSupport)->show();
00161     }
00162 
00163     return true;
00164 }
00165 
00166 
00167 
00168 #include "moc_TaskFilletParameters.cpp"

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