FreeCAD

Форк
0
/
QGIDrawingTemplate.cpp 
116 строк · 3.8 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2012-2014 Luke Parry <l.parry@warwick.ac.uk>            *
3
 *                                                                         *
4
 *   This file is part of the FreeCAD CAx development system.              *
5
 *                                                                         *
6
 *   This library is free software; you can redistribute it and/or         *
7
 *   modify it under the terms of the GNU Library General Public           *
8
 *   License as published by the Free Software Foundation; either          *
9
 *   version 2 of the License, or (at your option) any later version.      *
10
 *                                                                         *
11
 *   This library  is distributed in the hope that it will be useful,      *
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14
 *   GNU Library General Public License for more details.                  *
15
 *                                                                         *
16
 *   You should have received a copy of the GNU Library General Public     *
17
 *   License along with this library; see the file COPYING.LIB. If not,    *
18
 *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
19
 *   Suite 330, Boston, MA  02111-1307, USA                                *
20
 *                                                                         *
21
 ***************************************************************************/
22

23
#include "PreCompiled.h"
24
#ifndef _PreComp_
25
# include <QPainterPath>
26
#endif
27

28
#include <Mod/TechDraw/App/Geometry.h>
29
#include <Mod/TechDraw/App/DrawParametricTemplate.h>
30

31
#include "QGIDrawingTemplate.h"
32

33

34
using namespace TechDrawGui;
35

36
QGIDrawingTemplate::QGIDrawingTemplate(QGSPage* scene) : QGITemplate(scene),
37
                                                                                    pathItem(nullptr)
38
{
39
    pathItem = new QGraphicsPathItem;
40

41
    // Invert the Y for the QGraphicsPathItem with Y pointing upwards
42
    QTransform qtrans;
43
    qtrans.scale(1., -1.);
44

45
    pathItem->setTransform(qtrans);
46

47
    addToGroup(pathItem);
48
}
49

50
QGIDrawingTemplate::~QGIDrawingTemplate()
51
{
52
    pathItem = nullptr;
53
}
54

55
void QGIDrawingTemplate::clearContents()
56
{
57

58
}
59

60
TechDraw::DrawParametricTemplate * QGIDrawingTemplate::getParametricTemplate()
61
{
62
    if(pageTemplate && pageTemplate->isDerivedFrom(TechDraw::DrawParametricTemplate::getClassTypeId()))
63
        return static_cast<TechDraw::DrawParametricTemplate *>(pageTemplate);
64
    else
65
        return nullptr;
66
}
67

68
void QGIDrawingTemplate::draw()
69
{
70

71
    TechDraw::DrawParametricTemplate *tmplte = getParametricTemplate();
72
    if(!tmplte) {
73
        throw Base::RuntimeError("Template Feuature not set for QGIDrawingTemplate");
74
    }
75

76

77
    // Clear the previous geometry stored
78

79
    // Get a list of geometry and iterate
80
    const TechDraw::BaseGeomPtrVector &geoms =  tmplte->getGeometry();
81

82
    TechDraw::BaseGeomPtrVector::const_iterator it = geoms.begin();
83

84
    QPainterPath path;
85

86
    // Draw Edges
87
    // iterate through all the geometries
88
    for(; it != geoms.end(); ++it) {
89
        switch((*it)->getGeomType()) {
90
          case TechDraw::GENERIC: {
91

92
            TechDraw::GenericPtr geom = std::static_pointer_cast<TechDraw::Generic>(*it);
93

94
            path.moveTo(geom->points[0].x, geom->points[0].y);
95
            std::vector<Base::Vector3d>::const_iterator it = geom->points.begin();
96

97
            for(++it; it != geom->points.end(); ++it) {
98
                path.lineTo((*it).x, (*it).y);
99
            }
100
            break;
101
          }
102
          default:
103
            break;
104
        }
105
    }
106

107
    pathItem->setPath(path);
108
}
109

110
void QGIDrawingTemplate::updateView(bool update)
111
{
112
    Q_UNUSED(update);
113
    draw();
114
}
115

116
#include <Mod/TechDraw/Gui/moc_QGIDrawingTemplate.cpp>
117

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.