void SimulationBar::forEachSimulator(boost::function<void(SimulatorItem* simulator)> callback, bool doSelect)
{
    MessageView* mv = MessageView::instance();
    /*
      ItemList<SimulatorItem> simulators =
      ItemTreeView::mainInstance()->selectedItems<SimulatorItem>();
    */
    ItemList<SimulatorItem> simulators =
        ItemTreeView::mainInstance()->selectedItems<SimulatorItem>();

    if(simulators.empty()){
        simulators.extractChildItems(RootItem::instance());
        if(simulators.empty()){
            mv->notify(_("There is no simulator item."));
        } else  if(simulators.size() > 1){
            simulators.clear();
            mv->notify(_("Please select a simulator item to simulate."));
        } else {
            if(doSelect){
                ItemTreeView::instance()->selectItem(simulators.front());
            }
        }
    }

    typedef map<WorldItem*, SimulatorItem*> WorldToSimulatorMap;
    WorldToSimulatorMap worldToSimulator;

    for(int i=0; i < simulators.size(); ++i){
        SimulatorItem* simulator = simulators.get(i);
        WorldItem* world = simulator->findOwnerItem<WorldItem>();
        if(world){
            WorldToSimulatorMap::iterator p = worldToSimulator.find(world);
            if(p == worldToSimulator.end()){
                worldToSimulator[world] = simulator;
            } else {
                p->second = 0; // skip if multiple simulators are selected
            }
        }
    }

    for(int i=0; i < simulators.size(); ++i){
        SimulatorItem* simulator = simulators.get(i);
        WorldItem* world = simulator->findOwnerItem<WorldItem>();
        if(!world){
            mv->notify(format(_("%1% cannot be processed because it is not related with a world."))
                       % simulator->name());
        } else {
            WorldToSimulatorMap::iterator p = worldToSimulator.find(world);
            if(p != worldToSimulator.end()){
                if(!p->second){
                    mv->notify(format(_("%1% cannot be processed because another simulator"
                                        "in the same world is also selected."))
                               % simulator->name());
                } else {
                    callback(simulator);
                }
            }
        }
    }
}
Exemple #2
0
bool MonsterType::createChildLoot(Container* parent, const LootBlock& lootBlock)
{
	LootItems::const_iterator it = lootBlock.childLoot.begin();
	if(it == lootBlock.childLoot.end())
		return true;

	ItemList items;
	for(; it != lootBlock.childLoot.end() && !parent->full(); ++it)
	{
		items = createLoot(*it);
		if(items.empty())
			continue;

		for(ItemList::iterator iit = items.begin(); iit != items.end(); ++iit)
		{
			Item* tmpItem = *iit;
			if(Container* container = tmpItem->getContainer())
			{
				if(createChildLoot(container, *it))
					parent->__internalAddThing(tmpItem);
				else
					delete container;
			}
			else
				parent->__internalAddThing(tmpItem);
		}
	}

	return !parent->empty();
}
Exemple #3
0
DropList::DropList (Window &win, const ItemList &items_, size_t default_select)
	: Control (win)
	, FocusColorControl (win)
	, items (items_.empty () ? ItemList (1) : items_)
	, select (default_select < items_.size () ? default_select : 0)
{
}
Item_spawn_data::ItemList Item_group::create(int birthday, RecursionList &rec) const
{
    ItemList result;
    if (type == G_COLLECTION) {
        for(prop_list::const_iterator a = items.begin(); a != items.end(); ++a) {
            if(rng(0, 99) >= (*a)->probability) {
                continue;
            }
            ItemList tmp = (*a)->create(birthday, rec);
            result.insert(result.end(), tmp.begin(), tmp.end());
        }
    } else if (type == G_DISTRIBUTION) {
        int p = rng(0, sum_prob - 1);
        for(prop_list::const_iterator a = items.begin(); a != items.end(); ++a) {
            p -= (*a)->probability;
            if (p >= 0) {
                continue;
            }
            ItemList tmp = (*a)->create(birthday, rec);
            result.insert(result.end(), tmp.begin(), tmp.end());
            break;
        }
    }
    if (with_ammo && !result.empty()) {
        it_gun *maybe_gun = dynamic_cast<it_gun *>(result.front().type);
        if (maybe_gun != NULL) {
            item ammo(default_ammo(maybe_gun->ammo), birthday);
            // TODO: change the spawn lists to contain proper references to containers
            ammo = ammo.in_its_container();
            result.push_back(ammo);
        }
    }
    return result;
}
void KinematicFaultCheckerImpl::apply()
{
    bool processed = false;
        
    ItemList<BodyMotionItem> items = ItemTreeView::mainInstance()->selectedItems<BodyMotionItem>();
    if(items.empty()){
        mes.notify(_("No BodyMotionItems are selected."));
    } else {
        for(size_t i=0; i < items.size(); ++i){
            BodyMotionItem* motionItem = items.get(i);
            BodyItem* bodyItem = motionItem->findOwnerItem<BodyItem>();
            if(!bodyItem){
                mes.notify(str(fmt(_("%1% is not owned by any BodyItem. Check skiped.")) % motionItem->name()));
            } else {
                mes.putln();
                mes.notify(str(fmt(_("Applying the Kinematic Fault Checker to %1% ..."))
                               % motionItem->headItem()->name()));
                
                dynamic_bitset<> linkSelection;
                if(selectedJointsRadio.isChecked()){
                    linkSelection = LinkSelectionView::mainInstance()->linkSelection(bodyItem);
                } else if(nonSelectedJointsRadio.isChecked()){
                    linkSelection = LinkSelectionView::mainInstance()->linkSelection(bodyItem);
                    linkSelection.flip();
                } else {
                    linkSelection.resize(bodyItem->body()->numLinks(), true);
                }
                
                double beginningTime = 0.0;
                double endingTime = motionItem->motion()->getTimeLength();
                std::numeric_limits<double>::max();
                if(onlyTimeBarRangeCheck.isChecked()){
                    TimeBar* timeBar = TimeBar::instance();
                    beginningTime = timeBar->minTime();
                    endingTime = timeBar->maxTime();
                }
                
                int n = checkFaults(bodyItem, motionItem, mes.cout(),
                                    positionCheck.isChecked(),
                                    velocityCheck.isChecked(),
                                    collisionCheck.isChecked(),
                                    linkSelection,
                                    beginningTime, endingTime);
                
                if(n > 0){
                    if(n == 1){
                        mes.notify(_("A fault has been detected."));
                    } else {
                        mes.notify(str(fmt(_("%1% faults have been detected.")) % n));
                    }
                } else {
                    mes.notify(_("No faults have been detected."));
                }
                processed = true;
            }
        }
    }
}
Exemple #6
0
void MonsterType::dropLoot(Container* corpse)
{
	ItemList items;
	for(LootItems::const_iterator it = lootItems.begin(); it != lootItems.end() && !corpse->full(); ++it)
	{
		items = createLoot(*it);
		if(items.empty())
			continue;

		for(ItemList::iterator iit = items.begin(); iit != items.end(); ++iit)
		{
			Item* tmpItem = *iit;
			if(Container* container = tmpItem->getContainer())
			{
				if(createChildLoot(container, *it))
					corpse->__internalAddThing(tmpItem);
				else
					delete container;
			}
			else
				corpse->__internalAddThing(tmpItem);
		}
	}

	corpse->__startDecaying();
	uint32_t ownerId = corpse->getCorpseOwner();
	if(!ownerId)
		return;

	Player* owner = g_game.getPlayerByGuid(ownerId);
	if(!owner)
		return;

	LootMessage_t message = lootMessage;
	if(message == LOOTMSG_IGNORE)
		message = (LootMessage_t)g_config.getNumber(ConfigManager::LOOT_MESSAGE);

	if(message < LOOTMSG_PLAYER)
		return;

	std::stringstream ss;
	ss << "Loot of " << nameDescription << ": " << corpse->getContentDescription() << ".";
	if(owner->getParty() && message > LOOTMSG_PLAYER)
		owner->getParty()->broadcastMessage((MessageClasses)g_config.getNumber(ConfigManager::LOOT_MESSAGE_TYPE), ss.str());
	else if(message == LOOTMSG_PLAYER || message == LOOTMSG_BOTH)
		owner->sendTextMessage((MessageClasses)g_config.getNumber(ConfigManager::LOOT_MESSAGE_TYPE), ss.str());
}
void MultiAffine3SeqGraphView::onItemSelectionChanged(const ItemList<MultiAffine3SeqItem>& items)
{
    if(items.empty()){
        return;
    }

    if(itemInfos.size() == items.size()){
        bool unchanged = true;
        int i=0;
        for(list<ItemInfo>::iterator it = itemInfos.begin(); it != itemInfos.end(); ++it){
            if(it->item != items[i++]){
                unchanged = false;
                break;
            }
        }
        if(unchanged){
            return;
        }
    }
            
    itemInfos.clear();

    for(size_t i=0; i < items.size(); ++i){
        BodyItemPtr bodyItem = items[i]->findOwnerItem<BodyItem>();
        if(bodyItem){
            itemInfos.push_back(ItemInfo());
            list<ItemInfo>::iterator it = --itemInfos.end();
            it->item = items[i];
            it->seq = it->item->seq();
            it->bodyItem = bodyItem;

            it->connections.add(it->item->sigUpdated().connect(
                                    bind(&MultiAffine3SeqGraphView::onDataItemUpdated, this, it)));

            it->connections.add(it->item->sigDetachedFromRoot().connect(
                                    bind(&MultiAffine3SeqGraphView::onDataItemDetachedFromRoot, this, it)));
        }
    }

    updateBodyItems();
    setupGraphWidget();
}
void GraphViewBaseImpl::onItemSelectionChanged(const ItemList<>& allItems)
{
    ItemList<> items = self->extractTargetItems(allItems);

    if(items.empty()){
        return;
    }

    if(itemInfos.size() == items.size()){
        bool unchanged = true;
        int i=0;
        for(list<ItemInfo>::iterator it = itemInfos.begin(); it != itemInfos.end(); ++it){
            if(it->item != items[i++]){
                unchanged = false;
                break;
            }
        }
        if(unchanged){
            return;
        }
    }

    itemInfos.clear();

    for(size_t i=0; i < items.size(); ++i){

        itemInfos.push_back(ItemInfo(this));
        list<ItemInfo>::iterator it = --itemInfos.end();
        it->item = items[i];

        ConnectionSet& connections = itemToConnectionSetMap[it->item.get()];
        connections.add(it->item->sigUpdated().connect(
                            boost::bind(&GraphViewBaseImpl::onItemUpdated, this, it)));

        connections.add(it->item->sigDetachedFromRoot().connect(
                            boost::bind(&GraphViewBaseImpl::onItemDetachedFromRoot, this, it)));
    }

    updatePartList();
}
Exemple #9
0
Item_spawn_data::ItemList Item_group::create(int birthday, RecursionList &rec) const
{
    ItemList result;
    if (type == G_COLLECTION) {
        for( const auto &elem : items ) {
            if( rng( 0, 99 ) >= ( elem )->probability ) {
                continue;
            }
            ItemList tmp = ( elem )->create( birthday, rec );
            result.insert(result.end(), tmp.begin(), tmp.end());
        }
    } else if (type == G_DISTRIBUTION) {
        int p = rng(0, sum_prob - 1);
        for( const auto &elem : items ) {
            p -= ( elem )->probability;
            if (p >= 0) {
                continue;
            }
            ItemList tmp = ( elem )->create( birthday, rec );
            result.insert(result.end(), tmp.begin(), tmp.end());
            break;
        }
    }
    if (with_ammo && !result.empty()) {
        const auto t = result.front().type;
        if( t->gun ) {
            const std::string ammoid = default_ammo( t->gun->ammo );
            if ( !ammoid.empty() ) {
                item ammo( ammoid, birthday );
                // TODO: change the spawn lists to contain proper references to containers
                ammo = ammo.in_its_container();
                result.push_back( ammo );
            }
        }
    }
    return result;
}
Exemple #10
0
void GSMediaViewImpl::onItemCheckToggled(Item* item, bool isChecked)
{
    if(TRACE_FUNCTIONS){
        cout << "GSMediaViewImpl::onItemCheckToggled()" << endl;
    }
    
    MediaItem* mediaItem = dynamic_cast<MediaItem*>(item);
    if(mediaItem){
        ItemList<MediaItem> checkedItems = ItemTreeView::mainInstance()->checkedItems<MediaItem>();
        MediaItemPtr targetItem;
        if(!checkedItems.empty()){
            targetItem = checkedItems.front();
        }
        if(targetItem != currentMediaItem){

            if(currentMediaItem){
                stopPlayback();
            }
            currentMediaItem = targetItem;

            if(!currentMediaItem || currentMediaItem->mediaURI().empty()){
                g_object_set(G_OBJECT(playbin), "uri", "", NULL);
                timeBarConnections.disconnect();

            } else {
                GstPad* pad = gst_element_get_static_pad(GST_ELEMENT(videoSink), "sink");
                gst_pad_add_probe(pad, GST_PAD_PROBE_TYPE_BUFFER,
                                  (GstPadProbeCallback)videoPadBufferProbeCallback, this, NULL);
                gst_object_unref(pad);
                if(self->winId()){
                    activateCurrentMediaItem();
                }
            }
        }
    }
}
void WidgetDataBase::loadPlugins()
{
    typedef QMap<QString, int> NameIndexMap;
    typedef QList<QDesignerWidgetDataBaseItemInterface*> ItemList;
    typedef QMap<QString, QDesignerWidgetDataBaseItemInterface*> NameItemMap;
    typedef QSet<QString> NameSet;
    // 1) create a map of existing custom classes
    NameIndexMap existingCustomClasses;
    NameSet nonCustomClasses;
    const int count = m_items.size();
    for (int i = 0; i < count; i++)    {
        const QDesignerWidgetDataBaseItemInterface* item =  m_items[i];
        if (item->isCustom() && !item->isPromoted())
            existingCustomClasses.insert(item->name(), i);
        else
            nonCustomClasses.insert(item->name());
    }
    // 2) create a list plugins
    ItemList pluginList;
    const QDesignerPluginManager *pm = m_core->pluginManager();
    foreach(QDesignerCustomWidgetInterface* c, pm->registeredCustomWidgets())
        pluginList += createCustomWidgetItem(c, pm->customWidgetData(c));

    // 3) replace custom classes or add new ones, remove them from existingCustomClasses,
    // leaving behind deleted items
    unsigned replacedPlugins = 0;
    unsigned addedPlugins = 0;
    unsigned removedPlugins = 0;
    if (!pluginList.empty()) {
        ItemList::const_iterator cend = pluginList.constEnd();
        for (ItemList::const_iterator it = pluginList.constBegin();it != cend; ++it )  {
            QDesignerWidgetDataBaseItemInterface* pluginItem = *it;
            const QString pluginName = pluginItem->name();
            NameIndexMap::iterator existingIt = existingCustomClasses.find(pluginName);
            if (existingIt == existingCustomClasses.end()) {
                // Add new class.
                if (nonCustomClasses.contains(pluginName)) {
                    designerWarning(tr("A custom widget plugin whose class name (%1) matches that of an existing class has been found.").arg(pluginName));
                } else {
                    append(pluginItem);
                    addedPlugins++;
                }
            } else {
                // replace existing info
                const int existingIndex = existingIt.value();
                delete m_items[existingIndex];
                m_items[existingIndex] = pluginItem;
                existingCustomClasses.erase(existingIt);
                replacedPlugins++;

            }
        }
    }
    // 4) remove classes that have not been matched. The stored indexes become invalid while deleting.
    if (!existingCustomClasses.empty()) {
        NameIndexMap::const_iterator cend = existingCustomClasses.constEnd();
        for (NameIndexMap::const_iterator it = existingCustomClasses.constBegin();it != cend; ++it )  {
            const int index = indexOfClassName(it.key());
            if (index != -1) {
                remove(index);
                removedPlugins++;
            }
        }
    }
    if (debugWidgetDataBase)
        qDebug() << "WidgetDataBase::loadPlugins(): " << addedPlugins << " added, " << replacedPlugins << " replaced, " << removedPlugins << "deleted.";
}
Exemple #12
0
 gcc_pure
 FlarmId GetCursorId() const {
   return items.empty()
     ? FlarmId::Undefined()
     : items[GetList().GetCursorIndex()].id;
 }
