menucfg.cpp 9.17 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
	/***************************************/
	/** menucfg : configuration de CVPCB  **/
	/***************************************/

/* cree et/ou affiche et modifie la configuration de CVPCB */

// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"

#ifdef __BORLANDC__
#pragma hdrstop
#endif

// for all others, include the necessary headers (this file is usually all you
// need because it includes almost all "standard" wxWindows headers
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif

#include "fctsys.h"
#include "common.h"

#include "cvpcb.h"
#include "protos.h"


/* Routines Locales */


	/*****************************************/
	/* classe pour la frame de Configuration */
	/*****************************************/
#include "dialog_cvpcb_config.cpp"



/***************************************************/
38
void WinEDA_CvpcbFrame::CreateConfigWindow()
39 40 41 42 43 44 45 46 47
/***************************************************/
/* Creation de la fenetre de configuration de CVPCB */
{
KiConfigCvpcbFrame * ConfigFrame = new KiConfigCvpcbFrame(this);
	ConfigFrame->ShowModal(); ConfigFrame->Destroy();
}


/*********************************************/
48
void KiConfigCvpcbFrame::SetDialogDatas()
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
/*********************************************/
{
	m_ListLibr->InsertItems(g_LibName_List,0);
	m_ListEquiv->InsertItems(g_ListName_Equ,0);

	switch( g_NetType )
	{
		case TYPE_NON_SPECIFIE:
		case TYPE_ORCADPCB2:
			m_NetFormatBox->SetSelection(0);
			break;

		case TYPE_PCAD:
			break;

		case TYPE_VIEWLOGIC_WIR:
			m_NetFormatBox->SetSelection(1);
			break;

		case TYPE_VIEWLOGIC_NET:
			m_NetFormatBox->SetSelection(2);
			break;

		default:
			break;
	}

	m_LibDirCtrl = new WinEDA_EnterText(this,
				_("Lib Dir:"), g_UserLibDirBuffer,
				m_RightBoxSizer, wxDefaultSize);

	m_NetInputExtCtrl = new WinEDA_EnterText(this,
				_("Net Input Ext:"),NetInExtBuffer,
				m_NetExtBoxSizer, wxDefaultSize);

	m_PkgExtCtrl = new WinEDA_EnterText(this,
				_("Pkg Ext:"), PkgInExtBuffer,
				m_PkgExtBoxSizer, wxDefaultSize);
				
	wxString DocModuleFileName =
89
		g_EDA_Appl->m_EDA_CommonConfig->Read( wxT("module_doc_file"), wxT("pcbnew/footprints.pdf"));
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
	m_TextHelpModulesFileName = new WinEDA_EnterText(this,
				_("Module Doc File:"),  DocModuleFileName,
				m_RightBoxSizer, wxDefaultSize);

	/* Create info on Files ext */
	wxStaticText * StaticText;
	wxString text;
	text.Printf( wxT("%s     %s"), _("Cmp ext:"), g_ExtCmpBuffer.GetData() );
	StaticText = new wxStaticText(this, -1,text);
	m_FileExtList->Add(StaticText, wxGROW|wxLEFT|wxRIGHT|wxTOP|wxBOTTOM|wxADJUST_MINSIZE);

	text.Printf( wxT("%s      %s"), _("Lib ext:"), LibExtBuffer.GetData());
	StaticText = new wxStaticText(this, -1,text);
	m_FileExtList->Add(StaticText, wxGROW|wxLEFT|wxRIGHT|wxTOP|wxBOTTOM|wxADJUST_MINSIZE);

	text.Printf( wxT("%s %s"), _("NetOut ext:"), NetExtBuffer.GetData());
	StaticText = new wxStaticText(this, -1,text);
	m_FileExtList->Add(StaticText, wxGROW|wxLEFT|wxRIGHT|wxTOP|wxBOTTOM|wxADJUST_MINSIZE);

	text.Printf( wxT("%s  %s"), _("Equiv ext:"), g_EquivExtBuffer.GetData());
	StaticText = new wxStaticText(this, -1,text);
	m_FileExtList->Add(StaticText, wxGROW|wxLEFT|wxRIGHT|wxTOP|wxBOTTOM|wxADJUST_MINSIZE);

	text.Printf( wxT("%s  %s"), _("Retro ext:"), ExtRetroBuffer.GetData());
	StaticText = new wxStaticText(this, -1,text);
	m_FileExtList->Add(StaticText, wxGROW|wxLEFT|wxRIGHT|wxTOP|wxBOTTOM|wxADJUST_MINSIZE);
}

