Commit 26336943 authored by Jan Möbius's avatar Jan Möbius

Move Plugin ask if common cog should be used when moving objects

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@6763 383ad7c9-94d9-4d36-a494-682f7c89f535
parent bea23351
......@@ -298,6 +298,8 @@ void MovePlugin::slotKeyEvent (QKeyEvent* _event)
setManipMode (QtTranslationManipulatorNode::LocalRotation);
}
#include <qt4/QtGui/QDialog>
#include <qt4/QtGui/qmessagebox.h>
//------------------------------------------------------------------------------
void MovePlugin::slotKeyReleaseEvent (QKeyEvent* _event)
......@@ -1068,42 +1070,75 @@ void MovePlugin::slotScale() {
//------------------------------------------------------------------------------
/** \brief Move currently active or first Mesh with its COG to the origin
/** \brief Move target Meshes cog to the origin
*
*/
void MovePlugin::slotMoveToOrigin() {
for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it) {
bool useCommonCOG = false;
ACG::Vec3d cog = ACG::Vec3d(0.0,0.0,0.0);
if ( PluginFunctions::targetCount() > 1 ) {
QMessageBox::StandardButton button = QMessageBox::question( 0, tr("Use common COG?"), tr("Should the targets be moved depending on their common cog?"),QMessageBox::Yes|QMessageBox::No);
useCommonCOG = ( button == QMessageBox::Yes );
double count = 0.0;
// Compute cog for all objects
for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it) {
if ( o_it->dataType( DATA_TRIANGLE_MESH )) {
TriMesh& mesh = *PluginFunctions::triMesh(*o_it);
const TriMesh::Point cog = MeshInfo::cog(mesh);
for ( TriMesh::VertexIter v_it = mesh.vertices_begin(); v_it != mesh.vertices_end() ; ++v_it)
mesh.set_point(v_it , ( mesh.point(v_it) ) - cog );
o_it->manipulatorNode()->set_center( o_it->manipulatorNode()->center() - cog );
cog += MeshInfo::cog(mesh);
++count;
}
if ( o_it->dataType( DATA_POLY_MESH )) {
PolyMesh& mesh = *PluginFunctions::polyMesh(*o_it);
const PolyMesh::Point cog = MeshInfo::cog(mesh);
cog += MeshInfo::cog(mesh);
++count;
}
}
cog = cog / count;
}
for ( PolyMesh::VertexIter v_it = mesh.vertices_begin(); v_it != mesh.vertices_end() ; ++v_it)
mesh.set_point(v_it , ( mesh.point(v_it) ) - cog );
for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it) {
if ( o_it->dataType( DATA_TRIANGLE_MESH )) {
TriMesh& mesh = *PluginFunctions::triMesh(*o_it);
if ( !useCommonCOG )
cog = MeshInfo::cog(mesh);
o_it->manipulatorNode()->set_center( o_it->manipulatorNode()->center() - cog );
for ( TriMesh::VertexIter v_it = mesh.vertices_begin(); v_it != mesh.vertices_end() ; ++v_it)
mesh.set_point(v_it , ( mesh.point(v_it) ) - cog );
}
o_it->manipulatorNode()->set_center( o_it->manipulatorNode()->center() - cog );
}
emit updatedObject( o_it->id() );
if ( o_it->dataType( DATA_POLY_MESH )) {
PolyMesh& mesh = *PluginFunctions::polyMesh(*o_it);
if ( !useCommonCOG )
cog = MeshInfo::cog(mesh);
updateManipulatorDialog();
o_it->manipulatorNode()->loadIdentity();
for ( PolyMesh::VertexIter v_it = mesh.vertices_begin(); v_it != mesh.vertices_end() ; ++v_it)
mesh.set_point(v_it , ( mesh.point(v_it) ) - cog );
emit createBackup(o_it->id(),"Move to origin");
}
o_it->manipulatorNode()->set_center( o_it->manipulatorNode()->center() - cog );
}
emit updatedObject( o_it->id() );
updateManipulatorDialog();
o_it->manipulatorNode()->loadIdentity();
emit createBackup(o_it->id(),"Move to origin");
}
emit updateView();
emit updateView();
}
......@@ -1114,31 +1149,17 @@ void MovePlugin::slotMoveToOrigin() {
*/
void MovePlugin::slotUnifyBoundingBoxDiagonal()
{
if ( tool_->targetObjects->isChecked() ) {
for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it) {
if ( o_it->dataType( DATA_TRIANGLE_MESH ) )
unifyBBDiag(*PluginFunctions::triMesh(*o_it));
else if ( o_it->dataType( DATA_POLY_MESH ) )
unifyBBDiag(*PluginFunctions::polyMesh(*o_it));
emit updatedObject( o_it->id() );
}
} else {
BaseObjectData* object;
if ( PluginFunctions::getObject(lastActiveManipulator_ , object) ) {
if ( object->manipulatorNode()->visible() ) {
for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it) {
if ( o_it->dataType( DATA_TRIANGLE_MESH ) )
unifyBBDiag(*PluginFunctions::triMesh(*o_it));
else if ( o_it->dataType( DATA_POLY_MESH ) )
unifyBBDiag(*PluginFunctions::polyMesh(*o_it));
if ( object->dataType( DATA_TRIANGLE_MESH ) )
unifyBBDiag(*PluginFunctions::triMesh(object));
else if ( object->dataType( DATA_POLY_MESH ) )
unifyBBDiag(*PluginFunctions::polyMesh(object));
}
emit updatedObject( o_it->id() );
emit updatedObject( object->id() );
}
}
emit updateView();
}
emit updateView();
}
......
......@@ -192,7 +192,7 @@ class MovePlugin : public QObject, BaseInterface, MouseInterface, KeyInterface,
/// Scale (with values from Tab)
void slotScale();
/// Move currently active or first Mesh with its COG to the origin
/// Move target Meshes cog to the origin
void slotMoveToOrigin();
/// Scale Boundingbox Diagonal to unit size
......
<ui version="4.0" >
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>moveControls</class>
<widget class="QWidget" name="moveControls" >
<property name="geometry" >
<widget class="QWidget" name="moveControls">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
......@@ -9,88 +10,78 @@
<height>169</height>
</rect>
</property>
<property name="sizePolicy" >
<sizepolicy vsizetype="Preferred" hsizetype="Fixed" >
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize" >
<property name="maximumSize">
<size>
<width>348</width>
<height>16777215</height>
</size>
</property>
<property name="windowTitle" >
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_6" >
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<widget class="QCheckBox" name="targetObjects" >
<property name="text" >
<string>Apply Transformation to Target Objects</string>
</property>
<property name="checked" >
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QTabWidget" name="tabWidget" >
<property name="enabled" >
<widget class="QTabWidget" name="tabWidget">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy" >
<sizepolicy vsizetype="Expanding" hsizetype="Preferred" >
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="currentIndex" >
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tab" >
<attribute name="title" >
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Move</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_3" >
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QPushButton" name="moveToOrigin" >
<property name="toolTip" >
<widget class="QPushButton" name="moveToOrigin">
<property name="toolTip">
<string>Move COG to origin</string>
</property>
<property name="statusTip" >
<property name="statusTip">
<string>Move COG of selected objects to origin</string>
</property>
<property name="whatsThis" >
<property name="whatsThis">
<string>Moves the selected objects such that
their center of gravity is at the origin.</string>
</property>
<property name="text" >
<property name="text">
<string>Move COG to origin</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="Transform" >
<attribute name="title" >
<widget class="QWidget" name="Transform">
<attribute name="title">
<string>Transform</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2" >
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QPushButton" name="unifyBoundingBoxDiagonal" >
<property name="toolTip" >
<widget class="QPushButton" name="unifyBoundingBoxDiagonal">
<property name="toolTip">
<string>Normalize bounding box diagonal of objects</string>
</property>
<property name="statusTip" >
<property name="statusTip">
<string>Normalize bounding box diagonal of objects</string>
</property>
<property name="whatsThis" >
<property name="whatsThis">
<string>Rescale objects such that its bounding box
diagonal has length one.</string>
</property>
<property name="text" >
<property name="text">
<string>Unify Boundingbox Diagonal</string>
</property>
</widget>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment