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 static const Standard_GUID GUID_SELF_SPLIT("997995aa-5c19-40bf-9a60-ab4b70ad04d8");
48 static const Standard_GUID GUID_HAS_LOCAL_POINTS("FD8841AA-FC44-42fa-B6A7-0F682CCC6F27");
49 static const Standard_GUID GUID_HAS_GLOBAL_POINTS("330D0E81-742D-4ea3-92D4-484877CFA7C1");
51 IMPLEMENT_STANDARD_HANDLE(HYDROData_Image, HYDROData_Entity)
52 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Image, HYDROData_Entity)
54 HYDROData_Image::HYDROData_Image()
55 : HYDROData_Entity( Geom_2d )
59 HYDROData_Image::~HYDROData_Image()
63 QStringList HYDROData_Image::DumpToPython( const QString& thePyScriptPath,
64 MapOfTreatedObjects& theTreatedObjects ) const
66 QStringList aResList = dumpObjectCreation( theTreatedObjects );
67 QString anImageName = GetObjPyName();
69 QString aFilePath = GetFilePath();
70 if ( !aFilePath.isEmpty() )
72 aResList << QString( "" );
73 aResList << QString( "%1.LoadImage( \"%2\" );" )
74 .arg( anImageName ).arg( aFilePath );
75 aResList << QString( "" );
77 // Dump transformation points for image
79 bool anIsByTwoPoints = IsByTwoPoints();
81 QPoint aLocalPointA, aLocalPointB, aLocalPointC;
82 if ( GetLocalPoints( aLocalPointA, aLocalPointB, aLocalPointC ) )
84 QString aGap = QString().fill( ' ', anImageName.size() + 17 );
86 aResList << QString( "%1.SetLocalPoints( QPoint( %2, %3 )," )
87 .arg( anImageName ).arg( aLocalPointA.x() ).arg( aLocalPointA.y() );
88 aResList << QString( aGap + "QPoint( %1, %2 )" )
89 .arg( aLocalPointB.x() ).arg( aLocalPointB.y() );
90 if ( !anIsByTwoPoints )
92 aResList.last().append( "," );
93 aResList << QString( aGap + "QPoint( %1, %2 ) );" )
94 .arg( aLocalPointC.x() ).arg( aLocalPointC.y() );
98 aResList.last().append( " );" );
100 aResList << QString( "" );
103 HYDROData_Image::TransformationMode aTransformationMode;
104 QPointF aTrsfPointA, aTrsfPointB, aTrsfPointC;
105 if ( GetGlobalPoints( aTransformationMode, aTrsfPointA, aTrsfPointB, aTrsfPointC ) )
107 QString aGap = QString().fill( ' ', anImageName.size() + 18 );
109 aResList << QString( "%1.SetGlobalPoints( %2," )
110 .arg( anImageName ).arg( aTransformationMode );
111 aResList << QString( aGap + "QPointF( %1, %2 )," )
112 .arg( aTrsfPointA.x() ).arg( aTrsfPointA.y() );
113 aResList << QString( aGap + "QPointF( %1, %2 )" )
114 .arg( aTrsfPointB.x() ).arg( aTrsfPointB.y() );
115 if ( !anIsByTwoPoints )
117 aResList.last().append( "," );
118 aResList << QString( aGap + "QPointF( %1, %2 ) );" )
119 .arg( aTrsfPointC.x() ).arg( aTrsfPointC.y() );
123 aResList.last().append( " );" );
126 if ( aTransformationMode == ReferenceImage )
128 Handle(HYDROData_Image) aRefImg = GetTrsfReferenceImage();
129 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aRefImg, "SetTrsfReferenceImage" );
135 // Image is composed from other image(s)
137 QString anOperatorName = OperatorName();
138 if ( !anOperatorName.isEmpty() )
140 aResList << QString( "" );
142 aResList << QString( "%1.SetOperatorName( \"%2\" );" )
143 .arg( anImageName ).arg( anOperatorName );
145 ImageComposer_Operator* anImageOp =
146 HYDROData_OperationsFactory::Factory()->Operator( OperatorName() );
149 // Dump operation arguments
150 QString anOpArgsArrayName;
151 QStringList anOpArgs = anImageOp->dumpArgsToPython( anOpArgsArrayName );
152 if ( !anOpArgs.isEmpty() )
154 aResList << QString( "" );
155 aResList << anOpArgs;
157 aResList << QString( "" );
158 aResList << QString( "%1.SetArgs( %2 );" )
159 .arg( anImageName ).arg( anOpArgsArrayName );
164 int aNbReferences = NbReferences();
165 if ( aNbReferences > 0 )
167 aResList << QString( "" );
169 for ( int i = 0; i < aNbReferences; ++i )
171 Handle(HYDROData_Image) aRefImg = Handle(HYDROData_Image)::DownCast( Reference( i ) );
172 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aRefImg, "AppendReference" );
177 aResList << QString( "" );
178 aResList << QString( "%1.Update();" ).arg( anImageName );
183 void HYDROData_Image::Update()
185 bool anIsToUpdate = IsMustBeUpdated( Geom_2d );
187 HYDROData_Entity::Update();
192 HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory();
194 ImageComposer_Operator* anOp = aFactory->Operator( OperatorName() );
195 if ( anOp ) // Update image if there is an operation
197 // Fill by arguments and process the operation
198 anOp->setBinArgs( Args() );
200 QVariant anObj1, anObj2;
201 int aNbReferences = NbReferences();
203 if ( aNbReferences > 0 )
205 // First referenced object
206 Handle(HYDROData_Entity) aRefObj = Reference( 0 );
207 if ( !aRefObj.IsNull() )
209 anObj1 = aRefObj->GetDataVariant();
210 if ( !anObj1.isNull() && anObj1.canConvert<ImageComposer_Image>() )
212 ImageComposer_Image anImage = anObj1.value<ImageComposer_Image>();
213 QTransform aTransform = anImage.transform();
214 SetTrsf( aTransform );
219 if ( aNbReferences > 1 )
221 // Second referenced object
222 Handle(HYDROData_Entity) aRefObj = Reference( 1 );
223 if ( !aRefObj.IsNull() )
224 anObj2 = aRefObj->GetDataVariant();
227 ImageComposer_Image aResImg = anOp->process( anObj1, anObj2 );
229 SetTrsf( aResImg.transform() );
231 else // Update image if it positioned relatively to other image
239 bool HYDROData_Image::IsHas2dPrs() const
244 QVariant HYDROData_Image::GetDataVariant()
246 QTransform aTransform = Trsf();
248 ImageComposer_Image anImage = Image();
249 anImage.setTransform( aTransform );
252 aVarData.setValue<ImageComposer_Image>( anImage );
257 HYDROData_SequenceOfObjects HYDROData_Image::GetAllReferenceObjects() const
259 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
261 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
262 if ( !aRefImage.IsNull() )
263 aResSeq.Append( aRefImage );
265 HYDROData_SequenceOfObjects aSeqRefObjects = GetReferenceObjects( 0 );
266 aResSeq.Append( aSeqRefObjects );
271 void HYDROData_Image::SetImage(const QImage& theImage)
273 if ( theImage.isNull() )
275 // for empty image remove all previously stored attributes
276 myLab.ForgetAttribute(TDataStd_IntegerArray::GetID());
277 myLab.ForgetAttribute(TDataStd_ByteArray::GetID());
283 // convert 8-bits images
284 if ( theImage.format() == QImage::Format_Indexed8 ) {
285 anImage = theImage.convertToFormat( QImage::Format_RGB32 );
290 // store width, height, bytes per line and format in integer array
291 Handle(TDataStd_IntegerArray) aParams;
292 if (!myLab.FindAttribute(TDataStd_IntegerArray::GetID(), aParams)) {
293 aParams = TDataStd_IntegerArray::Set(myLab, 1, 4);
295 aParams->SetValue(1, anImage.width());
296 aParams->SetValue(2, anImage.height());
297 aParams->SetValue(3, anImage.bytesPerLine());
298 aParams->SetValue(4, (int)(anImage.format()));
299 // store data of image in byte array
300 const char* aData = (const char*)(anImage.bits());
301 SaveByteArray(0, aData, anImage.byteCount());
307 bool HYDROData_Image::LoadImage( const QString& theFilePath )
309 QImage anImage( theFilePath );
312 SetFilePath( theFilePath );
314 return !anImage.isNull();
317 QImage HYDROData_Image::Image()
319 Handle(TDataStd_IntegerArray) aParams;
320 if (!myLab.FindAttribute(TDataStd_IntegerArray::GetID(), aParams))
321 return QImage(); // return empty image if there is no array
323 uchar* anArray = (uchar*)ByteArray(0, aLen);
325 return QImage(); // return empty image if there is no array
326 QImage aResult(anArray, aParams->Value(1), aParams->Value(2),
327 aParams->Value(3), QImage::Format(aParams->Value(4)));
331 void HYDROData_Image::SetFilePath( const QString& theFilePath )
333 TCollection_AsciiString anAsciiStr( theFilePath.toStdString().c_str() );
334 TDataStd_AsciiString::Set( myLab.FindChild( DataTag_FilePath ), anAsciiStr );
339 QString HYDROData_Image::GetFilePath() const
343 TDF_Label aLabel = myLab.FindChild( DataTag_FilePath, false );
344 if ( !aLabel.IsNull() )
346 Handle(TDataStd_AsciiString) anAsciiStr;
347 if ( aLabel.FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) )
348 aRes = QString( anAsciiStr->Get().ToCString() );
354 void HYDROData_Image::SetTrsf(const QTransform& theTrsf)
356 // locate 9 coeffs of matrix into the real array
357 Handle(TDataStd_RealArray) anArray;
358 if (!myLab.FindAttribute(TDataStd_RealArray::GetID(), anArray)) {
359 if (theTrsf.isIdentity()) return; // no need to store identity transformation
360 anArray = TDataStd_RealArray::Set(myLab, 1, 9);
362 anArray->SetValue(1, theTrsf.m11());
363 anArray->SetValue(2, theTrsf.m12());
364 anArray->SetValue(3, theTrsf.m13());
365 anArray->SetValue(4, theTrsf.m21());
366 anArray->SetValue(5, theTrsf.m22());
367 anArray->SetValue(6, theTrsf.m23());
368 anArray->SetValue(7, theTrsf.m31());
369 anArray->SetValue(8, theTrsf.m32());
370 anArray->SetValue(9, theTrsf.m33());
375 QTransform HYDROData_Image::Trsf() const
377 // get 9 coeffs of matrix from the real array
378 Handle(TDataStd_RealArray) anArray;
379 if (!myLab.FindAttribute(TDataStd_RealArray::GetID(), anArray))
380 return QTransform(); // return identity if there is no array
382 anArray->Value(1), anArray->Value(2), anArray->Value(3),
383 anArray->Value(4), anArray->Value(5), anArray->Value(6),
384 anArray->Value(7), anArray->Value(8), anArray->Value(9));
388 void HYDROData_Image::UpdateTrsf()
390 QPoint aPointA, aPointB, aPointC;
391 if ( !GetLocalPoints( aPointA, aPointB, aPointC ) )
394 TransformationMode aTrsfMode;
395 QPointF aTrsfPointA, aTrsfPointB, aTrsfPointC;
396 if ( !GetGlobalPoints( aTrsfMode, aTrsfPointA, aTrsfPointB, aTrsfPointC ) )
399 QTransform aRefTransform;
400 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
402 bool anIsRefImage = aTrsfMode == ReferenceImage;
405 if ( aRefImage.IsNull() )
408 aRefTransform = aRefImage->Trsf();
411 bool anIsByTwoPoints = IsByTwoPoints();
413 // Convert lambert coordinates to cartesian
414 if ( aTrsfMode == ManualGeodesic )
416 double aXCart = 0, aYCart = 0;
418 HYDROData_Lambert93::toXY( aTrsfPointA.y(), aTrsfPointA.x(), aXCart, aYCart );
419 aTrsfPointA = QPointF( aXCart, aYCart );
421 HYDROData_Lambert93::toXY( aTrsfPointB.y(), aTrsfPointB.x(), aXCart, aYCart );
422 aTrsfPointB = QPointF( aXCart, aYCart );
424 if ( !anIsByTwoPoints )
426 HYDROData_Lambert93::toXY( aTrsfPointC.y(), aTrsfPointC.x(), aXCart, aYCart );
427 aTrsfPointC = QPointF( aXCart, aYCart );
431 // generate third points if needed
432 if ( anIsByTwoPoints )
434 aPointC = generateThirdPoint( aPointA, aPointB, true ).toPoint();
435 aTrsfPointC = generateThirdPoint( aTrsfPointA, aTrsfPointB, anIsRefImage );
438 int xa = aPointA.x();
439 int ya = aPointA.y();
440 int xb = aPointB.x();
441 int yb = aPointB.y();
442 int xc = aPointC.x();
443 int yc = aPointC.y();
445 double xta = aTrsfPointA.x();
446 double yta = aTrsfPointA.y();
447 double xtb = aTrsfPointB.x();
448 double ytb = aTrsfPointB.y();
449 double xtc = aTrsfPointC.x();
450 double ytc = aTrsfPointC.y();
452 // first, check that three input points don't belong to a single line
453 if( ( yb - ya ) * ( xc - xa ) == ( yc - ya ) * ( xb - xa ) )
456 // the same check for the reference points
457 if( anIsRefImage && ( ( ytb - yta ) * ( xtc - xta ) == ( ytc - yta ) * ( xtb - xta ) ) )
460 QTransform aTransform1( xa, ya, 1, xb, yb, 1, xc, yc, 1 );
461 QTransform aTransform2( xta, yta, 1, xtb, ytb, 1, xtc, ytc, 1 );
463 bool anIsInvertible = false;
464 QTransform aTransform1Inverted = aTransform1.inverted( &anIsInvertible );
465 if( !anIsInvertible )
468 QTransform aResTransform = aTransform1Inverted * aTransform2;
470 aResTransform *= aRefTransform;
472 SetTrsf( aResTransform );
475 bool HYDROData_Image::IsByTwoPoints() const
477 if ( !HasLocalPoints() || !HasGlobalPoints() )
480 QPoint aPointA, aPointB, aPointC;
481 GetLocalPoints( aPointA, aPointB, aPointC );
483 return aPointC.x() < 0 && aPointC.y() < 0;
486 bool HYDROData_Image::HasReferences() const
488 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
489 int aNbReferences = NbReferences();
491 return !aRefImage.IsNull() || aNbReferences > 0;
494 void HYDROData_Image::RemoveAllReferences()
496 if ( !HasReferences() )
499 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
500 if ( !aRefImage.IsNull() )
502 RemoveTrsfReferenceImage();
507 SetOperatorName( "" );
509 SetIsSelfSplit( false );
512 bool anIsByTwoPoints = IsByTwoPoints();
514 QImage anImage = Image();
515 if ( anImage.isNull() )
521 // Set local points to default position
522 QPoint aLocalPointA = QPoint( 0, 0 );
523 QPoint aLocalPointB = QPoint( anImage.width(), 0 );
524 QPoint aLocalPointC = anIsByTwoPoints ? QPoint( INT_MIN, INT_MIN ) : QPoint( 0, anImage.height() );
526 SetLocalPoints( aLocalPointA, aLocalPointB, aLocalPointC, false );
528 // Calculate global points
529 QTransform aTransform = Trsf();
531 QPointF aTrsfPointA = QPointF( aTransform.map( aLocalPointA ) );
532 QPointF aTrsfPointB = QPointF( aTransform.map( aLocalPointB ) );
533 QPointF aTrsfPointC = anIsByTwoPoints ? QPointF( INT_MIN, INT_MIN ) :
534 QPointF( aTransform.map( aLocalPointC ) );
536 SetGlobalPoints( ManualCartesian, aTrsfPointA, aTrsfPointB, aTrsfPointC );
541 void HYDROData_Image::SetLocalPoints( const QPoint& thePointA,
542 const QPoint& thePointB,
543 const QPoint& thePointC,
544 const bool theIsUpdate )
546 Handle(TDataStd_RealArray) anArray;
547 if ( !myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
548 anArray = TDataStd_RealArray::Set( myLab.FindChild( DataTag_TrsfPoints ), 1, 12 );
550 anArray->SetValue( 1, thePointA.x() );
551 anArray->SetValue( 2, thePointA.y() );
552 anArray->SetValue( 3, thePointB.x() );
553 anArray->SetValue( 4, thePointB.y() );
554 anArray->SetValue( 5, thePointC.x() );
555 anArray->SetValue( 6, thePointC.y() );
557 TDataStd_UAttribute::Set( myLab.FindChild( DataTag_TrsfPoints ), GUID_HAS_LOCAL_POINTS );
565 bool HYDROData_Image::GetLocalPoints( QPoint& thePointA,
567 QPoint& thePointC ) const
569 if ( !HasLocalPoints() )
572 Handle(TDataStd_RealArray) anArray;
573 myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray );
575 thePointA = QPointF( anArray->Value( 1 ), anArray->Value( 2 ) ).toPoint();
576 thePointB = QPointF( anArray->Value( 3 ), anArray->Value( 4 ) ).toPoint();
577 thePointC = QPointF( anArray->Value( 5 ), anArray->Value( 6 ) ).toPoint();
582 bool HYDROData_Image::HasLocalPoints() const
584 TDF_Label aLabel = myLab.FindChild( DataTag_TrsfPoints, false );
585 if ( aLabel.IsNull() || !aLabel.IsAttribute( GUID_HAS_LOCAL_POINTS ) )
588 Handle(TDataStd_RealArray) anArray;
589 return aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray );
593 void HYDROData_Image::SetGlobalPoints( const TransformationMode& theMode,
594 const QPointF& thePointA,
595 const QPointF& thePointB,
596 const QPointF& thePointC,
597 const bool theIsUpdate )
599 Handle(TDataStd_RealArray) anArray;
600 if ( !myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
601 anArray = TDataStd_RealArray::Set( myLab.FindChild( DataTag_TrsfPoints ), 1, 12 );
603 anArray->SetValue( 7, thePointA.x() );
604 anArray->SetValue( 8, thePointA.y() );
605 anArray->SetValue( 9, thePointB.x() );
606 anArray->SetValue( 10, thePointB.y() );
607 anArray->SetValue( 11, thePointC.x() );
608 anArray->SetValue( 12, thePointC.y() );
610 SetTrsfMode( theMode );
612 TDataStd_UAttribute::Set( myLab.FindChild( DataTag_TrsfPoints ), GUID_HAS_GLOBAL_POINTS );
620 bool HYDROData_Image::GetGlobalPoints( TransformationMode& theMode,
623 QPointF& thePointC ) const
625 if ( !HasGlobalPoints() )
628 theMode = GetTrsfMode();
630 Handle(TDataStd_RealArray) anArray;
631 myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray );
633 thePointA = QPointF( anArray->Value( 7 ), anArray->Value( 8 ) );
634 thePointB = QPointF( anArray->Value( 9 ), anArray->Value( 10 ) );
635 thePointC = QPointF( anArray->Value( 11 ), anArray->Value( 12 ) );
640 bool HYDROData_Image::SetGlobalPointsFromFile( const QString& theFileName )
644 // Try to open the file
645 QFile aFile( theFileName );
646 if ( !aFile.exists() || !aFile.open( QIODevice::ReadOnly ) ) {
650 QPointF aPointA, aPointB;
651 double aXmin, anYmin, aXmax, anYmax;
652 aXmin = anYmin = aXmax = anYmax = -1;
654 while ( !aFile.atEnd() &&
655 ( aXmin < 0 || anYmin < 0 || aXmax < 0 || anYmax < 0 ) ) {
657 QString aLine = aFile.readLine().simplified();
658 aLine.replace( " ", "" );
659 if ( aLine.isEmpty() ) {
663 // Try to read double value after ":"
664 bool isDoubleOk = false;
665 double aDoubleValue = -1;
666 QStringList aValues = aLine.split( ":", QString::SkipEmptyParts );
667 if ( aValues.count() == 2 ) {
668 aDoubleValue = aValues.last().toDouble( &isDoubleOk );
673 isnan( aDoubleValue ) ||
674 isinf( aDoubleValue ) ) {
679 if ( aLine.startsWith( "Xminimum" ) ) {
680 aXmin = aDoubleValue;
682 else if ( aLine.startsWith( "Yminimum" ) ) {
683 anYmin = aDoubleValue;
685 else if ( aLine.startsWith( "Xmaximum" ) ) {
686 aXmax = aDoubleValue;
688 else if ( aLine.startsWith( "Ymaximum" ) ) {
689 anYmax = aDoubleValue;
696 if ( aXmin >= 0 && anYmin >= 0 ) {
697 aPointA.setX( aXmin );
698 aPointA.setY( anYmin );
701 if ( aXmax >= 0 && anYmax >= 0 ) {
702 aPointB.setX( aXmax );
703 aPointB.setY( anYmax );
706 if ( !aPointA.isNull() && !aPointB.isNull() ) {
707 SetGlobalPoints( ManualCartesian, aPointA, aPointB );
714 bool HYDROData_Image::HasGlobalPoints() const
716 TDF_Label aLabel = myLab.FindChild( DataTag_TrsfPoints, false );
717 if ( aLabel.IsNull() || !aLabel.IsAttribute( GUID_HAS_GLOBAL_POINTS ) )
720 Handle(TDataStd_RealArray) anArray;
721 return aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray );
724 void HYDROData_Image::SetReferencePoints( const Handle(HYDROData_Image)& theRefImage,
725 const QPointF& thePointA,
726 const QPointF& thePointB,
727 const QPointF& thePointC,
728 const bool theIsUpdate )
730 SetTrsfReferenceImage( theRefImage );
731 SetGlobalPoints( ReferenceImage, thePointA, thePointB, thePointC, theIsUpdate );
734 bool HYDROData_Image::GetReferencePoints( Handle(HYDROData_Image)& theRefImage,
737 QPointF& thePointC ) const
739 if ( !HasReferencePoints() )
742 theRefImage = GetTrsfReferenceImage();
744 TransformationMode aMode;
745 GetGlobalPoints( aMode, thePointA, thePointB, thePointC );
750 bool HYDROData_Image::HasReferencePoints() const
752 if ( !HasGlobalPoints() )
755 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
756 if ( aRefImage.IsNull() )
759 TransformationMode aTrsfMode = GetTrsfMode();
760 if ( aTrsfMode != ReferenceImage )
766 void HYDROData_Image::SetTrsfMode( const TransformationMode& theMode )
768 TDataStd_Integer::Set( myLab.FindChild( DataTag_TrsfMode ), (int)theMode );
772 HYDROData_Image::TransformationMode HYDROData_Image::GetTrsfMode() const
774 TransformationMode aResMode = ManualGeodesic;
776 TDF_Label aLabel = myLab.FindChild( DataTag_TrsfPoints, false );
777 if ( !aLabel.IsNull() )
779 Handle(TDataStd_Integer) aMode;
780 if ( myLab.FindChild( DataTag_TrsfMode ).FindAttribute( TDataStd_Integer::GetID(), aMode ) )
781 aResMode = (TransformationMode)aMode->Get();
787 void HYDROData_Image::SetTrsfReferenceImage( const Handle(HYDROData_Image)& theRefImage )
789 SetReferenceObject( theRefImage, DataTag_TrsfImage );
793 Handle(HYDROData_Image) HYDROData_Image::GetTrsfReferenceImage() const
795 return Handle(HYDROData_Image)::DownCast( GetReferenceObject( DataTag_TrsfImage ) );
798 void HYDROData_Image::RemoveTrsfReferenceImage()
800 RemoveReferenceObject( DataTag_TrsfImage );
804 void HYDROData_Image::AppendReference( const Handle(HYDROData_Entity)& theReferenced )
806 AddReferenceObject( theReferenced, 0 );
810 int HYDROData_Image::NbReferences() const
812 return NbReferenceObjects( 0 );
815 Handle(HYDROData_Entity) HYDROData_Image::Reference( const int theIndex ) const
817 return GetReferenceObject( 0, theIndex );
820 void HYDROData_Image::ChangeReference(
821 const int theIndex, Handle(HYDROData_Entity) theReferenced)
823 SetReferenceObject( theReferenced, 0, theIndex );
827 void HYDROData_Image::RemoveReference(const int theIndex)
829 RemoveReferenceObject( 0, theIndex );
833 void HYDROData_Image::ClearReferences()
835 ClearReferenceObjects( 0 );
839 void HYDROData_Image::SetOperatorName( const QString theOpName )
841 TCollection_AsciiString anAsciiStr( theOpName.toStdString().c_str() );
842 TDataStd_AsciiString::Set( myLab.FindChild( DataTag_Operator ), anAsciiStr );
846 QString HYDROData_Image::OperatorName() const
850 TDF_Label aLabel = myLab.FindChild( DataTag_Operator, false );
851 if ( !aLabel.IsNull() )
853 Handle(TDataStd_AsciiString) anAsciiStr;
854 if ( aLabel.FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) )
855 aRes = QString( anAsciiStr->Get().ToCString() );
861 void HYDROData_Image::SetArgs(const QByteArray& theArgs)
863 SaveByteArray(DataTag_Operator, theArgs.constData(), theArgs.length());
867 QByteArray HYDROData_Image::Args() const
870 const char* aData = ByteArray(DataTag_Operator, aLen);
873 return QByteArray(aData, aLen);
876 void HYDROData_Image::SetIsSelfSplit(bool theFlag)
879 TDataStd_UAttribute::Set(myLab, GUID_SELF_SPLIT);
881 myLab.ForgetAttribute(GUID_SELF_SPLIT);
886 bool HYDROData_Image::IsSelfSplit() const
888 return myLab.IsAttribute(GUID_SELF_SPLIT);
891 QPointF HYDROData_Image::generateThirdPoint( const QPointF& thePointA,
892 const QPointF& thePointB,
893 const bool& theIsLocal ) const
895 // Rotate vector to 90 degrees : clockwise - for local
896 // counterclockwise - for global
897 const double aTheta = theIsLocal ? -M_PI_2 : M_PI_2;
901 // Move to (0,0) for correct rotation
902 double x = thePointB.x() - thePointA.x();
903 double y = thePointB.y() - thePointA.y();
905 aResPoint.setX( x * cos( aTheta ) - y * sin( aTheta ) );
906 aResPoint.setY( x * sin( aTheta ) + y * cos( aTheta ) );
908 // Move back to origin position
909 aResPoint.setX( aResPoint.x() + thePointA.x() );
910 aResPoint.setY( aResPoint.y() + thePointA.y() );