Need a way to scale line widths as well. :-/ Shouldn't be too difficult, just
need a thickness parameter similar to the "size" param for dimensions. (And now
we do! :-)
-
*/
-// gridPixels = 12; //tmp???
-// SetGridSize(12.0); // This is in pixels
}
void DrawingView::DrawBackground(Painter * painter)
painter->DrawHLine(start.y + i);
}
-#if 0
-void DrawingView::SetGridSize(uint32_t size)
-{
-#if 0
- // Sanity check
- if (size == gridPixels)
- return;
-
- // tmp...
- if (size <= 1)
- return;
-
- // Recreate the background bitmap
- gridPixels = size;
- QPainter pmp(&gridBackground);
- pmp.fillRect(0, 0, BACKGROUND_MAX_SIZE, BACKGROUND_MAX_SIZE, QColor(240, 240, 240));
- pmp.setPen(QPen(QColor(210, 210, 255), 2.0, Qt::SolidLine));
-
- for(int i=0; i<(BACKGROUND_MAX_SIZE-1); i+=gridPixels)
- {
- pmp.drawLine(i, 0, i, BACKGROUND_MAX_SIZE - 1);
- pmp.drawLine(0, i, BACKGROUND_MAX_SIZE - 1, i);
- }
-
- pmp.end();
-
- // Set up new BG brush & zoom level (pixels per base unit)
-// This shouldn't be done here, because it fucks up the scrollwheel zooming...
-// Global::zoom = gridPixels / Global::gridSpacing;
- UpdateGridBackground();
-#endif
-}
-
-void DrawingView::UpdateGridBackground(void)
-{
-#if 0
- // Transform the origin to Qt coordinates
- Vector pixmapOrigin = Painter::CartesianToQtCoords(Vector());
- int x = (int)pixmapOrigin.x;
- int y = (int)pixmapOrigin.y;
- // Use mod arithmetic to grab the correct swatch of background
-/*
-Negative numbers still screw it up... Need to think about what we're
-trying to do here. The fact that it worked with 72 seems to have been pure luck.
-It seems the problem is negative numbers: We can't let that happen.
-When taking away the zero, it pops over 1 px at zero, then goes about 1/2 a
-grid at x<0.
-
-The bitmap looks like this:
-
-+---+---+---+---+---
-| | | | |
-| | | | |
-+---+---+---+---+---
-| | | | |
-| | | | |
-| | | | |
-
-@ x = 1, we want it to look like:
-
--+---+---+---+---+---
- | | | | |
- | | | | |
--+---+---+---+---+---
- | | | | |
- | | | | |
- | | | | |
-
-Which means we need to grab the sample from x = 3. @ x = -1:
-
----+---+---+---+---
- | | | |
- | | | |
----+---+---+---+---
- | | | |
- | | | |
- | | | |
-
-Which means we need to grab the sample from x = 1. Which means we have to take
-the mirror of the modulus of gridPixels.
-
-Doing a mod of a negative number is problematic: 1st, the compiler converts the
-negative number to an unsigned int, then it does the mod. Gets you wrong answers
-most of the time, unless you use a power of 2. :-P So what we do here is just
-take the modulus of the negation, which means we don't have to worry about
-mirroring it later.
-
-The positive case looks gruesome (and it is) but it boils down to this: We take
-the modulus of the X coordinate, then mirror it by subtraction from the
-maximum (in this case, gridPixels). This gives us a number in the range of 1 to
-gridPixels. But we need the case where the result equalling gridPixels to be
-zero; so we do another modulus operation on the result to achieve this.
-*/
- if (x < 0)
- x = -x % gridPixels;
- else
- x = (gridPixels - (x % gridPixels)) % gridPixels;
-
- if (y < 0)
- y = -y % gridPixels;
- else
- y = (gridPixels - (y % gridPixels)) % gridPixels;
-
- // Here we grab a section of the bigger pixmap, so that the background
- // *looks* like it's scrolling...
- QPixmap pm = gridBackground.copy(x, y, gridPixels, gridPixels);
- QPalette pal = palette();
- pal.setBrush(backgroundRole(), QBrush(pm));
- setAutoFillBackground(true);
- setPalette(pal);
-#endif
-}
-
-void DrawingView::SetGridSize(double size)
-{
-#if 0
- // Sanity check
- if (size == gridPixelsF)
- return;
-
- // tmp...
- if (size <= 1)
- return;
-
- // Recreate the background bitmap
- gridPixelsF = size;
- QPainter pmp(&gridBackground);
- pmp.fillRect(0, 0, BACKGROUND_MAX_SIZE, BACKGROUND_MAX_SIZE, QColor(240, 240, 240));
- pmp.setPen(QPen(QColor(210, 210, 255), 2.0, Qt::SolidLine));
-
- for(double i=0; i<(BACKGROUND_MAX_SIZE-1); i+=gridPixelsF)
- {
- pmp.drawLine(i, 0, i, (double)(BACKGROUND_MAX_SIZE - 1));
- pmp.drawLine(0, i, (double)(BACKGROUND_MAX_SIZE - 1), i);
- }
-
- pmp.end();
-
- // Set up new BG brush & zoom level (pixels per base unit)
-// This shouldn't be done here, because it fucks up the scrollwheel zooming...
-// Global::zoom = gridPixels / Global::gridSpacing;
- UpdateGridBackgroundF();
-#endif
-}
-
-
-void DrawingView::UpdateGridBackgroundF(void)
-{
-#if 0
- // Transform the origin to Qt coordinates
- Vector pixmapOrigin = Painter::CartesianToQtCoords(Vector());
- int x = 0;// (int)pixmapOrigin.x;
- int y = 0;// (int)pixmapOrigin.y;
- // Use mod arithmetic to grab the correct swatch of background
-
-/* if (x < 0)
- x = -x % gridPixels;
- else
- x = (gridPixels - (x % gridPixels)) % gridPixels;
-
- if (y < 0)
- y = -y % gridPixels;
- else
- y = (gridPixels - (y % gridPixels)) % gridPixels;*/
-
- // Here we grab a section of the bigger pixmap, so that the background
- // *looks* like it's scrolling...
- QPixmap pm = gridBackground.copy(x, y, gridPixelsF, gridPixelsF);
- QPalette pal = palette();
- pal.setBrush(backgroundRole(), QBrush(pm));
- setAutoFillBackground(true);
- setPalette(pal);
-#endif
-}
-#endif
-
//
// Basically, we just make a single pass through the Container. If the layer #
// is less than the layer # being deleted, then do nothing. If the layer # is
break;
}
+ case OTPolyline:
+ {
+ break;
+ }
+
case OTContainer:
{
// Containers require recursive rendering...
return v;
}
-VPVector DrawingView::GetHovered(void)
+//
+// When testing for hovered intersections, we need to be able to exclude some
+// objects which have funky characteristics or handles; so we allow for that
+// here.
+//
+VPVector DrawingView::GetHovered(bool exclude/*= false*/)
{
VPVector v;
for(VPVectorIter i=document.objects.begin(); i!=document.objects.end(); i++)
{
- if (((Object *)(*i))->hovered)
+ Object * obj = (Object *)(*i);
+
+ if (obj->hovered)
+ {
+ if (exclude
+ && ((obj->type == OTDimension)
+ || ((obj->type == OTCircle) && (obj->hitPoint[0] == true))
+ || ((obj->type == OTArc) && (obj->hitPoint[0] == true))
+ || (draggingObject && (obj == dragged))))
+ continue;
+
v.push_back(*i);
+ }
}
return v;
void DrawingView::resizeEvent(QResizeEvent * /*event*/)
{
Global::screenSize = Vector(size().width(), size().height());
-// UpdateGridBackground();
}
void DrawingView::ToolHandler(int mode, Point p)
switch (mode)
{
case ToolMouseDown:
+/* toolObj[0] = NULL;
+
+ // Check to see if we can do a circle tangent snap
+ if (numHovered == 1)
+ {
+ VPVector hover = GetHovered();
+ Object * obj = (Object *)hover[0];
+
+ // Save for later if the object clicked was a circle (need to check that it wasn't the center clicked on, because that will fuck up connecting centers of circles with lines... and now we do! :-)
+ if ((obj->type == OTCircle) && (obj->hitPoint[0] == false))
+ toolObj[0] = obj;
+ }*/
+
if (Global::toolState == TSNone)
toolPoint[0] = p;
else
if (Global::toolState == TSNone)
toolPoint[0] = p;
else
+ {
toolPoint[1] = p;
+/* bool isCircle = false;
+
+ if (numHovered == 1)
+ {
+ VPVector hover = GetHovered();
+ Object * obj = (Object *)hover[0];
+
+ if ((obj->type == OTCircle) && (obj->hitPoint[0] == false))
+ {
+ isCircle = true;
+ toolObj[1] = obj;
+ }
+ }
+
+ // Adjust initial point if it's on a circle (tangent point)
+ if (toolObj[0] != NULL)
+ {
+ if (isCircle)
+ {
+ Geometry::FindTangents(toolObj[0], toolObj[1]);
+
+ if (Global::numIntersectPoints > 0)
+ {
+ toolPoint[0] = Global::intersectPoint[0];
+ toolPoint[1] = Global::intersectPoint[1];
+ }
+ }
+ else
+ {
+ Geometry::FindTangents(toolObj[0], p);
+
+ if (Global::numIntersectPoints > 0)
+ toolPoint[0] = Global::intersectPoint[0];
+ }
+ }
+ else
+ {
+ if (isCircle)
+ {
+ Geometry::FindTangents(toolObj[1], toolPoint[0]);
+
+ if (Global::numIntersectPoints > 0)
+ toolPoint[1] = Global::intersectPoint[0];
+ }
+ }*/
+ }
break;
void DrawingView::TrimHandler(int mode, Point p)
{
/*
-n.b.: this code is lifted straight out of the old oo code. needs to be updated.
+N.B.: this code is lifted straight out of the old oo code. needs to be updated.
+ Also: trim tool should ignore snap.
*/
switch (mode)
{
// Do object hit testing...
bool needUpdate = HitTestObjects(point);
- VPVector hover2 = GetHovered();
+ VPVector hover2 = GetHovered(true); // Exclude dimension objects and circle centers (probably need to add arc centers too) from hover (also dragged objects...)
#if 0
{
if (needUpdate)
#endif
// Check for multi-hover...
- if (numHovered > 1)
+ if (hover2.size() > 1)
{
-//need to check for case where hover is over 2 circles and a 3rd's center...
+//need to check for case where hover is over 2 circles and a 3rd's center (no longer a problem, I think)...
Object * obj1 = (Object *)hover2[0], * obj2 = (Object *)hover2[1];
Geometry::Intersects(obj1, obj2);
intersectionPoint = v1;
}
}
- else if (numHovered == 1)
+ else if (hover2.size() == 1)
{
Object * obj = (Object *)hover2[0];
{
/*
Not sure that this is the best way to handle this, but it works(TM)...
-Except when lines are overlapping, then it doesn't work... !!! FIX !!!
*/
Point midpoint = Geometry::Midpoint((Line *)obj);
Vector v1 = Vector::Magnitude(midpoint, point);
needUpdate = true;
}
}
+ else if (obj->type == OTCircle)
+ {
+ if ((draggingObject && (dragged->type == OTLine)) && (dragged->hitPoint[0] || dragged->hitPoint[1]))
+ {
+ Point p = (dragged->hitPoint[0] ? dragged->p[1] : dragged->p[0]);
+ Geometry::FindTangents(obj, p);
+
+ if (Global::numIntersectPoints > 0)
+ {
+ hoveringIntersection = true;
+ intersectionPoint = Geometry::NearestTo(point, Global::intersectPoint[0], Global::intersectPoint[1]);
+ }
+ }
+ else if ((Global::tool == TTLine) && (Global::toolState == TSPoint2))
+ {
+ Geometry::FindTangents(obj, toolPoint[0]);
+
+ if (Global::numIntersectPoints > 0)
+ {
+ hoveringIntersection = true;
+ intersectionPoint = Geometry::NearestTo(point, Global::intersectPoint[0], Global::intersectPoint[1]);
+ }
+ }
+ }
}
// Handle object movement (left button down & over an object)
switch (obj->type)
{
case OTLine:
- case OTDimension:
+ case OTDimension: // N.B.: We don't check this properly...
{
Line * l = (Line *)obj;