00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
00060
00061 boxLength->setMaximum(DBL_MAX);
00062 boxWidth->setMaximum(DBL_MAX);
00063 boxHeight->setMaximum(DBL_MAX);
00064
00065 cylinderRadius->setMaximum(DBL_MAX);
00066 cylinderLength->setMaximum(DBL_MAX);
00067 cylinderEdgeLength->setMaximum(DBL_MAX);
00068 cylinderCount->setMaximum(1000);
00069
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
00076 sphereRadius->setMaximum(DBL_MAX);
00077 sphereCount->setMaximum(1000);
00078
00079 ellipsoidRadius1->setMaximum(DBL_MAX);
00080 ellipsoidRadius2->setMaximum(DBL_MAX);
00081 ellipsoidCount->setMaximum(1000);
00082
00083 toroidRadius1->setMaximum(DBL_MAX);
00084 toroidRadius2->setMaximum(DBL_MAX);
00085 toroidCount->setMaximum(1000);
00086 }
00087
00091 MeshGui::DlgRegularSolidImp::~DlgRegularSolidImp()
00092 {
00093
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) {
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) {
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) {
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) {
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) {
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) {
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
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
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"