~ubuntu-branches/debian/sid/librecad/sid

« back to all changes in this revision

Viewing changes to src/lib/gui/rs_graphicview.cpp

  • Committer: Package Import Robot
  • Author(s): Scott Howard
  • Date: 2011-12-17 20:08:57 UTC
  • mfrom: (0.2.4)
  • Revision ID: package-import@ubuntu.com-20111217200857-r9wmynaloj230qm1
Tags: 1.0.0+nolibs-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
**
8
8
**
9
9
** This file may be distributed and/or modified under the terms of the
10
 
** GNU General Public License version 2 as published by the Free Software 
 
10
** GNU General Public License version 2 as published by the Free Software
11
11
** Foundation and appearing in the file gpl-2.0.txt included in the
12
12
** packaging of this file.
13
13
**
15
15
** but WITHOUT ANY WARRANTY; without even the implied warranty of
16
16
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
17
** GNU General Public License for more details.
18
 
** 
 
18
**
19
19
** You should have received a copy of the GNU General Public License
20
20
** along with this program; if not, write to the Free Software
21
21
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22
22
**
23
 
** This copyright notice MUST APPEAR in all copies of the script!  
 
23
** This copyright notice MUST APPEAR in all copies of the script!
24
24
**
25
25
**********************************************************************/
26
26
 
