Exemple #1
0
void Entity_createFromSelection (const std::string& name, const Vector3& origin)
{
	try {
		bool revert = Entity_create(name, origin);
		if (revert) {
			GlobalUndoSystem().undo();
			GlobalUndoSystem().clearRedo();
			GlobalSceneGraph().sceneChanged();
		}
	} catch (EntityCreationException e) {
		gtkutil::errorDialog(e.what());
	}
}
void RadiantSelectionSystem::cancelMove() {

    // Unselect any currently selected manipulators to be sure
    _manipulator->setSelected(false);

    // Tell all the scene objects to revert their transformations
    RevertTransformForSelected walker;
    Node_traverseSubgraph(GlobalSceneGraph().root(), walker);

    _pivotMoving = false;
    pivotChanged();

    // greebo: Deselect all faces if we are in brush and drag mode
    if (Mode() == ePrimitive && ManipulatorMode() == eDrag)
    {
        SelectAllComponentWalker faceSelector(false, SelectionSystem::eFace);
        Node_traverseSubgraph(GlobalSceneGraph().root(), faceSelector);
    }

    if (_undoBegun) {
        // Cancel the undo operation, if one has been begun
        GlobalUndoSystem().cancel();
        _undoBegun = false;
    }

    // Update the views
    SceneChangeNotify();
}
// Pre-show callback
void PatchInspector::_preShow()
{
	TransientWindow::_preShow();

	_undoHandler.disconnect();
	_redoHandler.disconnect();

	// Register self to the SelSystem to get notified upon selection changes.
	GlobalSelectionSystem().addObserver(this);
	
	_undoHandler = GlobalUndoSystem().signal_postUndo().connect(
		sigc::mem_fun(this, &PatchInspector::queueUpdate));
	_redoHandler = GlobalUndoSystem().signal_postRedo().connect(
		sigc::mem_fun(this, &PatchInspector::queueUpdate));

	// Check for selection changes before showing the dialog again
	rescanSelection();
}
// Pre-show callback
void PatchInspector::_preShow()
{
	TransientWindow::_preShow();

	// Register self to the SelSystem to get notified upon selection changes.
	GlobalSelectionSystem().addObserver(this);
	GlobalUndoSystem().addObserver(this);

	// Check for selection changes before showing the dialog again
	rescanSelection();
}
// Pre-hide callback
void PatchInspector::_preHide()
{
	TransientWindow::_preHide();

	// Clear the patch, we don't need to observe it while hidden
	setPatch(PatchNodePtr());

	// A hidden PatchInspector doesn't need to listen for events
	GlobalUndoSystem().removeObserver(this);
	GlobalSelectionSystem().removeObserver(this);
}
Exemple #6
0
void Map::onResourceUnrealise() {
    if(m_resource != 0)
    {
        setValid(false);
      setWorldspawn(scene::INodePtr());

      GlobalUndoSystem().clear();
      GlobalSelectionSetManager().deleteAllSelectionSets();

      GlobalSceneGraph().setRoot(scene::INodePtr());
    }
}
// Pre-show callback
void LightInspector::_preShow()
{
    TransientWindow::_preShow();

    _selectionChanged.disconnect();
    _undoHandler.disconnect();
    _redoHandler.disconnect();

    // Register self as observer to receive events
    _undoHandler = GlobalUndoSystem().signal_postUndo().connect(
        sigc::mem_fun(this, &LightInspector::update));
    _redoHandler = GlobalUndoSystem().signal_postRedo().connect(
        sigc::mem_fun(this, &LightInspector::update));

    // Register self to the SelSystem to get notified upon selection changes.
    _selectionChanged = GlobalSelectionSystem().signal_selectionChanged().connect(
        [this](const ISelectable&) { update(); });

    // Update the widgets before showing
    update();
}
void TraversableNodeSet::importState(const IUndoMementoPtr& state)
{
	undoSave();

	// Import the child set from the state
	const NodeList& other = std::static_pointer_cast<UndoListMemento>(state)->data();

	// Copy the current container into a temporary one for later comparison
	std::vector<INodePtr> before_sorted(_children.begin(), _children.end());
	std::vector<INodePtr> after_sorted(other.begin(), other.end());

	// greebo: Now sort these, the set_difference algorithm requires the sets to be sorted
	std::sort(before_sorted.begin(), before_sorted.end());
	std::sort(after_sorted.begin(), after_sorted.end());

	// Import the state, overwriting the current set
	_children = other;

	// Now, handle the difference of <before> and <after>
	// The owning node needs to know about all nodes which are removed in <after>, these are
	// instantly removed from the scenegraph
	ObserverEraseFunctor eraseFunctor;

	// greebo: Now find all the nodes that exist in <_children>, but not in <other> and
	// call the EraseFunctor for each of them (the iterator calls onChildRemoved() on the owning node).
	std::set_difference(
		before_sorted.begin(), before_sorted.end(),
		after_sorted.begin(), after_sorted.end(),
		ObserverOutputIterator(_owner, eraseFunctor)
	);

	// A special treatment is necessary for insertions of new nodes, as calling onChildAdded
	// right away might lead to double-insertions into the scenegraph (in case the same node
	// has not been removed from another node yet - a race condition during undo).
	// Therefore, collect all nodes that need to be added and process them in postUndo/postRedo.
	CollectNodesFunctor collectFunctor(_undoInsertBuffer);

	// greebo: Next step is to find all nodes existing in <other>, but not in <_children>,
	// these have to be added, that's why the onChildAdded() method is called for each of them
	std::set_difference(
		after_sorted.begin(), after_sorted.end(),
		before_sorted.begin(), before_sorted.end(),
		ObserverOutputIterator(_owner, collectFunctor)
	);

	if (!_undoInsertBuffer.empty())
	{
		// Register to get notified when the undo operation is complete
		GlobalUndoSystem().addObserver(this);
	}
}
// End the move, this freezes the current transforms
void RadiantSelectionSystem::endMove() {
    freezeTransforms();

    // greebo: Deselect all faces if we are in brush and drag mode
    if ((Mode() == ePrimitive || Mode() == eGroupPart) &&
        ManipulatorMode() == eDrag)
    {
        SelectAllComponentWalker faceSelector(false, SelectionSystem::eFace);
        Node_traverseSubgraph(GlobalSceneGraph().root(), faceSelector);
    }

    // Remove all degenerated brushes from the scene graph (should emit a warning)
    foreachSelected(RemoveDegenerateBrushWalker());

    _pivotMoving = false;
    pivotChanged();

    // Update the views
    SceneChangeNotify();

    // If we started an undoable operation, end it now and tell the console what happened
    if (_undoBegun)
    {
        std::ostringstream command;

        if (ManipulatorMode() == eTranslate) {
            command << "translateTool";
            outputTranslation(command);
        }
        else if (ManipulatorMode() == eRotate) {
            command << "rotateTool";
            outputRotation(command);
        }
        else if (ManipulatorMode() == eScale) {
            command << "scaleTool";
            outputScale(command);
        }
        else if (ManipulatorMode() == eDrag) {
            command << "dragTool";
        }

        _undoBegun = false;

        // Finish the undo move
        GlobalUndoSystem().finish(command.str());
    }
}
/* greebo: This "moves" the current selection. It calculates the device manipulation matrix
 * and passes it to the currently active Manipulator.
 */
