glc_3dwidget.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002 
00003  This file is part of the GLC-lib library.
00004  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
00005  http://glc-lib.sourceforge.net
00006 
00007  GLC-lib is free software; you can redistribute it and/or modify
00008  it under the terms of the GNU Lesser General Public License as published by
00009  the Free Software Foundation; either version 3 of the License, or
00010  (at your option) any later version.
00011 
00012  GLC-lib is distributed in the hope that it will be useful,
00013  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  GNU Lesser General Public License for more details.
00016 
00017  You should have received a copy of the GNU Lesser General Public License
00018  along with GLC-lib; if not, write to the Free Software
00019  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00020 
00021  *****************************************************************************/
00023 
00024 #include "glc_3dwidget.h"
00025 
00026 
00027 GLC_3DWidget::GLC_3DWidget(GLC_3DWidgetManagerHandle*  pWidgetManagerHandle)
00028 : QObject()
00029 , m_Uid(glc::GLC_Gen3DWidgetID())
00030 , m_pWidgetManagerHandle(pWidgetManagerHandle)
00031 , m_InstanceIdList()
00032 {
00033 
00034 }
00035 
00036 GLC_3DWidget::GLC_3DWidget(const GLC_3DWidget& widget)
00037 : QObject()
00038 , m_Uid(glc::GLC_Gen3DWidgetID())
00039 , m_pWidgetManagerHandle(widget.m_pWidgetManagerHandle)
00040 , m_InstanceIdList()
00041 {
00042         // Copy the 3Dview instance of the widget
00043         const int size= widget.m_InstanceIdList.size();
00044         for (int i= 0; i < size; ++i)
00045         {
00046                 GLC_3DViewInstance newInstance(widget.m_pWidgetManagerHandle->instanceHandle(widget.m_InstanceIdList.at(i))->deepCopy());
00047                 GLC_uint newId= newInstance.id();
00048                 m_InstanceIdList.append(newId);
00049                 m_pWidgetManagerHandle->add3DViewInstance(newInstance, m_Uid);
00050         }
00051 }
00052 
00053 GLC_3DWidget::~GLC_3DWidget()
00054 {
00055         remove3DViewInstance();
00056 }
00057 
00058 bool GLC_3DWidget::operator==(const GLC_3DWidget& widget) const
00059 {
00060         return this == &widget;
00061 }
00062 
00063 GLC_3DWidget& GLC_3DWidget::operator=(const GLC_3DWidget& widget)
00064 {
00065         if (this != &widget)
00066         {
00067                 remove3DViewInstance();
00068 
00069                 m_Uid= widget.m_Uid;
00070                 m_pWidgetManagerHandle= widget.m_pWidgetManagerHandle;
00071                 m_InstanceIdList= widget.m_InstanceIdList;
00072 
00073                 // Copy the 3Dview instance of the widget
00074                 const int size= widget.m_InstanceIdList.size();
00075                 for (int i= 0; i < size; ++i)
00076                 {
00077                         GLC_3DViewInstance newInstance(widget.m_pWidgetManagerHandle->instanceHandle(widget.m_InstanceIdList.at(i))->deepCopy());
00078                         GLC_uint newId= newInstance.id();
00079                         m_InstanceIdList.append(newId);
00080                         m_pWidgetManagerHandle->add3DViewInstance(newInstance, m_Uid);
00081                 }
00082         }
00083         return *this;
00084 }
00085 
00086 void GLC_3DWidget::setWidgetManager(GLC_3DWidgetManagerHandle* pWidgetManagerHandle)
00087 {
00088         if (NULL != m_pWidgetManagerHandle)
00089         {
00090                 m_pWidgetManagerHandle->take(m_Uid);
00091                 remove3DViewInstance();
00092         }
00093         m_pWidgetManagerHandle= pWidgetManagerHandle;
00094 
00095         create3DviewInstance();
00096 }
00097 
00098 void GLC_3DWidget::setVisible(bool visible)
00099 {
00100         if (NULL != m_pWidgetManagerHandle)
00101         {
00102                 const int instanceCount= m_InstanceIdList.size();
00103                 for (int i= 0; i < instanceCount; ++i)
00104                 {
00105                         m_pWidgetManagerHandle->instanceHandle(m_InstanceIdList.at(i))->setVisibility(visible);
00106                 }
00107                 resetViewState();
00108         }
00109 }
00111 // Interaction Functions
00113 glc::WidgetEventFlag GLC_3DWidget::select(const GLC_Point3d&, GLC_uint)
00114 {
00115         return glc::IgnoreEvent;
00116 }
00117 
00118 glc::WidgetEventFlag GLC_3DWidget::unselect(const GLC_Point3d&, GLC_uint)
00119 {
00120         return glc::IgnoreEvent;
00121 }
00122 
00123 glc::WidgetEventFlag GLC_3DWidget::mouseOver(const GLC_Point3d&, GLC_uint)
00124 {
00125         return glc::IgnoreEvent;
00126 }
00127 
00128 glc::WidgetEventFlag GLC_3DWidget::mousePressed(const GLC_Point3d&, Qt::MouseButton, GLC_uint)
00129 {
00130         return glc::IgnoreEvent;
00131 }
00132 
00133 glc::WidgetEventFlag GLC_3DWidget::mouseReleased(Qt::MouseButton)
00134 {
00135         return glc::IgnoreEvent;
00136 }
00137 
00138 glc::WidgetEventFlag GLC_3DWidget::mouseMove(const GLC_Point3d&, Qt::MouseButtons, GLC_uint)
00139 {
00140         return glc::IgnoreEvent;
00141 }
00142 
00143 
00145 // Protected services functions
00147 void GLC_3DWidget::add3DViewInstance(const GLC_3DViewInstance& instance)
00148 {
00149         m_pWidgetManagerHandle->add3DViewInstance(instance, m_Uid);
00150         const GLC_uint instanceId= instance.id();
00151         m_InstanceIdList.append(instanceId);
00152 }
00153 
00154 void GLC_3DWidget::remove3DViewInstance()
00155 {
00156         if (NULL != m_pWidgetManagerHandle)
00157         {
00158                 const int size= m_InstanceIdList.size();
00159                 for (int i= 0; i < size; ++i)
00160                 {
00161                         m_pWidgetManagerHandle->remove3DViewInstance(m_InstanceIdList.at(i));
00162                 }
00163         }
00164 }
00165 
00166 void GLC_3DWidget::set3DViewInstanceVisibility(int index, bool visibility)
00167 {
00168         m_pWidgetManagerHandle->instanceHandle(m_InstanceIdList[index])->setVisibility(visibility);
00169 }
00170 
00171 

SourceForge.net Logo

©2005-2011 Laurent Ribon