TaskPadParameters.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "PreCompiled.h"
00025
00026 #ifndef _PreComp_
00027 # include <QMessageBox>
00028 #endif
00029
00030 #include "ui_TaskPadParameters.h"
00031 #include "TaskPadParameters.h"
00032 #include <App/Application.h>
00033 #include <App/Document.h>
00034 #include <Gui/Application.h>
00035 #include <Gui/Document.h>
00036 #include <Gui/BitmapFactory.h>
00037 #include <Gui/ViewProvider.h>
00038 #include <Gui/WaitCursor.h>
00039 #include <Base/Console.h>
00040 #include <Gui/Selection.h>
00041 #include <Gui/Command.h>
00042 #include <Mod/PartDesign/App/FeaturePad.h>
00043 #include <Mod/Sketcher/App/SketchObject.h>
00044
00045
00046 using namespace PartDesignGui;
00047 using namespace Gui;
00048
00049
00050
00051 TaskPadParameters::TaskPadParameters(ViewProviderPad *PadView,QWidget *parent)
00052 : TaskBox(Gui::BitmapFactory().pixmap("PartDesign_Pad"),tr("Pad parameters"),true, parent),PadView(PadView)
00053 {
00054
00055 proxy = new QWidget(this);
00056 ui = new Ui_TaskPadParameters();
00057 ui->setupUi(proxy);
00058 QMetaObject::connectSlotsByName(this);
00059
00060 connect(ui->doubleSpinBox, SIGNAL(valueChanged(double)),
00061 this, SLOT(onLengthChanged(double)));
00062 connect(ui->checkBoxMirrored, SIGNAL(toggled(bool)),
00063 this, SLOT(onMirrored(bool)));
00064 connect(ui->checkBoxReversed, SIGNAL(toggled(bool)),
00065 this, SLOT(onReversed(bool)));
00066
00067 this->groupLayout()->addWidget(proxy);
00068
00069 PartDesign::Pad* pcPad = static_cast<PartDesign::Pad*>(PadView->getObject());
00070 double l = pcPad->Length.getValue();
00071 bool mirrored = pcPad->MirroredExtent.getValue();
00072 bool reversed = pcPad->Reversed.getValue();
00073
00074 ui->doubleSpinBox->setValue(l);
00075 ui->doubleSpinBox->selectAll();
00076 ui->checkBoxMirrored->setChecked(mirrored);
00077
00078
00079 Sketcher::SketchObject *pcSketch;
00080 if (pcPad->Sketch.getValue()) {
00081 pcSketch = static_cast<Sketcher::SketchObject*>(pcPad->Sketch.getValue());
00082 if (pcSketch->Support.getValue())
00083
00084 ui->checkBoxReversed->setEnabled(0);
00085 else
00086 ui->checkBoxReversed->setChecked(reversed);
00087 }
00088
00089 ui->checkBoxReversed->setChecked(reversed);
00090
00091 setFocus ();
00092 }
00093
00094 void TaskPadParameters::onLengthChanged(double len)
00095 {
00096 PartDesign::Pad* pcPad = static_cast<PartDesign::Pad*>(PadView->getObject());
00097 pcPad->Length.setValue((float)len);
00098 pcPad->getDocument()->recomputeFeature(pcPad);
00099 }
00100
00101 void TaskPadParameters::onMirrored(bool on)
00102 {
00103 PartDesign::Pad* pcPad = static_cast<PartDesign::Pad*>(PadView->getObject());
00104 pcPad->MirroredExtent.setValue(on);
00105 pcPad->getDocument()->recomputeFeature(pcPad);
00106 }
00107
00108 void TaskPadParameters::onReversed(bool on)
00109 {
00110 PartDesign::Pad* pcPad = static_cast<PartDesign::Pad*>(PadView->getObject());
00111 pcPad->Reversed.setValue(on);
00112 pcPad->getDocument()->recomputeFeature(pcPad);
00113 }
00114
00115 double TaskPadParameters::getLength(void) const
00116 {
00117 return ui->doubleSpinBox->value();
00118 }
00119
00120 bool TaskPadParameters::getReversed(void) const
00121 {
00122 return ui->checkBoxReversed->isChecked();
00123 }
00124
00125 bool TaskPadParameters::getMirroredExtent(void) const
00126 {
00127 return ui->checkBoxMirrored->isChecked();
00128 }
00129
00130 TaskPadParameters::~TaskPadParameters()
00131 {
00132 delete ui;
00133 }
00134
00135 void TaskPadParameters::changeEvent(QEvent *e)
00136 {
00137 TaskBox::changeEvent(e);
00138 if (e->type() == QEvent::LanguageChange) {
00139 ui->retranslateUi(proxy);
00140 }
00141 }
00142
00143
00144
00145
00146
00147
00148 TaskDlgPadParameters::TaskDlgPadParameters(ViewProviderPad *PadView)
00149 : TaskDialog(),PadView(PadView)
00150 {
00151 assert(PadView);
00152 parameter = new TaskPadParameters(PadView);
00153
00154 Content.push_back(parameter);
00155 }
00156
00157 TaskDlgPadParameters::~TaskDlgPadParameters()
00158 {
00159
00160 }
00161
00162
00163
00164
00165 void TaskDlgPadParameters::open()
00166 {
00167
00168 }
00169
00170 void TaskDlgPadParameters::clicked(int)
00171 {
00172
00173 }
00174
00175 bool TaskDlgPadParameters::accept()
00176 {
00177 std::string name = PadView->getObject()->getNameInDocument();
00178
00179 try {
00180
00181 Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Length = %f",name.c_str(),parameter->getLength());
00182 Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %i",name.c_str(),parameter->getReversed()?1:0);
00183 Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.MirroredExtent = %i",name.c_str(),parameter->getMirroredExtent()?1:0);
00184 Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()");
00185 Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
00186 Gui::Command::commitCommand();
00187 }
00188 catch (const Base::Exception& e) {
00189 QMessageBox::warning(parameter, tr("Input error"), QString::fromAscii(e.what()));
00190 return false;
00191 }
00192
00193 return true;
00194 }
00195
00196 bool TaskDlgPadParameters::reject()
00197 {
00198
00199 PartDesign::Pad* pcPad = static_cast<PartDesign::Pad*>(PadView->getObject());
00200 Sketcher::SketchObject *pcSketch;
00201 App::DocumentObject *pcSupport;
00202 if (pcPad->Sketch.getValue()) {
00203 pcSketch = static_cast<Sketcher::SketchObject*>(pcPad->Sketch.getValue());
00204 pcSupport = pcSketch->Support.getValue();
00205 }
00206
00207
00208 Gui::Command::abortCommand();
00209 Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
00210
00211
00212 if (!Gui::Application::Instance->getViewProvider(pcPad)) {
00213 if (pcSketch && Gui::Application::Instance->getViewProvider(pcSketch))
00214 Gui::Application::Instance->getViewProvider(pcSketch)->show();
00215 if (pcSupport && Gui::Application::Instance->getViewProvider(pcSupport))
00216 Gui::Application::Instance->getViewProvider(pcSupport)->show();
00217 }
00218
00219
00220
00221
00222 return true;
00223 }
00224
00225
00226
00227 #include "moc_TaskPadParameters.cpp"