2 #include "HYDROData_Image.h"
4 #include "HYDROData_Document.h"
5 #include "HYDROData_Lambert93.h"
6 #include "HYDROData_Tool.h"
7 #include "HYDROData_OperationsFactory.h"
9 #include <TDataStd_RealArray.hxx>
10 #include <TDataStd_ByteArray.hxx>
11 #include <TDataStd_Integer.hxx>
12 #include <TDataStd_IntegerArray.hxx>
13 #include <TDataStd_ReferenceList.hxx>
14 #include <TDataStd_Name.hxx>
15 #include <TDataStd_UAttribute.hxx>
16 #include <TDataStd_AsciiString.hxx>
18 #include <ImageComposer_Operator.h>
19 #include <ImageComposer_MetaTypes.h>
21 #include <QStringList>
23 static const Standard_GUID GUID_SELF_SPLITTED("997995aa-5c19-40bf-9a60-ab4b70ad04d8");
24 static const Standard_GUID GUID_HAS_LOCAL_POINTS("FD8841AA-FC44-42fa-B6A7-0F682CCC6F27");
25 static const Standard_GUID GUID_HAS_GLOBAL_POINTS("330D0E81-742D-4ea3-92D4-484877CFA7C1");
27 #define PYTHON_IMAGE_ID "KIND_IMAGE"
29 IMPLEMENT_STANDARD_HANDLE(HYDROData_Image, HYDROData_Entity)
30 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Image, HYDROData_Entity)
32 HYDROData_Image::HYDROData_Image()
37 HYDROData_Image::~HYDROData_Image()
41 QStringList HYDROData_Image::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
45 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
46 if ( aDocument.IsNull() )
49 QString aDocName = aDocument->GetDocPyName();
50 QString anImageName = GetName();
52 aResList << QString( "%1 = %2.CreateObject( %3 );" )
53 .arg( anImageName ).arg( aDocName ).arg( PYTHON_IMAGE_ID );
54 aResList << QString( "%1.SetName( \"%2\" );" )
55 .arg( anImageName ).arg( anImageName );
57 QString aFilePath = GetFilePath();
58 if ( !aFilePath.isEmpty() )
60 aResList << QString( "" );
61 aResList << QString( "%1.LoadImage( \"%2\" );" )
62 .arg( anImageName ).arg( aFilePath );
63 aResList << QString( "" );
65 // Dump transformation points for image
67 QString aGap = QString().fill( ' ', anImageName.size() + 16 );
69 bool anIsByTwoPoints = IsByTwoPoints();
71 QPoint aLocalPointA, aLocalPointB, aLocalPointC;
72 if ( GetLocalPoints( aLocalPointA, aLocalPointB, aLocalPointC ) )
74 aResList << QString( "%1.SetLocalPoints( QPoint( %2, %3 )," )
75 .arg( anImageName ).arg( aLocalPointA.x() ).arg( aLocalPointA.y() );
76 aResList << QString( aGap + "QPoint( %1, %2 )," )
77 .arg( aLocalPointB.x() ).arg( aLocalPointB.y() );
78 aResList << QString( aGap + "QPoint( %1, %2 ) );" )
79 .arg( aLocalPointC.x() ).arg( aLocalPointC.y() );
80 aResList << QString( "" );
83 HYDROData_Image::TransformationMode aTransformationMode;
84 QPointF aTrsfPointA, aTrsfPointB, aTrsfPointC;
85 if ( GetGlobalPoints( aTransformationMode, aTrsfPointA, aTrsfPointB, aTrsfPointC ) )
87 aResList << QString( "%1.SetGlobalPoints( %2," )
88 .arg( anImageName ).arg( aTransformationMode );
89 aResList << QString( aGap + "QPointF( %1, %2 )," )
90 .arg( aTrsfPointA.x() ).arg( aTrsfPointA.y() );
91 aResList << QString( aGap + "QPointF( %1, %2 )," )
92 .arg( aTrsfPointB.x() ).arg( aTrsfPointB.y() );
93 aResList << QString( aGap + "QPointF( %1, %2 ) );" )
94 .arg( aTrsfPointC.x() ).arg( aTrsfPointC.y() );
96 if ( aTransformationMode == ReferenceImage )
98 Handle(HYDROData_Image) aRefImg = GetTrsfReferenceImage();
99 setPythonReferenceObject( theTreatedObjects, aResList, aRefImg, "SetTrsfReferenceImage" );
105 // Image is composed from other image(s)
107 QString anOperatorName = OperatorName();
108 if ( !anOperatorName.isEmpty() )
110 aResList << QString( "" );
112 aResList << QString( "%1.SetOperatorName( \"%2\" );" )
113 .arg( anImageName ).arg( anOperatorName );
115 ImageComposer_Operator* anImageOp =
116 HYDROData_OperationsFactory::Factory()->Operator( OperatorName() );
119 // Dump operation arguments
120 QString anOpArgsArrayName;
121 QStringList anOpArgs = anImageOp->dumpArgsToPython( anOpArgsArrayName );
122 if ( !anOpArgs.isEmpty() )
124 aResList << QString( "" );
125 aResList << anOpArgs;
127 aResList << QString( "" );
128 aResList << QString( "%1.SetArgs( %2 );" )
129 .arg( anImageName ).arg( anOpArgsArrayName );
134 int aNbReferences = NbReferences();
135 if ( aNbReferences > 0 )
137 aResList << QString( "" );
139 for ( int i = 0; i < aNbReferences; ++i )
141 Handle(HYDROData_Image) aRefImg = Handle(HYDROData_Image)::DownCast( Reference( i ) );
142 setPythonReferenceObject( theTreatedObjects, aResList, aRefImg, "AppendReference" );
146 // Necessary to update image in case of composed operator
147 aResList << QString( "" );
148 aResList << QString( "%1.Update();" ).arg( anImageName );
154 void HYDROData_Image::Update()
156 HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory();
158 ImageComposer_Operator* anOp = aFactory->Operator( OperatorName() );
159 if ( anOp ) // Update image if there is an operation
161 // Fill by arguments and process the operation
162 QVariant anObj1, anObj2;
163 int aNbReferences = NbReferences();
165 if ( aNbReferences > 0 )
167 // First referenced object
168 Handle(HYDROData_Entity) aRefObj = Reference( 0 );
169 if ( !aRefObj.IsNull() )
171 anObj1 = aRefObj->GetDataVariant();
172 if ( !anObj1.isNull() && anObj1.canConvert<ImageComposer_Image>() )
174 ImageComposer_Image anImage = anObj1.value<ImageComposer_Image>();
175 QTransform aTransform = anImage.transform();
176 SetTrsf( aTransform );
181 if ( aNbReferences > 1 )
183 // Second referenced object
184 Handle(HYDROData_Entity) aRefObj = Reference( 1 );
185 if ( !aRefObj.IsNull() )
186 anObj2 = aRefObj->GetDataVariant();
189 ImageComposer_Image aResImg = anOp->process( anObj1, anObj2 );
191 SetTrsf( aResImg.transform() );
193 else // Update image if it positioned relatively to other image
198 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
199 if ( !aDocument.IsNull() )
201 // Change the states of this and all depended images
203 HYDROData_Tool::SetMustBeUpdatedImages( aDocument );
204 SetToUpdate( false );
208 QVariant HYDROData_Image::GetDataVariant()
210 QTransform aTransform = Trsf();
212 ImageComposer_Image anImage = Image();
213 anImage.setTransform( aTransform );
216 aVarData.setValue<ImageComposer_Image>( anImage );
221 HYDROData_SequenceOfObjects HYDROData_Image::GetAllReferenceObjects() const
223 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
225 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
226 if ( !aRefImage.IsNull() )
227 aResSeq.Append( aRefImage );
229 HYDROData_SequenceOfObjects aSeqRefObjects = GetReferenceObjects( 0 );
230 aResSeq.Append( aSeqRefObjects );
235 void HYDROData_Image::SetImage(const QImage& theImage)
237 if (theImage.isNull()) {
238 // for empty image remove all previously stored attributes
239 myLab.ForgetAttribute(TDataStd_IntegerArray::GetID());
240 myLab.ForgetAttribute(TDataStd_ByteArray::GetID());
243 // store width, height, bytes per line and format in integer array
244 Handle(TDataStd_IntegerArray) aParams;
245 if (!myLab.FindAttribute(TDataStd_IntegerArray::GetID(), aParams)) {
246 aParams = TDataStd_IntegerArray::Set(myLab, 1, 4);
248 aParams->SetValue(1, theImage.width());
249 aParams->SetValue(2, theImage.height());
250 aParams->SetValue(3, theImage.bytesPerLine());
251 aParams->SetValue(4, (int)(theImage.format()));
252 // store data of image in byte array
253 const char* aData = (const char*)(theImage.bits());
254 SaveByteArray(0, aData, theImage.byteCount());
257 bool HYDROData_Image::LoadImage(const QString& theFilePath)
259 QImage anImage( theFilePath );
261 return !anImage.isNull();
264 QImage HYDROData_Image::Image()
266 Handle(TDataStd_IntegerArray) aParams;
267 if (!myLab.FindAttribute(TDataStd_IntegerArray::GetID(), aParams))
268 return QImage(); // return empty image if there is no array
270 uchar* anArray = (uchar*)ByteArray(0, aLen);
272 return QImage(); // return empty image if there is no array
273 QImage aResult(anArray, aParams->Value(1), aParams->Value(2),
274 aParams->Value(3), QImage::Format(aParams->Value(4)));
278 void HYDROData_Image::SetFilePath(const QString& theFilePath)
280 TCollection_AsciiString anAsciiStr( theFilePath.toStdString().c_str() );
281 TDataStd_AsciiString::Set( myLab.FindChild( DataTag_FilePath ), anAsciiStr );
284 QString HYDROData_Image::GetFilePath() const
288 Handle(TDataStd_AsciiString) anAsciiStr;
289 if ( myLab.FindChild( DataTag_FilePath ).FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) )
290 aRes = QString( anAsciiStr->Get().ToCString() );
295 void HYDROData_Image::SetTrsf(const QTransform& theTrsf)
297 // locate 9 coeffs of matrix into the real array
298 Handle(TDataStd_RealArray) anArray;
299 if (!myLab.FindAttribute(TDataStd_RealArray::GetID(), anArray)) {
300 if (theTrsf.isIdentity()) return; // no need to store identity transformation
301 anArray = TDataStd_RealArray::Set(myLab, 1, 9);
303 anArray->SetValue(1, theTrsf.m11());
304 anArray->SetValue(2, theTrsf.m12());
305 anArray->SetValue(3, theTrsf.m13());
306 anArray->SetValue(4, theTrsf.m21());
307 anArray->SetValue(5, theTrsf.m22());
308 anArray->SetValue(6, theTrsf.m23());
309 anArray->SetValue(7, theTrsf.m31());
310 anArray->SetValue(8, theTrsf.m32());
311 anArray->SetValue(9, theTrsf.m33());
314 QTransform HYDROData_Image::Trsf() const
316 // get 9 coeffs of matrix from the real array
317 Handle(TDataStd_RealArray) anArray;
318 if (!myLab.FindAttribute(TDataStd_RealArray::GetID(), anArray))
319 return QTransform(); // return identity if there is no array
321 anArray->Value(1), anArray->Value(2), anArray->Value(3),
322 anArray->Value(4), anArray->Value(5), anArray->Value(6),
323 anArray->Value(7), anArray->Value(8), anArray->Value(9));
327 void HYDROData_Image::UpdateTrsf()
329 QPoint aPointA, aPointB, aPointC;
330 if ( !GetLocalPoints( aPointA, aPointB, aPointC ) )
333 TransformationMode aTrsfMode;
334 QPointF aTrsfPointA, aTrsfPointB, aTrsfPointC;
335 if ( !GetGlobalPoints( aTrsfMode, aTrsfPointA, aTrsfPointB, aTrsfPointC ) )
338 QTransform aRefTransform;
339 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
341 bool anIsRefImage = aTrsfMode == ReferenceImage;
344 if ( aRefImage.IsNull() )
347 aRefTransform = aRefImage->Trsf();
350 bool anIsByTwoPoints = IsByTwoPoints();
352 // Convert lambert coordinates to cartesian
353 if ( aTrsfMode == ManualGeodesic )
355 double aXCart = 0, aYCart = 0;
357 HYDROData_Lambert93::toXY( aTrsfPointA.y(), aTrsfPointA.x(), aXCart, aYCart );
358 aTrsfPointA = QPointF( aXCart, aYCart );
360 HYDROData_Lambert93::toXY( aTrsfPointB.y(), aTrsfPointB.x(), aXCart, aYCart );
361 aTrsfPointB = QPointF( aXCart, aYCart );
363 if ( !anIsByTwoPoints )
365 HYDROData_Lambert93::toXY( aTrsfPointC.y(), aTrsfPointC.x(), aXCart, aYCart );
366 aTrsfPointC = QPointF( aXCart, aYCart );
370 // generate third points if needed
371 if ( anIsByTwoPoints )
373 aPointC = generateThirdPoint( aPointA, aPointB, true ).toPoint();
374 aTrsfPointC = generateThirdPoint( aTrsfPointA, aTrsfPointB, anIsRefImage );
377 int xa = aPointA.x();
378 int ya = aPointA.y();
379 int xb = aPointB.x();
380 int yb = aPointB.y();
381 int xc = aPointC.x();
382 int yc = aPointC.y();
384 double xta = aTrsfPointA.x();
385 double yta = aTrsfPointA.y();
386 double xtb = aTrsfPointB.x();
387 double ytb = aTrsfPointB.y();
388 double xtc = aTrsfPointC.x();
389 double ytc = aTrsfPointC.y();
391 // first, check that three input points don't belong to a single line
392 if( ( yb - ya ) * ( xc - xa ) == ( yc - ya ) * ( xb - xa ) )
395 // the same check for the reference points
396 if( anIsRefImage && ( ( ytb - yta ) * ( xtc - xta ) == ( ytc - yta ) * ( xtb - xta ) ) )
399 QTransform aTransform1( xa, ya, 1, xb, yb, 1, xc, yc, 1 );
400 QTransform aTransform2( xta, yta, 1, xtb, ytb, 1, xtc, ytc, 1 );
402 bool anIsInvertible = false;
403 QTransform aTransform1Inverted = aTransform1.inverted( &anIsInvertible );
404 if( !anIsInvertible )
407 QTransform aResTransform = aTransform1Inverted * aTransform2;
409 aResTransform *= aRefTransform;
411 SetTrsf( aResTransform );
414 bool HYDROData_Image::IsByTwoPoints() const
416 if ( !HasLocalPoints() || !HasGlobalPoints() )
419 QPoint aPointA, aPointB, aPointC;
420 GetLocalPoints( aPointA, aPointB, aPointC );
422 return aPointC.x() < 0 && aPointC.y() < 0;
425 bool HYDROData_Image::HasReferences() const
427 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
428 int aNbReferences = NbReferences();
430 return !aRefImage.IsNull() || aNbReferences > 0;
433 void HYDROData_Image::RemoveAllReferences()
435 if ( !HasReferences() )
438 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
439 if ( !aRefImage.IsNull() )
441 RemoveTrsfReferenceImage();
446 SetOperatorName( "" );
448 SetIsSelfSplitted( false );
451 SetToUpdate( false );
453 bool anIsByTwoPoints = IsByTwoPoints();
455 QImage anImage = Image();
456 if ( anImage.isNull() )
459 // Set local points to default position
460 QPoint aLocalPointA = QPoint( 0, 0 );
461 QPoint aLocalPointB = QPoint( anImage.width(), 0 );
462 QPoint aLocalPointC = anIsByTwoPoints ? QPoint( INT_MIN, INT_MIN ) : QPoint( 0, anImage.height() );
464 SetLocalPoints( aLocalPointA, aLocalPointB, aLocalPointC, false );
466 // Calculate global points
467 QTransform aTransform = Trsf();
469 QPointF aTrsfPointA = QPointF( aTransform.map( aLocalPointA ) );
470 QPointF aTrsfPointB = QPointF( aTransform.map( aLocalPointB ) );
471 QPointF aTrsfPointC = anIsByTwoPoints ? QPointF( INT_MIN, INT_MIN ) :
472 QPointF( aTransform.map( aLocalPointC ) );
474 SetGlobalPoints( ManualCartesian, aTrsfPointA, aTrsfPointB, aTrsfPointC );
477 void HYDROData_Image::SetLocalPoints( const QPoint& thePointA,
478 const QPoint& thePointB,
479 const QPoint& thePointC,
480 const bool theIsUpdate )
482 Handle(TDataStd_RealArray) anArray;
483 if ( !myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
484 anArray = TDataStd_RealArray::Set( myLab.FindChild( DataTag_TrsfPoints ), 1, 12 );
486 anArray->SetValue( 1, thePointA.x() );
487 anArray->SetValue( 2, thePointA.y() );
488 anArray->SetValue( 3, thePointB.x() );
489 anArray->SetValue( 4, thePointB.y() );
490 anArray->SetValue( 5, thePointC.x() );
491 anArray->SetValue( 6, thePointC.y() );
493 TDataStd_UAttribute::Set( myLab.FindChild( DataTag_TrsfPoints ), GUID_HAS_LOCAL_POINTS );
499 bool HYDROData_Image::GetLocalPoints( QPoint& thePointA,
501 QPoint& thePointC ) const
503 if ( !HasLocalPoints() )
506 Handle(TDataStd_RealArray) anArray;
507 myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray );
509 thePointA = QPointF( anArray->Value( 1 ), anArray->Value( 2 ) ).toPoint();
510 thePointB = QPointF( anArray->Value( 3 ), anArray->Value( 4 ) ).toPoint();
511 thePointC = QPointF( anArray->Value( 5 ), anArray->Value( 6 ) ).toPoint();
516 bool HYDROData_Image::HasLocalPoints() const
518 TDF_Label aLabel = myLab.FindChild( DataTag_TrsfPoints, false );
519 if ( aLabel.IsNull() || !aLabel.IsAttribute( GUID_HAS_LOCAL_POINTS ) )
522 Handle(TDataStd_RealArray) anArray;
523 return aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray );
527 void HYDROData_Image::SetGlobalPoints( const TransformationMode& theMode,
528 const QPointF& thePointA,
529 const QPointF& thePointB,
530 const QPointF& thePointC,
531 const bool theIsUpdate )
533 Handle(TDataStd_RealArray) anArray;
534 if ( !myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
535 anArray = TDataStd_RealArray::Set( myLab.FindChild( DataTag_TrsfPoints ), 1, 12 );
537 anArray->SetValue( 7, thePointA.x() );
538 anArray->SetValue( 8, thePointA.y() );
539 anArray->SetValue( 9, thePointB.x() );
540 anArray->SetValue( 10, thePointB.y() );
541 anArray->SetValue( 11, thePointC.x() );
542 anArray->SetValue( 12, thePointC.y() );
544 SetTrsfMode( theMode );
546 TDataStd_UAttribute::Set( myLab.FindChild( DataTag_TrsfPoints ), GUID_HAS_GLOBAL_POINTS );
554 aCPointA = QPointF( aTransform.map( aPointA ) );
555 aCPointB = QPointF( aTransform.map( aPointB ) );
556 aCPointC = QPointF( aTransform.map( aPointC ) );
558 // compute Lambert93 points
566 double xla = 0, yla = 0, xlb = 0, ylb = 0, xlc = 0, ylc = 0;
567 HYDROData_Lambert93::toGeo( xca, yca, yla, xla );
568 HYDROData_Lambert93::toGeo( xcb, ycb, ylb, xlb );
569 HYDROData_Lambert93::toGeo( xcc, ycc, ylc, xlc );
571 aLPointA = QPointF( xla * 3600.0, yla * 3600.0 ); // convert degrees to seconds
572 aLPointB = QPointF( xlb * 3600.0, ylb * 3600.0 ); // convert degrees to seconds
573 aLPointC = QPointF( xlc * 3600.0, ylc * 3600.0 ); // convert degrees to seconds
578 bool HYDROData_Image::GetGlobalPoints( TransformationMode& theMode,
581 QPointF& thePointC ) const
583 if ( !HasGlobalPoints() )
586 theMode = GetTrsfMode();
588 Handle(TDataStd_RealArray) anArray;
589 myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray );
591 thePointA = QPointF( anArray->Value( 7 ), anArray->Value( 8 ) );
592 thePointB = QPointF( anArray->Value( 9 ), anArray->Value( 10 ) );
593 thePointC = QPointF( anArray->Value( 11 ), anArray->Value( 12 ) );
598 bool HYDROData_Image::HasGlobalPoints() const
600 TDF_Label aLabel = myLab.FindChild( DataTag_TrsfPoints, false );
601 if ( aLabel.IsNull() || !aLabel.IsAttribute( GUID_HAS_GLOBAL_POINTS ) )
604 Handle(TDataStd_RealArray) anArray;
605 return aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray );
608 void HYDROData_Image::SetReferencePoints( const Handle(HYDROData_Image)& theRefImage,
609 const QPointF& thePointA,
610 const QPointF& thePointB,
611 const QPointF& thePointC,
612 const bool theIsUpdate )
614 SetTrsfReferenceImage( theRefImage );
615 SetGlobalPoints( ReferenceImage, thePointA, thePointB, thePointC, theIsUpdate );
618 bool HYDROData_Image::GetReferencePoints( Handle(HYDROData_Image)& theRefImage,
621 QPointF& thePointC ) const
623 if ( !HasReferencePoints() )
626 theRefImage = GetTrsfReferenceImage();
628 TransformationMode aMode;
629 GetGlobalPoints( aMode, thePointA, thePointB, thePointC );
634 bool HYDROData_Image::HasReferencePoints() const
636 if ( !HasGlobalPoints() )
639 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
640 if ( aRefImage.IsNull() )
643 TransformationMode aTrsfMode = GetTrsfMode();
644 if ( aTrsfMode != ReferenceImage )
650 void HYDROData_Image::SetTrsfMode( const TransformationMode& theMode )
652 TDataStd_Integer::Set( myLab.FindChild( DataTag_TrsfMode ), (int)theMode );
655 HYDROData_Image::TransformationMode HYDROData_Image::GetTrsfMode() const
657 TransformationMode aResMode = ManualGeodesic;
659 TDF_Label aLabel = myLab.FindChild( DataTag_TrsfPoints, false );
660 if ( !aLabel.IsNull() )
662 Handle(TDataStd_Integer) aMode;
663 if ( myLab.FindChild( DataTag_TrsfMode ).FindAttribute( TDataStd_Integer::GetID(), aMode ) )
664 aResMode = (TransformationMode)aMode->Get();
670 void HYDROData_Image::SetTrsfReferenceImage( const Handle(HYDROData_Image)& theRefImage )
672 SetReferenceObject( theRefImage, DataTag_TrsfImage );
675 Handle(HYDROData_Image) HYDROData_Image::GetTrsfReferenceImage() const
677 return Handle(HYDROData_Image)::DownCast( GetReferenceObject( DataTag_TrsfImage ) );
680 void HYDROData_Image::RemoveTrsfReferenceImage()
682 return RemoveReferenceObject( DataTag_TrsfImage );
685 void HYDROData_Image::AppendReference( const Handle(HYDROData_Entity)& theReferenced )
687 AddReferenceObject( theReferenced, 0 );
690 int HYDROData_Image::NbReferences() const
692 return NbReferenceObjects( 0 );
695 Handle(HYDROData_Entity) HYDROData_Image::Reference( const int theIndex ) const
697 return GetReferenceObject( 0, theIndex );
700 void HYDROData_Image::ChangeReference(
701 const int theIndex, Handle(HYDROData_Entity) theReferenced)
703 SetReferenceObject( theReferenced, 0, theIndex );
706 void HYDROData_Image::RemoveReference(const int theIndex)
708 RemoveReferenceObject( 0, theIndex );
711 void HYDROData_Image::ClearReferences()
713 ClearReferenceObjects( 0 );
716 void HYDROData_Image::SetOperatorName(const QString theOpName)
718 TDataStd_Name::Set(myLab.FindChild(DataTag_Operator),
719 TCollection_ExtendedString(theOpName.toLatin1().constData()));
722 QString HYDROData_Image::OperatorName() const
724 Handle(TDataStd_Name) aName;
725 if (myLab.FindChild(DataTag_Operator).
726 FindAttribute(TDataStd_Name::GetID(), aName)) {
727 TCollection_AsciiString aStr(aName->Get());
728 return QString(aStr.ToCString());
733 void HYDROData_Image::SetArgs(const QByteArray& theArgs)
735 SaveByteArray(DataTag_Operator, theArgs.constData(), theArgs.length());
738 QByteArray HYDROData_Image::Args() const
741 const char* aData = ByteArray(DataTag_Operator, aLen);
744 return QByteArray(aData, aLen);
747 void HYDROData_Image::SetIsSelfSplitted(bool theFlag)
750 TDataStd_UAttribute::Set(myLab, GUID_SELF_SPLITTED);
752 myLab.ForgetAttribute(GUID_SELF_SPLITTED);
756 bool HYDROData_Image::IsSelfSplitted() const
758 return myLab.IsAttribute(GUID_SELF_SPLITTED);
761 QPointF HYDROData_Image::generateThirdPoint( const QPointF& thePointA,
762 const QPointF& thePointB,
763 const bool& theIsLocal ) const
765 // Rotate vector to 90 degrees : clockwise - for local
766 // anticlockwise - for global
767 const double aTheta = theIsLocal ? -M_PI_2 : M_PI_2;
771 // Move to (0,0) for correct rotation
772 double x = thePointB.x() - thePointA.x();
773 double y = thePointB.y() - thePointA.y();
775 aResPoint.setX( x * cos( aTheta ) - y * sin( aTheta ) );
776 aResPoint.setY( x * sin( aTheta ) + y * cos( aTheta ) );
778 // Move back to origin position
779 aResPoint.setX( aResPoint.x() + thePointA.x() );
780 aResPoint.setY( aResPoint.y() + thePointA.y() );