コード例 #1
0
void WinEDA_ModuleEditFrame::OnSelectOptionToolbar(wxCommandEvent& event)
/***********************************************************************/
{
int id = event.GetId();
wxClientDC dc(DrawPanel);

	DrawPanel->PrepareGraphicContext(&dc);
	switch ( id )
		{
		case ID_TB_OPTIONS_SHOW_GRID:
			m_Draw_Grid = m_OptionsToolBar->GetToolState(id);
			DrawPanel->ReDraw(&dc, TRUE);
			break;

		case ID_TB_OPTIONS_SELECT_UNIT_MM:
			UnitMetric = MILLIMETRE;
		case ID_TB_OPTIONS_SELECT_UNIT_INCH:
			if ( id == ID_TB_OPTIONS_SELECT_UNIT_INCH )
				UnitMetric = INCHES;
			Affiche_Status_Box();	 /* Reaffichage des coord curseur */
			ReCreateAuxiliaryToolbar();
			break;

		case ID_TB_OPTIONS_SHOW_POLAR_COORD:
			Affiche_Message(wxEmptyString);
			DisplayOpt.DisplayPolarCood = m_OptionsToolBar->GetToolState(id);
			Affiche_Status_Box();	 /* Reaffichage des coord curseur */
			break;

		case ID_TB_OPTIONS_SELECT_CURSOR:
			GetScreen()->Trace_Curseur(DrawPanel, &dc);
			g_CursorShape = m_OptionsToolBar->GetToolState(id);
			GetScreen()->Trace_Curseur(DrawPanel, &dc);
			break;

		case ID_TB_OPTIONS_SHOW_PADS_SKETCH:
			m_DisplayPadFill = ! m_OptionsToolBar->GetToolState(id);
			DrawPanel->ReDraw(&dc, TRUE);
			break;

		case ID_TB_OPTIONS_SHOW_MODULE_TEXT_SKETCH:
			m_DisplayModText =
				m_OptionsToolBar->GetToolState(id) ? SKETCH : FILLED;
			DrawPanel->ReDraw(&dc, TRUE);
			break;

		case ID_TB_OPTIONS_SHOW_MODULE_EDGE_SKETCH:
			m_DisplayModEdge =
				m_OptionsToolBar->GetToolState(id) ? SKETCH : FILLED;
			DrawPanel->ReDraw(&dc, TRUE);
			break;

		default:
			DisplayError(this, wxT("WinEDA_ModuleEditFrame::OnSelectOptionToolbar error") );
			break;
		}

	SetToolbars();
}
コード例 #2
0
//------------------------------------------------------------------------------
void OS_Main()
{
  Affiche_Message(">>>Initialisation de la Pile (ESP) : ","OK");

  Initialisation_IDT();
  Affiche_Message(">>>Initialisation de la IDT : ","OK");

  Inititialisation_8259A();
  Affiche_Message(">>>Initialisation du PIC 8259A : ","OK");

  Initialisation_8253(1193);
  Affiche_Message(">>>Initialisation du controleur 8253 : ","OK");

  AUTORISE_INTERRUPTION;

//   Affiche_Chaine("Appuyez sur une touche pour remplir l'ecran via un appel systeme \n");
//   Attendre_Touche_Relache();
//   
//   
//   
//   API_clrscr();
//   API_puts("Voici un texte \n", 6);
//
//
//   API_puts("Appuyez sur une touche pour terminer \n", 5);
//   Attendre_Touche_Relache();

   Affiche_Chaine("Appuyez sur une touche pour remplir l'ecran via un appel systeme \n");
   Attendre_Touche_Relache();
   
   
   
   API_clrscr();
   API_puts("Voici un texte \n");


   API_puts("Appuyez sur une touche pour terminer \n");
   Attendre_Touche_Relache();




   Affiche_Chaine("FIN");
   while(1);

 }
コード例 #3
0
 //----------------------------------------------------------------------------
