TaskPocketParameters.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_TaskPocketParameters.h"
00030 #include "TaskPocketParameters.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/FeaturePocket.h>
00042 #include <Mod/Sketcher/App/SketchObject.h>
00043 
00044 
00045 using namespace PartDesignGui;
00046 using namespace Gui;
00047 
00048 /* TRANSLATOR PartDesignGui::TaskPocketParameters */
00049 
00050 TaskPocketParameters::TaskPocketParameters(ViewProviderPocket *PocketView,QWidget *parent)
00051     : TaskBox(Gui::BitmapFactory().pixmap("PartDesign_Pocket"),tr("Pocket parameters"),true, parent),PocketView(PocketView)
00052 {
00053     // we need a separate container widget to add all controls to
00054     proxy = new QWidget(this);
00055     ui = new Ui_TaskPocketParameters();
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::Pocket* pcPocket = static_cast<PartDesign::Pocket*>(PocketView->getObject());
00065     double l = pcPocket->Length.getValue();
00066 
00067     ui->doubleSpinBox->setMaximum(INT_MAX);
00068     ui->doubleSpinBox->setValue(l);
00069     ui->doubleSpinBox->selectAll();
00070  
00072     //Sketcher::SketchObject *pcSketch;
00073     //if (pcPocket->Sketch.getValue()) {
00074     //    pcSketch = static_cast<Sketcher::SketchObject*>(pcPocket->Sketch.getValue());
00075     //    if (pcSketch->Support.getValue())
00076     //        // in case of sketch with support, reverse makes no sense (goes into the part)
00077     //        ui->checkBoxReversed->setEnabled(0);
00078     //    else
00079     //        ui->checkBoxReversed->setChecked(reversed);
00080     //}
00081 
00082     setFocus ();
00083 }
00084 
00085 void TaskPocketParameters::onLengthChanged(double len)
00086 {
00087     PartDesign::Pocket* pcPocket = static_cast<PartDesign::Pocket*>(PocketView->getObject());
00088     pcPocket->Length.setValue((float)len);
00089     pcPocket->getDocument()->recomputeFeature(pcPocket);
00090 }
00091 
00092 double TaskPocketParameters::getLength(void) const
00093 {
00094     return ui->doubleSpinBox->value();
00095 }
00096 
00097 
00098 TaskPocketParameters::~TaskPocketParameters()
00099 {
00100     delete ui;
00101 }
00102 
00103 void TaskPocketParameters::changeEvent(QEvent *e)
00104 {
00105     TaskBox::changeEvent(e);
00106     if (e->type() == QEvent::LanguageChange) {
00107         ui->retranslateUi(proxy);
00108     }
00109 }
00110 
00111 //**************************************************************************
00112 //**************************************************************************
00113 // TaskDialog
00114 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00115 
00116 TaskDlgPocketParameters::TaskDlgPocketParameters(ViewProviderPocket *PocketView)
00117     : TaskDialog(),PocketView(PocketView)
00118 {
00119     assert(PocketView);
00120     parameter  = new TaskPocketParameters(PocketView);
00121 
00122     Content.push_back(parameter);
00123 }
00124 
00125 TaskDlgPocketParameters::~TaskDlgPocketParameters()
00126 {
00127 
00128 }
00129 
00130 //==== calls from the TaskView ===============================================================
00131 
00132 
00133 void TaskDlgPocketParameters::open()
00134 {
00135     
00136 }
00137 
00138 void TaskDlgPocketParameters::clicked(int)
00139 {
00140     
00141 }
00142 
00143 bool TaskDlgPocketParameters::accept()
00144 {
00145     std::string name = PocketView->getObject()->getNameInDocument();
00146 
00147     //Gui::Command::openCommand("Pocket changed");
00148     Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Length = %f",name.c_str(),parameter->getLength());
00149     Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()");
00150     Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
00151     Gui::Command::commitCommand();
00152 
00153     return true;
00154 }
00155 
00156 bool TaskDlgPocketParameters::reject()
00157 {
00158     // get the support and Sketch
00159     PartDesign::Pocket* pcPocket = static_cast<PartDesign::Pocket*>(PocketView->getObject()); 
00160     Sketcher::SketchObject *pcSketch;
00161     App::DocumentObject    *pcSupport;
00162     if (pcPocket->Sketch.getValue()) {
00163         pcSketch = static_cast<Sketcher::SketchObject*>(pcPocket->Sketch.getValue()); 
00164         pcSupport = pcSketch->Support.getValue();
00165     }
00166 
00167     // role back the done things
00168     Gui::Command::abortCommand();
00169     Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
00170     
00171     // if abort command deleted the object the support is visible again
00172     if (!Gui::Application::Instance->getViewProvider(pcPocket)) {
00173         if (pcSketch && Gui::Application::Instance->getViewProvider(pcSketch))
00174             Gui::Application::Instance->getViewProvider(pcSketch)->show();
00175         if (pcSupport && Gui::Application::Instance->getViewProvider(pcSupport))
00176             Gui::Application::Instance->getViewProvider(pcSupport)->show();
00177     }
00178 
00179     //Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()");
00180     //Gui::Command::commitCommand();
00181 
00182     return true;
00183 }
00184 
00185 
00186 
00187 #include "moc_TaskPocketParameters.cpp"

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