44
44
RS_GraphicView::RS_GraphicView()
45
45
        : background(), foreground() {
46
46
    drawingMode = RS2::ModeFull;
47
 
        printing = false;
 
47
        printing = false;
48
48
    deleteMode = false;
49
49
    factor = RS_Vector(1.0,1.0);
50
50
    offsetX = 0;
246
246
 * Sets the current action of the event handler.
247
247
 */
248
248
void RS_GraphicView::setCurrentAction(RS_ActionInterface* action) {
249
 
        RS_DEBUG->print("RS_GraphicView::setCurrentAction");
 
249
        RS_DEBUG->print("RS_GraphicView::setCurrentAction");
250
250
    if (eventHandler!=NULL) {
251
251
        eventHandler->setCurrentAction(action);
252
252
    }
253
 
        RS_DEBUG->print("RS_GraphicView::setCurrentAction: OK");
 
253
        RS_DEBUG->print("RS_GraphicView::setCurrentAction: OK");
254
254
}
255
255
 
256
256
 
267
267
 
268
268
 
269
269
/**
270
 
 * Kills all running actions. 
 
270
 * Kills all running actions.
271
271
 */
272
272
void RS_GraphicView::killAllActions() {
273
273
    if (eventHandler!=NULL) {
304
304
 
305
305
 
306
306
/**
307
 
 * Called by the actual GUI class which implements the RS_GraphicView 
 
307
 * Called by the actual GUI class which implements the RS_GraphicView
308
308
 * interface to notify LibreCAD about mouse events.
309
309
 */
310
310
void RS_GraphicView::mousePressEvent(QMouseEvent* e) {
320
320
 * interface to notify LibreCAD about mouse events.
321
321
 */
322
322
void RS_GraphicView::mouseReleaseEvent(QMouseEvent* e) {
323
 
        RS_DEBUG->print("RS_GraphicView::mouseReleaseEvent");
 
323
        RS_DEBUG->print("RS_GraphicView::mouseReleaseEvent");
324
324
    if (eventHandler!=NULL) {
325
325
        if (e->button()!=Qt::RightButton ||
326
 
                        eventHandler->hasAction()) {
 
326
                        eventHandler->hasAction()) {
327
327
 
328
328
            eventHandler->mouseReleaseEvent(e);
329
329
            //e->accept();
334
334
            e->accept();
335
335
        }
336
336
    }
337
 
        RS_DEBUG->print("RS_GraphicView::mouseReleaseEvent: OK");
 
337
        RS_DEBUG->print("RS_GraphicView::mouseReleaseEvent: OK");
338
338
}
339
339
 
340
340
 
345
345
 *                                                        RS_GraphicView interface to notify LibreCAD about
346
346
 *                                                        mouse events.
347
347
 *
348
 
 *      Author(s):                      ..., Claude Sylvain     
349
 
 *      Created:                                ?       
 
348
 *      Author(s):                      ..., Claude Sylvain
 
349
 *      Created:                                ?
350
350
 *      Last modified:          23 July 2011
351
351
 *
352
352
 *      Parameters:                     QMouseEvent* e:
380
380
    RS_DEBUG->print("RS_GraphicView::mouseMoveEvent 003");
381
381
 
382
382
    if (        ((eventHandler == NULL) || !eventHandler->hasAction()) &&
383
 
                        (graphic != NULL))
384
 
         {
 
383
                        (graphic != NULL))
 
384
         {
385
385
        RS_Vector       mouse           = toGraph(RS_Vector(mx, my));
386
386
        RS_Vector       relMouse        = mouse - getRelativeZero();
387
387
 
482
482
 
483
483
    if (f<1.0e-6) {
484
484
        RS_DEBUG->print(RS_Debug::D_WARNING,
485
 
                "RS_GraphicView::zoomIn: invalid factor");
 
485
                "RS_GraphicView::zoomIn: invalid factor");
486
486
        return;
487
487
    }
488
488
 
540
540
void RS_GraphicView::zoomOut(double f, const RS_Vector& center) {
541
541
    if (f<1.0e-6) {
542
542
        RS_DEBUG->print(RS_Debug::D_WARNING,
543
 
                "RS_GraphicView::zoomOut: invalid factor");
 
543
                "RS_GraphicView::zoomOut: invalid factor");
544
544
        return;
545
545
    }
546
546
    zoomIn(1/f, center);
554
554
void RS_GraphicView::zoomOutX(double f) {
555
555
    if (f<1.0e-6) {
556
556
        RS_DEBUG->print(RS_Debug::D_WARNING,
557
 
                "RS_GraphicView::zoomOutX: invalid factor");
 
557
                "RS_GraphicView::zoomOutX: invalid factor");
558
558
        return;
559
559
    }
560
560
    factor.x/=f;
573
573
void RS_GraphicView::zoomOutY(double f) {
574
574
    if (f<1.0e-6) {
575
575
        RS_DEBUG->print(RS_Debug::D_WARNING,
576
 
                "RS_GraphicView::zoomOutY: invalid factor");
 
576
                "RS_GraphicView::zoomOutY: invalid factor");
577
577
        return;
578
578
    }
579
579
    factor.y/=f;
594
594
void RS_GraphicView::zoomAuto(bool axis, bool keepAspectRatio) {
595
595
 
596
596
    RS_DEBUG->print("RS_GraphicView::zoomAuto");
597
 
    
598
 
        saveView();
 
597
 
 
598
        saveView();
599
599
 
600
600
    if (container!=NULL) {
601
601
        container->calculateBorders();
651
651
        RS_DEBUG->print("centerOffsetY");
652
652
        centerOffsetY();
653
653
        RS_DEBUG->print("updateGrid");
654
 
                //    updateGrid();
 
654
                //    updateGrid();
655
655
 
656
656
        redraw();
657
657
    }
661
661
 
662
662
 
663
663
/**
664
 
 * Shows previous view. 
 
664
 * Shows previous view.
665
665
 */
666
666
void RS_GraphicView::zoomPrevious() {
667
667
 
668
668
    RS_DEBUG->print("RS_GraphicView::zoomPrevious");
669
669
 
670
670
    if (container!=NULL) {
671
 
                restoreView();
 
671
                restoreView();
672
672
    }
673
673
}
674
674
 
675
675
 
676
676
 
677
677
/**
678
 
 * Saves the current view as previous view to which we can 
679
 
 * switch back later with @see restoreView(). 
 
678
 * Saves the current view as previous view to which we can
 
679
 * switch back later with @see restoreView().
680
680
 */
681
681
void RS_GraphicView::saveView() {
682
 
        previousOffsetX = offsetX;
683
 
        previousOffsetY = offsetY;
684
 
        previousFactor = factor;
 
682
        previousOffsetX = offsetX;
 
683
        previousOffsetY = offsetY;
 
684
        previousFactor = factor;
685
685
}
686
686
 
687
687
 
688
688
 
689
689
/**
690
 
 * Restores the view previously saved with 
691
 
 * @see saveView(). 
 
690
 * Restores the view previously saved with
 
691
 * @see saveView().
692
692
 */
693
693
void RS_GraphicView::restoreView() {
694
 
        int pox = previousOffsetX;
695
 
        int poy = previousOffsetY;
696
 
        RS_Vector pf = previousFactor;
697
 
 
698
 
        saveView();
699
 
        
700
 
        offsetX = pox;
701
 
        offsetY = poy;
702
 
        factor = pf;
703
 
        
 
694
        int pox = previousOffsetX;
 
695
        int poy = previousOffsetY;
 
696
        RS_Vector pf = previousFactor;
 
697
 
 
698
        saveView();
 
699
 
 
700
        offsetX = pox;
 
701
        offsetY = poy;
 
702
        factor = pf;
 
703
 
704
704
    adjustOffsetControls();
705
705
    adjustZoomControls();
706
 
        //    updateGrid();
 
706
        //    updateGrid();
707
707
 
708
 
        redraw();
 
708
        redraw();
709
709
}
710
710
 
711
711
 
712
712
/*      *
713
713
 *      Function name:
714
714
 *      Description:            Performs autozoom in Y axis only.
715
 
 *      Author(s):                      ..., Claude Sylvain     
716
 
 *      Created:                                ?       
 
715
 *      Author(s):                      ..., Claude Sylvain
 
716
 *      Created:                                ?
717
717
 *      Last modified:          23 July 2011
718
718
 *
719
719
 *      Parameters:                     bool axis:
741
741
 
742
742
                if (    ((x1 > 0.0) && (x1 < (double) getWidth())) ||
743
743
                     ((x2 > 0.0) && (x2 < (double) getWidth())))
744
 
                                         {
 
744
                                         {
745
745
                    minY = std::min(minY, l->getStartpoint().y);
746
746
                    minY = std::min(minY, l->getEndpoint().y);
747
747
                    maxY = std::max(maxY, l->getStartpoint().y);
777
777
                            - (minY*factor.y)) + borderBottom;
778
778
            adjustOffsetControls();
779
779
            adjustZoomControls();
780
 
                        //    updateGrid();
 
780
                        //    updateGrid();
781
781
 
782
782
        }
783
783
        RS_DEBUG->print("Auto zoom y ok");
797
797
                                bool keepAspectRatio) {
798
798
 
799
799
 
800
 
        saveView();
801
 
        
 
800
        saveView();
 
801
 
802
802
    double zoomX=480.0;    // Zoom for X-Axis
803
803
    double zoomY=640.0;    // Zoom for Y-Axis   (Set smaller one)
804
 
    double dum;            // Dummy for switching values
805
804
    int zoomBorder = 0;
806
805
 
807
806
    // Switch left/right and top/bottom is necessary:
808
807
    if(v1.x>v2.x) {
809
 
        dum=v1.x;
810
 
        v1.x=v2.x;
811
 
        v2.x=dum;
 
808
        std::swap(v1.x,v2.x);
812
809
    }
813
810
    if(v1.y>v2.y) {
814
 
        dum=v1.y;
815
 
        v1.y=v2.y;
816
 
        v2.y=dum;
 
811
        std::swap(v1.y,v2.y);
817
812
    }
818
813
 
819
814
    // Get zoom in X and zoom in Y:
839
834
        }
840
835
    }
841
836
 
842
 
    if(zoomX<0.0) {
843
 
        zoomX*=-1;
844
 
    }
845
 
    if(zoomY<0.0) {
846
 
        zoomY*=-1;
847
 
    }
 
837
    zoomX=fabs(zoomX);
 
838
    zoomY=fabs(zoomY);
848
839
 
849
840
    // Borders in pixel after zoom
850
841
    int pixLeft  =(int)(v1.x*zoomX);
860
851
 
861
852
    adjustOffsetControls();
862
853
    adjustZoomControls();
863
 
        //    updateGrid();
 
854
        //    updateGrid();
864
855
 
865
856
    redraw();
866
857
}
879
870
 
880
871
    adjustOffsetControls();
881
872
    //adjustZoomControls();
882
 
        //    updateGrid();
 
873
        //    updateGrid();
883
874
 
884
875
    redraw();
885
876
}
906
897
    }
907
898
    adjustOffsetControls();
908
899
    adjustZoomControls();
909
 
        //    updateGrid();
 
900
        //    updateGrid();
910
901
 
911
902
    redraw();
912
903
}
928
919
        return;
929
920
    }
930
921
 
931
 
    RS_Vector s = graphic->getPaperSize();
932
 
    RS_Vector pinsbase = graphic->getPaperInsertionBase();
 
922
    RS_Vector s = graphic->getPaperSize()/graphic->getPaperScale();
933
923
 
934
924
    double fx, fy;
935
925
 
964
954
    centerOffsetY();
965
955
    adjustOffsetControls();
966
956
    adjustZoomControls();
967
 
        //    updateGrid();
 
957
        //    updateGrid();
968
958
 
969
959
    redraw();
970
960
}
972
962
 
973
963
 
974
964
/**
975
 
 * Draws the entities within the given range. 
 
965
 * Draws the entities within the given range.
976
966
 */
977
967
void RS_GraphicView::drawWindow_DEPRECATED(RS_Vector v1, RS_Vector v2) {
978
968
    RS_DEBUG->print("RS_GraphicView::drawWindow() begin");
989
979
}
990
980
 
991
981
/**
992
 
 * Draws the entities. 
 
982
 * Draws the entities.
993
983
 * This function can only be called from within the paint event
994
 
 * 
 
984
 *
995
985
 */
996
986
void RS_GraphicView::drawLayer1(RS_Painter *painter) {
997
987
 
1004
994
    if (!isPrintPreview()) {
1005
995
 
1006
996
        //only drawGrid updates the grid layout (updatePointArray())
 
997
 
 
998
        drawMetaGrid(painter);
 
999
        //draw grid after metaGrid to avoid overwriting grid points by metaGrid lines
 
1000
        //bug# 3430258
1007
1001
        drawGrid(painter);
1008
 
        drawMetaGrid(painter);
1009
1002
 
1010
1003
    }
1011
1004
 
1015
1008
/*      *
1016
1009
 *      Function name:
1017
1010
 *      Description:            Do the drawing, step 2/3.
1018
 
 *      Author(s):                      ..., Claude Sylvain     
1019
 
 *      Created:                                ?       
 
1011
 *      Author(s):                      ..., Claude Sylvain
 
1012
 *      Created:                                ?
1020
1013
 *      Last modified:          23 July 2011
1021
1014
 *
1022
1015
 *      Parameters:                     RS_Painter *painter:
1027
1020
 
1028
1021
void RS_GraphicView::drawLayer2(RS_Painter *painter)
1029
1022
{
1030
 
        drawEntity(painter, container); //      Draw all entities.
 
1023
        drawEntity(painter, container); //      Draw all entities.
1031
1024
 
1032
 
        //      If not in print preview, draw the absolute zero reference.
1033
 
        //      ----------------------------------------------------------
1034
 
        if (!isPrintPreview())
1035
 
                drawAbsoluteZero(painter);
 
1025
        //      If not in print preview, draw the absolute zero reference.
 
1026
        //      ----------------------------------------------------------
 
1027
        if (!isPrintPreview())
 
1028
                drawAbsoluteZero(painter);
1036
1029
}
1037
1030
 
1038
1031
 
1040
1033
    // drawing zero points:
1041
1034
    if (!isPrintPreview()) {
1042
1035
        drawRelativeZero(painter);
1043
 
                drawOverlay(painter);
1044
 
    }   
 
1036
                drawOverlay(painter);
 
1037
    }
1045
1038
}
1046
1039
 
1047
1040
 
1053
1046
 *
1054
1047
 *      Author(s):              ..., Claude Sylvain
1055
1048
 *      Created:                        ?
1056
 
 *      Last modified:  24 July 2011
 
1049
 *      Last modified:  17 November 2011
1057
1050
 *
1058
1051
 *      Parameters:             RS_Painter *painter:
1059
1052
 *                                                      ...
1068
1061
{
1069
1062
    if (draftMode) {
1070
1063
        painter->setPen(RS_Pen(foreground,
1071
 
                                                           RS2::Width00, RS2::SolidLine));
1072
 
    }
1073
 
        
1074
 
        // Getting pen from entity (or layer)
1075
 
        RS_Pen pen = e->getPen(true);
1076
 
 
1077
 
        int w = pen.getWidth();
1078
 
        if (w<0) {
1079
 
            w = 0;
1080
 
        }
1081
 
 
1082
 
                // Scale pen width.
1083
 
                //      ----------------
1084
 
                if (!draftMode)
1085
 
                {
1086
 
                        double uf = 1.0;        //      Unit factor.
1087
 
 
1088
 
                        RS_Graphic* graphic = container->getGraphic();
1089
 
 
1090
 
                        if (graphic != NULL)
1091
 
                                uf = RS_Units::convert(1.0, RS2::Millimeter, graphic->getUnit());
1092
 
 
1093
 
                                pen.setScreenWidth(toGuiDX(w / 100.0 * uf));
1094
 
                }
1095
 
                else
1096
 
                        pen.setScreenWidth(0);
1097
 
 
1098
 
        // prevent drawing with 1-width which is slow:
1099
 
        if (RS_Math::round(pen.getScreenWidth())==1) {
1100
 
            pen.setScreenWidth(0.0);
1101
 
        }
1102
 
 
1103
 
        // prevent background color on background drawing:
1104
 
        if (pen.getColor().stripFlags()==background.stripFlags()) {
1105
 
            pen.setColor(foreground);
1106
 
        }
1107
 
 
1108
 
        // this entity is selected:
1109
 
        if (e->isSelected()) {
1110
 
            pen.setLineType(RS2::DotLine);
1111
 
            pen.setColor(selectedColor);
1112
 
        }
1113
 
 
1114
 
        // this entity is highlighted:
1115
 
        if (e->isHighlighted()) {
1116
 
            pen.setColor(highlightedColor);
1117
 
        }
1118
 
 
1119
 
        // deleting not drawing:
1120
 
        if (getDeleteMode()) {
1121
 
            pen.setColor(background);
1122
 
        }
1123
 
 
1124
 
        painter->setPen(pen);
 
1064
                               RS2::Width00, RS2::SolidLine));
 
1065
    }
 
1066
 
 
1067
    // Getting pen from entity (or layer)
 
1068
    RS_Pen pen = e->getPen(true);
 
1069
 
 
1070
    int w = pen.getWidth();
 
1071
    if (w<0) {
 
1072
        w = 0;
 
1073
    }
 
1074
 
 
1075
#if TRUE
 
1076
        // - Scale pen width.
 
1077
        // - Notes: pen width is not scaled on print and print preview.
 
1078
        //   This is the standard (AutoCAD like) behaviour.
 
1079
    // bug# 3437941
 
1080
        // ------------------------------------------------------------
 
1081
        if (!draftMode)
 
1082
        {
 
1083
                double  uf = 1.0;       // Unit factor.
 
1084
                double  wf = 1.0;       // Width factor.
 
1085
 
 
1086
                RS_Graphic* graphic = container->getGraphic();
 
1087
 
 
1088
                if (graphic != NULL)
 
1089
                {
 
1090
                        uf = RS_Units::convert(1.0, RS2::Millimeter, graphic->getUnit());
 
1091
 
 
1092
                        if (    (isPrinting() || isPrintPreview()) &&
 
1093
                                        graphic->getPaperScale() > RS_TOLERANCE )
 
1094
                        {
 
1095
                                wf = 1.0 / graphic->getPaperScale();
 
1096
                        }
 
1097
                }
 
1098
 
 
1099
                pen.setScreenWidth(toGuiDX(w / 100.0 * uf * wf));
 
1100
        }
 
1101
        else
 
1102
        {
 
1103
//              pen.setWidth(RS2::Width00);
 
1104
                pen.setScreenWidth(0);
 
1105
        }
 
1106
 
 
1107
#else
 
1108
 
 
1109
        // - Scale pen width.
 
1110
        // - Notes: pen width is scaled on print and print preview.
 
1111
        //   This is not the standard (AutoCAD like) behaviour.
 
1112
        // --------------------------------------------------------
 
1113
        if (!draftMode)
 
1114
        {
 
1115
                double  uf = 1.0;       //      Unit factor.
 
1116
 
 
1117
                RS_Graphic* graphic = container->getGraphic();
 
1118
 
 
1119
                if (graphic != NULL)
 
1120
                        uf = RS_Units::convert(1.0, RS2::Millimeter, graphic->getUnit());
 
1121
 
 
1122
                pen.setScreenWidth(toGuiDX(w / 100.0 * uf));
 
1123
        }
 
1124
        else
 
1125
                pen.setScreenWidth(0);
 
1126
#endif
 
1127
 
 
1128
    // prevent drawing with 1-width which is slow:
 
1129
    if (RS_Math::round(pen.getScreenWidth())==1) {
 
1130
        pen.setScreenWidth(0.0);
 
1131
    }
 
1132
 
 
1133
    // prevent background color on background drawing:
 
1134
    if (pen.getColor().stripFlags()==background.stripFlags()) {
 
1135
        pen.setColor(foreground);
 
1136
    }
 
1137
 
 
1138
    // this entity is selected:
 
1139
    if (e->isSelected()) {
 
1140
        pen.setLineType(RS2::DotLine);
 
1141
        pen.setColor(selectedColor);
 
1142
    }
 
1143
 
 
1144
    // this entity is highlighted:
 
1145
    if (e->isHighlighted()) {
 
1146
        pen.setColor(highlightedColor);
 
1147
    }
 
1148
 
 
1149
    // deleting not drawing:
 
1150
    if (getDeleteMode()) {
 
1151
        pen.setColor(background);
 
1152
    }
 
1153
 
 
1154
    painter->setPen(pen);
1125
1155
}
1126
1156
 
1127
 
 
1128
1157
/**
1129
1158
 * Draws an entity. Might be recusively called e.g. for polylines.
1130
 
 * If the class wide painter is NULL a new painter will be created 
 
1159
 * If the class wide painter is NULL a new painter will be created
1131
1160
 * and destroyed afterwards.
1132
1161
 *
1133
 
 * @param patternOffset Offset of line pattern (used for connected 
 
1162
 * @param patternOffset Offset of line pattern (used for connected
1134
1163
 *        lines e.g. in splines).
1135
1164
 * @param db Double buffering on (recommended) / off
1136
1165
 */
1137
1166
void RS_GraphicView::drawEntity(RS_Entity* e, double patternOffset) {
1138
 
        RS_DEBUG->print("RS_GraphicView::drawEntity(RS_Entity*,patternOffset) not supported anymore");
1139
 
        // RVT_PORT this needs to be optimized
1140
 
        // ONe way to do is to send a RS2::RedrawSelected, then teh draw routine will onyl draw all selected entities
1141
 
        // Dis-advantage is that we still need to iterate over all entities, but
1142
 
        // this might be very fast
1143
 
        // For now we just redraw the drawing untill we are going to optmize drawing
1144
 
        redraw(RS2::RedrawDrawing); 
 
1167
        RS_DEBUG->print("RS_GraphicView::drawEntity(RS_Entity*,patternOffset) not supported anymore");
 
1168
        // RVT_PORT this needs to be optimized
 
1169
        // ONe way to do is to send a RS2::RedrawSelected, then teh draw routine will onyl draw all selected entities
 
1170
        // Dis-advantage is that we still need to iterate over all entities, but
 
1171
        // this might be very fast
 
1172
        // For now we just redraw the drawing untill we are going to optmize drawing
 
1173
        redraw(RS2::RedrawDrawing);
1145
1174
}
1146
1175
void RS_GraphicView::drawEntity(RS_Painter *painter, RS_Entity* e, double patternOffset) {
1147
1176
 
1155
1184
    if (!e->isVisible()) {
1156
1185
        return;
1157
1186
    }
1158
 
        
 
1187
 
1159
1188
    // test if the entity is in the viewport
1160
 
        /* temporary disabled so rs_overlaylien can be drawn
 
1189
        /* temporary disabled so rs_overlaylien can be drawn
1161
1190
    if (!e->isContainer() && !isPrinting() &&
1162
1191
            (painter==NULL || !painter->isPreviewMode()) &&
1163
1192
            (toGuiX(e->getMax().x)<0 || toGuiX(e->getMin().x)>getWidth() ||
1167
1196
 
1168
1197
    // set pen (color):
1169
1198
    setPenForEntity(painter, e );
1170
 
        
 
1199
 
1171
1200
    //RS_DEBUG->print("draw plain");
1172
1201
    if (isDraftMode()) {
1173
 
                // large texts as rectangles:
 
1202
                // large texts as rectangles:
1174
1203
        if (e->rtti()==RS2::EntityText) {
1175
1204
            if (toGuiDX(((RS_Text*)e)->getHeight())<4 || e->countDeep()>100) {
1176
1205
                painter->drawRect(toGui(e->getMin()), toGui(e->getMax()));
1177
1206
            } else {
1178
1207
                drawEntityPlain(painter, e, patternOffset);
1179
1208
            }
1180
 
                } 
1181
 
                
1182
 
                // all images as rectangles:
1183
 
                else if (e->rtti()==RS2::EntityImage) {
 
1209
                }
 
1210
 
 
1211
                // all images as rectangles:
 
1212
                else if (e->rtti()==RS2::EntityImage) {
1184
1213
            painter->drawRect(toGui(e->getMin()), toGui(e->getMax()));
1185
 
        } 
1186
 
                
1187
 
                // hide hatches:
1188
 
                else if (e->rtti()==RS2::EntityHatch) {
 
1214
        }
 
1215
 
 
1216
                // hide hatches:
 
1217
                else if (e->rtti()==RS2::EntityHatch) {
1189
1218
            // nothing
1190
1219
        }
1191
1220
 
1202
1231
            RS_VectorSolutions s = e->getRefPoints();
1203
1232
 
1204
1233
            for (int i=0; i<s.getNumber(); ++i) {
1205
 
                                int sz = -1;
1206
 
                                RS_Color col = RS_Color(0,0,255);
1207
 
                                if (e->rtti()==RS2::EntityPolyline) {
1208
 
                                        if (i==0 || i==s.getNumber()-1) {
1209
 
                                                if (i==0) {
1210
 
                                                        sz = 4;
1211
 
                                                        col = QColor(0,64,255);
1212
 
                                                }
1213
 
                                                else {
1214
 
                                                        sz = 3;
1215
 
                                                        col = QColor(0,0,128);
1216
 
                                                }
1217
 
                                        }
1218
 
                                }
 
1234
                                int sz = -1;
 
1235
                                RS_Color col = RS_Color(0,0,255);
 
1236
                                if (e->rtti()==RS2::EntityPolyline) {
 
1237
                                        if (i==0 || i==s.getNumber()-1) {
 
1238
                                                if (i==0) {
 
1239
                                                        sz = 4;
 
1240
                                                        col = QColor(0,64,255);
 
1241
                                                }
 
1242
                                                else {
 
1243
                                                        sz = 3;
 
1244
                                                        col = QColor(0,0,128);
 
1245
                                                }
 
1246
                                        }
 
1247
                                }
1219
1248
                if (getDeleteMode()) {
1220
1249
                    painter->drawHandle(toGui(s.get(i)), background, sz);
1221
1250
                } else {
1233
1262
 
1234
1263
 
1235
1264
/**
1236
 
 * Draws an entity. 
 
1265
 * Draws an entity.
1237
1266
 * The painter must be initialized and all the attributes (pen) must be set.
1238
1267
 */
1239
1268
void RS_GraphicView::drawEntityPlain(RS_Painter *painter, RS_Entity* e, double patternOffset) {
1250
1279
}
1251
1280
 
1252
1281
/**
1253
 
 * Deletes an entity with the background color. 
 
1282
 * Deletes an entity with the background color.
1254
1283
 * Might be recusively called e.g. for polylines.
1255
1284
 */
1256
1285
void RS_GraphicView::deleteEntity(RS_Entity* e) {
1257
 
        
1258
 
        // RVT_PORT When we delete a single entoty, we can do this but we need to remove this then also from containerEntities
1259
 
        RS_DEBUG->print("RS_GraphicView::deleteEntity will for now redraw the whole screen instead of just deleting the entity");
1260
 
        setDeleteMode(true);
 
1286
 
 
1287
        // RVT_PORT When we delete a single entoty, we can do this but we need to remove this then also from containerEntities
 
1288
        RS_DEBUG->print("RS_GraphicView::deleteEntity will for now redraw the whole screen instead of just deleting the entity");
 
1289
        setDeleteMode(true);
1261
1290
    drawEntity(e);
1262
 
        setDeleteMode(false);
1263
 
        redraw(RS2::RedrawDrawing);
 
1291
        setDeleteMode(false);
 
1292
        redraw(RS2::RedrawDrawing);
1264
1293
}
1265
1294
 
1266
1295
 
1351
1380
 
1352
1381
 
1353
1382
/**
1354
 
 * This virtual method can be overwritten to draw the absolute 
 
1383
 * This virtual method can be overwritten to draw the absolute
1355
1384
 * zero. It's called from within drawIt(). The default implemetation
1356
1385
 * draws a simple red cross on the zero of thge sheet
1357
1386
 * THis function can ONLY be called from within a paintEvent because it will
1358
1387
 * use the painter
1359
 
 * 
 
1388
 *
1360
1389
 * @see drawIt()
1361
1390
 */
1362
1391
void RS_GraphicView::drawAbsoluteZero(RS_Painter *painter) {
1363
 
        
 
1392
 
1364
1393
    int zr = 20;
1365
1394
 
1366
 
        RS_Pen p(QColor(255,0,0), RS2::Width00, RS2::SolidLine);
1367
 
        p.setScreenWidth(0);
 
1395
        RS_Pen p(QColor(255,0,0), RS2::Width00, RS2::SolidLine);
 
1396
        p.setScreenWidth(0);
1368
1397
    painter->setPen(p);
1369
1398
    //painter->setBrush(Qt::NoBrush);
1370
1399
 
1383
1412
 
1384
1413
 
1385
1414
/**
1386
 
 * This virtual method can be overwritten to draw the relative 
 
1415
 * This virtual method can be overwritten to draw the relative
1387
1416
 * zero point. It's called from within drawIt(). The default implemetation
1388
1417
 * draws a simple red round zero point. This is the point that was last created by the user, end of a line for example
1389
1418
 * THis function can ONLY be called from within a paintEvent because it will
1396
1425
    if (relativeZero.valid==false) {
1397
1426
        return;
1398
1427
    }
1399
 
        
1400
 
        RS_Pen p(RS_Color(255, 0, 0), RS2::Width00, RS2::SolidLine);
1401
 
        p.setScreenWidth(0);
 
1428
 
 
1429
        RS_Pen p(RS_Color(255, 0, 0), RS2::Width00, RS2::SolidLine);
 
1430
        p.setScreenWidth(0);
1402
1431
    painter->setPen(p);
1403
1432
 
1404
1433
    int zr=5;
1422
1451
 * Draws the paper border (for print previews).
1423
1452
 * This function can ONLY be called from within a paintEvent because it will
1424
1453
 * use the painter
1425
 
 * 
 
1454
 *
1426
1455
 * @see drawIt()
1427
1456
 */
1428
1457
void RS_GraphicView::drawPaper(RS_Painter *painter) {
1430
1459
    if (container==NULL) {
1431
1460
        return;
1432
1461
    }
1433
 
        
1434
 
        RS_Graphic* graphic = container->getGraphic();
 
1462
 
 
1463
        RS_Graphic* graphic = container->getGraphic();
1435
1464
    if (graphic->getPaperScale()<1.0e-6) {
1436
1465
        return;
1437
1466
    }
1438
1467
 
1439
1468
    // draw paper:
1440
 
        // RVT_PORT rewritten from     painter->setPen(Qt::gray);
 
1469
        // RVT_PORT rewritten from     painter->setPen(Qt::gray);
1441
1470
    painter->setPen(QColor(Qt::gray));
1442
1471
 
1443
1472
    RS_Vector pinsbase = graphic->getPaperInsertionBase();
1475
1504
/**
1476
1505
 * Draws the grid.
1477
1506
 *
1478
 
 * @see drawIt() 
 
1507
 * @see drawIt()
1479
1508
 */
1480
1509
void RS_GraphicView::drawGrid(RS_Painter *painter) {
1481
1510
 
1482
1511
    if (grid==NULL || isGridOn()==false) {
1483
1512
        return;
1484
1513
    }
1485
 
        
1486
 
        
 
1514
 
 
1515
 
1487
1516
    // draw grid:
1488
1517
    //painter->setPen(Qt::gray);
1489
1518
    painter->setPen(gridColor);
1490
1519
 
1491
 
        grid->updatePointArray();
 
1520
//      grid->updatePointArray();
1492
1521
    RS_Vector* pts = grid->getPoints();
1493
1522
    if (pts!=NULL) {
1494
1523
        for (int i=0; i<grid->count(); ++i) {
1520
1549
    if (grid==NULL || isGridOn()==false /*|| grid->getMetaSpacing()<0.0*/) {
1521
1550
        return;
1522
1551
    }
1523
 
        
 
1552
 
1524
1553
    RS_Pen pen(metaGridColor,
1525
1554
               RS2::Width00,
1526
1555
               RS2::DotLine);
1527
1556
    painter->setPen(pen);
1528
1557
 
1529
1558
    // draw meta grid:
 
1559
    grid->updatePointArray();
1530
1560
    double* mx = grid->getMetaX();
1531
1561
    if (mx!=NULL) {
1532
1562
        for (int i=0; i<grid->countMetaX(); ++i) {
1546
1576
}
1547
1577
 
1548
1578
void RS_GraphicView::drawOverlay(RS_Painter *painter) {
1549
 
        QList<int> keys=overlayEntities.keys();
1550
 
        for (int i = 0; i < keys.size(); ++i) {
1551
 
                if (overlayEntities[i] != NULL) {
1552
 
                        setPenForEntity(painter, overlayEntities[i] );
1553
 
                        drawEntityPlain(painter, overlayEntities[i], 0.0);
1554
 
                }
1555
 
        }
 
1579
        QList<int> keys=overlayEntities.keys();
 
1580
        for (int i = 0; i < keys.size(); ++i) {
 
1581
                if (overlayEntities[i] != NULL) {
 
1582
                        setPenForEntity(painter, overlayEntities[i] );
 
1583
                        drawEntityPlain(painter, overlayEntities[i], 0.0);
 
1584
                }
 
1585
        }
1556
1586
}
1557
1587
 
1558
1588
/**
1699
1729
 */
1700
1730
void RS_GraphicView::moveRelativeZero(const RS_Vector& pos) {
1701
1731
    setRelativeZero(pos);
1702
 
        redraw(RS2::RedrawGrid);
 
1732
        redraw(RS2::RedrawGrid);
1703
1733
}
1704
1734
 
1705
1735
 
1706
1736
/**
1707
1737
 * Remove all overlay entities
1708
 
 */ 
 
1738
 */
1709
1739
RS_EntityContainer* RS_GraphicView::getOverlayContainer(RS2::OverlayGraphics position)
1710
1740
{
1711
 
        if (overlayEntities[position]!=NULL) {
1712
 
                return overlayEntities[position];
1713
 
        } 
1714
 
        overlayEntities[position]=new RS_EntityContainer(NULL);
1715
 
        
1716
 
        return overlayEntities[position];
 
1741
        if (overlayEntities[position]!=NULL) {
 
1742
                return overlayEntities[position];
 
1743
        }
 
1744
        overlayEntities[position]=new RS_EntityContainer(NULL);
 
1745
 
 
1746
        return overlayEntities[position];
1717
1747
 
1718
1748
}
1719
1749