// // Add a SimObj to a particular position in a given geometry and give the // object reasonable default positions for the other geometries as well. // The goal is to have the geometric relationships between the new object // and the existing objects be the same for all geometries. // // We assume that the object already has semi-reasonable positions for // all geometries, so if we don't have a great idea we just leave things // as they are. // bool SimWorkspace::addSimObjAtPosition(SimObj* obj, int x, int y, CanvasDefs::CanvasGeometry geom) { CanvasID canvasOrig; CanvasID canvas1; CanvasID canvas2; CanvasDefs::CanvasGeometry otherGeom1; CanvasDefs::CanvasGeometry otherGeom2; if (geom == CanvasDefs::Geom_SIMULATION) { otherGeom1 = CanvasDefs::Geom_ACCOUNTING; otherGeom2 = CanvasDefs::Geom_GEOSPATIAL; canvasOrig = CanvasDefs::CanvasID_SIMULATION; canvas1 = CanvasDefs::CanvasID_ACCOUNTING; canvas2 = CanvasDefs::CanvasID_GEOSPATIAL; } else if (geom == CanvasDefs::Geom_ACCOUNTING) { otherGeom1 = CanvasDefs::Geom_SIMULATION; otherGeom2 = CanvasDefs::Geom_GEOSPATIAL; canvasOrig = CanvasDefs::CanvasID_ACCOUNTING; canvas1 = CanvasDefs::CanvasID_SIMULATION; canvas2 = CanvasDefs::CanvasID_GEOSPATIAL; } else if (geom == CanvasDefs::Geom_GEOSPATIAL) { otherGeom1 = CanvasDefs::Geom_SIMULATION; otherGeom2 = CanvasDefs::Geom_ACCOUNTING; canvasOrig = CanvasDefs::CanvasID_GEOSPATIAL; canvas1 = CanvasDefs::CanvasID_SIMULATION; canvas2 = CanvasDefs::CanvasID_ACCOUNTING; } const QList objs (visibleObjects()); const int objCnt = objs.count(); objCnt; // (avoid compilation warning) QPoint lowerLeftOrig; QPoint lowerLeft1; QPoint lowerLeft2; QPoint upperRightOrig; QPoint upperRight1; QPoint upperRight2; objBoundingBox (objs, geom, lowerLeftOrig, upperRightOrig); objBoundingBox (objs, otherGeom1, lowerLeft1, upperRight1); objBoundingBox (objs, otherGeom2, lowerLeft2, upperRight2); const int widthOrig (upperRightOrig.x() - lowerLeftOrig.x()); const int width1 (upperRight1.x() - lowerLeft1.x()); const int width2 (upperRight2.x() - lowerLeft2.x()); const int heightOrig (upperRightOrig.y() - lowerLeftOrig.y()); const int height1 (upperRight1.y() - lowerLeft1.y()); const int height2 (upperRight2.y() - lowerLeft2.y()); if (!lowerLeftOrig.isNull() && (widthOrig > 0) && (heightOrig > 0)) { if (!lowerLeft1.isNull() && (width1 > 0) && (height1 > 0)) { int x1 = lowerLeft1.x() + (x - lowerLeftOrig.x())*(width1/widthOrig); int y1 = lowerLeft1.y() + (y - lowerLeftOrig.y())*(height1/heightOrig); ensureOnCanvas(canvas1, x1, y1, 50); obj->setXY(otherGeom1, x1, y1); } if (!lowerLeft2.isNull() && (width2 > 0) && (height2 > 0)) { int x2 = lowerLeft2.x() + (x - lowerLeftOrig.x())*(width2/widthOrig); int y2 = lowerLeft2.y() + (y - lowerLeftOrig.y())*(height2/heightOrig); ensureOnCanvas(canvas2, x2, y2, 50); obj->setXY(otherGeom2, x2, y2); } } return addSimObj(obj); } =============================================================================== // Get the bounding box void objBoundingBox(QList objs, CanvasDefs::CanvasGeometry geom, QPoint& lowerLeft, QPoint& upperRight) { QPoint curPos; for (int i = 0; i < objs.size(); ++i) { curPos = QPoint(objs[i]->getX(geom), objs[i]->getY(geom)); if (i == 0) { lowerLeft = curPos; upperRight = curPos; } else { if (curPos.x() < lowerLeft.x()) { lowerLeft.setX(curPos.x()); } if (curPos.x() > upperRight.x()) { upperRight.setX(curPos.x()); } if (curPos.y() < lowerLeft.y()) { lowerLeft.setY(curPos.y()); } if (curPos.y() > upperRight.y()) { upperRight.setY(curPos.y()); } } } } ---