void OS_Start(T_BOOT_INFO* P_Info)
{
  Efface_Ecran();
  Affiche_Message(">>>BOOT JLV OS V1 - 2011 Via GRUB : ", "OK");
  Affiche_Informations_Boot(P_Info);

  Initialisation_GDT();
  Affiche_Message(">>>Initialisation de la GDT : ","OK");

  //Initialiser le pointeur pile.
  // NE PAS ETRE DANS UNE FONCTION CAR à la sortie d'une fonction, le regsitre ESP est réinitialisé à la valeur précédant l'appel.
 //  INITIALISE_SS_ESP(SELECTEUR_STACK_NOYAU,DEBUT_STACK_NOYAU);


  INITIALISE_SS_ESP(SELECTEUR_STACK_NOYAU, DEBUT_STACK_NOYAU)
   OS_Main();
   asm ("NOP");
}
コード例 #4
0
void WinEDA_BasePcbFrame::test_1_net_connexion(wxDC * DC,  int net_code)
/*************************************************************************/
/*
Routine recherchant les connexions deja faites relatives a 1 net
*/
{
TRACK * pt_start_conn, * pt_end_conn;
int ii, nb_net_noconnect = 0;
LISTE_PAD * pt_pad;
wxString msg;
	
	if(net_code == 0) return;

	if ( (m_Pcb->m_Status_Pcb & LISTE_CHEVELU_OK) == 0 )
		Compile_Ratsnest( DC, TRUE );

	pt_pad = (LISTE_PAD*)m_Pcb->m_Pads;
	for( ii = 0; ii < m_Pcb->m_NbPads; ii++ , pt_pad++)
		{
		int pad_net_code = (*pt_pad)->m_NetCode;
		if(pad_net_code < net_code) continue;
		if(pad_net_code > net_code) break;
		(*pt_pad)->m_physical_connexion = 0 ;
		}

	/* Determination des limites du net */
	if( m_Pcb->m_Track )
		{
		pt_end_conn = NULL;
		pt_start_conn = m_Pcb->m_Track->GetStartNetCode(net_code);

		if( pt_start_conn )
			pt_end_conn = pt_start_conn->GetEndNetCode(net_code);

		if( pt_start_conn && pt_end_conn ) // c.a.d. s'il y a des segments
			{
			calcule_connexite_1_net(pt_start_conn, pt_end_conn);
			}
		}

	/* Test des chevelus */
	nb_net_noconnect = Test_1_Net_Ratsnest(DC, net_code);

	/* Affichage des resultats */
	msg.Printf( wxT("links %d nc %d  net:nc %d"),
				 m_Pcb->m_NbLinks, m_Pcb->GetNumNoconnect(),
				 nb_net_noconnect);

	Affiche_Message(msg);
	return;
}
コード例 #5
0
void WinEDA_PcbFrame::DisplayTrackSettings(void)
/***********************************************/
/* Display the current track width and via diameter
*/
{
wxString msg;
wxString buftrc, bufvia;

	valeur_param(g_DesignSettings.m_CurrentTrackWidth, buftrc);
	valeur_param(g_DesignSettings.m_CurrentViaSize, bufvia);
	msg.Printf( _("Track Width: %s   Vias Size : %s"),
			buftrc.GetData(), bufvia.GetData());
	Affiche_Message( msg);
	m_SelTrackWidthBox_Changed = TRUE;
	m_SelViaSizeBox_Changed = TRUE;
}
コード例 #6
0
/*****************************************************************************
* Routine to save an EESchema file.											 *
* FileSave controls how the file is to be saved - under what name.			 *
* Returns TRUE if the file has been saved.									 *
*****************************************************************************/
bool WinEDA_SchematicFrame::SaveEEFile(BASE_SCREEN *Window, int FileSave)
{
wxString msg;
wxString Name, BakName;
const wxChar **LibNames;
char * layer, *width;
int ii, shape;
bool Failed = FALSE;
EDA_BaseStruct *Phead;
Ki_PageDescr * PlotSheet;
FILE *f;
wxString dirbuf;

	if ( Window == NULL ) Window = ActiveScreen;

	/* If no name exists in the window yet - save as new. */
	if( Window->m_FileName.IsEmpty() ) FileSave = FILE_SAVE_NEW;

	switch (FileSave)
	{
		case FILE_SAVE_AS:
			dirbuf = wxGetCwd() + STRING_DIR_SEP;
			Name = MakeFileName(dirbuf, Window->m_FileName, g_SchExtBuffer);
			/* Rename the old file to a '.bak' one: */
			BakName = Name;
			if ( wxFileExists(Name) )
			{
				ChangeFileNameExt(BakName, wxT(".bak"));
				wxRemoveFile(BakName);	/* delete Old .bak file */
				if( ! wxRenameFile(Name, BakName) )
				{
					DisplayError(this, wxT("Warning: unable to rename old file"), 10);
				}
			}
			break;

		case FILE_SAVE_NEW:
		{
			wxString mask = wxT("*") + g_SchExtBuffer;
			Name = EDA_FileSelector(_("Schematic files:"),
					wxEmptyString,					/* Chemin par defaut */
					Window->m_FileName,				/* nom fichier par defaut, et resultat */
					g_SchExtBuffer,		/* extension par defaut */
					mask,				/* Masque d'affichage */
					this,
					wxSAVE,
					FALSE
					);
			if ( Name.IsEmpty() ) return FALSE;

			Window->m_FileName = Name;
			dirbuf = wxGetCwd() + STRING_DIR_SEP;
			Name = MakeFileName(dirbuf, Name, g_SchExtBuffer);

			break;
		}

		default: break;
	}

	if ((f = wxFopen(Name, wxT("wt"))) == NULL)
	{
		msg = _("Failed to create file ") + Name;
		DisplayError(this, msg);
		return FALSE;
	}

	msg = _("Save file ") + Name;
	Affiche_Message(msg);

	LibNames = GetLibNames();
	BakName.Empty();	// temporary buffer!
	for (ii = 0; LibNames[ii] != NULL; ii++)
	{
		if (ii > 0) BakName += wxT(",");
		BakName += LibNames[ii];
	}
	MyFree( LibNames);

	if (fprintf(f, "%s %s %d\n", EESCHEMA_FILE_STAMP,
		SCHEMATIC_HEAD_STRING, EESCHEMA_VERSION) == EOF ||
		fprintf(f, "LIBS:%s\n", CONV_TO_UTF8(BakName)) == EOF)
	{
		DisplayError(this, _("File write operation failed."));
		fclose(f);
		return FALSE;
	}

	Window->ClrModify();

	SaveLayers(f);
	/* Sauvegarde des dimensions du schema, des textes du cartouche.. */
	
	PlotSheet = Window->m_CurrentSheet;
	fprintf(f,"$Descr %s %d %d\n",CONV_TO_UTF8(PlotSheet->m_Name),
			PlotSheet->m_Size.x, PlotSheet->m_Size.y);

	fprintf(f,"Sheet %d %d\n",Window->m_SheetNumber, Window->m_NumberOfSheet);
	fprintf(f,"Title \"%s\"\n",CONV_TO_UTF8(Window->m_Title));
	fprintf(f,"Date \"%s\"\n",CONV_TO_UTF8(Window->m_Date));
	fprintf(f,"Rev \"%s\"\n",CONV_TO_UTF8(Window->m_Revision));
	fprintf(f,"Comp \"%s\"\n",CONV_TO_UTF8(Window->m_Company));
	fprintf(f,"Comment1 \"%s\"\n", CONV_TO_UTF8(Window->m_Commentaire1));
	fprintf(f,"Comment2 \"%s\"\n", CONV_TO_UTF8(Window->m_Commentaire2));
	fprintf(f,"Comment3 \"%s\"\n", CONV_TO_UTF8(Window->m_Commentaire3));
	fprintf(f,"Comment4 \"%s\"\n", CONV_TO_UTF8(Window->m_Commentaire4));

	fprintf(f,"$EndDescr\n");

	/* Sauvegarde des elements du dessin */
	Phead = Window->EEDrawList;
	while (Phead)
		{
		switch(Phead->m_StructType)
			{
			case DRAW_LIB_ITEM_STRUCT_TYPE:		  /* Its a library item. */
				SavePartDescr( f, (EDA_SchComponentStruct *) Phead);
				break;

			case DRAW_SHEET_STRUCT_TYPE:	   /* Its a Sheet item. */
				SaveSheetDescr( f, (DrawSheetStruct *) Phead);
				break;

			case DRAW_SEGMENT_STRUCT_TYPE:		 /* Its a Segment item. */
				#undef STRUCT
				#define STRUCT ((EDA_DrawLineStruct *) Phead)
				layer = "Notes"; width = "Line";
				if (STRUCT->m_Layer == LAYER_WIRE) layer = "Wire";
				if (STRUCT->m_Layer == LAYER_BUS) layer = "Bus";
				if( STRUCT->m_Width != GR_NORM_WIDTH) layer = "Bus";
				if (fprintf(f, "Wire %s %s\n", layer, width ) == EOF)
					{
					Failed = TRUE; break;
					}
				if (fprintf(f, "\t%-4d %-4d %-4d %-4d\n",
						STRUCT->m_Start.x,STRUCT->m_Start.y,
						STRUCT->m_End.x,STRUCT->m_End.y) == EOF)
					{
					Failed = TRUE; break;
					}
				break;

			case DRAW_BUSENTRY_STRUCT_TYPE:		 /* Its a Raccord item. */
				#undef STRUCT
				#define STRUCT ((DrawBusEntryStruct *) Phead)
				layer = "Wire"; width = "Line";
				if (STRUCT->m_Layer == LAYER_BUS)
					{
					layer = "Bus"; width = "Bus";
					}

				if (fprintf(f, "Entry %s %s\n", layer, width) == EOF)
					{
					Failed = TRUE; break;
					}
				if( fprintf(f, "\t%-4d %-4d %-4d %-4d\n",
						STRUCT->m_Pos.x,STRUCT->m_Pos.y,
						STRUCT->m_End().x,STRUCT->m_End().y) == EOF)
						{
						Failed = TRUE; break;
						}
				break;

			case DRAW_POLYLINE_STRUCT_TYPE:		  /* Its a polyline item. */
				#undef STRUCT
				#define STRUCT ((DrawPolylineStruct *) Phead)
				layer = "Notes"; width = "Line";
				if (STRUCT->m_Layer == LAYER_WIRE) layer = "Wire";
				if (STRUCT->m_Layer == LAYER_BUS) layer = "Bus";
				if( STRUCT->m_Width != GR_NORM_WIDTH) width = "Bus";
				if (fprintf(f, "Poly %s %s %d\n",
							width, layer, STRUCT->m_NumOfPoints) == EOF)
					{
					Failed = TRUE; break;
					}
				for (ii = 0; ii < STRUCT->m_NumOfPoints; ii++)
					{
					if (fprintf(f, "\t%-4d %-4d\n",
						STRUCT->m_Points[ii*2],
						STRUCT->m_Points[ii*2+1]) == EOF)
						{
						Failed = TRUE;
						break;
						}
					}
				break;

			case DRAW_JUNCTION_STRUCT_TYPE:	/* Its a connection item. */
				#undef STRUCT
				#define STRUCT ((DrawJunctionStruct *) Phead)
				if (fprintf(f, "Connection ~ %-4d %-4d\n",
					STRUCT->m_Pos.x, STRUCT->m_Pos.y) == EOF)
					{
					Failed = TRUE;
					}
				break;

			case DRAW_NOCONNECT_STRUCT_TYPE:	/* Its a NoConnection item. */
				#undef STRUCT
				#define STRUCT ((DrawNoConnectStruct *) Phead)
				if (fprintf(f, "NoConn ~ %-4d %-4d\n",
					STRUCT->m_Pos.x, STRUCT->m_Pos.y) == EOF)
					{
					Failed = TRUE;
					}
				break;

			case DRAW_TEXT_STRUCT_TYPE:			/* Its a text item. */
				#undef STRUCT
				#define STRUCT ((DrawTextStruct *) Phead)
				if (fprintf(f, "Text Notes %-4d %-4d %-4d %-4d ~\n%s\n",
						STRUCT->m_Pos.x, STRUCT->m_Pos.y,
						STRUCT->m_Orient, STRUCT->m_Size.x,
						CONV_TO_UTF8(STRUCT->m_Text)) == EOF)
					Failed = TRUE;
				break;


			case DRAW_LABEL_STRUCT_TYPE:		/* Its a label item. */
				#undef STRUCT
				#define STRUCT ((DrawLabelStruct *) Phead)
				shape = '~';
				if (fprintf(f, "Text Label %-4d %-4d %-4d %-4d %c\n%s\n",
						STRUCT->m_Pos.x, STRUCT->m_Pos.y,
						STRUCT->m_Orient, STRUCT->m_Size.x, shape,
						CONV_TO_UTF8(STRUCT->m_Text)) == EOF)
					Failed = TRUE;
				break;


			case DRAW_GLOBAL_LABEL_STRUCT_TYPE: /* Its a Global label item. */
				#undef STRUCT
				#define STRUCT ((DrawGlobalLabelStruct *) Phead)
				shape = STRUCT->m_Shape;
			if (fprintf(f, "Text GLabel %-4d %-4d %-4d %-4d %s\n%s\n",
						STRUCT->m_Pos.x, STRUCT->m_Pos.y,
						STRUCT->m_Orient,	STRUCT->m_Size.x,
						SheetLabelType[shape],
						CONV_TO_UTF8(STRUCT->m_Text)) == EOF)
					Failed = TRUE;
				break;

			case DRAW_MARKER_STRUCT_TYPE:	/* Its a marker item. */
				#undef STRUCT
				#define STRUCT ((DrawMarkerStruct *) Phead)
				if( STRUCT->GetComment() ) msg = STRUCT->GetComment();
				else msg.Empty();
				if (fprintf(f, "Kmarq %c %-4d %-4d \"%s\" F=%X\n",
								(int) STRUCT->m_Type + 'A',
								STRUCT->m_Pos.x, STRUCT->m_Pos.y,
								CONV_TO_UTF8(msg), STRUCT->m_MarkFlags) == EOF)
					{
					Failed = TRUE;
					}
				break;

			case DRAW_SHEETLABEL_STRUCT_TYPE :
			case DRAW_PICK_ITEM_STRUCT_TYPE :
				break;

			default:
				break;
			}

		if (Failed)
			{
			DisplayError(this, _("File write operation failed."));
			break;
			}

		Phead = Phead->Pnext;
		}
	if (fprintf(f, "$EndSCHEMATC\n") == EOF) Failed = TRUE;

	fclose(f);

	if (FileSave == FILE_SAVE_NEW) Window->m_FileName = Name;

	return !Failed;
}
コード例 #7
0
void WinEDA_GerberFrame::OnSelectOptionToolbar(wxCommandEvent& event)
/*****************************************************************/
{
int id = event.GetId();
wxClientDC dc(DrawPanel);

	DrawPanel->PrepareGraphicContext(&dc);
	switch ( id )
	{
		case ID_TB_OPTIONS_SHOW_GRID:
			m_Draw_Grid = g_ShowGrid = m_OptionsToolBar->GetToolState(id);
			DrawPanel->ReDraw(&dc, TRUE);
			break;

		case ID_TB_OPTIONS_SELECT_UNIT_MM:
			UnitMetric = MILLIMETRE;
			Affiche_Status_Box();	 /* Reaffichage des coord curseur */
			break;

		case ID_TB_OPTIONS_SELECT_UNIT_INCH:
			UnitMetric = INCHES;
			Affiche_Status_Box();	 /* Reaffichage des coord curseur */
			break;

		case ID_TB_OPTIONS_SHOW_POLAR_COORD:
			Affiche_Message("");
			DisplayOpt.DisplayPolarCood = m_OptionsToolBar->GetToolState(id);
			Affiche_Status_Box();	 /* Reaffichage des coord curseur */
			break;

		case ID_TB_OPTIONS_SELECT_CURSOR:
			GetScreen()->Trace_Curseur(DrawPanel, &dc);
			g_CursorShape = m_OptionsToolBar->GetToolState(id);
			GetScreen()->Trace_Curseur(DrawPanel, &dc);
			break;

		case ID_TB_OPTIONS_SHOW_PADS_SKETCH:
			if ( m_OptionsToolBar->GetToolState(id) )
			{
				m_DisplayPadFill = FALSE;
				DisplayOpt.DisplayPadFill = FALSE;
			}
			else
			{
				m_DisplayPadFill = TRUE;
				DisplayOpt.DisplayPadFill = TRUE;
			}
			DrawPanel->ReDraw(&dc, TRUE);
			break;

		case ID_TB_OPTIONS_SHOW_TRACKS_SKETCH:
			if( m_OptionsToolBar->GetToolState(id) )
			{
				m_DisplayPcbTrackFill = FALSE;
				DisplayOpt.DisplayPcbTrackFill = FALSE;
			}
			else
			{
				m_DisplayPcbTrackFill = TRUE;
				DisplayOpt.DisplayPcbTrackFill = TRUE;
			}
			DrawPanel->ReDraw(&dc, TRUE);
			break;

		case ID_TB_OPTIONS_SHOW_DCODES:
			DisplayOpt.DisplayPadNum = m_OptionsToolBar->GetToolState(id);
			DrawPanel->ReDraw(&dc, TRUE);
			break;


		default:
			DisplayError(this, "WinEDA_PcbFrame::OnSelectOptionToolbar error");
			break;
	}

	SetToolbars();
}
コード例 #8
0
ファイル: eeload.cpp プロジェクト: BackupTheBerlios/kicad-svn
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);
}
コード例 #9
0
wxString WinEDA_BasePcbFrame::Select_1_Module_From_List(
				wxWindow * active_window,
				const wxString & Library,
				const wxString & Mask, const wxString & KeyWord)
