2 #include "HYDROData_Image.h"
4 #include "HYDROData_Document.h"
5 #include "HYDROData_Lambert93.h"
6 #include "HYDROData_OperationsFactory.h"
8 #include <TDataStd_RealArray.hxx>
9 #include <TDataStd_ByteArray.hxx>
10 #include <TDataStd_Integer.hxx>
11 #include <TDataStd_IntegerArray.hxx>
12 #include <TDataStd_ReferenceList.hxx>
13 #include <TDataStd_UAttribute.hxx>
14 #include <TDataStd_AsciiString.hxx>
16 #include <ImageComposer_Operator.h>
17 #include <ImageComposer_MetaTypes.h>
19 #include <QStringList>
21 static const Standard_GUID GUID_SELF_SPLITTED("997995aa-5c19-40bf-9a60-ab4b70ad04d8");
22 static const Standard_GUID GUID_HAS_LOCAL_POINTS("FD8841AA-FC44-42fa-B6A7-0F682CCC6F27");
23 static const Standard_GUID GUID_HAS_GLOBAL_POINTS("330D0E81-742D-4ea3-92D4-484877CFA7C1");
25 #define PYTHON_IMAGE_ID "KIND_IMAGE"
27 IMPLEMENT_STANDARD_HANDLE(HYDROData_Image, HYDROData_Entity)
28 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Image, HYDROData_Entity)
30 HYDROData_Image::HYDROData_Image()
35 HYDROData_Image::~HYDROData_Image()
39 QStringList HYDROData_Image::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
43 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
44 if ( aDocument.IsNull() )
47 QString aDocName = aDocument->GetDocPyName();
48 QString anImageName = GetName();
50 aResList << QString( "%1 = %2.CreateObject( %3 );" )
51 .arg( anImageName ).arg( aDocName ).arg( PYTHON_IMAGE_ID );
52 aResList << QString( "%1.SetName( \"%2\" );" )
53 .arg( anImageName ).arg( anImageName );
55 QString aFilePath = GetFilePath();
56 if ( !aFilePath.isEmpty() )
58 aResList << QString( "" );
59 aResList << QString( "%1.LoadImage( \"%2\" );" )
60 .arg( anImageName ).arg( aFilePath );
61 aResList << QString( "" );
63 // Dump transformation points for image
65 QString aGap = QString().fill( ' ', anImageName.size() + 16 );
67 bool anIsByTwoPoints = IsByTwoPoints();
69 QPoint aLocalPointA, aLocalPointB, aLocalPointC;
70 if ( GetLocalPoints( aLocalPointA, aLocalPointB, aLocalPointC ) )
72 aResList << QString( "%1.SetLocalPoints( QPoint( %2, %3 )," )
73 .arg( anImageName ).arg( aLocalPointA.x() ).arg( aLocalPointA.y() );
74 aResList << QString( aGap + "QPoint( %1, %2 )," )
75 .arg( aLocalPointB.x() ).arg( aLocalPointB.y() );
76 aResList << QString( aGap + "QPoint( %1, %2 ) );" )
77 .arg( aLocalPointC.x() ).arg( aLocalPointC.y() );
78 aResList << QString( "" );
81 HYDROData_Image::TransformationMode aTransformationMode;
82 QPointF aTrsfPointA, aTrsfPointB, aTrsfPointC;
83 if ( GetGlobalPoints( aTransformationMode, aTrsfPointA, aTrsfPointB, aTrsfPointC ) )
85 aResList << QString( "%1.SetGlobalPoints( %2," )
86 .arg( anImageName ).arg( aTransformationMode );
87 aResList << QString( aGap + "QPointF( %1, %2 )," )
88 .arg( aTrsfPointA.x() ).arg( aTrsfPointA.y() );
89 aResList << QString( aGap + "QPointF( %1, %2 )," )
90 .arg( aTrsfPointB.x() ).arg( aTrsfPointB.y() );
91 aResList << QString( aGap + "QPointF( %1, %2 ) );" )
92 .arg( aTrsfPointC.x() ).arg( aTrsfPointC.y() );
94 if ( aTransformationMode == ReferenceImage )
96 Handle(HYDROData_Image) aRefImg = GetTrsfReferenceImage();
97 setPythonReferenceObject( theTreatedObjects, aResList, aRefImg, "SetTrsfReferenceImage" );
103 // Image is composed from other image(s)
105 QString anOperatorName = OperatorName();
106 if ( !anOperatorName.isEmpty() )
108 aResList << QString( "" );
110 aResList << QString( "%1.SetOperatorName( \"%2\" );" )
111 .arg( anImageName ).arg( anOperatorName );
113 ImageComposer_Operator* anImageOp =
114 HYDROData_OperationsFactory::Factory()->Operator( OperatorName() );
117 // Dump operation arguments
118 QString anOpArgsArrayName;
119 QStringList anOpArgs = anImageOp->dumpArgsToPython( anOpArgsArrayName );
120 if ( !anOpArgs.isEmpty() )
122 aResList << QString( "" );
123 aResList << anOpArgs;
125 aResList << QString( "" );
126 aResList << QString( "%1.SetArgs( %2 );" )
127 .arg( anImageName ).arg( anOpArgsArrayName );
132 int aNbReferences = NbReferences();
133 if ( aNbReferences > 0 )
135 aResList << QString( "" );
137 for ( int i = 0; i < aNbReferences; ++i )
139 Handle(HYDROData_Image) aRefImg = Handle(HYDROData_Image)::DownCast( Reference( i ) );
140 setPythonReferenceObject( theTreatedObjects, aResList, aRefImg, "AppendReference" );
144 // Necessary to update image in case of composed operator
145 aResList << QString( "" );
146 aResList << QString( "%1.Update();" ).arg( anImageName );
152 void HYDROData_Image::Update()
154 bool anIsToUpdate = IsMustBeUpdated();
156 HYDROData_Entity::Update();
161 HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory();
163 ImageComposer_Operator* anOp = aFactory->Operator( OperatorName() );
164 if ( anOp ) // Update image if there is an operation
166 // Fill by arguments and process the operation
167 anOp->setBinArgs( Args() );
169 QVariant anObj1, anObj2;
170 int aNbReferences = NbReferences();
172 if ( aNbReferences > 0 )
174 // First referenced object
175 Handle(HYDROData_Entity) aRefObj = Reference( 0 );
176 if ( !aRefObj.IsNull() )
178 anObj1 = aRefObj->GetDataVariant();
179 if ( !anObj1.isNull() && anObj1.canConvert<ImageComposer_Image>() )
181 ImageComposer_Image anImage = anObj1.value<ImageComposer_Image>();
182 QTransform aTransform = anImage.transform();
183 SetTrsf( aTransform );
188 if ( aNbReferences > 1 )
190 // Second referenced object
191 Handle(HYDROData_Entity) aRefObj = Reference( 1 );
192 if ( !aRefObj.IsNull() )
193 anObj2 = aRefObj->GetDataVariant();
196 ImageComposer_Image aResImg = anOp->process( anObj1, anObj2 );
198 SetTrsf( aResImg.transform() );
200 else // Update image if it positioned relatively to other image
205 SetToUpdate( false );
208 QVariant HYDROData_Image::GetDataVariant()
210 QTransform aTransform = Trsf();
212 ImageComposer_Image anImage = Image();
213 anImage.setTransform( aTransform );
216 aVarData.setValue<ImageComposer_Image>( anImage );
221 HYDROData_SequenceOfObjects HYDROData_Image::GetAllReferenceObjects() const
223 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
225 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
226 if ( !aRefImage.IsNull() )
227 aResSeq.Append( aRefImage );
229 HYDROData_SequenceOfObjects aSeqRefObjects = GetReferenceObjects( 0 );
230 aResSeq.Append( aSeqRefObjects );
235 void HYDROData_Image::SetImage(const QImage& theImage)
237 if ( theImage.isNull() )
239 // for empty image remove all previously stored attributes
240 myLab.ForgetAttribute(TDataStd_IntegerArray::GetID());
241 myLab.ForgetAttribute(TDataStd_ByteArray::GetID());
245 // store width, height, bytes per line and format in integer array
246 Handle(TDataStd_IntegerArray) aParams;
247 if (!myLab.FindAttribute(TDataStd_IntegerArray::GetID(), aParams)) {
248 aParams = TDataStd_IntegerArray::Set(myLab, 1, 4);
250 aParams->SetValue(1, theImage.width());
251 aParams->SetValue(2, theImage.height());
252 aParams->SetValue(3, theImage.bytesPerLine());
253 aParams->SetValue(4, (int)(theImage.format()));
254 // store data of image in byte array
255 const char* aData = (const char*)(theImage.bits());
256 SaveByteArray(0, aData, theImage.byteCount());
262 bool HYDROData_Image::LoadImage( const QString& theFilePath )
264 QImage anImage( theFilePath );
266 return !anImage.isNull();
269 QImage HYDROData_Image::Image()
271 Handle(TDataStd_IntegerArray) aParams;
272 if (!myLab.FindAttribute(TDataStd_IntegerArray::GetID(), aParams))
273 return QImage(); // return empty image if there is no array
275 uchar* anArray = (uchar*)ByteArray(0, aLen);
277 return QImage(); // return empty image if there is no array
278 QImage aResult(anArray, aParams->Value(1), aParams->Value(2),
279 aParams->Value(3), QImage::Format(aParams->Value(4)));
283 void HYDROData_Image::SetFilePath( const QString& theFilePath )
285 TCollection_AsciiString anAsciiStr( theFilePath.toStdString().c_str() );
286 TDataStd_AsciiString::Set( myLab.FindChild( DataTag_FilePath ), anAsciiStr );
291 QString HYDROData_Image::GetFilePath() const
295 TDF_Label aLabel = myLab.FindChild( DataTag_FilePath, false );
296 if ( !aLabel.IsNull() )
298 Handle(TDataStd_AsciiString) anAsciiStr;
299 if ( aLabel.FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) )
300 aRes = QString( anAsciiStr->Get().ToCString() );
306 void HYDROData_Image::SetTrsf(const QTransform& theTrsf)
308 // locate 9 coeffs of matrix into the real array
309 Handle(TDataStd_RealArray) anArray;
310 if (!myLab.FindAttribute(TDataStd_RealArray::GetID(), anArray)) {
311 if (theTrsf.isIdentity()) return; // no need to store identity transformation
312 anArray = TDataStd_RealArray::Set(myLab, 1, 9);
314 anArray->SetValue(1, theTrsf.m11());
315 anArray->SetValue(2, theTrsf.m12());
316 anArray->SetValue(3, theTrsf.m13());
317 anArray->SetValue(4, theTrsf.m21());
318 anArray->SetValue(5, theTrsf.m22());
319 anArray->SetValue(6, theTrsf.m23());
320 anArray->SetValue(7, theTrsf.m31());
321 anArray->SetValue(8, theTrsf.m32());
322 anArray->SetValue(9, theTrsf.m33());
327 QTransform HYDROData_Image::Trsf() const
329 // get 9 coeffs of matrix from the real array
330 Handle(TDataStd_RealArray) anArray;
331 if (!myLab.FindAttribute(TDataStd_RealArray::GetID(), anArray))
332 return QTransform(); // return identity if there is no array
334 anArray->Value(1), anArray->Value(2), anArray->Value(3),
335 anArray->Value(4), anArray->Value(5), anArray->Value(6),
336 anArray->Value(7), anArray->Value(8), anArray->Value(9));
340 void HYDROData_Image::UpdateTrsf()
342 QPoint aPointA, aPointB, aPointC;
343 if ( !GetLocalPoints( aPointA, aPointB, aPointC ) )
346 TransformationMode aTrsfMode;
347 QPointF aTrsfPointA, aTrsfPointB, aTrsfPointC;
348 if ( !GetGlobalPoints( aTrsfMode, aTrsfPointA, aTrsfPointB, aTrsfPointC ) )
351 QTransform aRefTransform;
352 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
354 bool anIsRefImage = aTrsfMode == ReferenceImage;
357 if ( aRefImage.IsNull() )
360 aRefTransform = aRefImage->Trsf();
363 bool anIsByTwoPoints = IsByTwoPoints();
365 // Convert lambert coordinates to cartesian
366 if ( aTrsfMode == ManualGeodesic )
368 double aXCart = 0, aYCart = 0;
370 HYDROData_Lambert93::toXY( aTrsfPointA.y(), aTrsfPointA.x(), aXCart, aYCart );
371 aTrsfPointA = QPointF( aXCart, aYCart );
373 HYDROData_Lambert93::toXY( aTrsfPointB.y(), aTrsfPointB.x(), aXCart, aYCart );
374 aTrsfPointB = QPointF( aXCart, aYCart );
376 if ( !anIsByTwoPoints )
378 HYDROData_Lambert93::toXY( aTrsfPointC.y(), aTrsfPointC.x(), aXCart, aYCart );
379 aTrsfPointC = QPointF( aXCart, aYCart );
383 // generate third points if needed
384 if ( anIsByTwoPoints )
386 aPointC = generateThirdPoint( aPointA, aPointB, true ).toPoint();
387 aTrsfPointC = generateThirdPoint( aTrsfPointA, aTrsfPointB, anIsRefImage );
390 int xa = aPointA.x();
391 int ya = aPointA.y();
392 int xb = aPointB.x();
393 int yb = aPointB.y();
394 int xc = aPointC.x();
395 int yc = aPointC.y();
397 double xta = aTrsfPointA.x();
398 double yta = aTrsfPointA.y();
399 double xtb = aTrsfPointB.x();
400 double ytb = aTrsfPointB.y();
401 double xtc = aTrsfPointC.x();
402 double ytc = aTrsfPointC.y();
404 // first, check that three input points don't belong to a single line
405 if( ( yb - ya ) * ( xc - xa ) == ( yc - ya ) * ( xb - xa ) )
408 // the same check for the reference points
409 if( anIsRefImage && ( ( ytb - yta ) * ( xtc - xta ) == ( ytc - yta ) * ( xtb - xta ) ) )
412 QTransform aTransform1( xa, ya, 1, xb, yb, 1, xc, yc, 1 );
413 QTransform aTransform2( xta, yta, 1, xtb, ytb, 1, xtc, ytc, 1 );
415 bool anIsInvertible = false;
416 QTransform aTransform1Inverted = aTransform1.inverted( &anIsInvertible );
417 if( !anIsInvertible )
420 QTransform aResTransform = aTransform1Inverted * aTransform2;
422 aResTransform *= aRefTransform;
424 SetTrsf( aResTransform );
427 bool HYDROData_Image::IsByTwoPoints() const
429 if ( !HasLocalPoints() || !HasGlobalPoints() )
432 QPoint aPointA, aPointB, aPointC;
433 GetLocalPoints( aPointA, aPointB, aPointC );
435 return aPointC.x() < 0 && aPointC.y() < 0;
438 bool HYDROData_Image::HasReferences() const
440 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
441 int aNbReferences = NbReferences();
443 return !aRefImage.IsNull() || aNbReferences > 0;
446 void HYDROData_Image::RemoveAllReferences()
448 if ( !HasReferences() )
451 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
452 if ( !aRefImage.IsNull() )
454 RemoveTrsfReferenceImage();
459 SetOperatorName( "" );
461 SetIsSelfSplitted( false );
464 bool anIsByTwoPoints = IsByTwoPoints();
466 QImage anImage = Image();
467 if ( anImage.isNull() )
469 SetToUpdate( false );
473 // Set local points to default position
474 QPoint aLocalPointA = QPoint( 0, 0 );
475 QPoint aLocalPointB = QPoint( anImage.width(), 0 );
476 QPoint aLocalPointC = anIsByTwoPoints ? QPoint( INT_MIN, INT_MIN ) : QPoint( 0, anImage.height() );
478 SetLocalPoints( aLocalPointA, aLocalPointB, aLocalPointC, false );
480 // Calculate global points
481 QTransform aTransform = Trsf();
483 QPointF aTrsfPointA = QPointF( aTransform.map( aLocalPointA ) );
484 QPointF aTrsfPointB = QPointF( aTransform.map( aLocalPointB ) );
485 QPointF aTrsfPointC = anIsByTwoPoints ? QPointF( INT_MIN, INT_MIN ) :
486 QPointF( aTransform.map( aLocalPointC ) );
488 SetGlobalPoints( ManualCartesian, aTrsfPointA, aTrsfPointB, aTrsfPointC );
490 SetToUpdate( false );
493 void HYDROData_Image::SetLocalPoints( const QPoint& thePointA,
494 const QPoint& thePointB,
495 const QPoint& thePointC,
496 const bool theIsUpdate )
498 Handle(TDataStd_RealArray) anArray;
499 if ( !myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
500 anArray = TDataStd_RealArray::Set( myLab.FindChild( DataTag_TrsfPoints ), 1, 12 );
502 anArray->SetValue( 1, thePointA.x() );
503 anArray->SetValue( 2, thePointA.y() );
504 anArray->SetValue( 3, thePointB.x() );
505 anArray->SetValue( 4, thePointB.y() );
506 anArray->SetValue( 5, thePointC.x() );
507 anArray->SetValue( 6, thePointC.y() );
509 TDataStd_UAttribute::Set( myLab.FindChild( DataTag_TrsfPoints ), GUID_HAS_LOCAL_POINTS );
517 bool HYDROData_Image::GetLocalPoints( QPoint& thePointA,
519 QPoint& thePointC ) const
521 if ( !HasLocalPoints() )
524 Handle(TDataStd_RealArray) anArray;
525 myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray );
527 thePointA = QPointF( anArray->Value( 1 ), anArray->Value( 2 ) ).toPoint();
528 thePointB = QPointF( anArray->Value( 3 ), anArray->Value( 4 ) ).toPoint();
529 thePointC = QPointF( anArray->Value( 5 ), anArray->Value( 6 ) ).toPoint();
534 bool HYDROData_Image::HasLocalPoints() const
536 TDF_Label aLabel = myLab.FindChild( DataTag_TrsfPoints, false );
537 if ( aLabel.IsNull() || !aLabel.IsAttribute( GUID_HAS_LOCAL_POINTS ) )
540 Handle(TDataStd_RealArray) anArray;
541 return aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray );
545 void HYDROData_Image::SetGlobalPoints( const TransformationMode& theMode,
546 const QPointF& thePointA,
547 const QPointF& thePointB,
548 const QPointF& thePointC,
549 const bool theIsUpdate )
551 Handle(TDataStd_RealArray) anArray;
552 if ( !myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
553 anArray = TDataStd_RealArray::Set( myLab.FindChild( DataTag_TrsfPoints ), 1, 12 );
555 anArray->SetValue( 7, thePointA.x() );
556 anArray->SetValue( 8, thePointA.y() );
557 anArray->SetValue( 9, thePointB.x() );
558 anArray->SetValue( 10, thePointB.y() );
559 anArray->SetValue( 11, thePointC.x() );
560 anArray->SetValue( 12, thePointC.y() );
562 SetTrsfMode( theMode );
564 TDataStd_UAttribute::Set( myLab.FindChild( DataTag_TrsfPoints ), GUID_HAS_GLOBAL_POINTS );
572 bool HYDROData_Image::GetGlobalPoints( TransformationMode& theMode,
575 QPointF& thePointC ) const
577 if ( !HasGlobalPoints() )
580 theMode = GetTrsfMode();
582 Handle(TDataStd_RealArray) anArray;
583 myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray );
585 thePointA = QPointF( anArray->Value( 7 ), anArray->Value( 8 ) );
586 thePointB = QPointF( anArray->Value( 9 ), anArray->Value( 10 ) );
587 thePointC = QPointF( anArray->Value( 11 ), anArray->Value( 12 ) );
592 bool HYDROData_Image::HasGlobalPoints() const
594 TDF_Label aLabel = myLab.FindChild( DataTag_TrsfPoints, false );
595 if ( aLabel.IsNull() || !aLabel.IsAttribute( GUID_HAS_GLOBAL_POINTS ) )
598 Handle(TDataStd_RealArray) anArray;
599 return aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray );
602 void HYDROData_Image::SetReferencePoints( const Handle(HYDROData_Image)& theRefImage,
603 const QPointF& thePointA,
604 const QPointF& thePointB,
605 const QPointF& thePointC,
606 const bool theIsUpdate )
608 SetTrsfReferenceImage( theRefImage );
609 SetGlobalPoints( ReferenceImage, thePointA, thePointB, thePointC, theIsUpdate );
612 bool HYDROData_Image::GetReferencePoints( Handle(HYDROData_Image)& theRefImage,
615 QPointF& thePointC ) const
617 if ( !HasReferencePoints() )
620 theRefImage = GetTrsfReferenceImage();
622 TransformationMode aMode;
623 GetGlobalPoints( aMode, thePointA, thePointB, thePointC );
628 bool HYDROData_Image::HasReferencePoints() const
630 if ( !HasGlobalPoints() )
633 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
634 if ( aRefImage.IsNull() )
637 TransformationMode aTrsfMode = GetTrsfMode();
638 if ( aTrsfMode != ReferenceImage )
644 void HYDROData_Image::SetTrsfMode( const TransformationMode& theMode )
646 TDataStd_Integer::Set( myLab.FindChild( DataTag_TrsfMode ), (int)theMode );
650 HYDROData_Image::TransformationMode HYDROData_Image::GetTrsfMode() const
652 TransformationMode aResMode = ManualGeodesic;
654 TDF_Label aLabel = myLab.FindChild( DataTag_TrsfPoints, false );
655 if ( !aLabel.IsNull() )
657 Handle(TDataStd_Integer) aMode;
658 if ( myLab.FindChild( DataTag_TrsfMode ).FindAttribute( TDataStd_Integer::GetID(), aMode ) )
659 aResMode = (TransformationMode)aMode->Get();
665 void HYDROData_Image::SetTrsfReferenceImage( const Handle(HYDROData_Image)& theRefImage )
667 SetReferenceObject( theRefImage, DataTag_TrsfImage );
671 Handle(HYDROData_Image) HYDROData_Image::GetTrsfReferenceImage() const
673 return Handle(HYDROData_Image)::DownCast( GetReferenceObject( DataTag_TrsfImage ) );
676 void HYDROData_Image::RemoveTrsfReferenceImage()
678 RemoveReferenceObject( DataTag_TrsfImage );
682 void HYDROData_Image::AppendReference( const Handle(HYDROData_Entity)& theReferenced )
684 AddReferenceObject( theReferenced, 0 );
688 int HYDROData_Image::NbReferences() const
690 return NbReferenceObjects( 0 );
693 Handle(HYDROData_Entity) HYDROData_Image::Reference( const int theIndex ) const
695 return GetReferenceObject( 0, theIndex );
698 void HYDROData_Image::ChangeReference(
699 const int theIndex, Handle(HYDROData_Entity) theReferenced)
701 SetReferenceObject( theReferenced, 0, theIndex );
705 void HYDROData_Image::RemoveReference(const int theIndex)
707 RemoveReferenceObject( 0, theIndex );
711 void HYDROData_Image::ClearReferences()
713 ClearReferenceObjects( 0 );
717 void HYDROData_Image::SetOperatorName( const QString theOpName )
719 TCollection_AsciiString anAsciiStr( theOpName.toStdString().c_str() );
720 TDataStd_AsciiString::Set( myLab.FindChild( DataTag_Operator ), anAsciiStr );
724 QString HYDROData_Image::OperatorName() const
728 TDF_Label aLabel = myLab.FindChild( DataTag_Operator, false );
729 if ( !aLabel.IsNull() )
731 Handle(TDataStd_AsciiString) anAsciiStr;
732 if ( aLabel.FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) )
733 aRes = QString( anAsciiStr->Get().ToCString() );
739 void HYDROData_Image::SetArgs(const QByteArray& theArgs)
741 SaveByteArray(DataTag_Operator, theArgs.constData(), theArgs.length());
745 QByteArray HYDROData_Image::Args() const
748 const char* aData = ByteArray(DataTag_Operator, aLen);
751 return QByteArray(aData, aLen);
754 void HYDROData_Image::SetIsSelfSplitted(bool theFlag)
757 TDataStd_UAttribute::Set(myLab, GUID_SELF_SPLITTED);
759 myLab.ForgetAttribute(GUID_SELF_SPLITTED);
764 bool HYDROData_Image::IsSelfSplitted() const
766 return myLab.IsAttribute(GUID_SELF_SPLITTED);
769 QPointF HYDROData_Image::generateThirdPoint( const QPointF& thePointA,
770 const QPointF& thePointB,
771 const bool& theIsLocal ) const
773 // Rotate vector to 90 degrees : clockwise - for local
774 // counterclockwise - for global
775 const double aTheta = theIsLocal ? -M_PI_2 : M_PI_2;
779 // Move to (0,0) for correct rotation
780 double x = thePointB.x() - thePointA.x();
781 double y = thePointB.y() - thePointA.y();
783 aResPoint.setX( x * cos( aTheta ) - y * sin( aTheta ) );
784 aResPoint.setY( x * sin( aTheta ) + y * cos( aTheta ) );
786 // Move back to origin position
787 aResPoint.setX( aResPoint.x() + thePointA.x() );
788 aResPoint.setY( aResPoint.y() + thePointA.y() );