void RadiantSelectionSystem::MoveSelected(const View& view, const Vector2& devicePoint)
{
    // Check, if the active manipulator is selected in the first place
    if (_manipulator->isSelected()) {
        // Initalise the undo system, if not yet done
        if (!_undoBegun) {
            _undoBegun = true;
            GlobalUndoSystem().start();
        }

        Matrix4 device2manip;
        ConstructDevice2Manip(device2manip, _pivot2worldStart, view.GetModelview(), view.GetProjection(), view.GetViewport());

        Vector2 constrainedDevicePoint(devicePoint);

        // Constrain the movement to the axes, if the modifier is held
        if ((GlobalEventManager().getModifierState() & GDK_SHIFT_MASK) != 0)
        {
            // Get the movement delta relative to the start point
            Vector2 delta = devicePoint - _deviceStart;

            // Set the "minor" value of the movement to zero
            if (fabs(delta[0]) > fabs(delta[1])) {
                // X axis is major, reset the y-value to the start
                delta[1] = 0;
            }
            else {
                // Y axis is major, reset the x-value to the start
                delta[0] = 0;
            }

            // Add the modified delta to the start point, constrained to one axis
            constrainedDevicePoint = _deviceStart + delta;
        }

        // Get the manipulatable from the currently active manipulator (done by selection test)
        // and call the Transform method (can be anything)
        _manipulator->getActiveComponent()->Transform(_manip2pivotStart, device2manip, constrainedDevicePoint[0], constrainedDevicePoint[1]);

        _requestWorkZoneRecalculation = true;
        _requestSceneGraphChange = true;

        requestIdleCallback();
    }
}
Exemple #11
0
void MainFrame::Shutdown (void)
{
	map::AutoSaver().stopTimer();
	ui::TexTool::Instance().shutdown();

	GlobalUndoSystem().trackerDetach(m_saveStateTracker);

	GlobalXYWnd().destroyViews();

	GlobalCamera().deleteCamWnd(m_pCamWnd);
	m_pCamWnd = 0;

	PreferencesDialog_destroyWindow();

	delete _sidebar;

	// Stop the AutoSaver class from being called
	map::AutoSaver().stopTimer();
}
/* greebo: This "moves" the current selection. It calculates the device manipulation matrix
 * and passes it to the currently active Manipulator.
 */