/***************************************************************/
/*
 Affiche la liste des modules des librairies
	Recherche dans la librairie Library ou generale si Library == NULL
	Mask = Filtre d'affichage( Mask = wxEmptyString pour listage non filtré )
	KeyWord = Liste de mots cles, Recherche limitee aux composants
		ayant ces mots cles ( KeyWord = wxEmptyString pour listage de tous les modules )

	retourne wxEmptyString si abort ou probleme
	ou le nom du module
*/
{
int LineNum;
unsigned ii, NbModules;
char Line[1024];
wxString FullLibName;
static wxString OldName;	/* Memorise le nom du dernier composant charge */
wxString CmpName;
FILE * lib_module;
wxString msg;
	
WinEDAListBox * ListBox = new WinEDAListBox(active_window, wxEmptyString,
			NULL, OldName, DisplayCmpDoc, wxColour(200, 200, 255) );

	wxBeginBusyCursor();

	/* Recherche des composants en librairies */
	NbModules = 0;
	for( ii = 0; ii < g_LibName_List.GetCount(); ii++)
	{
		/* Calcul du nom complet de la librairie */
		if( Library.IsEmpty() )
		{
			FullLibName = MakeFileName(g_RealLibDirBuffer,
						g_LibName_List[ii], LibExtBuffer);
		}
		else
			FullLibName = MakeFileName(g_RealLibDirBuffer,Library,LibExtBuffer);

		ReadDocLib(FullLibName );

		if( ! KeyWord.IsEmpty())	/* Inutile de lire la librairie si selection
						par mots cles, deja lus */
		{
			if( ! Library.IsEmpty() ) break;
			continue ;
		}

		if ((lib_module = wxFopen(FullLibName, wxT("rt")))  == NULL )
		{
			if( ! Library.IsEmpty() ) break;
			continue ;
		}

		msg = _("Library: "); msg << FullLibName;
		Affiche_Message(msg);

		/* lecture entete */
		LineNum = 0;
		GetLine(lib_module, Line, &LineNum, sizeof(Line) -1);

		if(strnicmp( Line,ENTETE_LIBRAIRIE, L_ENTETE_LIB) != 0)
		{
			DisplayError(this, wxT("This file is not an Eeschema libray file"), 20); continue;
		}

		/* Lecture de la librairie */
		while( GetLine(lib_module,Line, &LineNum, sizeof(Line) -1) )
		{
			if( Line[0] != '$' ) continue;
			if( strnicmp( Line, "$MODULE",6) == 0 ) break;
			if( strnicmp( Line,"$INDEX",6) == 0 )
			{
				while( GetLine(lib_module,Line, &LineNum) )
				{
					if( strnicmp( Line,"$EndINDEX",9) == 0 ) break;
                    strupper(Line);
					msg = CONV_FROM_UTF8(StrPurge(Line));
					if ( Mask.IsEmpty() )
					{
						ListBox->Append( msg );
						NbModules++;
					}
					else if ( WildCompareString(Mask, msg, FALSE) )
					{
						ListBox->Append( msg );
						NbModules++;
					}
				}
			} /* Fin Lecture INDEX */
		}  /* Fin lecture 1 Librairie */

		fclose(lib_module) ; lib_module = NULL;
		if( ! Library.IsEmpty() ) break;
	}

	/*  creation de la liste des modules si recherche par mots-cles */
	if( ! KeyWord.IsEmpty() )
	{
		ModList * ItemMod = MList;
		while( ItemMod != NULL )
		{
			if( KeyWordOk(KeyWord, ItemMod->m_KeyWord) )
			{
				NbModules++;
				ListBox->Append( ItemMod->m_Name );
			}
			ItemMod = ItemMod->Next;
		}
	}

	wxEndBusyCursor();

	msg.Printf( _("Modules (%d items)"), NbModules);
	ListBox->SetTitle(msg);
	ListBox->SortList();
	
	ii = ListBox->ShowModal();
	if ( ii >= 0 ) CmpName = ListBox->GetTextSelection();
	else CmpName.Empty();

	ListBox->Destroy();

	/* liberation mem de la liste des textes doc module */
	while( MList != NULL )
	{
		ModList * NewMod = MList->Next;
		delete MList;
		MList = NewMod;
	}

	if( CmpName != wxEmptyString ) OldName = CmpName;

	return(CmpName);
}
コード例 #10
0
MODULE * WinEDA_BasePcbFrame::Get_Librairie_Module(wxWindow * winaff,
		const wxString & library, const wxString & ModuleName, bool show_msg_err)
