// $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_PassThroughFilter.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 "VTKViewer_InteractorStyleSALOME.h"
-#include "VTKViewer_VectorText.h"
+#include "ToolsGUI.h"
+#include "SALOMEDS_Tool.hxx"
#include "utilities.h"
// VTK Includes
#include <vtkActor.h>
+#include <vtkCamera.h>
#include <vtkRenderer.h>
-#include <vtkPolyDataMapper.h>
+#include <vtkTransform.h>
+#include <vtkActorCollection.h>
+#include <vtkTextProperty.h>
+
+#include <TColStd_IndexedMapOfInteger.hxx>
-#include <vtkMath.h>
-#include <vtkLine.h>
-#include <vtkConeSource.h>
-#include <vtkFollower.h>
+#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();
-}
-
-
-vtkFollower* CreateTextActor(char *text, float aSize) {
- VTKViewer_VectorText* aTxt = VTKViewer_VectorText::New();
- aTxt->SetText(text);
- vtkPolyDataMapper* textMapper = vtkPolyDataMapper::New();
- textMapper->SetInput(aTxt->GetOutput());
- vtkFollower* textActor = vtkFollower::New();
- textActor->SetMapper(textMapper);
- float aScale = 17 * aSize/100;
- textActor->SetScale(aScale, aScale, aScale);
- return textActor;
-}
-
-void VTKViewer_ViewFrame::AddVector(float* o,float* p,vtkRenderer* renderer, float aSize) {
- vtkPoints* myPoints = vtkPoints::New();
- vtkLine* myLine = vtkLine::New();
-
- myPoints->InsertNextPoint(o);
- myPoints->InsertNextPoint(p);
-
- (myLine->GetPointIds())->InsertNextId(0);
- (myLine->GetPointIds())->InsertNextId(1);
-
- vtkActor* lineActor = vtkActor::New();
-
- vtkCellArray* cell = vtkCellArray::New();
-
- cell->InsertNextCell(myLine);
-
- vtkPolyData* output = vtkPolyData::New();
-
- output->SetPoints(myPoints);
- output->SetLines(cell);
-
- vtkPolyDataMapper* mapper = vtkPolyDataMapper::New();
-
- mapper->SetInput(output);
-
- lineActor->SetMapper(mapper);
-
- // Create CONE
-
- vtkConeSource* acone = vtkConeSource::New();
-
- float dim = aSize;
-
- 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;
-
- vtkFollower* aTextActor;
-
- coneActor->AddPosition(p);
- if(p[0]!=0) {
- // x
- aTextActor = CreateTextActor("X", dim);
- } else if(p[1]!=0) {
- // y
- rot[2]=90;
- coneActor->AddOrientation(rot);
- aTextActor = CreateTextActor("Y", dim);
- } else if(p[2]!=0) {
- // z
- rot[1]=-90;
- coneActor->AddOrientation(rot);
- aTextActor = CreateTextActor("Z", dim);
- }
- aTextActor->AddPosition(p);
- aTextActor->SetCamera(renderer->GetActiveCamera());
-
- 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);
-
- aTextActor->GetProperty()->SetAmbient(1);
- aTextActor->GetProperty()->SetAmbientColor(1,1,1);
- aTextActor->GetProperty()->SetDiffuseColor(0.7,0.7,0.7);
- aTextActor->GetProperty()->SetSpecularColor(0.7,0.7,0.7);
-
- coneActor->PickableOff();
- lineActor->PickableOff();
- aTextActor->PickableOff();
-
- m_Triedron->AddItem(coneActor);
- m_Triedron->AddItem(lineActor);
- m_Triedron->AddItem(aTextActor);
-
- renderer->AddActor(coneActor);
- renderer->AddActor(lineActor);
- renderer->AddActor(aTextActor);
}
-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->update();
-}
-
-
-void VTKViewer_ViewFrame::AddAxis(vtkRenderer* renderer) {
- 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, dim);
- AddVector(origine,Y,renderer, dim);
- AddVector(origine,Z,renderer, dim);
-
-}
-
-/*!
- Returns widget containing 3D-Viewer
-*/
-QWidget* VTKViewer_ViewFrame::getViewWidget()
-{
- return m_RW;
-}
-
-
void VTKViewer_ViewFrame::InitialSetup() {
- m_Renderer = vtkRenderer::New() ;
-
m_RW = new VTKViewer_RenderWindow(this, "RenderWindow");
m_RW->getRenderWindow()->AddRenderer(m_Renderer);
m_Renderer->SetBackground( BgrColorRed.toInt()/255., BgrColorGreen.toInt()/255., BgrColorBlue.toInt()/255. );
else
m_Renderer->SetBackground( 0, 0, 0 );
-
- // CREATE AXIS
- m_Triedron = vtkActorCollection::New();
- AddAxis(m_Renderer);
-
+
// Create an interactor.
m_RWInteractor = VTKViewer_RenderWindowInteractor::New();
- m_RWInteractor->setGUIWindow(m_RW);
m_RWInteractor->SetRenderWindow(m_RW->getRenderWindow());
VTKViewer_InteractorStyleSALOME* RWS = VTKViewer_InteractorStyleSALOME::New();
- RWS->setGUIWindow(m_RW);
m_RWInteractor->SetInteractorStyle(RWS);
+ RWS->Delete();
+
+ m_RWInteractor->setGUIWindow(m_RW);
+ RWS->setGUIWindow(m_RW);
m_RWInteractor->Initialize();
- RWS->setTriedron( m_Triedron );
+ m_RWInteractor->setViewFrame(this);
+
+ RWS->setViewFrame(this);
//SRN: additional initialization, to init CurrentRenderer of vtkInteractorStyle
RWS->FindPokedRenderer(0, 0);
+ vtkTextProperty* tprop = vtkTextProperty::New();
+ tprop->SetColor(1, 1, 1);
+ tprop->ShadowOn();
+
+ 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();
+
setCentralWidget( m_RW );
onViewReset();
}
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_Transform->Delete() ;
-
m_RWInteractor->SetRenderWindow(NULL) ;
m_RWInteractor->Delete() ;
+ 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()");
+}
/*!
- Display/hide Trihedron
+ Returns widget containing 3D-Viewer
*/
-void VTKViewer_ViewFrame::onViewTrihedron()
-{
- if (isTrihedronDisplayed()) {
- m_Triedron->InitTraversal();
- vtkActor *ac = m_Triedron->GetNextActor();
- while(!(ac==NULL)) {
- ac->VisibilityOff();
- ac = m_Triedron->GetNextActor();
+QWidget* VTKViewer_ViewFrame::getViewWidget(){
+ return m_RW;
+}
+
+bool VTKViewer_ViewFrame::isTrihedronDisplayed(){
+ return m_Triedron->GetVisibility() == VTKViewer_Trihedron::eOn;
+}
+
+bool VTKViewer_ViewFrame::isCubeAxesDisplayed(){
+ return m_CubeAxes->GetVisibility() == 1;
+}
+
+double VTKViewer_ViewFrame::GetTrihedronSize() const
+{
+ return m_Triedron->GetSize();
+}
+
+void VTKViewer_ViewFrame::AdjustTrihedrons(const bool forced)
+{
+
+ if ( (!isCubeAxesDisplayed() || !isTrihedronDisplayed()) && forced)
+ return;
+
+ 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];
+
+ }
+ }
+ }
+ }
}
}
- else {
- m_Triedron->InitTraversal();
- vtkActor *ac = m_Triedron->GetNextActor();
- while(!(ac==NULL)) {
- ac->VisibilityOn();
- ac = m_Triedron->GetNextActor();
- }
- m_TriedronVisible = true;
- }
- m_RW->update();
+ 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);
+
+ ::ResetCameraClippingRange(m_Renderer);
+}
+
+void VTKViewer_ViewFrame::onAdjustTrihedron()
+{
+ AdjustTrihedrons(false);
+}
+
+void VTKViewer_ViewFrame::onAdjustCubeAxes()
+{
+ AdjustTrihedrons(false);
+}
+
+/*!
+ Display/hide Trihedron
+*/
+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() {
+void VTKViewer_ViewFrame::onViewTop(){
vtkCamera* camera = m_Renderer->GetActiveCamera();
- camera->SetFocalPoint(0,0,0);
camera->SetPosition(0,0,1);
camera->SetViewUp(0,1,0);
- m_Renderer->ResetCamera();
+ camera->SetFocalPoint(0,0,0);
onViewFitAll();
- m_RW->update();
}
/*!
Provides bottom projection of the active view
*/
-void VTKViewer_ViewFrame::onViewBottom()
-{
+void VTKViewer_ViewFrame::onViewBottom(){
vtkCamera* camera = m_Renderer->GetActiveCamera();
- camera->SetFocalPoint(0,0,0);
camera->SetPosition(0,0,-1);
camera->SetViewUp(0,1,0);
- m_Renderer->ResetCamera();
+ camera->SetFocalPoint(0,0,0);
onViewFitAll();
- m_RW->update();
}
/*!
Provides left projection of the active view
*/
-void VTKViewer_ViewFrame::onViewLeft()
-{
+void VTKViewer_ViewFrame::onViewLeft(){
vtkCamera* camera = m_Renderer->GetActiveCamera();
- camera->SetFocalPoint(0,0,0);
- camera->SetPosition(0,1,0);
+ camera->SetPosition(0,-1,0);
camera->SetViewUp(0,0,1);
- m_Renderer->ResetCamera();
+ camera->SetFocalPoint(0,0,0);
onViewFitAll();
- m_RW->update();
}
/*!
Provides right projection of the active view
*/
-void VTKViewer_ViewFrame::onViewRight()
-{
+void VTKViewer_ViewFrame::onViewRight(){
vtkCamera* camera = m_Renderer->GetActiveCamera();
- camera->SetFocalPoint(0,0,0);
- camera->SetPosition(0,-1,0);
+ camera->SetPosition(0,1,0);
camera->SetViewUp(0,0,1);
- m_Renderer->ResetCamera();
+ camera->SetFocalPoint(0,0,0);
onViewFitAll();
- m_RW->update();
}
/*!
Provides back projection of the active view
*/
-void VTKViewer_ViewFrame::onViewBack()
-{
+void VTKViewer_ViewFrame::onViewBack(){
vtkCamera* camera = m_Renderer->GetActiveCamera();
camera->SetPosition(-1,0,0);
- camera->SetFocalPoint(0,0,0);
camera->SetViewUp(0,0,1);
- m_Renderer->ResetCamera();
+ camera->SetFocalPoint(0,0,0);
onViewFitAll();
- m_RW->update();
}
/*!
Provides front projection of the active view
*/
-void VTKViewer_ViewFrame::onViewFront()
-{
+void VTKViewer_ViewFrame::onViewFront(){
vtkCamera* camera = m_Renderer->GetActiveCamera();
camera->SetPosition(1,0,0);
- camera->SetFocalPoint(0,0,0);
camera->SetViewUp(0,0,1);
- m_Renderer->ResetCamera();
+ camera->SetFocalPoint(0,0,0);
onViewFitAll();
- m_RW->update();
+}
+
+/*!
+ 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 = m_Renderer->GetActiveCamera();
- camera->SetPosition(1,-1,1);
- camera->SetFocalPoint(0,0,0);
- camera->SetViewUp(0,0,1);
- m_Renderer->ResetCamera();
+void VTKViewer_ViewFrame::onViewReset(){
+ int aTriedronIsVisible = isTrihedronDisplayed();
+ int aCubeAxesIsVisible = isCubeAxesDisplayed();
- double aOldScale = camera->GetParallelScale();
- camera->SetParallelScale(500);
- double aNewScale = camera->GetParallelScale();
+ m_Triedron->SetVisibility(VTKViewer_Trihedron::eOnlyLineOn);
+ m_CubeAxes->SetVisibility(0);
- //for controlling labels scale after reset
- float dim;
- QString Size = QAD_CONFIG->getSetting("Viewer:TrihedronSize");
- if( Size.isEmpty() ){
- dim = 100;
- } else {
- dim = Size.toFloat();
- }
- float aScale = 17 * dim/100;
-
- m_Triedron->InitTraversal();
- vtkActor *ac = m_Triedron->GetNextActor();
- bool IsConeActor = true;
- while(!(ac==NULL)) {
- if(ac->IsA("vtkFollower")) {
- ac->SetScale(aScale, aScale, aScale);
- IsConeActor = true;
- }
- else {
- if (IsConeActor) {
- //coneActor is the first in the list (see m_Triedron->AddItem(...) in VTKViewer_ViewFrame::AddVector(...))
- IsConeActor = false;
- }
- }
- ac = m_Triedron->GetNextActor();
- }
+ ::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();
- m_Renderer->ResetCameraClippingRange();
- m_RW->update();
+ 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, vtkActorCollection* theTriedron, VTKViewer_RenderWindowInteractor* theRWInteractor){
- //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;
- int* winsize;
-
- 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);
-
- // find size of the window
- winsize = theRenderer->GetSize();
-
- // 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
- double aOldScale = theRenderer->GetActiveCamera()->GetParallelScale();
-
- if(winsize[0]<winsize[1] )
- width=width*(float(winsize[1])/float(winsize[0]));
-
- theRenderer->GetActiveCamera()->SetParallelScale(width/2.0);
- double aNewScale = theRenderer->GetActiveCamera()->GetParallelScale();
-
- // for controlling label size
- VTKViewer_InteractorStyleSALOME* Style = 0;
- if (theRWInteractor->GetInteractorStyle()->IsA("VTKViewer_InteractorStyleSALOME")) {
- Style = VTKViewer_InteractorStyleSALOME::SafeDownCast(theRWInteractor->GetInteractorStyle());
- Style->ControlLblSize(aOldScale,aNewScale);
- }
-
- //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,m_Triedron,m_RWInteractor);
- }
- 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_Triedron,m_RWInteractor);
- }
- }
- //m_Renderer->ResetCameraClippingRange();
- m_RW->update();
+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();
}
-/* 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 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);
}
- return IO;
-}
+};
-/* display */
-void VTKViewer_ViewFrame::Display(const Handle(SALOME_InteractiveObject)& IObject, bool update)
+void VTKViewer_ViewFrame::DisplayOnly(const Handle(SALOME_InteractiveObject)& theIObject)
{
- QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
- SALOME_Selection* Sel
- = SALOME_Selection::Selection( myStudy->getSelection() );
+ QAD_Study* aStudy = QAD_Application::getDesktop()->getActiveStudy();
+ SALOME_Selection* aSel = SALOME_Selection::Selection(aStudy->getSelection());
- 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)
- Repaint();
-}
+ aSel->ClearIObjects();
+ //m_RWInteractor->EraseAll();
+ EraseAll();
+ using namespace SALOME::VTK;
+ ForEachIf<SALOME_Actor>(getRenderer()->GetActors(),
+ TIsSameIObject<SALOME_Actor>(theIObject),
+ TDisplayAction(aSel,theIObject));
-void VTKViewer_ViewFrame::DisplayOnly(const Handle(SALOME_InteractiveObject)& IObject)
-{
- QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
- SALOME_Selection* Sel
- = SALOME_Selection::Selection( myStudy->getSelection() );
+ ToolsGUI::SetVisibility(
+ aStudy->getStudyDocument(), theIObject->getEntry(), true, this );
- 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->Erase(IO, false);
- Sel->RemoveIObject(IO, false);
- } else {
- anActor->SetVisibility(true);
- Sel->AddIObject(IO, false);
- }
- }
- }
- ac = theActors->GetNextActor();
- }
Repaint();
}
-void VTKViewer_ViewFrame::Erase(const Handle(SALOME_InteractiveObject)& IObject, bool update)
+
+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);
+ }
+};
+
+void VTKViewer_ViewFrame::Erase(const Handle(SALOME_InteractiveObject)& theIObject, bool update)
{
- QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
- SALOME_Selection* Sel
- = SALOME_Selection::Selection( myStudy->getSelection() );
+ QAD_Study* aStudy = QAD_Application::getDesktop()->getActiveStudy();
+ SALOME_Selection* aSel = SALOME_Selection::Selection(aStudy->getSelection());
- 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->Erase(IO, false);
- Sel->RemoveIObject(IO, false);
- break;
- }
- }
- }
- ac = theActors->GetNextActor();
- }
- if (update)
+ 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();
}
void VTKViewer_ViewFrame::DisplayAll()
{
m_RWInteractor->DisplayAll();
+
+ // 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()
+void VTKViewer_ViewFrame::Repaint(bool theUpdateTrihedron)
{
- // m_RWInteractor->Render();
+ if (theUpdateTrihedron) onAdjustTrihedron();
+ //if (theUpdateCubeAxes) onAdjustCubeAxes();
m_RW->update();
}
void VTKViewer_ViewFrame::SetScale(double theScale[3]){
m_Transform->SetScale(theScale[0], theScale[1], theScale[2]);
- m_Transform->Modified();
- vtkActorCollection* theActors = m_Renderer->GetActors();
- theActors->InitTraversal();
- vtkActor *anActor;
- while(anActor = theActors->GetNextActor())
- anActor->GetMapper()->Update();
+ m_RWInteractor->Render();
Repaint();
}
-void VTKViewer_ViewFrame::AddActor( SALOME_Actor* theActor, bool update /*=false*/ ){
- theActor->SetVisibility(true);
+void VTKViewer_ViewFrame::InsertActor( SALOME_Actor* theActor, bool theMoveInternalActors ){
theActor->AddToRender(m_Renderer);
theActor->SetTransform(m_Transform);
- if(update){
- m_Renderer->ResetCameraClippingRange();
- m_RWInteractor->Render();
- }
+ if(theMoveInternalActors)
+ m_RWInteractor->MoveInternalActors();
}
-void VTKViewer_ViewFrame::RemoveActor( SALOME_Actor* theActor, bool update /*=false*/ ){
+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(update){
- m_Renderer->ResetCameraClippingRange();
- m_RWInteractor->Render();
+ if(theUpdate)
+ Repaint();
+}
+
+void VTKViewer_ViewFrame::MoveActor(SALOME_Actor* theActor)
+{
+ 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* 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 && anActor->hasIO() && !strcmp( anActor->getIO()->getEntry(), entry ) ) {
+ prs->AddObject( ac );
+ }
+ }
+ }
+ 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 );
+}
+
+//==========================================================
+/*!
+ * VTKViewer_ViewFrame::redo
+ * Redisplay all objects in viewer
+ */
+//==========================================================
+void VTKViewer_ViewFrame::redo( QAD_Study* theQADStudy, const char* /*StudyFrameEntry*/ )
+{
+ 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();
+
+ /*
+ // 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 ) )
+ {
+ Handle(SALOME_InteractiveObject) anIObj = new SALOME_InteractiveObject();
+ anIObj->setEntry( anObj->GetID() );
+ aGUI->BuildPresentation( anIObj, this );
+ }
+
}
+
+ if ( theToUpdate )
+ Repaint();
+}
+
+#define INCREMENT_FOR_OP 10
+
+//=======================================================================
+// name : onPanLeft
+// Purpose : Performs incremental panning to the left
+//=======================================================================
+void VTKViewer_ViewFrame::onPanLeft()
+{
+ 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 );
}
+//=======================================================================
+// name : onPanUp
+// Purpose : Performs incremental panning to the top
+//=======================================================================
+void VTKViewer_ViewFrame::onPanUp()
+{
+ 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 );
+}
+
+//=======================================================================
+// name : onZoomIn
+// Purpose : Performs incremental zooming in
+//=======================================================================
+void VTKViewer_ViewFrame::onZoomIn()
+{
+ m_RWInteractor->GetInteractorStyleSALOME()->IncrementalZoom( INCREMENT_FOR_OP );
+}
+
+//=======================================================================
+// name : onZoomOut
+// Purpose : Performs incremental zooming out
+//=======================================================================
+void VTKViewer_ViewFrame::onZoomOut()
+{
+ 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 );
+}