void CtrlrPanelCanvas::handleRightClickOnMultiSelection(const MouseEvent &e)
{
	PopupMenu m;
	PopupMenu componentSubMenu = CtrlrComponentTypeManager::getComponentMenu(true);
	getEditMenu(m);
	m.addSeparator();
	m.addSubMenu ("Send to layer", getLayerMenu());
	m.addSeparator();
	m.addSubMenu ("Replace with", componentSubMenu, true);
	const int ret = m.show();

	if (ret >= 2048 && ret < 4096)
	{
		handleEditMenu (ret, e);
	}
	else if (ret >= 4096 && ret < 8192)
    {
        handleLayerMenu (ret, e);
    }
	else if (ret < 1024 && ret > 10)
	{
		String replaceWithComponentName;
		PopupMenu::MenuItemIterator iterator((const PopupMenu &)componentSubMenu);
		while (iterator.next())
		{
			if (iterator.getItem().subMenu)
			{
				PopupMenu::MenuItemIterator iterator2(*iterator.getItem().subMenu);
				while (iterator2.next())
				{
					if (iterator2.getItem().itemID == ret)
					{
						replaceWithComponentName = iterator2.getItem().text;
						break;
					}
				}
			}
		}

		if (!replaceWithComponentName.isEmpty())
		{
            Array <CtrlrComponent *> items;

            if (owner.getSelection())
                items = owner.getSelection()->getItemArray ();

			for (int i=0; i<items.size(); i++)
			{
				if (items[i])
				{
					replaceComponent (items[i]->getOwner(), replaceWithComponentName);
				}
			}
		}
	}
}
Exemplo n.º 2
0
/* process the results of a completed research topic */
void researchResult(UDWORD researchIndex, UBYTE player, bool bDisplay, STRUCTURE *psResearchFacility, bool bTrigger)
{
	RESEARCH                                       *pResearch = &asResearch[researchIndex];
	MESSAGE						*pMessage;
	//the message gets sent to console
	char						consoleMsg[MAX_RESEARCH_MSG_SIZE];

	ASSERT_OR_RETURN(, researchIndex < asResearch.size(), "Invalid research index %u", researchIndex);

	syncDebug("researchResult(%u, %u, …)", researchIndex, player);

	MakeResearchCompleted(&asPlayerResList[player][researchIndex]);

	//check for structures to be made available
	for (unsigned short pStructureResult : pResearch->pStructureResults)
	{
		if (apStructTypeLists[player][pStructureResult] != REDUNDANT)
		{
			apStructTypeLists[player][pStructureResult] = AVAILABLE;
		}
	}

	//check for structures to be made redundant
	for (unsigned short pRedStruct : pResearch->pRedStructs)
	{
		apStructTypeLists[player][pRedStruct] = REDUNDANT;
	}

	//check for component replacement
	if (!pResearch->componentReplacement.empty())
	{
		for (auto &ri : pResearch->componentReplacement)
		{
			COMPONENT_STATS *pOldComp = ri.pOldComponent;
			replaceComponent(ri.pNewComponent, pOldComp, player);
			apCompLists[player][pOldComp->compType][pOldComp->index] = REDUNDANT;
		}
	}

	//check for artefacts to be made available
	for (auto &componentResult : pResearch->componentResults)
	{
		//determine the type of artefact
		COMPONENT_TYPE type = componentResult->compType;
		//set the component state to AVAILABLE
		int compInc = componentResult->index;
		if (apCompLists[player][type][compInc] != REDUNDANT)
		{
			apCompLists[player][type][compInc] = AVAILABLE;
		}
		//check for default sensor
		if (type == COMP_SENSOR && (asSensorStats + compInc)->location == LOC_DEFAULT)
		{
			aDefaultSensor[player] = compInc;
		}
		//check for default ECM
		else if (type == COMP_ECM && (asECMStats + compInc)->location == LOC_DEFAULT)
		{
			aDefaultECM[player] = compInc;
		}
		//check for default Repair
		else if (type == COMP_REPAIRUNIT && (asRepairStats + compInc)->location == LOC_DEFAULT)
		{
			aDefaultRepair[player] = compInc;
			enableSelfRepair(player);
		}
	}

	//check for artefacts to be made redundant
	for (auto &pRedArtefact : pResearch->pRedArtefacts)
	{
		COMPONENT_TYPE type = pRedArtefact->compType;
		apCompLists[player][type][pRedArtefact->index] = REDUNDANT;
	}

	//Add message to player's list if Major Topic
	if ((pResearch->techCode == TC_MAJOR) && bDisplay)
	{
		//only play sound if major topic
		if (player == selectedPlayer)
		{
			audio_QueueTrack(ID_SOUND_MAJOR_RESEARCH);
		}

		//check there is viewdata for the research topic - just don't add message if not!
		if (pResearch->pViewData != nullptr)
		{
			pMessage = addMessage(MSG_RESEARCH, false, player);
			if (pMessage != nullptr)
			{
				pMessage->pViewData = pResearch->pViewData;
				jsDebugMessageUpdate();
			}
		}
	}
	else if (player == selectedPlayer && bDisplay)
	{
		audio_QueueTrack(ID_SOUND_RESEARCH_COMPLETED);
	}

	if (player == selectedPlayer && bDisplay)
	{
		//add console text message
		if (pResearch->pViewData != nullptr)
		{
			snprintf(consoleMsg, MAX_RESEARCH_MSG_SIZE, _("Research completed: %s"), _(pResearch->pViewData->textMsg[0].toUtf8().c_str()));
			addConsoleMessage(consoleMsg, LEFT_JUSTIFY, SYSTEM_MESSAGE);
		}
		else
		{
			addConsoleMessage(_("Research Completed"), LEFT_JUSTIFY, SYSTEM_MESSAGE);
		}
	}

	if (psResearchFacility)
	{
		psResearchFacility->pFunctionality->researchFacility.psSubject = nullptr;		// Make sure topic is cleared
	}
	if ((bMultiPlayer || player == selectedPlayer) && bTrigger)
	{
		psCBLastResearch = pResearch;  // Fun with pointers. Throw them into some random global variable, and get Nexus to absorb them.
		CBResFacilityOwner = player;
		psCBLastResStructure = psResearchFacility;
		eventFireCallbackTrigger((TRIGGER_TYPE)CALL_RESEARCHCOMPLETED);
		psCBLastResStructure = nullptr;
		CBResFacilityOwner = -1;
		psCBLastResearch = nullptr;
	}
	triggerEventResearched(pResearch, psResearchFacility, player);
}
bool BOARD_NETLIST_UPDATER::UpdateNetlist( NETLIST& aNetlist )
{
    wxString msg;
    m_errorCount = 0;
    m_warningCount = 0;

    if( !m_isDryRun )
    {
        m_board->SetStatus( 0 );
    }

    for( int i = 0; i < (int) aNetlist.GetCount();  i++ )
    {
        COMPONENT* component = aNetlist.GetComponent( i );
        MODULE* footprint = NULL;

        msg.Printf( _( "Processing component \"%s:%s:%s\".\n" ),
                    GetChars( component->GetReference() ),
                    GetChars( component->GetTimeStamp() ),
                    GetChars( component->GetFPID().Format() ) );
        m_reporter->Report( msg, REPORTER::RPT_INFO );

        if( aNetlist.IsFindByTimeStamp() )
            footprint = m_board->FindModule( component->GetTimeStamp(), true );
        else
            footprint = m_board->FindModule( component->GetReference() );

        if( footprint )        // An existing footprint.
        {
            MODULE* newFootprint = replaceComponent( aNetlist, footprint, component );

            if( newFootprint )
                footprint = newFootprint;
        }
        else
        {
            footprint = addNewComponent( component );
        }

        if( footprint )
        {
            updateComponentParameters( footprint, component );
            updateComponentPadConnections( footprint, component );
        }
    }

    //aNetlist.GetDeleteExtraFootprints()

    if( m_deleteUnusedComponents )
        deleteUnusedComponents( aNetlist );

    if( m_deleteSinglePadNets )
        deleteSinglePadNets();

    if( !m_isDryRun )
    {
        m_commit.Push( _( "Update netlist" ) );
        m_frame->Compile_Ratsnest( NULL, false );
        m_board->GetRatsnest()->ProcessBoard();
        testConnectivity( aNetlist );
    }

    // Update the ratsnest
    m_reporter->Report( wxT( "" ), REPORTER::RPT_ACTION );
    m_reporter->Report( wxT( "" ), REPORTER::RPT_ACTION );

    msg.Printf( _( "Total warnings: %d, errors: %d." ), m_warningCount, m_errorCount );
    m_reporter->Report( msg, REPORTER::RPT_ACTION );

    if( m_errorCount )
    {
        m_reporter->Report( _( "Errors occured during the netlist update. Unless you "
                               "fix them, your board will not be consistent with the schematics." ),
                            REPORTER::RPT_ERROR );

        return false;
    }
    else
    {
        m_reporter->Report( _( "Netlist update successful!" ), REPORTER::RPT_ACTION );
    }

    return true;
}
void CtrlrPanelCanvas::handleRightClickOnComponent(const MouseEvent &e)
{
	CtrlrComponent *c = findEventComponent(e);

	if (c == 0)
		return;

	if (dynamic_cast<ResizableBorderComponent*>(e.eventComponent) == 0 && getOwner().getSelection())
	{
		getOwner().getSelection()->selectOnly (c);
	}

	PopupMenu m;
	PopupMenu componentSubMenu = CtrlrComponentTypeManager::getComponentMenu(true);
	m.addSectionHeader ("Actions");
	m.addItem (512, "Export component");
	m.addItem (513, "Lock", true, c->getProperty(Ids::componentIsLocked));

	m.addSectionHeader ("Layout");
	m.addItem (1024, "Send to back");
	m.addItem (1025, "Send to front");
	m.addSubMenu ("Send to layer", getLayerMenu());
	m.addSeparator();
	m.addSubMenu ("Replace with", componentSubMenu, true);

	m.addSeparator();
	getEditMenu(m);

	m.addSeparator();
	if (CtrlrComponentTypeManager::isGroupingComponent(c))
	{
		m.addItem (1026, "Delete with children");
		m.addItem (1027, "Copy with children");
	}

	const int ret = m.show();

	if (ret == 512)
	{
		exportSelectedComponents();
	}
	else if (ret == 513)
	{
		c->setProperty (Ids::componentIsLocked, !c->getProperty(Ids::componentIsLocked));
	}
	if (ret == 1024)
	{
		c->toBack();
		c->setProperty (Ids::componentSentBack, true);
	}
	else if (ret == 1025)
	{
		c->toFront(false);
		c->setProperty (Ids::componentSentBack, false);
	}
	else if (ret == 1026)
	{
		deleteWithChildren (c);
	}
	else if (ret == 1027)
	{
		copyWithChildren (c);
	}
	else if (ret >= 2048 && ret < 4096)
	{
		handleEditMenu (ret, e);
	}
	else if (ret >= 4096 && ret < 8192)
    {
        handleLayerMenu (ret, e);
    }
	else if (ret < 1024 && ret > 10)
	{
		PopupMenu::MenuItemIterator iterator((const PopupMenu &)componentSubMenu);
		while (iterator.next())
		{
			if (iterator.getItem().subMenu)
			{
				PopupMenu::MenuItemIterator iterator2(*iterator.getItem().subMenu);
				while (iterator2.next())
				{
					if (iterator2.getItem().itemID == ret)
					{
						if (c)
						{
							replaceComponent (c->getOwner(), iterator2.getItem().text);
							return;
						}
					}
				}
			}
		}
	}
}