+ ClearUIToolStatesExcept(addDimensionAct);
+ SetInternalToolStates();
+}
+
+void ApplicationWindow::RotateTool(void)
+{
+ ClearUIToolStatesExcept(rotateAct);
+
+ // Do tear-down if Rotate tool has been turned off
+ if (!rotateAct->isChecked())
+ drawing->RotateHandler(ToolCleanup, Point(0, 0));
+
+ SetInternalToolStates();
+}
+
+void ApplicationWindow::MirrorTool(void)
+{
+ ClearUIToolStatesExcept(mirrorAct);
+
+ // Do tear-down if Rotate tool has been turned off
+ if (!mirrorAct->isChecked())
+ drawing->MirrorHandler(ToolCleanup, Point(0, 0));
+
+ SetInternalToolStates();
+}
+
+void ApplicationWindow::TrimTool(void)
+{
+ ClearUIToolStatesExcept(trimAct);
+ SetInternalToolStates();
+ Global::toolSuppressCrosshair = true;
+}
+
+void ApplicationWindow::ParallelTool(void)
+{
+ ClearUIToolStatesExcept(parallelAct);
+ SetInternalToolStates();
+ Global::toolSuppressCrosshair = true;
+}
+
+void ApplicationWindow::TriangulateTool(void)
+{
+ ClearUIToolStatesExcept(triangulateAct);
+ SetInternalToolStates();
+}
+
+void ApplicationWindow::AddLineTool(void)
+{
+ ClearUIToolStatesExcept(addLineAct);
+ SetInternalToolStates();
+}
+
+void ApplicationWindow::AddCircleTool(void)
+{
+ ClearUIToolStatesExcept(addCircleAct);
+ SetInternalToolStates();
+}
+
+void ApplicationWindow::AddArcTool(void)
+{
+ ClearUIToolStatesExcept(addArcAct);
+ SetInternalToolStates();
+}
+
+void ApplicationWindow::AddPolygonTool(void)
+{
+ ClearUIToolStatesExcept(addPolygonAct);
+ SetInternalToolStates();
+}
+
+void ApplicationWindow::AddSplineTool(void)
+{
+ ClearUIToolStatesExcept(addSplineAct);
+ SetInternalToolStates();
+}
+
+void ApplicationWindow::ZoomInTool(void)
+{
+ double zoomFactor = 1.20;
+ QSize size = drawing->size();
+ Vector center = Painter::QtToCartesianCoords(Vector(size.width() / 2.0, size.height() / 2.0));
+
+ Global::origin = center - ((center - Global::origin) / zoomFactor);
+ Global::zoom *= zoomFactor;
+
+ UpdateZoom();
+}
+
+void ApplicationWindow::ZoomOutTool(void)
+{
+ double zoomFactor = 1.20;
+ QSize size = drawing->size();
+ Vector center = Painter::QtToCartesianCoords(Vector(size.width() / 2.0, size.height() / 2.0));
+
+ Global::origin = center + ((Global::origin - center) * zoomFactor);
+ Global::zoom /= zoomFactor;
+
+ UpdateZoom();
+}
+
+void ApplicationWindow::UpdateZoom(void)
+{
+ // And now, a bunch of heuristics to select the right grid size--autogrid!
+ // :-P
+ if (Global::zoom < 0.25)
+ Global::gridSpacing = 48.0;
+ else if (Global::zoom >= 0.25 && Global::zoom < 0.50)
+ Global::gridSpacing = 36.0;
+ else if (Global::zoom >= 0.50 && Global::zoom < 1.00)
+ Global::gridSpacing = 24.0;
+ else if (Global::zoom >= 1.00 && Global::zoom < 2.00)
+ Global::gridSpacing = 12.0;
+ else if (Global::zoom >= 2.00 && Global::zoom < 4.00)
+ Global::gridSpacing = 6.0;
+ else if (Global::zoom >= 4.00 && Global::zoom < 8.00)
+ Global::gridSpacing = 3.0;
+ else if (Global::zoom >= 8.00 && Global::zoom < 16.00)
+ Global::gridSpacing = 1.0;
+ else if (Global::zoom >= 16.00 && Global::zoom < 32.00)
+ Global::gridSpacing = 0.5;
+ else if (Global::zoom >= 32.00 && Global::zoom < 64.00)
+ Global::gridSpacing = 0.25;
+ else if (Global::zoom >= 64.00 && Global::zoom < 128.00)
+ Global::gridSpacing = 0.125;
+ else if (Global::zoom >= 128.00 && Global::zoom < 256.00)
+ Global::gridSpacing = 0.0625;
+ else if (Global::zoom >= 256.00 && Global::zoom < 512.00)
+ Global::gridSpacing = 0.03125;
+ else
+ Global::gridSpacing = 0.015625;
+
+ drawing->update();
+
+ zoomIndicator->setText(QString("Zoom: %1% Grid: %2\" BU: Inch").arg(Global::zoom * 100.0).arg(Global::gridSpacing));
+
+ // This is the problem... Changing this causes the state to update itself again, screwing up the origin... !!! FIX !!! (commented out for now)
+// baseUnitInput->setText(QString("%1").arg(Global::gridSpacing));
+}
+
+void ApplicationWindow::ClearUIToolStatesExcept(QAction * exception)
+{
+ QAction * actionList[] = {
+ addArcAct, addLineAct, addCircleAct, addDimensionAct, addPolygonAct,
+ addSplineAct, deleteAct, rotateAct, mirrorAct, trimAct,
+ triangulateAct, parallelAct, 0
+ };
+
+ for(int i=0; actionList[i]!=0; i++)
+ {
+ if (actionList[i] != exception)
+ actionList[i]->setChecked(false);
+ }
+}
+
+void ApplicationWindow::SetInternalToolStates(void)
+{
+ // We can be sure that if we've come here, then either an active tool is
+ // being deactivated, or a new tool is being activated. In either case,
+ // the tool state needs to be reset. Also, we reset the crosshair
+ // suppression flag.
+ Global::toolState = TSNone;
+ Global::toolSuppressCrosshair = false;
+
+ if (addLineAct->isChecked())
+ Global::tool = TTLine;
+ else if (addCircleAct->isChecked())
+ Global::tool = TTCircle;
+ else if (addArcAct->isChecked())
+ Global::tool = TTArc;
+ else if (addDimensionAct->isChecked())
+ Global::tool = TTDimension;
+ else if (addSplineAct->isChecked())
+ Global::tool = TTSpline;
+ else if (addPolygonAct->isChecked())
+ Global::tool = TTPolygon;
+ else if (deleteAct->isChecked())
+ Global::tool = TTDelete;
+ else if (mirrorAct->isChecked())
+ Global::tool = TTMirror;
+ else if (rotateAct->isChecked())
+ Global::tool = TTRotate;
+ else if (trimAct->isChecked())
+ Global::tool = TTTrim;
+ else if (parallelAct->isChecked())
+ Global::tool = TTParallel;
+ else if (triangulateAct->isChecked())
+ Global::tool = TTTriangulate;
+ else
+ Global::tool = TTNone;
+
+ cw->SetToolPrompt();//cw->cmdline);
+ drawing->update();