# gcp::Fragment Class Reference

Atoms groups. More...

`#include <gcp/fragment.h>`

Inheritance diagram for gcp::Fragment:

List of all members.

## Public Member Functions

| Fragment ()
| Fragment (double x, double y)
virtual | ~Fragment ()
void | SetSelected (GtkWidget *w, int state)
void | Add (GtkWidget *w) const
void | Update (GtkWidget *w) const
xmlNodePtr | Save (xmlDocPtr xml) const
xmlNodePtr | SaveSelection (xmlDocPtr xml) const
bool | Load (xmlNodePtr node)
bool | OnChanged (bool save)
void | AnalContent ()
void | AnalContent (unsigned start, unsigned &end)
Object * | GetAtomAt (double x, double y, double z=0.)
void | Move (double x, double y, double z=0)
void | Transform2D (gcu::Matrix2D &m, double x, double y)
void | OnChangeAtom ()
Atom * | GetAtom ()
int | GetElementAtPos (unsigned start, unsigned &end)
int | GetChargePosition (FragmentAtom *pAtom, unsigned char &Pos, double Angle, double &x, double &y)
int | GetAvailablePosition (double &x, double &y)
bool | GetPosition (double angle, double &x, double &y)
bool | Validate ()
double | GetYAlign ()
bool | SetProperty (unsigned property, char const *value)
bool | Analyze ()
void | Update ()

## Detailed Description

Atoms groups.

Represents atoms groups displayed as a string. Currntly, the string is not fully parsed, so that some non sense strings might be accepted. Anyway, this will not always be the case in the future.

Definition at line 44 of file fragment.h.

## Constructor & Destructor Documentation

gcp::Fragment::Fragment | ( |  | ) |

The default constructor.

gcp::Fragment::Fragment | ( | double | x,
|  | double | y |
| ) |  |  |

Parameters:

  | x | the x position of the new fragment.
  | y | the y position of the new fragment.

Constructs a new fragment and position it. x and y are the position of the main atom or residue in the fragment.

virtual gcp::Fragment::~Fragment | ( |  | ) | `[virtual]`

The destructor.

## Member Function Documentation

void gcp::Fragment::SetSelected | ( | GtkWidget * | w,
|  | int | state |
| ) |  |  | `[virtual]`

Parameters:

  | w | the GtkWidget inside which the fragment is displayed.
  | state | the selection state of the fragment.

Used to set the selection state of the fragment inside the widget. The values of state might be gcp::SelStateUnselected, gcp::SelStateSelected, gcp::SelStateUpdating, or gcp::SelStateErasing.

Reimplemented from gcu::Object.

void gcp::Fragment::Add | ( | GtkWidget * | w | ) | const`[virtual]`

Parameters:

  | w | a GtkWidget.

Adds the representation of the fragment to the canvas widget.

Reimplemented from gcu::Object.

void gcp::Fragment::Update | ( | GtkWidget * | w | ) | const`[virtual]`

Parameters:

  | w | a GtkWidget.

Updates the representation of the fragment in the canvas widget.

Reimplemented from gcu::Object.

xmlNodePtr gcp::Fragment::Save | ( | xmlDocPtr | xml | ) | const`[virtual]`

Parameters:

  | xml | the xmlDoc used to save the document.

Used to save the fragment to the xmlDoc.

Returns:
  the xmlNode containing the serialized fragment.

Reimplemented from gcu::Object.

xmlNodePtr gcp::Fragment::SaveSelection | ( | xmlDocPtr | xml | ) | const

Parameters:

  | xml | the xmlDoc used for clipboard operations.

Saves the currently selected text inside the fragment. This method is used by the framework when editing the fragment.

Returns:
  the xmlNode containing the serialized selection.

bool gcp::Fragment::Load | ( | xmlNodePtr | node | ) | `[virtual]`

Parameters:

  | node | a pointer to the xmlNode containing the serialized fragment.

Used to load a frafment in memory. The Fragment must already exist.

Returns:
  true on succes, false otherwise.

Reimplemented from gcp::TextObject.

bool gcp::Fragment::OnChanged | ( | bool | save | ) | `[virtual]`

Parameters:

  | save | whether the text should be saved for undo/redo operations.

Called after any change in the text.

Implements gcp::TextObject.

void gcp::Fragment::AnalContent | ( |  | ) |

Analyses the whole contents.

void gcp::Fragment::AnalContent | ( | unsigned | start,
|  | unsigned & | end |
| ) |  |  |

Parameters:

  | start | the start fo the substring to parse, in bytes.
  | end | the end fo the substring to parse, in bytes.

Analyses a substring.

