Exemplo n.º 1
0
void MolecularFileDialog::onNotify(Message *message)
{
    if (RTTI::isKindOf<ControlSelectionMessage>(message))
	{
		checkMenu(*getMainControl());
	}
}
Exemplo n.º 2
0
		void EditMode::atomPropertiesTriggered_()
		{
			if (scene_->getCurrentAtom() == 0) return;

			CompositeProperties as(scene_->getCurrentAtom(), scene_);
			bool apply = as.exec();
			scene_->deselect();

			if (apply) getMainControl()->update(*scene_->getCurrentAtom(), true);
		}
Exemplo n.º 3
0
		void PickingMode::pickParent_(const QPoint& p)
		{
			ignore_pick_ = true;
			list<GeometricObject*> objects;
			scene_->pickObjects(p, objects);

			if (objects.empty()) return;

			Composite* composite = (Composite*)(**objects.begin()).getComposite();
			if (composite == 0) return;

			Composite* to_select = 0;
			Atom* atom = dynamic_cast<Atom*>(composite);
			if (atom != 0)
			{
				to_select = atom->getParent();
			}
			else
			{
				Bond* bond = dynamic_cast<Bond*>(composite);
				if (bond!= 0)
				{
					to_select = (Composite*)bond->getFirstAtom()->getParent();
				}
				else
				{
					to_select = composite;
				}
			}

			if (to_select != 0)
			{
				if (to_select->isSelected())
				{
					getMainControl()->deselectCompositeRecursive(to_select, true);
				}
				else
				{
					getMainControl()->selectCompositeRecursive(to_select, true);
				}
				getMainControl()->update(*to_select, true);
			}
		}
Exemplo n.º 4
0
		void LabelDialog::accept()
		{
			list<Composite*> selection = getMainControl()->getMolecularControlSelection();

			// no selection present => return
			if (selection.empty()) return;

			Representation* rep = new Representation;
			rep->setProperty(Representation::PROPERTY__ALWAYS_FRONT);
			rep->setModelType(MODEL_LABEL);

			LabelModel* model = new LabelModel;
			model->setText(ascii(text_box->currentText()));
			model->setColor(custom_color_);
			model->setFont(font_);

			if (		 all_items->isChecked()) model->setMode(LabelModel::ONE_LABEL);
			else if (		every_atom->isChecked()) model->setMode(LabelModel::ALL_ATOMS);
			else if (every_residue->isChecked()) model->setMode(LabelModel::ALL_RESIDUES);
			else if (	  every_item->isChecked()) model->setMode(LabelModel::ALL_ITEMS);

			rep->setModelProcessor(model);

			// process all objects in the selection list
			list<Composite*>::const_iterator list_it = selection.begin();
			list<const Composite*> composites;

			for (; list_it != selection.end(); ++list_it)
			{
				composites.push_back(*list_it);
			}

			rep->setComposites(composites);

			getMainControl()->insert(*rep);
			getMainControl()->update(*rep);

			text_box->addItem(text_box->currentText());

			setStatusbarText(tr("Label added."));
		}
Exemplo n.º 5
0
void PythonSettings::fileSelected()
{
	QString s = QFileDialog::getOpenFileName(
								0,
								tr("Choose a Startup Python Script"),
								getMainControl()->getWorkingDir().c_str(),
								tr("Python scripts") + " (*.py)");

	if (s == QString::null) return;
	script_edit->setText(s);
	QWidget::update();
}
Exemplo n.º 6
0
		void LabelDialog::onNotify(Message *message)
		{
#ifdef BALL_VIEW_DEBUG
			Log.error() << "LabelDialog " << this << " onNotify " << message << std::endl;
#endif
			// selection => store last selection for later processing
            if (RTTI::isKindOf<ControlSelectionMessage>(message))
			{
				ControlSelectionMessage* selection = RTTI::castTo<ControlSelectionMessage>(*message);
				// disabled apply button, if selection is empty
				const bool filled = !selection->getSelection().empty();
				apply_button_->setEnabled(filled);
				checkMenu(*getMainControl());
			}
		}
Exemplo n.º 7
0
		bool HelpViewer::showDocumentationForObject()
		{
			QPoint point = QCursor::pos();
			QWidget* widget = qApp->widgetAt(point);

			if (widget == 0) return false;
			
			/////////////////////////////////////////////
			// show help for widget
			/////////////////////////////////////////////
			if (showHelpFor(widget)) 
			{
				exitWhatsThisMode();
				return true;
			}

			/////////////////////////////////////////////
			// show help for menu entry 
			/////////////////////////////////////////////
			
			// catch block is needed on windows, 
			// otherwise we get a uncaught exception, no idea why
			// maybe the library has a bug under windows
			try
			{
                if (RTTI::isKindOf<QMenu>(widget))
				{
					ignore_event_ = true;

					// nothing happens if we dont have a docu entry
					QAction* id = getMainControl()->getLastHighLightedMenuEntry();

					if (docu_entries_.has(id))
					{
						showHelp(docu_entries_[id]);
						exitWhatsThisMode();
						return true;
					}
				}
			}
			catch(...)
			{
			}

			return false;
		}