/*******************************************************************************/
/*
	Analyse les LIBRAIRIES pour trouver le module demande
	Si ce module est trouve, le copie en memoire, et le
	chaine en fin de liste des modules
		- Entree:
			name_cmp = nom du module
		- Retour:
			Pointeur sur le nouveau module.
*/
{
int LineNum, Found= 0;
wxString fulllibname;
char Line[512];
wxString Name;
wxString ComponentName, msg;
MODULE * Module;
MODULE * NewModule;
FILE * lib_module = NULL;
unsigned ii;

	ComponentName = ModuleName;

	/* Calcul de l'adresse du dernier module: */
	Module = m_Pcb->m_Modules;
	if( Module ) while( Module->Pnext ) Module = (MODULE*) Module->Pnext;

	for( ii = 0; ii < g_LibName_List.GetCount(); ii++)
	{
		fulllibname = g_LibName_List[ii];

		/* Calcul du nom complet de la librairie */
		fulllibname = MakeFileName(g_RealLibDirBuffer,fulllibname,LibExtBuffer);

		if ((lib_module = wxFopen(fulllibname, wxT("rt")))  == NULL )
		{
			msg.Printf(_("Library <%s> not found"),fulllibname.GetData());
			Affiche_Message(msg);
			continue ;
		}

		msg.Printf(_("Scan Lib: %s"),fulllibname.GetData());
		Affiche_Message(msg);

		/* lecture entete chaine definie par ENTETE_LIBRAIRIE */
		LineNum = 0;
		GetLine(lib_module, Line, &LineNum) ;
		StrPurge(Line);
		if(strnicmp( Line,ENTETE_LIBRAIRIE, L_ENTETE_LIB) != 0)
		{
			DisplayError(winaff, _("File is Not a library") );
			return(NULL);
		}

		/* Lecture de la liste des composants de la librairie */
		Found = 0;
		while( !Found && GetLine(lib_module,Line, &LineNum) )
		{
			if( strnicmp( Line, "$MODULE",6) == 0 ) break;
			if( strnicmp( Line,"$INDEX",6) == 0 )
			{
				while( GetLine(lib_module,Line, &LineNum) )
				{
					if( strnicmp( Line,"$EndINDEX",9) == 0 ) break;
					StrPurge(Line);
					msg = CONV_FROM_UTF8(Line);
					if( msg.CmpNoCase(ComponentName) == 0 )
					{
						Found = 1; break; /* Trouve! */
					}
				}
			}
		}

		/* Lecture de la librairie */
		while( Found && GetLine(lib_module,Line, &LineNum) )
		{
			if( Line[0] != '$' ) continue;
			if( Line[1] != 'M' ) continue;
			if( strnicmp( Line, "$MODULE",7) != 0 ) continue;
			/* Lecture du nom du composant */
			Name = CONV_FROM_UTF8(Line+8);
			if( Name.CmpNoCase(ComponentName) == 0 )  /* composant localise */
			{
				NewModule = new MODULE(m_Pcb);
				NewModule->ReadDescr(lib_module, &LineNum);
				if( Module == NULL )	/* 1er Module */
				{
					m_Pcb->m_Modules = NewModule;
					NewModule->Pback = m_Pcb;
				}

				else
				{
					Module->Pnext = NewModule;
					NewModule->Pback = Module;
				}
				fclose(lib_module) ;
				Affiche_Message(wxEmptyString) ;
				return(NewModule) ;
			}
		}
		fclose(lib_module) ; lib_module = 0;
	}

	if( lib_module ) fclose(lib_module) ;

	if ( show_msg_err )
	{
		msg.Printf(_("Module <%s> not found"),ComponentName.GetData());
		DisplayError(winaff, msg);
	}
	return(NULL) ;
}
コード例 #11
0
ファイル: find.cpp プロジェクト: BackupTheBerlios/kicad-svn
EDA_BaseStruct * WinEDA_SchematicFrame::FindSchematicItem(
			const wxString & pattern, int SearchType)
