Commit 9239dd8a authored by Mike Kremer's avatar Mike Kremer

Added conversion of selection types (vertex, edge and face selections) to Selection-Plugin.

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@6466 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 316c355b
This diff is collapsed.
......@@ -12,12 +12,12 @@
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
//
// OpenFlipper 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 Lesser General Public License for more details.
//
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenFlipper. If not, see <http://www.gnu.org/licenses/>.
//
......@@ -44,7 +44,7 @@
/*! \file MeshSelection.hh
\brief Functions for selection on a mesh
*/
//== INCLUDES =================================================================
......@@ -62,21 +62,21 @@ namespace MeshSelection {
//===========================================================================
/** @name Vertex Selection
* @{ */
//===========================================================================
//===========================================================================
/// Select given vertices of a mesh
template< typename MeshT >
inline
void selectVertices(MeshT* _mesh, std::vector< int >& _vertices);
inline
void selectVertices(MeshT* _mesh, std::vector< int >& _vertices);
/// Unselect given vertices of a mesh
template< typename MeshT >
inline
void unselectVertices(MeshT* _mesh, std::vector< int >& _vertices);
inline
void unselectVertices(MeshT* _mesh, std::vector< int >& _vertices);
/// Select all vertices of a mesh
template< typename MeshT >
inline
inline
void selectAllVertices(MeshT* _mesh);
/// Set all vertices to unselected
......@@ -86,98 +86,114 @@ void clearVertexSelection(MeshT* _mesh);
/// invert vertex selection
template< typename MeshT >
inline
inline
void invertVertexSelection(MeshT* _mesh);
/** Select all vertices of the mesh which are boundary vertices
*/
template< typename MeshT >
inline
void selectBoundaryVertices(MeshT* _mesh);
/** shrink the vertex selection
/** shrink the vertex selection
*/
template< typename MeshT >
inline
inline
void shrinkVertexSelection(MeshT* _mesh) ;
/** grow the vertex selection
/** grow the vertex selection
*/
template< typename MeshT >
inline
inline
void growVertexSelection(MeshT* _mesh);
/** Get the current vertex selection
*/
template< typename MeshT >
inline
inline
std::vector< int > getVertexSelection(MeshT* _mesh);
/** Get the current vertex selection
/** Get the current vertex selection
* @param _invert if true : vector has been inverted to save mem
*/
template< typename MeshT >
inline
inline
std::vector< int > getVertexSelection(MeshT* _mesh, bool& _invert);
/** Get the vertices connected to a given boundary edge
* @param _vh handle of a boundary-edge
*/
template< typename MeshT >
inline
inline
void selectBoundaryVertices(MeshT* _mesh, typename MeshT::VertexHandle& _vh);
/** @} */
/**
* Select for each vertex in _vertices all incident edges
* @param _vertices List of vertices to be converted
*/
template< typename MeshT >
inline
void convertVertexToEdgeSelection(MeshT* _mesh, std::vector< int >& _vertices);
/**
* Select for each vertex in _vertices all adjacent faces
* @param _vertices List of vertices to be converted
*/
template< typename MeshT >
inline
void convertVertexToFaceSelection(MeshT* _mesh, std::vector< int >& _vertices);
/** @} */
//===========================================================================
/** @name Modeling Regions
* @{ */
//===========================================================================
//===========================================================================
/** Set the area bit for all defined vertices
* @param _vertices The vertices belonging to the modeling area
* @param _type Bit to be changed ( Normally Modeling area is OpenMesh::Attributes::UNUSED << 1 )
* */
template< typename MeshT >
inline
void setArea(MeshT* _mesh, std::vector< int >& _vertices , unsigned int _type, bool _state);
inline
void setArea(MeshT* _mesh, std::vector< int >& _vertices , unsigned int _type, bool _state);
/** Reset Modeling Status for vertices
*
*
* */
template< typename MeshT >
inline
inline
void setArea(MeshT* _mesh , unsigned int _type, bool _state);
/** Get the current vertex selection
*/
template< typename MeshT >
inline
inline
std::vector< int > getArea(MeshT* _mesh, unsigned int _type);
/** Get the current vertex selection
/** Get the current vertex selection
* @param _invert if true : vector has been inverted to save mem
*/
template< typename MeshT >
inline
inline
std::vector< int > getArea(MeshT* _mesh, unsigned int _type , bool& _invert);
/** @} */
/** @} */
//===========================================================================
/** @name Edge Selection
* @{ */
//===========================================================================
//===========================================================================
/// Select given edges of a mesh
template< typename MeshT >
inline
void selectEdges(MeshT* _mesh, std::vector< int >& _edges);
inline
void selectEdges(MeshT* _mesh, std::vector< int >& _edges);
/// Unselect given edges of a mesh
template< typename MeshT >
inline
void unselectEdges(MeshT* _mesh, std::vector< int >& _edges);
inline
void unselectEdges(MeshT* _mesh, std::vector< int >& _edges);
/// Select all edges of a mesh
template< typename MeshT >
......@@ -191,7 +207,7 @@ void clearEdgeSelection(MeshT* _mesh);
/// Invert Edge selection
template< typename MeshT >
inline
inline
void invertEdgeSelection(MeshT* _mesh);
/// Select all boundary edges of a mesh
......@@ -201,22 +217,39 @@ void selectBoundaryEdges(MeshT* _mesh);
/** Get the current edge selection
*/
template< typename MeshT >
inline
inline
std::vector< int > getEdgeSelection(MeshT* _mesh);
/** Get the current edge selection
/** Get the current edge selection
* @param _invert if true : vector has been inverted to save mem
*/
template< typename MeshT >
inline
inline
std::vector< int > getEdgeSelection(MeshT* _mesh, bool& _invert);
/** @} */
/**
* Select for each edge in _edges all incident vertices
* @param _edges List of edges to be converted
*/
template< typename MeshT >
inline
void convertEdgeToVertexSelection(MeshT* _mesh, std::vector< int >& _edges);
/**
* Select for each edge in _edges all adjacent faces
* @param _edges List of edges to be converted
*/
template< typename MeshT >
inline
void convertEdgeToFaceSelection(MeshT* _mesh, std::vector< int >& _edges);
/** @} */
//===========================================================================
/** @name Face Selection
* @{ */
//===========================================================================
//===========================================================================
/// Select given faces of a mesh
template< typename MeshT >
......@@ -240,46 +273,61 @@ void clearFaceSelection(MeshT* _mesh);
/// Invert face selection
template< typename MeshT >
inline
inline
void invertFaceSelection(MeshT* _mesh);
/// Select all boundary faces of a mesh
template< typename MeshT >
void selectBoundaryFaces(MeshT* _mesh);
/** \brief Shrink Face selection
*
*
* Deselects all faces which are adjacent to a boundary vertex of the original selection
*/
template< typename MeshT >
inline
inline
void shrinkFaceSelection(MeshT* _mesh);
/** \brief Grow Face selection
*
*
* Selects all faces which are adjacent to a vertex of a already selected face.
*/
template< typename MeshT >
inline
inline
void growFaceSelection(MeshT* _mesh);
/** Get the current face selection
*/
template< typename MeshT >
inline
inline
std::vector< int > getFaceSelection(MeshT* _mesh);
/** Get the current face selection
/** Get the current face selection
* @param _invert if true : vector has been inverted to save mem
*/
template< typename MeshT >
inline
inline
std::vector< int > getFaceSelection(MeshT* _mesh, bool& _invert);
/** @} */
/**
* Select for each face in _faces all adjacent vertices
* @param _faces List of faces to be converted
*/
template< typename MeshT >
inline
void convertFaceToVertexSelection(MeshT* _mesh, std::vector< int >& _faces);
/**
* Select for each face in _faces all adjacent edges
* @param _faces List of faces to be converted
*/
template< typename MeshT >
inline
void convertFaceToEdgeSelection(MeshT* _mesh, std::vector< int >& _faces);
/** @} */
//=============================================================================
} // MeshSelection Namespace
} // MeshSelection Namespace
//=============================================================================
#if defined(INCLUDE_TEMPLATES) && !defined(MESHSELECTION_C)
#define MESHSELECTION_TEMPLATES
......
......@@ -271,7 +271,7 @@ void SelectionPlugin::pluginsInitialized() {
*
* @param _id object-id of changed object
*/
void SelectionPlugin::slotObjectUpdated(int _id){
void SelectionPlugin::slotObjectUpdated(int /*_id*/){
#ifdef ENABLE_POLYLINE_SUPPORT
if (waitingForPolyLineSelection_){
......@@ -335,6 +335,18 @@ bool SelectionPlugin::initializeToolbox(QWidget*& _widget)
// Convert button
connect(tool_->convertButton, SIGNAL(clicked()), this, SLOT(slotConvertSelectionType()));
// Set combo box entries for the different selection types
tool_->convertSelectionFrom->addItem("Vertex Selection");
tool_->convertSelectionFrom->addItem("Edge Selection");
tool_->convertSelectionFrom->addItem("Face Selection");
tool_->convertSelectionTo->addItem("Vertex Selection");
tool_->convertSelectionTo->addItem("Edge Selection");
tool_->convertSelectionTo->addItem("Face Selection");
// Convert button
connect(tool_->convertSelectionButton, SIGNAL(clicked()), this, SLOT(slotConvertSelection()));
connect (tool_->restrictOnTargets, SIGNAL(clicked()), this, SLOT(slotToggleSelectionRestriction()) );
//Selection Buttons
......@@ -930,12 +942,12 @@ void SelectionPlugin::slotConvertSelectionType() {
// Default: Modeling Area
from = to = AREA;
if(tool_->convertFrom->currentText() == "Handle Region") {
if(tool_->convertFrom->currentText() == tr("Handle Region")) {
from = HANDLEAREA;
}
// Feature still to be implemented
else if(tool_->convertTo->currentText() == "Handle Region") {
else if(tool_->convertTo->currentText() == tr("Handle Region")) {
to = HANDLEAREA;
}
// Feature still to be implemented
......@@ -943,6 +955,36 @@ void SelectionPlugin::slotConvertSelectionType() {
convertSelectionType(from, to);
}
//******************************************************************************
void SelectionPlugin::slotConvertSelection() {
QString from, to;
from = tool_->convertSelectionFrom->currentText();
to = tool_->convertSelectionTo->currentText();
if(from == tr("Vertex Selection") && to == tr("Edge Selection")) {
convertVtoESelection();
}
else if(from == tr("Vertex Selection") && to == tr("Face Selection")) {
convertVtoFSelection();
}
else if(from == tr("Edge Selection") && to == tr("Vertex Selection")) {
convertEtoVSelection();
}
else if(from == tr("Edge Selection") && to == tr("Face Selection")) {
convertEtoFSelection();
}
else if(from == tr("Face Selection") && to == tr("Vertex Selection")) {
convertFtoVSelection();
}
else if(from == tr("Face Selection") && to == tr("Edge Selection")) {
convertFtoESelection();
}
}
//******************************************************************************
void SelectionPlugin::convertSelectionType(StatusBits from, StatusBits to) {
......@@ -987,6 +1029,182 @@ void SelectionPlugin::convertSelectionType(StatusBits from, StatusBits to) {
//******************************************************************************
void SelectionPlugin::convertVtoESelection(bool _unselectAfter) {
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) {
idList list = getVertexSelection(o_it->id());
if(_unselectAfter) { clearVertexSelection(o_it->id()); }
if ( o_it->dataType() == DATA_TRIANGLE_MESH ) {
MeshSelection::convertVertexToEdgeSelection(PluginFunctions::triMesh(o_it), list);
}
else if ( o_it->dataType() == DATA_POLY_MESH ) {
MeshSelection::convertVertexToEdgeSelection(PluginFunctions::polyMesh(o_it), list);
}
o_it->update();
}
emit updateView();
}
void SelectionPlugin::convertVtoFSelection(bool _unselectAfter) {
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) {
idList list = getVertexSelection(o_it->id());
if(_unselectAfter) { clearVertexSelection(o_it->id()); }
if ( o_it->dataType() == DATA_TRIANGLE_MESH ) {
MeshSelection::convertVertexToFaceSelection(PluginFunctions::triMesh(o_it), list);
}
else if ( o_it->dataType() == DATA_POLY_MESH ) {
MeshSelection::convertVertexToFaceSelection(PluginFunctions::polyMesh(o_it), list);
}
o_it->update();
}
emit updateView();
}
void SelectionPlugin::convertEtoVSelection(bool _unselectAfter) {
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) {
idList list = getEdgeSelection(o_it->id());
if(_unselectAfter) { clearEdgeSelection(o_it->id()); }
if ( o_it->dataType() == DATA_TRIANGLE_MESH ) {
MeshSelection::convertEdgeToVertexSelection(PluginFunctions::triMesh(o_it), list);
}
else if ( o_it->dataType() == DATA_POLY_MESH ) {
MeshSelection::convertEdgeToVertexSelection(PluginFunctions::polyMesh(o_it), list);
}
o_it->update();
}
emit updateView();
}
void SelectionPlugin::convertEtoFSelection(bool _unselectAfter) {
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) {
idList list = getEdgeSelection(o_it->id());
if(_unselectAfter) { clearEdgeSelection(o_it->id()); }
if ( o_it->dataType() == DATA_TRIANGLE_MESH ) {
MeshSelection::convertEdgeToFaceSelection(PluginFunctions::triMesh(o_it), list);
}
else if ( o_it->dataType() == DATA_POLY_MESH ) {
MeshSelection::convertEdgeToFaceSelection(PluginFunctions::polyMesh(o_it), list);
}
o_it->update();
}
emit updateView();
}
void SelectionPlugin::convertFtoVSelection(bool _unselectAfter) {
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) {
idList list = getFaceSelection(o_it->id());
if(_unselectAfter) { clearFaceSelection(o_it->id()); }
if ( o_it->dataType() == DATA_TRIANGLE_MESH ) {
MeshSelection::convertFaceToVertexSelection(PluginFunctions::triMesh(o_it), list);
}
else if ( o_it->dataType() == DATA_POLY_MESH ) {
MeshSelection::convertFaceToVertexSelection(PluginFunctions::polyMesh(o_it), list);
}
o_it->update();
}
emit updateView();
}
void SelectionPlugin::convertFtoESelection(bool _unselectAfter) {
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) {
idList list = getFaceSelection(o_it->id());
if(_unselectAfter) { clearFaceSelection(o_it->id()); }
if ( o_it->dataType() == DATA_TRIANGLE_MESH ) {
MeshSelection::convertFaceToEdgeSelection(PluginFunctions::triMesh(o_it), list);
}
else if ( o_it->dataType() == DATA_POLY_MESH ) {
MeshSelection::convertFaceToEdgeSelection(PluginFunctions::polyMesh(o_it), list);
}
o_it->update();
}
emit updateView();
}
//******************************************************************************
void SelectionPlugin::saveSelections()
{
// process all target meshes
......
......@@ -336,9 +336,12 @@ class SelectionPlugin : public QObject, BaseInterface , MouseInterface, KeyInter
/// Save the current selection
void slotSaveSelection();
/// Convert selection types (modeling area, handle region or feature
/// Convert selection types (modeling area, handle region or feature)
void slotConvertSelectionType();
/// Convert selection types (vertex, edge or face selection)
void slotConvertSelection();
/** @} */
......@@ -488,9 +491,36 @@ class SelectionPlugin : public QObject, BaseInterface , MouseInterface, KeyInter
//======================================================
/// Convert selection types (modeling area, handle region or feature
/// Convert selection types (modeling area, handle region or feature)
void convertSelectionType(StatusBits from, StatusBits to);
/// Convert selections (vertex, edge, face)
void convertSelection();
/// Select for each selected vertex the incident edges and
/// unselect vertices after (if _unselectAfter = true)
void convertVtoESelection(bool _unselectAfter = true);
/// Select for each selected vertex the adjacent faces and
/// unselect vertices after (if _unselectAfter = true)
void convertVtoFSelection(bool _unselectAfter = true);
/// Select for each selected edge the adjacent vertices and
/// unselect the edges after (if _unselectAfter = true)
void convertEtoVSelection(bool _unselectAfter = true);
/// Select for each selected edge the two adjacent faces and
/// unselect the edges after (if _unselectAfter = true)
void convertEtoFSelection(bool _unselectAfter = true);
/// Select for each selected face the adjacent vertices and
/// unselect the face after (if _unselectAfter = true)
void convertFtoVSelection(bool _unselectAfter = true);
/// Select for each selected face the adjacent edges and
/// unselect the face after (if _unselectAfter = true)
void convertFtoESelection(bool _unselectAfter = true);
/** @} */
//===========================================================================
......
......@@ -13,8 +13,8 @@
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<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 @@