void RadiantSelectionSystem::MoveSelected(const View& view, const float device_point[2]) {
	// Check, if the active manipulator is selected in the first place
	if (_manipulator->isSelected()) {
		// Initalise the undo system
		if (!_undoBegun) {
			_undoBegun = true;
			GlobalUndoSystem().start();
		}

		Matrix4 device2manip;
		ConstructDevice2Manip(device2manip, _pivot2worldStart, view.GetModelview(), view.GetProjection(), view.GetViewport());

		// Get the manipulatable from the currently active manipulator (done by selection test)
		// and call the Transform method (can be anything)
		_manipulator->GetManipulatable()->Transform(_manip2pivotStart, device2manip, device_point[0], device_point[1]);

		_requestWorkZoneRecalculation = true;

		requestIdleCallback();
	}
}
void Redo (void)
{
	GlobalUndoSystem().redo();
	SceneChangeNotify();
	GlobalShaderClipboard().clear();
}
void TraversableNodeSet::postRedo()
{
	processInsertBuffer();
	GlobalUndoSystem().removeObserver(this);
}
void TraversableNodeSet::instanceDetach(MapFile* map)
{
	_map = NULL;
    _undoStateSaver = NULL;
	GlobalUndoSystem().releaseStateSaver(*this);
}
void TraversableNodeSet::instanceAttach(MapFile* map)
{
	_map = map;
	_undoStateSaver = GlobalUndoSystem().getStateSaver(*this);
}
Exemple #17
0
/**
 * @brief Create the user settable window layout
 */
void MainFrame::Create (void)
{
	GtkWindow* window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));

	// do this here, because the commands are needed
	_sidebar = new ui::Sidebar();
	GtkWidget *sidebar = _sidebar->getWidget();

	// Tell the XYManager which window the xyviews should be transient for
	GlobalXYWnd().setGlobalParentWindow(window);

	GlobalWindowObservers_connectTopLevel(window);

	gtk_window_set_transient_for(ui::Splash::Instance().getWindow(), window);

#ifndef _WIN32
	{
		GdkPixbuf* pixbuf = gtkutil::getLocalPixbuf(ui::icons::ICON);
		if (pixbuf != 0) {
			gtk_window_set_icon(window, pixbuf);
			g_object_unref(pixbuf);
		}
	}
