Salome HOME
Update Help for VISU module.
[modules/visu.git] / src / OBJECT / VISU_Actor.cxx
index 1d5da42dba28ee0f6b100dc7005c9bda7b82f491..e38b8cd3a139f4aec69ef7ec76bac64a61138d5a 100644 (file)
-using namespace std;
-//  File      : VISU_Actor.cxx
-//  Created   : Wed Feb 20 18:04:42 CET 2002
-//  Author    : Laurent CORNABE with help of Nicolas REJNERI
-//  Project   : SALOME
-//  Module    : VISU
-//  Copyright : PRINCIPIA RD
+//  VISU OBJECT : interactive object for VISU entities implementation
+//
+//  Copyright (C) 2003  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 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 
+// 
+//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+//
+//
+//
+//  File   : VISU_Actor.cxx
+//  Author : Laurent CORNABE with help of Nicolas REJNERI
+//  Module : VISU
 //  $Header$
 
 #include "VISU_Actor.h"
-#include "utilities.h"
+#include "VISU_PipeLine.hxx"
+#include "VTKViewer_ShrinkFilter.h"
+#include "VTKViewer_GeometryFilter.h"
+#include "VTKViewer_PassThroughFilter.h"
  
+#include <stdexcept>
+
 // VTK Includes
+#include <vtkProperty.h>
+
+#include <vtkDataSet.h>
+#include <vtkPolyData.h>
+#include <vtkUnstructuredGrid.h>
+
+#include <vtkShrinkFilter.h>
+#include <vtkShrinkPolyData.h>
+
+#include <vtkDataSetMapper.h>
+#include <vtkGeometryFilter.h>
 #include <vtkObjectFactory.h>
 
