Esempio n. 1
0
int WriteArbWaveForm(unsigned short *wavefm, int len) 
{
    unsigned short tmplen = (unsigned short) len; 

    /* check that the waveform length is within limits */
    if (len > DIO_ARB_MAX_WAVE_LEN) {
	sprintf(tmpstring, "Error: waveform length %d too long to write to digital IO state machine. Must be <= %d", len, DIO_ARB_MAX_WAVE_LEN);
	DisplayErrorMessage(tmpstring);
	return 0;
    }
    /* write out the waveform to the waveform generator */
    if (!WriteDSPData(DSPDIO, DIO_ARB_WAVE_ADDR, 0, len, wavefm)) {
	sprintf(tmpstring, "Error writing waveform to arbitrary waveform generator");
	DisplayErrorMessage(tmpstring);
	return 0;
    }

    /* write out the waveform length */
    if (!WriteDSPData(DSPDIO, DSP_SRAM, DIO_ARB_LENGTH, 1, &tmplen)) {
	sprintf(tmpstring, "Error writing waveform length for arbitrary waveform generator");
	DisplayErrorMessage(tmpstring);
	return 0;
    }
    //ReadDSPData(DSPDIO, DSP_SRAM, DIO_ARB_LENGTH, 1, &tmplen);
//	    fprintf(stderr, "length %d\n", tmplen);
    return SetArbPointer(0);
}
unsigned int CheckTheROM(HWND hwnd)  {
struct stat StatBuffer;
char ROMTitle[21+1];
const char* ROMRealTitle="SUPER MARIOWORLD     ";
unsigned char country,version;

   fseek(TheROM,0,0);
   fstat(fileno(TheROM), &StatBuffer);
   if (!(StatBuffer.st_size&0x200))
     return DisplayErrorMessage(hwnd,-26,NULL); //no 0x200 byte header
   fseek(TheROM,0x81C0,0);
   fread(ROMTitle,21,1,TheROM);
   ROMTitle[21]=0;
   fseek(TheROM,0x81D9,0); //country byte
   fread(&country,1,1,TheROM);
   fseek(TheROM,0x81DB,0); //version byte
   fread(&version,1,1,TheROM);

   if (strcmp(ROMRealTitle,ROMTitle))
      return DisplayErrorMessage(hwnd,-27,NULL); //wrong game title
   else
   { //Mario World
     if (version)
         return DisplayErrorMessage(hwnd,-28,NULL); //not version 1.00
     if (country!=1)
         return DisplayErrorMessage(hwnd,-29,NULL); //wrong country (US only)
   }

   return 1;
}
Esempio n. 3
0
bool CExtUpdate::applySettings(std::string & filename, int mode)
{
	if(!FileHelpers)
		FileHelpers = new CFileHelpers();

	if (mode == MODE_EXPERT)
		imgFilename = (std::string)g_settings.update_dir + "/" + FILESYSTEM_ENCODING_TO_UTF8_STRING(filename);
	else
		imgFilename = FILESYSTEM_ENCODING_TO_UTF8_STRING(filename);

	DBG_TIMER_START()

	std::string oldFilename = imgFilename;
	std::string hostName    = netGetHostname();
	std::string orgPath     = getPathName(imgFilename);
	std::string orgName     = getBaseName(imgFilename);
	orgName                 = getFileName(orgName);
	std::string orgExt      = "." + getFileExt(imgFilename);
	std::string timeStr     = getNowTimeStr("_%Y%m%d_%H%M");
	std::string settingsStr = "+settings";

	if (orgPath != "/tmp") {
		if (g_settings.softupdate_name_mode_apply == CExtUpdate::SOFTUPDATE_NAME_HOSTNAME_TIME)
			imgFilename = orgPath + "/" + hostName + timeStr + settingsStr + orgExt;
		else if (g_settings.softupdate_name_mode_apply == CExtUpdate::SOFTUPDATE_NAME_ORGNAME_TIME)
			imgFilename = orgPath + "/" + orgName + timeStr  + settingsStr + orgExt;
		else
			imgFilename = orgPath + "/" + orgName  + settingsStr + orgExt;
		FileHelpers->copyFile(oldFilename.c_str(), imgFilename.c_str(), 0644);
	}
	else
		imgFilename = oldFilename;
	filename = imgFilename;

	bool ret = applySettings();
	DBG_TIMER_STOP("Image editing")
	if (!ret) {
		if ((mtdRamError != "") && (!flashErrorFlag))
			DisplayErrorMessage(mtdRamError.c_str());

		// error, delete image file
		unlink(imgFilename.c_str());
	}
	else {
		if (mode == MODE_EXPERT) {
			if ((mtdNumber < 3) || (mtdNumber > 4)) {
				const char *err = "invalid mtdNumber\n";
				printf(err);
				DisplayErrorMessage(err);
				WRITE_UPDATE_LOG("ERROR: %s", err);
				return false;
			}
		}
		WRITE_UPDATE_LOG("\n");
		WRITE_UPDATE_LOG("##### Settings taken. #####\n");
		if (mode == MODE_EXPERT)
			CFlashExpert::getInstance()->writemtd(filename, mtdNumber);
	}
	return ret;
}
Esempio n. 4
0
bool               P3DPlugLuaRunScript(const char         *FileName,
                                       const P3DPlantModel*PlantModel)
 {
  lua_State                           *State;

  SetCLocale();

  State = lua_open();

  if (State != NULL)
   {
    #if NGP_LUA_VER > 50
    luaL_openlibs(State);
    #else
    luaopen_base(State);
    luaopen_table(State);
    luaopen_io(State);
    luaopen_string(State);
    luaopen_math(State);
    #endif

    P3DPlugLuaRegisterHLI(State);
    P3DPlugLuaRegisterUI(State);
    P3DPlugLuaRegisterFS(State);
    P3DPlugLuaRegisterExportPrefs(State,P3DApp::GetApp()->GetExport3DPrefs());
    P3DPlugLuaRegisterModel(State,"PlantModel",PlantModel);

    lua_register(State,"GetTextureFileName",GetTextureFileName);
    lua_register(State,"GetCurrentLOD",GetCurrentLOD);
    lua_register(State,"GetDerivedFileName",GetDerivedFileName);

    if (luaL_loadfile(State,FileName) || lua_pcall(State,0,0,0))
     {
      if (lua_isstring(State,-1))
       {
        DisplayErrorMessage(wxString(lua_tostring(State,-1),wxConvUTF8));
       }
      else
       {
        DisplayErrorMessage(wxT("Script error: (undefined)"));
       }
     }

    lua_close(State);

    RestoreLocale();

    return(true);
   }
  else
   {
    DisplayErrorMessage(wxT("Unable to initialize Lua environment"));

    RestoreLocale();

    return(false);
   }
 }
