Commit 50b2513a authored by Hans-Christian Ebke's avatar Hans-Christian Ebke
Browse files

Improved PolyLine usability.


git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@17269 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 19ef73b5
...@@ -48,6 +48,7 @@ PolyLinePlugin::PolyLinePlugin() : ...@@ -48,6 +48,7 @@ PolyLinePlugin::PolyLinePlugin() :
cur_polyline_obj_(0), cur_polyline_obj_(0),
cur_move_id_(-1), cur_move_id_(-1),
move_point_ref_(0), move_point_ref_(0),
create_point_ref_(0),
cur_merge_id_(-1), cur_merge_id_(-1),
smart_move_timer_(0), smart_move_timer_(0),
cur_smart_move_obj_(0), cur_smart_move_obj_(0),
...@@ -155,7 +156,29 @@ slotMouseEvent( QMouseEvent* _event ) ...@@ -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 void
...@@ -176,7 +199,11 @@ pluginsInitialized() ...@@ -176,7 +199,11 @@ pluginsInitialized()
{ {
// Add the required Picking modes (Hidden, controlled only by the buttons) // Add the required Picking modes (Hidden, controlled only by the buttons)
emit addHiddenPickMode("PolyLine"); emit addHiddenPickMode("PolyLine");
emit setPickModeMouseTracking("PolyLine", true);
emit addHiddenPickMode( CREATE_CUT_POLYLINE ); 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
toolbar_ = new QToolBar(tr("PolyLine Editing")); toolbar_ = new QToolBar(tr("PolyLine Editing"));
...@@ -726,6 +753,21 @@ void ...@@ -726,6 +753,21 @@ void
PolyLinePlugin:: PolyLinePlugin::
me_insert( QMouseEvent* _event ) 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 // Pick position
unsigned int node_idx, target_idx; unsigned int node_idx, target_idx;
ACG::Vec3d hit_point; ACG::Vec3d hit_point;
...@@ -748,10 +790,15 @@ me_insert( QMouseEvent* _event ) ...@@ -748,10 +790,15 @@ me_insert( QMouseEvent* _event )
cur_polyline_obj_ = PluginFunctions::polyLineObject(obj); cur_polyline_obj_ = PluginFunctions::polyLineObject(obj);
cur_polyline_obj_->materialNode()->set_random_color(); 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 // add new point
cur_polyline_obj_->line()->add_point((PolyLine::Point) hit_point); cur_polyline_obj_->line()->add_point((PolyLine::Point) hit_point);
create_point_ref_ = &cur_polyline_obj_->line()->points().back();
// update // update
emit updatedObject(cur_insert_id_, UPDATE_GEOMETRY | UPDATE_TOPOLOGY); emit updatedObject(cur_insert_id_, UPDATE_GEOMETRY | UPDATE_TOPOLOGY);
...@@ -767,12 +814,27 @@ me_insert( QMouseEvent* _event ) ...@@ -767,12 +814,27 @@ me_insert( QMouseEvent* _event )
cur_polyline_obj_->line()->set_closed(true); 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 // update
emit updatedObject(cur_insert_id_, UPDATE_GEOMETRY | UPDATE_TOPOLOGY); emit updatedObject(cur_insert_id_, UPDATE_GEOMETRY | UPDATE_TOPOLOGY);
// reset current variables // reset current variables
cur_insert_id_ = -1; cur_insert_id_ = -1;
cur_polyline_obj_ = 0; cur_polyline_obj_ = 0;
create_point_ref_ = 0;
clearStatusMessage();
break; break;
} }
......
...@@ -31,6 +31,8 @@ ...@@ -31,6 +31,8 @@
#include <OpenFlipper/BasePlugin/LoggingInterface.hh> #include <OpenFlipper/BasePlugin/LoggingInterface.hh>
#include <OpenFlipper/BasePlugin/ToolbarInterface.hh> #include <OpenFlipper/BasePlugin/ToolbarInterface.hh>
#include <OpenFlipper/BasePlugin/LoadSaveInterface.hh> #include <OpenFlipper/BasePlugin/LoadSaveInterface.hh>
#include <OpenFlipper/BasePlugin/KeyInterface.hh>
#include <OpenFlipper/BasePlugin/StatusbarInterface.hh>
#include <OpenFlipper/BasePlugin/ScriptInterface.hh> #include <OpenFlipper/BasePlugin/ScriptInterface.hh>
#include <OpenFlipper/common/Types.hh> #include <OpenFlipper/common/Types.hh>
#include <ObjectTypes/PolyLine/PolyLine.hh> #include <ObjectTypes/PolyLine/PolyLine.hh>
...@@ -48,17 +50,27 @@ ...@@ -48,17 +50,27 @@
/** Plugin for PolyLine Support /** Plugin for PolyLine Support
*/ */
class PolyLinePlugin : public QObject, BaseInterface, MouseInterface, class PolyLinePlugin: public QObject,
PickingInterface, ToolboxInterface, LoggingInterface, LoadSaveInterface, ToolbarInterface, ScriptInterface BaseInterface,
{ MouseInterface,
Q_OBJECT PickingInterface,
Q_INTERFACES(BaseInterface) ToolboxInterface,
LoggingInterface,
LoadSaveInterface,
ToolbarInterface,
StatusbarInterface,
KeyInterface,
ScriptInterface {
Q_OBJECT
Q_INTERFACES(BaseInterface)
Q_INTERFACES(MouseInterface) Q_INTERFACES(MouseInterface)
Q_INTERFACES(PickingInterface) Q_INTERFACES(PickingInterface)
Q_INTERFACES(ToolboxInterface) Q_INTERFACES(ToolboxInterface)
Q_INTERFACES(LoggingInterface) Q_INTERFACES(LoggingInterface)
Q_INTERFACES(LoadSaveInterface) Q_INTERFACES(LoadSaveInterface)
Q_INTERFACES(ToolbarInterface) Q_INTERFACES(ToolbarInterface)
Q_INTERFACES(StatusbarInterface)
Q_INTERFACES(KeyInterface)
Q_INTERFACES(ScriptInterface) Q_INTERFACES(ScriptInterface)
#if QT_VERSION >= 0x050000 #if QT_VERSION >= 0x050000
...@@ -75,6 +87,7 @@ signals: ...@@ -75,6 +87,7 @@ signals:
void addPickMode( const std::string& _mode ); void addPickMode( const std::string& _mode );
void addHiddenPickMode( const std::string& _mode ); void addHiddenPickMode( const std::string& _mode );
void setPickModeToolbar (const std::string& _mode, QToolBar * _toolbar); void setPickModeToolbar (const std::string& _mode, QToolBar * _toolbar);
void setPickModeMouseTracking(const std::string& _mode , bool _mouseTracking);
// LoggingInterface // LoggingInterface
void log(Logtype _type, QString _message); void log(Logtype _type, QString _message);
...@@ -93,6 +106,9 @@ signals: ...@@ -93,6 +106,9 @@ signals:
void deleteObject( int _id ); void deleteObject( int _id );
void addEmptyObject( DataType _type, 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 : private slots :
// BaseInterface // BaseInterface
...@@ -101,6 +117,7 @@ private slots : ...@@ -101,6 +117,7 @@ private slots :
void slotEditModeChanged(); void slotEditModeChanged();
void slotMouseEvent( QMouseEvent* _event ); void slotMouseEvent( QMouseEvent* _event );
void slotKeyEvent(QKeyEvent* _event);
void slotPickModeChanged( const std::string& _mode); void slotPickModeChanged( const std::string& _mode);
...@@ -261,6 +278,7 @@ private: ...@@ -261,6 +278,7 @@ private:
int cur_move_id_; int cur_move_id_;
PolyLine::Point* move_point_ref_; PolyLine::Point* move_point_ref_;
PolyLine::Point* create_point_ref_;
PolyLine::Point move_point_orig_; PolyLine::Point move_point_orig_;
int cur_merge_id_; int cur_merge_id_;
......
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