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;
73 settings.beginGroup("Appearance");
74 setBackground(QColor(settings.value("BackgroundColor", "#000000").toString()));
75 setGridColor(QColor(settings.value("GridColor", "#7F7F7F").toString()));
76 setMetaGridColor(QColor(settings.value("MetaGridColor", "#3F3F3F").toString()));
77 setSelectedColor(QColor(settings.value("SelectedColor", "#A54747").toString()));
78 setHighlightedColor(QColor(settings.value("HighlightedColor", "#739373").toString()));
83 simulationSpeed = 100;
84 simulationSmooth = false;
85 simulationRapid = false;
86 simulationRunning = false;
88 //currentInsert = NULL;
94 RS_GraphicView::~RS_GraphicView()
96 //delete eventHandler;
104 * Must be called by any derrived class in the destructor.
106 void RS_GraphicView::cleanUp()
112 * @return Pointer to the graphic entity if the entity container
113 * connected to this view is a graphic and valid.
116 Drawing * RS_GraphicView::getGraphic()
118 if (container != NULL && container->rtti() == RS2::EntityGraphic)
119 return (Drawing*)container;
125 * Sets the drawing mode.
127 void RS_GraphicView::setDrawingMode(RS2::DrawingMode m)
133 * @return Current drawing mode.
135 RS2::DrawingMode RS_GraphicView::getDrawingMode()
141 * Activates or deactivates the delete mode.
143 void RS_GraphicView::setDeleteMode(bool m)
149 * @reval true Deleting instead of drawing.
150 * false Normal drawing mode.
152 bool RS_GraphicView::getDeleteMode()
157 /** This virtual method must be overwritten and is then
158 called whenever the view changed */
159 void RS_GraphicView::adjustOffsetControls()
163 /** This virtual method must be overwritten and is then
164 called whenever the view changed */
165 void RS_GraphicView::adjustZoomControls()
170 * Sets an external painter device.
172 //void RS_GraphicView::setPainter(RS_Painter * p)
173 void RS_GraphicView::setPainter(PaintInterface * p)
179 * Sets the background color. Note that applying the background
180 * color for the widget is up to the implementing class.
182 void RS_GraphicView::setBackground(const RS_Color & bg)
186 // bright background:
187 if (bg.red() + bg.green() + bg.blue() > 380)
188 // foreground = Qt::black;
189 foreground = RS_Color(0, 0, 0);
191 // foreground = Qt::white;
192 foreground = RS_Color(255, 255, 255);
196 * @return Current background color.
198 RS_Color RS_GraphicView::getBackground()
204 * @return Current foreground color.
206 RS_Color RS_GraphicView::getForeground()
212 * Sets the grid color.
214 void RS_GraphicView::setGridColor(const RS_Color & c)
220 * Sets the meta grid color.
222 void RS_GraphicView::setMetaGridColor(const RS_Color & c)
228 * Sets the selection color.
230 void RS_GraphicView::setSelectedColor(const RS_Color & c)
236 * Sets the highlight color.
238 void RS_GraphicView::setHighlightedColor(const RS_Color & c)
240 highlightedColor = c;
244 * This virtual method can be overwritten to set the mouse
245 * cursor to the given type.
247 void RS_GraphicView::setMouseCursor(RS2::CursorType /*c*/)
251 RS_EntityContainer * RS_GraphicView::getContainer()
256 void RS_GraphicView::setFactor(double f)
262 Vector RS_GraphicView::getFactor()
268 * Sets the offset of the graphic.
270 void RS_GraphicView::setOffset(int ox, int oy)
276 void RS_GraphicView::setOffsetX(int ox)
281 void RS_GraphicView::setOffsetY(int oy)
286 int RS_GraphicView::getOffsetX()
291 int RS_GraphicView::getOffsetY()
297 * Sets a fixed border in pixel around the graphic. This border
298 * specifies how far the user can scroll outside the graphic
301 void RS_GraphicView::setBorders(int left, int top, int right, int bottom)
306 borderBottom = bottom;
309 int RS_GraphicView::getBorderLeft()
314 int RS_GraphicView::getBorderTop()
319 int RS_GraphicView::getBorderRight()
324 int RS_GraphicView::getBorderBottom()
329 void RS_GraphicView::disableUpdate()
334 void RS_GraphicView::enableUpdate()
339 bool RS_GraphicView::isUpdateEnabled()
341 return (updateEnabled == 0);
344 void RS_GraphicView::freezeZoom(bool freeze)
349 bool RS_GraphicView::isZoomFrozen()
355 * Sets the pointer to the graphic which contains the entities
356 * which are visualized by this widget.
358 void RS_GraphicView::setContainer(RS_EntityContainer * container)
360 this->container = container;
361 //adjustOffsetControls();
365 * Sets the zoom factor in X for this visualization of the graphic.
367 void RS_GraphicView::setFactorX(double f)
374 * Sets the zoom factor in Y for this visualization of the graphic.
376 void RS_GraphicView::setFactorY(double f)
383 * @return true if the grid is switched on.
385 bool RS_GraphicView::isGridOn()
387 if (container != NULL)
389 Drawing * g = container->getGraphic();
392 return g->isGridOn();
399 * Centers the drawing in x-direction.
401 void RS_GraphicView::centerOffsetX()
403 if (container != NULL && !zoomFrozen)
404 offsetX = (int)(((getWidth() - borderLeft - borderRight)
405 - (container->getSize().x * factor.x)) / 2.0
406 - (container->getMin().x * factor.x)) + borderLeft;
410 * Centers the drawing in y-direction.
412 void RS_GraphicView::centerOffsetY()
414 if (container != NULL && !zoomFrozen)
415 offsetY = (int)((getHeight() - borderTop - borderBottom
416 - (container->getSize().y * factor.y)) / 2.0
417 - (container->getMin().y * factor.y)) + borderBottom;
421 * Centers the given coordinate in the view in x-direction.
423 void RS_GraphicView::centerX(double v)
426 offsetX = (int)((v * factor.x) - (double)(getWidth() - borderLeft - borderRight) / 2.0);
430 * Centers the given coordinate in the view in y-direction.
432 void RS_GraphicView::centerY(double v)
435 offsetY = (int)((v * factor.y) - (double)(getHeight() - borderTop - borderBottom) / 2.0);
438 void RS_GraphicView::updateView()
440 static int running = 0;
445 adjustZoomControls();
446 adjustOffsetControls();
456 * @return Current action or NULL.
458 RS_ActionInterface * RS_GraphicView::getDefaultAction()
460 if (eventHandler != NULL)
461 return eventHandler->getDefaultAction();
467 * Sets the default action of the event handler.
469 void RS_GraphicView::setDefaultAction(RS_ActionInterface * action)
471 if (eventHandler != NULL)
472 eventHandler->setDefaultAction(action);
476 * @return Current action or NULL.
478 RS_ActionInterface * RS_GraphicView::getCurrentAction()
480 if (eventHandler != NULL)
481 return eventHandler->getCurrentAction();
487 * Sets the current action of the event handler.
489 void RS_GraphicView::setCurrentAction(RS_ActionInterface * action)
491 RS_DEBUG->print("RS_GraphicView::setCurrentAction");
493 if (eventHandler != NULL)
494 eventHandler->setCurrentAction(action);
496 RS_DEBUG->print("RS_GraphicView::setCurrentAction: OK");
500 * Kills all running selection actions. Called when a selection action
501 * is launched to reduce confusion.
503 void RS_GraphicView::killSelectActions()
506 eventHandler->killSelectActions();
510 * Kills all running actions.
512 void RS_GraphicView::killAllActions()
515 eventHandler->killAllActions();
519 * Go back in menu or current action.
521 void RS_GraphicView::back()
523 if (eventHandler && eventHandler->hasAction())
524 eventHandler->back();
525 else if (RS_DIALOGFACTORY)
526 RS_DIALOGFACTORY->requestPreviousMenu();
530 * Go forward with the current action.
532 void RS_GraphicView::enter()
534 if (eventHandler && eventHandler->hasAction())
535 eventHandler->enter();
539 * Called by the actual GUI class which implements the RS_GraphicView
540 * interface to notify qcadlib about mouse events.
542 void RS_GraphicView::mousePressEvent(QMouseEvent * e)
545 eventHandler->mousePressEvent(e);
549 * Called by the actual GUI class which implements the RS_GraphicView
550 * interface to notify qcadlib about mouse events.
552 void RS_GraphicView::mouseReleaseEvent(QMouseEvent * e)
554 RS_DEBUG->print("RS_GraphicView::mouseReleaseEvent");
559 if (e->button() != Qt::RightButton || eventHandler->hasAction())
561 eventHandler->mouseReleaseEvent(e);
570 RS_DEBUG->print("RS_GraphicView::mouseReleaseEvent: OK");
574 * Called by the actual GUI class which implements the RS_GraphicView
575 * interface to notify qcadlib about mouse events.
577 void RS_GraphicView::mouseMoveEvent(QMouseEvent * e)
579 RS_DEBUG->print("RS_GraphicView::mouseMoveEvent begin");
581 Drawing * graphic = NULL;
583 if (container->rtti() == RS2::EntityGraphic)
584 graphic = (Drawing *)container;
586 RS_DEBUG->print("RS_GraphicView::mouseMoveEvent 001");
594 RS_DEBUG->print("RS_GraphicView::mouseMoveEvent 002");
597 eventHandler->mouseMoveEvent(e);
599 RS_DEBUG->print("RS_GraphicView::mouseMoveEvent 003");
601 if (!eventHandler || !eventHandler->hasAction() && graphic)
603 Vector mouse = toGraph(Vector(mx, my));
604 Vector relMouse = mouse - getRelativeZero();
606 if (RS_DIALOGFACTORY)
607 RS_DIALOGFACTORY->updateCoordinateWidget(mouse, relMouse);
610 RS_DEBUG->print("RS_GraphicView::mouseMoveEvent end");
614 * Called by the actual GUI class which implements the RS_GraphicView
615 * interface to notify qcadlib about mouse events.
617 void RS_GraphicView::mouseLeaveEvent()
620 eventHandler->mouseLeaveEvent();
624 * Called by the actual GUI class which implements the RS_GraphicView
625 * interface to notify qcadlib about mouse events.
627 void RS_GraphicView::mouseEnterEvent()
630 eventHandler->mouseEnterEvent();
634 * Called by the actual GUI class which implements the RS_GraphicView
635 * interface to notify qcadlib about key events.
637 void RS_GraphicView::keyPressEvent(QKeyEvent * e)
640 eventHandler->keyPressEvent(e);
644 * Called by the actual GUI class which implements the RS_GraphicView
645 * interface to notify qcadlib about key events.
647 void RS_GraphicView::keyReleaseEvent(QKeyEvent * e)
650 eventHandler->keyReleaseEvent(e);
654 * Called by the actual GUI class which implements a command line.
656 void RS_GraphicView::commandEvent(RS_CommandEvent * e)
659 eventHandler->commandEvent(e);
663 * Enables coordinate input in the command line.
665 void RS_GraphicView::enableCoordinateInput()
668 eventHandler->enableCoordinateInput();
672 * Disables coordinate input in the command line.
674 void RS_GraphicView::disableCoordinateInput()
677 eventHandler->disableCoordinateInput();
681 * zooms in by factor f
683 void RS_GraphicView::zoomIn(double f, const Vector & center)
687 RS_DEBUG->print(RS_Debug::D_WARNING, "RS_GraphicView::zoomIn: invalid factor");
691 if (simulationRunning)
695 if (c.valid == false)
696 c = toGraph(Vector(getWidth() / 2, getHeight() / 2));
699 toGraph(Vector(0, 0)).scale(c, Vector(1.0 / f, 1.0 / f)),
700 toGraph(Vector(getWidth(), getHeight())).scale(c, Vector(1.0 / f, 1.0 / f)));
702 //adjustOffsetControls();
703 //adjustZoomControls();
709 * zooms in by factor f in x
711 void RS_GraphicView::zoomInX(double f)
713 if (simulationRunning)
717 offsetX = (int)((offsetX - getWidth() / 2) * f) + getWidth() / 2;
718 adjustOffsetControls();
719 adjustZoomControls();
725 * zooms in by factor f in y
727 void RS_GraphicView::zoomInY(double f)
729 if (simulationRunning)
733 offsetY = (int)((offsetY - getHeight() / 2) * f)+getHeight() / 2;
734 adjustOffsetControls();
735 adjustZoomControls();
741 * zooms out by factor f
743 void RS_GraphicView::zoomOut(double f, const Vector & center)
747 RS_DEBUG->print(RS_Debug::D_WARNING,
748 "RS_GraphicView::zoomOut: invalid factor");
752 if (simulationRunning)
759 * zooms out by factor f in x
761 void RS_GraphicView::zoomOutX(double f)
765 RS_DEBUG->print(RS_Debug::D_WARNING,
766 "RS_GraphicView::zoomOutX: invalid factor");
770 if (simulationRunning)
774 offsetX = (int)(offsetX / f);
775 adjustOffsetControls();
776 adjustZoomControls();
782 * zooms out by factor f y
784 void RS_GraphicView::zoomOutY(double f)
788 RS_DEBUG->print(RS_Debug::D_WARNING,
789 "RS_GraphicView::zoomOutY: invalid factor");
793 if (simulationRunning)
797 offsetY = (int)(offsetY / f);
798 adjustOffsetControls();
799 adjustZoomControls();
807 * @param axis include axis in zoom
808 * @param keepAspectRatio true: keep aspect ratio 1:1
809 * false: factors in x and y are stretched to the max
811 void RS_GraphicView::zoomAuto(bool axis, bool keepAspectRatio)
813 RS_DEBUG->print("RS_GraphicView::zoomAuto");
815 if (simulationRunning)
820 if (container != NULL)
822 container->calculateBorders();
827 sx = std::max(container->getMax().x, 0.0) - std::min(container->getMin().x, 0.0);
828 sy = std::max(container->getMax().y, 0.0) - std::min(container->getMin().y, 0.0);
832 sx = container->getSize().x;
833 sy = container->getSize().y;
838 if (sx > RS_TOLERANCE)
839 fx = (getWidth() - borderLeft - borderRight) / sx;
843 if (sy > RS_TOLERANCE)
844 fy = (getHeight() - borderTop - borderBottom) / sy;
848 RS_DEBUG->print("f: %f/%f", fx, fy);
851 fx = fy = std::min(fx, fy);
853 RS_DEBUG->print("f: %f/%f", fx, fy);
855 if (fx < RS_TOLERANCE)
861 RS_DEBUG->print("f: %f/%f", fx, fy);
863 RS_DEBUG->print("adjustOffsetControls");
864 adjustOffsetControls();
865 RS_DEBUG->print("adjustZoomControls");
866 adjustZoomControls();
867 RS_DEBUG->print("centerOffsetX");
869 RS_DEBUG->print("centerOffsetY");
871 RS_DEBUG->print("updateGrid");
876 RS_DEBUG->print("RS_GraphicView::zoomAuto OK");
880 * Shows previous view.
882 void RS_GraphicView::zoomPrevious()
884 RS_DEBUG->print("RS_GraphicView::zoomPrevious");
886 if (simulationRunning)
889 if (container != NULL)
894 * Saves the current view as previous view to which we can
895 * switch back later with @see restoreView().
897 void RS_GraphicView::saveView()
899 previousOffsetX = offsetX;
900 previousOffsetY = offsetY;
901 previousFactor = factor;
905 * Restores the view previously saved with
908 void RS_GraphicView::restoreView()
910 int pox = previousOffsetX;
911 int poy = previousOffsetY;
912 Vector pf = previousFactor;
920 adjustOffsetControls();
921 adjustZoomControls();
927 * performs autozoom in y only
929 * @param axis include axis in zoom
931 void RS_GraphicView::zoomAutoY(bool axis)
933 if (simulationRunning)
936 if (container != NULL)
938 double visibleHeight = 0.0;
939 double minY = RS_MAXDOUBLE;
940 double maxY = RS_MINDOUBLE;
941 bool noChange = false;
943 for(RS_Entity * e=container->firstEntity(RS2::ResolveNone);
944 e!=NULL; e = container->nextEntity(RS2::ResolveNone))
946 if (e->rtti() == RS2::EntityLine)
948 RS_Line * l = (RS_Line *)e;
950 x1 = toGuiX(l->getStartpoint().x);
951 x2 = toGuiX(l->getEndpoint().x);
953 if (x1 > 0.0 && x1 < (double)getWidth() || x2 > 0.0 && x2 < (double)getWidth())
955 minY = std::min(minY, l->getStartpoint().y);
956 minY = std::min(minY, l->getEndpoint().y);
957 maxY = std::max(maxY, l->getStartpoint().y);
958 maxY = std::max(maxY, l->getEndpoint().y);
964 visibleHeight = std::max(maxY, 0.0) - std::min(minY, 0.0);
966 visibleHeight = maxY - minY;
968 if (visibleHeight < 1.0)
973 if (visibleHeight > 1.0e-6)
975 fy = (getHeight() - borderTop - borderBottom) / visibleHeight;
977 if (factor.y < 0.000001)
981 if (noChange == false)
985 offsetY = (int)((getHeight() - borderTop - borderBottom - (visibleHeight * factor.y)) / 2.0
986 - (minY * factor.y)) + borderBottom;
987 adjustOffsetControls();
988 adjustZoomControls();
992 RS_DEBUG->print("Auto zoom y ok");
997 * Zooms the area given by v1 and v2.
999 * @param keepAspectRatio true: keeps the aspect ratio 1:1
1000 * false: zooms exactly the selected range to the
1001 * current graphic view
1003 void RS_GraphicView::zoomWindow(Vector v1, Vector v2, bool keepAspectRatio)
1005 if (simulationRunning)
1010 double zoomX = 480.0; // Zoom for X-Axis
1011 double zoomY = 640.0; // Zoom for Y-Axis (Set smaller one)
1012 double dum; // Dummy for switching values
1015 // Switch left/right and top/bottom is necessary:
1030 // Get zoom in X and zoom in Y:
1031 if (v2.x - v1.x > 1.0e-6)
1032 zoomX = getWidth() / (v2.x - v1.x);
1034 if (v2.y - v1.y > 1.0e-6)
1035 zoomY = getHeight() / (v2.y - v1.y);
1037 // Take smaller zoom:
1038 if (keepAspectRatio)
1042 if (getWidth() != 0)
1044 zoomX = zoomY = ((double)(getWidth() - 2 * zoomBorder)) /
1045 (double)getWidth() * zoomX;
1050 if (getHeight() != 0)
1052 zoomX = zoomY = ((double)(getHeight() - 2 * zoomBorder)) /
1053 (double)getHeight() * zoomY;
1064 // Borders in pixel after zoom
1065 int pixLeft = (int)(v1.x * zoomX);
1066 int pixTop = (int)(v2.y * zoomY);
1067 int pixRight = (int)(v2.x * zoomX);
1068 int pixBottom = (int)(v1.y * zoomY);
1070 // Set new offset for zero point:
1071 offsetX = - pixLeft + (getWidth() - pixRight + pixLeft) / 2;
1072 offsetY = - pixTop + (getHeight() - pixBottom + pixTop) / 2;
1076 adjustOffsetControls();
1077 adjustZoomControls();
1083 * Centers the point v1.
1085 void RS_GraphicView::zoomPan(int dx, int dy)
1087 //offsetX+=(int)toGuiDX(v1.x);
1088 //offsetY+=(int)toGuiDY(v1.y);
1089 if (simulationRunning)
1096 adjustOffsetControls();
1097 //adjustZoomControls();
1104 * Scrolls in the given direction.
1106 void RS_GraphicView::zoomScroll(RS2::Direction direction)
1108 if (simulationRunning)
1127 adjustOffsetControls();
1128 adjustZoomControls();
1134 * Zooms to page extends.
1136 void RS_GraphicView::zoomPage()
1138 RS_DEBUG->print("RS_GraphicView::zoomPage");
1140 if (container == NULL)
1143 if (simulationRunning)
1146 Drawing * graphic = container->getGraphic();
1148 if (graphic == NULL)
1151 Vector s = graphic->getPaperSize();
1152 Vector pinsbase = graphic->getPaperInsertionBase();
1156 if (s.x > RS_TOLERANCE)
1157 fx = (getWidth() - borderLeft - borderRight) / s.x;
1161 if (s.y > RS_TOLERANCE)
1162 fy = (getHeight() - borderTop - borderBottom) / s.y;
1166 RS_DEBUG->print("f: %f/%f", fx, fy);
1168 fx = fy = std::min(fx, fy);
1170 RS_DEBUG->print("f: %f/%f", fx, fy);
1172 if (fx < RS_TOLERANCE)
1178 RS_DEBUG->print("f: %f/%f", fx, fy);
1182 adjustOffsetControls();
1183 adjustZoomControls();
1189 * Draws the entities within the given range.
1191 void RS_GraphicView::drawWindow(Vector v1, Vector v2)
1193 RS_DEBUG->print("RS_GraphicView::drawWindow() begin");
1195 if (simulationRunning)
1200 for(RS_Entity * se=container->firstEntity(RS2::ResolveNone); se!=NULL;
1201 se=container->nextEntity(RS2::ResolveNone))
1203 if (se->isInWindow(v1, v2))
1208 RS_DEBUG->print("RS_GraphicView::drawWindow() end");
1212 * Draws the entities. If painter is NULL a new painter will
1213 * be created and destroyed.
1215 void RS_GraphicView::drawIt()
1217 if (!isUpdateEnabled())
1219 //printf("RS_GraphicView::drawIt(): isUpdateEnabled() == false!\n");
1223 if (simulationRunning)
1225 //printf("RS_GraphicView::drawIt(): simulationRunning == true!\n");
1229 settings.beginGroup("Appearance");
1230 draftMode = settings.value("DraftMode", false).toBool();
1231 settings.endGroup();
1235 //printf("RS_GraphicView::drawIt(): painter == NULL!\n");
1241 // drawing paper border:
1242 if (isPrintPreview())
1244 // drawing meta grid:
1248 // drawing entities:
1249 //#warning "!!! This looks like a bug, no match for 'drawEntity(RS_Entity *, bool) !!!"
1250 // and indeed it *is* a bug... true is converted to 1.0 here. Dumb, dumb, dumb.
1251 drawEntity(container);//, true);
1253 // drawing zero points:
1254 if (!isPrintPreview())
1261 if (!isPrintPreview())
1266 * Sets the pen of the painter object to the suitable pen for the given
1269 void RS_GraphicView::setPenForEntity(RS_Entity * e)
1271 if (drawingMode == RS2::ModePreview /*|| draftMode==true*/)
1274 // set color of entity
1275 if (painter != NULL && !painter->isPreviewMode())
1277 // Getting pen from entity (or layer)
1278 RS_Pen pen = e->getPen(true);
1280 int w = pen.getWidth();
1288 double uf = 1.0; // unit factor
1289 double wf = 1.0; // width factor
1290 Drawing * graphic = container->getGraphic();
1292 if (graphic != NULL)
1294 uf = RS_Units::convert(1.0, RS2::Millimeter, graphic->getUnit());
1296 if ((isPrinting() || isPrintPreview()) && graphic->getPaperScale() > 1.0e-6)
1297 wf = 1.0 / graphic->getPaperScale();
1300 pen.setScreenWidth(toGuiDX(w / 100.0 * uf * wf));
1304 //pen.setWidth(RS2::Width00);
1305 pen.setScreenWidth(0);
1308 // prevent drawing with 1-width which is slow:
1309 if (RS_Math::round(pen.getScreenWidth()) == 1)
1310 pen.setScreenWidth(0.0);
1312 // prevent background color on background drawing:
1313 if (pen.getColor().stripFlags() == background.stripFlags())
1314 pen.setColor(foreground);
1316 // this entity is selected:
1317 if (e->isSelected())
1319 pen.setLineType(RS2::DotLine);
1320 //pen.setColor(RS_Color(0xa5,0x47,0x47));
1321 pen.setColor(selectedColor);
1324 // this entity is highlighted:
1325 if (e->isHighlighted())
1327 //pen.setColor(RS_Color(0x73, 0x93, 0x73));
1328 pen.setColor(highlightedColor);
1331 // deleting not drawing:
1332 if (getDeleteMode())
1333 pen.setColor(background);
1335 painter->setPen(pen);
1340 * Draws an entity. Might be recusively called e.g. for polylines.
1341 * If the class wide painter is NULL a new painter will be created
1342 * and destroyed afterwards.
1344 * @param patternOffset Offset of line pattern (used for connected
1345 * lines e.g. in splines).
1346 * @param db Double buffering on (recommended) / off
1348 void RS_GraphicView::drawEntity(RS_Entity * e, double patternOffset, bool db)
1350 //RS_DEBUG->print("RS_GraphicView::drawEntity() begin");
1352 // update is diabled:
1353 if (!isUpdateEnabled())
1356 // given entity is NULL:
1360 // entity is not visible:
1361 if (!e->isVisible())
1364 // test if the entity is in the viewport
1365 if (!e->isContainer() && !isPrinting()
1366 && (painter == NULL || !painter->isPreviewMode())
1367 && (toGuiX(e->getMax().x) < 0 || toGuiX(e->getMin().x) > getWidth()
1368 || toGuiY(e->getMin().y) < 0 || toGuiY(e->getMax().y) > getHeight()))
1370 //printf("RS_GraphicView::drawEntity(): Bailing out of big test!!!\n");
1375 //RS_DEBUG->print("recursion 1: %d", drawRecursion);
1380 //RS_DEBUG->print("draw plain");
1383 // large texts as rectangles:
1384 if (e->rtti() == RS2::EntityText)
1386 if (toGuiDX(((RS_Text *)e)->getHeight()) < 4 || e->countDeep() > 100)
1387 painter->drawRect(toGui(e->getMin()), toGui(e->getMax()));
1389 drawEntityPlain(e, patternOffset);
1391 // all images as rectangles:
1392 else if (e->rtti() == RS2::EntityImage)
1393 painter->drawRect(toGui(e->getMin()), toGui(e->getMax()));
1395 else if (e->rtti() == RS2::EntityHatch)
1400 drawEntityPlain(e, patternOffset);
1403 drawEntityPlain(e, patternOffset);
1405 // draw reference points:
1406 if (e->isSelected())
1408 if (!e->isParentSelected())
1410 VectorSolutions s = e->getRefPoints();
1412 for(int i=0; i<s.getNumber(); ++i)
1415 RS_Color col = RS_Color(0, 0, 255);
1417 if (e->rtti() == RS2::EntityPolyline)
1419 if (i == 0 || i == s.getNumber() - 1)
1424 // col = QColor(0, 64, 255);
1425 col = RS_Color(0, 64, 255);
1430 // col = QColor(0, 0, 128);
1431 col = RS_Color(0, 0, 128);
1436 if (getDeleteMode())
1437 painter->drawHandle(toGui(s.get(i)), background, sz);
1439 painter->drawHandle(toGui(s.get(i)), col, sz);
1444 //RS_DEBUG->print("draw plain OK");
1445 //RS_DEBUG->print("RS_GraphicView::drawEntity() end");
1449 * Deletes an entity with the background color.
1450 * Might be recusively called e.g. for polylines.
1452 void RS_GraphicView::deleteEntity(RS_Entity * e)
1454 setDeleteMode(true);
1456 setDeleteMode(false);
1461 * The painter must be initialized and all the attributes (pen) must be set.
1463 void RS_GraphicView::drawEntityPlain(RS_Entity * e, double patternOffset)
1467 //printf("RS_GraphicView::drawEntityPlain(): Entity passed in is NULL!\n");
1471 //printf("RS_GraphicView::drawEntityPlain(): Passing in painter=%08X, view=%08X\n", painter, this);
1472 e->draw(painter, this, patternOffset);
1476 * Simulates this drawing in slow motion.
1478 void RS_GraphicView::simulateIt()
1480 if (simulationRunning)
1483 simulationRunning = true;
1484 simulationLast = Vector(0.0, 0.0);
1486 //jlh destroyPainter();
1490 // drawing paper border:
1491 if (isPrintPreview())
1494 // drawing meta grid:
1495 if (!isPrintPreview())
1499 if (!isPrintPreview())
1503 //painter->setPen(RS_Pen(foreground,
1504 // RS2::Width00, RS2::SolidLine));
1507 // drawing entities:
1508 RS_Pen pen(foreground, RS2::Width00, RS2::SolidLine);
1509 simulateEntity(container, pen);
1511 //RS_DEBUG->timestamp();
1512 //RS_DEBUG->print(" draw zero..");
1514 // drawing zero points:
1515 if (!isPrintPreview())
1521 //RS_DEBUG->timestamp();
1522 //RS_DEBUG->print(" draw grid..");
1524 //RS_DEBUG->timestamp();
1525 //RS_DEBUG->print("RS_GraphicView::drawIt() end");
1526 //if (painterCreated==true) {
1527 //jlh destroyPainter();
1529 simulationRunning = false;
1533 * Simulates the given entity.
1535 * @param smooth If true, the entity will be drawn slowly (pixel by pixel).
1537 void RS_GraphicView::simulateEntity(RS_Entity * e, const RS_Pen & pen)
1539 if (painter == NULL || e == NULL)
1542 if (e->isContainer())
1544 RS_EntityContainer * ec = (RS_EntityContainer *)e;
1546 for(RS_Entity* en=ec->firstEntity(RS2::ResolveNone);
1547 en!=NULL; en = ec->nextEntity(RS2::ResolveNone))
1549 if (en->isVisible() && en->isUndone() == false)
1552 if (en->isAtomic() && simulationRapid)
1554 Vector sp = ((RS_AtomicEntity *)en)->getStartpoint();
1556 if (sp.distanceTo(simulationLast) > 1.0e-4)
1558 //jlh createDirectPainter();
1559 RS_Pen rpen(RS_Color(0, 0, 255), RS2::Width00, RS2::SolidLine);
1560 //painter->setPen(pen);
1561 RS_Line rapidLine(NULL, RS_LineData(simulationLast, sp));
1562 simulateEntity(&rapidLine, rpen);
1566 if (en->isHighlighted())
1568 RS_Pen hpen(highlightedColor, RS2::Width00, RS2::SolidLine);
1569 simulateEntity(en, hpen);
1572 simulateEntity(en, pen);
1575 simulationLast = ((RS_AtomicEntity *)en)->getEndpoint();
1577 if (!simulationSmooth)
1578 simulationDelay(true);
1584 if (simulationSmooth)
1588 case RS2::EntityLine:
1590 RS_Line * line = (RS_Line *)e;
1591 drawLineSmooth(toGui(line->getStartpoint()), toGui(line->getEndpoint()), pen);
1596 case RS2::EntityArc:
1598 RS_Arc * arc = (RS_Arc *)e;
1599 drawArcSmooth(toGui(arc->getCenter()), toGuiDX(arc->getRadius()),
1600 arc->getAngle1(), arc->getAngle2(), arc->isReversed(), pen);
1604 case RS2::EntityCircle:
1606 RS_Circle * circle = (RS_Circle *)e;
1607 drawArcSmooth(toGui(circle->getCenter()), toGuiDX(circle->getRadius()),
1608 0.0, 2.0 * M_PI, false, pen);
1618 //jlh createDirectPainter();
1619 //RS_Pen pen(foreground, RS2::Width00, RS2::SolidLine);
1620 painter->setPen(pen);
1627 * Delay for slow motion simulation.
1629 * @param step true: stepping mode (entity by entity simulation). adds a delay.
1631 void RS_GraphicView::simulationDelay(bool step)
1634 settings.beginGroup("CAM");
1635 double fact = settings.value("SimulationFactor", 12000.0).toDouble();
1636 settings.endGroup();
1638 // simulationSpeed: 0..100
1641 delay = (int)(((1.0 / (simulationSpeed + 1.0)) * fact) - (fact / 100.0));
1646 static int call = 0;
1648 if (call >= (fact - delay) / 1000)
1651 for(int i=0; i<delay; ++i)
1652 RS_APP->processEvents(10);
1657 delay = (int)(((1.0 / (simulationSpeed + 1.0)) * fact) - (fact / 100.0));
1664 for(int i=0; i<delay; ++i)
1666 #warning "Qt3->4 conversion: commented out problem line... !!! FIX !!!"
1667 // RS_APP->processEvents(10);
1673 * Draws a line slowly from (x1, y1) to (x2, y2). This is used for simulation only.
1675 void RS_GraphicView::drawLineSmooth(const Vector & p1, const Vector & p2, const RS_Pen & pen)
1677 double alpha = p1.angleTo(p2);
1678 double xStep, yStep;
1681 if (RS_Math::cmpDouble(alpha, 0.0) || RS_Math::cmpDouble(alpha, 2 * M_PI))
1687 else if (RS_Math::cmpDouble(alpha, M_PI / 2.0))
1693 else if (RS_Math::cmpDouble(alpha, M_PI))
1699 else if (RS_Math::cmpDouble(alpha, M_PI / 2.0 * 3.0))
1705 else if (fabs(p2.x - p1.x) > fabs(p2.y - p1.y))
1712 yStep = tan(alpha) * xStep;
1722 xStep = yStep / tan(alpha);
1728 //RS_Pen pen(foreground, RS2::Width00, RS2::SolidLine);
1732 if (lx >= 0.0 && lx <= (double)getWidth() && ly >= 0.0 && ly <= (double)getHeight())
1734 //if (painter==NULL) {
1735 //jlh createDirectPainter();
1737 painter->setPen(pen);
1738 painter->drawGridPoint(Vector(lx, ly));
1747 while ((xIsOne && ((lx >= p1.x && lx <= p2.x) || (lx >= p2.x && lx <= p1.x)))
1748 || (!xIsOne && ((ly >= p1.y && ly <= p2.y) || (ly >= p2.y && ly <= p1.y))));
1751 void RS_GraphicView::drawArcSmooth(const Vector & center, double radius, double a1, double a2, bool rev,
1754 //int icx = graphic->realToScreenX(cx);
1755 //int icy = graphic->realToScreenY(cy);
1756 //RS_Pen pen(foreground, RS2::Width00, RS2::SolidLine);
1760 //jlh createDirectPainter();
1761 painter->setPen(pen);
1762 painter->drawGridPoint(center);
1766 int ix1 = RS_Math::round(center.x + cos(a1) * radius);
1767 int iy1 = RS_Math::round(center.y - sin(a1) * radius);
1768 int ix2 = RS_Math::round(center.x + cos(a2) * radius);
1769 int iy2 = RS_Math::round(center.y - sin(a2) * radius);
1770 int k2x = 0; // Next point on circle
1772 int k1x = ix1; // Prev point on circle
1774 double aStep; // Angle Step (rad)
1775 double a; // Actual Angle (rad)
1776 double a2cp = a2; // Copy of a2
1778 if (1.0 / (radius * factor.x) <= 1.0)
1779 aStep = asin(1.0 / (radius * factor.x));
1788 // Arc Counterclockwise:
1790 if (a1 > a2cp - 0.01)
1793 //if (painter==NULL) {
1794 //painter->setPen(pen);
1795 //createDirectPainter();
1797 //painter->moveTo(ix1, iy1);
1799 for(a=a1+aStep; a<=a2cp; a+=aStep)
1801 k2x = RS_Math::round(center.x+cos(a)*radius);
1802 k2y = RS_Math::round(center.y-sin(a)*radius);
1803 //if(graphic->isPointOnScreen(k2x, k2y) ||
1804 // graphic->isPointOnScreen(k1x, k1y) ) {
1805 //jlh createDirectPainter();
1806 painter->setPen(pen);
1807 if ((k2x >= 0 && k2x <= painter->getWidth()
1808 && k2y >= 0 && k2y <= painter->getHeight())
1809 || (k1x >= 0 && k1x <= painter->getWidth()
1810 && k1y >= 0 && k1y <= painter->getHeight()))
1812 //painter->lineTo(k2x, k2y);
1813 painter->drawLine(Vector(k1x, k1y), Vector(k2x, k2y));
1815 //graphic->simulationDelay();
1817 //createDirectPainter();
1818 //painter->setPen(pen);
1819 //painter->moveTo(k2x, k2y);
1825 //jlh createDirectPainter();
1826 painter->setPen(pen);
1827 painter->drawLine(Vector(k2x, k2y), Vector(ix2, iy2));
1828 //painter->lineTo(ix2, iy2);
1834 if (a1 < a2cp + 0.01)
1837 //createDirectPainter();
1838 //painter->setPen(pen);
1839 //painter->moveTo(ix1, iy1);
1840 for(a=a1-aStep; a>=a2cp; a-=aStep)
1842 k2x = RS_Math::round(center.x + cos(a) * radius);
1843 k2y = RS_Math::round(center.y - sin(a) * radius);
1844 //if(graphic->isPointOnScreen(k2x, k2y) ||
1845 // graphic->isPointOnScreen(k1x, k1y) ) {
1846 //jlh createDirectPainter();
1847 painter->setPen(pen);
1848 if ((k2x >=0 && k2x <= painter->getWidth()
1849 && k2y >= 0 && k2y <= painter->getHeight())
1850 || (k1x >= 0 && k1x <= painter->getWidth()
1851 && k1y >= 0 && k1y <= painter->getHeight()))
1853 //painter->lineTo(k2x, k2y);
1854 painter->drawLine(Vector(k1x, k1y), Vector(k2x, k2y));
1857 //createDirectPainter();
1858 //painter->setPen(pen);
1859 //painter->moveTo(k2x, k2y);
1864 //jlh createDirectPainter();
1865 painter->setPen(pen);
1866 //painter->lineTo(ix2, iy2);
1867 painter->drawLine(Vector(k2x, k2y), Vector(ix2, iy2));
1873 * @return Pointer to the static pattern struct that belongs to the
1874 * given pattern type or NULL.
1876 RS_LineTypePattern * RS_GraphicView::getPattern(RS2::LineType t)
1880 case RS2::SolidLine:
1881 return &patternSolidLine;
1885 return &patternDotLine;
1888 return &patternDotLine2;
1890 case RS2::DotLineX2:
1891 return &patternDotLineX2;
1895 return &patternDashLine;
1897 case RS2::DashLine2:
1898 return &patternDashLine2;
1900 case RS2::DashLineX2:
1901 return &patternDashLineX2;
1904 case RS2::DashDotLine:
1905 return &patternDashDotLine;
1907 case RS2::DashDotLine2:
1908 return &patternDashDotLine2;
1910 case RS2::DashDotLineX2:
1911 return &patternDashDotLineX2;
1914 case RS2::DivideLine:
1915 return &patternDivideLine;
1917 case RS2::DivideLine2:
1918 return &patternDivideLine2;
1920 case RS2::DivideLineX2:
1921 return &patternDivideLineX2;
1924 case RS2::CenterLine:
1925 return &patternCenterLine;
1927 case RS2::CenterLine2:
1928 return &patternCenterLine2;
1930 case RS2::CenterLineX2:
1931 return &patternCenterLineX2;
1934 case RS2::BorderLine:
1935 return &patternBorderLine;
1937 case RS2::BorderLine2:
1938 return &patternBorderLine2;
1940 case RS2::BorderLineX2:
1941 return &patternBorderLineX2;
1944 case RS2::LineByLayer:
1945 return &patternBlockLine;
1947 case RS2::LineByBlock:
1948 return &patternBlockLine;
1958 * This virtual method can be overwritten to draw the absolute
1959 * zero. It's called from within drawIt(). The default implemetation
1960 * draws a simple red round zero point.
1962 * Actually, we have to rework the rendering code because the way that QCad did
1963 * it was wrong on so many levels... Part of that is making sure the rendering
1964 * path is 100% clear!
1968 void RS_GraphicView::drawAbsoluteZero()
1975 // RS_Pen pen(metaGridColor, RS2::Width00, RS2::SolidLine);
1976 // painter->setPen(pen);
1977 // RS_Pen p(Qt::red, RS2::Width00, RS2::SolidLine);
1978 //Using Qt::red doesn't seem to work here...
1979 //It's because Qt colors and RS_Color are not 100% compatible...
1980 RS_Pen p(RS_Color(255, 0, 0), RS2::Width00, RS2::SolidLine);
1983 painter->drawLine(Vector(toGuiX(0.0) - zr, toGuiY(0.0)),
1984 Vector(toGuiX(0.0) + zr, toGuiY(0.0)));
1986 painter->drawLine(Vector(toGuiX(0.0), toGuiY(0.0) - zr),
1987 Vector(toGuiX(0.0), toGuiY(0.0) + zr));
1991 * This virtual method can be overwritten to draw the relative
1992 * zero point. It's called from within drawIt(). The default implemetation
1993 * draws a simple red round zero point.
1997 void RS_GraphicView::drawRelativeZero()
1999 if (!relativeZero.valid || !painter)
2002 // RS_Pen p(Qt::red, RS2::Width00, RS2::SolidLine);
2003 // p.setScreenWidth(0);
2004 //Using Qt::red doesn't seem to work here...
2005 RS_Pen p(RS_Color(255, 0, 0), RS2::Width00, RS2::SolidLine);
2007 painter->setXORMode();
2011 painter->drawLine(Vector(toGuiX(relativeZero.x) - zr, toGuiY(relativeZero.y)),
2012 Vector(toGuiX(relativeZero.x) + zr, toGuiY(relativeZero.y)));
2014 painter->drawLine(Vector(toGuiX(relativeZero.x), toGuiY(relativeZero.y) - zr),
2015 Vector(toGuiX(relativeZero.x), toGuiY(relativeZero.y) + zr));
2017 painter->drawCircle(toGui(relativeZero), zr);
2018 painter->setNormalMode();
2022 * Draws the paper border (for print previews).
2026 void RS_GraphicView::drawPaper()
2028 if (container == NULL)
2031 Drawing * graphic = container->getGraphic();
2033 if (graphic == NULL)
2036 if (graphic->getPaperScale() < 1.0e-6)
2039 if (painter == NULL)
2043 painter->setPen(RS_Pen(Qt::gray));
2045 Vector pinsbase = graphic->getPaperInsertionBase();
2046 Vector size = graphic->getPaperSize();
2047 double scale = graphic->getPaperScale();
2049 Vector v1 = toGui((Vector(0, 0) - pinsbase) / scale);
2050 Vector v2 = toGui((size - pinsbase) / scale);
2053 painter->fillRect(0,0, getWidth(), getHeight(), RS_Color(200, 200, 200));
2056 painter->fillRect((int)(v1.x) + 6, (int)(v1.y) + 6,
2057 (int)((v2.x - v1.x)), (int)((v2.y - v1.y)),
2058 RS_Color(64, 64, 64));
2061 painter->fillRect((int)(v1.x), (int)(v1.y),
2062 (int)((v2.x - v1.x)), (int)((v2.y - v1.y)),
2063 RS_Color(64, 64, 64));
2066 painter->fillRect((int)(v1.x) + 1, (int)(v1.y) - 1,
2067 (int)((v2.x - v1.x)) - 2, (int)((v2.y - v1.y)) + 2,
2068 RS_Color(255, 255, 255));
2076 void RS_GraphicView::drawGrid()
2078 if (grid == NULL || isGridOn() == false)
2080 // printf("RS_GraphicView::drawGrid(): Aborting: grid=%08X, isGridOn=%s\n", grid, (isGridOn() ? "true" : "false"));
2085 //painter->setPen(Qt::gray);
2086 painter->setPen(gridColor);
2087 // painter->setPen(RS_Pen(RS_Color(128, 128, 128), RS2::Width00, RS2::SolidLine));
2089 //Problem here: pts is NULL!
2090 Vector * pts = grid->getPoints();
2094 for(int i=0; i<grid->count(); ++i)
2095 painter->drawGridPoint(toGui(pts[i]));
2098 // printf("RS_GraphicView::drawGrid(): pts == NULL!\n");
2101 //painter->setPen(Qt::white);
2102 QString info = grid->getInfo();
2103 //info = QString("%1 / %2")
2104 // .arg(grid->getSpacing())
2105 // .arg(grid->getMetaSpacing());
2107 updateGridStatusWidget(info);
2111 * Draws the meta grid.
2115 void RS_GraphicView::drawMetaGrid()
2117 if (grid == NULL || isGridOn() == false /*|| grid->getMetaSpacing()<0.0*/)
2120 if (painter == NULL)
2123 RS_Pen pen(metaGridColor, RS2::Width00, RS2::DotLine);
2124 painter->setPen(pen);
2127 double * mx = grid->getMetaX();
2128 double * my = grid->getMetaY();
2132 for(int i=0; i<grid->countMetaX(); ++i)
2133 painter->drawLine(Vector(toGuiX(mx[i]), 0), Vector(toGuiX(mx[i]), getHeight()));
2138 for(int i=0; i<grid->countMetaY(); ++i)
2139 painter->drawLine(Vector(0, toGuiY(my[i])), Vector(getWidth(), toGuiY(my[i])));
2144 * Updates the grid if there is one.
2146 void RS_GraphicView::updateGrid()
2152 RS_Grid * RS_GraphicView::getGrid()
2157 void RS_GraphicView::updateGridStatusWidget(const QString & /*text*/)
2161 RS2::SnapMode RS_GraphicView::getDefaultSnapMode()
2163 return defaultSnapMode;
2166 RS2::SnapRestriction RS_GraphicView::getSnapRestriction()
2168 return defaultSnapRes;
2172 * Sets the default snap mode used by newly created actions.
2174 void RS_GraphicView::setDefaultSnapMode(RS2::SnapMode sm)
2176 defaultSnapMode = sm;
2178 if (eventHandler != NULL)
2179 eventHandler->setSnapMode(sm);
2183 * Sets a snap restriction (e.g. orthogonal).
2185 void RS_GraphicView::setSnapRestriction(RS2::SnapRestriction sr)
2187 defaultSnapRes = sr;
2189 if (eventHandler != NULL)
2190 eventHandler->setSnapRestriction(sr);
2194 * Translates a vector in real coordinates to a vector in screen coordinates.
2196 Vector RS_GraphicView::toGui(Vector v)
2198 return Vector(toGuiX(v.x), toGuiY(v.y), 0.0);
2202 * Translates a real coordinate in X to a screen coordinate X.
2203 * @param visible Pointer to a boolean which will contain true
2204 * after the call if the coordinate is within the visible range.
2206 double RS_GraphicView::toGuiX(double x, bool * visible)
2208 if (visible != NULL)
2210 double res = x * factor.x + offsetX;
2212 if (res > 0.0 && res < getWidth())
2218 return x * factor.x + offsetX;
2222 * Translates a real coordinate in Y to a screen coordinate Y.
2224 double RS_GraphicView::toGuiY(double y)
2226 return -y * factor.y + getHeight() - offsetY;
2230 * Translates a real coordinate distance to a screen coordinate distance.
2232 double RS_GraphicView::toGuiDX(double d)
2234 return d * factor.x;
2238 * Translates a real coordinate distance to a screen coordinate distance.
2240 double RS_GraphicView::toGuiDY(double d)
2242 return d * factor.y;
2246 * Translates a vector in screen coordinates to a vector in real coordinates.
2248 Vector RS_GraphicView::toGraph(Vector v)
2250 return Vector(toGraphX(RS_Math::round(v.x)), toGraphY(RS_Math::round(v.y)), 0.0);
2254 * Translates two screen coordinates to a vector in real coordinates.
2256 Vector RS_GraphicView::toGraph(int x, int y)
2258 return Vector(toGraphX(x), toGraphY(y), 0.0);
2262 * Translates a screen coordinate in X to a real coordinate X.
2264 double RS_GraphicView::toGraphX(int x)
2266 return (x - offsetX) / factor.x;
2270 * Translates a screen coordinate in Y to a real coordinate Y.
2272 double RS_GraphicView::toGraphY(int y)
2274 return -(y - getHeight() + offsetY) / factor.y;
2278 * Translates a screen coordinate distance to a real coordinate distance.
2280 double RS_GraphicView::toGraphDX(int d)
2282 return d / factor.x;
2286 * Translates a screen coordinate distance to a real coordinate distance.
2288 double RS_GraphicView::toGraphDY(int d)
2290 return d / factor.y;
2294 * (Un-)Locks the position of the relative zero.
2296 * @param lock true: lock, false: unlock
2298 void RS_GraphicView::lockRelativeZero(bool lock)
2300 relativeZeroLocked=lock;
2304 * @return true if the position of the realtive zero point is
2307 bool RS_GraphicView::isRelativeZeroLocked()
2309 return relativeZeroLocked;
2313 * @return Relative zero coordinate.
2315 Vector RS_GraphicView::getRelativeZero()
2317 return relativeZero;
2321 * Sets the relative zero coordinate (if not locked)
2322 * without deleting / drawing the point.
2324 void RS_GraphicView::setRelativeZero(const Vector & pos)
2326 if (!relativeZeroLocked)
2331 * Sets the relative zero coordinate, deletes the old position
2332 * on the screen and draws the new one.
2334 void RS_GraphicView::moveRelativeZero(const Vector & pos)
2336 #warning "!!! RS_GraphicView::moveRelativeZero(): Bad render path !!!"
2340 //painter->setXORMode();
2342 setRelativeZero(pos);
2346 RS_EventHandler * RS_GraphicView::getEventHandler()
2348 return eventHandler;
2352 * Enables or disables print preview.
2354 void RS_GraphicView::setPrintPreview(bool pv)
2360 * @retval true This is a print preview graphic view.
2361 * @retval false Otherwise.
2363 bool RS_GraphicView::isPrintPreview()
2365 return printPreview;
2369 * Enables or disables printing.
2371 void RS_GraphicView::setPrinting(bool p)
2377 * @retval true This is a a graphic view for printing.
2378 * @retval false Otherwise.
2380 bool RS_GraphicView::isPrinting()
2386 * @retval true Draft mode is on for this view (all lines with 1 pixel / no style scaling).
2387 * @retval false Otherwise.
2389 bool RS_GraphicView::isDraftMode()
2395 * Sets the simulation speed in percentage.
2397 void RS_GraphicView::setSimulationSpeed(int s)
2399 simulationSpeed = s;
2403 * @return the simulation speed in percentage.
2405 int RS_GraphicView::getSimulationSpeed()
2407 return simulationSpeed;
2411 * Sets the simulation smooth mode.
2413 void RS_GraphicView::setSimulationSmooth(bool s)
2415 simulationSmooth = s;
2418 * Sets the simulation rapid mode.
2420 void RS_GraphicView::setSimulationRapid(bool r)
2422 simulationRapid = r;
2426 * @return the simulation rapid mode.
2428 bool RS_GraphicView::getSimulationRapid()
2430 return simulationRapid;
2433 // These functions are here because of the focacta way that this
2434 // program set up its rendering...
2435 void RS_GraphicView::SetPreviewMode(bool mode/*= true*/)
2440 void RS_GraphicView::SetPreviewEntity(RS_Preview * p)
2445 void RS_GraphicView::SetPreviewOffset(Vector o)
2450 void RS_GraphicView::SetSnapperDraw(bool mode)
2455 void RS_GraphicView::SetSnapperVars(Vector snapSpot, Vector snapCoord, bool showCrosshairs)
2457 snapSpot1 = snapSpot;
2458 snapCoord1 = snapCoord;
2459 showCrosshairs1 = showCrosshairs;