1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROData_Image.h"
21 #include "HYDROData_Document.h"
22 #include "HYDROData_Lambert93.h"
23 #include "HYDROData_OperationsFactory.h"
24 #include "HYDROData_Tool.h"
26 #include <TDataStd_RealArray.hxx>
27 #include <TDataStd_ByteArray.hxx>
28 #include <TDataStd_Integer.hxx>
29 #include <TDataStd_IntegerArray.hxx>
30 #include <TDataStd_ReferenceList.hxx>
31 #include <TDataStd_UAttribute.hxx>
32 #include <TDataStd_AsciiString.hxx>
35 #pragma warning ( disable: 4251 )
38 #include <ImageComposer_Operator.h>
39 #include <ImageComposer_MetaTypes.h>
41 #include <QStringList>
45 #pragma warning ( default: 4251 )
48 static const Standard_GUID GUID_SELF_SPLIT("997995aa-5c19-40bf-9a60-ab4b70ad04d8");
49 static const Standard_GUID GUID_HAS_LOCAL_POINTS("FD8841AA-FC44-42fa-B6A7-0F682CCC6F27");
50 static const Standard_GUID GUID_HAS_GLOBAL_POINTS("330D0E81-742D-4ea3-92D4-484877CFA7C1");
52 IMPLEMENT_STANDARD_HANDLE(HYDROData_Image, HYDROData_Entity)
53 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Image, HYDROData_Entity)
55 HYDROData_Image::HYDROData_Image()
56 : HYDROData_Entity( Geom_2d )
60 HYDROData_Image::~HYDROData_Image()
64 QStringList HYDROData_Image::DumpToPython( const QString& thePyScriptPath,
65 MapOfTreatedObjects& theTreatedObjects ) const
67 QStringList aResList = dumpObjectCreation( theTreatedObjects );
68 QString anImageName = GetObjPyName();
70 QString aFilePath = GetFilePath();
71 if ( !aFilePath.isEmpty() )
73 aResList << QString( "" );
74 aResList << QString( "%1.LoadImage( \"%2\" );" )
75 .arg( anImageName ).arg( aFilePath );
76 aResList << QString( "" );
78 // Dump transformation points for image
80 bool anIsByTwoPoints = IsByTwoPoints();
82 QPoint aLocalPointA, aLocalPointB, aLocalPointC;
83 if ( GetLocalPoints( aLocalPointA, aLocalPointB, aLocalPointC ) )
85 QString aGap = QString().fill( ' ', anImageName.size() + 17 );
87 aResList << QString( "%1.SetLocalPoints( QPoint( %2, %3 )," )
88 .arg( anImageName ).arg( aLocalPointA.x() ).arg( aLocalPointA.y() );
89 aResList << QString( aGap + "QPoint( %1, %2 )" )
90 .arg( aLocalPointB.x() ).arg( aLocalPointB.y() );
91 if ( !anIsByTwoPoints )
93 aResList.last().append( "," );
94 aResList << QString( aGap + "QPoint( %1, %2 ) );" )
95 .arg( aLocalPointC.x() ).arg( aLocalPointC.y() );
99 aResList.last().append( " );" );
101 aResList << QString( "" );
104 HYDROData_Image::TransformationMode aTransformationMode;
105 QPointF aTrsfPointA, aTrsfPointB, aTrsfPointC;
106 if ( GetGlobalPoints( aTransformationMode, aTrsfPointA, aTrsfPointB, aTrsfPointC ) )
108 QString aGap = QString().fill( ' ', anImageName.size() + 18 );
110 aResList << QString( "%1.SetGlobalPoints( %2," )
111 .arg( anImageName ).arg( aTransformationMode );
112 aResList << QString( aGap + "QPointF( %1, %2 )," )
113 .arg( aTrsfPointA.x() ).arg( aTrsfPointA.y() );
114 aResList << QString( aGap + "QPointF( %1, %2 )" )
115 .arg( aTrsfPointB.x() ).arg( aTrsfPointB.y() );
116 if ( !anIsByTwoPoints )
118 aResList.last().append( "," );
119 aResList << QString( aGap + "QPointF( %1, %2 ) );" )
120 .arg( aTrsfPointC.x() ).arg( aTrsfPointC.y() );
124 aResList.last().append( " );" );
127 if ( aTransformationMode == ReferenceImage )
129 Handle(HYDROData_Image) aRefImg = GetTrsfReferenceImage();
130 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aRefImg, "SetTrsfReferenceImage" );
136 // Image is composed from other image(s)
138 QString anOperatorName = OperatorName();
139 if ( !anOperatorName.isEmpty() )
141 aResList << QString( "" );
143 aResList << QString( "%1.SetOperatorName( \"%2\" );" )
144 .arg( anImageName ).arg( anOperatorName );
146 ImageComposer_Operator* anImageOp =
147 HYDROData_OperationsFactory::Factory()->Operator( OperatorName() );
150 // Dump operation arguments
151 QString anOpArgsArrayName;
152 QStringList anOpArgs = anImageOp->dumpArgsToPython( anOpArgsArrayName );
153 if ( !anOpArgs.isEmpty() )
155 aResList << QString( "" );
156 aResList << anOpArgs;
158 aResList << QString( "" );
159 aResList << QString( "%1.SetArgs( %2 );" )
160 .arg( anImageName ).arg( anOpArgsArrayName );
165 int aNbReferences = NbReferences();
166 if ( aNbReferences > 0 )
168 aResList << QString( "" );
170 for ( int i = 0; i < aNbReferences; ++i )
172 Handle(HYDROData_Image) aRefImg = Handle(HYDROData_Image)::DownCast( Reference( i ) );
173 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aRefImg, "AppendReference" );
178 aResList << QString( "" );
179 aResList << QString( "%1.Update();" ).arg( anImageName );
184 void HYDROData_Image::Update()
186 bool anIsToUpdate = IsMustBeUpdated( Geom_2d );
188 HYDROData_Entity::Update();
193 HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory();
195 ImageComposer_Operator* anOp = aFactory->Operator( OperatorName() );
196 if ( anOp ) // Update image if there is an operation
198 // Fill by arguments and process the operation
199 anOp->setBinArgs( Args() );
201 QVariant anObj1, anObj2;
202 int aNbReferences = NbReferences();
204 if ( aNbReferences > 0 )
206 // First referenced object
207 Handle(HYDROData_Entity) aRefObj = Reference( 0 );
208 if ( !aRefObj.IsNull() )
210 anObj1 = aRefObj->GetDataVariant();
211 if ( !anObj1.isNull() && anObj1.canConvert<ImageComposer_Image>() )
213 ImageComposer_Image anImage = anObj1.value<ImageComposer_Image>();
214 QTransform aTransform = anImage.transform();
215 SetTrsf( aTransform );
220 if ( aNbReferences > 1 )
222 // Second referenced object
223 Handle(HYDROData_Entity) aRefObj = Reference( 1 );
224 if ( !aRefObj.IsNull() )
225 anObj2 = aRefObj->GetDataVariant();
228 ImageComposer_Image aResImg = anOp->process( anObj1, anObj2 );
230 SetTrsf( aResImg.transform() );
232 else // Update image if it positioned relatively to other image
240 bool HYDROData_Image::IsHas2dPrs() const
245 QVariant HYDROData_Image::GetDataVariant()
247 QTransform aTransform = Trsf();
249 ImageComposer_Image anImage = Image();
250 anImage.setTransform( aTransform );
253 aVarData.setValue<ImageComposer_Image>( anImage );
258 HYDROData_SequenceOfObjects HYDROData_Image::GetAllReferenceObjects() const
260 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
262 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
263 if ( !aRefImage.IsNull() )
264 aResSeq.Append( aRefImage );
266 HYDROData_SequenceOfObjects aSeqRefObjects = GetReferenceObjects( 0 );
267 aResSeq.Append( aSeqRefObjects );
272 void HYDROData_Image::SetImage(const QImage& theImage)
274 if ( theImage.isNull() )
276 // for empty image remove all previously stored attributes
277 myLab.ForgetAttribute(TDataStd_IntegerArray::GetID());
278 myLab.ForgetAttribute(TDataStd_ByteArray::GetID());
284 // convert 8-bits images
285 if ( theImage.format() == QImage::Format_Indexed8 ) {
286 anImage = theImage.convertToFormat( QImage::Format_RGB32 );
291 // store width, height, bytes per line and format in integer array
292 Handle(TDataStd_IntegerArray) aParams;
293 if (!myLab.FindAttribute(TDataStd_IntegerArray::GetID(), aParams)) {
294 aParams = TDataStd_IntegerArray::Set(myLab, 1, 4);
296 aParams->SetValue(1, anImage.width());
297 aParams->SetValue(2, anImage.height());
298 aParams->SetValue(3, anImage.bytesPerLine());
299 aParams->SetValue(4, (int)(anImage.format()));
300 // store data of image in byte array
301 const char* aData = (const char*)(anImage.bits());
302 SaveByteArray(0, aData, anImage.byteCount());
308 bool HYDROData_Image::LoadImage( const QString& theFilePath )
310 QImage anImage( theFilePath );
313 SetFilePath( theFilePath );
315 return !anImage.isNull();
318 QImage HYDROData_Image::Image()
320 Handle(TDataStd_IntegerArray) aParams;
321 if (!myLab.FindAttribute(TDataStd_IntegerArray::GetID(), aParams))
322 return QImage(); // return empty image if there is no array
324 uchar* anArray = (uchar*)ByteArray(0, aLen);
326 return QImage(); // return empty image if there is no array
327 QImage aResult(anArray, aParams->Value(1), aParams->Value(2),
328 aParams->Value(3), QImage::Format(aParams->Value(4)));
332 void HYDROData_Image::SetFilePath( const QString& theFilePath )
334 TCollection_AsciiString anAsciiStr( theFilePath.toStdString().c_str() );
335 TDataStd_AsciiString::Set( myLab.FindChild( DataTag_FilePath ), anAsciiStr );
340 QString HYDROData_Image::GetFilePath() const
344 TDF_Label aLabel = myLab.FindChild( DataTag_FilePath, false );
345 if ( !aLabel.IsNull() )
347 Handle(TDataStd_AsciiString) anAsciiStr;
348 if ( aLabel.FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) )
349 aRes = QString( anAsciiStr->Get().ToCString() );
355 void HYDROData_Image::SetTrsf(const QTransform& theTrsf)
357 // locate 9 coeffs of matrix into the real array
358 Handle(TDataStd_RealArray) anArray;
359 if (!myLab.FindAttribute(TDataStd_RealArray::GetID(), anArray)) {
360 if (theTrsf.isIdentity()) return; // no need to store identity transformation
361 anArray = TDataStd_RealArray::Set(myLab, 1, 9);
363 anArray->SetValue(1, theTrsf.m11());
364 anArray->SetValue(2, theTrsf.m12());
365 anArray->SetValue(3, theTrsf.m13());
366 anArray->SetValue(4, theTrsf.m21());
367 anArray->SetValue(5, theTrsf.m22());
368 anArray->SetValue(6, theTrsf.m23());
369 anArray->SetValue(7, theTrsf.m31());
370 anArray->SetValue(8, theTrsf.m32());
371 anArray->SetValue(9, theTrsf.m33());
376 QTransform HYDROData_Image::Trsf() const
378 // get 9 coeffs of matrix from the real array
379 Handle(TDataStd_RealArray) anArray;
380 if (!myLab.FindAttribute(TDataStd_RealArray::GetID(), anArray))
381 return QTransform(); // return identity if there is no array
383 anArray->Value(1), anArray->Value(2), anArray->Value(3),
384 anArray->Value(4), anArray->Value(5), anArray->Value(6),
385 anArray->Value(7), anArray->Value(8), anArray->Value(9));
389 void HYDROData_Image::UpdateTrsf()
391 QPoint aPointA, aPointB, aPointC;
392 if ( !GetLocalPoints( aPointA, aPointB, aPointC ) )
395 TransformationMode aTrsfMode;
396 QPointF aTrsfPointA, aTrsfPointB, aTrsfPointC;
397 if ( !GetGlobalPoints( aTrsfMode, aTrsfPointA, aTrsfPointB, aTrsfPointC ) )
400 QTransform aRefTransform;
401 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
403 bool anIsRefImage = aTrsfMode == ReferenceImage;
406 if ( aRefImage.IsNull() )
409 aRefTransform = aRefImage->Trsf();
412 bool anIsByTwoPoints = IsByTwoPoints();
414 // Convert lambert coordinates to cartesian
415 if ( aTrsfMode == ManualGeodesic )
417 double aXCart = 0, aYCart = 0;
419 HYDROData_Lambert93::toXY( aTrsfPointA.y(), aTrsfPointA.x(), aXCart, aYCart );
420 aTrsfPointA = QPointF( aXCart, aYCart );
422 HYDROData_Lambert93::toXY( aTrsfPointB.y(), aTrsfPointB.x(), aXCart, aYCart );
423 aTrsfPointB = QPointF( aXCart, aYCart );
425 if ( !anIsByTwoPoints )
427 HYDROData_Lambert93::toXY( aTrsfPointC.y(), aTrsfPointC.x(), aXCart, aYCart );
428 aTrsfPointC = QPointF( aXCart, aYCart );
432 // generate third points if needed
433 if ( anIsByTwoPoints )
435 aPointC = generateThirdPoint( aPointA, aPointB, true ).toPoint();
436 aTrsfPointC = generateThirdPoint( aTrsfPointA, aTrsfPointB, anIsRefImage );
439 int xa = aPointA.x();
440 int ya = aPointA.y();
441 int xb = aPointB.x();
442 int yb = aPointB.y();
443 int xc = aPointC.x();
444 int yc = aPointC.y();
446 double xta = aTrsfPointA.x();
447 double yta = aTrsfPointA.y();
448 double xtb = aTrsfPointB.x();
449 double ytb = aTrsfPointB.y();
450 double xtc = aTrsfPointC.x();
451 double ytc = aTrsfPointC.y();
453 // first, check that three input points don't belong to a single line
454 if( ( yb - ya ) * ( xc - xa ) == ( yc - ya ) * ( xb - xa ) )
457 // the same check for the reference points
458 if( anIsRefImage && ( ( ytb - yta ) * ( xtc - xta ) == ( ytc - yta ) * ( xtb - xta ) ) )
461 QTransform aTransform1( xa, ya, 1, xb, yb, 1, xc, yc, 1 );
462 QTransform aTransform2( xta, yta, 1, xtb, ytb, 1, xtc, ytc, 1 );
464 bool anIsInvertible = false;
465 QTransform aTransform1Inverted = aTransform1.inverted( &anIsInvertible );
466 if( !anIsInvertible )
469 QTransform aResTransform = aTransform1Inverted * aTransform2;
471 aResTransform *= aRefTransform;
473 SetTrsf( aResTransform );
476 bool HYDROData_Image::IsByTwoPoints() const
478 if ( !HasLocalPoints() || !HasGlobalPoints() )
481 QPoint aPointA, aPointB, aPointC;
482 GetLocalPoints( aPointA, aPointB, aPointC );
484 return aPointC.x() < 0 && aPointC.y() < 0;
487 bool HYDROData_Image::HasReferences() const
489 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
490 int aNbReferences = NbReferences();
492 return !aRefImage.IsNull() || aNbReferences > 0;
495 void HYDROData_Image::RemoveAllReferences()
497 if ( !HasReferences() )
500 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
501 if ( !aRefImage.IsNull() )
503 RemoveTrsfReferenceImage();
508 SetOperatorName( "" );
510 SetIsSelfSplit( false );
513 bool anIsByTwoPoints = IsByTwoPoints();
515 QImage anImage = Image();
516 if ( anImage.isNull() )
522 // Set local points to default position
523 QPoint aLocalPointA = QPoint( 0, 0 );
524 QPoint aLocalPointB = QPoint( anImage.width(), 0 );
525 QPoint aLocalPointC = anIsByTwoPoints ? QPoint( INT_MIN, INT_MIN ) : QPoint( 0, anImage.height() );
527 SetLocalPoints( aLocalPointA, aLocalPointB, aLocalPointC, false );
529 // Calculate global points
530 QTransform aTransform = Trsf();
532 QPointF aTrsfPointA = QPointF( aTransform.map( aLocalPointA ) );
533 QPointF aTrsfPointB = QPointF( aTransform.map( aLocalPointB ) );
534 QPointF aTrsfPointC = anIsByTwoPoints ? QPointF( INT_MIN, INT_MIN ) :
535 QPointF( aTransform.map( aLocalPointC ) );
537 SetGlobalPoints( ManualCartesian, aTrsfPointA, aTrsfPointB, aTrsfPointC );
542 void HYDROData_Image::SetLocalPoints( const QPoint& thePointA,
543 const QPoint& thePointB,
544 const QPoint& thePointC,
545 const bool theIsUpdate )
547 Handle(TDataStd_RealArray) anArray;
548 if ( !myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
549 anArray = TDataStd_RealArray::Set( myLab.FindChild( DataTag_TrsfPoints ), 1, 12 );
551 anArray->SetValue( 1, thePointA.x() );
552 anArray->SetValue( 2, thePointA.y() );
553 anArray->SetValue( 3, thePointB.x() );
554 anArray->SetValue( 4, thePointB.y() );
555 anArray->SetValue( 5, thePointC.x() );
556 anArray->SetValue( 6, thePointC.y() );
558 TDataStd_UAttribute::Set( myLab.FindChild( DataTag_TrsfPoints ), GUID_HAS_LOCAL_POINTS );
566 bool HYDROData_Image::GetLocalPoints( QPoint& thePointA,
568 QPoint& thePointC ) const
570 if ( !HasLocalPoints() )
573 Handle(TDataStd_RealArray) anArray;
574 myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray );
576 thePointA = QPointF( anArray->Value( 1 ), anArray->Value( 2 ) ).toPoint();
577 thePointB = QPointF( anArray->Value( 3 ), anArray->Value( 4 ) ).toPoint();
578 thePointC = QPointF( anArray->Value( 5 ), anArray->Value( 6 ) ).toPoint();
583 bool HYDROData_Image::HasLocalPoints() const
585 TDF_Label aLabel = myLab.FindChild( DataTag_TrsfPoints, false );
586 if ( aLabel.IsNull() || !aLabel.IsAttribute( GUID_HAS_LOCAL_POINTS ) )
589 Handle(TDataStd_RealArray) anArray;
590 return aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray );
594 void HYDROData_Image::SetGlobalPoints( const TransformationMode& theMode,
595 const QPointF& thePointA,
596 const QPointF& thePointB,
597 const QPointF& thePointC,
598 const bool theIsUpdate )
600 Handle(TDataStd_RealArray) anArray;
601 if ( !myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
602 anArray = TDataStd_RealArray::Set( myLab.FindChild( DataTag_TrsfPoints ), 1, 12 );
604 anArray->SetValue( 7, thePointA.x() );
605 anArray->SetValue( 8, thePointA.y() );
606 anArray->SetValue( 9, thePointB.x() );
607 anArray->SetValue( 10, thePointB.y() );
608 anArray->SetValue( 11, thePointC.x() );
609 anArray->SetValue( 12, thePointC.y() );
611 SetTrsfMode( theMode );
613 TDataStd_UAttribute::Set( myLab.FindChild( DataTag_TrsfPoints ), GUID_HAS_GLOBAL_POINTS );
621 bool HYDROData_Image::GetGlobalPoints( TransformationMode& theMode,
624 QPointF& thePointC ) const
626 if ( !HasGlobalPoints() )
629 theMode = GetTrsfMode();
631 Handle(TDataStd_RealArray) anArray;
632 myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray );
634 thePointA = QPointF( anArray->Value( 7 ), anArray->Value( 8 ) );
635 thePointB = QPointF( anArray->Value( 9 ), anArray->Value( 10 ) );
636 thePointC = QPointF( anArray->Value( 11 ), anArray->Value( 12 ) );
641 bool HYDROData_Image::SetGlobalPointsFromFile( const QString& theFileName )
645 // Try to open the file
646 QFile aFile( theFileName );
647 if ( !aFile.exists() || !aFile.open( QIODevice::ReadOnly ) ) {
651 QPointF aPointA, aPointB;
652 double aXmin, anYmin, aXmax, anYmax;
653 aXmin = anYmin = aXmax = anYmax = -1;
655 while ( !aFile.atEnd() &&
656 ( aXmin < 0 || anYmin < 0 || aXmax < 0 || anYmax < 0 ) ) {
658 QString aLine = aFile.readLine().simplified();
659 aLine.replace( " ", "" );
660 if ( aLine.isEmpty() ) {
664 // Try to read double value after ":"
665 bool isDoubleOk = false;
666 double aDoubleValue = -1;
667 QStringList aValues = aLine.split( ":", QString::SkipEmptyParts );
668 if ( aValues.count() == 2 ) {
669 aDoubleValue = aValues.last().toDouble( &isDoubleOk );
674 HYDROData_Tool::IsNan( aDoubleValue ) ||
675 HYDROData_Tool::IsInf( aDoubleValue ) ) {
680 if ( aLine.startsWith( "Xminimum" ) ) {
681 aXmin = aDoubleValue;
683 else if ( aLine.startsWith( "Yminimum" ) ) {
684 anYmin = aDoubleValue;
686 else if ( aLine.startsWith( "Xmaximum" ) ) {
687 aXmax = aDoubleValue;
689 else if ( aLine.startsWith( "Ymaximum" ) ) {
690 anYmax = aDoubleValue;
697 if ( aXmin >= 0 && anYmin >= 0 ) {
698 aPointA.setX( aXmin );
699 aPointA.setY( anYmin );
702 if ( aXmax >= 0 && anYmax >= 0 ) {
703 aPointB.setX( aXmax );
704 aPointB.setY( anYmax );
707 if ( !aPointA.isNull() && !aPointB.isNull() ) {
708 SetGlobalPoints( ManualCartesian, aPointA, aPointB );
715 bool HYDROData_Image::HasGlobalPoints() const
717 TDF_Label aLabel = myLab.FindChild( DataTag_TrsfPoints, false );
718 if ( aLabel.IsNull() || !aLabel.IsAttribute( GUID_HAS_GLOBAL_POINTS ) )
721 Handle(TDataStd_RealArray) anArray;
722 return aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray );
725 void HYDROData_Image::SetReferencePoints( const Handle(HYDROData_Image)& theRefImage,
726 const QPointF& thePointA,
727 const QPointF& thePointB,
728 const QPointF& thePointC,
729 const bool theIsUpdate )
731 SetTrsfReferenceImage( theRefImage );
732 SetGlobalPoints( ReferenceImage, thePointA, thePointB, thePointC, theIsUpdate );
735 bool HYDROData_Image::GetReferencePoints( Handle(HYDROData_Image)& theRefImage,
738 QPointF& thePointC ) const
740 if ( !HasReferencePoints() )
743 theRefImage = GetTrsfReferenceImage();
745 TransformationMode aMode;
746 GetGlobalPoints( aMode, thePointA, thePointB, thePointC );
751 bool HYDROData_Image::HasReferencePoints() const
753 if ( !HasGlobalPoints() )
756 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
757 if ( aRefImage.IsNull() )
760 TransformationMode aTrsfMode = GetTrsfMode();
761 if ( aTrsfMode != ReferenceImage )
767 void HYDROData_Image::SetTrsfMode( const TransformationMode& theMode )
769 TDataStd_Integer::Set( myLab.FindChild( DataTag_TrsfMode ), (int)theMode );
773 HYDROData_Image::TransformationMode HYDROData_Image::GetTrsfMode() const
775 TransformationMode aResMode = ManualGeodesic;
777 TDF_Label aLabel = myLab.FindChild( DataTag_TrsfPoints, false );
778 if ( !aLabel.IsNull() )
780 Handle(TDataStd_Integer) aMode;
781 if ( myLab.FindChild( DataTag_TrsfMode ).FindAttribute( TDataStd_Integer::GetID(), aMode ) )
782 aResMode = (TransformationMode)aMode->Get();
788 void HYDROData_Image::SetTrsfReferenceImage( const Handle(HYDROData_Image)& theRefImage )
790 SetReferenceObject( theRefImage, DataTag_TrsfImage );
794 Handle(HYDROData_Image) HYDROData_Image::GetTrsfReferenceImage() const
796 return Handle(HYDROData_Image)::DownCast( GetReferenceObject( DataTag_TrsfImage ) );
799 void HYDROData_Image::RemoveTrsfReferenceImage()
801 RemoveReferenceObject( DataTag_TrsfImage );
805 void HYDROData_Image::AppendReference( const Handle(HYDROData_Entity)& theReferenced )
807 AddReferenceObject( theReferenced, 0 );
811 int HYDROData_Image::NbReferences() const
813 return NbReferenceObjects( 0 );
816 Handle(HYDROData_Entity) HYDROData_Image::Reference( const int theIndex ) const
818 return GetReferenceObject( 0, theIndex );
821 void HYDROData_Image::ChangeReference(
822 const int theIndex, Handle(HYDROData_Entity) theReferenced)
824 SetReferenceObject( theReferenced, 0, theIndex );
828 void HYDROData_Image::RemoveReference(const int theIndex)
830 RemoveReferenceObject( 0, theIndex );
834 void HYDROData_Image::ClearReferences()
836 ClearReferenceObjects( 0 );
840 void HYDROData_Image::SetOperatorName( const QString theOpName )
842 TCollection_AsciiString anAsciiStr( theOpName.toStdString().c_str() );
843 TDataStd_AsciiString::Set( myLab.FindChild( DataTag_Operator ), anAsciiStr );
847 QString HYDROData_Image::OperatorName() const
851 TDF_Label aLabel = myLab.FindChild( DataTag_Operator, false );
852 if ( !aLabel.IsNull() )
854 Handle(TDataStd_AsciiString) anAsciiStr;
855 if ( aLabel.FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) )
856 aRes = QString( anAsciiStr->Get().ToCString() );
862 void HYDROData_Image::SetArgs(const QByteArray& theArgs)
864 SaveByteArray(DataTag_Operator, theArgs.constData(), theArgs.length());
868 QByteArray HYDROData_Image::Args() const
871 const char* aData = ByteArray(DataTag_Operator, aLen);
874 return QByteArray(aData, aLen);
877 void HYDROData_Image::SetIsSelfSplit(bool theFlag)
880 TDataStd_UAttribute::Set(myLab, GUID_SELF_SPLIT);
882 myLab.ForgetAttribute(GUID_SELF_SPLIT);
887 bool HYDROData_Image::IsSelfSplit() const
889 return myLab.IsAttribute(GUID_SELF_SPLIT);
892 QPointF HYDROData_Image::generateThirdPoint( const QPointF& thePointA,
893 const QPointF& thePointB,
894 const bool& theIsLocal ) const
896 // Rotate vector to 90 degrees : clockwise - for local
897 // counterclockwise - for global
898 const double aTheta = theIsLocal ? -M_PI_2 : M_PI_2;
902 // Move to (0,0) for correct rotation
903 double x = thePointB.x() - thePointA.x();
904 double y = thePointB.y() - thePointA.y();
906 aResPoint.setX( x * cos( aTheta ) - y * sin( aTheta ) );
907 aResPoint.setY( x * sin( aTheta ) + y * cos( aTheta ) );
909 // Move back to origin position
910 aResPoint.setX( aResPoint.x() + thePointA.x() );
911 aResPoint.setY( aResPoint.y() + thePointA.y() );