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 = HYDROData_Entity::DumpToPython( theTreatedObjects );
43 QString anImageName = GetName();
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 );
142 void HYDROData_Image::Update()
144 bool anIsToUpdate = IsMustBeUpdated();
146 HYDROData_Entity::Update();
151 HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory();
153 ImageComposer_Operator* anOp = aFactory->Operator( OperatorName() );
154 if ( anOp ) // Update image if there is an operation
156 // Fill by arguments and process the operation
157 anOp->setBinArgs( Args() );
159 QVariant anObj1, anObj2;
160 int aNbReferences = NbReferences();
162 if ( aNbReferences > 0 )
164 // First referenced object
165 Handle(HYDROData_Entity) aRefObj = Reference( 0 );
166 if ( !aRefObj.IsNull() )
168 anObj1 = aRefObj->GetDataVariant();
169 if ( !anObj1.isNull() && anObj1.canConvert<ImageComposer_Image>() )
171 ImageComposer_Image anImage = anObj1.value<ImageComposer_Image>();
172 QTransform aTransform = anImage.transform();
173 SetTrsf( aTransform );
178 if ( aNbReferences > 1 )
180 // Second referenced object
181 Handle(HYDROData_Entity) aRefObj = Reference( 1 );
182 if ( !aRefObj.IsNull() )
183 anObj2 = aRefObj->GetDataVariant();
186 ImageComposer_Image aResImg = anOp->process( anObj1, anObj2 );
188 SetTrsf( aResImg.transform() );
190 else // Update image if it positioned relatively to other image
195 SetToUpdate( false );
198 QVariant HYDROData_Image::GetDataVariant()
200 QTransform aTransform = Trsf();
202 ImageComposer_Image anImage = Image();
203 anImage.setTransform( aTransform );
206 aVarData.setValue<ImageComposer_Image>( anImage );
211 HYDROData_SequenceOfObjects HYDROData_Image::GetAllReferenceObjects() const
213 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
215 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
216 if ( !aRefImage.IsNull() )
217 aResSeq.Append( aRefImage );
219 HYDROData_SequenceOfObjects aSeqRefObjects = GetReferenceObjects( 0 );
220 aResSeq.Append( aSeqRefObjects );
225 void HYDROData_Image::SetImage(const QImage& theImage)
227 if ( theImage.isNull() )
229 // for empty image remove all previously stored attributes
230 myLab.ForgetAttribute(TDataStd_IntegerArray::GetID());
231 myLab.ForgetAttribute(TDataStd_ByteArray::GetID());
237 // convert 8-bits images
238 if ( theImage.format() == QImage::Format_Indexed8 ) {
239 anImage = theImage.convertToFormat( QImage::Format_RGB32 );
244 // store width, height, bytes per line and format in integer array
245 Handle(TDataStd_IntegerArray) aParams;
246 if (!myLab.FindAttribute(TDataStd_IntegerArray::GetID(), aParams)) {
247 aParams = TDataStd_IntegerArray::Set(myLab, 1, 4);
249 aParams->SetValue(1, anImage.width());
250 aParams->SetValue(2, anImage.height());
251 aParams->SetValue(3, anImage.bytesPerLine());
252 aParams->SetValue(4, (int)(anImage.format()));
253 // store data of image in byte array
254 const char* aData = (const char*)(anImage.bits());
255 SaveByteArray(0, aData, anImage.byteCount());
261 bool HYDROData_Image::LoadImage( const QString& theFilePath )
263 QImage anImage( theFilePath );
265 return !anImage.isNull();
268 QImage HYDROData_Image::Image()
270 Handle(TDataStd_IntegerArray) aParams;
271 if (!myLab.FindAttribute(TDataStd_IntegerArray::GetID(), aParams))
272 return QImage(); // return empty image if there is no array
274 uchar* anArray = (uchar*)ByteArray(0, aLen);
276 return QImage(); // return empty image if there is no array
277 QImage aResult(anArray, aParams->Value(1), aParams->Value(2),
278 aParams->Value(3), QImage::Format(aParams->Value(4)));
282 void HYDROData_Image::SetFilePath( const QString& theFilePath )
284 TCollection_AsciiString anAsciiStr( theFilePath.toStdString().c_str() );
285 TDataStd_AsciiString::Set( myLab.FindChild( DataTag_FilePath ), anAsciiStr );
290 QString HYDROData_Image::GetFilePath() const
294 TDF_Label aLabel = myLab.FindChild( DataTag_FilePath, false );
295 if ( !aLabel.IsNull() )
297 Handle(TDataStd_AsciiString) anAsciiStr;
298 if ( aLabel.FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) )
299 aRes = QString( anAsciiStr->Get().ToCString() );
305 void HYDROData_Image::SetTrsf(const QTransform& theTrsf)
307 // locate 9 coeffs of matrix into the real array
308 Handle(TDataStd_RealArray) anArray;
309 if (!myLab.FindAttribute(TDataStd_RealArray::GetID(), anArray)) {
310 if (theTrsf.isIdentity()) return; // no need to store identity transformation
311 anArray = TDataStd_RealArray::Set(myLab, 1, 9);
313 anArray->SetValue(1, theTrsf.m11());
314 anArray->SetValue(2, theTrsf.m12());
315 anArray->SetValue(3, theTrsf.m13());
316 anArray->SetValue(4, theTrsf.m21());
317 anArray->SetValue(5, theTrsf.m22());
318 anArray->SetValue(6, theTrsf.m23());
319 anArray->SetValue(7, theTrsf.m31());
320 anArray->SetValue(8, theTrsf.m32());
321 anArray->SetValue(9, theTrsf.m33());
326 QTransform HYDROData_Image::Trsf() const
328 // get 9 coeffs of matrix from the real array
329 Handle(TDataStd_RealArray) anArray;
330 if (!myLab.FindAttribute(TDataStd_RealArray::GetID(), anArray))
331 return QTransform(); // return identity if there is no array
333 anArray->Value(1), anArray->Value(2), anArray->Value(3),
334 anArray->Value(4), anArray->Value(5), anArray->Value(6),
335 anArray->Value(7), anArray->Value(8), anArray->Value(9));
339 void HYDROData_Image::UpdateTrsf()
341 QPoint aPointA, aPointB, aPointC;
342 if ( !GetLocalPoints( aPointA, aPointB, aPointC ) )
345 TransformationMode aTrsfMode;
346 QPointF aTrsfPointA, aTrsfPointB, aTrsfPointC;
347 if ( !GetGlobalPoints( aTrsfMode, aTrsfPointA, aTrsfPointB, aTrsfPointC ) )
350 QTransform aRefTransform;
351 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
353 bool anIsRefImage = aTrsfMode == ReferenceImage;
356 if ( aRefImage.IsNull() )
359 aRefTransform = aRefImage->Trsf();
362 bool anIsByTwoPoints = IsByTwoPoints();
364 // Convert lambert coordinates to cartesian
365 if ( aTrsfMode == ManualGeodesic )
367 double aXCart = 0, aYCart = 0;
369 HYDROData_Lambert93::toXY( aTrsfPointA.y(), aTrsfPointA.x(), aXCart, aYCart );
370 aTrsfPointA = QPointF( aXCart, aYCart );
372 HYDROData_Lambert93::toXY( aTrsfPointB.y(), aTrsfPointB.x(), aXCart, aYCart );
373 aTrsfPointB = QPointF( aXCart, aYCart );
375 if ( !anIsByTwoPoints )
377 HYDROData_Lambert93::toXY( aTrsfPointC.y(), aTrsfPointC.x(), aXCart, aYCart );
378 aTrsfPointC = QPointF( aXCart, aYCart );
382 // generate third points if needed
383 if ( anIsByTwoPoints )
385 aPointC = generateThirdPoint( aPointA, aPointB, true ).toPoint();
386 aTrsfPointC = generateThirdPoint( aTrsfPointA, aTrsfPointB, anIsRefImage );
389 int xa = aPointA.x();
390 int ya = aPointA.y();
391 int xb = aPointB.x();
392 int yb = aPointB.y();
393 int xc = aPointC.x();
394 int yc = aPointC.y();
396 double xta = aTrsfPointA.x();
397 double yta = aTrsfPointA.y();
398 double xtb = aTrsfPointB.x();
399 double ytb = aTrsfPointB.y();
400 double xtc = aTrsfPointC.x();
401 double ytc = aTrsfPointC.y();
403 // first, check that three input points don't belong to a single line
404 if( ( yb - ya ) * ( xc - xa ) == ( yc - ya ) * ( xb - xa ) )
407 // the same check for the reference points
408 if( anIsRefImage && ( ( ytb - yta ) * ( xtc - xta ) == ( ytc - yta ) * ( xtb - xta ) ) )
411 QTransform aTransform1( xa, ya, 1, xb, yb, 1, xc, yc, 1 );
412 QTransform aTransform2( xta, yta, 1, xtb, ytb, 1, xtc, ytc, 1 );
414 bool anIsInvertible = false;
415 QTransform aTransform1Inverted = aTransform1.inverted( &anIsInvertible );
416 if( !anIsInvertible )
419 QTransform aResTransform = aTransform1Inverted * aTransform2;
421 aResTransform *= aRefTransform;
423 SetTrsf( aResTransform );
426 bool HYDROData_Image::IsByTwoPoints() const
428 if ( !HasLocalPoints() || !HasGlobalPoints() )
431 QPoint aPointA, aPointB, aPointC;
432 GetLocalPoints( aPointA, aPointB, aPointC );
434 return aPointC.x() < 0 && aPointC.y() < 0;
437 bool HYDROData_Image::HasReferences() const
439 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
440 int aNbReferences = NbReferences();
442 return !aRefImage.IsNull() || aNbReferences > 0;
445 void HYDROData_Image::RemoveAllReferences()
447 if ( !HasReferences() )
450 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
451 if ( !aRefImage.IsNull() )
453 RemoveTrsfReferenceImage();
458 SetOperatorName( "" );
460 SetIsSelfSplitted( false );
463 bool anIsByTwoPoints = IsByTwoPoints();
465 QImage anImage = Image();
466 if ( anImage.isNull() )
468 SetToUpdate( false );
472 // Set local points to default position
473 QPoint aLocalPointA = QPoint( 0, 0 );
474 QPoint aLocalPointB = QPoint( anImage.width(), 0 );
475 QPoint aLocalPointC = anIsByTwoPoints ? QPoint( INT_MIN, INT_MIN ) : QPoint( 0, anImage.height() );
477 SetLocalPoints( aLocalPointA, aLocalPointB, aLocalPointC, false );
479 // Calculate global points
480 QTransform aTransform = Trsf();
482 QPointF aTrsfPointA = QPointF( aTransform.map( aLocalPointA ) );
483 QPointF aTrsfPointB = QPointF( aTransform.map( aLocalPointB ) );
484 QPointF aTrsfPointC = anIsByTwoPoints ? QPointF( INT_MIN, INT_MIN ) :
485 QPointF( aTransform.map( aLocalPointC ) );
487 SetGlobalPoints( ManualCartesian, aTrsfPointA, aTrsfPointB, aTrsfPointC );
489 SetToUpdate( false );
492 void HYDROData_Image::SetLocalPoints( const QPoint& thePointA,
493 const QPoint& thePointB,
494 const QPoint& thePointC,
495 const bool theIsUpdate )
497 Handle(TDataStd_RealArray) anArray;
498 if ( !myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
499 anArray = TDataStd_RealArray::Set( myLab.FindChild( DataTag_TrsfPoints ), 1, 12 );
501 anArray->SetValue( 1, thePointA.x() );
502 anArray->SetValue( 2, thePointA.y() );
503 anArray->SetValue( 3, thePointB.x() );
504 anArray->SetValue( 4, thePointB.y() );
505 anArray->SetValue( 5, thePointC.x() );
506 anArray->SetValue( 6, thePointC.y() );
508 TDataStd_UAttribute::Set( myLab.FindChild( DataTag_TrsfPoints ), GUID_HAS_LOCAL_POINTS );
516 bool HYDROData_Image::GetLocalPoints( QPoint& thePointA,
518 QPoint& thePointC ) const
520 if ( !HasLocalPoints() )
523 Handle(TDataStd_RealArray) anArray;
524 myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray );
526 thePointA = QPointF( anArray->Value( 1 ), anArray->Value( 2 ) ).toPoint();
527 thePointB = QPointF( anArray->Value( 3 ), anArray->Value( 4 ) ).toPoint();
528 thePointC = QPointF( anArray->Value( 5 ), anArray->Value( 6 ) ).toPoint();
533 bool HYDROData_Image::HasLocalPoints() const
535 TDF_Label aLabel = myLab.FindChild( DataTag_TrsfPoints, false );
536 if ( aLabel.IsNull() || !aLabel.IsAttribute( GUID_HAS_LOCAL_POINTS ) )
539 Handle(TDataStd_RealArray) anArray;
540 return aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray );
544 void HYDROData_Image::SetGlobalPoints( const TransformationMode& theMode,
545 const QPointF& thePointA,
546 const QPointF& thePointB,
547 const QPointF& thePointC,
548 const bool theIsUpdate )
550 Handle(TDataStd_RealArray) anArray;
551 if ( !myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
552 anArray = TDataStd_RealArray::Set( myLab.FindChild( DataTag_TrsfPoints ), 1, 12 );
554 anArray->SetValue( 7, thePointA.x() );
555 anArray->SetValue( 8, thePointA.y() );
556 anArray->SetValue( 9, thePointB.x() );
557 anArray->SetValue( 10, thePointB.y() );
558 anArray->SetValue( 11, thePointC.x() );
559 anArray->SetValue( 12, thePointC.y() );
561 SetTrsfMode( theMode );
563 TDataStd_UAttribute::Set( myLab.FindChild( DataTag_TrsfPoints ), GUID_HAS_GLOBAL_POINTS );
571 bool HYDROData_Image::GetGlobalPoints( TransformationMode& theMode,
574 QPointF& thePointC ) const
576 if ( !HasGlobalPoints() )
579 theMode = GetTrsfMode();
581 Handle(TDataStd_RealArray) anArray;
582 myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray );
584 thePointA = QPointF( anArray->Value( 7 ), anArray->Value( 8 ) );
585 thePointB = QPointF( anArray->Value( 9 ), anArray->Value( 10 ) );
586 thePointC = QPointF( anArray->Value( 11 ), anArray->Value( 12 ) );
591 bool HYDROData_Image::SetGlobalPointsFromFile( const QString& theFileName )
595 // Try to open the file
596 QFile aFile( theFileName );
597 if ( !aFile.exists() || !aFile.open( QIODevice::ReadOnly ) ) {
601 QPointF aPointA, aPointB;
602 double aXmin, anYmin, aXmax, anYmax;
603 aXmin = anYmin = aXmax = anYmax = -1;
605 while ( !aFile.atEnd() &&
606 ( aXmin < 0 || anYmin < 0 || aXmax < 0 || anYmax < 0 ) ) {
608 QString aLine = aFile.readLine().simplified();
609 aLine.replace( " ", "" );
610 if ( aLine.isEmpty() ) {
614 // Try to read double value after ":"
615 bool isDoubleOk = false;
616 double aDoubleValue = -1;
617 QStringList aValues = aLine.split( ":", QString::SkipEmptyParts );
618 if ( aValues.count() == 2 ) {
619 aDoubleValue = aValues.last().toDouble( &isDoubleOk );
624 boost::math::isnan( aDoubleValue ) ||
625 boost::math::isinf( aDoubleValue ) ) {
630 if ( aLine.startsWith( "Xminimum" ) ) {
631 aXmin = aDoubleValue;
633 else if ( aLine.startsWith( "Yminimum" ) ) {
634 anYmin = aDoubleValue;
636 else if ( aLine.startsWith( "Xmaximum" ) ) {
637 aXmax = aDoubleValue;
639 else if ( aLine.startsWith( "Ymaximum" ) ) {
640 anYmax = aDoubleValue;
647 if ( aXmin >= 0 && anYmin >= 0 ) {
648 aPointA.setX( aXmin );
649 aPointA.setY( anYmin );
652 if ( aXmax >= 0 && anYmax >= 0 ) {
653 aPointB.setX( aXmax );
654 aPointB.setY( anYmax );
657 if ( !aPointA.isNull() && !aPointB.isNull() ) {
658 SetGlobalPoints( ManualCartesian, aPointA, aPointB );
665 bool HYDROData_Image::HasGlobalPoints() const
667 TDF_Label aLabel = myLab.FindChild( DataTag_TrsfPoints, false );
668 if ( aLabel.IsNull() || !aLabel.IsAttribute( GUID_HAS_GLOBAL_POINTS ) )
671 Handle(TDataStd_RealArray) anArray;
672 return aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray );
675 void HYDROData_Image::SetReferencePoints( const Handle(HYDROData_Image)& theRefImage,
676 const QPointF& thePointA,
677 const QPointF& thePointB,
678 const QPointF& thePointC,
679 const bool theIsUpdate )
681 SetTrsfReferenceImage( theRefImage );
682 SetGlobalPoints( ReferenceImage, thePointA, thePointB, thePointC, theIsUpdate );
685 bool HYDROData_Image::GetReferencePoints( Handle(HYDROData_Image)& theRefImage,
688 QPointF& thePointC ) const
690 if ( !HasReferencePoints() )
693 theRefImage = GetTrsfReferenceImage();
695 TransformationMode aMode;
696 GetGlobalPoints( aMode, thePointA, thePointB, thePointC );
701 bool HYDROData_Image::HasReferencePoints() const
703 if ( !HasGlobalPoints() )
706 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
707 if ( aRefImage.IsNull() )
710 TransformationMode aTrsfMode = GetTrsfMode();
711 if ( aTrsfMode != ReferenceImage )
717 void HYDROData_Image::SetTrsfMode( const TransformationMode& theMode )
719 TDataStd_Integer::Set( myLab.FindChild( DataTag_TrsfMode ), (int)theMode );
723 HYDROData_Image::TransformationMode HYDROData_Image::GetTrsfMode() const
725 TransformationMode aResMode = ManualGeodesic;
727 TDF_Label aLabel = myLab.FindChild( DataTag_TrsfPoints, false );
728 if ( !aLabel.IsNull() )
730 Handle(TDataStd_Integer) aMode;
731 if ( myLab.FindChild( DataTag_TrsfMode ).FindAttribute( TDataStd_Integer::GetID(), aMode ) )
732 aResMode = (TransformationMode)aMode->Get();
738 void HYDROData_Image::SetTrsfReferenceImage( const Handle(HYDROData_Image)& theRefImage )
740 SetReferenceObject( theRefImage, DataTag_TrsfImage );
744 Handle(HYDROData_Image) HYDROData_Image::GetTrsfReferenceImage() const
746 return Handle(HYDROData_Image)::DownCast( GetReferenceObject( DataTag_TrsfImage ) );
749 void HYDROData_Image::RemoveTrsfReferenceImage()
751 RemoveReferenceObject( DataTag_TrsfImage );
755 void HYDROData_Image::AppendReference( const Handle(HYDROData_Entity)& theReferenced )
757 AddReferenceObject( theReferenced, 0 );
761 int HYDROData_Image::NbReferences() const
763 return NbReferenceObjects( 0 );
766 Handle(HYDROData_Entity) HYDROData_Image::Reference( const int theIndex ) const
768 return GetReferenceObject( 0, theIndex );
771 void HYDROData_Image::ChangeReference(
772 const int theIndex, Handle(HYDROData_Entity) theReferenced)
774 SetReferenceObject( theReferenced, 0, theIndex );
778 void HYDROData_Image::RemoveReference(const int theIndex)
780 RemoveReferenceObject( 0, theIndex );
784 void HYDROData_Image::ClearReferences()
786 ClearReferenceObjects( 0 );
790 void HYDROData_Image::SetOperatorName( const QString theOpName )
792 TCollection_AsciiString anAsciiStr( theOpName.toStdString().c_str() );
793 TDataStd_AsciiString::Set( myLab.FindChild( DataTag_Operator ), anAsciiStr );
797 QString HYDROData_Image::OperatorName() const
801 TDF_Label aLabel = myLab.FindChild( DataTag_Operator, false );
802 if ( !aLabel.IsNull() )
804 Handle(TDataStd_AsciiString) anAsciiStr;
805 if ( aLabel.FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) )
806 aRes = QString( anAsciiStr->Get().ToCString() );
812 void HYDROData_Image::SetArgs(const QByteArray& theArgs)
814 SaveByteArray(DataTag_Operator, theArgs.constData(), theArgs.length());
818 QByteArray HYDROData_Image::Args() const
821 const char* aData = ByteArray(DataTag_Operator, aLen);
824 return QByteArray(aData, aLen);
827 void HYDROData_Image::SetIsSelfSplitted(bool theFlag)
830 TDataStd_UAttribute::Set(myLab, GUID_SELF_SPLITTED);
832 myLab.ForgetAttribute(GUID_SELF_SPLITTED);
837 bool HYDROData_Image::IsSelfSplitted() const
839 return myLab.IsAttribute(GUID_SELF_SPLITTED);
842 QPointF HYDROData_Image::generateThirdPoint( const QPointF& thePointA,
843 const QPointF& thePointB,
844 const bool& theIsLocal ) const
846 // Rotate vector to 90 degrees : clockwise - for local
847 // counterclockwise - for global
848 const double aTheta = theIsLocal ? -M_PI_2 : M_PI_2;
852 // Move to (0,0) for correct rotation
853 double x = thePointB.x() - thePointA.x();
854 double y = thePointB.y() - thePointA.y();
856 aResPoint.setX( x * cos( aTheta ) - y * sin( aTheta ) );
857 aResPoint.setY( x * sin( aTheta ) + y * cos( aTheta ) );
859 // Move back to origin position
860 aResPoint.setX( aResPoint.x() + thePointA.x() );
861 aResPoint.setY( aResPoint.y() + thePointA.y() );