Basic text placing tool.
This commit is contained in:
parent
02316e02c3
commit
4b27778451
|
@ -195,7 +195,8 @@ TEXTE_PCB* PCB_EDIT_FRAME::CreateTextePcb( wxDC* aDC, TEXTE_PCB* aText )
|
|||
textePcb->Copy( aText );
|
||||
GetBoard()->Add( textePcb );
|
||||
textePcb->SetFlags( IS_NEW );
|
||||
StartMoveTextePcb( textePcb, aDC, false ); // Don't erase aText when copying
|
||||
if( aDC )
|
||||
StartMoveTextePcb( textePcb, aDC, false ); // Don't erase aText when copying
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -222,7 +223,7 @@ TEXTE_PCB* PCB_EDIT_FRAME::CreateTextePcb( wxDC* aDC, TEXTE_PCB* aText )
|
|||
textePcb->DeleteStructure();
|
||||
textePcb = NULL;
|
||||
}
|
||||
else
|
||||
else if( aDC )
|
||||
{
|
||||
StartMoveTextePcb( textePcb, aDC );
|
||||
}
|
||||
|
|
|
@ -68,3 +68,7 @@ TOOL_ACTION COMMON_ACTIONS::drawCircle( "pcbnew.InteractiveDrawing.circle",
|
|||
TOOL_ACTION COMMON_ACTIONS::drawArc( "pcbnew.InteractiveDrawing.arc",
|
||||
AS_GLOBAL, 'A',
|
||||
"Draw an arc", "Draw an arc" );
|
||||
|
||||
TOOL_ACTION COMMON_ACTIONS::drawText( "pcbnew.InteractiveDrawing.text",
|
||||
AS_GLOBAL, 'T',
|
||||
"Add a text", "Add a text" );
|
||||
|
|
|
@ -65,4 +65,7 @@ public:
|
|||
|
||||
/// Activation of the drawing tool (arc)
|
||||
static TOOL_ACTION drawArc;
|
||||
|
||||
/// Activation of the drawing tool (text)
|
||||
static TOOL_ACTION drawText;
|
||||
};
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include <view/view_controls.h>
|
||||
#include <class_board.h>
|
||||
#include <class_drawsegment.h>
|
||||
#include <class_pcb_text.h>
|
||||
#include <gal/graphics_abstraction_layer.h>
|
||||
#include <tool/tool_manager.h>
|
||||
#include <confirm.h>
|
||||
|
@ -159,7 +160,7 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
|
|||
{
|
||||
DRAWSEGMENT* newItem = new DRAWSEGMENT( graphic );
|
||||
view->Add( newItem );
|
||||
getModel<BOARD>( PCB_T )->Add( newItem );
|
||||
board->Add( newItem );
|
||||
newItem->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
|
||||
}
|
||||
}
|
||||
|
@ -291,7 +292,7 @@ int DRAWING_TOOL::draw( STROKE_T aShape )
|
|||
{
|
||||
DRAWSEGMENT* newItem = new DRAWSEGMENT( graphic );
|
||||
view->Add( newItem );
|
||||
getModel<BOARD>( PCB_T )->Add( newItem );
|
||||
board->Add( newItem );
|
||||
newItem->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
|
||||
|
||||
if( m_continous )
|
||||
|
@ -342,9 +343,70 @@ int DRAWING_TOOL::draw( STROKE_T aShape )
|
|||
}
|
||||
|
||||
|
||||
int DRAWING_TOOL::DrawText( TOOL_EVENT& aEvent )
|
||||
{
|
||||
KIGFX::VIEW* view = getView();
|
||||
KIGFX::VIEW_CONTROLS* controls = getViewControls();
|
||||
|
||||
// Init the new item attributes
|
||||
TEXTE_PCB* newText = getEditFrame<PCB_EDIT_FRAME>()->CreateTextePcb( NULL );
|
||||
|
||||
// Add a VIEW_GROUP that serves as a preview for the new item
|
||||
KIGFX::VIEW_GROUP preview( view );
|
||||
preview.Add( newText );
|
||||
view->Add( &preview );
|
||||
|
||||
controls->ShowCursor( true );
|
||||
controls->SetSnapping( true );
|
||||
controls->SetAutoPan( true );
|
||||
|
||||
Activate();
|
||||
|
||||
// Main loop: keep receiving events
|
||||
while( OPT_TOOL_EVENT evt = Wait() )
|
||||
{
|
||||
VECTOR2D cursorPos = view->ToWorld( controls->GetCursorPosition() );
|
||||
|
||||
if( evt->IsCancel() )
|
||||
{
|
||||
// it was already added by CreateTextPcb()
|
||||
getModel<BOARD>( PCB_T )->Delete( newText );
|
||||
break;
|
||||
}
|
||||
|
||||
else if( evt->IsClick( BUT_LEFT ) )
|
||||
{
|
||||
newText->ClearFlags();
|
||||
view->Add( newText );
|
||||
// board->Add( newText ); // it is already added by CreateTextePcb()
|
||||
newText->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
|
||||
break;
|
||||
}
|
||||
|
||||
else if( evt->IsMotion() )
|
||||
{
|
||||
newText->SetTextPosition( wxPoint( cursorPos.x, cursorPos.y ) );
|
||||
|
||||
// Show a preview of the item
|
||||
preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
|
||||
}
|
||||
}
|
||||
|
||||
controls->ShowCursor( false );
|
||||
controls->SetSnapping( false );
|
||||
controls->SetAutoPan( false );
|
||||
view->Remove( &preview );
|
||||
|
||||
setTransitions();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void DRAWING_TOOL::setTransitions()
|
||||
{
|
||||
Go( &DRAWING_TOOL::DrawLine, COMMON_ACTIONS::drawLine.MakeEvent() );
|
||||
Go( &DRAWING_TOOL::DrawCircle, COMMON_ACTIONS::drawCircle.MakeEvent() );
|
||||
Go( &DRAWING_TOOL::DrawArc, COMMON_ACTIONS::drawArc.MakeEvent() );
|
||||
Go( &DRAWING_TOOL::DrawText, COMMON_ACTIONS::drawText.MakeEvent() );
|
||||
}
|
||||
|
|
|
@ -55,6 +55,8 @@ public:
|
|||
|
||||
int DrawArc( TOOL_EVENT& aEvent );
|
||||
|
||||
int DrawText( TOOL_EVENT& aEvent );
|
||||
|
||||
private:
|
||||
///> Starts drawing a selected shape.
|
||||
int draw( STROKE_T aShape );
|
||||
|
|
|
@ -58,6 +58,7 @@ void PCB_EDIT_FRAME::setupTools()
|
|||
m_toolManager->RegisterAction( &COMMON_ACTIONS::drawLine );
|
||||
m_toolManager->RegisterAction( &COMMON_ACTIONS::drawCircle );
|
||||
m_toolManager->RegisterAction( &COMMON_ACTIONS::drawArc );
|
||||
m_toolManager->RegisterAction( &COMMON_ACTIONS::drawText );
|
||||
|
||||
// Register tools
|
||||
m_toolManager->RegisterTool( new SELECTION_TOOL );
|
||||
|
|
Loading…
Reference in New Issue