void CmdSandboxMeshLoaderFuture::activated(int iMsg) { // use current path as default QStringList filter; filter << QObject::tr("All Mesh Files (*.stl *.ast *.bms *.obj)"); filter << QObject::tr("Binary STL (*.stl)"); filter << QObject::tr("ASCII STL (*.ast)"); filter << QObject::tr("Binary Mesh (*.bms)"); filter << QObject::tr("Alias Mesh (*.obj)"); filter << QObject::tr("Inventor V2.1 ascii (*.iv)"); //filter << "Nastran (*.nas *.bdf)"; filter << QObject::tr("All Files (*.*)"); // Allow multi selection QStringList fn = Gui::FileDialog::getOpenFileNames(Gui::getMainWindow(), QObject::tr("Import mesh"), QString(), filter.join(QLatin1String(";;"))); QFuture< Base::Reference<Mesh::MeshObject> > future = QtConcurrent::mapped (fn, loadMesh); QFutureWatcher< Base::Reference<Mesh::MeshObject> > watcher; watcher.setFuture(future); // keep it responsive during computation QEventLoop loop; QObject::connect(&watcher, SIGNAL(finished()), &loop, SLOT(quit())); loop.exec(); App::Document* doc = App::GetApplication().getActiveDocument(); for (QFuture< Base::Reference<Mesh::MeshObject> >::const_iterator it = future.begin(); it != future.end(); ++it) { Mesh::Feature* mesh = static_cast<Mesh::Feature*>(doc->addObject("Mesh::Feature","Mesh")); mesh->Mesh.setValuePtr((Mesh::MeshObject*)(*it)); mesh->purgeTouched(); } }
void CmdSandboxMeshLoaderBoost::activated(int iMsg) { # if BOOST_VERSION >= 104100 // use current path as default QStringList filter; filter << QObject::tr("All Mesh Files (*.stl *.ast *.bms *.obj)"); filter << QObject::tr("Binary STL (*.stl)"); filter << QObject::tr("ASCII STL (*.ast)"); filter << QObject::tr("Binary Mesh (*.bms)"); filter << QObject::tr("Alias Mesh (*.obj)"); filter << QObject::tr("Inventor V2.1 ascii (*.iv)"); //filter << "Nastran (*.nas *.bdf)"; filter << QObject::tr("All Files (*.*)"); // Allow multi selection QString fn = Gui::FileDialog::getOpenFileName(Gui::getMainWindow(), QObject::tr("Import mesh"), QString(), filter.join(QLatin1String(";;"))); boost::packaged_task< Base::Reference<Mesh::MeshObject> > pt (boost::bind(&loadMesh, fn)); boost::unique_future< Base::Reference<Mesh::MeshObject> > fi=pt.get_future(); boost::thread task(boost::move(pt)); // launch task on a thread fi.wait(); // wait for it to be finished App::Document* doc = App::GetApplication().getActiveDocument(); Mesh::Feature* mesh = static_cast<Mesh::Feature*>(doc->addObject("Mesh::Feature","Mesh")); mesh->Mesh.setValuePtr((Mesh::MeshObject*)fi.get()); mesh->purgeTouched(); #endif }
void CmdSandboxMeshLoader::activated(int iMsg) { // use current path as default QStringList filter; filter << QObject::tr("All Mesh Files (*.stl *.ast *.bms *.obj)"); filter << QObject::tr("Binary STL (*.stl)"); filter << QObject::tr("ASCII STL (*.ast)"); filter << QObject::tr("Binary Mesh (*.bms)"); filter << QObject::tr("Alias Mesh (*.obj)"); filter << QObject::tr("Inventor V2.1 ascii (*.iv)"); //filter << "Nastran (*.nas *.bdf)"; filter << QObject::tr("All Files (*.*)"); // Allow multi selection QString fn = Gui::FileDialog::getOpenFileName(Gui::getMainWindow(), QObject::tr("Import mesh"), QString(), filter.join(QLatin1String(";;"))); Sandbox::MeshLoaderThread thread(fn); QObject::connect(&thread, SIGNAL(finished()), &loop, SLOT(quit())); thread.start(); loop.exec(); Base::Reference<Mesh::MeshObject> data = thread.getMesh(); App::Document* doc = App::GetApplication().getActiveDocument(); Mesh::Feature* mesh = static_cast<Mesh::Feature*>(doc->addObject("Mesh::Feature","Mesh")); mesh->Mesh.setValuePtr((Mesh::MeshObject*)data); mesh->purgeTouched(); }
static PyObject * importer(PyObject *self, PyObject *args) { char* Name; char* DocName=0; if (!PyArg_ParseTuple(args, "et|s","utf-8",&Name,&DocName)) return NULL; std::string EncodedName = std::string(Name); PyMem_Free(Name); PY_TRY { App::Document *pcDoc = 0; if (DocName) pcDoc = App::GetApplication().getDocument(DocName); else pcDoc = App::GetApplication().getActiveDocument(); if (!pcDoc) { pcDoc = App::GetApplication().newDocument(DocName); } MeshObject mesh; if (mesh.load(EncodedName.c_str())) { Base::FileInfo file(EncodedName.c_str()); unsigned long segmct = mesh.countSegments(); if (segmct > 1) { for (unsigned long i=0; i<segmct; i++) { std::auto_ptr<MeshObject> segm(mesh.meshFromSegment(mesh.getSegment(i).getIndices())); Mesh::Feature *pcFeature = static_cast<Mesh::Feature *> (pcDoc->addObject("Mesh::Feature", file.fileNamePure().c_str())); pcFeature->Label.setValue(file.fileNamePure().c_str()); pcFeature->Mesh.swapMesh(*segm); pcFeature->purgeTouched(); } } else { Mesh::Feature *pcFeature = static_cast<Mesh::Feature *> (pcDoc->addObject("Mesh::Feature", file.fileNamePure().c_str())); pcFeature->Label.setValue(file.fileNamePure().c_str()); pcFeature->Mesh.swapMesh(mesh); pcFeature->purgeTouched(); } } } PY_CATCH; Py_Return; }
void CmdMengerSponge::activated(int iMsg) { bool ok; int level = QInputDialog::getInteger(Gui::getMainWindow(), QString::fromAscii("Menger sponge"), QString::fromAscii("Recursion depth:"), 3, 1, 5, 1, &ok); if (!ok) return; int ret = QMessageBox::question(Gui::getMainWindow(), QString::fromAscii("Parallel"), QString::fromAscii("Do you want to run this in a thread pool?"), QMessageBox::Yes|QMessageBox::No); bool parallel=(ret == QMessageBox::Yes); float x0=0,y0=0,z0=0; globalBox = Mesh::MeshObject::createCube(1,1,1); MeshObjectRef mesh; if (parallel) mesh = makeParallelMengerSponge(level,x0,y0,z0); else mesh = Sierpinski(level,x0,y0,z0); MeshCore::MeshKernel& kernel = mesh->getKernel(); // remove duplicated points MeshCore::MeshFixDuplicatePoints(kernel).Fixup(); // remove internal facets MeshCore::MeshEvalInternalFacets eval(kernel); eval.Evaluate(); kernel.DeleteFacets(eval.GetIndices()); // repair neighbourhood kernel.RebuildNeighbours(); App::Document* doc = App::GetApplication().newDocument(); Mesh::Feature* feature = static_cast<Mesh::Feature*>(doc->addObject("Mesh::Feature","MengerSponge")); feature->Mesh.setValue(*mesh); feature->purgeTouched(); }