GLG Toolkit, JavaScript Library  Version 4.6
Object Geometry and Layout

This group contains methods for positioning objects in the drawing, as well as scaling and rotating them. More...

Detailed Description

This group contains methods for positioning objects in the drawing, as well as scaling and rotating them.

It also includes the LayoutObjects method that can be used to align and distribute objects, as well as to set their width and height.

Functions

static boolean EnableAttachmentPoints (boolean state)
 Controls the use of attachment points to determine object extents when the objects are aligned. More...
 
boolean FitObject (GlgCoordType coord_type, GlgCube box, boolean keep_ratio)
 Fits the object to the specified rectangular area. More...
 
boolean LayoutObjects (GlgObject anchor, GlgLayoutType type, double distance, boolean use_box, boolean process_subobjects)
 Performs operations ranging from setting an object's width and height to aligning and layout of groups of objects. More...
 
boolean MoveObject (GlgCoordType coord_type, GlgPoint start_point, GlgPoint end_point)
 Moves an object by a move vector. More...
 
boolean MoveObjectBy (GlgCoordType coord_type, double x, double y, double z)
 Moves the object by the specified distances. More...
 
boolean MoveObjectByPoint (GlgCoordType coord_type, GlgPoint point)
 Moves the object by distances specified by the GlgPoint object. More...
 
boolean PositionObject (GlgCoordType coord_type, GlgAnchoringType anchoring, double x, double y, double z)
 Positions the object at the specified location. More...
 
boolean PositionObjectByPoint (GlgCoordType coord_type, GlgAnchoringType anchoring, GlgPoint position)
 Positions the object at the location specified by the GlgPoint object. More...
 
boolean RotateObject (GlgCoordType coord_type, GlgPoint center, double x_angle, double y_angle, double z_angle)
 Rotates the object. More...
 
boolean ScaleObject (GlgCoordType coord_type, GlgPoint center, double x_scale, double y_scale, double z_scale)
 Scales the object. More...
 
boolean TransformObject (GlgObject xform, GlgCoordType coord_type, GlgObject parent)
 ADVANCED: Transforms all control points of the object with an arbitrary transformation. More...
 

Function Documentation

◆ EnableAttachmentPoints()

static boolean EnableAttachmentPoints ( boolean  state)
static

Controls the use of attachment points to determine object extents when the objects are aligned.

Parameters
stateSpecifies if attachment points should be used in addition to the control points to determine object extents when the objects are aligned using control points.
Returns
The previous state of the setting.

◆ FitObject()

boolean FitObject ( GlgCoordType  coord_type,
GlgCube  box,
boolean  keep_ratio 
)

Fits the object to the specified rectangular area.

Parameters
coord_typeSpecifies the coordinate system for interpreting coordinates of the area to fit to:
  • SCREEN_COORD - the coordinates are interpreted as screen pixels.
  • OBJECT_COORD - the coordinates are interpreted as the GLG world coordinates of the object, which includes all transformations applied to the object.
  • PARENT_COORD - the coordinates are interpreted as the GLG world coordinates of the parent object, which includes all transformations applied to the parent, but excludes transformations attached to the object.
boxThe area to fit the object to.
  • If the Z extent of the box is 0, 2D fitting is performed and the object is not scaled in the Z dimension.
  • If the Z extent is not 0, 3D fitting is performed.
keep_ratioControls how the object's X/Y ratio is handled:
  • true to preserve the object's X/Y ratio by using the smallest of the required X and Y scale factors for both directions.
  • false to use different scale factors for X and Y scaling to fit the object to the box more precisely.
Returns
Success or failure status.

This method transforms the object to fit it to the area defined by the box parameter, calculating new control point values. The object's hierarchy must be set up to use this method.

◆ LayoutObjects()

boolean LayoutObjects ( GlgObject  anchor,
GlgLayoutType  type,
double  distance,
boolean  use_box,
boolean  process_subobjects 
)

