void DXF2BRD_CONVERTER::addText( const DRW_Text& aData ) { BOARD_ITEM* brdItem; EDA_TEXT* textItem; if( m_useModuleItems ) { TEXTE_MODULE* modText = new TEXTE_MODULE( NULL ); brdItem = static_cast< BOARD_ITEM* >( modText ); textItem = static_cast< EDA_TEXT* >( modText ); } else { TEXTE_PCB* pcbText = new TEXTE_PCB( NULL ); brdItem = static_cast< BOARD_ITEM* >( pcbText ); textItem = static_cast< EDA_TEXT* >( pcbText ); } brdItem->SetLayer( ToLAYER_ID( m_brdLayer ) ); wxPoint refPoint( mapX( aData.basePoint.x ), mapY( aData.basePoint.y ) ); wxPoint secPoint( mapX( aData.secPoint.x ), mapY( aData.secPoint.y ) ); if( aData.alignV != 0 || aData.alignH != 0 || aData.alignH == DRW_Text::HMiddle ) { if( aData.alignH != DRW_Text::HAligned && aData.alignH != DRW_Text::HFit ) { wxPoint tmp = secPoint; secPoint = refPoint; refPoint = tmp; } } switch( aData.alignV ) { case DRW_Text::VBaseLine: textItem->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM ); break; case DRW_Text::VBottom: textItem->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM ); break; case DRW_Text::VMiddle: textItem->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER ); break; case DRW_Text::VTop: textItem->SetVertJustify( GR_TEXT_VJUSTIFY_TOP ); break; } switch( aData.alignH ) { case DRW_Text::HLeft: textItem->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT ); break; case DRW_Text::HCenter: textItem->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER ); break; case DRW_Text::HRight: textItem->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT ); break; case DRW_Text::HAligned: // no equivalent options in text pcb. textItem->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT ); break; case DRW_Text::HMiddle: // no equivalent options in text pcb. textItem->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER ); break; case DRW_Text::HFit: // no equivalent options in text pcb. textItem->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT ); break; } #if 0 wxString sty = wxString::FromUTF8( aData.style.c_str() ); sty = sty.ToLower(); if( aData.textgen == 2 ) { // Text dir = left to right; } else if( aData.textgen == 4 ) { // Text dir = top to bottom; } else { } #endif wxString text = toNativeString( wxString::FromUTF8( aData.text.c_str() ) ); textItem->SetTextPos( refPoint ); textItem->SetTextAngle( aData.angle * 10 ); // The 0.8 factor gives a better height/width ratio with our font textItem->SetTextWidth( mapDim( aData.height * 0.8 ) ); textItem->SetTextHeight( mapDim( aData.height ) ); textItem->SetThickness( mapDim( aData.thickness == 0 ? m_defaultThickness : aData.thickness ) ); textItem->SetText( text ); m_newItemsList.push_back( static_cast< BOARD_ITEM* >( brdItem ) ); }
void DXF2BRD_CONVERTER::addMText( const DRW_MText& aData ) { wxString text = toNativeString( wxString::FromUTF8( aData.text.c_str() ) ); wxString attrib, tmp; /* Some texts start by '\' and have formating chars (font name, font option...) * ending with ';' * Here are some mtext formatting codes: * Format code Purpose * \0...\o Turns overline on and off * \L...\l Turns underline on and off * \~ Inserts a nonbreaking space \\ Inserts a backslash \\\{...\} Inserts an opening and closing brace \\ \File name; Changes to the specified font file \\ \Hvalue; Changes to the text height specified in drawing units \\ \Hvaluex; Changes the text height to a multiple of the current text height \\ \S...^...; Stacks the subsequent text at the \, #, or ^ symbol \\ \Tvalue; Adjusts the space between characters, from.75 to 4 times \\ \Qangle; Changes obliquing angle \\ \Wvalue; Changes width factor to produce wide text \\ \A Sets the alignment value; valid values: 0, 1, 2 (bottom, center, top) while( text.StartsWith( wxT("\\") ) ) */ while( text.StartsWith( wxT( "\\" ) ) ) { attrib << text.BeforeFirst( ';' ); tmp = text.AfterFirst( ';' ); text = tmp; } BOARD_ITEM* brdItem; EDA_TEXT* textItem; if( m_useModuleItems ) { TEXTE_MODULE* modText = new TEXTE_MODULE( NULL ); brdItem = static_cast< BOARD_ITEM* >( modText ); textItem = static_cast< EDA_TEXT* >( modText ); } else { TEXTE_PCB* pcbText = new TEXTE_PCB( NULL ); brdItem = static_cast< BOARD_ITEM* >( pcbText ); textItem = static_cast< EDA_TEXT* >( pcbText ); } brdItem->SetLayer( ToLAYER_ID( m_brdLayer ) ); wxPoint textpos( mapX( aData.basePoint.x ), mapY( aData.basePoint.y ) ); textItem->SetTextPos( textpos ); textItem->SetTextAngle( aData.angle * 10 ); // The 0.8 factor gives a better height/width ratio with our font textItem->SetTextWidth( mapDim( aData.height * 0.8 ) ); textItem->SetTextHeight( mapDim( aData.height ) ); textItem->SetThickness( mapDim( aData.thickness == 0 ? m_defaultThickness : aData.thickness ) ); textItem->SetText( text ); // Initialize text justifications: if( aData.textgen <= 3 ) { textItem->SetVertJustify( GR_TEXT_VJUSTIFY_TOP ); } else if( aData.textgen <= 6 ) { textItem->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER ); } else { textItem->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM ); } if( aData.textgen % 3 == 1 ) { textItem->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT ); } else if( aData.textgen % 3 == 2 ) { textItem->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER ); } else { textItem->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT ); } #if 0 // These setting have no mening in Pcbnew if( data.alignH == 1 ) { // Text is left to right; } else if( data.alignH == 3 ) { // Text is top to bottom; } else { // use ByStyle; } if( aData.alignV == 1 ) { // use AtLeast; } else { // useExact; } #endif m_newItemsList.push_back( static_cast< BOARD_ITEM* >( brdItem ) ); }
int DRAWING_TOOL::PlaceDXF( const TOOL_EVENT& aEvent ) { if( !m_frame->GetModel() ) return 0; DIALOG_DXF_IMPORT dlg( m_frame ); int dlgResult = dlg.ShowModal(); const std::list<BOARD_ITEM*>& list = dlg.GetImportedItems(); if( dlgResult != wxID_OK || list.empty() ) return 0; VECTOR2I cursorPos = m_controls->GetCursorPosition(); VECTOR2I delta = cursorPos - list.front()->GetPosition(); // Add a VIEW_GROUP that serves as a preview for the new item SELECTION preview( m_view ); BOARD_COMMIT commit( m_frame ); // Build the undo list & add items to the current view for( auto item : list ) { assert( item->Type() == PCB_LINE_T || item->Type() == PCB_TEXT_T ); preview.Add( item ); } BOARD_ITEM* firstItem = preview.Front(); m_view->Add( &preview ); m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true ); m_controls->ShowCursor( true ); m_controls->SetSnapping( true ); SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::DXF ); Activate(); // Main loop: keep receiving events while( OPT_TOOL_EVENT evt = Wait() ) { cursorPos = m_controls->GetCursorPosition(); if( evt->IsMotion() ) { delta = cursorPos - firstItem->GetPosition(); for( auto item : preview ) item->Move( wxPoint( delta.x, delta.y ) ); m_view->Update( &preview ); } else if( evt->Category() == TC_COMMAND ) { // TODO it should be handled by EDIT_TOOL, so add items and select? if( evt->IsAction( &COMMON_ACTIONS::rotate ) ) { for( auto item : preview ) item->Rotate( wxPoint( cursorPos.x, cursorPos.y ), m_frame->GetRotationAngle() ); m_view->Update( &preview ); } else if( evt->IsAction( &COMMON_ACTIONS::flip ) ) { for( auto item : preview ) item->Flip( wxPoint( cursorPos.x, cursorPos.y ) ); m_view->Update( &preview ); } else if( evt->IsCancel() || evt->IsActivate() ) { preview.FreeItems(); break; } } else if ( evt->IsClick( BUT_RIGHT ) ) { showContextMenu(); } else if( evt->IsClick( BUT_LEFT ) ) { // Place the drawing BOARD_ITEM_CONTAINER* parent = m_frame->GetModel(); for( auto item : preview ) { if( m_editModules ) { // Modules use different types for the same things, // so we need to convert imported items to appropriate classes. BOARD_ITEM* converted = NULL; switch( item->Type() ) { case PCB_TEXT_T: { TEXTE_PCB* text = static_cast<TEXTE_PCB*>( item ); TEXTE_MODULE* textMod = new TEXTE_MODULE( (MODULE*) parent ); // Assignment operator also copies the item PCB_TEXT_T type, // so it cannot be added to a module which handles PCB_MODULE_TEXT_T textMod->SetPosition( text->GetPosition() ); textMod->SetText( text->GetText() ); textMod->SetSize( text->GetSize() ); textMod->SetThickness( text->GetThickness() ); textMod->SetOrientation( text->GetOrientation() ); textMod->SetTextPosition( text->GetTextPosition() ); textMod->SetSize( text->GetSize() ); textMod->SetMirrored( text->IsMirrored() ); textMod->SetAttributes( text->GetAttributes() ); textMod->SetItalic( text->IsItalic() ); textMod->SetBold( text->IsBold() ); textMod->SetHorizJustify( text->GetHorizJustify() ); textMod->SetVertJustify( text->GetVertJustify() ); textMod->SetMultilineAllowed( text->IsMultilineAllowed() ); converted = textMod; break; } case PCB_LINE_T: { DRAWSEGMENT* seg = static_cast<DRAWSEGMENT*>( item ); EDGE_MODULE* modSeg = new EDGE_MODULE( (MODULE*) parent ); // Assignment operator also copies the item PCB_LINE_T type, // so it cannot be added to a module which handles PCB_MODULE_EDGE_T modSeg->SetWidth( seg->GetWidth() ); modSeg->SetStart( seg->GetStart() ); modSeg->SetEnd( seg->GetEnd() ); modSeg->SetAngle( seg->GetAngle() ); modSeg->SetShape( seg->GetShape() ); modSeg->SetType( seg->GetType() ); modSeg->SetBezControl1( seg->GetBezControl1() ); modSeg->SetBezControl2( seg->GetBezControl2() ); modSeg->SetBezierPoints( seg->GetBezierPoints() ); modSeg->SetPolyPoints( seg->GetPolyPoints() ); converted = modSeg; break; } default: assert( false ); break; } if( converted ) converted->SetLayer( item->GetLayer() ); delete item; item = converted; } if( item ) commit.Add( item ); } commit.Push( _( "Place a DXF drawing" ) ); break; } } preview.Clear(); m_controls->ShowCursor( false ); m_controls->SetSnapping( false ); m_controls->SetAutoPan( false ); m_controls->CaptureCursor( false ); m_view->Remove( &preview ); return 0; }