Commit f9d8e470 authored by Jan Möbius's avatar Jan Möbius
Browse files

Added scripting function to select vertices based on the value of one of their components

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@14331 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 628519b9
...@@ -265,6 +265,10 @@ void MeshObjectSelectionPlugin::updateSlotDescriptions() { ...@@ -265,6 +265,10 @@ void MeshObjectSelectionPlugin::updateSlotDescriptions() {
emit setSlotDescription("createMeshFromVertexSelection(int)", tr("Take vertex selection and create a new mesh from it"), emit setSlotDescription("createMeshFromVertexSelection(int)", tr("Take vertex selection and create a new mesh from it"),
QString("objectId").split(","), QString("Id of an object where the selection should be used to create a new mesh").split(",")); QString("objectId").split(","), QString("Id of an object where the selection should be used to create a new mesh").split(","));
emit setSlotDescription("selectVerticesByValue(int,QString,bool,double)", tr("Select vertices based on the value of their component"),
QString("objectId,component,greater,value").split(","),
QString("Id of an object where the selection should be used to create a new mesh,component specification: \"x\" or \"y\" or \"z\" ,true: select vertex if component greater than value; false: select if component less than value ,value to test").split(","));
emit setSlotDescription("colorizeVertexSelection(int,int,int,int)", tr("Colorize the selected vertices"), emit setSlotDescription("colorizeVertexSelection(int,int,int,int)", tr("Colorize the selected vertices"),
QString("objectId,r,g,b").split(","), QString("Id of an object,Red,Green,Blue").split(",")); QString("objectId,r,g,b").split(","), QString("Id of an object,Red,Green,Blue").split(","));
emit setSlotDescription("selectHandleVertices(int,IdList)", tr("Add specified vertices to handle area"), emit setSlotDescription("selectHandleVertices(int,IdList)", tr("Add specified vertices to handle area"),
......
...@@ -305,6 +305,9 @@ public slots: ...@@ -305,6 +305,9 @@ public slots:
/// Remove vertices from modeling area /// Remove vertices from modeling area
void unselectModelingVertices(int objectId, IdList _vertexList); void unselectModelingVertices(int objectId, IdList _vertexList);
/// Select vertices by their value
void selectVerticesByValue(int _objectId, QString _component, bool _greater, double _value );
/// Clear Modeling Area /// Clear Modeling Area
void clearModelingVertices(int objectId); void clearModelingVertices(int objectId);
...@@ -489,6 +492,10 @@ private: ...@@ -489,6 +492,10 @@ private:
template< class MeshT > template< class MeshT >
void createMeshFromSelection( MeshT& _mesh, MeshT& _newMesh, PrimitiveType _primitiveType); void createMeshFromSelection( MeshT& _mesh, MeshT& _newMesh, PrimitiveType _primitiveType);
/// Select vertices by value
template< class MeshT >
void selectVerticesByValue(MeshT* _mesh, QString _component, bool _greater, double _value);
/** @} */ /** @} */
//=========================================================================== //===========================================================================
......
...@@ -922,3 +922,37 @@ void MeshObjectSelectionPlugin::createMeshFromSelection(MeshT& _mesh, MeshT& _ne ...@@ -922,3 +922,37 @@ void MeshObjectSelectionPlugin::createMeshFromSelection(MeshT& _mesh, MeshT& _ne
} }
template<class MeshT>
void MeshObjectSelectionPlugin::selectVerticesByValue(MeshT* _mesh, QString _component, bool _greater, double _value)
{
//first copy vertices
typename MeshT::VertexIter v_it, v_end = _mesh->vertices_end();
for (v_it = _mesh->vertices_begin(); v_it != v_end; ++v_it) {
const typename MeshT::Point p = _mesh->point(v_it);
bool select = false;
if (_component.contains("x",Qt::CaseInsensitive) ) {
select = (p[0] > _value);
} else if (_component.contains("y",Qt::CaseInsensitive) ) {
select = (p[1] > _value);
} else if (_component.contains("z",Qt::CaseInsensitive) ) {
select = (p[2] > _value);
} else {
emit log(LOGERR,tr("selectVerticesByValue, undefined component ") + _component );
}
// invert if requested
if (! _greater )
select = !select;
// set selection status only if the vertex was previously unselected
if ( ! _mesh->status(v_it).selected() )
_mesh->status(v_it).set_selected(select);
}
}
...@@ -571,6 +571,31 @@ void MeshObjectSelectionPlugin::unselectModelingVertices(int _objectId, IdList _ ...@@ -571,6 +571,31 @@ void MeshObjectSelectionPlugin::unselectModelingVertices(int _objectId, IdList _
emit scriptInfo(selection); emit scriptInfo(selection);
} }
// =========================================================
void MeshObjectSelectionPlugin::selectVerticesByValue(int _objectId, QString _component, bool _greater, double _value ) {
BaseObjectData* object = 0;
if (!PluginFunctions::getObject(_objectId,object)) {
emit log(LOGERR,tr("selectVerticesByValue: unable to get object"));
return;
}
if (object->dataType() == DATA_TRIANGLE_MESH)
selectVerticesByValue(PluginFunctions::triMesh(object), _component, _greater, _value);
else if (object->dataType() == DATA_POLY_MESH)
selectVerticesByValue(PluginFunctions::polyMesh(object), _component, _greater, _value);
else{
emit log(LOGERR,tr("selectVerticesByValue: Unsupported object Type"));
return;
}
emit updatedObject(object->id(), UPDATE_SELECTION);
/// \todo emit scriptinfo
}
//========================================================= //=========================================================
void MeshObjectSelectionPlugin::clearModelingVertices(int _objectId) { void MeshObjectSelectionPlugin::clearModelingVertices(int _objectId) {
......
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