#include "DefaultTeapotSceneContent.h" const QString DefaultTeapotSceneContent::g_scene_name=QObject::tr("Teapot"); /** * Default constructor * */ DefaultTeapotSceneContent::DefaultTeapotSceneContent(SceneInterface* plugin): SceneContent(plugin), m_bWireframe(true), m_iWidth(1) { } /** * Destructor. * */ DefaultTeapotSceneContent::~DefaultTeapotSceneContent() { } /** * Implements the copy from other contents. * * This method is used by the copy constructor. * * @param content The source content to copy from. * * @return true if the copy is ok, false otherwise. The copy can fail if * SceneContent is not a DefaultTeapotSceneContent. * * @seealso is_equal_to * */ bool DefaultTeapotSceneContent::copy_from(const SceneContent& data) { if (!SceneContent::copy_from(data)) return false; Q_ASSERT(NULL!=plugin()); Q_ASSERT(NULL!=data.plugin()); const DefaultTeapotSceneContent& _data = static_cast(data); m_bWireframe = _data.m_bWireframe; m_iWidth = _data.m_iWidth; return true; } /** * Implements the egality-test with other contents. * * This could be an operator==. * * @param content The content to compare with. * * @return true if the content are equal, false otherwise. The test can * fail if the contents have different parameters, but also it * SceneContent is not a DefaultTeapotSceneContent. * * @seealso copy_from * */ bool DefaultTeapotSceneContent::is_equal_to(const SceneContent& data) const { if (!SceneContent::is_equal_to(data)) return false; const DefaultTeapotSceneContent& _data = static_cast(data); if (m_bWireframe) { return m_bWireframe==_data.m_bWireframe && m_iWidth==_data.m_iWidth; } else { return m_bWireframe==_data.m_bWireframe; } } /** * Draws the teapot. * * @param glWidget The QGLWidget that own the OpenGL context. * @param cameraMatrix The camera matrix that must be use. * */ void DefaultTeapotSceneContent::draw(QGLWidget *glWidget, const float* cameraMatrix) { Q_UNUSED (glWidget); Q_UNUSED(cameraMatrix); glPushAttrib(GL_ENABLE_BIT); glDisable(GL_TEXTURE_2D); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glPushMatrix(); if (!m_bWireframe) { glutSolidTeapot(0.25); } else { glLineWidth(m_iWidth); glutWireTeapot(0.25); } glPopMatrix(); glPopAttrib(); } /** * Loads the teapot from a QDomElement. * * @param element The QDomElement to read from. * */ void DefaultTeapotSceneContent::initFromDOMElement(const QDomElement& element) { if (!element.isNull()) { m_bWireframe=element.attribute("wireframe").toLower()=="true"; m_iWidth=element.attribute("width").toInt(); // <-- 0 if not present SceneContent::initFromDOMElement(element); } } /** * Writes the teapot in a QDomDocument. * * @param name The name of the element. * @param doc The document whom belongs the element. * * @return The QDomElement to add. * */ QDomElement DefaultTeapotSceneContent::domElement(const QString& name, QDomDocument& doc) const { QDomElement de = SceneContent::domElement(name, doc); de.setAttribute("wireframe", (m_bWireframe)?"true":"false"); de.setAttribute("width", m_iWidth); return de; }