50 #include "BSplineCurveSelectionPlugin.hh" 55 #define CONTROL_POINT_TYPE "controlpointselection.png" 56 #define KNOT_TYPE "knotselection.png" 61 #define G_CP_MODE "Control Point Selection View" 62 #define G_K_MODE "Knot Selection View" 65 #define CP_SELECT_ALL "Select All Control Points" 66 #define CP_DESELECT_ALL "Deselect All Control Points" 67 #define CP_INVERT "Invert Control Point Selection" 68 #define CP_DELETE "Delete Selected Control Points" 71 #define K_SELECT_ALL "Select All Knots" 72 #define K_DESELECT_ALL "Deselect All Knots" 73 #define K_INVERT "Invert Knot Selection" 74 #define K_DELETE "Delete Selected Knots" 80 allSupportedTypes_(0) {
90 void BSplineCurveSelectionPlugin::initializePlugin() {
98 void BSplineCurveSelectionPlugin::pluginsInitialized() {
102 QString iconPath = OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator();
104 emit addSelectionEnvironment(
"B-Spline Curve Selections",
"Select B-Spline curve primitives.",
119 QStringList generalOperations;
120 generalOperations.append(G_CP_MODE);
121 generalOperations.append(G_K_MODE);
124 QStringList controlPointOperations;
125 controlPointOperations.append(CP_SELECT_ALL);
126 controlPointOperations.append(CP_DESELECT_ALL);
127 controlPointOperations.append(CP_INVERT);
128 controlPointOperations.append(CP_DELETE);
130 QStringList knotOperations;
131 knotOperations.append(K_SELECT_ALL);
132 knotOperations.append(K_DESELECT_ALL);
133 knotOperations.append(K_INVERT);
134 knotOperations.append(K_DELETE);
136 emit addSelectionOperations(
environmentHandle_, generalOperations,
"Selection Operations");
143 emit registerKeyShortcut(Qt::Key_A, Qt::ControlModifier);
145 emit registerKeyShortcut(Qt::Key_C, Qt::NoModifier);
147 emit registerKeyShortcut(Qt::Key_I, Qt::NoModifier);
149 emit registerKeyShortcut(Qt::Key_Delete, Qt::NoModifier);
156 emit setSlotDescription(
"selectAllControlPoints(int)", tr(
"Select all control points of a B-spline curve"),
157 QStringList(
"objectId"), QStringList(
"Id of object"));
158 emit setSlotDescription(
"deselectAllControlPoints(int)", tr(
"Deselect all control points of a B-spline curve"),
159 QStringList(
"objectId"), QStringList(
"Id of object"));
160 emit setSlotDescription(
"invertControlPointSelection(int)", tr(
"Invert control point selection"),
161 QStringList(
"objectId"), QStringList(
"Id of object"));
162 emit setSlotDescription(
"deleteSelectedControlPoints(int)", tr(
"Delete selected control points"),
163 QStringList(
"objectId"), QStringList(
"Id of object"));
164 emit setSlotDescription(
"selectControlPoints(int,IdList)", tr(
"Select the specified control points"),
165 QString(
"objectId,control pointList").split(
","), QString(
"Id of object,List of control points").split(
","));
167 emit setSlotDescription(
"loadSelection(int,QString)", tr(
"Load selection from selection file"),
168 QString(
"objectId,filename").split(
","), QString(
"Id of an object,Selection file").split(
","));
170 emit setSlotDescription(
"selectAllKnots(int)", tr(
"Select all knots of a B-spline curve"),
171 QStringList(
"objectId"), QStringList(
"Id of object"));
172 emit setSlotDescription(
"deselectAllKnots(int)", tr(
"Deselect all knots of a B-spline curve"),
173 QStringList(
"objectId"), QStringList(
"Id of object"));
174 emit setSlotDescription(
"invertKnotSelection(int)", tr(
"Invert knot selection"),
175 QStringList(
"objectId"), QStringList(
"Id of object"));
176 emit setSlotDescription(
"deleteSelectedKnots(int)", tr(
"Delete selected knots"),
177 QStringList(
"objectId"), QStringList(
"Id of object"));
178 emit setSlotDescription(
"selectKnots(int,IdList)", tr(
"Select the specified knots"),
179 QString(
"objectId,knotList").split(
","), QString(
"Id of object,List of knots").split(
","));
186 SelectionInterface::PrimitiveType type = 0u;
187 emit getActivePrimitiveType(type);
193 bool targetsOnly =
false;
194 emit targetObjectsOnly(targetsOnly);
198 if(_operation == G_CP_MODE) {
201 }
else if(_operation == G_K_MODE) {
204 }
else if(_operation == CP_SELECT_ALL) {
208 if (o_it->visible()) {
213 emit createBackup(o_it->id(),
"Select All Controlpoints",
UPDATE_SELECTION);
215 }
else if (_operation == CP_DESELECT_ALL) {
219 if (o_it->visible()) {
224 emit createBackup(o_it->id(),
"Deselect All Controlpoints",
UPDATE_SELECTION);
226 }
else if (_operation == CP_INVERT) {
230 if (o_it->visible()) {
235 emit createBackup(o_it->id(),
"Invert Controlpoint Selection",
UPDATE_SELECTION);
237 }
else if (_operation == CP_DELETE) {
241 if (o_it->visible()) {
246 emit createBackup(o_it->id(),
"Delete Controlpoint Selection",
UPDATE_SELECTION);
248 }
else if(_operation == K_SELECT_ALL) {
252 if (o_it->visible()) {
259 }
else if (_operation == K_DESELECT_ALL) {
263 if (o_it->visible()) {
270 }
else if (_operation == K_INVERT) {
274 if (o_it->visible()) {
281 }
else if (_operation == K_DELETE) {
285 if (o_it->visible()) {
290 emit createBackup(o_it->id(),
"Delete Knot Selection",
UPDATE_ALL);
302 size_t node_idx, target_idx;
320 if(successfullyPicked) {
327 if(_currentType & controlPointType_) {
329 if(!curve->controlpoint_selections_available())
return;
334 if(curve->controlpoint_selected(target_idx))
335 curve->deselect_controlpoint(target_idx);
337 curve->select_controlpoint(target_idx);
347 int numKnots = curve->
n_knots();
348 int order = curve->
degree() + 1;
352 double minu = knotvec->getKnot(curve->
degree());
353 double maxu = knotvec->getKnot(numKnots - order);
354 double udiff = maxu - minu;
357 double param = ((double)target_idx/(
double)texres) * udiff + minu;
361 int knotIdx = interval[0];
363 if(knotvec->selected(knotIdx)) {
364 knotvec->deselect(knotIdx);
366 knotvec->select(knotIdx);
384 if(_event->type() == QEvent::MouseButtonPress) {
387 QPoint p(_event->pos().x(), state.
viewport_height() - _event->pos().y());
393 }
else if(_event->type() == QEvent::MouseButtonDblClick) {
399 bool targetsOnly =
false;
400 emit targetObjectsOnly(targetsOnly);
408 if (o_it->visible()) {
417 if(!curve->controlpoint_selections_available())
return;
425 QPoint p((
int)pc[0], (
int)pc[1]);
426 if(polygon.containsPoint(p, Qt::OddEvenFill)) {
428 curve->deselect_controlpoint(i);
430 curve->select_controlpoint(i);
442 int numKnots = curve->
n_knots();
443 int order = curve->
degree() + 1;
449 if(curve->
degree() == 0)
return;
450 if((
int)curve->
n_knots() <= ((numKnots - order) + 1))
return;
452 for(
int i = curve->
degree()-1; i < (numKnots - order)-1; ++i) {
454 double baseKnot = knotvec->getKnot(i+1);
455 double dhalf = 0.5*(knotvec->getKnot(i+2) - baseKnot);
457 double t = baseKnot + dhalf;
462 QPoint p((
int)pcp[0], (
int)pcp[1]);
464 if(polygon.containsPoint(p, Qt::OddEvenFill)) {
466 knotvec->deselect(i+1);
468 knotvec->select(i+1);
487 void BSplineCurveSelectionPlugin::loadSelection(
int _objId,
const QString& _filename) {
492 if(!file.
connect(_filename,
false)) {
493 emit log(
LOGERR, QString(
"Could not read file '%1'!").arg(_filename));
498 loadIniFile(file, _objId);
503 void BSplineCurveSelectionPlugin::loadIniFile(
INIFile& _ini,
int _id) {
510 void BSplineCurveSelectionPlugin::saveIniFile(
INIFile& _ini,
int _id) {
526 QString section = QString(
"BSplineCurveSelection") +
"//" + o_it->name();
531 std::vector<int> ids;
533 _file.
get_entry(ids, section,
"ControlPointSelection");
537 _file.
get_entry(ids, section,
"KnotSelection");
559 QString section = QString(
"BSplineCurveSelection") +
"//" + o_it->name();
571 SelectionInterface::PrimitiveType type = 0u;
572 emit getActivePrimitiveType(type);
579 bool targetsOnly =
false;
580 emit targetObjectsOnly(targetsOnly);
584 if(_key == Qt::Key_A && _modifiers == Qt::ControlModifier) {
588 if (o_it->visible()) {
595 }
else if(_key == Qt::Key_C && _modifiers == Qt::NoModifier) {
599 if (o_it->visible()) {
606 }
else if(_key == Qt::Key_I && _modifiers == Qt::NoModifier) {
610 if (o_it->visible()) {
617 }
else if(_key == Qt::Key_Delete && _modifiers == Qt::NoModifier) {
621 if (o_it->visible()) {
626 emit createBackup(o_it->id(),
"Delete Selection",
UPDATE_ALL);
QVector< QPoint > volumeLassoPoints_
Keep volume lasso points.
bool scenegraphPick(ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, size_t &_nodeIdx, size_t &_targetIdx, ACG::Vec3d *_hitPointPtr=0)
Execute picking operation on scenegraph.
BSplineCurve * splineCurve(BaseObjectData *_object)
Get a Bspline curve from an object.
Point curvePoint(Scalar _u)
unsigned int n_knots() const
Returns the number of knots.
void slotVolumeLassoSelection(QMouseEvent *_event, SelectionInterface::PrimitiveType _currentType, bool _deselect)
Called whenever the user performs a volume lasso selection.
BSplineCurveObject * bsplineCurveObject(BaseObjectData *_object)
Cast an BaseObject to a BSplineCurveObject if possible.
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
IdList getControlPointSelection(int _objectId)
Get current control point selection.
~BSplineCurveSelectionPlugin()
Default destructor.
void add_entry(const QString &_section, const QString &_key, const QString &_value)
Addition / modification of a string entry.
void invertKnotSelection(int _objectId)
Invert knot selection.
Vec3d project(const Vec3d &_point) const
project point in world coordinates to window coordinates
void updateSlotDescriptions()
Set slot descriptions for scripting functions.
const UpdateType UPDATE_SELECTION(UpdateTypeSet(16))
Selection updated.
unsigned int degree() const
Returns the spline degree.
const QStringList ALL_OBJECTS
Iterable object range.
bool get_entry(QString &_val, const QString &_section, const QString &_key) const
Access to a string entry.
void selectAllKnots(int _objectId)
Select all knots of a curve.
void selectAllControlPoints(int _objectId)
Select all control points of a curve.
void slotSelectionOperation(QString _operation)
A specific operation is requested.
void deselectAllKnots(int _objectId)
Deselect all knots of a curve.
void slotToggleSelection(QMouseEvent *_event, SelectionInterface::PrimitiveType _currentType, bool _deselect)
Called whenever the user performs a toggle selection.
QString environmentHandle_
Handle to selection environment.
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
PickTarget
What target to use for picking.
void deleteSelectedControlPoints(int _objectId)
Delete selected control points.
unsigned int controlPointType_
Primitive type handles:
void invertControlPointSelection(int _objectId)
Invert control point selection.
void selectControlPoints(int _objectId, const IdList &_ids, bool _deselect=false)
Select specific control points of a curve.
unsigned int n_control_points() const
Returns the number of control points.
Point & get_control_point(int _i)
get control point i
void slotSaveSelection(INIFile &_file)
Save selection for all objects in the scene.
picks verices (may not be implemented for all nodes)
#define DATA_BSPLINE_CURVE
int viewport_height() const
get viewport height
void deselectAllControlPoints(int _objectId)
Deselect all control points of a curve.
Knotvector * get_knotvector_ref()
get a reference to the knotvector
SelectionViewMode
Change selection view mode for every B-spline curve in the scene.
QStringList IteratorRestriction
Iterable object range.
ACG::SceneGraph::BSplineCurveNodeT< BSplineCurve > * splineCurveNode()
Get the scenegraph Node.
void deleteSelectedKnots(int _objectId)
Delete selected knots.
void selectKnots(int _objectId, const IdList &_ids, bool _deselect=false)
Select specific knots of a curve.
const QStringList TARGET_OBJECTS("target")
Iterable object range.
ACG::Vec2i interval(double _t)
void slotKeyShortcutEvent(int _key, Qt::KeyboardModifiers _modifiers)
One of the previously registered keys has been pressed.
Class for the handling of simple configuration files.
BSplineCurveSelectionPlugin()
Default constructor.
bool connect(const QString &name, const bool create)
Connect INIFile object with given filename.
Viewer::ViewerProperties & viewerProperties(int _id)
Get the viewer properties Use this functions to get basic viewer properties such as backgroundcolor o...
void setSelectionViewMode(const SelectionViewMode _mode)
Change selection view mode for every B-spline curve in the scene.
Pick spline curve or surface (picks u or u,v coords respectively)
bool section_exists(const QString &_section) const
Check if given section exists in the current INI file.
IdList getKnotSelection(int _objectId)
Get current knot selection.
void slotLoadSelection(const INIFile &_file)
Load selection for specific objects in the scene.
bool getPickedObject(const size_t _node_idx, BaseObjectData *&_object)
Get the picked mesh.
unsigned int allSupportedTypes_
Handle to selection environment.
unsigned int knotType_
Handle to selection environment.
ACG::GLState & glState()
Get the glState of the Viewer.