示例#1
0
vector < gd::String > GD_CORE_API GetBehaviorsOfObject(const gd::Project & project, const gd::Layout & layout, gd::String name, bool searchInGroups)
{
    bool behaviorsAlreadyInserted = false;
    vector < gd::String > behaviors;

    //Search in objects
    if ( layout.HasObjectNamed(name) ) //We check first layout's objects' list.
    {
        std::vector < gd::String > objectBehaviors = layout.GetObject(name).GetAllBehaviorNames();
        std::copy(objectBehaviors.begin(), objectBehaviors.end(), back_inserter(behaviors));
        behaviorsAlreadyInserted = true;
    }
    else if ( project.HasObjectNamed(name) ) //Then the global object list
    {
        vector < gd::String > objectBehaviors = project.GetObject(name).GetAllBehaviorNames();
        std::copy(objectBehaviors.begin(), objectBehaviors.end(), back_inserter(behaviors));
        behaviorsAlreadyInserted = true;
    }

    //Search in groups
    if ( searchInGroups )
    {
        for (std::size_t i = 0;i<layout.GetObjectGroups().size();++i)
        {
            if ( layout.GetObjectGroups()[i].GetName() == name )
            {
                //A group has the name searched
                //Verifying now that all objects have common behaviors.

                vector < gd::String > groupsObjects = layout.GetObjectGroups()[i].GetAllObjectsNames();
                for (std::size_t j = 0;j<groupsObjects.size();++j)
                {
                    //Get behaviors of the object of the group and delete behavior which are not in commons.
                	vector < gd::String > objectBehaviors = GetBehaviorsOfObject(project, layout, groupsObjects[j], false);
                	if (!behaviorsAlreadyInserted)
                	{
                	    behaviorsAlreadyInserted = true;
                	    behaviors = objectBehaviors;
                	}
                	else
                	{
                        for (std::size_t a = 0 ;a<behaviors.size();++a)
                        {
                            if ( find(objectBehaviors.begin(), objectBehaviors.end(), behaviors[a]) == objectBehaviors.end() )
                            {
                                behaviors.erase(behaviors.begin() + a);
                                --a;
                            }
                        }
                	}
                }
            }
        }
        for (std::size_t i = 0;i<project.GetObjectGroups().size();++i)
        {
            if ( project.GetObjectGroups()[i].GetName() == name )
            {
                //A group has the name searched
                //Verifying now that all objects have common behaviors.

                vector < gd::String > groupsObjects = project.GetObjectGroups()[i].GetAllObjectsNames();
                for (std::size_t j = 0;j<groupsObjects.size();++j)
                {
                    //Get behaviors of the object of the group and delete behavior which are not in commons.
                	vector < gd::String > objectBehaviors = GetBehaviorsOfObject(project, layout, groupsObjects[j], false);
                	if (!behaviorsAlreadyInserted)
                	{
                	    behaviorsAlreadyInserted = true;
                	    behaviors = objectBehaviors;
                	}
                	else
                	{
                        for (std::size_t a = 0 ;a<behaviors.size();++a)
                        {
                            if ( find(objectBehaviors.begin(), objectBehaviors.end(), behaviors[a]) == objectBehaviors.end() )
                            {
                                behaviors.erase(behaviors.begin() + a);
                                --a;
                            }
                        }
                	}
                }
            }
        }
    }

    return behaviors;
}
示例#2
0
gd::String GD_CORE_API GetTypeOfObject(const gd::Project & project, const gd::Layout & layout, gd::String name, bool searchInGroups)
{
    gd::String type;

    //Search in objects
    if ( layout.HasObjectNamed(name) )
        type = layout.GetObject(name).GetType();
    else if ( project.HasObjectNamed(name) )
        type = project.GetObject(name).GetType();

    //Search in groups
    if ( searchInGroups )
    {
        for (std::size_t i = 0;i<layout.GetObjectGroups().size();++i)
        {
            if ( layout.GetObjectGroups()[i].GetName() == name )
            {
                //A group has the name searched
                //Verifying now that all objects have the same type.

                vector < gd::String > groupsObjects = layout.GetObjectGroups()[i].GetAllObjectsNames();
                gd::String previousType = groupsObjects.empty() ? "" : GetTypeOfObject(project, layout, groupsObjects[0], false);

                for (std::size_t j = 0;j<groupsObjects.size();++j)
                {
                    if ( GetTypeOfObject(project, layout, groupsObjects[j], false) != previousType )
                        return ""; //The group has more than one type.

                }

                if ( !type.empty() && previousType != type )
                    return ""; //The group has objects of different type, so the group has not any type.

                type = previousType;
            }
        }
        for (std::size_t i = 0;i<project.GetObjectGroups().size();++i)
        {
            if ( project.GetObjectGroups()[i].GetName() == name )
            {
                //A group has the name searched
                //Verifying now that all objects have the same type.

                vector < gd::String > groupsObjects = project.GetObjectGroups()[i].GetAllObjectsNames();
                gd::String previousType = groupsObjects.empty() ? "" : GetTypeOfObject(project, layout, groupsObjects[0], false);

                for (std::size_t j = 0;j<groupsObjects.size();++j)
                {
                    if ( GetTypeOfObject(project, layout, groupsObjects[j], false) != previousType )
                        return ""; //The group has more than one type.

                }

                if ( !type.empty() && previousType != type )
                    return ""; //The group has objects of different type, so the group has not any type.

                type = previousType;
            }
        }
    }

    return type;
}