FreeCAD

Форк
0
/
TaskProjection.cpp 
166 строк · 6.8 Кб
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
//this file originally part of TechDraw workbench
23
//migrated to TechDraw workbench 2022-01-26 by Wandererfan
24

25
#include "PreCompiled.h"
26
#ifndef _PreComp_
27
# include <QMessageBox>
28
#endif
29

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

40
#include "TaskProjection.h"
41
#include "ui_TaskProjection.h"
42

43

44
using namespace TechDrawGui;
45

46
/* TRANSLATOR TechDrawGui::TaskProjection */
47

48
TaskProjection::TaskProjection() :
49
    ui(new Ui_TaskProjection)
50
{
51

52
    ui->setupUi(this);
53
}
54

55
TaskProjection::~TaskProjection()
56
{
57
    // automatically deleted in the sub-class
58
}
59

60
bool TaskProjection::accept()
61
{
62
    Gui::Document* document = Gui::Application::Instance->activeDocument();
63
    if (!document) {
64
        QMessageBox::warning(Gui::getMainWindow(), tr("No active document"),
65
            tr("There is currently no active document to complete the operation"));
66
        return true;
67
    }
68
    std::list<Gui::MDIView*> mdis = document->getMDIViewsOfType(Gui::View3DInventor::getClassTypeId());
69
    if (mdis.empty()) {
70
        QMessageBox::warning(Gui::getMainWindow(), tr("No active view"),
71
            tr("There is currently no active view to complete the operation"));
72
        return false;
73
    }
74

75
    Gui::View3DInventorViewer* viewer = static_cast<Gui::View3DInventor*>(mdis.front())->getViewer();
76
    SbVec3f pnt, dir;
77
    viewer->getNearPlane(pnt, dir);
78
    float x=0, y=1, z=1;
79
    dir.getValue(x, y,z);
80

81
    std::vector<Part::Feature*> shapes = Gui::Selection().getObjectsOfType<Part::Feature>();
82
    Gui::Command::openCommand("Project shape");
83
    Gui::Command::addModule(Gui::Command::Doc, "TechDraw");
84
    for (std::vector<Part::Feature*>::iterator it = shapes.begin(); it != shapes.end(); ++it) {
85
        const char* object = (*it)->getNameInDocument();
86
        Gui::Command::doCommand(Gui::Command::Doc,
87
            "FreeCAD.ActiveDocument.addObject('TechDraw::FeatureProjection', '%s_proj')", object);
88
        Gui::Command::doCommand(Gui::Command::Doc,
89
            "FreeCAD.ActiveDocument.ActiveObject.Direction=FreeCAD.Vector(%f, %f, %f)", x, y,z);
90
        Gui::Command::doCommand(Gui::Command::Doc,
91
            "FreeCAD.ActiveDocument.ActiveObject.Source=FreeCAD.ActiveDocument.%s", object);
92
        Gui::Command::doCommand(Gui::Command::Doc,
93
            "FreeCAD.ActiveDocument.ActiveObject.VCompound=%s", (ui->cbVisSharp->isChecked() ? "True" : "False"));
94
        Gui::Command::doCommand(Gui::Command::Doc,
95
            "FreeCAD.ActiveDocument.ActiveObject.Rg1LineVCompound=%s", (ui->cbVisSmooth->isChecked() ? "True" : "False"));
96
        Gui::Command::doCommand(Gui::Command::Doc,
97
            "FreeCAD.ActiveDocument.ActiveObject.RgNLineVCompound=%s", (ui->cbVisSewn->isChecked() ? "True" : "False"));
98
        Gui::Command::doCommand(Gui::Command::Doc,
99
            "FreeCAD.ActiveDocument.ActiveObject.OutLineVCompound=%s", (ui->cbVisOutline->isChecked() ? "True" : "False"));
100
        Gui::Command::doCommand(Gui::Command::Doc,
101
            "FreeCAD.ActiveDocument.ActiveObject.IsoLineVCompound=%s", (ui->cbVisIso->isChecked() ? "True" : "False"));
102
        Gui::Command::doCommand(Gui::Command::Doc,
103
            "FreeCAD.ActiveDocument.ActiveObject.HCompound=%s", (ui->cbHidSharp->isChecked() ? "True" : "False"));
104
        Gui::Command::doCommand(Gui::Command::Doc,
105
            "FreeCAD.ActiveDocument.ActiveObject.Rg1LineHCompound=%s", (ui->cbHidSmooth->isChecked() ? "True" : "False"));
106
        Gui::Command::doCommand(Gui::Command::Doc,
107
            "FreeCAD.ActiveDocument.ActiveObject.RgNLineHCompound=%s", (ui->cbHidSewn->isChecked() ? "True" : "False"));
108
        Gui::Command::doCommand(Gui::Command::Doc,
109
            "FreeCAD.ActiveDocument.ActiveObject.OutLineHCompound=%s", (ui->cbHidOutline->isChecked() ? "True" : "False"));
110
        Gui::Command::doCommand(Gui::Command::Doc,
111
            "FreeCAD.ActiveDocument.ActiveObject.IsoLineHCompound=%s", (ui->cbHidIso->isChecked() ? "True" : "False"));
112
    }
113
    Gui::Command::updateActive();
114
    Gui::Command::commitCommand();
115
    return true;
116
}
117

118
bool TaskProjection::reject()
119
{
120
    return true;
121
}
122

123

124
///////////////////////////////////////////////////////////////////////////
125

126
TaskDlgProjection::TaskDlgProjection() :
127
    TaskDialog()
128
{
129
    widget  = new TaskProjection();
130
    taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("actions/TechDraw_ProjectShape"), widget->windowTitle(), true, nullptr);
131
    taskbox->groupLayout()->addWidget(widget);
132
    Content.push_back(taskbox);
133
    setAutoCloseOnTransactionChange(true);
134
}
135

136
TaskDlgProjection::~TaskDlgProjection()
137
{
138
}
139

140
void TaskDlgProjection::update()
141
{
142
}
143

144
//==== calls from the TaskView ===============================================================
145
void TaskDlgProjection::open()
146
{
147
}
148

149
void TaskDlgProjection::clicked(int i)
150
{
151
    Q_UNUSED(i);
152
}
153

154
bool TaskDlgProjection::accept()
155
{
156
    widget->accept();
157
    return true;
158
}
159

160
bool TaskDlgProjection::reject()
161
{
162
    widget->reject();
163
    return true;
164
}
165

166
#include "moc_TaskProjection.cpp"
167

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

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

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

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