+ break;
+
+ case ToolMouseUp:
+ if (Global::toolState == TSNone)
+ {
+ Global::toolState = TSPoint2;
+ // Prevent spurious line from drawing...
+ toolPoint[1] = toolPoint[0];
+ }
+ else if ((Global::toolState == TSPoint2) && shiftDown)
+ {
+ // Key override is telling us to make a new line, not continue the
+ // previous one.
+ toolPoint[0] = toolPoint[1];
+ }
+ else
+ {
+ Dimension * d = new Dimension(toolPoint[0], toolPoint[1], DTLinear);
+ d->layer = Global::activeLayer;
+ document.objects.push_back(d);
+ Global::toolState = TSNone;
+ }
+ }
+}
+
+
+void DrawingView::TriangulateHandler(int mode, Point/*p*/)
+{
+ switch (mode)
+ {
+ case ToolMouseDown:
+ {
+ // Skip if nothing hovered...
+ if (numHovered != 1)
+ break;
+
+ VPVector hover = GetHovered();
+ Object * obj = (Object *)hover[0];
+
+ // Skip if it's not a line...
+ if (obj->type != OTLine)
+ break;
+
+ if (Global::toolState == TSNone)
+ toolObj[0] = obj;
+ else if (Global::toolState == TSPoint2)
+ toolObj[1] = obj;
+ else
+ toolObj[2] = obj;
+
+ break;
+ }
+#if 0
+ case ToolMouseMove:
+ if (Global::toolState == TSNone)
+ toolPoint[0] = p;
+ else if (Global::toolState == TSPoint2)
+ toolPoint[1] = p;
+ else if (Global::toolState == TSPoint3)
+ {
+ toolPoint[2] = p;
+ angleSnap = true;
+ }
+ else
+ {
+ toolPoint[3] = p;
+ angleSnap = true;
+ }
+
+ break;
+#endif
+ case ToolMouseUp:
+ if (Global::toolState == TSNone)
+ {
+ Global::toolState = TSPoint2;
+ }
+ else if (Global::toolState == TSPoint2)
+ {
+/* if (shiftDown)
+ {
+ // Key override is telling us to start arc at new center, not
+ // continue the current one.
+ toolPoint[0] = toolPoint[1];
+ return;
+ }*/
+
+ Global::toolState = TSPoint3;
+ }
+ else
+ {
+ double len2 = Vector::Magnitude(toolObj[1]->p[0], toolObj[1]->p[1]);
+ double len3 = Vector::Magnitude(toolObj[2]->p[0], toolObj[2]->p[1]);
+
+ Circle c1(toolObj[0]->p[0], len2);
+ Circle c2(toolObj[0]->p[1], len3);
+
+ Geometry::CheckCircleToCircleIntersection((Object *)&c1, (Object *)&c2);
+
+ // Only move lines if the triangle formed by them is not degenerate
+ if (Global::numIntersectPoints > 0)
+ {
+ toolObj[1]->p[0] = toolObj[0]->p[0];
+ toolObj[1]->p[1] = Global::intersectPoint[0];
+
+ toolObj[2]->p[0] = Global::intersectPoint[0];
+ toolObj[2]->p[1] = toolObj[0]->p[1];
+ }
+
+ Global::toolState = TSNone;
+ }
+ }
+}
+
+
+void DrawingView::TrimHandler(int mode, Point p)
+{
+/*
+n.b.: this code is lifted straight out of the old oo code. needs to be updated.
+*/
+ switch (mode)
+ {
+ case ToolMouseDown:
+ {
+#if 0
+ Object * toTrim = doc->lastObjectHovered;
+
+ if (toTrim == NULL)
+ return;
+
+ Vector v(((Line *)toTrim)->position, ((Line *)toTrim)->endpoint);
+
+ // Check to see which case we have...
+ // We're trimming point #1...
+ if (t == 0)
+ {
+ ((Line *)toTrim)->position = ((Line *)toTrim)->position + (v * u);
+ }
+ else if (u == 1.0)
+ {
+ ((Line *)toTrim)->endpoint = ((Line *)toTrim)->position + (v * t);
+ }
+ else
+ {
+ Point p1 = ((Line *)toTrim)->position + (v * t);
+ Point p2 = ((Line *)toTrim)->position + (v * u);
+ Point p3 = ((Line *)toTrim)->endpoint;
+ ((Line *)toTrim)->endpoint = p1;
+ Line * line = new Line(p2, p3);
+ emit ObjectReady(line);
+ }
+
+ doc->lastObjectHovered = NULL;
+#endif
+ }
+ break;
+
+ case ToolMouseMove:
+ {
+#if 0
+ Object * toTrim = doc->lastObjectHovered;
+ t = 0, u = 1.0;
+
+ if (toTrim == NULL)
+ return;
+
+ if (toTrim->type != OTLine)
+ return;
+
+ double pointHoveredT = Geometry::ParameterOfLineAndPoint(((Line *)toTrim)->position, ((Line *)toTrim)->endpoint, point);
+
+ std::vector<Object *>::iterator i;
+
+ for(i=doc->objects.begin(); i!=doc->objects.end(); i++)
+ {
+ // Can't trim against yourself... :-P
+ if (*i == toTrim)
+ continue;
+
+ Object * trimAgainst = *i;
+ double t1;//, u1;
+
+ if ((toTrim->type != OTLine) || (trimAgainst->type != OTLine))
+ continue;
+
+ int intersects = Geometry::Intersects((Line *)toTrim, (Line *)trimAgainst, &t1);//, &u1);
+
+ if (intersects)
+ {
+ // Now what? We don't know which side to trim!
+ // ... now we do, we know which side of the Line we're on!
+ if ((t1 > t) && (t1 < pointHoveredT))
+ t = t1;
+
+ if ((t1 < u) && (t1 > pointHoveredT))
+ u = t1;
+ }
+ }
+#endif
+ // Bail out if nothing hovered...
+ if (numHovered != 1)
+ {
+ toolObj[0] = NULL;
+ return;
+ }
+
+ VPVector hover = GetHovered();
+ Object * obj = (Object *)hover[0];
+
+ // Skip if it's not a line...
+ if (obj->type != OTLine)
+ {
+ toolObj[0] = NULL;
+ return;
+ }
+
+ toolObj[0] = obj;
+ double hoveredParam = Geometry::ParameterOfLineAndPoint(obj->p[0], obj->p[1], p);
+
+ // Currently only deal with line against line trimming, can expand to
+ // others as well (line/circle, circle/circle, line/arc, etc)
+ VPVectorIter i;
+ for(i=document.objects.begin(); i!=document.objects.end(); i++)
+ {
+ obj = (Object *)(*i);
+
+ if (obj == toolObj[0])
+ continue;
+ else if (obj->type != OTLine)
+ continue;
+
+ Geometry::CheckLineToLineIntersection(toolObj[0], obj);
+
+ if (Global::numIntersectParams > 0)
+ {
+ // Mark the line segment somehow (the side the mouse is on) so that it can be drawn & trimmed when we hit ToolMouseDown.
+ }
+ }
+ }
+ break;
+
+ case ToolMouseUp:
+ break;
+
+ case ToolKeyDown:
+ break;
+
+ case ToolKeyUp:
+ break;
+
+ case ToolCleanup:
+ break;
+ }
+}
+
+
+void DrawingView::ParallelHandler(int mode, Point /*p*/)
+{
+ switch (mode)
+ {
+ case ToolMouseDown:
+ break;
+
+ case ToolMouseMove:
+ break;
+
+ case ToolMouseUp:
+ break;
+
+ case ToolKeyDown:
+ break;
+
+ case ToolKeyUp:
+ break;
+
+ case ToolCleanup:
+ break;
+ }
+}
+
+
+void DrawingView::mousePressEvent(QMouseEvent * event)
+{
+ if (event->button() == Qt::LeftButton)
+ {
+//printf("mousePressEvent::Qt::LeftButton numHovered=%li\n", numHovered);
+ Vector point = Painter::QtToCartesianCoords(Vector(event->x(), event->y()));
+
+ // Handle tool processing, if any
+ if (Global::tool)
+ {
+ if (hoveringIntersection)
+ point = intersectionPoint;
+ else if (hoverPointValid)
+ point = hoverPoint;
+ else if (Global::snapToGrid)
+ point = SnapPointToGrid(point);
+
+ //Also, may want to figure out if hovering over a snap point on an
+ //object, snap to grid if not.
+ // Snap to object point if valid...
+// if (Global::snapPointIsValid)
+// point = Global::snapPoint;
+
+ ToolHandler(ToolMouseDown, point);
+ return;
+ }
+
+ // Clear the selection only if CTRL isn't being held on click
+ if (!ctrlDown)
+ ClearSelected(document.objects);
+// ClearSelection();