Salome HOME
updated copyright message
[modules/gui.git] / src / GLViewer / GLViewer_Group.cxx
1 // Copyright (C) 2007-2023  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, or (at your option) any later version.
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
23 //  Author : OPEN CASCADE
24 // File:      GLViewer_Group.xx
25 // Created:   March, 2005
26 //#include "GLViewerAfx.h"
27 //
28 #include "GLViewer_Group.h"
29 #include "GLViewer_Object.h"
30
31 /*!
32   constructor
33 */
34 GLViewer_Group::GLViewer_Group()
35 {
36   mySelObjNum = 0;
37 }
38
39 /*!
40   destructor
41 */
42 GLViewer_Group::~GLViewer_Group()
43 {  
44 }
45
46 /*!
47   detection of empty group
48 */
49 bool GLViewer_Group::isEmpty()
50 {
51   return myList.empty(); 
52 }
53
54 /*!
55   \return number of elements
56 */
57 int GLViewer_Group::count()
58 {
59   return (int)myList.size(); //!< TODO: conversion from size_t to int
60 }
61
62 /*!
63   \return the position of object if group contains it, else -1
64 */
65 int GLViewer_Group::contains( GLViewer_Object* theObject )
66 {
67   if( !theObject )
68     return -1;
69   
70   OGIterator it = myList.begin();
71   OGIterator end_it = myList.end();
72   for( int i = 0; it != end_it; ++it, i++ )
73     if( *it == theObject )
74       return i;
75
76   return -1;
77 }
78
79 /*!
80   adding object to group
81 */
82 int GLViewer_Group::addObject( GLViewer_Object* theObject )
83 {
84   if( theObject && contains( theObject ) == -1 )
85   {
86     myList.push_back( theObject );
87     theObject->setGroup( this );
88   }
89   return count();
90 }
91
92 /*!
93   removing object from group
94 */
95 int GLViewer_Group::removeObject( GLViewer_Object* theObject )
96 {
97   if( theObject )
98   {
99     myList.remove( theObject );
100     //theObject->setGroup( NULL );
101   }
102
103
104   if( isEmpty() )
105   {
106     this->~GLViewer_Group();
107     return -1;
108   }
109   else
110     return count();
111 }
112
113 /*!
114   Dragging operation
115   \param Once is true, if this operation calls only one time for all object
116   \param x, y - dragging position
117 */
118 void GLViewer_Group::dragingObjects( float x, float y, bool once )
119 {
120   if( !once )
121   {
122     if( !mySelObjNum )
123     {
124       OGIterator it = myList.begin();
125       OGIterator end_it = myList.end();
126       for( int i = 0; it != end_it; ++it, i++ )
127         if( (*it)->isSelected() )
128           mySelObjNum++;
129
130       if( mySelObjNum )
131         mySelObjNum--;
132     }
133     else
134     {
135       mySelObjNum--;
136       return;
137     }
138   }
139
140   OGIterator it = myList.begin();
141   OGIterator end_it = myList.end();
142   for( int i = 0; it != end_it; ++it, i++ )
143     (*it)->moveObject( x, y, true );  
144 }
145
146 /*!
147   Updates zoom of object
148   \param sender - object to be updated
149   \param zoom - zoom coefficient
150 */
151 void GLViewer_Group::updateZoom( GLViewer_Object* sender, float zoom )
152 {
153   OGIterator it = myList.begin();
154   OGIterator end_it = myList.end();
155   for( int i = 0; it != end_it; ++it, i++ )
156   {
157     GLViewer_Object* anObject = *it;
158     if( anObject != sender )
159       anObject->setZoom( zoom, true, true );
160   }
161 }