From 6a7d2dea17ab966d570f2a938ca7ee81ba43a85b Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 2 Oct 2013 14:15:39 +0200 Subject: [PATCH] + Show orientation dialog when creating an image plane --- src/Mod/Image/Gui/CMakeLists.txt | 9 ++ src/Mod/Image/Gui/Command.cpp | 12 ++ src/Mod/Image/Gui/ImageOrientationDialog.cpp | 122 +++++++++++++++ src/Mod/Image/Gui/ImageOrientationDialog.h | 54 +++++++ src/Mod/Image/Gui/ImageOrientationDialog.ui | 150 +++++++++++++++++++ 5 files changed, 347 insertions(+) create mode 100644 src/Mod/Image/Gui/ImageOrientationDialog.cpp create mode 100644 src/Mod/Image/Gui/ImageOrientationDialog.h create mode 100644 src/Mod/Image/Gui/ImageOrientationDialog.ui diff --git a/src/Mod/Image/Gui/CMakeLists.txt b/src/Mod/Image/Gui/CMakeLists.txt index 243b1b58d..cc967ee48 100644 --- a/src/Mod/Image/Gui/CMakeLists.txt +++ b/src/Mod/Image/Gui/CMakeLists.txt @@ -20,6 +20,7 @@ set(ImageGui_LIBS set(ImageGui_MOC_HDRS ImageView.h GLImageBox.h + ImageOrientationDialog.h ) fc_wrap_cpp(ImageGui_MOC_SRCS ${ImageGui_MOC_HDRS}) @@ -32,12 +33,20 @@ SET(ImageGui_RES_SRCS fc_add_resources(ImageGui_QRC_SRCS ${ImageGui_RES_SRCS}) #QT4_ADD_RESOURCES(ImageGui_QRC_SRCS ${ImageGui_RES_SRCS}) +set(ImageGui_UIC_SRCS + ImageOrientationDialog.ui +) +qt4_wrap_ui(ImageGui_UIC_HDRS ${ImageGui_UIC_SRCS}) + SET(ImageGui_SRCS # ${ImageGui_MOC_SRCS} # ${ImageGui_QRC_SRCS} + ${ImageGui_UIC_HDRS} AppImageGui.cpp AppImageGuiPy.cpp Command.cpp + ImageOrientationDialog.cpp + ImageOrientationDialog.h ViewProviderImagePlane.cpp ViewProviderImagePlane.h GLImageBox.cpp diff --git a/src/Mod/Image/Gui/Command.cpp b/src/Mod/Image/Gui/Command.cpp index 78947b6b4..e143792ad 100644 --- a/src/Mod/Image/Gui/Command.cpp +++ b/src/Mod/Image/Gui/Command.cpp @@ -29,6 +29,7 @@ #include #include #include +#include "ImageOrientationDialog.h" //#include @@ -120,6 +121,14 @@ void CmdCreateImagePlane::activated(int iMsg) return; } + // ask user for orientation + ImageOrientationDialog Dlg; + + if (Dlg.exec() != QDialog::Accepted) + return; // canceled + Base::Vector3d p = Dlg.Pos.getPosition(); + Base::Rotation r = Dlg.Pos.getRotation(); + std::string FeatName = getUniqueObjectName("ImagePlane"); openCommand("Create ImagePlane"); @@ -127,6 +136,9 @@ void CmdCreateImagePlane::activated(int iMsg) doCommand(Doc,"App.activeDocument().%s.ImageFile = '%s'",FeatName.c_str(),(const char*)s.toUtf8()); doCommand(Doc,"App.activeDocument().%s.XSize = %d",FeatName.c_str(),impQ.width () ); doCommand(Doc,"App.activeDocument().%s.YSize = %d",FeatName.c_str(),impQ.height() ); + doCommand(Doc,"App.activeDocument().%s.Placement = App.Placement(App.Vector(%f,%f,%f),App.Rotation(%f,%f,%f,%f))" + ,FeatName.c_str(),p.x,p.y,p.z,r[0],r[1],r[2],r[3]); + commitCommand(); } } diff --git a/src/Mod/Image/Gui/ImageOrientationDialog.cpp b/src/Mod/Image/Gui/ImageOrientationDialog.cpp new file mode 100644 index 000000000..f6bfd64dc --- /dev/null +++ b/src/Mod/Image/Gui/ImageOrientationDialog.cpp @@ -0,0 +1,122 @@ +/*************************************************************************** + * Copyright (c) 2013 Werner Mayer * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#include "PreCompiled.h" + +#ifndef _PreComp_ +# include +# include +#endif + +#include +#include +#include + +#include "ui_ImageOrientationDialog.h" +#include "ImageOrientationDialog.h" + +using namespace ImageGui; + +ImageOrientationDialog::ImageOrientationDialog() + : QDialog(Gui::getMainWindow()), ui(new Ui_ImageOrientationDialog) +{ + ui->setupUi(this); + onPreview(); + + connect(ui->Reverse_checkBox, SIGNAL(clicked(bool)), this, SLOT(onPreview())); + connect(ui->XY_radioButton , SIGNAL(clicked(bool)), this, SLOT(onPreview())); + connect(ui->XZ_radioButton , SIGNAL(clicked(bool)), this, SLOT(onPreview())); + connect(ui->YZ_radioButton , SIGNAL(clicked(bool)), this, SLOT(onPreview())); +} + +ImageOrientationDialog::~ImageOrientationDialog() +{ + +} + +void ImageOrientationDialog::accept() +{ + double offset = ui->Offset_doubleSpinBox->value(); + bool reverse = ui->Reverse_checkBox->isChecked(); + if (ui->XY_radioButton->isChecked()) { + if (reverse) { + Pos = Base::Placement(Base::Vector3d(0,0,offset),Base::Rotation(-1.0,0.0,0.0,0.0)); + DirType = 1; + } + else { + Pos = Base::Placement(Base::Vector3d(0,0,offset),Base::Rotation()); + DirType = 0; + } + } + else if (ui->XZ_radioButton->isChecked()) { + if (reverse) { + Pos = Base::Placement(Base::Vector3d(0,offset,0),Base::Rotation(Base::Vector3d(0,sqrt(2.0)/2.0,sqrt(2.0)/2.0),M_PI)); + DirType = 3; + } + else { + Pos = Base::Placement(Base::Vector3d(0,offset,0),Base::Rotation(Base::Vector3d(-1,0,0),1.5*M_PI)); + DirType = 2; + } + } + else if (ui->YZ_radioButton->isChecked()) { + if (reverse) { + Pos = Base::Placement(Base::Vector3d(offset,0,0),Base::Rotation(-0.5,0.5,0.5,-0.5)); + DirType = 5; + } + else { + Pos = Base::Placement(Base::Vector3d(offset,0,0),Base::Rotation(0.5,0.5,0.5,0.5)); + DirType = 4; + } + } + + QDialog::accept(); +} + +void ImageOrientationDialog::onPreview() +{ + std::string icon; + bool reverse = ui->Reverse_checkBox->isChecked(); + if (ui->XY_radioButton->isChecked()) { + if (reverse) + icon = "view-bottom"; + else + icon = "view-top"; + } + else if (ui->XZ_radioButton->isChecked()) { + if (reverse) + icon = "view-rear"; + else + icon = "view-front"; + } + else if (ui->YZ_radioButton->isChecked()) { + if (reverse) + icon = "view-left"; + else + icon = "view-right"; + } + + ui->previewLabel->setPixmap( + Gui::BitmapFactory().pixmapFromSvg(icon.c_str(), + ui->previewLabel->size())); +} + +#include "moc_ImageOrientationDialog.cpp" diff --git a/src/Mod/Image/Gui/ImageOrientationDialog.h b/src/Mod/Image/Gui/ImageOrientationDialog.h new file mode 100644 index 000000000..b295e470f --- /dev/null +++ b/src/Mod/Image/Gui/ImageOrientationDialog.h @@ -0,0 +1,54 @@ +/*************************************************************************** + * Copyright (c) 2013 Werner Mayer * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#ifndef IMAGEGUI_IMAGEORIENTATIONDIALOG_H +#define IMAGEGUI_IMAGEORIENTATIONDIALOG_H + +#include +#include + +namespace ImageGui { + +class Ui_ImageOrientationDialog; +class ImageOrientationDialog : public QDialog +{ + Q_OBJECT + +public: + ImageOrientationDialog(); + ~ImageOrientationDialog(); + + Base::Placement Pos; + int DirType; + + void accept(); + +protected Q_SLOTS: + void onPreview(); + +private: + Ui_ImageOrientationDialog* ui; +}; + +} + +#endif // IMAGEGUI_IMAGEORIENTATIONDIALOG_H diff --git a/src/Mod/Image/Gui/ImageOrientationDialog.ui b/src/Mod/Image/Gui/ImageOrientationDialog.ui new file mode 100644 index 000000000..04d2c5edd --- /dev/null +++ b/src/Mod/Image/Gui/ImageOrientationDialog.ui @@ -0,0 +1,150 @@ + + + ImageGui::ImageOrientationDialog + + + + 0 + 0 + 178 + 201 + + + + Choose orientation + + + + + + Image plane + + + + + + XY-Plane + + + true + + + + + + + XZ-Plane + + + + + + + YZ-Plane + + + + + + + + + + + 48 + 48 + + + + + 48 + 48 + + + + Preview + + + + + + + Reverse direction + + + + + + + + + Offset: + + + + + + + 1 + + + -999999999.000000000000000 + + + 999999999.000000000000000 + + + 10.000000000000000 + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + ImageGui::ImageOrientationDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + ImageGui::ImageOrientationDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + +