Salome HOME
new files added
[modules/gui.git] / src / GLViewer / GLViewer_Group.cxx
1 // File:      GLViewer_Group.xx
2 // Created:   March, 2005
3 // Author:    OCC team
4 // Copyright (C) CEA 2005
5
6 //#include "GLViewerAfx.h"
7 #include "GLViewer_Group.h"
8 #include "GLViewer_Object.h"
9
10 /***************************************************************************
11 **  Class:   GLViewer_Group
12 **  Descr:   Group of GLViewer_Objects
13 **  Module:  GLViewer
14 **  Created: UI team, 25.03.05
15 ****************************************************************************/
16
17 //--------------------------------------------------------------------------
18 //Function: GLViewer_Group()
19 //Description: constructor
20 //--------------------------------------------------------------------------
21 GLViewer_Group::GLViewer_Group()
22 {
23   mySelObjNum = 0;
24 }
25
26 //--------------------------------------------------------------------------
27 //Function: GLViewer_Group()
28 //Description: destructor
29 //--------------------------------------------------------------------------
30 GLViewer_Group::~GLViewer_Group()
31 {  
32 }
33
34 //--------------------------------------------------------------------------
35 //Function: isEmpty
36 //Description: detection of empty group
37 //--------------------------------------------------------------------------
38 bool GLViewer_Group::isEmpty()
39 {
40   return myList.empty(); 
41 }
42
43 //--------------------------------------------------------------------------
44 //Function: count
45 //Description: number of elements
46 //--------------------------------------------------------------------------
47 int GLViewer_Group::count()
48 {
49   return myList.size();
50 }
51
52 //--------------------------------------------------------------------------
53 //Function: contains
54 //Description: return the position of object, else -1
55 //--------------------------------------------------------------------------
56 int GLViewer_Group::contains( GLViewer_Object* theObject )
57 {
58   if( !theObject )
59     return -1;
60   
61   OGIterator it = myList.begin();
62   OGIterator end_it = myList.end();
63   for( int i = 0; it != end_it; ++it, i++ )
64     if( *it == theObject )
65       return i;
66
67   return -1;
68 }
69
70 //--------------------------------------------------------------------------
71 //Function: addObject
72 //Description: adding object to group
73 //--------------------------------------------------------------------------
74 int GLViewer_Group::addObject( GLViewer_Object* theObject )
75 {
76   if( theObject && contains( theObject ) == -1 )
77   {
78     myList.push_back( theObject );
79     theObject->setGroup( this );
80   }
81   return count();
82 }
83
84 //--------------------------------------------------------------------------
85 //Function: removeObject
86 //Description: removing object from group
87 //--------------------------------------------------------------------------
88 int GLViewer_Group::removeObject( GLViewer_Object* theObject )
89 {
90   if( theObject )
91   {
92     myList.remove( theObject );
93     //theObject->setGroup( NULL );
94   }
95
96
97   if( isEmpty() )
98   {
99     this->~GLViewer_Group();
100     return -1;
101   }
102   else
103     return count();
104 }
105
106 //--------------------------------------------------------------------------
107 //Function: dragingObjects
108 //Description: 
109 //--------------------------------------------------------------------------
110 void GLViewer_Group::dragingObjects( float x, float y, bool once )
111 {
112   if( !once )
113   {
114     if( !mySelObjNum )
115     {
116       OGIterator it = myList.begin();
117       OGIterator end_it = myList.end();
118       for( int i = 0; it != end_it; ++it, i++ )
119         if( (*it)->isSelected() )
120           mySelObjNum++;
121
122       if( mySelObjNum )
123         mySelObjNum--;
124     }
125     else
126     {
127       mySelObjNum--;
128       return;
129     }
130   }
131
132   OGIterator it = myList.begin();
133   OGIterator end_it = myList.end();
134   for( int i = 0; it != end_it; ++it, i++ )
135     (*it)->moveObject( x, y, true );  
136 }
137
138 //--------------------------------------------------------------------------
139 //Function: updateZoom
140 //Description: 
141 //--------------------------------------------------------------------------
142 void GLViewer_Group::updateZoom( GLViewer_Object* sender, float zoom )
143 {
144   OGIterator it = myList.begin();
145   OGIterator end_it = myList.end();
146   for( int i = 0; it != end_it; ++it, i++ )
147   {
148     GLViewer_Object* anObject = *it;
149     if( anObject != sender )
150       anObject->setZoom( zoom, true, true );
151   }
152 }