/********************************************************/
void KiConfigCvpcbFrame::AcceptCfg(wxCommandEvent& event)
/********************************************************/
{
	Update();
	Close();
}

/**********************************/
127
void KiConfigCvpcbFrame::Update()
128 129 130 131 132 133 134
/**********************************/
{
wxString msg;
	
	if ( ! m_DoUpdate ) return;
	NetInExtBuffer = m_NetInputExtCtrl->GetValue();
	PkgInExtBuffer = m_PkgExtCtrl->GetValue();
135
	g_EDA_Appl->m_EDA_CommonConfig->Write( wxT("module_doc_file"),
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
			m_TextHelpModulesFileName->GetValue());

	msg = m_LibDirCtrl->GetValue();
	if ( msg != g_UserLibDirBuffer )
	{
		g_UserLibDirBuffer = m_LibDirCtrl->GetValue();
		SetRealLibraryPath( wxT("modules") );
		listlib();
		ListModIsModified = 1;
		m_Parent->BuildFootprintListBox();
	}
}


/****************************************************/
void KiConfigCvpcbFrame::SaveCfg(wxCommandEvent& event)
/****************************************************/
{
	Update();
	Save_Config(this);
}

/******************************************************/
void KiConfigCvpcbFrame::ReadOldCfg(wxCommandEvent& event)
/******************************************************/
{
wxString line;

	NetInNameBuffer.Replace(WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP);
	
wxString FullFileName = NetInNameBuffer.AfterLast('/');
	
	ChangeFileNameExt( FullFileName, g_Prj_Config_Filename_ext );

	FullFileName = EDA_FileSelector(_("Read config file"),
					wxGetCwd(),					/* Chemin par defaut */
					FullFileName,		/* nom fichier par defaut */
					g_Prj_Config_Filename_ext,				/* extension par defaut */
					FullFileName,				/* Masque d'affichage */
					this,
					wxFD_OPEN,
					TRUE				/* ne change pas de repertoire courant */
					);
	if ( FullFileName.IsEmpty() ) return;
	if ( ! wxFileExists(FullFileName) )
	{
		line.Printf( _("File %s not found"), FullFileName.GetData());
		DisplayError(this, line); return;
	}

	Read_Config( FullFileName );
	m_DoUpdate = FALSE;
	Close(TRUE);
}


/*******************************************************/
void KiConfigCvpcbFrame::LibDelFct(wxCommandEvent& event)
/*******************************************************/
{
int ii;
	
	ii = m_ListLibr->GetSelection();
	if ( ii < 0 ) return;

	ListModIsModified = 1;
	g_LibName_List.RemoveAt(ii);

	/* suppression de la reference dans la liste des librairies */
	m_ListLibr->Delete(ii);
	
	g_UserLibDirBuffer = m_LibDirCtrl->GetValue();
	SetRealLibraryPath( wxT("modules") );
	listlib();

	m_Parent->BuildFootprintListBox();

}

