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 void HYDROData_Image::SetImage(const QImage& theImage)
223 if (theImage.isNull()) {
224 // for empty image remove all previously stored attributes
225 myLab.ForgetAttribute(TDataStd_IntegerArray::GetID());
226 myLab.ForgetAttribute(TDataStd_ByteArray::GetID());
229 // store width, height, bytes per line and format in integer array
230 Handle(TDataStd_IntegerArray) aParams;
231 if (!myLab.FindAttribute(TDataStd_IntegerArray::GetID(), aParams)) {
232 aParams = TDataStd_IntegerArray::Set(myLab, 1, 4);
234 aParams->SetValue(1, theImage.width());
235 aParams->SetValue(2, theImage.height());
236 aParams->SetValue(3, theImage.bytesPerLine());
237 aParams->SetValue(4, (int)(theImage.format()));
238 // store data of image in byte array
239 const char* aData = (const char*)(theImage.bits());
240 SaveByteArray(0, aData, theImage.byteCount());
243 bool HYDROData_Image::LoadImage(const QString& theFilePath)
245 QImage anImage( theFilePath );
247 return !anImage.isNull();
250 QImage HYDROData_Image::Image()
252 Handle(TDataStd_IntegerArray) aParams;
253 if (!myLab.FindAttribute(TDataStd_IntegerArray::GetID(), aParams))
254 return QImage(); // return empty image if there is no array
256 uchar* anArray = (uchar*)ByteArray(0, aLen);
258 return QImage(); // return empty image if there is no array
259 QImage aResult(anArray, aParams->Value(1), aParams->Value(2),
260 aParams->Value(3), QImage::Format(aParams->Value(4)));
264 void HYDROData_Image::SetFilePath(const QString& theFilePath)
266 TCollection_AsciiString anAsciiStr( theFilePath.toStdString().c_str() );
267 TDataStd_AsciiString::Set( myLab.FindChild( DataTag_FilePath ), anAsciiStr );
270 QString HYDROData_Image::GetFilePath() const
274 Handle(TDataStd_AsciiString) anAsciiStr;
275 if ( myLab.FindChild( DataTag_FilePath ).FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) )
276 aRes = QString( anAsciiStr->Get().ToCString() );
281 void HYDROData_Image::SetTrsf(const QTransform& theTrsf)
283 // locate 9 coeffs of matrix into the real array
284 Handle(TDataStd_RealArray) anArray;
285 if (!myLab.FindAttribute(TDataStd_RealArray::GetID(), anArray)) {
286 if (theTrsf.isIdentity()) return; // no need to store identity transformation
287 anArray = TDataStd_RealArray::Set(myLab, 1, 9);
289 anArray->SetValue(1, theTrsf.m11());
290 anArray->SetValue(2, theTrsf.m12());
291 anArray->SetValue(3, theTrsf.m13());
292 anArray->SetValue(4, theTrsf.m21());
293 anArray->SetValue(5, theTrsf.m22());
294 anArray->SetValue(6, theTrsf.m23());
295 anArray->SetValue(7, theTrsf.m31());
296 anArray->SetValue(8, theTrsf.m32());
297 anArray->SetValue(9, theTrsf.m33());
300 QTransform HYDROData_Image::Trsf() const
302 // get 9 coeffs of matrix from the real array
303 Handle(TDataStd_RealArray) anArray;
304 if (!myLab.FindAttribute(TDataStd_RealArray::GetID(), anArray))
305 return QTransform(); // return identity if there is no array
307 anArray->Value(1), anArray->Value(2), anArray->Value(3),
308 anArray->Value(4), anArray->Value(5), anArray->Value(6),
309 anArray->Value(7), anArray->Value(8), anArray->Value(9));
313 void HYDROData_Image::UpdateTrsf()
315 QPoint aPointA, aPointB, aPointC;
316 if ( !GetLocalPoints( aPointA, aPointB, aPointC ) )
319 TransformationMode aTrsfMode;
320 QPointF aTrsfPointA, aTrsfPointB, aTrsfPointC;
321 if ( !GetGlobalPoints( aTrsfMode, aTrsfPointA, aTrsfPointB, aTrsfPointC ) )
324 QTransform aRefTransform;
325 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
327 bool anIsRefImage = aTrsfMode == ReferenceImage;
330 if ( aRefImage.IsNull() )
333 aRefTransform = aRefImage->Trsf();
336 bool anIsByTwoPoints = IsByTwoPoints();
338 // Convert lambert coordinates to cartesian
339 if ( aTrsfMode == ManualGeodesic )
341 double aXCart = 0, aYCart = 0;
343 HYDROData_Lambert93::toXY( aTrsfPointA.x(), aTrsfPointA.y(), aXCart, aYCart );
344 aTrsfPointA = QPointF( aXCart, aYCart );
346 HYDROData_Lambert93::toXY( aTrsfPointB.x(), aTrsfPointB.y(), aXCart, aYCart );
347 aTrsfPointB = QPointF( aXCart, aYCart );
349 if ( !anIsByTwoPoints )
351 HYDROData_Lambert93::toXY( aTrsfPointC.x(), aTrsfPointC.y(), aXCart, aYCart );
352 aTrsfPointC = QPointF( aXCart, aYCart );
356 // generate third points if needed
357 if ( anIsByTwoPoints )
359 aPointC = generateThirdPoint( aPointA, aPointB, true ).toPoint();
360 aTrsfPointC = generateThirdPoint( aTrsfPointA, aTrsfPointB, anIsRefImage );
363 int xa = aPointA.x();
364 int ya = aPointA.y();
365 int xb = aPointB.x();
366 int yb = aPointB.y();
367 int xc = aPointC.x();
368 int yc = aPointC.y();
370 double xta = aTrsfPointA.x();
371 double yta = aTrsfPointA.y();
372 double xtb = aTrsfPointB.x();
373 double ytb = aTrsfPointB.y();
374 double xtc = aTrsfPointC.x();
375 double ytc = aTrsfPointC.y();
377 // first, check that three input points don't belong to a single line
378 if( ( yb - ya ) * ( xc - xa ) == ( yc - ya ) * ( xb - xa ) )
381 // the same check for the reference points
382 if( anIsRefImage && ( ( ytb - yta ) * ( xtc - xta ) == ( ytc - yta ) * ( xtb - xta ) ) )
385 QTransform aTransform1( xa, ya, 1, xb, yb, 1, xc, yc, 1 );
386 QTransform aTransform2( xta, yta, 1, xtb, ytb, 1, xtc, ytc, 1 );
388 bool anIsInvertible = false;
389 QTransform aTransform1Inverted = aTransform1.inverted( &anIsInvertible );
390 if( !anIsInvertible )
393 QTransform aResTransform = aTransform1Inverted * aTransform2;
395 aResTransform *= aRefTransform;
397 SetTrsf( aResTransform );
400 bool HYDROData_Image::IsByTwoPoints() const
402 if ( !HasLocalPoints() || !HasGlobalPoints() )
405 QPoint aPointA, aPointB, aPointC;
406 GetLocalPoints( aPointA, aPointB, aPointC );
408 return aPointC.x() < 0 && aPointC.y() < 0;
411 bool HYDROData_Image::HasReferences() const
413 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
414 int aNbReferences = NbReferences();
416 return !aRefImage.IsNull() || aNbReferences > 0;
419 void HYDROData_Image::RemoveAllReferences()
421 if ( !HasReferences() )
424 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
425 if ( !aRefImage.IsNull() )
427 RemoveTrsfReferenceImage();
432 SetOperatorName( "" );
434 SetIsSelfSplitted( false );
437 SetToUpdate( false );
439 bool anIsByTwoPoints = IsByTwoPoints();
441 QImage anImage = Image();
442 if ( anImage.isNull() )
445 // Set local points to default position
446 QPoint aLocalPointA = QPoint( 0, 0 );
447 QPoint aLocalPointB = QPoint( anImage.width(), 0 );
448 QPoint aLocalPointC = anIsByTwoPoints ? QPoint( INT_MIN, INT_MIN ) : QPoint( 0, anImage.height() );
450 SetLocalPoints( aLocalPointA, aLocalPointB, aLocalPointC, false );
452 // Calculate global points
453 QTransform aTransform = Trsf();
455 QPointF aTrsfPointA = QPointF( aTransform.map( aLocalPointA ) );
456 QPointF aTrsfPointB = QPointF( aTransform.map( aLocalPointB ) );
457 QPointF aTrsfPointC = anIsByTwoPoints ? QPointF( INT_MIN, INT_MIN ) :
458 QPointF( aTransform.map( aLocalPointC ) );
460 SetGlobalPoints( ManualCartesian, aTrsfPointA, aTrsfPointB, aTrsfPointC );
463 void HYDROData_Image::SetLocalPoints( const QPoint& thePointA,
464 const QPoint& thePointB,
465 const QPoint& thePointC,
466 const bool theIsUpdate )
468 Handle(TDataStd_RealArray) anArray;
469 if ( !myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
470 anArray = TDataStd_RealArray::Set( myLab.FindChild( DataTag_TrsfPoints ), 1, 12 );
472 anArray->SetValue( 1, thePointA.x() );
473 anArray->SetValue( 2, thePointA.y() );
474 anArray->SetValue( 3, thePointB.x() );
475 anArray->SetValue( 4, thePointB.y() );
476 anArray->SetValue( 5, thePointC.x() );
477 anArray->SetValue( 6, thePointC.y() );
479 TDataStd_UAttribute::Set( myLab.FindChild( DataTag_TrsfPoints ), GUID_HAS_LOCAL_POINTS );
485 bool HYDROData_Image::GetLocalPoints( QPoint& thePointA,
487 QPoint& thePointC ) const
489 if ( !HasLocalPoints() )
492 Handle(TDataStd_RealArray) anArray;
493 myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray );
495 thePointA = QPointF( anArray->Value( 1 ), anArray->Value( 2 ) ).toPoint();
496 thePointB = QPointF( anArray->Value( 3 ), anArray->Value( 4 ) ).toPoint();
497 thePointC = QPointF( anArray->Value( 5 ), anArray->Value( 6 ) ).toPoint();
502 bool HYDROData_Image::HasLocalPoints() const
504 TDF_Label aLabel = myLab.FindChild( DataTag_TrsfPoints, false );
505 if ( aLabel.IsNull() || !aLabel.IsAttribute( GUID_HAS_LOCAL_POINTS ) )
508 Handle(TDataStd_RealArray) anArray;
509 return aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray );
513 void HYDROData_Image::SetGlobalPoints( const TransformationMode& theMode,
514 const QPointF& thePointA,
515 const QPointF& thePointB,
516 const QPointF& thePointC,
517 const bool theIsUpdate )
519 Handle(TDataStd_RealArray) anArray;
520 if ( !myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray ) )
521 anArray = TDataStd_RealArray::Set( myLab.FindChild( DataTag_TrsfPoints ), 1, 12 );
523 anArray->SetValue( 7, thePointA.x() );
524 anArray->SetValue( 8, thePointA.y() );
525 anArray->SetValue( 9, thePointB.x() );
526 anArray->SetValue( 10, thePointB.y() );
527 anArray->SetValue( 11, thePointC.x() );
528 anArray->SetValue( 12, thePointC.y() );
530 SetTrsfMode( theMode );
532 TDataStd_UAttribute::Set( myLab.FindChild( DataTag_TrsfPoints ), GUID_HAS_GLOBAL_POINTS );
540 aCPointA = QPointF( aTransform.map( aPointA ) );
541 aCPointB = QPointF( aTransform.map( aPointB ) );
542 aCPointC = QPointF( aTransform.map( aPointC ) );
544 // compute Lambert93 points
552 double xla = 0, yla = 0, xlb = 0, ylb = 0, xlc = 0, ylc = 0;
553 HYDROData_Lambert93::toGeo( xca, yca, yla, xla );
554 HYDROData_Lambert93::toGeo( xcb, ycb, ylb, xlb );
555 HYDROData_Lambert93::toGeo( xcc, ycc, ylc, xlc );
557 aLPointA = QPointF( xla * 3600.0, yla * 3600.0 ); // convert degrees to seconds
558 aLPointB = QPointF( xlb * 3600.0, ylb * 3600.0 ); // convert degrees to seconds
559 aLPointC = QPointF( xlc * 3600.0, ylc * 3600.0 ); // convert degrees to seconds
564 bool HYDROData_Image::GetGlobalPoints( TransformationMode& theMode,
567 QPointF& thePointC ) const
569 if ( !HasGlobalPoints() )
572 theMode = GetTrsfMode();
574 Handle(TDataStd_RealArray) anArray;
575 myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray );
577 thePointA = QPointF( anArray->Value( 7 ), anArray->Value( 8 ) );
578 thePointB = QPointF( anArray->Value( 9 ), anArray->Value( 10 ) );
579 thePointC = QPointF( anArray->Value( 11 ), anArray->Value( 12 ) );
584 bool HYDROData_Image::HasGlobalPoints() const
586 TDF_Label aLabel = myLab.FindChild( DataTag_TrsfPoints, false );
587 if ( aLabel.IsNull() || !aLabel.IsAttribute( GUID_HAS_GLOBAL_POINTS ) )
590 Handle(TDataStd_RealArray) anArray;
591 return aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray );
594 void HYDROData_Image::SetReferencePoints( const Handle(HYDROData_Image)& theRefImage,
595 const QPointF& thePointA,
596 const QPointF& thePointB,
597 const QPointF& thePointC,
598 const bool theIsUpdate )
600 SetTrsfReferenceImage( theRefImage );
601 SetGlobalPoints( ReferenceImage, thePointA, thePointB, thePointC, theIsUpdate );
604 bool HYDROData_Image::GetReferencePoints( Handle(HYDROData_Image)& theRefImage,
607 QPointF& thePointC ) const
609 if ( !HasReferencePoints() )
612 theRefImage = GetTrsfReferenceImage();
614 TransformationMode aMode;
615 GetGlobalPoints( aMode, thePointA, thePointB, thePointC );
620 bool HYDROData_Image::HasReferencePoints() const
622 if ( !HasGlobalPoints() )
625 Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
626 if ( aRefImage.IsNull() )
629 TransformationMode aTrsfMode = GetTrsfMode();
630 if ( aTrsfMode != ReferenceImage )
636 void HYDROData_Image::SetTrsfMode( const TransformationMode& theMode )
638 TDataStd_Integer::Set( myLab.FindChild( DataTag_TrsfMode ), (int)theMode );
641 HYDROData_Image::TransformationMode HYDROData_Image::GetTrsfMode() const
643 TransformationMode aResMode = ManualGeodesic;
645 TDF_Label aLabel = myLab.FindChild( DataTag_TrsfPoints, false );
646 if ( !aLabel.IsNull() )
648 Handle(TDataStd_Integer) aMode;
649 if ( myLab.FindChild( DataTag_TrsfMode ).FindAttribute( TDataStd_Integer::GetID(), aMode ) )
650 aResMode = (TransformationMode)aMode->Get();
656 void HYDROData_Image::SetTrsfReferenceImage( const Handle(HYDROData_Image)& theRefImage )
658 SetReferenceObject( theRefImage, DataTag_TrsfImage );
661 Handle(HYDROData_Image) HYDROData_Image::GetTrsfReferenceImage() const
663 return Handle(HYDROData_Image)::DownCast( GetReferenceObject( DataTag_TrsfImage ) );
666 void HYDROData_Image::RemoveTrsfReferenceImage()
668 return RemoveReferenceObject( DataTag_TrsfImage );
671 void HYDROData_Image::AppendReference( const Handle(HYDROData_Entity)& theReferenced )
673 AddReferenceObject( theReferenced, 0 );
676 int HYDROData_Image::NbReferences() const
678 return NbReferenceObjects( 0 );
681 Handle(HYDROData_Entity) HYDROData_Image::Reference( const int theIndex ) const
683 return GetReferenceObject( 0, theIndex );
686 void HYDROData_Image::ChangeReference(
687 const int theIndex, Handle(HYDROData_Entity) theReferenced)
689 SetReferenceObject( theReferenced, 0, theIndex );
692 void HYDROData_Image::RemoveReference(const int theIndex)
694 RemoveReferenceObject( 0, theIndex );
697 void HYDROData_Image::ClearReferences()
699 ClearReferenceObjects( 0 );
702 void HYDROData_Image::SetOperatorName(const QString theOpName)
704 TDataStd_Name::Set(myLab.FindChild(DataTag_Operator),
705 TCollection_ExtendedString(theOpName.toLatin1().constData()));
708 QString HYDROData_Image::OperatorName() const
710 Handle(TDataStd_Name) aName;
711 if (myLab.FindChild(DataTag_Operator).
712 FindAttribute(TDataStd_Name::GetID(), aName)) {
713 TCollection_AsciiString aStr(aName->Get());
714 return QString(aStr.ToCString());
719 void HYDROData_Image::SetArgs(const QByteArray& theArgs)
721 SaveByteArray(DataTag_Operator, theArgs.constData(), theArgs.length());
724 QByteArray HYDROData_Image::Args() const
727 const char* aData = ByteArray(DataTag_Operator, aLen);
730 return QByteArray(aData, aLen);
733 void HYDROData_Image::SetIsSelfSplitted(bool theFlag)
736 TDataStd_UAttribute::Set(myLab, GUID_SELF_SPLITTED);
738 myLab.ForgetAttribute(GUID_SELF_SPLITTED);
742 bool HYDROData_Image::IsSelfSplitted() const
744 return myLab.IsAttribute(GUID_SELF_SPLITTED);
747 QPointF HYDROData_Image::generateThirdPoint( const QPointF& thePointA,
748 const QPointF& thePointB,
749 const bool& theIsLocal ) const
751 // Rotate vector to 90 degrees : clockwise - for local
752 // anticlockwise - for global
753 const double aTheta = theIsLocal ? -M_PI_2 : M_PI_2;
757 // Move to (0,0) for correct rotation
758 double x = thePointB.x() - thePointA.x();
759 double y = thePointB.y() - thePointA.y();
761 aResPoint.setX( x * cos( aTheta ) - y * sin( aTheta ) );
762 aResPoint.setY( x * sin( aTheta ) + y * cos( aTheta ) );
764 // Move back to origin position
765 aResPoint.setX( aResPoint.x() + thePointA.x() );
766 aResPoint.setY( aResPoint.y() + thePointA.y() );