3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // (C) 2010 Underground Software
8 // JLH = James L. Hammons <jlhamm@acm.org>
11 // --- ---------- -----------------------------------------------------------
12 // JLH 05/21/2010 Added this text. :-)
15 #include "rs_graphicview.h"
18 #include "rs_actioninterface.h"
19 #include "rs_application.h"
21 #include "rs_eventhandler.h"
22 #include "rs_graphic.h"
24 #include "rs_insert.h"
30 #include "paintintf.h"
36 RS_GraphicView::RS_GraphicView(): background(), foreground(), previewMode(false),
37 previewOffset(Vector(0, 0)), snapperDraw(false)
39 drawingMode = RS2::ModeFull;
42 factor = Vector(1.0, 1.0);
45 previousFactor = Vector(1.0, 1.0);
49 eventHandler = new RS_EventHandler(this);
51 metaGridColor = RS_Color(64, 64, 64);
52 grid = new RS_Grid(this);
65 relativeZero = Vector(false);
66 relativeZeroLocked = false;
70 defaultSnapMode = RS2::SnapFree;
71 defaultSnapRes = RS2::RestrictNothing;
74 background = RS_Color(0,0,0);
75 foreground = RS_Color(255,255,255);
76 gridColor = RS_Color("gray");
77 metaGridColor = RS_Color("#404040");
78 selectedColor = RS_Color("#a54747");
79 highlightedColor = RS_Color("#739373");
82 settings.beginGroup("Appearance");
83 setBackground(QColor(settings.value("BackgroundColor", "#000000").toString()));
84 setGridColor(QColor(settings.value("GridColor", "#7F7F7F").toString()));
85 setMetaGridColor(QColor(settings.value("MetaGridColor", "#3F3F3F").toString()));
86 setSelectedColor(QColor(settings.value("SelectedColor", "#A54747").toString()));
87 setHighlightedColor(QColor(settings.value("HighlightedColor", "#739373").toString()));
92 simulationSpeed = 100;
93 simulationSmooth = false;
94 simulationRapid = false;
95 simulationRunning = false;
97 //currentInsert = NULL;
103 RS_GraphicView::~RS_GraphicView()
105 //delete eventHandler;
113 * Must be called by any derrived class in the destructor.
115 void RS_GraphicView::cleanUp()
121 * @return Pointer to the graphic entity if the entity container
122 * connected to this view is a graphic and valid.
125 RS_Graphic * RS_GraphicView::getGraphic()
127 if (container != NULL && container->rtti() == RS2::EntityGraphic)
128 return (RS_Graphic*)container;
134 * Sets the drawing mode.
136 void RS_GraphicView::setDrawingMode(RS2::DrawingMode m)
142 * @return Current drawing mode.
144 RS2::DrawingMode RS_GraphicView::getDrawingMode()
150 * Activates or deactivates the delete mode.
152 void RS_GraphicView::setDeleteMode(bool m)
158 * @reval true Deleting instead of drawing.
159 * false Normal drawing mode.
161 bool RS_GraphicView::getDeleteMode()
166 /** This virtual method must be overwritten and is then
167 called whenever the view changed */
168 void RS_GraphicView::adjustOffsetControls()
172 /** This virtual method must be overwritten and is then
173 called whenever the view changed */
174 void RS_GraphicView::adjustZoomControls()
179 * Sets an external painter device.
181 //void RS_GraphicView::setPainter(RS_Painter * p)
182 void RS_GraphicView::setPainter(PaintInterface * p)
188 * Sets the background color. Note that applying the background
189 * color for the widget is up to the implementing class.
191 void RS_GraphicView::setBackground(const RS_Color & bg)
195 // bright background:
196 if (bg.red() + bg.green() + bg.blue() > 380)
197 // foreground = Qt::black;
198 foreground = RS_Color(0, 0, 0);
200 // foreground = Qt::white;
201 foreground = RS_Color(255, 255, 255);
205 * @return Current background color.
207 RS_Color RS_GraphicView::getBackground()
213 * @return Current foreground color.
215 RS_Color RS_GraphicView::getForeground()
221 * Sets the grid color.
223 void RS_GraphicView::setGridColor(const RS_Color & c)
229 * Sets the meta grid color.
231 void RS_GraphicView::setMetaGridColor(const RS_Color & c)
237 * Sets the selection color.
239 void RS_GraphicView::setSelectedColor(const RS_Color & c)
245 * Sets the highlight color.
247 void RS_GraphicView::setHighlightedColor(const RS_Color & c)
249 highlightedColor = c;
253 * This virtual method can be overwritten to set the mouse
254 * cursor to the given type.
256 void RS_GraphicView::setMouseCursor(RS2::CursorType /*c*/)
260 RS_EntityContainer * RS_GraphicView::getContainer()
265 void RS_GraphicView::setFactor(double f)
271 Vector RS_GraphicView::getFactor()
277 * Sets the offset of the graphic.
279 void RS_GraphicView::setOffset(int ox, int oy)
285 void RS_GraphicView::setOffsetX(int ox)
290 void RS_GraphicView::setOffsetY(int oy)
295 int RS_GraphicView::getOffsetX()
300 int RS_GraphicView::getOffsetY()
306 * Sets a fixed border in pixel around the graphic. This border
307 * specifies how far the user can scroll outside the graphic
310 void RS_GraphicView::setBorders(int left, int top, int right, int bottom)
315 borderBottom = bottom;
318 int RS_GraphicView::getBorderLeft()
323 int RS_GraphicView::getBorderTop()
328 int RS_GraphicView::getBorderRight()
333 int RS_GraphicView::getBorderBottom()
338 void RS_GraphicView::disableUpdate()
343 void RS_GraphicView::enableUpdate()
348 bool RS_GraphicView::isUpdateEnabled()
350 return (updateEnabled == 0);
353 void RS_GraphicView::freezeZoom(bool freeze)
358 bool RS_GraphicView::isZoomFrozen()
364 * Sets the pointer to the graphic which contains the entities
365 * which are visualized by this widget.
367 void RS_GraphicView::setContainer(RS_EntityContainer * container)
369 this->container = container;
370 //adjustOffsetControls();
374 * Sets the zoom factor in X for this visualization of the graphic.
376 void RS_GraphicView::setFactorX(double f)
383 * Sets the zoom factor in Y for this visualization of the graphic.
385 void RS_GraphicView::setFactorY(double f)
392 * @return true if the grid is switched on.
394 bool RS_GraphicView::isGridOn()
396 if (container != NULL)
398 RS_Graphic * g = container->getGraphic();
401 return g->isGridOn();
408 * Centers the drawing in x-direction.
410 void RS_GraphicView::centerOffsetX()
412 if (container != NULL && !zoomFrozen)
413 offsetX = (int)(((getWidth() - borderLeft - borderRight)
414 - (container->getSize().x * factor.x)) / 2.0
415 - (container->getMin().x * factor.x)) + borderLeft;
419 * Centers the drawing in y-direction.
421 void RS_GraphicView::centerOffsetY()
423 if (container != NULL && !zoomFrozen)
424 offsetY = (int)((getHeight() - borderTop - borderBottom
425 - (container->getSize().y * factor.y)) / 2.0
426 - (container->getMin().y * factor.y)) + borderBottom;
430 * Centers the given coordinate in the view in x-direction.
432 void RS_GraphicView::centerX(double v)
435 offsetX = (int)((v * factor.x) - (double)(getWidth() - borderLeft - borderRight) / 2.0);
439 * Centers the given coordinate in the view in y-direction.
441 void RS_GraphicView::centerY(double v)
444 offsetY = (int)((v * factor.y) - (double)(getHeight() - borderTop - borderBottom) / 2.0);
447 void RS_GraphicView::updateView()
449 static int running = 0;
454 adjustZoomControls();
455 adjustOffsetControls();
465 * @return Current action or NULL.
467 RS_ActionInterface * RS_GraphicView::getDefaultAction()
469 if (eventHandler != NULL)
470 return eventHandler->getDefaultAction();
476 * Sets the default action of the event handler.
478 void RS_GraphicView::setDefaultAction(RS_ActionInterface * action)
480 if (eventHandler != NULL)
481 eventHandler->setDefaultAction(action);
485 * @return Current action or NULL.
487 RS_ActionInterface * RS_GraphicView::getCurrentAction()
489 if (eventHandler != NULL)
490 return eventHandler->getCurrentAction();
496 * Sets the current action of the event handler.
498 void RS_GraphicView::setCurrentAction(RS_ActionInterface * action)
500 RS_DEBUG->print("RS_GraphicView::setCurrentAction");
502 if (eventHandler != NULL)
503 eventHandler->setCurrentAction(action);
505 RS_DEBUG->print("RS_GraphicView::setCurrentAction: OK");
509 * Kills all running selection actions. Called when a selection action
510 * is launched to reduce confusion.
512 void RS_GraphicView::killSelectActions()
514 if (eventHandler != NULL)
515 eventHandler->killSelectActions();
519 * Kills all running actions.
521 void RS_GraphicView::killAllActions()
523 if (eventHandler != NULL)
524 eventHandler->killAllActions();
528 * Go back in menu or current action.
530 void RS_GraphicView::back()
532 if (eventHandler != NULL && eventHandler->hasAction())
533 eventHandler->back();
535 if (RS_DIALOGFACTORY != NULL)
536 RS_DIALOGFACTORY->requestPreviousMenu();
540 * Go forward with the current action.
542 void RS_GraphicView::enter()
544 if (eventHandler != NULL && eventHandler->hasAction())
545 eventHandler->enter();
549 * Called by the actual GUI class which implements the RS_GraphicView
550 * interface to notify qcadlib about mouse events.
552 void RS_GraphicView::mousePressEvent(QMouseEvent * e)
554 if (eventHandler != NULL)
555 eventHandler->mousePressEvent(e);
559 * Called by the actual GUI class which implements the RS_GraphicView
560 * interface to notify qcadlib about mouse events.
562 void RS_GraphicView::mouseReleaseEvent(QMouseEvent * e)
564 RS_DEBUG->print("RS_GraphicView::mouseReleaseEvent");
566 if (eventHandler != NULL)
568 if (RS2::qtToRsButtonState(e->button()) != RS2::RightButton
569 || eventHandler->hasAction())
571 eventHandler->mouseReleaseEvent(e);
577 //#if QT_VERSION>=0x030000
584 RS_DEBUG->print("RS_GraphicView::mouseReleaseEvent: OK");
588 * Called by the actual GUI class which implements the RS_GraphicView
589 * interface to notify qcadlib about mouse events.
591 void RS_GraphicView::mouseMoveEvent(QMouseEvent * e)
593 RS_DEBUG->print("RS_GraphicView::mouseMoveEvent begin");
595 RS_Graphic * graphic = NULL;
597 if (container->rtti() == RS2::EntityGraphic)
598 graphic = (RS_Graphic *)container;
600 RS_DEBUG->print("RS_GraphicView::mouseMoveEvent 001");
608 RS_DEBUG->print("RS_GraphicView::mouseMoveEvent 002");
610 if (eventHandler != NULL)
611 eventHandler->mouseMoveEvent(e);
613 RS_DEBUG->print("RS_GraphicView::mouseMoveEvent 003");
615 if (eventHandler == NULL || !eventHandler->hasAction() && graphic != NULL)
617 Vector mouse = toGraph(Vector(mx, my));
618 Vector relMouse = mouse - getRelativeZero();
620 if (RS_DIALOGFACTORY != NULL)
621 RS_DIALOGFACTORY->updateCoordinateWidget(mouse, relMouse);
624 RS_DEBUG->print("RS_GraphicView::mouseMoveEvent end");
628 * Called by the actual GUI class which implements the RS_GraphicView
629 * interface to notify qcadlib about mouse events.
631 void RS_GraphicView::mouseLeaveEvent()
633 if (eventHandler != NULL)
634 eventHandler->mouseLeaveEvent();
638 * Called by the actual GUI class which implements the RS_GraphicView
639 * interface to notify qcadlib about mouse events.
641 void RS_GraphicView::mouseEnterEvent()
643 if (eventHandler != NULL)
644 eventHandler->mouseEnterEvent();
648 * Called by the actual GUI class which implements the RS_GraphicView
649 * interface to notify qcadlib about key events.
651 void RS_GraphicView::keyPressEvent(QKeyEvent * e)
653 if (eventHandler != NULL)
654 eventHandler->keyPressEvent(e);
658 * Called by the actual GUI class which implements the RS_GraphicView
659 * interface to notify qcadlib about key events.
661 void RS_GraphicView::keyReleaseEvent(QKeyEvent * e)
663 if (eventHandler != NULL)
664 eventHandler->keyReleaseEvent(e);
668 * Called by the actual GUI class which implements a command line.
670 void RS_GraphicView::commandEvent(RS_CommandEvent * e)
672 if (eventHandler != NULL)
673 eventHandler->commandEvent(e);
677 * Enables coordinate input in the command line.
679 void RS_GraphicView::enableCoordinateInput()
681 if (eventHandler != NULL)
682 eventHandler->enableCoordinateInput();
686 * Disables coordinate input in the command line.
688 void RS_GraphicView::disableCoordinateInput()
690 if (eventHandler != NULL)
691 eventHandler->disableCoordinateInput();
695 * zooms in by factor f
697 void RS_GraphicView::zoomIn(double f, const Vector & center)
701 RS_DEBUG->print(RS_Debug::D_WARNING, "RS_GraphicView::zoomIn: invalid factor");
705 if (simulationRunning)
709 if (c.valid == false)
710 c = toGraph(Vector(getWidth() / 2, getHeight() / 2));
713 toGraph(Vector(0, 0)).scale(c, Vector(1.0 / f, 1.0 / f)),
714 toGraph(Vector(getWidth(), getHeight())).scale(c, Vector(1.0 / f, 1.0 / f)));
716 //adjustOffsetControls();
717 //adjustZoomControls();
723 * zooms in by factor f in x
725 void RS_GraphicView::zoomInX(double f)
727 if (simulationRunning)
731 offsetX = (int)((offsetX - getWidth() / 2) * f) + getWidth() / 2;
732 adjustOffsetControls();
733 adjustZoomControls();
739 * zooms in by factor f in y
741 void RS_GraphicView::zoomInY(double f)
743 if (simulationRunning)
747 offsetY = (int)((offsetY - getHeight() / 2) * f)+getHeight() / 2;
748 adjustOffsetControls();
749 adjustZoomControls();
755 * zooms out by factor f
757 void RS_GraphicView::zoomOut(double f, const Vector & center)
761 RS_DEBUG->print(RS_Debug::D_WARNING,
762 "RS_GraphicView::zoomOut: invalid factor");
766 if (simulationRunning)
773 * zooms out by factor f in x
775 void RS_GraphicView::zoomOutX(double f)
779 RS_DEBUG->print(RS_Debug::D_WARNING,
780 "RS_GraphicView::zoomOutX: invalid factor");
784 if (simulationRunning)
788 offsetX = (int)(offsetX / f);
789 adjustOffsetControls();
790 adjustZoomControls();
796 * zooms out by factor f y
798 void RS_GraphicView::zoomOutY(double f)
802 RS_DEBUG->print(RS_Debug::D_WARNING,
803 "RS_GraphicView::zoomOutY: invalid factor");
807 if (simulationRunning)
811 offsetY = (int)(offsetY / f);
812 adjustOffsetControls();
813 adjustZoomControls();
821 * @param axis include axis in zoom
822 * @param keepAspectRatio true: keep aspect ratio 1:1
823 * false: factors in x and y are stretched to the max
825 void RS_GraphicView::zoomAuto(bool axis, bool keepAspectRatio)
827 RS_DEBUG->print("RS_GraphicView::zoomAuto");
829 if (simulationRunning)
834 if (container != NULL)
836 container->calculateBorders();
841 sx = std::max(container->getMax().x, 0.0) - std::min(container->getMin().x, 0.0);
842 sy = std::max(container->getMax().y, 0.0) - std::min(container->getMin().y, 0.0);
846 sx = container->getSize().x;
847 sy = container->getSize().y;
852 if (sx > RS_TOLERANCE)
853 fx = (getWidth() - borderLeft - borderRight) / sx;
857 if (sy > RS_TOLERANCE)
858 fy = (getHeight() - borderTop - borderBottom) / sy;
862 RS_DEBUG->print("f: %f/%f", fx, fy);
865 fx = fy = std::min(fx, fy);
867 RS_DEBUG->print("f: %f/%f", fx, fy);
869 if (fx < RS_TOLERANCE)
875 RS_DEBUG->print("f: %f/%f", fx, fy);
877 RS_DEBUG->print("adjustOffsetControls");
878 adjustOffsetControls();
879 RS_DEBUG->print("adjustZoomControls");
880 adjustZoomControls();
881 RS_DEBUG->print("centerOffsetX");
883 RS_DEBUG->print("centerOffsetY");
885 RS_DEBUG->print("updateGrid");
890 RS_DEBUG->print("RS_GraphicView::zoomAuto OK");
894 * Shows previous view.
896 void RS_GraphicView::zoomPrevious()
898 RS_DEBUG->print("RS_GraphicView::zoomPrevious");
900 if (simulationRunning)
903 if (container != NULL)
908 * Saves the current view as previous view to which we can
909 * switch back later with @see restoreView().
911 void RS_GraphicView::saveView()
913 previousOffsetX = offsetX;
914 previousOffsetY = offsetY;
915 previousFactor = factor;
919 * Restores the view previously saved with
922 void RS_GraphicView::restoreView()
924 int pox = previousOffsetX;
925 int poy = previousOffsetY;
926 Vector pf = previousFactor;
934 adjustOffsetControls();
935 adjustZoomControls();
941 * performs autozoom in y only
943 * @param axis include axis in zoom
945 void RS_GraphicView::zoomAutoY(bool axis)
947 if (simulationRunning)
950 if (container != NULL)
952 double visibleHeight = 0.0;
953 double minY = RS_MAXDOUBLE;
954 double maxY = RS_MINDOUBLE;
955 bool noChange = false;
957 for(RS_Entity * e=container->firstEntity(RS2::ResolveNone);
958 e!=NULL; e = container->nextEntity(RS2::ResolveNone))
960 if (e->rtti() == RS2::EntityLine)
962 RS_Line * l = (RS_Line *)e;
964 x1 = toGuiX(l->getStartpoint().x);
965 x2 = toGuiX(l->getEndpoint().x);
967 if (x1 > 0.0 && x1 < (double)getWidth() || x2 > 0.0 && x2 < (double)getWidth())
969 minY = std::min(minY, l->getStartpoint().y);
970 minY = std::min(minY, l->getEndpoint().y);
971 maxY = std::max(maxY, l->getStartpoint().y);
972 maxY = std::max(maxY, l->getEndpoint().y);
978 visibleHeight = std::max(maxY, 0.0) - std::min(minY, 0.0);
980 visibleHeight = maxY - minY;
982 if (visibleHeight < 1.0)
987 if (visibleHeight > 1.0e-6)
989 fy = (getHeight() - borderTop - borderBottom) / visibleHeight;
991 if (factor.y < 0.000001)
995 if (noChange == false)
999 offsetY = (int)((getHeight() - borderTop - borderBottom - (visibleHeight * factor.y)) / 2.0
1000 - (minY * factor.y)) + borderBottom;
1001 adjustOffsetControls();
1002 adjustZoomControls();
1006 RS_DEBUG->print("Auto zoom y ok");
1011 * Zooms the area given by v1 and v2.
1013 * @param keepAspectRatio true: keeps the aspect ratio 1:1
1014 * false: zooms exactly the selected range to the
1015 * current graphic view
1017 void RS_GraphicView::zoomWindow(Vector v1, Vector v2, bool keepAspectRatio)
1019 if (simulationRunning)
1024 double zoomX = 480.0; // Zoom for X-Axis
1025 double zoomY = 640.0; // Zoom for Y-Axis (Set smaller one)
1026 double dum; // Dummy for switching values
1029 // Switch left/right and top/bottom is necessary:
1044 // Get zoom in X and zoom in Y:
1045 if (v2.x - v1.x > 1.0e-6)
1046 zoomX = getWidth() / (v2.x - v1.x);
1048 if (v2.y - v1.y > 1.0e-6)
1049 zoomY = getHeight() / (v2.y - v1.y);
1051 // Take smaller zoom:
1052 if (keepAspectRatio)
1056 if (getWidth() != 0)
1058 zoomX = zoomY = ((double)(getWidth() - 2 * zoomBorder)) /
1059 (double)getWidth() * zoomX;
1064 if (getHeight() != 0)
1066 zoomX = zoomY = ((double)(getHeight() - 2 * zoomBorder)) /
1067 (double)getHeight() * zoomY;
1078 // Borders in pixel after zoom
1079 int pixLeft = (int)(v1.x * zoomX);
1080 int pixTop = (int)(v2.y * zoomY);
1081 int pixRight = (int)(v2.x * zoomX);
1082 int pixBottom = (int)(v1.y * zoomY);
1084 // Set new offset for zero point:
1085 offsetX = - pixLeft + (getWidth() - pixRight + pixLeft) / 2;
1086 offsetY = - pixTop + (getHeight() - pixBottom + pixTop) / 2;
1090 adjustOffsetControls();
1091 adjustZoomControls();
1097 * Centers the point v1.
1099 void RS_GraphicView::zoomPan(int dx, int dy)
1101 //offsetX+=(int)toGuiDX(v1.x);
1102 //offsetY+=(int)toGuiDY(v1.y);
1103 if (simulationRunning)
1110 adjustOffsetControls();
1111 //adjustZoomControls();
1118 * Scrolls in the given direction.
1120 void RS_GraphicView::zoomScroll(RS2::Direction direction)
1122 if (simulationRunning)
1141 adjustOffsetControls();
1142 adjustZoomControls();
1148 * Zooms to page extends.
1150 void RS_GraphicView::zoomPage()
1152 RS_DEBUG->print("RS_GraphicView::zoomPage");
1154 if (container == NULL)
1157 if (simulationRunning)
1160 RS_Graphic * graphic = container->getGraphic();
1162 if (graphic == NULL)
1165 Vector s = graphic->getPaperSize();
1166 Vector pinsbase = graphic->getPaperInsertionBase();
1170 if (s.x > RS_TOLERANCE)
1171 fx = (getWidth() - borderLeft - borderRight) / s.x;
1175 if (s.y > RS_TOLERANCE)
1176 fy = (getHeight() - borderTop - borderBottom) / s.y;
1180 RS_DEBUG->print("f: %f/%f", fx, fy);
1182 fx = fy = std::min(fx, fy);
1184 RS_DEBUG->print("f: %f/%f", fx, fy);
1186 if (fx < RS_TOLERANCE)
1192 RS_DEBUG->print("f: %f/%f", fx, fy);
1196 adjustOffsetControls();
1197 adjustZoomControls();
1203 * Draws the entities within the given range.
1205 void RS_GraphicView::drawWindow(Vector v1, Vector v2)
1207 RS_DEBUG->print("RS_GraphicView::drawWindow() begin");
1209 if (simulationRunning)
1212 if (container != NULL)
1214 for (RS_Entity * se=container->firstEntity(RS2::ResolveNone);
1215 se!=NULL; se = container->nextEntity(RS2::ResolveNone))
1217 if (se->isInWindow(v1, v2))
1222 RS_DEBUG->print("RS_GraphicView::drawWindow() end");
1226 * Draws the entities. If painter is NULL a new painter will
1227 * be created and destroyed.
1229 void RS_GraphicView::drawIt()
1231 if (!isUpdateEnabled())
1233 //printf("RS_GraphicView::drawIt(): isUpdateEnabled() == false!\n");
1237 if (simulationRunning)
1239 //printf("RS_GraphicView::drawIt(): simulationRunning == true!\n");
1243 // bool painterCreated = false;
1245 settings.beginGroup("Appearance");
1246 draftMode = settings.value("DraftMode", false).toBool();
1247 settings.endGroup();
1249 //RS_DEBUG->print("RS_GraphicView::drawIt() begin");
1250 //RS_DEBUG->print(" factors: %f/%f", factor.x, factor.y);
1251 //RS_DEBUG->timestamp();
1253 if (painter == NULL)
1255 printf("RS_GraphicView::drawIt(): painter == NULL!\n");
1258 // painterCreated = true;
1263 // drawing paper border:
1264 if (isPrintPreview())
1266 // drawing meta grid:
1271 // painter->setPen(RS_Pen(foreground, RS2::Width00, RS2::SolidLine));
1274 // drawing entities:
1275 //#warning "!!! This looks like a bug, no match for 'drawEntity(RS_Entity *, bool) !!!"
1276 // and indeed it *is* a bug... true is converted to 1.0 here. Dumb, dumb, dumb.
1277 drawEntity(container, true);
1279 //RS_DEBUG->timestamp();
1280 //RS_DEBUG->print(" draw zero..");
1282 // drawing zero points:
1283 if (!isPrintPreview())
1289 //RS_DEBUG->timestamp();
1290 //RS_DEBUG->print(" draw grid..");
1293 if (!isPrintPreview())
1296 //RS_DEBUG->timestamp();
1297 //RS_DEBUG->print("RS_GraphicView::drawIt() end");
1298 // if (painterCreated == true)
1299 // destroyPainter();
1303 * Sets the pen of the painter object to the suitable pen for the given
1306 void RS_GraphicView::setPenForEntity(RS_Entity * e)
1308 if (drawingMode == RS2::ModePreview /*|| draftMode==true*/)
1311 // set color of entity
1312 if (painter != NULL && !painter->isPreviewMode())
1314 // Getting pen from entity (or layer)
1315 RS_Pen pen = e->getPen(true);
1317 int w = pen.getWidth();
1325 double uf = 1.0; // unit factor
1326 double wf = 1.0; // width factor
1327 RS_Graphic * graphic = container->getGraphic();
1329 if (graphic != NULL)
1331 uf = RS_Units::convert(1.0, RS2::Millimeter, graphic->getUnit());
1333 if ((isPrinting() || isPrintPreview()) && graphic->getPaperScale() > 1.0e-6)
1334 wf = 1.0 / graphic->getPaperScale();
1337 pen.setScreenWidth(toGuiDX(w / 100.0 * uf * wf));
1341 //pen.setWidth(RS2::Width00);
1342 pen.setScreenWidth(0);
1345 // prevent drawing with 1-width which is slow:
1346 if (RS_Math::round(pen.getScreenWidth()) == 1)
1347 pen.setScreenWidth(0.0);
1349 // prevent background color on background drawing:
1350 if (pen.getColor().stripFlags() == background.stripFlags())
1351 pen.setColor(foreground);
1353 // this entity is selected:
1354 if (e->isSelected())
1356 pen.setLineType(RS2::DotLine);
1357 //pen.setColor(RS_Color(0xa5,0x47,0x47));
1358 pen.setColor(selectedColor);
1361 // this entity is highlighted:
1362 if (e->isHighlighted())
1364 //pen.setColor(RS_Color(0x73, 0x93, 0x73));
1365 pen.setColor(highlightedColor);
1368 // deleting not drawing:
1369 if (getDeleteMode())
1370 pen.setColor(background);
1372 painter->setPen(pen);
1377 * Draws an entity. Might be recusively called e.g. for polylines.
1378 * If the class wide painter is NULL a new painter will be created
1379 * and destroyed afterwards.
1381 * @param patternOffset Offset of line pattern (used for connected
1382 * lines e.g. in splines).
1383 * @param db Double buffering on (recommended) / off
1385 void RS_GraphicView::drawEntity(RS_Entity * e, double patternOffset, bool db)
1387 //RS_DEBUG->print("RS_GraphicView::drawEntity() begin");
1389 // update is diabled:
1390 if (!isUpdateEnabled())
1393 // given entity is NULL:
1397 // entity is not visible:
1398 if (!e->isVisible())
1401 // test if the entity is in the viewport
1402 if (!e->isContainer() && !isPrinting()
1403 && (painter == NULL || !painter->isPreviewMode())
1404 && (toGuiX(e->getMax().x) < 0 || toGuiX(e->getMin().x) > getWidth()
1405 || toGuiY(e->getMin().y) < 0 || toGuiY(e->getMax().y) > getHeight()))
1407 //printf("RS_GraphicView::drawEntity(): Bailing out of big test!!!\n");
1412 //RS_DEBUG->print("recursion 1: %d", drawRecursion);
1417 //RS_DEBUG->print("draw plain");
1420 // large texts as rectangles:
1421 if (e->rtti() == RS2::EntityText)
1423 if (toGuiDX(((RS_Text *)e)->getHeight()) < 4 || e->countDeep() > 100)
1424 painter->drawRect(toGui(e->getMin()), toGui(e->getMax()));
1426 drawEntityPlain(e, patternOffset);
1428 // all images as rectangles:
1429 else if (e->rtti() == RS2::EntityImage)
1430 painter->drawRect(toGui(e->getMin()), toGui(e->getMax()));
1432 else if (e->rtti() == RS2::EntityHatch)
1437 drawEntityPlain(e, patternOffset);
1440 drawEntityPlain(e, patternOffset);
1442 // draw reference points:
1443 if (e->isSelected())
1445 if (!e->isParentSelected())
1447 VectorSolutions s = e->getRefPoints();
1449 for(int i=0; i<s.getNumber(); ++i)
1452 RS_Color col = RS_Color(0, 0, 255);
1454 if (e->rtti() == RS2::EntityPolyline)
1456 if (i == 0 || i == s.getNumber() - 1)
1461 // col = QColor(0, 64, 255);
1462 col = RS_Color(0, 64, 255);
1467 // col = QColor(0, 0, 128);
1468 col = RS_Color(0, 0, 128);
1473 if (getDeleteMode())
1474 painter->drawHandle(toGui(s.get(i)), background, sz);
1476 painter->drawHandle(toGui(s.get(i)), col, sz);
1481 //RS_DEBUG->print("draw plain OK");
1482 //RS_DEBUG->print("RS_GraphicView::drawEntity() end");
1486 * Deletes an entity with the background color.
1487 * Might be recusively called e.g. for polylines.
1489 void RS_GraphicView::deleteEntity(RS_Entity * e)
1491 setDeleteMode(true);
1493 setDeleteMode(false);
1498 * The painter must be initialized and all the attributes (pen) must be set.
1500 void RS_GraphicView::drawEntityPlain(RS_Entity * e, double patternOffset)
1504 //printf("RS_GraphicView::drawEntityPlain(): Entity passed in is NULL!\n");
1508 //printf("RS_GraphicView::drawEntityPlain(): Passing in painter=%08X, view=%08X\n", painter, this);
1509 e->draw(painter, this, patternOffset);
1513 * Simulates this drawing in slow motion.
1515 void RS_GraphicView::simulateIt()
1517 if (simulationRunning)
1520 simulationRunning = true;
1521 simulationLast = Vector(0.0, 0.0);
1525 createDirectPainter();
1528 // drawing paper border:
1529 if (isPrintPreview())
1532 // drawing meta grid:
1533 if (!isPrintPreview())
1537 if (!isPrintPreview())
1541 //painter->setPen(RS_Pen(foreground,
1542 // RS2::Width00, RS2::SolidLine));
1545 // drawing entities:
1546 RS_Pen pen(foreground, RS2::Width00, RS2::SolidLine);
1547 simulateEntity(container, pen);
1549 //RS_DEBUG->timestamp();
1550 //RS_DEBUG->print(" draw zero..");
1552 // drawing zero points:
1553 if (!isPrintPreview())
1559 //RS_DEBUG->timestamp();
1560 //RS_DEBUG->print(" draw grid..");
1562 //RS_DEBUG->timestamp();
1563 //RS_DEBUG->print("RS_GraphicView::drawIt() end");
1564 //if (painterCreated==true) {
1567 simulationRunning = false;
1571 * Simulates the given entity.
1573 * @param smooth If true, the entity will be drawn slowly (pixel by pixel).
1575 void RS_GraphicView::simulateEntity(RS_Entity * e, const RS_Pen & pen)
1577 if (painter == NULL || e == NULL)
1580 if (e->isContainer())
1582 RS_EntityContainer * ec = (RS_EntityContainer *)e;
1584 for(RS_Entity* en=ec->firstEntity(RS2::ResolveNone);
1585 en!=NULL; en = ec->nextEntity(RS2::ResolveNone))
1587 if (en->isVisible() && en->isUndone() == false)
1590 if (en->isAtomic() && simulationRapid)
1592 Vector sp = ((RS_AtomicEntity *)en)->getStartpoint();
1594 if (sp.distanceTo(simulationLast) > 1.0e-4)
1596 createDirectPainter();
1597 RS_Pen rpen(RS_Color(0, 0, 255), RS2::Width00, RS2::SolidLine);
1598 //painter->setPen(pen);
1599 RS_Line rapidLine(NULL, RS_LineData(simulationLast, sp));
1600 simulateEntity(&rapidLine, rpen);
1604 if (en->isHighlighted())
1606 RS_Pen hpen(highlightedColor, RS2::Width00, RS2::SolidLine);
1607 simulateEntity(en, hpen);
1610 simulateEntity(en, pen);
1613 simulationLast = ((RS_AtomicEntity *)en)->getEndpoint();
1615 if (!simulationSmooth)
1616 simulationDelay(true);
1622 if (simulationSmooth)
1626 case RS2::EntityLine:
1628 RS_Line * line = (RS_Line *)e;
1629 drawLineSmooth(toGui(line->getStartpoint()), toGui(line->getEndpoint()), pen);
1634 case RS2::EntityArc:
1636 RS_Arc * arc = (RS_Arc *)e;
1637 drawArcSmooth(toGui(arc->getCenter()), toGuiDX(arc->getRadius()),
1638 arc->getAngle1(), arc->getAngle2(), arc->isReversed(), pen);
1642 case RS2::EntityCircle:
1644 RS_Circle * circle = (RS_Circle *)e;
1645 drawArcSmooth(toGui(circle->getCenter()), toGuiDX(circle->getRadius()),
1646 0.0, 2.0 * M_PI, false, pen);
1656 createDirectPainter();
1657 //RS_Pen pen(foreground, RS2::Width00, RS2::SolidLine);
1658 painter->setPen(pen);
1665 * Delay for slow motion simulation.
1667 * @param step true: stepping mode (entity by entity simulation). adds a delay.
1669 void RS_GraphicView::simulationDelay(bool step)
1672 settings.beginGroup("CAM");
1673 double fact = settings.value("SimulationFactor", 12000.0).toDouble();
1674 settings.endGroup();
1676 // simulationSpeed: 0..100
1679 delay = (int)(((1.0 / (simulationSpeed + 1.0)) * fact) - (fact / 100.0));
1684 static int call = 0;
1686 if (call >= (fact - delay) / 1000)
1689 for(int i=0; i<delay; ++i)
1690 RS_APP->processEvents(10);
1695 delay = (int)(((1.0 / (simulationSpeed + 1.0)) * fact) - (fact / 100.0));
1702 for(int i=0; i<delay; ++i)
1704 #warning "Qt3->4 conversion: commented out problem line... !!! FIX !!!"
1705 // RS_APP->processEvents(10);
1711 * Draws a line slowly from (x1, y1) to (x2, y2). This is used for simulation only.
1713 void RS_GraphicView::drawLineSmooth(const Vector & p1, const Vector & p2, const RS_Pen & pen)
1715 double alpha = p1.angleTo(p2);
1716 double xStep, yStep;
1719 if (RS_Math::cmpDouble(alpha, 0.0) || RS_Math::cmpDouble(alpha, 2 * M_PI))
1725 else if (RS_Math::cmpDouble(alpha, M_PI / 2.0))
1731 else if (RS_Math::cmpDouble(alpha, M_PI))
1737 else if (RS_Math::cmpDouble(alpha, M_PI / 2.0 * 3.0))
1743 else if (fabs(p2.x - p1.x) > fabs(p2.y - p1.y))
1750 yStep = tan(alpha) * xStep;
1760 xStep = yStep / tan(alpha);
1766 //RS_Pen pen(foreground, RS2::Width00, RS2::SolidLine);
1770 if (lx >= 0.0 && lx <= (double)getWidth() && ly >= 0.0 && ly <= (double)getHeight())
1772 //if (painter==NULL) {
1773 createDirectPainter();
1775 painter->setPen(pen);
1776 painter->drawGridPoint(Vector(lx, ly));
1785 while ((xIsOne && ((lx >= p1.x && lx <= p2.x) || (lx >= p2.x && lx <= p1.x)))
1786 || (!xIsOne && ((ly >= p1.y && ly <= p2.y) || (ly >= p2.y && ly <= p1.y))));
1789 void RS_GraphicView::drawArcSmooth(const Vector & center, double radius, double a1, double a2, bool rev,
1792 //int icx = graphic->realToScreenX(cx);
1793 //int icy = graphic->realToScreenY(cy);
1794 //RS_Pen pen(foreground, RS2::Width00, RS2::SolidLine);
1798 createDirectPainter();
1799 painter->setPen(pen);
1800 painter->drawGridPoint(center);
1804 int ix1 = RS_Math::round(center.x + cos(a1) * radius);
1805 int iy1 = RS_Math::round(center.y - sin(a1) * radius);
1806 int ix2 = RS_Math::round(center.x + cos(a2) * radius);
1807 int iy2 = RS_Math::round(center.y - sin(a2) * radius);
1808 int k2x = 0; // Next point on circle
1810 int k1x = ix1; // Prev point on circle
1812 double aStep; // Angle Step (rad)
1813 double a; // Actual Angle (rad)
1814 double a2cp = a2; // Copy of a2
1816 if (1.0 / (radius * factor.x) <= 1.0)
1817 aStep = asin(1.0 / (radius * factor.x));
1826 // Arc Counterclockwise:
1828 if (a1 > a2cp - 0.01)
1831 //if (painter==NULL) {
1832 //painter->setPen(pen);
1833 //createDirectPainter();
1835 //painter->moveTo(ix1, iy1);
1837 for(a=a1+aStep; a<=a2cp; a+=aStep)
1839 k2x = RS_Math::round(center.x+cos(a)*radius);
1840 k2y = RS_Math::round(center.y-sin(a)*radius);
1841 //if(graphic->isPointOnScreen(k2x, k2y) ||
1842 // graphic->isPointOnScreen(k1x, k1y) ) {
1843 createDirectPainter();
1844 painter->setPen(pen);
1845 if ((k2x >= 0 && k2x <= painter->getWidth()
1846 && k2y >= 0 && k2y <= painter->getHeight())
1847 || (k1x >= 0 && k1x <= painter->getWidth()
1848 && k1y >= 0 && k1y <= painter->getHeight()))
1850 //painter->lineTo(k2x, k2y);
1851 painter->drawLine(Vector(k1x, k1y), Vector(k2x, k2y));
1853 //graphic->simulationDelay();
1855 //createDirectPainter();
1856 //painter->setPen(pen);
1857 //painter->moveTo(k2x, k2y);
1863 createDirectPainter();
1864 painter->setPen(pen);
1865 painter->drawLine(Vector(k2x, k2y), Vector(ix2, iy2));
1866 //painter->lineTo(ix2, iy2);
1872 if (a1 < a2cp + 0.01)
1875 //createDirectPainter();
1876 //painter->setPen(pen);
1877 //painter->moveTo(ix1, iy1);
1878 for(a=a1-aStep; a>=a2cp; a-=aStep)
1880 k2x = RS_Math::round(center.x + cos(a) * radius);
1881 k2y = RS_Math::round(center.y - sin(a) * radius);
1882 //if(graphic->isPointOnScreen(k2x, k2y) ||
1883 // graphic->isPointOnScreen(k1x, k1y) ) {
1884 createDirectPainter();
1885 painter->setPen(pen);
1886 if ((k2x >=0 && k2x <= painter->getWidth()
1887 && k2y >= 0 && k2y <= painter->getHeight())
1888 || (k1x >= 0 && k1x <= painter->getWidth()
1889 && k1y >= 0 && k1y <= painter->getHeight()))
1891 //painter->lineTo(k2x, k2y);
1892 painter->drawLine(Vector(k1x, k1y), Vector(k2x, k2y));
1895 //createDirectPainter();
1896 //painter->setPen(pen);
1897 //painter->moveTo(k2x, k2y);
1902 createDirectPainter();
1903 painter->setPen(pen);
1904 //painter->lineTo(ix2, iy2);
1905 painter->drawLine(Vector(k2x, k2y), Vector(ix2, iy2));
1911 * @return Pointer to the static pattern struct that belongs to the
1912 * given pattern type or NULL.
1914 RS_LineTypePattern * RS_GraphicView::getPattern(RS2::LineType t)
1918 case RS2::SolidLine:
1919 return &patternSolidLine;
1923 return &patternDotLine;
1926 return &patternDotLine2;
1928 case RS2::DotLineX2:
1929 return &patternDotLineX2;
1933 return &patternDashLine;
1935 case RS2::DashLine2:
1936 return &patternDashLine2;
1938 case RS2::DashLineX2:
1939 return &patternDashLineX2;
1942 case RS2::DashDotLine:
1943 return &patternDashDotLine;
1945 case RS2::DashDotLine2:
1946 return &patternDashDotLine2;
1948 case RS2::DashDotLineX2:
1949 return &patternDashDotLineX2;
1952 case RS2::DivideLine:
1953 return &patternDivideLine;
1955 case RS2::DivideLine2:
1956 return &patternDivideLine2;
1958 case RS2::DivideLineX2:
1959 return &patternDivideLineX2;
1962 case RS2::CenterLine:
1963 return &patternCenterLine;
1965 case RS2::CenterLine2:
1966 return &patternCenterLine2;
1968 case RS2::CenterLineX2:
1969 return &patternCenterLineX2;
1972 case RS2::BorderLine:
1973 return &patternBorderLine;
1975 case RS2::BorderLine2:
1976 return &patternBorderLine2;
1978 case RS2::BorderLineX2:
1979 return &patternBorderLineX2;
1982 case RS2::LineByLayer:
1983 return &patternBlockLine;
1985 case RS2::LineByBlock:
1986 return &patternBlockLine;
1996 * This virtual method can be overwritten to draw the absolute
1997 * zero. It's called from within drawIt(). The default implemetation
1998 * draws a simple red round zero point.
2002 void RS_GraphicView::drawAbsoluteZero()
2004 //RS_DEBUG->print(RS_Debug::D_CRITICAL, "RS_GraphicView::drawAbsoluteZero (painter=%08X)", painter);
2005 // bool painterCreated = false;
2007 // create a temporary painter device
2008 if (painter == NULL)
2011 //Hrm. createDirectPainter();
2013 // painterCreated = true;
2018 // RS_Pen pen(metaGridColor, RS2::Width00, RS2::SolidLine);
2019 // painter->setPen(pen);
2020 // RS_Pen p(Qt::red, RS2::Width00, RS2::SolidLine);
2021 //Using Qt::red doesn't seem to work here...
2022 //It's because Qt colors and RS_Color are not 100% compatible...
2023 RS_Pen p(RS_Color(255, 0, 0), RS2::Width00, RS2::SolidLine);
2024 // p.setScreenWidth(0);
2026 //painter->setBrush(Qt::NoBrush);
2028 painter->drawLine(Vector(toGuiX(0.0) - zr, toGuiY(0.0)),
2029 Vector(toGuiX(0.0) + zr, toGuiY(0.0)));
2031 painter->drawLine(Vector(toGuiX(0.0), toGuiY(0.0) - zr),
2032 Vector(toGuiX(0.0), toGuiY(0.0) + zr));
2034 // if (painterCreated)
2035 // destroyPainter();
2039 * This virtual method can be overwritten to draw the relative
2040 * zero point. It's called from within drawIt(). The default implemetation
2041 * draws a simple red round zero point.
2045 void RS_GraphicView::drawRelativeZero()
2047 //#warning "!!! drawRelativeZero() not working AT ALL !!!"
2049 // bool painterCreated = false;
2051 if (relativeZero.valid == false)
2054 // create a temporary painter device
2055 if (painter == NULL)
2058 //hrm. createDirectPainter();
2060 // painterCreated = true;
2063 // RS_Pen p(Qt::red, RS2::Width00, RS2::SolidLine);
2064 // p.setScreenWidth(0);
2065 //Using Qt::red doesn't seem to work here...
2066 RS_Pen p(RS_Color(255, 0, 0), RS2::Width00, RS2::SolidLine);
2068 painter->setXORMode();
2072 painter->drawLine(Vector(toGuiX(relativeZero.x) - zr, toGuiY(relativeZero.y)),
2073 Vector(toGuiX(relativeZero.x) + zr, toGuiY(relativeZero.y)));
2075 painter->drawLine(Vector(toGuiX(relativeZero.x), toGuiY(relativeZero.y) - zr),
2076 Vector(toGuiX(relativeZero.x), toGuiY(relativeZero.y) + zr));
2078 painter->drawCircle(toGui(relativeZero), zr);
2080 painter->setNormalMode();
2082 // if (painterCreated)
2083 // destroyPainter();
2088 * Draws the paper border (for print previews).
2092 void RS_GraphicView::drawPaper()
2094 bool painterCreated = false;
2096 if (container == NULL)
2099 RS_Graphic * graphic = container->getGraphic();
2101 if (graphic == NULL)
2104 if (graphic->getPaperScale() < 1.0e-6)
2107 // create a temporary painter device
2108 if (painter == NULL)
2110 createDirectPainter();
2111 painterCreated = true;
2115 painter->setPen(RS_Pen(Qt::gray));
2117 Vector pinsbase = graphic->getPaperInsertionBase();
2118 Vector size = graphic->getPaperSize();
2119 double scale = graphic->getPaperScale();
2121 Vector v1 = toGui((Vector(0, 0) - pinsbase) / scale);
2122 Vector v2 = toGui((size - pinsbase) / scale);
2125 painter->fillRect(0,0, getWidth(), getHeight(), RS_Color(200, 200, 200));
2128 painter->fillRect((int)(v1.x) + 6, (int)(v1.y) + 6,
2129 (int)((v2.x - v1.x)), (int)((v2.y - v1.y)),
2130 RS_Color(64, 64, 64));
2133 painter->fillRect((int)(v1.x), (int)(v1.y),
2134 (int)((v2.x - v1.x)), (int)((v2.y - v1.y)),
2135 RS_Color(64, 64, 64));
2138 painter->fillRect((int)(v1.x) + 1, (int)(v1.y) - 1,
2139 (int)((v2.x - v1.x)) - 2, (int)((v2.y - v1.y)) + 2,
2140 RS_Color(255, 255, 255));
2151 void RS_GraphicView::drawGrid()
2153 if (grid == NULL || isGridOn() == false)
2155 // printf("RS_GraphicView::drawGrid(): Aborting: grid=%08X, isGridOn=%s\n", grid, (isGridOn() ? "true" : "false"));
2160 //painter->setPen(Qt::gray);
2161 painter->setPen(gridColor);
2162 // painter->setPen(RS_Pen(RS_Color(128, 128, 128), RS2::Width00, RS2::SolidLine));
2164 //Problem here: pts is NULL!
2165 Vector * pts = grid->getPoints();
2169 for(int i=0; i<grid->count(); ++i)
2170 painter->drawGridPoint(toGui(pts[i]));
2173 // printf("RS_GraphicView::drawGrid(): pts == NULL!\n");
2176 //painter->setPen(Qt::white);
2177 QString info = grid->getInfo();
2178 //info = QString("%1 / %2")
2179 // .arg(grid->getSpacing())
2180 // .arg(grid->getMetaSpacing());
2182 updateGridStatusWidget(info);
2186 * Draws the meta grid.
2190 void RS_GraphicView::drawMetaGrid()
2192 if (grid == NULL || isGridOn() == false /*|| grid->getMetaSpacing()<0.0*/)
2195 bool painterCreated = false;
2197 // create a temporary painter device
2198 if (painter == NULL)
2200 //hrm createDirectPainter();
2202 painterCreated = true;
2205 RS_Pen pen(metaGridColor, RS2::Width00, RS2::DotLine);
2206 painter->setPen(pen);
2209 double * mx = grid->getMetaX();
2213 for(int i=0; i<grid->countMetaX(); ++i)
2214 painter->drawLine(Vector(toGuiX(mx[i]), 0), Vector(toGuiX(mx[i]), getHeight()));
2217 double * my = grid->getMetaY();
2221 for(int i=0; i<grid->countMetaY(); ++i)
2222 painter->drawLine(Vector(0, toGuiY(my[i])), Vector(getWidth(), toGuiY(my[i])));
2230 * Updates the grid if there is one.
2232 void RS_GraphicView::updateGrid()
2238 RS_Grid * RS_GraphicView::getGrid()
2243 void RS_GraphicView::updateGridStatusWidget(const QString & /*text*/)
2247 RS2::SnapMode RS_GraphicView::getDefaultSnapMode()
2249 return defaultSnapMode;
2252 RS2::SnapRestriction RS_GraphicView::getSnapRestriction()
2254 return defaultSnapRes;
2258 * Sets the default snap mode used by newly created actions.
2260 void RS_GraphicView::setDefaultSnapMode(RS2::SnapMode sm)
2262 defaultSnapMode = sm;
2264 if (eventHandler != NULL)
2265 eventHandler->setSnapMode(sm);
2269 * Sets a snap restriction (e.g. orthogonal).
2271 void RS_GraphicView::setSnapRestriction(RS2::SnapRestriction sr)
2273 defaultSnapRes = sr;
2275 if (eventHandler != NULL)
2276 eventHandler->setSnapRestriction(sr);
2280 * Translates a vector in real coordinates to a vector in screen coordinates.
2282 Vector RS_GraphicView::toGui(Vector v)
2284 return Vector(toGuiX(v.x), toGuiY(v.y), 0.0);
2288 * Translates a real coordinate in X to a screen coordinate X.
2289 * @param visible Pointer to a boolean which will contain true
2290 * after the call if the coordinate is within the visible range.
2292 double RS_GraphicView::toGuiX(double x, bool * visible)
2294 if (visible != NULL)
2296 double res = x * factor.x + offsetX;
2298 if (res > 0.0 && res < getWidth())
2304 return x * factor.x + offsetX;
2308 * Translates a real coordinate in Y to a screen coordinate Y.
2310 double RS_GraphicView::toGuiY(double y)
2312 return -y * factor.y + getHeight() - offsetY;
2316 * Translates a real coordinate distance to a screen coordinate distance.
2318 double RS_GraphicView::toGuiDX(double d)
2320 return d * factor.x;
2324 * Translates a real coordinate distance to a screen coordinate distance.
2326 double RS_GraphicView::toGuiDY(double d)
2328 return d * factor.y;
2332 * Translates a vector in screen coordinates to a vector in real coordinates.
2334 Vector RS_GraphicView::toGraph(Vector v)
2336 return Vector(toGraphX(RS_Math::round(v.x)), toGraphY(RS_Math::round(v.y)), 0.0);
2340 * Translates two screen coordinates to a vector in real coordinates.
2342 Vector RS_GraphicView::toGraph(int x, int y)
2344 return Vector(toGraphX(x), toGraphY(y), 0.0);
2348 * Translates a screen coordinate in X to a real coordinate X.
2350 double RS_GraphicView::toGraphX(int x)
2352 return (x - offsetX) / factor.x;
2356 * Translates a screen coordinate in Y to a real coordinate Y.
2358 double RS_GraphicView::toGraphY(int y)
2360 return -(y - getHeight() + offsetY) / factor.y;
2364 * Translates a screen coordinate distance to a real coordinate distance.
2366 double RS_GraphicView::toGraphDX(int d)
2368 return d / factor.x;
2372 * Translates a screen coordinate distance to a real coordinate distance.
2374 double RS_GraphicView::toGraphDY(int d)
2376 return d / factor.y;
2380 * (Un-)Locks the position of the relative zero.
2382 * @param lock true: lock, false: unlock
2384 void RS_GraphicView::lockRelativeZero(bool lock)
2386 relativeZeroLocked=lock;
2390 * @return true if the position of the realtive zero point is
2393 bool RS_GraphicView::isRelativeZeroLocked()
2395 return relativeZeroLocked;
2399 * @return Relative zero coordinate.
2401 Vector RS_GraphicView::getRelativeZero()
2403 return relativeZero;
2407 * Sets the relative zero coordinate (if not locked)
2408 * without deleting / drawing the point.
2410 void RS_GraphicView::setRelativeZero(const Vector & pos)
2412 if (!relativeZeroLocked)
2417 * Sets the relative zero coordinate, deletes the old position
2418 * on the screen and draws the new one.
2420 void RS_GraphicView::moveRelativeZero(const Vector & pos)
2422 // bool painterCreated = false;
2424 if (painter == NULL)
2427 //hrm painter = createDirectPainter();
2428 // painter = createPainter();
2429 // painterCreated = true;
2432 //painter->setXORMode();
2435 setRelativeZero(pos);
2439 // if (painterCreated)
2440 // destroyPainter();
2443 RS_EventHandler * RS_GraphicView::getEventHandler()
2445 return eventHandler;
2449 * Enables or disables print preview.
2451 void RS_GraphicView::setPrintPreview(bool pv)
2457 * @retval true This is a print preview graphic view.
2458 * @retval false Otherwise.
2460 bool RS_GraphicView::isPrintPreview()
2462 return printPreview;
2466 * Enables or disables printing.
2468 void RS_GraphicView::setPrinting(bool p)
2474 * @retval true This is a a graphic view for printing.
2475 * @retval false Otherwise.
2477 bool RS_GraphicView::isPrinting()
2483 * @retval true Draft mode is on for this view (all lines with 1 pixel / no style scaling).
2484 * @retval false Otherwise.
2486 bool RS_GraphicView::isDraftMode()
2492 * Sets the simulation speed in percentage.
2494 void RS_GraphicView::setSimulationSpeed(int s)
2496 simulationSpeed = s;
2500 * @return the simulation speed in percentage.
2502 int RS_GraphicView::getSimulationSpeed()
2504 return simulationSpeed;
2508 * Sets the simulation smooth mode.
2510 void RS_GraphicView::setSimulationSmooth(bool s)
2512 simulationSmooth = s;
2515 * Sets the simulation rapid mode.
2517 void RS_GraphicView::setSimulationRapid(bool r)
2519 simulationRapid = r;
2523 * @return the simulation rapid mode.
2525 bool RS_GraphicView::getSimulationRapid()
2527 return simulationRapid;
2530 // These functions are here because of the focacta way that this
2531 // program set up its rendering...
2532 void RS_GraphicView::SetPreviewMode(bool mode/*= true*/)
2537 void RS_GraphicView::SetPreviewEntity(RS_Preview * p)
2542 void RS_GraphicView::SetPreviewOffset(Vector o)
2547 void RS_GraphicView::SetSnapperDraw(bool mode)
2552 void RS_GraphicView::SetSnapperVars(Vector snapSpot, Vector snapCoord, bool showCrosshairs)
2554 snapSpot1 = snapSpot;
2555 snapCoord1 = snapCoord;
2556 showCrosshairs1 = showCrosshairs;