mirror of https://github.com/KLayout/klayout.git
Editor hooks for move operations
This commit is contained in:
parent
00bc208e3f
commit
1c284b0939
|
|
@ -39,6 +39,7 @@ HEADERS = \
|
|||
edtEditorHooks.h \
|
||||
edtEditorOptionsPages.h \
|
||||
edtInstPropertiesPage.h \
|
||||
edtMoveTrackerService.h \
|
||||
edtPCellParametersPage.h \
|
||||
edtPropertiesPages.h \
|
||||
edtPropertiesPageUtils.h \
|
||||
|
|
@ -49,6 +50,7 @@ SOURCES = \
|
|||
edtEditorHooks.cc \
|
||||
edtEditorOptionsPages.cc \
|
||||
edtInstPropertiesPage.cc \
|
||||
edtMoveTrackerService.cc \
|
||||
edtPCellParametersPage.cc \
|
||||
edtPropertiesPages.cc \
|
||||
edtPropertiesPageUtils.cc \
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ public:
|
|||
virtual void end_modify () { }
|
||||
|
||||
// editing protocol
|
||||
virtual void begin_edit (lay::LayoutViewBase * /*view*/) { }
|
||||
virtual void begin_edit (lay::CellViewRef & /*cv*/) { }
|
||||
virtual void begin_edits () { }
|
||||
virtual void transformed (const lay::ObjectInstPath & /*object*/, const db::ICplxTrans & /*applied*/, const db::CplxTrans & /*view_trans*/) { }
|
||||
virtual void end_edits () { }
|
||||
|
|
|
|||
|
|
@ -0,0 +1,161 @@
|
|||
|
||||
/*
|
||||
|
||||
KLayout Layout Viewer
|
||||
Copyright (C) 2006-2024 Matthias Koefferlein
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
*/
|
||||
|
||||
#include "layLayoutViewBase.h"
|
||||
#include "edtMoveTrackerService.h"
|
||||
#include "edtService.h"
|
||||
|
||||
namespace edt
|
||||
{
|
||||
|
||||
// -------------------------------------------------------------
|
||||
|
||||
MoveTrackerService::MoveTrackerService (lay::LayoutViewBase *view)
|
||||
: lay::EditorServiceBase (view),
|
||||
mp_view (view)
|
||||
{
|
||||
// .. nothing yet ..
|
||||
}
|
||||
|
||||
MoveTrackerService::~MoveTrackerService ()
|
||||
{
|
||||
// .. nothing yet ..
|
||||
}
|
||||
|
||||
bool
|
||||
MoveTrackerService::begin_move (lay::Editable::MoveMode mode, const db::DPoint & /*p*/, lay::angle_constraint_type /*ac*/)
|
||||
{
|
||||
if (view ()->is_editable () && mode == lay::Editable::Selected) {
|
||||
open_editor_hooks ();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
MoveTrackerService::issue_edit_events ()
|
||||
{
|
||||
if (m_editor_hooks.empty ()) {
|
||||
return;
|
||||
}
|
||||
|
||||
call_editor_hooks (m_editor_hooks, &edt::EditorHooks::begin_edits);
|
||||
|
||||
// build the transformation variants cache
|
||||
TransformationVariants tv (view ());
|
||||
|
||||
std::vector<edt::Service *> services = view ()->get_plugins<edt::Service> ();
|
||||
std::vector<lay::ObjectInstPath> sel;
|
||||
|
||||
for (auto s = services.begin (); s != services.end (); ++s) {
|
||||
|
||||
edt::Service *svc = *s;
|
||||
|
||||
sel.clear ();
|
||||
svc->get_selection (sel);
|
||||
|
||||
for (auto r = sel.begin (); r != sel.end (); ++r) {
|
||||
|
||||
const lay::CellView &cv = view ()->cellview (r->cv_index ());
|
||||
|
||||
// compute the transformation into context cell's micron space
|
||||
double dbu = cv->layout ().dbu ();
|
||||
db::CplxTrans gt = db::CplxTrans (dbu) * cv.context_trans () * r->trans ();
|
||||
|
||||
// compute the move transformation in local object space
|
||||
db::ICplxTrans applied = gt.inverted () * db::DCplxTrans (svc->move_trans ()) * gt;
|
||||
|
||||
db::DCplxTrans tvt;
|
||||
|
||||
// get one representative global transformation
|
||||
const std::vector<db::DCplxTrans> *tv_list = 0;
|
||||
if (r->is_cell_inst ()) {
|
||||
tv_list = tv.per_cv (r->cv_index ());
|
||||
} else {
|
||||
tv_list = tv.per_cv_and_layer (r->cv_index (), r->layer ());
|
||||
}
|
||||
if (tv_list && ! tv_list->empty ()) {
|
||||
tvt = tv_list->front ();
|
||||
}
|
||||
|
||||
call_editor_hooks<const lay::ObjectInstPath &, const db::ICplxTrans &, const db::CplxTrans &> (m_editor_hooks, &edt::EditorHooks::transformed, *r, applied, tvt * gt);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
call_editor_hooks (m_editor_hooks, &edt::EditorHooks::end_edits);
|
||||
}
|
||||
|
||||
void
|
||||
MoveTrackerService::move (const db::DPoint & /*pu*/, lay::angle_constraint_type /*ac*/)
|
||||
{
|
||||
// we don't interpret this event, but use it to request status from the editor services
|
||||
issue_edit_events ();
|
||||
}
|
||||
|
||||
void
|
||||
MoveTrackerService::move_transform (const db::DPoint & /*pu*/, db::DFTrans /*tr*/, lay::angle_constraint_type /*ac*/)
|
||||
{
|
||||
// we don't interpret this event, but use it to request status from the editor services
|
||||
issue_edit_events ();
|
||||
}
|
||||
|
||||
void
|
||||
MoveTrackerService::end_move (const db::DPoint & /*p*/, lay::angle_constraint_type /*ac*/)
|
||||
{
|
||||
call_editor_hooks (m_editor_hooks, &edt::EditorHooks::commit_edit);
|
||||
move_cancel (); // formally this functionality fits here
|
||||
}
|
||||
|
||||
void
|
||||
MoveTrackerService::edit_cancel ()
|
||||
{
|
||||
move_cancel ();
|
||||
}
|
||||
|
||||
void
|
||||
MoveTrackerService::move_cancel ()
|
||||
{
|
||||
call_editor_hooks (m_editor_hooks, &edt::EditorHooks::end_edit);
|
||||
m_editor_hooks.clear ();
|
||||
}
|
||||
|
||||
void
|
||||
MoveTrackerService::open_editor_hooks ()
|
||||
{
|
||||
lay::CellViewRef cv_ref (view ()->cellview_ref (view ()->active_cellview_index ()));
|
||||
if (! cv_ref.is_valid ()) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::string technology;
|
||||
if (cv_ref->layout ().technology ()) {
|
||||
technology = cv_ref->layout ().technology ()->name ();
|
||||
}
|
||||
|
||||
m_editor_hooks = edt::EditorHooks::get_editor_hooks (technology);
|
||||
call_editor_hooks<lay::CellViewRef &> (m_editor_hooks, &edt::EditorHooks::begin_edit, (lay::CellViewRef &) cv_ref);
|
||||
}
|
||||
|
||||
} // namespace edt
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,97 @@
|
|||
|
||||
/*
|
||||
|
||||
KLayout Layout Viewer
|
||||
Copyright (C) 2006-2024 Matthias Koefferlein
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
*/
|
||||
|
||||
#ifndef HDR_edtMoveTrackerService
|
||||
#define HDR_edtMoveTrackerService
|
||||
|
||||
#include "edtCommon.h"
|
||||
|
||||
#include "layEditorServiceBase.h"
|
||||
#include "edtEditorHooks.h"
|
||||
|
||||
namespace edt {
|
||||
|
||||
/**
|
||||
* @brief A service tracking move commands a forwarding them to the editor hooks
|
||||
*/
|
||||
|
||||
class EDT_PUBLIC MoveTrackerService
|
||||
: public lay::EditorServiceBase
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief The constructor
|
||||
*/
|
||||
MoveTrackerService (lay::LayoutViewBase *view);
|
||||
|
||||
/**
|
||||
* @brief The destructor
|
||||
*/
|
||||
~MoveTrackerService ();
|
||||
|
||||
/**
|
||||
* @brief Begin a "move" operation
|
||||
*/
|
||||
virtual bool begin_move (lay::Editable::MoveMode mode, const db::DPoint &p, lay::angle_constraint_type ac);
|
||||
|
||||
/**
|
||||
* @brief Continue a "move" operation
|
||||
*/
|
||||
virtual void move (const db::DPoint &p, lay::angle_constraint_type ac);
|
||||
|
||||
/**
|
||||
* @brief Transform during a move operation
|
||||
*/
|
||||
virtual void move_transform (const db::DPoint &p, db::DFTrans tr, lay::angle_constraint_type ac);
|
||||
|
||||
/**
|
||||
* @brief Terminate a "move" operation
|
||||
*/
|
||||
virtual void end_move (const db::DPoint &p, lay::angle_constraint_type ac);
|
||||
|
||||
/**
|
||||
* @brief Access to the view object
|
||||
*/
|
||||
lay::LayoutViewBase *view () const
|
||||
{
|
||||
tl_assert (mp_view != 0);
|
||||
return mp_view;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Cancel any edit operations (such as move)
|
||||
*/
|
||||
virtual void edit_cancel ();
|
||||
|
||||
private:
|
||||
lay::LayoutViewBase *mp_view;
|
||||
tl::weak_collection<edt::EditorHooks> m_editor_hooks;
|
||||
|
||||
void move_cancel ();
|
||||
void open_editor_hooks ();
|
||||
void issue_edit_events ();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -34,6 +34,7 @@
|
|||
#include "edtServiceImpl.h"
|
||||
#include "edtMainService.h"
|
||||
#include "edtPartialService.h"
|
||||
#include "edtMoveTrackerService.h"
|
||||
#if defined(HAVE_QT)
|
||||
# include "edtEditorOptionsPages.h"
|
||||
# include "edtRecentConfigurationPage.h"
|
||||
|
|
@ -565,5 +566,26 @@ static tl::RegisteredClass<lay::PluginDeclaration> config_decl30 (
|
|||
"edt::PartialService"
|
||||
);
|
||||
|
||||
class MoveTrackerPluginDeclaration
|
||||
: public lay::PluginDeclaration
|
||||
{
|
||||
public:
|
||||
MoveTrackerPluginDeclaration ()
|
||||
{
|
||||
// .. nothing yet ..
|
||||
}
|
||||
|
||||
virtual lay::Plugin *create_plugin (db::Manager * /*manager*/, lay::Dispatcher * /*root*/, lay::LayoutViewBase *view) const
|
||||
{
|
||||
return new edt::MoveTrackerService (view);
|
||||
}
|
||||
};
|
||||
|
||||
static tl::RegisteredClass<lay::PluginDeclaration> config_decl40 (
|
||||
new MoveTrackerPluginDeclaration (),
|
||||
4100,
|
||||
"edt::MoveTrackerService"
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -381,6 +381,22 @@ public:
|
|||
*/
|
||||
std::pair<bool, lay::ObjectInstPath> handle_guiding_shape_changes (const lay::ObjectInstPath &obj) const;
|
||||
|
||||
/**
|
||||
* @brief Gets a value indicating whether a move operation is ongoing
|
||||
*/
|
||||
bool is_moving () const
|
||||
{
|
||||
return m_moving;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets the current move transformation (in DBU space on context cell level)
|
||||
*/
|
||||
const db::DTrans &move_trans () const
|
||||
{
|
||||
return m_move_trans;
|
||||
}
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief Update m_markers to reflect the selection
|
||||
|
|
|
|||
|
|
@ -201,12 +201,12 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
virtual void begin_edit (lay::LayoutViewBase *view)
|
||||
virtual void begin_edit (lay::CellViewRef &cv_ref)
|
||||
{
|
||||
if (f_begin_edit.can_issue ()) {
|
||||
f_begin_edit.issue<edt::EditorHooks, lay::LayoutViewBase *> (&edt::EditorHooks::begin_edit, view);
|
||||
f_begin_edit.issue<edt::EditorHooks, lay::CellViewRef &> (&edt::EditorHooks::begin_edit, cv_ref);
|
||||
} else {
|
||||
edt::EditorHooks::begin_edit (view);
|
||||
edt::EditorHooks::begin_edit (cv_ref);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -380,7 +380,7 @@ gsi::Class<EditorHooksImpl> decl_EditorHooks ("lay", "EditorHooks",
|
|||
"@brief Modification protocol - finish session\n"
|
||||
"See \\begin_modify for a description of the protocol."
|
||||
) +
|
||||
gsi::callback ("begin_edit", &EditorHooksImpl::begin_edit, &EditorHooksImpl::f_begin_edit, gsi::arg ("view"),
|
||||
gsi::callback ("begin_edit", &EditorHooksImpl::begin_edit, &EditorHooksImpl::f_begin_edit, gsi::arg ("cellview"),
|
||||
"@brief Editing protocol - begin session\n"
|
||||
"This method is called to initiate an object editing session. The session is ended with "
|
||||
"\\end_edit. Between these calls, edits are announced with \\begin_edits, "
|
||||
|
|
|
|||
Loading…
Reference in New Issue