Example #1
0
NORETURN(void wxrubyAssert(const wxString& file,
                                  int line,
                                  const wxString& func,
                                  const wxString& cond,
                                  const wxString& msg)
{
	rb_fatal("(%s) in %s \n %s",
		cond.GetData().AsChar(),
		func.GetData().AsChar(),
		msg.GetData().AsChar()
		);
})
Example #2
0
void PARSE_ERROR::init( const char* aThrowersFile, const char* aThrowersLoc,
           const wxString& aMsg, const wxString& aSource,
           const char* aInputLine,
           int aLineNumber, int aByteIndex )
{
    // save inpuLine, lineNumber, and offset for UI (.e.g. Sweet text editor)
    inputLine  = aInputLine;
    lineNumber = aLineNumber;
    byteIndex  = aByteIndex;

    errorText.Printf( PARSE_FORMAT, aMsg.GetData(), aSource.GetData(),
        aLineNumber, aByteIndex,
        wxString::FromUTF8( aThrowersFile ).GetData(),
        wxString::FromUTF8( aThrowersLoc ).GetData() );
}
Example #3
0
// ----------------------------------------------------------------------------
void SettingsDlg::GetFileName(wxString& newFileName)
// ----------------------------------------------------------------------------
{
    newFileName = wxEmptyString;

    // Ask user for filename
    wxFileDialog dlg(this,                      //parent  window
                 _T("Select file "),             //message
                 wxEmptyString,                 //default directory
                 wxEmptyString,                 //default file
                 wxT("*.*"),                    //wildcards
                 wxFD_OPEN | wxFD_FILE_MUST_EXIST );  //style

   // move dialog into the parents frame space
    wxPoint mousePosn = ::wxGetMousePosition();
    (&dlg)->Move(mousePosn.x, mousePosn.y);

    if (dlg.ShowModal() != wxID_OK) return;
    newFileName = dlg.GetPath();

    #ifdef LOGGING
     LOGIT( _T("New filename[%s]"), newFileName.GetData() );
    #endif //LOGGING;

}
Example #4
0
bool WinEDA_App::OnInit(void)
{
wxString msg;
wxString currCWD = wxGetCwd();

	EDA_Appl = this;
	InitEDA_Appl( wxT("cvpcb") );

    if ( m_Checker && m_Checker->IsAnotherRunning() ) 
    { 
        if ( ! IsOK(NULL, _("Cvpcb is already running, Continue?") ) )
			return false; 
    }
	
	GetSettings();					// read current setup

	wxSetWorkingDirectory(currCWD); // mofifie par GetSetting
	SetRealLibraryPath( wxT("modules") );

	if(argc > 1 )
		{
		NetInNameBuffer = argv[1];
		NetNameBuffer = argv[1];
		}

	if ( ! NetInNameBuffer.IsEmpty() )
		wxSetWorkingDirectory( wxPathOnly(NetInNameBuffer) );
	g_DrawBgColor = BLACK;

	Read_Config(NetInNameBuffer);

	m_CvpcbFrame = new WinEDA_CvpcbFrame(this, Main_Title);

	msg.Printf( wxT("Modules: %d"), nblib);
	m_CvpcbFrame->SetStatusText(msg,2);

	// Show the frame
	SetTopWindow(m_CvpcbFrame);

	m_CvpcbFrame->Show(TRUE);

	listlib();
	m_CvpcbFrame->BuildModListBox();

	if( ! NetInNameBuffer.IsEmpty() ) /* nom de fichier passe a la commande */
		{
		FFileName = MakeFileName(NetDirBuffer,
							NetInNameBuffer, NetInExtBuffer);

		m_CvpcbFrame->ReadNetListe();
		}
	else		/* Mise a jour du titre de la fenetre principale */
		{
 		msg.Printf( wxT("%s {%s%c} [no file]"),
			Main_Title.GetData(), wxGetCwd().GetData(), DIR_SEP);
		m_CvpcbFrame->SetTitle(msg);
		}

  return TRUE;
}
Example #5
0
ViewFrame::ViewFrame(const wxString& filepath)
    : wxFrame(NULL, wxID_ANY, filepath, wxDefaultPosition, wxSize(250, 150))
{
    frozen = false;

    wxMenuBar* menubar = new wxMenuBar();
    wxMenu* filemenu = new wxMenu();

    filemenu->Append(wxID_OPEN, "Open\tCtrl-O");
    filemenu->Append(wxID_CLOSE, "Close Window\tCtrl-W");
    filemenu->Append(wxID_EXIT, "Quit\tCtrl-Q");
    menubar->Append(filemenu, "File");

    SetMenuBar(menubar);

    MarkdownRenderer renderer;

    viewer = wxWebView::New(this, wxID_ANY);
    if(!renderer.render(filepath.GetData())) {
        std::cerr << renderer.getErrMsg() << std::endl;
        return;
    }
    viewer->SetPage(renderer.getData(), filepath);
    frozen = true;

    Centre();

    Show(true);
}
void NETLIST_EXPORTER::sprintPinNetName( wxString& aResult,
                                    const wxString& aNetNameFormat, NETLIST_OBJECT* aPin,
                                    bool aUseNetcodeAsNetName )
{
    int netcode = aPin->GetNet();

    // Not wxString::Clear(), which would free memory.  We want the worst
    // case wxString memory to grow to avoid reallocation from within the
    // caller's loop.
    aResult.Empty();

    if( netcode != 0 && aPin->GetConnectionType() == PAD_CONNECT )
    {
        if( aUseNetcodeAsNetName )
        {
            aResult.Printf( wxT("%d"), netcode );
        }
        else
        {
        aResult = aPin->GetNetName();

        if( aResult.IsEmpty() )     // No net name: give a name from net code
            aResult.Printf( aNetNameFormat.GetData(), netcode );
        }
    }
}
Example #7
0
bool Tokenizer::GetActualContextForMacro(Token* tk, wxString& actualContext)
{
    // e.g. "#define AAA AAA" and usage "AAA(x)"
    if (!tk || tk->m_Name == tk->m_Type)
        return false;

    // 1. break the args into substring with ","
    wxArrayString formalArgs;
    if (ReplaceBufferForReparse(tk->m_Args, false))
        SpliteArguments(formalArgs);

    // 2. splite the actual macro arguments
    wxArrayString actualArgs;
    if (!formalArgs.IsEmpty()) // e.g. #define AAA(x) x \n #define BBB AAA \n BBB(int) variable;
        SpliteArguments(actualArgs);

    // 3. get actual context
    actualContext = tk->m_Type;
    const size_t totalCount = std::min(formalArgs.GetCount(), actualArgs.GetCount());
    for (size_t i = 0; i < totalCount; ++i)
    {
        TRACE(_T("GetActualContextForMacro(): The formal args are '%s' and the actual args are '%s'."),
              formalArgs[i].wx_str(), actualArgs[i].wx_str());

        wxChar* data = const_cast<wxChar*>((const wxChar*)actualContext.GetData());
        const wxChar* dataEnd = data + actualContext.Len();
        const wxChar* target = formalArgs[i].GetData();
        const int targetLen = formalArgs[i].Len();

        wxString alreadyReplaced;
        alreadyReplaced.Alloc(actualContext.Len() * 2);

        while (true)
        {
            const int pos = GetFirstTokenPosition(data, dataEnd - data, target, targetLen);
            if (pos != -1)
            {
                alreadyReplaced << wxString(data, pos) << actualArgs[i];
                data += pos + targetLen;
                if (data == dataEnd)
                    break;
            }
            else
            {
                alreadyReplaced << data;
                break;
            }
        }

        actualContext = alreadyReplaced;
    }

    // 4. erease string "##"
    actualContext.Replace(_T("##"), wxEmptyString);

    TRACE(_T("The replaced actual context are '%s'."), actualContext.wx_str());
    return true;
}
Example #8
0
void IO_ERROR::init( const char* aThrowersFile, const char* aThrowersLoc, const wxString& aMsg )
{
    // The throwers filename is a full filename, depending on Kicad source location.
    // a short filename will be printed (it is better for user, the full filename has no meaning).
    wxString srcname = wxString::FromUTF8( aThrowersFile );

    errorText.Printf( IO_FORMAT, aMsg.GetData(),
        srcname.AfterLast( '/' ).GetData(),
        wxString::FromUTF8( aThrowersLoc ).GetData() );
}
Example #9
0
void PARSE_ERROR::init( const char* aThrowersFile, const char* aThrowersLoc,
           const wxString& aMsg, const wxString& aSource,
           const char* aInputLine,
           int aLineNumber, int aByteIndex )
{
    // save inpuLine, lineNumber, and offset for UI (.e.g. Sweet text editor)
    inputLine  = aInputLine;
    lineNumber = aLineNumber;
    byteIndex  = aByteIndex;

    // The throwers filename is a full filename, depending on Kicad source location.
    // a short filename will be printed (it is better for user, the full filename has no meaning).
    wxString srcname = wxString::FromUTF8( aThrowersFile );

    errorText.Printf( PARSE_FORMAT, aMsg.GetData(), aSource.GetData(),
        aLineNumber, aByteIndex,
        srcname.AfterLast( '/' ).GetData(),
        wxString::FromUTF8( aThrowersLoc ).GetData() );
}
wxSQLite3ResultSet TagsDatabase::SelectTagsByFile(const wxString& file, const wxFileName& path)
{
	// Incase empty file path is provided, use the current file name
	wxFileName databaseFileName(path);
	path.IsOk() == false ? databaseFileName = m_fileName : databaseFileName = path;
	OpenDatabase(databaseFileName);

	wxString query;
	query = wxString::Format(_T("select * from tags where file='%s';"), file.GetData());
	return m_db->ExecuteQuery(query.GetData());
}
// ----------------------------------------------------------------------------
bool SnippetDropTarget::OnDropText(wxCoord x, wxCoord y, const wxString& data)
// ----------------------------------------------------------------------------
{
    // Put dragged text into SnippetTextCtrl
    #ifdef LOGGING
     LOGIT( _T("Dragged Data[%s]"), data.GetData() );
    #endif //LOGGING
    //m_Window->m_SnippetEditCtrl->WriteText(data);
    m_Window->m_SnippetEditCtrl->AddText(data);
    return true;

} // end of OnDropText
wxString NETLIST_EXPORTER::MakeCommandLine( const wxString& aFormatString,
            const wxString& aTempfile, const wxString& aFinalFile, const wxString& aProjectPath )
{
    wxString    ret  = aFormatString;
    wxFileName  in   = aTempfile;
    wxFileName  out  = aFinalFile;

    ret.Replace( wxT( "%P" ), aProjectPath.GetData(), true );
    ret.Replace( wxT( "%B" ), out.GetName().GetData(), true );
    ret.Replace( wxT( "%I" ), in.GetFullPath().GetData(), true );
    ret.Replace( wxT( "%O" ), out.GetFullPath().GetData(), true );

    return ret;
}
Example #13
0
//-----------------------------------------------------------------------------
wxColor Property::StringToColor (wxString strColor)
{
	std::string stdStrColor(strColor.GetData());
	std::string::size_type posK0 = stdStrColor.find_first_of("(");
	std::string::size_type posD0 = stdStrColor.find_first_of(",");
	std::string strRed = stdStrColor.substr(posK0+1, posD0-posK0-1);
	std::string::size_type posD1 = stdStrColor.find_last_of(",");
	std::string::size_type posK1 = stdStrColor.find_first_of(")");
	std::string strGreen = stdStrColor.substr(posD0+1, posD1-posD0-1);
	std::string strBlue = stdStrColor.substr(posD1+1, posK1-posD1);
	int red = atoi(strRed.c_str());
	int green = atoi(strGreen.c_str());
	int blue = atoi(strBlue.c_str());

	return wxColor((unsigned char)red, (unsigned char)green,
		(unsigned char)blue);
}
FILE_LINE_READER::FILE_LINE_READER( const wxString& aFileName,
            unsigned aStartingLineNumber,
            unsigned aMaxLineLength ) throw( IO_ERROR ) :
    LINE_READER( aMaxLineLength ),
    iOwn( true )
{
    fp = wxFopen( aFileName, wxT( "rt" ) );
    if( !fp )
    {
        wxString msg = wxString::Format(
            _( "Unable to open filename '%s' for reading" ), aFileName.GetData() );
        THROW_IO_ERROR( msg );
    }

    source  = aFileName;
    lineNum = aStartingLineNumber;
}
static inline long parseInt( const wxString& aValue, double aScalar )
{
    double value = LONG_MAX;

    /*
     * In 2011 gEDA/pcb introduced values with units, like "10mm" or "200mil".
     * Unit-less values are still centimils (100000 units per inch), like with
     * the previous format.
     *
     * Distinction between the even older format (mils, 1000 units per inch)
     * and the pre-2011 format is done in ::parseMODULE already; the
     * distinction is by wether an object definition opens with '(' or '['.
     * All values with explicite unit open with a '[' so there's no need to
     * consider this distinction when parsing them.
     *
     * The solution here is to watch for a unit and, if present, convert the
     * value to centimils. All unit-less values are read unaltered. This way
     * the code below can contine to consider all read values to be in mils or
     * centimils. It also matches the strategy gEDA/pcb uses for backwards
     * compatibility with its own layouts.
     *
     * Fortunately gEDA/pcb allows only units 'mil' and 'mm' in files, see
     * definition of ALLOW_READABLE in gEDA/pcb's pcb_printf.h. So we don't
     * have to test for all 11 units gEDA/pcb allows in user dialogs.
     */
    if( aValue.EndsWith( wxT( "mm" ) ) )
    {
        aScalar *= 100000.0 / 25.4;
    }
    else if( aValue.EndsWith( wxT( "mil" ) ) )
    {
        aScalar *= 100.;
    }

    // This conversion reports failure on strings as simple as "1000", still
    // it returns the right result in &value. Thus, ignore the return value.
    aValue.ToCDouble(&value);
    if( value == LONG_MAX ) // conversion really failed
    {
        THROW_IO_ERROR( wxString::Format( _( "Cannot convert \"%s\" to an integer" ),
                                          aValue.GetData() ) );
        return 0;
    }

    return KiROUND( value * aScalar );
}
void GPCB_PLUGIN::FootprintDelete( const wxString& aLibraryPath, const wxString& aFootprintName,
                                   const PROPERTIES* aProperties )
{
    LOCALE_IO   toggle;     // toggles on, then off, the C locale.

    init( aProperties );

    cacheLib( aLibraryPath );

    if( !m_cache->IsWritable() )
    {
        THROW_IO_ERROR( wxString::Format( _( "Library '%s' is read only" ),
                                          aLibraryPath.GetData() ) );
    }

    m_cache->Remove( aFootprintName );
}
void GPCB_FPL_CACHE::Remove( const wxString& aFootprintName )
{
    std::string footprintName = TO_UTF8( aFootprintName );

    MODULE_CITER it = m_modules.find( footprintName );

    if( it == m_modules.end() )
    {
        THROW_IO_ERROR( wxString::Format( _( "library <%s> has no footprint '%s' to delete" ),
                                          m_lib_path.GetPath().GetData(),
                                          aFootprintName.GetData() ) );
    }

    // Remove the module from the cache and delete the module file from the library.
    wxString fullPath = it->second->GetFileName().GetFullPath();
    m_modules.erase( footprintName );
    wxRemoveFile( fullPath );
}
Example #18
0
//----------------------------------------------------------------------------------------
bool BrowserDB::OnExecSql(wxString SQLStmt, int Quiet)
{
    //---------------------------------------------------------------------------------------
    if (!db_BrowserDB->ExecSql((wxChar *)(SQLStmt.GetData())))
    {
        Temp0.Printf(_("\n-E-> BrowserDB::OnExecSQL - ODBC-Error with ExecSql of >%s<.\n-E-> "),SQLStmt.c_str());
        Temp0 += GetExtendedDBErrorMsg(__TFILE__,__LINE__);
        if (!Quiet)
            wxLogMessage(Temp0);
        else
            wxMessageBox(_T("-E-> BrowserDB::OnExecSql - ExecSql()"));
        return false;
    }
    if (!Quiet)
    {
        // wxLogMessage(_("\n-I-> BrowserDB::OnExecSql(%s) - End - Time needed : %ld ms"),SQLStmt.c_str(),sw.Time());
    }
    return true;
}
Example #19
0
static wxString ReturnPinNetName(ObjetNetListStruct *Pin,
	const wxString& DefaultFormatNetname)