Object* gcp::Fragment::GetAtomAt | ( | double | x,
|  | double | y,
|  | double | z = `0.` |
| ) |  |  | `[virtual]`

Parameters:

  | x | the x coordinate
  | y | the y coordinate
  | z | the z coordinate (unused)

Returns:
  a pointer to the Atom correpoding to the symbol at or near the position defined by the coordinates passed as parameters, if any.

Reimplemented from gcu::Object.

void gcp::Fragment::Move | ( | double | x,
|  | double | y,
|  | double | z = `0` |
| ) |  |  | `[virtual]`

Parameters:

  | x | the x component of the transation vector.
  | y | the y component of the transation vector.
  | z | the z component of the transation vector.

Moves the fragment.

Reimplemented from gcp::TextObject.

void gcp::Fragment::Transform2D | ( | gcu::Matrix2D & | m,
|  | double | x,
|  | double | y |
| ) |  |  | `[virtual]`

Parameters:

  | m | the Matrix2D of the transformation.
  | x | the x component of the center of the transformation.
  | y | the y component of the center of the transformation.

Moves and/or transform an object.

Reimplemented from gcu::Object.

void gcp::Fragment::OnChangeAtom | ( |  | ) |

Called by the framework when the user changes the nature of an atom using the element tool.

Atom* gcp::Fragment::GetAtom | ( |  | ) | `[inline]`

Returns:
  the main atom, which might have a bond.

Definition at line 157 of file fragment.h.

int gcp::Fragment::GetElementAtPos | ( | unsigned | start,
|  | unsigned & | end |
| ) |  |  |

Parameters:

  | start | the start position of the atomic symbol.
  | end | the end position of the atomic symbol.

Returns:
  the atomic number corresponding to the symbol starting at start, if any, or 0. end is updated accordingly.

int gcp::Fragment::GetChargePosition | ( | FragmentAtom * | pAtom,
|  | unsigned char & | Pos,
|  | double | Angle,
|  | double & | x,
|  | double & | y |
| ) |  |  |

Parameters:

  | pAtom | the main atom which will get the local charge.
  | Pos | the approximate position of the charge.
  | Angle | the angle from horizontal left.
  | x | the x position of the charge symbol.
  | y | the y position of the charge symbol.

If pAtom is not the main atom of the fragment, 0 is returned and Pos is not updated. On input Pos can be one of POSITION_E, POSITION_N,... or 0xff, in which case, it will be given a default value. x and y are set to the position where the charge sign should be displayed usding the alignment code returned by this method.

Returns:
  a number to set how the charge symbol should be aligned relative to its position. Possible values are:
  - −2: center top.
  - −1: right.
  - 0: center.
  - 1: left.
  - 2: center bottom.

int gcp::Fragment::GetAvailablePosition | ( | double & | x,
|  | double & | y |
| ) |  |  |

Parameters:

  | x | the x position.
  | y | the y position.

This method finds an available position for drawing a charge sign or electrons and returns it as a symbolic value (see POSITION_E, POSITION_N,...). The x and y are updated so that they give the absolute position.

Returns:
  an available position.

bool gcp::Fragment::GetPosition | ( | double | angle,
|  | double & | x,
|  | double & | y |
| ) |  |  |

Parameters:

  | angle | the angle at which a charge sign should be displayed.
  | x | the x position.
  | y | the y position.

Returns:
  false and do not update the coordinates.

bool gcp::Fragment::Validate | ( |  | ) |

Validates the contents of the fragment text, and display error messages when necessary.

double gcp::Fragment::GetYAlign | ( |  | ) | `[virtual]`

Returns:
  the y coordinate at half height of a carbon atom symbol if any was present.

Reimplemented from gcu::Object.

bool gcp::Fragment::SetProperty | ( | unsigned | property,
|  | char const * | value |
| ) |  |  | `[virtual]`

Parameters:

  | property | the property id as defined in objprops.h
  | value | the property value as a string

Used when loading to set properties for the fragment. This method supports GCU_PROP_POS2D, GCU_PROP_TEXT_TEXT, GCU_PROP_FRAGMENT_ATOM_START, and GCU_PROP_FRAGMENT_ATOM_ID.

Returns:
  true if the property could be set, or if the property is not relevant, false otherwise.

Reimplemented from gcu::Object.

bool gcp::Fragment::Analyze | ( |  | ) |

Analyses the text in the fragment. This calls gcp::Fragment::AnalContent() and updates the attribute list.

void gcp::Fragment::Update | ( |  | ) |

Changes the order of the symbols if necessary when a bond is at an extremity of the fragment.

The documentation for this class was generated from the following file:

- fragment.h