source: projectionDesigner/trunk/projdesignerplugins/defaultplugin/DefaultTeapotSceneContent.cpp @ 322

Last change on this file since 322 was 4, checked in by Torben Dannhauer, 15 years ago
File size: 3.3 KB
Line 
1#include "DefaultTeapotSceneContent.h"
2
3
4const QString DefaultTeapotSceneContent::g_scene_name=QObject::tr("Teapot");
5
6
7/**
8 * Default constructor
9 *
10 */
11DefaultTeapotSceneContent::DefaultTeapotSceneContent(SceneInterface* plugin):
12    SceneContent(plugin),
13    m_bWireframe(true),
14    m_iWidth(1)
15{
16}
17
18
19/**
20 * Destructor.
21 *
22 */
23DefaultTeapotSceneContent::~DefaultTeapotSceneContent()
24{
25}
26
27
28/**
29 * Implements the copy from other contents.
30 *
31 * This method is used by the copy constructor.
32 *
33 * @param content The source content to copy from.
34 *
35 * @return true if the copy is ok, false otherwise. The copy can fail if
36 *         SceneContent is not a DefaultTeapotSceneContent.
37 *
38 * @seealso is_equal_to
39 *
40 */
41bool DefaultTeapotSceneContent::copy_from(const SceneContent& data) 
42{
43    if (!SceneContent::copy_from(data)) return false;
44    Q_ASSERT(NULL!=plugin());
45    Q_ASSERT(NULL!=data.plugin());
46    const DefaultTeapotSceneContent& _data = static_cast<const DefaultTeapotSceneContent&>(data);
47    m_bWireframe = _data.m_bWireframe;
48    m_iWidth     = _data.m_iWidth;
49    return true;
50}
51
52
53/**
54 * Implements the egality-test with other contents.
55 *
56 * This could be an operator==.
57 *
58 * @param content The content to compare with.
59 *
60 * @return true if the content are equal, false otherwise. The test can
61 *         fail if the contents have different parameters, but also it
62 *         SceneContent is not a DefaultTeapotSceneContent.
63 *
64 * @seealso copy_from
65 *
66 */
67bool DefaultTeapotSceneContent::is_equal_to(const SceneContent& data) const
68{
69    if (!SceneContent::is_equal_to(data)) return false;
70    const DefaultTeapotSceneContent& _data = static_cast<const DefaultTeapotSceneContent&>(data);
71    if (m_bWireframe)
72    {
73        return m_bWireframe==_data.m_bWireframe
74            && m_iWidth==_data.m_iWidth;
75    }
76    else
77    {
78        return m_bWireframe==_data.m_bWireframe;
79    }
80}
81
82
83/**
84 * Draws the teapot.
85 *
86 * @param glWidget The QGLWidget that own the OpenGL context.
87 * @param cameraMatrix The camera matrix that must be use.
88 *
89 */
90void DefaultTeapotSceneContent::draw(QGLWidget *glWidget, const float* cameraMatrix)
91{
92    Q_UNUSED (glWidget);
93    Q_UNUSED(cameraMatrix);
94    glPushAttrib(GL_ENABLE_BIT);
95    glDisable(GL_TEXTURE_2D);
96    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
97    glPushMatrix();
98    if (!m_bWireframe)
99    {
100        glutSolidTeapot(0.25);
101    }
102    else
103    {
104        glLineWidth(m_iWidth);
105        glutWireTeapot(0.25);
106    }
107    glPopMatrix();
108    glPopAttrib();
109}
110
111
112/**
113 * Loads the teapot from a QDomElement.
114 *
115 * @param element The QDomElement to read from.
116 *
117 */
118void DefaultTeapotSceneContent::initFromDOMElement(const QDomElement& element)
119{
120    if (!element.isNull())
121    {
122        m_bWireframe=element.attribute("wireframe").toLower()=="true";
123        m_iWidth=element.attribute("width").toInt(); // <-- 0 if not present
124        SceneContent::initFromDOMElement(element);
125    }
126}
127
128
129/**
130 * Writes the teapot in a QDomDocument.
131 *
132 * @param name The name of the element.
133 * @param doc The document whom belongs the element.
134 *
135 * @return The QDomElement to add.
136 *
137 */
138QDomElement DefaultTeapotSceneContent::domElement(const QString& name, QDomDocument& doc) const
139{
140    QDomElement de = SceneContent::domElement(name, doc);
141    de.setAttribute("wireframe", (m_bWireframe)?"true":"false");
142    de.setAttribute("width",     m_iWidth);
143    return de;
144}
145
Note: See TracBrowser for help on using the repository browser.