Commit 0754fcf3 authored by Dirk Wilden's avatar Dirk Wilden
Browse files

colorize selections

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@6811 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 0c00d268
......@@ -305,7 +305,5 @@ idList SelectionPlugin::getEdgeSelection( int objectId )
}
......@@ -280,7 +280,33 @@ idList SelectionPlugin::getFaceSelection( int objectId )
}
}
}
//=========================================================
/// colorize the face selection
void SelectionPlugin::colorizeFaceSelection(int objectId, int r, int g, int b )
{
BaseObjectData* object;
if ( ! PluginFunctions::getObject(objectId,object) ) {
emit log(LOGERR,"colorizeFaceSelection : unable to get object" );
return;
}
if ( object->dataType() == DATA_TRIANGLE_MESH )
colorizeSelection(PluginFunctions::triMesh(object), FACE, r, g, b);
else if ( object->dataType() == DATA_POLY_MESH )
colorizeSelection(PluginFunctions::polyMesh(object), FACE, r, g, b);
else {
emit log(LOGERR,"colorizeFaceSelection : Unsupported object Type" );
return;
}
object->update();
emit scriptInfo( "colorizeFaceSelection( ObjectId, "
+ QString::number(r) + ", " + QString::number(g) + ", " + QString::number(b) + " )" );
}
......@@ -43,6 +43,7 @@
#include "SelectionPlugin.hh"
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
#include <QColorDialog>
//***********************************************************************************
......@@ -70,6 +71,8 @@ void SelectionPlugin::selectionContextMenu(QAction* _action) {
growSelection( objectId );
else if ( _action->text() == tr("Boundary"))
selectBoundary( objectId );
else if ( _action->text() == "Colorize")
colorizeSelection( objectId );
emit updatedObject(objectId);
}
......@@ -156,4 +159,25 @@ void SelectionPlugin::selectBoundary( int objectID ){
if (selectionType_ & FACE)
selectBoundaryFaces( objectID );
}
\ No newline at end of file
}
//***********************************************************************************
void SelectionPlugin::colorizeSelection( int objectID ){
if (selectionType_ & EDGE){
emit log(LOGERR, "Edge coloring not supported.");
return;
}
QColor color = QColorDialog::getColor();
if ( color.isValid() ){
if (selectionType_ & VERTEX)
colorizeVertexSelection( objectID, color.red(), color.green(), color.blue() );
if (selectionType_ & FACE)
colorizeFaceSelection( objectID, color.red(), color.green(), color.blue() );
}
}
......@@ -155,11 +155,10 @@ void SelectionPlugin::paintSphereSelection(QMouseEvent* _event) {
/// Hide sphere, otherwise it might get picked
sphere_node_->hide();
if (PluginFunctions::scenegraphPick(ACG::SceneGraph::PICK_FACE, _event->pos(),node_idx, target_idx, &hit_point)) {
if (PluginFunctions::scenegraphPick(ACG::SceneGraph::PICK_ANYTHING, _event->pos(),node_idx, target_idx, &hit_point)) {
BaseObjectData* object;
if ( PluginFunctions::getPickedObject(node_idx, object) ) {
sphere_node_->show();
sphere_node_->set_position((ACG::Vec3f)hit_point);
sphere_node_->set_size(sphere_radius_);
......
......@@ -183,6 +183,9 @@ void SelectionPlugin::pluginsInitialized() {
lastAction->setToolTip(tr("Select the boundary of the object"));
lastAction->setStatusTip( lastAction->toolTip() );
lastAction = contextMenu_->addAction( "Colorize" );
lastAction->setToolTip("Change the color of selected elements.");
lastAction->setStatusTip( lastAction->toolTip() );
emit addContextMenuItem(contextMenu_->menuAction() , DATA_TRIANGLE_MESH , CONTEXTOBJECTMENU );
emit addContextMenuItem(contextMenu_->menuAction() , DATA_POLY_MESH , CONTEXTOBJECTMENU );
......@@ -373,6 +376,8 @@ bool SelectionPlugin::initializeToolbox(QWidget*& _widget)
connect( tool_->deleteSelection, SIGNAL(clicked()), this,SLOT(slotDeleteSelection()) );
connect( tool_->colorizeSelection,SIGNAL(clicked()), this,SLOT(slotColorizeSelection()) );
connect( tool_->loadSelection, SIGNAL(clicked()), this,SLOT(slotLoadSelection()) );
connect( tool_->saveSelection, SIGNAL(clicked()), this,SLOT(slotSaveSelection()) );
......@@ -556,6 +561,7 @@ void SelectionPlugin::toolBarActionClicked(QAction * _action)
if ( objectAction_->isChecked() ){
type = type | OBJECT;
if ( PluginFunctions::actionMode() == Viewer::ExamineMode )
toolBarActionClicked( toggleAction_ ); //automatically switch to toggle
}if ( vertexAction_->isChecked() )
......@@ -576,6 +582,7 @@ void SelectionPlugin::toolBarActionClicked(QAction * _action)
connectedAction_->setEnabled( !objectAction_->isChecked() );
}else{
//first check if a selection type was set
if (selectionType_ == 0){
emit log(LOGERR,tr("Choose at least one selection type first."));
......
......@@ -232,6 +232,10 @@ class SelectionPlugin : public QObject, BaseInterface , MouseInterface, KeyInter
template< typename MeshT >
bool deleteSelection(MeshT* _mesh);
/// Colorize a selection
template< typename MeshT >
void colorizeSelection(MeshT* _mesh, SelectionPrimitive _type, int _red, int _green, int _blue);
/// when SHIFT key is pressed do source-selection instead of target selection in object-mode
bool sourceSelection_;
......@@ -349,6 +353,9 @@ class SelectionPlugin : public QObject, BaseInterface , MouseInterface, KeyInter
/// Convert selection types (modeling area, handle region or feature)
void slotConvertSelectionType();
/// Colorize given selection
void slotColorizeSelection();
//==========================================
/// clear all vertex selections of every object
......@@ -402,6 +409,9 @@ class SelectionPlugin : public QObject, BaseInterface , MouseInterface, KeyInter
/// delete vertices and faces that are currently selected
void deleteSelection( int objectId );
/// colorize the vertex selection
void colorizeVertexSelection(int objectId, int r, int g, int b );
//==========================================
/// Set vertices to be part of the handle area
......@@ -494,6 +504,9 @@ class SelectionPlugin : public QObject, BaseInterface , MouseInterface, KeyInter
/// return a list of all selected faces
idList getFaceSelection( int objectId );
/// colorize the face selection
void colorizeFaceSelection(int objectId, int r, int g, int b );
/// save Selections into File
void saveSelections();
......@@ -654,6 +667,9 @@ class SelectionPlugin : public QObject, BaseInterface , MouseInterface, KeyInter
/// select the boundary of the giben object
void selectBoundary ( int objectId );
/// choose a color and colorize the selection
void colorizeSelection(int objectId );
/** @} */
public slots:
......
......@@ -373,4 +373,39 @@ bool SelectionPlugin::deleteSelection(MeshT* _mesh) {
return changed;
}
//-----------------------------------------------------------------------------
/** \brief Colorize a selection
*
* @param _mesh a mesh
* @param _type selection type
* @param _red rgb color
* @param _green rgb color
* @param _blue rgb color
*/
template< typename MeshT >
void SelectionPlugin::colorizeSelection(MeshT* _mesh, SelectionPrimitive _type, int _red, int _green, int _blue) {
typename MeshT::Color color;
color[0] = _red;
color[1] = _green;
color[2] = _blue;
if (_type & VERTEX){
typename MeshT::VertexIter v_it, v_end=_mesh->vertices_end();
for (v_it=_mesh->vertices_begin(); v_it!=v_end; ++v_it)
if ( _mesh->status(v_it).selected() )
_mesh->set_color(v_it, color);
}
if (_type & FACE){
typename MeshT::FaceIter f_it, f_end( _mesh->faces_end() );
for (f_it=_mesh->faces_begin(); f_it!=f_end; ++f_it)
if ( _mesh->status(f_it).selected() )
_mesh->set_color(f_it, color);
}
}
......@@ -385,6 +385,30 @@ void SelectionPlugin::deleteSelection( int objectId )
emit scriptInfo( "deleteSelection( ObjectId )" );
}
//=========================================================
/// colorize the vertex selection
void SelectionPlugin::colorizeVertexSelection(int objectId, int r, int g, int b )
{
BaseObjectData* object;
if ( ! PluginFunctions::getObject(objectId,object) ) {
emit log(LOGERR,"colorizeVertexSelection : unable to get object" );
return;
}
if ( object->dataType() == DATA_TRIANGLE_MESH )
colorizeSelection(PluginFunctions::triMesh(object), VERTEX, r, g, b);
else if ( object->dataType() == DATA_POLY_MESH )
colorizeSelection(PluginFunctions::polyMesh(object), VERTEX, r, g, b);
else {
emit log(LOGERR,"colorizeVertexSelection : Unsupported object Type" );
return;
}
object->update();
emit scriptInfo( "colorizeVertexSelection( ObjectId, "
+ QString::number(r) + ", " + QString::number(g) + ", " + QString::number(b) + " )" );
}
......@@ -182,6 +182,26 @@ void SelectionPlugin::slotGrowSelection() {
}
//-----------------------------------------------------------------------------
/** \brief Colorize the selection of each (target) object
*
*/
void SelectionPlugin::slotColorizeSelection() {
PluginFunctions::IteratorRestriction restriction;
if ( !tool_->restrictOnTargets->isChecked() )
restriction = PluginFunctions::ALL_OBJECTS;
else
restriction = PluginFunctions::TARGET_OBJECTS;
for ( PluginFunctions::ObjectIterator o_it(restriction,DataType( DATA_TRIANGLE_MESH | DATA_POLY_MESH )) ;
o_it != PluginFunctions::objectsEnd(); ++o_it)
if ( o_it->visible() )
colorizeSelection( o_it->id() );
emit updateView();
}
//-----------------------------------------------------------------------------
/** \brief load a selection from ini file
......
......@@ -6,15 +6,15 @@
<rect>
<x>0</x>
<y>0</y>
<width>345</width>
<width>362</width>
<height>688</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string> Selection Mode </string>
......@@ -167,7 +167,7 @@
</layout>
</widget>
</item>
<item row="1" column="0">
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string> Selection </string>
......@@ -252,6 +252,13 @@
</widget>
</item>
<item row="3" column="0">
<widget class="QPushButton" name="colorizeSelection">
<property name="text">
<string>Colorize</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QPushButton" name="deleteSelection">
<property name="toolTip">
<string>Delete selection on all (target) objects</string>
......@@ -264,21 +271,21 @@
</property>
</widget>
</item>
<item row="4" column="0">
<item row="5" column="0">
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="4" column="1">
<item row="5" column="1">
<widget class="Line" name="line_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="5" column="0">
<item row="6" column="0">
<widget class="QPushButton" name="loadSelection">
<property name="toolTip">
<string>Load current selection from file</string>
......@@ -291,7 +298,7 @@
</property>
</widget>
</item>
<item row="5" column="1">
<item row="6" column="1">
<widget class="QPushButton" name="saveSelection">
<property name="toolTip">
<string>Save current selection to file</string>
......@@ -307,7 +314,7 @@
</layout>
</widget>
</item>
<item row="2" column="0">
<item>
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string> Mesh Properties </string>
......
Supports Markdown
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