// We want certain tools to be exclusive, and this approach isn't working correctly...
void ApplicationWindow::DeleteTool(void)
{
-
+ // For this tool, we check first to see if anything is selected. If so, we
+ // delete those and *don't* select the delete tool.
+ if (drawing->document.ItemsSelected() > 0)
+ {
+ drawing->document.DeleteSelectedItems();
+ drawing->update();
+ deleteAct->setChecked(false);
+ return;
+ }
+
+ // Otherwise, toggle the state of the tool
ClearUIToolStatesExcept(deleteAct);
SetInternalToolStates();
}
}
+//
+// Group a bunch of selected objects (which can include other groups) together
+// or ungroup a selected group.
+//
void ApplicationWindow::HandleGrouping(void)
{
- // Group a bunch of selected objects together or ungroup a selected group.
-
+ // If nothing selected, do nothing
if (drawing->document.ItemsSelected() == 0)
{
statusBar()->showMessage(tr("No objects selected to make a group from."));
QIcon(":/res/fix-length.png"), QKeySequence(tr("F,L")), true);
connect(fixLengthAct, SIGNAL(triggered()), this, SLOT(FixLength()));
- deleteAct = CreateAction(tr("&Delete"), tr("Delete Object"), tr("Deletes selected objects."), QIcon(":/res/delete-tool.png"), QKeySequence(), true);
+ deleteAct = CreateAction(tr("&Delete"), tr("Delete Object"), tr("Deletes selected objects."), QIcon(":/res/delete-tool.png"), QKeySequence(tr("Delete")), true);
connect(deleteAct, SIGNAL(triggered()), this, SLOT(DeleteTool()));
addDimensionAct = CreateAction(tr("Add &Dimension"), tr("Add Dimension"), tr("Adds a dimension to the drawing."), QIcon(":/res/dimension-tool.png"), QKeySequence("D,I"), true);
/*virtual*/ bool Container::Collided(Vector point)
{
objectWasDragged = false;
- Vector v1 = position - point;
+// Vector v1 = position - point;
-#if 0
- if (state == OSInactive)
- {
-//printf("Circle: pp = %lf, length = %lf, distance = %lf\n", parameterizedPoint, lineSegment.Magnitude(), distance);
-//printf(" v1.Magnitude = %lf, v2.Magnitude = %lf\n", v1.Magnitude(), v2.Magnitude());
-//printf(" point = %lf,%lf,%lf; p1 = %lf,%lf,%lf; p2 = %lf,%lf,%lf\n", point.x, point.y, point.z, position.x, position.y, position.z, endpoint.x, endpoint.y, endpoint.z);
-//printf(" \n", );
-//How to translate this into pixels from Document space???
-//Maybe we need to pass a scaling factor in here from the caller? That would make sense, as
-//the caller knows about the zoom factor and all that good kinda crap
- if (v1.Magnitude() < 10.0)
- {
- oldState = state;
- state = OSSelected;
- oldPoint = position; //maybe "position"?
- draggingHandle1 = true;
- return true;
- }
- else if ((v1.Magnitude() < radius + 2.0) && (v1.Magnitude() > radius - 2.0))
- {
- oldState = state;
- state = OSSelected;
- oldPoint = point;
- dragging = true;
- return true;
- }
- }
- else if (state == OSSelected)
- {
- // Here we test for collision with handles as well! (SOON!)
-/*
-Like so:
- if (v1.Magnitude() < 2.0) // Handle #1
- else if (v2.Magnitude() < 2.0) // Handle #2
-*/
- if ((v1.Magnitude() < radius + 2.0) && (v1.Magnitude() > radius - 2.0))
- {
- oldState = state;
-// state = OSInactive;
- oldPoint = point;
- dragging = true;
- return true;
- }
- }
-#else
bool collision = false;
// NOTE that this deletes the object on mouse down instead of mouse up. Have to
// check to see how it feels to do it that way...
if (deleteActive)
{
- for(int i=0; i<(int)objects.size(); i++)
+ for(std::vector<Object *>::iterator i=objects.begin(); i!=objects.end();)
{
- if (objects[i]->Collided(point))
+ if ((*i)->Collided(point))
{
-#if 0
-Dimension * dimension = objects[i]->GetAttachedDimension();
-#endif
- Object * objectToDelete = objects[i];
- objects.erase(objects.begin() + i); // Calls the destructor, (deletes the object, I presume... O_o) [NOPE! SURE DOESN'T!]
+printf("Container::Collided: Deleting object ($%X)\n", *i);
+ Object * objectToDelete = *i;
+ objects.erase(i);
delete objectToDelete;
-
-// If this object had an attached dimension, reattach it to another object, if any...
-// The only problem with that approach is if the object it gets attached to is deleted,
-// it will call the dimension to use a NULL pointer and BLAMMO
-#if 0
-if (dimension)
-{
- Vector p1 = dimension->GetPoint1();
- Vector p2 = dimension->GetPoint2();
- for(int j=0; j<(int)objects.size(); j++)
- {
- Vector * objectP1 = objects[i]->GetPointAt(p1);
- Vector * objectP2 = objects[i]->GetPointAt(p2);
-
- if (objectP1)
- dimension->SetPoint1(objectP1);
-
- if (objectP2)
- dimension->SetPoint2(objectP2);
- }
-}
-#endif
- // This only allows deleting objects one at a time...
- break;
- // however, this way of doing things could be problematic if we don't
- // delete one at a time... Need to come up with a better approach.
}
+ else
+ i++;
}
}
else
{
- for(int i=0; i<(int)objects.size(); i++)
+ for(std::vector<Object *>::iterator i=objects.begin(); i!=objects.end(); i++)
{
- if (objects[i]->Collided(point))
+ if ((*i)->Collided(point))
collision = true;
}
}
-#endif
// Do we decouple the state of the generic container from the objects inside??? Mebbe.
state = OSInactive;
-// return false;
return collision;
}
void Container::Delete(Object * objectToDelete)
{
-#if 0
- //this is wrong
- for(unsigned int i=0; i<objects.size(); i++)
+ std::vector<Object *>::iterator i = objects.begin();
+
+ while (i != objects.end())
{
- if (objects[i] == objectToDelete)
+ if (*i == objectToDelete)
{
objects.erase(i);
delete objectToDelete;
return;
}
+
+ i++;
}
-#else
+}
+
+
+void Container::DeleteSelectedItems(void)
+{
std::vector<Object *>::iterator i = objects.begin();
while (i != objects.end())
{
- if (*i == objectToDelete)
+ if ((*i)->state == OSSelected)
{
+ delete *i;
objects.erase(i);
- delete objectToDelete;
- return;
}
-
- i++;
+ else
+ i++;
}
-#endif
}
void Container::Clear(void)
{
+#if 0
// No memory leaks!
while (objects.size() > 0)
{
delete objects[0];
objects.erase(objects.begin());
}
+#else
+ std::vector<Object *>::iterator i = objects.begin();
+
+ while (i != objects.end())
+ {
+printf("Container: Deleting object ($%X)...\n", *i);
+ delete (*i);
+ objects.erase(i);
+ }
+#endif
}
}
-/*ObjectType Container::SelectedItemType(unsigned int index)
-{
- if (index >= objects.size())
- return OTNone;
-
- return objects[index]->Type();
-}*/
-
-
Object * Container::SelectedItem(unsigned int index)
{
-// if (index >= objects.size())
-// return NULL;
-
unsigned int selectedIndex = 0;
for(std::vector<Object *>::iterator i=objects.begin(); i!=objects.end(); i++)