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 #ifndef _PreComp_
00026 # include <QMessageBox>
00027 # include <TopExp_Explorer.hxx>
00028 #endif
00029
00030 #include "ui_DlgRevolution.h"
00031 #include "DlgRevolution.h"
00032 #include "../App/PartFeature.h"
00033 #include <App/Application.h>
00034 #include <App/Document.h>
00035 #include <App/DocumentObject.h>
00036 #include <Gui/Application.h>
00037 #include <Gui/BitmapFactory.h>
00038 #include <Gui/Command.h>
00039 #include <Gui/Document.h>
00040 #include <Gui/Utilities.h>
00041 #include <Gui/ViewProvider.h>
00042 #include <Gui/WaitCursor.h>
00043
00044 using namespace PartGui;
00045
00046 DlgRevolution::DlgRevolution(QWidget* parent, Qt::WFlags fl)
00047 : Gui::LocationDialog(parent, fl)
00048 {
00049 ui = new Ui_RevolutionComp(this);
00050 ui->baseX->setRange(-DBL_MAX,DBL_MAX);
00051 ui->baseY->setRange(-DBL_MAX,DBL_MAX);
00052 ui->baseZ->setRange(-DBL_MAX,DBL_MAX);
00053 findShapes();
00054
00055 Gui::ItemViewSelection sel(ui->treeWidget);
00056 sel.applyFrom(Gui::Selection().getObjectsOfType(Part::Feature::getClassTypeId()));
00057 }
00058
00059
00060
00061
00062 DlgRevolution::~DlgRevolution()
00063 {
00064
00065 delete ui;
00066 }
00067
00068 void DlgRevolution::directionActivated(int index)
00069 {
00070 ui->directionActivated(this, index);
00071 }
00072
00073 Base::Vector3f DlgRevolution::getDirection() const
00074 {
00075 return ui->getDirection();
00076 }
00077
00078 void DlgRevolution::changeEvent(QEvent *e)
00079 {
00080 if (e->type() == QEvent::LanguageChange) {
00081 ui->retranslate(this);
00082 }
00083 else {
00084 QDialog::changeEvent(e);
00085 }
00086 }
00087
00088 void DlgRevolution::findShapes()
00089 {
00090 App::Document* activeDoc = App::GetApplication().getActiveDocument();
00091 if (!activeDoc) return;
00092 Gui::Document* activeGui = Gui::Application::Instance->getDocument(activeDoc);
00093
00094 std::vector<App::DocumentObject*> objs = activeDoc->getObjectsOfType
00095 (Part::Feature::getClassTypeId());
00096 for (std::vector<App::DocumentObject*>::iterator it = objs.begin(); it!=objs.end(); ++it) {
00097 const TopoDS_Shape& shape = static_cast<Part::Feature*>(*it)->Shape.getValue();
00098 if (shape.IsNull()) continue;
00099
00100 TopExp_Explorer xp;
00101 xp.Init(shape,TopAbs_SOLID);
00102 if (xp.More()) continue;
00103 xp.Init(shape,TopAbs_COMPSOLID);
00104 if (xp.More()) continue;
00105
00106 QTreeWidgetItem* item = new QTreeWidgetItem(ui->treeWidget);
00107 item->setText(0, QString::fromUtf8((*it)->Label.getValue()));
00108 item->setData(0, Qt::UserRole, QString::fromAscii((*it)->getNameInDocument()));
00109 Gui::ViewProvider* vp = activeGui->getViewProvider(*it);
00110 if (vp) item->setIcon(0, vp->getIcon());
00111 }
00112 }
00113
00114 void DlgRevolution::accept()
00115 {
00116 if (ui->treeWidget->selectedItems().isEmpty()) {
00117 QMessageBox::critical(this, windowTitle(),
00118 tr("Select a shape for revolution, first."));
00119 return;
00120 }
00121
00122 Gui::WaitCursor wc;
00123 App::Document* activeDoc = App::GetApplication().getActiveDocument();
00124 activeDoc->openTransaction("Revolve");
00125
00126 QString shape, type, name;
00127 QList<QTreeWidgetItem *> items = ui->treeWidget->selectedItems();
00128 for (QList<QTreeWidgetItem *>::iterator it = items.begin(); it != items.end(); ++it) {
00129 shape = (*it)->data(0, Qt::UserRole).toString();
00130 type = QString::fromAscii("Part::Revolution");
00131 name = QString::fromAscii(activeDoc->getUniqueObjectName("Revolve").c_str());
00132 Base::Vector3f axis = this->getDirection();
00133
00134 QString code = QString::fromAscii(
00135 "FreeCAD.ActiveDocument.addObject(\"%1\",\"%2\")\n"
00136 "FreeCAD.ActiveDocument.%2.Source = FreeCAD.ActiveDocument.%3\n"
00137 "FreeCAD.ActiveDocument.%2.Axis = (%4,%5,%6)\n"
00138 "FreeCAD.ActiveDocument.%2.Base = (%7,%8,%9)\n"
00139 "FreeCAD.ActiveDocument.%2.Angle = %10\n"
00140 "FreeCADGui.ActiveDocument.%3.Visibility = False\n")
00141 .arg(type).arg(name).arg(shape)
00142 .arg(axis.x,0,'f',2)
00143 .arg(axis.y,0,'f',2)
00144 .arg(axis.z,0,'f',2)
00145 .arg(ui->baseX->value(),0,'f',2)
00146 .arg(ui->baseY->value(),0,'f',2)
00147 .arg(ui->baseZ->value(),0,'f',2)
00148 .arg(ui->angle->value(),0,'f',2);
00149 Gui::Application::Instance->runPythonCode((const char*)code.toAscii());
00150 QByteArray to = name.toAscii();
00151 QByteArray from = shape.toAscii();
00152 Gui::Command::copyVisual(to, "ShapeColor", from);
00153 Gui::Command::copyVisual(to, "LineColor", from);
00154 Gui::Command::copyVisual(to, "PointColor", from);
00155 }
00156
00157 activeDoc->commitTransaction();
00158 activeDoc->recompute();
00159 QDialog::accept();
00160 }
00161
00162
00163
00164 TaskRevolution::TaskRevolution()
00165 {
00166 widget = new DlgRevolution();
00167 taskbox = new Gui::TaskView::TaskBox(
00168 Gui::BitmapFactory().pixmap("Part_Revolve"),
00169 widget->windowTitle(), true, 0);
00170 taskbox->groupLayout()->addWidget(widget);
00171 Content.push_back(taskbox);
00172 }
00173
00174 TaskRevolution::~TaskRevolution()
00175 {
00176
00177 }
00178
00179 bool TaskRevolution::accept()
00180 {
00181 widget->accept();
00182 return (widget->result() == QDialog::Accepted);
00183 }
00184
00185 #include "moc_DlgRevolution.cpp"