Salome HOME
Update from BR_V5_DEV 13Feb2009
[modules/gui.git] / src / GLViewer / GLViewer_Group.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
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 GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  Author : OPEN CASCADE
23 // File:      GLViewer_Group.xx
24 // Created:   March, 2005
25 //#include "GLViewerAfx.h"
26 //
27 #include "GLViewer_Group.h"
28 #include "GLViewer_Object.h"
29
30 /*!
31   constructor
32 */
33 GLViewer_Group::GLViewer_Group()
34 {
35   mySelObjNum = 0;
36 }
37
38 /*!
39   destructor
40 */
41 GLViewer_Group::~GLViewer_Group()
42 {  
43 }
44
45 /*!
46   detection of empty group
47 */
48 bool GLViewer_Group::isEmpty()
49 {
50   return myList.empty(); 
51 }
52
53 /*!
54   \return number of elements
55 */
56 int GLViewer_Group::count()
57 {
58   return myList.size();
59 }
60
61 /*!
62   \return the position of object if group contains it, else -1
63 */
64 int GLViewer_Group::contains( GLViewer_Object* theObject )
65 {
66   if( !theObject )
67     return -1;
68   
69   OGIterator it = myList.begin();
70   OGIterator end_it = myList.end();
71   for( int i = 0; it != end_it; ++it, i++ )
72     if( *it == theObject )
73       return i;
74
75   return -1;
76 }
77
78 /*!
79   adding object to group
80 */
81 int GLViewer_Group::addObject( GLViewer_Object* theObject )
82 {
83   if( theObject && contains( theObject ) == -1 )
84   {
85     myList.push_back( theObject );
86     theObject->setGroup( this );
87   }
88   return count();
89 }
90
91 /*!
92   removing object from group
93 */
94 int GLViewer_Group::removeObject( GLViewer_Object* theObject )
95 {
96   if( theObject )
97   {
98     myList.remove( theObject );
99     //theObject->setGroup( NULL );
100   }
101
102
103   if( isEmpty() )
104   {
105     this->~GLViewer_Group();
106     return -1;
107   }
108   else
109     return count();
110 }
111
112 /*!
113   Dragging operation
114   \param Once is true, if this operation calls only one time for all object
115   \param x, y - dragging position
116 */
117 void GLViewer_Group::dragingObjects( float x, float y, bool once )
118 {
119   if( !once )
120   {
121     if( !mySelObjNum )
122     {
123       OGIterator it = myList.begin();
124       OGIterator end_it = myList.end();
125       for( int i = 0; it != end_it; ++it, i++ )
126         if( (*it)->isSelected() )
127           mySelObjNum++;
128
129       if( mySelObjNum )
130         mySelObjNum--;
131     }
132     else
133     {
134       mySelObjNum--;
135       return;
136     }
137   }
138
139   OGIterator it = myList.begin();
140   OGIterator end_it = myList.end();
141   for( int i = 0; it != end_it; ++it, i++ )
142     (*it)->moveObject( x, y, true );  
143 }
144
145 /*!
146   Updates zoom of object
147   \param sender - object to be updated
148   \param zoom - zoom coefficient
149 */
150 void GLViewer_Group::updateZoom( GLViewer_Object* sender, float zoom )
151 {
152   OGIterator it = myList.begin();
153   OGIterator end_it = myList.end();
154   for( int i = 0; it != end_it; ++it, i++ )
155   {
156     GLViewer_Object* anObject = *it;
157     if( anObject != sender )
158       anObject->setZoom( zoom, true, true );
159   }
160 }