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 #define PYTHON_IMAGE_ID "KIND_IMAGE"
30 IMPLEMENT_STANDARD_HANDLE(HYDROData_Image, HYDROData_Entity)
31 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Image, HYDROData_Entity)
33 HYDROData_Image::HYDROData_Image()
38 HYDROData_Image::~HYDROData_Image()
42 QStringList HYDROData_Image::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
46 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
47 if ( aDocument.IsNull() )
50 QString aDocName = aDocument->GetDocPyName();
51 QString anImageName = GetName();
53 aResList << QString( "%1 = %2.CreateObject( %3 );" )
54 .arg( anImageName ).arg( aDocName ).arg( PYTHON_IMAGE_ID );
55 aResList << QString( "%1.SetName( \"%2\" );" )
56 .arg( anImageName ).arg( anImageName );
58 QString aFilePath = GetFilePath();
59 if ( !aFilePath.isEmpty() )
61 aResList << QString( "" );
62 aResList << QString( "%1.LoadImage( \"%2\" );" )
63 .arg( anImageName ).arg( aFilePath );
64 aResList << QString( "" );
66 // Dump transformation points for image
68 QString aGap = QString().fill( ' ', anImageName.size() + 16 );
70 bool anIsByTwoPoints = IsByTwoPoints();
72 QPoint aLocalPointA, aLocalPointB, aLocalPointC;
73 if ( GetLocalPoints( aLocalPointA, aLocalPointB, aLocalPointC ) )
75 aResList << QString( "%1.SetLocalPoints( QPoint( %2, %3 )," )
76 .arg( anImageName ).arg( aLocalPointA.x() ).arg( aLocalPointA.y() );
77 aResList << QString( aGap + "QPoint( %1, %2 )," )
78 .arg( aLocalPointB.x() ).arg( aLocalPointB.y() );
79 aResList << QString( aGap + "QPoint( %1, %2 ) );" )
80 .arg( aLocalPointC.x() ).arg( aLocalPointC.y() );
81 aResList << QString( "" );
84 HYDROData_Image::TransformationMode aTransformationMode;
85 QPointF aTrsfPointA, aTrsfPointB, aTrsfPointC;
86 if ( GetGlobalPoints( aTransformationMode, aTrsfPointA, aTrsfPointB, aTrsfPointC ) )
88 aResList << QString( "%1.SetGlobalPoints( %2," )
89 .arg( anImageName ).arg( aTransformationMode );
90 aResList << QString( aGap + "QPointF( %1, %2 )," )
91 .arg( aTrsfPointA.x() ).arg( aTrsfPointA.y() );
92 aResList << QString( aGap + "QPointF( %1, %2 )," )
93 .arg( aTrsfPointB.x() ).arg( aTrsfPointB.y() );
94 aResList << QString( aGap + "QPointF( %1, %2 ) );" )
95 .arg( aTrsfPointC.x() ).arg( aTrsfPointC.y() );
97 if ( aTransformationMode == ReferenceImage )
99 Handle(HYDROData_Image) aRefImg = GetTrsfReferenceImage();
100 setPythonReferenceObject( theTreatedObjects, aResList, aRefImg, "SetTrsfReferenceImage" );
106 // Image is composed from other image(s)
108 QString anOperatorName = OperatorName();
109 if ( !anOperatorName.isEmpty() )
111 aResList << QString( "" );
113 aResList << QString( "%1.SetOperatorName( \"%2\" );" )
114 .arg( anImageName ).arg( anOperatorName );
116 ImageComposer_Operator* anImageOp =
117 HYDROData_OperationsFactory::Factory()->Operator( OperatorName() );
120 // Dump operation arguments
121 QString anOpArgsArrayName;
122 QStringList anOpArgs = anImageOp->dumpArgsToPython( anOpArgsArrayName );
123 if ( !anOpArgs.isEmpty() )
125 aResList << QString( "" );
126 aResList << anOpArgs;
128 aResList << QString( "" );
129 aResList << QString( "%1.SetArgs( %2 );" )
130 .arg( anImageName ).arg( anOpArgsArrayName );
135 int aNbReferences = NbReferences();
136 if ( aNbReferences > 0 )
138 aResList << QString( "" );
140 for ( int i = 0; i < aNbReferences; ++i )
142 Handle(HYDROData_Image) aRefImg = Handle(HYDROData_Image)::DownCast( Reference( i ) );
143 setPythonReferenceObject( theTreatedObjects, aResList, aRefImg, "AppendReference" );
147 // Necessary to update image in case of composed operator
148 aResList << QString( "" );
149 aResList << QString( "%1.Update();" ).arg( anImageName );
155 void HYDROData_Image::Update()
157 bool anIsToUpdate = IsMustBeUpdated();
159 HYDROData_Entity::Update();
164 HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory();
166 ImageComposer_Operator* anOp = aFactory->Operator( OperatorName() );
167 if ( anOp ) // Update image if there is an operation
169 // Fill by arguments and process the operation
170 anOp->setBinArgs( Args() );
172 QVariant anObj1, anObj2;
173 int aNbReferences = NbReferences();
175 if ( aNbReferences > 0 )
177 // First referenced object
178 Handle(HYDROData_Entity) aRefObj = Reference( 0 );
179 if ( !aRefObj.IsNull() )
181 anObj1 = aRefObj->GetDataVariant();
182 if ( !anObj1.isNull() && anObj1.canConvert<ImageComposer_Image>() )
184 ImageComposer_Image anImage = anObj1.value<ImageComposer_Image>();
185 QTransform aTransform = anImage.transform();
186 SetTrsf( aTransform );
191 if ( aNbReferences > 1 )
193 // Second referenced object
194 Handle(HYDROData_Entity) aRefObj = Reference( 1 );
195 if ( !aRefObj.IsNull() )
196 anObj2 = aRefObj->GetDataVariant();
199 ImageComposer_Image aResImg = anOp->process( anObj1, anObj2 );
201 SetTrsf( aResImg.transform() );
203 else // Update image if it positioned relatively to other image
208 SetToUpdate( false );
211 QVariant HYDROData_Image::GetDataVariant()
213 QTransform aTransform = Trsf();
215 ImageComposer_Image anImage = Image();
216 anImage.setTransform( aTransform );
219 aVarData.setValue<ImageComposer_Image>( anImage );
224 HYDROData_SequenceOfObjects HYDROData_Image::GetAllReferenceObjects() const
226 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
228 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
229 if ( !aRefImage.IsNull() )
230 aResSeq.Append( aRefImage );
232 HYDROData_SequenceOfObjects aSeqRefObjects = GetReferenceObjects( 0 );
233 aResSeq.Append( aSeqRefObjects );
238 void HYDROData_Image::SetImage(const QImage& theImage)
240 if ( theImage.isNull() )
242 // for empty image remove all previously stored attributes
243 myLab.ForgetAttribute(TDataStd_IntegerArray::GetID());
244 myLab.ForgetAttribute(TDataStd_ByteArray::GetID());
250 // convert 8-bits images
251 if ( theImage.format() == QImage::Format_Indexed8 ) {
252 anImage = theImage.convertToFormat( QImage::Format_RGB32 );
257 // store width, height, bytes per line and format in integer array
258 Handle(TDataStd_IntegerArray) aParams;
259 if (!myLab.FindAttribute(TDataStd_IntegerArray::GetID(), aParams)) {
260 aParams = TDataStd_IntegerArray::Set(myLab, 1, 4);
262 aParams->SetValue(1, anImage.width());
263 aParams->SetValue(2, anImage.height());
264 aParams->SetValue(3, anImage.bytesPerLine());
265 aParams->SetValue(4, (int)(anImage.format()));
266 // store data of image in byte array
267 const char* aData = (const char*)(anImage.bits());
268 SaveByteArray(0, aData, anImage.byteCount());
274 bool HYDROData_Image::LoadImage( const QString& theFilePath )
276 QImage anImage( theFilePath );
278 return !anImage.isNull();
281 QImage HYDROData_Image::Image()
283 Handle(TDataStd_IntegerArray) aParams;
284 if (!myLab.FindAttribute(TDataStd_IntegerArray::GetID(), aParams))
285 return QImage(); // return empty image if there is no array
287 uchar* anArray = (uchar*)ByteArray(0, aLen);
289 return QImage(); // return empty image if there is no array
290 QImage aResult(anArray, aParams->Value(1), aParams->Value(2),
291 aParams->Value(3), QImage::Format(aParams->Value(4)));
295 void HYDROData_Image::SetFilePath( const QString& theFilePath )
297 TCollection_AsciiString anAsciiStr( theFilePath.toStdString().c_str() );
298 TDataStd_AsciiString::Set( myLab.FindChild( DataTag_FilePath ), anAsciiStr );
303 QString HYDROData_Image::GetFilePath() const
307 TDF_Label aLabel = myLab.FindChild( DataTag_FilePath, false );
308 if ( !aLabel.IsNull() )
310 Handle(TDataStd_AsciiString) anAsciiStr;
311 if ( aLabel.FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) )
312 aRes = QString( anAsciiStr->Get().ToCString() );
318 void HYDROData_Image::SetTrsf(const QTransform& theTrsf)
320 // locate 9 coeffs of matrix into the real array
321 Handle(TDataStd_RealArray) anArray;
322 if (!myLab.FindAttribute(TDataStd_RealArray::GetID(), anArray)) {
323 if (theTrsf.isIdentity()) return; // no need to store identity transformation
324 anArray = TDataStd_RealArray::Set(myLab, 1, 9);
326 anArray->SetValue(1, theTrsf.m11());
327 anArray->SetValue(2, theTrsf.m12());
328 anArray->SetValue(3, theTrsf.m13());
329 anArray->SetValue(4, theTrsf.m21());
330 anArray->SetValue(5, theTrsf.m22());
331 anArray->SetValue(6, theTrsf.m23());
332 anArray->SetValue(7, theTrsf.m31());
333 anArray->SetValue(8, theTrsf.m32());
334 anArray->SetValue(9, theTrsf.m33());
339 QTransform HYDROData_Image::Trsf() const
341 // get 9 coeffs of matrix from the real array
342 Handle(TDataStd_RealArray) anArray;
343 if (!myLab.FindAttribute(TDataStd_RealArray::GetID(), anArray))
344 return QTransform(); // return identity if there is no array
346 anArray->Value(1), anArray->Value(2), anArray->Value(3),
347 anArray->Value(4), anArray->Value(5), anArray->Value(6),
348 anArray->Value(7), anArray->Value(8), anArray->Value(9));
352 void HYDROData_Image::UpdateTrsf()
354 QPoint aPointA, aPointB, aPointC;
355 if ( !GetLocalPoints( aPointA, aPointB, aPointC ) )
358 TransformationMode aTrsfMode;
359 QPointF aTrsfPointA, aTrsfPointB, aTrsfPointC;
360 if ( !GetGlobalPoints( aTrsfMode, aTrsfPointA, aTrsfPointB, aTrsfPointC ) )
363 QTransform aRefTransform;
364 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
366 bool anIsRefImage = aTrsfMode == ReferenceImage;
369 if ( aRefImage.IsNull() )
372 aRefTransform = aRefImage->Trsf();
375 bool anIsByTwoPoints = IsByTwoPoints();
377 // Convert lambert coordinates to cartesian
378 if ( aTrsfMode == ManualGeodesic )
380 double aXCart = 0, aYCart = 0;
382 HYDROData_Lambert93::toXY( aTrsfPointA.y(), aTrsfPointA.x(), aXCart, aYCart );
383 aTrsfPointA = QPointF( aXCart, aYCart );
385 HYDROData_Lambert93::toXY( aTrsfPointB.y(), aTrsfPointB.x(), aXCart, aYCart );
386 aTrsfPointB = QPointF( aXCart, aYCart );
388 if ( !anIsByTwoPoints )
390 HYDROData_Lambert93::toXY( aTrsfPointC.y(), aTrsfPointC.x(), aXCart, aYCart );
391 aTrsfPointC = QPointF( aXCart, aYCart );
395 // generate third points if needed
396 if ( anIsByTwoPoints )
398 aPointC = generateThirdPoint( aPointA, aPointB, true ).toPoint();
399 aTrsfPointC = generateThirdPoint( aTrsfPointA, aTrsfPointB, anIsRefImage );
402 int xa = aPointA.x();
403 int ya = aPointA.y();
404 int xb = aPointB.x();
405 int yb = aPointB.y();
406 int xc = aPointC.x();
407 int yc = aPointC.y();
409 double xta = aTrsfPointA.x();
410 double yta = aTrsfPointA.y();
411 double xtb = aTrsfPointB.x();
412 double ytb = aTrsfPointB.y();
413 double xtc = aTrsfPointC.x();
414 double ytc = aTrsfPointC.y();
416 // first, check that three input points don't belong to a single line
417 if( ( yb - ya ) * ( xc - xa ) == ( yc - ya ) * ( xb - xa ) )
420 // the same check for the reference points
421 if( anIsRefImage && ( ( ytb - yta ) * ( xtc - xta ) == ( ytc - yta ) * ( xtb - xta ) ) )
424 QTransform aTransform1( xa, ya, 1, xb, yb, 1, xc, yc, 1 );
425 QTransform aTransform2( xta, yta, 1, xtb, ytb, 1, xtc, ytc, 1 );
427 bool anIsInvertible = false;
428 QTransform aTransform1Inverted = aTransform1.inverted( &anIsInvertible );
429 if( !anIsInvertible )
432 QTransform aResTransform = aTransform1Inverted * aTransform2;
434 aResTransform *= aRefTransform;
436 SetTrsf( aResTransform );
439 bool HYDROData_Image::IsByTwoPoints() const
441 if ( !HasLocalPoints() || !HasGlobalPoints() )
444 QPoint aPointA, aPointB, aPointC;
445 GetLocalPoints( aPointA, aPointB, aPointC );
447 return aPointC.x() < 0 && aPointC.y() < 0;
450 bool HYDROData_Image::HasReferences() const
452 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
453 int aNbReferences = NbReferences();
455 return !aRefImage.IsNull() || aNbReferences > 0;
458 void HYDROData_Image::RemoveAllReferences()
460 if ( !HasReferences() )
463 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
464 if ( !aRefImage.IsNull() )
466 RemoveTrsfReferenceImage();
471 SetOperatorName( "" );
473 SetIsSelfSplitted( false );
476 bool anIsByTwoPoints = IsByTwoPoints();
478 QImage anImage = Image();
479 if ( anImage.isNull() )
481 SetToUpdate( false );
485 // Set local points to default position
486 QPoint aLocalPointA = QPoint( 0, 0 );
487 QPoint aLocalPointB = QPoint( anImage.width(), 0 );
488 QPoint aLocalPointC = anIsByTwoPoints ? QPoint( INT_MIN, INT_MIN ) : QPoint( 0, anImage.height() );
490 SetLocalPoints( aLocalPointA, aLocalPointB, aLocalPointC, false );
492 // Calculate global points
493 QTransform aTransform = Trsf();
495 QPointF aTrsfPointA = QPointF( aTransform.map( aLocalPointA ) );
496 QPointF aTrsfPointB = QPointF( aTransform.map( aLocalPointB ) );
497 QPointF aTrsfPointC = anIsByTwoPoints ? QPointF( INT_MIN, INT_MIN ) :
498 QPointF( aTransform.map( aLocalPointC ) );
500 SetGlobalPoints( ManualCartesian, aTrsfPointA, aTrsfPointB, aTrsfPointC );
502 SetToUpdate( false );
505 void HYDROData_Image::SetLocalPoints( const QPoint& thePointA,
506 const QPoint& thePointB,
507 const QPoint& thePointC,
508 const bool theIsUpdate )
510 Handle(TDataStd_RealArray) anArray;
511 if ( !myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
512 anArray = TDataStd_RealArray::Set( myLab.FindChild( DataTag_TrsfPoints ), 1, 12 );
514 anArray->SetValue( 1, thePointA.x() );
515 anArray->SetValue( 2, thePointA.y() );
516 anArray->SetValue( 3, thePointB.x() );
517 anArray->SetValue( 4, thePointB.y() );
518 anArray->SetValue( 5, thePointC.x() );
519 anArray->SetValue( 6, thePointC.y() );
521 TDataStd_UAttribute::Set( myLab.FindChild( DataTag_TrsfPoints ), GUID_HAS_LOCAL_POINTS );
529 bool HYDROData_Image::GetLocalPoints( QPoint& thePointA,
531 QPoint& thePointC ) const
533 if ( !HasLocalPoints() )
536 Handle(TDataStd_RealArray) anArray;
537 myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray );
539 thePointA = QPointF( anArray->Value( 1 ), anArray->Value( 2 ) ).toPoint();
540 thePointB = QPointF( anArray->Value( 3 ), anArray->Value( 4 ) ).toPoint();
541 thePointC = QPointF( anArray->Value( 5 ), anArray->Value( 6 ) ).toPoint();
546 bool HYDROData_Image::HasLocalPoints() const
548 TDF_Label aLabel = myLab.FindChild( DataTag_TrsfPoints, false );
549 if ( aLabel.IsNull() || !aLabel.IsAttribute( GUID_HAS_LOCAL_POINTS ) )
552 Handle(TDataStd_RealArray) anArray;
553 return aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray );
557 void HYDROData_Image::SetGlobalPoints( const TransformationMode& theMode,
558 const QPointF& thePointA,
559 const QPointF& thePointB,
560 const QPointF& thePointC,
561 const bool theIsUpdate )
563 Handle(TDataStd_RealArray) anArray;
564 if ( !myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
565 anArray = TDataStd_RealArray::Set( myLab.FindChild( DataTag_TrsfPoints ), 1, 12 );
567 anArray->SetValue( 7, thePointA.x() );
568 anArray->SetValue( 8, thePointA.y() );
569 anArray->SetValue( 9, thePointB.x() );
570 anArray->SetValue( 10, thePointB.y() );
571 anArray->SetValue( 11, thePointC.x() );
572 anArray->SetValue( 12, thePointC.y() );
574 SetTrsfMode( theMode );
576 TDataStd_UAttribute::Set( myLab.FindChild( DataTag_TrsfPoints ), GUID_HAS_GLOBAL_POINTS );
584 bool HYDROData_Image::GetGlobalPoints( TransformationMode& theMode,
587 QPointF& thePointC ) const
589 if ( !HasGlobalPoints() )
592 theMode = GetTrsfMode();
594 Handle(TDataStd_RealArray) anArray;
595 myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray );
597 thePointA = QPointF( anArray->Value( 7 ), anArray->Value( 8 ) );
598 thePointB = QPointF( anArray->Value( 9 ), anArray->Value( 10 ) );
599 thePointC = QPointF( anArray->Value( 11 ), anArray->Value( 12 ) );
604 bool HYDROData_Image::SetGlobalPointsFromFile( const QString& theFileName )
608 // Try to open the file
609 QFile aFile( theFileName );
610 if ( !aFile.exists() || !aFile.open( QIODevice::ReadOnly ) ) {
614 QPointF aPointA, aPointB;
615 double aXmin, anYmin, aXmax, anYmax;
616 aXmin = anYmin = aXmax = anYmax = -1;
618 while ( !aFile.atEnd() &&
619 ( aXmin < 0 || anYmin < 0 || aXmax < 0 || anYmax < 0 ) ) {
621 QString aLine = aFile.readLine().simplified();
622 aLine.replace( " ", "" );
623 if ( aLine.isEmpty() ) {
627 // Try to read double value after ":"
628 bool isDoubleOk = false;
629 double aDoubleValue = -1;
630 QStringList aValues = aLine.split( ":", QString::SkipEmptyParts );
631 if ( aValues.count() == 2 ) {
632 aDoubleValue = aValues.last().toDouble( &isDoubleOk );
637 boost::math::isnan( aDoubleValue ) ||
638 boost::math::isinf( aDoubleValue ) ) {
643 if ( aLine.startsWith( "Xminimum" ) ) {
644 aXmin = aDoubleValue;
646 else if ( aLine.startsWith( "Yminimum" ) ) {
647 anYmin = aDoubleValue;
649 else if ( aLine.startsWith( "Xmaximum" ) ) {
650 aXmax = aDoubleValue;
652 else if ( aLine.startsWith( "Ymaximum" ) ) {
653 anYmax = aDoubleValue;
660 if ( aXmin >= 0 && anYmin >= 0 ) {
661 aPointA.setX( aXmin );
662 aPointA.setY( anYmin );
665 if ( aXmax >= 0 && anYmax >= 0 ) {
666 aPointB.setX( aXmax );
667 aPointB.setY( anYmax );
670 if ( !aPointA.isNull() && !aPointB.isNull() ) {
671 SetGlobalPoints( ManualCartesian, aPointA, aPointB );
678 bool HYDROData_Image::HasGlobalPoints() const
680 TDF_Label aLabel = myLab.FindChild( DataTag_TrsfPoints, false );
681 if ( aLabel.IsNull() || !aLabel.IsAttribute( GUID_HAS_GLOBAL_POINTS ) )
684 Handle(TDataStd_RealArray) anArray;
685 return aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray );
688 void HYDROData_Image::SetReferencePoints( const Handle(HYDROData_Image)& theRefImage,
689 const QPointF& thePointA,
690 const QPointF& thePointB,
691 const QPointF& thePointC,
692 const bool theIsUpdate )
694 SetTrsfReferenceImage( theRefImage );
695 SetGlobalPoints( ReferenceImage, thePointA, thePointB, thePointC, theIsUpdate );
698 bool HYDROData_Image::GetReferencePoints( Handle(HYDROData_Image)& theRefImage,
701 QPointF& thePointC ) const
703 if ( !HasReferencePoints() )
706 theRefImage = GetTrsfReferenceImage();
708 TransformationMode aMode;
709 GetGlobalPoints( aMode, thePointA, thePointB, thePointC );
714 bool HYDROData_Image::HasReferencePoints() const
716 if ( !HasGlobalPoints() )
719 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
720 if ( aRefImage.IsNull() )
723 TransformationMode aTrsfMode = GetTrsfMode();
724 if ( aTrsfMode != ReferenceImage )
730 void HYDROData_Image::SetTrsfMode( const TransformationMode& theMode )
732 TDataStd_Integer::Set( myLab.FindChild( DataTag_TrsfMode ), (int)theMode );
736 HYDROData_Image::TransformationMode HYDROData_Image::GetTrsfMode() const
738 TransformationMode aResMode = ManualGeodesic;
740 TDF_Label aLabel = myLab.FindChild( DataTag_TrsfPoints, false );
741 if ( !aLabel.IsNull() )
743 Handle(TDataStd_Integer) aMode;
744 if ( myLab.FindChild( DataTag_TrsfMode ).FindAttribute( TDataStd_Integer::GetID(), aMode ) )
745 aResMode = (TransformationMode)aMode->Get();
751 void HYDROData_Image::SetTrsfReferenceImage( const Handle(HYDROData_Image)& theRefImage )
753 SetReferenceObject( theRefImage, DataTag_TrsfImage );
757 Handle(HYDROData_Image) HYDROData_Image::GetTrsfReferenceImage() const
759 return Handle(HYDROData_Image)::DownCast( GetReferenceObject( DataTag_TrsfImage ) );
762 void HYDROData_Image::RemoveTrsfReferenceImage()
764 RemoveReferenceObject( DataTag_TrsfImage );
768 void HYDROData_Image::AppendReference( const Handle(HYDROData_Entity)& theReferenced )
770 AddReferenceObject( theReferenced, 0 );
774 int HYDROData_Image::NbReferences() const
776 return NbReferenceObjects( 0 );
779 Handle(HYDROData_Entity) HYDROData_Image::Reference( const int theIndex ) const
781 return GetReferenceObject( 0, theIndex );
784 void HYDROData_Image::ChangeReference(
785 const int theIndex, Handle(HYDROData_Entity) theReferenced)
787 SetReferenceObject( theReferenced, 0, theIndex );
791 void HYDROData_Image::RemoveReference(const int theIndex)
793 RemoveReferenceObject( 0, theIndex );
797 void HYDROData_Image::ClearReferences()
799 ClearReferenceObjects( 0 );
803 void HYDROData_Image::SetOperatorName( const QString theOpName )
805 TCollection_AsciiString anAsciiStr( theOpName.toStdString().c_str() );
806 TDataStd_AsciiString::Set( myLab.FindChild( DataTag_Operator ), anAsciiStr );
810 QString HYDROData_Image::OperatorName() const
814 TDF_Label aLabel = myLab.FindChild( DataTag_Operator, false );
815 if ( !aLabel.IsNull() )
817 Handle(TDataStd_AsciiString) anAsciiStr;
818 if ( aLabel.FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) )
819 aRes = QString( anAsciiStr->Get().ToCString() );
825 void HYDROData_Image::SetArgs(const QByteArray& theArgs)
827 SaveByteArray(DataTag_Operator, theArgs.constData(), theArgs.length());
831 QByteArray HYDROData_Image::Args() const
834 const char* aData = ByteArray(DataTag_Operator, aLen);
837 return QByteArray(aData, aLen);
840 void HYDROData_Image::SetIsSelfSplitted(bool theFlag)
843 TDataStd_UAttribute::Set(myLab, GUID_SELF_SPLITTED);
845 myLab.ForgetAttribute(GUID_SELF_SPLITTED);
850 bool HYDROData_Image::IsSelfSplitted() const
852 return myLab.IsAttribute(GUID_SELF_SPLITTED);
855 QPointF HYDROData_Image::generateThirdPoint( const QPointF& thePointA,
856 const QPointF& thePointB,
857 const bool& theIsLocal ) const
859 // Rotate vector to 90 degrees : clockwise - for local
860 // counterclockwise - for global
861 const double aTheta = theIsLocal ? -M_PI_2 : M_PI_2;
865 // Move to (0,0) for correct rotation
866 double x = thePointB.x() - thePointA.x();
867 double y = thePointB.y() - thePointA.y();
869 aResPoint.setX( x * cos( aTheta ) - y * sin( aTheta ) );
870 aResPoint.setY( x * sin( aTheta ) + y * cos( aTheta ) );
872 // Move back to origin position
873 aResPoint.setX( aResPoint.x() + thePointA.x() );
874 aResPoint.setY( aResPoint.y() + thePointA.y() );