EditDatumDialog.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "PreCompiled.h"
00023
00024 #ifndef _PreComp_
00025 # include <Standard_math.hxx>
00027 # include <QApplication>
00028 # include <QDialog>
00029 # include <QMessageBox>
00030 #endif
00031
00032 # include <Inventor/sensors/SoSensor.h>
00033
00034 #include <Base/Tools.h>
00035 #include <Gui/Application.h>
00036 #include <Gui/Command.h>
00037 #include <Gui/Document.h>
00038 #include <Gui/View3DInventor.h>
00039 #include <Gui/View3DInventorViewer.h>
00040 #include <Mod/Sketcher/App/SketchObject.h>
00041
00042 #include "ViewProviderSketch.h"
00043 #include "ui_InsertDatum.h"
00044 #include "EditDatumDialog.h"
00045
00046 using namespace SketcherGui;
00047
00048 EditDatumDialog::EditDatumDialog(ViewProviderSketch* vp, int ConstrNbr) : vp(vp), ConstrNbr(ConstrNbr)
00049 {
00050 const std::vector<Sketcher::Constraint *> &Constraints = vp->getSketchObject()->Constraints.getValues();
00051 Constr = Constraints[ConstrNbr];
00052 }
00053
00054 EditDatumDialog::~EditDatumDialog(){}
00055
00056 void EditDatumDialog::run(void * data, SoSensor * sensor)
00057 {
00058 EditDatumDialog* self = reinterpret_cast<EditDatumDialog*>(data);
00059 self->exec();
00060 delete self;
00061 delete sensor;
00062 }
00063
00064 void EditDatumDialog::exec(bool atCursor)
00065 {
00066
00067 if (Constr->Type == Sketcher::Distance ||
00068 Constr->Type == Sketcher::DistanceX || Constr->Type == Sketcher::DistanceY ||
00069 Constr->Type == Sketcher::Radius || Constr->Type == Sketcher::Angle) {
00070
00071 if (vp->getSketchObject()->hasConflicts()) {
00072 QMessageBox::critical(qApp->activeWindow(), QObject::tr("Distance constraint"),
00073 QObject::tr("Not allowed to edit the datum because the sketch contains conflicting constraints"));
00074 return;
00075 }
00076
00077 double datum = Constr->Value;
00078 if (Constr->Type == Sketcher::Angle)
00079 datum = Base::toDegrees<double>(datum);
00080
00081 Gui::MDIView *mdi = Gui::Application::Instance->activeDocument()->getActiveView();
00082 Gui::View3DInventorViewer *viewer = static_cast<Gui::View3DInventor *>(mdi)->getViewer();
00083
00084 QDialog dlg(viewer->getGLWidget());
00085
00086 Ui::InsertDatum ui_ins_datum;
00087 ui_ins_datum.setupUi(&dlg);
00088
00089 double init_val;
00090 if (Constr->Type == Sketcher::Angle ||
00091 ((Constr->Type == Sketcher::DistanceX || Constr->Type == Sketcher::DistanceY) &&
00092 Constr->FirstPos == Sketcher::none || Constr->Second != Sketcher::Constraint::GeoUndef))
00093
00094 init_val = std::abs(datum);
00095 else
00096 init_val = datum;
00097
00098 ui_ins_datum.lineEdit->setText(QLocale::system().toString(init_val,'g',6));
00099 ui_ins_datum.lineEdit->selectAll();
00100
00101 if (atCursor)
00102 dlg.setGeometry(QCursor::pos().x() - dlg.geometry().width() / 2, QCursor::pos().y(), dlg.geometry().width(), dlg.geometry().height());
00103
00104 if (dlg.exec()) {
00105 bool ok;
00106 double newDatum = ui_ins_datum.lineEdit->text().toDouble(&ok);
00107 if (ok) {
00108 if (Constr->Type == Sketcher::Angle)
00109 newDatum = Base::toRadians<double>(newDatum);
00110
00111 if (Constr->Type == Sketcher::Angle ||
00112 ((Constr->Type == Sketcher::DistanceX || Constr->Type == Sketcher::DistanceY) &&
00113 Constr->FirstPos == Sketcher::none || Constr->Second != Sketcher::Constraint::GeoUndef)) {
00114
00115 if (newDatum >= 0)
00116 newDatum = ((datum >= 0) ? 1 : -1) * std::abs(newDatum);
00117 else
00118 newDatum = ((datum >= 0) ? -1 : 1) * std::abs(newDatum);
00119 }
00120
00121 try {
00122 Gui::Command::openCommand("Modify sketch constraints");
00123 Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.setDatum(%i,%f)",
00124 vp->getObject()->getNameInDocument(),
00125 ConstrNbr, newDatum);
00126 Gui::Command::commitCommand();
00127 }
00128 catch (const Base::Exception& e) {
00129 QMessageBox::critical(qApp->activeWindow(), QObject::tr("Dimensional constraint"), QString::fromUtf8(e.what()));
00130 Gui::Command::abortCommand();
00131 }
00132 }
00133 }
00134 }
00135 }