Salome HOME
6377e9ecda81c079f40a8e93b1d0760f31ddb0b5
[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 **  Class:   GLViewer_Group
31 **  Descr:   Group of GLViewer_Objects
32 **  Module:  GLViewer
33 **  Created: UI team, 25.03.05
34 ****************************************************************************/
35
36 //--------------------------------------------------------------------------
37 //Function: GLViewer_Group()
38 //Description: constructor
39 //--------------------------------------------------------------------------
40 GLViewer_Group::GLViewer_Group()
41 {
42   mySelObjNum = 0;
43 }
44
45 //--------------------------------------------------------------------------
46 //Function: GLViewer_Group()
47 //Description: destructor
48 //--------------------------------------------------------------------------
49 GLViewer_Group::~GLViewer_Group()
50 {  
51 }
52
53 //--------------------------------------------------------------------------
54 //Function: isEmpty
55 //Description: detection of empty group
56 //--------------------------------------------------------------------------
57 bool GLViewer_Group::isEmpty()
58 {
59   return myList.empty(); 
60 }
61
62 //--------------------------------------------------------------------------
63 //Function: count
64 //Description: number of elements
65 //--------------------------------------------------------------------------
66 int GLViewer_Group::count()
67 {
68   return myList.size();
69 }
70
71 //--------------------------------------------------------------------------
72 //Function: contains
73 //Description: return the position of object, else -1
74 //--------------------------------------------------------------------------
75 int GLViewer_Group::contains( GLViewer_Object* theObject )
76 {
77   if( !theObject )
78     return -1;
79   
80   OGIterator it = myList.begin();
81   OGIterator end_it = myList.end();
82   for( int i = 0; it != end_it; ++it, i++ )
83     if( *it == theObject )
84       return i;
85
86   return -1;
87 }
88
89 //--------------------------------------------------------------------------
90 //Function: addObject
91 //Description: adding object to group
92 //--------------------------------------------------------------------------
93 int GLViewer_Group::addObject( GLViewer_Object* theObject )
94 {
95   if( theObject && contains( theObject ) == -1 )
96   {
97     myList.push_back( theObject );
98     theObject->setGroup( this );
99   }
100   return count();
101 }
102
103 //--------------------------------------------------------------------------
104 //Function: removeObject
105 //Description: removing object from group
106 //--------------------------------------------------------------------------
107 int GLViewer_Group::removeObject( GLViewer_Object* theObject )
108 {
109   if( theObject )
110   {
111     myList.remove( theObject );
112     //theObject->setGroup( NULL );
113   }
114
115
116   if( isEmpty() )
117   {
118     this->~GLViewer_Group();
119     return -1;
120   }
121   else
122     return count();
123 }
124
125 //--------------------------------------------------------------------------
126 //Function: dragingObjects
127 //Description: 
128 //--------------------------------------------------------------------------
129 void GLViewer_Group::dragingObjects( float x, float y, bool once )
130 {
131   if( !once )
132   {
133     if( !mySelObjNum )
134     {
135       OGIterator it = myList.begin();
136       OGIterator end_it = myList.end();
137       for( int i = 0; it != end_it; ++it, i++ )
138         if( (*it)->isSelected() )
139           mySelObjNum++;
140
141       if( mySelObjNum )
142         mySelObjNum--;
143     }
144     else
145     {
146       mySelObjNum--;
147       return;
148     }
149   }
150
151   OGIterator it = myList.begin();
152   OGIterator end_it = myList.end();
153   for( int i = 0; it != end_it; ++it, i++ )
154     (*it)->moveObject( x, y, true );  
155 }
156
157 //--------------------------------------------------------------------------
158 //Function: updateZoom
159 //Description: 
160 //--------------------------------------------------------------------------
161 void GLViewer_Group::updateZoom( GLViewer_Object* sender, float zoom )
162 {
163   OGIterator it = myList.begin();
164   OGIterator end_it = myList.end();
165   for( int i = 0; it != end_it; ++it, i++ )
166   {
167     GLViewer_Object* anObject = *it;
168     if( anObject != sender )
169       anObject->setZoom( zoom, true, true );
170   }
171 }