DlgRegularSolidImp.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2006 Werner Mayer <wmayer[at]users.sourceforge.net>     *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
00020  *                                                                         *
00021  ***************************************************************************/
00022 
00023 
00024 #include "PreCompiled.h"
00025 
00026 #ifndef _PreComp_
00027 # include <float.h>
00028 # include <qcheckbox.h>
00029 # include <qcombobox.h>
00030 # include <qmessagebox.h>
00031 #endif
00032 
00033 #include <Base/PyObjectBase.h>
00034 #include <Base/Interpreter.h>
00035 #include <Gui/Application.h>
00036 #include <Gui/Command.h>
00037 #include <Gui/Document.h>
00038 #include <Gui/MainWindow.h>
00039 #include <Gui/PrefWidgets.h>
00040 #include <Gui/WaitCursor.h>
00041 
00042 #include "DlgRegularSolidImp.h"
00043 
00044 using namespace MeshGui;
00045 
00053 MeshGui::DlgRegularSolidImp::DlgRegularSolidImp(QWidget* parent, Qt::WFlags fl)
00054   : QDialog( parent, fl )
00055 {
00056     this->setupUi(this);
00057     Gui::Command::doCommand(Gui::Command::Doc, "import Mesh,BuildRegularGeoms");
00058 
00059     // set limits
00060     // Box
00061     boxLength->setMaximum(DBL_MAX);
00062     boxWidth->setMaximum(DBL_MAX);
00063     boxHeight->setMaximum(DBL_MAX);
00064     // Cylinder
00065     cylinderRadius->setMaximum(DBL_MAX);
00066     cylinderLength->setMaximum(DBL_MAX);
00067     cylinderEdgeLength->setMaximum(DBL_MAX);
00068     cylinderCount->setMaximum(1000);
00069     // Cone
00070     coneRadius1->setMaximum(DBL_MAX);
00071     coneRadius2->setMaximum(DBL_MAX);
00072     coneLength->setMaximum(DBL_MAX);
00073     coneEdgeLength->setMaximum(DBL_MAX);
00074     coneCount->setMaximum(1000);
00075     // Sphere
00076     sphereRadius->setMaximum(DBL_MAX);
00077     sphereCount->setMaximum(1000);
00078     // Ellipsoid
00079     ellipsoidRadius1->setMaximum(DBL_MAX);
00080     ellipsoidRadius2->setMaximum(DBL_MAX);
00081     ellipsoidCount->setMaximum(1000);
00082     // Torus
00083     toroidRadius1->setMaximum(DBL_MAX);
00084     toroidRadius2->setMaximum(DBL_MAX);
00085     toroidCount->setMaximum(1000);
00086 }
00087 
00091 MeshGui::DlgRegularSolidImp::~DlgRegularSolidImp()
00092 {
00093     // no need to delete child widgets, Qt does it all for us
00094 }
00095 
00096 void MeshGui::DlgRegularSolidImp::changeEvent(QEvent *e)
00097 {
00098     if (e->type() == QEvent::LanguageChange) {
00099         this->retranslateUi(this);
00100     }
00101     QDialog::changeEvent(e);
00102 }
00103 
00107 void MeshGui::DlgRegularSolidImp::on_createSolidButton_clicked()
00108 {
00109     try {
00110         Gui::WaitCursor wc;
00111         QString cmd; std::string name;
00112         App::Document* doc = App::GetApplication().getActiveDocument();
00113         if (!doc) {
00114             QMessageBox::warning(this, tr("Create %1").arg(comboBox1->currentText()), tr("No active document"));
00115             return;
00116         }
00117         if (comboBox1->currentIndex() == 0) {         // cube
00118             name = doc->getUniqueObjectName("Cube");
00119             cmd = QString(QLatin1String(
00120                 "App.ActiveDocument.addObject(\"Mesh::Cube\",\"%1\")\n"
00121                 "App.ActiveDocument.%1.Length=%2\n"
00122                 "App.ActiveDocument.%1.Width=%3\n"
00123                 "App.ActiveDocument.%1.Height=%4\n"))
00124                 .arg(QLatin1String(name.c_str()))
00125                 .arg(boxLength->value(),0,'f',2)
00126                 .arg(boxWidth->value(),0,'f',2)
00127                 .arg(boxHeight->value(),0,'f',2);
00128         }
00129         else if (comboBox1->currentIndex() == 1) {  // cylinder
00130             name = doc->getUniqueObjectName("Cylinder");
00131             cmd = QString(QLatin1String(
00132                 "App.ActiveDocument.addObject(\"Mesh::Cylinder\",\"%1\")\n"
00133                 "App.ActiveDocument.%1.Radius=%2\n"
00134                 "App.ActiveDocument.%1.Length=%3\n"
00135                 "App.ActiveDocument.%1.EdgeLength=%4\n"
00136                 "App.ActiveDocument.%1.Closed=%5\n"
00137                 "App.ActiveDocument.%1.Sampling=%6\n"))
00138                 .arg(QLatin1String(name.c_str()))
00139                 .arg(cylinderRadius->value(),0,'f',2)
00140                 .arg(cylinderLength->value(),0,'f',2)
00141                 .arg(cylinderEdgeLength->value(),0,'f',2)
00142                 .arg(QLatin1String((cylinderClosed->isChecked()?"True":"False")))
00143                 .arg(cylinderCount->value());
00144         }
00145         else if (comboBox1->currentIndex() == 2) {  // cone
00146             name = doc->getUniqueObjectName("Cone");
00147             cmd = QString(QLatin1String(
00148                 "App.ActiveDocument.addObject(\"Mesh::Cone\",\"%1\")\n"
00149                 "App.ActiveDocument.%1.Radius1=%2\n"
00150                 "App.ActiveDocument.%1.Radius2=%3\n"
00151                 "App.ActiveDocument.%1.Length=%4\n"
00152                 "App.ActiveDocument.%1.EdgeLength=%5\n"
00153                 "App.ActiveDocument.%1.Closed=%6\n"
00154                 "App.ActiveDocument.%1.Sampling=%7\n"))
00155                 .arg(QLatin1String(name.c_str()))
00156                 .arg(coneRadius1->value(),0,'f',2)
00157                 .arg(coneRadius2->value(),0,'f',2)
00158                 .arg(coneLength->value(),0,'f',2)
00159                 .arg(coneEdgeLength->value(),0,'f',2)
00160                 .arg(QLatin1String((coneClosed->isChecked()?"True":"False")))
00161                 .arg(coneCount->value());
00162         }
00163         else if (comboBox1->currentIndex() == 3) {  // sphere
00164             name = doc->getUniqueObjectName("Sphere");
00165             cmd = QString(QLatin1String(
00166                 "App.ActiveDocument.addObject(\"Mesh::Sphere\",\"%1\")\n"
00167                 "App.ActiveDocument.%1.Radius=%2\n"
00168                 "App.ActiveDocument.%1.Sampling=%3\n"))
00169                 .arg(QLatin1String(name.c_str()))
00170                 .arg(sphereRadius->value(),0,'f',2)
00171                 .arg(sphereCount->value());
00172         }
00173         else if (comboBox1->currentIndex() == 4) {  // ellipsoid
00174             name = doc->getUniqueObjectName("Ellipsoid");
00175             cmd = QString(QLatin1String(
00176                 "App.ActiveDocument.addObject(\"Mesh::Ellipsoid\",\"%1\")\n"
00177                 "App.ActiveDocument.%1.Radius1=%2\n"
00178                 "App.ActiveDocument.%1.Radius2=%3\n"
00179                 "App.ActiveDocument.%1.Sampling=%4\n"))
00180                 .arg(QLatin1String(name.c_str()))
00181                 .arg(ellipsoidRadius1->value(),0,'f',2)
00182                 .arg(ellipsoidRadius2->value(),0,'f',2)
00183                 .arg(ellipsoidCount->value());
00184         }
00185         else if (comboBox1->currentIndex() == 5) {  // toroid
00186             name = doc->getUniqueObjectName("Torus");
00187             cmd = QString(QLatin1String(
00188                 "App.ActiveDocument.addObject(\"Mesh::Torus\",\"%1\")\n"
00189                 "App.ActiveDocument.%1.Radius1=%2\n"
00190                 "App.ActiveDocument.%1.Radius2=%3\n"
00191                 "App.ActiveDocument.%1.Sampling=%4\n"))
00192                 .arg(QLatin1String(name.c_str()))
00193                 .arg(toroidRadius1->value(),0,'f',2)
00194                 .arg(toroidRadius2->value(),0,'f',2)
00195                 .arg(toroidCount->value());
00196         }
00197 
00198         // Execute the Python block
00199         QString solid = tr("Create %1").arg(comboBox1->currentText());
00200         Gui::Application::Instance->activeDocument()->openCommand(solid.toUtf8());
00201         Gui::Command::doCommand(Gui::Command::Doc, (const char*)cmd.toAscii());
00202         Gui::Application::Instance->activeDocument()->commitCommand();
00203         Gui::Command::doCommand(Gui::Command::Doc, "App.activeDocument().recompute()");
00204         Gui::Command::doCommand(Gui::Command::Gui, "Gui.SendMsgToActiveView(\"ViewFit\")");
00205     }
00206     catch (const Base::PyException& e) {
00207         QMessageBox::warning(this, tr("Create %1").arg(comboBox1->currentText()),
00208             QString::fromLatin1(e.what()));
00209     }
00210 }
00211 
00212 // -------------------------------------------------------------
00213 
00214 SingleDlgRegularSolidImp* SingleDlgRegularSolidImp::_instance=0;
00215 
00216 SingleDlgRegularSolidImp* SingleDlgRegularSolidImp::instance()
00217 {
00218     // not initialized?
00219     if(!_instance) {
00220         _instance = new SingleDlgRegularSolidImp( Gui::getMainWindow());
00221         _instance->setAttribute(Qt::WA_DeleteOnClose);
00222     }
00223 
00224     return _instance;
00225 }
00226 
00227 void SingleDlgRegularSolidImp::destruct ()
00228 {
00229     if (_instance != 0) {
00230         SingleDlgRegularSolidImp *pTmp = _instance;
00231         _instance = 0;
00232         delete pTmp;
00233     }
00234 }
00235 
00236 bool SingleDlgRegularSolidImp::hasInstance()
00237 {
00238     return _instance != 0;
00239 }
00240 
00245 SingleDlgRegularSolidImp::SingleDlgRegularSolidImp(QWidget* parent, Qt::WFlags fl)
00246   : DlgRegularSolidImp(parent, fl)
00247 {
00248 }
00249 
00253 SingleDlgRegularSolidImp::~SingleDlgRegularSolidImp()
00254 {
00255     _instance = 0;
00256 }
00257 
00258 #include "moc_DlgRegularSolidImp.cpp"

Generated on Wed Nov 23 19:00:07 2011 for FreeCAD by  doxygen 1.6.1