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 QVariant HYDROData_Image::GetDataVariant()
217 QTransform aTransform = Trsf();
219 ImageComposer_Image anImage = Image();
220 anImage.setTransform( aTransform );
223 aVarData.setValue<ImageComposer_Image>( anImage );
228 HYDROData_SequenceOfObjects HYDROData_Image::GetAllReferenceObjects() const
230 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
232 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
233 if ( !aRefImage.IsNull() )
234 aResSeq.Append( aRefImage );
236 HYDROData_SequenceOfObjects aSeqRefObjects = GetReferenceObjects( 0 );
237 aResSeq.Append( aSeqRefObjects );
242 void HYDROData_Image::SetImage(const QImage& theImage)
244 if ( theImage.isNull() )
246 // for empty image remove all previously stored attributes
247 myLab.ForgetAttribute(TDataStd_IntegerArray::GetID());
248 myLab.ForgetAttribute(TDataStd_ByteArray::GetID());
254 // convert 8-bits images
255 if ( theImage.format() == QImage::Format_Indexed8 ) {
256 anImage = theImage.convertToFormat( QImage::Format_RGB32 );
261 // store width, height, bytes per line and format in integer array
262 Handle(TDataStd_IntegerArray) aParams;
263 if (!myLab.FindAttribute(TDataStd_IntegerArray::GetID(), aParams)) {
264 aParams = TDataStd_IntegerArray::Set(myLab, 1, 4);
266 aParams->SetValue(1, anImage.width());
267 aParams->SetValue(2, anImage.height());
268 aParams->SetValue(3, anImage.bytesPerLine());
269 aParams->SetValue(4, (int)(anImage.format()));
270 // store data of image in byte array
271 const char* aData = (const char*)(anImage.bits());
272 SaveByteArray(0, aData, anImage.byteCount());
278 bool HYDROData_Image::LoadImage( const QString& theFilePath )
280 QImage anImage( theFilePath );
283 SetFilePath( theFilePath );
285 return !anImage.isNull();
288 QImage HYDROData_Image::Image()
290 Handle(TDataStd_IntegerArray) aParams;
291 if (!myLab.FindAttribute(TDataStd_IntegerArray::GetID(), aParams))
292 return QImage(); // return empty image if there is no array
294 uchar* anArray = (uchar*)ByteArray(0, aLen);
296 return QImage(); // return empty image if there is no array
297 QImage aResult(anArray, aParams->Value(1), aParams->Value(2),
298 aParams->Value(3), QImage::Format(aParams->Value(4)));
302 void HYDROData_Image::SetFilePath( const QString& theFilePath )
304 TCollection_AsciiString anAsciiStr( theFilePath.toStdString().c_str() );
305 TDataStd_AsciiString::Set( myLab.FindChild( DataTag_FilePath ), anAsciiStr );
310 QString HYDROData_Image::GetFilePath() const
314 TDF_Label aLabel = myLab.FindChild( DataTag_FilePath, false );
315 if ( !aLabel.IsNull() )
317 Handle(TDataStd_AsciiString) anAsciiStr;
318 if ( aLabel.FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) )
319 aRes = QString( anAsciiStr->Get().ToCString() );
325 void HYDROData_Image::SetTrsf(const QTransform& theTrsf)
327 // locate 9 coeffs of matrix into the real array
328 Handle(TDataStd_RealArray) anArray;
329 if (!myLab.FindAttribute(TDataStd_RealArray::GetID(), anArray)) {
330 if (theTrsf.isIdentity()) return; // no need to store identity transformation
331 anArray = TDataStd_RealArray::Set(myLab, 1, 9);
333 anArray->SetValue(1, theTrsf.m11());
334 anArray->SetValue(2, theTrsf.m12());
335 anArray->SetValue(3, theTrsf.m13());
336 anArray->SetValue(4, theTrsf.m21());
337 anArray->SetValue(5, theTrsf.m22());
338 anArray->SetValue(6, theTrsf.m23());
339 anArray->SetValue(7, theTrsf.m31());
340 anArray->SetValue(8, theTrsf.m32());
341 anArray->SetValue(9, theTrsf.m33());
346 QTransform HYDROData_Image::Trsf() const
348 // get 9 coeffs of matrix from the real array
349 Handle(TDataStd_RealArray) anArray;
350 if (!myLab.FindAttribute(TDataStd_RealArray::GetID(), anArray))
351 return QTransform(); // return identity if there is no array
353 anArray->Value(1), anArray->Value(2), anArray->Value(3),
354 anArray->Value(4), anArray->Value(5), anArray->Value(6),
355 anArray->Value(7), anArray->Value(8), anArray->Value(9));
359 void HYDROData_Image::UpdateTrsf()
361 QPoint aPointA, aPointB, aPointC;
362 if ( !GetLocalPoints( aPointA, aPointB, aPointC ) )
365 TransformationMode aTrsfMode;
366 QPointF aTrsfPointA, aTrsfPointB, aTrsfPointC;
367 if ( !GetGlobalPoints( aTrsfMode, aTrsfPointA, aTrsfPointB, aTrsfPointC ) )
370 QTransform aRefTransform;
371 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
373 bool anIsRefImage = aTrsfMode == ReferenceImage;
376 if ( aRefImage.IsNull() )
379 aRefTransform = aRefImage->Trsf();
382 bool anIsByTwoPoints = IsByTwoPoints();
384 // Convert lambert coordinates to cartesian
385 if ( aTrsfMode == ManualGeodesic )
387 double aXCart = 0, aYCart = 0;
389 HYDROData_Lambert93::toXY( aTrsfPointA.y(), aTrsfPointA.x(), aXCart, aYCart );
390 aTrsfPointA = QPointF( aXCart, aYCart );
392 HYDROData_Lambert93::toXY( aTrsfPointB.y(), aTrsfPointB.x(), aXCart, aYCart );
393 aTrsfPointB = QPointF( aXCart, aYCart );
395 if ( !anIsByTwoPoints )
397 HYDROData_Lambert93::toXY( aTrsfPointC.y(), aTrsfPointC.x(), aXCart, aYCart );
398 aTrsfPointC = QPointF( aXCart, aYCart );
402 // generate third points if needed
403 if ( anIsByTwoPoints )
405 aPointC = generateThirdPoint( aPointA, aPointB, true ).toPoint();
406 aTrsfPointC = generateThirdPoint( aTrsfPointA, aTrsfPointB, anIsRefImage );
409 int xa = aPointA.x();
410 int ya = aPointA.y();
411 int xb = aPointB.x();
412 int yb = aPointB.y();
413 int xc = aPointC.x();
414 int yc = aPointC.y();
416 double xta = aTrsfPointA.x();
417 double yta = aTrsfPointA.y();
418 double xtb = aTrsfPointB.x();
419 double ytb = aTrsfPointB.y();
420 double xtc = aTrsfPointC.x();
421 double ytc = aTrsfPointC.y();
423 // first, check that three input points don't belong to a single line
424 if( ( yb - ya ) * ( xc - xa ) == ( yc - ya ) * ( xb - xa ) )
427 // the same check for the reference points
428 if( anIsRefImage && ( ( ytb - yta ) * ( xtc - xta ) == ( ytc - yta ) * ( xtb - xta ) ) )
431 QTransform aTransform1( xa, ya, 1, xb, yb, 1, xc, yc, 1 );
432 QTransform aTransform2( xta, yta, 1, xtb, ytb, 1, xtc, ytc, 1 );
434 bool anIsInvertible = false;
435 QTransform aTransform1Inverted = aTransform1.inverted( &anIsInvertible );
436 if( !anIsInvertible )
439 QTransform aResTransform = aTransform1Inverted * aTransform2;
441 aResTransform *= aRefTransform;
443 SetTrsf( aResTransform );
446 bool HYDROData_Image::IsByTwoPoints() const
448 if ( !HasLocalPoints() || !HasGlobalPoints() )
451 QPoint aPointA, aPointB, aPointC;
452 GetLocalPoints( aPointA, aPointB, aPointC );
454 return aPointC.x() < 0 && aPointC.y() < 0;
457 bool HYDROData_Image::HasReferences() const
459 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
460 int aNbReferences = NbReferences();
462 return !aRefImage.IsNull() || aNbReferences > 0;
465 void HYDROData_Image::RemoveAllReferences()
467 if ( !HasReferences() )
470 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
471 if ( !aRefImage.IsNull() )
473 RemoveTrsfReferenceImage();
478 SetOperatorName( "" );
480 SetIsSelfSplitted( false );
483 bool anIsByTwoPoints = IsByTwoPoints();
485 QImage anImage = Image();
486 if ( anImage.isNull() )
488 SetToUpdate( false );
492 // Set local points to default position
493 QPoint aLocalPointA = QPoint( 0, 0 );
494 QPoint aLocalPointB = QPoint( anImage.width(), 0 );
495 QPoint aLocalPointC = anIsByTwoPoints ? QPoint( INT_MIN, INT_MIN ) : QPoint( 0, anImage.height() );
497 SetLocalPoints( aLocalPointA, aLocalPointB, aLocalPointC, false );
499 // Calculate global points
500 QTransform aTransform = Trsf();
502 QPointF aTrsfPointA = QPointF( aTransform.map( aLocalPointA ) );
503 QPointF aTrsfPointB = QPointF( aTransform.map( aLocalPointB ) );
504 QPointF aTrsfPointC = anIsByTwoPoints ? QPointF( INT_MIN, INT_MIN ) :
505 QPointF( aTransform.map( aLocalPointC ) );
507 SetGlobalPoints( ManualCartesian, aTrsfPointA, aTrsfPointB, aTrsfPointC );
509 SetToUpdate( false );
512 void HYDROData_Image::SetLocalPoints( const QPoint& thePointA,
513 const QPoint& thePointB,
514 const QPoint& thePointC,
515 const bool theIsUpdate )
517 Handle(TDataStd_RealArray) anArray;
518 if ( !myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
519 anArray = TDataStd_RealArray::Set( myLab.FindChild( DataTag_TrsfPoints ), 1, 12 );
521 anArray->SetValue( 1, thePointA.x() );
522 anArray->SetValue( 2, thePointA.y() );
523 anArray->SetValue( 3, thePointB.x() );
524 anArray->SetValue( 4, thePointB.y() );
525 anArray->SetValue( 5, thePointC.x() );
526 anArray->SetValue( 6, thePointC.y() );
528 TDataStd_UAttribute::Set( myLab.FindChild( DataTag_TrsfPoints ), GUID_HAS_LOCAL_POINTS );
536 bool HYDROData_Image::GetLocalPoints( QPoint& thePointA,
538 QPoint& thePointC ) const
540 if ( !HasLocalPoints() )
543 Handle(TDataStd_RealArray) anArray;
544 myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray );
546 thePointA = QPointF( anArray->Value( 1 ), anArray->Value( 2 ) ).toPoint();
547 thePointB = QPointF( anArray->Value( 3 ), anArray->Value( 4 ) ).toPoint();
548 thePointC = QPointF( anArray->Value( 5 ), anArray->Value( 6 ) ).toPoint();
553 bool HYDROData_Image::HasLocalPoints() const
555 TDF_Label aLabel = myLab.FindChild( DataTag_TrsfPoints, false );
556 if ( aLabel.IsNull() || !aLabel.IsAttribute( GUID_HAS_LOCAL_POINTS ) )
559 Handle(TDataStd_RealArray) anArray;
560 return aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray );
564 void HYDROData_Image::SetGlobalPoints( const TransformationMode& theMode,
565 const QPointF& thePointA,
566 const QPointF& thePointB,
567 const QPointF& thePointC,
568 const bool theIsUpdate )
570 Handle(TDataStd_RealArray) anArray;
571 if ( !myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
572 anArray = TDataStd_RealArray::Set( myLab.FindChild( DataTag_TrsfPoints ), 1, 12 );
574 anArray->SetValue( 7, thePointA.x() );
575 anArray->SetValue( 8, thePointA.y() );
576 anArray->SetValue( 9, thePointB.x() );
577 anArray->SetValue( 10, thePointB.y() );
578 anArray->SetValue( 11, thePointC.x() );
579 anArray->SetValue( 12, thePointC.y() );
581 SetTrsfMode( theMode );
583 TDataStd_UAttribute::Set( myLab.FindChild( DataTag_TrsfPoints ), GUID_HAS_GLOBAL_POINTS );
591 bool HYDROData_Image::GetGlobalPoints( TransformationMode& theMode,
594 QPointF& thePointC ) const
596 if ( !HasGlobalPoints() )
599 theMode = GetTrsfMode();
601 Handle(TDataStd_RealArray) anArray;
602 myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray );
604 thePointA = QPointF( anArray->Value( 7 ), anArray->Value( 8 ) );
605 thePointB = QPointF( anArray->Value( 9 ), anArray->Value( 10 ) );
606 thePointC = QPointF( anArray->Value( 11 ), anArray->Value( 12 ) );
611 bool HYDROData_Image::SetGlobalPointsFromFile( const QString& theFileName )
615 // Try to open the file
616 QFile aFile( theFileName );
617 if ( !aFile.exists() || !aFile.open( QIODevice::ReadOnly ) ) {
621 QPointF aPointA, aPointB;
622 double aXmin, anYmin, aXmax, anYmax;
623 aXmin = anYmin = aXmax = anYmax = -1;
625 while ( !aFile.atEnd() &&
626 ( aXmin < 0 || anYmin < 0 || aXmax < 0 || anYmax < 0 ) ) {
628 QString aLine = aFile.readLine().simplified();
629 aLine.replace( " ", "" );
630 if ( aLine.isEmpty() ) {
634 // Try to read double value after ":"
635 bool isDoubleOk = false;
636 double aDoubleValue = -1;
637 QStringList aValues = aLine.split( ":", QString::SkipEmptyParts );
638 if ( aValues.count() == 2 ) {
639 aDoubleValue = aValues.last().toDouble( &isDoubleOk );
644 boost::math::isnan( aDoubleValue ) ||
645 boost::math::isinf( aDoubleValue ) ) {
650 if ( aLine.startsWith( "Xminimum" ) ) {
651 aXmin = aDoubleValue;
653 else if ( aLine.startsWith( "Yminimum" ) ) {
654 anYmin = aDoubleValue;
656 else if ( aLine.startsWith( "Xmaximum" ) ) {
657 aXmax = aDoubleValue;
659 else if ( aLine.startsWith( "Ymaximum" ) ) {
660 anYmax = aDoubleValue;
667 if ( aXmin >= 0 && anYmin >= 0 ) {
668 aPointA.setX( aXmin );
669 aPointA.setY( anYmin );
672 if ( aXmax >= 0 && anYmax >= 0 ) {
673 aPointB.setX( aXmax );
674 aPointB.setY( anYmax );
677 if ( !aPointA.isNull() && !aPointB.isNull() ) {
678 SetGlobalPoints( ManualCartesian, aPointA, aPointB );
685 bool HYDROData_Image::HasGlobalPoints() const
687 TDF_Label aLabel = myLab.FindChild( DataTag_TrsfPoints, false );
688 if ( aLabel.IsNull() || !aLabel.IsAttribute( GUID_HAS_GLOBAL_POINTS ) )
691 Handle(TDataStd_RealArray) anArray;
692 return aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray );
695 void HYDROData_Image::SetReferencePoints( const Handle(HYDROData_Image)& theRefImage,
696 const QPointF& thePointA,
697 const QPointF& thePointB,
698 const QPointF& thePointC,
699 const bool theIsUpdate )
701 SetTrsfReferenceImage( theRefImage );
702 SetGlobalPoints( ReferenceImage, thePointA, thePointB, thePointC, theIsUpdate );
705 bool HYDROData_Image::GetReferencePoints( Handle(HYDROData_Image)& theRefImage,
708 QPointF& thePointC ) const
710 if ( !HasReferencePoints() )
713 theRefImage = GetTrsfReferenceImage();
715 TransformationMode aMode;
716 GetGlobalPoints( aMode, thePointA, thePointB, thePointC );
721 bool HYDROData_Image::HasReferencePoints() const
723 if ( !HasGlobalPoints() )
726 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
727 if ( aRefImage.IsNull() )
730 TransformationMode aTrsfMode = GetTrsfMode();
731 if ( aTrsfMode != ReferenceImage )
737 void HYDROData_Image::SetTrsfMode( const TransformationMode& theMode )
739 TDataStd_Integer::Set( myLab.FindChild( DataTag_TrsfMode ), (int)theMode );
743 HYDROData_Image::TransformationMode HYDROData_Image::GetTrsfMode() const
745 TransformationMode aResMode = ManualGeodesic;
747 TDF_Label aLabel = myLab.FindChild( DataTag_TrsfPoints, false );
748 if ( !aLabel.IsNull() )
750 Handle(TDataStd_Integer) aMode;
751 if ( myLab.FindChild( DataTag_TrsfMode ).FindAttribute( TDataStd_Integer::GetID(), aMode ) )
752 aResMode = (TransformationMode)aMode->Get();
758 void HYDROData_Image::SetTrsfReferenceImage( const Handle(HYDROData_Image)& theRefImage )
760 SetReferenceObject( theRefImage, DataTag_TrsfImage );
764 Handle(HYDROData_Image) HYDROData_Image::GetTrsfReferenceImage() const
766 return Handle(HYDROData_Image)::DownCast( GetReferenceObject( DataTag_TrsfImage ) );
769 void HYDROData_Image::RemoveTrsfReferenceImage()
771 RemoveReferenceObject( DataTag_TrsfImage );
775 void HYDROData_Image::AppendReference( const Handle(HYDROData_Entity)& theReferenced )
777 AddReferenceObject( theReferenced, 0 );
781 int HYDROData_Image::NbReferences() const
783 return NbReferenceObjects( 0 );
786 Handle(HYDROData_Entity) HYDROData_Image::Reference( const int theIndex ) const
788 return GetReferenceObject( 0, theIndex );
791 void HYDROData_Image::ChangeReference(
792 const int theIndex, Handle(HYDROData_Entity) theReferenced)
794 SetReferenceObject( theReferenced, 0, theIndex );
798 void HYDROData_Image::RemoveReference(const int theIndex)
800 RemoveReferenceObject( 0, theIndex );
804 void HYDROData_Image::ClearReferences()
806 ClearReferenceObjects( 0 );
810 void HYDROData_Image::SetOperatorName( const QString theOpName )
812 TCollection_AsciiString anAsciiStr( theOpName.toStdString().c_str() );
813 TDataStd_AsciiString::Set( myLab.FindChild( DataTag_Operator ), anAsciiStr );
817 QString HYDROData_Image::OperatorName() const
821 TDF_Label aLabel = myLab.FindChild( DataTag_Operator, false );
822 if ( !aLabel.IsNull() )
824 Handle(TDataStd_AsciiString) anAsciiStr;
825 if ( aLabel.FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) )
826 aRes = QString( anAsciiStr->Get().ToCString() );
832 void HYDROData_Image::SetArgs(const QByteArray& theArgs)
834 SaveByteArray(DataTag_Operator, theArgs.constData(), theArgs.length());
838 QByteArray HYDROData_Image::Args() const
841 const char* aData = ByteArray(DataTag_Operator, aLen);
844 return QByteArray(aData, aLen);
847 void HYDROData_Image::SetIsSelfSplitted(bool theFlag)
850 TDataStd_UAttribute::Set(myLab, GUID_SELF_SPLITTED);
852 myLab.ForgetAttribute(GUID_SELF_SPLITTED);
857 bool HYDROData_Image::IsSelfSplitted() const
859 return myLab.IsAttribute(GUID_SELF_SPLITTED);
862 QPointF HYDROData_Image::generateThirdPoint( const QPointF& thePointA,
863 const QPointF& thePointB,
864 const bool& theIsLocal ) const
866 // Rotate vector to 90 degrees : clockwise - for local
867 // counterclockwise - for global
868 const double aTheta = theIsLocal ? -M_PI_2 : M_PI_2;
872 // Move to (0,0) for correct rotation
873 double x = thePointB.x() - thePointA.x();
874 double y = thePointB.y() - thePointA.y();
876 aResPoint.setX( x * cos( aTheta ) - y * sin( aTheta ) );
877 aResPoint.setY( x * sin( aTheta ) + y * cos( aTheta ) );
879 // Move back to origin position
880 aResPoint.setX( aResPoint.x() + thePointA.x() );
881 aResPoint.setY( aResPoint.y() + thePointA.y() );