Esempio n. 5
0
static bool        FillIndexBufferFromLuaTable
                                      (lua_State          *State,
                                       P3DGMeshData       *MeshData)
 {
  bool             Result;
  unsigned int    *IndexBuffer;
  unsigned int     TriangleIndex;

  Result = GetTableTableField(State,"indices");

  if (Result)
   {
    IndexBuffer = MeshData->GetIndexBufferI();

    TriangleIndex = 1;

    lua_rawgeti(State,-1,TriangleIndex);

    while ((Result) && (!lua_isnil(State,-1)))
     {
      if (lua_istable(State,-1))
       {
        Result = GetIndexFromLuaArray(State,1,IndexBuffer++);

        if (Result)
         {
          Result = GetIndexFromLuaArray(State,2,IndexBuffer++);
         }

        if (Result)
         {
          Result = GetIndexFromLuaArray(State,3,IndexBuffer++);
         }

        if (!Result)
         {
          DisplayErrorMessage(wxT("Script error: invalid or absent vertex index in triangle list"));
         }
       }
      else
       {
        Result = false;

        DisplayErrorMessage(wxT("Script error: triangle description must be an array of three indices"));
       }

      lua_pop(State,1);
      lua_rawgeti(State,-1,++TriangleIndex);
     }

    lua_pop(State,1);

    lua_pop(State,1);
   }

  return(Result);
 }
Esempio n. 6
0
extern
P3DGMeshData      *P3DPlugLuaRunGMeshGenerator
                                      (const char         *FileName)
 {
  lua_State                           *State;
  P3DGMeshData                        *Result = 0;

  SetCLocale();

  State = lua_open();

  if (State != NULL)
   {
    #if NGP_LUA_VER > 50
    luaL_openlibs(State);
    #else
    luaopen_base(State);
    luaopen_table(State);
    luaopen_io(State);
    luaopen_string(State);
    luaopen_math(State);
    #endif

    P3DPlugLuaRegisterUI(State);

    if (luaL_loadfile(State,FileName) || lua_pcall(State,0,1,0))
     {
      if (lua_isstring(State,-1))
       {
        DisplayErrorMessage(wxString(lua_tostring(State,-1),wxConvUTF8));
       }
      else
       {
        DisplayErrorMessage(wxT("Script error: (undefined)"));
       }
     }
    else
     {
      Result = CreateGMeshDataFromLuaTable(State);
     }

    lua_close(State);

    RestoreLocale();
   }
  else
   {
    DisplayErrorMessage(wxT("Unable to initialize Lua environment"));

    RestoreLocale();
   }

  return(Result);
 }