/**************************************************************************************/
/* Return the net name for the pin Pin.
	Net name is:
	"?" if pin not connected
	"netname" for global net (like gnd, vcc ..
	"netname_sheetnumber" for the usual nets
*/
{
int netcode = Pin->m_NetCode;
wxString NetName;
	
	if( (netcode == 0 ) || ( Pin->m_FlagOfConnection != CONNECT ) )
	{
		return NetName;
	}
	else
	{
		int jj;
		for (jj = 0; jj < g_NbrObjNet; jj++)
		{
			if( g_TabObjNet[jj].m_NetCode != netcode) continue;
			if( ( g_TabObjNet[jj].m_Type != NET_GLOBLABEL) &&
				( g_TabObjNet[jj].m_Type != NET_LABEL) &&
				( g_TabObjNet[jj].m_Type != NET_PINLABEL) ) continue;

			NetName = g_TabObjNet[jj].m_Label;
			break;
		}
		
		if( NetName != "" )
		{
			if( g_TabObjNet[jj].m_Type != NET_PINLABEL )
				NetName << "_" << g_TabObjNet[jj].m_SheetNumber;
		}
		else
		{
			NetName.Printf(DefaultFormatNetname.GetData(), netcode);
		}
	}
	return NetName;
}
wxString NETLIST_EXPORTER::MakeCommandLine( const wxString& aFormatString,
            const wxString& aTempfile, const wxString& aFinalFile, const wxString& aProjectPath )
{
    // Expand format symbols in the command line:
    // %B => base filename of selected output file, minus path and extension.
    // %P => project directory name, without trailing '/' or '\'.
    // %I => full filename of the input file (the intermediate net file).
    // %O => complete filename and path (but without extension) of the user chosen output file.

    wxString    ret  = aFormatString;
    wxFileName  in   = aTempfile;
    wxFileName  out  = aFinalFile;

    ret.Replace( wxT( "%P" ), aProjectPath.GetData(), true );
    ret.Replace( wxT( "%B" ), out.GetName().GetData(), true );
    ret.Replace( wxT( "%I" ), in.GetFullPath().GetData(), true );
    ret.Replace( wxT( "%O" ), out.GetFullPath().GetData(), true );

    return ret;
}
Example #21
0
wxString ecUtils::StripExtraWhitespace (const wxString & strInput)
{
    wxString strOutput;
    wxChar* o=strOutput.GetWriteBuf(1+strInput.Len());
    for(const wxChar* c=strInput.GetData();*c;c++){
        if(ecIsSpace(*c)){
            *o++=wxT(' ');
            if (ecIsSpace(c[1])){
                for(c=c+2; ecIsSpace(*c);c++);
                c--;
            }
        } else {
            *o++=*c;
        }
    }
    *o=0;
    strOutput.UngetWriteBuf();
    strOutput.Trim(TRUE);
    strOutput.Trim(FALSE);
    return strOutput;
#if 0    
    wxString strOutput;
    LPTSTR o=strOutput.GetBuffer(1+strInput.GetLength());
    for(LPCTSTR c=strInput;*c;c++){
        if(_istspace(*c)){
            *o++=_TCHAR(' ');
            if (_istspace(c[1])){
                for(c=c+2;_istspace(*c);c++);
                c--;
            }
        } else {
            *o++=*c;
        }
    }
    *o=0;
    strOutput.ReleaseBuffer();
    strOutput.TrimLeft();
    strOutput.TrimRight();
    return strOutput;
#endif
}
void TagsDatabase::DeleteByFileName(const wxFileName& path, const wxString& fileName, bool autoCommit)
{
	// make sure database is open
	OpenDatabase(path);

	try	
	{
		if( autoCommit )
			m_db->Begin();
		m_db->ExecuteUpdate(wxString::Format(wxT("Delete from tags where File='%s'"), fileName.GetData()));

		if( autoCommit )
			m_db->Commit();
	}
	catch (wxSQLite3Exception& e)
	{
		wxLogMessage(e.GetMessage());
		if( autoCommit )
			m_db->Rollback();
	}
}
Example #23
0
void IO_ERROR::init( const char* aThrowersFile, const char* aThrowersLoc, const wxString& aMsg )
{
    errorText.Printf( IO_FORMAT, aMsg.GetData(),
        wxString::FromUTF8( aThrowersFile ).GetData(),
        wxString::FromUTF8( aThrowersLoc ).GetData() );
}
Example #24
0
myAttachment::myAttachment(wxString sData)
:   m_sContentType(wxT("text/html")),
    m_pData(0L),
    m_dataLen(0L)
{
    wxString sTmpFile;
    wxString        sHeader;
    wxArrayString   sHeadArray;
    wxString        sContentType;
    wxString        sTmp, sTmp2;

    size_t lastOffset;

#ifdef  ENABLE_FORM_DUMP
    /* Dump the file to temporary file */
    if (!(sTmpFile = wxFileName::CreateTempFileName(wxT("att"), &m_tmpFile)).IsEmpty()) {
        D(debug("Created temporary file %s\n", sTmpFile.c_str()));

        if (m_tmpFile.IsOpened()) {
            m_tmpFile.Write( sData.GetData(), sData.Length() );
            m_tmpFile.Close();
    }
}
#endif

    wxStringTokenizer       partToke( sData, wxT("\n"));

    while ((sHeader = partToke.GetNextToken()) != wxT("\r")) {
        //D(debug("-- header %s\n", sHeader.c_str()));

        sHeadArray.Add( sHeader );

        wxStringTokenizer hdrToke( sHeader, wxT(":") );

        sTmp = hdrToke.GetNextToken();
        //D(debug("-- sTMP %s\n", sTmp.c_str()));

        if (sTmp.CmpNoCase(wxT("content-disposition")) == 0) {
            wxString sFields = hdrToke.GetNextToken();
            //D(debug("-- found content disposition!\n"));

            sFields.Trim(true);
            sFields.Trim(false);

            //D(debug("fields = [%s]\n", sFields.c_str()));

            wxStringTokenizer attributes( sFields, wxT(";") );

            sTmp2 = attributes.GetNextToken();
            sTmp2.Trim(true);
            sTmp2.Trim(false);

//            D(debug("sTmp2 = [%s]\n", sTmp2.c_str()));

            if (sTmp2.CmpNoCase(wxT("form-data")) == 0) {
                while (attributes.HasMoreTokens()) {
                    wxString sAttName, sAttValue;
                    wxString subAttr = attributes.GetNextToken().Trim(false).Trim();

                    //D(debug("---- sub attribute = %s\n", subAttr.c_str()));

                    wxStringTokenizer subToke( subAttr, wxT("=") );

                    sAttName = subToke.GetNextToken().Trim(false).Trim();
                    sAttValue = subToke.GetNextToken().Trim(false).Trim();

                    D(debug("Attribute name [%s] value [%s]\n", sAttName.c_str(), sAttValue.c_str()));

                    if (sAttName.CmpNoCase(wxT("name")) == 0) {
                        m_sName = sAttValue;
                        m_sName.Replace(wxT("\""), wxEmptyString);
                    } else if (sAttName.CmpNoCase(wxT("filename")) == 0) {
                        m_sFilename = sAttValue;
                        m_sFilename.Replace(wxT("\""), wxEmptyString);
                    } else {
                        /* */
                    }
                }
            }
        } else if (sTmp.CmpNoCase(wxT("content-type"))  == 0) {
            m_sContentType = hdrToke.GetNextToken().Trim(false).Trim();
            D(debug("-- Found content type of %s\n", m_sContentType.c_str()));
        }

    }
    lastOffset = partToke.GetPosition();

    //D(debug("-- last offset @ %ld\n", lastOffset));

    sData = sData.Mid( lastOffset );

    m_pData     = (unsigned char*)malloc( sData.Length() );
    m_dataLen   = sData.Length();

    memcpy( m_pData, sData.GetData(), sData.Length() );

//  write_file();

    return;
}
Example #25
0
bool PCB_BASE_FRAME::Save_Module_In_Library( const wxString& aLibrary,
                                             MODULE*         aModule,
                                             bool            aOverwrite,
                                             bool            aDisplayDialog )
{
    if( aModule == NULL )
        return false;

    SetMsgPanel( aModule );

    // Ask what to use as the footprint name in the library
    wxString footprintName = aModule->GetFPID().GetFootprintName();

    if( aDisplayDialog )
    {
        wxTextEntryDialog dlg( this, _( "Name:" ), FMT_SAVE_MODULE, footprintName );

        if( dlg.ShowModal() != wxID_OK )
            return false;                   // canceled by user

        footprintName = dlg.GetValue();
        footprintName.Trim( true );
        footprintName.Trim( false );

        if( footprintName.IsEmpty() )
            return false;

        if( ! MODULE::IsLibNameValid( footprintName ) )
        {
            wxString msg = wxString::Format(
                    _("Error:\none of invalid chars '%s' found\nin '%s'" ),
                    MODULE::StringLibNameInvalidChars( true ),
                    GetChars( footprintName ) );

            DisplayError( NULL, msg );
            return false;
        }

        aModule->SetFPID( FPID( footprintName ) );
    }

    // Ensure this footprint has a libname
    if( footprintName.IsEmpty() )
    {
        footprintName = wxT("noname");
        aModule->SetFPID( FPID( footprintName ) );
    }

    bool module_exists = false;

    try
    {
        MODULE* m = FootprintLibs()->FootprintLoad( aLibrary, footprintName );

        if( m )
        {
            delete m;

            module_exists = true;

            // an existing footprint is found in current lib
            if( aDisplayDialog )
            {
                wxString msg = wxString::Format( FMT_MOD_EXISTS,
                        footprintName.GetData(), aLibrary.GetData() );

                SetStatusText( msg );
            }

            if( !aOverwrite )
            {
                // Do not save the given footprint: an old one exists
                return true;
            }
        }

        // this always overwrites any existing footprint, but should yell on its
        // own if the library or footprint is not writable.
        FootprintLibs()->FootprintSave( aLibrary, aModule );
    }
    catch( const IO_ERROR& ioe )
    {
        DisplayError( this, ioe.errorText );
        return false;
    }

    if( aDisplayDialog )
    {
        wxString fmt = module_exists ?
            _( "Component [%s] replaced in '%s'" ) :
            _( "Component [%s] added in  '%s'" );

        wxString msg = wxString::Format( fmt, footprintName.GetData(), aLibrary.GetData() );
        SetStatusText( msg );
    }

    return true;
}
Example #26
0
void WinEDA_PcbFindFrame::FindItem(wxCommandEvent& event)
/********************************************************/
{
PCB_SCREEN * screen = m_Parent->GetScreen();
wxPoint locate_pos;
wxString msg;
bool succes = FALSE;
bool FindMarker = FALSE;
MODULE * Module;
int StartCount;
	
	switch ( event.GetId() )
	{
		case ID_FIND_ITEM:
			s_ItemCount = 0;
			break;
		
		case ID_FIND_MARKER: s_MarkerCount = 0;
		case ID_FIND_NEXT_MARKER:
			FindMarker = TRUE;
			break;
	}

	s_OldStringFound = m_NewText->GetValue();

	m_Parent->DrawPanel->GetViewStart(&screen->m_StartVisu.x, &screen->m_StartVisu.y);
	StartCount = 0;
	
	if( FindMarker )
	{
	MARQUEUR * Marker = (MARQUEUR *) m_Parent->m_Pcb->m_Drawings; 
		for( ; Marker != NULL; Marker = (MARQUEUR *)Marker->Pnext)
		{
			if( Marker->m_StructType != TYPEMARQUEUR ) continue;
			StartCount++;
			if ( StartCount > s_MarkerCount )
			{
				succes = TRUE;
				locate_pos = Marker->m_Pos;
				s_MarkerCount++;
				break;
			}
		}
	}
	
	else for ( Module = m_Parent->m_Pcb->m_Modules; Module != NULL; Module = (MODULE*)Module->Pnext)
	{
		if( WildCompareString( s_OldStringFound, Module->m_Reference->m_Text.GetData(), FALSE ) )
		{
			StartCount++;
			if ( StartCount > s_ItemCount )
			{
				succes = TRUE;
				locate_pos = Module->m_Pos;
				s_ItemCount++;
				break;
			}
		}
		if( WildCompareString( s_OldStringFound, Module->m_Value->m_Text.GetData(), FALSE ) )
		{
			StartCount++;
			if ( StartCount > s_ItemCount )
			{
				succes = TRUE;
				locate_pos = Module->m_Pos;
				s_ItemCount++;
				break;
			}
		}
	}
	
	if ( succes )
	{	/* Il y a peut-etre necessite de recadrer le dessin: */		
		if( ! m_Parent->DrawPanel->IsPointOnDisplay(locate_pos) )
		{
			screen->m_Curseur = locate_pos;
			m_Parent->Recadre_Trace(TRUE);
		}
		else
		{	// Positionnement du curseur sur l'item
			screen->Trace_Curseur(m_Parent->DrawPanel, m_DC);
			screen->m_Curseur = locate_pos;
			GRMouseWarp(m_Parent->DrawPanel, screen->m_Curseur );
			m_Parent->DrawPanel->MouseToCursorSchema();
			screen->Trace_Curseur(m_Parent->DrawPanel, m_DC);
		}

		if( FindMarker ) msg = _("Marker found");
		else msg.Printf( _("<%s> Found"), s_OldStringFound.GetData() );
		m_Parent->Affiche_Message(msg);
		EndModal(1);
	}

	else
	{
		m_Parent->Affiche_Message(wxEmptyString);
		if( FindMarker ) msg = _("Marker not found");
		else msg.Printf( _("<%s> Not Found"), s_OldStringFound.GetData());
		DisplayError(this,msg, 10);
	}
	EndModal(0);
}
Example #27
0
bool PCB_BASE_FRAME::Save_Module_In_Library( const wxString& aLibPath,
                                             MODULE*         aModule,
                                             bool            aOverwrite,
                                             bool            aDisplayDialog )
{
    if( aModule == NULL )
        return false;

    SetMsgPanel( aModule );

    // Ask what to use as the footprint name in the library
    wxString footprintName = aModule->GetLibRef();

    if( aDisplayDialog )
    {
        wxTextEntryDialog dlg( this, _( "Name:" ), FMT_SAVE_MODULE, footprintName );

        if( dlg.ShowModal() != wxID_OK )
            return false;                   // canceled by user

        footprintName = dlg.GetValue();
        footprintName.Trim( true );
        footprintName.Trim( false );

        if( footprintName.IsEmpty() )
            return false;

        if( ! MODULE::IsLibNameValid( footprintName ) )
        {
            wxString msg;
            msg.Printf( _("Error:\none of invalid chars <%s> found\nin <%s>" ),
                        MODULE::ReturnStringLibNameInvalidChars( true ),
                        GetChars( footprintName ) );

            DisplayError( NULL, msg );
                return false;
        }

        aModule->SetLibRef( footprintName );
    }

    // Ensure this footprint has a libname
    if( footprintName.IsEmpty() )
    {
        footprintName = wxT("noname");
        aModule->SetLibRef( footprintName );
    }

    IO_MGR::PCB_FILE_T  pluginType = IO_MGR::GuessPluginTypeFromLibPath( aLibPath );

    MODULE*  module_exists = NULL;

    try
    {
        PLUGIN::RELEASER pi( IO_MGR::PluginFind( pluginType ) );

        module_exists = pi->FootprintLoad( aLibPath, footprintName );

        if( module_exists )
        {
            delete module_exists;

            // an existing footprint is found in current lib
            if( aDisplayDialog )
            {
                wxString msg = wxString::Format( FMT_MOD_EXISTS,
                    footprintName.GetData(), aLibPath.GetData() );

                SetStatusText( msg );
            }

            if( !aOverwrite )
            {
                // Do not save the given footprint: an old one exists
                return true;
            }
        }

        // this always overwrites any existing footprint, but should yell on its
        // own if the library or footprint is not writable.
        pi->FootprintSave( aLibPath, aModule );
    }
    catch( IO_ERROR ioe )
    {
        DisplayError( this, ioe.errorText );
        return false;
    }

    if( aDisplayDialog )
    {
        wxString fmt = module_exists ?
            _( "Component [%s] replaced in <%s>" ) :
            _( "Component [%s] added in  <%s>" );

        wxString msg = wxString::Format( fmt, footprintName.GetData(), aLibPath.GetData() );
        SetStatusText( msg );
    }

    return true;
}
Example #28
0
bool FOOTPRINT_EDIT_FRAME::SaveFootprintInLibrary( const wxString& aLibrary,
                                             MODULE*         aModule,
                                             bool            aOverwrite,
                                             bool            aDisplayDialog )
{
    if( aModule == NULL )
        return false;

    SetMsgPanel( aModule );


    // Legacy libraries are readable, but modifying legacy format is not allowed
    // So prompt the user if he try to add/replace a footprint in a legacy lib
    wxString    libfullname = Prj().PcbFootprintLibs()->FindRow( aLibrary )->GetFullURI();
    IO_MGR::PCB_FILE_T  piType = IO_MGR::GuessPluginTypeFromLibPath( libfullname );

    if( piType == IO_MGR::LEGACY )
    {
        DisplayInfoMessage( this, INFO_LEGACY_LIB_WARN_EDIT );
        return false;
    }

    // Ask what to use as the footprint name in the library
    wxString footprintName = aModule->GetFPID().GetFootprintName();

    if( aDisplayDialog )
    {
        wxTextEntryDialog dlg( this, _( "Name:" ), FMT_SAVE_MODULE, footprintName );

        if( dlg.ShowModal() != wxID_OK )
            return false;                   // canceled by user

        footprintName = dlg.GetValue();
        footprintName.Trim( true );
        footprintName.Trim( false );

        if( footprintName.IsEmpty() )
            return false;

        if( ! MODULE::IsLibNameValid( footprintName ) )
        {
            wxString msg = wxString::Format(
                    _("Error:\none of invalid chars '%s' found\nin '%s'" ),
                    MODULE::StringLibNameInvalidChars( true ),
                    GetChars( footprintName ) );

            DisplayError( NULL, msg );
            return false;
        }

        aModule->SetFPID( FPID( footprintName ) );
    }

    // Ensure this footprint has a libname
    if( footprintName.IsEmpty() )
    {
        footprintName = wxT("noname");
        aModule->SetFPID( FPID( footprintName ) );
    }

    bool module_exists = false;

    try
    {
        FP_LIB_TABLE* tbl = Prj().PcbFootprintLibs();

        MODULE* m = tbl->FootprintLoad( aLibrary, footprintName );

        if( m )
        {
            delete m;

            module_exists = true;

            // an existing footprint is found in current lib
            if( aDisplayDialog )
            {
                wxString msg = wxString::Format( FMT_MOD_EXISTS,
                        footprintName.GetData(), aLibrary.GetData() );

                SetStatusText( msg );
            }

            if( !aOverwrite )
            {
                // Do not save the given footprint: an old one exists
                return true;
            }
        }

        // this always overwrites any existing footprint, but should yell on its
        // own if the library or footprint is not writable.
        tbl->FootprintSave( aLibrary, aModule );
    }
    catch( const IO_ERROR& ioe )
    {
        DisplayError( this, ioe.errorText );
        return false;
    }

    if( aDisplayDialog )
    {
        wxString fmt = module_exists ?
            _( "Component [%s] replaced in '%s'" ) :
            _( "Component [%s] added in  '%s'" );

        wxString msg = wxString::Format( fmt, footprintName.GetData(), aLibrary.GetData() );
        SetStatusText( msg );
    }

    return true;
}
int dlgIndex::Go(bool modal)
{
    if (!connection->BackendMinimumVersion(7, 4))
        chkClustered->Disable();

    if (index)
    {
        // edit mode: view only

        // We only display the column options (ASC/DESC, NULLS FIRST/LAST)
        // on PostgreSQL 8.3+, for btree indexes.
		wxArrayString colsArr = index->GetColumnList();
        wxString colDef, colRest, colName, descDef, nullsDef, opclassDef;
        const wxString firstOrder = wxT(" NULLS FIRST"), lastOrder = wxT(" NULLS LAST"), descOrder = wxT(" DESC");
        if (this->database->BackendMinimumVersion(8, 3) && index->GetIndexType() == wxT("btree"))
        {
            for (int colIdx=0,colsCount=colsArr.Count(); colIdx<colsCount; colIdx++)
            {
                colDef = colsArr.Item(colIdx);

                if (colDef.EndsWith(firstOrder.GetData(), &colRest))
                {
                    colDef = colRest;
                    nullsDef = wxT("FIRST");
                }
                else if (colDef.EndsWith(lastOrder.GetData(), &colRest))
                {
                    colDef = colRest;
                    nullsDef = wxT("LAST");
                }
                else
                    nullsDef = wxT("");

                if (colDef.EndsWith(descOrder.GetData(), &colRest))
                {
                    colDef = colRest;
                    descDef = wxT("DESC");
                    if (nullsDef.IsEmpty())
                        nullsDef = wxT("FIRST");
                }
                else
                {
                    descDef = wxT("ASC");
                    if (nullsDef.IsEmpty())
                        nullsDef = wxT("LAST");
                }

                int pos = colDef.First(wxT(" "));
                if (pos > 0)
                {
                    opclassDef = colDef.Mid(pos + 1);
                    colDef = colDef.Mid(0, pos - 1);
                }
                else
                    opclassDef = wxEmptyString;

			    lstColumns->InsertItem(colIdx, colDef, columnFactory.GetIconId());
                lstColumns->SetItem(colIdx, 1, descDef);
                lstColumns->SetItem(colIdx, 2, nullsDef);
                lstColumns->SetItem(colIdx, 3, opclassDef);
            }
        }
        else
        {
            for (int colIdx=0,colsCount=colsArr.Count(); colIdx<colsCount; colIdx++)
            {
                int pos = colDef.First(wxT(" "));
                if (pos > 0)
                {
                    colDef = colRest;
                    opclassDef = colDef.Mid(pos + 1);
                    colDef = colDef.Mid(0, pos - 1);
                }
                else
                    opclassDef = wxEmptyString;

			    lstColumns->InsertItem(colIdx, colsArr.Item(colIdx), columnFactory.GetIconId());
                lstColumns->SetItem(colIdx, 3, cbOpClass->GetValue());
            }
        }

        cbType->Append(index->GetIndexType());
        chkUnique->SetValue(index->GetIsUnique());
        chkClustered->SetValue(index->GetIsClustered());
        txtWhere->SetValue(index->GetConstraint());
        cbType->SetSelection(0);
        cbType->Disable();
        txtWhere->Disable();
        chkUnique->Disable();
        chkConcurrent->Disable();
        PrepareTablespace(cbTablespace, index->GetTablespaceOid());
        cbOpClass->Disable();
        chkDesc->Disable();
        rdbNullsFirst->Disable();
        rdbNullsLast->Disable();
    }
    else
    {
        // create mode
        PrepareTablespace(cbTablespace);
        cbType->Append(wxT(""));
        pgSet *set=connection->ExecuteSet(wxT(
            "SELECT oid, amname FROM pg_am"));
        if (set)
        {
            while (!set->Eof())
            {
                cbType->Append(set->GetVal(1), set->GetVal(0));
                set->MoveNext();
            }
            delete set;
        }

        if (!this->database->BackendMinimumVersion(8, 2))
            chkConcurrent->Disable();

        if (!this->database->BackendMinimumVersion(8, 3))
        {
            chkDesc->Disable();
            rdbNullsFirst->Disable();
            rdbNullsLast->Disable();
        }

        // Add the default tablespace 
        cbTablespace->Insert(_("<default tablespace>"), 0, (void *)0);
        cbTablespace->SetSelection(0);
    }

    int returnCode = dlgIndexBase::Go(modal);

    if (index && connection->BackendMinimumVersion(8, 0))
        txtName->Enable(true);

    // This fixes a UI glitch on MacOS X
    // Because of the new layout code, the Columns pane doesn't size itself properly
    SetSize(GetSize().GetWidth()+1, GetSize().GetHeight());
    SetSize(GetSize().GetWidth()-1, GetSize().GetHeight());

    return returnCode;
}
Example #30
0
bool LibArchive(wxWindow * frame, const wxString & ArchFullFileName)
/*******************************************************************/
/*
Creation du fichier librairie contenant tous les composants utilisés dans
le projet en cours
retourne  TRUE si fichier créé
*/
{
wxString DocFileName, msg;
char Line[256];
FILE *ArchiveFile, *DocFile;
EDA_BaseStruct ** ListStruct;
EDA_LibComponentStruct ** ListEntry, *Entry;
int ii, NbItems;
char * Text;


	/* Creation de la liste des elements */
	NbItems = GenListeCmp(NULL );	// Comptage des composants
	if ( NbItems == 0 ) return FALSE;

	ListStruct = (EDA_BaseStruct **)
			MyZMalloc( NbItems * sizeof(EDA_BaseStruct **) );
	if (ListStruct == NULL ) return FALSE;

	/* Calcul de la liste des composants */
	GenListeCmp(ListStruct);

	/* Calcul de la liste des Entrees de librairie
		et Remplacement des alias par les composants "Root" */
	ListEntry = (EDA_LibComponentStruct ** )
				MyZMalloc( NbItems * sizeof(EDA_LibComponentStruct *) );
	if (ListEntry == NULL ) return FALSE;

	for ( ii = 0; ii < NbItems; ii++ )
	{
		Text = ( (EDA_SchComponentStruct*)ListStruct[ii])->m_ChipName;
		Entry = FindLibPart(Text, "", FIND_ROOT);
		ListEntry[ii] = Entry;	// = NULL si Composant non trouvé en librairie
	}

	MyFree(ListStruct);

	qsort( ListEntry, NbItems, sizeof(EDA_LibComponentStruct *),
			(int(*)(const void*, const void*))TriListEntry);

	/* mise a jour extension fichier doc associe */
	DocFileName = ArchFullFileName;
	ChangeFileNameExt(DocFileName, ".bck");

	if ((ArchiveFile = fopen(ArchFullFileName.GetData(), "wt")) == NULL)
	{
		MyFree(ListEntry);
		msg = _("Failed to create archive lib file ") + ArchFullFileName;
		DisplayError(frame, msg);
		return FALSE;
	}

	if ((DocFile = fopen(DocFileName.GetData(), "wt")) == NULL)
	{
		msg = _("Failed to create doc lib file ") + DocFileName;
		DisplayError(frame, msg);
	}

	fprintf(ArchiveFile,"%s  %s\n#\n", LIBFILE_IDENT,DateAndTime(Line));
	if( DocFile)
		fprintf(DocFile,"%s  %s\n", DOCFILE_IDENT, DateAndTime(Line));

	/* Generation des elements */
	for ( ii = 0; ii < NbItems; ii++ )
	{
		if ( ListEntry[ii] == NULL )	// Composant non trouvé en librairie
		{
		continue;
			}
		if ( ii == 0 )
		{
			WriteOneLibEntry(frame, ArchiveFile, ListEntry[ii]);
			if( DocFile ) WriteOneDocLibEntry(DocFile, ListEntry[ii]);
		}
		else if ( ListEntry[ii-1] != ListEntry[ii] )
		{
			 WriteOneLibEntry(frame, ArchiveFile, ListEntry[ii]);
			 if( DocFile ) WriteOneDocLibEntry(DocFile, ListEntry[ii]);
		}
	}

	/* Generation fin de fichier */
	fprintf(ArchiveFile,"#\n#EndLibrary\n");
	fclose(ArchiveFile);

	if( DocFile )
	{
		fprintf(DocFile,"#\n#End Doc Library\n");
		fclose(DocFile);
	}

	MyFree(ListEntry);

	return TRUE;
}