50 #include "MeshObjectSelectionPlugin.hh"
60 if(_vertexList.empty() )
return;
64 emit log(
LOGERR,tr(
"selectVertices: unable to get object"));
73 emit log(
LOGERR,tr(
"selectAllVertices: Unsupported object Type"));
77 QString selection =
"selectVertices(ObjectId(" + QString::number(_objectId) +
"), [ " + QString::number(_vertexList[0]);
79 for (uint i = 1 ; i < _vertexList.size(); ++i) {
80 selection +=
", " + QString::number(_vertexList[i]);
86 emit scriptInfo(selection);
93 if(_vertexList.empty() )
return;
97 emit log(
LOGERR,tr(
"unselectVertices: unable to get object"));
106 emit log(
LOGERR,tr(
"unselectVertices: Unsupported object Type"));
110 QString selection =
"unselectVertices(ObjectId(" + QString::number(_objectId) +
"), [ " + QString::number(_vertexList[0]);
112 for (uint i = 1 ; i < _vertexList.size(); ++i) {
113 selection +=
", " + QString::number(_vertexList[i]);
119 emit scriptInfo(selection);
130 emit log(
LOGERR,tr(
"selectAllVertices: unable to get object"));
139 emit log(
LOGERR,tr(
"selectAllVertices: Unsupported object Type"));
144 emit scriptInfo(
"selectAllVertices(ObjectId(" + QString::number(_objectId) +
"))");
153 emit log(
LOGERR,tr(
"clearVertexSelection: unable to get object"));
162 emit log(
LOGERR,tr(
"clearVertexSelection: Unsupported object Type"));
167 emit scriptInfo(
"clearVertexSelection(ObjectId(" + QString::number(_objectId) +
"))");
176 emit log(
LOGERR,tr(
"invertVertexSelection: unable to get object"));
185 emit log(
LOGERR,tr(
"invertVertexSelection: Unsupported object Type"));
190 emit scriptInfo(
"invertVertexSelection(ObjectId(" + QString::number(_objectId) +
"))");
199 emit log(
LOGERR,tr(
"selectBoundaryVertices: unable to get object"));
208 emit log(
LOGERR,tr(
"selectBoundaryVertices: Unsupported object Type"));
213 emit scriptInfo(
"selectBoundaryVertices(ObjectId(" + QString::number(_objectId) +
"))");
222 emit log(
LOGERR,tr(
"selectClosestBoundaryVertices: unable to get object"));
231 emit log(
LOGERR,tr(
"selectClosestBoundaryVertices: Unsupported object Type"));
236 emit scriptInfo(
"selectClosestBoundaryVertices(ObjectId(" + QString::number(_objectId) +
"), VertexId)");
245 emit log(
LOGERR,tr(
"shrinkVertexSelection: unable to get object"));
254 emit log(
LOGERR,tr(
"shrinkVertexSelection: Unsupported object Type"));
259 emit scriptInfo(
"shrinkVertexSelection(ObjectId(" + QString::number(_objectId) +
"))");
268 emit log(
LOGERR,tr(
"growVertexSelection: unable to get object"));
277 emit log(
LOGERR,tr(
"growVertexSelection: Unsupported object Type"));
282 emit scriptInfo(
"growVertexSelection(ObjectId(" + QString::number(_objectId) +
"))");
291 emit log(
LOGERR,tr(
"getVertexSelection: unable to get object"));
295 emit scriptInfo(
"getVertexSelection(ObjectId(" + QString::number(_objectId) +
"))");
302 emit log(
LOGERR,tr(
"getVertexSelection: Unsupported object Type"));
315 emit log(
LOGERR,tr(
"deleteVertexSelection: unable to get object"));
324 emit log(
LOGERR,tr(
"deleteVertexSelection: Unsupported object Type"));
329 emit scriptInfo(
"deleteVertexSelection(ObjectId(" + QString::number(_objectId) +
"))");
345 emit log(
LOGERR,
"colorizeVertexSelection: unable to get object");
354 emit log(
LOGERR,
"colorizeVertexSelection: Unsupported object Type");
358 emit scriptInfo(
"colorizeVertexSelection(ObjectId(" + QString::number(_objectId) +
"), "
359 + QString::number(r) +
", " + QString::number(g) +
", " + QString::number(b) +
")");
372 emit log(
LOGERR,tr(
"selectHandleVertices: unable to get object"));
376 if (_vertexList.empty() )
386 emit log(
LOGERR,tr(
"selectHandleVertices: Unsupported object Type"));
390 QString selection =
"selectHandleVertices(ObjectId(" + QString::number(_objectId) +
"), [ " + QString::number(_vertexList[0]);
392 for (uint i = 1 ; i < _vertexList.size(); ++i) {
393 selection +=
", " + QString::number(_vertexList[i]);
399 emit scriptInfo(selection);
406 if(_vertexList.empty())
return;
410 emit log(
LOGERR,tr(
"unselectHandleVertices: unable to get object"));
419 emit log(
LOGERR,tr(
"unselectHandleVertices: Unsupported object Type"));
423 QString selection =
"unselectHandleVertices(ObjectId(" + QString::number(_objectId) +
"), [ " + QString::number(_vertexList[0]);
425 for (uint i = 1 ; i < _vertexList.size(); ++i) {
426 selection +=
", " + QString::number(_vertexList[i]);
432 emit scriptInfo(selection);
441 emit log(
LOGERR,tr(
"clearHandleVertices: unable to get object"));
450 emit log(
LOGERR,tr(
"clearHandleVertices: Unsupported object Type"));
455 emit scriptInfo(
"clearHandleVertices(ObjectId(" + QString::number(_objectId) +
"))");
464 emit log(
LOGERR,tr(
"setAllHandleVertices: unable to get object"));
473 emit log(
LOGERR,tr(
"setAllHandleVertices: Unsupported object Type"));
478 emit scriptInfo(
"setAllHandleVertices(ObjectId(" + QString::number(_objectId) +
"))");
487 emit log(
LOGERR,tr(
"getHandleVertices: unable to get object"));
491 emit scriptInfo(
"getHandleVertices(ObjectId(" + QString::number(_objectId) +
"))");
498 emit log(
LOGERR,tr(
"getHandleVertices: Unsupported object Type"));
511 if(_vertexList.empty() )
return;
515 emit log(
LOGERR,tr(
"selectModelingVertices: unable to get object"));
526 emit log(
LOGERR,tr(
"selectModelingVertices: Unsupported object Type"));
530 QString selection =
"selectModelingVertices(ObjectId(" + QString::number(_objectId) +
"), [ " + QString::number(_vertexList[0]);
532 for (uint i = 1 ; i < _vertexList.size(); ++i) {
533 selection +=
", " + QString::number(_vertexList[i]);
539 emit scriptInfo(selection);
546 if(_vertexList.empty() )
return;
550 emit log(
LOGERR,tr(
"unselectModelingVertices: unable to get object"));
559 emit log(
LOGERR,tr(
"unselectModelingVertices: Unsupported object Type"));
563 QString selection =
"unselectModelingVertices(ObjectId(" + QString::number(_objectId) +
"), [ " + QString::number(_vertexList[0]);
565 for (uint i = 1 ; i < _vertexList.size(); ++i) {
566 selection +=
", " + QString::number(_vertexList[i]);
572 emit scriptInfo(selection);
580 emit log(
LOGERR,tr(
"selectVerticesByValue: unable to get object"));
589 emit log(
LOGERR,tr(
"selectVerticesByValue: Unsupported object Type"));
606 emit log(
LOGERR,tr(
"clearModelingVertices: unable to get object"));
615 emit log(
LOGERR,tr(
"clearModelingVertices: Unsupported object Type"));
620 emit scriptInfo(
"clearModelingVertices(ObjectId(" + QString::number(_objectId) +
"))");
629 emit log(
LOGERR,tr(
"setAllModelingVertices: unable to get object"));
638 emit log(
LOGERR,tr(
"setAllModelingVertices: Unsupported object Type"));
643 emit scriptInfo(
"setAllModelingVertices(ObjectId(" + QString::number(_objectId) +
"))");
650 emit log(
LOGERR,tr(
"getModelingVertices: unable to get object"));
654 emit scriptInfo(
"getModelingVertices(ObjectId(" + QString::number(_objectId) +
"))");
661 emit log(
LOGERR,tr(
"getModelingVertices: Unsupported object Type"));
672 QFile file(_filename);
674 if (!file.exists()) {
675 emit log(
LOGERR,tr(
"Unable to find file: ") + _filename);
679 if (file.open(QFile::ReadOnly)) {
681 QTextStream input(&file);
682 QString header = input.readLine();
684 if (!header.contains(
"Selection")) {
685 emit log(
LOGERR,tr(
"Wrong file header!should be Selection but is ") + header);
689 header = input.readLine();
692 uint vertexCount = header.toUInt(&ok);
695 emit log(
LOGERR,tr(
"Unable to parse header. Cant get vertex count from string: ") + header);
702 emit log(
LOGERR,tr(
"loadSelection: unable to get object"));
724 QStringList inputList = input.readLine().split(
" ");
726 if (inputList.size() != 2) {
727 emit log(
LOGERR,tr(
"Unable to parse entry at vertex index ") + QString::number(vertexId));
731 if (inputList[0] ==
"1")
732 modelingVertices.push_back(vertexId);
734 if (inputList[1] ==
"1")
735 handleVertices.push_back(vertexId);
739 }
while (!input.atEnd());
748 emit log(
LOGERR,tr(
"Unable to open selection file!"));
756 QFile file(_filename);
758 if (file.open(QFile::WriteOnly)) {
759 QTextStream input(&file);
764 emit log(
LOGERR,tr(
"saveFlipperModelingSelection: unable to get object"));
772 input <<
"Selection" << endl;
773 input << mesh->n_vertices() << endl;
775 std::vector< int > modelingVertices = MeshSelection::getArea(mesh, AREA);
776 std::vector< int > handleVertices = MeshSelection::getArea(mesh, HANDLEAREA);
778 std::vector< bool > modelingAll(mesh->n_vertices(),
false);
779 std::vector< bool > handleAll(mesh->n_vertices(),
false);
781 for (uint i=0; i < modelingVertices.size(); i++)
782 modelingAll[ modelingVertices[i] ] =
true;
784 for (uint i=0; i < handleVertices.size(); i++)
785 handleAll[ handleVertices[i] ] =
true;
787 for (uint i=0; i < mesh->n_vertices(); i++)
788 input << (
int) modelingAll[i] <<
" " << (int) handleAll[i] << endl;
795 input <<
"Selection" << endl;
796 input << mesh->n_vertices() << endl;
798 std::vector< int > modelingVertices = MeshSelection::getArea(mesh, AREA);
799 std::vector< int > handleVertices = MeshSelection::getArea(mesh, HANDLEAREA);
801 std::vector< bool > modelingAll(mesh->n_vertices(),
false);
802 std::vector< bool > handleAll(mesh->n_vertices(),
false);
804 for (uint i=0; i < modelingVertices.size(); i++)
805 modelingAll[ modelingVertices[i] ] =
true;
807 for (uint i=0; i < handleVertices.size(); i++)
808 handleAll[ handleVertices[i] ] =
true;
810 for (uint i=0; i < mesh->n_vertices(); i++)
811 input << (
int) modelingAll[i] <<
" " << (int) handleAll[i] << endl;
814 emit log(
LOGERR, tr(
"saveFlipperModelingSelection: Unsupported Type."));
817 emit log(
LOGERR,tr(
"Unable to open selection file!"));
void loadFlipperModelingSelection(int _objectId, QString _filename)
Load a selection from an Flipper selection file for the given object.
void colorizeSelection(MeshT *_mesh, PrimitiveType _primitiveTypes, int _red, int _green, int _blue, int _alpha)
Colorize the selection.
void selectHandleVertices(int objectId, IdList _vertexList)
Set vertices to be part of the handle area.
void selectBoundaryVertices(int _objectId)
Select all boundary vertices of the given object.
void setAllModelingVertices(int objectId)
Set all vertices to be part of the modeling area.
const UpdateType UPDATE_SELECTION_VERTICES(UpdateTypeSet(1)<< 5)
Vertex selection has changed.
bool deleteSelection(MeshT *_mesh, PrimitiveType _primitiveType)
Delete all selected elements of a mesh.
void unselectModelingVertices(int objectId, IdList _vertexList)
Remove vertices from modeling area.
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
bool getObject(int _identifier, BSplineCurveObject *&_object)
IdList getHandleVertices(int objectId)
Get a list of all handle vertices.
PolyMesh * polyMesh(BaseObjectData *_object)
Get a poly mesh from an object.
void createMeshFromSelection(MeshT &_mesh, MeshT &_newMesh, PrimitiveType _primitiveType)
Create a new mesh from the selection.
void selectModelingVertices(int objectId, IdList _vertexList)
Set vertices to be part of the modeling area.
void selectVerticesByValue(int _objectId, QString _component, bool _greater, double _value)
Select vertices by their value.
bool dataType(DataType _type) const
const UpdateType UPDATE_SELECTION(UpdateTypeSet(1)<< 4)
Selection updated.
void unselectHandleVertices(int objectId, IdList _vertexList)
Remove vertices from handle area.
TriMesh * triMesh(BaseObjectData *_object)
Get a triangle mesh from an object.
void setAllHandleVertices(int objectId)
Set all vertices to be part of the handle area.
void saveFlipperModelingSelection(int _objectId, QString _filename)
Save a selection in Flipper Selection Format.
std::vector< int > IdList
Standard Type for id Lists used for scripting.
void clearHandleVertices(int objectId)
Clear handle Area.
void unselectVertices(int objectId, IdList _vertexList)
unselect given vertices
void deleteVertexSelection(int _objectId)
Delete vertices and faces that are currently selected.
void growVertexSelection(int _objectId)
Grow the current vertex selection.
IdList getModelingVertices(int objectId)
Get a list of all modeling vertices.
void selectAllVertices(int _objectId)
Select all Vertices.
void colorizeVertexSelection(int _objectId, int _r, int _g, int _b, int a)
Colorize the vertex selection.
void shrinkVertexSelection(int _objectId)
Shrink the current vertex selection.
SelectionInterface::PrimitiveType vertexType_
Primitive type handles:
void selectClosestBoundaryVertices(int _objectId, int _vertexId)
Select all vertices of the boundary close to the given vertex.
Functions for selection on a mesh.
void selectVertices(int objectId, IdList _vertexList)
select given vertices
const UpdateType UPDATE_COLOR(UpdateTypeSet(1)<< 10)
Colors have changed.
void update_regions(MeshT *_mesh)
Update face selection to correspond to the vertex selection.
int createMeshFromVertexSelection(int _objectId)
select given vertices
void clearVertexSelection(int _objectId)
Unselect all vertices.
void invertVertexSelection(int _objectId)
Invert the current vertex selection.
#define DATA_TRIANGLE_MESH
void clearModelingVertices(int objectId)
Clear Modeling Area.
IdList getVertexSelection(int _objectId)
Return a list of all selected vertices.
void closestBoundarySelection(MeshT *_mesh, int _vh, PrimitiveType _primitiveTypes, bool _deselection)
Select all entities that are incident to closest boundary.