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 );
192 else // Update image if it positioned relatively to other image
197 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
198 if ( !aDocument.IsNull() )
200 // Change the states of this and all depended images
202 HYDROData_Tool::SetMustBeUpdatedImages( aDocument );
203 SetToUpdate( false );
207 QVariant HYDROData_Image::GetDataVariant()
209 QTransform aTransform = Trsf();
211 ImageComposer_Image anImage = Image();
212 anImage.setTransform( aTransform );
215 aVarData.setValue<ImageComposer_Image>( anImage );
220 void HYDROData_Image::SetImage(const QImage& theImage)
222 if (theImage.isNull()) {
223 // for empty image remove all previously stored attributes
224 myLab.ForgetAttribute(TDataStd_IntegerArray::GetID());
225 myLab.ForgetAttribute(TDataStd_ByteArray::GetID());
228 // store width, height, bytes per line and format in integer array
229 Handle(TDataStd_IntegerArray) aParams;
230 if (!myLab.FindAttribute(TDataStd_IntegerArray::GetID(), aParams)) {
231 aParams = TDataStd_IntegerArray::Set(myLab, 1, 4);
233 aParams->SetValue(1, theImage.width());
234 aParams->SetValue(2, theImage.height());
235 aParams->SetValue(3, theImage.bytesPerLine());
236 aParams->SetValue(4, (int)(theImage.format()));
237 // store data of image in byte array
238 const char* aData = (const char*)(theImage.bits());
239 SaveByteArray(0, aData, theImage.byteCount());
242 bool HYDROData_Image::LoadImage(const QString& theFilePath)
244 QImage anImage( theFilePath );
246 return !anImage.isNull();
249 QImage HYDROData_Image::Image()
251 Handle(TDataStd_IntegerArray) aParams;
252 if (!myLab.FindAttribute(TDataStd_IntegerArray::GetID(), aParams))
253 return QImage(); // return empty image if there is no array
255 uchar* anArray = (uchar*)ByteArray(0, aLen);
257 return QImage(); // return empty image if there is no array
258 QImage aResult(anArray, aParams->Value(1), aParams->Value(2),
259 aParams->Value(3), QImage::Format(aParams->Value(4)));
263 void HYDROData_Image::SetFilePath(const QString& theFilePath)
265 TCollection_AsciiString anAsciiStr( theFilePath.toStdString().c_str() );
266 TDataStd_AsciiString::Set( myLab.FindChild( DataTag_FilePath ), anAsciiStr );
269 QString HYDROData_Image::GetFilePath() const
273 Handle(TDataStd_AsciiString) anAsciiStr;
274 if ( myLab.FindChild( DataTag_FilePath ).FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) )
275 aRes = QString( anAsciiStr->Get().ToCString() );
280 void HYDROData_Image::SetTrsf(const QTransform& theTrsf)
282 // locate 9 coeffs of matrix into the real array
283 Handle(TDataStd_RealArray) anArray;
284 if (!myLab.FindAttribute(TDataStd_RealArray::GetID(), anArray)) {
285 if (theTrsf.isIdentity()) return; // no need to store identity transformation
286 anArray = TDataStd_RealArray::Set(myLab, 1, 9);
288 anArray->SetValue(1, theTrsf.m11());
289 anArray->SetValue(2, theTrsf.m12());
290 anArray->SetValue(3, theTrsf.m13());
291 anArray->SetValue(4, theTrsf.m21());
292 anArray->SetValue(5, theTrsf.m22());
293 anArray->SetValue(6, theTrsf.m23());
294 anArray->SetValue(7, theTrsf.m31());
295 anArray->SetValue(8, theTrsf.m32());
296 anArray->SetValue(9, theTrsf.m33());
299 QTransform HYDROData_Image::Trsf() const
301 // get 9 coeffs of matrix from the real array
302 Handle(TDataStd_RealArray) anArray;
303 if (!myLab.FindAttribute(TDataStd_RealArray::GetID(), anArray))
304 return QTransform(); // return identity if there is no array
306 anArray->Value(1), anArray->Value(2), anArray->Value(3),
307 anArray->Value(4), anArray->Value(5), anArray->Value(6),
308 anArray->Value(7), anArray->Value(8), anArray->Value(9));
312 void HYDROData_Image::UpdateTrsf()
314 QPoint aPointA, aPointB, aPointC;
315 if ( !GetLocalPoints( aPointA, aPointB, aPointC ) )
318 TransformationMode aTrsfMode;
319 QPointF aTrsfPointA, aTrsfPointB, aTrsfPointC;
320 if ( !GetGlobalPoints( aTrsfMode, aTrsfPointA, aTrsfPointB, aTrsfPointC ) )
323 QTransform aRefTransform;
324 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
326 bool anIsRefImage = aTrsfMode == ReferenceImage;
329 if ( aRefImage.IsNull() )
332 aRefTransform = aRefImage->Trsf();
335 bool anIsByTwoPoints = IsByTwoPoints();
337 // Convert lambert coordinates to cartesian
338 if ( aTrsfMode == ManualGeodesic )
340 double aXCart = 0, aYCart = 0;
342 HYDROData_Lambert93::toXY( aTrsfPointA.x(), aTrsfPointA.y(), aXCart, aYCart );
343 aTrsfPointA = QPointF( aXCart, aYCart );
345 HYDROData_Lambert93::toXY( aTrsfPointB.x(), aTrsfPointB.y(), aXCart, aYCart );
346 aTrsfPointB = QPointF( aXCart, aYCart );
348 if ( !anIsByTwoPoints )
350 HYDROData_Lambert93::toXY( aTrsfPointC.x(), aTrsfPointC.y(), aXCart, aYCart );
351 aTrsfPointC = QPointF( aXCart, aYCart );
355 // generate third points if needed
356 if ( anIsByTwoPoints )
358 aPointC = generateThirdPoint( aPointA, aPointB, true ).toPoint();
359 aTrsfPointC = generateThirdPoint( aTrsfPointA, aTrsfPointB, anIsRefImage );
362 int xa = aPointA.x();
363 int ya = aPointA.y();
364 int xb = aPointB.x();
365 int yb = aPointB.y();
366 int xc = aPointC.x();
367 int yc = aPointC.y();
369 double xta = aTrsfPointA.x();
370 double yta = aTrsfPointA.y();
371 double xtb = aTrsfPointB.x();
372 double ytb = aTrsfPointB.y();
373 double xtc = aTrsfPointC.x();
374 double ytc = aTrsfPointC.y();
376 // first, check that three input points don't belong to a single line
377 if( ( yb - ya ) * ( xc - xa ) == ( yc - ya ) * ( xb - xa ) )
380 // the same check for the reference points
381 if( anIsRefImage && ( ( ytb - yta ) * ( xtc - xta ) == ( ytc - yta ) * ( xtb - xta ) ) )
384 QTransform aTransform1( xa, ya, 1, xb, yb, 1, xc, yc, 1 );
385 QTransform aTransform2( xta, yta, 1, xtb, ytb, 1, xtc, ytc, 1 );
387 bool anIsInvertible = false;
388 QTransform aTransform1Inverted = aTransform1.inverted( &anIsInvertible );
389 if( !anIsInvertible )
392 QTransform aResTransform = aTransform1Inverted * aTransform2;
394 aResTransform *= aRefTransform;
396 SetTrsf( aResTransform );
399 bool HYDROData_Image::IsByTwoPoints() const
401 if ( !HasLocalPoints() || !HasGlobalPoints() )
404 QPoint aPointA, aPointB, aPointC;
405 GetLocalPoints( aPointA, aPointB, aPointC );
407 return aPointC.x() < 0 && aPointC.y() < 0;
410 bool HYDROData_Image::HasReferences() const
412 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
413 int aNbReferences = NbReferences();
415 return !aRefImage.IsNull() || aNbReferences > 0;
418 void HYDROData_Image::RemoveAllReferences()
420 if ( !HasReferences() )
423 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
424 if ( !aRefImage.IsNull() )
426 RemoveTrsfReferenceImage();
431 SetOperatorName( "" );
433 SetIsSelfSplitted( false );
436 SetToUpdate( false );
438 bool anIsByTwoPoints = IsByTwoPoints();
440 QImage anImage = Image();
441 if ( anImage.isNull() )
444 // Set local points to default position
445 QPoint aLocalPointA = QPoint( 0, 0 );
446 QPoint aLocalPointB = QPoint( anImage.width(), 0 );
447 QPoint aLocalPointC = anIsByTwoPoints ? QPoint( INT_MIN, INT_MIN ) : QPoint( 0, anImage.height() );
449 SetLocalPoints( aLocalPointA, aLocalPointB, aLocalPointC, false );
451 // Calculate global points
452 QTransform aTransform = Trsf();
454 QPointF aTrsfPointA = QPointF( aTransform.map( aLocalPointA ) );
455 QPointF aTrsfPointB = QPointF( aTransform.map( aLocalPointB ) );
456 QPointF aTrsfPointC = anIsByTwoPoints ? QPointF( INT_MIN, INT_MIN ) :
457 QPointF( aTransform.map( aLocalPointC ) );
459 SetGlobalPoints( ManualCartesian, aTrsfPointA, aTrsfPointB, aTrsfPointC );
462 void HYDROData_Image::SetLocalPoints( const QPoint& thePointA,
463 const QPoint& thePointB,
464 const QPoint& thePointC,
465 const bool theIsUpdate )
467 Handle(TDataStd_RealArray) anArray;
468 if ( !myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
469 anArray = TDataStd_RealArray::Set( myLab.FindChild( DataTag_TrsfPoints ), 1, 12 );
471 anArray->SetValue( 1, thePointA.x() );
472 anArray->SetValue( 2, thePointA.y() );
473 anArray->SetValue( 3, thePointB.x() );
474 anArray->SetValue( 4, thePointB.y() );
475 anArray->SetValue( 5, thePointC.x() );
476 anArray->SetValue( 6, thePointC.y() );
478 TDataStd_UAttribute::Set( myLab.FindChild( DataTag_TrsfPoints ), GUID_HAS_LOCAL_POINTS );
484 bool HYDROData_Image::GetLocalPoints( QPoint& thePointA,
486 QPoint& thePointC ) const
488 if ( !HasLocalPoints() )
491 Handle(TDataStd_RealArray) anArray;
492 myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray );
494 thePointA = QPointF( anArray->Value( 1 ), anArray->Value( 2 ) ).toPoint();
495 thePointB = QPointF( anArray->Value( 3 ), anArray->Value( 4 ) ).toPoint();
496 thePointC = QPointF( anArray->Value( 5 ), anArray->Value( 6 ) ).toPoint();
501 bool HYDROData_Image::HasLocalPoints() const
503 TDF_Label aLabel = myLab.FindChild( DataTag_TrsfPoints, false );
504 if ( aLabel.IsNull() || !aLabel.IsAttribute( GUID_HAS_LOCAL_POINTS ) )
507 Handle(TDataStd_RealArray) anArray;
508 return aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray );
512 void HYDROData_Image::SetGlobalPoints( const TransformationMode& theMode,
513 const QPointF& thePointA,
514 const QPointF& thePointB,
515 const QPointF& thePointC,
516 const bool theIsUpdate )
518 Handle(TDataStd_RealArray) anArray;
519 if ( !myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
520 anArray = TDataStd_RealArray::Set( myLab.FindChild( DataTag_TrsfPoints ), 1, 12 );
522 anArray->SetValue( 7, thePointA.x() );
523 anArray->SetValue( 8, thePointA.y() );
524 anArray->SetValue( 9, thePointB.x() );
525 anArray->SetValue( 10, thePointB.y() );
526 anArray->SetValue( 11, thePointC.x() );
527 anArray->SetValue( 12, thePointC.y() );
529 SetTrsfMode( theMode );
531 TDataStd_UAttribute::Set( myLab.FindChild( DataTag_TrsfPoints ), GUID_HAS_GLOBAL_POINTS );
539 aCPointA = QPointF( aTransform.map( aPointA ) );
540 aCPointB = QPointF( aTransform.map( aPointB ) );
541 aCPointC = QPointF( aTransform.map( aPointC ) );
543 // compute Lambert93 points
551 double xla = 0, yla = 0, xlb = 0, ylb = 0, xlc = 0, ylc = 0;
552 HYDROData_Lambert93::toGeo( xca, yca, yla, xla );
553 HYDROData_Lambert93::toGeo( xcb, ycb, ylb, xlb );
554 HYDROData_Lambert93::toGeo( xcc, ycc, ylc, xlc );
556 aLPointA = QPointF( xla * 3600.0, yla * 3600.0 ); // convert degrees to seconds
557 aLPointB = QPointF( xlb * 3600.0, ylb * 3600.0 ); // convert degrees to seconds
558 aLPointC = QPointF( xlc * 3600.0, ylc * 3600.0 ); // convert degrees to seconds
563 bool HYDROData_Image::GetGlobalPoints( TransformationMode& theMode,
566 QPointF& thePointC ) const
568 if ( !HasGlobalPoints() )
571 theMode = GetTrsfMode();
573 Handle(TDataStd_RealArray) anArray;
574 myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray );
576 thePointA = QPointF( anArray->Value( 7 ), anArray->Value( 8 ) );
577 thePointB = QPointF( anArray->Value( 9 ), anArray->Value( 10 ) );
578 thePointC = QPointF( anArray->Value( 11 ), anArray->Value( 12 ) );
583 bool HYDROData_Image::HasGlobalPoints() const
585 TDF_Label aLabel = myLab.FindChild( DataTag_TrsfPoints, false );
586 if ( aLabel.IsNull() || !aLabel.IsAttribute( GUID_HAS_GLOBAL_POINTS ) )
589 Handle(TDataStd_RealArray) anArray;
590 return aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray );
593 void HYDROData_Image::SetReferencePoints( const Handle(HYDROData_Image)& theRefImage,
594 const QPointF& thePointA,
595 const QPointF& thePointB,
596 const QPointF& thePointC,
597 const bool theIsUpdate )
599 SetTrsfReferenceImage( theRefImage );
600 SetGlobalPoints( ReferenceImage, thePointA, thePointB, thePointC, theIsUpdate );
603 bool HYDROData_Image::GetReferencePoints( Handle(HYDROData_Image)& theRefImage,
606 QPointF& thePointC ) const
608 if ( !HasReferencePoints() )
611 theRefImage = GetTrsfReferenceImage();
613 TransformationMode aMode;
614 GetGlobalPoints( aMode, thePointA, thePointB, thePointC );
619 bool HYDROData_Image::HasReferencePoints() const
621 if ( !HasGlobalPoints() )
624 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
625 if ( aRefImage.IsNull() )
628 TransformationMode aTrsfMode = GetTrsfMode();
629 if ( aTrsfMode != ReferenceImage )
635 void HYDROData_Image::SetTrsfMode( const TransformationMode& theMode )
637 TDataStd_Integer::Set( myLab.FindChild( DataTag_TrsfMode ), (int)theMode );
640 HYDROData_Image::TransformationMode HYDROData_Image::GetTrsfMode() const
642 TransformationMode aResMode = ManualGeodesic;
644 TDF_Label aLabel = myLab.FindChild( DataTag_TrsfPoints, false );
645 if ( !aLabel.IsNull() )
647 Handle(TDataStd_Integer) aMode;
648 if ( myLab.FindChild( DataTag_TrsfMode ).FindAttribute( TDataStd_Integer::GetID(), aMode ) )
649 aResMode = (TransformationMode)aMode->Get();
655 void HYDROData_Image::SetTrsfReferenceImage( const Handle(HYDROData_Image)& theRefImage )
657 SetReferenceObject( theRefImage, DataTag_TrsfImage );
660 Handle(HYDROData_Image) HYDROData_Image::GetTrsfReferenceImage() const
662 return Handle(HYDROData_Image)::DownCast( GetReferenceObject( DataTag_TrsfImage ) );
665 void HYDROData_Image::RemoveTrsfReferenceImage()
667 return RemoveReferenceObject( DataTag_TrsfImage );
670 void HYDROData_Image::AppendReference( const Handle(HYDROData_Entity)& theReferenced )
672 AddReferenceObject( theReferenced, 0 );
675 int HYDROData_Image::NbReferences() const
677 return NbReferenceObjects( 0 );
680 Handle(HYDROData_Entity) HYDROData_Image::Reference( const int theIndex ) const
682 return GetReferenceObject( 0, theIndex );
685 void HYDROData_Image::ChangeReference(
686 const int theIndex, Handle(HYDROData_Entity) theReferenced)
688 SetReferenceObject( theReferenced, 0, theIndex );
691 void HYDROData_Image::RemoveReference(const int theIndex)
693 RemoveReferenceObject( 0, theIndex );
696 void HYDROData_Image::ClearReferences()
698 ClearReferenceObjects( 0 );
701 void HYDROData_Image::SetOperatorName(const QString theOpName)
703 TDataStd_Name::Set(myLab.FindChild(DataTag_Operator),
704 TCollection_ExtendedString(theOpName.toLatin1().constData()));
707 QString HYDROData_Image::OperatorName() const
709 Handle(TDataStd_Name) aName;
710 if (myLab.FindChild(DataTag_Operator).
711 FindAttribute(TDataStd_Name::GetID(), aName)) {
712 TCollection_AsciiString aStr(aName->Get());
713 return QString(aStr.ToCString());
718 void HYDROData_Image::SetArgs(const QByteArray& theArgs)
720 SaveByteArray(DataTag_Operator, theArgs.constData(), theArgs.length());
723 QByteArray HYDROData_Image::Args() const
726 const char* aData = ByteArray(DataTag_Operator, aLen);
729 return QByteArray(aData, aLen);
732 void HYDROData_Image::SetIsSelfSplitted(bool theFlag)
735 TDataStd_UAttribute::Set(myLab, GUID_SELF_SPLITTED);
737 myLab.ForgetAttribute(GUID_SELF_SPLITTED);
741 bool HYDROData_Image::IsSelfSplitted() const
743 return myLab.IsAttribute(GUID_SELF_SPLITTED);
746 QPointF HYDROData_Image::generateThirdPoint( const QPointF& thePointA,
747 const QPointF& thePointB,
748 const bool& theIsLocal ) const
750 // Rotate vector to 90 degrees : clockwise - for local
751 // anticlockwise - for global
752 const double aTheta = theIsLocal ? -M_PI_2 : M_PI_2;
756 // Move to (0,0) for correct rotation
757 double x = thePointB.x() - thePointA.x();
758 double y = thePointB.y() - thePointA.y();
760 aResPoint.setX( x * cos( aTheta ) - y * sin( aTheta ) );
761 aResPoint.setY( x * sin( aTheta ) + y * cos( aTheta ) );
763 // Move back to origin position
764 aResPoint.setX( aResPoint.x() + thePointA.x() );
765 aResPoint.setY( aResPoint.y() + thePointA.y() );