Salome HOME
Drawing of zones in OCC view improved.
[modules/hydro.git] / src / HYDROData / HYDROData_Image.cxx
index 08a069fd756abcdb2ef11a4c6943781354fadb7d..362e151577e0dcf24ad2ba85377567fe0c440756 100644 (file)
@@ -1,9 +1,9 @@
 
 #include "HYDROData_Image.h"
 
-#include "HYDROData_Iterator.h"
-#include "HYDROOperations_Factory.h"
+#include "HYDROData_Document.h"
 #include "HYDROData_Tool.h"
+#include "HYDROOperations_Factory.h"
 
 #include <TDataStd_RealArray.hxx>
 #include <TDataStd_ByteArray.hxx>
@@ -12,7 +12,6 @@
 #include <TDataStd_Name.hxx>
 #include <TDataStd_UAttribute.hxx>
 #include <TDataStd_AsciiString.hxx>
-#include <TDF_ListIteratorOfLabelList.hxx>
 
 #include <ImageComposer_Operator.h>
 #include <ImageComposer_MetaTypes.h>
@@ -22,7 +21,7 @@
 static const Standard_GUID GUID_MUST_BE_UPDATED("80f2bb81-3873-4631-8ddd-940d2119f000");
 static const Standard_GUID GUID_SELF_SPLITTED("997995aa-5c19-40bf-9a60-ab4b70ad04d8");
 
-#define PYTHON_IMAGE_ID "1"
+#define PYTHON_IMAGE_ID "KIND_IMAGE"
 
 IMPLEMENT_STANDARD_HANDLE(HYDROData_Image, HYDROData_Object)
 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Image, HYDROData_Object)
