Refer to Manipulator Example
ManipulatorApplication.hxx
#ifndef __ManipulatorApplication_HeaderFile
#define __ManipulatorApplication_HeaderFile
#include "../baseviewer/BaseViewerApplication.hxx"
#include <cadex/ModelPrs_ManipulatorObserver.hxx>
#include <cadex/ModelPrs_ManipulatorMode.hxx>
#include <cadex/ModelPrs_SelectionChangesObserver.hxx>
class ModelPrs_Selection;
class ModelPrs_SceneNode;
}
class ManipulatorApplication;
{
public:
SelectionChangesObserver (ManipulatorApplication& theApplication);
private:
ManipulatorApplication& myApplication;
};
{
public:
ManipulatorObserver (ManipulatorApplication& theApplication);
double theValue) override;
private:
ManipulatorApplication& myApplication;
};
class ManipulatorApplication : public BaseViewerApplication
{
Q_OBJECT
public:
ManipulatorApplication();
void OnAttachedChanged (bool theValue);
void OnTransformationChanged (double theValue);
void OnTransformationModeChanged (cadex::ModelPrs_ManipulatorMode theMode);
void OnTransformationActiveChanged (bool theValue);
public slots:
void onInitialized();
void onResetTransformation();
void onManipulatorModeChanged (const QVariant& theMode);
protected:
void Clear() override;
protected:
ManipulatorObserver myManipulatorObserver;
SelectionChangesObserver mySelectionObserver;
};
#endif
Defines a 3D direction.
Definition: ModelData_Direction.hxx:180
Base abstract class for observers registered in ModelPrs_Manipulator.
Definition: ModelPrs_ManipulatorObserver.hxx:33
virtual void StartTransformation()=0
A callback is invoked when a manipulator controller is pressed down by the mouse button....
virtual void ModeChanged(ModelPrs_ManipulatorMode theMode, const ModelData_Direction &theDirection)=0
A callback is invoked when the manipulator has changed mode or the direction of translation/direction...
virtual void StopTransformation()=0
A callback is invoked when a manipulator controller is released. Before that, the manipulator updates...
virtual void Transformed(const ModelData_Transformation &theLocalTrsf, const ModelData_Transformation &theGlobalTrsf, double theValue)=0
A callback is invoked when the manipulator makes transformations to the graphic presentation of scene...
Represents a node in the visual scene graph.
Definition: ModelPrs_SceneNode.hxx:44
Defines an observer on selection events.
Definition: ModelPrs_SelectionChangesObserver.hxx:30
virtual void SelectionChangedByManager(const ModelPrs_Selection &theCurrent, const ModelPrs_Selection &theSelected, const ModelPrs_Selection &theDeselected)=0
The method is invoked when the source of the selection event is the manager's method call.
virtual void SelectionChangedByScene(const ModelPrs_Selection &theCurrent, const ModelPrs_Selection &theSelected, const ModelPrs_Selection &theDeselected)=0
The method is invoked when the source of the selection event is mouse click on the scene.
Encapsulates a container of selected scene nodes.
Definition: ModelPrs_Selection.hxx:41
Defines classes, types, and global functions related to CAD Exchanger.
Definition: A3DSTestLib.hxx:22
ManipulatorApplication.cxx
#include "ManipulatorApplication.hxx"
#include <cadex/ModelPrsQtQuick_ViewPort.hxx>
#include <cadex/ModelPrs_Manipulator.hxx>
#include <cadex/ModelPrs_SceneNode.hxx>
#include <cadex/ModelPrs_Selection.hxx>
#include <cadex/ModelPrs_SelectionVisitor.hxx>
#include <cadex/ModelPrs_SelectionManager.hxx>
#include <QtQuick/QQuickWindow>
namespace {
{
public:
{
mySceneNode = theNode;
}
{
}
};
}
SelectionChangesObserver::SelectionChangesObserver (ManipulatorApplication& theApplication)
: myApplication (theApplication)
{
}
{
mySceneNode.Nullify();
} else {
SelectionVisitor aVisitor;
mySceneNode = aVisitor.mySceneNode;
}
myApplication.OnSelectionChanged (mySceneNode);
}
ManipulatorObserver::ManipulatorObserver (ManipulatorApplication& theApplication)
: myApplication (theApplication)
{
}
void ManipulatorObserver::StartTransformation()
{
myApplication.OnTransformationActiveChanged (true);
myApplication.OnTransformationChanged (0.);
}
void ManipulatorObserver::ModeChanged (ModelPrs_ManipulatorMode theMode,
const ModelData_Direction& )
{
myApplication.OnTransformationModeChanged (theMode);
}
void ManipulatorObserver::StopTransformation()
{
myApplication.OnTransformationActiveChanged (false);
}
double theValue)
{
myApplication.OnTransformationChanged (theValue);
}
ManipulatorApplication::ManipulatorApplication()
: myManipulatorObserver (*this),
mySelectionObserver (*this)
{
myScene.SelectionManager().Register (mySelectionObserver);
myRoot.SetSelectionMode (ModelPrs_SM_Node);
connect (this, &BaseViewerApplication::initialized, this, &ManipulatorApplication::onInitialized);
}
{
if (theNode) {
myViewPort->Manipulator().AttachTo (theNode);
} else {
myViewPort->Manipulator().Detach();
}
OnAttachedChanged (!theNode.
IsNull());
}
void ManipulatorApplication::onResetTransformation()
{
myViewPort->Manipulator().ResetTransformation();
}
void ManipulatorApplication::onManipulatorModeChanged (const QVariant& theMode)
{
auto aMode = theMode.toInt();
auto aManipulatorMode = static_cast<ModelPrs_ManipulatorMode> (aMode);
myViewPort->Manipulator().SetMode (aManipulatorMode);
}
void ManipulatorApplication::onInitialized()
{
connect (myMainWindow, SIGNAL (resetTransformation()),
this, SLOT (onResetTransformation()));
connect (myMainWindow, SIGNAL (manipulatorModeChanged (const QVariant&)),
this, SLOT (onManipulatorModeChanged (const QVariant&)));
myViewPort->Manipulator().Register (myManipulatorObserver);
}
void ManipulatorApplication::OnTransformationModeChanged (cadex::ModelPrs_ManipulatorMode theMode)
{
if (theMode != ModelPrs_MM_None) {
myMainWindow->setProperty ("transformationType", theMode);
}
}
void ManipulatorApplication::OnTransformationChanged (double theValue)
{
myMainWindow->setProperty ("transformationValue", theValue);
}
void ManipulatorApplication::OnTransformationActiveChanged (bool theValue)
{
myMainWindow->setProperty ("transformationActive", theValue);
}
void ManipulatorApplication::OnAttachedChanged (bool theValue)
{
myMainWindow->setProperty ("isAttached", theValue);
if (!theValue) {
myMainWindow->setProperty ("transformationType", ModelPrs_MM_None);
}
}
void ManipulatorApplication::Clear()
{
myViewPort->Manipulator().Detach();
OnAttachedChanged (false);
OnTransformationActiveChanged (false);
BaseViewerApplication::Clear();
}
bool IsNull() const
Returns true if the object is nullified.
Definition: Base_PublicObject.cxx:46
Defines a list of shapes.
Definition: ModelData_ShapeList.hxx:32
void Accept(ModelPrs_SelectionVisitor &theVisitor) const
Accepts a visitor.
Definition: ModelPrs_Selection.cxx:235
Defines a visitor of the selection object.
Definition: ModelPrs_SelectionVisitor.hxx:34
ManipulatorWindow.qml
import QtQuick 2.12
import QtQuick.Controls 2.3
import CadEx 1.2
BaseViewerWindow {
id: root
property int transformationType: 0
property int transformationValue: 0
property bool transformationActive: false
property bool isAttached: false
signal resetTransformation()
signal manipulatorModeChanged (var theMode)
onTransformationActiveChanged: {
if (!transformationActive && transformationType == 0) {
transformationValue = 0
}
}
onTransformationTypeChanged: {
transformationValue = 0
}
enum ManipulatorModes {
None = 0x00,
Translation = 0x01,
Rotation = 0x02
}
Menu {
id: manipulatorModeMenu
title: qsTr("&Manipulator mode")
property var manipulatorModeMask: ManipulatorWindow.ManipulatorModes.Translation
| ManipulatorWindow.ManipulatorModes.Rotation
onManipulatorModeMaskChanged: {
manipulatorModeChanged (manipulatorModeMask);
}
function updateMask (theMode, checked)
{
manipulatorModeMask = checked ? manipulatorModeMask | theMode
: manipulatorModeMask & ~theMode;
}
MenuItem {
text: qsTr("&Translation")
checkable: true
checked: true
onCheckedChanged: {
manipulatorModeMenu.updateMask (ManipulatorWindow.ManipulatorModes.Translation, checked);
}
}
MenuItem {
text: qsTr("&Rotation")
checkable: true
checked: true
onCheckedChanged: {
manipulatorModeMenu.updateMask (ManipulatorWindow.ManipulatorModes.Rotation, checked)
}
}
}
onMenuCompleted: {
menuBarItem.addMenu (manipulatorModeMenu);
}
Rectangle {
id: transformationBar
radius: 3
width: 300
height: 200
anchors.margins: 10
anchors.top: parent.top
anchors.right: parent.right
color: "#CCFFFFFF"
border.color: "#55000000"
readonly property string textColor: "#BB000000"
Column {
padding: 20
spacing: 20
width: parent.width
Text {
width: parent.width - 40
horizontalAlignment: Text.AlignHCenter
font.pointSize: 14
font.bold: true
color: transformationBar.textColor
text: qsTr ("Transformation")
}
Text {
width: parent.width - 40
visible: !isAttached || (isAttached && transformationType == 0)
text: !isAttached ? qsTr ("Please select any part") : qsTr ("Transform or rotate")
font.pointSize: 13
font.italic: true
color: transformationBar.textColor
horizontalAlignment: Text.AlignHCenter
}
Text {
visible: isAttached && transformationType !=0
text: qsTr ("Type: ") + (transformationType == 1 ? qsTr ("Translation") : qsTr ("Rotation"))
font.pointSize: 13
color: transformationBar.textColor
}
Text {
visible: isAttached && transformationType !=0
text: qsTr ("Result: ") + transformationValue
font.pointSize: 13
color: transformationBar.textColor
}
Button {
width: parent.width - 40
anchors.horizontalCenter: parent.horizontalCenter
visible: isAttached && transformationType !=0
enabled: !transformationActive
text: qsTr ("Reset transformation")
onClicked: {
resetTransformation();
}
}
}
}
}
main.cxx
#include "ManipulatorApplication.hxx"
#include <cadex/LicenseManager_Activate.h>
#include <QtCore/QUrl>
#include <QtWidgets/QApplication>
#include "../../../cadex_license.cxx"
int main (int argc, char *argv[])
{
auto aKey = LicenseKey::Value();
if (!CADExLicense_Activate (aKey)) {
qCritical ("Failed to activate CAD Exchanger license.");
return 1;
}
QCoreApplication::setAttribute (Qt::AA_EnableHighDpiScaling);
QApplication app (argc, argv);
ManipulatorApplication anApp;
if (anApp.Initialize (QUrl ("qrc:/qml/ManipulatorWindow.qml"), "viewPort")) {
return app.exec();
}
return 0;
}