Пример #1
0
    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();
    }
Пример #2
0
    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();
    }
Пример #3
0
    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();
    }