diff --git a/eeschema/tools/ee_selection_tool.cpp b/eeschema/tools/ee_selection_tool.cpp index f886e43810..34355d73d1 100644 --- a/eeschema/tools/ee_selection_tool.cpp +++ b/eeschema/tools/ee_selection_tool.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -161,6 +162,7 @@ EE_SELECTION_TOOL::EE_SELECTION_TOOL() : m_multiple( false ), m_skip_heuristics( false ), m_isLibEdit( false ), + m_isLibView( false ), m_unit( 0 ), m_convert( 0 ), m_menu( *this ) @@ -179,6 +181,7 @@ bool EE_SELECTION_TOOL::Init() { m_frame = getEditFrame(); + LIB_VIEW_FRAME* libViewFrame = dynamic_cast( m_frame ); LIB_EDIT_FRAME* libEditFrame = dynamic_cast( m_frame ); if( libEditFrame ) @@ -187,6 +190,9 @@ bool EE_SELECTION_TOOL::Init() m_unit = libEditFrame->GetUnit(); m_convert = libEditFrame->GetConvert(); } + else + m_isLibView = libViewFrame != nullptr; + static KICAD_T wireOrBusTypes[] = { SCH_LINE_LOCATE_WIRE_T, SCH_LINE_LOCATE_BUS_T, EOT }; @@ -195,10 +201,10 @@ bool EE_SELECTION_TOOL::Init() auto wireOrBusSelection = E_C::MoreThan( 0 ) && E_C::OnlyTypes( wireOrBusTypes ); auto sheetSelection = E_C::Count( 1 ) && E_C::OnlyType( SCH_SHEET_T ); auto schEditCondition = [this] ( const SELECTION& aSel ) { - return !m_isLibEdit; + return !m_isLibEdit && !m_isLibView; }; auto belowRootSheetCondition = [this] ( const SELECTION& aSel ) { - return !m_isLibEdit && g_CurrentSheet->Last() != g_RootSheet; + return !m_isLibEdit && !m_isLibView && g_CurrentSheet->Last() != g_RootSheet; }; auto havePartCondition = [ this ] ( const SELECTION& sel ) { return m_isLibEdit && ( (LIB_EDIT_FRAME*) m_frame )->GetCurPart(); @@ -254,6 +260,7 @@ void EE_SELECTION_TOOL::Reset( RESET_REASON aReason ) getView()->GetPainter()->GetSettings()->SetHighlight( false ); LIB_EDIT_FRAME* libEditFrame = dynamic_cast( m_frame ); + LIB_VIEW_FRAME* libViewFrame = dynamic_cast( m_frame ); if( libEditFrame ) { @@ -261,6 +268,8 @@ void EE_SELECTION_TOOL::Reset( RESET_REASON aReason ) m_unit = libEditFrame->GetUnit(); m_convert = libEditFrame->GetConvert(); } + else + m_isLibView = libViewFrame != nullptr; } else // Restore previous properties of selected items and remove them from containers diff --git a/eeschema/tools/ee_selection_tool.h b/eeschema/tools/ee_selection_tool.h index ecc9e13b79..6cfc978d32 100644 --- a/eeschema/tools/ee_selection_tool.h +++ b/eeschema/tools/ee_selection_tool.h @@ -232,7 +232,7 @@ private: ///> Sets up handlers for various events. void setTransitions() override; - + private: SCH_BASE_FRAME* m_frame; // Pointer to the parent frame SELECTION m_selection; // Current state of selection @@ -242,7 +242,8 @@ private: bool m_multiple; // Multiple selection mode is active bool m_skip_heuristics; // Heuristics are not allowed when choosing item under cursor - bool m_isLibEdit; + bool m_isLibEdit; // True when libedit is the parent frame + bool m_isLibView; // True when libview is the parent frame int m_unit; // Fixed unit filter (for symbol editor) int m_convert; // Fixed DeMorgan filter (for symbol editor) diff --git a/eeschema/viewlib_frame.cpp b/eeschema/viewlib_frame.cpp index 9da348c610..6c8ce686f7 100644 --- a/eeschema/viewlib_frame.cpp +++ b/eeschema/viewlib_frame.cpp @@ -49,6 +49,7 @@ #include #include #include +#include // Save previous component library viewer state. wxString LIB_VIEW_FRAME::m_libraryName; @@ -137,11 +138,12 @@ LIB_VIEW_FRAME::LIB_VIEW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrame // Synchronize some draw options SetShowElectricalType( true ); - GetRenderSettings()->m_ShowPinsElectricalType = GetShowElectricalType(); - // Ensure axis are always drawn (initial default display was not drawn) KIGFX::GAL_DISPLAY_OPTIONS& gal_opts = GetGalDisplayOptions(); gal_opts.m_axesEnabled = true; + GetGalCanvas()->GetGAL()->SetAxesEnabled( true ); + GetRenderSettings()->m_ShowPinsElectricalType = GetShowElectricalType(); + GetGalCanvas()->GetGAL()->SetGridVisibility( IsGridVisible() ); SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y ); @@ -201,8 +203,6 @@ LIB_VIEW_FRAME::LIB_VIEW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrame SyncView(); GetGalCanvas()->GetViewControls()->SetSnapping( true ); - GetGalCanvas()->GetGAL()->SetAxesEnabled( true ); - GetGalCanvas()->GetGAL()->SetGridVisibility( IsGridVisible() ); // Set the working/draw area size to display a symbol to a reasonable value: // A 450mm x 450mm with a origin at the area center looks like a large working area @@ -234,11 +234,16 @@ void LIB_VIEW_FRAME::setupTools() // Register tools m_toolManager->RegisterTool( new COMMON_TOOLS ); m_toolManager->RegisterTool( new ZOOM_TOOL ); - m_toolManager->RegisterTool( new EE_SELECTION_TOOL ); - m_toolManager->RegisterTool( new LIB_CONTROL ); + m_toolManager->RegisterTool( new EE_SELECTION_TOOL ); // manage context menu + m_toolManager->RegisterTool( new LIB_CONTROL ); // manage show electrical type option + m_toolManager->RegisterTool( new LIB_MOVE_TOOL ); m_toolManager->InitTools(); + // Run the selection tool, it is supposed to be always active + // It also manages the mouse right click to show the context menu + m_toolManager->InvokeTool( "eeschema.InteractiveSelection" ); + GetCanvas()->SetEventDispatcher( m_toolDispatcher ); }