-using namespace std;
-// File : VTKViewer_ViewFrame.cxx
-// Created : Wed Mar 20 11:29:40 2002
-// Author : Nicolas REJNERI
-// Project : SALOME
-// Module : VTKViewer
-// Copyright : Open CASCADE 2002
+// SALOME VTKViewer : build VTK viewer into Salome desktop
+//
+// 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_ViewFrame.cxx
+// Author : Nicolas REJNERI
+// Module : SALOME
// $Header$
#include "VTKViewer_ViewFrame.h"
+#include "VTKViewer_Utilities.h"
+#include "VTKViewer_Trihedron.h"
+#include "SALOME_CubeAxesActor2D.h"
#include "VTKViewer_RenderWindow.h"
+#include "VTKViewer_RenderWindowInteractor.h"
#include "VTKViewer_InteractorStyleSALOME.h"
+#include "VTKViewer_Algorithm.h"
+#include "VTKViewer_Functor.h"
+#include "VTKViewer_Prs.h"
+
+#include "SALOME_Actor.h"
+#include "SALOME_Transform.h"
+#include "SALOME_TransformFilter.h"
+#include "SALOME_GeometryFilter.h"
+#include "SALOMEGUI.h"
#include "QAD_Settings.h"
#include "QAD_Config.h"
#include "QAD_Desktop.h"
#include "SALOME_Selection.h"
#include "SALOME_InteractiveObject.hxx"
+#include "ToolsGUI.h"
+#include "SALOMEDS_Tool.hxx"
#include "utilities.h"
#include <qapplication.h>
// VTK Includes
-#include <vtkMath.h>
-#include <vtkTextSource.h>
-#include <vtkLine.h>
-#include <vtkConeSource.h>
-#include <vtkTextMapper.h>
-#include <vtkMapper2D.h>
-#include <vtkActor2D.h>
-#include <vtkWindowToImageFilter.h>
-#include <vtkTIFFWriter.h>
-
-#include <vtkTransformPolyDataFilter.h>
-#include <vtkDataSetMapper.h>
+#include <vtkActor.h>
+#include <vtkCamera.h>
+#include <vtkRenderer.h>
+#include <vtkTransform.h>
+#include <vtkActorCollection.h>
+#include <vtkTextProperty.h>
+
+#include <TColStd_IndexedMapOfInteger.hxx>
+
+#ifdef _DEBUG_
+static int MYDEBUG = 0;
+#else
+static int MYDEBUG = 0;
+#endif
+
+using namespace std;
/*!
Constructor
{
m_ViewUp[0] = 0; m_ViewUp[1] = 0; m_ViewUp[2] = -1;
m_ViewNormal[0] = 0; m_ViewNormal[1] = 0; m_ViewNormal[2] = 1;
+ m_Triedron = VTKViewer_Trihedron::New();
+ m_CubeAxes = SALOME_CubeAxesActor2D::New();
+ m_Transform = SALOME_Transform::New();
+ //m_Renderer = VTKViewer_Renderer::New() ;
+ m_Renderer = vtkRenderer::New() ;
- // m_InitialSetupDone = false ;
+ m_Triedron->AddToRender(m_Renderer);
+ m_Renderer->AddProp(m_CubeAxes);
InitialSetup();
+}
- m_NonIsometricTransform = NULL;
-
-}
-
-
-static vtkActor* CreateTextActor(char *text) {
-
- vtkTextSource* XLabel = vtkTextSource::New();
- XLabel->SetForegroundColor(1,1,1);
- XLabel->SetBackgroundColor(0,0,0);
- XLabel->SetText(text);
-
- vtkActor* XLabelActor = vtkActor::New();
-
- vtkPolyDataMapper* text1Mapper = vtkPolyDataMapper::New();
- text1Mapper->SetInput(XLabel->GetOutput());
+void VTKViewer_ViewFrame::InitialSetup() {
+ m_RW = new VTKViewer_RenderWindow(this, "RenderWindow");
+ m_RW->getRenderWindow()->AddRenderer(m_Renderer);
- XLabelActor->SetMapper(text1Mapper);
- XLabelActor->SetScale(1,1,1);
+ m_Renderer->GetActiveCamera()->ParallelProjectionOn();
+ m_Renderer->LightFollowCameraOn();
+ m_Renderer->TwoSidedLightingOn();
- return XLabelActor;
-}
+ // Set BackgroundColor
+ QString BgrColorRed = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorRed");
+ QString BgrColorGreen = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorGreen");
+ QString BgrColorBlue = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorBlue");
-void VTKViewer_ViewFrame::AddVector(float* o,float* p,vtkRenderer* renderer) {
+ if( !BgrColorRed.isEmpty() && !BgrColorGreen.isEmpty() && !BgrColorBlue.isEmpty() )
+ m_Renderer->SetBackground( BgrColorRed.toInt()/255., BgrColorGreen.toInt()/255., BgrColorBlue.toInt()/255. );
+ else
+ m_Renderer->SetBackground( 0, 0, 0 );
- // Create line
-
- vtkPoints* myPoints = vtkPoints::New();
- vtkLine* myLine = vtkLine::New();
-
- myPoints->InsertNextPoint(o);
- myPoints->InsertNextPoint(p);
+ // Create an interactor.
+ m_RWInteractor = VTKViewer_RenderWindowInteractor::New();
+ m_RWInteractor->SetRenderWindow(m_RW->getRenderWindow());
- (myLine->GetPointIds())->InsertNextId(0);
- (myLine->GetPointIds())->InsertNextId(1);
+ VTKViewer_InteractorStyleSALOME* RWS = VTKViewer_InteractorStyleSALOME::New();
+ m_RWInteractor->SetInteractorStyle(RWS);
+ RWS->Delete();
- vtkActor* lineActor = vtkActor::New();
+ m_RWInteractor->setGUIWindow(m_RW);
+ RWS->setGUIWindow(m_RW);
- vtkCellArray* cell = vtkCellArray::New();
+ m_RWInteractor->Initialize();
+ m_RWInteractor->setViewFrame(this);
- cell->InsertNextCell(myLine);
+ RWS->setViewFrame(this);
+ //SRN: additional initialization, to init CurrentRenderer of vtkInteractorStyle
+ RWS->FindPokedRenderer(0, 0);
- vtkPolyData* output = vtkPolyData::New();
+ vtkTextProperty* tprop = vtkTextProperty::New();
+ tprop->SetColor(1, 1, 1);
+ tprop->ShadowOn();
- output->SetPoints(myPoints);
- output->SetLines(cell);
-
- vtkPolyDataMapper* mapper = vtkPolyDataMapper::New();
-
- mapper->SetInput(output);
-
- lineActor->SetMapper(mapper);
-
- // Create CONE
-
- vtkConeSource* acone = vtkConeSource::New();
-
- float dim;
- QString Size = QAD_CONFIG->getSetting("Viewer:TrihedronSize");
- if( Size.isEmpty() ) {
- dim = 100;
- } else {
- dim = Size.toFloat();
- }
-
- acone->SetResolution(2);
- // acone->SetAngle(70);
- acone->SetRadius(0.02*dim);
- acone->SetHeight(0.08*dim);
-
- vtkActor* coneActor = vtkActor::New();
-
- vtkPolyDataMapper* coneMapper = vtkPolyDataMapper::New();
- coneMapper->SetInput(acone->GetOutput());
-
- coneActor->SetMapper(coneMapper);
- float rot[3];
- rot[0]=0; rot[1]=0; rot[2]=0;
-
- if(p[0]!=0) {
- // x
- coneActor->AddPosition(p);
- }
- else {
- if(p[1]!=0) {
- // y
- coneActor->AddPosition(p);
- rot[2]=90;
- coneActor->AddOrientation(rot);
- }
- else {
- if(p[2]!=0) {
- // z
- coneActor->AddPosition(p);
- rot[1]=-90;
- coneActor->AddOrientation(rot);
- }
- }
- }
-
- // Create 2d TEXT
-
- coneActor->GetProperty()->SetInterpolation(1);
- coneActor->GetProperty()->SetRepresentationToSurface();
- coneActor->GetProperty()->SetAmbient(1);
- coneActor->GetProperty()->SetAmbientColor(1,1,1);
- coneActor->GetProperty()->SetDiffuseColor(0.7,0.7,0.7);
- coneActor->GetProperty()->SetSpecularColor(0.7,0.7,0.7);
-
- lineActor->GetProperty()->SetInterpolation(1);
- lineActor->GetProperty()->SetRepresentationToSurface();
- lineActor->GetProperty()->SetAmbient(1);
- lineActor->GetProperty()->SetAmbientColor(1,1,1);
- lineActor->GetProperty()->SetDiffuseColor(0.7,0.7,0.7);
- lineActor->GetProperty()->SetSpecularColor(0.7,0.7,0.7);
-
- coneActor->PickableOff();
- lineActor->PickableOff();
+ float bnd[6];
+ bnd[0] = bnd[2] = bnd[4] = 0;
+ bnd[1] = bnd[3] = bnd[5] = m_Triedron->GetSize();
+ m_CubeAxes->SetLabelFormat("%6.4g");
+ m_CubeAxes->SetBounds(bnd);
+ m_CubeAxes->SetCamera(m_Renderer->GetActiveCamera());
+ m_CubeAxes->SetLabelFormat("%6.4g");
+ m_CubeAxes->SetFlyModeToOuterEdges(); // ENK remarks: it must bee
+ m_CubeAxes->SetFontFactor(0.8);
+ m_CubeAxes->SetAxisTitleTextProperty(tprop);
+ m_CubeAxes->SetAxisLabelTextProperty(tprop);
+ m_CubeAxes->SetCornerOffset(0.0);
+ m_CubeAxes->SetScaling(0);
+ m_CubeAxes->SetNumberOfLabels(5);
+ tprop->Delete();
- m_Triedron->AddItem(coneActor);
- m_Triedron->AddItem(lineActor);
-
- renderer->AddActor(coneActor);
- renderer->AddActor(lineActor);
-}
-
-bool VTKViewer_ViewFrame::isTrihedronDisplayed()
-{
- m_Triedron->InitTraversal();
- vtkActor *ac = m_Triedron->GetNextActor();
- while(!(ac==NULL)) {
- if(ac->GetVisibility()) return true;
- ac = m_Triedron->GetNextActor();
- }
- return false;
-}
-
-void VTKViewer_ViewFrame::SetTrihedronSize(int size)
-{
- m_Triedron->InitTraversal();
- vtkActor* anActor = m_Triedron->GetNextActor();
- while(!(anActor==NULL)) {
- m_Renderer->RemoveActor( anActor );
- anActor = m_Triedron->GetNextActor();
- }
-
- m_Triedron->RemoveAllItems();
- AddAxis(m_Renderer);
- m_RW->updateGL();
+ setCentralWidget( m_RW );
+ onViewReset();
}
-
-void VTKViewer_ViewFrame::AddAxis(vtkRenderer* renderer) {
+VTKViewer_ViewFrame::~VTKViewer_ViewFrame() {
+ // In order to ensure that the interactor unregisters
+ // this RenderWindow, we assign a NULL RenderWindow to
+ // it before deleting it.
+ m_RWInteractor->SetRenderWindow(NULL) ;
+ m_RWInteractor->Delete() ;
- float origine[3];
- float X[3];
- float Y[3];
- float Z[3];
- float dim;
-
- QString Size = QAD_CONFIG->getSetting("Viewer:TrihedronSize");
- if( Size.isEmpty() ){
- dim = 100;
- } else {
- dim = Size.toFloat();
- }
-
- origine[0]=0; origine[1]=0; origine[2]=0;
- X[0]=origine[0]+dim; X[1]=origine[0]; X[2]=origine[0];
- Y[0]=origine[0]; Y[1]=origine[0]+dim; Y[2]=origine[0];
- Z[0]=origine[0]; Z[1]=origine[0]; Z[2]=origine[0]+dim;
-
- AddVector(origine,X,renderer);
- AddVector(origine,Y,renderer);
- AddVector(origine,Z,renderer);
-
+ m_Transform->Delete() ;
+ //m_RW->Delete() ;
+ m_Renderer->RemoveAllProps();
+ // NRI : BugID 1137: m_Renderer->Delete() ;
+ m_Triedron->Delete();
+
+ m_CubeAxes->Delete();
+ INFOS("VTKViewer_ViewFrame::~VTKViewer_ViewFrame()");
}
/*!
Returns widget containing 3D-Viewer
*/
-QWidget* VTKViewer_ViewFrame::getViewWidget()
-{
- return (QWidget*)getRW();
+QWidget* VTKViewer_ViewFrame::getViewWidget(){
+ return m_RW;
}
-
-void VTKViewer_ViewFrame::setRW(VTKViewer_RenderWindow* rw) {
- m_RW = rw;
+bool VTKViewer_ViewFrame::isTrihedronDisplayed(){
+ return m_Triedron->GetVisibility() == VTKViewer_Trihedron::eOn;
}
+bool VTKViewer_ViewFrame::isCubeAxesDisplayed(){
+ return m_CubeAxes->GetVisibility() == 1;
+}
-void VTKViewer_ViewFrame::InitialSetup() {
- //
- // Create a render window.
- //
- m_RW = new VTKViewer_RenderWindow(this,"");
- //
- // Create a renderer for this widget.
- //
- m_Renderer = vtkRenderer::New() ;
- m_RW->AddRenderer(m_Renderer) ;
-
-
- vtkCamera* camera = vtkCamera::New();
- camera->SetPosition(1,-1,1);
- camera->SetParallelProjection(true);
- camera->SetRoll(-60);
-
- // CREATE AXIS
- m_Triedron = vtkActorCollection::New();
- AddAxis(m_Renderer);
-
- // Set BackgroundColor
- QString BackgroundColorRed = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorRed");
- QString BackgroundColorGreen = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorGreen");
- QString BackgroundColorBlue = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorBlue");
+double VTKViewer_ViewFrame::GetTrihedronSize() const
+{
+ return m_Triedron->GetSize();
+}
- if( !BackgroundColorRed.isEmpty() && !BackgroundColorGreen.isEmpty() && !BackgroundColorBlue.isEmpty() )
- m_Renderer->SetBackground( BackgroundColorRed.toInt()/255., BackgroundColorGreen.toInt()/255., BackgroundColorBlue.toInt()/255. );
- else
- m_Renderer->SetBackground( 0, 0 , 0 );
+void VTKViewer_ViewFrame::AdjustTrihedrons(const bool forced)
+{
+
+ if ( (!isCubeAxesDisplayed() || !isTrihedronDisplayed()) && forced)
+ return;
- //
- // Create an interactor.
- //
- m_RWInteractor = VTKViewer_RenderWindowInteractor::New() ;
- m_RWInteractor->SetRenderWindow(m_RW) ;
- //
- // :TRICKY: Tue May 2 19:29:36 2000 Pagey
- // The order of the next two statements is very
- // important. The interactor must be initialized
- // before rendering.
- //
- m_RWInteractor->Initialize();
- m_Renderer->Render() ;
- m_Renderer->SetActiveCamera(camera);
- m_Renderer->ResetCamera();
- camera->Zoom(0.3);
- VTKViewer_InteractorStyleSALOME* RWS = dynamic_cast<VTKViewer_InteractorStyleSALOME*>(getRWInteractor()->GetInteractorStyle());
- if (RWS) {
- RWS->setTriedron( m_Triedron );
- //SRN: additional initialization, to init CurrentRenderer of vtkInteractorStyle
- RWS->FindPokedRenderer(0, 0);
+ float bnd[ 6 ];
+ float newbnd[6];
+ newbnd[ 0 ] = newbnd[ 2 ] = newbnd[ 4 ] = VTK_LARGE_FLOAT;
+ newbnd[ 1 ] = newbnd[ 3 ] = newbnd[ 5 ] = -VTK_LARGE_FLOAT;
+
+ m_CubeAxes->GetBounds(bnd);
+ if(MYDEBUG)
+ cout << "Bounds: BEFORE\n"
+ << "\txMin=" << bnd[ 0 ] << " xMax=" << bnd[ 1 ] << "\n"
+ << "\tyMin=" << bnd[ 2 ] << " yMax=" << bnd[ 3 ] << "\n"
+ << "\tzMin=" << bnd[ 4 ] << " zMax=" << bnd[ 5 ] << "\n";
+
+ int aVisibleNum = m_Triedron->GetVisibleActorCount( m_Renderer );
+ if ( aVisibleNum )
+ {
+ // if the new trihedron size have sufficient difference, then apply the value
+ double aNewSize = 100, anOldSize=m_Triedron->GetSize();
+ bool aTDisplayed = isTrihedronDisplayed();
+ bool aCDisplayed = isCubeAxesDisplayed();
+ if(aTDisplayed) m_Triedron->VisibilityOff();
+ if(aCDisplayed) m_CubeAxes->VisibilityOff();
+ static float aSizeInPercents = 105;
+ QString aSetting = QAD_CONFIG->getSetting( "Viewer:TrihedronSize" );
+ if ( !aSetting.isEmpty() )
+ aSizeInPercents = aSetting.toFloat();
+ bool isComputeTrihedronSize = ::ComputeTrihedronSize(m_Renderer, aNewSize, anOldSize, aSizeInPercents);
+ if(aTDisplayed) m_Triedron->VisibilityOn();
+ if(aCDisplayed) m_CubeAxes->VisibilityOn();
+
+ if ( isComputeTrihedronSize )
+ {
+ m_Triedron->SetSize( aNewSize );
+ // itearte throuh displayed objects and set size if necessary
+
+ vtkActorCollection* anActors = getRenderer()->GetActors();
+ anActors->InitTraversal();
+ while( vtkActor* anActor = anActors->GetNextActor() )
+ {
+ if( SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast( anActor ) )
+ {
+ if ( aSActor->IsResizable() )
+ aSActor->SetSize( 0.5 * aNewSize );
+ if( aSActor->GetVisibility()){
+ float abounds[6];
+ aSActor->GetBounds(abounds);
+ if(MYDEBUG)
+ cout << "Bounds: Actor="<<aSActor<<"\n"
+ << "\txMin=" << abounds[ 0 ] << " xMax=" << abounds[ 1 ] << "\n"
+ << "\tyMin=" << abounds[ 2 ] << " yMax=" << abounds[ 3 ] << "\n"
+ << "\tzMin=" << abounds[ 4 ] << " zMax=" << abounds[ 5 ] << "\n";
+ if ( abounds[0] > -VTK_LARGE_FLOAT && abounds[1] < VTK_LARGE_FLOAT &&
+ abounds[2] > -VTK_LARGE_FLOAT && abounds[3] < VTK_LARGE_FLOAT &&
+ abounds[4] > -VTK_LARGE_FLOAT && abounds[5] < VTK_LARGE_FLOAT)
+ for(int i=0;i<5;i=i+2){
+ if(abounds[i]<newbnd[i]) newbnd[i]=abounds[i];
+ if(abounds[i+1]>newbnd[i+1]) newbnd[i+1]=abounds[i+1];
+
+ }
+ }
+ }
+ }
+ }
}
+ if( newbnd[0]<VTK_LARGE_FLOAT && newbnd[2]<VTK_LARGE_FLOAT && newbnd[4]<VTK_LARGE_FLOAT &&
+ newbnd[1]>-VTK_LARGE_FLOAT && newbnd[3]>-VTK_LARGE_FLOAT && newbnd[5]>-VTK_LARGE_FLOAT){
+ for(int i=0;i<6;i++) bnd[i] = newbnd[i];
+ m_CubeAxes->SetBounds(bnd);
+ }
+ if(MYDEBUG)
+ cout << "Bounds AFTER: VisibleActors="<<aVisibleNum<<"\n"
+ << "\txMin=" << bnd[ 0 ] << " xMax=" << bnd[ 1 ] << "\n"
+ << "\tyMin=" << bnd[ 2 ] << " yMax=" << bnd[ 3 ] << "\n"
+ << "\tzMin=" << bnd[ 4 ] << " zMax=" << bnd[ 5 ] << "\n";
+
+ m_CubeAxes->SetBounds(bnd);
- m_RW->updateGL() ;
-
- setCentralWidget( m_RW );
+ ::ResetCameraClippingRange(m_Renderer);
}
-VTKViewer_ViewFrame::~VTKViewer_ViewFrame() {
- //
- // In order to ensure that the interactor unregisters
- // this RenderWindow, we assign a NULL RenderWindow to
- // it before deleting it.
- //
- if ( m_NonIsometricTransform )
- m_NonIsometricTransform->Delete() ;
-
- m_RWInteractor->SetRenderWindow(NULL) ;
- m_RWInteractor->Delete() ;
-
- m_RW->Delete() ;
-
- // NRI : BugID 1137.
- // m_Renderer->Delete() ;
+void VTKViewer_ViewFrame::onAdjustTrihedron()
+{
+ AdjustTrihedrons(false);
}
+void VTKViewer_ViewFrame::onAdjustCubeAxes()
+{
+ AdjustTrihedrons(false);
+}
/*!
Display/hide Trihedron
*/
-void VTKViewer_ViewFrame::onViewTrihedron()
-{
- if (isTrihedronDisplayed()) {
- m_Triedron->InitTraversal();
- vtkActor *ac = m_Triedron->GetNextActor();
- while(!(ac==NULL)) {
- ac->VisibilityOff();
- ac = m_Triedron->GetNextActor();
- }
- }
- else {
- m_Triedron->InitTraversal();
- vtkActor *ac = m_Triedron->GetNextActor();
- while(!(ac==NULL)) {
- ac->VisibilityOn();
- ac = m_Triedron->GetNextActor();
- }
- m_TriedronVisible = true;
- }
- m_RW->updateGL();
+void VTKViewer_ViewFrame::onViewTrihedron(){
+ onViewCubeAxes();
+ if(!m_Triedron) return;
+ if(isTrihedronDisplayed()) m_Triedron->VisibilityOff();
+ else m_Triedron->VisibilityOn();
+ Repaint();
}
+void VTKViewer_ViewFrame::onViewCubeAxes(){
+ if(!m_CubeAxes) return;
+ if(isCubeAxesDisplayed()) m_CubeAxes->VisibilityOff();
+ else m_CubeAxes->VisibilityOn();
+ Repaint();
+}
+
+
/*!
Provides top projection of the active view
*/
-void VTKViewer_ViewFrame::onViewTop() {
- vtkCamera* camera = vtkCamera::New();
+void VTKViewer_ViewFrame::onViewTop(){
+ vtkCamera* camera = m_Renderer->GetActiveCamera();
camera->SetPosition(0,0,1);
- camera->SetParallelProjection(true);
- m_Renderer->SetActiveCamera(camera);
-// m_Renderer->ResetCamera();
+ camera->SetViewUp(0,1,0);
+ camera->SetFocalPoint(0,0,0);
onViewFitAll();
-// m_RW->updateGL();
}
/*!
Provides bottom projection of the active view
*/
-void VTKViewer_ViewFrame::onViewBottom()
-{
- vtkCamera* camera = vtkCamera::New();
+void VTKViewer_ViewFrame::onViewBottom(){
+ vtkCamera* camera = m_Renderer->GetActiveCamera();
camera->SetPosition(0,0,-1);
- camera->SetParallelProjection(true);
- m_Renderer->SetActiveCamera(camera);
-// m_Renderer->ResetCamera();
+ camera->SetViewUp(0,1,0);
+ camera->SetFocalPoint(0,0,0);
onViewFitAll();
-// m_RW->updateGL();
}
/*!
Provides left projection of the active view
*/
-void VTKViewer_ViewFrame::onViewLeft()
-{
- vtkCamera* camera = vtkCamera::New();
- camera->SetPosition(0,1,0);
- camera->SetParallelProjection(true);
- m_Renderer->SetActiveCamera(camera);
-// m_Renderer->ResetCamera();
+void VTKViewer_ViewFrame::onViewLeft(){
+ vtkCamera* camera = m_Renderer->GetActiveCamera();
+ camera->SetPosition(0,-1,0);
+ camera->SetViewUp(0,0,1);
+ camera->SetFocalPoint(0,0,0);
onViewFitAll();
-// m_RW->updateGL();
}
/*!
Provides right projection of the active view
*/
-void VTKViewer_ViewFrame::onViewRight()
-{
- vtkCamera* camera = vtkCamera::New();
- camera->SetPosition(0,-1,0);
- camera->SetParallelProjection(true);
- m_Renderer->SetActiveCamera(camera);
-// m_Renderer->ResetCamera();
+void VTKViewer_ViewFrame::onViewRight(){
+ vtkCamera* camera = m_Renderer->GetActiveCamera();
+ camera->SetPosition(0,1,0);
+ camera->SetViewUp(0,0,1);
+ camera->SetFocalPoint(0,0,0);
onViewFitAll();
-// m_RW->updateGL();
}
/*!
Provides back projection of the active view
*/
-void VTKViewer_ViewFrame::onViewBack()
-{
- vtkCamera* camera = vtkCamera::New();
+void VTKViewer_ViewFrame::onViewBack(){
+ vtkCamera* camera = m_Renderer->GetActiveCamera();
camera->SetPosition(-1,0,0);
- camera->SetParallelProjection(true);
- m_Renderer->SetActiveCamera(camera);
-// m_Renderer->ResetCamera();
+ camera->SetViewUp(0,0,1);
+ camera->SetFocalPoint(0,0,0);
onViewFitAll();
-// m_RW->updateGL();
}
/*!
Provides front projection of the active view
*/
-void VTKViewer_ViewFrame::onViewFront()
-{
- vtkCamera* camera = vtkCamera::New();
+void VTKViewer_ViewFrame::onViewFront(){
+ vtkCamera* camera = m_Renderer->GetActiveCamera();
camera->SetPosition(1,0,0);
- camera->SetParallelProjection(true);
- m_Renderer->SetActiveCamera(camera);
-// m_Renderer->ResetCamera();
+ camera->SetViewUp(0,0,1);
+ camera->SetFocalPoint(0,0,0);
onViewFitAll();
-// m_RW->updateGL();
+}
+
+/*!
+ Fits all objects in the active view
+*/
+void VTKViewer_ViewFrame::onViewFitAll(){
+
+ int aTriedronWasVisible = false;
+ int aCubeAxesWasVisible = false;
+ if(m_Triedron){
+ aTriedronWasVisible = isTrihedronDisplayed();
+ if(aTriedronWasVisible) m_Triedron->VisibilityOff();
+ }
+ if(m_CubeAxes){
+ aCubeAxesWasVisible = isCubeAxesDisplayed();
+ if(aCubeAxesWasVisible) m_CubeAxes->VisibilityOff();
+ }
+
+ if(m_Triedron->GetVisibleActorCount(m_Renderer)){
+ m_Triedron->VisibilityOff();
+ m_CubeAxes->VisibilityOff();
+ ::ResetCamera(m_Renderer);
+ }else{
+ m_Triedron->SetVisibility(VTKViewer_Trihedron::eOnlyLineOn);
+ m_CubeAxes->SetVisibility(2);
+ ::ResetCamera(m_Renderer,true);
+ }
+ if(aTriedronWasVisible) m_Triedron->VisibilityOn();
+ else m_Triedron->VisibilityOff();
+ if(aCubeAxesWasVisible) m_CubeAxes->VisibilityOn();
+ else m_CubeAxes->VisibilityOff();
+ ::ResetCameraClippingRange(m_Renderer);
+
+ Repaint();
}
/*!
Reset the active view
*/
-void VTKViewer_ViewFrame::onViewReset()
-{
- vtkCamera* camera = vtkCamera::New();
- camera->SetPosition(1,-1,1);
- camera->SetParallelProjection(true);
- camera->SetRoll(-60);
- m_Renderer->SetActiveCamera(camera);
- m_Renderer->ResetCamera();
- m_Renderer->ResetCameraClippingRange();
- camera->Zoom(0.3);
- m_RW->updateGL();
+void VTKViewer_ViewFrame::onViewReset(){
+ int aTriedronIsVisible = isTrihedronDisplayed();
+ int aCubeAxesIsVisible = isCubeAxesDisplayed();
+
+ m_Triedron->SetVisibility(VTKViewer_Trihedron::eOnlyLineOn);
+ m_CubeAxes->SetVisibility(0);
+
+ ::ResetCamera(m_Renderer,true);
+ vtkCamera* aCamera = m_Renderer->GetActiveCamera();
+ aCamera->SetPosition(1,-1,1);
+ aCamera->SetViewUp(0,0,1);
+ ::ResetCamera(m_Renderer,true);
+
+ if(aTriedronIsVisible) m_Triedron->VisibilityOn();
+ else m_Triedron->VisibilityOff();
+
+ if(aCubeAxesIsVisible) m_CubeAxes->VisibilityOn();
+ else m_CubeAxes->VisibilityOff();
+
+ static float aCoeff = 3.0;
+ aCamera->SetParallelScale(aCoeff*aCamera->GetParallelScale());
+ Repaint();
}
/*!
Rotates the active view
*/
-void VTKViewer_ViewFrame::onViewRotate()
-{
- VTKViewer_InteractorStyleSALOME* RWS = dynamic_cast<VTKViewer_InteractorStyleSALOME*>(getRWInteractor()->GetInteractorStyle());
- if (RWS)
- RWS->startRotate();
+void VTKViewer_ViewFrame::onViewRotate(){
+ m_RWInteractor->GetInteractorStyleSALOME()->startRotate();
}
/*!
Sets a new center of the active view
*/
-void VTKViewer_ViewFrame::onViewGlobalPan()
-{
- VTKViewer_InteractorStyleSALOME* RWS = dynamic_cast<VTKViewer_InteractorStyleSALOME*>(getRWInteractor()->GetInteractorStyle());
- if (RWS)
- RWS->startGlobalPan();
+void VTKViewer_ViewFrame::onViewGlobalPan(){
+ if(m_Triedron->GetVisibleActorCount(m_Renderer))
+ m_RWInteractor->GetInteractorStyleSALOME()->startGlobalPan();
}
/*!
Zooms the active view
*/
-void VTKViewer_ViewFrame::onViewZoom()
-{
- VTKViewer_InteractorStyleSALOME* RWS = dynamic_cast<VTKViewer_InteractorStyleSALOME*>(getRWInteractor()->GetInteractorStyle());
- if (RWS)
- RWS->startZoom();
+void VTKViewer_ViewFrame::onViewZoom(){
+ m_RWInteractor->GetInteractorStyleSALOME()->startZoom();
}
/*!
Moves the active view
*/
-void VTKViewer_ViewFrame::onViewPan()
-{
- VTKViewer_InteractorStyleSALOME* RWS = dynamic_cast<VTKViewer_InteractorStyleSALOME*>(getRWInteractor()->GetInteractorStyle());
- if (RWS)
- RWS->startPan();
+void VTKViewer_ViewFrame::onViewPan(){
+ m_RWInteractor->GetInteractorStyleSALOME()->startPan();
}
/*!
Fits all obejcts within a rectangular area of the active view
*/
-void VTKViewer_ViewFrame::onViewFitArea()
-{
-
- VTKViewer_InteractorStyleSALOME* RWS = dynamic_cast<VTKViewer_InteractorStyleSALOME*>(getRWInteractor()->GetInteractorStyle());
- if (RWS)
- RWS->startFitArea();
-}
-
-/*!
- Fits all objects in the active view
-*/
-// Reset the camera clipping range to include this entire bounding box
-static void ResetCameraClippingRange(vtkRenderer* theRenderer, float bounds[6] )
-{
- //see vtkRenderer::ResetCameraClippingRange(float bounds[6]) method
- double vn[3], position[3], a, b, c, d;
- double range[2], dist;
- int i, j, k;
- float center[3];
- float distance;
- float width;
-
- vtkCamera* anActiveCamera = theRenderer->GetActiveCamera();
- if ( anActiveCamera == NULL )
- {
- //vtkErrorMacro(<< "Trying to reset clipping range of non-existant camera");
- return;
- }
-
- // Find the plane equation for the camera view plane
- anActiveCamera->GetViewPlaneNormal(vn);
- anActiveCamera->GetPosition(position);
-// a = -vn[0];
-// b = -vn[1];
-// c = -vn[2];
-// d = -(a*position[0] + b*position[1] + c*position[2]);
-
- // Set the max near clipping plane and the min far clipping plane
-// range[0] = a*bounds[0] + b*bounds[2] + c*bounds[4] + d;
-// range[1] = 1e-18;
-
- // Find the closest / farthest bounding box vertex
-// for ( k = 0; k < 2; k++ )
-// {
-// for ( j = 0; j < 2; j++ )
-// {
-// for ( i = 0; i < 2; i++ )
-// {
-// dist = a*bounds[i] + b*bounds[2+j] + c*bounds[4+k] + d;
-// range[0] = (dist<range[0])?(dist):(range[0]);
-// range[1] = (dist>range[1])?(dist):(range[1]);
-// }
-// }
-// }
-
- center[0] = (bounds[0] + bounds[1])/2.0;
- center[1] = (bounds[2] + bounds[3])/2.0;
- center[2] = (bounds[4] + bounds[5])/2.0;
- 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]));
- 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]));
- range[0] = distance - width/2.0;
- range[1] = distance + width/2.0;
-
- // Give ourselves a little breathing room
- range[0] = 0.99*range[0] - (range[1] - range[0])*0.5;
- range[1] = 1.01*range[1] + (range[1] - range[0])*0.5;
-
- // Make sure near is not bigger than far
- range[0] = (range[0] >= range[1])?(0.01*range[1]):(range[0]);
-
- // Make sure near is at least some fraction of far - this prevents near
- // from being behind the camera or too close in front. How close is too
- // close depends on the resolution of the depth buffer
- int ZBufferDepth = 16;
- vtkRenderWindow* aRenderWindow = theRenderer->GetRenderWindow();
- if (aRenderWindow)
- {
- ZBufferDepth = aRenderWindow->GetDepthBufferSize();
- }
- //
- if ( ZBufferDepth <= 16 )
- {
- range[0] = (range[0] < 0.01*range[1])?(0.01*range[1]):(range[0]);
- }
- else if ( ZBufferDepth <= 24 )
- {
- range[0] = (range[0] < 0.01*range[1])?(0.01*range[1]):(range[0]);
- }
- else
- {
- range[0] = (range[0] < 0.01*range[1])?(0.01*range[1]):(range[0]);
- }
- anActiveCamera->SetClippingRange( range );
-}
-
-static void ResetCamera(vtkRenderer* theRenderer){
- //see vtkRenderer::ResetCamera(float bounds[6]) method
- float bounds[6];
- if(!theRenderer) return;
- theRenderer->ComputeVisiblePropBounds( bounds );
-
- float center[3];
- float distance;
- float width;
- double vn[3], *vup;
-
- if ( theRenderer->GetActiveCamera() != NULL )
- {
- theRenderer->GetActiveCamera()->GetViewPlaneNormal(vn);
- }
- else
- {
- MESSAGE("Trying to reset non-existant camera");
- return;
- }
-
- center[0] = (bounds[0] + bounds[1])/2.0;
- center[1] = (bounds[2] + bounds[3])/2.0;
- center[2] = (bounds[4] + bounds[5])/2.0;
- 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();
- distance = 2.0*width/tan(ang*vtkMath::Pi()/360.0);
- // check view-up vector against view plane normal
- 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()->SetFocalPoint(center[0],center[1],center[2]);
- theRenderer->GetActiveCamera()->SetPosition(center[0]+distance*vn[0],
- center[1]+distance*vn[1],
- center[2]+distance*vn[2]);
- // setup default parallel scale
- theRenderer->GetActiveCamera()->SetParallelScale(width/2.0);
- //workaround on VTK
- //theRenderer->ResetCameraClippingRange(bounds);
- ResetCameraClippingRange(theRenderer,bounds);
-}
-
-void VTKViewer_ViewFrame::onViewFitAll()
-{
- Standard_Boolean TriedronWasVisible = false;
- if (isTrihedronDisplayed()) {
- m_Triedron->InitTraversal();
- vtkActor *ac = m_Triedron->GetNextActor();
- while(!(ac==NULL)) {
- ac->VisibilityOff();
- ac = m_Triedron->GetNextActor();
- }
- TriedronWasVisible = true;
- }
- bool hasVisibleActors = m_Renderer->VisibleActorCount() > 0;
- if ( hasVisibleActors ) // if there are visible actors, not to take into account Trihedron
- ResetCamera(m_Renderer);
- if(TriedronWasVisible) {
- m_Triedron->InitTraversal();
- vtkActor *ac = m_Triedron->GetNextActor();
- while(!(ac==NULL)) {
- ac->VisibilityOn();
- ac = m_Triedron->GetNextActor();
- }
- if ( !hasVisibleActors ) // if there are NO visible actors, fit view to see only Trihedron
- ResetCamera(m_Renderer);
- }
- //m_Renderer->ResetCameraClippingRange();
- m_RW->updateGL();
+void VTKViewer_ViewFrame::onViewFitArea(){
+ m_RWInteractor->GetInteractorStyleSALOME()->startFitArea();
}
/*!
}
-void VTKViewer_ViewFrame::SetSelectionMode( int mode )
+void VTKViewer_ViewFrame::SetSelectionMode( Selection_Mode mode )
{
m_RWInteractor->SetSelectionMode( mode );
}
{
QAD_Study* ActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
SALOME_Selection* Sel = SALOME_Selection::Selection( ActiveStudy->getSelection() );
-
- if ( Sel->SelectionMode() == 4 )
- m_RWInteractor->highlight(IObject, highlight, update);
- else if ( Sel->SelectionMode() == 3 ) {
- m_RWInteractor->highlight(IObject, highlight, update);
- if ( Sel->HasIndex( IObject ) ) {
- TColStd_MapOfInteger MapIndex;
- Sel->GetIndex( IObject, MapIndex );
- m_RWInteractor->highlightCell(IObject, highlight, MapIndex, update);
- }
- }
- else if ( Sel->SelectionMode() == 2 ) {
- m_RWInteractor->highlight(IObject, highlight, update);
- if ( Sel->HasIndex( IObject ) ) {
- TColStd_MapOfInteger MapIndex;
- Sel->GetIndex( IObject, MapIndex );
- m_RWInteractor->highlightEdge(IObject, highlight, MapIndex, update);
- }
- }
- else if ( Sel->SelectionMode() == 1 ) {
- m_RWInteractor->highlight(IObject, highlight, update);
- if ( Sel->HasIndex( IObject ) ) {
- TColStd_MapOfInteger MapIndex;
- Sel->GetIndex( IObject, MapIndex );
- m_RWInteractor->highlightPoint(IObject, highlight, MapIndex, update);
+ m_RWInteractor->highlight(IObject, highlight, update);
+
+ if(Sel->HasIndex(IObject) && IObject->hasEntry()){
+ TColStd_IndexedMapOfInteger MapIndex;
+ Sel->GetIndex(IObject,MapIndex);
+ using namespace SALOME::VTK;
+ const char* anEntry = IObject->getEntry();
+ vtkActorCollection* aCollection = getRenderer()->GetActors();
+ if(SALOME_Actor* anActor = Find<SALOME_Actor>(aCollection,TIsSameEntry<SALOME_Actor>(anEntry))){
+ switch (Sel->SelectionMode()) {
+ case NodeSelection:
+ m_RWInteractor->highlightPoint(MapIndex,anActor,highlight,update);
+ break;
+ case EdgeOfCellSelection:
+ m_RWInteractor->highlightEdge(MapIndex,anActor,highlight,update);
+ break;
+ case CellSelection:
+ case EdgeSelection:
+ case FaceSelection:
+ case VolumeSelection:
+ m_RWInteractor->highlightCell(MapIndex,anActor,highlight,update);
+ break;
+ }
}
+ }else{
+ m_RWInteractor->unHighlightSubSelection();
}
}
m_RW->setPopupServer( App );
}
-void VTKViewer_ViewFrame::undo(SALOMEDS::Study_var aStudy,
- const char* StudyFrameEntry)
+/* selection */
+Handle(SALOME_InteractiveObject) VTKViewer_ViewFrame::FindIObject(const char* theEntry)
{
- vtkActorCollection* theActors = m_Renderer->GetActors();
- theActors->InitTraversal();
- vtkActor *ac = theActors->GetNextActor();
- while(!(ac==NULL)) {
- if ( ac->IsA("SALOME_Actor") ) {
- SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
- if ( anActor->hasIO() ) {
- Handle(SALOME_InteractiveObject) IO = anActor->getIO();
- if ( IO->hasEntry() ) {
- if (!QAD_ViewFrame::isInViewer(aStudy, IO->getEntry(), StudyFrameEntry)) {
- m_RWInteractor->Erase(IO);
- }
- }
- }
- }
- ac = theActors->GetNextActor();
- }
+ using namespace SALOME::VTK;
+ SALOME_Actor* anActor =
+ Find<SALOME_Actor>(getRenderer()->GetActors(),
+ TIsSameEntry<SALOME_Actor>(theEntry));
+ if(anActor)
+ return anActor->getIO();
+
+ return Handle(SALOME_InteractiveObject)();
}
-void VTKViewer_ViewFrame::redo(SALOMEDS::Study_var aStudy,
- const char* StudyFrameEntry)
-{
- SALOMEDS::SObject_var RefSO;
- SALOMEDS::SObject_var SO = aStudy->FindObjectID( StudyFrameEntry );
- SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(SO);
- for (; it->More();it->Next()){
- SALOMEDS::SObject_var CSO= it->Value();
- if (CSO->ReferencedObject(RefSO)) {
- vtkActorCollection* theActors = m_Renderer->GetActors();
- theActors->InitTraversal();
- vtkActor *ac = theActors->GetNextActor();
- while(!(ac==NULL)) {
- if ( ac->IsA("SALOME_Actor") ) {
- SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
- if ( anActor->hasIO() ) {
- Handle(SALOME_InteractiveObject) IO = anActor->getIO();
- if ( IO->hasEntry() ) {
- if ( strcmp(IO->getEntry(),RefSO->GetID()) == 0 )
- m_RWInteractor->Display(IO);
- }
- }
- }
- ac = theActors->GetNextActor();
- }
- }
+/* display */
+void VTKViewer_ViewFrame::Display(const Handle(SALOME_InteractiveObject)& theIObject, bool update)
+{
+ QAD_Study* aQADStudy = QAD_Application::getDesktop()->getActiveStudy();
+ SALOME_Selection* aSel = SALOME_Selection::Selection( aQADStudy->getSelection() );
+ SALOMEDS::Study_var aStudy = aQADStudy->getStudyDocument();
+
+ m_RWInteractor->Display(theIObject,false);
+ ToolsGUI::SetVisibility( aStudy, theIObject->getEntry(), true, this );
+ aSel->AddIObject(theIObject,false);
+
+ if(update)
+ Repaint();
+}
+
+
+struct TDisplayAction{
+ SALOME_Selection* mySel;
+ Handle(SALOME_InteractiveObject) myIO;
+ TDisplayAction(SALOME_Selection* theSel,
+ Handle(SALOME_InteractiveObject) theIO):
+ mySel(theSel), myIO(theIO)
+ {}
+ void operator()(SALOME_Actor* theActor){
+ theActor->SetVisibility(true);
+ mySel->AddIObject(myIO,false);
}
+};
+
+void VTKViewer_ViewFrame::DisplayOnly(const Handle(SALOME_InteractiveObject)& theIObject)
+{
+ QAD_Study* aStudy = QAD_Application::getDesktop()->getActiveStudy();
+ SALOME_Selection* aSel = SALOME_Selection::Selection(aStudy->getSelection());
+
+ aSel->ClearIObjects();
+ //m_RWInteractor->EraseAll();
+ EraseAll();
+
+ using namespace SALOME::VTK;
+ ForEachIf<SALOME_Actor>(getRenderer()->GetActors(),
+ TIsSameIObject<SALOME_Actor>(theIObject),
+ TDisplayAction(aSel,theIObject));
+
+ ToolsGUI::SetVisibility(
+ aStudy->getStudyDocument(), theIObject->getEntry(), true, this );
+
+ Repaint();
}
-/* selection */
-Handle(SALOME_InteractiveObject) VTKViewer_ViewFrame::FindIObject(const char* Entry)
-{
- Handle(SALOME_InteractiveObject) IO;
- vtkActorCollection* theActors = m_Renderer->GetActors();
- theActors->InitTraversal();
- vtkActor *ac = theActors->GetNextActor();
- while(!(ac==NULL)) {
- if ( ac->IsA("SALOME_Actor") ) {
- SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
- if ( anActor->hasIO() ) {
- IO = anActor->getIO();
- if ( IO->hasEntry() ) {
- if ( strcmp( IO->getEntry(), Entry ) == 0 ) {
- return IO;
- }
- }
- }
- }
- ac = theActors->GetNextActor();
+struct TEraseAction: TDisplayAction{
+ VTKViewer_RenderWindowInteractor* myRWInteractor;
+ TEraseAction(SALOME_Selection* theSel,
+ Handle(SALOME_InteractiveObject) theIO,
+ VTKViewer_RenderWindowInteractor* theRWInteractor):
+ TDisplayAction(theSel,theIO),
+ myRWInteractor(theRWInteractor)
+ {}
+ void operator()(SALOME_Actor* theActor){
+ myRWInteractor->Erase(myIO,false);
+ mySel->RemoveIObject(myIO,false);
}
- return IO;
+};
+
+void VTKViewer_ViewFrame::Erase(const Handle(SALOME_InteractiveObject)& theIObject, bool update)
+{
+ QAD_Study* aStudy = QAD_Application::getDesktop()->getActiveStudy();
+ SALOME_Selection* aSel = SALOME_Selection::Selection(aStudy->getSelection());
+
+ using namespace SALOME::VTK;
+ ForEachIf<SALOME_Actor>(getRenderer()->GetActors(),
+ TIsSameIObject<SALOME_Actor>(theIObject),
+ TEraseAction(aSel,theIObject,m_RWInteractor));
+
+ ToolsGUI::SetVisibility(
+ aStudy->getStudyDocument(), theIObject->getEntry(), false, this );
+
+ if(update)
+ Repaint();
}
-/* display */
-void VTKViewer_ViewFrame::Display(const Handle(SALOME_InteractiveObject)& IObject, bool update)
+
+void VTKViewer_ViewFrame::DisplayAll()
{
- QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
- SALOME_Selection* Sel
- = SALOME_Selection::Selection( myStudy->getSelection() );
+ m_RWInteractor->DisplayAll();
- vtkActorCollection* theActors = m_Renderer->GetActors();
- theActors->InitTraversal();
- vtkActor *ac = theActors->GetNextActor();
- while(!(ac==NULL))
- {
- if ( ac->IsA("SALOME_Actor") )
- {
- SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
- if ( anActor->hasIO() )
- {
- Handle(SALOME_InteractiveObject) IO = anActor->getIO();
- if ( IO->isSame(IObject) )
- {
- m_RWInteractor->Display(IO, false);
- Sel->AddIObject(IO, false);
- break;
- }
- }
- }
- ac = theActors->GetNextActor();
- }
- if (update)
+ // update flag of visibility
+ QAD_Study* aQADStudy = QAD_Application::getDesktop()->getActiveStudy();
+ SALOMEDS::Study_var aStudy = aQADStudy->getStudyDocument();
+ QAD_Desktop* aDesktop = QAD_Application::getDesktop();
+ const QString& aCompName = aDesktop->getComponentDataType();
+ SALOMEDS::SObject_var aComponent =
+ SALOMEDS::SObject::_narrow( aStudy->FindComponent ( aCompName.latin1() ) );
+
+ std::list<SALOMEDS::SObject_var> aList;
+ SALOMEDS_Tool::GetAllChildren( aStudy, aComponent, aList );
+
+ std::list<SALOMEDS::SObject_var>::iterator anIter = aList.begin();
+ for ( ; anIter != aList.end(); ++anIter )
+ ToolsGUI::SetVisibility( aStudy, (*anIter)->GetID(), true, this );
+}
+
+
+void VTKViewer_ViewFrame::EraseAll()
+{
+ m_RWInteractor->EraseAll();
+
+ // update flag of visibility
+ QAD_Study* aQADStudy = QAD_Application::getDesktop()->getActiveStudy();
+ SALOMEDS::Study_var aStudy = aQADStudy->getStudyDocument();
+ QAD_Desktop* aDesktop = QAD_Application::getDesktop();
+ const QString& aCompName = aDesktop->getComponentDataType();
+ SALOMEDS::SObject_var aComponent =
+ SALOMEDS::SObject::_narrow( aStudy->FindComponent ( aCompName.latin1() ) );
+
+ std::list<SALOMEDS::SObject_var> aList;
+ SALOMEDS_Tool::GetAllChildren( aStudy, aComponent, aList );
+
+ std::list<SALOMEDS::SObject_var>::iterator anIter = aList.begin();
+ for ( ; anIter != aList.end(); ++anIter )
+ ToolsGUI::SetVisibility( aStudy, (*anIter)->GetID(), false, this );
+}
+
+
+void VTKViewer_ViewFrame::Repaint(bool theUpdateTrihedron)
+{
+ if (theUpdateTrihedron) onAdjustTrihedron();
+ //if (theUpdateCubeAxes) onAdjustCubeAxes();
+ m_RW->update();
+}
+
+void VTKViewer_ViewFrame::GetScale(double theScale[3]){
+ m_Transform->GetScale(theScale);
+}
+
+void VTKViewer_ViewFrame::SetScale(double theScale[3]){
+ m_Transform->SetScale(theScale[0], theScale[1], theScale[2]);
+ m_RWInteractor->Render();
+ Repaint();
+}
+
+void VTKViewer_ViewFrame::InsertActor( SALOME_Actor* theActor, bool theMoveInternalActors ){
+ theActor->AddToRender(m_Renderer);
+ theActor->SetTransform(m_Transform);
+ if(theMoveInternalActors)
+ m_RWInteractor->MoveInternalActors();
+}
+
+void VTKViewer_ViewFrame::AddActor( SALOME_Actor* theActor, bool theUpdate /*=false*/ ){
+ InsertActor(theActor);
+ if(theUpdate)
Repaint();
}
+void VTKViewer_ViewFrame::RemoveActor( SALOME_Actor* theActor, bool theUpdate /*=false*/ ){
+ theActor->RemoveFromRender(m_Renderer);
+ if(theUpdate)
+ Repaint();
+}
-void VTKViewer_ViewFrame::DisplayOnly(const Handle(SALOME_InteractiveObject)& IObject)
+void VTKViewer_ViewFrame::MoveActor(SALOME_Actor* theActor)
{
- QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
- SALOME_Selection* Sel
- = SALOME_Selection::Selection( myStudy->getSelection() );
+ RemoveActor(theActor);
+ InsertActor(theActor,true);
+}
+
+//==========================================================
+/*!
+ * VTKViewer_ViewFrame::Display
+ * Display presentation
+ */
+//==========================================================
+void VTKViewer_ViewFrame::Display( const SALOME_VTKPrs* prs )
+{
+ // try do downcast object
+ const VTKViewer_Prs* aVTKPrs = dynamic_cast<const VTKViewer_Prs*>( prs );
+ if ( !aVTKPrs || aVTKPrs->IsNull() )
+ return;
+
+ vtkActorCollection* actors = aVTKPrs->GetObjects();
+ if ( !actors )
+ return;
+
+ actors->InitTraversal();
+ vtkActor* actor;
+ while( ( actor = actors->GetNextActor() ) )
+ {
+ SALOME_Actor* salomeActor = SALOME_Actor::SafeDownCast( actor );
+ if ( salomeActor )
+ {
+ // just display the object
+ m_RWInteractor->Display( salomeActor, false );
+
+ // Set visibility flag
+ Handle(SALOME_InteractiveObject) anObj = salomeActor->getIO();
+ if ( !anObj.IsNull() && anObj->hasEntry() )
+ {
+ SALOMEDS::Study_var aStudy =
+ QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
+ ToolsGUI::SetVisibility( aStudy, anObj->getEntry(), true, this );
+ }
+
+ if ( salomeActor->IsSetCamera() )
+ salomeActor->SetCamera( getRenderer()->GetActiveCamera() );
+ }
+ }
+}
+
+//==========================================================
+/*!
+ * VTKViewer_ViewFrame::Erase
+ * Erase presentation
+ */
+//==========================================================
+void VTKViewer_ViewFrame::Erase( const SALOME_VTKPrs* prs, const bool forced )
+{
+ // try do downcast object
+ const VTKViewer_Prs* aVTKPrs = dynamic_cast<const VTKViewer_Prs*>( prs );
+ if ( !aVTKPrs || aVTKPrs->IsNull() )
+ return;
- vtkActorCollection* theActors = m_Renderer->GetActors();
- theActors->InitTraversal();
- vtkActor *ac = theActors->GetNextActor();
- while(!(ac==NULL)) {
- if ( ac->IsA("SALOME_Actor") ) {
+ vtkActorCollection* actors = aVTKPrs->GetObjects();
+ if ( !actors )
+ return;
+
+ SALOMEDS::Study_var aStudy =
+ QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
+
+ actors->InitTraversal();
+ vtkActor* actor;
+ while( ( actor = actors->GetNextActor() ) ) {
+ SALOME_Actor* salomeActor = SALOME_Actor::SafeDownCast( actor );
+ if ( salomeActor ) {
+ // just erase the object
+ if ( forced )
+ m_RWInteractor->Remove( salomeActor, false );
+ else
+ m_RWInteractor->Erase( salomeActor, forced );
+
+ // Set visibility flag if necessary
+ if ( !forced )
+ {
+ Handle(SALOME_InteractiveObject) anObj = salomeActor->getIO();
+ if ( !anObj.IsNull() && anObj->hasEntry() )
+ ToolsGUI::SetVisibility( aStudy, anObj->getEntry(), true, this );
+ }
+ }
+ }
+}
+
+//==========================================================
+/*!
+ * VTKViewer_ViewFrame::CreatePrs
+ * Create presentation by entry
+ */
+//==========================================================
+SALOME_Prs* VTKViewer_ViewFrame::CreatePrs( const char* entry )
+{
+ VTKViewer_Prs* prs = new VTKViewer_Prs();
+ if ( entry ) {
+ vtkActorCollection* theActors = m_Renderer->GetActors();
+ theActors->InitTraversal();
+ vtkActor* ac;
+ while( ( ac = theActors->GetNextActor() ) ) {
SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
- if ( anActor->hasIO() ) {
- Handle(SALOME_InteractiveObject) IO = anActor->getIO();
- if ( !IO->isSame(IObject) ) {
- m_RWInteractor->Erase(IO, false);
- Sel->RemoveIObject(IO, false);
- } else {
- anActor->SetVisibility(true);
- Sel->AddIObject(IO, false);
- }
+ if ( anActor && anActor->hasIO() && !strcmp( anActor->getIO()->getEntry(), entry ) ) {
+ prs->AddObject( ac );
}
}
- ac = theActors->GetNextActor();
}
- Repaint();
+ return prs;
+}
+
+//==========================================================
+/*!
+ * VTKViewer_ViewFrame::BeforeDisplay
+ * Axiluary method called before displaying of objects
+ */
+//==========================================================
+void VTKViewer_ViewFrame::BeforeDisplay( SALOME_Displayer* d )
+{
+ d->BeforeDisplay( this, SALOME_VTKViewType() );
+}
+
+//==========================================================
+/*!
+ * VTKViewer_ViewFrame::AfterDisplay
+ * Axiluary method called after displaying of objects
+ */
+//==========================================================
+void VTKViewer_ViewFrame::AfterDisplay( SALOME_Displayer* d )
+{
+ d->AfterDisplay( this, SALOME_VTKViewType() );
+}
+
+//==========================================================
+/*!
+ * VTKViewer_ViewFrame::undo
+ * Redisplay all objects in viewer
+ */
+//==========================================================
+void VTKViewer_ViewFrame::undo( QAD_Study* theQADStudy, const char* /*StudyFrameEntry*/ )
+{
+ redisplayAll( theQADStudy, true );
}
-void VTKViewer_ViewFrame::Erase(const Handle(SALOME_InteractiveObject)& IObject, bool update)
+//==========================================================
+/*!
+ * VTKViewer_ViewFrame::redo
+ * Redisplay all objects in viewer
+ */
+//==========================================================
+void VTKViewer_ViewFrame::redo( QAD_Study* theQADStudy, const char* /*StudyFrameEntry*/ )
{
- QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
- SALOME_Selection* Sel
- = SALOME_Selection::Selection( myStudy->getSelection() );
+ redisplayAll( theQADStudy, true );
+}
+
+//==========================================================
+/*!
+ * VTKViewer_ViewFrame::redisplayAll
+ * Redisplay all objects in viewer
+ */
+//==========================================================
+void VTKViewer_ViewFrame::redisplayAll( QAD_Study* theQADStudy, const bool theToUpdate )
+{
+ SALOMEDS::Study_var aStudy = theQADStudy->getStudyDocument();
+ SALOME_Selection* aSel = SALOME_Selection::Selection( theQADStudy->getSelection() );
+ QAD_Desktop* aDesktop = QAD_Application::getDesktop();
+ SALOMEGUI* aGUI = aDesktop->getActiveGUI();
+ const QString& aCompName = aDesktop->getComponentDataType();
+ SALOMEDS::SObject_var aComponent =
+ SALOMEDS::SObject::_narrow( aStudy->FindComponent ( aCompName.latin1() ) );
+
+ if ( aComponent->_is_nil() )
+ return;
+
+ m_RWInteractor->RemoveAll( false );
+ //m_RWInteractor->EraseAll();
+
+ aSel->ClearIObjects();
- vtkActorCollection* theActors = m_Renderer->GetActors();
- theActors->InitTraversal();
- vtkActor *ac = theActors->GetNextActor();
- while(!(ac==NULL))
+ /*
+ // ENK commented, already added to renderer in
+ // VTKViewer_ViewFrame::VTKViewer_ViewFrame(...)
+ if ( isTrhDisplayed )
+ m_Triedron->AddToRender( m_Renderer );
+ */
+
+ std::list<SALOMEDS::SObject_var> aList;
+ SALOMEDS_Tool::GetAllChildren( aStudy, aComponent, aList );
+
+ std::list<SALOMEDS::SObject_var>::iterator anIter = aList.begin();
+ for ( ; anIter != aList.end(); ++anIter )
+ {
+ SALOMEDS::SObject_var anObj = (*anIter);
+ if ( ToolsGUI::GetVisibility( aStudy, anObj, this ) )
{
- if ( ac->IsA("SALOME_Actor") )
- {
- SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
- if ( anActor->hasIO() )
- {
- Handle(SALOME_InteractiveObject) IO = anActor->getIO();
- if ( IO->isSame( IObject ) ) {
- m_RWInteractor->Erase(IO, false);
- Sel->RemoveIObject(IO, false);
- break;
- }
- }
- }
- ac = theActors->GetNextActor();
+ Handle(SALOME_InteractiveObject) anIObj = new SALOME_InteractiveObject();
+ anIObj->setEntry( anObj->GetID() );
+ aGUI->BuildPresentation( anIObj, this );
}
- if (update)
+
+ }
+
+ if ( theToUpdate )
Repaint();
}
+#define INCREMENT_FOR_OP 10
-void VTKViewer_ViewFrame::DisplayAll()
+//=======================================================================
+// name : onPanLeft
+// Purpose : Performs incremental panning to the left
+//=======================================================================
+void VTKViewer_ViewFrame::onPanLeft()
{
- m_RWInteractor->DisplayAll();
+ m_RWInteractor->GetInteractorStyleSALOME()->IncrementalPan( -INCREMENT_FOR_OP, 0 );
}
+//=======================================================================
+// name : onPanRight
+// Purpose : Performs incremental panning to the right
+//=======================================================================
+void VTKViewer_ViewFrame::onPanRight()
+{
+ m_RWInteractor->GetInteractorStyleSALOME()->IncrementalPan( INCREMENT_FOR_OP, 0 );
+}
-void VTKViewer_ViewFrame::EraseAll()
+//=======================================================================
+// name : onPanUp
+// Purpose : Performs incremental panning to the top
+//=======================================================================
+void VTKViewer_ViewFrame::onPanUp()
{
- m_RWInteractor->EraseAll();
+ m_RWInteractor->GetInteractorStyleSALOME()->IncrementalPan( 0, INCREMENT_FOR_OP );
}
+//=======================================================================
+// name : onPanDown
+// Purpose : Performs incremental panning to the bottom
+//=======================================================================
+void VTKViewer_ViewFrame::onPanDown()
+{
+ m_RWInteractor->GetInteractorStyleSALOME()->IncrementalPan( 0, -INCREMENT_FOR_OP );
+}
-void VTKViewer_ViewFrame::Repaint()
+//=======================================================================
+// name : onZoomIn
+// Purpose : Performs incremental zooming in
+//=======================================================================
+void VTKViewer_ViewFrame::onZoomIn()
{
- m_RWInteractor->Render();
- m_RW->updateGL();
+ m_RWInteractor->GetInteractorStyleSALOME()->IncrementalZoom( INCREMENT_FOR_OP );
}
-void VTKViewer_ViewFrame::AddActor( SALOME_Actor* theActor, bool update /*=false*/ )
+//=======================================================================
+// name : onZoomOut
+// Purpose : Performs incremental zooming out
+//=======================================================================
+void VTKViewer_ViewFrame::onZoomOut()
{
- m_Renderer->AddActor( theActor );
- if (m_NonIsometricTransform != NULL)
- {
- vtkPolyDataMapper* mapper = NULL;
- vtkMapper* initialMapper = theActor->GetInitialMapper();
- if ( initialMapper == NULL )
- initialMapper = theActor->GetMapper();
- if ( initialMapper->IsA("vtkDataSetMapper") )
- {
- mapper = vtkDataSetMapper::SafeDownCast( initialMapper )->GetPolyDataMapper ();
- if (!mapper)
- {
- initialMapper->Render(m_Renderer,theActor);
- mapper = vtkDataSetMapper::SafeDownCast( initialMapper )->GetPolyDataMapper ();
- }
- }
- else
- mapper = vtkPolyDataMapper::SafeDownCast( initialMapper );
- if (mapper)
- {
- //create Filter
- vtkTransformPolyDataFilter *aTransformFilter = vtkTransformPolyDataFilter::New();
- aTransformFilter->SetInput ( mapper->GetInput() );
- aTransformFilter->SetTransform (m_NonIsometricTransform);
-
- //create new mapper
- vtkPolyDataMapper *aMapper = vtkPolyDataMapper::New();
- aMapper->SetInput (aTransformFilter->GetOutput());
- aMapper->ShallowCopy ( theActor->GetMapper());
-
- //set new mapper
- theActor->SetMapper (aMapper);
-
- aTransformFilter->Delete();
- aMapper->Delete();
- }
- }
- theActor->SetVisibility( true );
-
- if (update)
- m_RWInteractor->Render();
+ m_RWInteractor->GetInteractorStyleSALOME()->IncrementalZoom( -INCREMENT_FOR_OP );
+}
+
+//=======================================================================
+// name : onRotateLeft
+// Purpose : Performs incremental rotating to the left
+//=======================================================================
+void VTKViewer_ViewFrame::onRotateLeft()
+{
+ m_RWInteractor->GetInteractorStyleSALOME()->IncrementalRotate( -INCREMENT_FOR_OP, 0 );
+}
+
+//=======================================================================
+// name : onRotateRight
+// Purpose : Performs incremental rotating to the right
+//=======================================================================
+void VTKViewer_ViewFrame::onRotateRight()
+{
+ m_RWInteractor->GetInteractorStyleSALOME()->IncrementalRotate( INCREMENT_FOR_OP, 0 );
+}
+
+//=======================================================================
+// name : onRotateUp
+// Purpose : Performs incremental rotating to the top
+//=======================================================================
+void VTKViewer_ViewFrame::onRotateUp()
+{
+ m_RWInteractor->GetInteractorStyleSALOME()->IncrementalRotate( 0, -INCREMENT_FOR_OP );
+}
+
+//=======================================================================
+// name : onRotateDown
+// Purpose : Performs incremental rotating to the bottom
+//=======================================================================
+void VTKViewer_ViewFrame::onRotateDown()
+{
+ m_RWInteractor->GetInteractorStyleSALOME()->IncrementalRotate( 0, INCREMENT_FOR_OP );
}