Exemplo n.º 8
0
		void EditMode::setFormalCharge_()
		{
			scene_->deselect();

			QAction* action = dynamic_cast<QAction*>(sender());
			if (action == 0) return;
			String string = ascii(action->text());
			try
			{
				Index fc = string.toInt();
				if (scene_->getCurrentAtom() != 0) {
					scene_->getCurrentAtom()->setFormalCharge(fc);
					getMainControl()->update(*scene_->getCurrentAtom(), true);
				}
			}
			catch(...)
			{
				BALLVIEW_DEBUG;
			}
		}
Exemplo n.º 9
0
		void DownloadPDBFile::downloadFinished()
		{
			String id = ascii(pdbId->currentText());
			String url = prefix_;
			url += id;
			url += (checkbox_biounit->isChecked()) ? biounit_suffix_ : suffix_;
			Log.info() << "Url: " << url << std::endl; 

			if (current_reply_->error() != QNetworkReply::NoError)
			{
				Log.error() << "Could not download PDBFile! Reason given was \"" + (String)(current_reply_->errorString()) + "\""<< std::endl;
				setStatusbarText("Could not download PDBFile! Reason given was \"" + (String)(current_reply_->errorString()) + "\"");

				error_ = true;
			}
			else
			{
				System *system = new System();

				try {
					String temp_filename = VIEW::createTemporaryFilename();
					
					QFile outfile(temp_filename.c_str());
					outfile.open(QIODevice::ReadWrite);

					outfile.write(current_reply_->readAll());
					outfile.close();
					
					// if we download the biological unit, we have to decompress the pdb.gz file
					if (checkbox_biounit->isChecked())
					{
						String unzipped_filename = VIEW::createTemporaryFilename();	
						std::ifstream file(temp_filename.c_str(), std::ios_base::in | std::ios_base::binary);
						boost::iostreams::filtering_streambuf<boost::iostreams::input> in;
						in.push(boost::iostreams::gzip_decompressor());
						in.push(file);
					
						PDBFile pdb_file(unzipped_filename, std::ios::out | std::ios::binary);
						boost::iostreams::copy(in, pdb_file);
						pdb_file.reopen(std::ios::in);
						
						// the individual units are organized as MODELs
						// by default PDBFile only reads the first MODEL
						pdb_file.selectAllModels();
						pdb_file >> *system;
						pdb_file.close();
						
						removeFile_(unzipped_filename);
					}
					else
					{
						PDBFile pdb_file(temp_filename);
						pdb_file >> *system;
						pdb_file.close();
					}

					removeFile_(temp_filename);

					if (system->countAtoms() == 0)
					{
						delete system;
						show();
						setStatusbarText(tr("Could not fetch the given PDBFile"), true);
						return;
					}
					else
					{
						setStatusbarText(String("read ") + String(system->countAtoms()) + " atoms for:  " + id, true);
					}

					if (system->getName() == "")
					{
						system->setName(ascii(pdbId->currentText()));
					}

					system->setProperty("FROM_FILE", url);
					close();
					pdbId->clearEditText();
					getMainControl()->insert(*system, ascii(pdbId->currentText()));
					
					notify_(new CompositeMessage(*system, CompositeMessage::CENTER_CAMERA));
					
					download->setDefault(true);
					pdbId->setFocus();
				}
				catch(...)
Exemplo n.º 10
0
		bool HelpViewer::eventFilter(QObject*, QEvent* e) 
		{
			/////////////////////////////////////////////
			// Prevent opening a menu entry when obtaining whats this info for a menu entry
			/////////////////////////////////////////////
			if (ignore_event_)
			{
				if (e->type() == QEvent::MouseButtonRelease)
				{
					ignore_event_ = false;
					getMainControl()->menuBar()->hide();
					getMainControl()->menuBar()->show();
					return true;
				}

				return false;
			}
			
			/////////////////////////////////////////////
			// Show Documentation if F1 is pressed
			/////////////////////////////////////////////
			if (e->type() == QEvent::KeyPress)
			{
				QKeyEvent* ke = (QKeyEvent*) e;
				if (ke->key() != Qt::Key_F1 ||
 						ke->modifiers() != Qt::NoModifier)
				{
					return false;
				}

				if (ke->key() == Qt::Key_Escape) 
				{
					if (whats_this_mode_)
					{
						exitWhatsThisMode();
						return true;
					}
				}

				showDocumentationForObject();
				return true;
			}

			/////////////////////////////////////////////
			// now react only in whats this mode and if a mouse button is pressed
			/////////////////////////////////////////////
			if (!whats_this_mode_ ||
					e->type() != QEvent::MouseButtonPress)
			{
				return false;
			}

			/////////////////////////////////////////////
			// exit whats this mode with right mouse click
			/////////////////////////////////////////////
			QMouseEvent* me = (QMouseEvent*) e;
			if (me->button() != Qt::LeftButton)
			{
				exitWhatsThisMode();
				return true;
			}

			if (me->button() != Qt::LeftButton) return false;
		
			QPoint point = QCursor::pos();
			QWidget* widget = qApp->widgetAt(point);
			QMenu* menu = 0;
			QMenuBar* menu_bar = 0;
			
			if (widget != 0) 
			{
				menu     = dynamic_cast<QMenu*>(widget);
				menu_bar = dynamic_cast<QMenuBar*>(widget);
			}

			if (menu_bar != 0) return false;

			bool shown_docu = showDocumentationForObject();

			if (menu != 0)
			{
				if (shown_docu)
				{
					menu->hide();
				}
				else
				{
					return false;
				}
			}

			return true;
		}
Exemplo n.º 11
0
void TestFramework::timeOut()
{
	if (is_command_line_ && 
			max_run_time_ != FLT_MAX &&
			runtime_.getClockTime() > max_run_time_)
	{
		abortTest();
		getMainControl()->quit(-1);
		return;
	}

	// if MainControl is busy: send event only if MC was also busy when we recorded it
	if (getMainControl()->isBusy() && !event_busy_)
	{
		return;
	}

	if (!getMainControl()->isBusy())
	{
		getMainControl()->processEvents(1000);
	}

	if (timer_.getClockTime() < time_) return;

#ifdef BALL_PYTHON_SUPPORT		
	if (python_line_ != "")
	{
		PyWidget* pyw = 0;

		pyw = PyWidget::getInstance(0);
		if (pyw == 0) 
		{
			Log.error() << "Can not exec Python in macro since no Python support available" << std::endl;
		}

		else
		{
			if (expected_result_ == "")
			{
				pyw->runString(python_line_);
			}
			else
			{
				bool ok;
				String result = PyInterpreter::run(python_line_, ok);
				// trim newline
				if (result.size()) result.truncate(result.size()-1);
				if (!ok || result != expected_result_)
				{
					Log.error() << "------------------------------------------------" << std::endl;
					Log.error() << "Test failed in "
											<< filename_ << " " << line_nr_ << ":";
					if (!ok) Log.error() << "(call failed)";
					Log.error() << std::endl 
					            << python_line_ << std::endl 
					            << result << "!=" 
					            << expected_result_<< "!" << std::endl;
					errors_++;
				}
			}
		}

		processEvent_();
		return;
	}
#endif

	if (type_ == 0) 
	{
		test_running_ = false;
		return;
	}

	if (our_type_ != SHORTCUT && widget_ == 0)
	{
		BALLVIEW_DEBUG;
		return;
	}

	QEvent* e = 0;

	bool hide = false;

	if (our_type_ == MOUSE)
	{
		// circumvent problems with context menus:	
		if ((Qt::MouseButton) button_ == Qt::RightButton)
		{
			/*
			QWidget* w = (QWidget*)widget_->parent();
			while (w != 0)
			{
				DockWidget* dw = dynamic_cast<DockWidget*>(w);
				if (dw != 0)
				{
					QCursor::setPos(QPoint(x_,y_));
					dw->showGuestContextMenu(QPoint(x_,y_));
					processEvent_();
					return;
				}

				w = (QWidget*)w->parent();
			}
			*/
		}

		bool was_visible = widget_->isVisible();
		widget_->show();
		QPoint local = widget_->mapFromGlobal(QPoint(x_,y_));
		QPoint org_p = local;
		if (local.x() >= widget_->width())  local.setX((int)(widget_->width() * 0.9));
		if (local.y() >= widget_->height()) local.setY((int)(widget_->height() * 0.9));
		if (local.x() <= 0) local.setX((int)(widget_->width() * 0.1));
		if (local.y() <= 0) local.setY((int)(widget_->height() * 0.1));
#ifdef BALL_VIEW_DEBUG
		if (org_p != local)
		{
			Log.error() << ascii(widget_->objectName()) << " " << org_p.x() 
									<< " " << org_p.y() << std::endl;
		}
#endif
		e = new MyMouseEvent((QMouseEvent::Type)type_, 
												local,
												(Qt::MouseButton)button_, 
												(Qt::MouseButtons)buttons_, 
												(Qt::KeyboardModifier)modifiers_);
		
		if ((Qt::MouseButton) button_ == Qt::LeftButton &&
				RTTI::isKindOf<QMenu>(*widget_) && 
				!was_visible)
		{
			hide = true;
		}
		
    QCursor::setPos(QPoint(x_,y_));
	}
	else if (our_type_ == KEY)
	{
		// workaround for capitalized keys:
		if (modifiers_ == Qt::ShiftModifier)
		{
			if (button_ != Qt::Key_Shift)
			{
				QKeySequence seq(button_);
				QTest::keyClicks(widget_, seq.toString());
			}
		}
		else
		{
			QTest::keyClick(widget_, (Qt::Key)button_, (Qt::KeyboardModifiers)modifiers_);
		}
	}
	else if (our_type_ == SHORTCUT)
	{
		if (action_ != 0)
		{
			action_->trigger();
		}
	}


	if (e != 0)
	{
		reinterpret_cast<QSpontaneKeyEvent*>(e)->setSpontaneous();
    if (!qApp->notify(widget_, e))
		{
 			BALLVIEW_DEBUG
		}
		delete e;
	}
Exemplo n.º 12
0
bool TestFramework::eventFilter(QObject* obj, QEvent* e) 
{
	if (test_running_)
	{
//   		if (e == last_event_) return false;
//   		last_event_ = e;

		bool stop = false;
		if (e->type() == QEvent::KeyPress)
		{
			QKeyEvent* ke = dynamic_cast<QKeyEvent*>(e);
			// pause macro if pause key is pressed
			if (ke->key() == Qt::Key_Pause) stop = true;
			else if (ke->key() == Qt::Key_X && ke->modifiers() == Qt::AltModifier)
			{
				// if a user presses Alt-X: quit immediately
				abortTest();
				getMainControl()->quit(0);
				return true;
			}
		}
		else if (e->type() == QEvent::MouseButtonPress ||
						 e->type() == QEvent::MouseButtonRelease)
		{
			// abort macro if user presses mouse button:
			if (!RTTI::isKindOf<MyMouseEvent>(*e) && e->spontaneous())
			{
 				stop = true;
			}
		}
		else
		{
			return false;
		}

		if (stop)
		{
			abortTest();
			qApp->installEventFilter(this);
			return true;
		}

		return false;
	}
	
	// if test is paused and pause key is pressed->resume macro
	if (!recording_ && e->type() == QEvent::KeyPress && lines_.size() > 0)
	{
		QKeyEvent* ke = dynamic_cast<QKeyEvent*>(e);
		if (ke->key() == Qt::Key_Pause)
		{
			processEvent_();
			timer_.reset();
			timer_.start();
			test_running_ = true;
			thread_.start();
			return true;
		}

		return false;
	}

	if (!recording_) return false;

	if (!RTTI::isKindOf<QKeyEvent>(*e) &&
			!RTTI::isKindOf<QMouseEvent>(*e) &&
			!RTTI::isKindOf<QShortcutEvent>(*e))
	{
		return false;
	}

	if (e->type() == QEvent::ShortcutOverride) return false;
 	if (e->type() == QEvent::KeyRelease) return false;
	QMouseEvent* 		me = dynamic_cast<QMouseEvent*>(e);
	QKeyEvent* 			ke = dynamic_cast<QKeyEvent*>(e);
	QShortcutEvent* se = dynamic_cast<QShortcutEvent*>(e);

	if (ke != 0 && 
			ke->type() == QEvent::KeyPress &&
			ke->key() == Qt::Key_Pause)
	{
		stopTest();
		return false;
	}

	///////////////////////////////////////////////////////
	// uniquely identify the active widget:
	// walk up the QObject tree and collect all names of QWidgets
	///////////////////////////////////////////////////////
	
	// take the sending object
 	QObject* o = obj;
	QObject* parent = 0;
	x_ = y_ = 0;

	// for mouse events: take widget under the mouse cursor
	if (me != 0) 
	{
		widget_ = qApp->widgetAt(me->globalPos());
		if (widget_ == 0) return false;
		if (widget_->objectName() == "" &&
				widget_->actions().size() == 0)
		{
			widget_ = dynamic_cast<QWidget*>(widget_->parent());
			if (widget_ == 0 || widget_->objectName() == "") return false;
		}
		o = widget_;

		QPoint global = me->globalPos();
		// if we can not get local coordinates: abort
 		QPoint local = widget_->mapFromGlobal(global);
		if (local.x() < 0 || local.y() < 0 ||
				local.x() >= widget_->width() || local.y() >= widget_->height()) 
		{
			return false;
		}

		// for menus: take the position of the action under the cursor
		QMenu* menu = dynamic_cast<QMenu*>(o);
		if (menu)
		{
			QAction* action = menu->actionAt(local);
			if (action != 0)
			{
				o = action;
				parent = menu;
				QRect rect = menu->actionGeometry(action);
				local.rx() -= rect.x();
				local.ry() -= rect.y();

				if (rect.width() == 0 || rect.height() == 0) return false;
				x_ = local.x();
				y_ = local.y();
			}
		}

		if (x_ == 0 && y_ == 0)
		{
			// take the position as percent of the widget's actual size
			if (widget_->width() == 0 || widget_->height() == 0) return false;
			x_ = local.x();
			y_ = local.y();
		}
	}

	String names;
	while (o != 0)
	{
		String name = ascii(o->objectName());
		if (name == "")
		{
			QWidget* widget = dynamic_cast<QWidget*>(o);
			if (widget != 0)
			{
				QList<QAction*> actions = widget->actions();
				if (actions.size() == 1)
				{
					name = ascii((**actions.begin()).objectName());
				}
			}
		}
		else
		{
			// if a parent has more childs with the same name: add a suffix with the number
			if (!parent) parent = o->parent();
			if (parent != 0)
			{
				QList<QWidget*> childs = parent->findChildren<QWidget*>(name.c_str());
				if (childs.size() > 1)
				{
					Position pos = 0;
					QList<QWidget*>::iterator wit = childs.begin();
					for (; wit != childs.end(); wit++)
					{
						if (*wit == o)
						{
							name += "#";
							name += String(pos);
							break;
						}

						pos++;
					}
				}
			}
		}

		if (name != "") names = name + "|" + names;
		o = o->parent();
	}


	String event_string;
	event_string += String((int)e->type()) + "|";
	event_string += String(getMainControl()->isBusy()) + "|";

	if (me != 0)
	{
		if (me->button() == Qt::NoButton &&
				!switch_move->isChecked() && 
				me->type() == QEvent::MouseMove &&	
				widget_ == last_widget_)
		{
			return false;
		}

 		last_widget_ = widget_;

		event_string += String((int)MOUSE) + "|";
		event_string += String((int) me->modifiers()) + "|";
		event_string += String((int) me->button()) + "|";
		event_string += String((int) me->buttons()) + "|";
		event_string += String(x_) + "|";
		event_string += String(y_) + "|";

		// prevent mouse move events with same position
		if (event_string == last_event_string_ &&
				names 			 == last_names_)
		{
			return false;
		}
	}
	else if (ke != 0)
	{
		// prevent accepting key events that are resend further up in the widget tree
		if (timer_.getClockTime() < 0.01) return false;

		int m = (int) ke->modifiers();
		// sometimes Qt sends nonsense Key messages
		if (m > (int)(Qt::AltModifier | Qt::ControlModifier | Qt::ShiftModifier)) return false;

		event_string += String((int)KEY) + "|";
		event_string += String(m);
		event_string += "|";
		event_string += String(ke->key()) + "|";
	}
	else if (se != 0)
	{
		event_string += String((int)SHORTCUT) + "|";
		event_string += String(se->shortcutId()) + "|";
		event_string += ascii(se->key().toString()) + "|";
	}

	float time = timer_.getClockTime();
	timer_.reset();

	outfile_ << "I°"
					 << time << "°"
					 << names << "°"
					 << event_string << std::endl;

	last_event_string_ = event_string;
	last_names_  			 = names;

	return false;
}
Exemplo n.º 13
0
		void StageSettings::apply()
		{
			if (stage_ == 0) return;
			stage_->setBackgroundColor(color_button->getColor());

			Scene::setMouseSensitivity(slider_->value() + 1);
			Scene::setMouseWheelSensitivity(wheel_slider_->value() + 1);

			stage_->setEyeDistance((float)(eye_distance_slider->value() / 10.0));
			stage_->setFocalDistance((float)(focal_distance_slider->value() / 10.));
			
			//TODO integration of textures
			//if (environement_map->isChecked())
			//{
			//   stage->setTextureUpDirection(getTextureUpDirection_()));	
			//   String filenname = ascii(texture_file_edit->text()));
			//   if (filename is valid?)
			//     stage->setTexture(filename));
			//}

			stage_->setSwapSideBySideStereo(swap_sss_button->isChecked());

			if (fog_box->isChecked())
			{
				stage_->setFogIntensity(fog_slider->value());
			}
			else
			{
				stage_->setFogIntensity(0);
			}

			Camera::ProjectionMode projection_mode = radioButton_perspectiveProjection->isChecked() ? Camera::PERSPECTIVE
			                                                                                        : Camera::ORTHOGRAPHIC;
			stage_->getCamera().setProjectionMode(projection_mode);

			Scene::setShowLightSources(show_lights_->isChecked());
			Scene::setAnimationSmoothness(((float)animation_smoothness->value()) / 10.0);
			scene_->setOffScreenRendering(offscreen_group->isChecked(), resolution_factor->value());

			ColorRGBA color;
			color = capping_color_button->getColor();
			color.setAlpha(255 - capping_transparency->value());
			ClippingPlane::getCappingColor() = color;

			scene_->setFPSEnabled(show_fps->isChecked());
			scene_->setPreview(use_preview->isChecked());

			// use vertex buffers ?
			bool use_buffer = use_vertex_buffers->isChecked() && use_vertex_buffers->isEnabled();
			GLRenderer& renderer = scene_->getGLRenderer();

			if (use_buffer != renderer.vertexBuffersEnabled() &&
					getMainControl()->getRepresentationManager().getNumberOfRepresentations() > 0)
			{
				getMainControl()->setStatusbarText(tr("Because of change in usage of vertex buffer, all Representations have to be deleted!"), true);
				// remove representations
				RepresentationManager& pm = getMainControl()->getRepresentationManager();
				Size nr = pm.getNumberOfRepresentations();
				list<Representation*> reps = pm.getRepresentations();
				for (Position p = 0; p < nr; p++)
				{
					getMainControl()->remove(**reps.begin());
					reps.pop_front();
				}
			}

			renderer.enableVertexBuffers(use_buffer);
			renderer.setSmoothLines(smooth_lines_->isChecked());

			scene_->setDownsamplingFactor(downsamplingfactor_label->text().toFloat());

			if (radioButton_opengl->isChecked())
				scene_->switchRenderer(RenderSetup::OPENGL_RENDERER);
			else
				scene_->switchRenderer(RenderSetup::RTFACT_RENDERER);
		}
Exemplo n.º 14
0
		void EditMode::mouseReleaseEventImpl_(QMouseEvent* evt)
		{
			if (temp_move_)
			{
				scene_->deselect();
				temp_move_ = false;
				return;
			}

			if (last_buttons_ == Qt::RightButton)
			{
				scene_->deselect();
				return;
			}

			if (scene_->isAnimationRunning() || scene_->getMainControl()->isBusy()) return;

			// if we didnt find first atom: abort
			if (!scene_->getCurrentAtom())
			{
				scene_->deselect();
				return;
			}

			scene_->getCurrentAtom()->deselect();
			scene_->notify(new CompositeMessage(*scene_->getCurrentAtom(), CompositeMessage::DESELECTED_COMPOSITE));

			Atom* atom = scene_->getCurrentAtom();
			scene_->getClickedItems(evt->pos());

			// decide what to do... did we find an atom at all?
			if (scene_->getCurrentAtom())
			{
				// is it the atom we started with?
				if (atom == scene_->getCurrentAtom() || // workaround against crashes:
						&atom->getRoot() != &scene_->getCurrentAtom()->getRoot())
				{
					// in this case, we assume that the user does not want to set a bond
					scene_->deselect();
					return;
				}

				// we found _another_ atom: set the bond
				new Bond("Bond", *scene_->getCurrentAtom(), *atom, Bond::ORDER__SINGLE);
/*			Bond* c = new Bond("Bond", *scene_->getCurrentAtom(), *atom, Bond::ORDER__SINGLE);

				EditOperation eo(0, c, "Added bond of type single" , EditOperation::ADDED__BOND);
				undo_.push_back(eo);

				// tell about the new undo operation
				emit newEditOperation(eo);
*/
				scene_->merge(scene_->getCurrentAtom(), atom);

				// update representation
				getMainControl()->update(*atom, true);
				scene_->setStatusbarText(qApp->tr("Edit Mode", "Added a bond"));
			}
			else // no atom found -> create one
			{
				// project the new atom on the plane of the old atom
				scene_->setCurrentAtom(atom);
				Vector3 new_pos = scene_->mapViewportTo3D(evt->x(), evt->y());

				// test if the two atoms would have the same position
				if (fabs((scene_->getCurrentAtom()->getPosition() - new_pos).getLength()) < 0.02)
				{
					scene_->setStatusbarText(qApp->tr("Edit Mode", "Aborting, since both atoms would have the same location!"), true);
					return;
				}

				// build a new atom...
				int atomic_number = scene_->getEditElementType();
				String name(PTE[atomic_number].getSymbol());
				name += String(atom_number_);
				atom_number_++;
				PDBAtom* a = new PDBAtom(PTE[atomic_number], name);
				a->setPosition(new_pos);
				scene_->getCurrentAtom()->getParent()->appendChild(*a);

				//store the Operation in undo_
				Vector3 atom_position = a->getPosition();
/*
				EditOperation eo(a, NULL, (String)qApp->tr("Edit Mode", "Added atom of type ") + PTE[atomic_number].getName() + (String)qApp->tr("Edit Mode", " at position (")
						+ String(atom_position.x) + ", "
						+ String(atom_position.y) + ", "
						+ String(atom_position.z) + ")", EditOperation::ADDED__ATOM);
				undo_.push_back(eo);

				// tell about the new undo operation
				emit newEditOperation(eo);
*/
				// set the bond
				new Bond("Bond", *scene_->getCurrentAtom(), *a, Bond::ORDER__SINGLE);

				// tell about the new undo operation
				/*
				Bond* c = new Bond("Bond", *scene_->getCurrentAtom(), *a, Bond::ORDER__SINGLE);
				String bond_string = getBondOrderString_(bond_order_);
				EditOperation eo2(0, c, (String)qApp->tr("Edit Mode", "Added bond of type ") + bond_string, EditOperation::ADDED__BOND);
				undo_.push_back(eo2);
				emit newEditOperation(eo2);
				*/

				scene_->getMainControl()->update(*a->getParent(), true);
				scene_->setStatusbarText(qApp->tr("Edit Mode", "Added a bond and an atom"));
			}

			scene_->deselect();
		}
Exemplo n.º 15
0
bool MolecularFileDialog::writeFile()
{
	list<Composite*>& selection = getMainControl()->getMolecularControlSelection();

    if (selection.size() != 1 || !RTTI::isKindOf<System> (*selection.begin()))
	{
		setStatusbarText((String)tr("Not a single system selected! Aborting writing..."), true);
		return false;
	}

	const System& system = *(const System*) (*selection.begin());
	String file_name = getWorkingDir();
	file_name += FileSystem::PATH_SEPARATOR;
	file_name += system.getName();
	file_name += ".pdb";

	QString s = QFileDialog::getSaveFileName(
								0,
								tr("Choose a filename to save the selected system"),
								file_name.c_str(),
								getSupportedFileFormats().c_str());

	if (s == QString::null) return false;

	setStatusbarText((String)tr("writing file..."));

	String filename = ascii(s);
	setWorkingDirFromFilename_(filename);

	String filter(filename);
	while (filter.has(FileSystem::PATH_SEPARATOR))
	{
		filter = filter.after(FileSystem::PATH_SEPARATOR);
	}

	String filename_without_path = filter;

	while (filter.has('.'))
	{
		filter = filter.after(".");
	}

	bool result = false;
	if (filter == "PDB" || filter == "pdb" ||
			filter == "ent" || filter == "ENT" ||
			filter == "brk" || filter == "BRK")
	{
		result = writePDBFile(filename, system);
	}
	else if (filter.hasSubstring("HIN") || filter.hasSubstring("hin"))
	{
		result = writeHINFile(filename, system);
	}
	else if (filter.hasSubstring("MOL2") || filter.hasSubstring("mol2"))
	{
		result = writeMOL2File(filename, system);
	}
	else if (filter.hasSubstring("MOL") || filter.hasSubstring("mol"))
	{
		result = writeMOLFile(filename, system);
	}
	else if (filter.hasSubstring("SDF") || filter.hasSubstring("sdf"))
	{
		result = writeSDFile(filename, system);
	}	
	else if (filter.hasSubstring("AC") || filter.hasSubstring("ac"))
	{
		result = writeACFile(filename, system);
	}
	else if (filter.hasSubstring("XYZ") || filter.hasSubstring("xyz"))
	{
		result = writeXYZFile(filename, system);
	}
	else
	{
		if (filter == filename_without_path)
		{
			filename += ".pdb";
			result = writePDBFile(filename, system);
		}
		else
		{
			setStatusbarText((String)tr("Unknown file format, please set the file extension accordingly to type, aborting..."), true);
			return false;
		}
	}

	if (!result) 
	{
		return false;
	}

	setStatusbarText(String(system.countAtoms()) + " " + (String)tr("atoms written to file") + " \"" + filename + "\"", true);
	return true;
}
Exemplo n.º 16
0
		void EditMode::mousePressEventImpl_(QMouseEvent* evt)
		{
			if (scene_->isAnimationRunning() || scene_->getMainControl()->isBusy()) return;

			scene_->deselect();

			last_buttons_ = evt->buttons();

			if (evt->button() != Qt::RightButton)
			{
				//TODO: readd this
				if (//only_highlighted_ &&
						getMainControl()->getMolecularControlSelection().size() == 0)
				{
					scene_->setStatusbarText(qApp->tr("Edit Mode", "Warning: no AtomContainer highlighted"), true);
					return;
				}
			}

			scene_->getClickedItems(evt->pos());

			/////////////////////////////////////////
			// right button -> context menu
			if (evt->button() == Qt::RightButton)
			{
				if (scene_->getCurrentAtom())
				{
					scene_->getCurrentAtom()->select();
					scene_->notify(new CompositeMessage(*scene_->getCurrentAtom(), CompositeMessage::SELECTED_COMPOSITE));
				}

				if (scene_->getCurrentBond())
				{
					scene_->getCurrentBond()->select();
					Atom* a1 = (Atom*)scene_->getCurrentBond()->getFirstAtom();
					Atom* a2 = (Atom*)scene_->getCurrentBond()->getSecondAtom();
					a1->select();
					a2->select();
					scene_->notify(new CompositeMessage(*a1, CompositeMessage::SELECTED_COMPOSITE));
					scene_->notify(new CompositeMessage(*a2, CompositeMessage::SELECTED_COMPOSITE));
				}

				// we open a context menu at this point
				scene_->showContextMenu(evt->pos());
				return;
			}

			////////////////////////////////////////////////
			// left button -> add atom or move existing atom
			if (evt->button() == Qt::LeftButton && evt->modifiers() != Qt::ControlModifier)
			{
				if (scene_->getCurrentBond() != 0) return;

				if (scene_->getCurrentAtom() != 0)
				{
					getMainControl()->selectCompositeRecursive(scene_->getCurrentAtom(), true);
					mouse_pos_old_ = mouse_pos_new_ = evt->globalPos();
					temp_move_ = true;
					return;
				}

				/////////////////////////////////////////
				// insert a new atom:
				int atomic_number = scene_->getEditElementType();

				String name = PTE[atomic_number].getSymbol();
				name += String(atom_number_);
				++atom_number_;
				PDBAtom* a = new PDBAtom(PTE[atomic_number], name);
				insert_(evt->x(), evt->y(), *a);
				scene_->setCurrentAtom(a);

				//store the Operation in undo_
				Vector3 atom_position = a->getPosition();

/*				EditOperation eo(a, NULL, (String)qApp->tr("Edit Mode", "Added atom of type ") + PTE[atomic_number_].getName() + (String)qApp->tr("Edit Mode", " at position (")
						+ String(atom_position.x) + ", "
						+ String(atom_position.y) + ", "
						+ String(atom_position.z) + ")", EditOperation::ADDED__ATOM);
				undo_.push_back(eo);
				// tell about the new undo operation
				emit newEditOperation(eo);
*/
				return;
			}

			//////////////////////////////////////////////
			// middle button -> add bond
			if ( evt->button() == Qt::MidButton ||
			    (evt->button() == Qt::LeftButton && evt->modifiers() == Qt::ControlModifier))
			{
				if (scene_->getCurrentAtom())
				{
					scene_->getCurrentAtom()->select();
					scene_->notify(new CompositeMessage(*scene_->getCurrentAtom(), CompositeMessage::SELECTED_COMPOSITE));
				}
			}
		}
Exemplo n.º 17
0
		// insert an atom at screen positions (x,y) on the view plane
		// TODO: make the renderer dependent on the current target!
		void EditMode::insert_(int x, int y, PDBAtom &atom)
		{
			// find the 3D coordinates of screen position (x,y) on the view plane
			// move the atom to that position
			atom.setPosition(scene_->mapViewportTo3D(x,y));

			// now we need to find the AtomContainer into which we will insert the atom.
			// get all highlighted composites
			list<Composite*> composite_list = scene_->getMainControl()->getMolecularControlSelection();

			Size nr_high = composite_list.size();
			//TODO: read highlighting
			if (nr_high > 1 /*|| (only_highlighted_ && nr_high == 0)*/)
			{
				scene_->setStatusbarText(qApp->tr("Edit Mode", "Please highlight exactly one AtomContainer for insertion of the created atoms!"), true);
				return;
			}

			// exactly one highlighted composite
			if (nr_high == 1)
			{
				// is it an AtomContainer?
				AtomContainer* ai = dynamic_cast<AtomContainer*>(*composite_list.begin());
				if (ai == 0)
				{
					// is the parent an AtomContainer?
					Composite* parent = (**composite_list.begin()).getParent();
					if (parent != 0)
					{
						ai = dynamic_cast<AtomContainer*>(parent);
					}

					if (ai == 0)
					{
						scene_->setStatusbarText(qApp->tr("Edit Mode", "Please highlight exactly one AtomContainer for insertion of the created atoms!"), true);
						return;
					}
				}

				// prevent adding of atoms to a System:
				// some forcefields will go havoc otherwise
				if (RTTI::isKindOf<System>(*ai))
				{
					System* system = (System*) ai;
					Molecule* mol = system->getMolecule(0);
					if (mol == 0)
					{
						mol = new Molecule();
						system->insert(*mol);
					}
					ai = mol;
				}

				// we do not need to create our own system
				ai->insert(atom);
				scene_->getMainControl()->update(*ai, true);
				return;
			}

			/////////////////////////////////////////////////////////
			// no atom container highlighted:

			HashSet<Composite*> composites = getMainControl()->getCompositeManager().getComposites();

			// no System exists? -> create one
			if (composites.size() == 0)
			{
				System *system = new System();
				Molecule* current_molecule = new Molecule();
				system->insert(*current_molecule);
				current_molecule->insert(atom);
				getMainControl()->insert(*system);
				getMainControl()->update(*system);
				return;
			}

			// add to first Molecule in first System
			System* system = dynamic_cast<System*>(*composites.begin());
			Molecule* mol = system->getMolecule(0);
			if (mol == 0)
			{
				mol = new Molecule();
				system->insert(*mol);
			}

			mol->appendChild(atom);
			getMainControl()->update(*mol, true);
		}