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"
20 #include "rs_dialogfactory.h"
22 #include "rs_eventhandler.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 Drawing * RS_GraphicView::getGraphic()
127 if (container != NULL && container->rtti() == RS2::EntityGraphic)
128 return (Drawing*)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 Drawing * 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 (e->button() != Qt::RightButton || eventHandler->hasAction())
570 eventHandler->mouseReleaseEvent(e);
580 RS_DEBUG->print("RS_GraphicView::mouseReleaseEvent: OK");
584 * Called by the actual GUI class which implements the RS_GraphicView
585 * interface to notify qcadlib about mouse events.
587 void RS_GraphicView::mouseMoveEvent(QMouseEvent * e)
589 RS_DEBUG->print("RS_GraphicView::mouseMoveEvent begin");
591 Drawing * graphic = NULL;
593 if (container->rtti() == RS2::EntityGraphic)
594 graphic = (Drawing *)container;
596 RS_DEBUG->print("RS_GraphicView::mouseMoveEvent 001");
604 RS_DEBUG->print("RS_GraphicView::mouseMoveEvent 002");
606 if (eventHandler != NULL)
607 eventHandler->mouseMoveEvent(e);
609 RS_DEBUG->print("RS_GraphicView::mouseMoveEvent 003");
611 if (eventHandler == NULL || !eventHandler->hasAction() && graphic != NULL)
613 Vector mouse = toGraph(Vector(mx, my));
614 Vector relMouse = mouse - getRelativeZero();
616 if (RS_DIALOGFACTORY != NULL)
617 RS_DIALOGFACTORY->updateCoordinateWidget(mouse, relMouse);
620 RS_DEBUG->print("RS_GraphicView::mouseMoveEvent end");
624 * Called by the actual GUI class which implements the RS_GraphicView
625 * interface to notify qcadlib about mouse events.
627 void RS_GraphicView::mouseLeaveEvent()
629 if (eventHandler != NULL)
630 eventHandler->mouseLeaveEvent();
634 * Called by the actual GUI class which implements the RS_GraphicView
635 * interface to notify qcadlib about mouse events.
637 void RS_GraphicView::mouseEnterEvent()
639 if (eventHandler != NULL)
640 eventHandler->mouseEnterEvent();
644 * Called by the actual GUI class which implements the RS_GraphicView
645 * interface to notify qcadlib about key events.
647 void RS_GraphicView::keyPressEvent(QKeyEvent * e)
649 if (eventHandler != NULL)
650 eventHandler->keyPressEvent(e);
654 * Called by the actual GUI class which implements the RS_GraphicView
655 * interface to notify qcadlib about key events.
657 void RS_GraphicView::keyReleaseEvent(QKeyEvent * e)
659 if (eventHandler != NULL)
660 eventHandler->keyReleaseEvent(e);
664 * Called by the actual GUI class which implements a command line.
666 void RS_GraphicView::commandEvent(RS_CommandEvent * e)
668 if (eventHandler != NULL)
669 eventHandler->commandEvent(e);
673 * Enables coordinate input in the command line.
675 void RS_GraphicView::enableCoordinateInput()
677 if (eventHandler != NULL)
678 eventHandler->enableCoordinateInput();
682 * Disables coordinate input in the command line.
684 void RS_GraphicView::disableCoordinateInput()
686 if (eventHandler != NULL)
687 eventHandler->disableCoordinateInput();
691 * zooms in by factor f
693 void RS_GraphicView::zoomIn(double f, const Vector & center)
697 RS_DEBUG->print(RS_Debug::D_WARNING, "RS_GraphicView::zoomIn: invalid factor");
701 if (simulationRunning)
705 if (c.valid == false)
706 c = toGraph(Vector(getWidth() / 2, getHeight() / 2));
709 toGraph(Vector(0, 0)).scale(c, Vector(1.0 / f, 1.0 / f)),
710 toGraph(Vector(getWidth(), getHeight())).scale(c, Vector(1.0 / f, 1.0 / f)));
712 //adjustOffsetControls();
713 //adjustZoomControls();
719 * zooms in by factor f in x
721 void RS_GraphicView::zoomInX(double f)
723 if (simulationRunning)
727 offsetX = (int)((offsetX - getWidth() / 2) * f) + getWidth() / 2;
728 adjustOffsetControls();
729 adjustZoomControls();
735 * zooms in by factor f in y
737 void RS_GraphicView::zoomInY(double f)
739 if (simulationRunning)
743 offsetY = (int)((offsetY - getHeight() / 2) * f)+getHeight() / 2;
744 adjustOffsetControls();
745 adjustZoomControls();
751 * zooms out by factor f
753 void RS_GraphicView::zoomOut(double f, const Vector & center)
757 RS_DEBUG->print(RS_Debug::D_WARNING,
758 "RS_GraphicView::zoomOut: invalid factor");
762 if (simulationRunning)
769 * zooms out by factor f in x
771 void RS_GraphicView::zoomOutX(double f)
775 RS_DEBUG->print(RS_Debug::D_WARNING,
776 "RS_GraphicView::zoomOutX: invalid factor");
780 if (simulationRunning)
784 offsetX = (int)(offsetX / f);
785 adjustOffsetControls();
786 adjustZoomControls();
792 * zooms out by factor f y
794 void RS_GraphicView::zoomOutY(double f)
798 RS_DEBUG->print(RS_Debug::D_WARNING,
799 "RS_GraphicView::zoomOutY: invalid factor");
803 if (simulationRunning)
807 offsetY = (int)(offsetY / f);
808 adjustOffsetControls();
809 adjustZoomControls();
817 * @param axis include axis in zoom
818 * @param keepAspectRatio true: keep aspect ratio 1:1
819 * false: factors in x and y are stretched to the max
821 void RS_GraphicView::zoomAuto(bool axis, bool keepAspectRatio)
823 RS_DEBUG->print("RS_GraphicView::zoomAuto");
825 if (simulationRunning)
830 if (container != NULL)
832 container->calculateBorders();
837 sx = std::max(container->getMax().x, 0.0) - std::min(container->getMin().x, 0.0);
838 sy = std::max(container->getMax().y, 0.0) - std::min(container->getMin().y, 0.0);
842 sx = container->getSize().x;
843 sy = container->getSize().y;
848 if (sx > RS_TOLERANCE)
849 fx = (getWidth() - borderLeft - borderRight) / sx;
853 if (sy > RS_TOLERANCE)
854 fy = (getHeight() - borderTop - borderBottom) / sy;
858 RS_DEBUG->print("f: %f/%f", fx, fy);
861 fx = fy = std::min(fx, fy);
863 RS_DEBUG->print("f: %f/%f", fx, fy);
865 if (fx < RS_TOLERANCE)
871 RS_DEBUG->print("f: %f/%f", fx, fy);
873 RS_DEBUG->print("adjustOffsetControls");
874 adjustOffsetControls();
875 RS_DEBUG->print("adjustZoomControls");
876 adjustZoomControls();
877 RS_DEBUG->print("centerOffsetX");
879 RS_DEBUG->print("centerOffsetY");
881 RS_DEBUG->print("updateGrid");
886 RS_DEBUG->print("RS_GraphicView::zoomAuto OK");
890 * Shows previous view.
892 void RS_GraphicView::zoomPrevious()
894 RS_DEBUG->print("RS_GraphicView::zoomPrevious");
896 if (simulationRunning)
899 if (container != NULL)
904 * Saves the current view as previous view to which we can
905 * switch back later with @see restoreView().
907 void RS_GraphicView::saveView()
909 previousOffsetX = offsetX;
910 previousOffsetY = offsetY;
911 previousFactor = factor;
915 * Restores the view previously saved with
918 void RS_GraphicView::restoreView()
920 int pox = previousOffsetX;
921 int poy = previousOffsetY;
922 Vector pf = previousFactor;
930 adjustOffsetControls();
931 adjustZoomControls();
937 * performs autozoom in y only
939 * @param axis include axis in zoom
941 void RS_GraphicView::zoomAutoY(bool axis)
943 if (simulationRunning)
946 if (container != NULL)
948 double visibleHeight = 0.0;
949 double minY = RS_MAXDOUBLE;
950 double maxY = RS_MINDOUBLE;
951 bool noChange = false;
953 for(RS_Entity * e=container->firstEntity(RS2::ResolveNone);
954 e!=NULL; e = container->nextEntity(RS2::ResolveNone))
956 if (e->rtti() == RS2::EntityLine)
958 RS_Line * l = (RS_Line *)e;
960 x1 = toGuiX(l->getStartpoint().x);
961 x2 = toGuiX(l->getEndpoint().x);
963 if (x1 > 0.0 && x1 < (double)getWidth() || x2 > 0.0 && x2 < (double)getWidth())
965 minY = std::min(minY, l->getStartpoint().y);
966 minY = std::min(minY, l->getEndpoint().y);
967 maxY = std::max(maxY, l->getStartpoint().y);
968 maxY = std::max(maxY, l->getEndpoint().y);
974 visibleHeight = std::max(maxY, 0.0) - std::min(minY, 0.0);
976 visibleHeight = maxY - minY;
978 if (visibleHeight < 1.0)
983 if (visibleHeight > 1.0e-6)
985 fy = (getHeight() - borderTop - borderBottom) / visibleHeight;
987 if (factor.y < 0.000001)
991 if (noChange == false)
995 offsetY = (int)((getHeight() - borderTop - borderBottom - (visibleHeight * factor.y)) / 2.0
996 - (minY * factor.y)) + borderBottom;
997 adjustOffsetControls();
998 adjustZoomControls();
1002 RS_DEBUG->print("Auto zoom y ok");
1007 * Zooms the area given by v1 and v2.
1009 * @param keepAspectRatio true: keeps the aspect ratio 1:1
1010 * false: zooms exactly the selected range to the
1011 * current graphic view
1013 void RS_GraphicView::zoomWindow(Vector v1, Vector v2, bool keepAspectRatio)
1015 if (simulationRunning)
1020 double zoomX = 480.0; // Zoom for X-Axis
1021 double zoomY = 640.0; // Zoom for Y-Axis (Set smaller one)
1022 double dum; // Dummy for switching values
1025 // Switch left/right and top/bottom is necessary:
1040 // Get zoom in X and zoom in Y:
1041 if (v2.x - v1.x > 1.0e-6)
1042 zoomX = getWidth() / (v2.x - v1.x);
1044 if (v2.y - v1.y > 1.0e-6)
1045 zoomY = getHeight() / (v2.y - v1.y);
1047 // Take smaller zoom:
1048 if (keepAspectRatio)
1052 if (getWidth() != 0)
1054 zoomX = zoomY = ((double)(getWidth() - 2 * zoomBorder)) /
1055 (double)getWidth() * zoomX;
1060 if (getHeight() != 0)
1062 zoomX = zoomY = ((double)(getHeight() - 2 * zoomBorder)) /
1063 (double)getHeight() * zoomY;
1074 // Borders in pixel after zoom
1075 int pixLeft = (int)(v1.x * zoomX);
1076 int pixTop = (int)(v2.y * zoomY);
1077 int pixRight = (int)(v2.x * zoomX);
1078 int pixBottom = (int)(v1.y * zoomY);
1080 // Set new offset for zero point:
1081 offsetX = - pixLeft + (getWidth() - pixRight + pixLeft) / 2;
1082 offsetY = - pixTop + (getHeight() - pixBottom + pixTop) / 2;
1086 adjustOffsetControls();
1087 adjustZoomControls();
1093 * Centers the point v1.
1095 void RS_GraphicView::zoomPan(int dx, int dy)
1097 //offsetX+=(int)toGuiDX(v1.x);
1098 //offsetY+=(int)toGuiDY(v1.y);
1099 if (simulationRunning)
1106 adjustOffsetControls();
1107 //adjustZoomControls();
1114 * Scrolls in the given direction.
1116 void RS_GraphicView::zoomScroll(RS2::Direction direction)
1118 if (simulationRunning)
1137 adjustOffsetControls();
1138 adjustZoomControls();
1144 * Zooms to page extends.
1146 void RS_GraphicView::zoomPage()
1148 RS_DEBUG->print("RS_GraphicView::zoomPage");
1150 if (container == NULL)
1153 if (simulationRunning)
1156 Drawing * graphic = container->getGraphic();
1158 if (graphic == NULL)
1161 Vector s = graphic->getPaperSize();
1162 Vector pinsbase = graphic->getPaperInsertionBase();
1166 if (s.x > RS_TOLERANCE)
1167 fx = (getWidth() - borderLeft - borderRight) / s.x;
1171 if (s.y > RS_TOLERANCE)
1172 fy = (getHeight() - borderTop - borderBottom) / s.y;
1176 RS_DEBUG->print("f: %f/%f", fx, fy);
1178 fx = fy = std::min(fx, fy);
1180 RS_DEBUG->print("f: %f/%f", fx, fy);
1182 if (fx < RS_TOLERANCE)
1188 RS_DEBUG->print("f: %f/%f", fx, fy);
1192 adjustOffsetControls();
1193 adjustZoomControls();
1199 * Draws the entities within the given range.
1201 void RS_GraphicView::drawWindow(Vector v1, Vector v2)
1203 RS_DEBUG->print("RS_GraphicView::drawWindow() begin");
1205 if (simulationRunning)
1208 if (container != NULL)
1210 for (RS_Entity * se=container->firstEntity(RS2::ResolveNone);
1211 se!=NULL; se = container->nextEntity(RS2::ResolveNone))
1213 if (se->isInWindow(v1, v2))
1218 RS_DEBUG->print("RS_GraphicView::drawWindow() end");
1222 * Draws the entities. If painter is NULL a new painter will
1223 * be created and destroyed.
1225 void RS_GraphicView::drawIt()
1227 if (!isUpdateEnabled())
1229 //printf("RS_GraphicView::drawIt(): isUpdateEnabled() == false!\n");
1233 if (simulationRunning)
1235 //printf("RS_GraphicView::drawIt(): simulationRunning == true!\n");
1239 // bool painterCreated = false;
1241 settings.beginGroup("Appearance");
1242 draftMode = settings.value("DraftMode", false).toBool();
1243 settings.endGroup();
1245 //RS_DEBUG->print("RS_GraphicView::drawIt() begin");
1246 //RS_DEBUG->print(" factors: %f/%f", factor.x, factor.y);
1247 //RS_DEBUG->timestamp();
1249 if (painter == NULL)
1251 printf("RS_GraphicView::drawIt(): painter == NULL!\n");
1254 // painterCreated = true;
1259 // drawing paper border:
1260 if (isPrintPreview())
1262 // drawing meta grid:
1267 // painter->setPen(RS_Pen(foreground, RS2::Width00, RS2::SolidLine));
1270 // drawing entities:
1271 //#warning "!!! This looks like a bug, no match for 'drawEntity(RS_Entity *, bool) !!!"
1272 // and indeed it *is* a bug... true is converted to 1.0 here. Dumb, dumb, dumb.
1273 drawEntity(container, true);
1275 //RS_DEBUG->timestamp();
1276 //RS_DEBUG->print(" draw zero..");
1278 // drawing zero points:
1279 if (!isPrintPreview())
1285 //RS_DEBUG->timestamp();
1286 //RS_DEBUG->print(" draw grid..");
1289 if (!isPrintPreview())
1292 //RS_DEBUG->timestamp();
1293 //RS_DEBUG->print("RS_GraphicView::drawIt() end");
1294 // if (painterCreated == true)
1295 // destroyPainter();
1299 * Sets the pen of the painter object to the suitable pen for the given
1302 void RS_GraphicView::setPenForEntity(RS_Entity * e)
1304 if (drawingMode == RS2::ModePreview /*|| draftMode==true*/)
1307 // set color of entity
1308 if (painter != NULL && !painter->isPreviewMode())
1310 // Getting pen from entity (or layer)
1311 RS_Pen pen = e->getPen(true);
1313 int w = pen.getWidth();
1321 double uf = 1.0; // unit factor
1322 double wf = 1.0; // width factor
1323 Drawing * graphic = container->getGraphic();
1325 if (graphic != NULL)
1327 uf = RS_Units::convert(1.0, RS2::Millimeter, graphic->getUnit());
1329 if ((isPrinting() || isPrintPreview()) && graphic->getPaperScale() > 1.0e-6)
1330 wf = 1.0 / graphic->getPaperScale();
1333 pen.setScreenWidth(toGuiDX(w / 100.0 * uf * wf));
1337 //pen.setWidth(RS2::Width00);
1338 pen.setScreenWidth(0);
1341 // prevent drawing with 1-width which is slow:
1342 if (RS_Math::round(pen.getScreenWidth()) == 1)
1343 pen.setScreenWidth(0.0);
1345 // prevent background color on background drawing:
1346 if (pen.getColor().stripFlags() == background.stripFlags())
1347 pen.setColor(foreground);
1349 // this entity is selected:
1350 if (e->isSelected())
1352 pen.setLineType(RS2::DotLine);
1353 //pen.setColor(RS_Color(0xa5,0x47,0x47));
1354 pen.setColor(selectedColor);
1357 // this entity is highlighted:
1358 if (e->isHighlighted())
1360 //pen.setColor(RS_Color(0x73, 0x93, 0x73));
1361 pen.setColor(highlightedColor);
1364 // deleting not drawing:
1365 if (getDeleteMode())
1366 pen.setColor(background);
1368 painter->setPen(pen);
1373 * Draws an entity. Might be recusively called e.g. for polylines.
1374 * If the class wide painter is NULL a new painter will be created
1375 * and destroyed afterwards.
1377 * @param patternOffset Offset of line pattern (used for connected
1378 * lines e.g. in splines).
1379 * @param db Double buffering on (recommended) / off
1381 void RS_GraphicView::drawEntity(RS_Entity * e, double patternOffset, bool db)
1383 //RS_DEBUG->print("RS_GraphicView::drawEntity() begin");
1385 // update is diabled:
1386 if (!isUpdateEnabled())
1389 // given entity is NULL:
1393 // entity is not visible:
1394 if (!e->isVisible())
1397 // test if the entity is in the viewport
1398 if (!e->isContainer() && !isPrinting()
1399 && (painter == NULL || !painter->isPreviewMode())
1400 && (toGuiX(e->getMax().x) < 0 || toGuiX(e->getMin().x) > getWidth()
1401 || toGuiY(e->getMin().y) < 0 || toGuiY(e->getMax().y) > getHeight()))
1403 //printf("RS_GraphicView::drawEntity(): Bailing out of big test!!!\n");
1408 //RS_DEBUG->print("recursion 1: %d", drawRecursion);
1413 //RS_DEBUG->print("draw plain");
1416 // large texts as rectangles:
1417 if (e->rtti() == RS2::EntityText)
1419 if (toGuiDX(((RS_Text *)e)->getHeight()) < 4 || e->countDeep() > 100)
1420 painter->drawRect(toGui(e->getMin()), toGui(e->getMax()));
1422 drawEntityPlain(e, patternOffset);
1424 // all images as rectangles:
1425 else if (e->rtti() == RS2::EntityImage)
1426 painter->drawRect(toGui(e->getMin()), toGui(e->getMax()));
1428 else if (e->rtti() == RS2::EntityHatch)
1433 drawEntityPlain(e, patternOffset);
1436 drawEntityPlain(e, patternOffset);
1438 // draw reference points:
1439 if (e->isSelected())
1441 if (!e->isParentSelected())
1443 VectorSolutions s = e->getRefPoints();
1445 for(int i=0; i<s.getNumber(); ++i)
1448 RS_Color col = RS_Color(0, 0, 255);
1450 if (e->rtti() == RS2::EntityPolyline)
1452 if (i == 0 || i == s.getNumber() - 1)
1457 // col = QColor(0, 64, 255);
1458 col = RS_Color(0, 64, 255);
1463 // col = QColor(0, 0, 128);
1464 col = RS_Color(0, 0, 128);
1469 if (getDeleteMode())
1470 painter->drawHandle(toGui(s.get(i)), background, sz);
1472 painter->drawHandle(toGui(s.get(i)), col, sz);
1477 //RS_DEBUG->print("draw plain OK");
1478 //RS_DEBUG->print("RS_GraphicView::drawEntity() end");
1482 * Deletes an entity with the background color.
1483 * Might be recusively called e.g. for polylines.
1485 void RS_GraphicView::deleteEntity(RS_Entity * e)
1487 setDeleteMode(true);
1489 setDeleteMode(false);
1494 * The painter must be initialized and all the attributes (pen) must be set.
1496 void RS_GraphicView::drawEntityPlain(RS_Entity * e, double patternOffset)
1500 //printf("RS_GraphicView::drawEntityPlain(): Entity passed in is NULL!\n");
1504 //printf("RS_GraphicView::drawEntityPlain(): Passing in painter=%08X, view=%08X\n", painter, this);
1505 e->draw(painter, this, patternOffset);
1509 * Simulates this drawing in slow motion.
1511 void RS_GraphicView::simulateIt()
1513 if (simulationRunning)
1516 simulationRunning = true;
1517 simulationLast = Vector(0.0, 0.0);
1521 createDirectPainter();
1524 // drawing paper border:
1525 if (isPrintPreview())
1528 // drawing meta grid:
1529 if (!isPrintPreview())
1533 if (!isPrintPreview())
1537 //painter->setPen(RS_Pen(foreground,
1538 // RS2::Width00, RS2::SolidLine));
1541 // drawing entities:
1542 RS_Pen pen(foreground, RS2::Width00, RS2::SolidLine);
1543 simulateEntity(container, pen);
1545 //RS_DEBUG->timestamp();
1546 //RS_DEBUG->print(" draw zero..");
1548 // drawing zero points:
1549 if (!isPrintPreview())
1555 //RS_DEBUG->timestamp();
1556 //RS_DEBUG->print(" draw grid..");
1558 //RS_DEBUG->timestamp();
1559 //RS_DEBUG->print("RS_GraphicView::drawIt() end");
1560 //if (painterCreated==true) {
1563 simulationRunning = false;
1567 * Simulates the given entity.
1569 * @param smooth If true, the entity will be drawn slowly (pixel by pixel).
1571 void RS_GraphicView::simulateEntity(RS_Entity * e, const RS_Pen & pen)
1573 if (painter == NULL || e == NULL)
1576 if (e->isContainer())
1578 RS_EntityContainer * ec = (RS_EntityContainer *)e;
1580 for(RS_Entity* en=ec->firstEntity(RS2::ResolveNone);
1581 en!=NULL; en = ec->nextEntity(RS2::ResolveNone))
1583 if (en->isVisible() && en->isUndone() == false)
1586 if (en->isAtomic() && simulationRapid)
1588 Vector sp = ((RS_AtomicEntity *)en)->getStartpoint();
1590 if (sp.distanceTo(simulationLast) > 1.0e-4)
1592 createDirectPainter();
1593 RS_Pen rpen(RS_Color(0, 0, 255), RS2::Width00, RS2::SolidLine);
1594 //painter->setPen(pen);
1595 RS_Line rapidLine(NULL, RS_LineData(simulationLast, sp));
1596 simulateEntity(&rapidLine, rpen);
1600 if (en->isHighlighted())
1602 RS_Pen hpen(highlightedColor, RS2::Width00, RS2::SolidLine);
1603 simulateEntity(en, hpen);
1606 simulateEntity(en, pen);
1609 simulationLast = ((RS_AtomicEntity *)en)->getEndpoint();
1611 if (!simulationSmooth)
1612 simulationDelay(true);
1618 if (simulationSmooth)
1622 case RS2::EntityLine:
1624 RS_Line * line = (RS_Line *)e;
1625 drawLineSmooth(toGui(line->getStartpoint()), toGui(line->getEndpoint()), pen);
1630 case RS2::EntityArc:
1632 RS_Arc * arc = (RS_Arc *)e;
1633 drawArcSmooth(toGui(arc->getCenter()), toGuiDX(arc->getRadius()),
1634 arc->getAngle1(), arc->getAngle2(), arc->isReversed(), pen);
1638 case RS2::EntityCircle:
1640 RS_Circle * circle = (RS_Circle *)e;
1641 drawArcSmooth(toGui(circle->getCenter()), toGuiDX(circle->getRadius()),
1642 0.0, 2.0 * M_PI, false, pen);
1652 createDirectPainter();
1653 //RS_Pen pen(foreground, RS2::Width00, RS2::SolidLine);
1654 painter->setPen(pen);
1661 * Delay for slow motion simulation.
1663 * @param step true: stepping mode (entity by entity simulation). adds a delay.
1665 void RS_GraphicView::simulationDelay(bool step)
1668 settings.beginGroup("CAM");
1669 double fact = settings.value("SimulationFactor", 12000.0).toDouble();
1670 settings.endGroup();
1672 // simulationSpeed: 0..100
1675 delay = (int)(((1.0 / (simulationSpeed + 1.0)) * fact) - (fact / 100.0));
1680 static int call = 0;
1682 if (call >= (fact - delay) / 1000)
1685 for(int i=0; i<delay; ++i)
1686 RS_APP->processEvents(10);
1691 delay = (int)(((1.0 / (simulationSpeed + 1.0)) * fact) - (fact / 100.0));
1698 for(int i=0; i<delay; ++i)
1700 #warning "Qt3->4 conversion: commented out problem line... !!! FIX !!!"
1701 // RS_APP->processEvents(10);
1707 * Draws a line slowly from (x1, y1) to (x2, y2). This is used for simulation only.
1709 void RS_GraphicView::drawLineSmooth(const Vector & p1, const Vector & p2, const RS_Pen & pen)
1711 double alpha = p1.angleTo(p2);
1712 double xStep, yStep;
1715 if (RS_Math::cmpDouble(alpha, 0.0) || RS_Math::cmpDouble(alpha, 2 * M_PI))
1721 else if (RS_Math::cmpDouble(alpha, M_PI / 2.0))
1727 else if (RS_Math::cmpDouble(alpha, M_PI))
1733 else if (RS_Math::cmpDouble(alpha, M_PI / 2.0 * 3.0))
1739 else if (fabs(p2.x - p1.x) > fabs(p2.y - p1.y))
1746 yStep = tan(alpha) * xStep;
1756 xStep = yStep / tan(alpha);
1762 //RS_Pen pen(foreground, RS2::Width00, RS2::SolidLine);
1766 if (lx >= 0.0 && lx <= (double)getWidth() && ly >= 0.0 && ly <= (double)getHeight())
1768 //if (painter==NULL) {
1769 createDirectPainter();
1771 painter->setPen(pen);
1772 painter->drawGridPoint(Vector(lx, ly));
1781 while ((xIsOne && ((lx >= p1.x && lx <= p2.x) || (lx >= p2.x && lx <= p1.x)))
1782 || (!xIsOne && ((ly >= p1.y && ly <= p2.y) || (ly >= p2.y && ly <= p1.y))));
1785 void RS_GraphicView::drawArcSmooth(const Vector & center, double radius, double a1, double a2, bool rev,
1788 //int icx = graphic->realToScreenX(cx);
1789 //int icy = graphic->realToScreenY(cy);
1790 //RS_Pen pen(foreground, RS2::Width00, RS2::SolidLine);
1794 createDirectPainter();
1795 painter->setPen(pen);
1796 painter->drawGridPoint(center);
1800 int ix1 = RS_Math::round(center.x + cos(a1) * radius);
1801 int iy1 = RS_Math::round(center.y - sin(a1) * radius);
1802 int ix2 = RS_Math::round(center.x + cos(a2) * radius);
1803 int iy2 = RS_Math::round(center.y - sin(a2) * radius);
1804 int k2x = 0; // Next point on circle
1806 int k1x = ix1; // Prev point on circle
1808 double aStep; // Angle Step (rad)
1809 double a; // Actual Angle (rad)
1810 double a2cp = a2; // Copy of a2
1812 if (1.0 / (radius * factor.x) <= 1.0)
1813 aStep = asin(1.0 / (radius * factor.x));
1822 // Arc Counterclockwise:
1824 if (a1 > a2cp - 0.01)
1827 //if (painter==NULL) {
1828 //painter->setPen(pen);
1829 //createDirectPainter();
1831 //painter->moveTo(ix1, iy1);
1833 for(a=a1+aStep; a<=a2cp; a+=aStep)
1835 k2x = RS_Math::round(center.x+cos(a)*radius);
1836 k2y = RS_Math::round(center.y-sin(a)*radius);
1837 //if(graphic->isPointOnScreen(k2x, k2y) ||
1838 // graphic->isPointOnScreen(k1x, k1y) ) {
1839 createDirectPainter();
1840 painter->setPen(pen);
1841 if ((k2x >= 0 && k2x <= painter->getWidth()
1842 && k2y >= 0 && k2y <= painter->getHeight())
1843 || (k1x >= 0 && k1x <= painter->getWidth()
1844 && k1y >= 0 && k1y <= painter->getHeight()))
1846 //painter->lineTo(k2x, k2y);
1847 painter->drawLine(Vector(k1x, k1y), Vector(k2x, k2y));
1849 //graphic->simulationDelay();
1851 //createDirectPainter();
1852 //painter->setPen(pen);
1853 //painter->moveTo(k2x, k2y);
1859 createDirectPainter();
1860 painter->setPen(pen);
1861 painter->drawLine(Vector(k2x, k2y), Vector(ix2, iy2));
1862 //painter->lineTo(ix2, iy2);
1868 if (a1 < a2cp + 0.01)
1871 //createDirectPainter();
1872 //painter->setPen(pen);
1873 //painter->moveTo(ix1, iy1);
1874 for(a=a1-aStep; a>=a2cp; a-=aStep)
1876 k2x = RS_Math::round(center.x + cos(a) * radius);
1877 k2y = RS_Math::round(center.y - sin(a) * radius);
1878 //if(graphic->isPointOnScreen(k2x, k2y) ||
1879 // graphic->isPointOnScreen(k1x, k1y) ) {
1880 createDirectPainter();
1881 painter->setPen(pen);
1882 if ((k2x >=0 && k2x <= painter->getWidth()
1883 && k2y >= 0 && k2y <= painter->getHeight())
1884 || (k1x >= 0 && k1x <= painter->getWidth()
1885 && k1y >= 0 && k1y <= painter->getHeight()))
1887 //painter->lineTo(k2x, k2y);
1888 painter->drawLine(Vector(k1x, k1y), Vector(k2x, k2y));
1891 //createDirectPainter();
1892 //painter->setPen(pen);
1893 //painter->moveTo(k2x, k2y);
1898 createDirectPainter();
1899 painter->setPen(pen);
1900 //painter->lineTo(ix2, iy2);
1901 painter->drawLine(Vector(k2x, k2y), Vector(ix2, iy2));
1907 * @return Pointer to the static pattern struct that belongs to the
1908 * given pattern type or NULL.
1910 RS_LineTypePattern * RS_GraphicView::getPattern(RS2::LineType t)
1914 case RS2::SolidLine:
1915 return &patternSolidLine;
1919 return &patternDotLine;
1922 return &patternDotLine2;
1924 case RS2::DotLineX2:
1925 return &patternDotLineX2;
1929 return &patternDashLine;
1931 case RS2::DashLine2:
1932 return &patternDashLine2;
1934 case RS2::DashLineX2:
1935 return &patternDashLineX2;
1938 case RS2::DashDotLine:
1939 return &patternDashDotLine;
1941 case RS2::DashDotLine2:
1942 return &patternDashDotLine2;
1944 case RS2::DashDotLineX2:
1945 return &patternDashDotLineX2;
1948 case RS2::DivideLine:
1949 return &patternDivideLine;
1951 case RS2::DivideLine2:
1952 return &patternDivideLine2;
1954 case RS2::DivideLineX2:
1955 return &patternDivideLineX2;
1958 case RS2::CenterLine:
1959 return &patternCenterLine;
1961 case RS2::CenterLine2:
1962 return &patternCenterLine2;
1964 case RS2::CenterLineX2:
1965 return &patternCenterLineX2;
1968 case RS2::BorderLine:
1969 return &patternBorderLine;
1971 case RS2::BorderLine2:
1972 return &patternBorderLine2;
1974 case RS2::BorderLineX2:
1975 return &patternBorderLineX2;
1978 case RS2::LineByLayer:
1979 return &patternBlockLine;
1981 case RS2::LineByBlock:
1982 return &patternBlockLine;
1992 * This virtual method can be overwritten to draw the absolute
1993 * zero. It's called from within drawIt(). The default implemetation
1994 * draws a simple red round zero point.
1998 void RS_GraphicView::drawAbsoluteZero()
2000 //RS_DEBUG->print(RS_Debug::D_CRITICAL, "RS_GraphicView::drawAbsoluteZero (painter=%08X)", painter);
2001 // bool painterCreated = false;
2003 // create a temporary painter device
2004 if (painter == NULL)
2007 //Hrm. createDirectPainter();
2009 // painterCreated = true;
2014 // RS_Pen pen(metaGridColor, RS2::Width00, RS2::SolidLine);
2015 // painter->setPen(pen);
2016 // RS_Pen p(Qt::red, RS2::Width00, RS2::SolidLine);
2017 //Using Qt::red doesn't seem to work here...
2018 //It's because Qt colors and RS_Color are not 100% compatible...
2019 RS_Pen p(RS_Color(255, 0, 0), RS2::Width00, RS2::SolidLine);
2020 // p.setScreenWidth(0);
2022 //painter->setBrush(Qt::NoBrush);
2024 painter->drawLine(Vector(toGuiX(0.0) - zr, toGuiY(0.0)),
2025 Vector(toGuiX(0.0) + zr, toGuiY(0.0)));
2027 painter->drawLine(Vector(toGuiX(0.0), toGuiY(0.0) - zr),
2028 Vector(toGuiX(0.0), toGuiY(0.0) + zr));
2030 // if (painterCreated)
2031 // destroyPainter();
2035 * This virtual method can be overwritten to draw the relative
2036 * zero point. It's called from within drawIt(). The default implemetation
2037 * draws a simple red round zero point.
2041 void RS_GraphicView::drawRelativeZero()
2043 //#warning "!!! drawRelativeZero() not working AT ALL !!!"
2045 // bool painterCreated = false;
2047 if (relativeZero.valid == false)
2050 // create a temporary painter device
2051 if (painter == NULL)
2054 //hrm. createDirectPainter();
2056 // painterCreated = true;
2059 // RS_Pen p(Qt::red, RS2::Width00, RS2::SolidLine);
2060 // p.setScreenWidth(0);
2061 //Using Qt::red doesn't seem to work here...
2062 RS_Pen p(RS_Color(255, 0, 0), RS2::Width00, RS2::SolidLine);
2064 painter->setXORMode();
2068 painter->drawLine(Vector(toGuiX(relativeZero.x) - zr, toGuiY(relativeZero.y)),
2069 Vector(toGuiX(relativeZero.x) + zr, toGuiY(relativeZero.y)));
2071 painter->drawLine(Vector(toGuiX(relativeZero.x), toGuiY(relativeZero.y) - zr),
2072 Vector(toGuiX(relativeZero.x), toGuiY(relativeZero.y) + zr));
2074 painter->drawCircle(toGui(relativeZero), zr);
2076 painter->setNormalMode();
2078 // if (painterCreated)
2079 // destroyPainter();
2084 * Draws the paper border (for print previews).
2088 void RS_GraphicView::drawPaper()
2090 bool painterCreated = false;
2092 if (container == NULL)
2095 Drawing * graphic = container->getGraphic();
2097 if (graphic == NULL)
2100 if (graphic->getPaperScale() < 1.0e-6)
2103 // create a temporary painter device
2104 if (painter == NULL)
2106 createDirectPainter();
2107 painterCreated = true;
2111 painter->setPen(RS_Pen(Qt::gray));
2113 Vector pinsbase = graphic->getPaperInsertionBase();
2114 Vector size = graphic->getPaperSize();
2115 double scale = graphic->getPaperScale();
2117 Vector v1 = toGui((Vector(0, 0) - pinsbase) / scale);
2118 Vector v2 = toGui((size - pinsbase) / scale);
2121 painter->fillRect(0,0, getWidth(), getHeight(), RS_Color(200, 200, 200));
2124 painter->fillRect((int)(v1.x) + 6, (int)(v1.y) + 6,
2125 (int)((v2.x - v1.x)), (int)((v2.y - v1.y)),
2126 RS_Color(64, 64, 64));
2129 painter->fillRect((int)(v1.x), (int)(v1.y),
2130 (int)((v2.x - v1.x)), (int)((v2.y - v1.y)),
2131 RS_Color(64, 64, 64));
2134 painter->fillRect((int)(v1.x) + 1, (int)(v1.y) - 1,
2135 (int)((v2.x - v1.x)) - 2, (int)((v2.y - v1.y)) + 2,
2136 RS_Color(255, 255, 255));
2147 void RS_GraphicView::drawGrid()
2149 if (grid == NULL || isGridOn() == false)
2151 // printf("RS_GraphicView::drawGrid(): Aborting: grid=%08X, isGridOn=%s\n", grid, (isGridOn() ? "true" : "false"));
2156 //painter->setPen(Qt::gray);
2157 painter->setPen(gridColor);
2158 // painter->setPen(RS_Pen(RS_Color(128, 128, 128), RS2::Width00, RS2::SolidLine));
2160 //Problem here: pts is NULL!
2161 Vector * pts = grid->getPoints();
2165 for(int i=0; i<grid->count(); ++i)
2166 painter->drawGridPoint(toGui(pts[i]));
2169 // printf("RS_GraphicView::drawGrid(): pts == NULL!\n");
2172 //painter->setPen(Qt::white);
2173 QString info = grid->getInfo();
2174 //info = QString("%1 / %2")
2175 // .arg(grid->getSpacing())
2176 // .arg(grid->getMetaSpacing());
2178 updateGridStatusWidget(info);
2182 * Draws the meta grid.
2186 void RS_GraphicView::drawMetaGrid()
2188 if (grid == NULL || isGridOn() == false /*|| grid->getMetaSpacing()<0.0*/)
2191 bool painterCreated = false;
2193 // create a temporary painter device
2194 if (painter == NULL)
2196 //hrm createDirectPainter();
2198 painterCreated = true;
2201 RS_Pen pen(metaGridColor, RS2::Width00, RS2::DotLine);
2202 painter->setPen(pen);
2205 double * mx = grid->getMetaX();
2209 for(int i=0; i<grid->countMetaX(); ++i)
2210 painter->drawLine(Vector(toGuiX(mx[i]), 0), Vector(toGuiX(mx[i]), getHeight()));
2213 double * my = grid->getMetaY();
2217 for(int i=0; i<grid->countMetaY(); ++i)
2218 painter->drawLine(Vector(0, toGuiY(my[i])), Vector(getWidth(), toGuiY(my[i])));
2226 * Updates the grid if there is one.
2228 void RS_GraphicView::updateGrid()
2234 RS_Grid * RS_GraphicView::getGrid()
2239 void RS_GraphicView::updateGridStatusWidget(const QString & /*text*/)
2243 RS2::SnapMode RS_GraphicView::getDefaultSnapMode()
2245 return defaultSnapMode;
2248 RS2::SnapRestriction RS_GraphicView::getSnapRestriction()
2250 return defaultSnapRes;
2254 * Sets the default snap mode used by newly created actions.
2256 void RS_GraphicView::setDefaultSnapMode(RS2::SnapMode sm)
2258 defaultSnapMode = sm;
2260 if (eventHandler != NULL)
2261 eventHandler->setSnapMode(sm);
2265 * Sets a snap restriction (e.g. orthogonal).
2267 void RS_GraphicView::setSnapRestriction(RS2::SnapRestriction sr)
2269 defaultSnapRes = sr;
2271 if (eventHandler != NULL)
2272 eventHandler->setSnapRestriction(sr);
2276 * Translates a vector in real coordinates to a vector in screen coordinates.
2278 Vector RS_GraphicView::toGui(Vector v)
2280 return Vector(toGuiX(v.x), toGuiY(v.y), 0.0);
2284 * Translates a real coordinate in X to a screen coordinate X.
2285 * @param visible Pointer to a boolean which will contain true
2286 * after the call if the coordinate is within the visible range.
2288 double RS_GraphicView::toGuiX(double x, bool * visible)
2290 if (visible != NULL)
2292 double res = x * factor.x + offsetX;
2294 if (res > 0.0 && res < getWidth())
2300 return x * factor.x + offsetX;
2304 * Translates a real coordinate in Y to a screen coordinate Y.
2306 double RS_GraphicView::toGuiY(double y)
2308 return -y * factor.y + getHeight() - offsetY;
2312 * Translates a real coordinate distance to a screen coordinate distance.
2314 double RS_GraphicView::toGuiDX(double d)
2316 return d * factor.x;
2320 * Translates a real coordinate distance to a screen coordinate distance.
2322 double RS_GraphicView::toGuiDY(double d)
2324 return d * factor.y;
2328 * Translates a vector in screen coordinates to a vector in real coordinates.
2330 Vector RS_GraphicView::toGraph(Vector v)
2332 return Vector(toGraphX(RS_Math::round(v.x)), toGraphY(RS_Math::round(v.y)), 0.0);
2336 * Translates two screen coordinates to a vector in real coordinates.
2338 Vector RS_GraphicView::toGraph(int x, int y)
2340 return Vector(toGraphX(x), toGraphY(y), 0.0);
2344 * Translates a screen coordinate in X to a real coordinate X.
2346 double RS_GraphicView::toGraphX(int x)
2348 return (x - offsetX) / factor.x;
2352 * Translates a screen coordinate in Y to a real coordinate Y.
2354 double RS_GraphicView::toGraphY(int y)
2356 return -(y - getHeight() + offsetY) / factor.y;
2360 * Translates a screen coordinate distance to a real coordinate distance.
2362 double RS_GraphicView::toGraphDX(int d)
2364 return d / factor.x;
2368 * Translates a screen coordinate distance to a real coordinate distance.
2370 double RS_GraphicView::toGraphDY(int d)
2372 return d / factor.y;
2376 * (Un-)Locks the position of the relative zero.
2378 * @param lock true: lock, false: unlock
2380 void RS_GraphicView::lockRelativeZero(bool lock)
2382 relativeZeroLocked=lock;
2386 * @return true if the position of the realtive zero point is
2389 bool RS_GraphicView::isRelativeZeroLocked()
2391 return relativeZeroLocked;
2395 * @return Relative zero coordinate.
2397 Vector RS_GraphicView::getRelativeZero()
2399 return relativeZero;
2403 * Sets the relative zero coordinate (if not locked)
2404 * without deleting / drawing the point.
2406 void RS_GraphicView::setRelativeZero(const Vector & pos)
2408 if (!relativeZeroLocked)
2413 * Sets the relative zero coordinate, deletes the old position
2414 * on the screen and draws the new one.
2416 void RS_GraphicView::moveRelativeZero(const Vector & pos)
2418 // bool painterCreated = false;
2420 if (painter == NULL)
2423 //hrm painter = createDirectPainter();
2424 // painter = createPainter();
2425 // painterCreated = true;
2428 //painter->setXORMode();
2431 setRelativeZero(pos);
2435 // if (painterCreated)
2436 // destroyPainter();
2439 RS_EventHandler * RS_GraphicView::getEventHandler()
2441 return eventHandler;
2445 * Enables or disables print preview.
2447 void RS_GraphicView::setPrintPreview(bool pv)
2453 * @retval true This is a print preview graphic view.
2454 * @retval false Otherwise.
2456 bool RS_GraphicView::isPrintPreview()
2458 return printPreview;
2462 * Enables or disables printing.
2464 void RS_GraphicView::setPrinting(bool p)
2470 * @retval true This is a a graphic view for printing.
2471 * @retval false Otherwise.
2473 bool RS_GraphicView::isPrinting()
2479 * @retval true Draft mode is on for this view (all lines with 1 pixel / no style scaling).
2480 * @retval false Otherwise.
2482 bool RS_GraphicView::isDraftMode()
2488 * Sets the simulation speed in percentage.
2490 void RS_GraphicView::setSimulationSpeed(int s)
2492 simulationSpeed = s;
2496 * @return the simulation speed in percentage.
2498 int RS_GraphicView::getSimulationSpeed()
2500 return simulationSpeed;
2504 * Sets the simulation smooth mode.
2506 void RS_GraphicView::setSimulationSmooth(bool s)
2508 simulationSmooth = s;
2511 * Sets the simulation rapid mode.
2513 void RS_GraphicView::setSimulationRapid(bool r)
2515 simulationRapid = r;
2519 * @return the simulation rapid mode.
2521 bool RS_GraphicView::getSimulationRapid()
2523 return simulationRapid;
2526 // These functions are here because of the focacta way that this
2527 // program set up its rendering...
2528 void RS_GraphicView::SetPreviewMode(bool mode/*= true*/)
2533 void RS_GraphicView::SetPreviewEntity(RS_Preview * p)
2538 void RS_GraphicView::SetPreviewOffset(Vector o)
2543 void RS_GraphicView::SetSnapperDraw(bool mode)
2548 void RS_GraphicView::SetSnapperVars(Vector snapSpot, Vector snapCoord, bool showCrosshairs)
2550 snapSpot1 = snapSpot;
2551 snapCoord1 = snapCoord;
2552 showCrosshairs1 = showCrosshairs;