/************************************************************************/
/* Find a string in schematic.
	Search is made in current sheet (SearchType = 0),
	or the whole hierarchy (SearchType = 1),
	or for the next item  (SearchType = 2).
	Mouse cursor is put on item
*/
{
SCH_SCREEN * Screen, * FirstScreen = NULL;
EDA_BaseStruct *DrawList = NULL, *FirstStruct = NULL, *Struct = NULL;
int NotFound, StartCount, ii, jj;
wxPoint firstpos, pos;
static int FindAll;
wxSize size = DrawPanel->GetClientSize();
wxPoint curpos;
bool force_recadre = FALSE;
wxString msg, WildText;
	
	g_LastSearchIsMarker = FALSE;
	
	Screen = ScreenSch;
	if( SearchType == 0 )
	{
		s_OldStringFound = pattern;
		Screen = (SCH_SCREEN*) m_CurrentScreen; FindAll = FALSE;
	}
	
	if( SearchType == 1 )
	{
		s_OldStringFound = pattern;
		FindAll = TRUE;
	}

	if(  SearchType != 2  ) ItemsCount = 0;

	WildText = s_OldStringFound;
	NotFound = 1; StartCount = 0;
	
	for ( ; Screen != NULL; Screen = Screen->Next() )
	{
		DrawList = Screen->EEDrawList;
		while ( DrawList )
		{
			switch (DrawList->m_StructType)
			{
				case DRAW_LIB_ITEM_STRUCT_TYPE :
					#undef STRUCT
					#define STRUCT ((EDA_SchComponentStruct*)DrawList)
					if( WildCompareString( WildText, STRUCT->m_Field[REFERENCE].m_Text, FALSE ) )
					{
						NotFound = 0;
						pos = STRUCT->m_Field[REFERENCE].m_Pos;
						break;
					}
					if( WildCompareString( WildText, STRUCT->m_Field[VALUE].m_Text, FALSE ) )
					{
						NotFound = 0;
						pos = STRUCT->m_Field[VALUE].m_Pos;
					}
					break;

				case DRAW_LABEL_STRUCT_TYPE :
				case DRAW_GLOBAL_LABEL_STRUCT_TYPE :
				case DRAW_TEXT_STRUCT_TYPE :
					#undef STRUCT
					#define STRUCT ((DrawTextStruct*)DrawList)
					if( WildCompareString( WildText, STRUCT->m_Text, FALSE ) )
					{
						NotFound = 0;
						pos = STRUCT->m_Pos;
					}
					break;

				default:
					break;
			}

			if(NotFound == 0)	/* Element trouve */
			{
				if ( FirstScreen == NULL )	/* 1er element trouve */
				{
					FirstScreen = Screen; firstpos = pos;
					FirstStruct = DrawList;
				}

				StartCount++;
				if( ItemsCount >= StartCount )
				{
					NotFound = 1;	/* Continue recherche de l'element suivant */
				}
				else
				{
					Struct = DrawList; ItemsCount++; break ;
				}
			}
			if( NotFound == 0 ) break;
			DrawList = DrawList->Pnext;
		}
		if( NotFound == 0 ) break;
		if( FindAll == FALSE ) break;
	}

	if( NotFound && FirstScreen )
	{
		NotFound = 0; Screen = FirstScreen; Struct = FirstStruct;
		pos = firstpos; ItemsCount = 1;
	}

	if( NotFound == 0)
	{
		if ( Screen != GetScreen() )
		{
			Screen->SetZoom(GetScreen()->GetZoom() );
			m_CurrentScreen = ActiveScreen = Screen;
			force_recadre = TRUE;
		}

		/* Si la struct localisee est du type DRAW_LIB_ITEM_STRUCT_TYPE,
			Les coordonnes sont a recalculer en fonction de la matrice
			d'orientation */
		if( Struct->m_StructType == DRAW_LIB_ITEM_STRUCT_TYPE )
		{
			#undef STRUCT
			#define STRUCT ((EDA_SchComponentStruct*)Struct)
			pos.x -= STRUCT->m_Pos.x; pos.y -= STRUCT->m_Pos.y;
			ii = STRUCT->m_Transform[0][0] * pos.x + STRUCT->m_Transform[0][1] * pos.y;
			jj = STRUCT->m_Transform[1][0] * pos.x + STRUCT->m_Transform[1][1] * pos.y;
			pos.x = ii + STRUCT->m_Pos.x; pos.y = jj + STRUCT->m_Pos.y;
		}

		Screen->m_Curseur = pos;
		curpos = DrawPanel->CursorScreenPosition();
		DrawPanel->GetViewStart(&m_CurrentScreen->m_StartVisu.x,
								&m_CurrentScreen->m_StartVisu.y);

		// calcul des coord curseur avec origine = screen
		curpos.x -= m_CurrentScreen->m_StartVisu.x;
		curpos.y -= m_CurrentScreen->m_StartVisu.y;

		/* Il y a peut-etre necessite de recadrer le dessin: */
		if( (curpos.x <= 0) || (curpos.x >= size.x-1) ||
			(curpos.y <= 0) || (curpos.y >= size.y) || force_recadre )
		{
			Recadre_Trace(TRUE);
		}
		else
		{
			GRMouseWarp(DrawPanel, curpos );
		}

		msg = WildText + _(" Found in ") + Screen->m_FileName;
		Affiche_Message(msg);
	}

	else
	{
		Affiche_Message(wxEmptyString);
		msg = WildText + _(" Not Found");
		DisplayError(this,msg, 10);
	}
	
	return DrawList;
}
コード例 #12
0
ファイル: find.cpp プロジェクト: BackupTheBerlios/kicad-svn
EDA_BaseStruct * WinEDA_SchematicFrame::FindMarker(int SearchType)
/*****************************************************************/
/* Search de markers in whole the hierarchy.
	Mouse cursor is put on the marker
	SearchType = 0: searche th first marker, else search next marker
*/
{
SCH_SCREEN * Screen, * FirstScreen = NULL;
EDA_BaseStruct *DrawList, *FirstStruct = NULL, *Struct = NULL;
DrawMarkerStruct * Marker = NULL;
int NotFound, StartCount;
wxPoint firstpos, pos;
wxSize size = DrawPanel->GetClientSize();
wxPoint curpos;
bool force_recadre = FALSE;
wxString msg, WildText;
	
	g_LastSearchIsMarker = TRUE;
	Screen = ScreenSch;
	if( SearchType == 0 ) MarkerCount = 0;

	NotFound = TRUE; StartCount = 0;
	for ( ; Screen != NULL; Screen = Screen->Next() )
	{
		DrawList = Screen->EEDrawList;
		while ( DrawList && NotFound )
		{
			if(DrawList->m_StructType == DRAW_MARKER_STRUCT_TYPE )
			{
			Marker = (DrawMarkerStruct *) DrawList;
				NotFound = FALSE;
				pos = Marker->m_Pos;
				if ( FirstScreen == NULL )	/* First item found */
				{
					FirstScreen = Screen; firstpos = pos;
					FirstStruct = DrawList;
				}
	
				StartCount++;
				if( MarkerCount >= StartCount )
				{
					NotFound = TRUE;	/* Search for the next item */
				}
				else
				{
					Struct = DrawList; MarkerCount++; break ;
				}
			}
			DrawList = DrawList->Pnext;
		}
		if( NotFound == FALSE ) break;
	}

	if( NotFound && FirstScreen )
	{
		NotFound = 0; Screen = FirstScreen; Struct = FirstStruct;
		pos = firstpos; MarkerCount = 1;
	}

	if( NotFound == 0)
	{
		if ( Screen != GetScreen() )
		{
			Screen->SetZoom(GetScreen()->GetZoom() );
			m_CurrentScreen = ActiveScreen = Screen;
			force_recadre = TRUE;
		}

		Screen->m_Curseur = pos;
		curpos = DrawPanel->CursorScreenPosition();
		DrawPanel->GetViewStart(&m_CurrentScreen->m_StartVisu.x,
								&m_CurrentScreen->m_StartVisu.y);

		// calcul des coord curseur avec origine = screen
		curpos.x -= m_CurrentScreen->m_StartVisu.x;
		curpos.y -= m_CurrentScreen->m_StartVisu.y;

		/* Il y a peut-etre necessite de recadrer le dessin: */
		if( (curpos.x <= 0) || (curpos.x >= size.x-1) ||
			(curpos.y <= 0) || (curpos.y >= size.y) || force_recadre )
		{
			Recadre_Trace(TRUE);
		}
		else
		{
			GRMouseWarp(DrawPanel, curpos );
		}

		msg = _("Marker found in ") + Screen->m_FileName;
		Affiche_Message(msg);
	}

	else
	{
		Affiche_Message(wxEmptyString);
		msg = _("Marker Not Found");
		DisplayError(NULL,msg, 10);
	}
	
	return Marker;
}
コード例 #13
0
int WinEDA_BasePcbFrame::Save_1_Module(const wxString & LibName,
			MODULE* Module, bool Overwrite, bool DisplayDialog)