Performs operations ranging from setting an object's width and height to aligning and layout of groups of objects.

This method can be invoked on an object or a group of objects to perform the requested operations upon them.

Parameters
anchorThe anchor object for alignment operations. If null, the first encountered object in the specified alignment direction is used.
typeThe type of the layout action to perform:
  • ALIGN_LEFT - aligns the left edge of elements within the group with the left edge of the anchor element.
  • ALIGN_RIGHT - aligns the right edge of elements within the group with the right edge of the anchor element.
  • ALIGN_HCENTER - aligns the center of elements within the group with the center of the anchor element horizontally.
  • ALIGN_TOP - aligns the top edge of elements within the group with the top edge of the anchor element.
  • ALIGN_BOTTOM - aligns the bottom edge of elements within the group with the bottom edge of the anchor element.
  • ALIGN_VCENTER - aligns the center of elements within the group with the center of the anchor element vertically.
  • SET_EQUAL_VSIZE - sets the height of elements within the group to the height of the anchor.
  • SET_EQUAL_HSIZE - sets the width of elements within the group to the width of the anchor.
  • SET_EQUAL_SIZE - sets the width and height of elements within the group to the width and height of the anchor.
  • SET_EQUAL_VDISTANCE - equally distributes the group's elements in vertical direction as measured by the distance between their centers.
  • SET_EQUAL_HDISTANCE - equally distributes the group's elements in horizontal direction as measured by the distance between their centers.
  • SET_EQUAL_VSPACE - equally distributes space gaps between group's elements in vertical direction.
  • SET_EQUAL_HSPACE - equally distributes space gaps between group's elements in horizontal direction.
  • SET_VSIZE - sets the height of the object or of all objects in the group to the value specified by the distance parameter:
    • if process_subobjects=false, sets the object's height
    • if process_subobjects=true, sets the height of all elements within the group.
  • SET_HSIZE - sets the width of the object or of all objects in the group to the value specified by the distance parameter:
    • if process_subobjects=false, sets the object's width
    • if process_subobjects=true, sets the width of all elements within the group.
  • SET_VDISTANCE - sets the vertical distance between centers of the group's elements to a value specified by the distance parameter.
  • SET_HDISTANCE - sets the horizontal distance between centers of the group's elements to a value specified by the distance parameter.
  • SET_VSPACE - sets the space gaps between group's elements in vertical direction to a value specified by the distance parameter.
  • SET_HSPACE - sets space gaps between group's elements in horizontal direction to a value specified by the distance parameter.
distanceThe distance in screen coordinates for positioning objects, it is interpreted depending on the layout action.
use_boxControls how the objects extent is determined:
  • true to use the object's real bounding box to align objects
  • false to use the object's control points to determine the object's extent, which could be different from the real bounding box for objects such as a Text object with a single conrol point.
process_subobjectsControls how to apply the layout action if the object is a group:
  • true to apply the action to all objects contained in the group
  • false the apply the action (such as SET_HSIZE) to the group itself.
Returns
  • false if errors were encountered during the requested layout action,
  • true if the requested action was successfully executed.

The object's hierarchy must be set up to use this method.

◆ MoveObject()

boolean MoveObject ( GlgCoordType  coord_type,
GlgPoint  start_point,
GlgPoint  end_point 
)

Moves an object by a move vector.

Parameters
coord_typeSpecifies the coordinate system for interpreting the move vector:
  • SCREEN_COORD - the move vector is considered to be defined using screen pixels.
  • OBJECT_COORD - the move vector coordinates are interpreted in the GLG world coordinates of the object, which includes all transformations applied to the object.
  • PARENT_COORD - the move vector coordinates are interpreted in the GLG world coordinates of the parent object, which includes all transformations applied to the parent, but excludes transformations attached to the object.