@@ -57,6 +56,50 @@ QStringList HYDROData_Image::DumpToPython( MapOfTreatedObjects& theTreatedObject
     aResList << QString( "" );
     aResList << QString( "%1.LoadImage( \"%2\" );" )
                 .arg( anImageName ).arg( aFilePath );
+
+    // Dump transformation matrix for image
+    aResList << QString( "" );
+
+    QTransform aTrsf = Trsf();
+
+    aResList << QString( "trsf = QTransform( %1, %2, %3," )
+                .arg( aTrsf.m11() ).arg( aTrsf.m12() ).arg( aTrsf.m13() );
+    aResList << QString( "                   %1, %2, %3," )
+                .arg( aTrsf.m21() ).arg( aTrsf.m22() ).arg( aTrsf.m23() );
+    aResList << QString( "                   %1, %2, %3 );" )
+                .arg( aTrsf.m31() ).arg( aTrsf.m32() ).arg( aTrsf.m33() );
+
+    aResList << QString( "%1.SetTrsf( trsf );" ).arg( anImageName );
+
+    // Dump transformation points for image
+    aResList << QString( "" );
+
+    QPoint aPointAIn,  aPointBIn,  aPointCIn;
+    QPointF aPointAOut, aPointBOut, aPointCOut;
+    TrsfPoints( aPointAIn,  aPointBIn,  aPointCIn,
+                aPointAOut, aPointBOut, aPointCOut );
+
+    aResList << QString( "a_in = QPoint( %1, %2 );" )
+                .arg( aPointAIn.x() ).arg( aPointAIn.y() );
+
+    aResList << QString( "b_in = QPoint( %1, %2 );" )
+                .arg( aPointBIn.x() ).arg( aPointBIn.y() );
+
+    aResList << QString( "c_in = QPoint( %1, %2 );" )
+                .arg( aPointCIn.x() ).arg( aPointCIn.y() );
+
+    aResList << QString( "a_out = QPointF( %1, %2 );" )
+                .arg( aPointAOut.x() ).arg( aPointAOut.y() );
+
+    aResList << QString( "b_out = QPointF( %1, %2 );" )
+                .arg( aPointBOut.x() ).arg( aPointBOut.y() );
+
+    aResList << QString( "c_out = QPointF( %1, %2 );" )
+                .arg( aPointCOut.x() ).arg( aPointCOut.y() );
+
+    QString aGap = QString().fill( ' ', anImageName.size() + 16 );
+    aResList << QString( "%1.SetTrsfPoints( a_in,  b_in,  c_in," ).arg( anImageName );
+    aResList << QString( aGap            + "a_out, b_out, c_out );" );
   }
   else
   {
@@ -125,62 +168,18 @@ QStringList HYDROData_Image::DumpToPython( MapOfTreatedObjects& theTreatedObject
 
     // Necessary to update image in case of composed operator
     aResList << QString( "" );
-    aResList << QString( "%1.Update();" ).arg( anImageName );
+    aResList << QString( "%1.Update( False );" ).arg( anImageName );
   }
 
-  // Dump transformation matrix for image
-  aResList << QString( "" );
-
-  QTransform aTrsf = Trsf();
-
-  aResList << QString( "trsf = QTransform( %2, %3, %4," )
-              .arg( aTrsf.m11() ).arg( aTrsf.m12() ).arg( aTrsf.m13() );
-  aResList << QString( "                   %1, %2, %3," )
-              .arg( aTrsf.m21() ).arg( aTrsf.m22() ).arg( aTrsf.m23() );
-  aResList << QString( "                   %1, %2, %3 );" )
-              .arg( aTrsf.m31() ).arg( aTrsf.m32() ).arg( aTrsf.m33() );
-
-  aResList << QString( "%1.SetTrsf( trsf );" ).arg( anImageName );
-
-  // Dump transformation points for image
-  aResList << QString( "" );
-
-  QPoint aPointAIn,  aPointBIn,  aPointCIn;
-  QPointF aPointAOut, aPointBOut, aPointCOut;
-  TrsfPoints( aPointAIn,  aPointBIn,  aPointCIn,
-              aPointAOut, aPointBOut, aPointCOut );
-
-  aResList << QString( "a_in = QPoint( %1, %2 );" )
-              .arg( aPointAIn.x() ).arg( aPointAIn.y() );
-
-  aResList << QString( "b_in = QPoint( %1, %2 );" )
-              .arg( aPointBIn.x() ).arg( aPointBIn.y() );
-
-  aResList << QString( "c_in = QPoint( %1, %2 );" )
-              .arg( aPointCIn.x() ).arg( aPointCIn.y() );
-
-  aResList << QString( "a_out = QPointF( %1, %2 );" )
-              .arg( aPointAOut.x() ).arg( aPointAOut.y() );
-
-  aResList << QString( "b_out = QPointF( %1, %2 );" )
-              .arg( aPointBOut.x() ).arg( aPointBOut.y() );
-
-  aResList << QString( "c_out = QPointF( %1, %2 );" )
-              .arg( aPointCOut.x() ).arg( aPointCOut.y() );
-
-  QString aGap = QString().fill( ' ', anImageName.size() + 16 );
-  aResList << QString( "%1.SetTrsfPoints( a_in,  b_in,  c_in," ).arg( anImageName );
-  aResList << QString( aGap            + "a_out, b_out, c_out );" );
-
   return aResList;
 }
 
-void HYDROData_Image::Update()
+void HYDROData_Image::Update( const bool theIsForce )
 {
   HYDROOperations_Factory* aFactory = HYDROOperations_Factory::Factory();
 
   // Update image only if there is an operation
-  ImageComposer_Operator* anOp = aFactory->Operator( this );
+  ImageComposer_Operator* anOp = aFactory->Operator( OperatorName() );
   if ( anOp ) 
   {
     // Fill by arguments and process the operation
@@ -215,13 +214,16 @@ void HYDROData_Image::Update()
     SetImage( aResImg );
   }
 
-  Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( this );
-  if ( !aDocument.IsNull() )
+  if ( theIsForce )
   {
-    // Change the states of this and all depended images
-    MustBeUpdated( true );
-    HYDROData_Tool::SetMustBeUpdatedImages( aDocument );
-    MustBeUpdated( false );
+    Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( this );
+    if ( !aDocument.IsNull() )
+    {
+      // Change the states of this and all depended images
+      MustBeUpdated( true );
+      HYDROData_Tool::SetMustBeUpdatedImages( aDocument );
+      MustBeUpdated( false );
+    }
   }
 }
 
