示例#1
0
FullDomainSelectionLayer::~FullDomainSelectionLayer()
{
	if (clickTool)
		delete clickTool;
	if (circleTool)
		delete circleTool;
	if (rectangleTool)
		delete rectangleTool;
	if (polygonTool)
		delete polygonTool;
	if (boundaryFinder)
		delete boundaryFinder;

	if (selectedState)
		delete selectedState;

	ClearUndoStack();
	ClearRedoStack();

	if (outlineShader)
		delete outlineShader;
	if (fillShader)
		delete fillShader;
	if (innerBoundaryShader)
		delete innerBoundaryShader;
	if (outerBoundaryShader)
		delete outerBoundaryShader;
}
示例#2
0
/**
 * @brief Called after a new selection is made to set the current state to the newly created one
 *
 * Called after a new selection is made to set the current state to the newly created one. Takes
 * care of undo/redo stacks and boundary searching.
 *
 * @param newState The newly created state
 */
void CreationSelectionLayer::UseNewState(ElementState *newState)
{
	/* A new selection has been made, so redo is no longer available */
	ClearRedoStack();

	/* Push the old state onto the undo stack */
	undoStack.push(selectedState);
	emit UndoAvailable(true);

	UseState(newState);
}
NS_IMETHODIMP
nsTransactionManager::Clear()
{
  nsresult result;

  result = ClearRedoStack();

  if (NS_FAILED(result)) {
    return result;
  }

  result = ClearUndoStack();

  return result;
}
NS_IMETHODIMP
nsTransactionManager::Clear()
{
  nsresult result;

  LOCK_TX_MANAGER(this);

  result = ClearRedoStack();

  if (NS_FAILED(result)) {
    UNLOCK_TX_MANAGER(this);
    return result;
  }

  result = ClearUndoStack();

  UNLOCK_TX_MANAGER(this);

  return result;
}
示例#5
0
/**
 * @brief Deconstructor that cleans up data on the GPU and any allocated data
 *
 * Cleans up any data that has been created by this class. Marks data for
 * deletion on the GPU. Note that we are not responsible for cleaning up
 * the VBO.
 *
 */
