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>
33 #include <ImageComposer_Operator.h>
34 #include <ImageComposer_MetaTypes.h>
36 #include <QStringList>
39 #include <boost/math/special_functions/fpclassify.hpp>
41 static const Standard_GUID GUID_SELF_SPLITTED("997995aa-5c19-40bf-9a60-ab4b70ad04d8");
42 static const Standard_GUID GUID_HAS_LOCAL_POINTS("FD8841AA-FC44-42fa-B6A7-0F682CCC6F27");
43 static const Standard_GUID GUID_HAS_GLOBAL_POINTS("330D0E81-742D-4ea3-92D4-484877CFA7C1");
45 IMPLEMENT_STANDARD_HANDLE(HYDROData_Image, HYDROData_Entity)
46 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Image, HYDROData_Entity)
48 HYDROData_Image::HYDROData_Image()
53 HYDROData_Image::~HYDROData_Image()
57 QStringList HYDROData_Image::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
59 QStringList aResList = dumpObjectCreation( theTreatedObjects );
60 QString anImageName = GetObjPyName();
62 QString aFilePath = GetFilePath();
63 if ( !aFilePath.isEmpty() )
65 aResList << QString( "" );
66 aResList << QString( "%1.LoadImage( \"%2\" );" )
67 .arg( anImageName ).arg( aFilePath );
68 aResList << QString( "" );
70 // Dump transformation points for image
72 bool anIsByTwoPoints = IsByTwoPoints();
74 QPoint aLocalPointA, aLocalPointB, aLocalPointC;
75 if ( GetLocalPoints( aLocalPointA, aLocalPointB, aLocalPointC ) )
77 QString aGap = QString().fill( ' ', anImageName.size() + 17 );
79 aResList << QString( "%1.SetLocalPoints( QPoint( %2, %3 )," )
80 .arg( anImageName ).arg( aLocalPointA.x() ).arg( aLocalPointA.y() );
81 aResList << QString( aGap + "QPoint( %1, %2 )" )
82 .arg( aLocalPointB.x() ).arg( aLocalPointB.y() );
83 if ( !anIsByTwoPoints )
85 aResList.last().append( "," );
86 aResList << QString( aGap + "QPoint( %1, %2 ) );" )
87 .arg( aLocalPointC.x() ).arg( aLocalPointC.y() );
91 aResList.last().append( " );" );
93 aResList << QString( "" );
96 HYDROData_Image::TransformationMode aTransformationMode;
97 QPointF aTrsfPointA, aTrsfPointB, aTrsfPointC;
98 if ( GetGlobalPoints( aTransformationMode, aTrsfPointA, aTrsfPointB, aTrsfPointC ) )
100 QString aGap = QString().fill( ' ', anImageName.size() + 18 );
102 aResList << QString( "%1.SetGlobalPoints( %2," )
103 .arg( anImageName ).arg( aTransformationMode );
104 aResList << QString( aGap + "QPointF( %1, %2 )," )
105 .arg( aTrsfPointA.x() ).arg( aTrsfPointA.y() );
106 aResList << QString( aGap + "QPointF( %1, %2 )" )
107 .arg( aTrsfPointB.x() ).arg( aTrsfPointB.y() );
108 if ( !anIsByTwoPoints )
110 aResList.last().append( "," );
111 aResList << QString( aGap + "QPointF( %1, %2 ) );" )
112 .arg( aTrsfPointC.x() ).arg( aTrsfPointC.y() );
116 aResList.last().append( " );" );
119 if ( aTransformationMode == ReferenceImage )
121 Handle(HYDROData_Image) aRefImg = GetTrsfReferenceImage();
122 setPythonReferenceObject( theTreatedObjects, aResList, aRefImg, "SetTrsfReferenceImage" );
128 // Image is composed from other image(s)
130 QString anOperatorName = OperatorName();
131 if ( !anOperatorName.isEmpty() )
133 aResList << QString( "" );
135 aResList << QString( "%1.SetOperatorName( \"%2\" );" )
136 .arg( anImageName ).arg( anOperatorName );
138 ImageComposer_Operator* anImageOp =
139 HYDROData_OperationsFactory::Factory()->Operator( OperatorName() );
142 // Dump operation arguments
143 QString anOpArgsArrayName;
144 QStringList anOpArgs = anImageOp->dumpArgsToPython( anOpArgsArrayName );
145 if ( !anOpArgs.isEmpty() )
147 aResList << QString( "" );
148 aResList << anOpArgs;
150 aResList << QString( "" );
151 aResList << QString( "%1.SetArgs( %2 );" )
152 .arg( anImageName ).arg( anOpArgsArrayName );
157 int aNbReferences = NbReferences();
158 if ( aNbReferences > 0 )
160 aResList << QString( "" );
162 for ( int i = 0; i < aNbReferences; ++i )
164 Handle(HYDROData_Image) aRefImg = Handle(HYDROData_Image)::DownCast( Reference( i ) );
165 setPythonReferenceObject( theTreatedObjects, aResList, aRefImg, "AppendReference" );
170 aResList << QString( "" );
171 aResList << QString( "%1.Update();" ).arg( anImageName );
176 void HYDROData_Image::Update()
178 bool anIsToUpdate = IsMustBeUpdated();
180 HYDROData_Entity::Update();
185 HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory();
187 ImageComposer_Operator* anOp = aFactory->Operator( OperatorName() );
188 if ( anOp ) // Update image if there is an operation
190 // Fill by arguments and process the operation
191 anOp->setBinArgs( Args() );
193 QVariant anObj1, anObj2;
194 int aNbReferences = NbReferences();
196 if ( aNbReferences > 0 )
198 // First referenced object
199 Handle(HYDROData_Entity) aRefObj = Reference( 0 );
200 if ( !aRefObj.IsNull() )
202 anObj1 = aRefObj->GetDataVariant();
203 if ( !anObj1.isNull() && anObj1.canConvert<ImageComposer_Image>() )
205 ImageComposer_Image anImage = anObj1.value<ImageComposer_Image>();
206 QTransform aTransform = anImage.transform();
207 SetTrsf( aTransform );
212 if ( aNbReferences > 1 )
214 // Second referenced object
215 Handle(HYDROData_Entity) aRefObj = Reference( 1 );
216 if ( !aRefObj.IsNull() )
217 anObj2 = aRefObj->GetDataVariant();
220 ImageComposer_Image aResImg = anOp->process( anObj1, anObj2 );
222 SetTrsf( aResImg.transform() );
224 else // Update image if it positioned relatively to other image
229 SetToUpdate( false );
232 bool HYDROData_Image::IsHas2dPrs() const
237 QVariant HYDROData_Image::GetDataVariant()
239 QTransform aTransform = Trsf();
241 ImageComposer_Image anImage = Image();
242 anImage.setTransform( aTransform );
245 aVarData.setValue<ImageComposer_Image>( anImage );
250 HYDROData_SequenceOfObjects HYDROData_Image::GetAllReferenceObjects() const
252 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
254 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
255 if ( !aRefImage.IsNull() )
256 aResSeq.Append( aRefImage );
258 HYDROData_SequenceOfObjects aSeqRefObjects = GetReferenceObjects( 0 );
259 aResSeq.Append( aSeqRefObjects );
264 void HYDROData_Image::SetImage(const QImage& theImage)
266 if ( theImage.isNull() )
268 // for empty image remove all previously stored attributes
269 myLab.ForgetAttribute(TDataStd_IntegerArray::GetID());
270 myLab.ForgetAttribute(TDataStd_ByteArray::GetID());
276 // convert 8-bits images
277 if ( theImage.format() == QImage::Format_Indexed8 ) {
278 anImage = theImage.convertToFormat( QImage::Format_RGB32 );
283 // store width, height, bytes per line and format in integer array
284 Handle(TDataStd_IntegerArray) aParams;
285 if (!myLab.FindAttribute(TDataStd_IntegerArray::GetID(), aParams)) {
286 aParams = TDataStd_IntegerArray::Set(myLab, 1, 4);
288 aParams->SetValue(1, anImage.width());
289 aParams->SetValue(2, anImage.height());
290 aParams->SetValue(3, anImage.bytesPerLine());
291 aParams->SetValue(4, (int)(anImage.format()));
292 // store data of image in byte array
293 const char* aData = (const char*)(anImage.bits());
294 SaveByteArray(0, aData, anImage.byteCount());
300 bool HYDROData_Image::LoadImage( const QString& theFilePath )
302 QImage anImage( theFilePath );
305 SetFilePath( theFilePath );
307 return !anImage.isNull();
310 QImage HYDROData_Image::Image()
312 Handle(TDataStd_IntegerArray) aParams;
313 if (!myLab.FindAttribute(TDataStd_IntegerArray::GetID(), aParams))
314 return QImage(); // return empty image if there is no array
316 uchar* anArray = (uchar*)ByteArray(0, aLen);
318 return QImage(); // return empty image if there is no array
319 QImage aResult(anArray, aParams->Value(1), aParams->Value(2),
320 aParams->Value(3), QImage::Format(aParams->Value(4)));
324 void HYDROData_Image::SetFilePath( const QString& theFilePath )
326 TCollection_AsciiString anAsciiStr( theFilePath.toStdString().c_str() );
327 TDataStd_AsciiString::Set( myLab.FindChild( DataTag_FilePath ), anAsciiStr );
332 QString HYDROData_Image::GetFilePath() const
336 TDF_Label aLabel = myLab.FindChild( DataTag_FilePath, false );
337 if ( !aLabel.IsNull() )
339 Handle(TDataStd_AsciiString) anAsciiStr;
340 if ( aLabel.FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) )
341 aRes = QString( anAsciiStr->Get().ToCString() );
347 void HYDROData_Image::SetTrsf(const QTransform& theTrsf)
349 // locate 9 coeffs of matrix into the real array
350 Handle(TDataStd_RealArray) anArray;
351 if (!myLab.FindAttribute(TDataStd_RealArray::GetID(), anArray)) {
352 if (theTrsf.isIdentity()) return; // no need to store identity transformation
353 anArray = TDataStd_RealArray::Set(myLab, 1, 9);
355 anArray->SetValue(1, theTrsf.m11());
356 anArray->SetValue(2, theTrsf.m12());
357 anArray->SetValue(3, theTrsf.m13());
358 anArray->SetValue(4, theTrsf.m21());
359 anArray->SetValue(5, theTrsf.m22());
360 anArray->SetValue(6, theTrsf.m23());
361 anArray->SetValue(7, theTrsf.m31());
362 anArray->SetValue(8, theTrsf.m32());
363 anArray->SetValue(9, theTrsf.m33());
368 QTransform HYDROData_Image::Trsf() const
370 // get 9 coeffs of matrix from the real array
371 Handle(TDataStd_RealArray) anArray;
372 if (!myLab.FindAttribute(TDataStd_RealArray::GetID(), anArray))
373 return QTransform(); // return identity if there is no array
375 anArray->Value(1), anArray->Value(2), anArray->Value(3),
376 anArray->Value(4), anArray->Value(5), anArray->Value(6),
377 anArray->Value(7), anArray->Value(8), anArray->Value(9));
381 void HYDROData_Image::UpdateTrsf()
383 QPoint aPointA, aPointB, aPointC;
384 if ( !GetLocalPoints( aPointA, aPointB, aPointC ) )
387 TransformationMode aTrsfMode;
388 QPointF aTrsfPointA, aTrsfPointB, aTrsfPointC;
389 if ( !GetGlobalPoints( aTrsfMode, aTrsfPointA, aTrsfPointB, aTrsfPointC ) )
392 QTransform aRefTransform;
393 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
395 bool anIsRefImage = aTrsfMode == ReferenceImage;
398 if ( aRefImage.IsNull() )
401 aRefTransform = aRefImage->Trsf();
404 bool anIsByTwoPoints = IsByTwoPoints();
406 // Convert lambert coordinates to cartesian
407 if ( aTrsfMode == ManualGeodesic )
409 double aXCart = 0, aYCart = 0;
411 HYDROData_Lambert93::toXY( aTrsfPointA.y(), aTrsfPointA.x(), aXCart, aYCart );
412 aTrsfPointA = QPointF( aXCart, aYCart );
414 HYDROData_Lambert93::toXY( aTrsfPointB.y(), aTrsfPointB.x(), aXCart, aYCart );
415 aTrsfPointB = QPointF( aXCart, aYCart );
417 if ( !anIsByTwoPoints )
419 HYDROData_Lambert93::toXY( aTrsfPointC.y(), aTrsfPointC.x(), aXCart, aYCart );
420 aTrsfPointC = QPointF( aXCart, aYCart );
424 // generate third points if needed
425 if ( anIsByTwoPoints )
427 aPointC = generateThirdPoint( aPointA, aPointB, true ).toPoint();
428 aTrsfPointC = generateThirdPoint( aTrsfPointA, aTrsfPointB, anIsRefImage );
431 int xa = aPointA.x();
432 int ya = aPointA.y();
433 int xb = aPointB.x();
434 int yb = aPointB.y();
435 int xc = aPointC.x();
436 int yc = aPointC.y();
438 double xta = aTrsfPointA.x();
439 double yta = aTrsfPointA.y();
440 double xtb = aTrsfPointB.x();
441 double ytb = aTrsfPointB.y();
442 double xtc = aTrsfPointC.x();
443 double ytc = aTrsfPointC.y();
445 // first, check that three input points don't belong to a single line
446 if( ( yb - ya ) * ( xc - xa ) == ( yc - ya ) * ( xb - xa ) )
449 // the same check for the reference points
450 if( anIsRefImage && ( ( ytb - yta ) * ( xtc - xta ) == ( ytc - yta ) * ( xtb - xta ) ) )
453 QTransform aTransform1( xa, ya, 1, xb, yb, 1, xc, yc, 1 );
454 QTransform aTransform2( xta, yta, 1, xtb, ytb, 1, xtc, ytc, 1 );
456 bool anIsInvertible = false;
457 QTransform aTransform1Inverted = aTransform1.inverted( &anIsInvertible );
458 if( !anIsInvertible )
461 QTransform aResTransform = aTransform1Inverted * aTransform2;
463 aResTransform *= aRefTransform;
465 SetTrsf( aResTransform );
468 bool HYDROData_Image::IsByTwoPoints() const
470 if ( !HasLocalPoints() || !HasGlobalPoints() )
473 QPoint aPointA, aPointB, aPointC;
474 GetLocalPoints( aPointA, aPointB, aPointC );
476 return aPointC.x() < 0 && aPointC.y() < 0;
479 bool HYDROData_Image::HasReferences() const
481 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
482 int aNbReferences = NbReferences();
484 return !aRefImage.IsNull() || aNbReferences > 0;
487 void HYDROData_Image::RemoveAllReferences()
489 if ( !HasReferences() )
492 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
493 if ( !aRefImage.IsNull() )
495 RemoveTrsfReferenceImage();
500 SetOperatorName( "" );
502 SetIsSelfSplitted( false );
505 bool anIsByTwoPoints = IsByTwoPoints();
507 QImage anImage = Image();
508 if ( anImage.isNull() )
510 SetToUpdate( false );
514 // Set local points to default position
515 QPoint aLocalPointA = QPoint( 0, 0 );
516 QPoint aLocalPointB = QPoint( anImage.width(), 0 );
517 QPoint aLocalPointC = anIsByTwoPoints ? QPoint( INT_MIN, INT_MIN ) : QPoint( 0, anImage.height() );
519 SetLocalPoints( aLocalPointA, aLocalPointB, aLocalPointC, false );
521 // Calculate global points
522 QTransform aTransform = Trsf();
524 QPointF aTrsfPointA = QPointF( aTransform.map( aLocalPointA ) );
525 QPointF aTrsfPointB = QPointF( aTransform.map( aLocalPointB ) );
526 QPointF aTrsfPointC = anIsByTwoPoints ? QPointF( INT_MIN, INT_MIN ) :
527 QPointF( aTransform.map( aLocalPointC ) );
529 SetGlobalPoints( ManualCartesian, aTrsfPointA, aTrsfPointB, aTrsfPointC );
531 SetToUpdate( false );
534 void HYDROData_Image::SetLocalPoints( const QPoint& thePointA,
535 const QPoint& thePointB,
536 const QPoint& thePointC,
537 const bool theIsUpdate )
539 Handle(TDataStd_RealArray) anArray;
540 if ( !myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
541 anArray = TDataStd_RealArray::Set( myLab.FindChild( DataTag_TrsfPoints ), 1, 12 );
543 anArray->SetValue( 1, thePointA.x() );
544 anArray->SetValue( 2, thePointA.y() );
545 anArray->SetValue( 3, thePointB.x() );
546 anArray->SetValue( 4, thePointB.y() );
547 anArray->SetValue( 5, thePointC.x() );
548 anArray->SetValue( 6, thePointC.y() );
550 TDataStd_UAttribute::Set( myLab.FindChild( DataTag_TrsfPoints ), GUID_HAS_LOCAL_POINTS );
558 bool HYDROData_Image::GetLocalPoints( QPoint& thePointA,
560 QPoint& thePointC ) const
562 if ( !HasLocalPoints() )
565 Handle(TDataStd_RealArray) anArray;
566 myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray );
568 thePointA = QPointF( anArray->Value( 1 ), anArray->Value( 2 ) ).toPoint();
569 thePointB = QPointF( anArray->Value( 3 ), anArray->Value( 4 ) ).toPoint();
570 thePointC = QPointF( anArray->Value( 5 ), anArray->Value( 6 ) ).toPoint();
575 bool HYDROData_Image::HasLocalPoints() const
577 TDF_Label aLabel = myLab.FindChild( DataTag_TrsfPoints, false );
578 if ( aLabel.IsNull() || !aLabel.IsAttribute( GUID_HAS_LOCAL_POINTS ) )
581 Handle(TDataStd_RealArray) anArray;
582 return aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray );
586 void HYDROData_Image::SetGlobalPoints( const TransformationMode& theMode,
587 const QPointF& thePointA,
588 const QPointF& thePointB,
589 const QPointF& thePointC,
590 const bool theIsUpdate )
592 Handle(TDataStd_RealArray) anArray;
593 if ( !myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
594 anArray = TDataStd_RealArray::Set( myLab.FindChild( DataTag_TrsfPoints ), 1, 12 );
596 anArray->SetValue( 7, thePointA.x() );
597 anArray->SetValue( 8, thePointA.y() );
598 anArray->SetValue( 9, thePointB.x() );
599 anArray->SetValue( 10, thePointB.y() );
600 anArray->SetValue( 11, thePointC.x() );
601 anArray->SetValue( 12, thePointC.y() );
603 SetTrsfMode( theMode );
605 TDataStd_UAttribute::Set( myLab.FindChild( DataTag_TrsfPoints ), GUID_HAS_GLOBAL_POINTS );
613 bool HYDROData_Image::GetGlobalPoints( TransformationMode& theMode,
616 QPointF& thePointC ) const
618 if ( !HasGlobalPoints() )
621 theMode = GetTrsfMode();
623 Handle(TDataStd_RealArray) anArray;
624 myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray );
626 thePointA = QPointF( anArray->Value( 7 ), anArray->Value( 8 ) );
627 thePointB = QPointF( anArray->Value( 9 ), anArray->Value( 10 ) );
628 thePointC = QPointF( anArray->Value( 11 ), anArray->Value( 12 ) );
633 bool HYDROData_Image::SetGlobalPointsFromFile( const QString& theFileName )
637 // Try to open the file
638 QFile aFile( theFileName );
639 if ( !aFile.exists() || !aFile.open( QIODevice::ReadOnly ) ) {
643 QPointF aPointA, aPointB;
644 double aXmin, anYmin, aXmax, anYmax;
645 aXmin = anYmin = aXmax = anYmax = -1;
647 while ( !aFile.atEnd() &&
648 ( aXmin < 0 || anYmin < 0 || aXmax < 0 || anYmax < 0 ) ) {
650 QString aLine = aFile.readLine().simplified();
651 aLine.replace( " ", "" );
652 if ( aLine.isEmpty() ) {
656 // Try to read double value after ":"
657 bool isDoubleOk = false;
658 double aDoubleValue = -1;
659 QStringList aValues = aLine.split( ":", QString::SkipEmptyParts );
660 if ( aValues.count() == 2 ) {
661 aDoubleValue = aValues.last().toDouble( &isDoubleOk );
666 boost::math::isnan( aDoubleValue ) ||
667 boost::math::isinf( aDoubleValue ) ) {
672 if ( aLine.startsWith( "Xminimum" ) ) {
673 aXmin = aDoubleValue;
675 else if ( aLine.startsWith( "Yminimum" ) ) {
676 anYmin = aDoubleValue;
678 else if ( aLine.startsWith( "Xmaximum" ) ) {
679 aXmax = aDoubleValue;
681 else if ( aLine.startsWith( "Ymaximum" ) ) {
682 anYmax = aDoubleValue;
689 if ( aXmin >= 0 && anYmin >= 0 ) {
690 aPointA.setX( aXmin );
691 aPointA.setY( anYmin );
694 if ( aXmax >= 0 && anYmax >= 0 ) {
695 aPointB.setX( aXmax );
696 aPointB.setY( anYmax );
699 if ( !aPointA.isNull() && !aPointB.isNull() ) {
700 SetGlobalPoints( ManualCartesian, aPointA, aPointB );
707 bool HYDROData_Image::HasGlobalPoints() const
709 TDF_Label aLabel = myLab.FindChild( DataTag_TrsfPoints, false );
710 if ( aLabel.IsNull() || !aLabel.IsAttribute( GUID_HAS_GLOBAL_POINTS ) )
713 Handle(TDataStd_RealArray) anArray;
714 return aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray );
717 void HYDROData_Image::SetReferencePoints( const Handle(HYDROData_Image)& theRefImage,
718 const QPointF& thePointA,
719 const QPointF& thePointB,
720 const QPointF& thePointC,
721 const bool theIsUpdate )
723 SetTrsfReferenceImage( theRefImage );
724 SetGlobalPoints( ReferenceImage, thePointA, thePointB, thePointC, theIsUpdate );
727 bool HYDROData_Image::GetReferencePoints( Handle(HYDROData_Image)& theRefImage,
730 QPointF& thePointC ) const
732 if ( !HasReferencePoints() )
735 theRefImage = GetTrsfReferenceImage();
737 TransformationMode aMode;
738 GetGlobalPoints( aMode, thePointA, thePointB, thePointC );
743 bool HYDROData_Image::HasReferencePoints() const
745 if ( !HasGlobalPoints() )
748 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
749 if ( aRefImage.IsNull() )
752 TransformationMode aTrsfMode = GetTrsfMode();
753 if ( aTrsfMode != ReferenceImage )
759 void HYDROData_Image::SetTrsfMode( const TransformationMode& theMode )
761 TDataStd_Integer::Set( myLab.FindChild( DataTag_TrsfMode ), (int)theMode );
765 HYDROData_Image::TransformationMode HYDROData_Image::GetTrsfMode() const
767 TransformationMode aResMode = ManualGeodesic;
769 TDF_Label aLabel = myLab.FindChild( DataTag_TrsfPoints, false );
770 if ( !aLabel.IsNull() )
772 Handle(TDataStd_Integer) aMode;
773 if ( myLab.FindChild( DataTag_TrsfMode ).FindAttribute( TDataStd_Integer::GetID(), aMode ) )
774 aResMode = (TransformationMode)aMode->Get();
780 void HYDROData_Image::SetTrsfReferenceImage( const Handle(HYDROData_Image)& theRefImage )
782 SetReferenceObject( theRefImage, DataTag_TrsfImage );
786 Handle(HYDROData_Image) HYDROData_Image::GetTrsfReferenceImage() const
788 return Handle(HYDROData_Image)::DownCast( GetReferenceObject( DataTag_TrsfImage ) );
791 void HYDROData_Image::RemoveTrsfReferenceImage()
793 RemoveReferenceObject( DataTag_TrsfImage );
797 void HYDROData_Image::AppendReference( const Handle(HYDROData_Entity)& theReferenced )
799 AddReferenceObject( theReferenced, 0 );
803 int HYDROData_Image::NbReferences() const
805 return NbReferenceObjects( 0 );
808 Handle(HYDROData_Entity) HYDROData_Image::Reference( const int theIndex ) const
810 return GetReferenceObject( 0, theIndex );
813 void HYDROData_Image::ChangeReference(
814 const int theIndex, Handle(HYDROData_Entity) theReferenced)
816 SetReferenceObject( theReferenced, 0, theIndex );
820 void HYDROData_Image::RemoveReference(const int theIndex)
822 RemoveReferenceObject( 0, theIndex );
826 void HYDROData_Image::ClearReferences()
828 ClearReferenceObjects( 0 );
832 void HYDROData_Image::SetOperatorName( const QString theOpName )
834 TCollection_AsciiString anAsciiStr( theOpName.toStdString().c_str() );
835 TDataStd_AsciiString::Set( myLab.FindChild( DataTag_Operator ), anAsciiStr );
839 QString HYDROData_Image::OperatorName() const
843 TDF_Label aLabel = myLab.FindChild( DataTag_Operator, false );
844 if ( !aLabel.IsNull() )
846 Handle(TDataStd_AsciiString) anAsciiStr;
847 if ( aLabel.FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) )
848 aRes = QString( anAsciiStr->Get().ToCString() );
854 void HYDROData_Image::SetArgs(const QByteArray& theArgs)
856 SaveByteArray(DataTag_Operator, theArgs.constData(), theArgs.length());
860 QByteArray HYDROData_Image::Args() const
863 const char* aData = ByteArray(DataTag_Operator, aLen);
866 return QByteArray(aData, aLen);
869 void HYDROData_Image::SetIsSelfSplitted(bool theFlag)
872 TDataStd_UAttribute::Set(myLab, GUID_SELF_SPLITTED);
874 myLab.ForgetAttribute(GUID_SELF_SPLITTED);
879 bool HYDROData_Image::IsSelfSplitted() const
881 return myLab.IsAttribute(GUID_SELF_SPLITTED);
884 QPointF HYDROData_Image::generateThirdPoint( const QPointF& thePointA,
885 const QPointF& thePointB,
886 const bool& theIsLocal ) const
888 // Rotate vector to 90 degrees : clockwise - for local
889 // counterclockwise - for global
890 const double aTheta = theIsLocal ? -M_PI_2 : M_PI_2;
894 // Move to (0,0) for correct rotation
895 double x = thePointB.x() - thePointA.x();
896 double y = thePointB.y() - thePointA.y();
898 aResPoint.setX( x * cos( aTheta ) - y * sin( aTheta ) );
899 aResPoint.setY( x * sin( aTheta ) + y * cos( aTheta ) );
901 // Move back to origin position
902 aResPoint.setX( aResPoint.x() + thePointA.x() );
903 aResPoint.setY( aResPoint.y() + thePointA.y() );