-VISU_Actor* VISU_Actor::New(){
-  vtkObject* ret = vtkObjectFactory::CreateInstance("VISU_Actor");
-  if(ret) return (VISU_Actor*)ret;
-  return new VISU_Actor;
-} 
+#include "utilities.h"
+
+using namespace std;
+
+static int MYVTKDEBUG = 0;
+
+#ifdef _DEBUG_
+static int MYDEBUG = 1;
+#else
+static int MYDEBUG = 0;
+#endif
+
+//=======================================================================
+
+vtkStandardNewMacro(VISU_Actor);
+
 VISU_Actor::VISU_Actor(){
-  this->Device = vtkActor::New();
-
-  this->EdgeDevice = vtkActor::New();
-  EdgeDevice->VisibilityOff();
-  EdgeDevice->PickableOff();
-
-  this->DataSource = NULL;
-  myScalarBar = NULL;
-  this->myIO = NULL;
-  this->myName = "";
-  this->IsDefined = false;
-  this->IsShrunk = false;
-  this->IsShrinkable = false;
-  this->VisuActorType = 0;
-  this->Presentation = NULL;
-  myHasScalarBar = false;
-  this->HighlightProperty = NULL;
-  this->ishighlighted = false;
-  this->IsHighlighting = true;
-  this->ResultAtNode = false;
-  this->VectorComponent = -1;
-  for (int i=0; i<6; i++)
-         this->VABounds[i] = 0.;
-  strcpy(this->FieldName,"");
-}
-
-
-VISU_Actor::~VISU_Actor()
-{
-  this->EdgeDevice->Delete();  
-}
-
-
-void VISU_Actor::setScalarBar(VISU_ScalarBarActor* theBar) {
-  if (theBar) {
-    myScalarBar = theBar;
-    myHasScalarBar = true;
-  } else {
-    myScalarBar = NULL;
-    myHasScalarBar = false;
+  SetDebug(MYVTKDEBUG);
+  myParent = this;
+  myPipeLine = NULL;
+  myPrs3d = NULL;
+
+  myStoreMapping = true;
+
+  myIsShrunk = false;
+  myIsShrinkable = false;
+  myShrinkFilter = VTKViewer_ShrinkFilter::New();
+  myShrinkFilter->SetStoreMapping(true);
+  SetShrinkFactor();
+  
+  myMapper = vtkDataSetMapper::New();
+
+  myIO = NULL;
+  myName = "";
+}
+
+VISU_Actor::~VISU_Actor(){
+  SALOME_Actor::SetProperty(NULL);
+
+  myMapper->RemoveAllInputs();
+  myMapper->Delete();
+
+  if(myPipeLine) 
+    myPipeLine->UnRegister(this);
+
+  myShrinkFilter->UnRegisterAllOutputs();
+  myShrinkFilter->Delete();
+}
+
+void VISU_Actor::setIO(const Handle(SALOME_InteractiveObject)& theIO){
+  SALOME_Actor::setIO(theIO); 
+  myName = theIO->getName(); 
+}
+
+void VISU_Actor::SetPrs3d(VISU::Prs3d_i* thePrs3d){ 
+  myPrs3d = thePrs3d;
+}
+
+void VISU_Actor::SetPipeLine(VISU_PipeLine* thePipeLine) {
+  if (myPipeLine != thePipeLine){
+    if (myPipeLine != NULL) myPipeLine->UnRegister(this);
+    myPipeLine = thePipeLine;
+    if (myPipeLine != NULL) myPipeLine->Register(this);
+    this->Modified();
+    vtkMapper *aMapper = myPipeLine->GetMapper();
+    vtkDataSet *aDataSet = aMapper->GetInput();
+
+    //This code has been moved into VISU::Prs3d_i::UpdateActor() for bug 9808
+    //if(!aDataSet)
+    //  throw std::runtime_error("VISU_Actor::SetPipeLine >> There is no input data !!!");
+    //aDataSet->Update();
+    //static float eps = VTK_LARGE_FLOAT * 0.1 ;
+    //if(aDataSet->GetLength() > eps)
+    //  throw std::runtime_error("VISU_Actor::SetPipeLine >> Diagonal of the actor is too large !!!");
+    //if(!aDataSet->GetNumberOfCells())
+    //  throw std::runtime_error("VISU_Actor::SetPipeLine >> There is no visible elements");
+
+    //Bug SAL4221:  Mesh with less than 10 cells : shrink mode disable
+    //SetShrinkable(aDataSet->GetNumberOfCells() > 10);
+    SetShrinkable(thePipeLine->IsShrinkable());
+    //Now, we use vtkShrinkPolyData (not vtkShrinkFilter), 
+    //and the class there is no such limitation.
+
+    myMapper->SetInput(aDataSet);
+    SetMapper(myMapper);
   }
 }
 
+void VISU_Actor::SetParent(VISU_Actor* theParent){ 
+  myParent = theParent;
+}
 
-void VISU_Actor::setActor(vtkActor *Actor){
-  this->Device=Actor;
+void VISU_Actor::SetRepresentation(int theMode) { 
+  SALOME_Actor::SetRepresentation(theMode);
+  if(myRepresentation == VTK_POINTS)
+    UnShrink();
 }
 
-void VISU_Actor::ShallowCopy(vtkProp *prop){
-  VISU_Actor *f = VISU_Actor::SafeDownCast(prop);
-  if ( f != NULL )
-    {
-      setName( f->getName() );
-      if ( f->hasIO() )
-       setIO( f->getIO() );
-    }
-  SALOME_Actor::ShallowCopy(prop);
+void VISU_Actor::SetOpacity(float theValue){
+  GetProperty()->SetOpacity(theValue);
+}
+
+float VISU_Actor::GetOpacity(){ 
+  return GetProperty()->GetOpacity();
 }
 
-void VISU_Actor::highlight(Standard_Boolean highlight) {
-  if (this->IsHighlighting) {
-    if(highlight && !ishighlighted) {
-      ishighlighted=true;
-      // build highlight property is necessary
-      if(HighlightProperty==NULL) {
-       HighlightProperty = vtkProperty::New();
-       HighlightProperty->SetAmbient(0.5);
-       HighlightProperty->SetDiffuse(0.3);
-       HighlightProperty->SetSpecular(0.2);
-       HighlightProperty->SetRepresentationToSurface();
-       HighlightProperty->SetAmbientColor(1, 1, 1);
-       HighlightProperty->SetDiffuseColor(1, 1, 1);
-       HighlightProperty->SetSpecularColor(0.5, 0.5, 0.5);
-      }
-      this->Property = HighlightProperty;
-    }else if (!highlight) {
-      if(ishighlighted) {
-       ishighlighted=false;
-      }
-    }
+
+void VISU_Actor::SetShrink(){
+  if(!myIsShrinkable) return;
+  if(vtkDataSet* aDataSet = myPassFilter[0]->GetOutput()){
+    myShrinkFilter->SetInput(aDataSet);
+    myPassFilter[1]->SetInput(myShrinkFilter->GetOutput());
+    myIsShrunk = true;
   }
 }
 
+void VISU_Actor::UnShrink(){
+  if(!myIsShrunk) return;
+  if(vtkDataSet* aDataSet = myPassFilter[0]->GetOutput()){
+    myPassFilter[1]->SetInput(aDataSet);
+    myPassFilter[1]->Modified();
+    myIsShrunk = false;
+    Modified();
+  }
+}
 
-void VISU_Actor::setVABounds(const float bounds[6]){
-  for (int i=0; i<6; i++)
-    VABounds[i] = bounds[i];
+void VISU_Actor::SetShrinkable(bool theIsShrinkable){
+  myIsShrinkable = theIsShrinkable;
 }
 
+void VISU_Actor::SetShrinkFactor(float theValue){
+  myShrinkFilter->SetShrinkFactor(theValue);
+  Modified();
+}
+
+float VISU_Actor::GetShrinkFactor(){
+  return myShrinkFilter->GetShrinkFactor();
+}
+
+
+//----------------------------------------------------------------------------
+void VISU_Actor::SetVisibility(int theMode){
+  SALOME_Actor::SetVisibility(theMode);
+}
 
-void VISU_Actor::getVABounds(float bounds[6]){
-  for (int i=0; i<6; i++)
-    bounds[i] = VABounds[i];
+int VISU_Actor::GetVisibility(){
+  return SALOME_Actor::GetVisibility();
 }
 
+void VISU_Actor::SetLineWidth(float theLineWidth){
+  GetProperty()->SetLineWidth(theLineWidth);
+}
+
+float VISU_Actor::GetLineWidth(){
+  return GetProperty()->GetLineWidth();
+}
+
+//----------------------------------------------------------------------------
+void VISU_Actor::ShallowCopy(vtkProp *prop){
+  VISU_Actor *anActor = VISU_Actor::SafeDownCast(prop);
+  if(anActor != NULL){
+    setName(anActor->getName());
+    if(anActor->hasIO()) setIO(anActor->getIO());
+  }
+  SALOME_Actor::ShallowCopy(prop);
+}
+
+//----------------------------------------------------------------------------
+int VISU_Actor::GetNodeObjId(int theVtkID){
+  if ( myIsShrunk ) 
+    return myShrinkFilter->GetNodeObjId(theVtkID);
+  return theVtkID;
+}
+
+int VISU_Actor::GetElemObjId(int theVtkID){
+  return myGeomFilter->GetElemObjId(theVtkID);
+}