void LIB_EDIT_FRAME::KiwayMailIn( KIWAY_EXPRESS& mail )
{
    const std::string& payload = mail.GetPayload();

    switch( mail.Command() )
    {
    case MAIL_LIB_EDIT:
        if( !payload.empty() )
        {
            wxString libFileName( payload );
            wxString libNickname;
            wxString msg;

            SYMBOL_LIB_TABLE*    libTable = Prj().SchSymbolLibTable();
            const LIB_TABLE_ROW* libTableRow = libTable->FindRowByURI( libFileName );

            if( !libTableRow )
            {
                msg.Printf( _( "The current configuration does not include the symbol library\n"
                               "\"%s\".\nUse Manage Symbol Libraries to edit the configuration." ),
                            libFileName );
                DisplayErrorMessage( this, _( "Library not found in symbol library table." ), msg );
                break;
            }

            libNickname = libTableRow->GetNickName();

            if( !libTable->HasLibrary( libNickname, true ) )
            {
                msg.Printf( _( "The library with the nickname \"%s\" is not enabled\n"
                               "in the current configuration.  Use Manage Symbol Libraries to\n"
                               "edit the configuration." ), libNickname );
                DisplayErrorMessage( this, _( "Symbol library not enabled." ), msg );
                break;
            }

            SetCurLib( libNickname );

            if( m_treePane )
            {
                LIB_ID id( libNickname, wxEmptyString );
                m_treePane->GetLibTree()->ExpandLibId( id );
                m_treePane->GetLibTree()->CenterLibId( id );
            }
        }

        break;

    default:
        ;
    }
}
//---------------------------------------------------------------------------
LRESULT CSimpleDialog::OnClose(HWND hDlg, WPARAM wParam, LPARAM lParam)
{ 
    HRESULT hr = S_OK;
    CSmartComPtr<IEnumBackgroundCopyJobs> JobsEnum;
    CSmartComPtr<IBackgroundCopyJob>      Job;
    WCHAR *pwszJobName = NULL;

    //
    // As we are leaving the application, cancel jobs that are still
    // in progress. This will only apply to Jobs submitted by this 
    // user AND with our predefined description string
    //
    hr = g_JobManager->EnumJobs(0, JobsEnum.GrabOutPtr());
    if (FAILED(hr))
    {
        DisplayErrorMessage(L"Failed to create a BITS job enumerator. Error id is 0x%X.", hr);
        goto done;
    }

    while((JobsEnum->Next(1, Job.GrabOutPtr(), NULL) == S_OK))
    {
        hr = Job->GetDisplayName(&pwszJobName);
        if (SUCCEEDED(hr))
        {
            if (wcscmp(pwszJobName, STR_JOBNAME_DEFAULT) == 0)
            {
                // Found a job that was created by this app -- remove the
                // notification callback and then cancel it
                hr = Job->SetNotifyInterface(NULL);
                if (FAILED(hr))
                {
                    DisplayErrorMessage(L"Failed to remove the notification callback for a job while cleaning up jobs created by this application.", hr);
                }

                hr = Job->Cancel();
                if (FAILED(hr))
                {
                    DisplayErrorMessage(L"Failed to cancel a job while cleaning up jobs created by this application.", hr);
                }
            }

            CoTaskMemFree(pwszJobName);
            pwszJobName = NULL;
        }
    }

done:

    return DestroyWindow(m_hWnd);
}
Esempio n. 9
0
int SetArbAOutChan(unsigned short aout)
    /* set the analog output for the arbitrary waveform generator */
{
    if ((aout != DIO_ARB_AOUT_CHANNEL_1) && (aout != DIO_ARB_AOUT_CHANNEL_2)){
	sprintf(tmpstring, "Error: Analog output for arbitrary waveform generator must be %d or %d", DIO_ARB_AOUT_CHANNEL_1, DIO_ARB_AOUT_CHANNEL_2);
	DisplayErrorMessage(tmpstring);
	return 0;
    }
    if (!WriteDSPData(DSPDIO, DSP_SRAM, DIO_ARB_AOUT_CHANNEL_ADDR, 1, &aout)) {
	sprintf(tmpstring, "Error setting analog output of arbitrary waveform generator");
	DisplayErrorMessage(tmpstring);
	return 0;
    }
    return 1;
}
Esempio n. 10
0
void LIB_EDIT_FRAME::OnImportPart( wxCommandEvent& event )
{
    wxString msg;
    m_lastDrawItem = NULL;
    wxString libName = getTargetLib();

    if( !m_libMgr->LibraryExists( libName ) )
    {
        libName = SelectLibraryFromList();

        if( !m_libMgr->LibraryExists( libName ) )
            return;
    }

    wxFileDialog dlg( this, _( "Import Symbol" ), m_mruPath,
                      wxEmptyString, SchematicLibraryFileWildcard(),
                      wxFD_OPEN | wxFD_FILE_MUST_EXIST );

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

    wxFileName fn = dlg.GetPath();
    m_mruPath = fn.GetPath();

    wxArrayString symbols;
    SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_LEGACY ) );

    // TODO dialog to select the part to be imported if there is more than one
    try
    {
        pi->EnumerateSymbolLib( symbols, fn.GetFullPath() );
    }
    catch( const IO_ERROR& ioe )
    {
        msg.Printf( _( "Cannot import symbol library \"%s\"." ), fn.GetFullPath() );
        DisplayErrorMessage( this, msg, ioe.What() );
        return;
    }

    if( symbols.empty() )
    {
        msg.Printf( _( "Symbol library file \"%s\" is empty." ), fn.GetFullPath() );
        DisplayError( this,  msg );
        return;
    }

    wxString symbolName = symbols[0];
    LIB_ALIAS* entry = pi->LoadSymbol( fn.GetFullPath(), symbolName );

    if( m_libMgr->PartExists( symbols[0], libName ) )
    {
        msg.Printf( _( "Symbol \"%s\" already exists in library \"%s\"." ), symbolName, libName );
        DisplayError( this,  msg );
        return;
    }

    m_libMgr->UpdatePart( entry->GetPart(), libName );
    SyncLibraries( false );
    loadPart( symbolName, libName, 1 );
}
TSharedRef<SDockTab> FMerge::GenerateMergeWidget(const UBlueprint& Object, TSharedRef<FBlueprintEditor> Editor)
{
	auto ActiveTabPtr = ActiveTab.Pin();
	if( ActiveTabPtr.IsValid() )
	{
		// just bring the tab to the foreground:
		auto CurrentTab = FGlobalTabmanager::Get()->InvokeTab(MergeToolTabId);
		check( CurrentTab == ActiveTabPtr );
		return ActiveTabPtr.ToSharedRef();
	}

	// merge the local asset with the depot, SCC provides us with the last common revision as
	// a basis for the merge:

	TSharedPtr<SWidget> Contents;

	if (!PendingMerge(Object))
	{
		// this should load up the merge-tool, with an asset picker, where they
		// can pick the asset/revisions to merge against
		Contents = GenerateMergeTabContents(Editor, nullptr, FRevisionInfo::InvalidRevision(), nullptr, FRevisionInfo::InvalidRevision(), &Object, FOnMergeResolved());
	}
	else
	{
		// @todo DO: this will probably need to be async.. pulling down some old versions of assets:
		const FString& PackageName = Object.GetOutermost()->GetName();
		const FString& AssetName = Object.GetName();

		FSourceControlStatePtr SourceControlState = FMergeToolUtils::GetSourceControlState(PackageName);
		if (!SourceControlState.IsValid())
		{
			DisplayErrorMessage(
				FText::Format(
					LOCTEXT("MergeFailedNoSourceControl", "Aborted Load of {0} from {1} because the source control state was invalidated")
					, FText::FromString(AssetName)
					, FText::FromString(PackageName)
				)
			);

			Contents = SNew(SHorizontalBox);
		}
		else
		{
			ISourceControlState const& SourceControlStateRef = *SourceControlState;

			FRevisionInfo CurrentRevInfo = FRevisionInfo::InvalidRevision();
			const UBlueprint* RemoteBlueprint = Cast< UBlueprint >(LoadHeadRev(PackageName, AssetName, SourceControlStateRef, CurrentRevInfo));
			FRevisionInfo BaseRevInfo = FRevisionInfo::InvalidRevision();
			const UBlueprint* BaseBlueprint = Cast< UBlueprint >(LoadBaseRev(PackageName, AssetName, SourceControlStateRef, BaseRevInfo));

			Contents = GenerateMergeTabContents(Editor, BaseBlueprint, BaseRevInfo, RemoteBlueprint, CurrentRevInfo, &Object, FOnMergeResolved());
		}
	}

	TSharedRef<SDockTab> Tab =  FGlobalTabmanager::Get()->InvokeTab(MergeToolTabId);
	Tab->SetContent(Contents.ToSharedRef());
	ActiveTab = Tab;
	return Tab;

}
Esempio n. 12
0
int ResetStateMachines()
{
    int i;
    unsigned short addr;
    unsigned short command[DIO_MAX_COMMAND_LEN];

    /* reset each state machines to the beginning of its buffer and
     * set its output to be 0 */
    command[0] = 0;
    for (i = 0; i <  DIO_N_STATE_MACHINES; i++) {
	ResetStateMachine(i);
	switch(i) {
	    case 0:
		addr = DIO_OUT_1;
		break;
	    case 1:
		addr = DIO_OUT_2;
		break;
	    case 2:
		addr = DIO_OUT_3;
		break;
	    case 3:
		addr = DIO_OUT_4;
		break;
	}
	/* set the output to be 0 */
	if (!WriteDSPData(DSPDIO, DSP_SRAM, addr, 1, command)) {
	    sprintf(tmpstring, "Error setting port %d to output 0", i);
	    DisplayErrorMessage(tmpstring);
	    return 0;
	}
    }

    return 1;
}
Esempio n. 13
0
FP_LIB_TABLE* PROJECT::PcbFootprintLibs()
{
    // This is a lazy loading function, it loads the project specific table when
    // that table is asked for, not before.

    FP_LIB_TABLE*   tbl = (FP_LIB_TABLE*) GetElem( ELEM_FPTBL );

    // its gotta be NULL or a FP_LIB_TABLE, or a bug.
    wxASSERT( !tbl || tbl->Type() == FP_LIB_TABLE_T );

    if( !tbl )
    {
        // Stack the project specific FP_LIB_TABLE overlay on top of the global table.
        // ~FP_LIB_TABLE() will not touch the fallback table, so multiple projects may
        // stack this way, all using the same global fallback table.
        tbl = new FP_LIB_TABLE( &GFootprintTable );

        SetElem( ELEM_FPTBL, tbl );

        wxString projectFpLibTableFileName = FootprintLibTblName();

        try
        {
            tbl->Load( projectFpLibTableFileName );
        }
        catch( const IO_ERROR& ioe )
        {
            DisplayErrorMessage( nullptr, _( "Error loading project footprint libraries" ),
                                 ioe.What() );
        }
    }

    return tbl;
}
Esempio n. 14
0
int CLuaInstMisc::checkVersion(lua_State *L)
{
	/* workaround for deprecated functions */
	CLuaMisc *D;
	if (luaL_testudata(L, 1, LUA_CLASSNAME) == NULL) {
		D = MiscCheckData(L, 1);
		if (!D) return 0;
	}
	/* CLuaMisc *D = MiscCheckData(L, 1);
	if (!D) return 0; */
	int numargs = lua_gettop(L);
	if (numargs < 3) {
		printf("CLuaInstMisc::%s: not enough arguments (%d, expected 2)\n", __func__, numargs);
		lua_pushnil(L);
		return 1;
	}
	int major=0, minor=0;
	major = luaL_checkint(L, 2);
	minor = luaL_checkint(L, 3);
	if ((major > LUA_API_VERSION_MAJOR) || ((major == LUA_API_VERSION_MAJOR) && (minor > LUA_API_VERSION_MINOR))) {
		char msg[1024];
		snprintf(msg, sizeof(msg)-1, "%s (v%d.%d)\n%s v%d.%d",
				g_Locale->getText(LOCALE_LUA_VERSIONSCHECK1),
				LUA_API_VERSION_MAJOR, LUA_API_VERSION_MINOR,
				g_Locale->getText(LOCALE_LUA_VERSIONSCHECK2),
				major, minor);
		DisplayErrorMessage(msg, "Lua Script Error:");

	}
	lua_pushinteger(L, 1); /* for backward compatibility */
	return 1;
}
Esempio n. 15
0
CC_FILE_ERROR FileIOFilter::SaveToFile(	ccHObject* entities,
										const QString& filename,
										SaveParameters& parameters,
										Shared filter)
{
	if (!entities || filename.isEmpty() || !filter)
		return CC_FERR_BAD_ARGUMENT;

	//if the file name has no extension, we had a default one!
	QString completeFileName(filename);
	if (QFileInfo(filename).suffix().isEmpty())
		completeFileName += QString(".%1").arg(filter->getDefaultExtension());

	CC_FILE_ERROR result = CC_FERR_NO_ERROR;
	try
	{
		result = filter->saveToFile(entities, completeFileName, parameters);
	}
	catch(...)
	{
		ccLog::Warning(QString("[I/O] CC has caught an unhandled exception while saving file '%1'").arg(filename));
		result = CC_FERR_CONSOLE_ERROR;
	}

	if (result == CC_FERR_NO_ERROR)
	{
		ccLog::Print(QString("[I/O] File '%1' saved successfully").arg(filename));
	}
	else
	{
		DisplayErrorMessage(result,"saving",filename);
	}

	return result;
}
Esempio n. 16
0
void LIB_EDIT_FRAME::OnAddPartToSchematic( wxCommandEvent& event )
{
    if( GetCurPart() )
    {
        SCH_EDIT_FRAME* schframe = (SCH_EDIT_FRAME*) Kiway().Player( FRAME_SCH, false );

        if( schframe == NULL )      // happens when the schematic editor is not active (or closed)
        {
            DisplayErrorMessage( this, _( "No schematic currently open." ) );
            return;
        }

        SCH_COMPONENT* component = new SCH_COMPONENT( *GetCurPart(), GetCurPart()->GetLibId(),
                                                      g_CurrentSheet, GetUnit(), GetConvert() );

        // Be sure the link to the corresponding LIB_PART is OK:
        component->Resolve( *Prj().SchSymbolLibTable() );

        if( schframe->GetAutoplaceFields() )
            component->AutoplaceFields( /* aScreen */ NULL, /* aManual */ false );

        schframe->Raise();
        schframe->GetToolManager()->RunAction( EE_ACTIONS::placeSymbol, true, component );
    }
}
Esempio n. 17
0
bool LIB_EDIT_FRAME::LoadComponentFromCurrentLib( const wxString& aAliasName, int aUnit,
                                                  int aConvert )
{
    LIB_ALIAS* alias = nullptr;

    try
    {
        alias = Prj().SchSymbolLibTable()->LoadSymbol( GetCurLib(), aAliasName );
    }
    catch( const IO_ERROR& ioe )
    {
        wxString msg;

        msg.Printf( _( "Error occurred loading symbol \"%s\" from library \"%s\"." ),
                    aAliasName, GetCurLib() );
        DisplayErrorMessage( this, msg, ioe.What() );
        return false;
    }

    if( !alias || !LoadOneLibraryPartAux( alias, GetCurLib(), aUnit, aConvert ) )
        return false;

    // Enable synchronized pin edit mode for symbols with interchangeable units
    m_syncPinEdit = !GetCurPart()->UnitsLocked();

    GetScreen()->ClearUndoRedoList();
    Zoom_Automatique( false );
    SetShowDeMorgan( GetCurPart()->HasConversion() );

    if( aUnit > 0 )
        UpdatePartSelectList();

    return true;
}
Esempio n. 18
0
LIB_ALIAS* SchGetLibAlias( const LIB_ID& aLibId, SYMBOL_LIB_TABLE* aLibTable, PART_LIB* aCacheLib,
                           wxWindow* aParent, bool aShowErrorMsg )
{
    // wxCHECK_MSG( aLibId.IsValid(), NULL, "LIB_ID is not valid." );
    wxCHECK_MSG( aLibTable, NULL, "Invalid symbol library table." );

    LIB_ALIAS* alias = NULL;

    try
    {
        alias = aLibTable->LoadSymbol( aLibId );

        if( !alias && aCacheLib )
            alias = aCacheLib->FindAlias( aLibId );
    }
    catch( const IO_ERROR& ioe )
    {
        if( aShowErrorMsg )
        {
            wxString msg;

            msg.Printf( _( "Could not load symbol \"%s\" from library \"%s\"." ),
                        aLibId.GetLibItemName().wx_str(), aLibId.GetLibNickname().wx_str() );
            DisplayErrorMessage( aParent, msg, ioe.What() );
        }
    }

    return alias;
}
Esempio n. 19
0
void KICAD_MANAGER_FRAME::OnNewProject( wxCommandEvent& aEvent )
{
    wxString        default_dir = GetMruPath();
    wxFileDialog    dlg( this, _( "Create New Project" ), default_dir, wxEmptyString,
                         ProjectFileWildcard(), wxFD_SAVE | wxFD_OVERWRITE_PROMPT );

    // Add a "Create a new directory" checkbox
    dlg.SetExtraControlCreator( &DIR_CHECKBOX::Create );

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

    wxFileName pro( dlg.GetPath() );

    // wxFileName automatically extracts an extension.  But if it isn't
    // a .pro extension, we should keep it as part of the filename
    if( !pro.GetExt().IsEmpty()
            && pro.GetExt().ToStdString() != ProjectFileExtension )
        pro.SetName( pro.GetName() + wxT( "." ) + pro.GetExt() );

    pro.SetExt( ProjectFileExtension );     // enforce extension

    if( !pro.IsAbsolute() )
        pro.MakeAbsolute();

    // Append a new directory with the same name of the project file.
    if( static_cast<DIR_CHECKBOX*>( dlg.GetExtraControl() )->CreateNewDir() )
        pro.AppendDir( pro.GetName() );

    // Check if the project directory is empty if it already exists.
    wxDir directory( pro.GetPath() );

    if( !pro.DirExists() )
    {
        if( !pro.Mkdir() )
        {
            wxString msg;
            msg.Printf( _( "Directory \"%s\" could not be created.\n\n"
                           "Please make sure you have write permissions and try again." ),
                        pro.GetPath() );
            DisplayErrorMessage( this, msg );
            return;
        }
    }
    else if( directory.HasFiles() )
    {
        wxString msg = _( "The selected directory is not empty.  It is recommended that you "
                          "create projects in their own empty directory.\n\nDo you "
                          "want to continue?" );

        if( !IsOK( this, msg ) )
            return;
    }

    CreateNewProject( pro );
    LoadProject( pro );
}
Esempio n. 20
0
int LookForDSPDIOResponse(void)
{
    if (!GetDSPResponse(DSPDIO, 0, NULL)) {
        sprintf(tmpstring, "No response from master DSP when asked");
        DisplayErrorMessage(tmpstring);
	return 0;
    }
    return 1;
}
//---------------------------------------------------------------------------
LRESULT CSimpleDialog::OnOK(HWND hDlg, WPARAM wParam, LPARAM lParam)
{ 
    HRESULT hr = S_OK;
    WCHAR   wszBuffSampleText[MAX_BUFFER_SIZE]         = {0};
    WCHAR   wszBuffVirtualDir[INTERNET_MAX_URL_LENGTH] = {0};
    BOOL    fRequireUploadReply = FALSE;
    LRESULT lRet = 1;
    CPack   XMLPack;

    //
    // Grab input values from the UI
    //
    hr = CollectUserInput(
        wszBuffVirtualDir, 
        ARRAYSIZE(wszBuffVirtualDir),
        wszBuffSampleText, 
        ARRAYSIZE(wszBuffSampleText),
        &fRequireUploadReply
    );
    if (FAILED(hr))
    {

        DisplayErrorMessage(L"Failed to collect input values from the UI.", hr);
        lRet = 0;
        goto done;
    }


    //
    //  Pack the text as an XML file and UPLOAD it to the server!!
    //
    AddStatusMessage(L"START OF PROCESS TO UPLOAD FILE");

    hr = XMLPack.PackText(wszBuffSampleText);
    if (FAILED(hr))
    {
        lRet = 0;
        goto done;
    }

    hr = XMLPack.Upload(STR_JOBNAME_DEFAULT, wszBuffVirtualDir, fRequireUploadReply);
    if (FAILED(hr))
    {
        lRet = 0;
        goto done;
    }

done:

    if (!lRet)
    {
        AddStatusMessage(L"END OF UPLOAD PROCESS -- FAILED");
    }

    return lRet;
}
Esempio n. 22
0
int SetArbTrigger(unsigned short trigger)
    /* set the trigger for the aritrary waveform generator */
{
   if (!WriteDSPData(DSPDIO, DSP_SRAM, DIO_ARB_TRIGGER_ADDR, 1, &trigger)) {
	sprintf(tmpstring, "Error setting trigger for arbitrary waveform generator to 0x%x", trigger);
	DisplayErrorMessage(tmpstring);
	return 0;
   }
   return 1;
}
Esempio n. 23
0
int EnableArb(unsigned short enable)
    /* enable or disable the arbitrary waveform generator */
{
   if (!WriteDSPData(DSPDIO, DSP_SRAM, DIO_ARB_ENABLE_ADDR, 1, &enable)) {
	sprintf(tmpstring, "Error enabling or disabling arbitrary waveform generator");
	DisplayErrorMessage(tmpstring);
	return 0;
   }
   return 1;
}
Esempio n. 24
0
int SetArbPointer(unsigned short offset)
    /* reset the arbitrary waveform generator's pointer to the beginning of the buffer */
{
    if (!WriteDSPData(DSPDIO, DSP_SRAM, DIO_ARB_POINTER, 1, &offset)) {
	sprintf(tmpstring, "Error setting pointer to offset %d for arbitrary waveform generator", offset);
	DisplayErrorMessage(tmpstring);
	return 0;
    }
    return 1;
}
Esempio n. 25
0
static bool copy_pro_file_template( const SEARCH_STACK& aSearchS, const wxString& aDestination )
{
    if( aDestination.IsEmpty() )
    {
        wxLogTrace( tracePathsAndFiles, "%s: destination is empty.", __func__ );
        return false;
    }

    wxString templateFile = wxT( "kicad." ) + ProjectFileExtension;

    wxString kicad_pro_template = aSearchS.FindValidPath( templateFile );

    if( !kicad_pro_template )
    {
        wxLogTrace( tracePathsAndFiles, "%s: template file '%s' not found using search paths.",
                    __func__, TO_UTF8( templateFile ) );

        wxFileName  templ( wxStandardPaths::Get().GetDocumentsDir(),
                            wxT( "kicad" ), ProjectFileExtension );

        if( !templ.IsFileReadable() )
        {
            wxString msg = wxString::Format( _(
                    "Unable to find \"%s\" template config file." ),
                    GetChars( templateFile ) );

            DisplayErrorMessage( nullptr, _( "Error copying project file template" ), msg );

            return false;
        }

        kicad_pro_template = templ.GetFullPath();
    }

    wxLogTrace( tracePathsAndFiles, "%s: using template file '%s' as project file.",
                __func__, TO_UTF8( kicad_pro_template ) );

    // Verify aDestination can be created. if this is not the case, wxCopyFile
    // will generate a crappy log error message, and we *do not want* this kind
    // of stupid message
    wxFileName fn( aDestination );
    bool success = true;

    if( fn.IsOk() && fn.IsDirWritable() )
        success = wxCopyFile( kicad_pro_template, aDestination );
    else
    {
        wxLogMessage( _( "Cannot create prj file \"%s\" (Directory not writable)" ),
                      GetChars( aDestination) );
        success = false;
    }

    return success;
}
Esempio n. 26
0
int WriteDSPDIORestartStateMachine(int s)
{
  unsigned short command = 1;
    /* Finally, we reset the state machine pointer to the beginning of the 
     * new command, which is at offset 1 from the beginning of the buffer */
    if (!WriteDSPData(DSPDIO, DSP_SRAM, digioinfo.statemachineptr[s], 1, &command)) {
        sprintf(tmpstring, "Error writing digital IO state machine pointer to master DSP");
        DisplayErrorMessage(tmpstring);
	return 0;
    }
    return 1;
}
Esempio n. 27
0
unsigned short ReadStateMachinePtr(int number)
  /* returns the current offset for the specified state machine */
{
    unsigned short command[1];
    if (!ReadDSPData(DSPDIO, DSP_SRAM, digioinfo.statemachineptr[number], 
          1, command)) {
	sprintf(tmpstring, "Error reading Digital IO state machine pointer ");
	DisplayErrorMessage(tmpstring);
	return USHRT_MAX;
    }
    return command[0];
}
Esempio n. 28
0
int SendStartDIOCommand(int s)
    /* write data to the dsp. data must contain < 24 words */
{
    unsigned short command[1];
    command[0] = 2;
    if (!WriteDSPData(DSPDIO, DSP_SRAM, digioinfo.statemachineptr[s], 1, command)) {
      sprintf(tmpstring, "Error writing digital IO state machine pointer to DIO DSP");
      DisplayErrorMessage(tmpstring);
      return 0;
    }
    fprintf(stderr, "Wrote start command to statemachine %d\n", s);
    return 1;
}
Esempio n. 29
0
bool LIB_VIEW_FRAME::ShowModal( wxString* aSymbol, wxWindow* aParent )
{
    if( aSymbol && !aSymbol->IsEmpty() )
    {
        wxString msg;
        LIB_TABLE* libTable = Prj().SchSymbolLibTable();
        LIB_ID libid;

        libid.Parse( *aSymbol, LIB_ID::ID_SCH, true );

        if( libid.IsValid() )
        {
            wxString nickname = libid.GetLibNickname();

            if( !libTable->HasLibrary( libid.GetLibNickname(), false ) )
            {
                msg.sprintf( _( "The current configuration does not include a library with the\n"
                                "nickname \"%s\".  Use Manage Symbol Libraries\n"
                                "to edit the configuration." ), nickname );
                DisplayErrorMessage( aParent, _( "Symbol library not found." ), msg );
            }
            else if ( !libTable->HasLibrary( libid.GetLibNickname(), true ) )
            {
                msg.sprintf( _( "The library with the nickname \"%s\" is not enabled\n"
                                "in the current configuration.  Use Manage Symbol Libraries to\n"
                                "edit the configuration." ), nickname );
                DisplayErrorMessage( aParent, _( "Symbol library not enabled." ), msg );
            }
            else
            {
                SetSelectedLibrary( libid.GetLibNickname() );
                SetSelectedComponent( libid.GetLibItemName() );
            }
        }
    }

    return KIWAY_PLAYER::ShowModal( aSymbol, aParent );
}
Esempio n. 30
0
int SetAOut(int aout, unsigned short level)
  /* Set the level of the specific analog output directly */
{
  unsigned short addr;
  
  addr = (aout == 1) ? DIO_AOUT1_ADDR : DIO_AOUT2_ADDR;

  if (!WriteDSPData(DSPDIO, DIO_AOUT_BASE_ADDR, addr, 1, &level)) {
      sprintf(tmpstring, "Error writing output to analog out %d", aout);
      DisplayErrorMessage(tmpstring);
      return 0;
  }
  return 1;
}