/*****************************************************************/
/*
	sauve en Librairie le module Module:
	si no_replace == TRUE, s'il est nouveau.

	retourne
		1 si OK
		0 si abort ou probleme
*/
{
int newmodule, end;
int LineNum = 0, tmp;
char Name[256], Line[1024];
wxString Name_Cmp;
wxString NewLib, OldLib, msg;
FILE * lib_module, *dest;
bool added = TRUE;
	
	Module->Display_Infos(this);

	if ( ! wxFileExists(LibName) )
	{
		msg.Printf( _("Library %s not found"), LibName.GetData());
		DisplayError(this, msg);
		return 0;
	}


	/* Demande du nom du composant en librairie */
	Name_Cmp = Module->m_LibRef;

	if( DisplayDialog )
	{
		Get_Message(_("Name:"), Name_Cmp, this ) ;
		if( Name_Cmp.IsEmpty() ) return(0);
		Name_Cmp.Trim(TRUE);
		Name_Cmp.Trim(FALSE);
		Module->m_LibRef = Name_Cmp;
	}

	if ((lib_module = wxFopen(LibName, wxT("rt"))) == NULL )
	{
		msg.Printf( _("Unable to open %s"), LibName.GetData());
		DisplayError(this, msg);
		return 0;
	}

	/* lecture entete : ENTETE_LIBRAIRIE */
	GetLine(lib_module, Line, &LineNum) ;
	if(strnicmp( Line,ENTETE_LIBRAIRIE, L_ENTETE_LIB) != 0)
	{
		fclose(lib_module) ;
		msg.Printf( _("File %s is not a eeschema library"), LibName.GetData());
		DisplayError(this, msg);
		return(0);
	}

	/* lecture des noms des composants - verif si le module est deja existant */
	newmodule = 1; end = 0;
	while( !end && GetLine(lib_module, Line, &LineNum) )
	{
		if( Line[0] != '$' ) continue;
		if( strncmp( Line+1, "INDEX",5) != 0 ) continue;

		 while( GetLine(lib_module, Line, &LineNum) )
		{
			if( strncmp( Line, "$EndINDEX",9) == 0 )
			{
				end = 1; break;
			}

			StrPurge(Line);
			msg = CONV_FROM_UTF8(Line);
			if( Name_Cmp.CmpNoCase(msg) == 0) /* composant trouve */
			{
				added = FALSE;
				newmodule = 0;
				if( DisplayDialog )
				{
					msg = _("Module exists Line ");
					msg << LineNum;
					Affiche_Message(msg) ;
				}
				if( ! Overwrite)	/* le module n'est pas a sauver car deja existant */
				{
					fclose(lib_module); return(1);
				}
				end = 1; break;
			}
		}
	}
	fclose(lib_module);

	/* Creation de la nouvelle librairie */

	if ((lib_module = wxFopen(LibName, wxT("rt")))  == NULL )
	{
		DisplayError(this, wxT("Librairi.cpp: Error oldlib not found"));
		return(0);
	}

	NewLib = LibName;
	ChangeFileNameExt(NewLib, FILETMP_EXT);
	if ((dest = wxFopen(NewLib, wxT("w+t")))  == NULL ) 
		{
		fclose(lib_module) ;
		msg = _("Unable to create ") + NewLib;
		DisplayError(this, msg);
		return(0);
		}
 
wxBeginBusyCursor() ;

	/* Creation de l'entete avec nouvelle date */
	fprintf(dest,ENTETE_LIBRAIRIE);
	fprintf(dest,"  %s\n$INDEX\n", DateAndTime(Line) );

	LineNum = 0;
	GetLine(lib_module, Line, &LineNum);
	while(GetLine(lib_module,Line, &LineNum))
	{
		StrPurge(Line);
		if ( strnicmp(Line,"$M",2 ) == 0 ) break;
		if ( strnicmp(Line,"$INDEX",6 ) == 0 )
		{
			while(GetLine(lib_module,Line, &LineNum))
			{
				if ( strnicmp(Line,"$EndINDEX",9 ) == 0 ) break;
				fprintf(dest,"%s\n",Line);
			}
		}
		if(newmodule) fprintf(dest,"%s\n",CONV_TO_UTF8(Name_Cmp) );
		if ( strnicmp(Line,"$EndINDEX",0 ) == 0 ) break;
	}

	fprintf(dest,"$EndINDEX\n");

	/* Copie des modules, jusqu'au module a supprimer */
	while( GetLine(lib_module, Line, &LineNum) )
		{
		StrPurge(Line);
		if( strnicmp( Line, "$EndLIBRARY", 8) == 0 ) continue;
		if( strnicmp( Line, "$MODULE", 7) == 0 )
			{
			sscanf(Line+7," %s", Name);
			msg = CONV_FROM_UTF8(Name);
			if( msg.CmpNoCase(Name_Cmp) == 0 )
				{
				/* suppression ancien module */
				while( GetLine(lib_module, Line, &LineNum) )
					{
					if( strnicmp( Line, "$EndMODULE", 9) == 0 ) break;
					}
				continue;
				}
			}
		fprintf(dest,"%s\n",Line);
		}

	/* Ecriture du module ( en fin de librairie ) */
	tmp = Module->m_TimeStamp; Module->m_TimeStamp = 0;
	Module->WriteDescr(dest);
	fprintf(dest,"$EndLIBRARY\n");
	Module->m_TimeStamp = tmp;

	fclose(dest) ;	fclose(lib_module) ;

wxEndBusyCursor() ;

	/* L'ancien fichier librairie est renomme en .bak */
	OldLib = LibName;
	ChangeFileNameExt ( OldLib, OLD_EXT);

	if( wxFileExists(OldLib) ) wxRemoveFile(OldLib);

	if ( ! wxRenameFile(LibName, OldLib ) )
		DisplayError(this, wxT("Librairi.cpp: rename .bak err") );

	/* Le nouveau fichier librairie est renomme */
	if ( ! wxRenameFile(NewLib,LibName) )
	{
		DisplayError(this, wxT("Librairi.cpp: rename NewLib err") );
		return(0);
	}

	CreateDocLibrary(OldLib);

	if ( DisplayDialog )
	{
		msg = _("Component ") ; msg += Name_Cmp;
		msg += added ? _(" added in ") : _(" replaced in ");
		msg += LibName;
		Affiche_Message(msg);
	}

	return(1);
}
コード例 #14
0
void WinEDA_ModuleEditFrame::Delete_Module_In_Library(const
		wxString & libname)
