Commit 6e0bd1ee authored by Maciej Suminski's avatar Maciej Suminski

Adapted tools to PCB_BASE{_EDIT}_FRAME.

parent b0f3e79e
......@@ -67,7 +67,11 @@ TOOL_ACTION COMMON_ACTIONS::drawArc( "pcbnew.InteractiveDrawing.arc",
AS_GLOBAL, 0,
"Draw an arc", "Draw an arc" );
TOOL_ACTION COMMON_ACTIONS::placeText( "pcbnew.InteractiveDrawing.text",
TOOL_ACTION COMMON_ACTIONS::placeTextModule( "pcbnew.InteractiveDrawing.textPcb",
AS_GLOBAL, 0,
"Add a text", "Add a text" );
TOOL_ACTION COMMON_ACTIONS::placeTextPcb( "pcbnew.InteractiveDrawing.textModule",
AS_GLOBAL, 0,
"Add a text", "Add a text" );
......@@ -284,7 +288,10 @@ std::string COMMON_ACTIONS::TranslateLegacyId( int aId )
return COMMON_ACTIONS::drawArc.GetName();
case ID_PCB_ADD_TEXT_BUTT:
return COMMON_ACTIONS::placeText.GetName();
return COMMON_ACTIONS::placeTextPcb.GetName();
case ID_MODEDIT_TEXT_TOOL:
return COMMON_ACTIONS::placeTextModule.GetName();
case ID_PCB_DIMENSION_BUTT:
return COMMON_ACTIONS::drawDimension.GetName();
......
......@@ -64,7 +64,8 @@ public:
static TOOL_ACTION drawArc;
/// Activation of the drawing tool (text)
static TOOL_ACTION placeText;
static TOOL_ACTION placeTextPcb;
static TOOL_ACTION placeTextModule;
/// Activation of the drawing tool (dimension)
static TOOL_ACTION drawDimension;
......
......@@ -65,7 +65,7 @@ void DRAWING_TOOL::Reset( RESET_REASON aReason )
m_view = getView();
m_controls = getViewControls();
m_board = getModel<BOARD>();
m_frame = getEditFrame<PCB_EDIT_FRAME>();
m_frame = getEditFrame<PCB_BASE_FRAME>();
setTransitions();
}
......@@ -281,7 +281,112 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
}
int DRAWING_TOOL::PlaceText( TOOL_EVENT& aEvent )
int DRAWING_TOOL::PlaceTextModule( TOOL_EVENT& aEvent )
{
TEXTE_MODULE* text = NULL;
// Add a VIEW_GROUP that serves as a preview for the new item
KIGFX::VIEW_GROUP preview( m_view );
m_view->Add( &preview );
m_toolMgr->GetTool<SELECTION_TOOL>()->ClearSelection();
m_controls->ShowCursor( true );
m_controls->SetSnapping( true );
m_controls->SetAutoPan( true );
Activate();
m_frame->SetToolID( ID_PCB_ADD_TEXT_BUTT, wxCURSOR_PENCIL, _( "Add text" ) );
// Main loop: keep receiving events
while( OPT_TOOL_EVENT evt = Wait() )
{
VECTOR2I cursorPos = m_controls->GetCursorPosition();
if( evt->IsCancel() )
{
if( text )
{
// Delete the old text and have another try
m_board->Delete( text ); // it was already added by CreateTextPcb()
text = NULL;
preview.Clear();
preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
m_controls->ShowCursor( true );
}
else
break;
}
else if( text && evt->Category() == TC_COMMAND )
{
if( evt->IsAction( &COMMON_ACTIONS::rotate ) )
{
text->Rotate( text->GetPosition(), 900.0 /*m_frame->GetRotationAngle()*/ ); // FIXME
preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
}
else if( evt->IsAction( &COMMON_ACTIONS::flip ) )
{
text->Flip( text->GetPosition() );
preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
}
}
else if( evt->IsClick( BUT_LEFT ) )
{
if( !text )
{
// Init the new item attributes
text = m_frame->CreateTextModule( m_frame->GetBoard()->m_Modules, NULL );
if( text == NULL )
continue;
m_controls->ShowCursor( false );
preview.Add( text );
}
else
{
assert( text->GetText().Length() > 0 );
assert( text->GetSize().x > 0 && text->GetSize().y > 0 );
text->ClearFlags();
m_view->Add( text );
// m_board->Add( text ); // it is already added by CreateTextePcb()
text->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
m_frame->OnModify();
m_frame->SaveCopyInUndoList( text, UR_NEW );
preview.Remove( text );
m_controls->ShowCursor( true );
text = NULL;
}
}
else if( text && evt->IsMotion() )
{
text->SetTextPosition( wxPoint( cursorPos.x, cursorPos.y ) );
// Show a preview of the item
preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
}
}
m_controls->ShowCursor( false );
m_controls->SetSnapping( false );
m_controls->SetAutoPan( false );
m_view->Remove( &preview );
setTransitions();
m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );
return 0;
}
int DRAWING_TOOL::PlaceTextPcb( TOOL_EVENT& aEvent )
{
TEXTE_PCB* text = NULL;
......@@ -322,7 +427,7 @@ int DRAWING_TOOL::PlaceText( TOOL_EVENT& aEvent )
{
if( evt->IsAction( &COMMON_ACTIONS::rotate ) )
{
text->Rotate( text->GetPosition(), m_frame->GetRotationAngle() );
text->Rotate( text->GetPosition(), /*m_frame->GetRotationAngle()*/ 900.0 ); // FIXME
preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
}
else if( evt->IsAction( &COMMON_ACTIONS::flip ) )
......@@ -337,7 +442,7 @@ int DRAWING_TOOL::PlaceText( TOOL_EVENT& aEvent )
if( !text )
{
// Init the new item attributes
text = m_frame->CreateTextePcb( NULL );
text = static_cast<PCB_EDIT_FRAME*>( m_frame )->CreateTextePcb( NULL );
if( text == NULL )
continue;
......@@ -698,7 +803,7 @@ int DRAWING_TOOL::PlaceModule( TOOL_EVENT& aEvent )
{
if( evt->IsAction( &COMMON_ACTIONS::rotate ) )
{
module->Rotate( module->GetPosition(), m_frame->GetRotationAngle() );
module->Rotate( module->GetPosition(), /*m_frame->GetRotationAngle()*/ 900.0 );
preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
}
else if( evt->IsAction( &COMMON_ACTIONS::flip ) )
......@@ -1029,7 +1134,7 @@ int DRAWING_TOOL::drawZone( bool aKeepout )
m_view->Add( zone );
if( !aKeepout )
m_frame->Fill_Zone( zone );
static_cast<PCB_EDIT_FRAME*>( m_frame )->Fill_Zone( zone );
zone->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
......@@ -1179,7 +1284,8 @@ void DRAWING_TOOL::setTransitions()
Go( &DRAWING_TOOL::DrawDimension, COMMON_ACTIONS::drawDimension.MakeEvent() );
Go( &DRAWING_TOOL::DrawZone, COMMON_ACTIONS::drawZone.MakeEvent() );
Go( &DRAWING_TOOL::DrawKeepout, COMMON_ACTIONS::drawKeepout.MakeEvent() );
Go( &DRAWING_TOOL::PlaceText, COMMON_ACTIONS::placeText.MakeEvent() );
Go( &DRAWING_TOOL::PlaceTextPcb, COMMON_ACTIONS::placeTextPcb.MakeEvent() );
Go( &DRAWING_TOOL::PlaceTextModule, COMMON_ACTIONS::placeTextModule.MakeEvent() );
Go( &DRAWING_TOOL::PlaceTarget, COMMON_ACTIONS::placeTarget.MakeEvent() );
Go( &DRAWING_TOOL::PlaceModule, COMMON_ACTIONS::placeModule.MakeEvent() );
}
......@@ -33,7 +33,7 @@ namespace KIGFX
class VIEW_CONTROLS;
}
class BOARD;
class PCB_EDIT_FRAME;
class PCB_BASE_FRAME;
class DRAWSEGMENT;
/**
......@@ -76,11 +76,18 @@ public:
int DrawArc( TOOL_EVENT& aEvent );
/**
* Function DrawText()
* Function PlaceTextModule()
* Displays a dialog that allows to input text and its settings and then lets the user decide
* where to place the text.
* where to place the text in module editor.
*/
int PlaceText( TOOL_EVENT& aEvent );
int PlaceTextModule( TOOL_EVENT& aEvent );
/**
* Function PlaceTextPcb()
* Displays a dialog that allows to input text and its settings and then lets the user decide
* where to place the text in board editor.
*/
int PlaceTextPcb( TOOL_EVENT& aEvent );
/**
* Function DrawDimension()
......@@ -143,7 +150,7 @@ private:
KIGFX::VIEW* m_view;
KIGFX::VIEW_CONTROLS* m_controls;
BOARD* m_board;
PCB_EDIT_FRAME* m_frame;
PCB_BASE_FRAME* m_frame;
// How does line width change after one -/+ key press.
static const int WIDTH_STEP = 100000;
......
......@@ -93,7 +93,7 @@ int EDIT_TOOL::Main( TOOL_EVENT& aEvent )
m_updateFlag = KIGFX::VIEW_ITEM::GEOMETRY;
KIGFX::VIEW_CONTROLS* controls = getViewControls();
PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();
PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
controls->ShowCursor( true );
controls->SetSnapping( true );
controls->SetAutoPan( true );
......@@ -217,7 +217,7 @@ int EDIT_TOOL::Main( TOOL_EVENT& aEvent )
int EDIT_TOOL::Properties( TOOL_EVENT& aEvent )
{
const SELECTION_TOOL::SELECTION& selection = m_selectionTool->GetSelection();
PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();
PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
if( !makeSelection( selection ) )
{
......@@ -286,7 +286,7 @@ int EDIT_TOOL::Properties( TOOL_EVENT& aEvent )
int EDIT_TOOL::Rotate( TOOL_EVENT& aEvent )
{
const SELECTION_TOOL::SELECTION& selection = m_selectionTool->GetSelection();
PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();
PCB_BASE_FRAME* editFrame = getEditFrame<PCB_BASE_FRAME>();
// Shall the selection be cleared at the end?
bool unselect = selection.Empty();
......@@ -310,7 +310,7 @@ int EDIT_TOOL::Rotate( TOOL_EVENT& aEvent )
{
BOARD_ITEM* item = selection.Item<BOARD_ITEM>( i );
item->Rotate( rotatePoint, editFrame->GetRotationAngle() );
item->Rotate( rotatePoint, 900.0 /*m_frame->GetRotationAngle()*/ );
if( !m_dragging )
item->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
......@@ -340,7 +340,7 @@ int EDIT_TOOL::Rotate( TOOL_EVENT& aEvent )
int EDIT_TOOL::Flip( TOOL_EVENT& aEvent )
{
const SELECTION_TOOL::SELECTION& selection = m_selectionTool->GetSelection();
PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();
PCB_BASE_FRAME* editFrame = getEditFrame<PCB_BASE_FRAME>();
// Shall the selection be cleared at the end?
bool unselect = selection.Empty();
......@@ -404,7 +404,7 @@ int EDIT_TOOL::Remove( TOOL_EVENT& aEvent )
// Get a copy of the selected items set
PICKED_ITEMS_LIST selectedItems = selection.items;
PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();
PCB_BASE_FRAME* editFrame = getEditFrame<PCB_BASE_FRAME>();
// As we are about to remove items, they have to be removed from the selection first
m_selectionTool->ClearSelection();
......
......@@ -209,7 +209,7 @@ int POINT_EDITOR::OnSelectionChange( TOOL_EVENT& aEvent )
KIGFX::VIEW_CONTROLS* controls = getViewControls();
KIGFX::VIEW* view = getView();
PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();
PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
EDA_ITEM* item = selection.items.GetPickedItem( 0 );
m_editPoints = EDIT_POINTS_FACTORY::Make( item, getView()->GetGAL() );
......@@ -661,8 +661,8 @@ void POINT_EDITOR::breakOutline( const VECTOR2I& aBreakPoint )
if( item->Type() == PCB_ZONE_AREA_T )
{
getEditFrame<PCB_EDIT_FRAME>()->OnModify();
getEditFrame<PCB_EDIT_FRAME>()->SaveCopyInUndoList( selection.items, UR_CHANGED );
getEditFrame<PCB_BASE_FRAME>()->OnModify();
getEditFrame<PCB_BASE_FRAME>()->SaveCopyInUndoList( selection.items, UR_CHANGED );
ZONE_CONTAINER* zone = static_cast<ZONE_CONTAINER*>( item );
CPolyLine* outline = zone->Outline();
......@@ -702,8 +702,8 @@ void POINT_EDITOR::breakOutline( const VECTOR2I& aBreakPoint )
else if( item->Type() == PCB_LINE_T )
{
getEditFrame<PCB_EDIT_FRAME>()->OnModify();
getEditFrame<PCB_EDIT_FRAME>()->SaveCopyInUndoList( selection.items, UR_CHANGED );
getEditFrame<PCB_BASE_FRAME>()->OnModify();
getEditFrame<PCB_BASE_FRAME>()->SaveCopyInUndoList( selection.items, UR_CHANGED );
DRAWSEGMENT* segment = static_cast<DRAWSEGMENT*>( item );
......
......@@ -78,6 +78,8 @@ void SELECTION_TOOL::Reset( RESET_REASON aReason )
// Restore previous properties of selected items and remove them from containers
ClearSelection();
m_frame = getEditFrame<PCB_BASE_FRAME>();
// Reinsert the VIEW_GROUP, in case it was removed from the VIEW
getView()->Remove( m_selection.group );
getView()->Add( m_selection.group );
......@@ -185,7 +187,7 @@ int SELECTION_TOOL::Main( TOOL_EVENT& aEvent )
bool SELECTION_TOOL::SelectSingle( const VECTOR2I& aWhere, bool aAllowDisambiguation )
{
BOARD_ITEM* item;
GENERAL_COLLECTORS_GUIDE guide = getEditFrame<PCB_EDIT_FRAME>()->GetCollectorsGuide();
GENERAL_COLLECTORS_GUIDE guide = m_frame->GetCollectorsGuide();
GENERAL_COLLECTOR collector;
const KICAD_T types[] = { PCB_TRACE_T, PCB_VIA_T, PCB_LINE_T, EOT }; // preferred types
......@@ -269,7 +271,7 @@ void SELECTION_TOOL::ClearSelection()
}
m_selection.clear();
getEditFrame<PCB_EDIT_FRAME>()->SetCurItem( NULL );
m_frame->SetCurItem( NULL );
// Do not show the context menu when there is nothing selected
SetContextMenu( &m_menu, CMENU_OFF );
......@@ -370,7 +372,7 @@ bool SELECTION_TOOL::selectMultiple()
}
// Do not display information about selected item,as there is more than one
getEditFrame<PCB_EDIT_FRAME>()->SetCurItem( NULL );
m_frame->SetCurItem( NULL );
if( !m_selection.Empty() )
{
......@@ -586,7 +588,7 @@ void SELECTION_TOOL::select( BOARD_ITEM* aItem )
if( m_selection.Size() == 1 )
{
// Set as the current item, so the information about selection is displayed
getEditFrame<PCB_EDIT_FRAME>()->SetCurItem( aItem, true );
m_frame->SetCurItem( aItem, true );
// Now the context menu should be enabled
SetContextMenu( &m_menu, CMENU_BUTTON );
......@@ -594,7 +596,7 @@ void SELECTION_TOOL::select( BOARD_ITEM* aItem )
else if( m_selection.Size() == 2 ) // Check only for 2, so it will not be
{ // called for every next selected item
// If multiple items are selected, do not show the information about the selected item
getEditFrame<PCB_EDIT_FRAME>()->SetCurItem( NULL, true );
m_frame->SetCurItem( NULL, true );
}
}
......@@ -619,7 +621,7 @@ void SELECTION_TOOL::deselect( BOARD_ITEM* aItem )
if( m_selection.Empty() )
{
SetContextMenu( &m_menu, CMENU_OFF );
getEditFrame<PCB_EDIT_FRAME>()->SetCurItem( NULL );
m_frame->SetCurItem( NULL );
}
// Inform other potentially interested tools
......@@ -671,7 +673,7 @@ bool SELECTION_TOOL::selectionContains( const VECTOR2I& aPoint ) const
void SELECTION_TOOL::highlightNet( const VECTOR2I& aPoint )
{
KIGFX::RENDER_SETTINGS* render = getView()->GetPainter()->GetSettings();
GENERAL_COLLECTORS_GUIDE guide = getEditFrame<PCB_EDIT_FRAME>()->GetCollectorsGuide();
GENERAL_COLLECTORS_GUIDE guide = m_frame->GetCollectorsGuide();
GENERAL_COLLECTOR collector;
int net = -1;
......
......@@ -31,6 +31,7 @@
#include <tool/context_menu.h>
#include <class_undoredo_container.h>
class PCB_BASE_FRAME;
class SELECTION_AREA;
class BOARD_ITEM;
class GENERAL_COLLECTOR;
......@@ -257,6 +258,9 @@ private:
*/
BOARD_ITEM* prefer( GENERAL_COLLECTOR& aCollector, const KICAD_T aTypes[] ) const;
/// Pointer to the parent frame.
PCB_BASE_FRAME* m_frame;
/// Visual representation of selection box
SELECTION_AREA* m_selArea;
......
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