~ubuntu-branches/ubuntu/maverick/freecad/maverick

« back to all changes in this revision

Viewing changes to src/Mod/Part/Gui/DlgExtrusion.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Teemu Ikonen
  • Date: 2009-07-16 18:37:41 UTC
  • Revision ID: james.westby@ubuntu.com-20090716183741-oww9kcxqrk991i1n
Tags: upstream-0.8.2237
ImportĀ upstreamĀ versionĀ 0.8.2237

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (c) 2008 Werner Mayer <wmayer@users.sourceforge.net>        *
 
3
 *                                                                         *
 
4
 *   This file is part of the FreeCAD CAx development system.              *
 
5
 *                                                                         *
 
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.      *
 
10
 *                                                                         *
 
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.                  *
 
15
 *                                                                         *
 
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                                *
 
20
 *                                                                         *
 
21
 ***************************************************************************/
 
22
 
 
23
 
 
24
#include "PreCompiled.h"
 
25
#include <Gui/Qt4All.h>
 
26
 
 
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>
 
36
 
 
37
using namespace PartGui;
 
38
 
 
39
DlgExtrusion::DlgExtrusion(QWidget* parent, Qt::WFlags fl)
 
40
  : QDialog(parent, fl)
 
41
{
 
42
    ui.setupUi(this);
 
43
    ui.okButton->setDisabled(true);
 
44
    findShapes();
 
45
}
 
46
 
 
47
/*  
 
48
 *  Destroys the object and frees any allocated resources
 
49
 */
 
50
DlgExtrusion::~DlgExtrusion()
 
51
{
 
52
    // no need to delete child widgets, Qt does it all for us
 
53
}
 
54
 
 
55
void DlgExtrusion::findShapes()
 
56
{
 
57
    App::Document* activeDoc = App::GetApplication().getActiveDocument();
 
58
    if (!activeDoc) return;
 
59
    Gui::Document* activeGui = Gui::Application::Instance->getDocument(activeDoc);
 
60
 
 
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);
 
73
            if (vp)
 
74
                item->setIcon(0, vp->getIcon());
 
75
        }
 
76
    }
 
77
}
 
78
 
 
79
void DlgExtrusion::accept()
 
80
{
 
81
    App::Document* activeDoc = App::GetApplication().getActiveDocument();
 
82
    activeDoc->openTransaction("Extrude");
 
83
 
 
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();
 
91
 
 
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());
 
102
    }
 
103
 
 
104
    activeDoc->commitTransaction();
 
105
    activeDoc->recompute();
 
106
 
 
107
    QDialog::accept();
 
108
}
 
109
 
 
110
void DlgExtrusion::on_treeWidget_itemSelectionChanged()
 
111
{
 
112
    ui.okButton->setEnabled(!ui.treeWidget->selectedItems().isEmpty());
 
113
}
 
114
 
 
115
void DlgExtrusion::on_checkNormal_toggled(bool b)
 
116
{
 
117
    ui.dirX->setDisabled(b);
 
118
    ui.dirY->setDisabled(b);
 
119
    ui.dirZ->setDisabled(b);
 
120
}
 
121
 
 
122
#include "moc_DlgExtrusion.cpp"