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