bool TaskDlgMeshShapeNetgen::accept()
{
    try {
        if(param->touched)
        {
            Gui::WaitCursor wc;
            App::DocumentObjectExecReturn* ret = FemMeshShapeNetgenObject->recompute();
            if (ret) {
                wc.restoreCursor();
                QMessageBox::critical(Gui::getMainWindow(), tr("Meshing failure"), QString::fromStdString(ret->Why));
                delete ret;
                return true;
            }
        }

        // hide the input object
        App::DocumentObject* obj = FemMeshShapeNetgenObject->Shape.getValue();
        if (obj) {
            Gui::Application::Instance->hideViewProvider(obj);
        }

        //FemSetNodesObject->Label.setValue(name->name);
        Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
        Gui::Command::commitCommand();

        return true;
    }
    catch (const Base::Exception& e) {
        Base::Console().Warning("TaskDlgMeshShapeNetgen::accept(): %s\n", e.what());
    }

    return false;
}
Exemplo n.º 2
0
static PyObject * open(PyObject *self, PyObject *args)
{
    char* Name;
    if (!PyArg_ParseTuple(args, "et","utf-8",&Name))
        return NULL;
    std::string EncodedName = std::string(Name);
    PyMem_Free(Name);
    Base::FileInfo fi(EncodedName);
    if (!fi.exists())
        Py_Error(Base::BaseExceptionFreeCADError, "File not found");
    Gui::WaitCursor wc;
    wc.restoreCursor();

    PY_TRY {
        std::string path = App::GetApplication().getHomePath();
        path += "Mod/Path/PathScripts/";
        QDir dir1(QString::fromUtf8(path.c_str()), QString::fromAscii("*_pre.py"));
        std::string cMacroPath = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro")
            ->GetASCII("MacroPath",App::Application::getUserAppDataDir().c_str());
        QDir dir2(QString::fromUtf8(cMacroPath.c_str()), QString::fromAscii("*_pre.py"));
        QFileInfoList list = dir1.entryInfoList();
        list << dir2.entryInfoList();
        std::vector<std::string> scripts;
        for (int i = 0; i < list.size(); ++i) {
            QFileInfo fileInfo = list.at(i);
            scripts.push_back(fileInfo.baseName().toStdString());
        }
        std::string selected;
        PathGui::DlgProcessorChooser Dlg(scripts);
        if (Dlg.exec() != QDialog::Accepted) {
            Py_Return;
        }
        selected = Dlg.getSelected();
    
        std::ostringstream pre;
        std::ostringstream cmd;
        if (selected.empty()) {
            App::Document *pcDoc = App::GetApplication().newDocument("Unnamed");
            Gui::Command::runCommand(Gui::Command::Gui,"import Path");
            cmd << "Path.read(\"" << EncodedName << "\",\"" << pcDoc->getName() << "\")";
            Gui::Command::runCommand(Gui::Command::Gui,cmd.str().c_str());
        } else {
            for (int i = 0; i < list.size(); ++i) {
                QFileInfo fileInfo = list.at(i);
                if (fileInfo.baseName().toStdString() == selected) {
                    if (fileInfo.absoluteFilePath().contains(QString::fromAscii("PathScripts"))) {
                        pre << "from PathScripts import " << selected;
                    } else {
                        pre << "import " << selected;
                    }
                    Gui::Command::runCommand(Gui::Command::Gui,pre.str().c_str());
                    cmd << selected << ".open(\"" << EncodedName << "\")";
                    Gui::Command::runCommand(Gui::Command::Gui,cmd.str().c_str());
                }
            }
        }
    } PY_CATCH;
    Py_Return;
}
Exemplo n.º 3
0
static PyObject * exporter(PyObject *self, PyObject *args)
{
    PyObject* object;
    char* Name;
    if (!PyArg_ParseTuple(args, "Oet",&object,"utf-8",&Name))
        return NULL;
    std::string EncodedName = std::string(Name);
    PyMem_Free(Name);
    Gui::WaitCursor wc;
    wc.restoreCursor();

    PY_TRY {
        Py::Sequence objlist(object);
        if (objlist.size() == 0)
            Py_Error(Base::BaseExceptionFreeCADError, "No object to export");
        std::string path = App::GetApplication().getHomePath();
        path += "Mod/Path/PathScripts/";
        QDir dir1(QString::fromUtf8(path.c_str()), QString::fromAscii("*_post.py"));
        std::string cMacroPath = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro")
            ->GetASCII("MacroPath",App::Application::getUserAppDataDir().c_str());
        QDir dir2(QString::fromUtf8(cMacroPath.c_str()), QString::fromAscii("*_post.py"));
        QFileInfoList list = dir1.entryInfoList();
        list << dir2.entryInfoList();
        std::vector<std::string> scripts;
        for (int i = 0; i < list.size(); ++i) {
            QFileInfo fileInfo = list.at(i);
            scripts.push_back(fileInfo.baseName().toStdString());
        }
        std::string selected;
        PathGui::DlgProcessorChooser Dlg(scripts);
        if (Dlg.exec() != QDialog::Accepted) {
            Py_Return;
        }
        selected = Dlg.getSelected();
            
        std::ostringstream pre;
        std::ostringstream cmd;
        if (selected.empty()) {
            if (objlist.size() > 1) {
                Py_Error(Base::BaseExceptionFreeCADError, "Cannot export more than one object without using a post script");
            }
            PyObject* item = objlist[0].ptr();
            if (PyObject_TypeCheck(item, &(App::DocumentObjectPy::Type))) {
                App::DocumentObject* obj = static_cast<App::DocumentObjectPy*>(item)->getDocumentObjectPtr();
                App::Document* doc = obj->getDocument();
                Gui::Command::runCommand(Gui::Command::Gui,"import Path");
                cmd << "Path.write(FreeCAD.getDocument(\"" << doc->getName() << "\").getObject(\"" << obj->getNameInDocument() << "\"),\"" << EncodedName << "\")";            
                Gui::Command::runCommand(Gui::Command::Gui,cmd.str().c_str());
            } else {
                Py_Return;
            }
        } else {
            for (int i = 0; i < list.size(); ++i) {
                QFileInfo fileInfo = list.at(i);
                if (fileInfo.baseName().toStdString() == selected) {
                    if (fileInfo.absoluteFilePath().contains(QString::fromAscii("PathScripts"))) {
                        pre << "from PathScripts import " << selected;
                    } else {
                        pre << "import " << selected;
                    }
                    Gui::Command::runCommand(Gui::Command::Gui,pre.str().c_str());
                    cmd << selected << ".export(__objs__,\"" << EncodedName << "\")";
                    Gui::Command::runCommand(Gui::Command::Gui,cmd.str().c_str());
                }
            }
        }
    } PY_CATCH;
    Py_Return;
}
Exemplo n.º 4
0
void Workbench::activated()
{
    std::string res = App::Application::getResourceDir();
    QString dir = QString::fromLatin1("%1/Mod/Robot/Lib/Kuka")
                  .arg(QString::fromUtf8(res.c_str()));
    QFileInfo fi(dir, QString::fromLatin1("kr_16.csv"));

    if (!fi.exists()) {
        Gui::WaitCursor wc;
        wc.restoreCursor();
        QMessageBox::warning(
            Gui::getMainWindow(),
            QObject::tr("No robot files installed"),
            QObject::tr("Please visit %1 and copy the files to %2")
            .arg(QString::fromLatin1(
            "https://free-cad.svn.sourceforge.net"
            "/svnroot/free-cad/trunk/src/Mod/Robot/Lib/Kuka")).arg(dir)
        );
        wc.setWaitCursor();
    }

    Gui::Workbench::activated();

    const char* RobotAndTrac[] = {
        "Robot_InsertWaypoint",
        "Robot_InsertWaypointPreselect",
        0};

    const char* Robot[] = {
        "Robot_AddToolShape",
        "Robot_SetHomePos",
        "Robot_RestoreHomePos",
        0};

    const char* Empty[] = {
        "Robot_InsertKukaIR500",
        "Robot_InsertKukaIR16",
        "Robot_InsertKukaIR210",
        "Robot_InsertKukaIR125",
        0};

    const char* TracSingle[] = {
        "Robot_TrajectoryDressUp",
        0};

    const char* TracMore[] = {
        "Robot_TrajectoryCompound",
        0};

    std::vector<Gui::TaskView::TaskWatcher*> Watcher;

    Watcher.push_back(new Gui::TaskView::TaskWatcherCommands(
        "SELECT Robot::TrajectoryObject COUNT 1"
        "SELECT Robot::RobotObject COUNT 1",
        RobotAndTrac,
        "Trajectory tools",
        "Robot_InsertWaypoint"
    ));

    Watcher.push_back(new TaskWatcherRobot);

    Watcher.push_back(new Gui::TaskView::TaskWatcherCommands(
        "SELECT Robot::RobotObject COUNT 1",
        Robot,
        "Robot tools",
        "Robot_CreateRobot"
    ));

    Watcher.push_back(new Gui::TaskView::TaskWatcherCommands(
        "SELECT Robot::TrajectoryObject COUNT 1",
        TracSingle,
        "Trajectory tools",
        "Robot_CreateRobot"
    ));

    Watcher.push_back(new Gui::TaskView::TaskWatcherCommands(
        "SELECT Robot::TrajectoryObject COUNT 2..",
        TracMore,
        "Trajectory tools",
        "Robot_CreateRobot"
    ));

   Watcher.push_back(new Gui::TaskView::TaskWatcherCommandsEmptyDoc(
         Empty,
        "Insert Robot",
        "Robot_CreateRobot"
    ));

    
    addTaskWatcher(Watcher);
    Gui::Control().showTaskView();
}
    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);
        Base::FileInfo fi(EncodedName);
        if (!fi.exists())
            throw Py::RuntimeError("File not found");

        Gui::WaitCursor wc;
        wc.restoreCursor();

        try {
            std::string path = App::GetApplication().getHomePath();
            path += "Mod/Path/PathScripts/";
            QDir dir1(QString::fromUtf8(path.c_str()), QString::fromLatin1("*_pre.py"));
            std::string cMacroPath = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro")
                ->GetASCII("MacroPath",App::Application::getUserMacroDir().c_str());
            QDir dir2(QString::fromUtf8(cMacroPath.c_str()), QString::fromLatin1("*_pre.py"));
            QFileInfoList list = dir1.entryInfoList();
            list << dir2.entryInfoList();
            std::vector<std::string> scripts;
            for (int i = 0; i < list.size(); ++i) {
                QFileInfo fileInfo = list.at(i);
                scripts.push_back(fileInfo.baseName().toStdString());
            }
            std::string processor;
            PathGui::DlgProcessorChooser Dlg(scripts);
            if (Dlg.exec() != QDialog::Accepted) {
                return Py::None();
            }
            processor = Dlg.getProcessor();

            std::ostringstream pre;
            std::ostringstream cmd;
            if (processor.empty()) {
                App::Document *pcDoc = App::GetApplication().newDocument("Unnamed");
                Gui::Command::runCommand(Gui::Command::Gui,"import Path");
                cmd << "Path.read(\"" << EncodedName << "\",\"" << pcDoc->getName() << "\")";
                Gui::Command::runCommand(Gui::Command::Gui,cmd.str().c_str());
            } else {
                for (int i = 0; i < list.size(); ++i) {
                    QFileInfo fileInfo = list.at(i);
                    if (fileInfo.baseName().toStdString() == processor) {
                        if (fileInfo.absoluteFilePath().contains(QString::fromLatin1("PathScripts"))) {
                            pre << "from PathScripts import " << processor;
                        } else {
                            pre << "import " << processor;
                        }
                        Gui::Command::runCommand(Gui::Command::Gui,pre.str().c_str());
                        cmd << processor << ".open(\"" << EncodedName << "\")";
                        Gui::Command::runCommand(Gui::Command::Gui,cmd.str().c_str());
                    }
                }
            }
        }
        catch (const Base::Exception& e) {
            throw Py::RuntimeError(e.what());
        }

        return Py::None();
    }
    Py::Object exporter(const Py::Tuple& args)
    {
        PyObject* object;
        char* Name;
        if (!PyArg_ParseTuple(args.ptr(), "Oet",&object,"utf-8",&Name))
            throw Py::Exception();

        std::string EncodedName = std::string(Name);
        PyMem_Free(Name);
        Gui::WaitCursor wc;
        wc.restoreCursor();

        try {
            Py::Sequence objlist(object);
            if (objlist.size() == 0)
                throw Py::RuntimeError("No object to export");

            std::string path = App::GetApplication().getHomePath();
            path += "Mod/Path/PathScripts/";
            QDir dir1(QString::fromUtf8(path.c_str()), QString::fromLatin1("*_post.py"));
            std::string cMacroPath = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro")
                ->GetASCII("MacroPath",App::Application::getUserMacroDir().c_str());
            QDir dir2(QString::fromUtf8(cMacroPath.c_str()), QString::fromLatin1("*_post.py"));
            QFileInfoList list = dir1.entryInfoList();
            list << dir2.entryInfoList();
            std::vector<std::string> scripts;
            for (int i = 0; i < list.size(); ++i) {
                QFileInfo fileInfo = list.at(i);
                scripts.push_back(fileInfo.baseName().toStdString());
            }
            PathGui::DlgProcessorChooser Dlg(scripts, true);
            if (Dlg.exec() != QDialog::Accepted) {
                return Py::None();
            }
            std::string processor = Dlg.getProcessor();
            std::string arguments = Dlg.getArguments();

            std::ostringstream pre;
            std::ostringstream cmd;
            if (processor.empty()) {
                if (objlist.size() > 1) {
                    throw Py::RuntimeError("Cannot export more than one object without using a post script");
                }
                PyObject* item = objlist[0].ptr();
                if (PyObject_TypeCheck(item, &(App::DocumentObjectPy::Type))) {
                    App::DocumentObject* obj = static_cast<App::DocumentObjectPy*>(item)->getDocumentObjectPtr();
                    App::Document* doc = obj->getDocument();
                    Gui::Command::runCommand(Gui::Command::Gui,"import Path");
                    cmd << "Path.write(FreeCAD.getDocument(\"" << doc->getName() << "\").getObject(\"" << obj->getNameInDocument() << "\"),\"" << EncodedName << "\")";
                    Gui::Command::runCommand(Gui::Command::Gui,cmd.str().c_str());
                } else {
                    return Py::None();
                }
            } else {
                for (int i = 0; i < list.size(); ++i) {
                    QFileInfo fileInfo = list.at(i);
                    if (fileInfo.baseName().toStdString() == processor) {
                        if (fileInfo.absoluteFilePath().contains(QString::fromLatin1("PathScripts"))) {
                            pre << "from PathScripts import " << processor;
                        } else {
                            pre << "import " << processor;
                        }
                        Gui::Command::runCommand(Gui::Command::Gui,pre.str().c_str());
                        cmd << processor << ".export(__objs__,\"" << EncodedName << "\",\"" << arguments << "\")";
                        Gui::Command::runCommand(Gui::Command::Gui,cmd.str().c_str());
                    }
                }
            }
        }
        catch (const Base::Exception& e) {
            throw Py::RuntimeError(e.what());
        }

        return Py::None();
    }