#endif

	gtk_widget_add_events(GTK_WIDGET(window), GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_FOCUS_CHANGE_MASK);
	g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(mainframe_delete), this);

	m_position_tracker.connect(window);

	g_MainWindowActive.connect(window);

	GtkWidget* vbox = gtk_vbox_new(FALSE, 0);
	gtk_container_add(GTK_CONTAINER(window), vbox);
	gtk_widget_show(vbox);

	GlobalEventManager().connect(GTK_OBJECT(window));
	GlobalEventManager().connectAccelGroup(GTK_WINDOW(window));

	m_nCurrentStyle = eSplit;

	// Create the Filter menu entries
	ui::FiltersMenu::addItemsToMainMenu();

	// Retrieve the "main" menubar from the UIManager
	GtkMenuBar* mainMenu = GTK_MENU_BAR(GlobalUIManager().getMenuManager()->get("main"));
	gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(mainMenu), false, false, 0);

	// Instantiate the ToolbarCreator and retrieve the standard toolbar widget
	ui::ToolbarCreator toolbarCreator;

	GtkToolbar* generalToolbar = toolbarCreator.getToolbar("view");
	gtk_widget_show(GTK_WIDGET(generalToolbar));

	GlobalSelectionSetManager().init(generalToolbar);

	// Pack it into the main window
	gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(generalToolbar), FALSE, FALSE, 0);

	GtkWidget* main_statusbar = create_main_statusbar(m_pStatusLabel);
	gtk_box_pack_end(GTK_BOX(vbox), main_statusbar, FALSE, TRUE, 2);

	GtkWidget* hbox = gtk_hbox_new(FALSE, 0);
	gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(hbox), TRUE, TRUE, 0);
	gtk_widget_show(hbox);

	GtkToolbar* main_toolbar_v = toolbarCreator.getToolbar("edit");
	gtk_widget_show(GTK_WIDGET(main_toolbar_v));

	gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(main_toolbar_v), FALSE, FALSE, 0);


	// Connect the window position tracker
	_windowPosition.loadFromPath(RKEY_WINDOW_STATE);

	// Yes, connect the position tracker, this overrides the existing setting.
	_windowPosition.connect(window);

	int startMonitor = GlobalRegistry().getInt(RKEY_MULTIMON_START_MONITOR);
	if (startMonitor < gtkutil::MultiMonitor::getNumMonitors()) {
		// Load the correct coordinates into the position tracker
		_windowPosition.fitToScreen(gtkutil::MultiMonitor::getMonitor(startMonitor), 0.8f, 0.8f);
	}

	// Apply the position
	_windowPosition.applyPosition();

	int windowState = string::toInt(GlobalRegistry().getAttribute(RKEY_WINDOW_STATE, "state"), GDK_WINDOW_STATE_MAXIMIZED);
	if (windowState & GDK_WINDOW_STATE_MAXIMIZED)
		gtk_window_maximize(window);

	m_window = window;

	gtk_widget_show(GTK_WIDGET(window));

	// The default XYView pointer
	XYWnd* xyWnd;

	GtkWidget* mainHBox = gtk_hbox_new(0, 0);
	gtk_box_pack_start(GTK_BOX(hbox), mainHBox, TRUE, TRUE, 0);
	gtk_widget_show(mainHBox);

	int w, h;
	gtk_window_get_size(window, &w, &h);

	// camera
	m_pCamWnd = GlobalCamera().newCamWnd();
	GlobalCamera().setCamWnd(m_pCamWnd);
	GlobalCamera().setParent(m_pCamWnd, window);
	GtkWidget* camera = m_pCamWnd->getWidget();

	// Allocate the three ortho views
	xyWnd = GlobalXYWnd().createXY();
	xyWnd->setViewType(XY);
	GtkWidget* xy = xyWnd->getWidget();

	XYWnd* yzWnd = GlobalXYWnd().createXY();
	yzWnd->setViewType(YZ);
	GtkWidget* yz = yzWnd->getWidget();

	XYWnd* xzWnd = GlobalXYWnd().createXY();
	xzWnd->setViewType(XZ);
	GtkWidget* xz = xzWnd->getWidget();

	// split view (4 views)
	GtkHPaned* split = create_split_views(camera, yz, xy, xz);
	gtk_box_pack_start(GTK_BOX(mainHBox), GTK_WIDGET(split), TRUE, TRUE, 0);

	// greebo: In any layout, there is at least the XY view present, make it active
	GlobalXYWnd().setActiveXY(xyWnd);

	PreferencesDialog_constructWindow(window);

	GlobalGrid().addGridChangeCallback(FreeCaller<XY_UpdateAllWindows> ());

	/* enable button state tracker, set default states for begin */
	GlobalUndoSystem().trackerAttach(m_saveStateTracker);

	gtk_box_pack_start(GTK_BOX(mainHBox), GTK_WIDGET(sidebar), FALSE, FALSE, 0);

	// Start the autosave timer so that it can periodically check the map for changes
	map::AutoSaver().startTimer();
}