start_pointThe start point of the move vector. If null, (0,0,0) is used as the start point.
end_pointThe end point of the move vector.
Returns
Success or failure status.

This method moves an object's control points by the distance defined by the move vector, calculating new control point values. The object's hierarchy must be set up to use this method.

◆ MoveObjectBy()

boolean MoveObjectBy ( GlgCoordType  coord_type,
double  x,
double  y,
double  z 
)

Moves the object by the specified distances.

Parameters
coord_typeSpecifies the coordinate system for interpreting move distances:
  • SCREEN_COORD - move distances are considered to be in screen pixels.
  • OBJECT_COORD - move distances are considered to be in the GLG world coordinates of the object, which includes all transformations applied to the object.
  • PARENT_COORD - move distances are considered to be in the GLG world coordinates of the parent object, which includes all transformations applied to the parent, but excludes transformations attached to the object.
x,y,zThe X, Y and Z move distances.
Returns
Success or failure status.

This method moves the object's control points by the specified X, Y and Z distances, calculating new control point values. The object's hierarchy must be set up to use this method.

◆ MoveObjectByPoint()

boolean MoveObjectByPoint ( GlgCoordType  coord_type,
GlgPoint  point 
)

Moves the object by distances specified by the GlgPoint object.

Parameters
coord_typeSpecifies the coordinate system for interpreting move distances:
  • SCREEN_COORD - the distances is considered to be defined using screen pixels.
  • OBJECT_COORD - the distances are interpreted in the GLG world coordinates of the object, which includes all transformations applied to the object.
  • PARENT_COORD - the coordinates are interpreted in the GLG world coordinates of the parent object, which includes all transformations applied to the parent, but excludes transformations attached to the object.
pointGlgPoint containing X, Y and Z move distance values.
Returns
Success or failure status.

This method moves an object's control points by the distances specified as the X, Y and Z parameters of the GlgPoint, calculating new control point values. The object's hierarchy must be set up to use this method.

◆ PositionObject()

boolean PositionObject ( GlgCoordType  coord_type,
GlgAnchoringType  anchoring,
double  x,
double  y,
double  z 
)

Positions the object at the specified location.

Parameters
coord_typeSpecifies the coordinate system for interpreting postion coordinates:
  • SCREEN_COORD - the coordinates are interpreted as screen pixels.
  • OBJECT_COORD - the coordinates are interpreted as the GLG world coordinates of the object, which includes all transformations applied to the object.
  • PARENT_COORD - the coordinates are interpreted as the GLG world coordinates of the parent object, which includes all transformations applied to the parent, but excludes transformations attached to the object.
anchoring

Specifies what part of the object's bounding box will be anchored at the specified position. It is formed as a bitwise OR of the horizontal anchoring constant (HLEFT, HCENTER or HRIGHT) with the vertical anchoring constants (VTOP, VCENTER or VBOTTOM).

For example, using ( VTOP | HLEFT ) causes the upper left corner of the object's bounding box to be positioned at the specified location.

x,y,zThe X, Y and Z coordinates of the desired object position.
Returns
Success or failure status.

This method positions the object, calculating new control point values. The object's hierarchy must be set up to use this method.

◆ PositionObjectByPoint()

boolean PositionObjectByPoint ( GlgCoordType  coord_type,
GlgAnchoringType  anchoring,
GlgPoint  position 
)

Positions the object at the location specified by the GlgPoint object.

Parameters
coord_typeSpecifies the coordinate system for interpreting postion coordinates:
  • SCREEN_COORD - the coordinates are interpreted as screen pixels.
  • OBJECT_COORD - the coordinates are interpreted as the GLG world coordinates of the object, which includes all transformations applied to the object.
  • PARENT_COORD - the coordinates are interpreted as the GLG world coordinates of the parent object, which includes all transformations applied to the parent, but excludes transformations attached to the object.
anchoring

