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

« back to all changes in this revision

Viewing changes to src/Mod/Part/Gui/CommandParametric.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) J�rgen Riegel          (juergen.riegel@web.de) 2002     *
 
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
 
 
26
#ifndef _PreComp_
 
27
# include <QDir>
 
28
# include <QFileInfo>
 
29
# include <QLineEdit>
 
30
#endif
 
31
 
 
32
#include <Gui/Application.h>
 
33
#include <Gui/Command.h>
 
34
#include <Gui/MainWindow.h>
 
35
#include "DlgPartCylinderImp.h"
 
36
#include "DlgPartBoxImp.h"
 
37
 
 
38
//===========================================================================
 
39
// Part_Cylinder
 
40
//===========================================================================
 
41
DEF_STD_CMD_A(CmdPartCylinder);
 
42
 
 
43
CmdPartCylinder::CmdPartCylinder()
 
44
  : Command("Part_Cylinder")
 
45
{
 
46
    sAppModule    = "Part";
 
47
    sGroup        = QT_TR_NOOP("Part");
 
48
    sMenuText     = QT_TR_NOOP("Create Cylinder...");
 
49
    sToolTipText  = QT_TR_NOOP("Create a Cylinder");
 
50
    sWhatsThis    = sToolTipText;
 
51
    sStatusTip    = sToolTipText;
 
52
    sPixmap       = "Part_Cylinder";
 
53
    iAccel        = 0;
 
54
}
 
55
 
 
56
void CmdPartCylinder::activated(int iMsg)
 
57
{
 
58
    PartGui::DlgPartCylinderImp dlg(Gui::getMainWindow());
 
59
    if (dlg.exec()== QDialog::Accepted) {
 
60
        Base::Vector3f dir = dlg.getDirection();
 
61
        openCommand("Create Part Cylinder");
 
62
        doCommand(Doc,"from FreeCAD import Base");
 
63
        doCommand(Doc,"import Part");
 
64
        doCommand(Doc,"__cf__ = App.ActiveDocument.addObject(\"Part::Cylinder\",\"Cylinder\")");
 
65
        doCommand(Doc,"__cf__.Location = Base.Vector(%f,%f,%f)",
 
66
                        dlg.xPos->value(),
 
67
                        dlg.yPos->value(),
 
68
                        dlg.zPos->value());
 
69
        doCommand(Doc,"__cf__.Axis = Base.Vector(%f,%f,%f)",
 
70
                        dir.x, dir.y, dir.z);
 
71
        doCommand(Doc,"__cf__.Radius = %f", dlg.radius->value());
 
72
        doCommand(Doc,"__cf__.Height = %f", dlg.length->value());
 
73
        doCommand(Doc,"del __cf__");
 
74
        commitCommand();
 
75
        updateActive();
 
76
    }
 
77
}
 
78
 
 
79
bool CmdPartCylinder::isActive(void)
 
80
{
 
81
    if (getActiveGuiDocument())
 
82
        return true;
 
83
    else
 
84
        return false;
 
85
}
 
86
 
 
87
//===========================================================================
 
88
// Part_Box
 
89
//===========================================================================
 
90
DEF_STD_CMD_A(CmdPartBox);
 
91
 
 
92
CmdPartBox::CmdPartBox()
 
93
  :Command("Part_Box")
 
94
{
 
95
    sAppModule    = "Part";
 
96
    sGroup        = QT_TR_NOOP("Part");
 
97
    sMenuText     = QT_TR_NOOP("Create box...");
 
98
    sToolTipText  = QT_TR_NOOP("Create a Box feature");
 
99
    sWhatsThis    = "Part_Box";
 
100
    sStatusTip    = sToolTipText;
 
101
    sPixmap       = "Part_Box";
 
102
    iAccel        = 0;
 
103
}
 
104
 
 
105
void CmdPartBox::activated(int iMsg)
 
106
{
 
107
    PartGui::DlgPartBoxImp dlg(Gui::getMainWindow());
 
108
    if (dlg.exec()== QDialog::Accepted) {
 
109
        Base::Vector3f dir = dlg.getDirection();
 
110
        openCommand("Part Box Create");
 
111
        doCommand(Doc,"from FreeCAD import Base");
 
112
        doCommand(Doc,"import Part");
 
113
        doCommand(Doc,"__fb__ = App.ActiveDocument.addObject(\"Part::Box\",\"PartBox\")");
 
114
        doCommand(Doc,"__fb__.Location = Base.Vector(%f,%f,%f)",
 
115
                                 dlg.xPos->value(),
 
116
                                 dlg.yPos->value(),
 
117
                                 dlg.zPos->value());
 
118
        doCommand(Doc,"__fb__.Axis = Base.Vector(%f,%f,%f)",
 
119
                        dir.x, dir.y, dir.z);
 
120
        doCommand(Doc,"__fb__.Length = %f",dlg.uLength->value());
 
121
        doCommand(Doc,"__fb__.Width = %f" ,dlg.vLength->value());
 
122
        doCommand(Doc,"__fb__.Height = %f",dlg.wLength->value());
 
123
        doCommand(Doc,"del __fb__");
 
124
        commitCommand();
 
125
        updateActive();
 
126
    }
 
127
}
 
128
 
 
129
bool CmdPartBox::isActive(void)
 
130
{
 
131
    if (getActiveGuiDocument())
 
132
        return true;
 
133
    else
 
134
        return false;
 
135
}
 
136
 
 
137
 
 
138
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
139
 
 
140
void CreateParamPartCommands(void)
 
141
{
 
142
    Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager();
 
143
    rcCmdMgr.addCommand(new CmdPartCylinder());
 
144
    rcCmdMgr.addCommand(new CmdPartBox());
 
145
}