diff --git a/MoveContextMenu.cc b/MoveContextMenu.cc index 674d968dccd146570eb6ec7a41cd67534a225f87..d0fad2146dcb41334ec5d4d0765ba31b35712ee6 100644 --- a/MoveContextMenu.cc +++ b/MoveContextMenu.cc @@ -63,21 +63,20 @@ void MovePlugin::showProps(){ ACG::SceneGraph::BaseNode* mesh = ACG::SceneGraph::find_node( PluginFunctions::getSceneGraphRootNode(), meshID ); - // TODO: Fenster an obj attachen und Daten per Signale austauschen + movePropsWidget* pW = new movePropsWidget(obj); + pW->setWindowTitle(QString((mesh->name()).c_str())); - propsWindow_->setWindowTitle(QString((mesh->name()).c_str())); - - connect(propsWindow_->posButton,SIGNAL(clicked() ),this,SLOT(slotSetPosition())); - connect(propsWindow_->axisAButton,SIGNAL(clicked() ),this,SLOT(slotToggleAxisA())); - connect(propsWindow_->axisBButton,SIGNAL(clicked() ),this,SLOT(slotToggleAxisB())); - connect(propsWindow_->dirButton,SIGNAL(clicked() ),this,SLOT(slotSetDirection())); - connect(propsWindow_->transButton,SIGNAL(clicked() ),this,SLOT(slotTranslation())); + connect(pW->posButton,SIGNAL(clicked() ),this,SLOT(slotSetPosition())); + connect(pW->axisAButton,SIGNAL(clicked() ),this,SLOT(slotToggleAxisA())); + connect(pW->axisBButton,SIGNAL(clicked() ),this,SLOT(slotToggleAxisB())); + connect(pW->dirButton,SIGNAL(clicked() ),this,SLOT(slotSetDirection())); + connect(pW->transButton,SIGNAL(clicked() ),this,SLOT(slotTranslation())); - connect(propsWindow_->rotButton,SIGNAL(clicked() ),this,SLOT(slotRotate())); - connect(propsWindow_->scaleButton,SIGNAL(clicked() ),this,SLOT(slotScale())); + connect(pW->rotButton,SIGNAL(clicked() ),this,SLOT(slotRotate())); + connect(pW->scaleButton,SIGNAL(clicked() ),this,SLOT(slotScale())); - connect(propsWindow_->projectTangentButton,SIGNAL(clicked() ),this,SLOT(slotProjectToTangentPlane())); - connect(propsWindow_->moveManipToCOG,SIGNAL(clicked() ),this,SLOT(slotMoveManipToCOG())); + connect(pW->projectTangentButton,SIGNAL(clicked() ),this,SLOT(slotProjectToTangentPlane())); + connect(pW->moveManipToCOG,SIGNAL(clicked() ),this,SLOT(slotMoveManipToCOG())); // Values BaseObjectData* object; @@ -87,27 +86,28 @@ void MovePlugin::showProps(){ QString num; - num = QString::number(pos[0]); propsWindow_->posx->setText(num); - num = QString::number(pos[1]); propsWindow_->posy->setText(num); - num = QString::number(pos[2]); propsWindow_->posz->setText(num); + num = QString::number(pos[0]); pW->posx->setText(num); + num = QString::number(pos[1]); pW->posy->setText(num); + num = QString::number(pos[2]); pW->posz->setText(num); TriMesh::Point direction = object->manipulatorNode()->directionX(); - num = QString::number(direction[0]); propsWindow_->dirxx->setText(num); - num = QString::number(direction[1]); propsWindow_->dirxy->setText(num); - num = QString::number(direction[2]); propsWindow_->dirxz->setText(num); + num = QString::number(direction[0]); pW->dirxx->setText(num); + num = QString::number(direction[1]); pW->dirxy->setText(num); + num = QString::number(direction[2]); pW->dirxz->setText(num); direction = object->manipulatorNode()->directionY(); - num = QString::number(direction[0]); propsWindow_->diryx->setText(num); - num = QString::number(direction[1]); propsWindow_->diryy->setText(num); - num = QString::number(direction[2]); propsWindow_->diryz->setText(num); + num = QString::number(direction[0]); pW->diryx->setText(num); + num = QString::number(direction[1]); pW->diryy->setText(num); + num = QString::number(direction[2]); pW->diryz->setText(num); direction = object->manipulatorNode()->directionZ(); - num = QString::number(direction[0]); propsWindow_->dirzx->setText(num); - num = QString::number(direction[1]); propsWindow_->dirzy->setText(num); - num = QString::number(direction[2]); propsWindow_->dirzz->setText(num); + num = QString::number(direction[0]); pW->dirzx->setText(num); + num = QString::number(direction[1]); pW->dirzy->setText(num); + num = QString::number(direction[2]); pW->dirzz->setText(num); } } - propsWindow_->show(); + pW->show(); + propsWindows_.append(pW); } \ No newline at end of file diff --git a/MovePlugin.cc b/MovePlugin.cc index 49e80c0b7bcf0df45024a4bd4929cd23f6e2c60c..73fd15f6920b511a3d40a5f9267993423e560a97 100644 --- a/MovePlugin.cc +++ b/MovePlugin.cc @@ -90,9 +90,6 @@ void MovePlugin::pluginsInitialized() { setDescriptions(); // CONTEXT MENU - propsWindow_ = new movePropsWidget(); - propsWindow_->hide(); - lastAction_ = new QAction("Set properties", this); lastAction_->setToolTip("Set properties"); lastAction_->setStatusTip( lastAction_->toolTip() ); @@ -447,31 +444,45 @@ void MovePlugin::showManipulators( ) } +//------------------------------------------------------------------------------ +/** \brief Get Dialog Widget that contains the button + * + * @param _but Reference to QPushButton object that has been pressed + */ +movePropsWidget* MovePlugin::getDialogFromButton(QPushButton* _but) { + + if(_but == 0) return 0; + return dynamic_cast<movePropsWidget*>((((_but->parentWidget())->parentWidget())->parentWidget())); +} //------------------------------------------------------------------------------ /** \brief Position of manipulator in tab changed * */ void MovePlugin::slotSetPosition() { - TriMesh::Point newpos; - - bool ok = false; - newpos[0] = (propsWindow_->nposx->text()).toDouble(&ok); - if ( !ok ) { emit log(LOGERR,"Wrong Format for X Coordinate"); return; } - newpos[1] = (propsWindow_->nposy->text()).toDouble(&ok); - if ( !ok ) { emit log(LOGERR,"Wrong Format for Y Coordinate"); return; } - newpos[2] = (propsWindow_->nposz->text()).toDouble(&ok); - if ( !ok ) { emit log(LOGERR,"Wrong Format for Z Coordinate"); return; } - - BaseObjectData* object; - if ( PluginFunctions::getObject(lastActiveManipulator_ , object) ) { - if ( object->manipulatorNode()->visible() ) - object->manipulatorNode()->set_center( newpos ); - updateManipulatorDialog(); - emit updateView(); - } - + + QPushButton* but = dynamic_cast<QPushButton*>(QObject::sender()); + movePropsWidget* pW = getDialogFromButton(but); + if(pW == 0) return; + + TriMesh::Point newpos; + + bool ok = false; + newpos[0] = (pW->nposx->text()).toDouble(&ok); + if ( !ok ) { emit log(LOGERR,"Wrong Format for X Coordinate"); return; } + newpos[1] = (pW->nposy->text()).toDouble(&ok); + if ( !ok ) { emit log(LOGERR,"Wrong Format for Y Coordinate"); return; } + newpos[2] = (pW->nposz->text()).toDouble(&ok); + if ( !ok ) { emit log(LOGERR,"Wrong Format for Z Coordinate"); return; } + + BaseObjectData* object; + if ( PluginFunctions::getObject(lastActiveManipulator_ , object) ) { + if ( object->manipulatorNode()->visible() ) + object->manipulatorNode()->set_center( newpos ); + updateManipulatorDialog(); + emit updateView(); + } } @@ -481,18 +492,22 @@ void MovePlugin::slotSetPosition() { * */ void MovePlugin::slotToggleAxisA() { + + QPushButton* but = dynamic_cast<QPushButton*>(QObject::sender()); + movePropsWidget* pW = getDialogFromButton(but); + if(pW == 0) return; - axisA_ = (axisA_ + 1) % 3; - - if (axisA_ == axisB_) axisA_ = (axisA_ + 1) % 3; - - switch(axisA_){ - case 0: propsWindow_->axisAButton->setText("X Direction"); break; - case 1: propsWindow_->axisAButton->setText("Y Direction"); break; - case 2: propsWindow_->axisAButton->setText("Z Direction"); break; - default: break; - } + + if (axisA_ == axisB_) + axisA_ = (axisA_ + 1) % 3; + + switch(axisA_){ + case 0: pW->axisAButton->setText("X Direction"); break; + case 1: pW->axisAButton->setText("Y Direction"); break; + case 2: pW->axisAButton->setText("Z Direction"); break; + default: break; + } } @@ -502,18 +517,22 @@ void MovePlugin::slotToggleAxisA() { * */ void MovePlugin::slotToggleAxisB() { + + QPushButton* but = dynamic_cast<QPushButton*>(QObject::sender()); + movePropsWidget* pW = getDialogFromButton(but); + if(pW == 0) return; - axisB_ = (axisB_ + 1) % 3; - - if (axisA_ == axisB_) axisB_ = (axisB_ + 1) % 3; - - switch(axisB_){ - case 0: propsWindow_->axisBButton->setText("X Direction"); break; - case 1: propsWindow_->axisBButton->setText("Y Direction"); break; - case 2: propsWindow_->axisBButton->setText("Z Direction"); break; - default: break; - } + + if (axisA_ == axisB_) + axisB_ = (axisB_ + 1) % 3; + + switch(axisB_){ + case 0: pW->axisBButton->setText("X Direction"); break; + case 1: pW->axisBButton->setText("Y Direction"); break; + case 2: pW->axisBButton->setText("Z Direction"); break; + default: break; + } } @@ -523,71 +542,76 @@ void MovePlugin::slotToggleAxisB() { * */ void MovePlugin::slotSetDirection() { + + QPushButton* but = dynamic_cast<QPushButton*>(QObject::sender()); + movePropsWidget* pW = getDialogFromButton(but); + if(pW == 0) return; - ACG::Vec3d newdirA,newdirB; - ACG::Vec3d dirX,dirY; - ACG::Vec3d dirZ(0.0,0.0,0.0); - - bool ok = false; - newdirA[0] = (propsWindow_->ndirAx->text()).toDouble(&ok); - if ( !ok ) { emit log(LOGERR,"Wrong Format for X Coordinate"); return; } - newdirA[1] = (propsWindow_->ndirAy->text()).toDouble(&ok); - if ( !ok ) { emit log(LOGERR,"Wrong Format for Y Coordinate"); return; } - newdirA[2] = (propsWindow_->ndirAz->text()).toDouble(&ok); - if ( !ok ) { emit log(LOGERR,"Wrong Format for Z Coordinate"); return; } - - newdirB[0] = (propsWindow_->ndirBx->text()).toDouble(&ok); - if ( !ok ) { emit log(LOGERR,"Wrong Format for X Coordinate"); return; } - newdirB[1] = (propsWindow_->ndirBy->text()).toDouble(&ok); - if ( !ok ) { emit log(LOGERR,"Wrong Format for Y Coordinate"); return; } - newdirB[2] = (propsWindow_->ndirBz->text()).toDouble(&ok); - if ( !ok ) { emit log(LOGERR,"Wrong Format for Z Coordinate"); return; } - - bool xAxis = false; - bool yAxis = false; - - switch(axisA_){ - case 0: dirX = newdirA; xAxis = true; break; - case 1: dirY = newdirA; yAxis = true; break; - default: dirZ = newdirA; break; - } - - switch(axisB_){ - case 0: dirX = newdirB; xAxis = true; break; - case 1: dirY = newdirB; yAxis = true; break; - default: dirZ = newdirB; break; - } - - if (!xAxis) - dirX = dirY % dirZ; - - if (!yAxis) - dirY = dirX % dirZ; - - - if ( (dirX | dirY) != 0.0){ - emit log(LOGERR,"The axes of the new direction have to be orthogonal"); - return; - } - - // Apply to All Target Objects - if ( propsWindow_->targetObjects->isChecked() ) { - for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it){ - - o_it->manipulatorNode()->set_direction( dirX, dirY ); - } - } else { - BaseObjectData* object; - if ( PluginFunctions::getObject(lastActiveManipulator_ , object) ) { - if ( object->manipulatorNode()->visible() ){ + ACG::Vec3d newdirA,newdirB; + ACG::Vec3d dirX,dirY; + ACG::Vec3d dirZ(0.0,0.0,0.0); + + bool ok = false; + newdirA[0] = (pW->ndirAx->text()).toDouble(&ok); + if ( !ok ) { emit log(LOGERR,"Wrong Format for X Coordinate"); return; } + newdirA[1] = (pW->ndirAy->text()).toDouble(&ok); + if ( !ok ) { emit log(LOGERR,"Wrong Format for Y Coordinate"); return; } + newdirA[2] = (pW->ndirAz->text()).toDouble(&ok); + if ( !ok ) { emit log(LOGERR,"Wrong Format for Z Coordinate"); return; } + + newdirB[0] = (pW->ndirBx->text()).toDouble(&ok); + if ( !ok ) { emit log(LOGERR,"Wrong Format for X Coordinate"); return; } + newdirB[1] = (pW->ndirBy->text()).toDouble(&ok); + if ( !ok ) { emit log(LOGERR,"Wrong Format for Y Coordinate"); return; } + newdirB[2] = (pW->ndirBz->text()).toDouble(&ok); + if ( !ok ) { emit log(LOGERR,"Wrong Format for Z Coordinate"); return; } + + bool xAxis = false; + bool yAxis = false; + + switch(axisA_){ + case 0: dirX = newdirA; xAxis = true; break; + case 1: dirY = newdirA; yAxis = true; break; + default: dirZ = newdirA; break; + } + + switch(axisB_){ + case 0: dirX = newdirB; xAxis = true; break; + case 1: dirY = newdirB; yAxis = true; break; + default: dirZ = newdirB; break; + } + + if (!xAxis) + dirX = dirY % dirZ; + + if (!yAxis) + dirY = dirX % dirZ; + + + if ( (dirX | dirY) != 0.0){ + emit log(LOGERR,"The axes of the new direction have to be orthogonal"); + return; + } + +// // Apply to All Target Objects +// if ( pW->targetObjects->isChecked() ) { +// for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS) ; +// o_it PluginFunctions::objectsEnd(); ++o_it){ +// +// o_it->manipulatorNode()->set_direction( dirX, dirY ); +// } +// } + + BaseObjectData* object = pW->getBaseObjectData(); + if ( object != 0 ) { + if ( object->manipulatorNode()->visible() ){ object->manipulatorNode()->set_direction( dirX, dirY ); - } - } else return; - } - - updateManipulatorDialog(); - emit updateView(); + } + } else return; + + updateManipulatorDialog(); + emit updateView(); } @@ -597,63 +621,68 @@ void MovePlugin::slotSetDirection() { * */ void MovePlugin::slotTranslation() { + + QPushButton* but = dynamic_cast<QPushButton*>(QObject::sender()); + movePropsWidget* pW = getDialogFromButton(but); + if(pW == 0) return; - ACG::Vec3d translation; - - bool ok = false; - translation[0] = (propsWindow_->translationX->text()).toDouble(&ok); - if ( !ok ) { emit log(LOGERR,"Wrong Format for X Coordinate"); return; } - translation[1] = (propsWindow_->translationY->text()).toDouble(&ok); - if ( !ok ) { emit log(LOGERR,"Wrong Format for Y Coordinate"); return; } - translation[2] = (propsWindow_->translationZ->text()).toDouble(&ok); - if ( !ok ) { emit log(LOGERR,"Wrong Format for Z Coordinate"); return; } - - // Apply to All Target Objects - if ( propsWindow_->targetObjects->isChecked() ) { - - int manipcount = 0; // Check how many of the target meshes have an visible manipulator - int targets = 0; // Count the number of target meshes - for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it) { - ++targets; - if ( ! o_it->manipulatorNode()->hidden() ) { - ++ manipcount; - } - } - - if (manipcount == 0 ) // No manipulator -> no translation - return; - - for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS,DataType( DATA_TRIANGLE_MESH | DATA_POLY_MESH )) ; - o_it != PluginFunctions::objectsEnd(); ++o_it) { - if ( manipcount > 1 ) { // Use manipulator direction for each target mesh - if ( o_it->manipulatorNode()->hidden() ) - continue; - } - - translate( o_it->id() , translation ); - - o_it->manipulatorNode()->set_center( o_it->manipulatorNode()->center() + translation ); - emit createBackup(o_it->id(),"Translation"); - emit updatedObject(o_it->id()); - } - - } else { - BaseObjectData* object; - if ( PluginFunctions::getObject(lastActiveManipulator_ , object) ) { - if ( object->manipulatorNode()->visible() ) { - - translate( object->id() , translation ); + ACG::Vec3d translation; + + bool ok = false; + translation[0] = (pW->translationX->text()).toDouble(&ok); + if ( !ok ) { emit log(LOGERR,"Wrong Format for X Coordinate"); return; } + translation[1] = (pW->translationY->text()).toDouble(&ok); + if ( !ok ) { emit log(LOGERR,"Wrong Format for Y Coordinate"); return; } + translation[2] = (pW->translationZ->text()).toDouble(&ok); + if ( !ok ) { emit log(LOGERR,"Wrong Format for Z Coordinate"); return; } + + // Apply to All Target Objects +// if ( pW->targetObjects->isChecked() ) { +// +// int manipcount = 0; // Check how many of the target meshes have an visible manipulator +// int targets = 0; // Count the number of target meshes +// for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it) { +// ++targets; +// if ( ! o_it->manipulatorNode()->hidden() ) { +// ++ manipcount; +// } +// } +// +// if (manipcount == 0 ) // No manipulator -> no translation +// return; +// +// for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS,DataType( DATA_TRIANGLE_MESH | DATA_POLY_MESH )) ; +// o_it != PluginFunctions::objectsEnd(); ++o_it) { +// if ( manipcount > 1 ) { // Use manipulator direction for each target mesh +// if ( o_it->manipulatorNode()->hidden() ) +// continue; +// } +// +// translate( o_it->id() , translation ); +// +// o_it->manipulatorNode()->set_center( o_it->manipulatorNode()->center() + translation ); +// emit createBackup(o_it->id(),"Translation"); +// emit updatedObject(o_it->id()); +// } +// +// } + + BaseObjectData* object = pW->getBaseObjectData(); + if ( object != 0 ) { + if ( object->manipulatorNode()->visible() ){ - object->manipulatorNode()->set_center( object->manipulatorNode()->center() + translation ); - emit createBackup(object->id(),"Translation"); - emit updatedObject(object->id()); - } - } else return; - } + translate( object->id() , translation ); + + object->manipulatorNode()->set_center( object->manipulatorNode()->center() + translation ); + emit createBackup(object->id(),"Translation"); + emit updatedObject(object->id()); + } + } else return; - updateManipulatorDialog(); - emit scriptInfo(QString("slotTranslation()")); - emit updateView(); + + updateManipulatorDialog(); + emit scriptInfo(QString("slotTranslation()")); + emit updateView(); } @@ -663,14 +692,18 @@ void MovePlugin::slotTranslation() { * */ void MovePlugin::slotProjectToTangentPlane() { - - if ( propsWindow_->targetObjects->isChecked() ) { - emit log(LOGWARN,"TODO Project for multiple targets"); - return; - } else { - emit log(LOGWARN,"TODO Project for one target"); - return; - } + + QPushButton* but = dynamic_cast<QPushButton*>(QObject::sender()); + movePropsWidget* pW = getDialogFromButton(but); + if(pW == 0) return; + + if ( pW->targetObjects->isChecked() ) { + emit log(LOGWARN,"TODO Project for multiple targets"); + return; + } else { + emit log(LOGWARN,"TODO Project for one target"); + return; + } } @@ -681,35 +714,42 @@ void MovePlugin::slotProjectToTangentPlane() { * */ void MovePlugin::slotMoveManipToCOG() { - if ( propsWindow_->targetObjects->isChecked() ) { - for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it) { - if ( o_it->manipulatorNode()->hidden() ) - continue; - - if ( o_it->dataType( DATA_TRIANGLE_MESH ) ) - o_it->manipulatorNode()->set_center( MeshInfo::cog(*PluginFunctions::triMesh(*o_it) ) ); - else if ( o_it->dataType( DATA_POLY_MESH ) ) - o_it->manipulatorNode()->set_center( MeshInfo::cog(*PluginFunctions::polyMesh(*o_it)) ); - - updateManipulatorDialog(); - o_it->manipulatorNode()->loadIdentity(); - } - } else { - BaseObjectData* object; - if ( PluginFunctions::getObject(lastActiveManipulator_ , object) ) { - if ( object->manipulatorNode()->visible() ) { + + QPushButton* but = dynamic_cast<QPushButton*>(QObject::sender()); + movePropsWidget* pW = getDialogFromButton(but); + if(pW == 0) return; + + +// if ( pW->targetObjects->isChecked() ) { +// for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it) { +// if ( o_it->manipulatorNode()->hidden() ) +// continue; +// +// if ( o_it->dataType( DATA_TRIANGLE_MESH ) ) +// o_it->manipulatorNode()->set_center( MeshInfo::cog(*PluginFunctions::triMesh(*o_it) ) ); +// else if ( o_it->dataType( DATA_POLY_MESH ) ) +// o_it->manipulatorNode()->set_center( MeshInfo::cog(*PluginFunctions::polyMesh(*o_it)) ); +// +// updateManipulatorDialog(); +// o_it->manipulatorNode()->loadIdentity(); +// } +// } else { + + BaseObjectData* object = pW->getBaseObjectData(); + if ( object != 0 ) { + if ( object->manipulatorNode()->visible() ){ + + if ( object->dataType( DATA_TRIANGLE_MESH ) ) + object->manipulatorNode()->set_center( MeshInfo::cog(*PluginFunctions::triMesh(object)) ); + else if ( object->dataType( DATA_POLY_MESH ) ) + object->manipulatorNode()->set_center( MeshInfo::cog(*PluginFunctions::polyMesh(object)) ); - if ( object->dataType( DATA_TRIANGLE_MESH ) ) - object->manipulatorNode()->set_center( MeshInfo::cog(*PluginFunctions::triMesh(object)) ); - else if ( object->dataType( DATA_POLY_MESH ) ) - object->manipulatorNode()->set_center( MeshInfo::cog(*PluginFunctions::polyMesh(object)) ); + updateManipulatorDialog(); + object->manipulatorNode()->loadIdentity(); + } + } - updateManipulatorDialog(); - object->manipulatorNode()->loadIdentity(); - } - } - } - emit updateView(); + emit updateView(); } @@ -719,59 +759,67 @@ void MovePlugin::slotMoveManipToCOG() { * */ void MovePlugin::slotRotate() { - TriMesh::Point axis; - double angle; - - bool ok = false; - axis[0] = (propsWindow_->rotx->text()).toDouble(&ok); - if ( !ok ) { emit log(LOGERR,"Wrong Format for X Coordinate"); return; } - axis[1] = (propsWindow_->roty->text()).toDouble(&ok); - if ( !ok ) { emit log(LOGERR,"Wrong Format for Y Coordinate"); return; } - axis[2] = (propsWindow_->rotz->text()).toDouble(&ok); - if ( !ok ) { emit log(LOGERR,"Wrong Format for Z Coordinate"); return; } - - angle = (propsWindow_->rotAngle->text()).toDouble(&ok); - if ( !ok ) { emit log(LOGERR,"Wrong Format for Angle"); return; } - - if ( propsWindow_->targetObjects->isChecked() ) { - for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it) { - if ( o_it->manipulatorNode()->hidden() ) - continue; - o_it->manipulatorNode()->rotate( angle,axis); - - if (o_it->dataType( DATA_TRIANGLE_MESH ) ) - transformMesh( o_it->manipulatorNode()->matrix() , (*PluginFunctions::triMesh(*o_it)) ); - - if (o_it->dataType( DATA_POLY_MESH ) ) - transformMesh( o_it->manipulatorNode()->matrix() , (*PluginFunctions::polyMesh(*o_it)) ); - - o_it->manipulatorNode()->loadIdentity(); - updateManipulatorDialog(); - - emit createBackup(o_it->id(),"Rotation"); - emit updatedObject(o_it->id()); - } - } else { - BaseObjectData* object; - if ( PluginFunctions::getObject(lastActiveManipulator_ , object) ) { - - object->manipulatorNode()->rotate(angle,axis); - - if (object->dataType( DATA_TRIANGLE_MESH ) ) - transformMesh( getLastManipulatorMatrix(true) , (*PluginFunctions::triMesh(object)) ); - - if (object->dataType( DATA_POLY_MESH ) ) - transformMesh( getLastManipulatorMatrix(true) , (*PluginFunctions::polyMesh(object)) ); - - updateManipulatorDialog(); - - emit createBackup(object->id(),"Rotation"); - emit updatedObject(object->id()); - } - } - emit scriptInfo(QString("slotRotate()")); - emit updateView(); - + + QPushButton* but = dynamic_cast<QPushButton*>(QObject::sender()); + movePropsWidget* pW = getDialogFromButton(but); + if(pW == 0) return; + + TriMesh::Point axis; + double angle; + + bool ok = false; + axis[0] = (pW->rotx->text()).toDouble(&ok); + if ( !ok ) { emit log(LOGERR,"Wrong Format for X Coordinate"); return; } + axis[1] = (pW->roty->text()).toDouble(&ok); + if ( !ok ) { emit log(LOGERR,"Wrong Format for Y Coordinate"); return; } + axis[2] = (pW->rotz->text()).toDouble(&ok); + if ( !ok ) { emit log(LOGERR,"Wrong Format for Z Coordinate"); return; } + + angle = (pW->rotAngle->text()).toDouble(&ok); + if ( !ok ) { emit log(LOGERR,"Wrong Format for Angle"); return; } + +// if ( pW->targetObjects->isChecked() ) { +// for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it) { +// if ( o_it->manipulatorNode()->hidden() ) +// continue; +// o_it->manipulatorNode()->rotate( angle,axis); +// +// if (o_it->dataType( DATA_TRIANGLE_MESH ) ) +// transformMesh( o_it->manipulatorNode()->matrix() , (*PluginFunctions::triMesh(*o_it)) ); +// +// if (o_it->dataType( DATA_POLY_MESH ) ) +// transformMesh( o_it->manipulatorNode()->matrix() , (*PluginFunctions::polyMesh(*o_it)) ); +// +// o_it->manipulatorNode()->loadIdentity(); +// updateManipulatorDialog(); +// +// emit createBackup(o_it->id(),"Rotation"); +// emit updatedObject(o_it->id()); +// } +// } else { + + + BaseObjectData* object = pW->getBaseObjectData(); + if ( object != 0 ) { + if ( object->manipulatorNode()->visible() ){ + + object->manipulatorNode()->rotate(angle,axis); + + if (object->dataType( DATA_TRIANGLE_MESH ) ) + transformMesh( getLastManipulatorMatrix(true) , (*PluginFunctions::triMesh(object)) ); + + if (object->dataType( DATA_POLY_MESH ) ) + transformMesh( getLastManipulatorMatrix(true) , (*PluginFunctions::polyMesh(object)) ); + + updateManipulatorDialog(); + + emit createBackup(object->id(),"Rotation"); + emit updatedObject(object->id()); + } + } + + emit scriptInfo(QString("slotRotate()")); + emit updateView(); } @@ -781,54 +829,64 @@ void MovePlugin::slotRotate() { * */ void MovePlugin::slotScale() { - TriMesh::Point scale; - - bool ok = false; - scale[0] = (propsWindow_->scalex->text()).toDouble(&ok); - if ( !ok ) { emit log(LOGERR,"Wrong Format for factor 1"); return; } - scale[1] = (propsWindow_->scaley->text()).toDouble(&ok); - if ( !ok ) { emit log(LOGERR,"Wrong Format for factor 2"); return; } - scale[2] = (propsWindow_->scalez->text()).toDouble(&ok); - if ( !ok ) { emit log(LOGERR,"Wrong Format for factor 3"); return; } - - if ( propsWindow_->targetObjects->isChecked() ) { - for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it) { - if ( o_it->manipulatorNode()->hidden() ) - continue; - o_it->manipulatorNode()->scale( scale); - - if (o_it->dataType( DATA_TRIANGLE_MESH ) ) - transformMesh( o_it->manipulatorNode()->matrix() , (*PluginFunctions::triMesh(*o_it)) ); - - if (o_it->dataType( DATA_POLY_MESH ) ) - transformMesh( o_it->manipulatorNode()->matrix() , (*PluginFunctions::polyMesh(*o_it)) ); - - o_it->manipulatorNode()->loadIdentity(); - updateManipulatorDialog(); - - emit createBackup(o_it->id(),"Scaling"); - emit updatedObject(o_it->id()); - } - } else { - BaseObjectData* object; - if ( PluginFunctions::getObject(lastActiveManipulator_ , object) ) { - - object->manipulatorNode()->scale( scale); - - if (object->dataType( DATA_TRIANGLE_MESH ) ) - transformMesh( getLastManipulatorMatrix(true) , (*PluginFunctions::triMesh(object)) ); - - if (object->dataType( DATA_POLY_MESH ) ) - transformMesh( getLastManipulatorMatrix(true) , (*PluginFunctions::polyMesh(object)) ); + + QPushButton* but = dynamic_cast<QPushButton*>(QObject::sender()); + movePropsWidget* pW = getDialogFromButton(but); + if(pW == 0) return; + + + TriMesh::Point scale; + + bool ok = false; + scale[0] = (pW->scalex->text()).toDouble(&ok); + if ( !ok ) { emit log(LOGERR,"Wrong Format for factor 1"); return; } + scale[1] = (pW->scaley->text()).toDouble(&ok); + if ( !ok ) { emit log(LOGERR,"Wrong Format for factor 2"); return; } + scale[2] = (pW->scalez->text()).toDouble(&ok); + if ( !ok ) { emit log(LOGERR,"Wrong Format for factor 3"); return; } + +// if ( pW->targetObjects->isChecked() ) { +// for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it) { +// if ( o_it->manipulatorNode()->hidden() ) +// continue; +// o_it->manipulatorNode()->scale( scale); +// +// if (o_it->dataType( DATA_TRIANGLE_MESH ) ) +// transformMesh( o_it->manipulatorNode()->matrix() , (*PluginFunctions::triMesh(*o_it)) ); +// +// if (o_it->dataType( DATA_POLY_MESH ) ) +// transformMesh( o_it->manipulatorNode()->matrix() , (*PluginFunctions::polyMesh(*o_it)) ); +// +// o_it->manipulatorNode()->loadIdentity(); +// updateManipulatorDialog(); +// +// emit createBackup(o_it->id(),"Scaling"); +// emit updatedObject(o_it->id()); +// } +// } else { + + + BaseObjectData* object = pW->getBaseObjectData(); + if ( object != 0 ) { + if ( object->manipulatorNode()->visible() ){ - updateManipulatorDialog(); + object->manipulatorNode()->scale( scale); + + if (object->dataType( DATA_TRIANGLE_MESH ) ) + transformMesh( getLastManipulatorMatrix(true) , (*PluginFunctions::triMesh(object)) ); + + if (object->dataType( DATA_POLY_MESH ) ) + transformMesh( getLastManipulatorMatrix(true) , (*PluginFunctions::polyMesh(object)) ); + + updateManipulatorDialog(); + + emit createBackup(object->id(),"Scaling"); + emit updatedObject(object->id()); + } + } - emit createBackup(object->id(),"Scaling"); - emit updatedObject(object->id()); - } - } - emit scriptInfo(QString("slotScale()")); - emit updateView(); + emit scriptInfo(QString("slotScale()")); + emit updateView(); } @@ -916,40 +974,61 @@ void MovePlugin::slotUnifyBoundingBoxDiagonal() */ void MovePlugin::updateManipulatorDialog() { - if(!propsWindow_->isHidden()) { - - BaseObjectData* object; - if ( PluginFunctions::getObject(lastActiveManipulator_ , object) ) { - if ( object->manipulatorNode()->visible() ) { - const TriMesh::Point pos = object->manipulatorNode()->center(); - - QString num; - - num = QString::number(pos[0]); propsWindow_->posx->setText(num); - num = QString::number(pos[1]); propsWindow_->posy->setText(num); - num = QString::number(pos[2]); propsWindow_->posz->setText(num); - - TriMesh::Point direction = object->manipulatorNode()->directionX(); - num = QString::number(direction[0]); propsWindow_->dirxx->setText(num); - num = QString::number(direction[1]); propsWindow_->dirxy->setText(num); - num = QString::number(direction[2]); propsWindow_->dirxz->setText(num); - - direction = object->manipulatorNode()->directionY(); - num = QString::number(direction[0]); propsWindow_->diryx->setText(num); - num = QString::number(direction[1]); propsWindow_->diryy->setText(num); - num = QString::number(direction[2]); propsWindow_->diryz->setText(num); + BaseObjectData* object; + if ( !PluginFunctions::getObject(lastActiveManipulator_ , object) ) { + return; + } + + if ( object->manipulatorNode()->visible() ) { + + // Get properties widget that corresponds to + // to the last manipulated object + movePropsWidget* pW = getDialogWidget(object); + + // If there's no properties dialog yet... + if(pW == 0) return; + + const TriMesh::Point pos = object->manipulatorNode()->center(); + + QString num; + + num = QString::number(pos[0]); pW->posx->setText(num); + num = QString::number(pos[1]); pW->posy->setText(num); + num = QString::number(pos[2]); pW->posz->setText(num); + + TriMesh::Point direction = object->manipulatorNode()->directionX(); + num = QString::number(direction[0]); pW->dirxx->setText(num); + num = QString::number(direction[1]); pW->dirxy->setText(num); + num = QString::number(direction[2]); pW->dirxz->setText(num); + + direction = object->manipulatorNode()->directionY(); + num = QString::number(direction[0]); pW->diryx->setText(num); + num = QString::number(direction[1]); pW->diryy->setText(num); + num = QString::number(direction[2]); pW->diryz->setText(num); + + direction = object->manipulatorNode()->directionZ(); + num = QString::number(direction[0]); pW->dirzx->setText(num); + num = QString::number(direction[1]); pW->dirzy->setText(num); + num = QString::number(direction[2]); pW->dirzz->setText(num); - direction = object->manipulatorNode()->directionZ(); - num = QString::number(direction[0]); propsWindow_->dirzx->setText(num); - num = QString::number(direction[1]); propsWindow_->dirzy->setText(num); - num = QString::number(direction[2]); propsWindow_->dirzz->setText(num); - - } - } } } +//------------------------------------------------------------------------------ +/** \brief Get pointer to corresponding dialog widget + * + * @param _obj the object to which the dialog is attached + */ +movePropsWidget* MovePlugin::getDialogWidget(BaseObjectData* _obj) { + + for(QList<movePropsWidget*>::iterator it = propsWindows_.begin(); + it != propsWindows_.end(); it++) { + if ((*it)->getBaseObjectData() == _obj) + return *it; + } + return 0; +} //------------------------------------------------------------------------------ /** \brief Called by Toolbar to enable move mode diff --git a/MovePlugin.hh b/MovePlugin.hh index 13cc309292403e96ed2332cc594cbc9d172e7d09..9a0d772843b8788127bd6672f254edd966e81195 100644 --- a/MovePlugin.hh +++ b/MovePlugin.hh @@ -298,10 +298,13 @@ class MovePlugin : public QObject, BaseInterface, MouseInterface, PickingInterfa /// Show properties of move manipulator in a dialog void showProps( ); + movePropsWidget* getDialogWidget(BaseObjectData* _obj); + movePropsWidget* getDialogFromButton(QPushButton* _but); private: /// Move context menu QMenu* contextMenu_; + QList<movePropsWidget*> propsWindows_; movePropsWidget* propsWindow_; QAction* lastAction_; diff --git a/MoveProps.cc b/MoveProps.cc index f01ed0ec136298a33e2bfecb1c2a6576f32c0aaf..7e5c4856215fd5907501566c7e49ac35c65e1e70 100644 --- a/MoveProps.cc +++ b/MoveProps.cc @@ -32,8 +32,8 @@ #include "MoveProps.hh" #include <QtGui> -movePropsWidget::movePropsWidget(QWidget *parent) - : QWidget(parent) +movePropsWidget::movePropsWidget(BaseObjectData* obj, QWidget *parent) + : QWidget(parent), obd(obj) { setupUi(this); } \ No newline at end of file diff --git a/MoveProps.hh b/MoveProps.hh index ba56c69219d671d18c275a94e92384bc1eca4b2a..083acadf383ebf9546a77d1d5643fc5bc3943350 100644 --- a/MoveProps.hh +++ b/MoveProps.hh @@ -32,11 +32,20 @@ #include "ui_setProps.hh" #include <QtGui> +#include <OpenFlipper/BasePlugin/PluginFunctions.hh> + class movePropsWidget : public QWidget, public Ui::setProps { Q_OBJECT public: - movePropsWidget(QWidget *parent = 0); + movePropsWidget(BaseObjectData* obj, QWidget *parent = 0); + + BaseObjectData* getBaseObjectData() { return obd; }; + + private: + + BaseObjectData* obd; + };