Specifies what part of the object's bounding box will be anchored at the specified position. It is formed as a bitwise OR of the horizontal anchoring constant (HLEFT, HCENTER or HRIGHT) with the vertical anchoring constants (VTOP, VCENTER or VBOTTOM).

For example, using ( VTOP | HLEFT ) causes the upper left corner of the object's bounding box to be positioned at the specified location.

positionGlgPoint containing x, y and z coordinates of the desired object position.
Returns
Success or failure status.

This method positions the object, calculating new control point values. The object's hierarchy must be set up to use this method.

◆ RotateObject()

boolean RotateObject ( GlgCoordType  coord_type,
GlgPoint  center,
double  x_angle,
double  y_angle,
double  z_angle 
)

Rotates the object.

Parameters
coord_typeSpecifies the coordinate system for interpreting the rotation's center:
  • SCREEN_COORD - the rotation's center coordinates are interpreted as screen pixels.
  • OBJECT_COORD - the rotation's center coordinates are interpreted as the GLG world coordinates of the object, which includes all transformations applied to the object.
  • PARENT_COORD - the rotation's center coordinates are interpreted as the GLG world coordinates of the parent object, which includes all transformations applied to the parent, but excludes transformations attached to the object.
centerThe center of rotation. If the parameter is null, the object is rotated relative to the center of its bounding box.
x_angle,y_angle,z_angleThe X, Y and Z rotation angles in degrees. Only one rotation at a time can be performed (only one angle can have non-zero value).
Returns
Success or failure status.

This method rotates the object's control points by the specified rotation angle and relative to the specified center, calculating new control point values. The object's hierarchy must be set up to use this method.

◆ ScaleObject()

boolean ScaleObject ( GlgCoordType  coord_type,
GlgPoint  center,
double  x_scale,
double  y_scale,
double  z_scale 
)

Scales the object.

Parameters
coord_typeSpecifies the coordinate system for interpreting the scale center:
  • SCREEN_COORD - the scale center coordinates are interpreted as screen pixels.
  • OBJECT_COORD - the scale center coordinates are interpreted as the GLG world coordinates of the object, which includes all transformations applied to the object.
  • PARENT_COORD - the scale center coordinates are interpreted as the GLG world coordinates of the parent object, which includes all transformations applied to the parent, but excludes transformations attached to the object.
centerThe center of scaling. If the parameter is null, the object is scaled relative to the center of its bounding box.
x_scale,y_scale,z_scaleThe X, Y and Z scaling factors. Use the same value for all three factors to scale the object uniformly in all dimensions.
Returns
Success or failure status.

This method scales the object's control points by the specified scale factors and relative to the specified center, calculating new control point values. The object's hierarchy must be set up to use this method.

◆ TransformObject()

boolean TransformObject ( GlgObject  xform,
GlgCoordType  coord_type,
GlgObject  parent 
)

ADVANCED: Transforms all control points of the object with an arbitrary transformation.

The method can be invoked on a drawable object or on a G data object representing a control point.

Parameters
xformThe transformation (an XFORM object) to be applied to the object's points
coord_typeThe coordinate system to interpret the transformation in:
  • SCREEN_COORD - parameters of the transformation are considered to be in screen pixels.
    For example, this may be used to move the object by the number of screen pixels as defined by the mouse move. The start and end coordinates of the mouse move can be supplied using the TRANSLATE_XF transformation as the xform parameter.
  • OBJECT_COORD - transformation parameters are interpreted in the GLG world coordinates of the object, which includes all transformations applied to the object.
  • PARENT_COORD - transformation parameters are interpreted in the GLG world coordinates of the parent object, which includes all transformations applied to the parent, but excludes transformations attached to the object.
parentThe object's parent. It is required if coord_type=PARENT_COORD, or if the object is a G data object representing a control point. null may be passed in all other cases.
Returns
Success or failure status.

This method applies the given transformation to an object's control points, calculating new control point values. The object's hierarchy must be set up to use this method.