1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "HYDROData_Image.h"
25 #include "HYDROData_Document.h"
26 #include "HYDROData_Lambert93.h"
27 #include "HYDROData_OperationsFactory.h"
29 #include <TDataStd_RealArray.hxx>
30 #include <TDataStd_ByteArray.hxx>
31 #include <TDataStd_Integer.hxx>
32 #include <TDataStd_IntegerArray.hxx>
33 #include <TDataStd_ReferenceList.hxx>
34 #include <TDataStd_UAttribute.hxx>
35 #include <TDataStd_AsciiString.hxx>
37 #include <ImageComposer_Operator.h>
38 #include <ImageComposer_MetaTypes.h>
40 #include <QStringList>
43 #include <boost/math/special_functions/fpclassify.hpp>
45 static const Standard_GUID GUID_SELF_SPLITTED("997995aa-5c19-40bf-9a60-ab4b70ad04d8");
46 static const Standard_GUID GUID_HAS_LOCAL_POINTS("FD8841AA-FC44-42fa-B6A7-0F682CCC6F27");
47 static const Standard_GUID GUID_HAS_GLOBAL_POINTS("330D0E81-742D-4ea3-92D4-484877CFA7C1");
49 IMPLEMENT_STANDARD_HANDLE(HYDROData_Image, HYDROData_Entity)
50 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Image, HYDROData_Entity)
52 HYDROData_Image::HYDROData_Image()
57 HYDROData_Image::~HYDROData_Image()
61 QStringList HYDROData_Image::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
63 QStringList aResList = dumpObjectCreation( theTreatedObjects );
64 QString anImageName = GetObjPyName();
66 QString aFilePath = GetFilePath();
67 if ( !aFilePath.isEmpty() )
69 aResList << QString( "" );
70 aResList << QString( "%1.LoadImage( \"%2\" );" )
71 .arg( anImageName ).arg( aFilePath );
72 aResList << QString( "" );
74 // Dump transformation points for image
76 bool anIsByTwoPoints = IsByTwoPoints();
78 QPoint aLocalPointA, aLocalPointB, aLocalPointC;
79 if ( GetLocalPoints( aLocalPointA, aLocalPointB, aLocalPointC ) )
81 QString aGap = QString().fill( ' ', anImageName.size() + 17 );
83 aResList << QString( "%1.SetLocalPoints( QPoint( %2, %3 )," )
84 .arg( anImageName ).arg( aLocalPointA.x() ).arg( aLocalPointA.y() );
85 aResList << QString( aGap + "QPoint( %1, %2 )" )
86 .arg( aLocalPointB.x() ).arg( aLocalPointB.y() );
87 if ( !anIsByTwoPoints )
89 aResList.last().append( "," );
90 aResList << QString( aGap + "QPoint( %1, %2 ) );" )
91 .arg( aLocalPointC.x() ).arg( aLocalPointC.y() );
95 aResList.last().append( " );" );
97 aResList << QString( "" );
100 HYDROData_Image::TransformationMode aTransformationMode;
101 QPointF aTrsfPointA, aTrsfPointB, aTrsfPointC;
102 if ( GetGlobalPoints( aTransformationMode, aTrsfPointA, aTrsfPointB, aTrsfPointC ) )
104 QString aGap = QString().fill( ' ', anImageName.size() + 18 );
106 aResList << QString( "%1.SetGlobalPoints( %2," )
107 .arg( anImageName ).arg( aTransformationMode );
108 aResList << QString( aGap + "QPointF( %1, %2 )," )
109 .arg( aTrsfPointA.x() ).arg( aTrsfPointA.y() );
110 aResList << QString( aGap + "QPointF( %1, %2 )" )
111 .arg( aTrsfPointB.x() ).arg( aTrsfPointB.y() );
112 if ( !anIsByTwoPoints )
114 aResList.last().append( "," );
115 aResList << QString( aGap + "QPointF( %1, %2 ) );" )
116 .arg( aTrsfPointC.x() ).arg( aTrsfPointC.y() );
120 aResList.last().append( " );" );
123 if ( aTransformationMode == ReferenceImage )
125 Handle(HYDROData_Image) aRefImg = GetTrsfReferenceImage();
126 setPythonReferenceObject( theTreatedObjects, aResList, aRefImg, "SetTrsfReferenceImage" );
132 // Image is composed from other image(s)
134 QString anOperatorName = OperatorName();
135 if ( !anOperatorName.isEmpty() )
137 aResList << QString( "" );
139 aResList << QString( "%1.SetOperatorName( \"%2\" );" )
140 .arg( anImageName ).arg( anOperatorName );
142 ImageComposer_Operator* anImageOp =
143 HYDROData_OperationsFactory::Factory()->Operator( OperatorName() );
146 // Dump operation arguments
147 QString anOpArgsArrayName;
148 QStringList anOpArgs = anImageOp->dumpArgsToPython( anOpArgsArrayName );
149 if ( !anOpArgs.isEmpty() )
151 aResList << QString( "" );
152 aResList << anOpArgs;
154 aResList << QString( "" );
155 aResList << QString( "%1.SetArgs( %2 );" )
156 .arg( anImageName ).arg( anOpArgsArrayName );
161 int aNbReferences = NbReferences();
162 if ( aNbReferences > 0 )
164 aResList << QString( "" );
166 for ( int i = 0; i < aNbReferences; ++i )
168 Handle(HYDROData_Image) aRefImg = Handle(HYDROData_Image)::DownCast( Reference( i ) );
169 setPythonReferenceObject( theTreatedObjects, aResList, aRefImg, "AppendReference" );
174 aResList << QString( "" );
175 aResList << QString( "%1.Update();" ).arg( anImageName );
180 void HYDROData_Image::Update()
182 bool anIsToUpdate = IsMustBeUpdated();
184 HYDROData_Entity::Update();
189 HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory();
191 ImageComposer_Operator* anOp = aFactory->Operator( OperatorName() );
192 if ( anOp ) // Update image if there is an operation
194 // Fill by arguments and process the operation
195 anOp->setBinArgs( Args() );
197 QVariant anObj1, anObj2;
198 int aNbReferences = NbReferences();
200 if ( aNbReferences > 0 )
202 // First referenced object
203 Handle(HYDROData_Entity) aRefObj = Reference( 0 );
204 if ( !aRefObj.IsNull() )
206 anObj1 = aRefObj->GetDataVariant();
207 if ( !anObj1.isNull() && anObj1.canConvert<ImageComposer_Image>() )
209 ImageComposer_Image anImage = anObj1.value<ImageComposer_Image>();
210 QTransform aTransform = anImage.transform();
211 SetTrsf( aTransform );
216 if ( aNbReferences > 1 )
218 // Second referenced object
219 Handle(HYDROData_Entity) aRefObj = Reference( 1 );
220 if ( !aRefObj.IsNull() )
221 anObj2 = aRefObj->GetDataVariant();
224 ImageComposer_Image aResImg = anOp->process( anObj1, anObj2 );
226 SetTrsf( aResImg.transform() );
228 else // Update image if it positioned relatively to other image
233 SetToUpdate( false );
236 bool HYDROData_Image::IsHas2dPrs() const
241 QVariant HYDROData_Image::GetDataVariant()
243 QTransform aTransform = Trsf();
245 ImageComposer_Image anImage = Image();
246 anImage.setTransform( aTransform );
249 aVarData.setValue<ImageComposer_Image>( anImage );
254 HYDROData_SequenceOfObjects HYDROData_Image::GetAllReferenceObjects() const
256 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
258 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
259 if ( !aRefImage.IsNull() )
260 aResSeq.Append( aRefImage );
262 HYDROData_SequenceOfObjects aSeqRefObjects = GetReferenceObjects( 0 );
263 aResSeq.Append( aSeqRefObjects );
268 void HYDROData_Image::SetImage(const QImage& theImage)
270 if ( theImage.isNull() )
272 // for empty image remove all previously stored attributes
273 myLab.ForgetAttribute(TDataStd_IntegerArray::GetID());
274 myLab.ForgetAttribute(TDataStd_ByteArray::GetID());
280 // convert 8-bits images
281 if ( theImage.format() == QImage::Format_Indexed8 ) {
282 anImage = theImage.convertToFormat( QImage::Format_RGB32 );
287 // store width, height, bytes per line and format in integer array
288 Handle(TDataStd_IntegerArray) aParams;
289 if (!myLab.FindAttribute(TDataStd_IntegerArray::GetID(), aParams)) {
290 aParams = TDataStd_IntegerArray::Set(myLab, 1, 4);
292 aParams->SetValue(1, anImage.width());
293 aParams->SetValue(2, anImage.height());
294 aParams->SetValue(3, anImage.bytesPerLine());
295 aParams->SetValue(4, (int)(anImage.format()));
296 // store data of image in byte array
297 const char* aData = (const char*)(anImage.bits());
298 SaveByteArray(0, aData, anImage.byteCount());
304 bool HYDROData_Image::LoadImage( const QString& theFilePath )
306 QImage anImage( theFilePath );
309 SetFilePath( theFilePath );
311 return !anImage.isNull();
314 QImage HYDROData_Image::Image()
316 Handle(TDataStd_IntegerArray) aParams;
317 if (!myLab.FindAttribute(TDataStd_IntegerArray::GetID(), aParams))
318 return QImage(); // return empty image if there is no array
320 uchar* anArray = (uchar*)ByteArray(0, aLen);
322 return QImage(); // return empty image if there is no array
323 QImage aResult(anArray, aParams->Value(1), aParams->Value(2),
324 aParams->Value(3), QImage::Format(aParams->Value(4)));
328 void HYDROData_Image::SetFilePath( const QString& theFilePath )
330 TCollection_AsciiString anAsciiStr( theFilePath.toStdString().c_str() );
331 TDataStd_AsciiString::Set( myLab.FindChild( DataTag_FilePath ), anAsciiStr );
336 QString HYDROData_Image::GetFilePath() const
340 TDF_Label aLabel = myLab.FindChild( DataTag_FilePath, false );
341 if ( !aLabel.IsNull() )
343 Handle(TDataStd_AsciiString) anAsciiStr;
344 if ( aLabel.FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) )
345 aRes = QString( anAsciiStr->Get().ToCString() );
351 void HYDROData_Image::SetTrsf(const QTransform& theTrsf)
353 // locate 9 coeffs of matrix into the real array
354 Handle(TDataStd_RealArray) anArray;
355 if (!myLab.FindAttribute(TDataStd_RealArray::GetID(), anArray)) {
356 if (theTrsf.isIdentity()) return; // no need to store identity transformation
357 anArray = TDataStd_RealArray::Set(myLab, 1, 9);
359 anArray->SetValue(1, theTrsf.m11());
360 anArray->SetValue(2, theTrsf.m12());
361 anArray->SetValue(3, theTrsf.m13());
362 anArray->SetValue(4, theTrsf.m21());
363 anArray->SetValue(5, theTrsf.m22());
364 anArray->SetValue(6, theTrsf.m23());
365 anArray->SetValue(7, theTrsf.m31());
366 anArray->SetValue(8, theTrsf.m32());
367 anArray->SetValue(9, theTrsf.m33());
372 QTransform HYDROData_Image::Trsf() const
374 // get 9 coeffs of matrix from the real array
375 Handle(TDataStd_RealArray) anArray;
376 if (!myLab.FindAttribute(TDataStd_RealArray::GetID(), anArray))
377 return QTransform(); // return identity if there is no array
379 anArray->Value(1), anArray->Value(2), anArray->Value(3),
380 anArray->Value(4), anArray->Value(5), anArray->Value(6),
381 anArray->Value(7), anArray->Value(8), anArray->Value(9));
385 void HYDROData_Image::UpdateTrsf()
387 QPoint aPointA, aPointB, aPointC;
388 if ( !GetLocalPoints( aPointA, aPointB, aPointC ) )
391 TransformationMode aTrsfMode;
392 QPointF aTrsfPointA, aTrsfPointB, aTrsfPointC;
393 if ( !GetGlobalPoints( aTrsfMode, aTrsfPointA, aTrsfPointB, aTrsfPointC ) )
396 QTransform aRefTransform;
397 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
399 bool anIsRefImage = aTrsfMode == ReferenceImage;
402 if ( aRefImage.IsNull() )
405 aRefTransform = aRefImage->Trsf();
408 bool anIsByTwoPoints = IsByTwoPoints();
410 // Convert lambert coordinates to cartesian
411 if ( aTrsfMode == ManualGeodesic )
413 double aXCart = 0, aYCart = 0;
415 HYDROData_Lambert93::toXY( aTrsfPointA.y(), aTrsfPointA.x(), aXCart, aYCart );
416 aTrsfPointA = QPointF( aXCart, aYCart );
418 HYDROData_Lambert93::toXY( aTrsfPointB.y(), aTrsfPointB.x(), aXCart, aYCart );
419 aTrsfPointB = QPointF( aXCart, aYCart );
421 if ( !anIsByTwoPoints )
423 HYDROData_Lambert93::toXY( aTrsfPointC.y(), aTrsfPointC.x(), aXCart, aYCart );
424 aTrsfPointC = QPointF( aXCart, aYCart );
428 // generate third points if needed
429 if ( anIsByTwoPoints )
431 aPointC = generateThirdPoint( aPointA, aPointB, true ).toPoint();
432 aTrsfPointC = generateThirdPoint( aTrsfPointA, aTrsfPointB, anIsRefImage );
435 int xa = aPointA.x();
436 int ya = aPointA.y();
437 int xb = aPointB.x();
438 int yb = aPointB.y();
439 int xc = aPointC.x();
440 int yc = aPointC.y();
442 double xta = aTrsfPointA.x();
443 double yta = aTrsfPointA.y();
444 double xtb = aTrsfPointB.x();
445 double ytb = aTrsfPointB.y();
446 double xtc = aTrsfPointC.x();
447 double ytc = aTrsfPointC.y();
449 // first, check that three input points don't belong to a single line
450 if( ( yb - ya ) * ( xc - xa ) == ( yc - ya ) * ( xb - xa ) )
453 // the same check for the reference points
454 if( anIsRefImage && ( ( ytb - yta ) * ( xtc - xta ) == ( ytc - yta ) * ( xtb - xta ) ) )
457 QTransform aTransform1( xa, ya, 1, xb, yb, 1, xc, yc, 1 );
458 QTransform aTransform2( xta, yta, 1, xtb, ytb, 1, xtc, ytc, 1 );
460 bool anIsInvertible = false;
461 QTransform aTransform1Inverted = aTransform1.inverted( &anIsInvertible );
462 if( !anIsInvertible )
465 QTransform aResTransform = aTransform1Inverted * aTransform2;
467 aResTransform *= aRefTransform;
469 SetTrsf( aResTransform );
472 bool HYDROData_Image::IsByTwoPoints() const
474 if ( !HasLocalPoints() || !HasGlobalPoints() )
477 QPoint aPointA, aPointB, aPointC;
478 GetLocalPoints( aPointA, aPointB, aPointC );
480 return aPointC.x() < 0 && aPointC.y() < 0;
483 bool HYDROData_Image::HasReferences() const
485 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
486 int aNbReferences = NbReferences();
488 return !aRefImage.IsNull() || aNbReferences > 0;
491 void HYDROData_Image::RemoveAllReferences()
493 if ( !HasReferences() )
496 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
497 if ( !aRefImage.IsNull() )
499 RemoveTrsfReferenceImage();
504 SetOperatorName( "" );
506 SetIsSelfSplitted( false );
509 bool anIsByTwoPoints = IsByTwoPoints();
511 QImage anImage = Image();
512 if ( anImage.isNull() )
514 SetToUpdate( false );
518 // Set local points to default position
519 QPoint aLocalPointA = QPoint( 0, 0 );
520 QPoint aLocalPointB = QPoint( anImage.width(), 0 );
521 QPoint aLocalPointC = anIsByTwoPoints ? QPoint( INT_MIN, INT_MIN ) : QPoint( 0, anImage.height() );
523 SetLocalPoints( aLocalPointA, aLocalPointB, aLocalPointC, false );
525 // Calculate global points
526 QTransform aTransform = Trsf();
528 QPointF aTrsfPointA = QPointF( aTransform.map( aLocalPointA ) );
529 QPointF aTrsfPointB = QPointF( aTransform.map( aLocalPointB ) );
530 QPointF aTrsfPointC = anIsByTwoPoints ? QPointF( INT_MIN, INT_MIN ) :
531 QPointF( aTransform.map( aLocalPointC ) );
533 SetGlobalPoints( ManualCartesian, aTrsfPointA, aTrsfPointB, aTrsfPointC );
535 SetToUpdate( false );
538 void HYDROData_Image::SetLocalPoints( const QPoint& thePointA,
539 const QPoint& thePointB,
540 const QPoint& thePointC,
541 const bool theIsUpdate )
543 Handle(TDataStd_RealArray) anArray;
544 if ( !myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
545 anArray = TDataStd_RealArray::Set( myLab.FindChild( DataTag_TrsfPoints ), 1, 12 );
547 anArray->SetValue( 1, thePointA.x() );
548 anArray->SetValue( 2, thePointA.y() );
549 anArray->SetValue( 3, thePointB.x() );
550 anArray->SetValue( 4, thePointB.y() );
551 anArray->SetValue( 5, thePointC.x() );
552 anArray->SetValue( 6, thePointC.y() );
554 TDataStd_UAttribute::Set( myLab.FindChild( DataTag_TrsfPoints ), GUID_HAS_LOCAL_POINTS );
562 bool HYDROData_Image::GetLocalPoints( QPoint& thePointA,
564 QPoint& thePointC ) const
566 if ( !HasLocalPoints() )
569 Handle(TDataStd_RealArray) anArray;
570 myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray );
572 thePointA = QPointF( anArray->Value( 1 ), anArray->Value( 2 ) ).toPoint();
573 thePointB = QPointF( anArray->Value( 3 ), anArray->Value( 4 ) ).toPoint();
574 thePointC = QPointF( anArray->Value( 5 ), anArray->Value( 6 ) ).toPoint();
579 bool HYDROData_Image::HasLocalPoints() const
581 TDF_Label aLabel = myLab.FindChild( DataTag_TrsfPoints, false );
582 if ( aLabel.IsNull() || !aLabel.IsAttribute( GUID_HAS_LOCAL_POINTS ) )
585 Handle(TDataStd_RealArray) anArray;
586 return aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray );
590 void HYDROData_Image::SetGlobalPoints( const TransformationMode& theMode,
591 const QPointF& thePointA,
592 const QPointF& thePointB,
593 const QPointF& thePointC,
594 const bool theIsUpdate )
596 Handle(TDataStd_RealArray) anArray;
597 if ( !myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
598 anArray = TDataStd_RealArray::Set( myLab.FindChild( DataTag_TrsfPoints ), 1, 12 );
600 anArray->SetValue( 7, thePointA.x() );
601 anArray->SetValue( 8, thePointA.y() );
602 anArray->SetValue( 9, thePointB.x() );
603 anArray->SetValue( 10, thePointB.y() );
604 anArray->SetValue( 11, thePointC.x() );
605 anArray->SetValue( 12, thePointC.y() );
607 SetTrsfMode( theMode );
609 TDataStd_UAttribute::Set( myLab.FindChild( DataTag_TrsfPoints ), GUID_HAS_GLOBAL_POINTS );
617 bool HYDROData_Image::GetGlobalPoints( TransformationMode& theMode,
620 QPointF& thePointC ) const
622 if ( !HasGlobalPoints() )
625 theMode = GetTrsfMode();
627 Handle(TDataStd_RealArray) anArray;
628 myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray );
630 thePointA = QPointF( anArray->Value( 7 ), anArray->Value( 8 ) );
631 thePointB = QPointF( anArray->Value( 9 ), anArray->Value( 10 ) );
632 thePointC = QPointF( anArray->Value( 11 ), anArray->Value( 12 ) );
637 bool HYDROData_Image::SetGlobalPointsFromFile( const QString& theFileName )
641 // Try to open the file
642 QFile aFile( theFileName );
643 if ( !aFile.exists() || !aFile.open( QIODevice::ReadOnly ) ) {
647 QPointF aPointA, aPointB;
648 double aXmin, anYmin, aXmax, anYmax;
649 aXmin = anYmin = aXmax = anYmax = -1;
651 while ( !aFile.atEnd() &&
652 ( aXmin < 0 || anYmin < 0 || aXmax < 0 || anYmax < 0 ) ) {
654 QString aLine = aFile.readLine().simplified();
655 aLine.replace( " ", "" );
656 if ( aLine.isEmpty() ) {
660 // Try to read double value after ":"
661 bool isDoubleOk = false;
662 double aDoubleValue = -1;
663 QStringList aValues = aLine.split( ":", QString::SkipEmptyParts );
664 if ( aValues.count() == 2 ) {
665 aDoubleValue = aValues.last().toDouble( &isDoubleOk );
670 boost::math::isnan( aDoubleValue ) ||
671 boost::math::isinf( aDoubleValue ) ) {
676 if ( aLine.startsWith( "Xminimum" ) ) {
677 aXmin = aDoubleValue;
679 else if ( aLine.startsWith( "Yminimum" ) ) {
680 anYmin = aDoubleValue;
682 else if ( aLine.startsWith( "Xmaximum" ) ) {
683 aXmax = aDoubleValue;
685 else if ( aLine.startsWith( "Ymaximum" ) ) {
686 anYmax = aDoubleValue;
693 if ( aXmin >= 0 && anYmin >= 0 ) {
694 aPointA.setX( aXmin );
695 aPointA.setY( anYmin );
698 if ( aXmax >= 0 && anYmax >= 0 ) {
699 aPointB.setX( aXmax );
700 aPointB.setY( anYmax );
703 if ( !aPointA.isNull() && !aPointB.isNull() ) {
704 SetGlobalPoints( ManualCartesian, aPointA, aPointB );
711 bool HYDROData_Image::HasGlobalPoints() const
713 TDF_Label aLabel = myLab.FindChild( DataTag_TrsfPoints, false );
714 if ( aLabel.IsNull() || !aLabel.IsAttribute( GUID_HAS_GLOBAL_POINTS ) )
717 Handle(TDataStd_RealArray) anArray;
718 return aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray );
721 void HYDROData_Image::SetReferencePoints( const Handle(HYDROData_Image)& theRefImage,
722 const QPointF& thePointA,
723 const QPointF& thePointB,
724 const QPointF& thePointC,
725 const bool theIsUpdate )
727 SetTrsfReferenceImage( theRefImage );
728 SetGlobalPoints( ReferenceImage, thePointA, thePointB, thePointC, theIsUpdate );
731 bool HYDROData_Image::GetReferencePoints( Handle(HYDROData_Image)& theRefImage,
734 QPointF& thePointC ) const
736 if ( !HasReferencePoints() )
739 theRefImage = GetTrsfReferenceImage();
741 TransformationMode aMode;
742 GetGlobalPoints( aMode, thePointA, thePointB, thePointC );
747 bool HYDROData_Image::HasReferencePoints() const
749 if ( !HasGlobalPoints() )
752 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
753 if ( aRefImage.IsNull() )
756 TransformationMode aTrsfMode = GetTrsfMode();
757 if ( aTrsfMode != ReferenceImage )
763 void HYDROData_Image::SetTrsfMode( const TransformationMode& theMode )
765 TDataStd_Integer::Set( myLab.FindChild( DataTag_TrsfMode ), (int)theMode );
769 HYDROData_Image::TransformationMode HYDROData_Image::GetTrsfMode() const
771 TransformationMode aResMode = ManualGeodesic;
773 TDF_Label aLabel = myLab.FindChild( DataTag_TrsfPoints, false );
774 if ( !aLabel.IsNull() )
776 Handle(TDataStd_Integer) aMode;
777 if ( myLab.FindChild( DataTag_TrsfMode ).FindAttribute( TDataStd_Integer::GetID(), aMode ) )
778 aResMode = (TransformationMode)aMode->Get();
784 void HYDROData_Image::SetTrsfReferenceImage( const Handle(HYDROData_Image)& theRefImage )
786 SetReferenceObject( theRefImage, DataTag_TrsfImage );
790 Handle(HYDROData_Image) HYDROData_Image::GetTrsfReferenceImage() const
792 return Handle(HYDROData_Image)::DownCast( GetReferenceObject( DataTag_TrsfImage ) );
795 void HYDROData_Image::RemoveTrsfReferenceImage()
797 RemoveReferenceObject( DataTag_TrsfImage );
801 void HYDROData_Image::AppendReference( const Handle(HYDROData_Entity)& theReferenced )
803 AddReferenceObject( theReferenced, 0 );
807 int HYDROData_Image::NbReferences() const
809 return NbReferenceObjects( 0 );
812 Handle(HYDROData_Entity) HYDROData_Image::Reference( const int theIndex ) const
814 return GetReferenceObject( 0, theIndex );
817 void HYDROData_Image::ChangeReference(
818 const int theIndex, Handle(HYDROData_Entity) theReferenced)
820 SetReferenceObject( theReferenced, 0, theIndex );
824 void HYDROData_Image::RemoveReference(const int theIndex)
826 RemoveReferenceObject( 0, theIndex );
830 void HYDROData_Image::ClearReferences()
832 ClearReferenceObjects( 0 );
836 void HYDROData_Image::SetOperatorName( const QString theOpName )
838 TCollection_AsciiString anAsciiStr( theOpName.toStdString().c_str() );
839 TDataStd_AsciiString::Set( myLab.FindChild( DataTag_Operator ), anAsciiStr );
843 QString HYDROData_Image::OperatorName() const
847 TDF_Label aLabel = myLab.FindChild( DataTag_Operator, false );
848 if ( !aLabel.IsNull() )
850 Handle(TDataStd_AsciiString) anAsciiStr;
851 if ( aLabel.FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) )
852 aRes = QString( anAsciiStr->Get().ToCString() );
858 void HYDROData_Image::SetArgs(const QByteArray& theArgs)
860 SaveByteArray(DataTag_Operator, theArgs.constData(), theArgs.length());
864 QByteArray HYDROData_Image::Args() const
867 const char* aData = ByteArray(DataTag_Operator, aLen);
870 return QByteArray(aData, aLen);
873 void HYDROData_Image::SetIsSelfSplitted(bool theFlag)
876 TDataStd_UAttribute::Set(myLab, GUID_SELF_SPLITTED);
878 myLab.ForgetAttribute(GUID_SELF_SPLITTED);
883 bool HYDROData_Image::IsSelfSplitted() const
885 return myLab.IsAttribute(GUID_SELF_SPLITTED);
888 QPointF HYDROData_Image::generateThirdPoint( const QPointF& thePointA,
889 const QPointF& thePointB,
890 const bool& theIsLocal ) const
892 // Rotate vector to 90 degrees : clockwise - for local
893 // counterclockwise - for global
894 const double aTheta = theIsLocal ? -M_PI_2 : M_PI_2;
898 // Move to (0,0) for correct rotation
899 double x = thePointB.x() - thePointA.x();
900 double y = thePointB.y() - thePointA.y();
902 aResPoint.setX( x * cos( aTheta ) - y * sin( aTheta ) );
903 aResPoint.setY( x * sin( aTheta ) + y * cos( aTheta ) );
905 // Move back to origin position
906 aResPoint.setX( aResPoint.x() + thePointA.x() );
907 aResPoint.setY( aResPoint.y() + thePointA.y() );