TaskRevolutionParameters.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 #endif
00028
00029 #include "ui_TaskRevolutionParameters.h"
00030 #include "TaskRevolutionParameters.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/FeatureRevolution.h>
00042 #include <Mod/Sketcher/App/SketchObject.h>
00043
00044
00045 using namespace PartDesignGui;
00046 using namespace Gui;
00047
00048
00049
00050 TaskRevolutionParameters::TaskRevolutionParameters(ViewProviderRevolution *RevolutionView,QWidget *parent)
00051 : TaskBox(Gui::BitmapFactory().pixmap("PartDesign_Revolution"),tr("Revolution parameters"),true, parent),RevolutionView(RevolutionView)
00052 {
00053
00054 proxy = new QWidget(this);
00055 ui = new Ui_TaskRevolutionParameters();
00056 ui->setupUi(proxy);
00057 QMetaObject::connectSlotsByName(this);
00058
00059 connect(ui->doubleSpinBox, SIGNAL(valueChanged(double)),
00060 this, SLOT(onAngleChanged(double)));
00061 connect(ui->axis, SIGNAL(activated(int)),
00062 this, SLOT(onAxisChanged(int)));
00063
00064 this->groupLayout()->addWidget(proxy);
00065
00066 PartDesign::Revolution* pcRevolution = static_cast<PartDesign::Revolution*>(RevolutionView->getObject());
00067 double l = pcRevolution->Angle.getValue();
00068 Base::Vector3f Ax = pcRevolution->Axis.getValue();
00069
00070 ui->doubleSpinBox->setValue(l);
00071 if(Ax.y > 0)
00072 ui->axis->setCurrentIndex(0);
00073 else
00074 ui->axis->setCurrentIndex(1);
00075
00076 setFocus ();
00077 }
00078
00079 void TaskRevolutionParameters::onAngleChanged(double len)
00080 {
00081 PartDesign::Revolution* pcRevolution = static_cast<PartDesign::Revolution*>(RevolutionView->getObject());
00082 pcRevolution->Angle.setValue((float)len);
00083 pcRevolution->getDocument()->recomputeFeature(pcRevolution);
00084 }
00085
00086 void TaskRevolutionParameters::onAxisChanged(int num)
00087 {
00088 PartDesign::Revolution* pcRevolution = static_cast<PartDesign::Revolution*>(RevolutionView->getObject());
00089 if(num == 0)
00090 pcRevolution->Axis.setValue(Base::Vector3f(0,1,0));
00091 else
00092 pcRevolution->Axis.setValue(Base::Vector3f(1,0,0));
00093
00094 pcRevolution->getDocument()->recomputeFeature(pcRevolution);
00095 }
00096
00097
00098 double TaskRevolutionParameters::getAngle(void) const
00099 {
00100 return ui->doubleSpinBox->value();
00101 }
00102
00103 Base::Vector3f TaskRevolutionParameters::getAxis(void) const
00104 {
00105 if( ui->axis->currentIndex() == 0)
00106 return Base::Vector3f(0,1,0);
00107 else
00108 return Base::Vector3f(1,0,0);
00109
00110 }
00111
00112
00113 TaskRevolutionParameters::~TaskRevolutionParameters()
00114 {
00115 delete ui;
00116 }
00117
00118 void TaskRevolutionParameters::changeEvent(QEvent *e)
00119 {
00120 TaskBox::changeEvent(e);
00121 if (e->type() == QEvent::LanguageChange) {
00122 ui->retranslateUi(proxy);
00123 }
00124 }
00125
00126
00127
00128
00129
00130
00131 TaskDlgRevolutionParameters::TaskDlgRevolutionParameters(ViewProviderRevolution *RevolutionView)
00132 : TaskDialog(),RevolutionView(RevolutionView)
00133 {
00134 assert(RevolutionView);
00135 parameter = new TaskRevolutionParameters(RevolutionView);
00136
00137 Content.push_back(parameter);
00138 }
00139
00140 TaskDlgRevolutionParameters::~TaskDlgRevolutionParameters()
00141 {
00142
00143 }
00144
00145
00146
00147
00148 void TaskDlgRevolutionParameters::open()
00149 {
00150
00151 }
00152
00153 void TaskDlgRevolutionParameters::clicked(int)
00154 {
00155
00156 }
00157
00158 bool TaskDlgRevolutionParameters::accept()
00159 {
00160 std::string name = RevolutionView->getObject()->getNameInDocument();
00161
00162
00163 Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Angle = %f",name.c_str(),parameter->getAngle());
00164 Base::Vector3f axis = parameter->getAxis();
00165 Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Axis = FreeCAD.Vector(%f,%f,%f)",name.c_str(),axis.x,axis.y,axis.z);
00166 Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()");
00167 Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
00168 Gui::Command::commitCommand();
00169
00170 return true;
00171 }
00172
00173 bool TaskDlgRevolutionParameters::reject()
00174 {
00175
00176 PartDesign::Revolution* pcRevolution = static_cast<PartDesign::Revolution*>(RevolutionView->getObject());
00177 Sketcher::SketchObject *pcSketch;
00178 App::DocumentObject *pcSupport;
00179 if (pcRevolution->Sketch.getValue()) {
00180 pcSketch = static_cast<Sketcher::SketchObject*>(pcRevolution->Sketch.getValue());
00181 pcSupport = pcSketch->Support.getValue();
00182 }
00183
00184
00185 Gui::Command::abortCommand();
00186 Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
00187
00188
00189 if (!Gui::Application::Instance->getViewProvider(pcRevolution)) {
00190 if (pcSketch && Gui::Application::Instance->getViewProvider(pcSketch))
00191 Gui::Application::Instance->getViewProvider(pcSketch)->show();
00192 if (pcSupport && Gui::Application::Instance->getViewProvider(pcSupport))
00193 Gui::Application::Instance->getViewProvider(pcSupport)->show();
00194 }
00195
00196
00197
00198
00199 return true;
00200 }
00201
00202
00203
00204 #include "moc_TaskRevolutionParameters.cpp"