Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
FaceSelection.cc
1 /*===========================================================================*\
2  * *
3  * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39  * *
40 \*===========================================================================*/
41 
42 /*===========================================================================*\
43  * *
44  * $Revision$ *
45  * $Author$ *
46  * $Date$ *
47  * *
48 \*===========================================================================*/
49 
50 #include "MeshObjectSelectionPlugin.hh"
51 
53 
54 //=========================================================
55 //==== Face selections
56 //=========================================================
57 
58 void MeshObjectSelectionPlugin::selectFaces(int objectId , IdList _faceList) {
59 
60  if(_faceList.empty() ) return;
61 
62  BaseObjectData* object = 0;
63  if (! PluginFunctions::getObject(objectId,object)) {
64  emit log(LOGERR,tr("selectFaces : unable to get object"));
65  return;
66  }
67 
68  if (object->dataType() == DATA_TRIANGLE_MESH)
69  MeshSelection::selectFaces(PluginFunctions::triMesh(object), _faceList);
70  else if (object->dataType() == DATA_POLY_MESH)
71  MeshSelection::selectFaces(PluginFunctions::polyMesh(object), _faceList);
72  else {
73  emit log(LOGERR,tr("selectFaces : Unsupported object Type"));
74  return;
75  }
76 
77  QString selection = "selectFaces(ObjectId(" + QString::number(objectId) + ") , [ " + QString::number(_faceList[0]);
78 
79  for (uint i = 1 ; i < _faceList.size(); ++i) {
80  selection += " , " + QString::number(_faceList[i]);
81  }
82 
83  selection += " ])";
84 
85  emit updatedObject(object->id(), UPDATE_SELECTION_FACES);
86  emit scriptInfo(selection);
87 }
88 
89 //=========================================================
90 
91 void MeshObjectSelectionPlugin::unselectFaces(int objectId , IdList _faceList) {
92 
93  if(_faceList.empty() ) return;
94 
95  BaseObjectData* object = 0;
96  if (! PluginFunctions::getObject(objectId,object)) {
97  emit log(LOGERR,tr("unselectFaces : unable to get object"));
98  return;
99  }
100 
101  if (object->dataType() == DATA_TRIANGLE_MESH)
102  MeshSelection::unselectFaces(PluginFunctions::triMesh(object), _faceList);
103  else if (object->dataType() == DATA_POLY_MESH)
104  MeshSelection::unselectFaces(PluginFunctions::polyMesh(object), _faceList);
105  else {
106  emit log(LOGERR,tr("unselectFaces : Unsupported object Type"));
107  return;
108  }
109 
110  QString selection = "unselectFaces(ObjectId(" + QString::number(objectId) + ") , [ " + QString::number(_faceList[0]);
111 
112  for (uint i = 1 ; i < _faceList.size(); ++i) {
113  selection += " , " + QString::number(_faceList[i]);
114  }
115 
116  selection += " ])";
117 
118  emit updatedObject(object->id(), UPDATE_SELECTION_FACES);
119  emit scriptInfo(selection);
120 }
121 
122 //=========================================================
123 
125 
126  BaseObjectData* object;
127  if (! PluginFunctions::getObject(objectId,object)) {
128  emit log(LOGERR,tr("selectAllFaces : unable to get object"));
129  return;
130  }
131 
132  if (object->dataType() == DATA_TRIANGLE_MESH)
133  MeshSelection::selectAllFaces(PluginFunctions::triMesh(object));
134  else if (object->dataType() == DATA_POLY_MESH)
135  MeshSelection::selectAllFaces(PluginFunctions::polyMesh(object));
136  else {
137  emit log(LOGERR,tr("selectAllFaces : Unsupported object Type"));
138  return;
139  }
140 
141  emit updatedObject(object->id(), UPDATE_SELECTION_FACES);
142  emit scriptInfo("selectAllFaces(ObjectId(" + QString::number(objectId) + "))");
143 }
144 
145 //=========================================================
146 
148 
149  BaseObjectData* object;
150  if (! PluginFunctions::getObject(objectId,object)) {
151  emit log(LOGERR,tr("clearFaceSelection : unable to get object"));
152  return;
153  }
154 
155  if (object->dataType() == DATA_TRIANGLE_MESH)
156  MeshSelection::clearFaceSelection(PluginFunctions::triMesh(object));
157  else if (object->dataType() == DATA_POLY_MESH)
158  MeshSelection::clearFaceSelection(PluginFunctions::polyMesh(object));
159  else {
160  emit log(LOGERR,tr("clearFaceSelection : Unsupported object Type"));
161  return;
162  }
163 
164  emit updatedObject(object->id(), UPDATE_SELECTION_FACES);
165  emit scriptInfo("clearFaceSelection(ObjectId(" + QString::number(objectId) + "))");
166 }
167 
168 //=========================================================
169 
171 
172  BaseObjectData* object;
173  if (! PluginFunctions::getObject(objectId,object)) {
174  emit log(LOGERR,tr("invertFaceSelection : unable to get object"));
175  return;
176  }
177 
178  if (object->dataType() == DATA_TRIANGLE_MESH)
179  MeshSelection::invertFaceSelection(PluginFunctions::triMesh(object));
180  else if (object->dataType() == DATA_POLY_MESH)
181  MeshSelection::invertFaceSelection(PluginFunctions::polyMesh(object));
182  else {
183  emit log(LOGERR,tr("invertFaceSelection : Unsupported object Type"));
184  return;
185  }
186 
187  emit updatedObject(object->id(), UPDATE_SELECTION_FACES);
188  emit scriptInfo("invertFaceSelection(ObjectId(" + QString::number(objectId) + "))");
189 }
190 
191 //=========================================================
192 
194 
195  BaseObjectData* object = 0;
196  if (!PluginFunctions::getObject(_objectId,object)) {
197  emit log(LOGERR,tr("deleteFaceSelection: unable to get object"));
198  return;
199  }
200 
201  if (object->dataType() == DATA_TRIANGLE_MESH)
203  else if (object->dataType() == DATA_POLY_MESH)
205  else {
206  emit log(LOGERR,tr("deleteFaceSelection: Unsupported object Type"));
207  return;
208  }
209 
210  emit updatedObject(object->id(), UPDATE_ALL);
211  emit scriptInfo("deleteFaceSelection(ObjectId(" + QString::number(_objectId) + "))");
212 }
213 
214 //=========================================================
215 
217  return createMeshFromSelection(_objectId, faceType_ );
218 }
219 
220 //=========================================================
221 
223 
224  BaseObjectData* object;
225  if (! PluginFunctions::getObject(objectId,object)) {
226  emit log(LOGERR,tr("selectBoundaryFaces : unable to get object"));
227  return;
228  }
229 
230  if (object->dataType() == DATA_TRIANGLE_MESH)
231  MeshSelection::selectBoundaryFaces(PluginFunctions::triMesh(object));
232  else if (object->dataType() == DATA_POLY_MESH)
233  MeshSelection::selectBoundaryFaces(PluginFunctions::polyMesh(object));
234  else {
235  emit log(LOGERR,tr("selectBoundaryFaces : Unsupported object Type"));
236  return;
237  }
238 
239  emit updatedObject(object->id(), UPDATE_SELECTION_FACES);
240  emit scriptInfo("selectBoundaryFaces(ObjectId(" + QString::number(objectId) + "))");
241 }
242 
243 
244 //=========================================================
245 
247 
248  BaseObjectData* object;
249  if (! PluginFunctions::getObject(objectId,object)) {
250  emit log(LOGERR,tr("shrinkFaceSelection : unable to get object"));
251  return;
252  }
253 
254  if (object->dataType() == DATA_TRIANGLE_MESH)
255  MeshSelection::shrinkFaceSelection(PluginFunctions::triMesh(object));
256  else if (object->dataType() == DATA_POLY_MESH)
257  MeshSelection::shrinkFaceSelection(PluginFunctions::polyMesh(object));
258  else {
259  emit log(LOGERR,tr("shrinkFaceSelection : Unsupported object Type"));
260  return;
261  }
262 
263  emit updatedObject(object->id(), UPDATE_SELECTION_FACES);
264  emit scriptInfo("shrinkFaceSelection(ObjectId(" + QString::number(objectId) + "))");
265 }
266 
267 //=========================================================
268 
270 
271  BaseObjectData* object;
272  if (! PluginFunctions::getObject(objectId,object)) {
273  emit log(LOGERR,tr("growFaceSelection : unable to get object"));
274  return;
275  }
276 
277  if (object->dataType() == DATA_TRIANGLE_MESH)
278  MeshSelection::growFaceSelection(PluginFunctions::triMesh(object));
279  else if (object->dataType() == DATA_POLY_MESH)
280  MeshSelection::growFaceSelection(PluginFunctions::polyMesh(object));
281  else {
282  emit log(LOGERR,tr("growFaceSelection : Unsupported object Type"));
283  return;
284  }
285 
286  emit updatedObject(object->id(), UPDATE_SELECTION_FACES);
287  emit scriptInfo("growFaceSelection(ObjectId(" + QString::number(objectId) + "))");
288 }
289 
290 //=========================================================
291 
293 
294  BaseObjectData* object;
295  if (! PluginFunctions::getObject(objectId,object)) {
296  emit log(LOGERR,tr("getFaceSelection : unable to get object"));
297  return IdList(0);
298  }
299 
300  emit scriptInfo("getFaceSelection(ObjectId(" + QString::number(objectId) + "))");
301 
302  if (object->dataType() == DATA_TRIANGLE_MESH)
303  return MeshSelection::getFaceSelection(PluginFunctions::triMesh(object));
304  else if (object->dataType() == DATA_POLY_MESH)
305  return MeshSelection::getFaceSelection(PluginFunctions::polyMesh(object));
306  else {
307  emit log(LOGERR,tr("getFaceSelection : Unsupported object Type"));
308  return IdList(0);
309  }
310 }
311 
312 //=========================================================
313 
315 void MeshObjectSelectionPlugin::colorizeFaceSelection(int objectId, int r, int g, int b, int a) {
316 
317  BaseObjectData* object;
318  if (! PluginFunctions::getObject(objectId,object)) {
319  emit log(LOGERR,"colorizeFaceSelection : unable to get object");
320  return;
321  }
322 
323  if (object->dataType() == DATA_TRIANGLE_MESH) {
325  } else if (object->dataType() == DATA_POLY_MESH) {
327  } else {
328  emit log(LOGERR,"colorizeFaceSelection : Unsupported object Type");
329  return;
330  }
331 
332 
333  emit scriptInfo("colorizeFaceSelection(ObjectId(" + QString::number(objectId) + "), "
334  + QString::number(r) + ", " + QString::number(g) + ", " + QString::number(b) + ")");
335 
336  emit updatedObject(objectId, UPDATE_COLOR);
337 }
void colorizeSelection(MeshT *_mesh, PrimitiveType _primitiveTypes, int _red, int _green, int _blue, int _alpha)
Colorize the selection.
void deleteFaceSelection(int _objectId)
Delete face that are currently selected.
SelectionInterface::PrimitiveType faceType_
Handle to selection environment.
bool deleteSelection(MeshT *_mesh, PrimitiveType _primitiveType)
Delete all selected elements of a mesh.
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
bool getObject(int _identifier, BSplineCurveObject *&_object)
void selectAllFaces(int objectId)
Select all faces.
PolyMesh * polyMesh(BaseObjectData *_object)
Get a poly mesh from an object.
void colorizeFaceSelection(int objectId, int r, int g, int b, int a)
Colorize the face selection.
void createMeshFromSelection(MeshT &_mesh, MeshT &_newMesh, PrimitiveType _primitiveType)
Create a new mesh from the selection.
bool dataType(DataType _type) const
Definition: BaseObject.cc:232
void growFaceSelection(int objectId)
Grow the current face selection.
void selectFaces(int objectId, IdList _facesList)
Select given faces.
void shrinkFaceSelection(int objectId)
Shrink the current face selection.
TriMesh * triMesh(BaseObjectData *_object)
Get a triangle mesh from an object.
std::vector< int > IdList
Standard Type for id Lists used for scripting.
Definition: DataTypes.hh:192
int createMeshFromFaceSelection(int _objectId)
Create a mesh containing the face selection of the given mesh.
#define DATA_POLY_MESH
Definition: PolyMesh.hh:65
void unselectFaces(int objectId, IdList _facesList)
Unselect given faces.
IdList getFaceSelection(int objectId)
Return a list of all selected faces.
void invertFaceSelection(int objectId)
Invert the current face selection.
void clearFaceSelection(int objectId)
Unselect all faces.
void selectBoundaryFaces(int objectId)
Select all boundary faces of the given object.
Functions for selection on a mesh.
const UpdateType UPDATE_COLOR(UpdateTypeSet(1)<< 10)
Colors have changed.
#define DATA_TRIANGLE_MESH
Definition: TriangleMesh.hh:66
const UpdateType UPDATE_SELECTION_FACES(UpdateTypeSet(1)<< 8)
Face selection has changed.
int id() const
Definition: BaseObject.cc:201