CreationSelectionLayer::~CreationSelectionLayer()
{
	DEBUG("Deleting Creation Selection Layer. Layer ID: " << GetID());

	/* Clean up shaders */
	if (outlineShader)
		delete outlineShader;
	if (fillShader)
		delete fillShader;
	if (boundaryShader)
		delete boundaryShader;

	// Clean up the OpenGL stuff
	glBindBuffer(GL_ARRAY_BUFFER, 0);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

	/* Note that we aren't responsible for cleaning up the VBO */

	if (VAOId)
		glDeleteBuffers(1, &VAOId);
	if (IBOId)
		glDeleteBuffers(1, &IBOId);

	/* Delete all tools */
	if (clickTool)
		delete clickTool;
	if (circleTool)
		delete circleTool;
	if (rectangleTool)
		delete rectangleTool;
	if (polygonTool)
		delete polygonTool;
	if (boundaryFinder)
		delete boundaryFinder;

	/* Delete all states */
	if (selectedState)
		delete selectedState;
	ClearUndoStack();
	ClearRedoStack();
}
nsresult
nsTransactionManager::EndTransaction()
{
  nsCOMPtr<nsITransaction> tint;
  nsRefPtr<nsTransactionItem> tx;
  nsresult result              = NS_OK;

  // No need for LOCK/UNLOCK_TX_MANAGER() calls since the calling routine
  // should have done this already!

  result = mDoStack.Pop(getter_AddRefs(tx));

  if (NS_FAILED(result) || !tx)
    return result;

  result = tx->GetTransaction(getter_AddRefs(tint));

  if (NS_FAILED(result)) {
    // XXX: What do we do with the transaction item at this point?
    return result;
  }

  if (!tint) {
    PRInt32 nc = 0;

    // If we get here, the transaction must be a dummy batch transaction
    // created by BeginBatch(). If it contains no children, get rid of it!

    tx->GetNumberOfChildren(&nc);

    if (!nc) {
      return result;
    }
  }

  // Check if the transaction is transient. If it is, there's nothing
  // more to do, just return.

  PRBool isTransient = PR_FALSE;

  if (tint)
    result = tint->GetIsTransient(&isTransient);

  if (NS_FAILED(result) || isTransient || !mMaxTransactionCount) {
    // XXX: Should we be clearing the redo stack if the transaction
    //      is transient and there is nothing on the do stack?
    return result;
  }

  nsRefPtr<nsTransactionItem> top;

  // Check if there is a transaction on the do stack. If there is,
  // the current transaction is a "sub" transaction, and should
  // be added to the transaction at the top of the do stack.

  result = mDoStack.Peek(getter_AddRefs(top));
  if (top) {
    result = top->AddChild(tx);

    // XXX: What do we do if this fails?

    return result;
  }

  // The transaction succeeded, so clear the redo stack.

  result = ClearRedoStack();

  if (NS_FAILED(result)) {
    // XXX: What do we do if this fails?
  }

  // Check if we can coalesce this transaction with the one at the top
  // of the undo stack.

  top = 0;
  result = mUndoStack.Peek(getter_AddRefs(top));

  if (tint && top) {
    PRBool didMerge = PR_FALSE;
    nsCOMPtr<nsITransaction> topTransaction;

    result = top->GetTransaction(getter_AddRefs(topTransaction));

    if (topTransaction) {

      PRBool doInterrupt = PR_FALSE;

      result = WillMergeNotify(topTransaction, tint, &doInterrupt);

      NS_ENSURE_SUCCESS(result, result);

      if (!doInterrupt) {
        result = topTransaction->Merge(tint, &didMerge);

        nsresult result2 = DidMergeNotify(topTransaction, tint, didMerge, result);

        if (NS_SUCCEEDED(result))
          result = result2;

        if (NS_FAILED(result)) {
          // XXX: What do we do if this fails?
        }

        if (didMerge) {
          return result;
        }
      }
    }
  }

  // Check to see if we've hit the max level of undo. If so,
  // pop the bottom transaction off the undo stack and release it!

  PRInt32 sz = 0;

  result = mUndoStack.GetSize(&sz);

  if (mMaxTransactionCount > 0 && sz >= mMaxTransactionCount) {
    nsRefPtr<nsTransactionItem> overflow;

    result = mUndoStack.PopBottom(getter_AddRefs(overflow));

    // XXX: What do we do in the case where this fails?
  }

  // Push the transaction on the undo stack:

  result = mUndoStack.Push(tx);

  if (NS_FAILED(result)) {
    // XXX: What do we do in the case where a clear fails?
    //      Remove the transaction from the stack, and release it?
  }

  return result;
}
nsresult
nsTransactionManager::EndTransaction()
{
  nsresult result              = NS_OK;

  nsRefPtr<nsTransactionItem> tx = mDoStack.Pop();

  if (!tx)
    return NS_ERROR_FAILURE;

  nsCOMPtr<nsITransaction> tint = tx->GetTransaction();

  if (!tint) {
    PRInt32 nc = 0;

    // If we get here, the transaction must be a dummy batch transaction
    // created by BeginBatch(). If it contains no children, get rid of it!

    tx->GetNumberOfChildren(&nc);

    if (!nc) {
      return result;
    }
  }

  // Check if the transaction is transient. If it is, there's nothing
  // more to do, just return.

  bool isTransient = false;

  if (tint)
    result = tint->GetIsTransient(&isTransient);

  if (NS_FAILED(result) || isTransient || !mMaxTransactionCount) {
    // XXX: Should we be clearing the redo stack if the transaction
    //      is transient and there is nothing on the do stack?
    return result;
  }

  // Check if there is a transaction on the do stack. If there is,
  // the current transaction is a "sub" transaction, and should
  // be added to the transaction at the top of the do stack.

  nsRefPtr<nsTransactionItem> top = mDoStack.Peek();
  if (top) {
    result = top->AddChild(tx);

    // XXX: What do we do if this fails?

    return result;
  }

  // The transaction succeeded, so clear the redo stack.

  result = ClearRedoStack();

  if (NS_FAILED(result)) {
    // XXX: What do we do if this fails?
  }

  // Check if we can coalesce this transaction with the one at the top
  // of the undo stack.

  top = mUndoStack.Peek();

  if (tint && top) {
    bool didMerge = false;
    nsCOMPtr<nsITransaction> topTransaction = top->GetTransaction();

    if (topTransaction) {

      bool doInterrupt = false;

      result = WillMergeNotify(topTransaction, tint, &doInterrupt);

      NS_ENSURE_SUCCESS(result, result);

      if (!doInterrupt) {
        result = topTransaction->Merge(tint, &didMerge);

        nsresult result2 = DidMergeNotify(topTransaction, tint, didMerge, result);

        if (NS_SUCCEEDED(result))
          result = result2;

        if (NS_FAILED(result)) {
          // XXX: What do we do if this fails?
        }

        if (didMerge) {
          return result;
        }
      }
    }
  }

  // Check to see if we've hit the max level of undo. If so,
  // pop the bottom transaction off the undo stack and release it!

  PRInt32 sz = mUndoStack.GetSize();

  if (mMaxTransactionCount > 0 && sz >= mMaxTransactionCount) {
    nsRefPtr<nsTransactionItem> overflow = mUndoStack.PopBottom();
  }

  // Push the transaction on the undo stack:

  mUndoStack.Push(tx);

  return NS_OK;
}