Core: Gui: SoFCSysDragger: adding SoFCSysDragger.

This commit is contained in:
blobfish 2015-08-09 11:46:40 -04:00 committed by wmayer
parent 381a59bb36
commit 729c116081
5 changed files with 1604 additions and 0 deletions

View File

@ -204,6 +204,7 @@ set(Gui_MOC_HDRS
DlgToolbarsImp.h
DlgWorkbenchesImp.h
TaskDlgRelocation.h
TaskCSysDragger.h
DlgUndoRedo.h
DockWindow.h
DockWindowManager.h
@ -382,6 +383,7 @@ SET(Dialog_CPP_SRCS
DlgExpressionInput.cpp
TaskDlgRelocation.cpp
DlgCheckableMessageBox.cpp
TaskCSysDragger.cpp
DlgUndoRedo.cpp
InputVector.cpp
Placement.cpp
@ -415,6 +417,7 @@ SET(Dialog_HPP_SRCS
DlgTipOfTheDayImp.h
DlgExpressionInput.h
TaskDlgRelocation.h
TaskCSysDragger.h
DlgUndoRedo.h
InputVector.h
Placement.h
@ -890,6 +893,7 @@ SET(Inventor_CPP_SRCS
SoAxisCrossKit.cpp
SoTextLabel.cpp
SoTouchEvents.cpp
SoFCCSysDragger.cpp
)
SET(Inventor_SRCS
${Inventor_CPP_SRCS}
@ -913,6 +917,7 @@ SET(Inventor_SRCS
SoAxisCrossKit.h
SoTextLabel.h
SoTouchEvents.h
SoFCCSysDragger.h
)
SOURCE_GROUP("View3D\\Inventor" FILES ${Inventor_SRCS})

1131
src/Gui/SoFCCSysDragger.cpp Normal file

File diff suppressed because it is too large Load Diff

264
src/Gui/SoFCCSysDragger.h Normal file
View File

@ -0,0 +1,264 @@
/***************************************************************************
* Copyright (c) 2015 Thomas Anderson <blobfish[at]gmx.com> *
* *
* 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 CSYSDRAGGER_H
#define CSYSDRAGGER_H
#include <Inventor/draggers/SoDragger.h>
#include <Inventor/fields/SoSFColor.h>
#include <Inventor/fields/SoSFDouble.h>
#include <Inventor/fields/SoSFFloat.h>
#include <Inventor/fields/SoSFInt32.h>
#include <Inventor/fields/SoSFRotation.h>
#include <Inventor/projectors/SbLineProjector.h>
#include <Inventor/projectors/SbPlaneProjector.h>
#include <Inventor/sensors/SoFieldSensor.h>
#include <Inventor/sensors/SoIdleSensor.h>
class SoCamera;
namespace Gui
{
/*! @brief Translation Dragger.
*
* used for translating along axis. Set the
* translationIncrement to desired step. Use
* 'translationIncrementCount' multiplied with
* 'translationIncrement' for a full double
* precision vector scalar.
*/
class TDragger : public SoDragger
{
SO_KIT_HEADER(TDragger);
SO_KIT_CATALOG_ENTRY_HEADER(translatorSwitch);
SO_KIT_CATALOG_ENTRY_HEADER(translator);
SO_KIT_CATALOG_ENTRY_HEADER(translatorActive);
public:
static void initClass();
TDragger();
SoSFVec3f translation; //!< set from outside and used from outside for single precision.
SoSFDouble translationIncrement; //!< set from outside and used for rounding.
SoSFInt32 translationIncrementCount; //!< number of steps. used from outside.
SoSFFloat autoScaleResult; //!< set from parent dragger.
protected:
virtual ~TDragger() override;
virtual SbBool setUpConnections(SbBool onoff, SbBool doitalways = FALSE) override;
static void startCB(void *, SoDragger * d);
static void motionCB(void *, SoDragger * d);
static void finishCB(void *, SoDragger * d);
static void fieldSensorCB(void *f, SoSensor *);
static void valueChangedCB(void *, SoDragger *d);
void dragStart();
void drag();
void dragFinish();
SoFieldSensor fieldSensor;
SbLineProjector projector;
private:
void buildFirstInstance();
SbVec3f roundTranslation(const SbVec3f &vecIn, float incrementIn);
SoGroup* buildGeometry();
typedef SoDragger inherited;
};
/*! @brief Rotation Dragger.
*
* used for rotating around an axis. Set the rotation
* increment to desired step. Use rotationIncrementCount
* multiplied with rotationIncrement for full double
* precision vector scalar.
*/
class RDragger : public SoDragger
{
SO_KIT_HEADER(RDragger);
SO_KIT_CATALOG_ENTRY_HEADER(rotatorSwitch);
SO_KIT_CATALOG_ENTRY_HEADER(rotator);
SO_KIT_CATALOG_ENTRY_HEADER(rotatorActive);
public:
static void initClass();
RDragger();
SoSFRotation rotation; //!< set from outside and used from outside for single precision.
SoSFDouble rotationIncrement; //!< set from outside and used for rounding.
SoSFInt32 rotationIncrementCount; //!< number of steps. used from outside.
SoSFColor color; //!< set from outside. non-active color.
protected:
virtual ~RDragger() override;
virtual SbBool setUpConnections(SbBool onoff, SbBool doitalways = FALSE) override;
static void startCB(void *, SoDragger * d);
static void motionCB(void *, SoDragger * d);
static void finishCB(void *, SoDragger * d);
static void fieldSensorCB(void *f, SoSensor *);
static void valueChangedCB(void *, SoDragger *d);
void dragStart();
void drag();
void dragFinish();
SoFieldSensor fieldSensor;
SbPlaneProjector projector;
float arcRadius;
private:
void buildFirstInstance();
int roundIncrement(const float &radiansIn);
SoGroup* buildGeometry();
typedef SoDragger inherited;
};
/*! @brief Coordinate System Dragger
*
* used to transform objects in 3d space. Set intial:
* translation, rotation, translationIncrement and
* rotationIncrement. Use *IncrementCount* multiplied
* with *Increment for full double precision output.
*
* Dragger can be displayed in 2 modes: static scale and auto scale.
* for static you can set the field scale and you are done. For
* auto scale you set the field scale and call setupAutoScale with
* the viewer camera. @see setUpAutoScale @see scale.
*/
class GuiExport SoFCCSysDragger : public SoDragger
{
SO_KIT_HEADER(SoFCCSysDragger);
SO_KIT_CATALOG_ENTRY_HEADER(annotation);
SO_KIT_CATALOG_ENTRY_HEADER(scaleNode);
SO_KIT_CATALOG_ENTRY_HEADER(xTranslatorSwitch);
SO_KIT_CATALOG_ENTRY_HEADER(yTranslatorSwitch);
SO_KIT_CATALOG_ENTRY_HEADER(zTranslatorSwitch);
SO_KIT_CATALOG_ENTRY_HEADER(xTranslatorSeparator);
SO_KIT_CATALOG_ENTRY_HEADER(yTranslatorSeparator);
SO_KIT_CATALOG_ENTRY_HEADER(zTranslatorSeparator);
SO_KIT_CATALOG_ENTRY_HEADER(xTranslatorColor);
SO_KIT_CATALOG_ENTRY_HEADER(yTranslatorColor);
SO_KIT_CATALOG_ENTRY_HEADER(zTranslatorColor);
SO_KIT_CATALOG_ENTRY_HEADER(xTranslatorRotation);
SO_KIT_CATALOG_ENTRY_HEADER(yTranslatorRotation);
SO_KIT_CATALOG_ENTRY_HEADER(zTranslatorRotation);
SO_KIT_CATALOG_ENTRY_HEADER(xTranslatorDragger);
SO_KIT_CATALOG_ENTRY_HEADER(yTranslatorDragger);
SO_KIT_CATALOG_ENTRY_HEADER(zTranslatorDragger);
SO_KIT_CATALOG_ENTRY_HEADER(xRotatorSwitch);
SO_KIT_CATALOG_ENTRY_HEADER(yRotatorSwitch);
SO_KIT_CATALOG_ENTRY_HEADER(zRotatorSwitch);
SO_KIT_CATALOG_ENTRY_HEADER(xRotatorSeparator);
SO_KIT_CATALOG_ENTRY_HEADER(yRotatorSeparator);
SO_KIT_CATALOG_ENTRY_HEADER(zRotatorSeparator);
SO_KIT_CATALOG_ENTRY_HEADER(xRotatorColor);
SO_KIT_CATALOG_ENTRY_HEADER(yRotatorColor);
SO_KIT_CATALOG_ENTRY_HEADER(zRotatorColor);
SO_KIT_CATALOG_ENTRY_HEADER(xRotatorRotation);
SO_KIT_CATALOG_ENTRY_HEADER(yRotatorRotation);
SO_KIT_CATALOG_ENTRY_HEADER(zRotatorRotation);
SO_KIT_CATALOG_ENTRY_HEADER(xRotatorDragger);
SO_KIT_CATALOG_ENTRY_HEADER(yRotatorDragger);
SO_KIT_CATALOG_ENTRY_HEADER(zRotatorDragger);
public:
static void initClass();
SoFCCSysDragger();
~SoFCCSysDragger();
SoSFVec3f translation; //!< initial translation and reflects single precision movement.
SoSFDouble translationIncrement; //!< set from outside used for rounding.
SoSFInt32 translationIncrementCountX; //!< used from outside for translation x steps.
SoSFInt32 translationIncrementCountY; //!< used from outside for translation y steps.
SoSFInt32 translationIncrementCountZ; //!< used from outside for translation z steps.
SoSFRotation rotation; //!< initial rotation and reflects single precision movement.
SoSFDouble rotationIncrement; //!< radians set from outside and used for rounding.
SoSFInt32 rotationIncrementCountX; //!< used from outside for rotation x steps.
SoSFInt32 rotationIncrementCountY; //!< used from outside for rotation y steps.
SoSFInt32 rotationIncrementCountZ; //!< used from outside for rotation z steps.
void clearIncrementCounts(); //!< used to reset after drag update.
/*! @brief Overall scale of dragger node.
*
* When using autoscale mode, this represents normalized device coordinates (0.0 to 1.0). A value
* of 0.05 is a good place to start. When NOT using autoscale mode, scale represents
* a traditional scale and a value of 1.0 is a good place to start.
*/
SoSFFloat draggerSize;
SoSFFloat autoScaleResult; //!< result of autoscale calculation and used by childdraggers. Don't use.
SoIdleSensor idleSensor; //!< might be overkill, but want to make sure of performance.
void setUpAutoScale(SoCamera *cameraIn); //!< used to setup the auto scaling of dragger.
SoCamera *camera = nullptr; //!< don't assign directly! use setUpAutoScale.
//! @name Visibility Functions
//@{
void showTranslationX(); //!< show the x translation dragger.
void showTranslationY(); //!< show the y translation dragger.
void showTranslationZ(); //!< show the z translation dragger.
void hideTranslationX(); //!< hide the x translation dragger.
void hideTranslationY(); //!< hide the y translation dragger.
void hideTranslationZ(); //!< hide the z translation dragger.
void showRotationX(); //!< show the x rotation dragger.
void showRotationY(); //!< show the y rotation dragger.
void showRotationZ(); //!< show the z rotation dragger.
void hideRotationX(); //!< hide the x rotation dragger.
void hideRotationY(); //!< hide the y rotation dragger.
void hideRotationZ(); //!< hide the z rotation dragger.
bool isShownTranslationX(); //!< is x translation dragger shown.
bool isShownTranslationY(); //!< is y translation dragger shown.
bool isShownTranslationZ(); //!< is z translation dragger shown.
bool isShownRotationX(); //!< is x rotation dragger shown.
bool isShownRotationY(); //!< is x rotation dragger shown.
bool isShownRotationZ(); //!< is x rotation dragger shown.
bool isHiddenTranslationX(); //!< is x translation dragger hidden.
bool isHiddenTranslationY(); //!< is y translation dragger hidden.
bool isHiddenTranslationZ(); //!< is z translation dragger hidden.
bool isHiddenRotationX(); //!< is x rotation dragger hidden.
bool isHiddenRotationY(); //!< is x rotation dragger hidden.
bool isHiddenRotationZ(); //!< is x rotation dragger hidden.
//@}
protected:
virtual SbBool setUpConnections(SbBool onoff, SbBool doitalways = FALSE) override;
static void translationSensorCB(void *f, SoSensor *);
static void rotationSensorCB(void *f, SoSensor *);
static void valueChangedCB(void *, SoDragger *d);
static void cameraCB(void *data, SoSensor *);
static void idleCB(void *data, SoSensor *); //!< scheduled from cameraCB to auto scale dragger.
static void finishDragCB(void *data, SoDragger *);
SoFieldSensor translationSensor;
SoFieldSensor rotationSensor;
SoFieldSensor cameraSensor;
private:
typedef SoDragger inherited;
};
}
#endif // CSYSDRAGGER_H

147
src/Gui/TaskCSysDragger.cpp Normal file
View File

@ -0,0 +1,147 @@
/***************************************************************************
* Copyright (c) 2015 Thomas Anderson <blobfish[at]gmx.com> *
* *
* 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 <assert.h>
#include <limits>
#include <QApplication>
#endif
#include <QGridLayout>
#include <QFontMetrics>
#include <TaskView/TaskView.h>
#include "QuantitySpinBox.h"
#include <Gui/Application.h>
#include <Gui/Document.h>
#include <BitmapFactory.h>
#include <ViewProviderGeometryObject.h>
#include <SoFCCSysDragger.h>
#include "TaskCSysDragger.h"
using namespace Gui;
static double radiansToDegrees(const double &radiansIn)
{
return radiansIn * (180.0 / M_PI);
}
static double degreesToRadains(const double &degreesIn)
{
return degreesIn * (M_PI / 180.0);
}
static double lastTranslationIncrement = 1.0;
static double lastRotationIncrement = degreesToRadains(15.0);
TaskCSysDragger::TaskCSysDragger(Gui::ViewProviderGeometryObject* vpObjectIn, Gui::SoFCCSysDragger* draggerIn) :
vpObject(vpObjectIn), dragger(draggerIn)
{
assert(vpObject);
assert(dragger);
setupGui();
}
TaskCSysDragger::~TaskCSysDragger()
{
}
void TaskCSysDragger::setupGui()
{
Gui::TaskView::TaskBox *incrementsBox = new Gui::TaskView::TaskBox(
Gui::BitmapFactory().pixmap("button_valid"),
tr("Increments"), true, 0);
QGridLayout *gridLayout = new QGridLayout();
gridLayout->setColumnStretch(1, 1);
QLabel *tLabel = new QLabel(tr("Translation Increment: "), incrementsBox);
gridLayout->addWidget(tLabel, 0, 0, Qt::AlignRight);
int spinBoxWidth = QApplication::fontMetrics().averageCharWidth() * 20;
tSpinBox = new QuantitySpinBox(incrementsBox);
tSpinBox->setMinimum(0.0);
tSpinBox->setMaximum(std::numeric_limits<double>::max());
tSpinBox->setUnit(Base::Unit::Length);
tSpinBox->setMinimumWidth(spinBoxWidth);
gridLayout->addWidget(tSpinBox, 0, 1, Qt::AlignLeft);
QLabel *rLabel = new QLabel(tr("Rotation Increment: "), incrementsBox);
gridLayout->addWidget(rLabel, 1, 0, Qt::AlignRight);
rSpinBox = new QuantitySpinBox(incrementsBox);
rSpinBox->setMinimum(0.0);
rSpinBox->setMaximum(180.0);
rSpinBox->setUnit(Base::Unit::Angle);
rSpinBox->setMinimumWidth(spinBoxWidth);
gridLayout->addWidget(rSpinBox, 1, 1, Qt::AlignLeft);
incrementsBox->groupLayout()->addLayout(gridLayout);
Content.push_back(incrementsBox);
connect(tSpinBox, SIGNAL(valueChanged(double)), this, SLOT(onTIncrementSlot(double)));
connect(rSpinBox, SIGNAL(valueChanged(double)), this, SLOT(onRIncrementSlot(double)));
}
void TaskCSysDragger::onTIncrementSlot(double freshValue)
{
dragger->translationIncrement.setValue(freshValue);
}
void TaskCSysDragger::onRIncrementSlot(double freshValue)
{
dragger->rotationIncrement.setValue(degreesToRadains(freshValue));
}
void TaskCSysDragger::open()
{
// dragger->translationIncrement.setValue(lastTranslationIncrement);
// dragger->rotationIncrement.setValue(lastRotationIncrement);
tSpinBox->setValue(lastTranslationIncrement);
rSpinBox->setValue(radiansToDegrees(lastRotationIncrement));
Gui::TaskView::TaskDialog::open();
}
bool TaskCSysDragger::accept()
{
lastTranslationIncrement = dragger->translationIncrement.getValue();
lastRotationIncrement = dragger->rotationIncrement.getValue();
assert(vpObject);
App::DocumentObject* dObject = vpObject->getObject();
assert(dObject);
Gui::Document* document = Gui::Application::Instance->getDocument(dObject->getDocument());
assert(document);
document->commitCommand();
document->resetEdit();
document->getDocument()->recompute();
return Gui::TaskView::TaskDialog::accept();
}
#include "moc_TaskCSysDragger.cpp"

57
src/Gui/TaskCSysDragger.h Normal file
View File

@ -0,0 +1,57 @@
/***************************************************************************
* Copyright (c) 2015 Thomas Anderson <blobfish[at]gmx.com> *
* *
* 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 TASKCSYSDRAGGER_H
#define TASKCSYSDRAGGER_H
#include <Gui/TaskView/TaskDialog.h>
class QuantitySpinBox;
namespace Gui
{
class SoFCCSysDragger;
class ViewProviderGeometryObject;
class TaskCSysDragger : public Gui::TaskView::TaskDialog
{
Q_OBJECT
public:
TaskCSysDragger(ViewProviderGeometryObject *vpObjectIn, SoFCCSysDragger *draggerIn);
virtual ~TaskCSysDragger() override;
virtual QDialogButtonBox::StandardButtons getStandardButtons() const override
{ return QDialogButtonBox::Ok;}
virtual void open() override;
virtual bool accept() override;
private Q_SLOTS:
void onTIncrementSlot(double freshValue);
void onRIncrementSlot(double freshValue);
private:
void setupGui();
ViewProviderGeometryObject *vpObject;
SoFCCSysDragger *dragger;
QuantitySpinBox *tSpinBox;
QuantitySpinBox *rSpinBox;
};
}
#endif // TASKCSYSDRAGGER_H