// Create hierarchy sheet. SCH_SHEET* SCH_EDIT_FRAME::CreateSheet( wxDC* aDC ) { SetRepeatItem( NULL ); SCH_SHEET* sheet = new SCH_SHEET( GetCrossHairPosition() ); sheet->SetFlags( IS_NEW | IS_RESIZED ); sheet->SetTimeStamp( GetNewTimeStamp() ); sheet->SetParent( GetScreen() ); sheet->SetScreen( NULL ); // need to check if this is being added to the GetDrawItems(). // also need to update the hierarchy, if we are adding // a sheet to a screen that already has multiple instances (!) GetScreen()->SetCurItem( sheet ); m_canvas->SetMouseCapture( resizeSheetWithMouseCursor, ExitSheet ); m_canvas->CallMouseCapture( aDC, wxDefaultPosition, false ); m_canvas->CrossHairOff( aDC ); SetCrossHairPosition( sheet->GetResizePosition() ); m_canvas->MoveCursorToCrossHair(); m_canvas->CrossHairOn( aDC ); return sheet; }
void SCH_EDIT_FRAME::MoveItem( SCH_ITEM* aItem, wxDC* aDC ) { wxCHECK_RET( aItem != NULL, wxT( "Cannot move invalid schematic item" ) ); SetRepeatItem( NULL ); if( !aItem->IsNew() ) { if( (aItem->Type() == SCH_SHEET_PIN_T) || (aItem->Type() == SCH_FIELD_T) ) SetUndoItem( (SCH_ITEM*) aItem->GetParent() ); else SetUndoItem( aItem ); } aItem->SetFlags( IS_MOVED ); #ifdef USE_WX_OVERLAY this->Refresh(); this->Update(); #endif m_canvas->CrossHairOff( aDC ); if( aItem->Type() != SCH_SHEET_PIN_T ) SetCrossHairPosition( aItem->GetPosition() ); m_canvas->MoveCursorToCrossHair(); OnModify(); m_canvas->SetMouseCapture( moveItem, abortMoveItem ); GetScreen()->SetCurItem( aItem ); moveItem( m_canvas, aDC, wxDefaultPosition, true ); m_canvas->CrossHairOn( aDC ); }
SCH_NO_CONNECT* SCH_EDIT_FRAME::AddNoConnect( wxDC* aDC, const wxPoint& aPosition ) { SCH_NO_CONNECT* no_connect = new SCH_NO_CONNECT( aPosition ); SetRepeatItem( no_connect ); GetScreen()->Append( no_connect ); GetScreen()->SchematicCleanUp(); OnModify(); m_canvas->Refresh(); SaveCopyInUndoList( no_connect, UR_NEW ); return no_connect; }
void SCH_EDIT_FRAME::PrepareMoveItem( SCH_ITEM* aItem, wxDC* aDC ) { wxCHECK_RET( aItem != NULL, wxT( "Cannot move invalid schematic item" ) ); SetRepeatItem( NULL ); if( !aItem->IsNew() ) { if( (aItem->Type() == SCH_SHEET_PIN_T) || (aItem->Type() == SCH_FIELD_T) ) SetUndoItem( (SCH_ITEM*) aItem->GetParent() ); else SetUndoItem( aItem ); } if( aItem->Type() == SCH_FIELD_T && aItem->GetParent()->Type() == SCH_COMPONENT_T ) { // Now that we're moving a field, they're no longer autoplaced. SCH_COMPONENT *parent = static_cast<SCH_COMPONENT*>( aItem->GetParent() ); parent->ClearFieldsAutoplaced(); } aItem->SetFlags( IS_MOVED ); // For some items, moving the cursor to anchor is not good // (for instance large hierarchical sheets od componants can have // the anchor position outside the canvas) // these items return IsMovableFromAnchorPoint() == false // For these items, do not wrap the cursor if( aItem->IsMovableFromAnchorPoint() ) { SetCrossHairPosition( aItem->GetPosition() ); m_canvas->MoveCursorToCrossHair(); aItem->SetStoredPos( wxPoint( 0,0 ) ); } else { // Round the point under the cursor to a multiple of the grid wxPoint cursorpos = GetCrossHairPosition() - aItem->GetPosition(); wxPoint gridsize = GetScreen()->GetGridSize(); cursorpos.x = ( cursorpos.x / gridsize.x ) * gridsize.x; cursorpos.y = ( cursorpos.y / gridsize.y ) * gridsize.y; aItem->SetStoredPos( cursorpos ); } OnModify(); GetScreen()->SetCurItem( aItem ); m_canvas->SetMouseCapture( moveItemWithMouseCursor, abortMoveItem ); m_canvas->Refresh(); }
void SCH_EDIT_FRAME::RepeatDrawItem( wxDC* DC ) { SCH_ITEM* repeater = GetRepeatItem(); if( !repeater ) return; //D( repeater>Show( 0, std::cout ); ) // clone the repeater, move it, insert into display list, then save a copy // via SetRepeatItem(); SCH_ITEM* my_clone = (SCH_ITEM*) repeater->Clone(); // If cloning a component then put into 'move' mode. if( my_clone->Type() == SCH_COMPONENT_T ) { wxPoint pos = GetCrossHairPosition() - ( (SCH_COMPONENT*) my_clone )->GetPosition(); my_clone->SetFlags( IS_NEW ); ( (SCH_COMPONENT*) my_clone )->SetTimeStamp( GetNewTimeStamp() ); my_clone->Move( pos ); my_clone->Draw( m_canvas, DC, wxPoint( 0, 0 ), g_XorMode ); PrepareMoveItem( my_clone, DC ); } else { my_clone->Move( GetRepeatStep() ); if( my_clone->CanIncrementLabel() ) ( (SCH_TEXT*) my_clone )->IncrementLabel( GetRepeatDeltaLabel() ); GetScreen()->Append( my_clone ); if( my_clone->IsConnectable() ) { GetScreen()->TestDanglingEnds(); m_canvas->Refresh(); } else { my_clone->Draw( m_canvas, DC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE ); } SaveCopyInUndoList( my_clone, UR_NEW ); my_clone->ClearFlags(); } // clone my_clone, now that it has been moved, thus saving new position. SetRepeatItem( my_clone ); }
void SCH_EDIT_FRAME::DeleteCurrentSegment( wxDC* DC ) { SCH_SCREEN* screen = GetScreen(); SetRepeatItem( NULL ); if( ( screen->GetCurItem() == NULL ) || !screen->GetCurItem()->IsNew() ) return; DrawSegment( m_canvas, DC, wxDefaultPosition, false ); screen->Remove( screen->GetCurItem() ); m_canvas->SetMouseCaptureCallback( NULL ); screen->SetCurItem( NULL ); }
void SCH_EDIT_FRAME::DisplayCurrentSheet() { SetRepeatItem( NULL ); ClearMsgPanel(); SCH_SCREEN* screen = m_CurrentSheet->LastScreen(); // Switch to current sheet, // and update the grid size, because it can be modified in latest screen SetScreen( screen ); GetScreen()->SetGrid( m_LastGridSizeId + ID_POPUP_GRID_LEVEL_1000 ); // update the References m_CurrentSheet->UpdateAllScreenReferences(); SetSheetNumberAndCount(); m_canvas->SetCanStartBlock( -1 ); if( screen->m_FirstRedraw ) { Zoom_Automatique( false ); screen->m_FirstRedraw = false; SetCrossHairPosition( GetScrollCenterPosition() ); m_canvas->MoveCursorToCrossHair(); // Ensure the schematic is fully segmented on first display BreakSegmentsOnJunctions(); SchematicCleanUp( true ); screen->ClearUndoORRedoList( screen->m_UndoList, 1 ); screen->TestDanglingEnds(); } else { RedrawScreen( GetScrollCenterPosition(), true ); } // Some items (wires, labels) can be highlighted. So prepare the highlight flag: SetCurrentSheetHighlightFlags(); // Now refresh m_canvas. Should be not necessary, but because screen has changed // the previous refresh has set all new draw parameters (scroll position ..) // but most of time there were some inconsitencies about cursor parameters // ( previous position of cursor ...) and artefacts can happen // mainly when sheet size has changed // This second refresh clears artefacts because at this point, // all parameters are now updated m_canvas->Refresh(); }
SCH_NO_CONNECT* SCH_EDIT_FRAME::AddNoConnect( wxDC* aDC, const wxPoint& aPosition ) { SCH_NO_CONNECT* no_connect = new SCH_NO_CONNECT( aPosition ); SetRepeatItem( no_connect ); m_canvas->CrossHairOff( aDC ); // Erase schematic cursor no_connect->Draw( m_canvas, aDC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE ); m_canvas->CrossHairOn( aDC ); // Display schematic cursor GetScreen()->Append( no_connect ); OnModify(); SaveCopyInUndoList( no_connect, UR_NEW ); return no_connect; }
SCH_JUNCTION* SCH_EDIT_FRAME::AddJunction( wxDC* aDC, const wxPoint& aPosition, bool aPutInUndoList ) { SCH_JUNCTION* junction = new SCH_JUNCTION( aPosition ); SetRepeatItem( junction ); m_canvas->CrossHairOff( aDC ); // Erase schematic cursor junction->Draw( m_canvas, aDC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE ); m_canvas->CrossHairOn( aDC ); // Display schematic cursor if( aPutInUndoList ) { GetScreen()->Append( junction ); SaveCopyInUndoList( junction, UR_NEW ); OnModify(); } return junction; }
void SCH_EDIT_FRAME::PrepareMoveItem( SCH_ITEM* aItem, wxDC* aDC ) { wxCHECK_RET( aItem != NULL, wxT( "Cannot move invalid schematic item" ) ); SetRepeatItem( NULL ); if( !aItem->IsNew() ) { if( (aItem->Type() == SCH_SHEET_PIN_T) || (aItem->Type() == SCH_FIELD_T) ) SetUndoItem( (SCH_ITEM*) aItem->GetParent() ); else SetUndoItem( aItem ); } aItem->SetFlags( IS_MOVED ); // For some items, moving the cursor to anchor is not good // (for instance large hierarchical sheets od componants can have // the anchor position outside the canvas) // these items return IsMovableFromAnchorPoint() == false // For these items, do not wrap the cursor if( aItem->IsMovableFromAnchorPoint() ) { SetCrossHairPosition( aItem->GetPosition() ); m_canvas->MoveCursorToCrossHair(); aItem->SetStoredPos( wxPoint( 0,0 ) ); } else aItem->SetStoredPos( GetCrossHairPosition() - aItem->GetPosition() ); OnModify(); m_canvas->SetMouseCapture( moveItemWithMouseCursor, abortMoveItem ); GetScreen()->SetCurItem( aItem ); m_canvas->Refresh(); }
bool SCH_EDIT_FRAME::DeleteItemAtCrossHair( wxDC* DC ) { SCH_ITEM* item; SCH_SCREEN* screen = GetScreen(); item = LocateItem( GetCrossHairPosition(), SCH_COLLECTOR::ParentItems ); if( item ) { bool itemHasConnections = item->IsConnectable(); screen->SetCurItem( NULL ); SetRepeatItem( NULL ); DeleteItem( item ); if( itemHasConnections ) screen->TestDanglingEnds( m_canvas, DC ); OnModify(); return true; } return false; }
void SCH_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) { int id = event.GetId(); wxPoint pos; SCH_SCREEN* screen = GetScreen(); SCH_ITEM* item = screen->GetCurItem(); pos = wxGetMousePosition(); pos.y += 20; // If needed, stop the current command and deselect current tool switch( id ) { case wxID_CUT: case wxID_COPY: case ID_POPUP_CANCEL_CURRENT_COMMAND: case ID_POPUP_SCH_ENTRY_SELECT_SLASH: case ID_POPUP_SCH_ENTRY_SELECT_ANTISLASH: case ID_POPUP_SCH_BEGIN_WIRE: case ID_POPUP_SCH_BEGIN_BUS: case ID_POPUP_END_LINE: case ID_POPUP_SCH_SET_SHAPE_TEXT: case ID_POPUP_SCH_CLEANUP_SHEET: case ID_POPUP_SCH_END_SHEET: case ID_POPUP_SCH_RESIZE_SHEET: case ID_POPUP_IMPORT_GLABEL: case ID_POPUP_SCH_INIT_CMP: case ID_POPUP_SCH_DISPLAYDOC_CMP: case ID_POPUP_SCH_EDIT_CONVERT_CMP: case ID_POPUP_DELETE_BLOCK: case ID_POPUP_PLACE_BLOCK: case ID_POPUP_ZOOM_BLOCK: case ID_POPUP_DRAG_BLOCK: case ID_POPUP_COPY_BLOCK: case ID_POPUP_SCH_DELETE_NODE: case ID_POPUP_SCH_DELETE_CONNECTION: case ID_POPUP_SCH_ENTER_SHEET: case ID_POPUP_SCH_LEAVE_SHEET: case ID_POPUP_SCH_ADD_JUNCTION: case ID_POPUP_SCH_ADD_LABEL: case ID_POPUP_SCH_GETINFO_MARKER: /* At this point: Do nothing. these commands do not need to stop the * current command (mainly a block command) or reset the current state * They will be executed later, in next switch structure. */ break; case ID_POPUP_SCH_DELETE_CMP: case ID_POPUP_SCH_DELETE: // Stop the current command (if any) but keep the current tool m_canvas->EndMouseCapture(); break; default: // Stop the current command and deselect the current tool m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() ); break; } INSTALL_UNBUFFERED_DC( dc, m_canvas ); item = screen->GetCurItem(); // Can be modified by previous calls. switch( id ) { case ID_HIERARCHY: InstallHierarchyFrame( &dc, pos ); SetRepeatItem( NULL ); break; case wxID_CUT: if( screen->m_BlockLocate.GetCommand() != BLOCK_MOVE ) break; screen->m_BlockLocate.SetCommand( BLOCK_DELETE ); screen->m_BlockLocate.SetMessageBlock( this ); HandleBlockEnd( &dc ); SetRepeatItem( NULL ); SetSheetNumberAndCount(); break; case wxID_PASTE: HandleBlockBegin( &dc, BLOCK_PASTE, GetCrossHairPosition() ); break; case ID_POPUP_SCH_ENTRY_SELECT_SLASH: m_canvas->MoveCursorToCrossHair(); SetBusEntryShape( &dc, dynamic_cast<SCH_BUS_ENTRY_BASE*>( item ), '/' ); break; case ID_POPUP_SCH_ENTRY_SELECT_ANTISLASH: m_canvas->MoveCursorToCrossHair(); SetBusEntryShape( &dc, dynamic_cast<SCH_BUS_ENTRY_BASE*>( item ), '\\' ); break; case ID_POPUP_CANCEL_CURRENT_COMMAND: if( m_canvas->IsMouseCaptured() ) { m_canvas->EndMouseCapture(); SetToolID( GetToolId(), m_canvas->GetCurrentCursor(), wxEmptyString ); } else { SetToolID( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(), wxEmptyString ); } break; case ID_POPUP_END_LINE: m_canvas->MoveCursorToCrossHair(); EndSegment( &dc ); break; case ID_POPUP_SCH_BEGIN_WIRE: m_canvas->MoveCursorToCrossHair(); OnLeftClick( &dc, GetCrossHairPosition() ); break; case ID_POPUP_SCH_BEGIN_BUS: m_canvas->MoveCursorToCrossHair(); OnLeftClick( &dc, GetCrossHairPosition() ); break; case ID_POPUP_SCH_SET_SHAPE_TEXT: // Not used break; case ID_POPUP_SCH_DELETE_NODE: case ID_POPUP_SCH_DELETE_CONNECTION: m_canvas->MoveCursorToCrossHair(); DeleteConnection( id == ID_POPUP_SCH_DELETE_CONNECTION ); screen->SetCurItem( NULL ); SetRepeatItem( NULL ); screen->TestDanglingEnds( m_canvas, &dc ); m_canvas->Refresh(); break; case ID_POPUP_SCH_BREAK_WIRE: { DLIST< SCH_ITEM > oldWires; oldWires.SetOwnership( false ); // Prevent DLIST for deleting items in destructor. m_canvas->MoveCursorToCrossHair(); screen->ExtractWires( oldWires, true ); screen->BreakSegment( GetCrossHairPosition() ); if( oldWires.GetCount() != 0 ) { PICKED_ITEMS_LIST oldItems; oldItems.m_Status = UR_WIRE_IMAGE; while( oldWires.GetCount() != 0 ) { ITEM_PICKER picker = ITEM_PICKER( oldWires.PopFront(), UR_WIRE_IMAGE ); oldItems.PushItem( picker ); } SaveCopyInUndoList( oldItems, UR_WIRE_IMAGE ); } screen->TestDanglingEnds( m_canvas, &dc ); } break; case ID_POPUP_SCH_DELETE_CMP: case ID_POPUP_SCH_DELETE: if( item == NULL ) break; DeleteItem( item ); screen->SetCurItem( NULL ); SetRepeatItem( NULL ); screen->TestDanglingEnds( m_canvas, &dc ); SetSheetNumberAndCount(); OnModify(); break; case ID_POPUP_SCH_END_SHEET: m_canvas->MoveCursorToCrossHair(); addCurrentItemToList( &dc ); break; case ID_POPUP_SCH_RESIZE_SHEET: ReSizeSheet( (SCH_SHEET*) item, &dc ); screen->TestDanglingEnds( m_canvas, &dc ); break; case ID_POPUP_IMPORT_GLABEL: if( item != NULL && item->Type() == SCH_SHEET_T ) screen->SetCurItem( ImportSheetPin( (SCH_SHEET*) item, &dc ) ); break; case ID_POPUP_SCH_CLEANUP_SHEET: if( item != NULL && item->Type() == SCH_SHEET_T ) { SCH_SHEET* sheet = (SCH_SHEET*) item; if( !sheet->HasUndefinedPins() ) { DisplayInfoMessage( this, _( "There are no undefined labels in this sheet to clean up." ) ); return; } if( !IsOK( this, _( "Do you wish to cleanup this sheet?" ) ) ) return; /* Save sheet in undo list before cleaning up unreferenced hierarchical labels. */ SaveCopyInUndoList( sheet, UR_CHANGED ); sheet->CleanupSheet(); OnModify(); m_canvas->RefreshDrawingRect( sheet->GetBoundingBox() ); } break; case ID_POPUP_SCH_INIT_CMP: m_canvas->MoveCursorToCrossHair(); break; case ID_POPUP_SCH_EDIT_CONVERT_CMP: // Ensure the struct is a component (could be a struct of a component, like Field, text..) if( item && item->Type() == SCH_COMPONENT_T ) { m_canvas->MoveCursorToCrossHair(); ConvertPart( (SCH_COMPONENT*) item, &dc ); } break; case ID_POPUP_SCH_DISPLAYDOC_CMP: // Ensure the struct is a component (could be a piece of a component, like Field, text..) if( item && item->Type() == SCH_COMPONENT_T ) { LIB_ALIAS* LibEntry; LibEntry = CMP_LIBRARY::FindLibraryEntry( ( (SCH_COMPONENT*) item )->GetLibName() ); if( LibEntry && LibEntry->GetDocFileName() != wxEmptyString ) { GetAssociatedDocument( this, LibEntry->GetDocFileName(), &wxGetApp().GetLibraryPathList() ); } } break; case ID_POPUP_SCH_ENTER_SHEET: if( item && (item->Type() == SCH_SHEET_T) ) { m_CurrentSheet->Push( (SCH_SHEET*) item ); DisplayCurrentSheet(); } break; case ID_POPUP_SCH_LEAVE_SHEET: m_CurrentSheet->Pop(); DisplayCurrentSheet(); break; case wxID_COPY: // really this is a Save block for paste screen->m_BlockLocate.SetCommand( BLOCK_SAVE ); screen->m_BlockLocate.SetMessageBlock( this ); HandleBlockEnd( &dc ); break; case ID_POPUP_PLACE_BLOCK: m_canvas->SetAutoPanRequest( false ); m_canvas->MoveCursorToCrossHair(); HandleBlockPlace( &dc ); break; case ID_POPUP_ZOOM_BLOCK: screen->m_BlockLocate.SetCommand( BLOCK_ZOOM ); screen->m_BlockLocate.SetMessageBlock( this ); HandleBlockEnd( &dc ); break; case ID_POPUP_DELETE_BLOCK: m_canvas->MoveCursorToCrossHair(); screen->m_BlockLocate.SetCommand( BLOCK_DELETE ); screen->m_BlockLocate.SetMessageBlock( this ); HandleBlockEnd( &dc ); SetSheetNumberAndCount(); break; case ID_POPUP_COPY_BLOCK: m_canvas->MoveCursorToCrossHair(); screen->m_BlockLocate.SetCommand( BLOCK_COPY ); screen->m_BlockLocate.SetMessageBlock( this ); HandleBlockEnd( &dc ); break; case ID_POPUP_DRAG_BLOCK: m_canvas->MoveCursorToCrossHair(); screen->m_BlockLocate.SetCommand( BLOCK_DRAG ); screen->m_BlockLocate.SetMessageBlock( this ); HandleBlockEnd( &dc ); break; case ID_POPUP_SCH_ADD_JUNCTION: m_canvas->MoveCursorToCrossHair(); screen->SetCurItem( AddJunction( &dc, GetCrossHairPosition(), true ) ); screen->TestDanglingEnds( m_canvas, &dc ); screen->SetCurItem( NULL ); break; case ID_POPUP_SCH_ADD_LABEL: case ID_POPUP_SCH_ADD_GLABEL: screen->SetCurItem( CreateNewText( &dc, id == ID_POPUP_SCH_ADD_LABEL ? LAYER_LOCLABEL : LAYER_GLOBLABEL ) ); item = screen->GetCurItem(); if( item ) addCurrentItemToList( &dc ); break; case ID_POPUP_SCH_GETINFO_MARKER: if( item && item->Type() == SCH_MARKER_T ) ( (SCH_MARKER*) item )->DisplayMarkerInfo( this ); break; default: // Log error: wxFAIL_MSG( wxString::Format( wxT( "Cannot process command event ID %d" ), event.GetId() ) ); break; } // End switch ( id ) (Command execution) if( GetToolId() == ID_NO_TOOL_SELECTED ) SetRepeatItem( NULL ); }
void SCH_EDIT_FRAME::addCurrentItemToList( wxDC* aDC ) { SCH_SCREEN* screen = GetScreen(); SCH_ITEM* item = screen->GetCurItem(); wxCHECK_RET( item != NULL, wxT( "Cannot add current item to list." ) ); m_canvas->SetAutoPanRequest( false ); SCH_ITEM* undoItem = item; if( item->Type() == SCH_SHEET_PIN_T ) { SCH_SHEET* sheet = (SCH_SHEET*) item->GetParent(); wxCHECK_RET( (sheet != NULL) && (sheet->Type() == SCH_SHEET_T), wxT( "Cannot place sheet pin in invalid schematic sheet object." ) ); undoItem = sheet; } else if( item->Type() == SCH_FIELD_T ) { SCH_COMPONENT* cmp = (SCH_COMPONENT*) item->GetParent(); wxCHECK_RET( (cmp != NULL) && (cmp->Type() == SCH_COMPONENT_T), wxT( "Cannot place field in invalid schematic component object." ) ); undoItem = cmp; } if( item->IsNew() ) { if( item->Type() == SCH_SHEET_T ) { // Fix the size and position of the new sheet using the last values set by // the m_mouseCaptureCallback function. m_canvas->SetMouseCapture( NULL, NULL ); if( !EditSheet( (SCH_SHEET*)item, aDC ) ) { screen->SetCurItem( NULL ); item->Draw( m_canvas, aDC, wxPoint( 0, 0 ), g_XorMode ); delete item; return; } SetSheetNumberAndCount(); } if( undoItem == item ) { if( !screen->CheckIfOnDrawList( item ) ) // don't want a loop! screen->Append( item ); SetRepeatItem( item ); SaveCopyInUndoList( undoItem, UR_NEW ); } else { // Here, item is not a basic schematic item, but an item inside // a parent basic schematic item, // currently: sheet pin or component field. // currently, only a sheet pin can be found as new item, // because new component fields have a specific handling, and do not appears here SaveCopyInUndoList( undoItem, UR_CHANGED ); if( item->Type() == SCH_SHEET_PIN_T ) ( (SCH_SHEET*)undoItem )->AddPin( (SCH_SHEET_PIN*) item ); else wxLogMessage(wxT( "addCurrentItemToList: expected type = SCH_SHEET_PIN_T, actual type = %d" ), item->Type() ); } } else { SaveUndoItemInUndoList( undoItem ); } // Erase the wire representation before the 'normal' view is drawn. if ( item->IsWireImage() ) item->Draw( m_canvas, aDC, wxPoint( 0, 0 ), g_XorMode ); item->ClearFlags(); screen->SetModify(); screen->SetCurItem( NULL ); m_canvas->SetMouseCapture( NULL, NULL ); m_canvas->EndMouseCapture(); if( item->IsConnectable() ) screen->TestDanglingEnds(); if( aDC ) { EDA_CROSS_HAIR_MANAGER( m_canvas, aDC ); // Erase schematic cursor undoItem->Draw( m_canvas, aDC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE ); } }
void SCH_EDIT_FRAME::OnMoveItem( wxCommandEvent& aEvent ) { SCH_SCREEN* screen = GetScreen(); SCH_ITEM* item = screen->GetCurItem(); if( screen->m_BlockLocate.GetState() != STATE_NO_BLOCK ) { // trying to move an item when there is a block at the same time is not acceptable return; } if( item == NULL ) { // If we didn't get here by a hot key, then something has gone wrong. if( aEvent.GetInt() == 0 ) return; EDA_HOTKEY_CLIENT_DATA* data = (EDA_HOTKEY_CLIENT_DATA*) aEvent.GetClientObject(); wxCHECK_RET( data != NULL, wxT( "Invalid hot key client object." ) ); item = LocateAndShowItem( data->GetPosition(), SCH_COLLECTOR::MovableItems, aEvent.GetInt() ); // Exit if no item found at the current location or the item is already being edited. if( (item == NULL) || (item->GetFlags() != 0) ) return; } INSTALL_UNBUFFERED_DC( dc, m_canvas ); switch( item->Type() ) { case SCH_LINE_T: break; case SCH_JUNCTION_T: case SCH_NO_CONNECT_T: case SCH_BUS_BUS_ENTRY_T: case SCH_BUS_WIRE_ENTRY_T: case SCH_LABEL_T: case SCH_GLOBAL_LABEL_T: case SCH_HIERARCHICAL_LABEL_T: case SCH_TEXT_T: case SCH_COMPONENT_T: case SCH_SHEET_PIN_T: case SCH_FIELD_T: case SCH_SHEET_T: PrepareMoveItem( item, &dc ); break; case SCH_BITMAP_T: // move an image is a special case: // we cannot undraw/redraw a bitmap just using our xor mode // the MoveImage function handle this undraw/redraw difficulty // By redrawing the full bounding box MoveImage( (SCH_BITMAP*) item, &dc ); break; case SCH_MARKER_T: // Moving a marker has no sense break; default: // Unknown items cannot be moved wxFAIL_MSG( wxString::Format( wxT( "Cannot move item type %d" ), item->Type() ) ); break; } if( GetToolId() == ID_NO_TOOL_SELECTED ) SetRepeatItem( NULL ); }
void SCH_EDIT_FRAME::EndSegment( wxDC* DC ) { SCH_SCREEN* screen = GetScreen(); SCH_LINE* segment = (SCH_LINE*) screen->GetCurItem(); if( segment == NULL || segment->Type() != SCH_LINE_T || !segment->IsNew() ) return; // Delete zero length segments and clear item flags. SCH_ITEM* item = s_wires.begin(); while( item ) { item->ClearFlags(); wxCHECK_RET( item->Type() == SCH_LINE_T, wxT( "Unexpected object type in wire list." ) ); segment = (SCH_LINE*) item; item = item->Next(); if( segment->IsNull() ) delete s_wires.Remove( segment ); } if( s_wires.GetCount() == 0 ) return; // Get the last non-null wire (this is the last created segment). SetRepeatItem( segment = (SCH_LINE*) s_wires.GetLast() ); screen->SetCurItem( NULL ); m_canvas->EndMouseCapture( -1, -1, wxEmptyString, false ); // store the terminal point of this last segment: a junction could be needed // (the last wire could be merged/deleted/modified, and lost) wxPoint endpoint = segment->GetEndPoint(); // store the starting point of this first segment: a junction could be needed SCH_LINE* firstsegment = (SCH_LINE*) s_wires.GetFirst(); wxPoint startPoint = firstsegment->GetStartPoint(); // Save the old wires for the undo command DLIST< SCH_ITEM > oldWires; // stores here the old wires GetScreen()->ExtractWires( oldWires, true ); // Save them in oldWires list // Put the snap shot of the previous wire, buses, and junctions in the undo/redo list. PICKED_ITEMS_LIST oldItems; oldItems.m_Status = UR_WIRE_IMAGE; while( oldWires.GetCount() != 0 ) { ITEM_PICKER picker = ITEM_PICKER( oldWires.PopFront(), UR_WIRE_IMAGE ); oldItems.PushItem( picker ); } SaveCopyInUndoList( oldItems, UR_WIRE_IMAGE ); // Remove segments backtracking over others RemoveBacktracks( s_wires ); // Add the new wires screen->Append( s_wires ); // Correct and remove segments that need to be merged. screen->SchematicCleanUp(); // A junction could be needed to connect the end point of the last created segment. if( screen->IsJunctionNeeded( endpoint ) ) screen->Append( AddJunction( DC, endpoint ) ); // A junction could be needed to connect the start point of the set of new created wires if( screen->IsJunctionNeeded( startPoint ) ) screen->Append( AddJunction( DC, startPoint ) ); m_canvas->Refresh(); OnModify(); }
void SCH_EDIT_FRAME::BeginSegment( wxDC* DC, int type ) { SCH_LINE* segment; SCH_LINE* nextSegment; wxPoint cursorpos = GetCrossHairPosition(); // We should know if a segment is currently in progress segment = (SCH_LINE*) GetScreen()->GetCurItem(); if( segment ) // a current item exists, but not necessary a currently edited item { if( !segment->GetFlags() || ( segment->Type() != SCH_LINE_T ) ) { if( segment->GetFlags() ) { wxLogDebug( wxT( "BeginSegment: item->GetFlags()== %X" ), segment->GetFlags() ); } // no wire, bus or graphic line in progress segment = NULL; } } if( !segment ) // first point : Create the first wire or bus segment { switch( type ) { default: segment = new SCH_LINE( cursorpos, LAYER_NOTES ); break; case LAYER_WIRE: segment = new SCH_LINE( cursorpos, LAYER_WIRE ); /* A junction will be created later, when we'll know the * segment end position, and if the junction is really needed */ break; case LAYER_BUS: segment = new SCH_LINE( cursorpos, LAYER_BUS ); break; } segment->SetFlags( IS_NEW ); s_wires.PushBack( segment ); GetScreen()->SetCurItem( segment ); // We need 2 segments to go from a given start pin to an end point when the horizontal // and vertical lines only switch is on. if( GetForceHVLines() ) { nextSegment = new SCH_LINE( *segment ); nextSegment->SetFlags( IS_NEW ); s_wires.PushBack( nextSegment ); GetScreen()->SetCurItem( nextSegment ); } m_canvas->SetMouseCapture( DrawSegment, AbortCreateNewLine ); SetRepeatItem( NULL ); } else // A segment is in progress: terminates the current segment and add a new segment. { SCH_LINE* prevSegment = segment->Back(); // Be aware prevSegment can be null when the horizontal and vertical lines only switch is off // when we create the first segment. if( !GetForceHVLines() ) { // If only one segment is needed and it has a zero length, do not create a new one. if( segment->IsNull() ) return; } else { wxCHECK_RET( prevSegment != NULL, wxT( "Failed to create second line segment." ) ); // If two segments are required and they both have zero length, do not // create a new one. if( prevSegment && prevSegment->IsNull() && segment->IsNull() ) return; } m_canvas->CallMouseCapture( DC, wxDefaultPosition, false ); // Terminate the command if the end point is on a pin, junction, or another wire or bus. if( GetScreen()->IsTerminalPoint( cursorpos, segment->GetLayer() ) ) { EndSegment( DC ); return; } // Create a new segment, and chain it after the current new segment. nextSegment = new SCH_LINE( *segment ); nextSegment->SetStartPoint( cursorpos ); s_wires.PushBack( nextSegment ); segment->SetEndPoint( cursorpos ); segment->ClearFlags( IS_NEW ); segment->SetFlags( SELECTED ); nextSegment->SetFlags( IS_NEW ); GetScreen()->SetCurItem( nextSegment ); m_canvas->CallMouseCapture( DC, wxDefaultPosition, false ); } }
SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( const SCHLIB_FILTER* aFilter, SCH_BASE_FRAME::HISTORY_LIST& aHistoryList, bool aAllowBrowser ) { wxString msg; SetRepeatItem( NULL ); m_canvas->SetIgnoreMouseEvents( true ); auto sel = SelectComponentFromLibTree( aFilter, aHistoryList, aAllowBrowser, 1, 1, m_footprintPreview ); if( !sel.LibId.IsValid() ) { m_canvas->SetIgnoreMouseEvents( false ); m_canvas->MoveCursorToCrossHair(); return NULL; } m_canvas->SetIgnoreMouseEvents( false ); m_canvas->MoveCursorToCrossHair(); wxString libsource; // the library name to use. If empty, load from any lib if( aFilter ) libsource = aFilter->GetLibSource(); LIB_ID libId = sel.LibId; LIB_PART* part = GetLibPart( libId, true ); if( !part ) return NULL; SCH_COMPONENT* component = new SCH_COMPONENT( *part, libId, g_CurrentSheet, sel.Unit, sel.Convert, GetCrossHairPosition(), true ); // Be sure the link to the corresponding LIB_PART is OK: component->Resolve( *Prj().SchSymbolLibTable() ); // Set any fields that have been modified for( auto const& i : sel.Fields ) { auto field = component->GetField( i.first ); if( field ) field->SetText( i.second ); } MSG_PANEL_ITEMS items; component->GetMsgPanelInfo( m_UserUnits, items ); SetMsgPanel( items ); component->SetFlags( IS_NEW ); if( m_autoplaceFields ) component->AutoplaceFields( /* aScreen */ NULL, /* aManual */ false ); PrepareMoveItem( component ); return component; }
SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( wxDC* aDC, const SCHLIB_FILTER* aFilter, SCH_BASE_FRAME::HISTORY_LIST& aHistoryList, bool aUseLibBrowser ) { wxString msg; SetRepeatItem( NULL ); m_canvas->SetIgnoreMouseEvents( true ); auto sel = SelectComponentFromLibrary( aFilter, aHistoryList, aUseLibBrowser, 1, 1, m_footprintPreview ); if( !sel.LibId.IsValid() ) { m_canvas->SetIgnoreMouseEvents( false ); m_canvas->MoveCursorToCrossHair(); return NULL; } m_canvas->SetIgnoreMouseEvents( false ); m_canvas->MoveCursorToCrossHair(); wxString libsource; // the library name to use. If empty, load from any lib if( aFilter ) libsource = aFilter->GetLibSource(); LIB_ID libId = sel.LibId; LIB_PART* part = GetLibPart( libId, true ); if( !part ) return NULL; SCH_COMPONENT* component = new SCH_COMPONENT( *part, m_CurrentSheet, sel.Unit, sel.Convert, GetCrossHairPosition(), true ); // Set the m_ChipName value, from component name in lib, for aliases // Note if part is found, and if name is an alias of a component, // alias exists because its root component was found component->SetLibId( libId ); // Be sure the link to the corresponding LIB_PART is OK: component->Resolve( *Prj().SchSymbolLibTable() ); // Set any fields that have been modified for( auto const& i : sel.Fields ) { auto field = component->GetField( i.first ); if( field ) field->SetText( i.second ); } // Set the component value that can differ from component name in lib, for aliases component->GetField( VALUE )->SetText( sel.LibId.GetLibItemName() ); // If there is no field defined in the component, copy one over from the library // ( from the .dcm file ) // This way the Datasheet field will not be empty and can be changed from the schematic if( component->GetField( DATASHEET )->GetText().IsEmpty() ) { LIB_ALIAS* entry = GetLibAlias( component->GetLibId(), true, true ); if( entry && !!entry->GetDocFileName() ) component->GetField( DATASHEET )->SetText( entry->GetDocFileName() ); } MSG_PANEL_ITEMS items; component->SetCurrentSheetPath( &GetCurrentSheet() ); component->GetMsgPanelInfo( items ); SetMsgPanel( items ); component->Draw( m_canvas, aDC, wxPoint( 0, 0 ), g_XorMode ); component->SetFlags( IS_NEW ); if( m_autoplaceFields ) component->AutoplaceFields( /* aScreen */ NULL, /* aManual */ false ); PrepareMoveItem( (SCH_ITEM*) component, aDC ); return component; }
/* * OnConvertTextType is a command event handler to change a text type to an other one. * The new text, label, hierarchical label, or global label is created from the old text * The old text is deleted. * A tricky case is when the 'old" text is being edited (i.e. moving) * because we must create a new text, and prepare the undo/redo command data for this * change and the current move/edit command */ void SCH_EDIT_FRAME::OnConvertTextType( wxCommandEvent& aEvent ) { SCH_SCREEN* screen = GetScreen(); SCH_TEXT* text = (SCH_TEXT*) screen->GetCurItem(); wxCHECK_RET( (text != NULL) && text->CanIncrementLabel(), wxT( "Cannot convert text type." ) ); KICAD_T type; switch( aEvent.GetId() ) { case ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_LABEL: type = SCH_LABEL_T; break; case ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_GLABEL: type = SCH_GLOBAL_LABEL_T; break; case ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_HLABEL: type = SCH_HIERARCHICAL_LABEL_T; break; case ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_COMMENT: type = SCH_TEXT_T; break; default: wxFAIL_MSG( wxString::Format( wxT( "Invalid text type command ID %d." ), aEvent.GetId() ) ); return; } if( text->Type() == type ) return; SCH_TEXT* newtext; const wxPoint &position = text->GetPosition(); const wxString &txt = text->GetText(); switch( type ) { case SCH_LABEL_T: newtext = new SCH_LABEL( position, txt ); break; case SCH_GLOBAL_LABEL_T: newtext = new SCH_GLOBALLABEL( position, txt ); break; case SCH_HIERARCHICAL_LABEL_T: newtext = new SCH_HIERLABEL( position, txt ); break; case SCH_TEXT_T: newtext = new SCH_TEXT( position, txt ); break; default: newtext = NULL; wxFAIL_MSG( wxString::Format( wxT( "Cannot convert text type to %d" ), type ) ); return; } /* Copy the old text item settings to the new one. Justifications are not copied because * they are not used in labels. Justifications will be set to default value in the new * text item type. */ newtext->SetFlags( text->GetFlags() ); newtext->SetShape( text->GetShape() ); newtext->SetOrientation( text->GetOrientation() ); newtext->SetSize( text->GetSize() ); newtext->SetThickness( text->GetThickness() ); newtext->SetItalic( text->IsItalic() ); newtext->SetBold( text->IsBold() ); /* Save the new text in undo list if the old text was not itself a "new created text" * In this case, the old text is already in undo list as a deleted item. * Of course if the old text was a "new created text" the new text will be * put in undo list later, at the end of the current command (if not aborted) */ INSTALL_UNBUFFERED_DC( dc, m_canvas ); m_canvas->CrossHairOff( &dc ); // Erase schematic cursor text->Draw( m_canvas, &dc, wxPoint( 0, 0 ), g_XorMode ); // For an exiting item (i.e. already in list): // replace the existing item by the new text in list for( SCH_ITEM* item = screen->GetDrawItems(); item != NULL; item = item->Next() ) { if( item == text ) { screen->Remove( text ); screen->Append( newtext ); break; } } SetRepeatItem( NULL ); OnModify(); newtext->Draw( m_canvas, &dc, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE ); m_canvas->CrossHairOn( &dc ); // redraw schematic cursor // if the old item is the current schematic item, replace it by the new text: if( screen->GetCurItem() == text ) screen->SetCurItem( newtext ); if( text->IsNew() ) { // if the previous text is new, no undo command to prepare here // just delete this previous text. delete text; return; } // previous text is not new and we replace text by new text. // So this is equivalent to delete text and add newtext // If text if being currently edited (i.e. moved) // we also save the initial copy of text, and prepare undo command for new text modifications. // we must save it as modified text,if it is currently edited, then save as deleted text, // and replace text with newtext PICKED_ITEMS_LIST pickList; ITEM_PICKER picker( text, UR_CHANGED ); if( text->GetFlags() ) { // text is being edited, save initial text for undo command picker.SetLink( GetUndoItem() ); pickList.PushItem( picker ); // the owner of undoItem is no more "this", it is now "picker": SetUndoItem( NULL ); // save current newtext copy for undo/abort current command SetUndoItem( newtext ); } // Prepare undo command for delete old text picker.SetStatus( UR_DELETED ); picker.SetLink( NULL ); pickList.PushItem( picker ); // Prepare undo command for new text picker.SetStatus( UR_NEW ); picker.SetItem(newtext); pickList.PushItem( picker ); SaveCopyInUndoList( pickList, UR_UNSPECIFIED ); }
SCH_TEXT* SCH_EDIT_FRAME::CreateNewText( wxDC* aDC, int aType ) { SCH_TEXT* textItem = NULL; SetRepeatItem( NULL ); switch( aType ) { case LAYER_NOTES: textItem = new SCH_TEXT( GetCrossHairPosition() ); break; case LAYER_LOCLABEL: textItem = new SCH_LABEL( GetCrossHairPosition() ); break; case LAYER_HIERLABEL: textItem = new SCH_HIERLABEL( GetCrossHairPosition() ); textItem->SetShape( lastGlobalLabelShape ); break; case LAYER_GLOBLABEL: textItem = new SCH_GLOBALLABEL( GetCrossHairPosition() ); textItem->SetShape( lastGlobalLabelShape ); break; default: DisplayError( this, wxT( "SCH_EDIT_FRAME::CreateNewText() Internal error" ) ); return NULL; } textItem->SetBold( lastTextBold ); textItem->SetItalic( lastTextItalic ); textItem->SetOrientation( lastTextOrientation ); textItem->SetSize( wxSize( GetDefaultTextSize(), GetDefaultTextSize() ) ); textItem->SetFlags( IS_NEW | IS_MOVED ); EditSchematicText( textItem ); if( textItem->GetText().IsEmpty() ) { delete textItem; return NULL; } lastTextBold = textItem->IsBold(); lastTextItalic = textItem->IsItalic(); lastTextOrientation = textItem->GetOrientation(); if( ( textItem->Type() == SCH_GLOBAL_LABEL_T ) || ( textItem->Type() == SCH_HIERARCHICAL_LABEL_T ) ) { lastGlobalLabelShape = textItem->GetShape(); } // Prepare display to move the new item textItem->Draw( m_canvas, aDC, wxPoint( 0, 0 ), g_XorMode ); PrepareMoveItem( (SCH_ITEM*) textItem, aDC ); return textItem; }
void SCH_EDIT_FRAME::OnSelectTool( wxCommandEvent& aEvent ) { int id = aEvent.GetId(); // Stop the current command and deselect the current tool. m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() ); switch( id ) { case ID_NO_TOOL_SELECTED: SetToolID( id, m_canvas->GetDefaultCursor(), _( "No tool selected" ) ); break; case ID_HIERARCHY_PUSH_POP_BUTT: SetToolID( id, wxCURSOR_HAND, _( "Descend or ascend hierarchy" ) ); break; case ID_NOCONN_BUTT: SetToolID( id, wxCURSOR_PENCIL, _( "Add no connect" ) ); break; case ID_WIRE_BUTT: SetToolID( id, wxCURSOR_PENCIL, _( "Add wire" ) ); break; case ID_BUS_BUTT: SetToolID( id, wxCURSOR_PENCIL, _( "Add bus" ) ); break; case ID_LINE_COMMENT_BUTT: SetToolID( id, wxCURSOR_PENCIL, _( "Add lines" ) ); break; case ID_JUNCTION_BUTT: SetToolID( id, wxCURSOR_PENCIL, _( "Add junction" ) ); break; case ID_LABEL_BUTT: SetToolID( id, wxCURSOR_PENCIL, _( "Add label" ) ); break; case ID_GLABEL_BUTT: SetToolID( id, wxCURSOR_PENCIL, _( "Add global label" ) ); break; case ID_HIERLABEL_BUTT: SetToolID( id, wxCURSOR_PENCIL, _( "Add hierarchical label" ) ); break; case ID_TEXT_COMMENT_BUTT: SetToolID( id, wxCURSOR_PENCIL, _( "Add text" ) ); break; case ID_ADD_IMAGE_BUTT: SetToolID( id, wxCURSOR_PENCIL, _( "Add image" ) ); break; case ID_WIRETOBUS_ENTRY_BUTT: SetToolID( id, wxCURSOR_PENCIL, _( "Add wire to bus entry" ) ); break; case ID_BUSTOBUS_ENTRY_BUTT: SetToolID( id, wxCURSOR_PENCIL, _( "Add bus to bus entry" ) ); break; case ID_SHEET_SYMBOL_BUTT: SetToolID( id, wxCURSOR_PENCIL, _( "Add sheet" ) ); break; case ID_SHEET_PIN_BUTT: SetToolID( id, wxCURSOR_PENCIL, _( "Add sheet pins" ) ); break; case ID_IMPORT_HLABEL_BUTT: SetToolID( id, wxCURSOR_PENCIL, _( "Import sheet pins" ) ); break; case ID_SCH_PLACE_COMPONENT: SetToolID( id, wxCURSOR_PENCIL, _( "Add component" ) ); break; case ID_PLACE_POWER_BUTT: SetToolID( id, wxCURSOR_PENCIL, _( "Add power" ) ); break; case ID_SCHEMATIC_DELETE_ITEM_BUTT: SetToolID( id, wxCURSOR_BULLSEYE, _( "Delete item" ) ); break; default: SetRepeatItem( NULL ); } // Simulate left click event if we got here from a hot key. if( aEvent.GetClientObject() != NULL ) { EDA_HOTKEY_CLIENT_DATA* data = (EDA_HOTKEY_CLIENT_DATA*) aEvent.GetClientObject(); wxPoint pos = data->GetPosition(); INSTALL_UNBUFFERED_DC( dc, m_canvas ); OnLeftClick( &dc, pos ); } }
void SCH_EDIT_FRAME::OnMoveItem( wxCommandEvent& aEvent ) { SCH_SCREEN* screen = GetScreen(); SCH_ITEM* item = screen->GetCurItem(); if( screen->m_BlockLocate.GetState() != STATE_NO_BLOCK ) { // trying to move an item when there is a block at the same time is not acceptable return; } if( item == NULL ) { // If we didn't get here by a hot key, then something has gone wrong. if( aEvent.GetInt() == 0 ) return; EDA_HOTKEY_CLIENT_DATA* data = (EDA_HOTKEY_CLIENT_DATA*) aEvent.GetClientObject(); wxCHECK_RET( data != NULL, wxT( "Invalid hot key client object." ) ); item = LocateAndShowItem( data->GetPosition(), SCH_COLLECTOR::MovableItems, aEvent.GetInt() ); // Exit if no item found at the current location or the item is already being edited. if( (item == NULL) || (item->GetFlags() != 0) ) return; } INSTALL_UNBUFFERED_DC( dc, m_canvas ); switch( item->Type() ) { case SCH_LINE_T: break; case SCH_JUNCTION_T: case SCH_NO_CONNECT_T: case SCH_BUS_BUS_ENTRY_T: case SCH_BUS_WIRE_ENTRY_T: case SCH_LABEL_T: case SCH_GLOBAL_LABEL_T: case SCH_HIERARCHICAL_LABEL_T: case SCH_TEXT_T: case SCH_COMPONENT_T: case SCH_SHEET_PIN_T: case SCH_FIELD_T: MoveItem( item, &dc ); break; case SCH_BITMAP_T: MoveImage( (SCH_BITMAP*) item, &dc ); break; case SCH_SHEET_T: StartMoveSheet( (SCH_SHEET*) item, &dc ); break; case SCH_MARKER_T: default: wxFAIL_MSG( wxString::Format( wxT( "Cannot move item type %s" ), GetChars( item->GetClass() ) ) ); break; } if( GetToolId() == ID_NO_TOOL_SELECTED ) SetRepeatItem( NULL ); }
void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) { SCH_ITEM* item = GetScreen()->GetCurItem(); wxPoint gridPosition = GetGridPosition( aPosition ); if( ( GetToolId() == ID_NO_TOOL_SELECTED ) || ( item && item->GetFlags() ) ) { m_canvas->SetAutoPanRequest( false ); SetRepeatItem( NULL ); if( item && item->GetFlags() ) { switch( item->Type() ) { case SCH_LABEL_T: case SCH_GLOBAL_LABEL_T: case SCH_HIERARCHICAL_LABEL_T: case SCH_TEXT_T: case SCH_SHEET_PIN_T: case SCH_SHEET_T: case SCH_BUS_WIRE_ENTRY_T: case SCH_BUS_BUS_ENTRY_T: case SCH_JUNCTION_T: case SCH_COMPONENT_T: case SCH_FIELD_T: case SCH_BITMAP_T: case SCH_NO_CONNECT_T: addCurrentItemToList( aDC ); return; case SCH_LINE_T: // May already be drawing segment. break; default: wxFAIL_MSG( wxT( "SCH_EDIT_FRAME::OnLeftClick error. Item type <" ) + item->GetClass() + wxT( "> is already being edited." ) ); item->ClearFlags(); break; } } else { item = LocateAndShowItem( aPosition ); } } switch( GetToolId() ) { case ID_NO_TOOL_SELECTED: break; case ID_HIERARCHY_PUSH_POP_BUTT: if( ( item && item->GetFlags() ) || ( g_RootSheet->CountSheets() == 0 ) ) break; item = LocateAndShowItem( aPosition, SCH_COLLECTOR::SheetsOnly ); if( item ) // The user has clicked on a sheet: this is an enter sheet command { m_CurrentSheet->Push( (SCH_SHEET*) item ); DisplayCurrentSheet(); } else if( m_CurrentSheet->Last() != g_RootSheet ) { // The user has clicked ouside a sheet:this is an leave sheet command m_CurrentSheet->Pop(); DisplayCurrentSheet(); } break; case ID_NOCONN_BUTT: if( ( item == NULL ) || ( item->GetFlags() == 0 ) ) { if( false == GetScreen()->GetItem( gridPosition, 0, SCH_NO_CONNECT_T ) ) { SCH_NO_CONNECT* no_connect = AddNoConnect( aDC, gridPosition ); SetRepeatItem( no_connect ); GetScreen()->SetCurItem( no_connect ); m_canvas->SetAutoPanRequest( true ); } } else { addCurrentItemToList( aDC ); } break; case ID_JUNCTION_BUTT: if( ( item == NULL ) || ( item->GetFlags() == 0 ) ) { if( false == GetScreen()->GetItem( gridPosition, 0, SCH_JUNCTION_T ) ) { SCH_JUNCTION* junction = AddJunction( aDC, gridPosition, true ); SetRepeatItem( junction ); GetScreen()->SetCurItem( junction ); m_canvas->SetAutoPanRequest( true ); } } else { addCurrentItemToList( aDC ); } break; case ID_WIRETOBUS_ENTRY_BUTT: if( ( item == NULL ) || ( item->GetFlags() == 0 ) ) { CreateBusWireEntry( aDC ); m_canvas->SetAutoPanRequest( true ); } else { addCurrentItemToList( aDC ); } break; case ID_BUSTOBUS_ENTRY_BUTT: if( ( item == NULL ) || ( item->GetFlags() == 0 ) ) { CreateBusBusEntry( aDC ); m_canvas->SetAutoPanRequest( true ); } else { addCurrentItemToList( aDC ); } break; case ID_SCHEMATIC_DELETE_ITEM_BUTT: DeleteItemAtCrossHair( aDC ); break; case ID_WIRE_BUTT: BeginSegment( aDC, LAYER_WIRE ); m_canvas->SetAutoPanRequest( true ); break; case ID_BUS_BUTT: BeginSegment( aDC, LAYER_BUS ); m_canvas->SetAutoPanRequest( true ); break; case ID_LINE_COMMENT_BUTT: BeginSegment( aDC, LAYER_NOTES ); m_canvas->SetAutoPanRequest( true ); break; case ID_TEXT_COMMENT_BUTT: if( ( item == NULL ) || ( item->GetFlags() == 0 ) ) { GetScreen()->SetCurItem( CreateNewText( aDC, LAYER_NOTES ) ); m_canvas->SetAutoPanRequest( true ); } else { addCurrentItemToList( aDC ); } break; case ID_ADD_IMAGE_BUTT: if( ( item == NULL ) || ( item->GetFlags() == 0 ) ) { GetScreen()->SetCurItem( CreateNewImage( aDC ) ); m_canvas->SetAutoPanRequest( true ); } else { addCurrentItemToList( aDC ); } break; case ID_LABEL_BUTT: if( ( item == NULL ) || ( item->GetFlags() == 0 ) ) { GetScreen()->SetCurItem( CreateNewText( aDC, LAYER_LOCLABEL ) ); m_canvas->SetAutoPanRequest( true ); } else { addCurrentItemToList( aDC ); } break; case ID_GLABEL_BUTT: case ID_HIERLABEL_BUTT: if( (item == NULL) || (item->GetFlags() == 0) ) { if( GetToolId() == ID_GLABEL_BUTT ) GetScreen()->SetCurItem( CreateNewText( aDC, LAYER_GLOBLABEL ) ); if( GetToolId() == ID_HIERLABEL_BUTT ) GetScreen()->SetCurItem( CreateNewText( aDC, LAYER_HIERLABEL ) ); m_canvas->SetAutoPanRequest( true ); } else { addCurrentItemToList( aDC ); } break; case ID_SHEET_SYMBOL_BUTT: if( ( item == NULL ) || ( item->GetFlags() == 0 ) ) { item = CreateSheet( aDC ); if( item != NULL ) { GetScreen()->SetCurItem( item ); m_canvas->SetAutoPanRequest( true ); } } else { addCurrentItemToList( aDC ); } break; case ID_IMPORT_HLABEL_BUTT: case ID_SHEET_PIN_BUTT: if( ( item == NULL ) || ( item->GetFlags() == 0 ) ) item = LocateAndShowItem( aPosition, SCH_COLLECTOR::SheetsAndSheetLabels ); if( item == NULL ) break; if( (item->Type() == SCH_SHEET_T) && (item->GetFlags() == 0) ) { if( GetToolId() == ID_IMPORT_HLABEL_BUTT ) GetScreen()->SetCurItem( ImportSheetPin( (SCH_SHEET*) item, aDC ) ); else GetScreen()->SetCurItem( CreateSheetPin( (SCH_SHEET*) item, aDC ) ); } else if( (item->Type() == SCH_SHEET_PIN_T) && (item->GetFlags() != 0) ) { addCurrentItemToList( aDC ); } break; case ID_SCH_PLACE_COMPONENT: if( (item == NULL) || (item->GetFlags() == 0) ) { GetScreen()->SetCurItem( Load_Component( aDC, wxEmptyString, s_CmpNameList, s_CmpLastUnit, true ) ); m_canvas->SetAutoPanRequest( true ); } else { addCurrentItemToList( aDC ); } break; case ID_PLACE_POWER_BUTT: if( ( item == NULL ) || ( item->GetFlags() == 0 ) ) { GetScreen()->SetCurItem( Load_Component( aDC, wxT( "power" ), s_PowerNameList, s_LastPowerUnit, false ) ); m_canvas->SetAutoPanRequest( true ); } else { addCurrentItemToList( aDC ); } break; default: SetToolID( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(), wxEmptyString ); wxFAIL_MSG( wxT( "SCH_EDIT_FRAME::OnLeftClick invalid tool ID <" ) + wxString::Format( wxT( "%d> selected." ), GetToolId() ) ); } }
void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) { SCH_ITEM* item = GetScreen()->GetCurItem(); wxPoint gridPosition = GetGridPosition( aPosition ); if( ( GetToolId() == ID_NO_TOOL_SELECTED ) || ( item && item->GetFlags() ) ) { m_canvas->SetAutoPanRequest( false ); SetRepeatItem( NULL ); if( item && item->GetFlags() ) { switch( item->Type() ) { case SCH_LABEL_T: case SCH_GLOBAL_LABEL_T: case SCH_HIERARCHICAL_LABEL_T: case SCH_TEXT_T: case SCH_SHEET_PIN_T: case SCH_SHEET_T: case SCH_BUS_WIRE_ENTRY_T: case SCH_BUS_BUS_ENTRY_T: case SCH_JUNCTION_T: case SCH_COMPONENT_T: case SCH_FIELD_T: case SCH_BITMAP_T: case SCH_NO_CONNECT_T: addCurrentItemToList(); return; case SCH_LINE_T: // May already be drawing segment. break; default: wxFAIL_MSG( wxT( "SCH_EDIT_FRAME::OnLeftClick error. Item type <" ) + item->GetClass() + wxT( "> is already being edited." ) ); item->ClearFlags(); break; } } else { item = LocateAndShowItem( aPosition ); } } switch( GetToolId() ) { case ID_NO_TOOL_SELECTED: break; case ID_HIGHLIGHT: HighlightConnectionAtPosition( aPosition ); break; case ID_HIERARCHY_PUSH_POP_BUTT: if( ( item && item->GetFlags() ) || ( g_RootSheet->CountSheets() == 0 ) ) break; item = LocateAndShowItem( aPosition, SCH_COLLECTOR::SheetsOnly ); if( item ) // The user has clicked on a sheet: this is an enter sheet command { m_CurrentSheet->push_back( (SCH_SHEET*) item ); DisplayCurrentSheet(); } else if( m_CurrentSheet->Last() != g_RootSheet ) { // The user has clicked ouside a sheet:this is an leave sheet command m_CurrentSheet->pop_back(); DisplayCurrentSheet(); } break; case ID_NOCONN_BUTT: if( ( item == NULL ) || ( item->GetFlags() == 0 ) ) { if( GetScreen()->GetItem( gridPosition, 0, SCH_NO_CONNECT_T ) == NULL ) { SCH_NO_CONNECT* no_connect = AddNoConnect( aDC, gridPosition ); SetRepeatItem( no_connect ); GetScreen()->SetCurItem( no_connect ); m_canvas->SetAutoPanRequest( true ); } } else { addCurrentItemToList(); } break; case ID_JUNCTION_BUTT: if( ( item == NULL ) || ( item->GetFlags() == 0 ) ) { if( GetScreen()->GetItem( gridPosition, 0, SCH_JUNCTION_T ) == NULL ) { SCH_JUNCTION* junction = AddJunction( aDC, gridPosition, true ); SetRepeatItem( junction ); GetScreen()->SetCurItem( junction ); m_canvas->SetAutoPanRequest( true ); } } else { addCurrentItemToList(); } break; case ID_WIRETOBUS_ENTRY_BUTT: if( ( item == NULL ) || ( item->GetFlags() == 0 ) ) { CreateBusWireEntry(); m_canvas->SetAutoPanRequest( true ); } else { addCurrentItemToList(); } break; case ID_BUSTOBUS_ENTRY_BUTT: if( ( item == NULL ) || ( item->GetFlags() == 0 ) ) { CreateBusBusEntry(); m_canvas->SetAutoPanRequest( true ); } else { addCurrentItemToList(); } break; case ID_SCHEMATIC_DELETE_ITEM_BUTT: DeleteItemAtCrossHair( aDC ); break; case ID_WIRE_BUTT: BeginSegment( aDC, LAYER_WIRE ); m_canvas->SetAutoPanRequest( true ); break; case ID_BUS_BUTT: BeginSegment( aDC, LAYER_BUS ); m_canvas->SetAutoPanRequest( true ); break; case ID_LINE_COMMENT_BUTT: BeginSegment( aDC, LAYER_NOTES ); m_canvas->SetAutoPanRequest( true ); break; case ID_TEXT_COMMENT_BUTT: if( ( item == NULL ) || ( item->GetFlags() == 0 ) ) { GetScreen()->SetCurItem( CreateNewText( aDC, LAYER_NOTES ) ); m_canvas->SetAutoPanRequest( true ); } else { addCurrentItemToList(); } break; case ID_ADD_IMAGE_BUTT: if( ( item == NULL ) || ( item->GetFlags() == 0 ) ) { GetScreen()->SetCurItem( CreateNewImage( aDC ) ); m_canvas->SetAutoPanRequest( true ); } else { addCurrentItemToList(); } break; case ID_LABEL_BUTT: if( ( item == NULL ) || ( item->GetFlags() == 0 ) ) { GetScreen()->SetCurItem( CreateNewText( aDC, LAYER_LOCLABEL ) ); m_canvas->SetAutoPanRequest( true ); } else { addCurrentItemToList(); } break; case ID_GLABEL_BUTT: case ID_HIERLABEL_BUTT: if( (item == NULL) || (item->GetFlags() == 0) ) { if( GetToolId() == ID_GLABEL_BUTT ) GetScreen()->SetCurItem( CreateNewText( aDC, LAYER_GLOBLABEL ) ); if( GetToolId() == ID_HIERLABEL_BUTT ) GetScreen()->SetCurItem( CreateNewText( aDC, LAYER_HIERLABEL ) ); m_canvas->SetAutoPanRequest( true ); } else { addCurrentItemToList(); } break; case ID_SHEET_SYMBOL_BUTT: if( ( item == NULL ) || ( item->GetFlags() == 0 ) ) { item = CreateSheet( aDC ); if( item != NULL ) { GetScreen()->SetCurItem( item ); m_canvas->SetAutoPanRequest( true ); } } else { addCurrentItemToList(); } break; case ID_IMPORT_HLABEL_BUTT: case ID_SHEET_PIN_BUTT: if( ( item == NULL ) || ( item->GetFlags() == 0 ) ) item = LocateAndShowItem( aPosition, SCH_COLLECTOR::SheetsAndSheetLabels ); if( item == NULL ) break; if( (item->Type() == SCH_SHEET_T) && (item->GetFlags() == 0) ) { if( GetToolId() == ID_IMPORT_HLABEL_BUTT ) GetScreen()->SetCurItem( ImportSheetPin( (SCH_SHEET*) item, aDC ) ); else GetScreen()->SetCurItem( CreateSheetPin( (SCH_SHEET*) item, aDC ) ); } else if( (item->Type() == SCH_SHEET_PIN_T) && (item->GetFlags() != 0) ) { addCurrentItemToList(); } break; case ID_SCH_PLACE_COMPONENT: if( (item == NULL) || (item->GetFlags() == 0) ) { GetScreen()->SetCurItem( Load_Component( aDC, NULL, s_CmpNameList, s_CmpLastUnit, true ) ); m_canvas->SetAutoPanRequest( true ); } else { addCurrentItemToList(); } break; case ID_PLACE_POWER_BUTT: if( ( item == NULL ) || ( item->GetFlags() == 0 ) ) { SCHLIB_FILTER filter; filter.FilterPowerParts( true ); GetScreen()->SetCurItem( Load_Component( aDC, &filter, s_PowerNameList, s_LastPowerUnit, false ) ); m_canvas->SetAutoPanRequest( true ); } else { addCurrentItemToList(); } break; #ifdef KICAD_SPICE case ID_SIM_PROBE: { const KICAD_T wiresAndComponents[] = { SCH_LINE_T, SCH_COMPONENT_T, SCH_SHEET_PIN_T }; item = LocateAndShowItem( aPosition, wiresAndComponents ); if( !item ) break; NETLIST_OBJECT_LIST* netlist = BuildNetListBase(); for( NETLIST_OBJECT* obj : *netlist ) { if( obj->m_Comp == item ) { SIM_PLOT_FRAME* simFrame = (SIM_PLOT_FRAME*) Kiway().Player( FRAME_SIMULATOR, false ); if( simFrame ) simFrame->AddVoltagePlot( obj->GetNetName() ); break; } } } break; case ID_SIM_TUNE: { const KICAD_T fieldsAndComponents[] = { SCH_COMPONENT_T, SCH_FIELD_T }; item = LocateAndShowItem( aPosition, fieldsAndComponents ); if( !item ) return; if( item->Type() != SCH_COMPONENT_T ) { item = static_cast<SCH_ITEM*>( item->GetParent() ); if( item->Type() != SCH_COMPONENT_T ) return; } SIM_PLOT_FRAME* simFrame = (SIM_PLOT_FRAME*) Kiway().Player( FRAME_SIMULATOR, false ); if( simFrame ) simFrame->AddTuner( static_cast<SCH_COMPONENT*>( item ) ); } break; #endif /* KICAD_SPICE */ default: SetToolID( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(), wxEmptyString ); wxFAIL_MSG( wxT( "SCH_EDIT_FRAME::OnLeftClick invalid tool ID <" ) + wxString::Format( wxT( "%d> selected." ), GetToolId() ) ); } }