/**********************************************************/
{
int ii, NoFound = 1, LineNum = 0;
char Line[1024], Name[256];
wxString NewLib, OldLib;
FILE * dest, * lib_module;
wxString CmpName, msg;

	/* Demande du nom du composant a supprimer */
	CmpName = Select_1_Module_From_List( this, libname, wxEmptyString, wxEmptyString );
	if( CmpName == wxEmptyString )	return;

	/* Confirmation */
	msg.Printf( _("Ok to delete module %s in library %s"),
				CmpName.GetData(), libname.GetData() );
	if( !IsOK(this, msg) ) return;

	OldLib = libname;

	if ((lib_module = wxFopen( OldLib, wxT("rt")))  == NULL )
	{
		wxString msg;
		msg = _("Library ") + OldLib + _(" not found");
		DisplayError(this, msg);
		return;
	}


	/* lecture entete */
	GetLine(lib_module,Line, &LineNum) ;

	if(strnicmp( Line,ENTETE_LIBRAIRIE, L_ENTETE_LIB) != 0)
	{
		DisplayError(this, _("Not a Library file"));
		fclose(lib_module);
		return;
	}

	/* lecture des nom des composants  */
	while( GetLine(lib_module, Line, &LineNum) )
	{
		if( strnicmp( Line, "$INDEX",6) == 0 )
		{
			while( GetLine(lib_module, Line, &LineNum) )
			{
				StrPurge(Line);
				msg = CONV_FROM_UTF8(Line);
				if( CmpName.CmpNoCase(msg) == 0) /* composant trouve */
				{
					NoFound = 0; break;
				}
				if( strnicmp( Line, "$EndINDEX",9) == 0 ) break;
			}
		}
		if( strnicmp( Line, "$EndINDEX",9) == 0 ) break;
	}

	if( NoFound )
	{
		fclose(lib_module);
		msg.Printf( _("Module [%s] not found"), CmpName.GetData() );
		DisplayError(this, msg);
		return ;
	}

	/* Creation de la nouvelle librairie */
	NewLib = OldLib;
	ChangeFileNameExt(NewLib,FILETMP_EXT);
	if ((dest = wxFopen(NewLib, wxT("wt") )) == NULL ) 
		{
		fclose(lib_module) ;
		wxString msg;
		msg = _("Unable to create ") + NewLib;
		DisplayError(this, msg);
		return;
		}

wxBeginBusyCursor();

	/* Creation de l'entete avec nouvelle date */
	fprintf(dest,ENTETE_LIBRAIRIE);
	fprintf(dest,"  %s\n$INDEX\n", DateAndTime(Line) );

	fseek(lib_module,0,0); GetLine(lib_module, Line, &ii);
	while(GetLine(lib_module,Line, &ii))
	{
		if ( strnicmp(Line,"$M",2 ) == 0 ) break;
		if ( strnicmp(Line,"$INDEX",6 ) == 0 )
		{
			while(GetLine(lib_module,Line, &ii))
			{
				if ( strnicmp(Line,"$EndINDEX",9 ) == 0 ) break;
				StrPurge(Line);
				msg = CONV_FROM_UTF8(Line);
				if( CmpName.CmpNoCase(msg) != 0 )
					 fprintf(dest,"%s\n",Line);
			}
		}
		if ( strnicmp(Line,"$EndINDEX",9 ) == 0 ) break;
	}

	fprintf(dest,"$EndINDEX\n");

	/* Copie des modules */
	while( GetLine(lib_module, Line, &LineNum) )
	{
		StrPurge(Line);
		if( strnicmp( Line, "$MODULE", 7) == 0 )
		{
			sscanf(Line+7," %s", Name);
			msg = CONV_FROM_UTF8(Name);
			if( msg.CmpNoCase(CmpName) == 0 )
			{
				/* suppression ancien module */
				while( GetLine(lib_module, Line, &LineNum) )
				{
					if( strnicmp( Line, "$EndMODULE", 9) == 0 ) break;
				}
				continue;
			}
		}
		fprintf(dest, "%s\n", Line);
	}

	fclose(lib_module);
	fclose(dest) ;

wxEndBusyCursor();

	/* Le fichier ancienne librairie est renommee en .bak */
wxString BakFilename = OldLib;
	ChangeFileNameExt( BakFilename, OLD_EXT);

	if( wxFileExists(BakFilename) ) wxRemoveFile(BakFilename);

	if( ! wxRenameFile(OldLib, BakFilename) )
	{
		DisplayError(this, wxT("Librairi.cpp: rename .bak err"));
		return;
	}

	/* Le fichier temporaire est renommee comme l'ancienne Lib */
	if( ! wxRenameFile(NewLib,OldLib) )
	{
		DisplayError(this, wxT("Librairi.cpp: rename err 2") );
		return;
	}

	msg.Printf( _("Component %s deleted in library %s"), CmpName.GetData(), OldLib.GetData() ) ;
	Affiche_Message(msg) ;

	CreateDocLibrary(OldLib);
}