]> SALOME platform Git repositories - modules/visu.git/blobdiff - src/VISU_I/VISU_Table_i.cc
Salome HOME
Implementation of the "21384: [CEA 508] Plot2d Allow user to rescale curve" isuue.
[modules/visu.git] / src / VISU_I / VISU_Table_i.cc
index 22166fd5a01c5a8d4e2a550495eeb0569fc643e8..852f1404f43824c7c06d2706bbb1707429d0945d 100644 (file)
@@ -1,23 +1,23 @@
-//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
-//  This library is free software; you can redistribute it and/or
-//  modify it under the terms of the GNU Lesser General Public
-//  License as published by the Free Software Foundation; either
-//  version 2.1 of the License.
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
 //
-//  This library is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-//  Lesser General Public License for more details.
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
 //
-//  You should have received a copy of the GNU Lesser General Public
-//  License along with this library; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 //  VISU OBJECT : interactive object for VISU entities implementation
@@ -27,6 +27,7 @@
 //
 #include "VISU_Table_i.hh"
 
+#include "VISU_Tools.h"
 #include "VISU_CutLinesBase_i.hh"
 #include "VISU_CutSegment_i.hh"
 #include "VISU_Result_i.hh"
@@ -519,6 +520,7 @@ VISU::Curve_i::Curve_i( SALOMEDS::Study_ptr theStudy, Table_i* theTable,
   myLineWidth = 0;
   myMarker = VISU::Curve::CIRCLE;
   myColor.R = 0.0; myColor.G = 0.0; myColor.B = 0.0;
+  myScale = 1.0;
 }
 /*!
   Destructor
@@ -604,6 +606,31 @@ VISU::Curve_i
   return myLineWidth;
 }
 
+//----------------------------------------------------------------------------
+void 
+VISU::Curve_i
+::SetScale( CORBA::Double theCoef )
+{
+  myScale = theCoef;  
+  UpdatePlot2d( this, eUpdateData );
+}
+
+//----------------------------------------------------------------------------
+CORBA::Double 
+VISU::Curve_i
+::GetScale()
+{
+  return myScale;    
+}
+
+//----------------------------------------------------------------------------
+void 
+VISU::Curve_i
+::RemoveScale()
+{
+  SetScale( 1.0 );
+}
+
 //----------------------------------------------------------------------------
 /*!
   Creates curve object
@@ -929,6 +956,9 @@ SPlot2d_Curve* VISU::Curve_i::CreatePresentation()
   crv->setIO(new SALOME_InteractiveObject(aString.in(), "VISU", GetName().c_str()));
   if ( myTable )
     crv->setTableIO(new SALOME_InteractiveObject(myTable->GetObjectEntry().c_str(), "VISU", myTable->GetName().c_str()));
+
+  if(!myContainers.isEmpty())     
+    crv->addOwners(myContainers);
   return crv;
 }
 /*!
@@ -948,6 +978,8 @@ VISU::Storable* VISU::Curve_i::Restore( const Storable::TRestoringMap& theMap, S
   QString v2_str = VISU::Storable::FindValue(theMap,"myIsV2", &ok);
   myIsV2 = ok ? v2_str.toInt() : false;
 
+  QString scale_str = VISU::Storable::FindValue(theMap,"myScale", &ok);
+  myScale = ok ? scale_str.toDouble() : 1.0;
   myColor.R = VISU::Storable::FindValue(theMap,"myColor.R").toDouble();
   myColor.G = VISU::Storable::FindValue(theMap,"myColor.G").toDouble();
   myColor.B = VISU::Storable::FindValue(theMap,"myColor.B").toDouble();
@@ -967,6 +999,7 @@ void VISU::Curve_i::ToStream( std::ostringstream& theStr )
   Storable::DataToStream( theStr, "myVRow",      myVRow );
   Storable::DataToStream( theStr, "myZRow",      myZRow );
   Storable::DataToStream( theStr, "myIsV2",      myIsV2 );
+  Storable::DataToStream( theStr, "myScale",     myScale );
   Storable::DataToStream( theStr, "myColor.R",   myColor.R );
   Storable::DataToStream( theStr, "myColor.G",   myColor.G );
   Storable::DataToStream( theStr, "myColor.B",   myColor.B );
@@ -1000,6 +1033,21 @@ VISU::Storable* VISU::Curve_i::StorableEngine(SALOMEDS::SObject_ptr theSObject,
 
 void VISU::Curve_i::RemoveFromStudy()
 {
+  
+  //remove curve from containers
+  PortableServer::POA_ptr aPOA = GetPOA();
+  ContainerSet::ConstIterator it = myContainers.begin();
+  for ( ; it != myContainers.end(); it++ ) {    
+    SALOMEDS::SObject_var aSObject =  GetStudyDocument()->FindObjectID( (*it).toLatin1().data() );
+    if ( aSObject->_is_nil() ) continue;
+    
+    CORBA::Object_var anObj = VISU::SObjectToObject( aSObject );
+    if ( CORBA::is_nil( anObj ) ) continue;
+    VISU::Container_i* aContainer = dynamic_cast<VISU::Container_i*>( VISU::GetServant( anObj.in() ).in() );
+    if ( !aContainer ) continue;
+    aContainer->RemoveCurve(VISU::Curve::_narrow(aPOA->servant_to_reference(this)));
+  }
+
   struct TRemoveFromStudy: public SALOME_Event
   {
     VISU::Curve_i* myRemovable;
@@ -1024,6 +1072,32 @@ SALOMEDS::SObject_var VISU::Curve_i::GetSObject()
   return mySObj;
 }
 
+
+/*!
+  Add container.
+  id  - owner of the curve
+*/
+void VISU::Curve_i::addContainer(const QString& id) {
+  myContainers.insert(id);
+}
+
+/*!
+  Remove Container
+  id  - entry of the container
+*/
+void VISU::Curve_i::removeContainer(const QString& id) {
+  myContainers.insert(id);
+}
+
+/*!
+  Get all owners of the curve.
+  \return owners of the curve.
+*/
+VISU::ContainerSet VISU::Curve_i::getContainers() const {
+  return myContainers;
+}
+
+
 //----------------------------------------------------------------
 //                      Container Object
 //----------------------------------------------------------------
@@ -1078,6 +1152,7 @@ void VISU::Container_i::AddCurve( Curve_ptr theCurve )
       SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
       SALOMEDS::SObject_var newSO = Builder->NewObject( mySO );
       Builder->Addreference( newSO, SO );
+      pCurve->addContainer(GetEntry().c_str());
     }
   }
 }
@@ -1107,6 +1182,7 @@ void VISU::Container_i::RemoveCurve( Curve_ptr theCurve )
          Builder->RemoveObject( childSO );
        }
       }
+      pCurve->removeContainer(GetEntry().c_str());
     }
   }
 }
@@ -1115,7 +1191,7 @@ void VISU::Container_i::RemoveCurve( Curve_ptr theCurve )
 */
 CORBA::Long VISU::Container_i::GetNbCurves()
 {
-  Update();
+  //  Update();
   return myCurves.count();
 }
 /*!