FreeCAD

Форк
0
/
TaskDialog.cpp 
160 строк · 7.2 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2009 Werner Mayer <wmayer[at]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
#include "PreCompiled.h"
24
#ifndef _PreComp_
25
#include <QCheckBox>
26
#include <QMessageBox>
27
#endif
28

29
#include <Gui/Application.h>
30
#include <Gui/Command.h>
31
#include <Gui/Document.h>
32
#include <Gui/Selection.h>
33
#include <Gui/View3DInventor.h>
34
#include <Gui/View3DInventorViewer.h>
35
#include <Mod/Part/App/PartFeature.h>
36

37
#include "TaskDialog.h"
38

39

40
using namespace DrawingGui;
41

42
/* TRANSLATOR DrawingGui::TaskProjection */
43

44
TaskProjection::TaskProjection()
45
{
46
    QString texts[10] = {tr("Visible sharp edges"),
47
                         tr("Visible smooth edges"),
48
                         tr("Visible sewn edges"),
49
                         tr("Visible outline edges"),
50
                         tr("Visible isoparameters"),
51
                         tr("Hidden sharp edges"),
52
                         tr("Hidden smooth edges"),
53
                         tr("Hidden sewn edges"),
54
                         tr("Hidden outline edges"),
55
                         tr("Hidden isoparameters")};
56
    widget = new QWidget();
57
    QVBoxLayout* mainLayout = new QVBoxLayout;
58

59
    for (int i = 0; i < 10; i++) {
60
        QCheckBox* cb = new QCheckBox();
61
        if (i < 5) {
62
            cb->setChecked(true);
63
        }
64
        cb->setText(texts[i]);
65
        mainLayout->addWidget(cb);
66
        boxes.push_back(cb);
67
    }
68

69
    widget->setLayout(mainLayout);
70
    widget->setWindowTitle(tr("Project shapes"));
71

72
    addTaskBox(widget, false);
73
}
74

75
TaskProjection::~TaskProjection()
76
{
77
    // automatically deleted in the sub-class
78
}
79

80
bool TaskProjection::accept()
81
{
82
    Gui::Document* document = Gui::Application::Instance->activeDocument();
83
    if (!document) {
84
        QMessageBox::warning(widget,
85
                             tr("No active document"),
86
                             tr("There is currently no active document to complete the operation"));
87
        return true;
88
    }
89
    std::list<Gui::MDIView*> mdis =
90
        document->getMDIViewsOfType(Gui::View3DInventor::getClassTypeId());
91
    if (mdis.empty()) {
92
        QMessageBox::warning(widget,
93
                             tr("No active view"),
94
                             tr("There is currently no active view to complete the operation"));
95
        return false;
96
    }
97

98
    Gui::View3DInventorViewer* viewer =
99
        static_cast<Gui::View3DInventor*>(mdis.front())->getViewer();
100
    SbVec3f pnt, dir;
101
    viewer->getNearPlane(pnt, dir);
102
    float x = 0, y = 1, z = 1;
103
    dir.getValue(x, y, z);
104

105
    std::vector<Part::Feature*> shapes = Gui::Selection().getObjectsOfType<Part::Feature>();
106
    Gui::Command::openCommand("Project shape");
107
    Gui::Command::addModule(Gui::Command::Doc, "Drawing");
108
    for (std::vector<Part::Feature*>::iterator it = shapes.begin(); it != shapes.end(); ++it) {
109
        const char* object = (*it)->getNameInDocument();
110
        Gui::Command::doCommand(
111
            Gui::Command::Doc,
112
            "FreeCAD.ActiveDocument.addObject('Drawing::FeatureProjection','%s_proj')",
113
            object);
114
        Gui::Command::doCommand(
115
            Gui::Command::Doc,
116
            "FreeCAD.ActiveDocument.ActiveObject.Direction=FreeCAD.Vector(%f,%f,%f)",
117
            x,
118
            y,
119
            z);
120
        Gui::Command::doCommand(
121
            Gui::Command::Doc,
122
            "FreeCAD.ActiveDocument.ActiveObject.Source=FreeCAD.ActiveDocument.%s",
123
            object);
124
        Gui::Command::doCommand(Gui::Command::Doc,
125
                                "FreeCAD.ActiveDocument.ActiveObject.VCompound=%s",
126
                                (boxes[0]->isChecked() ? "True" : "False"));
127
        Gui::Command::doCommand(Gui::Command::Doc,
128
                                "FreeCAD.ActiveDocument.ActiveObject.Rg1LineVCompound=%s",
129
                                (boxes[1]->isChecked() ? "True" : "False"));
130
        Gui::Command::doCommand(Gui::Command::Doc,
131
                                "FreeCAD.ActiveDocument.ActiveObject.RgNLineVCompound=%s",
132
                                (boxes[2]->isChecked() ? "True" : "False"));
133
        Gui::Command::doCommand(Gui::Command::Doc,
134
                                "FreeCAD.ActiveDocument.ActiveObject.OutLineVCompound=%s",
135
                                (boxes[3]->isChecked() ? "True" : "False"));
136
        Gui::Command::doCommand(Gui::Command::Doc,
137
                                "FreeCAD.ActiveDocument.ActiveObject.IsoLineVCompound=%s",
138
                                (boxes[4]->isChecked() ? "True" : "False"));
139
        Gui::Command::doCommand(Gui::Command::Doc,
140
                                "FreeCAD.ActiveDocument.ActiveObject.HCompound=%s",
141
                                (boxes[5]->isChecked() ? "True" : "False"));
142
        Gui::Command::doCommand(Gui::Command::Doc,
143
                                "FreeCAD.ActiveDocument.ActiveObject.Rg1LineHCompound=%s",
144
                                (boxes[6]->isChecked() ? "True" : "False"));
145
        Gui::Command::doCommand(Gui::Command::Doc,
146
                                "FreeCAD.ActiveDocument.ActiveObject.RgNLineHCompound=%s",
147
                                (boxes[7]->isChecked() ? "True" : "False"));
148
        Gui::Command::doCommand(Gui::Command::Doc,
149
                                "FreeCAD.ActiveDocument.ActiveObject.OutLineHCompound=%s",
150
                                (boxes[8]->isChecked() ? "True" : "False"));
151
        Gui::Command::doCommand(Gui::Command::Doc,
152
                                "FreeCAD.ActiveDocument.ActiveObject.IsoLineHCompound=%s",
153
                                (boxes[9]->isChecked() ? "True" : "False"));
154
    }
155
    Gui::Command::updateActive();
156
    Gui::Command::commitCommand();
157
    return true;
158
}
159

160
#include "moc_TaskDialog.cpp"
161

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.