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