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 QString aGap = QString().fill( ' ', anImageName.size() + 16 );
57 bool anIsByTwoPoints = IsByTwoPoints();
59 QPoint aLocalPointA, aLocalPointB, aLocalPointC;
60 if ( GetLocalPoints( aLocalPointA, aLocalPointB, aLocalPointC ) )
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 aResList << QString( aGap + "QPoint( %1, %2 ) );" )
67 .arg( aLocalPointC.x() ).arg( aLocalPointC.y() );
68 aResList << QString( "" );
71 HYDROData_Image::TransformationMode aTransformationMode;
72 QPointF aTrsfPointA, aTrsfPointB, aTrsfPointC;
73 if ( GetGlobalPoints( aTransformationMode, aTrsfPointA, aTrsfPointB, aTrsfPointC ) )
75 aResList << QString( "%1.SetGlobalPoints( %2," )
76 .arg( anImageName ).arg( aTransformationMode );
77 aResList << QString( aGap + "QPointF( %1, %2 )," )
78 .arg( aTrsfPointA.x() ).arg( aTrsfPointA.y() );
79 aResList << QString( aGap + "QPointF( %1, %2 )," )
80 .arg( aTrsfPointB.x() ).arg( aTrsfPointB.y() );
81 aResList << QString( aGap + "QPointF( %1, %2 ) );" )
82 .arg( aTrsfPointC.x() ).arg( aTrsfPointC.y() );
84 if ( aTransformationMode == ReferenceImage )
86 Handle(HYDROData_Image) aRefImg = GetTrsfReferenceImage();
87 setPythonReferenceObject( theTreatedObjects, aResList, aRefImg, "SetTrsfReferenceImage" );
93 // Image is composed from other image(s)
95 QString anOperatorName = OperatorName();
96 if ( !anOperatorName.isEmpty() )
98 aResList << QString( "" );
100 aResList << QString( "%1.SetOperatorName( \"%2\" );" )
101 .arg( anImageName ).arg( anOperatorName );
103 ImageComposer_Operator* anImageOp =
104 HYDROData_OperationsFactory::Factory()->Operator( OperatorName() );
107 // Dump operation arguments
108 QString anOpArgsArrayName;
109 QStringList anOpArgs = anImageOp->dumpArgsToPython( anOpArgsArrayName );
110 if ( !anOpArgs.isEmpty() )
112 aResList << QString( "" );
113 aResList << anOpArgs;
115 aResList << QString( "" );
116 aResList << QString( "%1.SetArgs( %2 );" )
117 .arg( anImageName ).arg( anOpArgsArrayName );
122 int aNbReferences = NbReferences();
123 if ( aNbReferences > 0 )
125 aResList << QString( "" );
127 for ( int i = 0; i < aNbReferences; ++i )
129 Handle(HYDROData_Image) aRefImg = Handle(HYDROData_Image)::DownCast( Reference( i ) );
130 setPythonReferenceObject( theTreatedObjects, aResList, aRefImg, "AppendReference" );
134 // Necessary to update image in case of composed operator
135 aResList << QString( "" );
136 aResList << QString( "%1.Update();" ).arg( anImageName );
139 aResList << QString( "" );
144 void HYDROData_Image::Update()
146 bool anIsToUpdate = IsMustBeUpdated();
148 HYDROData_Entity::Update();
153 HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory();
155 ImageComposer_Operator* anOp = aFactory->Operator( OperatorName() );
156 if ( anOp ) // Update image if there is an operation
158 // Fill by arguments and process the operation
159 anOp->setBinArgs( Args() );
161 QVariant anObj1, anObj2;
162 int aNbReferences = NbReferences();
164 if ( aNbReferences > 0 )
166 // First referenced object
167 Handle(HYDROData_Entity) aRefObj = Reference( 0 );
168 if ( !aRefObj.IsNull() )
170 anObj1 = aRefObj->GetDataVariant();
171 if ( !anObj1.isNull() && anObj1.canConvert<ImageComposer_Image>() )
173 ImageComposer_Image anImage = anObj1.value<ImageComposer_Image>();
174 QTransform aTransform = anImage.transform();
175 SetTrsf( aTransform );
180 if ( aNbReferences > 1 )
182 // Second referenced object
183 Handle(HYDROData_Entity) aRefObj = Reference( 1 );
184 if ( !aRefObj.IsNull() )
185 anObj2 = aRefObj->GetDataVariant();
188 ImageComposer_Image aResImg = anOp->process( anObj1, anObj2 );
190 SetTrsf( aResImg.transform() );
192 else // Update image if it positioned relatively to other image
197 SetToUpdate( false );
200 QVariant HYDROData_Image::GetDataVariant()
202 QTransform aTransform = Trsf();
204 ImageComposer_Image anImage = Image();
205 anImage.setTransform( aTransform );
208 aVarData.setValue<ImageComposer_Image>( anImage );
213 HYDROData_SequenceOfObjects HYDROData_Image::GetAllReferenceObjects() const
215 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
217 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
218 if ( !aRefImage.IsNull() )
219 aResSeq.Append( aRefImage );
221 HYDROData_SequenceOfObjects aSeqRefObjects = GetReferenceObjects( 0 );
222 aResSeq.Append( aSeqRefObjects );
227 void HYDROData_Image::SetImage(const QImage& theImage)
229 if ( theImage.isNull() )
231 // for empty image remove all previously stored attributes
232 myLab.ForgetAttribute(TDataStd_IntegerArray::GetID());
233 myLab.ForgetAttribute(TDataStd_ByteArray::GetID());
239 // convert 8-bits images
240 if ( theImage.format() == QImage::Format_Indexed8 ) {
241 anImage = theImage.convertToFormat( QImage::Format_RGB32 );
246 // store width, height, bytes per line and format in integer array
247 Handle(TDataStd_IntegerArray) aParams;
248 if (!myLab.FindAttribute(TDataStd_IntegerArray::GetID(), aParams)) {
249 aParams = TDataStd_IntegerArray::Set(myLab, 1, 4);
251 aParams->SetValue(1, anImage.width());
252 aParams->SetValue(2, anImage.height());
253 aParams->SetValue(3, anImage.bytesPerLine());
254 aParams->SetValue(4, (int)(anImage.format()));
255 // store data of image in byte array
256 const char* aData = (const char*)(anImage.bits());
257 SaveByteArray(0, aData, anImage.byteCount());
263 bool HYDROData_Image::LoadImage( const QString& theFilePath )
265 QImage anImage( theFilePath );
267 return !anImage.isNull();
270 QImage HYDROData_Image::Image()
272 Handle(TDataStd_IntegerArray) aParams;
273 if (!myLab.FindAttribute(TDataStd_IntegerArray::GetID(), aParams))
274 return QImage(); // return empty image if there is no array
276 uchar* anArray = (uchar*)ByteArray(0, aLen);
278 return QImage(); // return empty image if there is no array
279 QImage aResult(anArray, aParams->Value(1), aParams->Value(2),
280 aParams->Value(3), QImage::Format(aParams->Value(4)));
284 void HYDROData_Image::SetFilePath( const QString& theFilePath )
286 TCollection_AsciiString anAsciiStr( theFilePath.toStdString().c_str() );
287 TDataStd_AsciiString::Set( myLab.FindChild( DataTag_FilePath ), anAsciiStr );
292 QString HYDROData_Image::GetFilePath() const
296 TDF_Label aLabel = myLab.FindChild( DataTag_FilePath, false );
297 if ( !aLabel.IsNull() )
299 Handle(TDataStd_AsciiString) anAsciiStr;
300 if ( aLabel.FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) )
301 aRes = QString( anAsciiStr->Get().ToCString() );
307 void HYDROData_Image::SetTrsf(const QTransform& theTrsf)
309 // locate 9 coeffs of matrix into the real array
310 Handle(TDataStd_RealArray) anArray;
311 if (!myLab.FindAttribute(TDataStd_RealArray::GetID(), anArray)) {
312 if (theTrsf.isIdentity()) return; // no need to store identity transformation
313 anArray = TDataStd_RealArray::Set(myLab, 1, 9);
315 anArray->SetValue(1, theTrsf.m11());
316 anArray->SetValue(2, theTrsf.m12());
317 anArray->SetValue(3, theTrsf.m13());
318 anArray->SetValue(4, theTrsf.m21());
319 anArray->SetValue(5, theTrsf.m22());
320 anArray->SetValue(6, theTrsf.m23());
321 anArray->SetValue(7, theTrsf.m31());
322 anArray->SetValue(8, theTrsf.m32());
323 anArray->SetValue(9, theTrsf.m33());
328 QTransform HYDROData_Image::Trsf() const
330 // get 9 coeffs of matrix from the real array
331 Handle(TDataStd_RealArray) anArray;
332 if (!myLab.FindAttribute(TDataStd_RealArray::GetID(), anArray))
333 return QTransform(); // return identity if there is no array
335 anArray->Value(1), anArray->Value(2), anArray->Value(3),
336 anArray->Value(4), anArray->Value(5), anArray->Value(6),
337 anArray->Value(7), anArray->Value(8), anArray->Value(9));
341 void HYDROData_Image::UpdateTrsf()
343 QPoint aPointA, aPointB, aPointC;
344 if ( !GetLocalPoints( aPointA, aPointB, aPointC ) )
347 TransformationMode aTrsfMode;
348 QPointF aTrsfPointA, aTrsfPointB, aTrsfPointC;
349 if ( !GetGlobalPoints( aTrsfMode, aTrsfPointA, aTrsfPointB, aTrsfPointC ) )
352 QTransform aRefTransform;
353 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
355 bool anIsRefImage = aTrsfMode == ReferenceImage;
358 if ( aRefImage.IsNull() )
361 aRefTransform = aRefImage->Trsf();
364 bool anIsByTwoPoints = IsByTwoPoints();
366 // Convert lambert coordinates to cartesian
367 if ( aTrsfMode == ManualGeodesic )
369 double aXCart = 0, aYCart = 0;
371 HYDROData_Lambert93::toXY( aTrsfPointA.y(), aTrsfPointA.x(), aXCart, aYCart );
372 aTrsfPointA = QPointF( aXCart, aYCart );
374 HYDROData_Lambert93::toXY( aTrsfPointB.y(), aTrsfPointB.x(), aXCart, aYCart );
375 aTrsfPointB = QPointF( aXCart, aYCart );
377 if ( !anIsByTwoPoints )
379 HYDROData_Lambert93::toXY( aTrsfPointC.y(), aTrsfPointC.x(), aXCart, aYCart );
380 aTrsfPointC = QPointF( aXCart, aYCart );
384 // generate third points if needed
385 if ( anIsByTwoPoints )
387 aPointC = generateThirdPoint( aPointA, aPointB, true ).toPoint();
388 aTrsfPointC = generateThirdPoint( aTrsfPointA, aTrsfPointB, anIsRefImage );
391 int xa = aPointA.x();
392 int ya = aPointA.y();
393 int xb = aPointB.x();
394 int yb = aPointB.y();
395 int xc = aPointC.x();
396 int yc = aPointC.y();
398 double xta = aTrsfPointA.x();
399 double yta = aTrsfPointA.y();
400 double xtb = aTrsfPointB.x();
401 double ytb = aTrsfPointB.y();
402 double xtc = aTrsfPointC.x();
403 double ytc = aTrsfPointC.y();
405 // first, check that three input points don't belong to a single line
406 if( ( yb - ya ) * ( xc - xa ) == ( yc - ya ) * ( xb - xa ) )
409 // the same check for the reference points
410 if( anIsRefImage && ( ( ytb - yta ) * ( xtc - xta ) == ( ytc - yta ) * ( xtb - xta ) ) )
413 QTransform aTransform1( xa, ya, 1, xb, yb, 1, xc, yc, 1 );
414 QTransform aTransform2( xta, yta, 1, xtb, ytb, 1, xtc, ytc, 1 );
416 bool anIsInvertible = false;
417 QTransform aTransform1Inverted = aTransform1.inverted( &anIsInvertible );
418 if( !anIsInvertible )
421 QTransform aResTransform = aTransform1Inverted * aTransform2;
423 aResTransform *= aRefTransform;
425 SetTrsf( aResTransform );
428 bool HYDROData_Image::IsByTwoPoints() const
430 if ( !HasLocalPoints() || !HasGlobalPoints() )
433 QPoint aPointA, aPointB, aPointC;
434 GetLocalPoints( aPointA, aPointB, aPointC );
436 return aPointC.x() < 0 && aPointC.y() < 0;
439 bool HYDROData_Image::HasReferences() const
441 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
442 int aNbReferences = NbReferences();
444 return !aRefImage.IsNull() || aNbReferences > 0;
447 void HYDROData_Image::RemoveAllReferences()
449 if ( !HasReferences() )
452 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
453 if ( !aRefImage.IsNull() )
455 RemoveTrsfReferenceImage();
460 SetOperatorName( "" );
462 SetIsSelfSplitted( false );
465 bool anIsByTwoPoints = IsByTwoPoints();
467 QImage anImage = Image();
468 if ( anImage.isNull() )
470 SetToUpdate( false );
474 // Set local points to default position
475 QPoint aLocalPointA = QPoint( 0, 0 );
476 QPoint aLocalPointB = QPoint( anImage.width(), 0 );
477 QPoint aLocalPointC = anIsByTwoPoints ? QPoint( INT_MIN, INT_MIN ) : QPoint( 0, anImage.height() );
479 SetLocalPoints( aLocalPointA, aLocalPointB, aLocalPointC, false );
481 // Calculate global points
482 QTransform aTransform = Trsf();
484 QPointF aTrsfPointA = QPointF( aTransform.map( aLocalPointA ) );
485 QPointF aTrsfPointB = QPointF( aTransform.map( aLocalPointB ) );
486 QPointF aTrsfPointC = anIsByTwoPoints ? QPointF( INT_MIN, INT_MIN ) :
487 QPointF( aTransform.map( aLocalPointC ) );
489 SetGlobalPoints( ManualCartesian, aTrsfPointA, aTrsfPointB, aTrsfPointC );
491 SetToUpdate( false );
494 void HYDROData_Image::SetLocalPoints( const QPoint& thePointA,
495 const QPoint& thePointB,
496 const QPoint& thePointC,
497 const bool theIsUpdate )
499 Handle(TDataStd_RealArray) anArray;
500 if ( !myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
501 anArray = TDataStd_RealArray::Set( myLab.FindChild( DataTag_TrsfPoints ), 1, 12 );
503 anArray->SetValue( 1, thePointA.x() );
504 anArray->SetValue( 2, thePointA.y() );
505 anArray->SetValue( 3, thePointB.x() );
506 anArray->SetValue( 4, thePointB.y() );
507 anArray->SetValue( 5, thePointC.x() );
508 anArray->SetValue( 6, thePointC.y() );
510 TDataStd_UAttribute::Set( myLab.FindChild( DataTag_TrsfPoints ), GUID_HAS_LOCAL_POINTS );
518 bool HYDROData_Image::GetLocalPoints( QPoint& thePointA,
520 QPoint& thePointC ) const
522 if ( !HasLocalPoints() )
525 Handle(TDataStd_RealArray) anArray;
526 myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray );
528 thePointA = QPointF( anArray->Value( 1 ), anArray->Value( 2 ) ).toPoint();
529 thePointB = QPointF( anArray->Value( 3 ), anArray->Value( 4 ) ).toPoint();
530 thePointC = QPointF( anArray->Value( 5 ), anArray->Value( 6 ) ).toPoint();
535 bool HYDROData_Image::HasLocalPoints() const
537 TDF_Label aLabel = myLab.FindChild( DataTag_TrsfPoints, false );
538 if ( aLabel.IsNull() || !aLabel.IsAttribute( GUID_HAS_LOCAL_POINTS ) )
541 Handle(TDataStd_RealArray) anArray;
542 return aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray );
546 void HYDROData_Image::SetGlobalPoints( const TransformationMode& theMode,
547 const QPointF& thePointA,
548 const QPointF& thePointB,
549 const QPointF& thePointC,
550 const bool theIsUpdate )
552 Handle(TDataStd_RealArray) anArray;
553 if ( !myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
554 anArray = TDataStd_RealArray::Set( myLab.FindChild( DataTag_TrsfPoints ), 1, 12 );
556 anArray->SetValue( 7, thePointA.x() );
557 anArray->SetValue( 8, thePointA.y() );
558 anArray->SetValue( 9, thePointB.x() );
559 anArray->SetValue( 10, thePointB.y() );
560 anArray->SetValue( 11, thePointC.x() );
561 anArray->SetValue( 12, thePointC.y() );
563 SetTrsfMode( theMode );
565 TDataStd_UAttribute::Set( myLab.FindChild( DataTag_TrsfPoints ), GUID_HAS_GLOBAL_POINTS );
573 bool HYDROData_Image::GetGlobalPoints( TransformationMode& theMode,
576 QPointF& thePointC ) const
578 if ( !HasGlobalPoints() )
581 theMode = GetTrsfMode();
583 Handle(TDataStd_RealArray) anArray;
584 myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray );
586 thePointA = QPointF( anArray->Value( 7 ), anArray->Value( 8 ) );
587 thePointB = QPointF( anArray->Value( 9 ), anArray->Value( 10 ) );
588 thePointC = QPointF( anArray->Value( 11 ), anArray->Value( 12 ) );
593 bool HYDROData_Image::SetGlobalPointsFromFile( const QString& theFileName )
597 // Try to open the file
598 QFile aFile( theFileName );
599 if ( !aFile.exists() || !aFile.open( QIODevice::ReadOnly ) ) {
603 QPointF aPointA, aPointB;
604 double aXmin, anYmin, aXmax, anYmax;
605 aXmin = anYmin = aXmax = anYmax = -1;
607 while ( !aFile.atEnd() &&
608 ( aXmin < 0 || anYmin < 0 || aXmax < 0 || anYmax < 0 ) ) {
610 QString aLine = aFile.readLine().simplified();
611 aLine.replace( " ", "" );
612 if ( aLine.isEmpty() ) {
616 // Try to read double value after ":"
617 bool isDoubleOk = false;
618 double aDoubleValue = -1;
619 QStringList aValues = aLine.split( ":", QString::SkipEmptyParts );
620 if ( aValues.count() == 2 ) {
621 aDoubleValue = aValues.last().toDouble( &isDoubleOk );
626 boost::math::isnan( aDoubleValue ) ||
627 boost::math::isinf( aDoubleValue ) ) {
632 if ( aLine.startsWith( "Xminimum" ) ) {
633 aXmin = aDoubleValue;
635 else if ( aLine.startsWith( "Yminimum" ) ) {
636 anYmin = aDoubleValue;
638 else if ( aLine.startsWith( "Xmaximum" ) ) {
639 aXmax = aDoubleValue;
641 else if ( aLine.startsWith( "Ymaximum" ) ) {
642 anYmax = aDoubleValue;
649 if ( aXmin >= 0 && anYmin >= 0 ) {
650 aPointA.setX( aXmin );
651 aPointA.setY( anYmin );
654 if ( aXmax >= 0 && anYmax >= 0 ) {
655 aPointB.setX( aXmax );
656 aPointB.setY( anYmax );
659 if ( !aPointA.isNull() && !aPointB.isNull() ) {
660 SetGlobalPoints( ManualCartesian, aPointA, aPointB );
667 bool HYDROData_Image::HasGlobalPoints() const
669 TDF_Label aLabel = myLab.FindChild( DataTag_TrsfPoints, false );
670 if ( aLabel.IsNull() || !aLabel.IsAttribute( GUID_HAS_GLOBAL_POINTS ) )
673 Handle(TDataStd_RealArray) anArray;
674 return aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray );
677 void HYDROData_Image::SetReferencePoints( const Handle(HYDROData_Image)& theRefImage,
678 const QPointF& thePointA,
679 const QPointF& thePointB,
680 const QPointF& thePointC,
681 const bool theIsUpdate )
683 SetTrsfReferenceImage( theRefImage );
684 SetGlobalPoints( ReferenceImage, thePointA, thePointB, thePointC, theIsUpdate );
687 bool HYDROData_Image::GetReferencePoints( Handle(HYDROData_Image)& theRefImage,
690 QPointF& thePointC ) const
692 if ( !HasReferencePoints() )
695 theRefImage = GetTrsfReferenceImage();
697 TransformationMode aMode;
698 GetGlobalPoints( aMode, thePointA, thePointB, thePointC );
703 bool HYDROData_Image::HasReferencePoints() const
705 if ( !HasGlobalPoints() )
708 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
709 if ( aRefImage.IsNull() )
712 TransformationMode aTrsfMode = GetTrsfMode();
713 if ( aTrsfMode != ReferenceImage )
719 void HYDROData_Image::SetTrsfMode( const TransformationMode& theMode )
721 TDataStd_Integer::Set( myLab.FindChild( DataTag_TrsfMode ), (int)theMode );
725 HYDROData_Image::TransformationMode HYDROData_Image::GetTrsfMode() const
727 TransformationMode aResMode = ManualGeodesic;
729 TDF_Label aLabel = myLab.FindChild( DataTag_TrsfPoints, false );
730 if ( !aLabel.IsNull() )
732 Handle(TDataStd_Integer) aMode;
733 if ( myLab.FindChild( DataTag_TrsfMode ).FindAttribute( TDataStd_Integer::GetID(), aMode ) )
734 aResMode = (TransformationMode)aMode->Get();
740 void HYDROData_Image::SetTrsfReferenceImage( const Handle(HYDROData_Image)& theRefImage )
742 SetReferenceObject( theRefImage, DataTag_TrsfImage );
746 Handle(HYDROData_Image) HYDROData_Image::GetTrsfReferenceImage() const
748 return Handle(HYDROData_Image)::DownCast( GetReferenceObject( DataTag_TrsfImage ) );
751 void HYDROData_Image::RemoveTrsfReferenceImage()
753 RemoveReferenceObject( DataTag_TrsfImage );
757 void HYDROData_Image::AppendReference( const Handle(HYDROData_Entity)& theReferenced )
759 AddReferenceObject( theReferenced, 0 );
763 int HYDROData_Image::NbReferences() const
765 return NbReferenceObjects( 0 );
768 Handle(HYDROData_Entity) HYDROData_Image::Reference( const int theIndex ) const
770 return GetReferenceObject( 0, theIndex );
773 void HYDROData_Image::ChangeReference(
774 const int theIndex, Handle(HYDROData_Entity) theReferenced)
776 SetReferenceObject( theReferenced, 0, theIndex );
780 void HYDROData_Image::RemoveReference(const int theIndex)
782 RemoveReferenceObject( 0, theIndex );
786 void HYDROData_Image::ClearReferences()
788 ClearReferenceObjects( 0 );
792 void HYDROData_Image::SetOperatorName( const QString theOpName )
794 TCollection_AsciiString anAsciiStr( theOpName.toStdString().c_str() );
795 TDataStd_AsciiString::Set( myLab.FindChild( DataTag_Operator ), anAsciiStr );
799 QString HYDROData_Image::OperatorName() const
803 TDF_Label aLabel = myLab.FindChild( DataTag_Operator, false );
804 if ( !aLabel.IsNull() )
806 Handle(TDataStd_AsciiString) anAsciiStr;
807 if ( aLabel.FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) )
808 aRes = QString( anAsciiStr->Get().ToCString() );
814 void HYDROData_Image::SetArgs(const QByteArray& theArgs)
816 SaveByteArray(DataTag_Operator, theArgs.constData(), theArgs.length());
820 QByteArray HYDROData_Image::Args() const
823 const char* aData = ByteArray(DataTag_Operator, aLen);
826 return QByteArray(aData, aLen);
829 void HYDROData_Image::SetIsSelfSplitted(bool theFlag)
832 TDataStd_UAttribute::Set(myLab, GUID_SELF_SPLITTED);
834 myLab.ForgetAttribute(GUID_SELF_SPLITTED);
839 bool HYDROData_Image::IsSelfSplitted() const
841 return myLab.IsAttribute(GUID_SELF_SPLITTED);
844 QPointF HYDROData_Image::generateThirdPoint( const QPointF& thePointA,
845 const QPointF& thePointB,
846 const bool& theIsLocal ) const
848 // Rotate vector to 90 degrees : clockwise - for local
849 // counterclockwise - for global
850 const double aTheta = theIsLocal ? -M_PI_2 : M_PI_2;
854 // Move to (0,0) for correct rotation
855 double x = thePointB.x() - thePointA.x();
856 double y = thePointB.y() - thePointA.y();
858 aResPoint.setX( x * cos( aTheta ) - y * sin( aTheta ) );
859 aResPoint.setY( x * sin( aTheta ) + y * cos( aTheta ) );
861 // Move back to origin position
862 aResPoint.setX( aResPoint.x() + thePointA.x() );
863 aResPoint.setY( aResPoint.y() + thePointA.y() );