2D Graphics > Managers > Basic Manager Features > Managing Objects
 
Managing Objects
This section explains how to manipulate the objects contained in a manager. It is divided as follows:
*Modifying the Geometry of Graphic Objects
*Selecting Objects
*Selection Procedures
*Managing Selected Objects
*Managing Object Properties
*Arranging Objects
Modifying the Geometry of Graphic Objects
The IlvManager class has been designed to handle a large number of graphic objects. In order to perform graphical operations efficiently (for example, redrawing part of a view, locating the objects at a given position, and so on), the manager uses a complex internal data structure where graphic objects are organized according to their geometry, that is, their bounding box. To keep this data structure up to date, the manager needs to be aware of any modification in the geometry of its graphic objects. This is why any such modification should be carried out in the following manner:
1. Take the object out of the manager list.
2. Manipulate its geometric characteristics.
3. Put the object back into the manager list.
The easiest way to do this is to use the dedicated IlvManager member functions respecting these requirements:
*IlvManager::applyToObject
*IlvManager::applyToObjects
*IlvManager::applyInside
*IlvManager::applyIntersects
*IlvManager::applyToTaggedObjects
*IlvManager::applyToSelections
Note: Do not change the size of a managed object by calling its IlvGraphic::translate or IlvGraphic::scale member functions. The manager use sophisticated data structures and an intricate indexing system for tracking the position of objects with respect to each other. You should not interfere with these mechanisms.
For simple geometric operations such as moving, translating, or reshaping, IlvManager provides the following member functions that do not need to call IlvManager::applyToObject:
*IlvManager::translateObject
*IlvManager::moveObject
*IlvManager::reshapeObject
Example: Translating an Object
The following code gets a pointer to an object named test from the manager. If this object exists, it is translated 10 pixels right and 20 pixels down, and then redrawn (fourth parameter set to IlTrue):
object = manager->getObject("test");
if (object)
manager->translateObject(object, 10, 20, IlTrue);
 
Applying Functions to Objects in a Region
In order to apply a user-defined function to objects that are located either partly or wholly within a specific region, use the following IlvManager member functions:
*IlvManager::applyInside
*IlvManager::applyIntersects
Selecting Objects
Use the following two member functions of IlvManager to handle the selection state of objects:
*IlvManager::isSelected
*IlvManager::setSelected
Example:
The following code gets a pointer to an object named test from the manager. If this object exists, it is selected (second parameter is set to IlTrue) and redrawn (third parameter set to IlTrue):
object = manager->getObject("test");
if (object)
manager->setSelected(object, IlTrue, IlTrue);
 
Selection Procedures
The IlvManager member functions involved in selection tasks are the following:
*IlvManager::applyToSelection
*IlvManager::numberOfSelections
*IlvManager::deSelectAll
*IlvManager::getSelections
*IlvManager::deleteSelections
*IlvManager::getSelection
*IlvManager::setMakeSelection
Example: Customizing Selection Handle Objects
This example shows how to attach new selection handle objects to line objects:
static IlvDrawSelection*
MakeSelection(IlvManager* manager, IlvGraphic* graphic)
{
if (graphic->isSubtypeOf("IlvLine"))
return new IlvLineHandle(manager->getDisplay(), graphic);
else
return new IlvDrawSelection(manager->getDisplay(), graphic);
}
 
The following code changes the function called to create the selection object. If the selected object is an IlvLine or an instance of a class derived from it, the manager uses the IlvLineHandle object to draw the selection:
manager->setMakeSelection(MakeSelection);
Managing Selected Objects
Selecting is a basic process for managers and most manager functions should apply to a selected list of objects. A manager selection can be thought of as a special set holding some of the managed objects. To display selected objects within a manager,  Rogue Wave® Views creates selection objects that are stored in the manager. The difference between these objects and others is that they are internally managed and cannot be manipulated.
Example: Translating the Selected Objects
The following example shows an accelerator that translates all selected objects ten pixels right and 20 pixels down. This accelerator uses the IlvManager::applyToSelections member function to translate each of the objects. Redrawing of the objects is done once at the end of the call to this method, as is done for all the apply functions, because its third parameter is set to the default value IlTrue.
static void
TranslateSelectedObjects (IlvGraphic* object, IlAny arg)
{
IlvManager* manager = (IlvManager*) arg;
manager->translateObject(object, 10, 20, IlFalse);
}
 
static void
TranslateAccelerator(IlvManager* manager, IlvView*, IlvEvent&, IlAny)
{
manager->applyToSelections(TranslateSelectedObjects, manager);
}
 
Managing Object Properties
Several member functions of the IlvManager class describe properties that are assigned to an object when it is added to a manager (for example, IlvManager::isSelectable, IlvManager::setSelectable, IlvManager::isResizeable, and so on).
You can also add specific properties to each object by means of the property-related member functions of the IlvGraphic class. These properties are application-dependent and have no effect on the manager.
IlvManager provides member functions to check whether an object has a property or to change a property of an object.
Example: Setting an Object as Unmovable
This is an example of how to set an object in a manager as unmovable:
object = manager->getObject("test");
if (object)
manager->setMoveable(object, IlFalse);
 
Arranging Objects
The IlvManager class provides member functions to help organize the layout of graphic objects.
*Grouping
*Aligning and Duplicating
Grouping
The IlvManager::group member function lets you create an IlvGraphicSet from an array of objects and put the objects from an IlvGraphicSet into the manager.
The IlvManager::unGroup member function lets you do the inverse of this.
Note:  Graphic objects grouped in a graphic set are no longer handled by the manager. The manager only sees the graphic set.
Example: Grouping Objects
This is an example of an accelerator that groups selected objects:
static void
Group(IlvManager* manager, IlvView*, IlvEvent&, IlAny)
{
if (!manager->numberOfSelections()) return;
IlvUInt n;
IlvGraphic* const* objs = manager->getSelections(n);
IlvGraphicSet* g = manager->group(n, (IlvGraphic* const*)objs);
if (g) manager->setSelected((IlvGraphic*)g, IlTrue, IlTrue);
}
 
The first line checks the number of objects and returns if no objects are selected. Then, a pointer to the selected objects is obtained using the IlvManager::getSelections member function. The next line creates the group. The new object is selected at the end of this accelerator.
Aligning and Duplicating
Some IlvManager member functions are defined to automatically align objects with respect to each other:
*IlvManager::align
*IlvManager::makeColumn
*IlvManager::makeRow
*IlvManager::sameWidth
*IlvManager::sameHeight
Another member function duplicates objects, that is, it creates a copy of the objects and inserts them into the manager:
*IlvManager::duplicate
Note: These modifications are always applied to the currently selected objects
Example: Make All Selected Objects the Same Width
This accelerator gives the width of the first selected object to all the selected objects:
static void
SameWidth(IlvManager* manager, IlvView*, IlvEvent&, IlAny)
{
manager->sameWidth(IlTrue);
}
 
The value IlTrue passed to IlvManager::sameWidth indicates that the objects are automatically redrawn.

Version 6.1
Copyright © 2016, Rogue Wave Software, Inc. All Rights Reserved.