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>
22 #include <boost/math/special_functions/fpclassify.hpp>
24 static const Standard_GUID GUID_SELF_SPLITTED("997995aa-5c19-40bf-9a60-ab4b70ad04d8");
25 static const Standard_GUID GUID_HAS_LOCAL_POINTS("FD8841AA-FC44-42fa-B6A7-0F682CCC6F27");
26 static const Standard_GUID GUID_HAS_GLOBAL_POINTS("330D0E81-742D-4ea3-92D4-484877CFA7C1");
28 IMPLEMENT_STANDARD_HANDLE(HYDROData_Image, HYDROData_Entity)
29 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Image, HYDROData_Entity)
31 HYDROData_Image::HYDROData_Image()
36 HYDROData_Image::~HYDROData_Image()
40 QStringList HYDROData_Image::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
42 QStringList aResList = dumpObjectCreation( theTreatedObjects );
43 QString anImageName = GetObjPyName();
45 QString aFilePath = GetFilePath();
46 if ( !aFilePath.isEmpty() )
48 aResList << QString( "" );
49 aResList << QString( "%1.LoadImage( \"%2\" );" )
50 .arg( anImageName ).arg( aFilePath );
51 aResList << QString( "" );
53 // Dump transformation points for image
55 bool anIsByTwoPoints = IsByTwoPoints();
57 QPoint aLocalPointA, aLocalPointB, aLocalPointC;
58 if ( GetLocalPoints( aLocalPointA, aLocalPointB, aLocalPointC ) )
60 QString aGap = QString().fill( ' ', anImageName.size() + 17 );
62 aResList << QString( "%1.SetLocalPoints( QPoint( %2, %3 )," )
63 .arg( anImageName ).arg( aLocalPointA.x() ).arg( aLocalPointA.y() );
64 aResList << QString( aGap + "QPoint( %1, %2 )" )
65 .arg( aLocalPointB.x() ).arg( aLocalPointB.y() );
66 if ( !anIsByTwoPoints )
68 aResList.last().append( "," );
69 aResList << QString( aGap + "QPoint( %1, %2 ) );" )
70 .arg( aLocalPointC.x() ).arg( aLocalPointC.y() );
74 aResList.last().append( " );" );
76 aResList << QString( "" );
79 HYDROData_Image::TransformationMode aTransformationMode;
80 QPointF aTrsfPointA, aTrsfPointB, aTrsfPointC;
81 if ( GetGlobalPoints( aTransformationMode, aTrsfPointA, aTrsfPointB, aTrsfPointC ) )
83 QString aGap = QString().fill( ' ', anImageName.size() + 18 );
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 if ( !anIsByTwoPoints )
93 aResList.last().append( "," );
94 aResList << QString( aGap + "QPointF( %1, %2 ) );" )
95 .arg( aTrsfPointC.x() ).arg( aTrsfPointC.y() );
99 aResList.last().append( " );" );
102 if ( aTransformationMode == ReferenceImage )
104 Handle(HYDROData_Image) aRefImg = GetTrsfReferenceImage();
105 setPythonReferenceObject( theTreatedObjects, aResList, aRefImg, "SetTrsfReferenceImage" );
111 // Image is composed from other image(s)
113 QString anOperatorName = OperatorName();
114 if ( !anOperatorName.isEmpty() )
116 aResList << QString( "" );
118 aResList << QString( "%1.SetOperatorName( \"%2\" );" )
119 .arg( anImageName ).arg( anOperatorName );
121 ImageComposer_Operator* anImageOp =
122 HYDROData_OperationsFactory::Factory()->Operator( OperatorName() );
125 // Dump operation arguments
126 QString anOpArgsArrayName;
127 QStringList anOpArgs = anImageOp->dumpArgsToPython( anOpArgsArrayName );
128 if ( !anOpArgs.isEmpty() )
130 aResList << QString( "" );
131 aResList << anOpArgs;
133 aResList << QString( "" );
134 aResList << QString( "%1.SetArgs( %2 );" )
135 .arg( anImageName ).arg( anOpArgsArrayName );
140 int aNbReferences = NbReferences();
141 if ( aNbReferences > 0 )
143 aResList << QString( "" );
145 for ( int i = 0; i < aNbReferences; ++i )
147 Handle(HYDROData_Image) aRefImg = Handle(HYDROData_Image)::DownCast( Reference( i ) );
148 setPythonReferenceObject( theTreatedObjects, aResList, aRefImg, "AppendReference" );
153 aResList << QString( "" );
154 aResList << QString( "%1.Update();" ).arg( anImageName );
159 void HYDROData_Image::Update()
161 bool anIsToUpdate = IsMustBeUpdated();
163 HYDROData_Entity::Update();
168 HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory();
170 ImageComposer_Operator* anOp = aFactory->Operator( OperatorName() );
171 if ( anOp ) // Update image if there is an operation
173 // Fill by arguments and process the operation
174 anOp->setBinArgs( Args() );
176 QVariant anObj1, anObj2;
177 int aNbReferences = NbReferences();
179 if ( aNbReferences > 0 )
181 // First referenced object
182 Handle(HYDROData_Entity) aRefObj = Reference( 0 );
183 if ( !aRefObj.IsNull() )
185 anObj1 = aRefObj->GetDataVariant();
186 if ( !anObj1.isNull() && anObj1.canConvert<ImageComposer_Image>() )
188 ImageComposer_Image anImage = anObj1.value<ImageComposer_Image>();
189 QTransform aTransform = anImage.transform();
190 SetTrsf( aTransform );
195 if ( aNbReferences > 1 )
197 // Second referenced object
198 Handle(HYDROData_Entity) aRefObj = Reference( 1 );
199 if ( !aRefObj.IsNull() )
200 anObj2 = aRefObj->GetDataVariant();
203 ImageComposer_Image aResImg = anOp->process( anObj1, anObj2 );
205 SetTrsf( aResImg.transform() );
207 else // Update image if it positioned relatively to other image
212 SetToUpdate( false );
215 bool HYDROData_Image::IsHas2dPrs() const
220 QVariant HYDROData_Image::GetDataVariant()
222 QTransform aTransform = Trsf();
224 ImageComposer_Image anImage = Image();
225 anImage.setTransform( aTransform );
228 aVarData.setValue<ImageComposer_Image>( anImage );
233 HYDROData_SequenceOfObjects HYDROData_Image::GetAllReferenceObjects() const
235 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
237 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
238 if ( !aRefImage.IsNull() )
239 aResSeq.Append( aRefImage );
241 HYDROData_SequenceOfObjects aSeqRefObjects = GetReferenceObjects( 0 );
242 aResSeq.Append( aSeqRefObjects );
247 void HYDROData_Image::SetImage(const QImage& theImage)
249 if ( theImage.isNull() )
251 // for empty image remove all previously stored attributes
252 myLab.ForgetAttribute(TDataStd_IntegerArray::GetID());
253 myLab.ForgetAttribute(TDataStd_ByteArray::GetID());
259 // convert 8-bits images
260 if ( theImage.format() == QImage::Format_Indexed8 ) {
261 anImage = theImage.convertToFormat( QImage::Format_RGB32 );
266 // store width, height, bytes per line and format in integer array
267 Handle(TDataStd_IntegerArray) aParams;
268 if (!myLab.FindAttribute(TDataStd_IntegerArray::GetID(), aParams)) {
269 aParams = TDataStd_IntegerArray::Set(myLab, 1, 4);
271 aParams->SetValue(1, anImage.width());
272 aParams->SetValue(2, anImage.height());
273 aParams->SetValue(3, anImage.bytesPerLine());
274 aParams->SetValue(4, (int)(anImage.format()));
275 // store data of image in byte array
276 const char* aData = (const char*)(anImage.bits());
277 SaveByteArray(0, aData, anImage.byteCount());
283 bool HYDROData_Image::LoadImage( const QString& theFilePath )
285 QImage anImage( theFilePath );
288 SetFilePath( theFilePath );
290 return !anImage.isNull();
293 QImage HYDROData_Image::Image()
295 Handle(TDataStd_IntegerArray) aParams;
296 if (!myLab.FindAttribute(TDataStd_IntegerArray::GetID(), aParams))
297 return QImage(); // return empty image if there is no array
299 uchar* anArray = (uchar*)ByteArray(0, aLen);
301 return QImage(); // return empty image if there is no array
302 QImage aResult(anArray, aParams->Value(1), aParams->Value(2),
303 aParams->Value(3), QImage::Format(aParams->Value(4)));
307 void HYDROData_Image::SetFilePath( const QString& theFilePath )
309 TCollection_AsciiString anAsciiStr( theFilePath.toStdString().c_str() );
310 TDataStd_AsciiString::Set( myLab.FindChild( DataTag_FilePath ), anAsciiStr );
315 QString HYDROData_Image::GetFilePath() const
319 TDF_Label aLabel = myLab.FindChild( DataTag_FilePath, false );
320 if ( !aLabel.IsNull() )
322 Handle(TDataStd_AsciiString) anAsciiStr;
323 if ( aLabel.FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) )
324 aRes = QString( anAsciiStr->Get().ToCString() );
330 void HYDROData_Image::SetTrsf(const QTransform& theTrsf)
332 // locate 9 coeffs of matrix into the real array
333 Handle(TDataStd_RealArray) anArray;
334 if (!myLab.FindAttribute(TDataStd_RealArray::GetID(), anArray)) {
335 if (theTrsf.isIdentity()) return; // no need to store identity transformation
336 anArray = TDataStd_RealArray::Set(myLab, 1, 9);
338 anArray->SetValue(1, theTrsf.m11());
339 anArray->SetValue(2, theTrsf.m12());
340 anArray->SetValue(3, theTrsf.m13());
341 anArray->SetValue(4, theTrsf.m21());
342 anArray->SetValue(5, theTrsf.m22());
343 anArray->SetValue(6, theTrsf.m23());
344 anArray->SetValue(7, theTrsf.m31());
345 anArray->SetValue(8, theTrsf.m32());
346 anArray->SetValue(9, theTrsf.m33());
351 QTransform HYDROData_Image::Trsf() const
353 // get 9 coeffs of matrix from the real array
354 Handle(TDataStd_RealArray) anArray;
355 if (!myLab.FindAttribute(TDataStd_RealArray::GetID(), anArray))
356 return QTransform(); // return identity if there is no array
358 anArray->Value(1), anArray->Value(2), anArray->Value(3),
359 anArray->Value(4), anArray->Value(5), anArray->Value(6),
360 anArray->Value(7), anArray->Value(8), anArray->Value(9));
364 void HYDROData_Image::UpdateTrsf()
366 QPoint aPointA, aPointB, aPointC;
367 if ( !GetLocalPoints( aPointA, aPointB, aPointC ) )
370 TransformationMode aTrsfMode;
371 QPointF aTrsfPointA, aTrsfPointB, aTrsfPointC;
372 if ( !GetGlobalPoints( aTrsfMode, aTrsfPointA, aTrsfPointB, aTrsfPointC ) )
375 QTransform aRefTransform;
376 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
378 bool anIsRefImage = aTrsfMode == ReferenceImage;
381 if ( aRefImage.IsNull() )
384 aRefTransform = aRefImage->Trsf();
387 bool anIsByTwoPoints = IsByTwoPoints();
389 // Convert lambert coordinates to cartesian
390 if ( aTrsfMode == ManualGeodesic )
392 double aXCart = 0, aYCart = 0;
394 HYDROData_Lambert93::toXY( aTrsfPointA.y(), aTrsfPointA.x(), aXCart, aYCart );
395 aTrsfPointA = QPointF( aXCart, aYCart );
397 HYDROData_Lambert93::toXY( aTrsfPointB.y(), aTrsfPointB.x(), aXCart, aYCart );
398 aTrsfPointB = QPointF( aXCart, aYCart );
400 if ( !anIsByTwoPoints )
402 HYDROData_Lambert93::toXY( aTrsfPointC.y(), aTrsfPointC.x(), aXCart, aYCart );
403 aTrsfPointC = QPointF( aXCart, aYCart );
407 // generate third points if needed
408 if ( anIsByTwoPoints )
410 aPointC = generateThirdPoint( aPointA, aPointB, true ).toPoint();
411 aTrsfPointC = generateThirdPoint( aTrsfPointA, aTrsfPointB, anIsRefImage );
414 int xa = aPointA.x();
415 int ya = aPointA.y();
416 int xb = aPointB.x();
417 int yb = aPointB.y();
418 int xc = aPointC.x();
419 int yc = aPointC.y();
421 double xta = aTrsfPointA.x();
422 double yta = aTrsfPointA.y();
423 double xtb = aTrsfPointB.x();
424 double ytb = aTrsfPointB.y();
425 double xtc = aTrsfPointC.x();
426 double ytc = aTrsfPointC.y();
428 // first, check that three input points don't belong to a single line
429 if( ( yb - ya ) * ( xc - xa ) == ( yc - ya ) * ( xb - xa ) )
432 // the same check for the reference points
433 if( anIsRefImage && ( ( ytb - yta ) * ( xtc - xta ) == ( ytc - yta ) * ( xtb - xta ) ) )
436 QTransform aTransform1( xa, ya, 1, xb, yb, 1, xc, yc, 1 );
437 QTransform aTransform2( xta, yta, 1, xtb, ytb, 1, xtc, ytc, 1 );
439 bool anIsInvertible = false;
440 QTransform aTransform1Inverted = aTransform1.inverted( &anIsInvertible );
441 if( !anIsInvertible )
444 QTransform aResTransform = aTransform1Inverted * aTransform2;
446 aResTransform *= aRefTransform;
448 SetTrsf( aResTransform );
451 bool HYDROData_Image::IsByTwoPoints() const
453 if ( !HasLocalPoints() || !HasGlobalPoints() )
456 QPoint aPointA, aPointB, aPointC;
457 GetLocalPoints( aPointA, aPointB, aPointC );
459 return aPointC.x() < 0 && aPointC.y() < 0;
462 bool HYDROData_Image::HasReferences() const
464 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
465 int aNbReferences = NbReferences();
467 return !aRefImage.IsNull() || aNbReferences > 0;
470 void HYDROData_Image::RemoveAllReferences()
472 if ( !HasReferences() )
475 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
476 if ( !aRefImage.IsNull() )
478 RemoveTrsfReferenceImage();
483 SetOperatorName( "" );
485 SetIsSelfSplitted( false );
488 bool anIsByTwoPoints = IsByTwoPoints();
490 QImage anImage = Image();
491 if ( anImage.isNull() )
493 SetToUpdate( false );
497 // Set local points to default position
498 QPoint aLocalPointA = QPoint( 0, 0 );
499 QPoint aLocalPointB = QPoint( anImage.width(), 0 );
500 QPoint aLocalPointC = anIsByTwoPoints ? QPoint( INT_MIN, INT_MIN ) : QPoint( 0, anImage.height() );
502 SetLocalPoints( aLocalPointA, aLocalPointB, aLocalPointC, false );
504 // Calculate global points
505 QTransform aTransform = Trsf();
507 QPointF aTrsfPointA = QPointF( aTransform.map( aLocalPointA ) );
508 QPointF aTrsfPointB = QPointF( aTransform.map( aLocalPointB ) );
509 QPointF aTrsfPointC = anIsByTwoPoints ? QPointF( INT_MIN, INT_MIN ) :
510 QPointF( aTransform.map( aLocalPointC ) );
512 SetGlobalPoints( ManualCartesian, aTrsfPointA, aTrsfPointB, aTrsfPointC );
514 SetToUpdate( false );
517 void HYDROData_Image::SetLocalPoints( const QPoint& thePointA,
518 const QPoint& thePointB,
519 const QPoint& thePointC,
520 const bool theIsUpdate )
522 Handle(TDataStd_RealArray) anArray;
523 if ( !myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
524 anArray = TDataStd_RealArray::Set( myLab.FindChild( DataTag_TrsfPoints ), 1, 12 );
526 anArray->SetValue( 1, thePointA.x() );
527 anArray->SetValue( 2, thePointA.y() );
528 anArray->SetValue( 3, thePointB.x() );
529 anArray->SetValue( 4, thePointB.y() );
530 anArray->SetValue( 5, thePointC.x() );
531 anArray->SetValue( 6, thePointC.y() );
533 TDataStd_UAttribute::Set( myLab.FindChild( DataTag_TrsfPoints ), GUID_HAS_LOCAL_POINTS );
541 bool HYDROData_Image::GetLocalPoints( QPoint& thePointA,
543 QPoint& thePointC ) const
545 if ( !HasLocalPoints() )
548 Handle(TDataStd_RealArray) anArray;
549 myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray );
551 thePointA = QPointF( anArray->Value( 1 ), anArray->Value( 2 ) ).toPoint();
552 thePointB = QPointF( anArray->Value( 3 ), anArray->Value( 4 ) ).toPoint();
553 thePointC = QPointF( anArray->Value( 5 ), anArray->Value( 6 ) ).toPoint();
558 bool HYDROData_Image::HasLocalPoints() const
560 TDF_Label aLabel = myLab.FindChild( DataTag_TrsfPoints, false );
561 if ( aLabel.IsNull() || !aLabel.IsAttribute( GUID_HAS_LOCAL_POINTS ) )
564 Handle(TDataStd_RealArray) anArray;
565 return aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray );
569 void HYDROData_Image::SetGlobalPoints( const TransformationMode& theMode,
570 const QPointF& thePointA,
571 const QPointF& thePointB,
572 const QPointF& thePointC,
573 const bool theIsUpdate )
575 Handle(TDataStd_RealArray) anArray;
576 if ( !myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
577 anArray = TDataStd_RealArray::Set( myLab.FindChild( DataTag_TrsfPoints ), 1, 12 );
579 anArray->SetValue( 7, thePointA.x() );
580 anArray->SetValue( 8, thePointA.y() );
581 anArray->SetValue( 9, thePointB.x() );
582 anArray->SetValue( 10, thePointB.y() );
583 anArray->SetValue( 11, thePointC.x() );
584 anArray->SetValue( 12, thePointC.y() );
586 SetTrsfMode( theMode );
588 TDataStd_UAttribute::Set( myLab.FindChild( DataTag_TrsfPoints ), GUID_HAS_GLOBAL_POINTS );
596 bool HYDROData_Image::GetGlobalPoints( TransformationMode& theMode,
599 QPointF& thePointC ) const
601 if ( !HasGlobalPoints() )
604 theMode = GetTrsfMode();
606 Handle(TDataStd_RealArray) anArray;
607 myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray );
609 thePointA = QPointF( anArray->Value( 7 ), anArray->Value( 8 ) );
610 thePointB = QPointF( anArray->Value( 9 ), anArray->Value( 10 ) );
611 thePointC = QPointF( anArray->Value( 11 ), anArray->Value( 12 ) );
616 bool HYDROData_Image::SetGlobalPointsFromFile( const QString& theFileName )
620 // Try to open the file
621 QFile aFile( theFileName );
622 if ( !aFile.exists() || !aFile.open( QIODevice::ReadOnly ) ) {
626 QPointF aPointA, aPointB;
627 double aXmin, anYmin, aXmax, anYmax;
628 aXmin = anYmin = aXmax = anYmax = -1;
630 while ( !aFile.atEnd() &&
631 ( aXmin < 0 || anYmin < 0 || aXmax < 0 || anYmax < 0 ) ) {
633 QString aLine = aFile.readLine().simplified();
634 aLine.replace( " ", "" );
635 if ( aLine.isEmpty() ) {
639 // Try to read double value after ":"
640 bool isDoubleOk = false;
641 double aDoubleValue = -1;
642 QStringList aValues = aLine.split( ":", QString::SkipEmptyParts );
643 if ( aValues.count() == 2 ) {
644 aDoubleValue = aValues.last().toDouble( &isDoubleOk );
649 boost::math::isnan( aDoubleValue ) ||
650 boost::math::isinf( aDoubleValue ) ) {
655 if ( aLine.startsWith( "Xminimum" ) ) {
656 aXmin = aDoubleValue;
658 else if ( aLine.startsWith( "Yminimum" ) ) {
659 anYmin = aDoubleValue;
661 else if ( aLine.startsWith( "Xmaximum" ) ) {
662 aXmax = aDoubleValue;
664 else if ( aLine.startsWith( "Ymaximum" ) ) {
665 anYmax = aDoubleValue;
672 if ( aXmin >= 0 && anYmin >= 0 ) {
673 aPointA.setX( aXmin );
674 aPointA.setY( anYmin );
677 if ( aXmax >= 0 && anYmax >= 0 ) {
678 aPointB.setX( aXmax );
679 aPointB.setY( anYmax );
682 if ( !aPointA.isNull() && !aPointB.isNull() ) {
683 SetGlobalPoints( ManualCartesian, aPointA, aPointB );
690 bool HYDROData_Image::HasGlobalPoints() const
692 TDF_Label aLabel = myLab.FindChild( DataTag_TrsfPoints, false );
693 if ( aLabel.IsNull() || !aLabel.IsAttribute( GUID_HAS_GLOBAL_POINTS ) )
696 Handle(TDataStd_RealArray) anArray;
697 return aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray );
700 void HYDROData_Image::SetReferencePoints( const Handle(HYDROData_Image)& theRefImage,
701 const QPointF& thePointA,
702 const QPointF& thePointB,
703 const QPointF& thePointC,
704 const bool theIsUpdate )
706 SetTrsfReferenceImage( theRefImage );
707 SetGlobalPoints( ReferenceImage, thePointA, thePointB, thePointC, theIsUpdate );
710 bool HYDROData_Image::GetReferencePoints( Handle(HYDROData_Image)& theRefImage,
713 QPointF& thePointC ) const
715 if ( !HasReferencePoints() )
718 theRefImage = GetTrsfReferenceImage();
720 TransformationMode aMode;
721 GetGlobalPoints( aMode, thePointA, thePointB, thePointC );
726 bool HYDROData_Image::HasReferencePoints() const
728 if ( !HasGlobalPoints() )
731 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
732 if ( aRefImage.IsNull() )
735 TransformationMode aTrsfMode = GetTrsfMode();
736 if ( aTrsfMode != ReferenceImage )
742 void HYDROData_Image::SetTrsfMode( const TransformationMode& theMode )
744 TDataStd_Integer::Set( myLab.FindChild( DataTag_TrsfMode ), (int)theMode );
748 HYDROData_Image::TransformationMode HYDROData_Image::GetTrsfMode() const
750 TransformationMode aResMode = ManualGeodesic;
752 TDF_Label aLabel = myLab.FindChild( DataTag_TrsfPoints, false );
753 if ( !aLabel.IsNull() )
755 Handle(TDataStd_Integer) aMode;
756 if ( myLab.FindChild( DataTag_TrsfMode ).FindAttribute( TDataStd_Integer::GetID(), aMode ) )
757 aResMode = (TransformationMode)aMode->Get();
763 void HYDROData_Image::SetTrsfReferenceImage( const Handle(HYDROData_Image)& theRefImage )
765 SetReferenceObject( theRefImage, DataTag_TrsfImage );
769 Handle(HYDROData_Image) HYDROData_Image::GetTrsfReferenceImage() const
771 return Handle(HYDROData_Image)::DownCast( GetReferenceObject( DataTag_TrsfImage ) );
774 void HYDROData_Image::RemoveTrsfReferenceImage()
776 RemoveReferenceObject( DataTag_TrsfImage );
780 void HYDROData_Image::AppendReference( const Handle(HYDROData_Entity)& theReferenced )
782 AddReferenceObject( theReferenced, 0 );
786 int HYDROData_Image::NbReferences() const
788 return NbReferenceObjects( 0 );
791 Handle(HYDROData_Entity) HYDROData_Image::Reference( const int theIndex ) const
793 return GetReferenceObject( 0, theIndex );
796 void HYDROData_Image::ChangeReference(
797 const int theIndex, Handle(HYDROData_Entity) theReferenced)
799 SetReferenceObject( theReferenced, 0, theIndex );
803 void HYDROData_Image::RemoveReference(const int theIndex)
805 RemoveReferenceObject( 0, theIndex );
809 void HYDROData_Image::ClearReferences()
811 ClearReferenceObjects( 0 );
815 void HYDROData_Image::SetOperatorName( const QString theOpName )
817 TCollection_AsciiString anAsciiStr( theOpName.toStdString().c_str() );
818 TDataStd_AsciiString::Set( myLab.FindChild( DataTag_Operator ), anAsciiStr );
822 QString HYDROData_Image::OperatorName() const
826 TDF_Label aLabel = myLab.FindChild( DataTag_Operator, false );
827 if ( !aLabel.IsNull() )
829 Handle(TDataStd_AsciiString) anAsciiStr;
830 if ( aLabel.FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) )
831 aRes = QString( anAsciiStr->Get().ToCString() );
837 void HYDROData_Image::SetArgs(const QByteArray& theArgs)
839 SaveByteArray(DataTag_Operator, theArgs.constData(), theArgs.length());
843 QByteArray HYDROData_Image::Args() const
846 const char* aData = ByteArray(DataTag_Operator, aLen);
849 return QByteArray(aData, aLen);
852 void HYDROData_Image::SetIsSelfSplitted(bool theFlag)
855 TDataStd_UAttribute::Set(myLab, GUID_SELF_SPLITTED);
857 myLab.ForgetAttribute(GUID_SELF_SPLITTED);
862 bool HYDROData_Image::IsSelfSplitted() const
864 return myLab.IsAttribute(GUID_SELF_SPLITTED);
867 QPointF HYDROData_Image::generateThirdPoint( const QPointF& thePointA,
868 const QPointF& thePointB,
869 const bool& theIsLocal ) const
871 // Rotate vector to 90 degrees : clockwise - for local
872 // counterclockwise - for global
873 const double aTheta = theIsLocal ? -M_PI_2 : M_PI_2;
877 // Move to (0,0) for correct rotation
878 double x = thePointB.x() - thePointA.x();
879 double y = thePointB.y() - thePointA.y();
881 aResPoint.setX( x * cos( aTheta ) - y * sin( aTheta ) );
882 aResPoint.setY( x * sin( aTheta ) + y * cos( aTheta ) );
884 // Move back to origin position
885 aResPoint.setX( aResPoint.x() + thePointA.x() );
886 aResPoint.setY( aResPoint.y() + thePointA.y() );