24
#include "PreCompiled.h"
27
# define WIN32_LEAN_AND_MEAN
31
# include <QApplication>
32
# include <QCalendarWidget>
33
# include <QColorDialog>
34
# include <QCryptographicHash>
37
# include <QFontMetrics>
39
# include <QFutureWatcher>
40
# include <QtConcurrentMap>
42
# include <QInputDialog>
43
# include <QMessageBox>
46
# include <QImageReader>
48
# include <QPainterPath>
50
# include <Inventor/nodes/SoAnnotation.h>
51
# include <Inventor/nodes/SoImage.h>
52
# include <Inventor/nodes/SoCone.h>
54
# include <boost/thread/thread.hpp>
55
# include <boost/thread/mutex.hpp>
56
# include <boost/thread/condition_variable.hpp>
57
# include <boost/thread/future.hpp>
58
# include <boost/bind/bind.hpp>
62
#include <Base/Console.h>
63
#include <Base/Sequencer.h>
64
#include <App/Application.h>
65
#include <App/Document.h>
66
#include <Gui/Application.h>
67
#include <Gui/BitmapFactory.h>
68
#include <Gui/Command.h>
69
#include <Gui/MainWindow.h>
70
#include <Gui/FileDialog.h>
72
#include <Gui/View3DInventor.h>
73
#include <Gui/View3DInventorViewer.h>
74
#include <Gui/WaitCursor.h>
76
#include <Mod/Sandbox/App/DocumentThread.h>
77
#include <Mod/Sandbox/App/DocumentProtector.h>
78
#include <Mod/Mesh/App/MeshFeature.h>
79
#include <Mod/Mesh/App/Core/Degeneration.h>
81
#include "GLGraphicsView.h"
82
#include "TaskPanelView.h"
84
namespace bp = boost::placeholders;
86
DEF_STD_CMD(CmdSandboxDocumentThread)
88
CmdSandboxDocumentThread::CmdSandboxDocumentThread()
89
:Command("Sandbox_Thread")
91
sAppModule = "Sandbox";
92
sGroup = QT_TR_NOOP("Sandbox");
93
sMenuText = QT_TR_NOOP("Run several threads");
94
sToolTipText = QT_TR_NOOP("Sandbox Test function");
95
sWhatsThis = "Sandbox_Thread";
96
sStatusTip = QT_TR_NOOP("Sandbox Test function");
97
sPixmap = "Std_Tool1";
100
void CmdSandboxDocumentThread::activated(int)
102
App::GetApplication().newDocument("Thread");
103
for (int i=0; i<5; i++) {
104
Sandbox::DocumentThread* dt = new Sandbox::DocumentThread();
105
dt->setObjectName(QString::fromLatin1("MyMesh_%1").arg(i));
106
QObject::connect(dt, SIGNAL(finished()), dt, SLOT(deleteLater()));
113
DEF_STD_CMD(CmdSandboxDocumentTestThread)
115
CmdSandboxDocumentTestThread::CmdSandboxDocumentTestThread()
116
:Command("Sandbox_TestThread")
118
sAppModule = "Sandbox";
119
sGroup = QT_TR_NOOP("Sandbox");
120
sMenuText = QT_TR_NOOP("Test thread");
121
sToolTipText = QT_TR_NOOP("Sandbox Test function");
122
sWhatsThis = "Sandbox_TestThread";
123
sStatusTip = QT_TR_NOOP("Sandbox Test function");
124
sPixmap = "Std_Tool1";
127
void CmdSandboxDocumentTestThread::activated(int)
129
App::GetApplication().newDocument("Thread");
130
Sandbox::DocumentTestThread* dt = new Sandbox::DocumentTestThread();
131
QObject::connect(dt, SIGNAL(finished()), dt, SLOT(deleteLater()));
137
DEF_STD_CMD_A(CmdSandboxDocumentSaveThread)
139
CmdSandboxDocumentSaveThread::CmdSandboxDocumentSaveThread()
140
:Command("Sandbox_SaveThread")
142
sAppModule = "Sandbox";
143
sGroup = QT_TR_NOOP("Sandbox");
144
sMenuText = QT_TR_NOOP("Save thread");
145
sToolTipText = QT_TR_NOOP("Sandbox save function");
146
sWhatsThis = "Sandbox_SaveThread";
147
sStatusTip = QT_TR_NOOP("Sandbox save function");
150
void CmdSandboxDocumentSaveThread::activated(int)
152
App::Document* doc = App::GetApplication().getActiveDocument();
153
Sandbox::DocumentSaverThread* dt = new Sandbox::DocumentSaverThread(doc);
154
QObject::connect(dt, SIGNAL(finished()), dt, SLOT(deleteLater()));
158
bool CmdSandboxDocumentSaveThread::isActive()
160
return App::GetApplication().getActiveDocument() != 0;
165
DEF_STD_CMD(CmdSandboxDocThreadWithSeq)
167
CmdSandboxDocThreadWithSeq::CmdSandboxDocThreadWithSeq()
168
:Command("Sandbox_SeqThread")
170
sAppModule = "Sandbox";
171
sGroup = QT_TR_NOOP("Sandbox");
172
sMenuText = QT_TR_NOOP("Thread and sequencer");
173
sToolTipText = QT_TR_NOOP("Sandbox Test function");
174
sWhatsThis = "Sandbox_SeqThread";
175
sStatusTip = QT_TR_NOOP("Sandbox Test function");
176
sPixmap = "Std_Tool2";
179
void CmdSandboxDocThreadWithSeq::activated(int)
181
App::GetApplication().newDocument("Thread");
182
Sandbox::DocumentThread* dt = new Sandbox::DocumentThread();
183
dt->setObjectName(QString::fromLatin1("MyMesh"));
184
QObject::connect(dt, SIGNAL(finished()), dt, SLOT(deleteLater()));
191
Base::SequencerLauncher seq("Do something meaningful...", max);
193
for (int i=0; i<max; i++) {
194
for (int j=0; j<max; j++) {
204
DEF_STD_CMD(CmdSandboxDocThreadBusy)
206
CmdSandboxDocThreadBusy::CmdSandboxDocThreadBusy()
207
:Command("Sandbox_BlockThread")
209
sAppModule = "Sandbox";
210
sGroup = QT_TR_NOOP("Sandbox");
211
sMenuText = QT_TR_NOOP("Thread and no sequencer");
212
sToolTipText = QT_TR_NOOP("Sandbox Test function");
213
sWhatsThis = "Sandbox_BlockThread";
214
sStatusTip = QT_TR_NOOP("Sandbox Test function");
215
sPixmap = "Std_Tool3";
218
void CmdSandboxDocThreadBusy::activated(int)
220
App::GetApplication().newDocument("Thread");
221
Sandbox::DocumentThread* dt = new Sandbox::DocumentThread();
222
dt->setObjectName(QString::fromLatin1("MyMesh"));
223
QObject::connect(dt, SIGNAL(finished()), dt, SLOT(deleteLater()));
231
for (int i=0; i<max; i++) {
232
for (int j=0; j<max; j++) {
241
DEF_STD_CMD(CmdSandboxDocumentNoThread)
243
CmdSandboxDocumentNoThread::CmdSandboxDocumentNoThread()
244
:Command("Sandbox_NoThread")
246
sAppModule = "Sandbox";
247
sGroup = QT_TR_NOOP("Sandbox");
248
sMenuText = QT_TR_NOOP("GUI thread");
249
sToolTipText = QT_TR_NOOP("Sandbox Test function");
250
sWhatsThis = "Sandbox_NoThread";
251
sStatusTip = QT_TR_NOOP("Sandbox Test function");
252
sPixmap = "Std_Tool4";
255
void CmdSandboxDocumentNoThread::activated(int)
257
App::GetApplication().newDocument("Thread");
258
App::Document* doc = App::GetApplication().getActiveDocument();
259
Sandbox::DocumentProtector dp(doc);
260
App::DocumentObject* obj = dp.addObject("Mesh::Cube", "MyCube");
263
App::GetApplication().closeDocument("Thread");
265
App::DocumentObject* obj2 = dp.addObject("Mesh::Cube", "MyCube");
272
DEF_STD_CMD(CmdSandboxWorkerThread)
274
CmdSandboxWorkerThread::CmdSandboxWorkerThread()
275
:Command("Sandbox_WorkerThread")
277
sAppModule = "Sandbox";
278
sGroup = QT_TR_NOOP("Sandbox");
279
sMenuText = QT_TR_NOOP("Worker thread");
280
sToolTipText = QT_TR_NOOP("Sandbox Test function");
281
sWhatsThis = "Sandbox_WorkerThread";
282
sStatusTip = QT_TR_NOOP("Sandbox Test function");
283
sPixmap = "Std_Tool1";
286
void CmdSandboxWorkerThread::activated(int)
288
Sandbox::WorkerThread* wt = new Sandbox::WorkerThread();
289
QObject::connect(wt, SIGNAL(finished()), wt, SLOT(deleteLater()));
295
DEF_STD_CMD(CmdSandboxPythonLockThread)
297
CmdSandboxPythonLockThread::CmdSandboxPythonLockThread()
298
:Command("Sandbox_PythonLockThread")
300
sAppModule = "Sandbox";
301
sGroup = QT_TR_NOOP("Sandbox");
302
sMenuText = QT_TR_NOOP("Locked Python threads");
303
sToolTipText = QT_TR_NOOP("Use Python's thread module where each thread is locked");
304
sWhatsThis = "Sandbox_PythonLockThread";
305
sStatusTip = QT_TR_NOOP("Use Python's thread module where each thread is locked");
308
void CmdSandboxPythonLockThread::activated(int)
311
"import thread, time, Sandbox\n"
314
" dp=Sandbox.DocumentProtector(doc)\n"
315
" dp.addObject(\"Mesh::Ellipsoid\",\"Mesh\")\n"
319
"lock=thread.allocate_lock()\n"
320
"doc=App.newDocument()\n"
321
"for i in range(2):\n"
322
" thread.start_new(adder,(doc,))\n"
330
DEF_STD_CMD(CmdSandboxPythonNolockThread)
332
CmdSandboxPythonNolockThread::CmdSandboxPythonNolockThread()
333
:Command("Sandbox_NolockPython")
335
sAppModule = "Sandbox";
336
sGroup = QT_TR_NOOP("Sandbox");
337
sMenuText = QT_TR_NOOP("Unlocked Python threads");
338
sToolTipText = QT_TR_NOOP("Use Python's thread module where each thread is unlocked");
339
sWhatsThis = "Sandbox_NolockPython";
340
sStatusTip = QT_TR_NOOP("Use Python's thread module where each thread is unlocked");
343
void CmdSandboxPythonNolockThread::activated(int)
346
"import thread, time, Sandbox\n"
348
" dp=Sandbox.DocumentProtector(doc)\n"
349
" dp.addObject(\"Mesh::Ellipsoid\",\"Mesh\")\n"
352
"doc=App.newDocument()\n"
353
"for i in range(2):\n"
354
" thread.start_new(adder,(doc,))\n"
362
DEF_STD_CMD(CmdSandboxPySideThread)
364
CmdSandboxPySideThread::CmdSandboxPySideThread()
365
:Command("Sandbox_PySideThread")
367
sAppModule = "Sandbox";
368
sGroup = QT_TR_NOOP("Sandbox");
369
sMenuText = QT_TR_NOOP("PySide threads");
370
sToolTipText = QT_TR_NOOP("Use PySide's thread module");
371
sWhatsThis = "Sandbox_PySideThread";
372
sStatusTip = QT_TR_NOOP("Use PySide's thread module");
375
void CmdSandboxPySideThread::activated(int)
378
"from PySide import QtCore; import Sandbox\n"
379
"class Thread(QtCore.QThread):\n"
381
" dp=Sandbox.DocumentProtector(doc)\n"
382
" dp.addObject(\"Mesh::Ellipsoid\",\"Mesh\")\n"
385
"doc=App.newDocument()\n"
387
"for i in range(2):\n"
389
" threads.append(thread)\n"
397
DEF_STD_CMD(CmdSandboxPythonThread)
399
CmdSandboxPythonThread::CmdSandboxPythonThread()
400
:Command("Sandbox_PythonThread")
402
sAppModule = "Sandbox";
403
sGroup = QT_TR_NOOP("Sandbox");
404
sMenuText = QT_TR_NOOP("Python threads");
405
sToolTipText = QT_TR_NOOP("Use class PythonThread running Python code in its run() method");
406
sWhatsThis = "Sandbox_PythonThread";
407
sStatusTip = QT_TR_NOOP("Use class PythonThread running Python code in its run() method");
410
void CmdSandboxPythonThread::activated(int)
412
App::GetApplication().newDocument("Thread");
413
for (int i=0; i<5; i++) {
414
Sandbox::PythonThread* pt = new Sandbox::PythonThread();
415
pt->setObjectName(QString::fromLatin1("MyMesh_%1").arg(i));
416
QObject::connect(pt, SIGNAL(finished()), pt, SLOT(deleteLater()));
423
DEF_STD_CMD(CmdSandboxPythonMainThread)
425
CmdSandboxPythonMainThread::CmdSandboxPythonMainThread()
426
:Command("Sandbox_PythonMainThread")
428
sAppModule = "Sandbox";
429
sGroup = QT_TR_NOOP("Sandbox");
430
sMenuText = QT_TR_NOOP("Python main thread");
431
sToolTipText = QT_TR_NOOP("Run python code in main thread");
432
sWhatsThis = "Sandbox_PythonMainThread";
433
sStatusTip = QT_TR_NOOP("Run python code in main thread");
436
void CmdSandboxPythonMainThread::activated(int)
440
"doc=App.newDocument()\n"
441
"dp=Sandbox.DocumentProtector(doc)\n"
442
"dp.addObject(\"Mesh::Ellipsoid\",\"Mesh\")\n"
449
DEF_STD_CMD(CmdSandboxDocThreadWithDialog)
451
CmdSandboxDocThreadWithDialog::CmdSandboxDocThreadWithDialog()
452
:Command("Sandbox_Dialog")
454
sAppModule = "Sandbox";
455
sGroup = QT_TR_NOOP("Sandbox");
456
sMenuText = QT_TR_NOOP("Thread and modal dialog");
457
sToolTipText = QT_TR_NOOP("Sandbox Test function");
458
sWhatsThis = "Sandbox_Dialog";
459
sStatusTip = QT_TR_NOOP("Sandbox Test function");
460
sPixmap = "Std_Tool7";
463
void CmdSandboxDocThreadWithDialog::activated(int)
465
App::GetApplication().newDocument("Thread");
466
Sandbox::DocumentThread* dt = new Sandbox::DocumentThread();
467
dt->setObjectName(QString::fromLatin1("MyMesh"));
468
QObject::connect(dt, SIGNAL(finished()), dt, SLOT(deleteLater()));
471
QColorDialog::getColor(Qt::white,Gui::getMainWindow());
476
DEF_STD_CMD(CmdSandboxDocThreadWithFileDlg)
478
CmdSandboxDocThreadWithFileDlg::CmdSandboxDocThreadWithFileDlg()
479
:Command("Sandbox_FileDialog")
481
sAppModule = "Sandbox";
482
sGroup = QT_TR_NOOP("Sandbox");
483
sMenuText = QT_TR_NOOP("Thread and file dialog");
484
sToolTipText = QT_TR_NOOP("Sandbox Test function");
485
sWhatsThis = "Sandbox_FileDialog";
486
sStatusTip = QT_TR_NOOP("Sandbox Test function");
487
sPixmap = "Std_Tool7";
490
void CmdSandboxDocThreadWithFileDlg::activated(int)
492
App::GetApplication().newDocument("Thread");
493
Sandbox::DocumentThread* dt = new Sandbox::DocumentThread();
494
dt->setObjectName(QString::fromLatin1("MyMesh"));
495
QObject::connect(dt, SIGNAL(finished()), dt, SLOT(deleteLater()));
497
QFileDialog::getOpenFileName();
502
class CmdSandboxEventLoop : public Gui::Command
505
CmdSandboxEventLoop();
506
const char* className() const
507
{ return "CmdSandboxEventLoop"; }
509
void activated(int iMsg);
516
CmdSandboxEventLoop::CmdSandboxEventLoop()
517
:Command("Sandbox_EventLoop")
519
sAppModule = "Sandbox";
520
sGroup = QT_TR_NOOP("Sandbox");
521
sMenuText = QT_TR_NOOP("Local event loop");
522
sToolTipText = QT_TR_NOOP("Sandbox Test function");
523
sWhatsThis = "Sandbox_EventLoop";
524
sStatusTip = QT_TR_NOOP("Sandbox Test function");
525
sPixmap = "Std_Tool6";
528
void CmdSandboxEventLoop::activated(int)
531
timer.setSingleShot(true);
532
QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
536
Base::Console().Message("CmdSandboxEventLoop: timeout\n");
539
bool CmdSandboxEventLoop::isActive(void)
541
return (!loop.isRunning());
546
class CmdSandboxMeshLoader : public Gui::Command
549
CmdSandboxMeshLoader();
550
const char* className() const
551
{ return "CmdSandboxMeshLoader"; }
553
void activated(int iMsg);
559
CmdSandboxMeshLoader::CmdSandboxMeshLoader()
560
:Command("Sandbox_MeshLoad")
562
sAppModule = "Sandbox";
563
sGroup = QT_TR_NOOP("Sandbox");
564
sMenuText = QT_TR_NOOP("Load mesh in thread");
565
sToolTipText = QT_TR_NOOP("Sandbox Test function");
566
sWhatsThis = "Sandbox_MeshLoad";
567
sStatusTip = QT_TR_NOOP("Sandbox Test function");
568
sPixmap = "Std_Tool6";
571
void CmdSandboxMeshLoader::activated(int)
575
filter << QObject::tr("All Mesh Files (*.stl *.ast *.bms *.obj)");
576
filter << QObject::tr("Binary STL (*.stl)");
577
filter << QObject::tr("ASCII STL (*.ast)");
578
filter << QObject::tr("Binary Mesh (*.bms)");
579
filter << QObject::tr("Alias Mesh (*.obj)");
580
filter << QObject::tr("Inventor V2.1 ascii (*.iv)");
582
filter << QObject::tr("All Files (*.*)");
585
QString fn = Gui::FileDialog::getOpenFileName(Gui::getMainWindow(),
586
QObject::tr("Import mesh"), QString(), filter.join(QLatin1String(";;")));
588
Sandbox::MeshLoaderThread thread(fn);
589
QObject::connect(&thread, SIGNAL(finished()), &loop, SLOT(quit()));
594
Base::Reference<Mesh::MeshObject> data = thread.getMesh();
595
App::Document* doc = App::GetApplication().getActiveDocument();
596
Mesh::Feature* mesh = static_cast<Mesh::Feature*>(doc->addObject("Mesh::Feature","Mesh"));
597
mesh->Mesh.setValuePtr((Mesh::MeshObject*)data);
598
mesh->purgeTouched();
601
bool CmdSandboxMeshLoader::isActive(void)
603
return (hasActiveDocument() && !loop.isRunning());
608
Base::Reference<Mesh::MeshObject> loadMesh(const QString& s)
610
Mesh::MeshObject* mesh = new Mesh::MeshObject();
611
mesh->load((const char*)s.toUtf8());
615
DEF_STD_CMD_A(CmdSandboxMeshLoaderBoost)
617
CmdSandboxMeshLoaderBoost::CmdSandboxMeshLoaderBoost()
618
:Command("Sandbox_MeshLoaderBoost")
620
sAppModule = "Sandbox";
621
sGroup = QT_TR_NOOP("Sandbox");
622
sMenuText = QT_TR_NOOP("Load mesh in boost-thread");
623
sToolTipText = QT_TR_NOOP("Sandbox Test function");
624
sWhatsThis = "Sandbox_MeshLoaderBoost";
625
sStatusTip = QT_TR_NOOP("Sandbox Test function");
626
sPixmap = "Std_Tool6";
629
void CmdSandboxMeshLoaderBoost::activated(int)
633
filter << QObject::tr("All Mesh Files (*.stl *.ast *.bms *.obj)");
634
filter << QObject::tr("Binary STL (*.stl)");
635
filter << QObject::tr("ASCII STL (*.ast)");
636
filter << QObject::tr("Binary Mesh (*.bms)");
637
filter << QObject::tr("Alias Mesh (*.obj)");
638
filter << QObject::tr("Inventor V2.1 ascii (*.iv)");
640
filter << QObject::tr("All Files (*.*)");
643
QString fn = Gui::FileDialog::getOpenFileName(Gui::getMainWindow(),
644
QObject::tr("Import mesh"), QString(), filter.join(QLatin1String(";;")));
646
boost::packaged_task< Base::Reference<Mesh::MeshObject> > pt
647
(boost::bind(&loadMesh, fn));
648
boost::unique_future< Base::Reference<Mesh::MeshObject> > fi=pt.get_future();
649
boost::thread task(boost::move(pt));
652
App::Document* doc = App::GetApplication().getActiveDocument();
653
Mesh::Feature* mesh = static_cast<Mesh::Feature*>(doc->addObject("Mesh::Feature","Mesh"));
654
mesh->Mesh.setValuePtr((Mesh::MeshObject*)fi.get());
655
mesh->purgeTouched();
658
bool CmdSandboxMeshLoaderBoost::isActive(void)
660
return hasActiveDocument();
663
DEF_STD_CMD_A(CmdSandboxMeshLoaderFuture)
665
CmdSandboxMeshLoaderFuture::CmdSandboxMeshLoaderFuture()
666
:Command("Sandbox_MeshLoaderFuture")
668
sAppModule = "Sandbox";
669
sGroup = QT_TR_NOOP("Sandbox");
670
sMenuText = QT_TR_NOOP("Load mesh in QFuture");
671
sToolTipText = QT_TR_NOOP("Sandbox Test function");
672
sWhatsThis = "Sandbox_MeshLoaderFuture";
673
sStatusTip = QT_TR_NOOP("Sandbox Test function");
674
sPixmap = "Std_Tool6";
677
void CmdSandboxMeshLoaderFuture::activated(int)
681
filter << QObject::tr("All Mesh Files (*.stl *.ast *.bms *.obj)");
682
filter << QObject::tr("Binary STL (*.stl)");
683
filter << QObject::tr("ASCII STL (*.ast)");
684
filter << QObject::tr("Binary Mesh (*.bms)");
685
filter << QObject::tr("Alias Mesh (*.obj)");
686
filter << QObject::tr("Inventor V2.1 ascii (*.iv)");
688
filter << QObject::tr("All Files (*.*)");
691
QStringList fn = Gui::FileDialog::getOpenFileNames(Gui::getMainWindow(),
692
QObject::tr("Import mesh"), QString(), filter.join(QLatin1String(";;")));
694
QFuture< Base::Reference<Mesh::MeshObject> > future = QtConcurrent::mapped
697
QFutureWatcher< Base::Reference<Mesh::MeshObject> > watcher;
698
watcher.setFuture(future);
702
QObject::connect(&watcher, SIGNAL(finished()), &loop, SLOT(quit()));
705
App::Document* doc = App::GetApplication().getActiveDocument();
706
for (QFuture< Base::Reference<Mesh::MeshObject> >::const_iterator it = future.begin(); it != future.end(); ++it) {
707
Mesh::Feature* mesh = static_cast<Mesh::Feature*>(doc->addObject("Mesh::Feature","Mesh"));
708
mesh->Mesh.setValuePtr((Mesh::MeshObject*)(*it));
709
mesh->purgeTouched();
713
bool CmdSandboxMeshLoaderFuture::isActive(void)
715
return hasActiveDocument();
719
typedef Base::Reference<const MeshObject> MeshObjectConstRef;
720
typedef std::list<MeshObjectConstRef> MeshObjectConstRefList;
721
typedef std::vector<MeshObjectConstRef> MeshObjectConstRefArray;
724
struct MeshObject_greater : public std::binary_function<const Mesh::MeshObjectConstRef&,
725
const Mesh::MeshObjectConstRef&, bool>
727
bool operator()(const Mesh::MeshObjectConstRef& x,
728
const Mesh::MeshObjectConstRef& y) const
730
return x->countFacets() > y->countFacets();
745
Mesh::MeshObject* run(const std::vector<Mesh::MeshObjectConstRef>& meshdata)
747
std::vector<Mesh::MeshObjectConstRef> meshes = meshdata;
750
Mesh::MeshObjectConstRef myMesh = 0;
751
std::sort(meshes.begin(), meshes.end(), MeshObject_greater());
752
myMesh = meshes.front();
754
if (meshes.size() > 1) {
755
MeshCore::MeshKernel kernel;
758
kernel = myMesh->getKernel();
759
for (std::vector<Mesh::MeshObjectConstRef>::iterator it = meshes.begin(); it != meshes.end(); ++it) {
761
Base::Console().Message("MeshTestJob::run() in thread: %p\n", QThread::currentThreadId());
766
Mesh::MeshObject* mesh = new Mesh::MeshObject();
771
Mesh::MeshObject* mesh = new Mesh::MeshObject();
772
mesh->setKernel(myMesh->getKernel());
778
DEF_STD_CMD_A(CmdSandboxMeshTestJob)
780
CmdSandboxMeshTestJob::CmdSandboxMeshTestJob()
781
: Command("Sandbox_MeshTestJob")
783
sAppModule = "Sandbox";
784
sGroup = QT_TR_NOOP("Sandbox");
785
sMenuText = QT_TR_NOOP("Test mesh job");
786
sToolTipText = QT_TR_NOOP("Sandbox Test function");
787
sWhatsThis = "Sandbox_MeshTestJob";
788
sStatusTip = QT_TR_NOOP("Sandbox Test function");
789
sPixmap = "Std_Tool7";
792
void CmdSandboxMeshTestJob::activated(int)
794
Mesh::MeshObjectConstRefList meshes;
795
App::Document* app_doc = App::GetApplication().getActiveDocument();
796
std::vector<Mesh::Feature*> meshObj = Gui::Selection().getObjectsOfType<Mesh::Feature>(app_doc->getName());
797
for (std::vector<Mesh::Feature*>::iterator it = meshObj.begin(); it != meshObj.end(); ++it) {
798
meshes.push_back((*it)->Mesh.getValuePtr());
802
while (meshes.size() > 1) {
803
int numJobs = QThread::idealThreadCount();
804
if (numJobs < 0) numJobs = 2;
806
while (numJobs > (int)(meshes.size()+1)/2)
808
numJobs = std::max<int>(1, numJobs);
811
std::vector<Mesh::MeshObjectConstRefArray> mesh_groups;
812
while (numJobs > 0) {
813
int size = (int)meshes.size();
814
int count = size / numJobs;
816
Mesh::MeshObjectConstRefArray meshes_per_job;
817
for (int i=0; i<count; i++) {
818
meshes_per_job.push_back(meshes.front());
821
mesh_groups.push_back(meshes_per_job);
825
Base::Console().Message("Mesh test (step %d)...\n",iteration++);
827
QFuture<Mesh::MeshObject*> mesh_future = QtConcurrent::mapped
828
(mesh_groups, boost::bind(&MeshTestJob::run, &meshJob, bp::_1));
831
QFutureWatcher<Mesh::MeshObject*> mesh_watcher;
832
mesh_watcher.setFuture(mesh_future);
834
QObject::connect(&mesh_watcher, SIGNAL(finished()), &loop, SLOT(quit()));
837
for (QFuture<Mesh::MeshObject*>::const_iterator it = mesh_future.begin(); it != mesh_future.end(); ++it) {
838
meshes.push_back(Mesh::MeshObjectConstRef(*it));
842
if (meshes.empty()) {
843
Base::Console().Error("The mesh test failed to create a valid mesh.\n");
848
bool CmdSandboxMeshTestJob::isActive(void)
850
return hasActiveDocument();
853
class MeshThread : public QThread
856
MeshThread(Base::Reference<Mesh::MeshObject> m, QObject* p=0)
857
: QThread(p), mesh(m)
863
for (int i=0; i<100;i++) {
864
Base::Reference<Mesh::MeshObject> new_ref;
870
Base::Reference<Mesh::MeshObject> mesh;
873
DEF_STD_CMD_A(CmdSandboxMeshTestRef)
875
CmdSandboxMeshTestRef::CmdSandboxMeshTestRef()
876
: Command("Sandbox_MeshTestRef")
878
sAppModule = "Sandbox";
879
sGroup = QT_TR_NOOP("Sandbox");
880
sMenuText = QT_TR_NOOP("Test mesh reference");
881
sToolTipText = QT_TR_NOOP("Sandbox Test function");
882
sWhatsThis = "Sandbox_MeshTestRef";
883
sStatusTip = QT_TR_NOOP("Sandbox Test function");
886
void CmdSandboxMeshTestRef::activated(int)
889
std::vector< std::shared_ptr<QThread> > threads;
890
Base::Reference<Mesh::MeshObject> mesh(new Mesh::MeshObject);
891
int num = mesh.getRefCount();
893
for (int i=0; i<10; i++) {
894
std::shared_ptr<QThread> trd(new MeshThread(mesh));
896
threads.push_back(trd);
901
QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
906
Mesh::MeshObject* ptr = (Mesh::MeshObject*)mesh;
908
Base::Console().Error("Object deleted\n");
909
if (num != mesh.getRefCount())
910
Base::Console().Error("Reference count is %d\n",mesh.getRefCount());
913
bool CmdSandboxMeshTestRef::isActive(void)
921
DEF_STD_CMD_A(CmdTestGrabWidget)
923
CmdTestGrabWidget::CmdTestGrabWidget()
924
: Command("Std_GrabWidget")
926
sGroup = "Standard-Test";
927
sMenuText = "Grab widget";
928
sToolTipText = "Grab widget";
929
sWhatsThis = "Std_GrabWidget";
930
sStatusTip = sToolTipText;
933
void CmdTestGrabWidget::activated(int)
935
QCalendarWidget* c = new QCalendarWidget();
937
QPixmap p = c->grab(c->rect());
938
QLabel* label = new QLabel();
939
label->resize(c->size());
945
bool CmdTestGrabWidget::isActive(void)
953
DEF_3DV_CMD(CmdTestImageNode)
955
class RenderArea : public QWidget
963
RenderArea(const QPainterPath &path, QWidget *parent=0)
964
: QWidget(parent), path(path), penColor(0,0,127)
967
setBackgroundRole(QPalette::Base);
970
QSize minimumSizeHint() const
972
return QSize(50, 50);
975
QSize sizeHint() const
977
return QSize(100, 30);
980
void setFillRule(Qt::FillRule rule)
982
path.setFillRule(rule);
986
void setPenWidth(int width)
992
void setPenColor(const QColor &color)
998
void paintEvent(QPaintEvent *)
1000
QPainter painter(this);
1001
painter.setRenderHint(QPainter::Antialiasing);
1003
painter.scale(width() / 100.0, height() / 100.0);
1004
painter.translate(50.0, 50.0);
1005
painter.translate(-50.0, -50.0);
1007
painter.setPen(QPen(penColor, penWidth, Qt::SolidLine, Qt::RoundCap,
1009
painter.setBrush(QBrush(QColor(0,85,255), Qt::SolidPattern));
1010
painter.drawPath(path);
1011
painter.setPen(Qt::white);
1012
painter.drawText(25, 40, 70, 20, Qt::AlignHCenter|Qt::AlignVCenter,
1013
QString::fromLatin1("Distance: 2.784mm"));
1018
class GDIWidget : public QWidget
1021
GDIWidget(QWidget* parent) : QWidget(parent)
1023
setAttribute(Qt::WA_PaintOnScreen);
1024
setAttribute(Qt::WA_NativeWindow);
1026
QPaintEngine *paintEngine() const {
1030
void paintEvent(QPaintEvent *event) {
1032
HWND hWnd = (HWND)this->winId();
1033
HDC hdc = GetDC(hWnd);
1034
SelectObject(hdc, GetSysColorBrush(COLOR_WINDOW));
1035
Rectangle(hdc, 0, 0, width(), height());
1036
RECT rect = {0, 0, width(), height() };
1037
DrawTextA(hdc, "Hello World!", 12, &rect,
1038
DT_SINGLELINE | DT_VCENTER | DT_CENTER);
1039
ReleaseDC(hWnd, hdc);
1044
CmdTestImageNode::CmdTestImageNode()
1045
: Command("Std_ImageNode")
1047
sGroup = "Standard-Test";
1048
sMenuText = "SoImage node";
1049
sToolTipText = "SoImage node";
1050
sWhatsThis = "Std_ImageNode";
1051
sStatusTip = sToolTipText;
1054
void CmdTestImageNode::activated(int)
1056
QString text = QString::fromLatin1("Distance: 2.7jgiorjgor84mm");
1058
QFontMetrics fm(font);
1059
int w = Gui::QtTools::horizontalAdvance(fm, text);
1060
int h = fm.height();
1063
QPainterPath roundRectPath;
1065
roundRectPath.moveTo(100.0, 5.0);
1066
roundRectPath.arcTo(90.0, 0.0, 10.0, 10.0, 0.0, 90.0);
1067
roundRectPath.lineTo(5.0, 0.0);
1068
roundRectPath.arcTo(0.0, 0.0, 10.0, 10.0, 90.0, 90.0);
1069
roundRectPath.lineTo(0.0, 95.0);
1070
roundRectPath.arcTo(0.0, 90.0, 10.0, 10.0, 180.0, 90.0);
1071
roundRectPath.lineTo(95.0, 100.0);
1072
roundRectPath.arcTo(90.0, 90.0, 10.0, 10.0, 270.0, 90.0);
1073
roundRectPath.closeSubpath();
1076
Gui::MDIView* view = Gui::getMainWindow()->activeWindow();
1077
Gui::View3DInventorViewer* viewer = static_cast<Gui::View3DInventor*>(view)->getViewer();
1078
SoImage* node = new SoImage();
1080
QImage image(w+10,h+10,QImage::Format_ARGB32_Premultiplied);
1081
image.fill(0x00000000);
1082
QPainter painter(&image);
1083
painter.setRenderHint(QPainter::Antialiasing);
1085
painter.setPen(QPen(QColor(0,0,127), 2, Qt::SolidLine, Qt::RoundCap,
1087
painter.setBrush(QBrush(QColor(0,85,255), Qt::SolidPattern));
1088
QRectF rectangle(0.0, 0.0, w+10, h+10);
1089
painter.drawRoundedRect(rectangle, 5, 5);
1091
painter.setPen(QColor(255,255,255));
1092
painter.drawText(5,h+3, text);
1096
Gui::BitmapFactory().convert(image, texture);
1097
node->image = texture;
1098
SoAnnotation* anno = new SoAnnotation();
1099
anno->addChild(node);
1100
static_cast<SoGroup*>(viewer->getSceneGraph())->addChild(anno);
1106
DEF_STD_CMD(CmdTestGDIWidget)
1108
CmdTestGDIWidget::CmdTestGDIWidget()
1109
: Command("Sandbox_GDIWidget")
1111
sGroup = "Standard-Test";
1112
sMenuText = "GDI widget";
1113
sToolTipText = "GDI widget";
1114
sWhatsThis = "Sandbox_GDIWidget";
1115
sStatusTip = sToolTipText;
1118
void CmdTestGDIWidget::activated(int)
1121
GDIWidget* gdi = new GDIWidget(Gui::getMainWindow());
1123
gdi->resize(200,200);
1125
gdi->setAttribute(Qt::WA_DeleteOnClose);
1132
DEF_STD_CMD(CmdTestRedirectPaint)
1134
CmdTestRedirectPaint::CmdTestRedirectPaint()
1135
: Command("Sandbox_RedirectPaint")
1137
sGroup = "Standard-Test";
1138
sMenuText = "Redirect paint";
1139
sToolTipText = "Redirect paint";
1140
sWhatsThis = "Sandbox_RedirectPaint";
1141
sStatusTip = sToolTipText;
1144
void CmdTestRedirectPaint::activated(int)
1146
QCalendarWidget* cal = new QCalendarWidget();
1147
cal->setWindowTitle(QString::fromLatin1("QCalendarWidget"));
1149
QPixmap img(cal->size());
1152
QLabel* label = new QLabel();
1153
label->setPixmap(img);
1155
label->setWindowTitle(QString::fromLatin1("QLabel"));
1161
DEF_STD_CMD(CmdTestCryptographicHash)
1163
CmdTestCryptographicHash::CmdTestCryptographicHash()
1164
: Command("Sandbox_CryptographicHash")
1166
sGroup = "Standard-Test";
1167
sMenuText = "Cryptographic Hash";
1168
sToolTipText = "Cryptographic Hash";
1169
sWhatsThis = "Sandbox_CryptographicHash";
1170
sStatusTip = sToolTipText;
1173
void CmdTestCryptographicHash::activated(int)
1175
QByteArray data = "FreeCAD";
1176
QByteArray hash = QCryptographicHash::hash(data, QCryptographicHash::Md5);
1177
QMessageBox::information(0,QLatin1String("Hash of: FreeCAD"),QString::fromLatin1(hash));
1183
DEF_3DV_CMD(CmdTestWidgetShape)
1185
CmdTestWidgetShape::CmdTestWidgetShape()
1186
: Command("Sandbox_WidgetShape")
1188
sGroup = "Standard-Test";
1189
sMenuText = "Widget shape";
1190
sToolTipText = "Widget shape";
1191
sWhatsThis = "Sandbox_WidgetShape";
1192
sStatusTip = sToolTipText;
1195
void CmdTestWidgetShape::activated(int)
1197
SandboxGui::SoWidgetShape* shape = new SandboxGui::SoWidgetShape;
1198
shape->setWidget(new QCalendarWidget());
1199
Gui::MDIView* view = Gui::getMainWindow()->activeWindow();
1200
Gui::View3DInventorViewer* viewer = static_cast<Gui::View3DInventor*>(view)->getViewer();
1201
static_cast<SoGroup*>(viewer->getSceneGraph())->addChild(shape);
1206
DEF_STD_CMD(CmdMengerSponge)
1208
CmdMengerSponge::CmdMengerSponge()
1209
:Command("Sandbox_MengerSponge")
1211
sAppModule = "Sandbox";
1212
sGroup = QT_TR_NOOP("Sandbox");
1213
sMenuText = QT_TR_NOOP("Menger sponge");
1214
sToolTipText = QT_TR_NOOP("Menger sponge");
1215
sWhatsThis = "Sandbox_MengerSponge";
1216
sStatusTip = QT_TR_NOOP("Menger sponge");
1222
Param(int l, float x, float y, float z)
1223
: level(l), x(x), y(y), z(z)
1228
typedef Base::Reference<Mesh::MeshObject> MeshObjectRef;
1230
MeshObjectRef globalBox;
1233
MeshObjectRef PlaceBox(float x, float y, float z)
1235
MeshObjectRef mesh = new Mesh::MeshObject(*globalBox);
1238
mesh->getKernel().Transform(m);
1242
MeshObjectRef Sierpinski(int level, float x0, float y0, float z0)
1244
float boxnums = std::pow(3.0f,level);
1245
float thirds = boxnums / 3;
1246
float twothirds = thirds * 2;
1248
QList<float> rangerx, rangery, rangerz;
1255
rangerx << x0 << (x0 + thirds) << (x0 + twothirds);
1256
rangery << y0 << (y0 + thirds) << (y0 + twothirds);
1257
rangerz << z0 << (z0 + thirds) << (z0 + twothirds);
1261
QList<int> skip; skip << 5 << 11 << 13 << 14 << 15 << 17 << 23;
1262
MeshObjectRef mesh = new Mesh::MeshObject();
1264
for (QList<float>::iterator i = rangerx.begin(); i != rangerx.end(); ++i) {
1265
for (QList<float>::iterator j = rangery.begin(); j != rangery.end(); ++j) {
1266
for (QList<float>::iterator k = rangerz.begin(); k != rangerz.end(); ++k) {
1267
if (!skip.contains(block)) {
1269
mesh->addMesh(*Sierpinski(level-1,*i,*j,*k));
1271
mesh->addMesh(*PlaceBox(*i,*j,*k));
1281
MeshObjectRef runSierpinski(const Param& p)
1283
return Sierpinski(p.level,p.x,p.y,p.z);
1286
MeshObjectRef makeParallelMengerSponge(int level, float x0, float y0, float z0)
1288
float boxnums = std::pow(3.0f,level);
1289
float thirds = boxnums / 3;
1290
float twothirds = thirds * 2;
1292
QList<float> rangerx, rangery, rangerz;
1293
rangerx << x0 << (x0 + thirds) << (x0 + twothirds);
1294
rangery << y0 << (y0 + thirds) << (y0 + twothirds);
1295
rangerz << z0 << (z0 + thirds) << (z0 + twothirds);
1298
QList<int> skip; skip << 5 << 11 << 13 << 14 << 15 << 17 << 23;
1303
for (QList<float>::iterator i = rangerx.begin(); i != rangerx.end(); ++i) {
1304
for (QList<float>::iterator j = rangery.begin(); j != rangery.end(); ++j) {
1305
for (QList<float>::iterator k = rangerz.begin(); k != rangerz.end(); ++k) {
1306
if (!skip.contains(block)) {
1307
args << Param(level-1, *i, *j, *k);
1314
QFuture<MeshObjectRef> future = QtConcurrent::mapped(args, runSierpinski);
1316
QFutureWatcher<MeshObjectRef> watcher;
1317
watcher.setFuture(future);
1321
QObject::connect(&watcher, SIGNAL(finished()), &loop, SLOT(quit()));
1324
MeshObjectRef mesh = new Mesh::MeshObject();
1325
for (QFuture<MeshObjectRef>::const_iterator it = future.begin(); it != future.end(); ++it) {
1326
mesh->addMesh(**it);
1333
void CmdMengerSponge::activated(int)
1336
int level = QInputDialog::getInt(Gui::getMainWindow(),
1337
QString::fromLatin1("Menger sponge"),
1338
QString::fromLatin1("Recursion depth:"),
1342
int ret = QMessageBox::question(Gui::getMainWindow(),
1343
QString::fromLatin1("Parallel"),
1344
QString::fromLatin1("Do you want to run this in a thread pool?"),
1345
QMessageBox::Yes|QMessageBox::No);
1346
bool parallel=(ret == QMessageBox::Yes);
1347
float x0=0,y0=0,z0=0;
1349
globalBox = Mesh::MeshObject::createCube(1,1,1);
1353
mesh = makeParallelMengerSponge(level,x0,y0,z0);
1355
mesh = Sierpinski(level,x0,y0,z0);
1357
MeshCore::MeshKernel& kernel = mesh->getKernel();
1360
MeshCore::MeshFixDuplicatePoints(kernel).Fixup();
1363
MeshCore::MeshEvalInternalFacets eval(kernel);
1365
kernel.DeleteFacets(eval.GetIndices());
1368
kernel.RebuildNeighbours();
1370
App::Document* doc = App::GetApplication().newDocument();
1371
Mesh::Feature* feature = static_cast<Mesh::Feature*>(doc->addObject("Mesh::Feature","MengerSponge"));
1372
feature->Mesh.setValue(*mesh);
1373
feature->purgeTouched();
1376
DEF_STD_CMD_A(CmdTestGraphicsView)
1378
CmdTestGraphicsView::CmdTestGraphicsView()
1379
: Command("Std_TestGraphicsView")
1381
sGroup = QT_TR_NOOP("Standard-Test");
1382
sMenuText = QT_TR_NOOP("Create new graphics view");
1383
sToolTipText= QT_TR_NOOP("Creates a new view window for the active document");
1384
sStatusTip = QT_TR_NOOP("Creates a new view window for the active document");
1387
void CmdTestGraphicsView::activated(int)
1389
Gui::GraphicsView3D* view3D = new Gui::GraphicsView3D(getActiveGuiDocument(), Gui::getMainWindow());
1390
view3D->setWindowTitle(QString::fromLatin1("Graphics scene"));
1391
view3D->setWindowIcon(QApplication::windowIcon());
1392
view3D->resize(400, 300);
1393
Gui::getMainWindow()->addWindow(view3D);
1396
bool CmdTestGraphicsView::isActive(void)
1398
return (getActiveGuiDocument()!=NULL);
1404
DEF_STD_CMD(CmdTestTaskBox)
1406
CmdTestTaskBox::CmdTestTaskBox()
1407
: Command("Std_TestTaskBox")
1409
sGroup = "Standard-Test";
1410
sMenuText = "Task box";
1411
sToolTipText = "Task box";
1412
sWhatsThis = "Std_TestTaskBox";
1413
sStatusTip = sToolTipText;
1416
void CmdTestTaskBox::activated(int)
1418
QWidget* w = new SandboxGui::TaskPanelView();
1419
w->setAttribute(Qt::WA_DeleteOnClose);
1424
void CreateSandboxCommands()
1426
Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager();
1427
rcCmdMgr.addCommand(new CmdSandboxDocumentThread());
1428
rcCmdMgr.addCommand(new CmdSandboxDocumentTestThread());
1429
rcCmdMgr.addCommand(new CmdSandboxDocumentSaveThread());
1430
rcCmdMgr.addCommand(new CmdSandboxDocThreadWithSeq());
1431
rcCmdMgr.addCommand(new CmdSandboxDocThreadBusy());
1432
rcCmdMgr.addCommand(new CmdSandboxDocumentNoThread());
1433
rcCmdMgr.addCommand(new CmdSandboxWorkerThread());
1434
rcCmdMgr.addCommand(new CmdSandboxPythonLockThread());
1435
rcCmdMgr.addCommand(new CmdSandboxPythonNolockThread());
1436
rcCmdMgr.addCommand(new CmdSandboxPySideThread());
1437
rcCmdMgr.addCommand(new CmdSandboxPythonThread());
1438
rcCmdMgr.addCommand(new CmdSandboxPythonMainThread());
1439
rcCmdMgr.addCommand(new CmdSandboxDocThreadWithDialog());
1440
rcCmdMgr.addCommand(new CmdSandboxDocThreadWithFileDlg());
1441
rcCmdMgr.addCommand(new CmdSandboxEventLoop);
1442
rcCmdMgr.addCommand(new CmdSandboxMeshLoader);
1443
rcCmdMgr.addCommand(new CmdSandboxMeshLoaderBoost);
1444
rcCmdMgr.addCommand(new CmdSandboxMeshLoaderFuture);
1445
rcCmdMgr.addCommand(new CmdSandboxMeshTestJob);
1446
rcCmdMgr.addCommand(new CmdSandboxMeshTestRef);
1447
rcCmdMgr.addCommand(new CmdTestGrabWidget());
1448
rcCmdMgr.addCommand(new CmdTestImageNode());
1449
rcCmdMgr.addCommand(new CmdTestWidgetShape());
1450
rcCmdMgr.addCommand(new CmdTestGDIWidget());
1451
rcCmdMgr.addCommand(new CmdTestRedirectPaint());
1452
rcCmdMgr.addCommand(new CmdTestCryptographicHash());
1453
rcCmdMgr.addCommand(new CmdMengerSponge());
1454
rcCmdMgr.addCommand(new CmdTestGraphicsView());
1455
rcCmdMgr.addCommand(new CmdTestTaskBox());