Salome HOME
Image update corrected.
[modules/hydro.git] / src / HYDROData / HYDROData_Image.cxx
index e589ae9cbec11205a3d233c17013a183b29f6820..1a0bec79ebd2b0251d9023a07cfc1f42eb716887 100644 (file)
@@ -3,7 +3,6 @@
 
 #include "HYDROData_Document.h"
 #include "HYDROData_Lambert93.h"
-#include "HYDROData_Tool.h"
 #include "HYDROData_OperationsFactory.h"
 
 #include <TDataStd_RealArray.hxx>
@@ -152,12 +151,21 @@ QStringList HYDROData_Image::DumpToPython( MapOfTreatedObjects& theTreatedObject
 
 void HYDROData_Image::Update()
 {
+  bool anIsToUpdate = IsMustBeUpdated();
+
+  HYDROData_Entity::Update();
+
+  if ( !anIsToUpdate )
+    return;
+
   HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory();
 
   ImageComposer_Operator* anOp = aFactory->Operator( OperatorName() );
   if ( anOp ) // Update image if there is an operation
   {
     // Fill by arguments and process the operation
+    anOp->setBinArgs( Args() );
+
     QVariant anObj1, anObj2;
     int aNbReferences = NbReferences();
 
@@ -194,14 +202,7 @@ void HYDROData_Image::Update()
     UpdateTrsf();
   }
 
-  Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
-  if ( !aDocument.IsNull() )
-  {
-    // Change the states of this and all depended images
-    SetToUpdate( true );
-    HYDROData_Tool::SetMustBeUpdatedImages( aDocument );
-    SetToUpdate( false );
-  }
+  SetToUpdate( false );
 }
 
 QVariant HYDROData_Image::GetDataVariant()
@@ -233,27 +234,32 @@ HYDROData_SequenceOfObjects HYDROData_Image::GetAllReferenceObjects() const
 
 void HYDROData_Image::SetImage(const QImage& theImage)
 {
-  if (theImage.isNull()) {
+  if ( theImage.isNull() )
+  {
     // for empty image remove all previously stored attributes
     myLab.ForgetAttribute(TDataStd_IntegerArray::GetID());
     myLab.ForgetAttribute(TDataStd_ByteArray::GetID());
-    return;
   }
-  // store width, height, bytes per line and format in integer array 
-  Handle(TDataStd_IntegerArray) aParams;
-  if (!myLab.FindAttribute(TDataStd_IntegerArray::GetID(), aParams)) {
-    aParams = TDataStd_IntegerArray::Set(myLab, 1, 4);
+  else
+  {
+    // store width, height, bytes per line and format in integer array 
+    Handle(TDataStd_IntegerArray) aParams;
+    if (!myLab.FindAttribute(TDataStd_IntegerArray::GetID(), aParams)) {
+      aParams = TDataStd_IntegerArray::Set(myLab, 1, 4);
+    }
+    aParams->SetValue(1, theImage.width());
+    aParams->SetValue(2, theImage.height());
+    aParams->SetValue(3, theImage.bytesPerLine());
+    aParams->SetValue(4, (int)(theImage.format()));
+    // store data of image in byte array
+    const char* aData = (const char*)(theImage.bits());
+    SaveByteArray(0, aData, theImage.byteCount());
   }
-  aParams->SetValue(1, theImage.width());
-  aParams->SetValue(2, theImage.height());
-  aParams->SetValue(3, theImage.bytesPerLine());
-  aParams->SetValue(4, (int)(theImage.format()));
-  // store data of image in byte array
-  const char* aData = (const char*)(theImage.bits());
-  SaveByteArray(0, aData, theImage.byteCount());
+
+  SetToUpdate( true );
 }
 
-bool HYDROData_Image::LoadImage(const QString& theFilePath)
+bool HYDROData_Image::LoadImage( const QString& theFilePath )
 {
   QImage anImage( theFilePath );
   SetImage( anImage );
@@ -274,10 +280,12 @@ QImage HYDROData_Image::Image()
   return aResult;
 }
 
-void HYDROData_Image::SetFilePath(const QString& theFilePath)
+void HYDROData_Image::SetFilePath( const QString& theFilePath )
 {
   TCollection_AsciiString anAsciiStr( theFilePath.toStdString().c_str() );
   TDataStd_AsciiString::Set( myLab.FindChild( DataTag_FilePath ), anAsciiStr );
+
+  SetToUpdate( true );
 }
 
 QString HYDROData_Image::GetFilePath() const
@@ -312,6 +320,8 @@ void HYDROData_Image::SetTrsf(const QTransform& theTrsf)
   anArray->SetValue(7, theTrsf.m31());
   anArray->SetValue(8, theTrsf.m32());
   anArray->SetValue(9, theTrsf.m33());
+
+  SetToUpdate( true );
 }
 
 QTransform HYDROData_Image::Trsf() const
@@ -451,13 +461,14 @@ void HYDROData_Image::RemoveAllReferences()
     SetIsSelfSplitted( false );
   }
 
-  SetToUpdate( false );
-
   bool anIsByTwoPoints = IsByTwoPoints();
 
   QImage anImage = Image();
   if ( anImage.isNull() )
+  {
+    SetToUpdate( false );
     return;
+  }
 
   // Set local points to default position
   QPoint aLocalPointA = QPoint( 0, 0 );
@@ -475,6 +486,8 @@ void HYDROData_Image::RemoveAllReferences()
                                           QPointF( aTransform.map( aLocalPointC ) );
 
   SetGlobalPoints( ManualCartesian, aTrsfPointA, aTrsfPointB, aTrsfPointC );
+
+  SetToUpdate( false );
 }
 
 void HYDROData_Image::SetLocalPoints( const QPoint& thePointA,
@@ -497,6 +510,8 @@ void HYDROData_Image::SetLocalPoints( const QPoint& thePointA,
 
   if ( theIsUpdate )
     UpdateTrsf();
+
+  SetToUpdate( true );
 }
 
 bool HYDROData_Image::GetLocalPoints( QPoint& thePointA,
@@ -551,31 +566,7 @@ void HYDROData_Image::SetGlobalPoints( const TransformationMode& theMode,
   if ( theIsUpdate )
     UpdateTrsf();
 
-  /*
-  if( anIsRefImage )
-  {
-    aCPointA = QPointF( aTransform.map( aPointA ) );
-    aCPointB = QPointF( aTransform.map( aPointB ) );
-    aCPointC = QPointF( aTransform.map( aPointC ) );
-
-    // compute Lambert93 points
-    xca = aCPointA.x();
-    yca = aCPointA.y();
-    xcb = aCPointB.x();
-    ycb = aCPointB.y();
-    xcc = aCPointC.x();
-    ycc = aCPointC.y();
-
-    double xla = 0, yla = 0, xlb = 0, ylb = 0, xlc = 0, ylc = 0;
-    HYDROData_Lambert93::toGeo( xca, yca, yla, xla );
-    HYDROData_Lambert93::toGeo( xcb, ycb, ylb, xlb );
-    HYDROData_Lambert93::toGeo( xcc, ycc, ylc, xlc );
-
-    aLPointA = QPointF( xla * 3600.0, yla * 3600.0 ); // convert degrees to seconds
-    aLPointB = QPointF( xlb * 3600.0, ylb * 3600.0 ); // convert degrees to seconds
-    aLPointC = QPointF( xlc * 3600.0, ylc * 3600.0 ); // convert degrees to seconds
-  }
-  */
+  SetToUpdate( true );
 }
 
 bool HYDROData_Image::GetGlobalPoints( TransformationMode& theMode,
@@ -653,6 +644,7 @@ bool HYDROData_Image::HasReferencePoints() const
 void HYDROData_Image::SetTrsfMode( const TransformationMode& theMode )
 {
   TDataStd_Integer::Set( myLab.FindChild( DataTag_TrsfMode ), (int)theMode );
+  SetToUpdate( true );
 }
 
 HYDROData_Image::TransformationMode HYDROData_Image::GetTrsfMode() const
@@ -673,6 +665,7 @@ HYDROData_Image::TransformationMode HYDROData_Image::GetTrsfMode() const
 void HYDROData_Image::SetTrsfReferenceImage( const Handle(HYDROData_Image)& theRefImage )
 {
   SetReferenceObject( theRefImage, DataTag_TrsfImage );
+  SetToUpdate( true );
 }
 
 Handle(HYDROData_Image) HYDROData_Image::GetTrsfReferenceImage() const
@@ -682,12 +675,14 @@ Handle(HYDROData_Image) HYDROData_Image::GetTrsfReferenceImage() const
 
 void HYDROData_Image::RemoveTrsfReferenceImage()
 {
-  return RemoveReferenceObject( DataTag_TrsfImage );
+  RemoveReferenceObject( DataTag_TrsfImage );
+  SetToUpdate( true );
 }
 
 void HYDROData_Image::AppendReference( const Handle(HYDROData_Entity)& theReferenced )
 {
   AddReferenceObject( theReferenced, 0 );
+  SetToUpdate( true );
 }
 
 int HYDROData_Image::NbReferences() const
@@ -704,22 +699,26 @@ void HYDROData_Image::ChangeReference(
     const int theIndex, Handle(HYDROData_Entity) theReferenced)
 {
   SetReferenceObject( theReferenced, 0, theIndex );
+  SetToUpdate( true );
 }
 
 void HYDROData_Image::RemoveReference(const int theIndex)
 {
   RemoveReferenceObject( 0, theIndex );
+  SetToUpdate( true );
 }
 
 void HYDROData_Image::ClearReferences()
 {
   ClearReferenceObjects( 0 );
+  SetToUpdate( true );
 }
 
 void HYDROData_Image::SetOperatorName( const QString theOpName )
 {
   TCollection_AsciiString anAsciiStr( theOpName.toStdString().c_str() );
   TDataStd_AsciiString::Set( myLab.FindChild( DataTag_Operator ), anAsciiStr );
+  SetToUpdate( true );
 }
 
 QString HYDROData_Image::OperatorName() const
@@ -740,6 +739,7 @@ QString HYDROData_Image::OperatorName() const
 void HYDROData_Image::SetArgs(const QByteArray& theArgs)
 {
   SaveByteArray(DataTag_Operator, theArgs.constData(), theArgs.length());
+  SetToUpdate( true );
 }
 
 QByteArray HYDROData_Image::Args() const
@@ -758,6 +758,7 @@ void HYDROData_Image::SetIsSelfSplitted(bool theFlag)
   } else {
     myLab.ForgetAttribute(GUID_SELF_SPLITTED);
   }
+  SetToUpdate( true );
 }
 
 bool HYDROData_Image::IsSelfSplitted() const
@@ -770,7 +771,7 @@ QPointF HYDROData_Image::generateThirdPoint( const QPointF& thePointA,
                                              const bool&    theIsLocal ) const
 {
   // Rotate vector to 90 degrees : clockwise - for local
-  //                               anticlockwise - for global
+  //                               counterclockwise - for global
   const double aTheta = theIsLocal ? -M_PI_2 : M_PI_2;
 
   QPointF aResPoint;