@@ -379,77 +381,35 @@ bool HYDROData_Image::HasTrsfPoints() const
   return myLab.FindChild(DataTag_TrsfPoints).FindAttribute(TDataStd_RealArray::GetID(), anArray);
 }
 
-void HYDROData_Image::AppendReference(Handle(HYDROData_Object) theReferenced)
+void HYDROData_Image::AppendReference( const Handle(HYDROData_Object)& theReferenced )
 {
-  Handle(TDataStd_ReferenceList) aRefs;
-  if (!myLab.FindAttribute(TDataStd_ReferenceList::GetID(), aRefs))
-    aRefs = TDataStd_ReferenceList::Set(myLab);
-  aRefs->Append(theReferenced->Label());
+  AddReferenceObject( theReferenced, 0 );
 }
 
 int HYDROData_Image::NbReferences() const
 {
-  Handle(TDataStd_ReferenceList) aRefs;
-  if (!myLab.FindAttribute(TDataStd_ReferenceList::GetID(), aRefs))
-    return 0;
-  return aRefs->Extent();
+  return NbReferenceObjects( 0 );
 }
 
-Handle(HYDROData_Object) HYDROData_Image::Reference(const int theIndex) const
+Handle(HYDROData_Object) HYDROData_Image::Reference( const int theIndex ) const
 {
-  Handle(TDataStd_ReferenceList) aRefs;
-  if (!myLab.FindAttribute(TDataStd_ReferenceList::GetID(), aRefs))
-    return Handle(HYDROData_Object)();
-  if (theIndex < 0 || theIndex >= aRefs->Extent())
-    return Handle(HYDROData_Object)();
-
-  TDF_ListIteratorOfLabelList anIter(aRefs->List());
-  for(int anIndex = 0; anIndex != theIndex; anIter.Next(), anIndex++);
-  const TDF_Label& aRefLab = anIter.Value();
-  return Handle(HYDROData_Object)::DownCast(HYDROData_Iterator::Object(aRefLab));
+  return GetReferenceObject( 0, theIndex );
 }
 
 void HYDROData_Image::ChangeReference(
     const int theIndex, Handle(HYDROData_Object) theReferenced)
 {
-  Handle(TDataStd_ReferenceList) aRefs;
-  if (!myLab.FindAttribute(TDataStd_ReferenceList::GetID(), aRefs))
-    aRefs = TDataStd_ReferenceList::Set(myLab);
-  if (theIndex >= aRefs->Extent()) { // for too big index append it just to the end
-    AppendReference(theReferenced);
-  } else { // remove and insert new
-    TDF_ListIteratorOfLabelList anIter(aRefs->List());
-    int anIndex = 0;
-    for(; anIndex != theIndex; anIter.Next(), anIndex++);
-    const TDF_Label& aRemovedLab = anIter.Value();
-    anIter.Next();
-    aRefs->Remove(aRemovedLab);
-    if (anIter.More()) 
-      aRefs->InsertBefore(theReferenced->Label(), anIter.Value());
-    else 
-      aRefs->Append(theReferenced->Label());
-  }
+  SetReferenceObject( theReferenced, 0, theIndex );
 }
 
 void HYDROData_Image::RemoveReference(const int theIndex)
 {
-  Handle(TDataStd_ReferenceList) aRefs;
-  if (!myLab.FindAttribute(TDataStd_ReferenceList::GetID(), aRefs))
-    return; // no references, nothing to remove
-  if (aRefs->Extent() == 1 && theIndex == 0) { // remove all if only one
-    ClearReferences();
-    return;
-  }
-  TDF_ListIteratorOfLabelList anIter(aRefs->List());
-  int anIndex = 0;
-  for(; anIndex != theIndex && anIter.More(); anIter.Next(), anIndex++);
-  if (anIter.More())
-    aRefs->Remove(anIter.Value());
+  RemoveReferenceObject( 0, theIndex );
 }
 
 void HYDROData_Image::ClearReferences()
 {
-  myLab.ForgetAttribute(TDataStd_ReferenceList::GetID());
+  ClearReferenceObjects( 0 );
 }
 
 void HYDROData_Image::SetOperatorName(const QString theOpName)