1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
|
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
// $Id: label.C,v 1.10.16.1 2007-03-25 22:02:34 oliver Exp $
//
#include <BALL/VIEW/PRIMITIVES/label.h>
#include <BALL/KERNEL/atom.h>
#include <BALL/KERNEL/atomContainer.h>
#include <BALL/KERNEL/residue.h>
#include <BALL/KERNEL/PTE.h>
using namespace std;
namespace BALL
{
namespace VIEW
{
Label::Label()
: GeometricObject(),
Vertex()
{
}
Label::Label(const Label& label)
: GeometricObject(label),
Vertex(label),
text_(label.text_)
{
}
Label::~Label()
{
#ifdef BALL_VIEW_DEBUG
Log.info() << "Destructing object " << (void *)this
<< " of class " << RTTI::getName<Label>() << std::endl;
#endif
}
void Label::clear()
{
GeometricObject::clear();
Vertex::clear();
text_.clear();
}
void Label::set(const Label& label)
{
GeometricObject::set(label);
Vertex::set(label);
text_ = label.text_;
}
const Label& Label::operator = (const Label& label)
{
set(label);
return *this;
}
void Label::swap(Label& label)
{
GeometricObject::swap(label);
Vertex::swap(label);
}
bool Label::isValid() const
{
return (GeometricObject::isValid() &&
Vertex::isValid());
}
void Label::dump(ostream& s, Size depth) const
{
BALL_DUMP_STREAM_PREFIX(s);
BALL_DUMP_DEPTH(s, depth);
BALL_DUMP_HEADER(s, this, this);
BALL_DUMP_DEPTH(s, depth);
s << "Label Text: " << text_ << endl;
GeometricObject::dump(s, depth + 1);
Vertex::dump(s, depth + 1);
BALL_DUMP_STREAM_SUFFIX(s);
}
String Label::getExpandedText() const
{
if (!text_.has('%') || getComposite() == 0)
{
return text_;
}
String result;
const Atom* atom = dynamic_cast<const Atom*> (getComposite());
const AtomContainer* ac = dynamic_cast<const AtomContainer*> (getComposite());
const Residue* residue = dynamic_cast<const Residue*> (getComposite());
for (Position pos = 0; pos < text_.size(); pos++)
{
// normal text
if (text_[pos] != '%')
{
result += text_[pos];
continue;
}
pos++;
// dont step over the size of the string
if (pos == text_.size()) break;
// make it possible to escape %
if (text_[pos] == '%')
{
result += '%';
}
// name
else if (text_[pos] == 'N')
{
if (atom) result += atom->getName();
else result += ac->getName();
}
// resiude ID
else if (text_[pos] == 'I')
{
if (residue) result += residue->getID();
if (atom) result += ((Residue*)atom->getParent())->getID();
}
// atom type
else if (text_[pos] == 'T')
{
if (atom) result += String(atom->getType());
}
// atom charge
else if (text_[pos] == 'C')
{
if (atom)
{
String charge(atom->getCharge());
charge.trimRight("0");
if (charge.hasSuffix(".")) charge += '0';
result += charge;
}
}
// element
else if (text_[pos] == 'E')
{
if (atom)
{
result += atom->getElement().getSymbol();
}
}
// type name
else if (text_[pos] == 'Y')
{
if (atom)
{
result += atom->getTypeName();
}
}
} // for
return result;
} // getExpandedText
void Label::getVertices(vector<Vector3>& vertices) const
{
vertices.push_back(getVertex());
}
} // namespace VIEW
} // namespace BALL
|