Mod/Sandbox/Gui/Command.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2009 Werner Mayer <wmayer@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 #ifndef _PreComp_
00026 # include <QCalendarWidget>
00027 # include <QColorDialog>
00028 # include <QCryptographicHash>
00029 # include <QObject>
00030 # include <QEventLoop>
00031 # include <QFontMetrics>
00032 # include <QFuture>
00033 # include <QFutureWatcher>
00034 # include <QtConcurrentMap>
00035 # include <QLabel>
00036 # include <QMessageBox>
00037 # include <QTimer>
00038 # include <QImage>
00039 # include <QImageReader>
00040 # include <QPainter>
00041 # include <QThread>
00042 # include <Inventor/nodes/SoAnnotation.h>
00043 # include <Inventor/nodes/SoImage.h>
00044 # include <Inventor/nodes/SoCone.h>
00045 # include <Inventor/Qt/viewers/SoQtPlaneViewer.h>
00046 # include <Inventor/Qt/viewers/SoQtExaminerViewer.h>
00047 # include <Inventor/Qt/viewers/SoQtFlyViewer.h>
00048 # include <boost/thread/thread.hpp>
00049 # include <boost/thread/mutex.hpp>
00050 # include <boost/thread/condition_variable.hpp>
00051 # if BOOST_VERSION >= 104100
00052 # include <boost/thread/future.hpp>
00053 # endif
00054 # include <boost/bind.hpp>
00055 # include <boost/shared_ptr.hpp>
00056 #endif
00057 
00058 #include <Base/Console.h>
00059 #include <Base/Sequencer.h>
00060 #include <App/Application.h>
00061 #include <App/Document.h>
00062 #include <Gui/Application.h>
00063 #include <Gui/BitmapFactory.h>
00064 #include <Gui/Command.h>
00065 #include <Gui/MainWindow.h>
00066 #include <Gui/FileDialog.h>
00067 #include <Gui/View3DInventor.h>
00068 #include <Gui/View3DInventorViewer.h>
00069 #include <Gui/WaitCursor.h>
00070 
00071 #include <Mod/Sandbox/App/DocumentThread.h>
00072 #include <Mod/Sandbox/App/DocumentProtector.h>
00073 #include <Mod/Mesh/App/MeshFeature.h>
00074 #include "Workbench.h"
00075 
00076 
00077 DEF_STD_CMD(CmdSandboxDocumentThread);
00078 
00079 CmdSandboxDocumentThread::CmdSandboxDocumentThread()
00080   :Command("Sandbox_Thread")
00081 {
00082     sAppModule    = "Sandbox";
00083     sGroup        = QT_TR_NOOP("Sandbox");
00084     sMenuText     = QT_TR_NOOP("Run several threads");
00085     sToolTipText  = QT_TR_NOOP("Sandbox Test function");
00086     sWhatsThis    = QT_TR_NOOP("Sandbox Test function");
00087     sStatusTip    = QT_TR_NOOP("Sandbox Test function");
00088     sPixmap       = "Std_Tool1";
00089 }
00090 
00091 void CmdSandboxDocumentThread::activated(int iMsg)
00092 {
00093     App::GetApplication().newDocument("Thread");
00094     for (int i=0; i<5; i++) {
00095         Sandbox::DocumentThread* dt = new Sandbox::DocumentThread();
00096         dt->setObjectName(QString::fromAscii("MyMesh_%1").arg(i));
00097         QObject::connect(dt, SIGNAL(finished()), dt, SLOT(deleteLater()));
00098         dt->start();
00099     }
00100 }
00101 
00102 // -------------------------------------------------------------------------------
00103 
00104 DEF_STD_CMD(CmdSandboxDocumentTestThread);
00105 
00106 CmdSandboxDocumentTestThread::CmdSandboxDocumentTestThread()
00107   :Command("Sandbox_TestThread")
00108 {
00109     sAppModule    = "Sandbox";
00110     sGroup        = QT_TR_NOOP("Sandbox");
00111     sMenuText     = QT_TR_NOOP("Test thread");
00112     sToolTipText  = QT_TR_NOOP("Sandbox Test function");
00113     sWhatsThis    = QT_TR_NOOP("Sandbox Test function");
00114     sStatusTip    = QT_TR_NOOP("Sandbox Test function");
00115     sPixmap       = "Std_Tool1";
00116 }
00117 
00118 void CmdSandboxDocumentTestThread::activated(int iMsg)
00119 {
00120     App::GetApplication().newDocument("Thread");
00121     Sandbox::DocumentTestThread* dt = new Sandbox::DocumentTestThread();
00122     QObject::connect(dt, SIGNAL(finished()), dt, SLOT(deleteLater()));
00123     dt->start();
00124 }
00125 
00126 // -------------------------------------------------------------------------------
00127 
00128 DEF_STD_CMD(CmdSandboxDocThreadWithSeq);
00129 
00130 CmdSandboxDocThreadWithSeq::CmdSandboxDocThreadWithSeq()
00131   :Command("Sandbox_SeqThread")
00132 {
00133     sAppModule    = "Sandbox";
00134     sGroup        = QT_TR_NOOP("Sandbox");
00135     sMenuText     = QT_TR_NOOP("Thread and sequencer");
00136     sToolTipText  = QT_TR_NOOP("Sandbox Test function");
00137     sWhatsThis    = QT_TR_NOOP("Sandbox Test function");
00138     sStatusTip    = QT_TR_NOOP("Sandbox Test function");
00139     sPixmap       = "Std_Tool2";
00140 }
00141 
00142 void CmdSandboxDocThreadWithSeq::activated(int iMsg)
00143 {
00144     App::GetApplication().newDocument("Thread");
00145     Sandbox::DocumentThread* dt = new Sandbox::DocumentThread();
00146     dt->setObjectName(QString::fromAscii("MyMesh"));
00147     QObject::connect(dt, SIGNAL(finished()), dt, SLOT(deleteLater()));
00148     dt->start();
00149 #ifdef FC_DEBUG
00150     int max = 10000;
00151 #else
00152     int max = 100000000;
00153 #endif
00154     Base::SequencerLauncher seq("Do something meaningful...", max);
00155     double val=0;
00156     for (int i=0; i<max; i++) {
00157         for (int j=0; j<max; j++) {
00158             val = sin(0.12345);
00159         }
00160         seq.next(true);
00161     }
00162 }
00163 
00164 // -------------------------------------------------------------------------------
00165 
00166 DEF_STD_CMD(CmdSandboxDocThreadBusy);
00167 
00168 CmdSandboxDocThreadBusy::CmdSandboxDocThreadBusy()
00169   :Command("Sandbox_BlockThread")
00170 {
00171     sAppModule    = "Sandbox";
00172     sGroup        = QT_TR_NOOP("Sandbox");
00173     sMenuText     = QT_TR_NOOP("Thread and no sequencer");
00174     sToolTipText  = QT_TR_NOOP("Sandbox Test function");
00175     sWhatsThis    = QT_TR_NOOP("Sandbox Test function");
00176     sStatusTip    = QT_TR_NOOP("Sandbox Test function");
00177     sPixmap       = "Std_Tool3";
00178 }
00179 
00180 void CmdSandboxDocThreadBusy::activated(int iMsg)
00181 {
00182     App::GetApplication().newDocument("Thread");
00183     Sandbox::DocumentThread* dt = new Sandbox::DocumentThread();
00184     dt->setObjectName(QString::fromAscii("MyMesh"));
00185     QObject::connect(dt, SIGNAL(finished()), dt, SLOT(deleteLater()));
00186     dt->start();
00187 #ifdef FC_DEBUG
00188     int max = 10000;
00189 #else
00190     int max = 100000000;
00191 #endif
00192     double val=0;
00193     for (int i=0; i<max; i++) {
00194         for (int j=0; j<max; j++) {
00195             val = sin(0.12345);
00196         }
00197     }
00198 }
00199 
00200 // -------------------------------------------------------------------------------
00201 
00202 DEF_STD_CMD(CmdSandboxDocumentNoThread);
00203 
00204 CmdSandboxDocumentNoThread::CmdSandboxDocumentNoThread()
00205   :Command("Sandbox_NoThread")
00206 {
00207     sAppModule    = "Sandbox";
00208     sGroup        = QT_TR_NOOP("Sandbox");
00209     sMenuText     = QT_TR_NOOP("GUI thread");
00210     sToolTipText  = QT_TR_NOOP("Sandbox Test function");
00211     sWhatsThis    = QT_TR_NOOP("Sandbox Test function");
00212     sStatusTip    = QT_TR_NOOP("Sandbox Test function");
00213     sPixmap       = "Std_Tool4";
00214 }
00215 
00216 void CmdSandboxDocumentNoThread::activated(int iMsg)
00217 {
00218     App::GetApplication().newDocument("Thread");
00219     App::Document* doc = App::GetApplication().getActiveDocument();
00220     Sandbox::DocumentProtector dp(doc);
00221     App::DocumentObject* obj = dp.addObject("Mesh::Cube", "MyCube");
00222     dp.recompute();
00223     App::GetApplication().closeDocument("Thread");
00224     // this forces an exception
00225     App::DocumentObject* obj2 = dp.addObject("Mesh::Cube", "MyCube");
00226     dp.recompute();
00227 }
00228 
00229 // -------------------------------------------------------------------------------
00230 
00231 DEF_STD_CMD(CmdSandboxWorkerThread);
00232 
00233 CmdSandboxWorkerThread::CmdSandboxWorkerThread()
00234   :Command("Sandbox_WorkerThread")
00235 {
00236     sAppModule    = "Sandbox";
00237     sGroup        = QT_TR_NOOP("Sandbox");
00238     sMenuText     = QT_TR_NOOP("Worker thread");
00239     sToolTipText  = QT_TR_NOOP("Sandbox Test function");
00240     sWhatsThis    = QT_TR_NOOP("Sandbox Test function");
00241     sStatusTip    = QT_TR_NOOP("Sandbox Test function");
00242     sPixmap       = "Std_Tool1";
00243 }
00244 
00245 void CmdSandboxWorkerThread::activated(int iMsg)
00246 {
00247     Sandbox::WorkerThread* wt = new Sandbox::WorkerThread();
00248     QObject::connect(wt, SIGNAL(finished()), wt, SLOT(deleteLater()));
00249     wt->start();
00250 }
00251 
00252 // -------------------------------------------------------------------------------
00253 
00254 DEF_STD_CMD(CmdSandboxPythonLockThread);
00255 
00256 CmdSandboxPythonLockThread::CmdSandboxPythonLockThread()
00257   :Command("Sandbox_PythonLockThread")
00258 {
00259     sAppModule    = "Sandbox";
00260     sGroup        = QT_TR_NOOP("Sandbox");
00261     sMenuText     = QT_TR_NOOP("Locked Python threads");
00262     sToolTipText  = QT_TR_NOOP("Use Python's thread module where each thread is locked");
00263     sWhatsThis    = QT_TR_NOOP("Use Python's thread module where each thread is locked");
00264     sStatusTip    = QT_TR_NOOP("Use Python's thread module where each thread is locked");
00265 }
00266 
00267 void CmdSandboxPythonLockThread::activated(int iMsg)
00268 {
00269     doCommand(Doc,
00270         "import thread, time, Sandbox\n"
00271         "def adder(doc):\n"
00272         "    lock.acquire()\n"
00273         "    dp=Sandbox.DocumentProtector(doc)\n"
00274         "    dp.addObject(\"Mesh::Ellipsoid\",\"Mesh\")\n"
00275         "    dp.recompute()\n"
00276         "    lock.release()\n"
00277         "\n"
00278         "lock=thread.allocate_lock()\n"
00279         "doc=App.newDocument()\n"
00280         "for i in range(2):\n"
00281         "    thread.start_new(adder,(doc,))\n"
00282         "\n"
00283         "time.sleep(1)\n"
00284     );
00285 }
00286 
00287 // -------------------------------------------------------------------------------
00288 
00289 DEF_STD_CMD(CmdSandboxPythonNolockThread);
00290 
00291 CmdSandboxPythonNolockThread::CmdSandboxPythonNolockThread()
00292   :Command("Sandbox_NolockPython")
00293 {
00294     sAppModule    = "Sandbox";
00295     sGroup        = QT_TR_NOOP("Sandbox");
00296     sMenuText     = QT_TR_NOOP("Unlocked Python threads");
00297     sToolTipText  = QT_TR_NOOP("Use Python's thread module where each thread is unlocked");
00298     sWhatsThis    = QT_TR_NOOP("Use Python's thread module where each thread is unlocked");
00299     sStatusTip    = QT_TR_NOOP("Use Python's thread module where each thread is unlocked");
00300 }
00301 
00302 void CmdSandboxPythonNolockThread::activated(int iMsg)
00303 {
00304     doCommand(Doc,
00305         "import thread, time, Sandbox\n"
00306         "def adder(doc):\n"
00307         "    dp=Sandbox.DocumentProtector(doc)\n"
00308         "    dp.addObject(\"Mesh::Ellipsoid\",\"Mesh\")\n"
00309         "    dp.recompute()\n"
00310         "\n"
00311         "doc=App.newDocument()\n"
00312         "for i in range(2):\n"
00313         "    thread.start_new(adder,(doc,))\n"
00314         "\n"
00315         "time.sleep(1)\n"
00316     );
00317 }
00318 
00319 // -------------------------------------------------------------------------------
00320 
00321 DEF_STD_CMD(CmdSandboxPyQtThread);
00322 
00323 CmdSandboxPyQtThread::CmdSandboxPyQtThread()
00324   :Command("Sandbox_PyQtThread")
00325 {
00326     sAppModule    = "Sandbox";
00327     sGroup        = QT_TR_NOOP("Sandbox");
00328     sMenuText     = QT_TR_NOOP("PyQt threads");
00329     sToolTipText  = QT_TR_NOOP("Use PyQt's thread module");
00330     sWhatsThis    = QT_TR_NOOP("Use PyQt's thread module");
00331     sStatusTip    = QT_TR_NOOP("Use PyQt's thread module");
00332 }
00333 
00334 void CmdSandboxPyQtThread::activated(int iMsg)
00335 {
00336     doCommand(Doc,
00337         "from PyQt4 import QtCore; import Sandbox\n"
00338         "class Thread(QtCore.QThread):\n"
00339         "    def run(self):\n"
00340         "        dp=Sandbox.DocumentProtector(doc)\n"
00341         "        dp.addObject(\"Mesh::Ellipsoid\",\"Mesh\")\n"
00342         "        dp.recompute()\n"
00343         "\n"
00344         "doc=App.newDocument()\n"
00345         "threads=[]\n"
00346         "for i in range(2):\n"
00347         "    thread=Thread()\n"
00348         "    threads.append(thread)\n"
00349         "    thread.start()\n"
00350         "\n"
00351     );
00352 }
00353 
00354 // -------------------------------------------------------------------------------
00355 
00356 DEF_STD_CMD(CmdSandboxPythonThread);
00357 
00358 CmdSandboxPythonThread::CmdSandboxPythonThread()
00359   :Command("Sandbox_PythonThread")
00360 {
00361     sAppModule    = "Sandbox";
00362     sGroup        = QT_TR_NOOP("Sandbox");
00363     sMenuText     = QT_TR_NOOP("Python threads");
00364     sToolTipText  = QT_TR_NOOP("Use class PythonThread running Python code in its run() method");
00365     sWhatsThis    = QT_TR_NOOP("Use class PythonThread running Python code in its run() method");
00366     sStatusTip    = QT_TR_NOOP("Use class PythonThread running Python code in its run() method");
00367 }
00368 
00369 void CmdSandboxPythonThread::activated(int iMsg)
00370 {
00371     App::GetApplication().newDocument("Thread");
00372     for (int i=0; i<5; i++) {
00373         Sandbox::PythonThread* pt = new Sandbox::PythonThread();
00374         pt->setObjectName(QString::fromAscii("MyMesh_%1").arg(i));
00375         QObject::connect(pt, SIGNAL(finished()), pt, SLOT(deleteLater()));
00376         pt->start();
00377     }
00378 }
00379 
00380 // -------------------------------------------------------------------------------
00381 
00382 DEF_STD_CMD(CmdSandboxPythonMainThread);
00383 
00384 CmdSandboxPythonMainThread::CmdSandboxPythonMainThread()
00385   :Command("Sandbox_PythonMainThread")
00386 {
00387     sAppModule    = "Sandbox";
00388     sGroup        = QT_TR_NOOP("Sandbox");
00389     sMenuText     = QT_TR_NOOP("Python main thread");
00390     sToolTipText  = QT_TR_NOOP("Run python code in main thread");
00391     sWhatsThis    = QT_TR_NOOP("Run python code in main thread");
00392     sStatusTip    = QT_TR_NOOP("Run python code in main thread");
00393 }
00394 
00395 void CmdSandboxPythonMainThread::activated(int iMsg)
00396 {
00397     doCommand(Doc,
00398         "import Sandbox\n"
00399         "doc=App.newDocument()\n"
00400         "dp=Sandbox.DocumentProtector(doc)\n"
00401         "dp.addObject(\"Mesh::Ellipsoid\",\"Mesh\")\n"
00402         "dp.recompute()\n"
00403     );
00404 }
00405 
00406 // -------------------------------------------------------------------------------
00407 
00408 DEF_STD_CMD(CmdSandboxDocThreadWithDialog);
00409 
00410 CmdSandboxDocThreadWithDialog::CmdSandboxDocThreadWithDialog()
00411   :Command("Sandbox_Dialog")
00412 {
00413     sAppModule    = "Sandbox";
00414     sGroup        = QT_TR_NOOP("Sandbox");
00415     sMenuText     = QT_TR_NOOP("Thread and modal dialog");
00416     sToolTipText  = QT_TR_NOOP("Sandbox Test function");
00417     sWhatsThis    = QT_TR_NOOP("Sandbox Test function");
00418     sStatusTip    = QT_TR_NOOP("Sandbox Test function");
00419     sPixmap       = "Std_Tool7";
00420 }
00421 
00422 void CmdSandboxDocThreadWithDialog::activated(int iMsg)
00423 {
00424     App::GetApplication().newDocument("Thread");
00425     Sandbox::DocumentThread* dt = new Sandbox::DocumentThread();
00426     dt->setObjectName(QString::fromAscii("MyMesh"));
00427     QObject::connect(dt, SIGNAL(finished()), dt, SLOT(deleteLater()));
00428     dt->start();
00429     //QFileDialog::getOpenFileName();
00430     QColorDialog::getColor(Qt::white,Gui::getMainWindow());
00431 }
00432 
00433 // -------------------------------------------------------------------------------
00434 
00435 DEF_STD_CMD(CmdSandboxDocThreadWithFileDlg);
00436 
00437 CmdSandboxDocThreadWithFileDlg::CmdSandboxDocThreadWithFileDlg()
00438   :Command("Sandbox_FileDialog")
00439 {
00440     sAppModule    = "Sandbox";
00441     sGroup        = QT_TR_NOOP("Sandbox");
00442     sMenuText     = QT_TR_NOOP("Thread and file dialog");
00443     sToolTipText  = QT_TR_NOOP("Sandbox Test function");
00444     sWhatsThis    = QT_TR_NOOP("Sandbox Test function");
00445     sStatusTip    = QT_TR_NOOP("Sandbox Test function");
00446     sPixmap       = "Std_Tool7";
00447 }
00448 
00449 void CmdSandboxDocThreadWithFileDlg::activated(int iMsg)
00450 {
00451     App::GetApplication().newDocument("Thread");
00452     Sandbox::DocumentThread* dt = new Sandbox::DocumentThread();
00453     dt->setObjectName(QString::fromAscii("MyMesh"));
00454     QObject::connect(dt, SIGNAL(finished()), dt, SLOT(deleteLater()));
00455     dt->start();
00456     QFileDialog::getOpenFileName();
00457 }
00458 
00459 // -------------------------------------------------------------------------------
00460 
00461 class CmdSandboxEventLoop : public Gui::Command
00462 {
00463 public:
00464     CmdSandboxEventLoop();
00465     const char* className() const
00466     { return "CmdSandboxEventLoop"; }
00467 protected:
00468     void activated(int iMsg);
00469     bool isActive(void);
00470 private:
00471     QEventLoop loop;
00472 };
00473 
00474 
00475 CmdSandboxEventLoop::CmdSandboxEventLoop()
00476   :Command("Sandbox_EventLoop")
00477 {
00478     sAppModule    = "Sandbox";
00479     sGroup        = QT_TR_NOOP("Sandbox");
00480     sMenuText     = QT_TR_NOOP("Local event loop");
00481     sToolTipText  = QT_TR_NOOP("Sandbox Test function");
00482     sWhatsThis    = QT_TR_NOOP("Sandbox Test function");
00483     sStatusTip    = QT_TR_NOOP("Sandbox Test function");
00484     sPixmap       = "Std_Tool6";
00485 }
00486 
00487 void CmdSandboxEventLoop::activated(int iMsg)
00488 {
00489     QTimer timer;
00490     timer.setSingleShot(true);
00491     QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
00492 
00493     timer.start(5000); // 5s timeout
00494     loop.exec();
00495     Base::Console().Message("CmdSandboxEventLoop: timeout\n");
00496 }
00497 
00498 bool CmdSandboxEventLoop::isActive(void)
00499 {
00500     return (!loop.isRunning());
00501 }
00502 
00503 // -------------------------------------------------------------------------------
00504 
00505 class CmdSandboxMeshLoader : public Gui::Command
00506 {
00507 public:
00508     CmdSandboxMeshLoader();
00509     const char* className() const
00510     { return "CmdSandboxMeshLoader"; }
00511 protected:
00512     void activated(int iMsg);
00513     bool isActive(void);
00514 private:
00515     QEventLoop loop;
00516 };
00517 
00518 CmdSandboxMeshLoader::CmdSandboxMeshLoader()
00519   :Command("Sandbox_MeshLoad")
00520 {
00521     sAppModule    = "Sandbox";
00522     sGroup        = QT_TR_NOOP("Sandbox");
00523     sMenuText     = QT_TR_NOOP("Load mesh in thread");
00524     sToolTipText  = QT_TR_NOOP("Sandbox Test function");
00525     sWhatsThis    = QT_TR_NOOP("Sandbox Test function");
00526     sStatusTip    = QT_TR_NOOP("Sandbox Test function");
00527     sPixmap       = "Std_Tool6";
00528 }
00529 
00530 void CmdSandboxMeshLoader::activated(int iMsg)
00531 {
00532     // use current path as default
00533     QStringList filter;
00534     filter << QObject::tr("All Mesh Files (*.stl *.ast *.bms *.obj)");
00535     filter << QObject::tr("Binary STL (*.stl)");
00536     filter << QObject::tr("ASCII STL (*.ast)");
00537     filter << QObject::tr("Binary Mesh (*.bms)");
00538     filter << QObject::tr("Alias Mesh (*.obj)");
00539     filter << QObject::tr("Inventor V2.1 ascii (*.iv)");
00540     //filter << "Nastran (*.nas *.bdf)";
00541     filter << QObject::tr("All Files (*.*)");
00542 
00543     // Allow multi selection
00544     QString fn = Gui::FileDialog::getOpenFileName(Gui::getMainWindow(),
00545         QObject::tr("Import mesh"), QString(), filter.join(QLatin1String(";;")));
00546 
00547     Sandbox::MeshLoaderThread thread(fn);
00548     QObject::connect(&thread, SIGNAL(finished()), &loop, SLOT(quit()));
00549 
00550     thread.start();
00551     loop.exec();
00552 
00553     Base::Reference<Mesh::MeshObject> data = thread.getMesh();
00554     App::Document* doc = App::GetApplication().getActiveDocument();
00555     Mesh::Feature* mesh = static_cast<Mesh::Feature*>(doc->addObject("Mesh::Feature","Mesh"));
00556     mesh->Mesh.setValuePtr((Mesh::MeshObject*)data);
00557     mesh->purgeTouched();
00558 }
00559 
00560 bool CmdSandboxMeshLoader::isActive(void)
00561 {
00562     return (hasActiveDocument() && !loop.isRunning());
00563 }
00564 
00565 // -------------------------------------------------------------------------------
00566 
00567 Base::Reference<Mesh::MeshObject> loadMesh(const QString& s)
00568 {
00569     Mesh::MeshObject* mesh = new Mesh::MeshObject();
00570     mesh->load((const char*)s.toUtf8());
00571     return mesh;
00572 }
00573 
00574 DEF_STD_CMD_A(CmdSandboxMeshLoaderBoost)
00575 
00576 CmdSandboxMeshLoaderBoost::CmdSandboxMeshLoaderBoost()
00577   :Command("Sandbox_MeshLoaderBoost")
00578 {
00579     sAppModule    = "Sandbox";
00580     sGroup        = QT_TR_NOOP("Sandbox");
00581     sMenuText     = QT_TR_NOOP("Load mesh in boost-thread");
00582     sToolTipText  = QT_TR_NOOP("Sandbox Test function");
00583     sWhatsThis    = QT_TR_NOOP("Sandbox Test function");
00584     sStatusTip    = QT_TR_NOOP("Sandbox Test function");
00585     sPixmap       = "Std_Tool6";
00586 }
00587 
00588 void CmdSandboxMeshLoaderBoost::activated(int iMsg)
00589 {
00590 # if BOOST_VERSION >= 104100
00591     // use current path as default
00592     QStringList filter;
00593     filter << QObject::tr("All Mesh Files (*.stl *.ast *.bms *.obj)");
00594     filter << QObject::tr("Binary STL (*.stl)");
00595     filter << QObject::tr("ASCII STL (*.ast)");
00596     filter << QObject::tr("Binary Mesh (*.bms)");
00597     filter << QObject::tr("Alias Mesh (*.obj)");
00598     filter << QObject::tr("Inventor V2.1 ascii (*.iv)");
00599     //filter << "Nastran (*.nas *.bdf)";
00600     filter << QObject::tr("All Files (*.*)");
00601 
00602     // Allow multi selection
00603     QString fn = Gui::FileDialog::getOpenFileName(Gui::getMainWindow(),
00604         QObject::tr("Import mesh"), QString(), filter.join(QLatin1String(";;")));
00605 
00606     boost::packaged_task< Base::Reference<Mesh::MeshObject> > pt
00607         (boost::bind(&loadMesh, fn));
00608     boost::unique_future< Base::Reference<Mesh::MeshObject> > fi=pt.get_future();
00609     boost::thread task(boost::move(pt)); // launch task on a thread
00610     fi.wait(); // wait for it to be finished
00611 
00612     App::Document* doc = App::GetApplication().getActiveDocument();
00613     Mesh::Feature* mesh = static_cast<Mesh::Feature*>(doc->addObject("Mesh::Feature","Mesh"));
00614     mesh->Mesh.setValuePtr((Mesh::MeshObject*)fi.get());
00615     mesh->purgeTouched();
00616 #endif
00617 }
00618 
00619 bool CmdSandboxMeshLoaderBoost::isActive(void)
00620 {
00621 # if BOOST_VERSION >= 104100
00622     return hasActiveDocument();
00623 #else
00624     return false;
00625 #endif
00626 }
00627 
00628 DEF_STD_CMD_A(CmdSandboxMeshLoaderFuture)
00629 
00630 CmdSandboxMeshLoaderFuture::CmdSandboxMeshLoaderFuture()
00631   :Command("Sandbox_MeshLoaderFuture")
00632 {
00633     sAppModule    = "Sandbox";
00634     sGroup        = QT_TR_NOOP("Sandbox");
00635     sMenuText     = QT_TR_NOOP("Load mesh in QFuture");
00636     sToolTipText  = QT_TR_NOOP("Sandbox Test function");
00637     sWhatsThis    = QT_TR_NOOP("Sandbox Test function");
00638     sStatusTip    = QT_TR_NOOP("Sandbox Test function");
00639     sPixmap       = "Std_Tool6";
00640 }
00641 
00642 void CmdSandboxMeshLoaderFuture::activated(int iMsg)
00643 {
00644     // use current path as default
00645     QStringList filter;
00646     filter << QObject::tr("All Mesh Files (*.stl *.ast *.bms *.obj)");
00647     filter << QObject::tr("Binary STL (*.stl)");
00648     filter << QObject::tr("ASCII STL (*.ast)");
00649     filter << QObject::tr("Binary Mesh (*.bms)");
00650     filter << QObject::tr("Alias Mesh (*.obj)");
00651     filter << QObject::tr("Inventor V2.1 ascii (*.iv)");
00652     //filter << "Nastran (*.nas *.bdf)";
00653     filter << QObject::tr("All Files (*.*)");
00654 
00655     // Allow multi selection
00656     QStringList fn = Gui::FileDialog::getOpenFileNames(Gui::getMainWindow(),
00657         QObject::tr("Import mesh"), QString(), filter.join(QLatin1String(";;")));
00658 
00659     QFuture< Base::Reference<Mesh::MeshObject> > future = QtConcurrent::mapped
00660         (fn, loadMesh);
00661 
00662     QFutureWatcher< Base::Reference<Mesh::MeshObject> > watcher;
00663     watcher.setFuture(future);
00664 
00665     // keep it responsive during computation
00666     QEventLoop loop;
00667     QObject::connect(&watcher, SIGNAL(finished()), &loop, SLOT(quit()));
00668     loop.exec();
00669 
00670     App::Document* doc = App::GetApplication().getActiveDocument();
00671     for (QFuture< Base::Reference<Mesh::MeshObject> >::const_iterator it = future.begin(); it != future.end(); ++it) {
00672         Mesh::Feature* mesh = static_cast<Mesh::Feature*>(doc->addObject("Mesh::Feature","Mesh"));
00673         mesh->Mesh.setValuePtr((Mesh::MeshObject*)(*it));
00674         mesh->purgeTouched();
00675     }
00676 }
00677 
00678 bool CmdSandboxMeshLoaderFuture::isActive(void)
00679 {
00680     return hasActiveDocument();
00681 }
00682 
00683 namespace Mesh {
00684 typedef Base::Reference<const MeshObject> MeshObjectConstRef;
00685 typedef std::list<MeshObjectConstRef> MeshObjectConstRefList;
00686 typedef std::vector<MeshObjectConstRef> MeshObjectConstRefArray;
00687 }
00688 
00689 struct MeshObject_greater  : public std::binary_function<const Mesh::MeshObjectConstRef&, 
00690                                                          const Mesh::MeshObjectConstRef&, bool>
00691 {
00692     bool operator()(const Mesh::MeshObjectConstRef& x,
00693                     const Mesh::MeshObjectConstRef& y) const
00694     {
00695         return x->countFacets() > y->countFacets();
00696     }
00697 };
00698 
00699 class MeshTestJob
00700 {
00701 
00702 public:
00703     MeshTestJob()
00704     {
00705     }
00706     ~MeshTestJob()
00707     {
00708     }
00709 
00710     Mesh::MeshObject* run(const std::vector<Mesh::MeshObjectConstRef>& meshdata)
00711     {
00712         std::vector<Mesh::MeshObjectConstRef> meshes = meshdata;
00713         if (meshes.empty())
00714             return 0; // nothing todo
00715         Mesh::MeshObjectConstRef myMesh = 0;
00716         std::sort(meshes.begin(), meshes.end(), MeshObject_greater());
00717         myMesh = meshes.front();
00718 
00719         if (meshes.size() > 1) {
00720             MeshCore::MeshKernel kernel;
00721 
00722             // copy the data of the first mesh, this will be the new model then
00723             kernel = myMesh->getKernel();
00724             for (std::vector<Mesh::MeshObjectConstRef>::iterator it = meshes.begin(); it != meshes.end(); ++it) {
00725                 if (*it != myMesh) {
00726                     Base::Console().Message("MeshTestJob::run() in thread: %p\n", QThread::currentThreadId());
00727                 }
00728             }
00729 
00730             // avoid to copy the data
00731             Mesh::MeshObject* mesh = new Mesh::MeshObject();
00732             mesh->swap(kernel);
00733             return mesh;
00734         }
00735         else {
00736             Mesh::MeshObject* mesh = new Mesh::MeshObject();
00737             mesh->setKernel(myMesh->getKernel());
00738             return mesh;
00739         }
00740     }
00741 };
00742 
00743 DEF_STD_CMD_A(CmdSandboxMeshTestJob)
00744 
00745 CmdSandboxMeshTestJob::CmdSandboxMeshTestJob()
00746   : Command("Sandbox_MeshTestJob")
00747 {
00748     sAppModule    = "Sandbox";
00749     sGroup        = QT_TR_NOOP("Sandbox");
00750     sMenuText     = QT_TR_NOOP("Test mesh job");
00751     sToolTipText  = QT_TR_NOOP("Sandbox Test function");
00752     sWhatsThis    = QT_TR_NOOP("Sandbox Test function");
00753     sStatusTip    = QT_TR_NOOP("Sandbox Test function");
00754     sPixmap       = "Std_Tool7";
00755 }
00756 
00757 void CmdSandboxMeshTestJob::activated(int iMsg)
00758 {
00759     Mesh::MeshObjectConstRefList meshes;
00760     App::Document* app_doc = App::GetApplication().getActiveDocument();
00761     std::vector<Mesh::Feature*> meshObj = Gui::Selection().getObjectsOfType<Mesh::Feature>(app_doc->getName());
00762     for (std::vector<Mesh::Feature*>::iterator it = meshObj.begin(); it != meshObj.end(); ++it) {
00763         meshes.push_back((*it)->Mesh.getValuePtr());
00764     }
00765 
00766     int iteration = 1;
00767     while (meshes.size() > 1) {
00768         int numJobs = QThread::idealThreadCount();
00769         if (numJobs < 0) numJobs = 2;
00770 
00771         while (numJobs > (int)(meshes.size()+1)/2)
00772             numJobs /= 2;
00773         numJobs = std::max<int>(1, numJobs);
00774 
00775         // divide all meshes we have into several groups
00776         std::vector<Mesh::MeshObjectConstRefArray> mesh_groups;
00777         while (numJobs > 0) {
00778             int size = (int)meshes.size();
00779             int count = size / numJobs;
00780             --numJobs;
00781             Mesh::MeshObjectConstRefArray meshes_per_job;
00782             for (int i=0; i<count; i++) {
00783                 meshes_per_job.push_back(meshes.front());
00784                 meshes.pop_front();
00785             }
00786             mesh_groups.push_back(meshes_per_job);
00787         }
00788 
00789         // run the actual multi-threaded mesh test
00790         Base::Console().Message("Mesh test (step %d)...\n",iteration++);
00791         MeshTestJob meshJob;
00792         QFuture<Mesh::MeshObject*> mesh_future = QtConcurrent::mapped
00793             (mesh_groups, boost::bind(&MeshTestJob::run, &meshJob, _1));
00794 
00795         // keep it responsive during computation
00796         QFutureWatcher<Mesh::MeshObject*> mesh_watcher;
00797         mesh_watcher.setFuture(mesh_future);
00798         QEventLoop loop;
00799         QObject::connect(&mesh_watcher, SIGNAL(finished()), &loop, SLOT(quit()));
00800         loop.exec();
00801 
00802         for (QFuture<Mesh::MeshObject*>::const_iterator it = mesh_future.begin(); it != mesh_future.end(); ++it) {
00803             meshes.push_back(Mesh::MeshObjectConstRef(*it));
00804         }
00805     }
00806 
00807     if (meshes.empty()) {
00808         Base::Console().Error("The mesh test failed to create a valid mesh.\n");
00809         return;
00810     }
00811 }
00812 
00813 bool CmdSandboxMeshTestJob::isActive(void)
00814 {
00815     return hasActiveDocument();
00816 }
00817 
00818 class MeshThread : public QThread
00819 {
00820 public:
00821     MeshThread(Base::Reference<Mesh::MeshObject> m, QObject* p=0)
00822         : QThread(p), mesh(m)
00823     {}
00824 
00825 protected:
00826     void run()
00827     {
00828         for (int i=0; i<100;i++) {
00829             Base::Reference<Mesh::MeshObject> new_ref;
00830             new_ref = mesh;
00831         }
00832     }
00833 
00834 private:
00835     Base::Reference<Mesh::MeshObject> mesh;
00836 };
00837 
00838 DEF_STD_CMD_A(CmdSandboxMeshTestRef)
00839 
00840 CmdSandboxMeshTestRef::CmdSandboxMeshTestRef()
00841   : Command("Sandbox_MeshTestRef")
00842 {
00843     sAppModule    = "Sandbox";
00844     sGroup        = QT_TR_NOOP("Sandbox");
00845     sMenuText     = QT_TR_NOOP("Test mesh reference");
00846     sToolTipText  = QT_TR_NOOP("Sandbox Test function");
00847     sWhatsThis    = QT_TR_NOOP("Sandbox Test function");
00848     sStatusTip    = QT_TR_NOOP("Sandbox Test function");
00849 }
00850 
00851 void CmdSandboxMeshTestRef::activated(int iMsg)
00852 {
00853     Gui::WaitCursor wc;
00854     std::vector< boost::shared_ptr<QThread> > threads;
00855     Base::Reference<Mesh::MeshObject> mesh(new Mesh::MeshObject);
00856     int num = mesh.getRefCount();
00857 
00858     for (int i=0; i<10; i++) {
00859         boost::shared_ptr<QThread> trd(new MeshThread(mesh));
00860         trd->start();
00861         threads.push_back(trd);
00862     }
00863 
00864     QTimer timer;
00865     QEventLoop loop;
00866     QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
00867     timer.start(2000);
00868     loop.exec();
00869     threads.clear();
00870 
00871     Mesh::MeshObject* ptr = (Mesh::MeshObject*)mesh;
00872     if (!ptr)
00873         Base::Console().Error("Object deleted\n");
00874     if (num != mesh.getRefCount())
00875         Base::Console().Error("Reference count is %d\n",mesh.getRefCount());
00876 }
00877 
00878 bool CmdSandboxMeshTestRef::isActive(void)
00879 {
00880     return true;
00881 }
00882 
00883 //===========================================================================
00884 // Std_GrabWidget
00885 //===========================================================================
00886 DEF_STD_CMD_A(CmdTestGrabWidget);
00887 
00888 CmdTestGrabWidget::CmdTestGrabWidget()
00889   : Command("Std_GrabWidget")
00890 {
00891     sGroup          = "Standard-Test";
00892     sMenuText       = "Grab widget";
00893     sToolTipText    = "Grab widget";
00894     sWhatsThis      = sToolTipText;
00895     sStatusTip      = sToolTipText;
00896 }
00897 
00898 void CmdTestGrabWidget::activated(int iMsg)
00899 {
00900     QCalendarWidget* c = new QCalendarWidget();
00901     c->hide();
00902     QPixmap p = QPixmap::grabWidget(c, c->rect());
00903     QLabel* label = new QLabel();
00904     label->resize(c->size());
00905     label->setPixmap(p);
00906     label->show();
00907     delete c;
00908 }
00909 
00910 bool CmdTestGrabWidget::isActive(void)
00911 {
00912     return true;
00913 }
00914 
00915 //===========================================================================
00916 // Std_ImageNode
00917 //===========================================================================
00918 DEF_3DV_CMD(CmdTestImageNode);
00919 
00920 class RenderArea : public QWidget
00921 {
00922 private:
00923     QPainterPath path;
00924     int penWidth;
00925     QColor penColor;
00926 
00927 public:
00928     RenderArea(const QPainterPath &path, QWidget *parent=0)
00929       : QWidget(parent), path(path), penColor(0,0,127)
00930     {
00931         penWidth = 2;
00932         setBackgroundRole(QPalette::Base);
00933     }
00934 
00935     QSize minimumSizeHint() const
00936     {
00937         return QSize(50, 50);
00938     }
00939 
00940     QSize sizeHint() const
00941     {
00942         return QSize(100, 30);
00943     }
00944 
00945     void setFillRule(Qt::FillRule rule)
00946     {
00947         path.setFillRule(rule);
00948         update();
00949     }
00950 
00951     void setPenWidth(int width)
00952     {
00953         penWidth = width;
00954         update();
00955     }
00956 
00957     void setPenColor(const QColor &color)
00958     {
00959         penColor = color;
00960         update();
00961     }
00962 
00963     void paintEvent(QPaintEvent *)
00964     {
00965         QPainter painter(this);
00966         painter.setRenderHint(QPainter::Antialiasing);
00967 
00968         painter.scale(width() / 100.0, height() / 100.0);
00969         painter.translate(50.0, 50.0);
00970         painter.translate(-50.0, -50.0);
00971 
00972         painter.setPen(QPen(penColor, penWidth, Qt::SolidLine, Qt::RoundCap,
00973                             Qt::RoundJoin));
00974         painter.setBrush(QBrush(QColor(0,85,255), Qt::SolidPattern));
00975         painter.drawPath(path);
00976         painter.setPen(Qt::white);
00977         painter.drawText(25, 40, 70, 20, Qt::AlignHCenter|Qt::AlignVCenter,
00978             QString::fromAscii("Distance: 2.784mm"));
00979         //QPainterPath text;
00980         //text.addText(25,55,QFont(), QString::fromAscii("Distance"));
00981         //painter.setBrush(QBrush(Qt::white, Qt::SolidPattern));
00982         //painter.drawPath(text);
00983     }
00984 };
00985 
00986 #ifdef Q_OS_WIN32
00987 class GDIWidget : public QWidget
00988 {
00989 public:
00990     GDIWidget(QWidget* parent) : QWidget(parent)
00991     {setAttribute(Qt::WA_PaintOnScreen); }
00992     QPaintEngine *paintEngine() const { return 0; }
00993 protected:
00994     void paintEvent(QPaintEvent *event) {
00995         HDC hdc = getDC();
00996         SelectObject(hdc, GetSysColorBrush(COLOR_WINDOW));
00997         Rectangle(hdc, 0, 0, width(), height());
00998         RECT rect = {0, 0, width(), height() };
00999         DrawText(hdc, "Hello World!", 12, &rect,
01000         DT_SINGLELINE | DT_VCENTER | DT_CENTER);
01001         releaseDC(hdc);
01002     }
01003 };
01004 #endif
01005 
01006 CmdTestImageNode::CmdTestImageNode()
01007   : Command("Std_ImageNode")
01008 {
01009     sGroup          = "Standard-Test";
01010     sMenuText       = "SoImage node";
01011     sToolTipText    = "SoImage node";
01012     sWhatsThis      = sToolTipText;
01013     sStatusTip      = sToolTipText;
01014 }
01015 
01016 void CmdTestImageNode::activated(int iMsg)
01017 {
01018     QString text = QString::fromAscii("Distance: 2.7jgiorjgor84mm");
01019     QFont font;
01020     QFontMetrics fm(font);
01021     int w = fm.width(text);
01022     int h = fm.height();
01023 
01024 
01025     QPainterPath roundRectPath;
01026     //roundRectPath.moveTo(80.0, 35.0);
01027     //roundRectPath.arcTo(70.0, 30.0, 10.0, 10.0, 0.0, 90.0);
01028     //roundRectPath.lineTo(25.0, 30.0);
01029     //roundRectPath.arcTo(20.0, 30.0, 10.0, 10.0, 90.0, 90.0);
01030     //roundRectPath.lineTo(20.0, 65.0);
01031     //roundRectPath.arcTo(20.0, 60.0, 10.0, 10.0, 180.0, 90.0);
01032     //roundRectPath.lineTo(75.0, 70.0);
01033     //roundRectPath.arcTo(70.0, 60.0, 10.0, 10.0, 270.0, 90.0);
01034     roundRectPath.moveTo(100.0, 5.0);
01035     roundRectPath.arcTo(90.0, 0.0, 10.0, 10.0, 0.0, 90.0);
01036     roundRectPath.lineTo(5.0, 0.0);
01037     roundRectPath.arcTo(0.0, 0.0, 10.0, 10.0, 90.0, 90.0);
01038     roundRectPath.lineTo(0.0, 95.0);
01039     roundRectPath.arcTo(0.0, 90.0, 10.0, 10.0, 180.0, 90.0);
01040     roundRectPath.lineTo(95.0, 100.0);
01041     roundRectPath.arcTo(90.0, 90.0, 10.0, 10.0, 270.0, 90.0);
01042     roundRectPath.closeSubpath();
01043 
01044 
01045     QLabel* l = new QLabel();
01046     //l.setText(QLatin1String("Distance: 2.784mm"));
01047     //QPixmap p = QPixmap::grabWidget(&l, 0,0,100,100);
01048     //l.show();
01049     //QPixmap p = Gui::BitmapFactory().pixmap("edit-cut");
01050 
01051     Gui::MDIView* view = Gui::getMainWindow()->activeWindow();
01052     Gui::View3DInventorViewer* viewer = static_cast<Gui::View3DInventor*>(view)->getViewer();
01053     SoImage* node = new SoImage();
01054 
01055     QImage image(w+10,h+10,QImage::Format_ARGB32_Premultiplied);// = p.toImage();
01056     image.fill(0x00000000);
01057     QPainter painter(&image);
01058     painter.setRenderHint(QPainter::Antialiasing);
01059 
01060     painter.setPen(QPen(QColor(0,0,127), 2, Qt::SolidLine, Qt::RoundCap,
01061                         Qt::RoundJoin));
01062     painter.setBrush(QBrush(QColor(0,85,255), Qt::SolidPattern));
01063     QRectF rectangle(0.0, 0.0, w+10, h+10);
01064     painter.drawRoundedRect(rectangle, 5, 5);
01065     //painter.drawRect(rectangle);
01066     //painter.drawPath(roundRectPath);
01067     painter.setPen(QColor(255,255,255));
01068     painter.drawText(5,h+3, text);
01069     painter.end();
01070     //l->setPixmap(QPixmap::fromImage(image));
01071     //l->show();
01072     //RenderArea* ra = new RenderArea(roundRectPath);
01073     //ra->show();
01074 
01075     //QPixmap p = QPixmap::grabWidget(ra, 0,0,100,30);
01076     //image = p.toImage();
01077 
01078     SoSFImage texture;
01079     Gui::BitmapFactory().convert(image, texture);
01080     node->image = texture;
01081     SoAnnotation* anno = new SoAnnotation();
01082     anno->addChild(node);
01083     static_cast<SoGroup*>(viewer->getSceneGraph())->addChild(anno);
01084 }
01085 
01086 //===========================================================================
01087 // Sandbox_GDIWidget
01088 //===========================================================================
01089 DEF_STD_CMD(CmdTestGDIWidget);
01090 
01091 CmdTestGDIWidget::CmdTestGDIWidget()
01092   : Command("Sandbox_GDIWidget")
01093 {
01094     sGroup          = "Standard-Test";
01095     sMenuText       = "GDI widget";
01096     sToolTipText    = "GDI widget";
01097     sWhatsThis      = sToolTipText;
01098     sStatusTip      = sToolTipText;
01099 }
01100 
01101 void CmdTestGDIWidget::activated(int iMsg)
01102 {
01103 #ifdef Q_OS_WIN32
01104     GDIWidget* gdi = new GDIWidget(Gui::getMainWindow());
01105     gdi->show();
01106     gdi->resize(200,200);
01107     gdi->move(400,400);
01108     gdi->setAttribute(Qt::WA_DeleteOnClose);
01109 #endif
01110 }
01111 
01112 //===========================================================================
01113 // Sandbox_RedirectPaint
01114 //===========================================================================
01115 DEF_STD_CMD(CmdTestRedirectPaint);
01116 
01117 CmdTestRedirectPaint::CmdTestRedirectPaint()
01118   : Command("Sandbox_RedirectPaint")
01119 {
01120     sGroup          = "Standard-Test";
01121     sMenuText       = "Redirect paint";
01122     sToolTipText    = "Redirect paint";
01123     sWhatsThis      = sToolTipText;
01124     sStatusTip      = sToolTipText;
01125 }
01126 
01127 void CmdTestRedirectPaint::activated(int iMsg)
01128 {
01129     QCalendarWidget* cal = new QCalendarWidget();
01130     QLabel* label = new QLabel();
01131     QPainter::setRedirected(cal,label);
01132     cal->setWindowTitle(QString::fromAscii("QCalendarWidget"));
01133     cal->show();
01134     label->show();
01135     label->setWindowTitle(QString::fromAscii("QLabel"));
01136 }
01137 
01138 //===========================================================================
01139 // Sandbox_CryptographicHash
01140 //===========================================================================
01141 DEF_STD_CMD(CmdTestCryptographicHash);
01142 
01143 CmdTestCryptographicHash::CmdTestCryptographicHash()
01144   : Command("Sandbox_CryptographicHash")
01145 {
01146     sGroup          = "Standard-Test";
01147     sMenuText       = "Cryptographic Hash";
01148     sToolTipText    = "Cryptographic Hash";
01149     sWhatsThis      = sToolTipText;
01150     sStatusTip      = sToolTipText;
01151 }
01152 
01153 void CmdTestCryptographicHash::activated(int iMsg)
01154 {
01155     QByteArray data = "FreeCAD";
01156     QByteArray hash = QCryptographicHash::hash(data, QCryptographicHash::Md5);
01157     QMessageBox::information(0,QLatin1String("Hash of: FreeCAD"),QString::fromAscii(hash));
01158 }
01159 
01160 //===========================================================================
01161 // Sandbox_WidgetShape
01162 //===========================================================================
01163 DEF_3DV_CMD(CmdTestWidgetShape);
01164 
01165 CmdTestWidgetShape::CmdTestWidgetShape()
01166   : Command("Sandbox_WidgetShape")
01167 {
01168     sGroup          = "Standard-Test";
01169     sMenuText       = "Widget shape";
01170     sToolTipText    = "Widget shape";
01171     sWhatsThis      = sToolTipText;
01172     sStatusTip      = sToolTipText;
01173 }
01174 
01175 void CmdTestWidgetShape::activated(int iMsg)
01176 {
01177     SandboxGui::SoWidgetShape* shape = new SandboxGui::SoWidgetShape;
01178     shape->setWidget(new QCalendarWidget());
01179     Gui::MDIView* view = Gui::getMainWindow()->activeWindow();
01180     Gui::View3DInventorViewer* viewer = static_cast<Gui::View3DInventor*>(view)->getViewer();
01181     static_cast<SoGroup*>(viewer->getSceneGraph())->addChild(shape);
01182 }
01183 
01184 //===========================================================================
01185 // Sandbox_PlaneViewer
01186 //===========================================================================
01187 DEF_STD_CMD(CmdSandboxPlaneViewer);
01188 
01189 CmdSandboxPlaneViewer::CmdSandboxPlaneViewer()
01190   : Command("Sandbox_PlaneViewer")
01191 {
01192     sGroup          = "Standard-Test";
01193     sMenuText       = "Plane viewer";
01194     sToolTipText    = "Plane viewer";
01195     sWhatsThis      = sToolTipText;
01196     sStatusTip      = sToolTipText;
01197 }
01198 
01199 void CmdSandboxPlaneViewer::activated(int iMsg)
01200 {
01201     SoQtPlaneViewer* viewer = new SoQtPlaneViewer();
01202     viewer->show();
01203     viewer->setSceneGraph(new SoCone);
01204 }
01205 
01206 //===========================================================================
01207 // Sandbox_ExaminerViewer
01208 //===========================================================================
01209 DEF_STD_CMD(CmdSandboxExaminerViewer);
01210 
01211 CmdSandboxExaminerViewer::CmdSandboxExaminerViewer()
01212   : Command("Sandbox_ExaminerViewer")
01213 {
01214     sGroup          = "Standard-Test";
01215     sMenuText       = "Examiner viewer";
01216     sToolTipText    = "Examiner viewer";
01217     sWhatsThis      = sToolTipText;
01218     sStatusTip      = sToolTipText;
01219 }
01220 
01221 void CmdSandboxExaminerViewer::activated(int iMsg)
01222 {
01223     SoQtExaminerViewer* viewer = new SoQtExaminerViewer();
01224     viewer->show();
01225     viewer->setSceneGraph(new SoCone);
01226 }
01227 
01228 //===========================================================================
01229 // Sandbox_FlyViewer
01230 //===========================================================================
01231 DEF_STD_CMD(CmdSandboxFlyViewer);
01232 
01233 CmdSandboxFlyViewer::CmdSandboxFlyViewer()
01234   : Command("Sandbox_FlyViewer")
01235 {
01236     sGroup          = "Standard-Test";
01237     sMenuText       = "Fly viewer";
01238     sToolTipText    = "Fly viewer";
01239     sWhatsThis      = sToolTipText;
01240     sStatusTip      = sToolTipText;
01241 }
01242 
01243 void CmdSandboxFlyViewer::activated(int iMsg)
01244 {
01245     SoQtFlyViewer* viewer = new SoQtFlyViewer();
01246     viewer->show();
01247     viewer->setSceneGraph(new SoCone);
01248 }
01249 
01250 
01251 void CreateSandboxCommands(void)
01252 {
01253     Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager();
01254     rcCmdMgr.addCommand(new CmdSandboxDocumentThread());
01255     rcCmdMgr.addCommand(new CmdSandboxDocumentTestThread());
01256     rcCmdMgr.addCommand(new CmdSandboxDocThreadWithSeq());
01257     rcCmdMgr.addCommand(new CmdSandboxDocThreadBusy());
01258     rcCmdMgr.addCommand(new CmdSandboxDocumentNoThread());
01259     rcCmdMgr.addCommand(new CmdSandboxWorkerThread());
01260     rcCmdMgr.addCommand(new CmdSandboxPythonLockThread());
01261     rcCmdMgr.addCommand(new CmdSandboxPythonNolockThread());
01262     rcCmdMgr.addCommand(new CmdSandboxPyQtThread());
01263     rcCmdMgr.addCommand(new CmdSandboxPythonThread());
01264     rcCmdMgr.addCommand(new CmdSandboxPythonMainThread());
01265     rcCmdMgr.addCommand(new CmdSandboxDocThreadWithDialog());
01266     rcCmdMgr.addCommand(new CmdSandboxDocThreadWithFileDlg());
01267     rcCmdMgr.addCommand(new CmdSandboxEventLoop);
01268     rcCmdMgr.addCommand(new CmdSandboxMeshLoader);
01269     rcCmdMgr.addCommand(new CmdSandboxMeshLoaderBoost);
01270     rcCmdMgr.addCommand(new CmdSandboxMeshLoaderFuture);
01271     rcCmdMgr.addCommand(new CmdSandboxMeshTestJob);
01272     rcCmdMgr.addCommand(new CmdSandboxMeshTestRef);
01273     rcCmdMgr.addCommand(new CmdTestGrabWidget());
01274     rcCmdMgr.addCommand(new CmdTestImageNode());
01275     rcCmdMgr.addCommand(new CmdTestWidgetShape());
01276     rcCmdMgr.addCommand(new CmdTestGDIWidget());
01277     rcCmdMgr.addCommand(new CmdTestRedirectPaint());
01278     rcCmdMgr.addCommand(new CmdTestCryptographicHash());
01279     rcCmdMgr.addCommand(new CmdSandboxPlaneViewer());
01280     rcCmdMgr.addCommand(new CmdSandboxExaminerViewer());
01281     rcCmdMgr.addCommand(new CmdSandboxFlyViewer());
01282 }

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