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"
25 #include <TDataStd_RealArray.hxx>
26 #include <TDataStd_ByteArray.hxx>
27 #include <TDataStd_Integer.hxx>
28 #include <TDataStd_IntegerArray.hxx>
29 #include <TDataStd_ReferenceList.hxx>
30 #include <TDataStd_UAttribute.hxx>
31 #include <TDataStd_AsciiString.hxx>
34 #pragma warning ( disable: 4251 )
37 #include <ImageComposer_Operator.h>
38 #include <ImageComposer_MetaTypes.h>
40 #include <QStringList>
44 #pragma warning ( default: 4251 )
47 #include <boost/math/special_functions/fpclassify.hpp>
49 static const Standard_GUID GUID_SELF_SPLITTED("997995aa-5c19-40bf-9a60-ab4b70ad04d8");
50 static const Standard_GUID GUID_HAS_LOCAL_POINTS("FD8841AA-FC44-42fa-B6A7-0F682CCC6F27");
51 static const Standard_GUID GUID_HAS_GLOBAL_POINTS("330D0E81-742D-4ea3-92D4-484877CFA7C1");
53 IMPLEMENT_STANDARD_HANDLE(HYDROData_Image, HYDROData_Entity)
54 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Image, HYDROData_Entity)
56 HYDROData_Image::HYDROData_Image()
57 : HYDROData_Entity( Geom_2d )
61 HYDROData_Image::~HYDROData_Image()
65 QStringList HYDROData_Image::DumpToPython( const QString& thePyScriptPath,
66 MapOfTreatedObjects& theTreatedObjects ) const
68 QStringList aResList = dumpObjectCreation( theTreatedObjects );
69 QString anImageName = GetObjPyName();
71 QString aFilePath = GetFilePath();
72 if ( !aFilePath.isEmpty() )
74 aResList << QString( "" );
75 aResList << QString( "%1.LoadImage( \"%2\" );" )
76 .arg( anImageName ).arg( aFilePath );
77 aResList << QString( "" );
79 // Dump transformation points for image
81 bool anIsByTwoPoints = IsByTwoPoints();
83 QPoint aLocalPointA, aLocalPointB, aLocalPointC;
84 if ( GetLocalPoints( aLocalPointA, aLocalPointB, aLocalPointC ) )
86 QString aGap = QString().fill( ' ', anImageName.size() + 17 );
88 aResList << QString( "%1.SetLocalPoints( QPoint( %2, %3 )," )
89 .arg( anImageName ).arg( aLocalPointA.x() ).arg( aLocalPointA.y() );
90 aResList << QString( aGap + "QPoint( %1, %2 )" )
91 .arg( aLocalPointB.x() ).arg( aLocalPointB.y() );
92 if ( !anIsByTwoPoints )
94 aResList.last().append( "," );
95 aResList << QString( aGap + "QPoint( %1, %2 ) );" )
96 .arg( aLocalPointC.x() ).arg( aLocalPointC.y() );
100 aResList.last().append( " );" );
102 aResList << QString( "" );
105 HYDROData_Image::TransformationMode aTransformationMode;
106 QPointF aTrsfPointA, aTrsfPointB, aTrsfPointC;
107 if ( GetGlobalPoints( aTransformationMode, aTrsfPointA, aTrsfPointB, aTrsfPointC ) )
109 QString aGap = QString().fill( ' ', anImageName.size() + 18 );
111 aResList << QString( "%1.SetGlobalPoints( %2," )
112 .arg( anImageName ).arg( aTransformationMode );
113 aResList << QString( aGap + "QPointF( %1, %2 )," )
114 .arg( aTrsfPointA.x() ).arg( aTrsfPointA.y() );
115 aResList << QString( aGap + "QPointF( %1, %2 )" )
116 .arg( aTrsfPointB.x() ).arg( aTrsfPointB.y() );
117 if ( !anIsByTwoPoints )
119 aResList.last().append( "," );
120 aResList << QString( aGap + "QPointF( %1, %2 ) );" )
121 .arg( aTrsfPointC.x() ).arg( aTrsfPointC.y() );
125 aResList.last().append( " );" );
128 if ( aTransformationMode == ReferenceImage )
130 Handle(HYDROData_Image) aRefImg = GetTrsfReferenceImage();
131 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aRefImg, "SetTrsfReferenceImage" );
137 // Image is composed from other image(s)
139 QString anOperatorName = OperatorName();
140 if ( !anOperatorName.isEmpty() )
142 aResList << QString( "" );
144 aResList << QString( "%1.SetOperatorName( \"%2\" );" )
145 .arg( anImageName ).arg( anOperatorName );
147 ImageComposer_Operator* anImageOp =
148 HYDROData_OperationsFactory::Factory()->Operator( OperatorName() );
151 // Dump operation arguments
152 QString anOpArgsArrayName;
153 QStringList anOpArgs = anImageOp->dumpArgsToPython( anOpArgsArrayName );
154 if ( !anOpArgs.isEmpty() )
156 aResList << QString( "" );
157 aResList << anOpArgs;
159 aResList << QString( "" );
160 aResList << QString( "%1.SetArgs( %2 );" )
161 .arg( anImageName ).arg( anOpArgsArrayName );
166 int aNbReferences = NbReferences();
167 if ( aNbReferences > 0 )
169 aResList << QString( "" );
171 for ( int i = 0; i < aNbReferences; ++i )
173 Handle(HYDROData_Image) aRefImg = Handle(HYDROData_Image)::DownCast( Reference( i ) );
174 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aRefImg, "AppendReference" );
179 aResList << QString( "" );
180 aResList << QString( "%1.Update();" ).arg( anImageName );
185 void HYDROData_Image::Update()
187 bool anIsToUpdate = IsMustBeUpdated( Geom_2d );
189 HYDROData_Entity::Update();
194 HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory();
196 ImageComposer_Operator* anOp = aFactory->Operator( OperatorName() );
197 if ( anOp ) // Update image if there is an operation
199 // Fill by arguments and process the operation
200 anOp->setBinArgs( Args() );
202 QVariant anObj1, anObj2;
203 int aNbReferences = NbReferences();
205 if ( aNbReferences > 0 )
207 // First referenced object
208 Handle(HYDROData_Entity) aRefObj = Reference( 0 );
209 if ( !aRefObj.IsNull() )
211 anObj1 = aRefObj->GetDataVariant();
212 if ( !anObj1.isNull() && anObj1.canConvert<ImageComposer_Image>() )
214 ImageComposer_Image anImage = anObj1.value<ImageComposer_Image>();
215 QTransform aTransform = anImage.transform();
216 SetTrsf( aTransform );
221 if ( aNbReferences > 1 )
223 // Second referenced object
224 Handle(HYDROData_Entity) aRefObj = Reference( 1 );
225 if ( !aRefObj.IsNull() )
226 anObj2 = aRefObj->GetDataVariant();
229 ImageComposer_Image aResImg = anOp->process( anObj1, anObj2 );
231 SetTrsf( aResImg.transform() );
233 else // Update image if it positioned relatively to other image
241 bool HYDROData_Image::IsHas2dPrs() const
246 QVariant HYDROData_Image::GetDataVariant()
248 QTransform aTransform = Trsf();
250 ImageComposer_Image anImage = Image();
251 anImage.setTransform( aTransform );
254 aVarData.setValue<ImageComposer_Image>( anImage );
259 HYDROData_SequenceOfObjects HYDROData_Image::GetAllReferenceObjects() const
261 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
263 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
264 if ( !aRefImage.IsNull() )
265 aResSeq.Append( aRefImage );
267 HYDROData_SequenceOfObjects aSeqRefObjects = GetReferenceObjects( 0 );
268 aResSeq.Append( aSeqRefObjects );
273 void HYDROData_Image::SetImage(const QImage& theImage)
275 if ( theImage.isNull() )
277 // for empty image remove all previously stored attributes
278 myLab.ForgetAttribute(TDataStd_IntegerArray::GetID());
279 myLab.ForgetAttribute(TDataStd_ByteArray::GetID());
285 // convert 8-bits images
286 if ( theImage.format() == QImage::Format_Indexed8 ) {
287 anImage = theImage.convertToFormat( QImage::Format_RGB32 );
292 // store width, height, bytes per line and format in integer array
293 Handle(TDataStd_IntegerArray) aParams;
294 if (!myLab.FindAttribute(TDataStd_IntegerArray::GetID(), aParams)) {
295 aParams = TDataStd_IntegerArray::Set(myLab, 1, 4);
297 aParams->SetValue(1, anImage.width());
298 aParams->SetValue(2, anImage.height());
299 aParams->SetValue(3, anImage.bytesPerLine());
300 aParams->SetValue(4, (int)(anImage.format()));
301 // store data of image in byte array
302 const char* aData = (const char*)(anImage.bits());
303 SaveByteArray(0, aData, anImage.byteCount());
309 bool HYDROData_Image::LoadImage( const QString& theFilePath )
311 QImage anImage( theFilePath );
314 SetFilePath( theFilePath );
316 return !anImage.isNull();
319 QImage HYDROData_Image::Image()
321 Handle(TDataStd_IntegerArray) aParams;
322 if (!myLab.FindAttribute(TDataStd_IntegerArray::GetID(), aParams))
323 return QImage(); // return empty image if there is no array
325 uchar* anArray = (uchar*)ByteArray(0, aLen);
327 return QImage(); // return empty image if there is no array
328 QImage aResult(anArray, aParams->Value(1), aParams->Value(2),
329 aParams->Value(3), QImage::Format(aParams->Value(4)));
333 void HYDROData_Image::SetFilePath( const QString& theFilePath )
335 TCollection_AsciiString anAsciiStr( theFilePath.toStdString().c_str() );
336 TDataStd_AsciiString::Set( myLab.FindChild( DataTag_FilePath ), anAsciiStr );
341 QString HYDROData_Image::GetFilePath() const
345 TDF_Label aLabel = myLab.FindChild( DataTag_FilePath, false );
346 if ( !aLabel.IsNull() )
348 Handle(TDataStd_AsciiString) anAsciiStr;
349 if ( aLabel.FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) )
350 aRes = QString( anAsciiStr->Get().ToCString() );
356 void HYDROData_Image::SetTrsf(const QTransform& theTrsf)
358 // locate 9 coeffs of matrix into the real array
359 Handle(TDataStd_RealArray) anArray;
360 if (!myLab.FindAttribute(TDataStd_RealArray::GetID(), anArray)) {
361 if (theTrsf.isIdentity()) return; // no need to store identity transformation
362 anArray = TDataStd_RealArray::Set(myLab, 1, 9);
364 anArray->SetValue(1, theTrsf.m11());
365 anArray->SetValue(2, theTrsf.m12());
366 anArray->SetValue(3, theTrsf.m13());
367 anArray->SetValue(4, theTrsf.m21());
368 anArray->SetValue(5, theTrsf.m22());
369 anArray->SetValue(6, theTrsf.m23());
370 anArray->SetValue(7, theTrsf.m31());
371 anArray->SetValue(8, theTrsf.m32());
372 anArray->SetValue(9, theTrsf.m33());
377 QTransform HYDROData_Image::Trsf() const
379 // get 9 coeffs of matrix from the real array
380 Handle(TDataStd_RealArray) anArray;
381 if (!myLab.FindAttribute(TDataStd_RealArray::GetID(), anArray))
382 return QTransform(); // return identity if there is no array
384 anArray->Value(1), anArray->Value(2), anArray->Value(3),
385 anArray->Value(4), anArray->Value(5), anArray->Value(6),
386 anArray->Value(7), anArray->Value(8), anArray->Value(9));
390 void HYDROData_Image::UpdateTrsf()
392 QPoint aPointA, aPointB, aPointC;
393 if ( !GetLocalPoints( aPointA, aPointB, aPointC ) )
396 TransformationMode aTrsfMode;
397 QPointF aTrsfPointA, aTrsfPointB, aTrsfPointC;
398 if ( !GetGlobalPoints( aTrsfMode, aTrsfPointA, aTrsfPointB, aTrsfPointC ) )
401 QTransform aRefTransform;
402 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
404 bool anIsRefImage = aTrsfMode == ReferenceImage;
407 if ( aRefImage.IsNull() )
410 aRefTransform = aRefImage->Trsf();
413 bool anIsByTwoPoints = IsByTwoPoints();
415 // Convert lambert coordinates to cartesian
416 if ( aTrsfMode == ManualGeodesic )
418 double aXCart = 0, aYCart = 0;
420 HYDROData_Lambert93::toXY( aTrsfPointA.y(), aTrsfPointA.x(), aXCart, aYCart );
421 aTrsfPointA = QPointF( aXCart, aYCart );
423 HYDROData_Lambert93::toXY( aTrsfPointB.y(), aTrsfPointB.x(), aXCart, aYCart );
424 aTrsfPointB = QPointF( aXCart, aYCart );
426 if ( !anIsByTwoPoints )
428 HYDROData_Lambert93::toXY( aTrsfPointC.y(), aTrsfPointC.x(), aXCart, aYCart );
429 aTrsfPointC = QPointF( aXCart, aYCart );
433 // generate third points if needed
434 if ( anIsByTwoPoints )
436 aPointC = generateThirdPoint( aPointA, aPointB, true ).toPoint();
437 aTrsfPointC = generateThirdPoint( aTrsfPointA, aTrsfPointB, anIsRefImage );
440 int xa = aPointA.x();
441 int ya = aPointA.y();
442 int xb = aPointB.x();
443 int yb = aPointB.y();
444 int xc = aPointC.x();
445 int yc = aPointC.y();
447 double xta = aTrsfPointA.x();
448 double yta = aTrsfPointA.y();
449 double xtb = aTrsfPointB.x();
450 double ytb = aTrsfPointB.y();
451 double xtc = aTrsfPointC.x();
452 double ytc = aTrsfPointC.y();
454 // first, check that three input points don't belong to a single line
455 if( ( yb - ya ) * ( xc - xa ) == ( yc - ya ) * ( xb - xa ) )
458 // the same check for the reference points
459 if( anIsRefImage && ( ( ytb - yta ) * ( xtc - xta ) == ( ytc - yta ) * ( xtb - xta ) ) )
462 QTransform aTransform1( xa, ya, 1, xb, yb, 1, xc, yc, 1 );
463 QTransform aTransform2( xta, yta, 1, xtb, ytb, 1, xtc, ytc, 1 );
465 bool anIsInvertible = false;
466 QTransform aTransform1Inverted = aTransform1.inverted( &anIsInvertible );
467 if( !anIsInvertible )
470 QTransform aResTransform = aTransform1Inverted * aTransform2;
472 aResTransform *= aRefTransform;
474 SetTrsf( aResTransform );
477 bool HYDROData_Image::IsByTwoPoints() const
479 if ( !HasLocalPoints() || !HasGlobalPoints() )
482 QPoint aPointA, aPointB, aPointC;
483 GetLocalPoints( aPointA, aPointB, aPointC );
485 return aPointC.x() < 0 && aPointC.y() < 0;
488 bool HYDROData_Image::HasReferences() const
490 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
491 int aNbReferences = NbReferences();
493 return !aRefImage.IsNull() || aNbReferences > 0;
496 void HYDROData_Image::RemoveAllReferences()
498 if ( !HasReferences() )
501 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
502 if ( !aRefImage.IsNull() )
504 RemoveTrsfReferenceImage();
509 SetOperatorName( "" );
511 SetIsSelfSplitted( false );
514 bool anIsByTwoPoints = IsByTwoPoints();
516 QImage anImage = Image();
517 if ( anImage.isNull() )
523 // Set local points to default position
524 QPoint aLocalPointA = QPoint( 0, 0 );
525 QPoint aLocalPointB = QPoint( anImage.width(), 0 );
526 QPoint aLocalPointC = anIsByTwoPoints ? QPoint( INT_MIN, INT_MIN ) : QPoint( 0, anImage.height() );
528 SetLocalPoints( aLocalPointA, aLocalPointB, aLocalPointC, false );
530 // Calculate global points
531 QTransform aTransform = Trsf();
533 QPointF aTrsfPointA = QPointF( aTransform.map( aLocalPointA ) );
534 QPointF aTrsfPointB = QPointF( aTransform.map( aLocalPointB ) );
535 QPointF aTrsfPointC = anIsByTwoPoints ? QPointF( INT_MIN, INT_MIN ) :
536 QPointF( aTransform.map( aLocalPointC ) );
538 SetGlobalPoints( ManualCartesian, aTrsfPointA, aTrsfPointB, aTrsfPointC );
543 void HYDROData_Image::SetLocalPoints( const QPoint& thePointA,
544 const QPoint& thePointB,
545 const QPoint& thePointC,
546 const bool theIsUpdate )
548 Handle(TDataStd_RealArray) anArray;
549 if ( !myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
550 anArray = TDataStd_RealArray::Set( myLab.FindChild( DataTag_TrsfPoints ), 1, 12 );
552 anArray->SetValue( 1, thePointA.x() );
553 anArray->SetValue( 2, thePointA.y() );
554 anArray->SetValue( 3, thePointB.x() );
555 anArray->SetValue( 4, thePointB.y() );
556 anArray->SetValue( 5, thePointC.x() );
557 anArray->SetValue( 6, thePointC.y() );
559 TDataStd_UAttribute::Set( myLab.FindChild( DataTag_TrsfPoints ), GUID_HAS_LOCAL_POINTS );
567 bool HYDROData_Image::GetLocalPoints( QPoint& thePointA,
569 QPoint& thePointC ) const
571 if ( !HasLocalPoints() )
574 Handle(TDataStd_RealArray) anArray;
575 myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray );
577 thePointA = QPointF( anArray->Value( 1 ), anArray->Value( 2 ) ).toPoint();
578 thePointB = QPointF( anArray->Value( 3 ), anArray->Value( 4 ) ).toPoint();
579 thePointC = QPointF( anArray->Value( 5 ), anArray->Value( 6 ) ).toPoint();
584 bool HYDROData_Image::HasLocalPoints() const
586 TDF_Label aLabel = myLab.FindChild( DataTag_TrsfPoints, false );
587 if ( aLabel.IsNull() || !aLabel.IsAttribute( GUID_HAS_LOCAL_POINTS ) )
590 Handle(TDataStd_RealArray) anArray;
591 return aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray );
595 void HYDROData_Image::SetGlobalPoints( const TransformationMode& theMode,
596 const QPointF& thePointA,
597 const QPointF& thePointB,
598 const QPointF& thePointC,
599 const bool theIsUpdate )
601 Handle(TDataStd_RealArray) anArray;
602 if ( !myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
603 anArray = TDataStd_RealArray::Set( myLab.FindChild( DataTag_TrsfPoints ), 1, 12 );
605 anArray->SetValue( 7, thePointA.x() );
606 anArray->SetValue( 8, thePointA.y() );
607 anArray->SetValue( 9, thePointB.x() );
608 anArray->SetValue( 10, thePointB.y() );
609 anArray->SetValue( 11, thePointC.x() );
610 anArray->SetValue( 12, thePointC.y() );
612 SetTrsfMode( theMode );
614 TDataStd_UAttribute::Set( myLab.FindChild( DataTag_TrsfPoints ), GUID_HAS_GLOBAL_POINTS );
622 bool HYDROData_Image::GetGlobalPoints( TransformationMode& theMode,
625 QPointF& thePointC ) const
627 if ( !HasGlobalPoints() )
630 theMode = GetTrsfMode();
632 Handle(TDataStd_RealArray) anArray;
633 myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray );
635 thePointA = QPointF( anArray->Value( 7 ), anArray->Value( 8 ) );
636 thePointB = QPointF( anArray->Value( 9 ), anArray->Value( 10 ) );
637 thePointC = QPointF( anArray->Value( 11 ), anArray->Value( 12 ) );
642 bool HYDROData_Image::SetGlobalPointsFromFile( const QString& theFileName )
646 // Try to open the file
647 QFile aFile( theFileName );
648 if ( !aFile.exists() || !aFile.open( QIODevice::ReadOnly ) ) {
652 QPointF aPointA, aPointB;
653 double aXmin, anYmin, aXmax, anYmax;
654 aXmin = anYmin = aXmax = anYmax = -1;
656 while ( !aFile.atEnd() &&
657 ( aXmin < 0 || anYmin < 0 || aXmax < 0 || anYmax < 0 ) ) {
659 QString aLine = aFile.readLine().simplified();
660 aLine.replace( " ", "" );
661 if ( aLine.isEmpty() ) {
665 // Try to read double value after ":"
666 bool isDoubleOk = false;
667 double aDoubleValue = -1;
668 QStringList aValues = aLine.split( ":", QString::SkipEmptyParts );
669 if ( aValues.count() == 2 ) {
670 aDoubleValue = aValues.last().toDouble( &isDoubleOk );
675 boost::math::isnan( aDoubleValue ) ||
676 boost::math::isinf( aDoubleValue ) ) {
681 if ( aLine.startsWith( "Xminimum" ) ) {
682 aXmin = aDoubleValue;
684 else if ( aLine.startsWith( "Yminimum" ) ) {
685 anYmin = aDoubleValue;
687 else if ( aLine.startsWith( "Xmaximum" ) ) {
688 aXmax = aDoubleValue;
690 else if ( aLine.startsWith( "Ymaximum" ) ) {
691 anYmax = aDoubleValue;
698 if ( aXmin >= 0 && anYmin >= 0 ) {
699 aPointA.setX( aXmin );
700 aPointA.setY( anYmin );
703 if ( aXmax >= 0 && anYmax >= 0 ) {
704 aPointB.setX( aXmax );
705 aPointB.setY( anYmax );
708 if ( !aPointA.isNull() && !aPointB.isNull() ) {
709 SetGlobalPoints( ManualCartesian, aPointA, aPointB );
716 bool HYDROData_Image::HasGlobalPoints() const
718 TDF_Label aLabel = myLab.FindChild( DataTag_TrsfPoints, false );
719 if ( aLabel.IsNull() || !aLabel.IsAttribute( GUID_HAS_GLOBAL_POINTS ) )
722 Handle(TDataStd_RealArray) anArray;
723 return aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray );
726 void HYDROData_Image::SetReferencePoints( const Handle(HYDROData_Image)& theRefImage,
727 const QPointF& thePointA,
728 const QPointF& thePointB,
729 const QPointF& thePointC,
730 const bool theIsUpdate )
732 SetTrsfReferenceImage( theRefImage );
733 SetGlobalPoints( ReferenceImage, thePointA, thePointB, thePointC, theIsUpdate );
736 bool HYDROData_Image::GetReferencePoints( Handle(HYDROData_Image)& theRefImage,
739 QPointF& thePointC ) const
741 if ( !HasReferencePoints() )
744 theRefImage = GetTrsfReferenceImage();
746 TransformationMode aMode;
747 GetGlobalPoints( aMode, thePointA, thePointB, thePointC );
752 bool HYDROData_Image::HasReferencePoints() const
754 if ( !HasGlobalPoints() )
757 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
758 if ( aRefImage.IsNull() )
761 TransformationMode aTrsfMode = GetTrsfMode();
762 if ( aTrsfMode != ReferenceImage )
768 void HYDROData_Image::SetTrsfMode( const TransformationMode& theMode )
770 TDataStd_Integer::Set( myLab.FindChild( DataTag_TrsfMode ), (int)theMode );
774 HYDROData_Image::TransformationMode HYDROData_Image::GetTrsfMode() const
776 TransformationMode aResMode = ManualGeodesic;
778 TDF_Label aLabel = myLab.FindChild( DataTag_TrsfPoints, false );
779 if ( !aLabel.IsNull() )
781 Handle(TDataStd_Integer) aMode;
782 if ( myLab.FindChild( DataTag_TrsfMode ).FindAttribute( TDataStd_Integer::GetID(), aMode ) )
783 aResMode = (TransformationMode)aMode->Get();
789 void HYDROData_Image::SetTrsfReferenceImage( const Handle(HYDROData_Image)& theRefImage )
791 SetReferenceObject( theRefImage, DataTag_TrsfImage );
795 Handle(HYDROData_Image) HYDROData_Image::GetTrsfReferenceImage() const
797 return Handle(HYDROData_Image)::DownCast( GetReferenceObject( DataTag_TrsfImage ) );
800 void HYDROData_Image::RemoveTrsfReferenceImage()
802 RemoveReferenceObject( DataTag_TrsfImage );
806 void HYDROData_Image::AppendReference( const Handle(HYDROData_Entity)& theReferenced )
808 AddReferenceObject( theReferenced, 0 );
812 int HYDROData_Image::NbReferences() const
814 return NbReferenceObjects( 0 );
817 Handle(HYDROData_Entity) HYDROData_Image::Reference( const int theIndex ) const
819 return GetReferenceObject( 0, theIndex );
822 void HYDROData_Image::ChangeReference(
823 const int theIndex, Handle(HYDROData_Entity) theReferenced)
825 SetReferenceObject( theReferenced, 0, theIndex );
829 void HYDROData_Image::RemoveReference(const int theIndex)
831 RemoveReferenceObject( 0, theIndex );
835 void HYDROData_Image::ClearReferences()
837 ClearReferenceObjects( 0 );
841 void HYDROData_Image::SetOperatorName( const QString theOpName )
843 TCollection_AsciiString anAsciiStr( theOpName.toStdString().c_str() );
844 TDataStd_AsciiString::Set( myLab.FindChild( DataTag_Operator ), anAsciiStr );
848 QString HYDROData_Image::OperatorName() const
852 TDF_Label aLabel = myLab.FindChild( DataTag_Operator, false );
853 if ( !aLabel.IsNull() )
855 Handle(TDataStd_AsciiString) anAsciiStr;
856 if ( aLabel.FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) )
857 aRes = QString( anAsciiStr->Get().ToCString() );
863 void HYDROData_Image::SetArgs(const QByteArray& theArgs)
865 SaveByteArray(DataTag_Operator, theArgs.constData(), theArgs.length());
869 QByteArray HYDROData_Image::Args() const
872 const char* aData = ByteArray(DataTag_Operator, aLen);
875 return QByteArray(aData, aLen);
878 void HYDROData_Image::SetIsSelfSplitted(bool theFlag)
881 TDataStd_UAttribute::Set(myLab, GUID_SELF_SPLITTED);
883 myLab.ForgetAttribute(GUID_SELF_SPLITTED);
888 bool HYDROData_Image::IsSelfSplitted() const
890 return myLab.IsAttribute(GUID_SELF_SPLITTED);
893 QPointF HYDROData_Image::generateThirdPoint( const QPointF& thePointA,
894 const QPointF& thePointB,
895 const bool& theIsLocal ) const
897 // Rotate vector to 90 degrees : clockwise - for local
898 // counterclockwise - for global
899 const double aTheta = theIsLocal ? -M_PI_2 : M_PI_2;
903 // Move to (0,0) for correct rotation
904 double x = thePointB.x() - thePointA.x();
905 double y = thePointB.y() - thePointA.y();
907 aResPoint.setX( x * cos( aTheta ) - y * sin( aTheta ) );
908 aResPoint.setY( x * sin( aTheta ) + y * cos( aTheta ) );
910 // Move back to origin position
911 aResPoint.setX( aResPoint.x() + thePointA.x() );
912 aResPoint.setY( aResPoint.y() + thePointA.y() );