Commit af24e4af authored by Hans-Christian Ebke's avatar Hans-Christian Ebke

Improved PolyLine usability.


git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@17269 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 5f6e8b7b
......@@ -48,6 +48,7 @@ PolyLinePlugin::PolyLinePlugin() :
cur_polyline_obj_(0),
cur_move_id_(-1),
move_point_ref_(0),
create_point_ref_(0),
cur_merge_id_(-1),
smart_move_timer_(0),
cur_smart_move_obj_(0),
......@@ -155,7 +156,29 @@ slotMouseEvent( QMouseEvent* _event )
}
}
void PolyLinePlugin::slotKeyEvent(QKeyEvent* event) {
switch (event->key()) {
case Qt::Key_Return:
if (PluginFunctions::pickMode() == ("PolyLine") && PluginFunctions::actionMode() == Viewer::PickingMode && mode() == PL_INSERT) {
cur_polyline_obj_->line()->delete_point(cur_polyline_obj_->line()->n_vertices() - 1);
if (event->modifiers() & (Qt::ShiftModifier))
cur_polyline_obj_->line()->set_closed(true);
emit updatedObject(cur_insert_id_, UPDATE_GEOMETRY | UPDATE_TOPOLOGY);
cur_insert_id_ = -1;
cur_polyline_obj_ = 0;
create_point_ref_ = 0;
clearStatusMessage();
}
break;
default:
break;
}
}
//-----------------------------------------------------------------------------
void
......@@ -176,7 +199,11 @@ pluginsInitialized()
{
// Add the required Picking modes (Hidden, controlled only by the buttons)
emit addHiddenPickMode("PolyLine");
emit setPickModeMouseTracking("PolyLine", true);
emit addHiddenPickMode( CREATE_CUT_POLYLINE );
emit registerKey(Qt::Key_Return, Qt::NoModifier, tr("Terminate creation of poly line."), true);
emit registerKey(Qt::Key_Return, Qt::ShiftModifier, tr("Terminate creation of poly line and create loop."), true);
// TOOLBAR
toolbar_ = new QToolBar(tr("PolyLine Editing"));
......@@ -726,6 +753,21 @@ void
PolyLinePlugin::
me_insert( QMouseEvent* _event )
{
if (_event->type() == QEvent::MouseMove) {
if (create_point_ref_) {
// Pick position
unsigned int node_idx, target_idx;
ACG::Vec3d hit_point;
if (PluginFunctions::scenegraphPick(ACG::SceneGraph::PICK_FACE, _event->pos(), node_idx, target_idx, &hit_point)) {
*create_point_ref_ = (PolyLine::Point) hit_point;
// update
emit updatedObject(cur_insert_id_, UPDATE_GEOMETRY);
}
}
return;
}
// Pick position
unsigned int node_idx, target_idx;
ACG::Vec3d hit_point;
......@@ -748,10 +790,15 @@ me_insert( QMouseEvent* _event )
cur_polyline_obj_ = PluginFunctions::polyLineObject(obj);
cur_polyline_obj_->materialNode()->set_random_color();
cur_polyline_obj_->line()->add_point((PolyLine::Point) hit_point);
emit showStatusMessage(tr("Double click/Enter to terminate poly line. Use with shift to create loop."));
}
// add new point
cur_polyline_obj_->line()->add_point((PolyLine::Point) hit_point);
create_point_ref_ = &cur_polyline_obj_->line()->points().back();
// update
emit updatedObject(cur_insert_id_, UPDATE_GEOMETRY | UPDATE_TOPOLOGY);
......@@ -767,12 +814,27 @@ me_insert( QMouseEvent* _event )
cur_polyline_obj_->line()->set_closed(true);
}
if (cur_polyline_obj_->line()->n_vertices() >= 2) {
const PolyLine::Point &p1 = cur_polyline_obj_->line()->point(cur_polyline_obj_->line()->n_vertices() - 1),
&p2 = cur_polyline_obj_->line()->point(cur_polyline_obj_->line()->n_vertices() - 2);
/*
* Remove duplicate created as a move sentinel.
*/
if ((p2 - p1).sqrnorm() < 1e-6) {
cur_polyline_obj_->line()->delete_point(cur_polyline_obj_->line()->n_vertices() - 1);
}
}
// update
emit updatedObject(cur_insert_id_, UPDATE_GEOMETRY | UPDATE_TOPOLOGY);
// reset current variables
cur_insert_id_ = -1;
cur_polyline_obj_ = 0;
create_point_ref_ = 0;
clearStatusMessage();
break;
}
......
......@@ -31,6 +31,8 @@
#include <OpenFlipper/BasePlugin/LoggingInterface.hh>
#include <OpenFlipper/BasePlugin/ToolbarInterface.hh>
#include <OpenFlipper/BasePlugin/LoadSaveInterface.hh>
#include <OpenFlipper/BasePlugin/KeyInterface.hh>
#include <OpenFlipper/BasePlugin/StatusbarInterface.hh>
#include <OpenFlipper/BasePlugin/ScriptInterface.hh>
#include <OpenFlipper/common/Types.hh>
#include <ObjectTypes/PolyLine/PolyLine.hh>
......@@ -48,17 +50,27 @@
/** Plugin for PolyLine Support
*/
class PolyLinePlugin : public QObject, BaseInterface, MouseInterface,
PickingInterface, ToolboxInterface, LoggingInterface, LoadSaveInterface, ToolbarInterface, ScriptInterface
{
Q_OBJECT
Q_INTERFACES(BaseInterface)
class PolyLinePlugin: public QObject,
BaseInterface,
MouseInterface,
PickingInterface,
ToolboxInterface,
LoggingInterface,
LoadSaveInterface,
ToolbarInterface,
StatusbarInterface,
KeyInterface,
ScriptInterface {
Q_OBJECT
Q_INTERFACES(BaseInterface)
Q_INTERFACES(MouseInterface)
Q_INTERFACES(PickingInterface)
Q_INTERFACES(ToolboxInterface)
Q_INTERFACES(LoggingInterface)
Q_INTERFACES(LoadSaveInterface)
Q_INTERFACES(ToolbarInterface)
Q_INTERFACES(StatusbarInterface)
Q_INTERFACES(KeyInterface)
Q_INTERFACES(ScriptInterface)
#if QT_VERSION >= 0x050000
......@@ -75,6 +87,7 @@ signals:
void addPickMode( const std::string& _mode );
void addHiddenPickMode( const std::string& _mode );
void setPickModeToolbar (const std::string& _mode, QToolBar * _toolbar);
void setPickModeMouseTracking(const std::string& _mode , bool _mouseTracking);
// LoggingInterface
void log(Logtype _type, QString _message);
......@@ -93,6 +106,9 @@ signals:
void deleteObject( int _id );
void addEmptyObject( DataType _type, int& _id);
void registerKey(int _key, Qt::KeyboardModifiers _modifiers, QString _description, bool _multiUse = false);
void showStatusMessage(QString _message, int _timeout = 0);
void clearStatusMessage();
private slots :
// BaseInterface
......@@ -101,6 +117,7 @@ private slots :
void slotEditModeChanged();
void slotMouseEvent( QMouseEvent* _event );
void slotKeyEvent(QKeyEvent* _event);
void slotPickModeChanged( const std::string& _mode);
......@@ -261,6 +278,7 @@ private:
int cur_move_id_;
PolyLine::Point* move_point_ref_;
PolyLine::Point* create_point_ref_;
PolyLine::Point move_point_orig_;
int cur_merge_id_;
......
Markdown is supported
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