| Graphic Components > Equipment Component > Equipment Component Services > Relative Positioning |
Relative Positioning |
INDEX
PREVIOUS
NEXT
|
An equipment object has a hierarchical structure: a shelf can contain cards, which can contain ports and LEDs, thus defining parent-child relationships. When positioning objects as children of other objects, relative positioning is applied instead of regular positioning.
Regular positioning applies to root objects (parents), and is based on the component; it may change from one application to another. In contrast, relative positioning applies to child objects and is based on the position of the parent object; this relative position remains the same, regardless of the position of the parent in the component.
The supported parent objects are the following:
IltShelf. The positioning of child objects is based on slots.
IltCardCarrier. The positioning of child objects is based on slots.
IltCard. The positioning of child objects is based on (x,y) coordinates.
Shelves and card carriers are containers for card objects that are positioned based on the available slots. A card can occupy one or more slots in the container.
To position a card inside a shelf or a card carrier, use the IlpShelfItemPosition class (instance of IlpPosition). This class allows you to define the slot index and spanning, so that the card can spread over more than one slot.
The class IlpShelfItemPosition has four attributes:
xIndex defines the x coordinate of the slot.
yIndex defines the y coordinate of the slot.
xSpan defines the spanning over x.
ySpan defines the spanning over y.
For the special case of card carriers, yIndex is always equal to 0 and ySpan is always equal to 1.0.
Shelves support an array of slots, referenced by two indices (xIndex and yIndex), while card carriers support slots referenced by a single index (xIndex). The spanning attributes of IlpShelfItemPosition define by how much the card spans over the neighboring slots: a value of 1.0 means no spanning at all; a value of 2.0 means that the next slot is fully occupied; a value of 1.5 means that the next slot is partially occupied (50%).
| Note |
| One slot cannot hold more than one object, even if it is only partially occupied. |
The following code gives an example of relative positioning of cards inside a shelf. (It assumes that a data source is connected to the equipment component.)
// Creates a shelf business object IltShelf shelf = new IltShelf(3, 60, 3, 60, 0); // Sets its view position to point (50, 50) shelf.setPosition(new IlpPoint(50, 50)); // Creates a card business object IltCard card = new IltCard((IltObjectState)null, "card"); // Sets its relative position to index x = 0, spanning over by 1.8 // and index y = 1, spanning over by 1.2. card.setPosition(new IlpShelfItemPosition(0, 1, 1.8f, 1.2f)); // Sets the relationship between card and shelf dataSource.setParent(card, shelf); // Adds objects to the data source dataSource.addObject(shelf); dataSource.addOject(card);
The graphic result looks like this:
The XML file corresponding to Figure 3.2 is the following:
<cplData xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation = "ilog/cpl/schema/data.xsd"> <addObject id="shelf" container="true"> <class>ilog.tgo.model.IltShelf</class> <attribute name="slotSizes" javaClass="ilog.cpl.equipment.IlpSlotSizes"> <width> <value>60</value> <value>60</value> <value>60</value> </width> <height> <value>60</value> <value>60</value> <value>60</value> </height> </attribute> <attribute name="position" javaClass="ilog.cpl.graphic.IlpPoint"> <x>50</x> <y>50</y> </attribute> </addObject> <addObject id="card" container="true"> <class>ilog.tgo.model.IltCard</class> <parent>shelf</parent> <attribute name="name">card</attribute> <attribute name="position" javaClass="ilog.cpl.graphic.views.IlpShelfItemPosition"> <xIndex>0</xIndex> <yIndex>1</yIndex> <xSpan>1.8</xSpan> <ySpan>1.2</ySpan> </attribute> </addObject> </cplData>
The following code gives an example of relative positioning of cards inside a card carrier. (It assumes that a data source is connected to the equipment component.)
// Creates a card carrier business object IltCardCarrier carrier = new IltCardCarrier((IltObjectState)null, 3); // Sets its position and shape carrier.setPosition(new IlpShelfItemPosition(50, 50, 100, 200)); // Creates a card business object IltCard card = new IltCard((IltObjectState)null, ""); // Sets its relative position to index x = 0, spanning over by 1.8 card.setPosition(new IlpShelfItemPosition(0, 0, 1.8f, 0)); // Sets the relationship between card and card carrier dataSource.setParent(card, carrier); // Adds objects to the data source dataSource.addObject(carrier); dataSource.addOject(card);
The graphic result looks like this:
The XML file corresponding to Figure 3.3 is the following:
<cplData xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation = "ilog/cpl/schema/data.xsd"> <addObject id="carrier" container="true"> <class>ilog.tgo.model.IltCardCarrier</class> <attribute name="slotCount">3</attribute> <attribute name="position" javaClass="ilog.cpl.graphic.views.IlpShelfItemPosition"> <x>50</x> <y>50</y> <width>100</width> <height>200</height> </attribute> </addObject> <addObject id="card" container="true"> <class>ilog.tgo.model.IltCard</class> <parent>carrier</parent> <attribute name="name">card</attribute> <attribute name="position" javaClass="ilog.cpl.graphic.views.IlpShelfItemPosition"> <xIndex>0</xIndex> <yIndex>0</yIndex> <xSpan>1.8</xSpan> <ySpan>0</ySpan> </attribute> </addObject> </cplData>
Cards are containers for ports and LEDs. The top left corner of a card defines the origin for the relative positioning of ports and LEDs on the card. In other words, the child objects are placed at (x,y) pixels from the top left corner of the card.
This positioning system is dependent on the direction of the card. Usually, cards are oriented in a direction set to top. If this direction was set to right, the top right corner of the card would become the origin for positioning the child objects. If the card was oriented in the direction bottom, the (x,y) origin would be the lower right corner.
The IlpRelativePoint class, an instance of IlpPosition, is used to position a port or LED inside a card. IlpRelativePoint defines two attributes corresponding respectively to the horizontal (x) and vertical (y) distance from the container (x,y) origin (which has the position (0,0)).
The following code gives an example of the relative positioning of a port or LED inside a card. (It assumes that a data source is connected to the equipment component.)
// Creates a card business object
IltCard card = new IltCard((IltObjectState)null, "card");
// Sets its position and shape
card.setPosition(new IlpShelfItemPosition(50, 50, 50, 100));
// Creates a LED business object
IltLed led = new IltLed("", IltLed.Type.Rectangular);
// Sets its relative position, which is (10, 10) from the xy origin
led.setPosition(new IlpRelativePoint(10, 10));
// Sets the relationship between LED and card
dataSource.setParent(led, card);
// Adds objects to the data source
dataSource.addObject(card);
dataSource.addObject(led);
The graphic result looks like this:
The XML file corresponding to Figure 3.4 is the following:
<cplData xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation = "ilog/cpl/schema/data.xsd"> <addObject id="card" container="true"> <class>ilog.tgo.model.IltCard</class> <attribute name="name">card</attribute> <attribute name="position" javaClass="ilog.cpl.graphic.views.IlpShelfItemPosition"> <x>50</x> <y>50</y> <width>50</width> <height>100</height> </attribute> </addObject> <addObject id="led"> <class>ilog.tgo.model.IltLed</class> <parent>card</parent> <attribute name="type">Rectangular</attribute> <attribute name="position" javaClass="ilog.cpl.graphic.IlpRelativePoint"> <x>10</x> <y>10</y> </attribute> </addObject> </cplData>
| Copyright © 1987-2007 ILOG S.A. All rights reserved. Documentation homepage. All rights reserved. Legal terms. | PREVIOUS NEXT |