1 // Copyright (C) 2005 OPEN CASCADE
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.
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.
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
17 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
19 // Author : OPEN CASCADE
22 /***************************************************************************
23 ** Class: GLViewer_MimeSource
24 ** Descr: Needs for a work with QClipboard
26 ** Created: UI team, 22.03.04
27 ****************************************************************************/
29 //#include <GLViewerAfx.h>
30 #include "GLViewer_MimeSource.h"
31 #include "GLViewer_BaseObjects.h"
34 //using namespace std;
36 GLViewer_MimeSource::~GLViewer_MimeSource()
40 bool GLViewer_MimeSource::setObjects( QValueList<GLViewer_Object*> theObjects )
42 if( !theObjects.empty() )
44 QStringList aObjectsType;
45 QValueList<QByteArray> aObjects;
46 QValueList<GLViewer_Object*>::const_iterator anIt = theObjects.begin();
47 QValueList<GLViewer_Object*>::const_iterator anEndIt = theObjects.end();
50 for( ; anIt != anEndIt; anIt++ )
52 aObjects.append( (*anIt)->getByteCopy() );
53 aObjByteSize += aObjects.last().size();
54 aObjectsType.append( (*anIt)->getObjectType() );
57 int anISize = sizeof( int );
58 QString aTypes = aObjectsType.join("");
59 int aStrByteSize = aTypes.length();
60 int aObjNum = aObjects.count();
62 myByteArray = QByteArray( anISize * (1 + 2*aObjNum) + aStrByteSize + aObjByteSize );
64 int anIndex = 0, j = 0;
65 char* aPointer = (char*)&aObjNum;
66 for( anIndex = 0; anIndex < anISize; anIndex++, aPointer++ )
67 myByteArray[anIndex] = *aPointer;
69 QStringList::const_iterator aStrIt = aObjectsType.begin();
70 QStringList::const_iterator aEndStrIt = aObjectsType.end();
71 for( j = 1; aStrIt != aEndStrIt; aStrIt++, j++ )
73 int aStrLen = (*aStrIt).length();
74 aPointer = (char*)&aStrLen;
75 for( ; anIndex < anISize*( 1 + j ); anIndex++, aPointer++ )
76 myByteArray[anIndex] = *aPointer;
79 int aCurIndex = anIndex;
80 const char* aStr = aTypes.data();
82 for( j = 0 ; anIndex < aCurIndex + aStrByteSize; aPointer++, anIndex++, j++ )
83 myByteArray[anIndex] = aStr[j];
86 QValueList<QByteArray>::iterator anObjIt = aObjects.begin();
87 QValueList<QByteArray>::iterator anEndObjIt = aObjects.end();
88 for( j = 1; anObjIt != anEndObjIt; anObjIt++, j++ )
90 int aObjLen = (int)((*anObjIt).size());
91 aPointer = (char*)&aObjLen;
92 for( ; anIndex < aCurIndex + anISize*j; anIndex++, aPointer++ )
93 myByteArray[anIndex] = *aPointer;
97 anObjIt = aObjects.begin();
99 for( ; anObjIt != anEndObjIt; anObjIt++ )
101 int aObjLen = (int)((*anObjIt).size());
102 for( j = 0 ; anIndex < aCurIndex + aObjLen; anIndex++, aPointer++, j++ )
103 myByteArray[anIndex] = (*anObjIt)[j];
112 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!NOTE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
113 //If you want to use new class, following two method must be redefined
114 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!NOTE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
115 GLViewer_Object* GLViewer_MimeSource::getObject( QByteArray theArray, QString theType )
117 if( !theArray.isEmpty() )
119 if( theType == "GLViewer_MarkerSet" )
121 GLViewer_MarkerSet* aObject = new GLViewer_MarkerSet( 0, (float)0.0, 0 );
122 if( aObject->initializeFromByteCopy( theArray ) )
125 else if ( theType == "GLViewer_Polyline" )
127 GLViewer_Polyline* aObject = new GLViewer_Polyline( 0, (float)0.0, 0 );
128 if( aObject->initializeFromByteCopy( theArray ) )
131 else if( theType == "GLViewer_TextObject" )
133 GLViewer_TextObject* aObject = new GLViewer_TextObject( 0, 0, 0, QColor(255,255,255), 0 );
134 if( aObject->initializeFromByteCopy( theArray ) )
142 QValueList<GLViewer_Object*> GLViewer_MimeSource::getObjects( QByteArray theArray, QString theType )
144 if( !theArray.isEmpty() )
146 int anISize = sizeof( int );
147 if( theType == "GLViewer_Objects" )
149 QStringList aTypeList;
150 QValueList<QByteArray> aObjects;
151 QValueList<GLViewer_Object*> aObjectList;
153 QValueList<int> aTypeSizeList;
154 QValueList<int> aObjSizeList;
156 char* aPointer = (char*)&aObjNum;
158 int anIndex = 0, j = 0;
159 for( anIndex = 0; anIndex < anISize; anIndex++, aPointer++ )
160 *aPointer = theArray[anIndex];
162 for( j = 0; j < aObjNum; j++ )
165 aPointer = (char*)&aTempVal;
166 for( ; anIndex < anISize*(j+2); anIndex++, aPointer++ )
167 *aPointer = theArray[anIndex];
168 aTypeSizeList.append( aTempVal );
171 int aCurIndex = anIndex;
172 for( j = 0; j < aObjNum; j++ )
175 for( ; anIndex < aCurIndex + aTypeSizeList[j]; anIndex++ )
177 char aLetter = theArray[anIndex];
178 aTempStr.append( aLetter );
180 aTypeList.append( aTempStr );
184 for( j = 0; j < aObjNum; j++ )
187 aPointer = (char*)&aTempVal;
188 for( ; anIndex < aCurIndex + anISize*(j+1); anIndex++, aPointer++ )
189 *aPointer = theArray[anIndex];
190 aObjSizeList.append( aTempVal );
194 for( j = 0; j < aObjNum; j++ )
196 QByteArray aTempArray(aObjSizeList[j]);
197 for( ; anIndex < aCurIndex + aObjSizeList[j]; anIndex++ )
198 aTempArray[anIndex-aCurIndex] = theArray[anIndex];
199 aObjects.append( aTempArray );
203 for( j = 0; j < aObjNum; j++ )
204 aObjectList.append( getObject( aObjects[j], aTypeList[j] ) );
210 return QValueList<GLViewer_Object*>();
213 const char* GLViewer_MimeSource::format( int theIndex ) const
217 case 0: return "GLViewer_Objects";
218 //case 1: return "GLViewer_MarkerSet";
219 //case 2: return "GLViewer_Polyline";
220 //case 3: return "GLViewer_TextObject";
226 QByteArray GLViewer_MimeSource::encodedData( const char* theObjectType ) const
228 if( theObjectType == "GLViewer_Objects" )