1
/***************************************************************************
2
* Copyright (c) 2008 Werner Mayer <wmayer@users.sourceforge.net> *
4
* This file is part of the FreeCAD CAx development system. *
6
* This library is free software; you can redistribute it and/or *
7
* modify it under the terms of the GNU Library General Public *
8
* License as published by the Free Software Foundation; either *
9
* version 2 of the License, or (at your option) any later version. *
11
* This library is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU Library General Public License for more details. *
16
* You should have received a copy of the GNU Library General Public *
17
* License along with this library; see the file COPYING.LIB. If not, *
18
* write to the Free Software Foundation, Inc., 59 Temple Place, *
19
* Suite 330, Boston, MA 02111-1307, USA *
21
***************************************************************************/
24
#include "PreCompiled.h"
25
#include <Gui/Qt4All.h>
27
#include "DlgExtrusion.h"
28
#include "../App/PartFeature.h"
29
#include <App/Application.h>
30
#include <App/Document.h>
31
#include <App/DocumentObject.h>
32
#include <Gui/Application.h>
33
#include <Gui/Command.h>
34
#include <Gui/Document.h>
35
#include <Gui/ViewProvider.h>
37
using namespace PartGui;
39
DlgExtrusion::DlgExtrusion(QWidget* parent, Qt::WFlags fl)
43
ui.okButton->setDisabled(true);
48
* Destroys the object and frees any allocated resources
50
DlgExtrusion::~DlgExtrusion()
52
// no need to delete child widgets, Qt does it all for us
55
void DlgExtrusion::findShapes()
57
App::Document* activeDoc = App::GetApplication().getActiveDocument();
58
if (!activeDoc) return;
59
Gui::Document* activeGui = Gui::Application::Instance->getDocument(activeDoc);
61
std::vector<App::DocumentObject*> objs = activeDoc->getObjectsOfType
62
(Part::Feature::getClassTypeId());
63
for (std::vector<App::DocumentObject*>::iterator it = objs.begin(); it!=objs.end(); ++it) {
64
TopoDS_Shape shape = static_cast<Part::Feature*>(*it)->Shape.getValue();
65
TopAbs_ShapeEnum type = shape.ShapeType();
66
if (type == TopAbs_VERTEX || type == TopAbs_EDGE ||
67
type == TopAbs_WIRE || type == TopAbs_FACE ||
68
type == TopAbs_SHELL) {
69
QTreeWidgetItem* item = new QTreeWidgetItem(ui.treeWidget);
70
item->setText(0, QString::fromUtf8((*it)->Label.getValue()));
71
item->setData(0, Qt::UserRole, QString::fromAscii((*it)->getNameInDocument()));
72
Gui::ViewProvider* vp = activeGui->getViewProvider(*it);
74
item->setIcon(0, vp->getIcon());
79
void DlgExtrusion::accept()
81
App::Document* activeDoc = App::GetApplication().getActiveDocument();
82
activeDoc->openTransaction("Extrude");
84
QString shape, type, name;
85
QList<QTreeWidgetItem *> items = ui.treeWidget->selectedItems();
86
for (QList<QTreeWidgetItem *>::iterator it = items.begin(); it != items.end(); ++it) {
87
shape = (*it)->data(0, Qt::UserRole).toString();
88
type = QString::fromAscii("Part::Extrusion");
89
name = QString::fromAscii(activeDoc->getUniqueObjectName("Extrude").c_str());
90
double len = ui.dirLen->value();
92
QString code = QString::fromAscii(
93
"FreeCAD.ActiveDocument.addObject(\"%1\",\"%2\")\n"
94
"FreeCAD.ActiveDocument.%2.Base = FreeCAD.ActiveDocument.%3\n"
95
"FreeCAD.ActiveDocument.%2.Dir = (%4,%5,%6)\n"
96
"FreeCADGui.ActiveDocument.%3.Visibility = False\n")
97
.arg(type).arg(name).arg(shape)
98
.arg(ui.dirX->value()*len)
99
.arg(ui.dirY->value()*len)
100
.arg(ui.dirZ->value()*len);
101
Gui::Application::Instance->runPythonCode((const char*)code.toAscii());
104
activeDoc->commitTransaction();
105
activeDoc->recompute();
110
void DlgExtrusion::on_treeWidget_itemSelectionChanged()
112
ui.okButton->setEnabled(!ui.treeWidget->selectedItems().isEmpty());
115
void DlgExtrusion::on_checkNormal_toggled(bool b)
117
ui.dirX->setDisabled(b);
118
ui.dirY->setDisabled(b);
119
ui.dirZ->setDisabled(b);
122
#include "moc_DlgExtrusion.cpp"