File: compositeProperties.C

package info (click to toggle)
ball 1.5.0%2Bgit20180813.37fc53c-6
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 239,888 kB
  • sloc: cpp: 326,149; ansic: 4,208; python: 2,303; yacc: 1,778; lex: 1,099; xml: 958; sh: 322; makefile: 95
file content (207 lines) | stat: -rw-r--r-- 5,813 bytes parent folder | download | duplicates (4)
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
//
#include <BALL/VIEW/DIALOGS/compositeProperties.h>
#include <BALL/VIEW/KERNEL/common.h>
#include <BALL/KERNEL/PTE.h>
#include <BALL/KERNEL/residue.h>
#include <BALL/VIEW/WIDGETS/propertyEditor.h>

#include <QtWidgets/QLineEdit>
#include <QtWidgets/QPushButton>

namespace BALL
{
	namespace VIEW
	{

CompositeProperties::CompositeProperties(Composite* composite, QWidget* parent, 
																				 const char* name, bool, Qt::WindowFlags fl )
    : QDialog(parent, fl),
			Ui_CompositePropertiesData(),
			composite_(composite)
{
	setupUi(this);

	connect(buttonBox, SIGNAL(accepted()), named, SLOT(apply()));
	connect(buttonBox, SIGNAL(rejected()), named, SLOT(reset()));

	tabWidget->setTabText(0, tr("Standard"));	
	tabWidget->setTabText(1, tr("Named"));	
	named->setPropertyManager(dynamic_cast<PropertyManager*>(composite));

	setObjectName(name);
    if (RTTI::isKindOf<AtomContainer>(composite))
	{
		name_edit->setText(((AtomContainer*)composite)->getName().c_str());

        if (RTTI::isKindOf<Residue>(composite))
		{
			id_edit->setText(((Residue*)composite)->getID().c_str());
		}
	}

    if (!RTTI::isKindOf<Residue>(composite))
	{
		residues_box->setEnabled(false);
	}

    if (!RTTI::isKindOf<Atom>(composite))
	{
		atoms_box->setEnabled(false);
		return;
	}

	Atom* atom = (Atom*)composite;
	name_edit->setText(((Atom*)composite)->getName().c_str());
	
	type_edit->setText(String(atom->getType()).c_str());
	type_name_edit->setText(atom->getTypeName().c_str());
	charge_edit->setText(String(atom->getCharge()).c_str());
	formal_charge_edit->setText(String(atom->getFormalCharge()).c_str());
	radius_edit->setText(String(atom->getRadius()).c_str());
	position_edit->setText((String("(") + 
													getString_(atom->getPosition().x) + String("|") +
												 	getString_(atom->getPosition().y) + String("|") +
												 	getString_(atom->getPosition().z) + String(")")).c_str());

	force_edit->setText((String("(") + 
											 getString_(atom->getForce().x * pow(10., 12)) + String("|") +
											 getString_(atom->getForce().y * pow(10., 12)) + String("|") +
											 getString_(atom->getForce().z * pow(10., 12)) + String(")")).c_str());

	velocity_edit->setText((String("(") + 
													getString_(atom->getVelocity().x) + String("|") +
													getString_(atom->getVelocity().y) + String("|") +
													getString_(atom->getVelocity().z) + String(")")).c_str());

	vector<String> elements;
	Element element;

	for (Position nr = 1; ; nr++) 
	{
		element = PTE.getElement(nr);
		if (element == Element::UNKNOWN) break;

		elements.push_back(element.getSymbol());
	}

	sort(elements.begin(), elements.end());

	for (Position nr = 1; nr < elements.size(); nr++)
	{
		element_box->addItem(elements[nr].c_str());
	}

	String symb = atom->getElement().getSymbol();
	element_box->setCurrentIndex(element_box->findText(symb.c_str()));

}

String CompositeProperties::getString_(float data) const
{
	String result(data);
	result.trimRight("0");
	if (result.hasSuffix(".")) result.trimRight(".");
	return result;
}

CompositeProperties::~CompositeProperties()
{
  // no need to delete child widgets, Qt does it all for us
}

void CompositeProperties::accept()
{
	try
	{
        if (RTTI::isKindOf<Atom>(composite_))
		{
			Atom* atom = (Atom*) composite_;
			
			// if the atomtype has changed, we also want the atom name to be changed
			if (    (atom->getElement() != PTE[(ascii(element_box->currentText()))])
					 && (atom->getName() == ascii(name_edit->text())) 
				 )
			{
				String new_name = PTE[(ascii(element_box->currentText()))].getSymbol();
				// get the old atomnumber
				String old_name = atom->getName();
				old_name.toUpper();
				new_name += old_name.trimLeft("ABCDEFGHIJKLMNOPQRSTUVWXYZ ");
				atom->setName(new_name);
				//getMainControl()->update(*atom);
			}
			else
			{
				atom->setName(ascii(name_edit->text()));
			}
			atom->setType(ascii(type_edit->text()).toShort());
			atom->setTypeName(ascii(type_name_edit->text()));
			atom->setCharge(ascii(charge_edit->text()).toFloat());
			atom->setFormalCharge(ascii(formal_charge_edit->text()).toInt());
			atom->setRadius(ascii(radius_edit->text()).toFloat());
			atom->setElement(PTE[(ascii(element_box->currentText()))]);
			String text = ascii(position_edit->text());
			vector<String> fields;
			text.split(fields, "()|, ");
			if (fields.size() != 3)
			{
				Log.error() << (String)tr("Invalid values for position!") << std::endl;
				return;
			}

			atom->setPosition(Vector3(fields[0].toFloat(),
																fields[1].toFloat(),
																fields[2].toFloat()));

			text = ascii(velocity_edit->text());
			text.split(fields, "(),| ");
			if (fields.size() != 3)
			{
				Log.error() << (String)tr("Invalid values for velocity!") << std::endl;
				return;
			}

			atom->setVelocity(Vector3(fields[0].toFloat(),
																fields[1].toFloat(),
																fields[2].toFloat()));

			text = ascii(force_edit->text());
			text.split(fields, "(),| ");
			if (fields.size() != 3)
			{
				Log.error() << (String)tr("Invalid values for force!") << std::endl;
				return;
			}

			atom->setForce(Vector3(fields[0].toFloat(),
														 fields[1].toFloat(),
														 fields[2].toFloat()));
		}
	}
	catch(Exception::InvalidFormat&)
	{
		Log.error() << (String)tr("Invalid value, try a floating point number!") << std::endl;
		return;
	}

    if (RTTI::isKindOf<AtomContainer>(composite_))
	{
		((AtomContainer*)composite_)->setName(ascii(name_edit->text()));
	}

    if (RTTI::isKindOf<Residue>(composite_))
	{
		Residue* residue = (Residue*) composite_;
		residue->setID(ascii(id_edit->text()));
	}
	
	QDialog::accept();

	// Sending of messages to update Scene is done in MolecularControl
}

	}
}