bool BodyUnit::initialize(BodyItemPtr bodyItem)
{
    if(TRACE_FUNCTIONS){
        cout << "BodyUnit::initialize()" << endl;
    }

    if(bodyItem->body()->isStaticModel()){
        return false;
    }
        
    frame = 0;
    body = bodyItem->body()->duplicate();
    baseLink = 0;

    ItemList<BodyMotionItem> motionItems = bodyItem->getSubItems<BodyMotionItem>();
    if(!motionItems.empty()){
        BodyMotionItemPtr motionItem;
        // prefer the first checked item
        for(size_t i=0; i < motionItems.size(); ++i){
            if(ItemTreeView::mainInstance()->isItemChecked(motionItems[i])){
                motionItem = motionItems[i];
                break;
            }
        }
        if(!motionItem){
            motionItem = motionItems[0];
        }
        
        frameRate = motionItem->motion()->frameRate();
        qseqRef = motionItem->jointPosSeq();
        if(qseqResult){
            qseqResultBuf.reset(new MultiValueSeq(qseqResult->numParts(), 0, frameRate));
        }

        if(motionItem->hasRelativeZmpSeqItem()){
            zmpSeq = motionItem->relativeZmpSeq();
        }

        rootResultItem = motionItem->linkPosSeqItem();
        rootResultBuf.reset(new MultiAffine3Seq(1, 0, frameRate));
        rootResult = motionItem->linkPosSeq();
        rootResult->setFrameRate(frameRate);
        rootResult->setDimension(1, 1);
    }

    const YamlMapping& info = *bodyItem->body()->info();
    const YamlSequence& footLinkInfos = *info.findSequence("footLinks");
    if(footLinkInfos.isValid()){
        for(int i=0; i < footLinkInfos.size(); ++i){
            const YamlMapping& footLinkInfo = *footLinkInfos[i].toMapping();
            Link* link = body->link(footLinkInfo["link"].toString());
            Vector3 soleCenter;
            if(link && read(footLinkInfo, "soleCenter", soleCenter)){
                footLinks.push_back(link);
                footLinkOriginHeights.push_back(-soleCenter[2]);
            }
        }
    }

    if(!footLinks.empty()){
        if(zmpSeq){
            setBaseLinkByZmp(0);
        } else {
            if(bodyItem->currentBaseLink()){
                int currentBaseLinkIndex = bodyItem->currentBaseLink()->index;
                for(size_t i=0; i < footLinks.size(); ++i){
                    Link* footLink = footLinks[i];
                    if(footLink->index == currentBaseLinkIndex){
                        setBaseLink(footLink, footLinkOriginHeights[i]);
                    }
                }
            } else{
                setBaseLink(footLinks[0], footLinkOriginHeights[0]);
            }
        }
    }

    if(!baseLink){
        if(bodyItem->currentBaseLink()){
            baseLink = body->link(bodyItem->currentBaseLink()->index);
        } else {
            baseLink = body->rootLink();
        }
        fkTraverse.find(baseLink, true, true);
    }

    if(rootResult){
        Link* rootLink = body->rootLink();
        Affine3& initialPos = rootResult->at(0, 0);
        initialPos.translation() = rootLink->p;
        initialPos.linear() = rootLink->R;
    }

    return (qseqRef != 0);
}