/********************************************************/
void KiConfigCvpcbFrame::LibAddFct(wxCommandEvent& event)
/********************************************************/
{
int ii;
wxString FullFileName, ShortLibName, mask;

	ii = m_ListLibr->GetSelection();
	if ( event.GetId() == ADD_LIB )	/* Ajout apres selection */
		{
		ii ++;
		}
	if ( ii < 0 ) ii = 0;

	Update();
	mask = wxT("*") + LibExtBuffer;

CHARRAS's avatar
CHARRAS committed
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
	wxFileDialog FilesDialog(this, _("Library Files:"), g_RealLibDirBuffer,
		wxEmptyString, mask,
		wxFD_DEFAULT_STYLE | wxFD_MULTIPLE);

	FilesDialog.ShowModal();
	wxArrayString Filenames;
	FilesDialog.GetFilenames(Filenames);
	
	if ( Filenames.GetCount() == 0 )
		return;

	for ( unsigned jj = 0; jj < Filenames.GetCount(); jj ++ )
	{
		FullFileName = Filenames[jj];
		ShortLibName = MakeReducedFileName(FullFileName,g_RealLibDirBuffer,LibExtBuffer);
247

CHARRAS's avatar
CHARRAS committed
248 249 250 251 252 253 254 255 256 257 258 259 260
		//Add or insert new library name
		if ( g_LibName_List.Index(ShortLibName) == wxNOT_FOUND)
		{
			ListModIsModified = 1;
			g_LibName_List.Insert(ShortLibName, ii++);
		}
		else
		{
			wxString msg;
			msg << wxT("<") << ShortLibName << wxT("> : ") << _("Library already in use");
			DisplayError(this, msg);
		}
	}
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
	
	g_UserLibDirBuffer = m_LibDirCtrl->GetValue();
	SetRealLibraryPath( wxT("modules") );
	listlib();

	m_Parent->BuildFootprintListBox();

	m_ListLibr->Clear();
	m_ListLibr->InsertItems(g_LibName_List, 0);

}


/********************************************************/
void KiConfigCvpcbFrame::EquDelFct(wxCommandEvent& event)
/********************************************************/
{
int ii;

	ii = m_ListEquiv->GetSelection();
	if ( ii < 0 ) return;

	g_ListName_Equ.RemoveAt(ii);
	m_ListEquiv->Delete(ii);
}

/********************************************************/
void KiConfigCvpcbFrame::EquAddFct(wxCommandEvent& event)
/********************************************************/
{
int ii;
wxString FullFileName, ShortLibName, mask;

	ii = m_ListEquiv->GetSelection();
	if ( event.GetId() == ADD_EQU ) ii ++;	/* Ajout apres selection */
	if ( ii < 0 ) ii = 0;

	Update();
	mask = wxT("*") + g_EquivExtBuffer;

CHARRAS's avatar
CHARRAS committed
301 302 303
	wxFileDialog FilesDialog(this, _("Equiv Files:"), g_RealLibDirBuffer,
		wxEmptyString, mask,
		wxFD_DEFAULT_STYLE | wxFD_MULTIPLE);
304

CHARRAS's avatar
CHARRAS committed
305 306 307 308 309 310 311 312 313 314 315
	FilesDialog.ShowModal();
	wxArrayString Filenames;
	FilesDialog.GetFilenames(Filenames);
	
	if ( Filenames.GetCount() == 0 )
		return;

	for ( unsigned jj = 0; jj < Filenames.GetCount(); jj ++ )
	{
		FullFileName = Filenames[jj];
		ShortLibName = MakeReducedFileName(FullFileName,g_RealLibDirBuffer,g_EquivExtBuffer);
316

CHARRAS's avatar
CHARRAS committed
317 318 319 320 321 322 323 324 325 326 327 328
		//Add or insert new equiv library name
		if ( g_ListName_Equ.Index(ShortLibName) == wxNOT_FOUND)
		{
			g_ListName_Equ.Insert(ShortLibName, ii++);
		}
		else
		{
			wxString msg;
			msg << wxT("<") << ShortLibName << wxT("> : ") << _("Library already in use");
			DisplayError(this, msg);
		}
	}
329

CHARRAS's avatar
CHARRAS committed
330
	/* Update display list */
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354
	g_UserLibDirBuffer = m_LibDirCtrl->GetValue();
	SetRealLibraryPath( wxT("modules") );
	listlib();
	
	m_ListEquiv->Clear();
	m_ListEquiv->InsertItems(g_ListName_Equ, 0);
}




/*****************************************************************/
void KiConfigCvpcbFrame::ReturnNetFormat(wxCommandEvent& event)
/*****************************************************************/
{
int ii;

	ii = m_NetFormatBox->GetSelection();
	g_NetType = TYPE_ORCADPCB2;
	if ( ii == 1 ) g_NetType = TYPE_VIEWLOGIC_WIR;
	if ( ii == 2 ) g_NetType = TYPE_VIEWLOGIC_NET;

}