From f01807be7efc8616336154faab7c3439d2c540de Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 4 Jan 2012 16:17:57 +0000 Subject: [PATCH 1/6] 0000548: 3D Circle from three points in Part wb git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5387 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d --- src/Gui/Workbench.cpp | 2 +- src/Gui/Workbench.h | 2 +- src/Mod/Part/Gui/DlgPrimitives.cpp | 155 +- src/Mod/Part/Gui/DlgPrimitives.h | 29 + src/Mod/Part/Gui/DlgPrimitives.ui | 3233 ++++++++++++++-------------- 5 files changed, 1807 insertions(+), 1614 deletions(-) diff --git a/src/Gui/Workbench.cpp b/src/Gui/Workbench.cpp index 91874b9f3..e173b22e2 100644 --- a/src/Gui/Workbench.cpp +++ b/src/Gui/Workbench.cpp @@ -341,7 +341,7 @@ PyObject* Workbench::getPyObject() return new WorkbenchPy(this); } -void Workbench::addTaskWatcher(std::vector &Watcher) +void Workbench::addTaskWatcher(const std::vector &Watcher) { Gui::TaskView::TaskView* taskView = Control().taskPanel(); if (taskView) diff --git a/src/Gui/Workbench.h b/src/Gui/Workbench.h index d781792df..223766b58 100644 --- a/src/Gui/Workbench.h +++ b/src/Gui/Workbench.h @@ -90,7 +90,7 @@ public: virtual void deactivated(); /// helper to add TaskWatcher to the TaskView - void addTaskWatcher(std::vector &Watcher); + void addTaskWatcher(const std::vector &Watcher); /// remove the added TaskWatcher void removeTaskWatcher(void); diff --git a/src/Mod/Part/Gui/DlgPrimitives.cpp b/src/Mod/Part/Gui/DlgPrimitives.cpp index 04b5462f9..1aae98b0b 100644 --- a/src/Mod/Part/Gui/DlgPrimitives.cpp +++ b/src/Mod/Part/Gui/DlgPrimitives.cpp @@ -24,15 +24,22 @@ #include "PreCompiled.h" #ifndef _PreComp_ #include +#include #include #include #include +#include +#include +#include +#include +#include #include #include #endif #include #include +#include #include #include #include @@ -47,6 +54,91 @@ using namespace PartGui; +namespace PartGui { + +void Picker::createPrimitive(QWidget* widget, const QString& descr, Gui::Document* doc) +{ + try { + App::Document* app = doc->getDocument(); + QString cmd = this->command(app); + + // Execute the Python block + doc->openCommand(descr.toUtf8()); + Gui::Command::doCommand(Gui::Command::Doc, (const char*)cmd.toAscii()); + doc->commitCommand(); + Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.recompute()"); + Gui::Command::doCommand(Gui::Command::Gui, "Gui.SendMsgToActiveView(\"ViewFit\")"); + } + catch (const Base::PyException& e) { + QMessageBox::warning(widget, descr, QString::fromLatin1(e.what())); + } +} + +QString Picker::toPlacement(const gp_Ax2& axis) const +{ + gp_Dir dir = axis.Direction(); + gp_Pnt pnt = gp_Pnt(0.0,0.0,0.0); + gp_Ax3 ax3(pnt, dir, axis.XDirection()); + + gp_Trsf Trf; + Trf.SetTransformation(ax3); + Trf.Invert(); + + gp_XYZ theAxis(0,0,1); + Standard_Real theAngle = 0.0; + Trf.GetRotation(theAxis,theAngle); + + Base::Rotation rot(Base::convertTo(theAxis), theAngle); + gp_Pnt loc = axis.Location(); + + return QString::fromAscii("Base.Placement(Base.Vector(%1,%2,%3),Base.Rotation(%4,%5,%6,%7))") + .arg(loc.X(),0,'f',2) + .arg(loc.Y(),0,'f',2) + .arg(loc.Z(),0,'f',2) + .arg(rot[0],0,'f',2) + .arg(rot[1],0,'f',2) + .arg(rot[2],0,'f',2) + .arg(rot[3],0,'f',2); +} + +class CircleFromThreePoints : public Picker +{ +public: + CircleFromThreePoints() : Picker() + { + } + bool pickedPoint(const SoPickedPoint * point) + { + SbVec3f pnt = point->getPoint(); + points.push_back(gp_Pnt(pnt[0],pnt[1],pnt[2])); + return points.size() == 3; + } + QString command(App::Document* doc) const + { + GC_MakeArcOfCircle arc(points[0], points[1], points[2]); + Handle_Geom_TrimmedCurve trim = arc.Value(); + Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(trim->BasisCurve()); + + QString name = QString::fromAscii(doc->getUniqueObjectName("Circle").c_str()); + return QString::fromAscii( + "App.ActiveDocument.addObject(\"Part::Circle\",\"%1\")\n" + "App.ActiveDocument.%1.Radius=%2\n" + "App.ActiveDocument.%1.Angle0=%3\n" + "App.ActiveDocument.%1.Angle1=%4\n" + "App.ActiveDocument.%1.Placement=%5\n") + .arg(name) + .arg(circle->Radius(),0,'f',2) + .arg(Base::toDegrees(trim->FirstParameter()),0,'f',2) + .arg(Base::toDegrees(trim->LastParameter ()),0,'f',2) + .arg(toPlacement(circle->Position())); + } + +private: + std::vector points; +}; + +} + /* TRANSLATOR PartGui::DlgPrimitives */ DlgPrimitives::DlgPrimitives(QWidget* parent) @@ -136,6 +228,66 @@ DlgPrimitives::~DlgPrimitives() { } +void DlgPrimitives::pickCallback(void * ud, SoEventCallback * n) +{ + const SoMouseButtonEvent * mbe = static_cast(n->getEvent()); + Gui::View3DInventorViewer* view = reinterpret_cast(n->getUserData()); + + // Mark all incoming mouse button events as handled, especially, to deactivate the selection node + n->setHandled(); + if (mbe->getButton() == SoMouseButtonEvent::BUTTON1) { + if (mbe->getState() == SoButtonEvent::DOWN) { + const SoPickedPoint * point = n->getPickedPoint(); + if (point) { + Picker* pick = reinterpret_cast(ud); + if (pick->pickedPoint(point)) { + pick->loop.exit(0); + } + } + } + } + else if (mbe->getButton() == SoMouseButtonEvent::BUTTON2) { + if (mbe->getState() == SoButtonEvent::UP) { + Picker* pick = reinterpret_cast(ud); + pick->loop.exit(1); + } + } +} + +void DlgPrimitives::executeCallback(Picker* p) +{ + Gui::Document* doc = Gui::Application::Instance->activeDocument(); + if (!doc) { + return; + } + + Gui::View3DInventor* view = static_cast(doc->getActiveView()); + if (view) { + Gui::View3DInventorViewer* viewer = view->getViewer(); + if (!viewer->isEditing()) { + viewer->setEditing(true); + viewer->setRedirectToSceneGraph(true); + viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(), pickCallback, p); + this->setDisabled(true); + int ret = p->loop.exec(); + this->setEnabled(true); + viewer->setEditing(false); + viewer->setRedirectToSceneGraph(false); + viewer->removeEventCallback(SoMouseButtonEvent::getClassTypeId(), pickCallback, p); + + if (ret == 0) { + p->createPrimitive(this, ui.comboBox1->currentText(), doc); + } + } + } +} + +void DlgPrimitives::on_buttonCircleFromThreePoints_clicked() +{ + CircleFromThreePoints pp; + executeCallback(&pp); +} + void DlgPrimitives::createPrimitive(const QString& placement) { try { @@ -384,9 +536,6 @@ void DlgPrimitives::createPrimitive(const QString& placement) Location::Location(QWidget* parent) { ui.setupUi(this); - - connect(ui.viewPositionButton, SIGNAL(clicked()), - this, SLOT(on_viewPositionButton_clicked())); } Location::~Location() diff --git a/src/Mod/Part/Gui/DlgPrimitives.h b/src/Mod/Part/Gui/DlgPrimitives.h index d485047df..178dff08a 100644 --- a/src/Mod/Part/Gui/DlgPrimitives.h +++ b/src/Mod/Part/Gui/DlgPrimitives.h @@ -23,14 +23,36 @@ #ifndef PARTGUI_DLGPRIMITIVES_H #define PARTGUI_DLGPRIMITIVES_H +#include #include #include #include "ui_DlgPrimitives.h" #include "ui_Location.h" +class gp_Ax2; class SoEventCallback; +namespace App { class Document; } +namespace Gui { class Document; } namespace PartGui { + +class Picker +{ +public: + Picker() + { + } + virtual ~Picker() + { + } + + virtual bool pickedPoint(const SoPickedPoint * point) = 0; + virtual QString command(App::Document*) const = 0; + void createPrimitive(QWidget* widget, const QString&, Gui::Document*); + QString toPlacement(const gp_Ax2&) const; + + QEventLoop loop; +}; class DlgPrimitives : public QWidget { @@ -41,6 +63,13 @@ public: ~DlgPrimitives(); void createPrimitive(const QString&); +private Q_SLOTS: + void on_buttonCircleFromThreePoints_clicked(); + +private: + static void pickCallback(void * ud, SoEventCallback * n); + void executeCallback(Picker*); + private: Ui_DlgPrimitives ui; }; diff --git a/src/Mod/Part/Gui/DlgPrimitives.ui b/src/Mod/Part/Gui/DlgPrimitives.ui index 8f227b6fb..6138066ea 100644 --- a/src/Mod/Part/Gui/DlgPrimitives.ui +++ b/src/Mod/Part/Gui/DlgPrimitives.ui @@ -6,7 +6,7 @@ 0 0 - 285 + 260 370 @@ -16,1623 +16,1638 @@ true - + - - - Primitive + + + + 0 + 0 + - - - - - - 0 - 0 - - - - 14 - - - - Plane - - - - - Box - - - - - Cylinder - - - - - Cone - - - - - Sphere - - - - - Ellipsoid - - - - - Torus - - - - - Wedge - - - - - Helix - - - - - Circle - - - - - Ellipse - - - - - Point - - - - - Line - - - - + + 14 + + + + Plane + + + + + Box + + + + + Cylinder + + + + + Cone + + + + + Sphere + + + + + Ellipsoid + + + + + Torus + + + + + Wedge + + + + + Helix + + + + + Circle + + + + + Ellipse + + + + + Point + + + + + Line + + + + + + + + Parameter + + + + 9 + + + 6 + - - - Parameter + + + 0 - - - 9 - - - 6 - - - - - 0 - - - - - 9 - - - 6 - - - - - 0 - - - 6 - - - - - 0.000000000000000 - - - 1000.000000000000000 - - - 10.000000000000000 - - - - - - - Width: - - - - - - - Length: - - - - - - - 1000.000000000000000 - - - 10.000000000000000 - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - + + + + 9 + + + 6 + + + + + 0 + + + 6 + + + + + 0.000000000000000 + + + 1000.000000000000000 + + + 10.000000000000000 + + + + + + + Width: + + + + + + + Length: + + + + + + + 1000.000000000000000 + + + 10.000000000000000 + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + 9 + + + 6 + + + + + Qt::Vertical + + + QSizePolicy::Expanding + + + + 20 + 51 + + + + + + + + 0 + + + 6 + + + + + Height: + + + + + + + 1000.000000000000000 + + + 10.000000000000000 + + + + + + + 0.000000000000000 + + + 1000.000000000000000 + + + 10.000000000000000 + + + + + + + Length: + + + + + + + 1000.000000000000000 + + + 10.000000000000000 + + + + + + + Width: + + + + + + + + + + + 9 + + + 6 + + + + + 6 + + + 0 + + + + + Angle: + + + + + + + 360.000000000000000 + + + 360.000000000000000 + + + + + + + + + QFrame::HLine + + + QFrame::Sunken + - - - - 9 - - - 6 - - - - - Qt::Vertical - - - QSizePolicy::Expanding - - - - 20 - 51 - - - - - - - - 0 - - - 6 - - - - - Height: - - - - - - - 1000.000000000000000 - - - 10.000000000000000 - - - - - - - 0.000000000000000 - - - 1000.000000000000000 - - - 10.000000000000000 - - - - - - - Length: - - - - - - - 1000.000000000000000 - - - 10.000000000000000 - - - - - - - Width: - - - - - - + + + + + Qt::Vertical + + + QSizePolicy::Expanding + + + + 31 + 81 + + + + + + + + 0 + + + 6 + + + + + Radius: + + + + + + + 1000.000000000000000 + + + 2.000000000000000 + + + + + + + 1000.000000000000000 + + + 10.000000000000000 + + + + + + + Height: + + + + + + + + + + + 9 + + + 6 + + + + + 6 + + + 0 + + + + + Angle: + + + + + + + 360.000000000000000 + + + 360.000000000000000 + + + + + + + + + QFrame::HLine + + + QFrame::Sunken + - - - - 9 - - - 6 - - - - - 6 - - - 0 - - - - - Angle: - - - - - - - 360.000000000000000 - - - 360.000000000000000 - - - - - - - - - QFrame::HLine - - - QFrame::Sunken - - - - - - - Qt::Vertical - - - QSizePolicy::Expanding - - - - 31 - 81 - - - - - - - - 0 - - - 6 - - - - - Radius: - - - - - - - 1000.000000000000000 - - - 2.000000000000000 - - - - - - - 1000.000000000000000 - - - 10.000000000000000 - - - - - - - Height: - - - - - - + + + + + Qt::Vertical + + + QSizePolicy::Expanding + + + + 31 + 91 + + + + + + + + 0 + + + 6 + + + + + Height: + + + + + + + 1000.000000000000000 + + + 4.000000000000000 + + + + + + + 1000.000000000000000 + + + 10.000000000000000 + + + + + + + 1000.000000000000000 + + + 2.000000000000000 + + + + + + + Radius 1: + + + + + + + Radius 2: + + + + + + + + + + + 9 + + + 6 + + + + + QFrame::HLine + + + QFrame::Sunken + - - - - 9 - - - 6 - - - - - 6 - - - 0 - - - - - Angle: - - - - - - - 360.000000000000000 - - - 360.000000000000000 - - - - - - - - - QFrame::HLine - - - QFrame::Sunken - - - - - - - Qt::Vertical - - - QSizePolicy::Expanding - - - - 31 - 91 - - - - - - - - 0 - - - 6 - - - - - Height: - - - - - - - 1000.000000000000000 - - - 4.000000000000000 - - - - - - - 1000.000000000000000 - - - 10.000000000000000 - - - - - - - 1000.000000000000000 - - - 2.000000000000000 - - - - - - - Radius 1: - - - - - - - Radius 2: - - - - - - + + + + + 0 + + + 6 + + + + + U parametric: + + + + + + + Qt::Horizontal + + + QSizePolicy::Preferred + + + + 81 + 20 + + + + + + + + -90.000000000000000 + + + 90.000000000000000 + + + -90.000000000000000 + + + + + + + V parametric: + + + + + + + -90.000000000000000 + + + 90.000000000000000 + + + 90.000000000000000 + + + + + + + 360.000000000000000 + + + 360.000000000000000 + + + + + + + + + Qt::Vertical + + + QSizePolicy::Expanding + + + + 21 + 151 + + + + + + + + 6 + + + 0 + + + + + Radius: + + + + + + + 1000.000000000000000 + + + 5.000000000000000 + + + + + + + + + + + 9 + + + 6 + + + + + Qt::Vertical + + + + 20 + 20 + + + + + + + + QFrame::HLine + + + QFrame::Sunken + - - - - 9 - - - 6 - - - - - QFrame::HLine - - - QFrame::Sunken - - - - - - - 0 - - - 6 - - - - - U parametric: - - - - - - - Qt::Horizontal - - - QSizePolicy::Preferred - - - - 81 - 20 - - - - - - - - -90.000000000000000 - - - 90.000000000000000 - - - -90.000000000000000 - - - - - - - V parametric: - - - - - - - -90.000000000000000 - - - 90.000000000000000 - - - 90.000000000000000 - - - - - - - 360.000000000000000 - - - 360.000000000000000 - - - - - - - - - Qt::Vertical - - - QSizePolicy::Expanding - - - - 21 - 151 - - - - - - - - 6 - - - 0 - - - - - Radius: - - - - - - - 1000.000000000000000 - - - 5.000000000000000 - - - - - - + + + + + 0 + + + 6 + + + + + 1000.000000000000000 + + + 4.000000000000000 + + + + + + + 1000.000000000000000 + + + 2.000000000000000 + + + + + + + Radius 1: + + + + + + + Radius 2: + + + + + + + + + 0 + + + 6 + + + + + U parametric: + + + + + + + Qt::Horizontal + + + QSizePolicy::Preferred + + + + 81 + 20 + + + + + + + + -90.000000000000000 + + + 90.000000000000000 + + + -90.000000000000000 + + + + + + + V parametric: + + + + + + + -90.000000000000000 + + + 90.000000000000000 + + + 90.000000000000000 + + + + + + + 360.000000000000000 + + + 360.000000000000000 + + + + + + + + + + + 9 + + + 6 + + + + + QFrame::HLine + + + QFrame::Sunken + - - - - 9 - - - 6 - - - - - Qt::Vertical - - - - 20 - 20 - - - - - - - - QFrame::HLine - - - QFrame::Sunken - - - - - - - 0 - - - 6 - - - - - 1000.000000000000000 - - - 4.000000000000000 - - - - - - - 1000.000000000000000 - - - 2.000000000000000 - - - - - - - Radius 1: - - - - - - - Radius 2: - - - - - - - - - 0 - - - 6 - - - - - U parametric: - - - - - - - Qt::Horizontal - - - QSizePolicy::Preferred - - - - 81 - 20 - - - - - - - - -90.000000000000000 - - - 90.000000000000000 - - - -90.000000000000000 - - - - - - - V parametric: - - - - - - - -90.000000000000000 - - - 90.000000000000000 - - - 90.000000000000000 - - - - - - - 360.000000000000000 - - - 360.000000000000000 - - - - - - - - - - - 9 - - - 6 - - - - - QFrame::HLine - - - QFrame::Sunken - - - - - - - 0 - - - 6 - - - - - U parametric: - - - - - - - Qt::Horizontal - - - QSizePolicy::Preferred - - - - 81 - 20 - - - - - - - - -180.000000000000000 - - - 180.000000000000000 - - - -180.000000000000000 - - - - - - - V parametric: - - - - - - - -180.000000000000000 - - - 180.000000000000000 - - - 180.000000000000000 - - - - - - - 360.000000000000000 - - - 360.000000000000000 - - - - - - - - - Qt::Vertical - - - QSizePolicy::Expanding - - - - 20 - 91 - - - - - - - - 0 - - - 6 - - - - - Radius 2: - - - - - - - Radius 1: - - - - - - - 1000.000000000000000 - - - 2.000000000000000 - - - - - - - 1000.000000000000000 - - - 10.000000000000000 - - - - - - - - - - - - - - - X min/max: - - - - - - - - 0 - 0 - - - - - - - - - 0 - 0 - - - - 10.000000000000000 - - - - - - - Y min/max: - - - - - - - - 0 - 0 - - - - - - - - - 0 - 0 - - - - 10.000000000000000 - - - - - - - Z min/max: - - - - - - - - 0 - 0 - - - - - - - - - 0 - 0 - - - - 10.000000000000000 - - - - - - - X2 min/max: - - - - - - - - 0 - 0 - - - - 2.000000000000000 - - - - - - - - 0 - 0 - - - - 8.000000000000000 - - - - - - - Z2 min/max: - - - - - - - - 0 - 0 - - - - 2.000000000000000 - - - - - - - - 0 - 0 - - - - 8.000000000000000 - - - - - - - - - Qt::Vertical - - - - 20 - 81 - - - - - - - - - - 9 - - - 6 - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - 0 - - - 6 - - - - - Radius: - - - - - - - Pitch: - - - - - - - 1000.000000000000000 - - - 1.000000000000000 - - - - - - - 1000.000000000000000 - - - 1.000000000000000 - - - - - - - 1000.000000000000000 - - - 2.000000000000000 - - - - - - - Height: - - - - - - - Angle: - - - - - - - 0.000000000000000 - - - 89.989999999999995 - - - 1.000000000000000 - - - 0.000000000000000 - - - - - - - - - - - - - 0 - - - 6 - - - - - Radius: - - - - - - - 1000000000.000000000000000 - - - 2.000000000000000 - - - - - - - Angle 1: - - - - - - - 360.000000000000000 - - - 0.000000000000000 - - - - - - - Angle 2: - - - - - - - 0.000000000000000 - - - 360.000000000000000 - - - 1.000000000000000 - - - 360.000000000000000 - - - - - - - - - Qt::Vertical - - - - 20 - 95 - - - - - - - - - - - - - - Major radius: - - - - - - - 1000000000.000000000000000 - - - 4.000000000000000 - - - - - - - Minor radius: - - - - - - - 1000000000.000000000000000 - - - 2.000000000000000 - - - - - - - Angle 1: - - - - - - - 360.000000000000000 - - - 0.000000000000000 - - - - - - - Angle 2: - - - - - - - 0.000000000000000 - - - 360.000000000000000 - - - 1.000000000000000 - - - 360.000000000000000 - - - - - - - - - Qt::Vertical - - - - 20 - 131 - - - - - - - - - - - - - - - - - - - - - - - X: - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - Y: - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - Z: - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - - - Qt::Vertical - - - - 20 - 139 - - - - - - - - - - - - - - X: - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - Y: - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - Z: - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - Qt::Horizontal - - - - - - - End point - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - Start point - - - - - - - X: - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - Y: - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - Z: - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - 0.000000000000000 - - - - - - - 0.000000000000000 - - - - - - - - - - 0.000000000000000 - - - - - - - 1.000000000000000 - - - - - - - 1.000000000000000 - - - - - - - 1.000000000000000 - - - - - - - - - Qt::Vertical - - - - 20 - 0 - - - - - - - - - + + + + + 0 + + + 6 + + + + + U parametric: + + + + + + + Qt::Horizontal + + + QSizePolicy::Preferred + + + + 81 + 20 + + + + + + + + -180.000000000000000 + + + 180.000000000000000 + + + -180.000000000000000 + + + + + + + V parametric: + + + + + + + -180.000000000000000 + + + 180.000000000000000 + + + 180.000000000000000 + + + + + + + 360.000000000000000 + + + 360.000000000000000 + + + + + + + + + Qt::Vertical + + + QSizePolicy::Expanding + + + + 20 + 91 + + + + + + + + 0 + + + 6 + + + + + Radius 2: + + + + + + + Radius 1: + + + + + + + 1000.000000000000000 + + + 2.000000000000000 + + + + + + + 1000.000000000000000 + + + 10.000000000000000 + + + + + + + + + + + + + + + X min/max: + + + + + + + + 0 + 0 + + + + + + + + + 0 + 0 + + + + 10.000000000000000 + + + + + + + Y min/max: + + + + + + + + 0 + 0 + + + + + + + + + 0 + 0 + + + + 10.000000000000000 + + + + + + + Z min/max: + + + + + + + + 0 + 0 + + + + + + + + + 0 + 0 + + + + 10.000000000000000 + + + + + + + X2 min/max: + + + + + + + + 0 + 0 + + + + 2.000000000000000 + + + + + + + + 0 + 0 + + + + 8.000000000000000 + + + + + + + Z2 min/max: + + + + + + + + 0 + 0 + + + + 2.000000000000000 + + + + + + + + 0 + 0 + + + + 8.000000000000000 + + + + + + + + + Qt::Vertical + + + + 20 + 81 + + + + + + + + + + 9 + + + 6 + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + 0 + + + 6 + + + + + Radius: + + + + + + + Pitch: + + + + + + + 1000.000000000000000 + + + 1.000000000000000 + + + + + + + 1000.000000000000000 + + + 1.000000000000000 + + + + + + + 1000.000000000000000 + + + 2.000000000000000 + + + + + + + Height: + + + + + + + Angle: + + + + + + + 0.000000000000000 + + + 89.989999999999995 + + + 1.000000000000000 + + + 0.000000000000000 + + + + + + + + + + + + + 0 + + + 6 + + + + + Radius: + + + + + + + 1000000000.000000000000000 + + + 2.000000000000000 + + + + + + + Angle 1: + + + + + + + 360.000000000000000 + + + 0.000000000000000 + + + + + + + Angle 2: + + + + + + + 0.000000000000000 + + + 360.000000000000000 + + + 1.000000000000000 + + + 360.000000000000000 + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + From three points + + + + + + + + + Qt::Vertical + + + + 20 + 95 + + + + + + + + + + + + + + Major radius: + + + + + + + 1000000000.000000000000000 + + + 4.000000000000000 + + + + + + + Minor radius: + + + + + + + 1000000000.000000000000000 + + + 2.000000000000000 + + + + + + + Angle 1: + + + + + + + 360.000000000000000 + + + 0.000000000000000 + + + + + + + Angle 2: + + + + + + + 0.000000000000000 + + + 360.000000000000000 + + + 1.000000000000000 + + + 360.000000000000000 + + + + + + + + + Qt::Vertical + + + + 20 + 131 + + + + + + + + + + + + + + + + + + + + + + + X: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + Y: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + Z: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + + + Qt::Vertical + + + + 20 + 139 + + + + + + + + + + + + + + X: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + Y: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + Z: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + Qt::Horizontal + + + + + + + End point + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + Start point + + + + + + + X: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + Y: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + Z: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + 0.000000000000000 + + + + + + + 0.000000000000000 + + + + + + + + + + 0.000000000000000 + + + + + + + 1.000000000000000 + + + + + + + 1.000000000000000 + + + + + + + 1.000000000000000 + + + + + + + + + Qt::Vertical + + + + 20 + 0 + + + + + + From f3b9ee8e9aeffc6c7cbdc8093fd0f1712acbb34a Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 4 Jan 2012 16:44:55 +0000 Subject: [PATCH 2/6] 0000548: 3D Circle from three points in Part wb git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5388 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d --- src/Mod/Part/Gui/DlgPrimitives.cpp | 41 +++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/src/Mod/Part/Gui/DlgPrimitives.cpp b/src/Mod/Part/Gui/DlgPrimitives.cpp index 1aae98b0b..83b6b53cc 100644 --- a/src/Mod/Part/Gui/DlgPrimitives.cpp +++ b/src/Mod/Part/Gui/DlgPrimitives.cpp @@ -55,6 +55,43 @@ using namespace PartGui; namespace PartGui { + +const char* gce_ErrorStatusText(gce_ErrorType et) +{ + switch (et) + { + case gce_Done: + return "Construction was successful"; + case gce_ConfusedPoints: + return "Two points are coincident"; + case gce_NegativeRadius: + return "Radius value is negative"; + case gce_ColinearPoints: + return "Three points are collinear"; + case gce_IntersectionError: + return "Intersection cannot be computed"; + case gce_NullAxis: + return "Axis is undefined"; + case gce_NullAngle: + return "Angle value is invalid (usually null)"; + case gce_NullRadius: + return "Radius is null"; + case gce_InvertAxis: + return "Axis value is invalid"; + case gce_BadAngle: + return "Angle value is invalid"; + case gce_InvertRadius: + return "Radius value is incorrect (usually with respect to another radius)"; + case gce_NullFocusLength: + return "Focal distance is null"; + case gce_NullVector: + return "Vector is null"; + case gce_BadEquation: + return "Coefficients are incorrect (applies to the equation of a geometric object)"; + default: + return "Creation of geometry failed"; + } +} void Picker::createPrimitive(QWidget* widget, const QString& descr, Gui::Document* doc) { @@ -69,7 +106,7 @@ void Picker::createPrimitive(QWidget* widget, const QString& descr, Gui::Documen Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.recompute()"); Gui::Command::doCommand(Gui::Command::Gui, "Gui.SendMsgToActiveView(\"ViewFit\")"); } - catch (const Base::PyException& e) { + catch (const Base::Exception& e) { QMessageBox::warning(widget, descr, QString::fromLatin1(e.what())); } } @@ -116,6 +153,8 @@ public: QString command(App::Document* doc) const { GC_MakeArcOfCircle arc(points[0], points[1], points[2]); + if (!arc.IsDone()) + throw Base::Exception(gce_ErrorStatusText(arc.Status())); Handle_Geom_TrimmedCurve trim = arc.Value(); Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(trim->BasisCurve()); From ef4ce7f407936aec4ec4c4101a2e5dcce5a00968 Mon Sep 17 00:00:00 2001 From: jriegel Date: Thu, 5 Jan 2012 14:25:32 +0000 Subject: [PATCH 3/6] Merge branch 'master' into HEAD git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5389 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d --- src/Mod/Arch/ArchWall.py | 0 src/Mod/Arch/Init.py | 0 src/Mod/Arch/InitGui.py | 148 ++++++++++++++++-------------- src/Mod/Arch/ifcReader.py | 0 src/Mod/Arch/importDAE.py | 14 ++- src/Mod/Draft/Draft.py | 76 +++++++++------ src/Mod/Draft/DraftSnap.py | 2 + src/Mod/Draft/DraftTools.py | 0 src/Mod/Draft/InitGui.py | 16 ++-- src/Mod/Draft/importAirfoilDAT.py | 0 src/Mod/Draft/importSVG.py | 9 +- src/Mod/Draft/macros.py | 0 12 files changed, 152 insertions(+), 113 deletions(-) mode change 100755 => 100644 src/Mod/Arch/ArchWall.py mode change 100755 => 100644 src/Mod/Arch/Init.py mode change 100755 => 100644 src/Mod/Arch/InitGui.py mode change 100755 => 100644 src/Mod/Arch/ifcReader.py mode change 100755 => 100644 src/Mod/Draft/DraftTools.py mode change 100755 => 100644 src/Mod/Draft/importAirfoilDAT.py mode change 100755 => 100644 src/Mod/Draft/macros.py diff --git a/src/Mod/Arch/ArchWall.py b/src/Mod/Arch/ArchWall.py old mode 100755 new mode 100644 diff --git a/src/Mod/Arch/Init.py b/src/Mod/Arch/Init.py old mode 100755 new mode 100644 diff --git a/src/Mod/Arch/InitGui.py b/src/Mod/Arch/InitGui.py old mode 100755 new mode 100644 index 7df441047..0d069b29b --- a/src/Mod/Arch/InitGui.py +++ b/src/Mod/Arch/InitGui.py @@ -22,78 +22,84 @@ #*************************************************************************** class ArchWorkbench(Workbench): - "Arch workbench object" - Icon = """ - /* XPM */ - static char * arch_xpm[] = { - "16 16 9 1", - " c None", - ". c #543016", - "+ c #6D2F08", - "@ c #954109", - "# c #874C24", - "$ c #AE6331", - "% c #C86423", - "& c #FD7C26", - "* c #F5924F", - " ", - " ", - " # ", - " ***$# ", - " .*******. ", - " *##$****#+ ", - " #**%&&##$#@@ ", - ".$**%&&&&+@@+ ", - "@&@#$$%&&@@+.. ", - "@&&&%#.#$#+..#$.", - " %&&&&+%#.$**$@+", - " @%&+&&&$##@@+", - " @.&&&&&@@@ ", - " @%&&@@ ", - " @+ ", - " "}; - """ - MenuText = "Arch" - ToolTip = "Architecture workbench" + "Arch workbench object" + Icon = """ + /* XPM */ + static char * arch_xpm[] = { + "16 16 9 1", + " c None", + ". c #543016", + "+ c #6D2F08", + "@ c #954109", + "# c #874C24", + "$ c #AE6331", + "% c #C86423", + "& c #FD7C26", + "* c #F5924F", + " ", + " ", + " # ", + " ***$# ", + " .*******. ", + " *##$****#+ ", + " #**%&&##$#@@ ", + ".$**%&&&&+@@+ ", + "@&@#$$%&&@@+.. ", + "@&&&%#.#$#+..#$.", + " %&&&&+%#.$**$@+", + " @%&+&&&$##@@+", + " @.&&&&&@@@ ", + " @%&&@@ ", + " @+ ", + " "}; + """ + MenuText = "Arch" + ToolTip = "Architecture workbench" - def Initialize(self): - import DraftTools,DraftGui,Arch_rc,Arch - archtools = ["Arch_Wall","Arch_Structure","Arch_Cell", - "Arch_Floor","Arch_Building","Arch_Site", - "Arch_Window","Arch_Axis", - "Arch_SectionPlane","Arch_Add","Arch_Remove"] - drafttools = ["Draft_Line","Draft_Wire","Draft_Rectangle", - "Draft_Polygon","Draft_Arc", - "Draft_Circle","Draft_Dimension", - "Draft_Move","Draft_Rotate", - "Draft_Offset","Draft_Upgrade", - "Draft_Downgrade","Draft_Trimex"] - meshtools = ["Arch_SplitMesh","Arch_MeshToShape", - "Arch_SelectNonSolidMeshes","Arch_RemoveShape"] - self.appendToolbar(str(DraftTools.translate("arch","Arch tools")),archtools) - self.appendToolbar(str(DraftTools.translate("arch","Draft tools")),drafttools) - self.appendMenu([str(DraftTools.translate("arch","Architecture")),str(DraftTools.translate("arch","Tools"))],meshtools) - self.appendMenu(str(DraftTools.translate("arch","Architecture")),archtools) - self.appendMenu(str(DraftTools.translate("arch","Draft")),drafttools) - FreeCADGui.addIconPath(":/icons") - FreeCADGui.addLanguagePath(":/translations") - FreeCADGui.addPreferencePage(":/ui/archprefs-base.ui","Arch") - FreeCAD.addImportType("Industry Foundation Classes (*.ifc)","importIFC") - FreeCAD.addExportType("Wavefront OBJ - Arch module (*.obj)","importOBJ") - try: - import collada - except: - Log("pycollada not found, no collada support\n") - else: - FreeCAD.addImportType("Collada (*.dae)","importDAE") - FreeCAD.addExportType("Collada (*.dae)","importDAE") - Log ('Loading Arch module... done\n') - def Activated(self): - FreeCADGui.draftToolBar.Activated() - Msg("Arch workbench activated\n") - def Deactivated(self): - FreeCADGui.draftToolBar.Deactivated() - Msg("Arch workbench deactivated\n") + def Initialize(self): + import DraftTools,DraftGui,Arch_rc,Arch + self.archtools = ["Arch_Wall","Arch_Structure","Arch_Cell", + "Arch_Floor","Arch_Building","Arch_Site", + "Arch_Window","Arch_Axis", + "Arch_SectionPlane","Arch_Add","Arch_Remove"] + self.drafttools = ["Draft_Line","Draft_Wire","Draft_Rectangle", + "Draft_Polygon","Draft_Arc", + "Draft_Circle","Draft_Dimension", + "Draft_Move","Draft_Rotate", + "Draft_Offset","Draft_Upgrade", + "Draft_Downgrade","Draft_Trimex"] + self.draftcontexttools = ["Draft_ApplyStyle","Draft_ToggleDisplayMode", + "Draft_AddToGroup","Draft_SelectGroup", + "Draft_SelectPlane"] + self.meshtools = ["Arch_SplitMesh","Arch_MeshToShape", + "Arch_SelectNonSolidMeshes","Arch_RemoveShape"] + self.appendToolbar(str(DraftTools.translate("arch","Arch tools")),self.archtools) + self.appendToolbar(str(DraftTools.translate("arch","Draft tools")),self.drafttools) + self.appendMenu([str(DraftTools.translate("arch","Architecture")),str(DraftTools.translate("arch","Tools"))],self.meshtools) + self.appendMenu(str(DraftTools.translate("arch","Architecture")),self.archtools) + self.appendMenu(str(DraftTools.translate("arch","Draft")),self.drafttools+self.draftcontexttools) + FreeCADGui.addIconPath(":/icons") + FreeCADGui.addLanguagePath(":/translations") + FreeCADGui.addPreferencePage(":/ui/archprefs-base.ui","Arch") + FreeCAD.addImportType("Industry Foundation Classes (*.ifc)","importIFC") + FreeCAD.addExportType("Wavefront OBJ - Arch module (*.obj)","importOBJ") + FreeCAD.addImportType("Collada (*.dae)","importDAE") + FreeCAD.addExportType("Collada (*.dae)","importDAE") + Log ('Loading Arch module... done\n') + + def Activated(self): + FreeCADGui.draftToolBar.Activated() + Msg("Arch workbench activated\n") + + def Deactivated(self): + FreeCADGui.draftToolBar.Deactivated() + Msg("Arch workbench deactivated\n") + + def ContextMenu(self, recipient): + self.appendContextMenu("Display tools",self.draftcontexttools) + + def GetClassName(self): + return "Gui::PythonWorkbench" FreeCADGui.addWorkbench(ArchWorkbench) diff --git a/src/Mod/Arch/ifcReader.py b/src/Mod/Arch/ifcReader.py old mode 100755 new mode 100644 diff --git a/src/Mod/Arch/importDAE.py b/src/Mod/Arch/importDAE.py index f0c73b882..11aa527e1 100644 --- a/src/Mod/Arch/importDAE.py +++ b/src/Mod/Arch/importDAE.py @@ -21,7 +21,7 @@ #* * #*************************************************************************** -import FreeCAD, collada, Mesh, os, numpy +import FreeCAD, Mesh, os, numpy __title__="FreeCAD Collada importer" __author__ = "Yorik van Havre" @@ -29,8 +29,19 @@ __url__ = "http://free-cad.sourceforge.net" DEBUG = True +def checkCollada(): + "checks if collada if available" + try: + import collada + except: + FreeCAD.Console.PrintError("pycollada not found, no collada support.\n") + return False + else: + return True + def open(filename): "called when freecad wants to open a file" + if not checkCollada(): return docname = os.path.splitext(os.path.basename(filename))[0] doc = FreeCAD.newDocument(docname) doc.Label = decode(docname) @@ -76,6 +87,7 @@ def read(filename): def export(exportList,filename): "called when freecad exports a file" + if not checkCollada(): return colmesh = collada.Collada() effect = collada.material.Effect("effect0", [], "phong", diffuse=(.7,.7,.7), specular=(1,1,1)) mat = collada.material.Material("material0", "mymaterial", effect) diff --git a/src/Mod/Draft/Draft.py b/src/Mod/Draft/Draft.py index 454be1f39..eadc25d54 100644 --- a/src/Mod/Draft/Draft.py +++ b/src/Mod/Draft/Draft.py @@ -200,7 +200,6 @@ def shapify(obj): non-parametric and returns the new object''' if not (obj.isDerivedFrom("Part::Feature")): return None if not "Shape" in obj.PropertiesList: return None - if obj.Type == "Part::Feature": return obj shape = obj.Shape name = getRealName(obj.Name) FreeCAD.ActiveDocument.removeObject(obj.Name) @@ -515,7 +514,7 @@ def makeCopy(obj): _ViewProviderBSpline(newobj.ViewObject) elif getType(obj) == "Block": _Block(newobj) - _ViewProviderBlock(newobj.ViewObject) + _ViewProviderDraftPart(newobj.ViewObject) elif getType(obj) == "Structure": import Structure Structure._Structure(newobj) @@ -539,7 +538,7 @@ def makeBlock(objectslist): '''makeBlock(objectslist): Creates a Draft Block from the given objects''' obj = FreeCAD.ActiveDocument.addObject("Part::Part2DObjectPython","Block") _Block(obj) - _ViewProviderBlock(obj.ViewObject) + _ViewProviderDraftPart(obj.ViewObject) obj.Components = objectslist for o in objectslist: o.ViewObject.Visibility = False @@ -557,7 +556,7 @@ def makeArray(baseobject,arg1,arg2,arg3,arg4=None): The result is a parametric Draft Array.''' obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython","Array") _Array(obj) - _ViewProviderDraft(obj.ViewObject) + _ViewProviderDraftPart(obj.ViewObject) obj.Base = baseobject if arg4: obj.ArrayType = "ortho" @@ -796,11 +795,16 @@ def scale(objectslist,delta=Vector(1,1,1),center=Vector(0,0,0),copy=False,legacy return newobjlist else: obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython","Scale") - _Scale(obj) - _ViewProviderDraft(obj.ViewObject) + _Clone(obj) + _ViewProviderDraftPart(obj.ViewObject) obj.Objects = objectslist obj.Scale = delta - obj.BasePoint = center + corr = Vector(center.x,center.y,center.z) + corr.scale(delta.x,delta.y,delta.z) + corr = fcvec.neg(corr.sub(center)) + p = obj.Placement + p.move(corr) + obj.Placement = p if not copy: for o in objectslist: o.ViewObject.hide() @@ -1318,6 +1322,21 @@ def makePoint(X=0, Y=0, Z=0,color=(0,1,0),name = "Point", point_size= 5): obj.ViewObject.Visibility = True FreeCAD.ActiveDocument.recompute() return obj + +def clone(obj,delta=None): + '''clone(obj,[delta]): makes a clone of the given object(s). The clone is an exact, + linked copy of the given object. If the original object changes, the final object + changes too. Optionally, you can give a delta Vector to move the clone from the + original position.''' + if not isinstance(obj,list): + obj = [obj] + cl = FreeCAD.ActiveDocument.addObject("Part::FeaturePython","Clone") + _Clone(cl) + _ViewProviderDraftPart(cl.ViewObject) + cl.Objects = obj + if delta: + cl.Placement.move(delta) + return cl #--------------------------------------------------------------------------- # Python Features definitions @@ -1371,6 +1390,8 @@ class _ViewProviderDraft: objs.append(self.Object.Base) if hasattr(self.Object,"Objects"): objs.extend(self.Object.Objects) + if hasattr(self.Object,"Components"): + objs.extend(self.Object.Components) return objs class _Dimension: @@ -2263,14 +2284,6 @@ class _Block: fp.Shape = shape fp.Placement = plm -class _ViewProviderBlock(_ViewProviderDraft): - "A View Provider for the Block object" - def __init__(self,obj): - _ViewProviderDraft.__init__(self,obj) - - def claimChildren(self): - return self.Object.Components - class _Shape2DView: "The Shape2DView object" @@ -2310,6 +2323,8 @@ class _Array: "The base object that must be duplicated") obj.addProperty("App::PropertyEnumeration","ArrayType","Base", "The type of array to create") + obj.addProperty("App::PropertyVector","Axis","Base", + "The axis direction for polar arrays") obj.addProperty("App::PropertyInteger","NumberX","Base", "Number of copies in X direction (ortho arrays)") obj.addProperty("App::PropertyInteger","NumberY","Base", @@ -2333,6 +2348,7 @@ class _Array: obj.IntervalX = Vector(1,0,0) obj.IntervalY = Vector(0,1,0) obj.Angle = 360 + obj.Axis = Vector(0,0,1) def execute(self,obj): self.createGeometry(obj) @@ -2348,7 +2364,7 @@ class _Array: if obj.ArrayType == "ortho": sh = self.rectArray(obj.Base.Shape,obj.IntervalX,obj.IntervalY,obj.NumberX,obj.NumberY) else: - sh = self.polarArray(obj.Base.Shape,obj.Center,obj.Angle,obj.NumberPolar) + sh = self.polarArray(obj.Base.Shape,obj.Center,obj.Angle,obj.NumberPolar,obj.Axis) obj.Shape = sh if not fcgeo.isNull(pl): obj.Placement = pl @@ -2371,14 +2387,14 @@ class _Array: base.append(nshape) return Part.makeCompound(base) - def polarArray(self,shape,center,angle,num): + def polarArray(self,shape,center,angle,num,axis): import Part fraction = angle/num base = [shape.copy()] for i in range(num): currangle = fraction + (i*fraction) nshape = shape.copy() - nshape.rotate(fcvec.tup(center), (0,0,1), currangle) + nshape.rotate(fcvec.tup(center), fcvec.tup(axis), currangle) base.append(nshape) return Part.makeCompound(base) @@ -2422,25 +2438,23 @@ class _ViewProviderPoint: def getIcon(self): return ":/icons/Draft_Dot.svg" -class _Scale: - "The Scale object" +class _Clone: + "The Clone object" def __init__(self,obj): obj.addProperty("App::PropertyLinkList","Objects","Base", "The objects included in this scale object") obj.addProperty("App::PropertyVector","Scale","Base", "The scale vector of this object") - obj.addProperty("App::PropertyVector","BasePoint","Base", - "The base point of this scale object") obj.Scale = Vector(1,1,1) obj.Proxy = self - self.Type = "Scale" + self.Type = "Clone" def execute(self,obj): self.createGeometry(obj) def onChanged(self,obj,prop): - if prop in ["Scale","BasePoint","Objects"]: + if prop in ["Scale","Objects"]: self.createGeometry(obj) def createGeometry(self,obj): @@ -2449,19 +2463,23 @@ class _Scale: pl = obj.Placement shapes = [] for o in obj.Objects: - if hasattr(o,"Shape"): + if o.isDerivedFrom("Part::Feature"): sh = o.Shape.copy() m = FreeCAD.Matrix() m.scale(obj.Scale) sh = sh.transformGeometry(m) - corr = Vector(obj.BasePoint) - corr.scale(obj.Scale.x,obj.Scale.y,obj.Scale.z) - corr = fcvec.neg(corr.sub(obj.BasePoint)) - sh.translate(corr) shapes.append(sh) if shapes: obj.Shape = Part.makeCompound(shapes) if not fcgeo.isNull(pl): obj.Placement = pl +class _ViewProviderDraftPart(_ViewProviderDraft): + "a view provider that displays a Part icon instead of a Draft icon" + + def __init__(self,vobj): + _ViewProviderDraft.__init__(self,vobj) + + def getIcon(self): + return ":/icons/Tree_Part.svg" diff --git a/src/Mod/Draft/DraftSnap.py b/src/Mod/Draft/DraftSnap.py index 7d6e59353..7bd5ce5da 100644 --- a/src/Mod/Draft/DraftSnap.py +++ b/src/Mod/Draft/DraftSnap.py @@ -360,6 +360,8 @@ class Snapper: dv = last.sub(shape.Curve.Center) dv = fcvec.scaleTo(dv,shape.Curve.Radius) np = (shape.Curve.Center).add(dv) + else: + return snaps snaps.append([np,'perpendicular',np]) return snaps diff --git a/src/Mod/Draft/DraftTools.py b/src/Mod/Draft/DraftTools.py old mode 100755 new mode 100644 diff --git a/src/Mod/Draft/InitGui.py b/src/Mod/Draft/InitGui.py index b096c4a50..506904c2a 100644 --- a/src/Mod/Draft/InitGui.py +++ b/src/Mod/Draft/InitGui.py @@ -178,10 +178,10 @@ class DraftWorkbench (Workbench): FreeCADGui.addPreferencePage(":/ui/userprefs-import.ui","Draft") else: return - Log ('Loading Draft GUI...\n') try: import macros,DraftTools,DraftGui self.appendMenu(["&Macro",str(DraftTools.translate("draft","Installed Macros"))],macros.macrosList) + Log ('Loading Draft GUI...done\n') except: pass self.cmdList = ["Draft_Line","Draft_Wire","Draft_Circle","Draft_Arc", @@ -191,7 +191,7 @@ class DraftWorkbench (Workbench): "Draft_Trimex", "Draft_Upgrade", "Draft_Downgrade", "Draft_Scale", "Draft_Drawing","Draft_Edit","Draft_WireToBSpline","Draft_AddPoint", "Draft_DelPoint","Draft_Shape2DView","Draft_Draft2Sketch","Draft_Array"] - self.treecmdList = ["Draft_ApplyStyle","Draft_ToggleDisplayMode","Draft_AddToGroup","Draft_SelectGroup"] + self.treecmdList = ["Draft_ApplyStyle","Draft_ToggleDisplayMode","Draft_AddToGroup","Draft_SelectGroup","Draft_SelectPlane"] self.lineList = ["Draft_UndoLine","Draft_FinishLine","Draft_CloseLine"] self.appendToolbar(str(DraftTools.translate("draft","Draft creation tools")),self.cmdList) self.appendToolbar(str(DraftTools.translate("draft","Draft modification tools")),self.modList) @@ -208,17 +208,17 @@ class DraftWorkbench (Workbench): def ContextMenu(self, recipient): if (recipient == "View"): if (FreeCAD.activeDraftCommand == None): - if (FreeCADGui.Selection.getSelection() != []): - self.appendContextMenu(str(DraftTools.translate("draft","Draft")),self.cmdList+self.modList) - self.appendContextMenu(str(DraftTools.translate("draft","Display options")),self.treecmdList) + if (FreeCADGui.Selection.getSelection()): + self.appendContextMenu("Draft",self.cmdList+self.modList) + self.appendContextMenu("Display options",self.treecmdList) else: - self.appendContextMenu(str(DraftTools.translate("draft","Draft")),self.cmdList) + self.appendContextMenu("Draft",self.cmdList) else: if (FreeCAD.activeDraftCommand.featureName == "Line"): self.appendContextMenu("",self.lineList) else: - if (FreeCADGui.Selection.getSelection() != []): - self.appendContextMenu(str(DraftTools.translate("draft","Display options")),self.treecmdList) + if (FreeCADGui.Selection.getSelection()): + self.appendContextMenu("Display options",self.treecmdList) def GetClassName(self): return "Gui::PythonWorkbench" diff --git a/src/Mod/Draft/importAirfoilDAT.py b/src/Mod/Draft/importAirfoilDAT.py old mode 100755 new mode 100644 diff --git a/src/Mod/Draft/importSVG.py b/src/Mod/Draft/importSVG.py index 6a47fea1f..0590d7701 100644 --- a/src/Mod/Draft/importSVG.py +++ b/src/Mod/Draft/importSVG.py @@ -242,6 +242,7 @@ class svgHandler(xml.sax.ContentHandler): self.grouptransform = [] self.lastdim = None + global Part import Part if gui and draftui: @@ -561,15 +562,15 @@ class svgHandler(xml.sax.ContentHandler): pole2 = lastvec.add(Vector(point[2],-point[3],0)) else: currentvec = Vector(point[4],-point[5],0) - pole1 = Vector(point[0],point[1],0) - pole2 = Vector(point[2],point[3],0) + pole1 = Vector(point[0],-point[1],0) + pole2 = Vector(point[2],-point[3],0) if not fcvec.equals(currentvec,lastvec): mainv = currentvec.sub(lastvec) pole1v = lastvec.add(pole1) pole2v = currentvec.add(pole2) print "curve data:",mainv.normalize(),pole1v.normalize(),pole2v.normalize() - if (round(mainv.getAngle(pole1v),4) in [0,round(math.pi,4)]) \ - and (round(mainv.getAngle(pole2v),4) in [0,round(math.pi,4)]): + if (round(mainv.getAngle(pole1v),Draft.precision()) in [0,round(math.pi,Draft.precision())]) \ + and (round(mainv.getAngle(pole2v),Draft.precision()) in [0,round(math.pi,Draft.precision())]): print "straight segment" seg = Part.Line(lastvec,currentvec).toShape() else: diff --git a/src/Mod/Draft/macros.py b/src/Mod/Draft/macros.py old mode 100755 new mode 100644 From 776a083dce1922b186b9d6fe6a43eda04b7f9ecd Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 5 Jan 2012 18:50:56 +0000 Subject: [PATCH 4/6] + support multi-selection when inserting objects to drawing page git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5390 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d --- src/Mod/Drawing/Gui/Command.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Mod/Drawing/Gui/Command.cpp b/src/Mod/Drawing/Gui/Command.cpp index c8a9bf206..b4aa2640f 100644 --- a/src/Mod/Drawing/Gui/Command.cpp +++ b/src/Mod/Drawing/Gui/Command.cpp @@ -249,7 +249,7 @@ CmdDrawingNewView::CmdDrawingNewView() void CmdDrawingNewView::activated(int iMsg) { std::vector shapes = getSelection().getObjectsOfType(Part::Feature::getClassTypeId()); - if (shapes.size() != 1) { + if (shapes.empty()) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), QObject::tr("Select a Part object.")); return; @@ -262,19 +262,19 @@ void CmdDrawingNewView::activated(int iMsg) return; } - std::string FeatName = getUniqueObjectName("View"); std::string PageName = pages.front()->getNameInDocument(); - std::vector Sel = getSelection().getSelection(); - openCommand("Create view"); - doCommand(Doc,"App.activeDocument().addObject('Drawing::FeatureViewPart','%s')",FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.Source = App.activeDocument().%s",FeatName.c_str(),shapes.front()->getNameInDocument()); - doCommand(Doc,"App.activeDocument().%s.Direction = (0.0,0.0,1.0)",FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.X = 10.0",FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.Y = 10.0",FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.Scale = 1.0",FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.addObject(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str()); + for (std::vector::iterator it = shapes.begin(); it != shapes.end(); ++it) { + std::string FeatName = getUniqueObjectName("View"); + doCommand(Doc,"App.activeDocument().addObject('Drawing::FeatureViewPart','%s')",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.Source = App.activeDocument().%s",FeatName.c_str(),(*it)->getNameInDocument()); + doCommand(Doc,"App.activeDocument().%s.Direction = (0.0,0.0,1.0)",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.X = 10.0",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.Y = 10.0",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.Scale = 1.0",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.addObject(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str()); + } updateActive(); commitCommand(); } From 325d832010035ef865d82586088c1c6f62f63f6e Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 5 Jan 2012 18:59:14 +0000 Subject: [PATCH 5/6] + fix overflow problem with string buffer in fuse and common command git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5391 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d --- src/Gui/Command.cpp | 10 ++++++++++ src/Gui/Command.h | 1 + src/Mod/Part/Gui/Command.cpp | 19 +++++++++++-------- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/Gui/Command.cpp b/src/Gui/Command.cpp index 330720b3b..db0bf9890 100644 --- a/src/Gui/Command.cpp +++ b/src/Gui/Command.cpp @@ -424,6 +424,16 @@ void Command::doCommand(DoCmd_Type eType,const char* sCmd,...) free (format); } +/// Run a App level Action +void Command::runCommand(DoCmd_Type eType,const char* sCmd) +{ + if (eType == Gui) + Gui::Application::Instance->macroManager()->addLine(MacroManager::Gui,sCmd); + else + Gui::Application::Instance->macroManager()->addLine(MacroManager::Base,sCmd); + Base::Interpreter().runString(sCmd); +} + void Command::copyVisual(const char* to, const char* attr, const char* from) { doCommand(Gui,"Gui.ActiveDocument.%s.%s=Gui.ActiveDocument.%s.%s", to, attr, from, attr); diff --git a/src/Gui/Command.h b/src/Gui/Command.h index 789c6e7c9..5cd3c3c54 100644 --- a/src/Gui/Command.h +++ b/src/Gui/Command.h @@ -234,6 +234,7 @@ public: static void blockCommand(bool); /// Run a App level Action static void doCommand(DoCmd_Type eType,const char* sCmd,...); + static void runCommand(DoCmd_Type eType,const char* sCmd); static void copyVisual(const char* to, const char* attr, const char* from); static void copyVisual(const char* to, const char* attr_to, const char* from, const char* attr_from); /// import an external module only once diff --git a/src/Mod/Part/Gui/Command.cpp b/src/Mod/Part/Gui/Command.cpp index f4288f997..fdcfefc89 100644 --- a/src/Mod/Part/Gui/Command.cpp +++ b/src/Mod/Part/Gui/Command.cpp @@ -23,6 +23,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ +# include # include # include # include @@ -295,17 +296,18 @@ void CmdPartCommon::activated(int iMsg) std::string FeatName = getUniqueObjectName("Common"); std::vector Sel = getSelection().getSelection(); - std::string ObjectBuf; + std::stringstream str; std::vector tempSelNames; + str << "App.activeDocument()." << FeatName << ".Shapes = ["; for (std::vector::iterator it = Sel.begin(); it != Sel.end(); ++it){ - ObjectBuf += std::string("App.activeDocument().") + it->FeatName + ","; + str << "App.activeDocument()." << it->FeatName << ","; tempSelNames.push_back(it->FeatName); } - ObjectBuf.erase(--ObjectBuf.end()); + str << "]"; openCommand("Common"); doCommand(Doc,"App.activeDocument().addObject(\"Part::MultiCommon\",\"%s\")",FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.Shapes = [%s]",FeatName.c_str(),ObjectBuf.c_str()); + runCommand(Doc,str.str().c_str()); for (std::vector::iterator it = tempSelNames.begin(); it != tempSelNames.end(); ++it) doCommand(Gui,"Gui.activeDocument().%s.Visibility=False",it->c_str()); copyVisual(FeatName.c_str(), "ShapeColor", tempSelNames.front().c_str()); @@ -348,17 +350,18 @@ void CmdPartFuse::activated(int iMsg) std::string FeatName = getUniqueObjectName("Fusion"); std::vector Sel = getSelection().getSelection(); - std::string ObjectBuf; + std::stringstream str; std::vector tempSelNames; + str << "App.activeDocument()." << FeatName << ".Shapes = ["; for (std::vector::iterator it = Sel.begin(); it != Sel.end(); ++it){ - ObjectBuf += std::string("App.activeDocument().") + it->FeatName + ","; + str << "App.activeDocument()." << it->FeatName << ","; tempSelNames.push_back(it->FeatName); } - ObjectBuf.erase(--ObjectBuf.end()); + str << "]"; openCommand("Fusion"); doCommand(Doc,"App.activeDocument().addObject(\"Part::MultiFuse\",\"%s\")",FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.Shapes = [%s]",FeatName.c_str(),ObjectBuf.c_str()); + runCommand(Doc,str.str().c_str()); for (std::vector::iterator it = tempSelNames.begin(); it != tempSelNames.end(); ++it) doCommand(Gui,"Gui.activeDocument().%s.Visibility=False",it->c_str()); copyVisual(FeatName.c_str(), "ShapeColor", tempSelNames.front().c_str()); From d238b77dae3d35781e60b61530e7d1d2578aa1bf Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 7 Jan 2012 14:52:41 +0000 Subject: [PATCH 6/6] + use "ActivationHistoryOrder" for MDI windows git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5392 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d --- src/Gui/MainWindow.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Gui/MainWindow.cpp b/src/Gui/MainWindow.cpp index 09f13d19b..6b34086d5 100644 --- a/src/Gui/MainWindow.cpp +++ b/src/Gui/MainWindow.cpp @@ -282,6 +282,7 @@ MainWindow::MainWindow(QWidget * parent, Qt::WFlags f) d->mdiArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); d->mdiArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); d->mdiArea->setOption(QMdiArea::DontMaximizeSubWindowOnActivation, false); + d->mdiArea->setActivationOrder(QMdiArea::ActivationHistoryOrder); QPixmap backgnd((const char**) background); d->mdiArea->setBackground(backgnd); setCentralWidget(d->mdiArea);