Salome HOME
Unicode support: correct handling of unicode on GUI level
[modules/gui.git] / src / GLViewer / GLViewer_Object.cxx
index 5cc8685b71afd18ba79427909ad892b51c012ee4..fa54128d72b893d4bfc7bc77c445d94b40d9d0f7 100644 (file)
@@ -1,21 +1,36 @@
-/***************************************************************************
-**  Class:   GLViewer_Object
-**  Descr:   OpenGL Object
-**  Module:  GLViewer
-**  Created: UI team, 03.09.02
-****************************************************************************/
-
-//#include <GLViewerAfx.h>
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
 #include "GLViewer_Object.h"
 #include "GLViewer_Drawer.h"
 #include "GLViewer_AspectLine.h"
-#include "GLViewer_Geom.h"
 #include "GLViewer_Text.h"
 #include "GLViewer_Group.h"
 
-//#include <cmath>
-//using namespace std;
+#include <SUIT_DataOwner.h>
 
+/*!
+  Default constructor
+*/
 GLViewer_Object::GLViewer_Object()
 {
   myXScale = 1.0; 
@@ -44,6 +59,9 @@ GLViewer_Object::GLViewer_Object()
   myGroup = NULL;
 }
 
+/*!
+  Destructor
+*/
 GLViewer_Object::~GLViewer_Object()
 {
   if( myRect )
@@ -59,16 +77,27 @@ GLViewer_Object::~GLViewer_Object()
     delete myAspectLine;
 }
 
+/*!
+  \return priority of object
+*/
 int GLViewer_Object::getPriority() const
 {
     return myDrawer ? myDrawer->getPriority() : 0;
 }
 
+/*!
+  \return true if object is inside rectangle
+  \param theRect - rectangle
+*/
 GLboolean GLViewer_Object::isInside( GLViewer_Rect theRect )
 {
     return theRect.toQRect().contains( myRect->toQRect() );
 }
 
+/*!
+  Sets zoom factor
+  \param zoom - zoom factor
+*/
 GLboolean GLViewer_Object::setZoom( GLfloat zoom, bool, bool )
 {
     if( myZoom == zoom )
@@ -78,6 +107,10 @@ GLboolean GLViewer_Object::setZoom( GLfloat zoom, bool, bool )
     return GL_TRUE;
 }
 
+/*!
+  Performs zoom change by step
+  \param zoomIn - to increase to decrease zoom
+*/
 GLboolean GLViewer_Object::updateZoom( bool zoomIn )
 {
     float newZoom;
@@ -97,13 +130,17 @@ GLboolean GLViewer_Object::updateZoom( bool zoomIn )
     return setZoom( newZoom, true );
 }
 
+/*!
+  Codes object as byte copy
+  \return byte array
+*/
 QByteArray GLViewer_Object::getByteCopy()
 {
     int i = 0;
     int anISize = sizeof( int );
 
-    const char* aTypeStr = myType.data();
-    const char* aToolTipStr = myToolTipText.data();
+    const char* aTypeStr = myType.toLatin1().constData();
+    const char* aToolTipStr = myToolTipText.toUtf8().constData();
 
     int aTypeLength = myType.length();
     int aToolTipLength = myToolTipText.length();
@@ -124,9 +161,10 @@ QByteArray GLViewer_Object::getByteCopy()
     
     int sizeOf8Float = sizeof( aRectData );
 
-    QByteArray aResult( 2*anISize + sizeOf8Float + 
-                        aTypeLength + aToolTipLength +
-                        aGLText.size() + aAspect.size() );
+    QByteArray aResult;
+    aResult.resize( 2*anISize + sizeOf8Float + 
+                    aTypeLength + aToolTipLength +
+                    aGLText.size() + aAspect.size() );
     // puts 8 float values into the byte array
     char* aPointer = (char*)&aRectData;
     for( i = 0; i < sizeOf8Float; i++, aPointer++ )
@@ -148,22 +186,26 @@ QByteArray GLViewer_Object::getByteCopy()
 
     int aCurPos = 2*anISize + sizeOf8Float + aTypeLength + aToolTipLength;
     // adds aspect byte array
-    for( i = aCurPos; i < aCurPos + aAspect.size(); i++ )
+    for ( i = aCurPos; i < (int)( aCurPos + aAspect.size() ); i++ )
         aResult[i] = aAspect[i - aCurPos];
 
     aCurPos = aCurPos + aAspect.size();
     // adds GL text byte array
-    for( i = aCurPos; i < aCurPos + aGLText.size(); i++ )
+    for ( i = aCurPos; i < (int)( aCurPos + aGLText.size() ); i++ )
         aResult[i] = aGLText[i - aCurPos];    
 
     aCurPos += aGLText.size();
     aPointer = (char*)&myOwner;
-    for( i = 0; i < sizeof( GLViewer_Owner* ); i++, aPointer++ )
+    for( i = 0; i < sizeof( SUIT_DataOwner* ); i++, aPointer++ )
         aResult[ aCurPos + i ] = *aPointer;
 
     return aResult;
 }
 
+/*!
+  Initialize object by byte array
+  \param theArray - byte array
+*/
 bool GLViewer_Object::initializeFromByteCopy( QByteArray theArray )
 {
     int i = 0;
@@ -182,7 +224,9 @@ bool GLViewer_Object::initializeFromByteCopy( QByteArray theArray )
     GLViewer_AspectLine* aAspectLine = new GLViewer_AspectLine();
     int aGLAspLineSize = (aAspectLine->getByteCopy()).size();
 
-    QByteArray aGLTextArray, aAspect( aGLAspLineSize );
+    QByteArray aGLTextArray, aAspect;
+    aGLTextArray.resize( aGLAspLineSize );
+    aAspect.resize( aGLAspLineSize );
 
     if( aSize < 2*anISize + 8*aFSize + aGLTextMinSize + aGLAspLineSize )
         return false;
@@ -260,8 +304,15 @@ bool GLViewer_Object::initializeFromByteCopy( QByteArray theArray )
     return true;        
 }
 
+/*!
+  Sets object's group
+  \param theGroup - group
+*/
 void GLViewer_Object::setGroup( GLViewer_Group* theGroup )
 {
+  if ( myGroup == theGroup )
+    return;
+
   if( myGroup )
     myGroup->removeObject( this );
   
@@ -270,6 +321,9 @@ void GLViewer_Object::setGroup( GLViewer_Group* theGroup )
     myGroup->addObject( this );
 }
 
+/*!
+  \return object's group
+*/
 GLViewer_Group* GLViewer_Object::getGroup() const
 {
   return myGroup;