Back to index

salome-gui  6.5.0
GLViewer_Group.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  Author : OPEN CASCADE
00024 // File:      GLViewer_Group.xx
00025 // Created:   March, 2005
00026 //#include "GLViewerAfx.h"
00027 //
00028 #include "GLViewer_Group.h"
00029 #include "GLViewer_Object.h"
00030 
00034 GLViewer_Group::GLViewer_Group()
00035 {
00036   mySelObjNum = 0;
00037 }
00038 
00042 GLViewer_Group::~GLViewer_Group()
00043 {  
00044 }
00045 
00049 bool GLViewer_Group::isEmpty()
00050 {
00051   return myList.empty(); 
00052 }
00053 
00057 int GLViewer_Group::count()
00058 {
00059   return myList.size();
00060 }
00061 
00065 int GLViewer_Group::contains( GLViewer_Object* theObject )
00066 {
00067   if( !theObject )
00068     return -1;
00069   
00070   OGIterator it = myList.begin();
00071   OGIterator end_it = myList.end();
00072   for( int i = 0; it != end_it; ++it, i++ )
00073     if( *it == theObject )
00074       return i;
00075 
00076   return -1;
00077 }
00078 
00082 int GLViewer_Group::addObject( GLViewer_Object* theObject )
00083 {
00084   if( theObject && contains( theObject ) == -1 )
00085   {
00086     myList.push_back( theObject );
00087     theObject->setGroup( this );
00088   }
00089   return count();
00090 }
00091 
00095 int GLViewer_Group::removeObject( GLViewer_Object* theObject )
00096 {
00097   if( theObject )
00098   {
00099     myList.remove( theObject );
00100     //theObject->setGroup( NULL );
00101   }
00102 
00103 
00104   if( isEmpty() )
00105   {
00106     this->~GLViewer_Group();
00107     return -1;
00108   }
00109   else
00110     return count();
00111 }
00112 
00118 void GLViewer_Group::dragingObjects( float x, float y, bool once )
00119 {
00120   if( !once )
00121   {
00122     if( !mySelObjNum )
00123     {
00124       OGIterator it = myList.begin();
00125       OGIterator end_it = myList.end();
00126       for( int i = 0; it != end_it; ++it, i++ )
00127         if( (*it)->isSelected() )
00128           mySelObjNum++;
00129 
00130       if( mySelObjNum )
00131         mySelObjNum--;
00132     }
00133     else
00134     {
00135       mySelObjNum--;
00136       return;
00137     }
00138   }
00139 
00140   OGIterator it = myList.begin();
00141   OGIterator end_it = myList.end();
00142   for( int i = 0; it != end_it; ++it, i++ )
00143     (*it)->moveObject( x, y, true );  
00144 }
00145 
00151 void GLViewer_Group::updateZoom( GLViewer_Object* sender, float zoom )
00152 {
00153   OGIterator it = myList.begin();
00154   OGIterator end_it = myList.end();
00155   for( int i = 0; it != end_it; ++it, i++ )
00156   {
00157     GLViewer_Object* anObject = *it;
00158     if( anObject != sender )
00159       anObject->setZoom( zoom, true, true );
00160   }
00161 }