/* * Draw (on m_panelShowPin) the pin currently edited * accroding to current settings in dialog */ void DIALOG_LIB_EDIT_PIN::OnPaintShowPanel( wxPaintEvent& event ) { wxPaintDC dc( m_panelShowPin ); wxSize dc_size = dc.GetSize(); dc.SetDeviceOrigin( dc_size.x / 2, dc_size.y / 2 ); // Give a parent to m_dummyPin only from draw purpose. // In fact m_dummyPin should not have a parent, but draw functions need a parent // to know some options, about pin texts LIB_EDIT_FRAME* libframe = (LIB_EDIT_FRAME*) GetParent(); m_dummyPin->SetParent( libframe->GetComponent() ); // Calculate a suitable scale to fit the available draw area EDA_RECT bBox = m_dummyPin->GetBoundingBox(); double xscale = (double) dc_size.x / bBox.GetWidth(); double yscale = (double) dc_size.y / bBox.GetHeight(); double scale = std::min( xscale, yscale ); // Give a 10% margin scale *= 0.9; dc.SetUserScale( scale, scale ); wxPoint offset = bBox.Centre(); NEGATE( offset.x ); NEGATE( offset.y ); GRResetPenAndBrush( &dc ); m_dummyPin->Draw( NULL, &dc, offset, UNSPECIFIED_COLOR, GR_COPY, NULL, DefaultTransform ); m_dummyPin->SetParent(NULL); event.Skip(); }
/* * Traces the outline of the search block structures * The entire block follows the cursor */ void DrawMovingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition, bool aErase ) { SCH_DRAW_PANEL* panel =static_cast<SCH_DRAW_PANEL*>( aPanel ); LIB_EDIT_FRAME* frame = (LIB_EDIT_FRAME*) aPanel->GetParent(); KIGFX::SCH_VIEW* view = panel->GetView(); KIGFX::VIEW_GROUP* preview = view->GetPreview(); BASE_SCREEN* screen = aPanel->GetScreen(); BLOCK_SELECTOR* block = &screen->m_BlockLocate; LIB_PART* component = frame->GetCurPart(); if( component == NULL ) return; block->SetMoveVector( frame->GetCrossHairPosition( true ) - block->GetLastCursorPosition() ); preview->Clear(); view->SetVisible( preview, true ); for( unsigned ii = 0; ii < block->GetCount(); ii++ ) { LIB_ITEM* libItem = (LIB_ITEM*) block->GetItem( ii ); LIB_ITEM* copy = static_cast<LIB_ITEM*>( libItem->Clone() ); copy->Move( copy->GetPosition() + block->GetMoveVector() ); copy->SetFlags( IS_MOVED ); preview->Add( copy ); view->Hide( libItem ); } view->Update( preview ); }
int LIB_CONTROL::ShowComponentTree( const TOOL_EVENT& aEvent ) { if( m_isLibEdit ) { LIB_EDIT_FRAME* editFrame = static_cast<LIB_EDIT_FRAME*>( m_frame ); wxCommandEvent dummy; editFrame->OnToggleSearchTree( dummy ); } return 0; }
/* Move pin to the current mouse position. This function is called by the * cursor management code. */ static void DrawMovePin( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition, bool aErase ) { LIB_EDIT_FRAME* parent = (LIB_EDIT_FRAME*) aPanel->GetParent(); if( parent == NULL ) return; LIB_PIN* cur_pin = (LIB_PIN*) parent->GetDrawItem(); if( cur_pin == NULL || cur_pin->Type() != LIB_PIN_T ) return; wxPoint pinpos = cur_pin->GetPosition(); int show_opts = PIN_DRAW_TEXTS | PIN_DRAW_DANGLING | PIN_DANGLING_HIDDEN; if( parent->GetShowElectricalType() ) show_opts |= PIN_DRAW_ELECTRICAL_TYPE_NAME; // In LIB_PIN::Draw() a void* parameter used as flag to pass show_opts. // Build it: void* showOptions = reinterpret_cast<void*>( show_opts ); // Erase pin in old position if( aErase ) { cur_pin->Move( PinPreviousPos ); cur_pin->Draw( aPanel, aDC, wxPoint( 0, 0 ), UNSPECIFIED_COLOR, g_XorMode, showOptions, DefaultTransform ); } // Redraw pin in new position cur_pin->Move( aPanel->GetParent()->GetCrossHairPosition( true ) ); cur_pin->Draw( aPanel, aDC, wxPoint( 0, 0 ), UNSPECIFIED_COLOR, g_XorMode, showOptions, DefaultTransform ); PinPreviousPos = cur_pin->GetPosition(); /* Keep the original position for existing pin (for Undo command) * and the current position for a new pin */ if( !cur_pin->IsNew() ) cur_pin->Move( pinpos ); }
void SCH_EDIT_FRAME::OnOpenLibraryEditor( wxCommandEvent& event ) { SCH_COMPONENT* component = NULL; if( event.GetId() == ID_POPUP_SCH_CALL_LIBEDIT_AND_LOAD_CMP ) { SCH_ITEM* item = GetScreen()->GetCurItem(); if( (item == NULL) || (item->GetFlags() != 0) || ( item->Type() != SCH_COMPONENT_T ) ) { wxMessageBox( _("Error: not a component or no component" ) ); return; } component = (SCH_COMPONENT*) item; } LIB_EDIT_FRAME* libeditFrame = LIB_EDIT_FRAME::GetActiveLibraryEditor();; if( libeditFrame ) { if( libeditFrame->IsIconized() ) libeditFrame->Iconize( false ); libeditFrame->Raise(); } else { wxWindow* w = Kiface().CreateWindow( this, LIBEDITOR_FRAME_TYPE, &Kiway() ); libeditFrame = dynamic_cast<LIB_EDIT_FRAME*>( w ); } if( component ) { LIB_ALIAS* entry = CMP_LIBRARY::FindLibraryEntry( component->GetLibName() ); if( entry == NULL ) // Should not occur return; CMP_LIBRARY* library = entry->GetLibrary(); libeditFrame->LoadComponentAndSelectLib( entry, library ); } }
static void AbortSymbolTraceOn( EDA_DRAW_PANEL* Panel, wxDC* DC ) { LIB_EDIT_FRAME* parent = (LIB_EDIT_FRAME*) Panel->GetParent(); LIB_ITEM* item = parent->GetDrawItem(); if( item == NULL ) return; bool newItem = item->IsNew(); item->EndEdit( parent->GetCrossHairPosition( true ), true ); if( newItem ) { delete item; } else parent->RestoreComponent(); parent->SetDrawItem( NULL ); Panel->Refresh(); }
/** * Clean up after aborting a move pin command. */ static void AbortPinMove( EDA_DRAW_PANEL* Panel, wxDC* DC ) { LIB_EDIT_FRAME* parent = (LIB_EDIT_FRAME*) Panel->GetParent(); if( parent == NULL ) return; LIB_PIN* pin = (LIB_PIN*) parent->GetDrawItem(); if( pin == NULL || pin->Type() != LIB_PIN_T ) return; pin->ClearFlags(); if( pin->IsNew() ) delete pin; else parent->RestoreComponent(); // clear edit flags parent->SetDrawItem( NULL ); parent->SetLastDrawItem( NULL ); Panel->Refresh( true ); }
/* * Traces the outline of the search block structures * The entire block follows the cursor */ void DrawMovingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition, bool aErase ) { BLOCK_SELECTOR* PtBlock; BASE_SCREEN* screen = aPanel->GetScreen(); wxPoint move_offset; PtBlock = &screen->m_BlockLocate; LIB_EDIT_FRAME* parent = ( LIB_EDIT_FRAME* ) aPanel->GetParent(); wxASSERT( parent != NULL ); LIB_COMPONENT* component = parent->GetComponent(); if( component == NULL ) return; int unit = parent->GetUnit(); int convert = parent->GetConvert(); if( aErase ) { PtBlock->Draw( aPanel, aDC, PtBlock->m_MoveVector, g_XorMode, PtBlock->m_Color ); component->Draw( aPanel, aDC, PtBlock->m_MoveVector, unit, convert, g_XorMode, -1, DefaultTransform, true, true, true ); } /* Repaint new view */ PtBlock->m_MoveVector = screen->GetCrossHairPosition() - PtBlock->m_BlockLastCursorPosition; GRSetDrawMode( aDC, g_XorMode ); PtBlock->Draw( aPanel, aDC, PtBlock->m_MoveVector, g_XorMode, PtBlock->m_Color ); component->Draw( aPanel, aDC, PtBlock->m_MoveVector, unit, convert, g_XorMode, -1, DefaultTransform, true, true, true ); }
void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::OnOKButtonClick( wxCommandEvent& event ) { if( !copyPanelToSelectedField() ) return; // test if reference prefix is acceptable if( !SCH_COMPONENT::IsReferenceStringValid( m_FieldsBuf[REFERENCE].GetText() ) ) { DisplayError( NULL, _( "Illegal reference prefix. A reference must start by a letter" ) ); return; } /* Note: this code is now (2010-dec-04) not used, because the value field is no more editable * because changing the value is equivalent to create a new component or alias. * This is now handled in libedit main frame, and no more in this dialog * but this code is not removed, just in case */ /* If a new name entered in the VALUE field, that it not an existing alias name * or root alias of the component */ wxString newvalue = m_FieldsBuf[VALUE].GetText(); if( m_libEntry->HasAlias( newvalue ) && !m_libEntry->GetAlias( newvalue )->IsRoot() ) { wxString msg = wxString::Format( _( "A new name is entered for this component\n" "An alias %s already exists!\n" "Cannot update this component" ), GetChars( newvalue ) ); DisplayError( this, msg ); return; } /* End unused code */ // save old cmp in undo list m_parent->SaveCopyInUndoList( m_libEntry ); // delete any fields with no name or no value before we copy all of m_FieldsBuf // back into the component for( unsigned i = MANDATORY_FIELDS; i < m_FieldsBuf.size(); ) { if( m_FieldsBuf[i].GetName().IsEmpty() || m_FieldsBuf[i].GetText().IsEmpty() ) { m_FieldsBuf.erase( m_FieldsBuf.begin() + i ); continue; } ++i; } #if defined(DEBUG) for( unsigned i = 0; i<m_FieldsBuf.size(); ++i ) { printf( "save[%u].name:'%s' value:'%s'\n", i, TO_UTF8( m_FieldsBuf[i].GetName() ), TO_UTF8( m_FieldsBuf[i].GetText() ) ); } #endif // copy all the fields back, fully replacing any previous fields m_libEntry->SetFields( m_FieldsBuf ); // We need to keep the name and the value the same at the moment! SetName( m_libEntry->GetValueField().GetText() ); m_parent->OnModify(); EndQuasiModal( wxID_OK ); }
void SCH_EDIT_FRAME::OnCloseWindow( wxCloseEvent& aEvent ) { LIB_EDIT_FRAME * libeditFrame = LIB_EDIT_FRAME::GetActiveLibraryEditor();; if( libeditFrame && !libeditFrame->Close() ) // Can close component editor? return; LIB_VIEW_FRAME* viewlibFrame = LIB_VIEW_FRAME::GetActiveLibraryViewer( this ); if( viewlibFrame && !viewlibFrame->Close() ) // Can close component viewer? return; SCH_SHEET_LIST SheetList; if( SheetList.IsModified() ) { wxString msg; msg.Printf( _("Save the changes in\n<%s>\nbefore closing?"), GetChars( g_RootSheet->GetScreen()->GetFileName() ) ); int ii = DisplayExitDialog( this, msg ); switch( ii ) { case wxID_CANCEL: aEvent.Veto(); return; case wxID_NO: break; case wxID_YES: wxCommandEvent tmp( ID_SAVE_PROJECT ); OnSaveProject( tmp ); break; } } // Close the find dialog and perserve it's setting if it is displayed. if( m_dlgFindReplace ) { m_findDialogPosition = m_dlgFindReplace->GetPosition(); m_findDialogSize = m_dlgFindReplace->GetSize(); m_findStringHistoryList = m_dlgFindReplace->GetFindEntries(); m_replaceStringHistoryList = m_dlgFindReplace->GetReplaceEntries(); m_dlgFindReplace->Destroy(); m_dlgFindReplace = NULL; } SCH_SCREENS screens; wxFileName fn; for( SCH_SCREEN* screen = screens.GetFirst(); screen != NULL; screen = screens.GetNext() ) { fn = screen->GetFileName(); // Auto save file name is the normal file name prepended with $. fn.SetName( wxT( "$" ) + fn.GetName() ); if( fn.FileExists() && fn.IsFileWritable() ) wxRemoveFile( fn.GetFullPath() ); } SheetList.ClearModifyStatus(); if( !g_RootSheet->GetScreen()->GetFileName().IsEmpty() && (g_RootSheet->GetScreen()->GetDrawItems() != NULL) ) UpdateFileHistory( g_RootSheet->GetScreen()->GetFileName() ); g_RootSheet->GetScreen()->Clear(); // all sub sheets are deleted, only the main sheet is usable m_CurrentSheet->Clear(); Destroy(); }