Esempio n. 1
0
bool SCH_EDIT_FRAME::AppendOneEEProject()
{
    SCH_SCREEN* screen;
    wxString    FullFileName;
    wxString msg;

    screen = GetScreen();

    if( !screen )
    {
        wxLogError( wxT("Document not ready, cannot import") );
        return false;
    }

    // open file chooser dialog
    wxFileDialog dlg( this, _( "Import Schematic" ), wxGetCwd(),
                      wxEmptyString, SchematicFileWildcard,
                      wxFD_OPEN | wxFD_FILE_MUST_EXIST );

    if( dlg.ShowModal() == wxID_CANCEL )
        return false;

    FullFileName = dlg.GetPath();

    wxFileName fn = FullFileName;

    if( fn.IsRelative() )
    {
        fn.MakeAbsolute();
        FullFileName = fn.GetFullPath();
    }

    LoadCacheLibrary( FullFileName );

    wxLogDebug( wxT( "Importing schematic " ) + FullFileName );

    // load the project
    bool success = LoadOneEEFile( screen, FullFileName, true );
    if( success )
    {
        // load sub-sheets
        EDA_ITEM* bs = screen->GetDrawItems();
        while( bs )
        {
            // do not append hierarchical sheets
            if( bs->Type() ==  SCH_SHEET_T )
            {
                screen->Remove( (SCH_SHEET*) bs );
            }
            // clear annotation and init new time stamp for the new components
            else if( bs->Type() == SCH_COMPONENT_T )
            {
                ( (SCH_COMPONENT*) bs )->SetTimeStamp( GetNewTimeStamp() );
                ( (SCH_COMPONENT*) bs )->ClearAnnotation( NULL );
                // Clear flags, which are set by these previous modifications:
                bs->ClearFlags();
            }

            bs = bs->Next();
        }
    }

    // redraw base screen (ROOT) if necessary
    GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId );
    Zoom_Automatique( false );
    SetSheetNumberAndCount();
    m_canvas->Refresh( true );
    return success;
}
Esempio n. 2
0
int WinEDA_SchematicFrame::LoadOneEEProject(const wxString & FileName, bool IsNew)
/********************************************************************************/
/*
	Routine de chargement d'un projet ( schema principal "Root" et ses
	sous schemas ( hierarchie )
*/
{
BASE_SCREEN *screen, * NextScreen;
EDA_BaseStruct *EEDrawList ;
wxString FullFileName, msg;
bool LibCacheExist = FALSE;
	
	screen = ScreenSch ;
	while( screen )
	{
		if(screen->IsModify()) break;
		screen = screen->Next();
	}

	if ( screen )
	{
		if( ! IsOK(this, _("Clear Schematic Hierarchy (modified!)?")) ) return FALSE;
		if ( ScreenSch->m_FileName != g_DefaultSchematicFileName )
			SetLastProject(ScreenSch->m_FileName);
	}


	screen = ScreenSch ;
	if( ClearProjectDrawList((SCH_SCREEN*) screen) == FALSE ) return(1);

	FullFileName = FileName;
	if( (FullFileName.IsEmpty() ) && !IsNew )
	{
		wxString mask = wxT("*") + g_SchExtBuffer;
		FullFileName = EDA_FileSelector( _("Schematic files:"),
					wxEmptyString,		  			/* Chemin par defaut */
					wxEmptyString,					/* nom fichier par defaut */
					g_SchExtBuffer,		/* extension par defaut */
					mask,				/* Masque d'affichage */
					this,
					wxOPEN,
					TRUE
					);
		if ( FullFileName.IsEmpty() ) return ( FALSE );
	}

	m_CurrentScreen = screen = ActiveScreen = ScreenSch;
	screen->m_CurrentItem = NULL;
	wxSetWorkingDirectory(wxPathOnly(FullFileName) );
	m_CurrentScreen->m_FileName = FullFileName;
	Affiche_Message(wxEmptyString);
	MsgPanel->EraseMsgBox();

	memset( &g_EESchemaVar,0, sizeof(g_EESchemaVar) );

	m_CurrentScreen->ClrModify();
	m_CurrentScreen->Pnext = NextScreen = NULL;

	if( IsNew )
	{
		screen->m_CurrentSheet = &g_Sheet_A4;
		screen->SetZoom(32);
		screen->m_SheetNumber = screen->m_NumberOfSheet = 1;
		screen->m_Title = wxT("noname.sch");
		m_CurrentScreen->m_FileName = screen->m_Title;
		screen->m_Company.Empty();
		screen->m_Commentaire1.Empty();
		screen->m_Commentaire2.Empty();
		screen->m_Commentaire3.Empty();
		screen->m_Commentaire4.Empty();
		Read_Config(wxEmptyString, TRUE);
		Zoom_Automatique(TRUE);
		ReDrawPanel();
		return (1);
	}
	// Rechargement de la configuration:
	msg = _("Ready\nWorking dir: \n") + wxGetCwd();
	PrintMsg(msg);

	Read_Config(wxEmptyString, FALSE);

	// Delete old caches.
LibraryStruct *nextlib, *lib = g_LibraryList;
	for (; lib != NULL; lib = nextlib )
	{
		nextlib = lib->m_Pnext;
		if ( lib->m_IsLibCache )
			FreeCmpLibrary(this, lib->m_Name);
	}

	if( IsNew )
	{
		ReDrawPanel();
		return (1);
	}

	// Loading the project library cache
	wxString FullLibName;
	wxString shortfilename;
	wxSplitPath(ScreenSch->m_FileName, NULL, &shortfilename, NULL);
	FullLibName << wxT(".") << STRING_DIR_SEP << shortfilename << wxT(".cache") << g_LibExtBuffer;
	if ( wxFileExists(FullLibName) )
	{
		wxString libname;
		libname = FullLibName;
		ChangeFileNameExt(libname,wxEmptyString);
		msg = wxT("Load ") + FullLibName;
		LibraryStruct *LibCache = LoadLibraryName(this, FullLibName, libname);
		if ( LibCache )
		{
			LibCache->m_IsLibCache = TRUE;
			msg += wxT(" OK");
		}
		else msg += wxT(" ->Error");
		PrintMsg( msg );
		LibCacheExist = TRUE;
	}

	if ( ! wxFileExists(screen->m_FileName) && !LibCacheExist)	// Nouveau projet prpbablement
	{
		msg.Printf( _("File %s not found (new project ?)"),
			screen->m_FileName.GetData() );
		DisplayInfo(this, msg, 20);
		return (-1);
	}
	
	if( LoadOneEEFile(screen, screen->m_FileName) == FALSE) return (0);

	/* Chargement des sous feuilles */
	while(screen)
		{
		EEDrawList = screen->EEDrawList;
		while(EEDrawList)
			{
			if( EEDrawList->m_StructType == DRAW_SHEET_STRUCT_TYPE)
				{
				#undef STRUCT
				#define STRUCT ((DrawSheetStruct*)EEDrawList)
				int timestamp = STRUCT->m_TimeStamp;
				if(timestamp == 0 )
					{
					timestamp = GetTimeStamp();
					STRUCT->m_TimeStamp = timestamp;
					}
				if( screen->Pnext == NULL)	/* 1ere Sheet */
					{
					screen->Pnext = NextScreen =
									CreateNewScreen(this, (SCH_SCREEN*)screen,timestamp);
					}
				else
					{
					NextScreen->Pnext = CreateNewScreen(this, (SCH_SCREEN*)NextScreen, timestamp);
					NextScreen = (BASE_SCREEN*)NextScreen->Pnext;
					}

				STRUCT->m_Son = NextScreen;
				NextScreen->m_Parent = EEDrawList;

				if( ! STRUCT->m_Field[SHEET_FILENAME].m_Text.IsEmpty() )
				{
					NextScreen->m_FileName = STRUCT->m_Field[SHEET_FILENAME].m_Text;
					if( LoadOneEEFile(NextScreen, NextScreen->m_FileName) == TRUE )
					{
						ActiveScreen = (SCH_SCREEN*) NextScreen;
					}
				}
				else DisplayError(this, _("No FileName in SubSheet"));
				}
			EEDrawList = EEDrawList->Pnext;
			}
		screen = (BASE_SCREEN*)screen->Pnext;
		}


	/* Reaffichage ecran de base (ROOT) si necessaire */
	screen = ActiveScreen = ScreenSch;
	Zoom_Automatique(FALSE);

	return (1);
}