PyObject* Application::sInsert(PyObject * /*self*/, PyObject *args,PyObject * /*kwd*/) { const char* Name; const char* DocName=0; if (!PyArg_ParseTuple(args, "s|s",&Name,&DocName)) return NULL; PY_TRY { QString fileName = QString::fromUtf8(Name); QFileInfo fi; fi.setFile(fileName); QString ext = fi.completeSuffix().toLower(); if (ext == QLatin1String("iv")) { App::Document *doc = 0; if (DocName) doc = App::GetApplication().getDocument(DocName); else doc = App::GetApplication().getActiveDocument(); if (!doc) doc = App::GetApplication().newDocument(DocName); App::DocumentObject* obj = doc->addObject("App::InventorObject", (const char*)fi.baseName().toUtf8()); obj->Label.setValue((const char*)fi.baseName().toUtf8()); static_cast<App::PropertyString*>(obj->getPropertyByName("FileName")) ->setValue((const char*)fi.absoluteFilePath().toUtf8()); doc->recompute(); } else if (ext == QLatin1String("wrl") || ext == QLatin1String("vrml") || ext == QLatin1String("wrz")) { App::Document *doc = 0; if (DocName) doc = App::GetApplication().getDocument(DocName); else doc = App::GetApplication().getActiveDocument(); if (!doc) doc = App::GetApplication().newDocument(DocName); App::DocumentObject* obj = doc->addObject("App::VRMLObject", (const char*)fi.baseName().toUtf8()); obj->Label.setValue((const char*)fi.baseName().toUtf8()); static_cast<App::PropertyFileIncluded*>(obj->getPropertyByName("VrmlFile")) ->setValue((const char*)fi.absoluteFilePath().toUtf8()); doc->recompute(); } else if (ext == QLatin1String("py") || ext == QLatin1String("fcmacro") || ext == QLatin1String("fcscript")) { PythonEditor* editor = new PythonEditor(); editor->setWindowIcon(Gui::BitmapFactory().pixmap("python_small")); PythonEditorView* edit = new PythonEditorView(editor, getMainWindow()); edit->open(fileName); edit->resize(400, 300); getMainWindow()->addWindow( edit ); } } PY_CATCH; Py_Return; }
Py::Object insert(const Py::Tuple& args) { char* Name; const char* DocName = 0; if (!PyArg_ParseTuple(args.ptr(), "et|s","utf-8",&Name,&DocName)) throw Py::Exception(); std::string EncodedName = std::string(Name); PyMem_Free(Name); App::Document *pcDoc = 0; if (DocName) pcDoc = App::GetApplication().getDocument(DocName); else pcDoc = App::GetApplication().getActiveDocument(); if (!pcDoc) { pcDoc = App::GetApplication().newDocument(DocName); } Base::FileInfo file(EncodedName.c_str()); try { std::unique_ptr<FemMesh> mesh(new FemMesh); mesh->read(EncodedName.c_str()); FemMeshObject *pcFeature = static_cast<FemMeshObject *> (pcDoc->addObject("Fem::FemMeshObject", file.fileNamePure().c_str())); pcFeature->Label.setValue(file.fileNamePure().c_str()); pcFeature->FemMesh.setValuePtr(mesh.release()); pcFeature->purgeTouched(); } catch (Base::Exception&) { #ifdef FC_USE_VTK if (FemPostPipeline::canRead(file)) { FemPostPipeline *pcFeature = static_cast<FemPostPipeline *> (pcDoc->addObject("Fem::FemPostPipeline", file.fileNamePure().c_str())); pcFeature->Label.setValue(file.fileNamePure().c_str()); pcFeature->read(file); pcFeature->touch(); pcDoc->recomputeFeature(pcFeature); } else { throw; } #else throw; #endif } return Py::None(); }
Py::Object show(const Py::Tuple& args) { PyObject *pcObj; if (!PyArg_ParseTuple(args.ptr(), "O!", &(PathPy::Type), &pcObj)) throw Py::Exception(); try { App::Document *pcDoc = App::GetApplication().getActiveDocument(); if (!pcDoc) pcDoc = App::GetApplication().newDocument(); PathPy* pPath = static_cast<PathPy*>(pcObj); Path::Feature *pcFeature = (Path::Feature *)pcDoc->addObject("Path::Feature", "Path"); Path::Toolpath* pa = pPath->getToolpathPtr(); if (!pa) { throw Py::Exception(PyExc_ReferenceError, "object doesn't reference a valid path"); } // copy the data pcFeature->Path.setValue(*pa); } catch (const Base::Exception& e) { throw Py::RuntimeError(e.what()); } return Py::None(); }
static PyObject * show(PyObject *self, PyObject *args) { PyObject *pcObj; if (!PyArg_ParseTuple(args, "O!", &(MeshPy::Type), &pcObj)) return NULL; PY_TRY { App::Document *pcDoc = App::GetApplication().getActiveDocument(); if (!pcDoc) pcDoc = App::GetApplication().newDocument(); MeshPy* pMesh = static_cast<MeshPy*>(pcObj); Mesh::Feature *pcFeature = (Mesh::Feature *)pcDoc->addObject("Mesh::Feature", "Mesh"); Mesh::MeshObject* mo = pMesh->getMeshObjectPtr(); if (!mo) { PyErr_SetString(PyExc_ReferenceError, "object doesn't reference a valid mesh"); return 0; } // copy the data pcFeature->Mesh.setValue(*mo); } PY_CATCH; Py_Return; }
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(); }
Py::Object insert(const Py::Tuple& args) { char* Name; const char* DocName = 0; if (!PyArg_ParseTuple(args.ptr(), "et|s","utf-8",&Name,&DocName)) throw Py::Exception(); std::string EncodedName = std::string(Name); PyMem_Free(Name); App::Document *pcDoc = 0; if (DocName) pcDoc = App::GetApplication().getDocument(DocName); else pcDoc = App::GetApplication().getActiveDocument(); if (!pcDoc) { pcDoc = App::GetApplication().newDocument(DocName); } std::auto_ptr<FemMesh> mesh(new FemMesh); mesh->read(EncodedName.c_str()); Base::FileInfo file(EncodedName.c_str()); FemMeshObject *pcFeature = static_cast<FemMeshObject *> (pcDoc->addObject("Fem::FemMeshObject", file.fileNamePure().c_str())); pcFeature->Label.setValue(file.fileNamePure().c_str()); pcFeature->FemMesh.setValuePtr(mesh.get()); (void)mesh.release(); pcFeature->purgeTouched(); return Py::None(); }
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 Segmentation::accept() { const Mesh::MeshObject* mesh = myMesh->Mesh.getValuePtr(); // make a copy because we might smooth the mesh before MeshCore::MeshKernel kernel = mesh->getKernel(); if (ui->checkBoxSmooth->isChecked()) { MeshCore::LaplaceSmoothing smoother(kernel); smoother.Smooth(ui->smoothSteps->value()); } MeshCore::MeshSegmentAlgorithm finder(kernel); MeshCore::MeshCurvature meshCurv(kernel); meshCurv.ComputePerVertex(); std::vector<MeshCore::MeshSurfaceSegment*> segm; if (ui->groupBoxCyl->isChecked()) { segm.push_back(new MeshCore::MeshCurvatureCylindricalSegment (meshCurv.GetCurvature(), ui->numCyl->value(), ui->tol1Cyl->value(), ui->tol2Cyl->value(), ui->radCyl->value().getValue())); } if (ui->groupBoxSph->isChecked()) { segm.push_back(new MeshCore::MeshCurvatureSphericalSegment (meshCurv.GetCurvature(), ui->numSph->value(), ui->tolSph->value(), ui->radSph->value().getValue())); } if (ui->groupBoxPln->isChecked()) { segm.push_back(new MeshCore::MeshCurvaturePlanarSegment (meshCurv.GetCurvature(), ui->numPln->value(), ui->tolPln->value())); } finder.FindSegments(segm); App::Document* document = App::GetApplication().getActiveDocument(); document->openTransaction("Segmentation"); std::string internalname = "Segments_"; internalname += myMesh->getNameInDocument(); App::DocumentObjectGroup* group = static_cast<App::DocumentObjectGroup*>(document->addObject ("App::DocumentObjectGroup", internalname.c_str())); std::string labelname = "Segments "; labelname += myMesh->Label.getValue(); group->Label.setValue(labelname); for (std::vector<MeshCore::MeshSurfaceSegment*>::iterator it = segm.begin(); it != segm.end(); ++it) { const std::vector<MeshCore::MeshSegment>& data = (*it)->GetSegments(); for (std::vector<MeshCore::MeshSegment>::const_iterator jt = data.begin(); jt != data.end(); ++jt) { Mesh::MeshObject* segment = mesh->meshFromSegment(*jt); Mesh::Feature* feaSegm = static_cast<Mesh::Feature*>(group->addObject("Mesh::Feature", "Segment")); Mesh::MeshObject* feaMesh = feaSegm->Mesh.startEditing(); feaMesh->swap(*segment); feaSegm->Mesh.finishEditing(); delete segment; std::stringstream label; label << feaSegm->Label.getValue() << " (" << (*it)->GetType() << ")"; feaSegm->Label.setValue(label.str()); } delete (*it); } document->commitTransaction(); }
void OriginGroup::setupObject () { App::Document *doc = getDocument (); std::string objName = std::string ( getNameInDocument()).append ( "Origin" ); App::DocumentObject *originObj = doc->addObject ( "App::Origin", objName.c_str () ); assert ( originObj && originObj->isDerivedFrom ( App::Origin::getClassTypeId () ) ); Origin.setValue (originObj); GeoFeatureGroup::setupObject (); }
void Body::setupObject () { // NOTE: the code shared with App::OriginGroup App::Document *doc = getDocument (); std::string objName = std::string ( getNameInDocument() ).append ( "Origin" ); App::DocumentObject *originObj = doc->addObject ( "App::Origin", objName.c_str () ); assert ( originObj && originObj->isDerivedFrom ( App::Origin::getClassTypeId () ) ); Origin.setValue ( originObj ); Part::BodyBase::setupObject (); }
Py::Object show(const Py::Tuple& args) { PyObject *pcObj; if (!PyArg_ParseTuple(args.ptr(), "O!", &(FemMeshPy::Type), &pcObj)) throw Py::Exception(); App::Document *pcDoc = App::GetApplication().getActiveDocument(); if (!pcDoc) pcDoc = App::GetApplication().newDocument(); FemMeshPy* pShape = static_cast<FemMeshPy*>(pcObj); Fem::FemMeshObject *pcFeature = (Fem::FemMeshObject *)pcDoc->addObject("Fem::FemMeshObject", "Mesh"); // copy the data //TopoShape* shape = new MeshObject(*pShape->getTopoShapeObjectPtr()); pcFeature->FemMesh.setValue(*(pShape->getFemMeshPtr())); pcDoc->recompute(); return Py::None(); }
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(); }
Py::Object read(const Py::Tuple& args) { char* Name; const char* DocName=0; if (!PyArg_ParseTuple(args.ptr(), "et|s","utf-8",&Name,&DocName)) throw Py::Exception(); std::string EncodedName = std::string(Name); PyMem_Free(Name); Base::FileInfo file(EncodedName.c_str()); if (!file.exists()) throw Py::RuntimeError("File doesn't exist"); App::Document *pcDoc; if (DocName) pcDoc = App::GetApplication().getDocument(DocName); else pcDoc = App::GetApplication().getActiveDocument(); if (!pcDoc) pcDoc = App::GetApplication().newDocument(DocName); try { // read the gcode file std::ifstream filestr(file.filePath().c_str()); std::stringstream buffer; buffer << filestr.rdbuf(); std::string gcode = buffer.str(); Toolpath path; path.setFromGCode(gcode); Path::Feature *object = static_cast<Path::Feature *>(pcDoc->addObject("Path::Feature",file.fileNamePure().c_str())); object->Path.setValue(path); pcDoc->recompute(); } catch (const Base::Exception& e) { throw Py::RuntimeError(e.what()); } return Py::None(); }
Py::Object open(const Py::Tuple& args) { char* Name; if (!PyArg_ParseTuple(args.ptr(), "et","utf-8",&Name)) throw Py::Exception(); std::string EncodedName = std::string(Name); PyMem_Free(Name); std::unique_ptr<FemMesh> mesh(new FemMesh); mesh->read(EncodedName.c_str()); Base::FileInfo file(EncodedName.c_str()); // create new document and add Import feature App::Document *pcDoc = App::GetApplication().newDocument("Unnamed"); FemMeshObject *pcFeature = static_cast<FemMeshObject *> (pcDoc->addObject("Fem::FemMeshObject", file.fileNamePure().c_str())); pcFeature->Label.setValue(file.fileNamePure().c_str()); pcFeature->FemMesh.setValuePtr(mesh.release()); pcFeature->purgeTouched(); return Py::None(); }
Py::Object show(const Py::Tuple& args) { PyObject *pcObj; if (!PyArg_ParseTuple(args.ptr(), "O!", &(PointsPy::Type), &pcObj)) throw Py::Exception(); try { App::Document *pcDoc = App::GetApplication().getActiveDocument(); if (!pcDoc) pcDoc = App::GetApplication().newDocument(); PointsPy* pPoints = static_cast<PointsPy*>(pcObj); Points::Feature *pcFeature = (Points::Feature *)pcDoc->addObject("Points::Feature", "Points"); // copy the data //TopoShape* shape = new MeshObject(*pShape->getTopoShapeObjectPtr()); pcFeature->Points.setValue(*(pPoints->getPointKernelPtr())); //pcDoc->recompute(); } catch (const Base::Exception& e) { throw Py::RuntimeError(e.what()); } return Py::None(); }
Py::Object insert(const Py::Tuple& args) { char* Name; const char* DocName; if (!PyArg_ParseTuple(args.ptr(), "ets","utf-8",&Name,&DocName)) throw Py::Exception(); std::string EncodedName = std::string(Name); PyMem_Free(Name); try { //Base::Console().Log("Insert in Part with %s",Name); Base::FileInfo file(EncodedName.c_str()); // extract extension if (file.extension().empty()) throw Py::RuntimeError("No file extension"); App::Document *pcDoc = App::GetApplication().getDocument(DocName); if (!pcDoc) { pcDoc = App::GetApplication().newDocument(DocName); } if (file.hasExtension("skf")) { Sketcher::SketchObjectSF *pcFeature = (Sketcher::SketchObjectSF *)pcDoc->addObject("Sketcher::SketchObjectSF",file.fileNamePure().c_str()); pcFeature->SketchFlatFile.setValue(EncodedName.c_str()); pcDoc->recompute(); } else { throw Py::RuntimeError("Unknown file extension"); } } catch (const Base::Exception& e) { throw Py::RuntimeError(e.what()); } return Py::None(); }
/* module functions */ static PyObject * insert(PyObject *self, PyObject *args) { char* Name; const char* DocName; if (!PyArg_ParseTuple(args, "ets","utf-8",&Name,&DocName)) return NULL; std::string EncodedName = std::string(Name); PyMem_Free(Name); PY_TRY { //Base::Console().Log("Insert in Part with %s",Name); Base::FileInfo file(EncodedName.c_str()); // extract ending if (file.extension() == "") Py_Error(Base::BaseExceptionFreeCADError,"no file ending"); App::Document *pcDoc = App::GetApplication().getDocument(DocName); if (!pcDoc) { pcDoc = App::GetApplication().newDocument(DocName); } if (file.hasExtension("skf")) { Sketcher::SketchObjectSF *pcFeature = (Sketcher::SketchObjectSF *)pcDoc->addObject("Sketcher::SketchObjectSF",file.fileNamePure().c_str()); pcFeature->SketchFlatFile.setValue(EncodedName.c_str()); pcDoc->recompute(); } else { Py_Error(Base::BaseExceptionFreeCADError,"unknown file ending"); } } PY_CATCH; Py_Return; }
void CrossSections::apply() { std::vector<App::DocumentObject*> obj = Gui::Selection(). getObjectsOfType(Part::Feature::getClassTypeId()); std::vector<double> d; if (ui->sectionsBox->isChecked()) d = getPlanes(); else d.push_back(ui->position->value().getValue()); double a=0,b=0,c=0; switch (plane()) { case CrossSections::XY: c = 1.0; break; case CrossSections::XZ: b = 1.0; break; case CrossSections::YZ: a = 1.0; break; } #ifdef CS_FUTURE Standard::SetReentrant(Standard_True); for (std::vector<App::DocumentObject*>::iterator it = obj.begin(); it != obj.end(); ++it) { Part::CrossSection cs(a,b,c,static_cast<Part::Feature*>(*it)->Shape.getValue()); QFuture< std::list<TopoDS_Wire> > future = QtConcurrent::mapped (d, boost::bind(&Part::CrossSection::section, &cs, _1)); future.waitForFinished(); QFuture< std::list<TopoDS_Wire> >::const_iterator ft; TopoDS_Compound comp; BRep_Builder builder; builder.MakeCompound(comp); for (ft = future.begin(); ft != future.end(); ++ft) { const std::list<TopoDS_Wire>& w = *ft; for (std::list<TopoDS_Wire>::const_iterator wt = w.begin(); wt != w.end(); ++wt) { if (!wt->IsNull()) builder.Add(comp, *wt); } } App::Document* doc = (*it)->getDocument(); std::string s = (*it)->getNameInDocument(); s += "_cs"; Part::Feature* section = static_cast<Part::Feature*> (doc->addObject("Part::Feature",s.c_str())); section->Shape.setValue(comp); section->purgeTouched(); } #else Base::SequencerLauncher seq("Cross-sections...", obj.size() * (d.size() +1)); Gui::Command::runCommand(Gui::Command::App, "import Part\n"); Gui::Command::runCommand(Gui::Command::App, "from FreeCAD import Base\n"); for (std::vector<App::DocumentObject*>::iterator it = obj.begin(); it != obj.end(); ++it) { App::Document* doc = (*it)->getDocument(); std::string s = (*it)->getNameInDocument(); s += "_cs"; Gui::Command::runCommand(Gui::Command::App, QString::fromLatin1( "wires=list()\n" "shape=FreeCAD.getDocument(\"%1\").%2.Shape\n") .arg(QLatin1String(doc->getName())) .arg(QLatin1String((*it)->getNameInDocument())).toLatin1()); for (std::vector<double>::iterator jt = d.begin(); jt != d.end(); ++jt) { Gui::Command::runCommand(Gui::Command::App, QString::fromLatin1( "for i in shape.slice(Base.Vector(%1,%2,%3),%4):\n" " wires.append(i)\n" ).arg(a).arg(b).arg(c).arg(*jt).toLatin1()); seq.next(); } Gui::Command::runCommand(Gui::Command::App, QString::fromLatin1( "comp=Part.Compound(wires)\n" "slice=FreeCAD.getDocument(\"%1\").addObject(\"Part::Feature\",\"%2\")\n" "slice.Shape=comp\n" "slice.purgeTouched()\n" "del slice,comp,wires,shape") .arg(QLatin1String(doc->getName())) .arg(QLatin1String(s.c_str())).toLatin1()); seq.next(); } #endif }
void SegmentationBestFit::accept() { const Mesh::MeshObject* mesh = myMesh->Mesh.getValuePtr(); const MeshCore::MeshKernel& kernel = mesh->getKernel(); MeshCore::MeshSegmentAlgorithm finder(kernel); std::vector<MeshCore::MeshSurfaceSegment*> segm; if (ui->groupBoxCyl->isChecked()) { MeshCore::AbstractSurfaceFit* fitter; if (cylinderParameter.size() == 7) { std::vector<float>& p = cylinderParameter; fitter = new MeshCore::CylinderSurfaceFit( Base::Vector3f(p[0],p[1],p[2]), Base::Vector3f(p[3],p[4],p[5]), p[6]); } else { fitter = new MeshCore::CylinderSurfaceFit; } segm.push_back(new MeshCore::MeshDistanceGenericSurfaceFitSegment (fitter, kernel, ui->numCyl->value(), ui->tolCyl->value())); } if (ui->groupBoxSph->isChecked()) { MeshCore::AbstractSurfaceFit* fitter; if (sphereParameter.size() == 4) { std::vector<float>& p = sphereParameter; fitter = new MeshCore::SphereSurfaceFit( Base::Vector3f(p[0],p[1],p[2]), p[3]); } else { fitter = new MeshCore::SphereSurfaceFit; } segm.push_back(new MeshCore::MeshDistanceGenericSurfaceFitSegment (fitter, kernel, ui->numSph->value(), ui->tolSph->value())); } if (ui->groupBoxPln->isChecked()) { MeshCore::AbstractSurfaceFit* fitter; if (planeParameter.size() == 6) { std::vector<float>& p = planeParameter; fitter = new MeshCore::PlaneSurfaceFit( Base::Vector3f(p[0],p[1],p[2]), Base::Vector3f(p[3],p[4],p[5])); } else { fitter = new MeshCore::PlaneSurfaceFit; } segm.push_back(new MeshCore::MeshDistanceGenericSurfaceFitSegment (fitter, kernel, ui->numPln->value(), ui->tolPln->value())); } finder.FindSegments(segm); App::Document* document = App::GetApplication().getActiveDocument(); document->openTransaction("Segmentation"); std::string internalname = "Segments_"; internalname += myMesh->getNameInDocument(); App::DocumentObjectGroup* group = static_cast<App::DocumentObjectGroup*>(document->addObject ("App::DocumentObjectGroup", internalname.c_str())); std::string labelname = "Segments "; labelname += myMesh->Label.getValue(); group->Label.setValue(labelname); for (std::vector<MeshCore::MeshSurfaceSegment*>::iterator it = segm.begin(); it != segm.end(); ++it) { const std::vector<MeshCore::MeshSegment>& data = (*it)->GetSegments(); for (std::vector<MeshCore::MeshSegment>::const_iterator jt = data.begin(); jt != data.end(); ++jt) { Mesh::MeshObject* segment = mesh->meshFromSegment(*jt); Mesh::Feature* feaSegm = static_cast<Mesh::Feature*>(group->addObject("Mesh::Feature", "Segment")); Mesh::MeshObject* feaMesh = feaSegm->Mesh.startEditing(); feaMesh->swap(*segment); feaSegm->Mesh.finishEditing(); delete segment; std::stringstream label; label << feaSegm->Label.getValue() << " (" << (*it)->GetType() << ")"; feaSegm->Label.setValue(label.str()); } delete (*it); } document->commitTransaction(); }
PyObject* Application::sInsert(PyObject * /*self*/, PyObject *args,PyObject * /*kwd*/) { char* Name; char* DocName=0; if (!PyArg_ParseTuple(args, "et|s","utf-8",&Name,&DocName)) return NULL; std::string Utf8Name = std::string(Name); PyMem_Free(Name); PY_TRY { QString fileName = QString::fromUtf8(Utf8Name.c_str()); QFileInfo fi; fi.setFile(fileName); QString ext = fi.suffix().toLower(); if (ext == QLatin1String("iv")) { App::Document *doc = 0; if (DocName) doc = App::GetApplication().getDocument(DocName); else doc = App::GetApplication().getActiveDocument(); if (!doc) doc = App::GetApplication().newDocument(DocName); App::DocumentObject* obj = doc->addObject("App::InventorObject", (const char*)fi.baseName().toUtf8()); obj->Label.setValue((const char*)fi.baseName().toUtf8()); static_cast<App::PropertyString*>(obj->getPropertyByName("FileName")) ->setValue((const char*)fi.absoluteFilePath().toUtf8()); doc->recompute(); } else if (ext == QLatin1String("wrl") || ext == QLatin1String("vrml") || ext == QLatin1String("wrz")) { App::Document *doc = 0; if (DocName) doc = App::GetApplication().getDocument(DocName); else doc = App::GetApplication().getActiveDocument(); if (!doc) doc = App::GetApplication().newDocument(DocName); // Add this to the search path in order to read inline files (#0002029) QByteArray path = fi.absolutePath().toUtf8(); SoInput::addDirectoryFirst(path.constData()); App::DocumentObject* obj = doc->addObject("App::VRMLObject", (const char*)fi.baseName().toUtf8()); obj->Label.setValue((const char*)fi.baseName().toUtf8()); static_cast<App::PropertyFileIncluded*>(obj->getPropertyByName("VrmlFile")) ->setValue((const char*)fi.absoluteFilePath().toUtf8()); doc->recompute(); SoInput::removeDirectory(path.constData()); } else if (ext == QLatin1String("py") || ext == QLatin1String("fcmacro") || ext == QLatin1String("fcscript")) { PythonEditor* editor = new PythonEditor(); editor->setWindowIcon(Gui::BitmapFactory().iconFromTheme("applications-python")); PythonEditorView* edit = new PythonEditorView(editor, getMainWindow()); edit->open(fileName); edit->resize(400, 300); getMainWindow()->addWindow( edit ); } else { Base::Console().Error("File type '%s' not supported\n", ext.toLatin1().constData()); } } PY_CATCH; Py_Return; }
Py::Object open(const Py::Tuple& args) { char* Name; if (!PyArg_ParseTuple(args.ptr(), "et","utf-8",&Name)) throw Py::Exception(); std::string EncodedName = std::string(Name); PyMem_Free(Name); try { Base::Console().Log("Open in Points with %s",EncodedName.c_str()); Base::FileInfo file(EncodedName.c_str()); // extract ending if (file.extension().empty()) throw Py::RuntimeError("No file extension"); std::unique_ptr<Reader> reader; if (file.hasExtension("asc")) { reader.reset(new AscReader); } #ifdef HAVE_PCL_IO else if (file.hasExtension("ply")) { reader.reset(new PlyReader); } else if (file.hasExtension("pcd")) { reader.reset(new PcdReader); } #endif else { throw Py::RuntimeError("Unsupported file extension"); } reader->read(EncodedName); App::Document *pcDoc = App::GetApplication().newDocument("Unnamed"); Points::Feature *pcFeature = 0; if (reader->hasProperties()) { // Scattered or structured points? if (reader->isStructured()) { pcFeature = new Points::StructuredCustom(); App::PropertyInteger* width = static_cast<App::PropertyInteger*> (pcFeature->getPropertyByName("Width")); if (width) { width->setValue(reader->getWidth()); } App::PropertyInteger* height = static_cast<App::PropertyInteger*> (pcFeature->getPropertyByName("Height")); if (height) { height->setValue(reader->getHeight()); } } else { pcFeature = new Points::FeatureCustom(); } pcFeature->Points.setValue(reader->getPoints()); // add gray values if (reader->hasIntensities()) { Points::PropertyGreyValueList* prop = static_cast<Points::PropertyGreyValueList*> (pcFeature->addDynamicProperty("Points::PropertyGreyValueList", "Intensity")); if (prop) { prop->setValues(reader->getIntensities()); } } // add colors if (reader->hasColors()) { App::PropertyColorList* prop = static_cast<App::PropertyColorList*> (pcFeature->addDynamicProperty("App::PropertyColorList", "Color")); if (prop) { prop->setValues(reader->getColors()); } } // add normals if (reader->hasNormals()) { Points::PropertyNormalList* prop = static_cast<Points::PropertyNormalList*> (pcFeature->addDynamicProperty("Points::PropertyNormalList", "Normal")); if (prop) { prop->setValues(reader->getNormals()); } } // delayed adding of the points feature pcDoc->addObject(pcFeature, file.fileNamePure().c_str()); pcDoc->recomputeFeature(pcFeature); pcFeature->purgeTouched(); } else { if (reader->isStructured()) { Structured* structured = new Points::Structured(); structured->Width.setValue(reader->getWidth()); structured->Height.setValue(reader->getHeight()); pcFeature = structured; } else { pcFeature = new Points::Feature(); } // delayed adding of the points feature pcFeature->Points.setValue(reader->getPoints()); pcDoc->addObject(pcFeature, file.fileNamePure().c_str()); pcDoc->recomputeFeature(pcFeature); pcFeature->purgeTouched(); } } catch (const Base::Exception& e) { throw Py::RuntimeError(e.what()); } return Py::None(); }
Py::Object open(const Py::Tuple& args) { char* Name; if (!PyArg_ParseTuple(args.ptr(), "et","utf-8",&Name)) throw Py::Exception(); std::string EncodedName = std::string(Name); PyMem_Free(Name); try { Base::Console().Log("Open in Points with %s",EncodedName.c_str()); Base::FileInfo file(EncodedName.c_str()); // extract ending if (file.extension().empty()) throw Py::RuntimeError("No file extension"); if (file.hasExtension("asc")) { // create new document and add Import feature App::Document *pcDoc = App::GetApplication().newDocument("Unnamed"); Points::Feature *pcFeature = (Points::Feature *)pcDoc->addObject("Points::Feature", file.fileNamePure().c_str()); Points::PointKernel pkTemp; pkTemp.load(EncodedName.c_str()); pcFeature->Points.setValue( pkTemp ); } #ifdef HAVE_PCL_IO else if (file.hasExtension("ply")) { PlyReader reader; reader.read(EncodedName); App::Document *pcDoc = App::GetApplication().newDocument("Unnamed"); if (reader.hasProperties()) { Points::FeatureCustom *pcFeature = new Points::FeatureCustom(); pcFeature->Points.setValue(reader.getPoints()); // add gray values if (reader.hasIntensities()) { Points::PropertyGreyValueList* prop = static_cast<Points::PropertyGreyValueList*> (pcFeature->addDynamicProperty("Points::PropertyGreyValueList", "Intensity")); if (prop) { prop->setValues(reader.getIntensities()); } } // add colors if (reader.hasColors()) { App::PropertyColorList* prop = static_cast<App::PropertyColorList*> (pcFeature->addDynamicProperty("App::PropertyColorList", "Color")); if (prop) { prop->setValues(reader.getColors()); } } // add normals if (reader.hasNormals()) { Points::PropertyNormalList* prop = static_cast<Points::PropertyNormalList*> (pcFeature->addDynamicProperty("Points::PropertyNormalList", "Normal")); if (prop) { prop->setValues(reader.getNormals()); } } // delayed adding of the points feature pcDoc->addObject(pcFeature, file.fileNamePure().c_str()); pcDoc->recomputeFeature(pcFeature); } else { Points::Feature *pcFeature = static_cast<Points::Feature*> (pcDoc->addObject("Points::Feature", file.fileNamePure().c_str())); pcFeature->Points.setValue(reader.getPoints()); pcDoc->recomputeFeature(pcFeature); } } #endif else { throw Py::RuntimeError("Unsupported file extension"); } } catch (const Base::Exception& e) { throw Py::RuntimeError(e.what()); } return Py::None(); }