Cherrypick from master 2004-01-30 13:28:12 UTC prascle <prascle> 'PR: merge SalomePro 1_2d = mergefrom_BRANCH_MergeV1_2d':
idl/SALOME_GenericObj.idl
src/GenericObj/Makefile.in
src/GenericObj/SALOME_GenericObj_i.cc
src/GenericObj/SALOME_GenericObj_i.hh
src/VTKViewer/VTKViewer_Trihedron.cxx
src/VTKViewer/VTKViewer_Trihedron.h
src/VTKViewer/VTKViewer_Utilities.cxx
src/VTKViewer/VTKViewer_Utilities.h
--- /dev/null
+// 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 : SALOME_Component.idl
+// Author : Alexey Petrov, OPEN CASCADE
+// $Header$
+
+#ifndef _SALOME_GENERICOBJ_IDL_
+#define _SALOME_GENERICOBJ_IDL_
+/*!
+
+This is a package of interfaces used for providing of common bechavior
+of SALOME transient CORBA objects in %SALOME application.
+*/
+module SALOME{
+ interface GenericObj{
+ /*! Increase the reference count (mark as used by another object).*/
+ void Register();
+ /*! Decrease the reference count (release by another object).*/
+ void Destroy();
+ };
+};
+
+#endif
--- /dev/null
+# Copyright (C) 2003 CEA/DEN, EDF R&D
+#
+#
+#
+# File : Makefile.in
+# Author : Alexey Petrov
+# Module : VISU
+# $Header:
+
+top_srcdir=@top_srcdir@
+top_builddir=../..
+srcdir=@srcdir@
+VPATH=.:@srcdir@:@top_srcdir@/idl
+
+
+@COMMENCE@
+
+# Libraries targets
+LIB = libSalomeGenericObj.la
+LIB_SRC = SALOME_GenericObj_i.cc
+
+LIB_SERVER_IDL = SALOME_GenericObj.idl
+LIB_CLIENT_IDL =
+
+# Executables targets
+BIN =
+BIN_SRC =
+
+BIN_CLIENT_IDL =
+BIN_SERVER_IDL =
+
+EXPORT_HEADERS = SALOME_GenericObj_i.hh
+
+# additionnal information to compil and link file
+CPPFLAGS +=
+
+LDFLAGS +=
+
+LIBS +=
+
+# additional file to be cleaned
+MOSTLYCLEAN +=
+CLEAN +=
+DISTCLEAN +=
+
+@CONCLUDE@
\ No newline at end of file
--- /dev/null
+// SALOME_GenericObj_i_CC
+//
+// 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 : SALOME_GenericObj_i.cc
+// Author : Alexey PETROV
+// Module : SALOME
+
+#include "SALOME_GenericObj_i.hh"
+#include "utilities.h"
+
+using namespace SALOME;
+
+GenericObj_i::GenericObj_i(PortableServer::POA_ptr thePOA): myRefCounter(1){
+ INFOS("GenericObj_i::GenericObj_i() - this = "<<this<<
+ "; CORBA::is_nil(thePOA) = "<<CORBA::is_nil(thePOA));
+ if(CORBA::is_nil(thePOA))
+ myPOA = PortableServer::RefCountServantBase::_default_POA();
+ else
+ myPOA = PortableServer::POA::_duplicate(thePOA);
+}
+
+
+PortableServer::POA_ptr GenericObj_i::_default_POA(){
+ //return PortableServer::RefCountServantBase::_default_POA();
+ return PortableServer::POA::_duplicate(myPOA);
+}
+
+
+void GenericObj_i::Register(){
+ INFOS("GenericObj_i::Register "<<this<<"; myRefCounter = "<<myRefCounter)
+ ++myRefCounter;
+}
+
+
+void GenericObj_i::Destroy(){
+ INFOS("GenericObj_i::Destroy "<<this<<"; myRefCounter = "<<myRefCounter)
+ if(--myRefCounter <= 0){
+ PortableServer::ObjectId_var anObjectId = myPOA->servant_to_id(this);
+ myPOA->deactivate_object(anObjectId.in());
+ _remove_ref();
+ }
+}
--- /dev/null
+// SALOME_GenericObj_i_HH
+//
+// 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 : SALOME_GenericObj_i.hh
+// Author : Alexey PETROV
+// Module : SALOME
+
+#ifndef SALOME_GenericObj_i_HH
+#define SALOME_GenericObj_i_HH
+
+// IDL headers
+#include "SALOMEconfig.h"
+#include CORBA_SERVER_HEADER(SALOME_GenericObj)
+
+namespace SALOME{
+ class GenericObj_i :
+ public virtual POA_SALOME::GenericObj,
+ public virtual PortableServer::RefCountServantBase
+ {
+ protected:
+ PortableServer::POA_var myPOA;
+ int myRefCounter;
+ public:
+ // In the constructor you can provide default POA for the servant
+ GenericObj_i(PortableServer::POA_ptr thePOA = PortableServer::POA::_nil());
+ // The function is used implicetly in "_this" function
+ virtual PortableServer::POA_ptr _default_POA();
+ public: // Follow functions is IDL defined
+ /*! Increase the reference count (mark as used by another object).*/
+ virtual void Register();
+ /*! Decrease the reference count (release by another object).*/
+ virtual void Destroy();
+ };
+};
+
+#endif
+
--- /dev/null
+// SALOME VTKViewer :
+//
+// 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 : VTKViewer_Trihedron.cxx
+// Author : Alexey PETROV
+// Module : SALOME
+// $Header:
+
+#include "VTKViewer_Trihedron.h"
+#include "utilities.h"
+#include "SALOME_Actor.h"
+
+// VTK Includes
+#include <vtkMath.h>
+#include <vtkMapper.h>
+#include <vtkDataSet.h>
+#include <vtkRenderer.h>
+#include <vtkFollower.h>
+#include <vtkRenderWindow.h>
+#include <vtkObjectFactory.h>
+
+#include <vtkActor.h>
+#include <vtkProperty.h>
+#include <vtkLineSource.h>
+#include <vtkConeSource.h>
+#include <vtkPolyDataMapper.h>
+
+#include "VTKViewer_VectorText.h"
+
+using namespace std;
+
+//==============================================================================
+
+class VTKViewer_UnScaledActor: public vtkFollower{
+ VTKViewer_UnScaledActor(const VTKViewer_UnScaledActor&);
+
+public:
+ vtkTypeMacro(VTKViewer_UnScaledActor,vtkFollower);
+ static VTKViewer_UnScaledActor *New();
+
+ virtual void SetSize(int theSize);
+ virtual void Render(vtkRenderer *theRenderer);
+
+protected:
+ VTKViewer_UnScaledActor();
+ int mySize;
+};
+
+vtkStandardNewMacro(VTKViewer_UnScaledActor);
+
+VTKViewer_UnScaledActor::VTKViewer_UnScaledActor(){}
+
+void VTKViewer_UnScaledActor::Render(vtkRenderer *theRenderer){
+ if(theRenderer){
+ float P[2][3] = {{-1.0, -1.0, 0.0},{+1.0, +1.0, 0.0}};
+ theRenderer->ViewToWorld(P[0][0],P[0][1],P[0][2]);
+ theRenderer->ViewToWorld(P[1][0],P[1][1],P[1][2]);
+ float aWorldDiag = sqrt((P[1][0]-P[0][0])*(P[1][0]-P[0][0])+
+ (P[1][1]-P[0][1])*(P[1][1]-P[0][1])+
+ (P[1][2]-P[0][2])*(P[1][2]-P[0][2]));
+ int* aSize = theRenderer->GetRenderWindow()->GetSize();
+ float aWinDiag = sqrt(float(aSize[0]*aSize[0]+aSize[1]*aSize[1]));
+ vtkDataSet* aDataSet = GetMapper()->GetInput();
+ float aLength = aDataSet->GetLength();
+ float aScale = mySize*aWorldDiag/aWinDiag/aLength*sqrt(float(aSize[0])/float(aSize[1]));
+ SetScale(aScale);
+ }
+ vtkFollower::Render(theRenderer);
+}
+
+void VTKViewer_UnScaledActor::SetSize(int theSize){
+ mySize = theSize;
+}
+
+//==============================================================================
+
+// The base class for concreate Axis
+// Its only duty is to give correct initialization and destruction
+// of its pipe-lines
+class VTKViewer_Axis : public vtkObject{
+protected:
+ VTKViewer_Axis();
+ VTKViewer_Axis(const VTKViewer_Axis&);
+ virtual ~VTKViewer_Axis();
+ public:
+ vtkTypeMacro(VTKViewer_Axis,vtkObject);
+
+ virtual void AddToRender(vtkRenderer* theRenderer){
+ theRenderer->AddActor(myLabelActor);
+ theRenderer->AddActor(myArrowActor);
+ theRenderer->AddActor(myLineActor);
+ }
+
+ virtual void SetVisibility(VTKViewer_Trihedron::TVisibility theVis);
+ virtual VTKViewer_Trihedron::TVisibility GetVisibility() {
+ return myVisibility;
+ }
+
+ virtual void SetCamera(vtkCamera* theCamera){
+ myLabelActor->SetCamera(theCamera);
+ }
+
+ virtual void SetProperty(vtkProperty* theProperty){
+ myLabelActor->SetProperty(theProperty);
+ myArrowActor->SetProperty(theProperty);
+ myLineActor->SetProperty(theProperty);
+ }
+
+ virtual void SetSize(float theSize);
+
+ virtual VTKViewer_UnScaledActor* GetLabel(){
+ return myLabelActor;
+ }
+
+ virtual VTKViewer_UnScaledActor* GetArrow(){
+ return myArrowActor;
+ }
+
+protected:
+ VTKViewer_Trihedron::TVisibility myVisibility;
+ float myDir[3], myRot[3];
+
+ vtkActor *myLineActor;
+ VTKViewer_UnScaledActor *myArrowActor;
+ VTKViewer_UnScaledActor *myLabelActor;
+
+ vtkPolyDataMapper *myMapper[3];
+ vtkLineSource *myLineSource;
+ vtkConeSource *myConeSource;
+ VTKViewer_VectorText* myVectorText;
+};
+
+VTKViewer_Axis::VTKViewer_Axis(){
+ // Initialize the Line pipe-line representation
+ myLineSource = vtkLineSource::New();
+ myLineSource->SetPoint1(0.0,0.0,0.0);
+
+ myMapper[0] = vtkPolyDataMapper::New();
+ myMapper[0]->SetInput(myLineSource->GetOutput());
+
+ myLineActor = vtkActor::New();
+ myLineActor->SetMapper(myMapper[0]);
+ myLineActor->PickableOff();
+
+ // Initialize the Arrow pipe-line representation
+ myConeSource = vtkConeSource::New();
+ myConeSource->SetResolution(2);
+ myConeSource->SetAngle(10);
+
+ myMapper[1] = vtkPolyDataMapper::New();
+ myMapper[1]->SetInput(myConeSource->GetOutput());
+
+ myArrowActor = VTKViewer_UnScaledActor::New();
+ myArrowActor->SetMapper(myMapper[1]);
+ static int aArrowActorSize = 24;
+ myArrowActor->SetSize(aArrowActorSize);
+ myArrowActor->PickableOff();
+
+ // Initialize the Label pipe-line representation
+ myVectorText = VTKViewer_VectorText::New();
+
+ myMapper[2] = vtkPolyDataMapper::New();
+ myMapper[2]->SetInput(myVectorText->GetOutput());
+
+ myLabelActor = VTKViewer_UnScaledActor::New();
+ myLabelActor->SetMapper(myMapper[2]);
+ static int aLabelActorSize = 12;
+ myLabelActor->SetSize(aLabelActorSize);
+ myLabelActor->PickableOff();
+
+ // Initialise visibility param.
+ myVisibility = VTKViewer_Trihedron::eOn;
+}
+
+VTKViewer_Axis::~VTKViewer_Axis(){
+ // Destroy of the Label pipe-line representation
+ myLabelActor->Delete();
+
+ myMapper[2]->RemoveAllInputs();
+ myMapper[2]->Delete();
+
+ myVectorText->Delete();
+
+ // Destroy of the Arrow pipe-line representation
+ myArrowActor->Delete();
+
+ myMapper[1]->RemoveAllInputs();
+ myMapper[1]->Delete();
+
+ myConeSource->Delete();
+
+ // Destroy of the Arrow pipe-line representation
+ myLineActor->Delete();
+
+ myMapper[2]->RemoveAllInputs();
+ myMapper[2]->Delete();
+
+ myLineSource->Delete();
+}
+
+void VTKViewer_Axis::SetVisibility(VTKViewer_Trihedron::TVisibility theVis){
+ switch(theVis){
+ case VTKViewer_Trihedron::eOff:
+ case VTKViewer_Trihedron::eOn:
+ myLabelActor->SetVisibility(theVis);
+ myArrowActor->SetVisibility(theVis);
+ myLineActor->SetVisibility(theVis);
+ break;
+ case VTKViewer_Trihedron::eOnlyLineOn:
+ myLabelActor->VisibilityOff();
+ myArrowActor->VisibilityOff();
+ myLineActor->VisibilityOn();
+ break;
+ default:
+ return;
+ }
+ myVisibility = theVis;
+}
+
+void VTKViewer_Axis::SetSize(float theSize){
+ float aPosition[3] = {myDir[0]*theSize, myDir[1]*theSize, myDir[2]*theSize};
+ myLineSource->SetPoint2(aPosition);
+
+ myArrowActor->SetPosition(0.0,0.0,0.0);
+ myArrowActor->AddPosition(aPosition);
+ myArrowActor->SetOrientation(myRot);
+
+ myLabelActor->SetPosition(0.0,0.0,0.0);
+ myLabelActor->AddPosition(aPosition);
+}
+
+//==============================================================================
+class VTKViewer_XAxis : public VTKViewer_Axis{
+protected:
+ VTKViewer_XAxis();
+ VTKViewer_XAxis(const VTKViewer_XAxis&);
+public:
+ vtkTypeMacro(VTKViewer_XAxis,VTKViewer_Axis);
+ static VTKViewer_XAxis *New();
+};
+
+vtkStandardNewMacro(VTKViewer_XAxis);
+
+VTKViewer_XAxis::VTKViewer_XAxis(){
+ myDir[0] = 1.0; myDir[1] = 0.0; myDir[2] = 0.0;
+ myRot[0] = 0.0; myRot[1] = 0.0; myRot[2] = 0.0;
+ myVectorText->SetText("X");
+ vtkProperty* aProperty = vtkProperty::New();
+ aProperty->SetColor(1.0,0.0,0.0);
+ SetProperty(aProperty);
+ aProperty->Delete();
+}
+
+//==============================================================================
+class VTKViewer_YAxis : public VTKViewer_Axis{
+protected:
+ VTKViewer_YAxis();
+ VTKViewer_YAxis(const VTKViewer_YAxis&);
+public:
+ vtkTypeMacro(VTKViewer_YAxis,VTKViewer_Axis);
+ static VTKViewer_YAxis *New();
+};
+
+vtkStandardNewMacro(VTKViewer_YAxis);
+
+VTKViewer_YAxis::VTKViewer_YAxis(){
+ myDir[0] = 0.0; myDir[1] = 1.0; myDir[2] = 0.0;
+ myRot[0] = 0.0; myRot[1] = 0.0; myRot[2] = 90.;
+ myVectorText->SetText("Y");
+ vtkProperty* aProperty = vtkProperty::New();
+ aProperty->SetColor(0.0,1.0,0.0);
+ SetProperty(aProperty);
+ aProperty->Delete();
+}
+
+//==============================================================================
+class VTKViewer_ZAxis : public VTKViewer_Axis{
+protected:
+ VTKViewer_ZAxis();
+ VTKViewer_ZAxis(const VTKViewer_ZAxis&);
+public:
+ vtkTypeMacro(VTKViewer_ZAxis,VTKViewer_Axis);
+ static VTKViewer_ZAxis *New();
+};
+
+vtkStandardNewMacro(VTKViewer_ZAxis);
+
+VTKViewer_ZAxis::VTKViewer_ZAxis(){
+ myDir[0] = 0.0; myDir[1] = 0.0; myDir[2] = 1.0;
+ myRot[0] = 0.0; myRot[1] = -90; myRot[2] = 0.0;
+ myVectorText->SetText("Z");
+ vtkProperty* aProperty = vtkProperty::New();
+ aProperty->SetColor(0.0,0.0,1.0);
+ SetProperty(aProperty);
+ aProperty->Delete();
+}
+
+//==============================================================================
+
+vtkStandardNewMacro(VTKViewer_Trihedron);
+
+VTKViewer_Trihedron::VTKViewer_Trihedron(){
+ myPresent = vtkActorCollection::New();
+ myAxis[0] = VTKViewer_XAxis::New();
+ myAxis[1] = VTKViewer_YAxis::New();
+ myAxis[2] = VTKViewer_ZAxis::New();
+ static float aSize = 100;
+ SetSize(aSize);
+}
+
+VTKViewer_Trihedron::~VTKViewer_Trihedron(){
+ myPresent->RemoveAllItems();
+ myPresent->Delete();
+ for(int i = 0; i < 3; i++)
+ myAxis[i]->Delete();
+}
+
+void VTKViewer_Trihedron::SetSize(float theSize){
+ mySize = theSize;
+ for(int i = 0; i < 3; i++)
+ myAxis[i]->SetSize(theSize);
+}
+
+void VTKViewer_Trihedron::SetVisibility(TVisibility theVis){
+ for(int i = 0; i < 3; i++)
+ myAxis[i]->SetVisibility(theVis);
+}
+
+VTKViewer_Trihedron::TVisibility VTKViewer_Trihedron::GetVisibility(){
+ return myAxis[0]->GetVisibility();
+}
+
+void VTKViewer_Trihedron::AddToRender(vtkRenderer* theRenderer){
+ vtkCamera* aCamera = theRenderer->GetActiveCamera();
+ for(int i = 0; i < 3; i++){
+ myAxis[i]->AddToRender(theRenderer);
+ myAxis[i]->SetCamera(aCamera);
+ }
+}
+
+void VTKViewer_Trihedron::RemoveFromRender(vtkRenderer* theRenderer){
+ myPresent->InitTraversal();
+ while(vtkActor* anActor = myPresent->GetNextActor())
+ theRenderer->RemoveActor(anActor);
+}
+
+int VTKViewer_Trihedron::GetVisibleActorCount(vtkRenderer* theRenderer){
+ //TVisibility aVis = GetVisibility();
+ //SetVisibility(eOff);
+ vtkActorCollection* aCollection = theRenderer->GetActors();
+ aCollection->InitTraversal();
+ int aCount = 0;
+ while(vtkActor* prop = aCollection->GetNextActor())
+ if( prop->GetVisibility())
+ if(SALOME_Actor* anActor = SALOME_Actor::SafeDownCast(prop))
+ if(!anActor->IsInfinitive())
+ aCount++;
+ //int aCount = theRenderer->VisibleActorCount();
+ //SetVisibility(aVis);
+ return aCount;
+}
+
+void VTKViewer_Trihedron::Render(vtkRenderer* theRenderer){
+ for(int i = 0; i < 3; i++)
+ {
+ myAxis[i]->GetLabel()->Render(theRenderer);
+ myAxis[i]->GetArrow()->Render(theRenderer);
+ }
+}
+
--- /dev/null
+// SALOME VTKViewer :
+//
+// 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 : VTKViewer_Trihedron.h
+// Author : Alexey PETROV
+// Module : SALOME
+// $Header:
+
+#ifndef VTKViewer_Trihedron_H
+#define VTKViewer_Trihedron_H
+
+#include <vtkObject.h>
+
+class vtkActorCollection;
+class VTKViewer_Axis;
+class vtkRenderer;
+
+class VTKViewer_Trihedron : public vtkObject{
+ protected:
+ VTKViewer_Trihedron();
+ VTKViewer_Trihedron(const VTKViewer_Trihedron&);
+ virtual ~VTKViewer_Trihedron();
+ public:
+ vtkTypeMacro(VTKViewer_Trihedron,vtkObject);
+ static VTKViewer_Trihedron *New();
+
+ virtual void SetSize(float theSize);
+ virtual float GetSize() { return mySize;}
+
+ enum TVisibility{eOff, eOn, eOnlyLineOn};
+ virtual void SetVisibility(TVisibility theVis);
+ virtual void VisibilityOff() { SetVisibility(eOff);}
+ virtual void VisibilityOn() { SetVisibility(eOn);}
+ virtual TVisibility GetVisibility();
+
+ virtual void AddToRender(vtkRenderer* theRenderer);
+ virtual void RemoveFromRender(vtkRenderer* theRenderer);
+
+ virtual int GetVisibleActorCount(vtkRenderer* theRenderer);
+
+ virtual void Render(vtkRenderer *theRenderer);
+
+protected:
+ vtkActorCollection* myPresent;
+ VTKViewer_Axis* myAxis[3];
+ float mySize;
+};
+
+#endif
--- /dev/null
+// SALOME VTKViewer :
+//
+// 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 : VTKViewer_Utilities.cxx
+// Author : Alexey PETROV
+// Module : SALOME
+// $Header:
+
+#include "VTKViewer_Utilities.h"
+#include "utilities.h"
+#include "SALOME_Actor.h"
+
+// VTK Includes
+#include <vtkMath.h>
+#include <vtkCamera.h>
+#include <vtkRenderer.h>
+#include <vtkRenderWindow.h>
+
+using namespace std;
+
+//see vtkRenderer::ResetCamera(float bounds[6]) method
+void ResetCamera(vtkRenderer* theRenderer, int theUsingZeroFocalPoint){
+ if(!theRenderer) return;
+ float bounds[6];
+ int aCount = ComputeVisiblePropBounds(theRenderer,bounds);
+ if(theUsingZeroFocalPoint || aCount){
+ float aLength = bounds[1]-bounds[0];
+ aLength = max((bounds[3]-bounds[2]),aLength);
+ aLength = max((bounds[5]-bounds[4]),aLength);
+
+ double vn[3];
+ if ( theRenderer->GetActiveCamera() != NULL )
+ theRenderer->GetActiveCamera()->GetViewPlaneNormal(vn);
+ else{
+ INFOS("Trying to reset non-existant camera");
+ return;
+ }
+
+ float center[3] = {0.0, 0.0, 0.0};
+ if(!theUsingZeroFocalPoint){
+ center[0] = (bounds[0] + bounds[1])/2.0;
+ center[1] = (bounds[2] + bounds[3])/2.0;
+ center[2] = (bounds[4] + bounds[5])/2.0;
+ }
+ theRenderer->GetActiveCamera()->SetFocalPoint(center[0],center[1],center[2]);
+
+ float width = sqrt((bounds[1]-bounds[0])*(bounds[1]-bounds[0]) +
+ (bounds[3]-bounds[2])*(bounds[3]-bounds[2]) +
+ (bounds[5]-bounds[4])*(bounds[5]-bounds[4]));
+
+ double ang = theRenderer->GetActiveCamera()->GetViewAngle();
+ float distance = 2.0*width/tan(ang*vtkMath::Pi()/360.0);
+
+ // check view-up vector against view plane normal
+ double *vup = theRenderer->GetActiveCamera()->GetViewUp();
+ if ( fabs(vtkMath::Dot(vup,vn)) > 0.999 ){
+ MESSAGE("Resetting view-up since view plane normal is parallel");
+ theRenderer->GetActiveCamera()->SetViewUp(-vup[2], vup[0], vup[1]);
+ }
+
+ // update the camera
+ theRenderer->GetActiveCamera()->SetPosition(center[0]+distance*vn[0],
+ center[1]+distance*vn[1],
+ center[2]+distance*vn[2]);
+ // find size of the window
+ int* winsize = theRenderer->GetSize();
+ if(winsize[0] < winsize[1]) width *= float(winsize[1])/float(winsize[0]);
+
+ if(theUsingZeroFocalPoint) width *= sqrt(2.0);
+
+ theRenderer->GetActiveCamera()->SetParallelScale(width/2.0);
+ }
+ //workaround on VTK
+ //theRenderer->ResetCameraClippingRange(bounds);
+ ResetCameraClippingRange(theRenderer);
+}
+
+
+// Compute the bounds of the visible props
+int ComputeVisiblePropBounds(vtkRenderer* theRenderer, float theBounds[6]){
+ vtkProp *prop;
+ float *bounds;
+ int aCount=0;
+
+ theBounds[0] = theBounds[2] = theBounds[4] = VTK_LARGE_FLOAT;
+ theBounds[1] = theBounds[3] = theBounds[5] = -VTK_LARGE_FLOAT;
+
+ // loop through all props
+ vtkActorCollection* aCollection = theRenderer->GetActors();
+ aCollection->InitTraversal();
+ while (vtkActor* prop = aCollection->GetNextActor()) {
+ // if it's invisible, or has no geometry, we can skip the rest
+ if ( prop->GetVisibility() )
+ {
+ if(SALOME_Actor* anActor = SALOME_Actor::SafeDownCast(prop))
+ if(anActor->IsInfinitive()) continue;
+ bounds = prop->GetBounds();
+ // make sure we haven't got bogus bounds
+ if ( bounds != NULL &&
+ bounds[0] > -VTK_LARGE_FLOAT && bounds[1] < VTK_LARGE_FLOAT &&
+ bounds[2] > -VTK_LARGE_FLOAT && bounds[3] < VTK_LARGE_FLOAT &&
+ bounds[4] > -VTK_LARGE_FLOAT && bounds[5] < VTK_LARGE_FLOAT )
+ {
+ aCount++;
+
+ if (bounds[0] < theBounds[0])
+ {
+ theBounds[0] = bounds[0];
+ }
+ if (bounds[1] > theBounds[1])
+ {
+ theBounds[1] = bounds[1];
+ }
+ if (bounds[2] < theBounds[2])
+ {
+ theBounds[2] = bounds[2];
+ }
+ if (bounds[3] > theBounds[3])
+ {
+ theBounds[3] = bounds[3];
+ }
+ if (bounds[4] < theBounds[4])
+ {
+ theBounds[4] = bounds[4];
+ }
+ if (bounds[5] > theBounds[5])
+ {
+ theBounds[5] = bounds[5];
+ }
+ }//not bogus
+ }
+ }
+ return aCount;
+}
+
+
+//see vtkRenderer::ResetCameraClippingRange(float bounds[6]) method
+void ResetCameraClippingRange(vtkRenderer* theRenderer){
+ if(!theRenderer || !theRenderer->VisibleActorCount()) return;
+
+ vtkCamera* anActiveCamera = theRenderer->GetActiveCamera();
+ if( anActiveCamera == NULL ){
+ MESSAGE("Trying to reset clipping range of non-existant camera");
+ return;
+ }
+
+ // Find the plane equation for the camera view plane
+ double vn[3];
+ anActiveCamera->GetViewPlaneNormal(vn);
+ double position[3];
+ anActiveCamera->GetPosition(position);
+
+ float bounds[6];
+ theRenderer->ComputeVisiblePropBounds(bounds);
+
+ double center[3];
+ center[0] = (bounds[0] + bounds[1])/2.0;
+ center[1] = (bounds[2] + bounds[3])/2.0;
+ center[2] = (bounds[4] + bounds[5])/2.0;
+
+ double width = sqrt((bounds[1]-bounds[0])*(bounds[1]-bounds[0]) +
+ (bounds[3]-bounds[2])*(bounds[3]-bounds[2]) +
+ (bounds[5]-bounds[4])*(bounds[5]-bounds[4]));
+
+ double distance = sqrt((position[0]-center[0])*(position[0]-center[0]) +
+ (position[1]-center[1])*(position[1]-center[1]) +
+ (position[2]-center[2])*(position[2]-center[2]));
+
+ float range[2] = {distance - width/2.0, distance + width/2.0};
+
+ // Do not let the range behind the camera throw off the calculation.
+ if (range[0] < 0.0) range[0] = 0.0;
+
+ anActiveCamera->SetClippingRange( range );
+}
--- /dev/null
+// SALOME VTKViewer :
+//
+// 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 : VTKViewer_Utilities.h
+// Author : Alexey PETROV
+// Module : SALOME
+// $Header:
+
+#ifndef VTKViewer_Utilities_H
+#define VTKViewer_Utilities_H
+
+class vtkRenderer;
+
+extern void ResetCamera(vtkRenderer* theRenderer, int theUsingZeroFocalPoint = false);
+extern int ComputeVisiblePropBounds(vtkRenderer* theRenderer, float theBounds[6]);
+extern void ResetCameraClippingRange(vtkRenderer* theRenderer);
+extern float EPS_BNDBOX;
+
+#endif