Merge pull request #345 from KLayout/issue-317

Issue 317
This commit is contained in:
Matthias Köfferlein
2019-09-06 23:24:34 +02:00
committed by GitHub
12 changed files with 379 additions and 70 deletions
+31 -26
View File
@@ -28,6 +28,7 @@
#include "layPropertiesDialog.h"
#include <algorithm>
#include <memory>
namespace lay
{
@@ -82,25 +83,30 @@ Editables::~Editables ()
}
void
Editables::del ()
Editables::del (db::Transaction *transaction)
{
std::auto_ptr<db::Transaction> trans_holder (transaction ? transaction : new db::Transaction (manager (), tl::to_string (QObject::tr ("Delete"))));
if (selection_size () > 0) {
cancel_edits ();
try {
// begin the transaction
tl_assert (! manager ()->transacting ());
manager ()->transaction (tl::to_string (QObject::tr ("Delete")));
// this dummy operation will update the screen:
manager ()->queue (this, new db::Op ());
trans_holder->open ();
for (iterator e = begin (); e != end (); ++e) {
e->del ();
cancel_edits ();
// this dummy operation will update the screen:
manager ()->queue (this, new db::Op ());
for (iterator e = begin (); e != end (); ++e) {
e->del ();
}
} catch (...) {
trans_holder->cancel ();
throw;
}
// end the transaction
manager ()->commit ();
}
}
@@ -155,14 +161,16 @@ Editables::selection_catch_bbox ()
}
void
Editables::transform (const db::DCplxTrans &tr)
Editables::transform (const db::DCplxTrans &tr, db::Transaction *transaction)
{
std::auto_ptr<db::Transaction> trans_holder (transaction ? transaction : new db::Transaction (manager (), tl::to_string (QObject::tr ("Transform"))));
if (selection_size () > 0) {
try {
tl_assert (! manager ()->transacting ());
manager ()->transaction (tl::to_string (QObject::tr ("Transform")));
trans_holder->open ();
// this dummy operation will update the screen:
manager ()->queue (this, new db::Op ());
@@ -170,11 +178,8 @@ Editables::transform (const db::DCplxTrans &tr)
e->transform (tr);
}
// end the transaction
manager ()->commit ();
} catch (...) {
manager ()->clear ();
trans_holder->cancel ();
throw;
}
@@ -525,13 +530,14 @@ Editables::move_transform (const db::DPoint &p, db::DFTrans t, lay::angle_constr
}
void
Editables::end_move (const db::DPoint &p, lay::angle_constraint_type ac)
Editables::end_move (const db::DPoint &p, lay::angle_constraint_type ac, db::Transaction *transaction)
{
std::auto_ptr<db::Transaction> trans_holder (transaction ? transaction : new db::Transaction (manager (), tl::to_string (QObject::tr ("Move"))));
if (m_any_move_operation) {
// begin the transaction
tl_assert (! manager ()->transacting ());
manager ()->transaction (tl::to_string (QObject::tr ("Move")));
trans_holder->open ();
// this dummy operation will update the screen:
manager ()->queue (this, new db::Op ());
@@ -539,9 +545,6 @@ Editables::end_move (const db::DPoint &p, lay::angle_constraint_type ac)
e->end_move (p, ac);
}
// end the transaction
manager ()->commit ();
// clear the selection that was set previously
if (m_move_selection) {
clear_selection ();
@@ -549,6 +552,8 @@ Editables::end_move (const db::DPoint &p, lay::angle_constraint_type ac)
} else {
trans_holder->cancel ();
// if nothing was moved, treat the end_move as a select which makes the move sticky or
// replaces a complex selection by a simple one
edit_cancel ();
+13 -3
View File
@@ -32,6 +32,7 @@
#include "dbPoint.h"
#include "dbBox.h"
#include "dbObject.h"
#include "dbManager.h"
#include <set>
#include <limits>
@@ -386,8 +387,11 @@ public:
/**
* @brief The delete operation
*
* If a transaction is given, the operation will be appended to this pending transaction
* The Editables object takes ownership over the Transaction object.
*/
void del ();
void del (db::Transaction *transaction = 0);
/**
* @brief "cut" operation
@@ -419,8 +423,11 @@ public:
* @brief transform the selection
*
* The transformation is given in micron units.
*
* If a transaction is given, the operation will be appended to this pending transaction.
* The Editables object takes ownership over the Transaction object.
*/
void transform (const db::DCplxTrans &tr);
void transform (const db::DCplxTrans &tr, db::Transaction *transaction = 0);
/**
* @brief Enable or disable a certain editable
@@ -494,8 +501,11 @@ public:
/**
* @brief End "move" operation
*
* If a transaction is given, the operation will be appended to this pending transaction
* The Editables object takes ownership over the Transaction object.
*/
void end_move (const db::DPoint &p, lay::angle_constraint_type ac);
void end_move (const db::DPoint &p, lay::angle_constraint_type ac, db::Transaction *transaction = 0);
/**
* @brief Tell how many objects are selected.
+44
View File
@@ -5085,6 +5085,33 @@ LayoutView::paste ()
}
}
void
LayoutView::paste_interactive ()
{
clear_selection ();
std::auto_ptr<db::Transaction> trans (new db::Transaction (manager (), tl::to_string (QObject::tr ("Paste and move"))));
{
// let the receivers sort out who is pasting what ..
if (mp_hierarchy_panel) {
mp_hierarchy_panel->paste ();
}
if (mp_control_panel) {
mp_control_panel->paste ();
}
lay::Editables::paste ();
}
// temporarily close the transaction and pass to the move service for appending it's own
// operations.
trans->close ();
if (mp_move_service->begin_move (trans.release ())) {
switch_mode (-1); // move mode
}
}
void
LayoutView::copy ()
{
@@ -6763,6 +6790,23 @@ LayoutView::cm_sel_scale ()
}
}
void
LayoutView::cm_sel_move_interactive ()
{
if (mp_move_service->begin_move ()) {
switch_mode (-1); // move mode
}
}
void
LayoutView::switch_mode (int m)
{
if (m_mode != m) {
mode (m);
emit mode_change (m);
}
}
void
LayoutView::cm_sel_move_to ()
{
+19
View File
@@ -254,6 +254,11 @@ public:
*/
void paste ();
/**
* @brief Pastes from clipboard and initiates a move
*/
void paste_interactive ();
/**
* @brief Copies to clipboard
*
@@ -1617,6 +1622,14 @@ public:
*/
void mode (int m);
/**
* @brief Switches the application's mode
*
* Switches the mode on application level. Use this method to initiate
* a mode switch from the view.
*/
void switch_mode (int m);
/**
* @brief Test, if the view is currently in move mode.
*/
@@ -2582,6 +2595,7 @@ public slots:
void cm_sel_scale ();
void cm_sel_move ();
void cm_sel_move_to ();
void cm_sel_move_interactive ();
// forwarded to the layer control panel
void cm_new_tab ();
@@ -2698,6 +2712,11 @@ signals:
*/
void menu_needs_update ();
/**
* @brief The view initiated a mode change
*/
void mode_change (int m);
protected:
/**
* @brief Establish the view operations
+34 -4
View File
@@ -163,7 +163,7 @@ MoveService::mouse_click_event (const db::DPoint &p, unsigned int buttons, bool
return true;
}
if (prio && (buttons & lay::LeftButton) != 0) {
if (handle_dragging (p, buttons)) {
if (handle_dragging (p, buttons, 0)) {
return true;
}
}
@@ -216,7 +216,7 @@ bool
MoveService::mouse_press_event (const db::DPoint &p, unsigned int buttons, bool prio)
{
if (prio && (buttons & lay::LeftButton) != 0) {
if (handle_dragging (p, buttons)) {
if (handle_dragging (p, buttons, 0)) {
return true;
}
}
@@ -229,12 +229,34 @@ MoveService::mouse_press_event (const db::DPoint &p, unsigned int buttons, bool
return false;
}
bool
MoveService::begin_move (db::Transaction *transaction)
{
std::auto_ptr<db::Transaction> trans_holder (transaction);
drag_cancel ();
db::DBox bbox = mp_editables->selection_bbox ();
if (bbox.empty ()) {
// nothing selected
return false;
}
set_cursor (lay::Cursor::size_all);
// emulate a "begin move" at the center of the selection bbox - this will become the reference point
return handle_dragging (bbox.center (), 0, trans_holder.release ());
}
bool
MoveService::handle_dragging (const db::DPoint &p, unsigned int buttons)
MoveService::handle_dragging (const db::DPoint &p, unsigned int buttons, db::Transaction *transaction)
{
std::auto_ptr<db::Transaction> trans_holder (transaction);
if (! m_dragging) {
mp_transaction.reset (trans_holder.release ());
if (mp_editables->begin_move (p, ac_from_buttons (buttons))) {
lay::SelectionService *selector = mp_view->selection_service ();
@@ -257,7 +279,7 @@ MoveService::handle_dragging (const db::DPoint &p, unsigned int buttons)
m_dragging = false;
widget ()->ungrab_mouse (this);
mp_editables->end_move (p, ac_from_buttons (buttons));
mp_editables->end_move (p, ac_from_buttons (buttons), mp_transaction.release ());
return true;
}
@@ -269,9 +291,17 @@ MoveService::drag_cancel ()
{
m_shift = db::DPoint ();
if (m_dragging) {
mp_editables->edit_cancel ();
widget ()->ungrab_mouse (this);
m_dragging = false;
if (mp_transaction.get ()) {
mp_transaction->cancel ();
}
mp_transaction.reset (0);
}
}
+6 -1
View File
@@ -25,11 +25,14 @@
#ifndef HDR_layMove
#define HDR_layMove
#include "dbManager.h"
#include "layViewObject.h"
#include <QTimer>
#include <QObject>
#include <memory>
namespace lay {
class Editables;
@@ -46,6 +49,7 @@ public:
~MoveService ();
virtual bool configure (const std::string &name, const std::string &value);
bool begin_move (db::Transaction *transaction = 0);
private:
virtual bool mouse_press_event (const db::DPoint &p, unsigned int buttons, bool prio);
@@ -58,13 +62,14 @@ private:
virtual void drag_cancel ();
virtual void deactivated ();
bool handle_dragging (const db::DPoint &p, unsigned int buttons);
bool handle_dragging (const db::DPoint &p, unsigned int buttons, db::Transaction *transaction);
bool m_dragging;
lay::Editables *mp_editables;
lay::LayoutView *mp_view;
double m_global_grid;
db::DPoint m_shift;
std::auto_ptr<db::Transaction> mp_transaction;
};
}