From 695d2df77f61c97759480ad6b55963aaa8b219df Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 10 Aug 2005 14:26:49 +0000 Subject: [PATCH] This commit was generated by cvs2git to create branch 'BR-D5-38-2003'. Cherrypick from master 2005-08-10 14:26:48 UTC ouv 'Fucntion createModule moved from VisuGUI.cxx to VisuGUI_Factory.cxx': src/PIPELINE/Makefile.in src/VISUGUI/VisuGUI_CursorDlg.cxx src/VISUGUI/VisuGUI_CursorDlg.h src/VISUGUI/VisuGUI_CutPlanesDlg.h src/VISUGUI/VisuGUI_EditContainerDlg.cxx src/VISUGUI/VisuGUI_EditContainerDlg.h src/VISUGUI/VisuGUI_Factory.cxx src/VISUGUI/VisuGUI_FileDlg.cxx src/VISUGUI/VisuGUI_FontWg.cxx src/VISUGUI/VisuGUI_Plot3DDlg.cxx src/VISUGUI/VisuGUI_Plot3DDlg.h src/VISUGUI/VisuGUI_ScalarBarDlg.cxx src/VISUGUI/VisuGUI_ScalarBarDlg.h src/VISUGUI/VisuGUI_Selection.cxx src/VISUGUI/VisuGUI_TimeAnimation.h src/VISUGUI/VisuGUI_Tools.cxx src/VISUGUI/VisuGUI_Tools.h src/VISU_I/VISUConfig.hh src/VISU_I/VISU_Gen_i.cc src/VISU_I/VISU_Result_i.cc src/VISU_I/VISU_Result_i.hh src/VISU_I/VISU_View_i.cc src/VISU_SWIG/visu_split_views.py --- src/PIPELINE/Makefile.in | 75 + src/VISUGUI/VisuGUI_CursorDlg.cxx | 109 ++ src/VISUGUI/VisuGUI_CursorDlg.h | 55 + src/VISUGUI/VisuGUI_CutPlanesDlg.h | 136 ++ src/VISUGUI/VisuGUI_EditContainerDlg.cxx | 429 +++++ src/VISUGUI/VisuGUI_EditContainerDlg.h | 63 + src/VISUGUI/VisuGUI_Factory.cxx | 40 + src/VISUGUI/VisuGUI_FileDlg.cxx | 111 ++ src/VISUGUI/VisuGUI_FontWg.cxx | 149 ++ src/VISUGUI/VisuGUI_Plot3DDlg.cxx | 566 +++++++ src/VISUGUI/VisuGUI_Plot3DDlg.h | 119 ++ src/VISUGUI/VisuGUI_ScalarBarDlg.cxx | 923 ++++++++++ src/VISUGUI/VisuGUI_ScalarBarDlg.h | 184 ++ src/VISUGUI/VisuGUI_Selection.cxx | 600 +++++++ src/VISUGUI/VisuGUI_TimeAnimation.h | 175 ++ src/VISUGUI/VisuGUI_Tools.cxx | 1190 +++++++++++++ src/VISUGUI/VisuGUI_Tools.h | 194 +++ src/VISU_I/VISUConfig.hh | 181 ++ src/VISU_I/VISU_Gen_i.cc | 979 +++++++++++ src/VISU_I/VISU_Result_i.cc | 858 ++++++++++ src/VISU_I/VISU_Result_i.hh | 132 ++ src/VISU_I/VISU_View_i.cc | 1963 ++++++++++++++++++++++ src/VISU_SWIG/visu_split_views.py | 129 ++ 23 files changed, 9360 insertions(+) create mode 100644 src/PIPELINE/Makefile.in create mode 100644 src/VISUGUI/VisuGUI_CursorDlg.cxx create mode 100644 src/VISUGUI/VisuGUI_CursorDlg.h create mode 100644 src/VISUGUI/VisuGUI_CutPlanesDlg.h create mode 100644 src/VISUGUI/VisuGUI_EditContainerDlg.cxx create mode 100644 src/VISUGUI/VisuGUI_EditContainerDlg.h create mode 100644 src/VISUGUI/VisuGUI_Factory.cxx create mode 100644 src/VISUGUI/VisuGUI_FileDlg.cxx create mode 100755 src/VISUGUI/VisuGUI_FontWg.cxx create mode 100644 src/VISUGUI/VisuGUI_Plot3DDlg.cxx create mode 100644 src/VISUGUI/VisuGUI_Plot3DDlg.h create mode 100644 src/VISUGUI/VisuGUI_ScalarBarDlg.cxx create mode 100644 src/VISUGUI/VisuGUI_ScalarBarDlg.h create mode 100644 src/VISUGUI/VisuGUI_Selection.cxx create mode 100644 src/VISUGUI/VisuGUI_TimeAnimation.h create mode 100644 src/VISUGUI/VisuGUI_Tools.cxx create mode 100644 src/VISUGUI/VisuGUI_Tools.h create mode 100644 src/VISU_I/VISUConfig.hh create mode 100644 src/VISU_I/VISU_Gen_i.cc create mode 100644 src/VISU_I/VISU_Result_i.cc create mode 100644 src/VISU_I/VISU_Result_i.hh create mode 100644 src/VISU_I/VISU_View_i.cc create mode 100644 src/VISU_SWIG/visu_split_views.py diff --git a/src/PIPELINE/Makefile.in b/src/PIPELINE/Makefile.in new file mode 100644 index 00000000..ca47dfad --- /dev/null +++ b/src/PIPELINE/Makefile.in @@ -0,0 +1,75 @@ +# VISU OBJECT : interactive object for VISU entities implementation +# +# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +# +# +# +# File : Makefile.in +# Module : VISU + +top_srcdir=@top_srcdir@ +top_builddir=../.. +srcdir=@srcdir@ +VPATH=.:@srcdir@ + + +@COMMENCE@ + +EXPORT_HEADERS = VISU_PipeLine.hxx VISU_PipeLineUtils.hxx \ + VISU_MeshPL.hxx VISU_ScalarMapPL.hxx \ + VISU_CutPlanesPL.hxx VISU_CutLinesPL.hxx \ + VISU_IsoSurfacesPL.hxx VISU_DeformedShapePL.hxx \ + VISU_VectorsPL.hxx VISU_StreamLinesPL.hxx \ + VISU_LookupTable.hxx VISU_ScalarBarActor.hxx \ + VISU_Extractor.hxx VISU_FieldTransform.hxx \ + VISU_UsedPointsFilter.hxx VISU_Plot3DPL.hxx + +# Libraries targets + +LIB = libVisuPipeLine.la +LIB_SRC = VISU_PipeLine.cxx VISU_PipeLineUtils.cxx \ + VISU_MeshPL.cxx VISU_ScalarMapPL.cxx \ + VISU_CutPlanesPL.cxx VISU_CutLinesPL.cxx \ + VISU_IsoSurfacesPL.cxx VISU_DeformedShapePL.cxx \ + VISU_VectorsPL.cxx VISU_StreamLinesPL.cxx \ + VISU_LookupTable.cxx VISU_ScalarBarActor.cxx \ + VISU_Extractor.cxx VISU_FieldTransform.cxx \ + VISU_UsedPointsFilter.cxx VISU_Plot3DPL.cxx \ + SALOME_ExtractGeometry.cxx + +# Executables targets + +BIN = VISUPipeLine +BIN_SRC = + +CPPFLAGS+= $(VTK_INCLUDES) \ + -I${KERNEL_ROOT_DIR}/include/salome \ + -I${GUI_ROOT_DIR}/include/salome \ + -I${MED_ROOT_DIR}/include/salome \ + $(HDF5_INCLUDES) $(BOOST_CPPFLAGS) + +LDFLAGS+= $(VTK_LIBS) -lVTKViewer -lVisuConvertor \ + -L${KERNEL_ROOT_DIR}/lib/salome -lSALOMELocalTrace \ + -L${GUI_ROOT_DIR}/lib/salome \ + -L${MED_ROOT_DIR}/lib/salome + +LDFLAGSFORBIN=$(LDFLAGS) -lOpUtil -lMEDWrapper -lMEDWrapper_V2_2 -lMEDWrapper_V2_1 -lMEDWrapperBase -lsuit -lqtx + +@CONCLUDE@ diff --git a/src/VISUGUI/VisuGUI_CursorDlg.cxx b/src/VISUGUI/VisuGUI_CursorDlg.cxx new file mode 100644 index 00000000..e1adefcf --- /dev/null +++ b/src/VISUGUI/VisuGUI_CursorDlg.cxx @@ -0,0 +1,109 @@ +// VISU VISUGUI : GUI of VISU component +// +// 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 : VisuGUI_CursorDlg.cxx +// Author : Laurent CORNABE & Hubert ROLLAND +// Module : VISU +// $Header$ + +using namespace std; +#include "VisuGUI_CursorDlg.h" +#include + +/*! + Constructor +*/ +VisuGUI_CursorDlg::VisuGUI_CursorDlg( QWidget* parent, const char* name, bool modal, WFlags fl ) + : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ) +{ + if ( !name ) + setName( "VisuGUI_CursorDlg" ); + setCaption( name ); + setSizeGripEnabled( TRUE ); + + QGridLayout* TopLayout = new QGridLayout( this ); + TopLayout->setSpacing( 6 ); + TopLayout->setMargin( 11 ); + + TopGroupBox = new QGroupBox( this, "TopGroupBox" ); + TopGroupBox->setColumnLayout(0, Qt::Vertical ); + TopGroupBox->layout()->setSpacing( 0 ); + TopGroupBox->layout()->setMargin( 0 ); + QGridLayout* TopGroupBoxLayout = new QGridLayout( TopGroupBox->layout() ); + TopGroupBoxLayout->setAlignment( Qt::AlignTop ); + TopGroupBoxLayout->setSpacing( 6 ); + TopGroupBoxLayout->setMargin( 11 ); + + Comment1 = new QLabel( tr( "TextLabel1" ), TopGroupBox, "Comment1" ); + Comment1->setAlignment( QLabel::AlignCenter ); + TopGroupBoxLayout->addWidget( Comment1, 0, 0 ); + + Comment2 = new QLabel( tr( "TextLabel2" ), TopGroupBox, "Comment2" ); + Comment2->setAlignment( QLabel::AlignCenter ); + TopGroupBoxLayout->addWidget( Comment2, 1, 0 ); + + SpinBox1 = new QSpinBox( 1, 100, 1, TopGroupBox, "SpinBox1" ); + SpinBox1->setValue( 100 ); + SpinBox1->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + SpinBox1->setMinimumSize( 70, 0 ); + QHBoxLayout* SLayout = new QHBoxLayout; + SLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ) ); + SLayout->addWidget( SpinBox1 ); + SLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ) ); + TopGroupBoxLayout->addLayout( SLayout, 2, 0 ); + + GroupButtons = new QGroupBox (this, "GroupButtons"); + GroupButtons->setGeometry(QRect(10, 10, 281, 48)); + GroupButtons->setColumnLayout(0, Qt::Vertical); + GroupButtons->layout()->setSpacing(0); + GroupButtons->layout()->setMargin(0); + QGridLayout* GroupButtonsLayout = new QGridLayout (GroupButtons->layout()); + GroupButtonsLayout->setAlignment(Qt::AlignTop); + GroupButtonsLayout->setSpacing(6); + GroupButtonsLayout->setMargin(11); + + buttonOk = new QPushButton (tr("&OK"), GroupButtons, "buttonOk"); + buttonOk->setAutoDefault(TRUE); + buttonOk->setDefault(TRUE); + GroupButtonsLayout->addWidget(buttonOk, 0, 0); + + GroupButtonsLayout->addItem(new QSpacerItem (5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 1); + + buttonCancel = new QPushButton(tr("&Cancel") , GroupButtons, "buttonCancel"); + buttonCancel->setAutoDefault(TRUE); + GroupButtonsLayout->addWidget(buttonCancel, 0, 2); + + TopLayout->addWidget(TopGroupBox, 0, 0); + TopLayout->addWidget(GroupButtons, 1, 0); + + // signals and slots connections + connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) ); + connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) ); +} + +/*! + Destructor +*/ +VisuGUI_CursorDlg::~VisuGUI_CursorDlg() +{ +} diff --git a/src/VISUGUI/VisuGUI_CursorDlg.h b/src/VISUGUI/VisuGUI_CursorDlg.h new file mode 100644 index 00000000..018709cf --- /dev/null +++ b/src/VISUGUI/VisuGUI_CursorDlg.h @@ -0,0 +1,55 @@ +// VISU VISUGUI : GUI of VISU component +// +// 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 : VisuGUI_CursorDlg.h +// Author : Laurent CORNABE & Hubert ROLLAND +// Module : VISU +// $Header$ + +#ifndef VISUGUI_CURSORDLG_H +#define VISUGUI_CURSORDLG_H + +#include +#include +#include +#include +#include + +class VisuGUI_CursorDlg : public QDialog +{ + Q_OBJECT + +public: + VisuGUI_CursorDlg( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 ); + ~VisuGUI_CursorDlg(); + + QGroupBox* TopGroupBox; + QLabel* Comment1; + QLabel* Comment2; + QSpinBox* SpinBox1; + QGroupBox* GroupButtons; + QPushButton* buttonOk; + QPushButton* buttonCancel; +}; + +#endif // VISUGUI_CURSORDLG_H diff --git a/src/VISUGUI/VisuGUI_CutPlanesDlg.h b/src/VISUGUI/VisuGUI_CutPlanesDlg.h new file mode 100644 index 00000000..e5ccea9f --- /dev/null +++ b/src/VISUGUI/VisuGUI_CutPlanesDlg.h @@ -0,0 +1,136 @@ +// VISU VISUGUI : GUI of VISU component +// +// 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 : VisuGUI_CutPlanesDlg.h +// Author : Laurent CORNABE & Hubert ROLLAND +// Module : VISU +// $Header$ + +#ifndef VISUGUI_CUTPLANESDLG_H +#define VISUGUI_CUTPLANESDLG_H + +#include "VisuGUI_ScalarBarDlg.h" +#include "VISU_CutPlanes_i.hh" + +#include + +#include +#include + +#include "SALOMEconfig.h" +#include CORBA_CLIENT_HEADER(VISU_Gen) + +class QtxDblSpinBox; +class SUIT_ViewWindow; +class SUIT_ViewManager; +class SalomeApp_Module; + + +class VisuGUI_CutPlanesPane : public QFrame +{ + Q_OBJECT + +public: + VisuGUI_CutPlanesPane (QWidget* parent); + ~VisuGUI_CutPlanesPane(); + + void setNbPlanes( const int nbp ) {nbPlan->setValue( nbp );} + int getNbPlanes() {return nbPlan->value();} + void setPlanePos( const VISU::CutPlanes::Orientation orient/*, const double pos1, const double pos2 */); + VISU::CutPlanes::Orientation getOrientaion(); + void setRotation( const double r1, const double r2 ); + double getRotation1() {return Rot1->value();} + double getRotation2() {return Rot2->value();} + + void initFromPrsObject(VISU::CutPlanes_i* thePrs); + int storeToPrsObject(VISU::CutPlanes_i* thePrs); + +private: + void createPlanes(); + void deletePlanes(); + + + QLabel* LabelRot1; + QLabel* LabelRot2; + QSpinBox* nbPlan; + QtxDblSpinBox* Rot1; + QtxDblSpinBox* Rot2; + QRadioButton* RBzx; + QRadioButton* RByz; + QRadioButton* RBxy; + QtxDblSpinBox* myPosSpn; + QTable* myPosTable; + VISU::CutPlanes_i* myCutPlanes; + QCheckBox* myPreviewCheck; + double X1, X2; + double Y1, Y2; + double Z1, Z2; + bool hasInit; + + SALOME_Actor* myPreviewActor; + +private slots: + void editScalarBar(); + void orientationChanged( int ); + void DrawTable(); + void setDefault( int all = -1); + void onValueChanged(int theRow, int theCol); + void onRotation(double theValue); + void onPreviewCheck(bool thePreview); +}; + + +class VisuGUI_CutPlanesDlg : public QDialog +{ + Q_OBJECT + +public: + VisuGUI_CutPlanesDlg (SalomeApp_Module* theModule); + ~VisuGUI_CutPlanesDlg() {}; + + void initFromPrsObject (VISU::CutPlanes_i* thePrs); + int storeToPrsObject (VISU::CutPlanes_i* thePrs); + +protected slots: + void accept(); + void reject(); + void onWindowActivated (SUIT_ViewWindow*); + +private: + VisuGUI_CutPlanesPane* myCutPane; + VisuGUI_ScalarBarPane* myScalarPane; + VISU::CutPlanes_i* myPrs; +}; + + +class VisuGUI_NumEditItem: public QTableItem +{ +public: + VisuGUI_NumEditItem(QTable* table, EditType et, const QString& text ): + QTableItem(table, et, text) {}; + ~VisuGUI_NumEditItem() {}; + + QWidget* createEditor() const; +}; + +#endif // VISUGUI_CUTPLANESDLG_H diff --git a/src/VISUGUI/VisuGUI_EditContainerDlg.cxx b/src/VISUGUI/VisuGUI_EditContainerDlg.cxx new file mode 100644 index 00000000..eed32a53 --- /dev/null +++ b/src/VISUGUI/VisuGUI_EditContainerDlg.cxx @@ -0,0 +1,429 @@ +// VISU VISUGUI : GUI of VISU component +// +// Copyright (C) 2003 CEA/DEN, EDF R&D +// +// +// +// File : VisuGUI_EditContainerDlg.cxx +// Author : VSV +// Module : VISU + + +#include "VisuGUI_EditContainerDlg.h" + +#include "VisuGUI.h" +#include "VisuGUI_Tools.h" + +#include "VISU_Table_i.hh" + +#include "SalomeApp_Application.h" +#include "SUIT_Desktop.h" + +#include +#include +#include +#include +#include + +using namespace std; + + +/* XPM */ +static const char * left_xpm[] = { +"24 24 61 1", +" c None", +". c #323232", +"+ c #010101", +"@ c #4A4A4A", +"# c #040404", +"$ c #979797", +"% c #7B7B7B", +"& c #939393", +"* c #EEEEEE", +"= c #686868", +"- c #030303", +"; c #9C9C9C", +"> c #FFFFFF", +", c #B1B1B1", +"' c #5E5E5E", +") c #060606", +"! c #C1C1C1", +"~ c #626262", +"{ c #000000", +"] c #989898", +"^ c #A1A1A1", +"/ c #A5A5A5", +"( c #909090", +"_ c #868686", +": c #616161", +"< c #959595", +"[ c #919191", +"} c #848484", +"| c #606060", +"1 c #0B0B0B", +"2 c #545454", +"3 c #727272", +"4 c #A2A2A2", +"5 c #969696", +"6 c #838383", +"7 c #5F5F5F", +"8 c #101010", +"9 c #434343", +"0 c #6B6B6B", +"a c #858585", +"b c #8E8E8E", +"c c #373737", +"d c #696969", +"e c #8D8D8D", +"f c #B5B5B5", +"g c #111111", +"h c #393939", +"i c #898989", +"j c #B0B0B0", +"k c #191919", +"l c #3A3A3A", +"m c #646464", +"n c #535353", +"o c #050505", +"p c #353535", +"q c #585858", +"r c #4C4C4C", +"s c #0D0D0D", +"t c #3E3E3E", +"u c #020202", +"v c #0A0A0A", +" ", +" ", +" .+ .+ ", +" .@# .@# ", +" .$%# .$%# ", +" .&*=- .&*=- ", +" .;>,') .;>,') ", +" .;>!;~{ .;>!;~{ ", +" .]>!^&~{ .]>!^&~{ ", +" ./>!/(_:{ ./>!/(_:{ ", +" .<*!^[}}|{.<*!^[}}|{ ", +" 123}45667{123}45667{ ", +" 890a45b7{ 890a45b7{ ", +" 8cdef5'{ 8cdef5'{ ", +" gh0ij7k gh0ij7k ", +" 8lm0no 8lm0no ", +" 8pqr- 8pqr- ", +" sht- sht- ", +" 1.u 1.u ", +" v{ v{ ", +" ", +" ", +" ", +" "}; + +static QPixmap MYLeftPix(left_xpm); + + +static const char * right_xpm[] = { +"24 24 43 1", +" g None", +". g #323232", +"+ g #5D5D5D", +"@ g #000000", +"# g #C4C4C4", +"$ g #313131", +"% g #C5C5C5", +"& g #E4E4E4", +"* g #2D2D2D", +"= g #B7B7B7", +"- g #EFEFEF", +"; g #DCDCDC", +"> g #282828", +", g #AFAFAF", +"' g #E0E0E0", +") g #242424", +"! g #C7C7C7", +"~ g #9A9A9A", +"{ g #8E8E8E", +"] g #1F1F1F", +"^ g #A5A5A5", +"/ g #989898", +"( g #888888", +"_ g #1B1B1B", +": g #ADADAD", +"< g #858585", +"[ g #838383", +"} g #868686", +"| g #929292", +"1 g #C1C1C1", +"2 g #161616", +"3 g #909090", +"4 g #747474", +"5 g #3A3A3A", +"6 g #121212", +"7 g #0D0D0D", +"8 g #7A7A7A", +"9 g #8A8A8A", +"0 g #090909", +"a g #040404", +"b g #707070", +"c g #6E6E6E", +"d g #3F3F3F", +" ", +" ", +" .. .. ", +" .+@ .+@ ", +" .#+@ .#+@ ", +" $%&+@ $%&+@ ", +" *=-;+@ *=-;+@ ", +" >,'=;+@ >,'=;+@ ", +" ),!~{;+@ ),!~{;+@ ", +" ]^!/({;+@ ]^!/({;+@ ", +" _~:<[}|1+@_~:<[}|1+@ ", +" 23~[[{:45@23~[[{:45@ ", +" 6setFrameStyle(QFrame::Box | QFrame::Sunken); + + QGridLayout* aControlLay = new QGridLayout (aControlFrame); + aControlLay->setSpacing(6); + aControlLay->setMargin(11); + aControlLay->addRowSpacing(1, 30); + aControlLay->addRowSpacing(4, 30); + aControlLay->setRowStretch(1, 1); + aControlLay->setRowStretch(4, 1); + aControlLay->addColSpacing(0, 180); + aControlLay->addColSpacing(2, 180); + + QLabel* aSelectLbl = new QLabel (tr("LBL_STUDY"), aControlFrame); + aControlLay->addWidget(aSelectLbl, 0, 0); + + myStudyLst = new QListView (aControlFrame); + myStudyLst->setSelectionMode(QListView::Extended); + myStudyLst->addColumn(tr("TXT_TABLE"), 80); + myStudyLst->addColumn(tr("TXT_CURVE"), 50); + myStudyLst->addColumn(tr(""), 0); + myStudyLst->setAllColumnsShowFocus(true); + myStudyLst->setMinimumHeight(130); + connect(myStudyLst, SIGNAL(selectionChanged()), this, SLOT(onLeftSelected())); + aControlLay->addMultiCellWidget(myStudyLst, 1, 4, 0, 0); + + myRightBtn = new QToolButton (aControlFrame); + myRightBtn->setIconSet(MYRightPix); + myRightBtn->setEnabled(false); + connect(myRightBtn, SIGNAL(clicked()), this, SLOT(onRightClicked())); + aControlLay->addWidget(myRightBtn, 2, 1); + + myLeftBtn = new QToolButton(aControlFrame); + myLeftBtn->setIconSet(MYLeftPix); + myLeftBtn->setEnabled(false); + connect(myLeftBtn, SIGNAL(clicked()), this, SLOT(onLeftClicked())); + aControlLay->addWidget(myLeftBtn, 3, 1); + + QLabel* aForceLbl = new QLabel (tr("LBL_CONTAINER"), aControlFrame); + aControlLay->addWidget(aForceLbl, 0, 2); + + myContainerLst = new QListView(aControlFrame); + myContainerLst->setSelectionMode(QListView::Extended); + myContainerLst->addColumn(tr("TXT_TABLE"), 80); + myContainerLst->addColumn(tr("TXT_CURVE"), 50); + myContainerLst->addColumn(tr(""), 0); + myContainerLst->setMinimumWidth(130); + connect(myContainerLst, SIGNAL(selectionChanged()), this, SLOT(onRightSelected())); + aControlLay->addMultiCellWidget(myContainerLst, 1, 4, 2, 2); + + TopLayout->addWidget(aControlFrame); + + // Common buttons =========================================================== + QGroupBox* GroupButtons = new QGroupBox(this, "GroupButtons"); + GroupButtons->setColumnLayout(0, Qt::Vertical); + GroupButtons->layout()->setSpacing(0); + GroupButtons->layout()->setMargin(0); + QGridLayout* GroupButtonsLayout = new QGridLayout(GroupButtons->layout()); + GroupButtonsLayout->setAlignment(Qt::AlignTop); + GroupButtonsLayout->setSpacing(6); + GroupButtonsLayout->setMargin(11); + + QPushButton* buttonOk = new QPushButton(tr("&OK"), GroupButtons, "buttonOk"); + buttonOk->setAutoDefault(TRUE); + buttonOk->setDefault(TRUE); + GroupButtonsLayout->addWidget(buttonOk, 0, 0); + GroupButtonsLayout->addItem(new QSpacerItem(5, 5, QSizePolicy::Expanding, + QSizePolicy::Minimum), 0, 1); + + QPushButton* buttonCancel = new QPushButton(tr("&Cancel") , GroupButtons, "buttonCancel"); + buttonCancel->setAutoDefault(TRUE); + GroupButtonsLayout->addWidget(buttonCancel, 0, 2); + + TopLayout->addWidget(GroupButtons); + + connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept())); + connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject())); +} + +void VisuGUI_EditContainerDlg::initFromPrsObject (VISU::Container_i* theContainer) +{ + _PTR(Study) aStudy = VISU::GetCStudy(VISU::GetAppStudy(myVisuGUI)); + _PTR(SComponent) aVisuSO = aStudy->FindComponent("VISU"); + if (!aVisuSO) { + return; + } + QValueList aStudyCurves; + QValueList aContainerCurves; + // Find curves in container + for (int i = 1; i <= theContainer->GetNbCurves(); i++) { + VISU::Curve_i* aCurve = theContainer->GetCurve(i); + if (aCurve == NULL) continue; + CurveStruct aEntry; + aEntry.CurveName = aCurve->GetTitle(); + aEntry.CurveEntry = aCurve->GetEntry(); + _PTR(SObject) aTableSO = aStudy->FindObjectID(aCurve->GetTableID()); + if (!aTableSO) continue; + aEntry.TableName = getSObjectName(aTableSO); + aContainerCurves.append(aEntry); + new QListViewItem(myContainerLst, aEntry.TableName, aEntry.CurveName, aEntry.CurveEntry); + } + // Find curves in study + _PTR(ChildIterator) aIter = aStudy->NewChildIterator(aVisuSO); + for (aIter->InitEx(true); aIter->More(); aIter->Next()) { + _PTR(SObject) aSObject = aIter->Value(); + CORBA::Object_var anObject = VISU::ClientSObjectToObject(aSObject); + VISU::Base_var aVisuObj = VISU::Base::_narrow(anObject); + if (!CORBA::is_nil(aVisuObj)) { + if (aVisuObj->GetType() == VISU::TCURVE) { + _PTR(SObject) aTableSO = aSObject->GetFather(); + CurveStruct aEntry; + aEntry.TableName = getSObjectName(aTableSO); + aEntry.CurveName = getSObjectName(aSObject); + aEntry.CurveEntry = aSObject->GetID().c_str(); + aStudyCurves.append(aEntry); + } + } + } + //Show Curves which are not in Curve + QValueList::iterator it; + QValueList::iterator it2; + bool isExist = false; + for (it = aStudyCurves.begin(); it != aStudyCurves.end(); ++it) { + for (it2 = aContainerCurves.begin(); it2 != aContainerCurves.end(); ++it2) { + if (isExist = ((*it).CurveEntry == (*it2).CurveEntry)) + break; + } + if (!isExist) + new QListViewItem(myStudyLst, (*it).TableName, (*it).CurveName, (*it).CurveEntry); + } +} + +void VisuGUI_EditContainerDlg::storeToPrsObject (VISU::Container_i* theContainer) +{ + theContainer->Clear(); + + _PTR(Study) aStudy = VISU::GetCStudy(VISU::GetAppStudy(myVisuGUI)); + QListViewItem* anItem = myContainerLst->firstChild(); + while (anItem) { + _PTR(SObject) aCurveSO = aStudy->FindObjectID(anItem->text(2).latin1()); + if (aCurveSO) { + CORBA::Object_var aObject = VISU::ClientSObjectToObject(aCurveSO); + if (!CORBA::is_nil(aObject)) { + VISU::Curve_i* aCurve = dynamic_cast(VISU::GetServant(aObject).in()); + if (aCurve) theContainer->AddCurve(aCurve->_this()); + } + } + anItem = anItem->nextSibling(); + } +} + +QString VisuGUI_EditContainerDlg::getSObjectName (_PTR(SObject) theSObject) +{ + if (!theSObject) return QString(""); + + _PTR(GenericAttribute) anAttr; + if (theSObject->FindAttribute(anAttr, "AttributeName")) { + _PTR(AttributeName) aName (anAttr); + return QString(aName->Value().c_str()); + } + return QString(""); +} + +void VisuGUI_EditContainerDlg::onLeftClicked() +{ + QListViewItem* anItem = myContainerLst->firstChild(); + while (anItem) { + if (anItem->isSelected()) { + QListViewItem* anTmpItem = anItem; + anItem = anTmpItem->nextSibling(); + myContainerLst->takeItem(anTmpItem); + myStudyLst->insertItem(anTmpItem); + } else { + anItem = anItem->nextSibling(); + } + } +} + +void VisuGUI_EditContainerDlg::onRightClicked() +{ + QListViewItem* anItem = myStudyLst->firstChild(); + while (anItem) { + if (anItem->isSelected()) { + QListViewItem* anTmpItem = anItem; + anItem = anTmpItem->nextSibling(); + myStudyLst->takeItem(anTmpItem); + myContainerLst->insertItem(anTmpItem); + } else { + anItem = anItem->nextSibling(); + } + } +} + +void VisuGUI_EditContainerDlg::onLeftSelected() +{ + QListViewItem* anItem = myStudyLst->firstChild(); + bool isSelected = false; + while (anItem) { + if (anItem->isSelected()) { + isSelected = true; + break; + } + anItem = anItem->nextSibling(); + } + myRightBtn->setEnabled(isSelected); +} + +void VisuGUI_EditContainerDlg::onRightSelected() +{ + QListViewItem* anItem = myContainerLst->firstChild(); + bool isSelected = false; + while (anItem) { + if (anItem->isSelected()) { + isSelected = true; + break; + } + anItem = anItem->nextSibling(); + } + myLeftBtn->setEnabled(isSelected); +} diff --git a/src/VISUGUI/VisuGUI_EditContainerDlg.h b/src/VISUGUI/VisuGUI_EditContainerDlg.h new file mode 100644 index 00000000..8493d0ff --- /dev/null +++ b/src/VISUGUI/VisuGUI_EditContainerDlg.h @@ -0,0 +1,63 @@ +// VISU VISUGUI : GUI of VISU component +// +// Copyright (C) 2003 CEA/DEN, EDF R&D +// +// +// +// File : VisuGUI_EditContainerDlg.h +// Author : VSV +// Module : VISU + +#ifndef VISUGUI_EDITCONTAINER_H +#define VISUGUI_EDITCONTAINER_H + +#include +#include +#include +#include + +#include "SALOMEDSClient_SObject.hxx" + +class VisuGUI; + +namespace VISU { + class Container_i; +} + + +struct CurveStruct { + QString TableName; + QString CurveName; + QString CurveEntry; +}; + + +class VisuGUI_EditContainerDlg: public QDialog +{ + Q_OBJECT; + + public: + VisuGUI_EditContainerDlg (VisuGUI* theModule, bool theIsModal = true); + ~VisuGUI_EditContainerDlg() {}; + + void initFromPrsObject (VISU::Container_i* theContainer); + void storeToPrsObject (VISU::Container_i* theContainer); + + private slots: + void onLeftClicked(); + void onRightClicked(); + void onLeftSelected(); + void onRightSelected(); + + private: + QString getSObjectName (_PTR(SObject) theSObject); + + QListView* myStudyLst; + QListView* myContainerLst; + QToolButton* myLeftBtn; + QToolButton* myRightBtn; + + VisuGUI* myVisuGUI; +}; + +#endif // VISUGUI_EDITCONTAINER_H diff --git a/src/VISUGUI/VisuGUI_Factory.cxx b/src/VISUGUI/VisuGUI_Factory.cxx new file mode 100644 index 00000000..24ea841b --- /dev/null +++ b/src/VISUGUI/VisuGUI_Factory.cxx @@ -0,0 +1,40 @@ +// VISU VISUGUI : GUI of VISU component +// +// 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 : VisuGUI_Factory.cxx +// Author : +// Module : VISU +// $Header$ + +#include "VisuGUI.h" + +#include "CAM_Module.h" + +extern "C" { + CAM_Module* + createModule() + { + return new VisuGUI(); + } +} + diff --git a/src/VISUGUI/VisuGUI_FileDlg.cxx b/src/VISUGUI/VisuGUI_FileDlg.cxx new file mode 100644 index 00000000..1e788c46 --- /dev/null +++ b/src/VISUGUI/VisuGUI_FileDlg.cxx @@ -0,0 +1,111 @@ +// SALOME SALOMEGUI : GUI of VISU module +// +// Copyright (C) 2003 CEA/DEN, EDF R&D +// +// +// +// File : VisuGUI_FileDlg.cxx +// Author : +// Module : SALOME +// $Header: /dn05/salome/CVS/SALOME_ROOT/SALOME/src/VISUGUI/Visu_FileDlg.cxx + + +#include +#include +#include +#include +#include + +#include "VISUConfig.hh" +#include "VisuGUI_FileDlg.h" +#include "SUIT_ResourceMgr.h" + +using namespace std; + +bool VisuGUI_FileDlg::IsBuild = false; + +/*! +Constructor +*/ +VisuGUI_FileDlg::VisuGUI_FileDlg (QWidget* parent, + bool open, + bool showQuickDir, + bool modal) : + SUIT_FileDlg(parent, open, showQuickDir, modal) +{ + myCBuildAll = new QCheckBox (tr("FULL_LOAD"), this); + QLabel* label = new QLabel("", this); + label->setMaximumWidth(0); + QPushButton* pb = new QPushButton(this); + pb->setMaximumWidth(0); + addWidgets( label, myCBuildAll, pb ); + bool toBuildAll = VISU::GetResourceMgr()->booleanValue("VISU", "full_med_loading", false); + if (toBuildAll) myCBuildAll->setChecked(true); +} + +/*! + Destructor +*/ +VisuGUI_FileDlg::~VisuGUI_FileDlg() +{ +} + +/*! + Processes selection : tries to set given path or filename as selection +*/ +bool VisuGUI_FileDlg::processPath( const QString& path ) +{ + if ( !path.isNull() ) { + QFileInfo fi( path ); + if ( fi.exists() ) { + if ( fi.isFile() ) + setSelection( path ); + else if ( fi.isDir() ) + setDir( path ); + return true; + } + else { + if ( QFileInfo( fi.dirPath() ).exists() ) { + setDir( fi.dirPath() ); + return true; + } + } + } + return false; +} + +/*! + Returns the file name for Open/Save [ static ] +*/ +QString VisuGUI_FileDlg::getFileName( QWidget* parent, + const QString& initial, + const QStringList& filters, + const QString& caption, + bool open, + bool showQuickDir, + SUIT_FileValidator* validator ) +{ + VisuGUI_FileDlg* fd = new VisuGUI_FileDlg( parent, open, showQuickDir, true ); + if ( !caption.isEmpty() ) + fd->setCaption( caption ); + if ( !initial.isEmpty() ) { + fd->processPath( initial ); // VSR 24/03/03 check for existing of directory has been added to avoid QFileDialog's bug + } + fd->setFilters( filters ); + if ( validator ) + fd->setValidator( validator ); + fd->exec(); + QString filename = fd->selectedFile(); + + VisuGUI_FileDlg::IsBuild = fd->IsChecked(); + + delete fd; + qApp->processEvents(); + + return filename; +} + +bool VisuGUI_FileDlg::IsChecked() +{ + return myCBuildAll->isChecked(); +} diff --git a/src/VISUGUI/VisuGUI_FontWg.cxx b/src/VISUGUI/VisuGUI_FontWg.cxx new file mode 100755 index 00000000..78d62a1c --- /dev/null +++ b/src/VISUGUI/VisuGUI_FontWg.cxx @@ -0,0 +1,149 @@ +// VISU VISUGUI : GUI for SMESH component +// +// 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 : VisuGUI_CubeAxesDlg.cxx +// Author : Sergey LITONIN +// Module : VISU + +#include "VisuGUI_FontWg.h" + +#include +#include +#include +#include + +#include + +/*! + * Class : VisuGUI_FontWg + * Description : Dialog for specifynig font + */ + +//======================================================================= +// name : VisuGUI_FontWg +// Purpose : Constructor +//======================================================================= +VisuGUI_FontWg::VisuGUI_FontWg( QWidget* theParent ) +: QHBox( theParent ) +{ + setSpacing( 5 ); + myColorBtn = new QToolButton( this ); + myColorBtn->setMinimumWidth( 20 ); + + myFamily = new QComboBox( this ); + myFamily->insertItem( tr( "ARIAL" ) ); + myFamily->insertItem( tr( "COURIER" ) ); + myFamily->insertItem( tr( "TIMES" ) ); + + myBold = new QCheckBox( tr( "BOLD" ), this ); + myItalic = new QCheckBox( tr( "ITALIC" ), this ); + myShadow = new QCheckBox( tr( "SHADOW" ), this ); + + connect( myColorBtn, SIGNAL( clicked() ), SLOT( onColor() ) ); +} + +//======================================================================= +// name : ~VisuGUI_FontWg +// Purpose : Destructor +//======================================================================= +VisuGUI_FontWg::~VisuGUI_FontWg() +{ +} + +//======================================================================= +// name : SetColor +// Purpose : +//======================================================================= +void VisuGUI_FontWg::SetColor( const QColor& theColor ) +{ + myColorBtn->setPaletteBackgroundColor( theColor ); +} + +//======================================================================= +// name : GetColor +// Purpose : +//======================================================================= +QColor VisuGUI_FontWg::GetColor() const +{ + return myColorBtn->paletteBackgroundColor(); +} + +//======================================================================= +// name : onColor +// Purpose : +//======================================================================= +void VisuGUI_FontWg::onColor() +{ + QColor aColor = QColorDialog::getColor( GetColor(), this ); + if ( aColor.isValid() ) + SetColor( aColor ); +} + +//======================================================================= +// name : SetData +// Purpose : +//======================================================================= +void VisuGUI_FontWg::SetData( const QColor& theColor, + const int theFamily, + const bool theBold, + const bool theItalic, + const bool theShadow ) +{ + SetColor( theColor ); + + if ( theFamily == VTK_ARIAL ) + myFamily->setCurrentItem( 0 ); + else if ( theFamily == VTK_COURIER ) + myFamily->setCurrentItem( 1 ); + else + myFamily->setCurrentItem( 2 ); + + myBold->setChecked( theBold ); + myItalic->setChecked( theItalic ); + myShadow->setChecked( theShadow ); +} + +//======================================================================= +// name : GetData +// Purpose : +//======================================================================= +void VisuGUI_FontWg::GetData( QColor& theColor, + int& theFamily, + bool& theBold, + bool& theItalic, + bool& theShadow ) const +{ + theColor = GetColor(); + + int anItem =myFamily->currentItem(); + if ( anItem == 0 ) + theFamily = VTK_ARIAL; + else if ( anItem == 1 ) + theFamily = VTK_COURIER; + else + theFamily = VTK_TIMES; + + theBold = myBold->isChecked(); + theItalic = myItalic->isChecked(); + theShadow = myShadow->isChecked(); +} diff --git a/src/VISUGUI/VisuGUI_Plot3DDlg.cxx b/src/VISUGUI/VisuGUI_Plot3DDlg.cxx new file mode 100644 index 00000000..78cbcec2 --- /dev/null +++ b/src/VISUGUI/VisuGUI_Plot3DDlg.cxx @@ -0,0 +1,566 @@ +// VISU VISUGUI : GUI of VISU component +// +// 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 : VisuGUI_Plot3DDlg.cxx +// Author : Laurent CORNABE & Hubert ROLLAND +// Module : VISU +// $Header$ + +#include "VisuGUI_Plot3DDlg.h" + +#include "VisuGUI.h" +#include "VisuGUI_Tools.h" + +#include "VISU_ViewManager_i.hh" +#include "VISU_Plot3DPL.hxx" + +#include "SALOME_Actor.h" +#include "SVTK_ViewWindow.h" +#include "SUIT_Desktop.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +using namespace std; + +#define SURFACE_PRS_ID 0 +#define CONTOUR_PRS_ID 1 + +//======================================================================= +//function : renderViewFrame +//purpose : +//======================================================================= +static void renderViewFrame (SVTK_ViewWindow* vw) +{ + if (vw) { + vw->getRenderer()->ResetCameraClippingRange(); + vw->Repaint(); + } +} + +//======================================================================= +//class : TPlane +//purpose : actor of plane preview +//======================================================================= +class TPlane : public SALOME_Actor +{ + float mySize; + vtkDataSetMapper* myMapper; + vtkPlaneSource* myPlaneSource; + + public: + // constructor + TPlane(float planeSize): mySize(planeSize) + { + Init(); + } + // set plane parameters + void Set(float origin[3], float normal[3]) + { + float point2[3], point1[3]; + vtkMath::Perpendiculars(normal, point1, point2, 0.); + for (int i = 0; i < 3; ++i) { + point1[ i ] = point1[ i ] * mySize + origin[ i ]; + point2[ i ] = point2[ i ] * mySize + origin[ i ]; + } + myPlaneSource->SetOrigin(origin); + myPlaneSource->SetPoint1(point1); + myPlaneSource->SetPoint2(point2); + myPlaneSource->SetCenter(origin); + } + vtkTypeMacro(TPlane,SALOME_Actor); + + protected: + void Init() { + myPlaneSource = vtkPlaneSource::New(); + myMapper = vtkDataSetMapper::New(); + myMapper->SetInput(myPlaneSource->GetOutput()); + // actor methods + VisibilityOff(); + PickableOff(); + SetInfinitive(true); + SetOpacity(0.85); + SetMapper(myMapper); + } + ~TPlane() { + myMapper->RemoveAllInputs(); + myMapper->Delete(); + myPlaneSource->UnRegisterAllOutputs(); + myPlaneSource->Delete(); + }; + // Not implemented. + TPlane(const TPlane&); + void operator=(const TPlane&); +}; + +//======================================================================= +//function : VisuGUI_Plot3DPane +//purpose : +//======================================================================= +VisuGUI_Plot3DPane::VisuGUI_Plot3DPane (QWidget* parent) + : QVBox(parent), myInitFromPrs(false), myPreviewActor(NULL), + myViewWindow(VISU::GetViewWindow()), myPrs(NULL), myPipeCopy(NULL) +{ + layout()->setAlignment(Qt::AlignTop); + setSpacing(6); + + // Orientation + + GBOrientation = new QButtonGroup (tr("Orientation"), this, "GBOrientation"); + GBOrientation->setTitle(tr("ORIENTATION")); + GBOrientation->setColumnLayout(0, Qt::Vertical); + GBOrientation->layout()->setSpacing(0); + GBOrientation->layout()->setMargin(0); + QGridLayout* BGOrientationLayout = new QGridLayout (GBOrientation->layout()); + BGOrientationLayout->setAlignment(Qt::AlignTop); + BGOrientationLayout->setSpacing(6); + BGOrientationLayout->setMargin(11); + + QRadioButton *RBxy, *RByz, *RBzx; + RBxy = new QRadioButton (tr("// X-Y"), GBOrientation, "RBxy"); + RByz = new QRadioButton (tr("// Y-Z"), GBOrientation, "RByz"); + RBzx = new QRadioButton (tr("// Z-X"), GBOrientation, "RBzx"); + BGOrientationLayout->addWidget(RBxy, 0, 0); + BGOrientationLayout->addWidget(RByz, 0, 1); + BGOrientationLayout->addWidget(RBzx, 0, 2); + + // Rotation + + QGroupBox* GBrot = new QGroupBox (tr("ROTATIONS"), this, "GBrot"); + GBrot->setColumnLayout(0, Qt::Vertical); + GBrot->layout()->setSpacing(0); + GBrot->layout()->setMargin(0); + QGridLayout* GBrotLayout = new QGridLayout (GBrot->layout()); + GBrotLayout->setAlignment(Qt::AlignTop); + GBrotLayout->setSpacing(6); + GBrotLayout->setMargin(11); + // label 1 + LabelRot1 = new QLabel (tr("ROTATION_X"), GBrot, "LabelRot1"); + GBrotLayout->addWidget(LabelRot1, 0, 0); + // spin 1 + Rot1 = new QtxDblSpinBox (-180, 180, 5, GBrot); + Rot1->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed)); + GBrotLayout->addWidget(Rot1, 0, 1); + // label 2 + LabelRot2 = new QLabel (tr("ROTATION_Y"), GBrot, "LabelRot2"); + GBrotLayout->addWidget(LabelRot2, 1, 0); + // spin 2 + Rot2 = new QtxDblSpinBox (-180, 180, 5, GBrot); + Rot2->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed)); + GBrotLayout->addWidget(Rot2, 1, 1); + + // Position + + QGroupBox* GBpos = new QGroupBox (tr("POSITION"), this, "GBpos"); + GBpos->setColumnLayout(0, Qt::Horizontal); + GBpos->layout()->setSpacing(0); + GBpos->layout()->setMargin(0); + QGridLayout* GBposLayout = new QGridLayout (GBpos->layout()); + GBposLayout->setAlignment(Qt::AlignTop); + GBposLayout->setSpacing(6); + GBposLayout->setMargin(11); + // value label + QLabel * valueLabel = new QLabel (tr("POSITION_VALUE"), GBpos, "LabelRot1"); + GBposLayout->addWidget(valueLabel, 0, 0); + // value spin + PositionSpn = new QtxDblSpinBox (0, 1, 0.1, GBpos); + GBposLayout->addWidget(PositionSpn, 0, 1); + // Relative CheckBox + RelativeChkB = new QCheckBox (tr("RELATIVE"), GBpos, "RelativeChkB"); + RelativeChkB->setChecked(true); + GBposLayout->addWidget(RelativeChkB, 0, 2); + + // Scale, Presentation type, Nb Contours, Preview + + QFrame* bottomFrame = new QFrame (this); + QGridLayout* bottomLayout = new QGridLayout (bottomFrame); + bottomLayout->setAlignment(Qt::AlignTop); + bottomLayout->setSpacing(11); + bottomLayout->setMargin(0); + // scale + QLabel* scaleLabel = new QLabel (tr("SCALE"), bottomFrame); + ScaleSpn = new QtxDblSpinBox (-1.e6, 1.e6, 0.1, bottomFrame); + // Presentation type + GBPrsType = new QHButtonGroup (tr("PRESENTATION_TYPE"), bottomFrame); + new QRadioButton (tr("SURFACE"), GBPrsType); + new QRadioButton (tr("CONTOUR"), GBPrsType); + // nb Contours + QLabel* nbContLabel = new QLabel (tr("NUMBER_CONTOURS"), bottomFrame); + NbContoursSpn = new QSpinBox (1, 999, 1, bottomFrame, "NbContoursSpn"); + // Preview + PreviewChkB = new QCheckBox (tr("PREVIEW"), bottomFrame); + PreviewChkB->setChecked(false); + + bottomLayout->addWidget(scaleLabel, 0, 0); + bottomLayout->addWidget(ScaleSpn, 0, 1); + bottomLayout->addMultiCellWidget(GBPrsType, 1, 1, 0, 1); + bottomLayout->addWidget(nbContLabel, 2, 0); + bottomLayout->addWidget(NbContoursSpn, 2, 1); + bottomLayout->addWidget(PreviewChkB, 3, 0); + + // signals and slots connections + connect(GBOrientation, SIGNAL(clicked(int)), this, SLOT(orientationChanged(int))); + connect(Rot1, SIGNAL(valueChanged(double)), this, SLOT(updatePreview())); + connect(Rot2, SIGNAL(valueChanged(double)), this, SLOT(updatePreview())); + connect(PositionSpn, SIGNAL(valueChanged(double)), this, SLOT(onPositionSpn())); + connect(RelativeChkB, SIGNAL(toggled(bool)), this, SLOT(onRelativePos(bool))); + connect(GBPrsType, SIGNAL(clicked(int)), this, SLOT(onPrsType(int))); + connect(PreviewChkB, SIGNAL(toggled(bool)), this, SLOT(updatePreview())); +} + +//======================================================================= +//function : destructor +//purpose : +//======================================================================= +VisuGUI_Plot3DPane::~VisuGUI_Plot3DPane() +{ +} + +//======================================================================= +//function : storePrsParams +//purpose : create a copy of Prs parameters and then store current +// control values into the Prs +//======================================================================= +void VisuGUI_Plot3DPane::storePrsParams() +{ + if (!myPipeCopy) + myPipeCopy = VISU_Plot3DPL::New(); + if (myPrs) { + myPipeCopy->ShallowCopy(myPrs->GetPL()); + storeToPrsObject(myPrs); + } +} + +//======================================================================= +//function : restorePrsParams +//purpose : restore Prs parameters from the copy +//======================================================================= +void VisuGUI_Plot3DPane::restorePrsParams() +{ + if (!myPipeCopy) + myPipeCopy = VISU_Plot3DPL::New(); + if (myPrs) + myPrs->GetPL()->ShallowCopy(myPipeCopy); +} + +//======================================================================= +//function : onPositionSpn +//purpose : update absolute position range +//======================================================================= +void VisuGUI_Plot3DPane::onPositionSpn() +{ + if (myPrs && !RelativeChkB->isChecked()) { + float minPos, maxPos; + storePrsParams(); + myPrs->GetPlot3DPL()->GetMinMaxPosition(minPos, maxPos); + restorePrsParams(); + if (minPos > PositionSpn->value()) + minPos = PositionSpn->value(); + if (maxPos < PositionSpn->value()) + maxPos = PositionSpn->value(); + PositionSpn->setRange(minPos, maxPos); + } + updatePreview(); +} + +//======================================================================= +//function : orientationChanged +//purpose : update rotation labels and preview +//======================================================================= +void VisuGUI_Plot3DPane::orientationChanged(int Id) +{ + if (Id == 0) { // RBxy->isChecked() + LabelRot1->setText(tr("ROTATION_X")); + LabelRot2->setText(tr("ROTATION_Y")); + } else if (Id == 1) { // RByz->isChecked() + LabelRot1->setText(tr("ROTATION_Y")); + LabelRot2->setText(tr("ROTATION_Z")); + } else { + LabelRot1->setText(tr("ROTATION_Z")); + LabelRot2->setText(tr("ROTATION_X")); + } + updatePreview(); +} + +//======================================================================= +//function : onRelativePos +//purpose : update position value and range +//======================================================================= +void VisuGUI_Plot3DPane::onRelativePos(bool isRelativePos) +{ + float minPos = 0., maxPos = 1., pos = PositionSpn->value(); + if (myPrs) { + storePrsParams(); + myPrs->GetPlot3DPL()->GetMinMaxPosition(minPos, maxPos); + restorePrsParams(); + if (-1e-7 < (maxPos - minPos) && (maxPos - minPos) < 1e-7) { + pos = 0; + } else { + if (isRelativePos) // absolute -> relative + pos = (pos - minPos) / (maxPos - minPos); + else // relative -> absolute + pos = minPos * (1. - pos) + maxPos * pos; + } + } + if (isRelativePos) { + minPos = 0.; + maxPos = 1.; + } + PositionSpn->setMinValue(minPos); + PositionSpn->setMaxValue(maxPos); + PositionSpn->setLineStep((maxPos - minPos) / 10.); + PositionSpn->setValue(pos); +} + +//======================================================================= +//function : onPrsType +//purpose : +//======================================================================= +void VisuGUI_Plot3DPane::onPrsType(int id) +{ + NbContoursSpn->setEnabled(id == CONTOUR_PRS_ID); +} + +//======================================================================= +//function : updatePreview +//purpose : +//======================================================================= +void VisuGUI_Plot3DPane::updatePreview() +{ + if (myInitFromPrs || !myPrs || !myViewWindow) + return; + bool fitall = false; + if (PreviewChkB->isChecked()) // place preview plane + { + // get plane preview actor + TPlane* planePreview = (TPlane*) myPreviewActor; + if (!planePreview) { + myPreviewActor = planePreview = new TPlane(myPrs->GetInput()->GetLength()); + myViewWindow->AddActor(planePreview); + fitall = !VISU::GetActor(myPrs, myViewWindow); + } + // set plane parameters corresponding to control values + storePrsParams(); + float normal[3], origin[3]; + myPrs->GetPlot3DPL()->GetBasePlane(origin, normal, true); + planePreview->Set(origin, normal); + restorePrsParams(); + } + if (myPreviewActor) + myPreviewActor->SetVisibility(PreviewChkB->isChecked()); + + renderViewFrame(myViewWindow); + + if (fitall) { + myPreviewActor->SetInfinitive(false); + myViewWindow->onFitAll(); + myPreviewActor->SetInfinitive(true); + } +} + +//======================================================================= +//function : initFromPrsObject +//purpose : +//======================================================================= +void VisuGUI_Plot3DPane::initFromPrsObject(VISU::Plot3D_i* thePrs) +{ + myInitFromPrs = true; + myPrs = thePrs; + + // orientation + int id; + switch (thePrs->GetOrientationType()) { + case VISU::Plot3D::XY: id = 0; break; + case VISU::Plot3D::YZ: id = 1; break; + default: id = 2; + } + GBOrientation->setButton(id); + orientationChanged(id); + + // rotation + Rot1->setValue(thePrs->GetRotateX() * 180./PI); + Rot2->setValue(thePrs->GetRotateY() * 180./PI); + + // position + RelativeChkB->setChecked(thePrs->IsPositionRelative()); + onRelativePos(thePrs->IsPositionRelative()); // update range + PositionSpn->setValue(thePrs->GetPlanePosition()); + + // scale + ScaleSpn->setValue(thePrs->GetScaleFactor()); + + // prs type + id = thePrs->GetIsContourPrs() ? CONTOUR_PRS_ID : SURFACE_PRS_ID; + GBPrsType->setButton(id); + onPrsType(id); + + // nb contours + NbContoursSpn->setValue(thePrs->GetNbOfContours()); + + // disable cutting plane controls if the mesh is planar + + if (thePrs->GetPL()->IsPlanarInput()) + { + GBOrientation->setEnabled(false); + Rot1 ->setEnabled(false); + Rot2 ->setEnabled(false); + PositionSpn ->setEnabled(false); + RelativeChkB ->setEnabled(false); + PreviewChkB ->setEnabled(false); + } + + myInitFromPrs = false; + updatePreview(); +} + +//======================================================================= +//function : storeToPrsObject +//purpose : +//======================================================================= +int VisuGUI_Plot3DPane::storeToPrsObject(VISU::Plot3D_i* thePrs) +{ + if (myInitFromPrs) + return 0; + // orientation + int id = GBOrientation->id (GBOrientation->selected()); + VISU::Plot3D::Orientation ori; + switch (id) { + case 0 : ori = VISU::Plot3D::XY; break; + case 1 : ori = VISU::Plot3D::YZ; break; + default: ori = VISU::Plot3D::ZX; + } + // rotation + thePrs->SetOrientation(ori, Rot1->value()*PI/180., Rot2->value()*PI/180.); + + // position + thePrs->SetPlanePosition(PositionSpn->value(), RelativeChkB->isChecked()); + + // scale + thePrs->SetScaleFactor(ScaleSpn->value()); + + // prs type + id = GBPrsType->id (GBPrsType->selected()); + thePrs->SetContourPrs(id == CONTOUR_PRS_ID); + + // nb contours + thePrs->SetNbOfContours(NbContoursSpn->value()); + + return 1; +} + +//======================================================================= +//function : check +//purpose : +//======================================================================= +bool VisuGUI_Plot3DPane::check() +{ + if (myPreviewActor && myViewWindow) // erase preview + { + myPreviewActor->SetVisibility(false); + myViewWindow->RemoveActor(myPreviewActor); + myPreviewActor->Delete(); + myPreviewActor = 0; + } + + return true; +} + +//======================================================================= +//function : Constructor +//purpose : +//======================================================================= +VisuGUI_Plot3DDlg::VisuGUI_Plot3DDlg (SalomeApp_Module* theModule) + : QDialog(VISU::GetDesktop(theModule), "VisuGUI_Plot3DDlg", false, WStyle_Customize | + WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu) +{ + setCaption(tr("TITLE")); + setSizeGripEnabled(TRUE); + + QVBoxLayout* TopLayout = new QVBoxLayout(this); + TopLayout->setSpacing(6); + TopLayout->setMargin(11); + + QTabWidget* aTabBox = new QTabWidget (this); + myIsoPane = new VisuGUI_Plot3DPane (this); + myIsoPane->setMargin(5); + aTabBox->addTab(myIsoPane, tr("PLOT3D_TAB_TITLE")); + myScalarPane = new VisuGUI_ScalarBarPane (this, false); + myScalarPane->setMargin(5); + aTabBox->addTab(myScalarPane, tr("SCALAR_BAR_TAB_TITLE")); + + TopLayout->addWidget(aTabBox); + + QGroupBox* GroupButtons = new QGroupBox (this, "GroupButtons"); + GroupButtons->setGeometry(QRect(10, 10, 281, 48)); + GroupButtons->setColumnLayout(0, Qt::Vertical); + GroupButtons->layout()->setSpacing(0); + GroupButtons->layout()->setMargin(0); + QGridLayout* GroupButtonsLayout = new QGridLayout (GroupButtons->layout()); + GroupButtonsLayout->setAlignment(Qt::AlignTop); + GroupButtonsLayout->setSpacing(6); + GroupButtonsLayout->setMargin(11); + + QPushButton* buttonOk = new QPushButton (tr("&OK"), GroupButtons, "buttonOk"); + buttonOk->setAutoDefault(TRUE); + buttonOk->setDefault(TRUE); + GroupButtonsLayout->addWidget(buttonOk, 0, 0); + GroupButtonsLayout->addItem(new QSpacerItem (5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 1); + QPushButton* buttonCancel = new QPushButton (tr("&Cancel") , GroupButtons, "buttonCancel"); + buttonCancel->setAutoDefault(TRUE); + GroupButtonsLayout->addWidget(buttonCancel, 0, 2); + + TopLayout->addWidget(GroupButtons); + + // signals and slots connections + connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept())); + connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject())); +} + +//======================================================================= +//function : accept +//purpose : +//======================================================================= +void VisuGUI_Plot3DDlg::accept() +{ + if (myIsoPane->check() && myScalarPane->check()) + QDialog::accept(); +} + +//======================================================================= +//function : reject +//purpose : +//======================================================================= +void VisuGUI_Plot3DDlg::reject() +{ + myIsoPane->check(); // hide preview + + QDialog::reject(); +} diff --git a/src/VISUGUI/VisuGUI_Plot3DDlg.h b/src/VISUGUI/VisuGUI_Plot3DDlg.h new file mode 100644 index 00000000..a1e59f90 --- /dev/null +++ b/src/VISUGUI/VisuGUI_Plot3DDlg.h @@ -0,0 +1,119 @@ +// VISU VISUGUI : GUI of VISU component +// +// 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 : VisuGUI_Plot3DDlg.h +// Author : Laurent CORNABE & Hubert ROLLAND +// Module : VISU +// $Header$ + +#ifndef VISUGUI_PLOT3D_H +#define VISUGUI_PLOT3D_H + +#include "VisuGUI_ScalarBarDlg.h" + +#include "VISU_Plot3D_i.hh" + +#include + +class SalomeApp_Module; + +namespace VISU { + class Plot3D_i; +}; + +class VISU_Plot3DPL; +class SVTK_ViewWindow; +class SALOME_Actor; +class QtxDblSpinBox; + +class VisuGUI_Plot3DPane : public QVBox +{ + Q_OBJECT + + public: + VisuGUI_Plot3DPane(QWidget* parent); + ~VisuGUI_Plot3DPane(); + + void initFromPrsObject (VISU::Plot3D_i* thePrs); + int storeToPrsObject (VISU::Plot3D_i* thePrs); + + bool check(); + + VISU::Plot3D_i* GetPrs() { return myPrs; } + + private: + bool myInitFromPrs; + SALOME_Actor* myPreviewActor; + SVTK_ViewWindow* myViewWindow; + VISU::Plot3D_i* myPrs; + VISU_Plot3DPL* myPipeCopy; + + void storePrsParams(); + void restorePrsParams(); + + QButtonGroup * GBOrientation; + QLabel * LabelRot1; + QLabel * LabelRot2; + QtxDblSpinBox * Rot1; + QtxDblSpinBox * Rot2; + QtxDblSpinBox * PositionSpn; + QCheckBox * RelativeChkB; + QtxDblSpinBox * ScaleSpn; + QHButtonGroup * GBPrsType; + QSpinBox * NbContoursSpn; + QCheckBox * PreviewChkB; + + private slots: + + void orientationChanged( int ); + void onRelativePos( bool ); + void onPrsType( int ); + void onPositionSpn(); + void updatePreview(); +}; + + +class VisuGUI_Plot3DDlg : public QDialog +{ + Q_OBJECT + + public: + VisuGUI_Plot3DDlg (SalomeApp_Module* theModule); + ~VisuGUI_Plot3DDlg() {}; + + void initFromPrsObject (VISU::Plot3D_i* thePrs) + { myScalarPane->initFromPrsObject(thePrs); myIsoPane->initFromPrsObject(thePrs); } + + int storeToPrsObject (VISU::Plot3D_i* thePrs) + { return myScalarPane->storeToPrsObject(thePrs) && myIsoPane->storeToPrsObject(thePrs); } + + protected slots: + void accept(); + void reject(); + + private: + VisuGUI_Plot3DPane* myIsoPane; + VisuGUI_ScalarBarPane* myScalarPane; +}; + +#endif // VISUGUI_PLOT3D_H diff --git a/src/VISUGUI/VisuGUI_ScalarBarDlg.cxx b/src/VISUGUI/VisuGUI_ScalarBarDlg.cxx new file mode 100644 index 00000000..6a24502f --- /dev/null +++ b/src/VISUGUI/VisuGUI_ScalarBarDlg.cxx @@ -0,0 +1,923 @@ +// VISU VISUGUI : GUI of VISU component +// +// 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 : VisuGUI_ScalarBarDlg.cxx +// Author : Laurent CORNABE & Hubert ROLLAND +// Module : VISU +// $Header$ + +#include "VisuGUI_ScalarBarDlg.h" + +#include "VisuGUI.h" +#include "VisuGUI_Tools.h" +#include "VisuGUI_FontWg.h" + +#include "VISUConfig.hh" +#include "VISU_Convertor.hxx" + +#include "VISU_ScalarMapPL.hxx" +#include "VISU_ScalarMap_i.hh" + +#include "SalomeApp_Application.h" + +#include "SUIT_MessageBox.h" +#include "SUIT_ResourceMgr.h" + +#include +#include +#include +#include + +using namespace std; + + +VisuGUI_ScalarBarPane::VisuGUI_ScalarBarPane (QWidget * parent, bool SetPref): + QVBox(parent) +{ + myVerX = 0.01; myVerY = 0.10; myVerW = 0.10; myVerH = 0.80; + myHorX = 0.20; myHorY = 0.01; myHorW = 0.60; myHorH = 0.12; + Imin = 0.0; Imax = 0.0; /*Fmin = 0.0; Fmax = 0.0;*/ Rmin = 0.0; Rmax = 0.0; + myRangeMode = -1; + + setSpacing(6); + //setMargin(11); + + // Range ============================================================ + RangeGroup = new QButtonGroup (tr("SCALAR_RANGE_GRP"), this, "RangeGroup"); + RangeGroup->setColumnLayout(0, Qt::Vertical ); + RangeGroup->layout()->setSpacing( 0 ); + RangeGroup->layout()->setMargin( 0 ); + QGridLayout* RangeGroupLayout = new QGridLayout( RangeGroup->layout() ); + RangeGroupLayout->setAlignment( Qt::AlignTop ); + RangeGroupLayout->setSpacing( 6 ); + RangeGroupLayout->setMargin( 11 ); + + myModeLbl = new QLabel("Scalar Mode", RangeGroup); + + myModeCombo = new QComboBox(RangeGroup); + myModeCombo->insertItem("Modulus"); + myModeCombo->insertItem("Component 1"); + myModeCombo->insertItem("Component 2"); + myModeCombo->insertItem("Component 3"); + + CBLog = new QCheckBox (tr("LOGARITHMIC_SCALING"), RangeGroup); + CBLog->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + + RBFrange = new QRadioButton (tr("FIELD_RANGE_BTN"), RangeGroup, "RBFrange"); + RBIrange = new QRadioButton (tr("IMPOSED_RANGE_BTN"), RangeGroup, "RBIrange"); + RBFrange->setChecked( true ); + + MinEdit = new QLineEdit( RangeGroup, "MinEdit" ); + MinEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + MinEdit->setMinimumWidth( 70 ); + MinEdit->setValidator( new QDoubleValidator(this) ); + MinEdit->setText( "0.0" ); + QLabel* MinLabel = new QLabel (tr("LBL_MIN"), RangeGroup, "MinLabel"); + MinLabel->setBuddy(MinEdit); + + MaxEdit = new QLineEdit( RangeGroup, "MaxEdit" ); + MaxEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + MaxEdit->setMinimumWidth( 70 ); + MaxEdit->setValidator( new QDoubleValidator(this) ); + MaxEdit->setText( "0.0" ); + QLabel* MaxLabel = new QLabel (tr("LBL_MAX"), RangeGroup, "MaxLabel"); + MaxLabel->setBuddy(MaxEdit); + + RangeGroupLayout->addWidget( myModeLbl, 0, 0 ); + RangeGroupLayout->addMultiCellWidget( myModeCombo, 0, 0, 1, 3); + RangeGroupLayout->addMultiCellWidget( CBLog, 1, 1, 0, 3); + RangeGroupLayout->addMultiCellWidget( RBFrange, 2, 2, 0, 1); + RangeGroupLayout->addMultiCellWidget( RBIrange, 2, 2, 2, 3); + RangeGroupLayout->addWidget( MinLabel, 3, 0 ); + RangeGroupLayout->addWidget( MinEdit, 3, 1 ); + RangeGroupLayout->addWidget( MaxLabel, 3, 2 ); + RangeGroupLayout->addWidget( MaxEdit, 3, 3 ); + + //TopLayout->addWidget( RangeGroup ); + + // Colors and Labels ======================================================== + QGroupBox* ColLabGroup = new QGroupBox (tr("COLORS_LABELS_GRP"), this, "ColLabGroup"); + ColLabGroup->setColumnLayout(0, Qt::Vertical ); + ColLabGroup->layout()->setSpacing( 0 ); + ColLabGroup->layout()->setMargin( 0 ); + QGridLayout* ColLabGroupLayout = new QGridLayout( ColLabGroup->layout() ); + ColLabGroupLayout->setAlignment( Qt::AlignTop ); + ColLabGroupLayout->setSpacing( 6 ); + ColLabGroupLayout->setMargin( 11 ); + + QLabel* ColorLabel = new QLabel (tr("LBL_NB_COLORS"), ColLabGroup, "ColorLabel"); + ColorSpin = new QSpinBox( 2, 256, 1, ColLabGroup ); + ColorSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + ColorSpin->setMinimumWidth( 70 ); + ColorSpin->setValue( 64 ); + + QLabel* LabelLabel = new QLabel (tr("LBL_NB_LABELS"), ColLabGroup, "LabelLabel"); + LabelSpin = new QSpinBox( 2, 65, 1, ColLabGroup ); + LabelSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + LabelSpin->setMinimumWidth( 70 ); + LabelSpin->setValue( 5 ); + + ColLabGroupLayout->addWidget( ColorLabel, 0, 0); + ColLabGroupLayout->addWidget( ColorSpin, 0, 1); + ColLabGroupLayout->addWidget( LabelLabel, 0, 2); + ColLabGroupLayout->addWidget( LabelSpin, 0, 3); + + //TopLayout->addWidget( ColLabGroup ); + + // Orientation ========================================================== + QButtonGroup* OrientGroup = new QButtonGroup (tr("ORIENTATION_GRP"), this, "OrientGroup"); + OrientGroup->setColumnLayout(0, Qt::Vertical ); + OrientGroup->layout()->setSpacing( 0 ); + OrientGroup->layout()->setMargin( 0 ); + QGridLayout* OrientGroupLayout = new QGridLayout( OrientGroup->layout() ); + OrientGroupLayout->setAlignment( Qt::AlignTop ); + OrientGroupLayout->setSpacing( 6 ); + OrientGroupLayout->setMargin( 11 ); + + RBvert = new QRadioButton (tr("VERTICAL_BTN"), OrientGroup, "RBvert"); + RBvert->setChecked( true ); + RBhori = new QRadioButton (tr("HORIZONTAL_BTN"), OrientGroup, "RBhori"); + OrientGroupLayout->addWidget( RBvert, 0, 0 ); + OrientGroupLayout->addWidget( RBhori, 0, 1 ); + + // TopLayout->addWidget( OrientGroup ); + + // Origin =============================================================== + QGroupBox* OriginGroup = new QGroupBox (tr("ORIGIN_GRP"), this, "OriginGroup"); + OriginGroup->setColumnLayout(0, Qt::Vertical ); + OriginGroup->layout()->setSpacing( 0 ); + OriginGroup->layout()->setMargin( 0 ); + QGridLayout* OriginGroupLayout = new QGridLayout( OriginGroup->layout() ); + OriginGroupLayout->setAlignment( Qt::AlignTop ); + OriginGroupLayout->setSpacing( 6 ); + OriginGroupLayout->setMargin( 11 ); + + QLabel* XLabel = new QLabel (tr("LBL_X"), OriginGroup, "XLabel"); + XSpin = new QtxDblSpinBox( 0.0, 1.0, 0.1, OriginGroup ); + XSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + XSpin->setMinimumWidth( 70 ); + XSpin->setValue( 0.01 ); + + QLabel* YLabel = new QLabel (tr("LBL_Y"), OriginGroup, "YLabel"); + YSpin = new QtxDblSpinBox( 0.0, 1.0, 0.1, OriginGroup ); + YSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + YSpin->setMinimumWidth( 70 ); + YSpin->setValue( 0.01 ); + + OriginGroupLayout->addWidget( XLabel, 0, 0); + OriginGroupLayout->addWidget( XSpin, 0, 1); + OriginGroupLayout->addWidget( YLabel, 0, 2); + OriginGroupLayout->addWidget( YSpin, 0, 3); + + //TopLayout->addWidget( OriginGroup ); + + // Dimensions ========================================================= + QGroupBox* DimGroup = new QGroupBox (tr("DIMENSIONS_GRP"), this, "DimGroup"); + DimGroup->setColumnLayout(0, Qt::Vertical ); + DimGroup->layout()->setSpacing( 0 ); + DimGroup->layout()->setMargin( 0 ); + QGridLayout* DimGroupLayout = new QGridLayout( DimGroup->layout() ); + DimGroupLayout->setAlignment( Qt::AlignTop ); + DimGroupLayout->setSpacing( 6 ); + DimGroupLayout->setMargin( 11 ); + + QLabel* WidthLabel = new QLabel (tr("LBL_WIDTH"), DimGroup, "WidthLabel"); + WidthSpin = new QtxDblSpinBox( 0.0, 1.0, 0.1, DimGroup ); + WidthSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + WidthSpin->setMinimumWidth( 70 ); + WidthSpin->setValue( 0.1 ); + + QLabel* HeightLabel = new QLabel (tr("LBL_HEIGHT"), DimGroup, "HeightLabel"); + HeightSpin = new QtxDblSpinBox( 0.0, 1.0, 0.1, DimGroup ); + HeightSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + HeightSpin->setMinimumWidth( 70 ); + HeightSpin->setValue( 0.8 ); + + DimGroupLayout->addWidget( WidthLabel, 0, 0); + DimGroupLayout->addWidget( WidthSpin, 0, 1); + DimGroupLayout->addWidget( HeightLabel, 0, 2); + DimGroupLayout->addWidget( HeightSpin, 0, 3); + + //TopLayout->addWidget( DimGroup ); + + // Save check box =========================================================== + QHBox* aSaveBox = new QHBox(this); + if (!SetPref) { + CBSave = new QCheckBox (tr("SAVE_DEFAULT_CHK"), aSaveBox, "CBSave"); + //TopLayout->addWidget(CBSave); + } + else { + CBSave = 0; + } + myTextBtn = new QPushButton("Text properties...", aSaveBox); + myTextDlg = new VisuGUI_TextPrefDlg(this); + myTextDlg->setTitleVisible(!SetPref); + + // signals and slots connections =========================================== + connect( RangeGroup, SIGNAL( clicked( int ) ), this, SLOT( changeRange( int ) ) ); + connect( OrientGroup, SIGNAL( clicked( int ) ), this, SLOT( changeDefaults( int ) ) ); + connect( XSpin, SIGNAL( valueChanged( double ) ), this, SLOT( XYChanged( double ) ) ); + connect( YSpin, SIGNAL( valueChanged( double ) ), this, SLOT( XYChanged( double ) ) ); + connect( myTextBtn, SIGNAL( clicked() ), this, SLOT( onTextPref() ) ); + + changeRange( 0 ); + changeDefaults( 0 ); + myIsStoreTextProp = false; +} + + +/** + * Initializes dialog box values from resources + */ +void VisuGUI_ScalarBarPane::initFromResources() { + int sbCol=64,sbLab=5,orient=0; + float sbX1=0.01,sbY1=0.1,sbW=0.1,sbH=0.8; + float sbVmin=0., sbVmax=0.; + bool sbRange=false; + QString aString; + + SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr(); + + int aScalarMode = aResourceMgr->integerValue("VISU", "scalar_bar_mode", 0); + myModeCombo->setCurrentItem(aScalarMode); + + orient = aResourceMgr->integerValue("VISU", "scalar_bar_orientation", orient); + if(orient != 0){ + orient=1; + sbX1=0.2; + sbY1=0.01; + sbW=0.6; + sbH=0.12; + } + + QString propertyName = QString( "scalar_bar_%1_" ).arg( orient == 0 ? "vertical" : "horizontal" ); + + sbX1 = aResourceMgr->doubleValue("VISU", propertyName + "x", sbX1); + sbY1 = aResourceMgr->doubleValue("VISU", propertyName + "y", sbY1); + + sbW = aResourceMgr->doubleValue("VISU", propertyName + "width", sbW); + sbH = aResourceMgr->doubleValue("VISU", propertyName + "height",sbH); + + sbCol = aResourceMgr->integerValue("VISU" ,"scalar_bar_num_colors", sbCol); + sbLab = aResourceMgr->integerValue("VISU", "scalar_bar_num_labels", sbLab); + + int rangeType = aResourceMgr->integerValue("VISU" , "scalar_range_type", 0); + if (rangeType == 1) sbRange = true; + sbVmin = aResourceMgr->doubleValue("VISU", "scalar_range_min", sbVmin); + sbVmax = aResourceMgr->doubleValue("VISU", "scalar_range_max", sbVmax); + + bool isLog = aResourceMgr->booleanValue("VISU", "scalar_bar_logarithmic", false); + setLogarithmic(isLog); + + if((sbX1 < 0.) || (sbY1 < 0.) || + ((sbX1+sbW) > 1.) || ((sbY1+sbH) > 1.)) { + if(orient == 0) { + sbX1=0.01; + sbY1=0.1; + sbW=0.1; + sbH=0.8; + } else { + sbX1=0.2; + sbY1=0.01; + sbW=0.6; + sbH=0.12; + } + } + if(sbCol < 2) sbCol=2; + if(sbCol > 64) sbCol=64; + if(sbLab < 2) sbLab=2; + if(sbLab > 65) sbLab=65; + + if(sbVmin > sbVmax) { + sbVmin=0.; + sbVmax=0.; + } + + setRange( sbVmin, sbVmax, /*0.0, 0.0,*/ sbRange ); + setPosAndSize( sbX1, sbY1, sbW, sbH, orient == 0); + setScalarBarData( sbCol, sbLab ); + + // "Title" + bool isBold = false, isItalic = false, isShadow = false; + int aFontFamily = VTK_ARIAL; + + if ( aResourceMgr->hasValue( "VISU", "scalar_bar_title_font" ) ) + { + QFont f = aResourceMgr->fontValue( "VISU", "scalar_bar_title_font" ); + + if ( f.family() == "Arial" ) + aFontFamily = VTK_ARIAL; + else if ( f.family() == "Courier" ) + aFontFamily = VTK_COURIER; + else if ( f.family() == "Times" ) + aFontFamily = VTK_TIMES; + + isBold = f.bold(); + isItalic = f.italic(); + isShadow = f.underline(); + } + + QColor aTextColor = aResourceMgr->colorValue( "VISU", "scalar_bar_title_color", QColor( 255, 255, 255 ) ); + + myTextDlg->myTitleFont->SetData(aTextColor, aFontFamily, isBold, isItalic, isShadow); + + // "Labels" + isBold = isItalic = isShadow = false; + aFontFamily = VTK_ARIAL; + + if ( aResourceMgr->hasValue( "VISU", "scalar_bar_label_font" ) ) + { + QFont f = aResourceMgr->fontValue( "VISU", "scalar_bar_label_font" ); + + if ( f.family() == "Arial" ) + aFontFamily = VTK_ARIAL; + else if ( f.family() == "Courier" ) + aFontFamily = VTK_COURIER; + else if ( f.family() == "Times" ) + aFontFamily = VTK_TIMES; + + isBold = f.bold(); + isItalic = f.italic(); + isShadow = f.underline(); + } + + aTextColor = aResourceMgr->colorValue( "VISU", "scalar_bar_label_color", QColor( 255, 255, 255 ) ); + + myTextDlg->myLabelFont->SetData(aTextColor, aFontFamily, isBold, isItalic, isShadow); +} + +/** + * Stores dialog values to resources + */ +void VisuGUI_ScalarBarPane::storeToResources() { + int orient = (RBvert->isChecked())? 0 : 1; + float sbX1 = XSpin->value(); + float sbY1 = YSpin->value(); + float sbW = WidthSpin->value(); + float sbH = HeightSpin->value(); + int sbCol = ColorSpin->value(); + int sbLab = LabelSpin->value(); + + if((sbX1 < 0.) || (sbY1 < 0.) || ((sbX1+sbW) > 1.) || ((sbY1+sbH) > 1.)) { + if(orient == 0) { + sbX1=0.01; + sbY1=0.1; + sbW=0.17; + sbH=0.8; + } else { + sbX1=0.2; + sbY1=0.01; + sbW=0.6; + sbH=0.12; + } + } + + bool sbRange = RBIrange->isChecked(); + float sbVmin = (float)(MinEdit->text().toDouble()); + float sbVmax = (float)(MaxEdit->text().toDouble()); + + if(sbVmin > sbVmax) { + sbVmin=0.; + sbVmax=0.; + } + + SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr(); + + aResourceMgr->setValue("VISU", "scalar_bar_orientation", orient); + + QString propertyName = QString( "scalar_bar_%1_" ).arg( orient == 0 ? "vertical" : "horizontal" ); + + aResourceMgr->setValue("VISU", propertyName + "x", sbX1); + aResourceMgr->setValue("VISU", propertyName + "y", sbY1); + aResourceMgr->setValue("VISU", propertyName + "width", sbW); + aResourceMgr->setValue("VISU", propertyName + "height", sbH); + + aResourceMgr->setValue("VISU", "scalar_bar_num_colors", sbCol); + aResourceMgr->setValue("VISU", "scalar_bar_num_labels", sbLab); + + if(sbRange) + { + aResourceMgr->setValue("VISU", "scalar_range_type", 1); + aResourceMgr->setValue("VISU", "scalar_range_min" ,sbVmin); + aResourceMgr->setValue("VISU", "scalar_range_max" ,sbVmax); + } + else + aResourceMgr->setValue("VISU", "scalar_range_type", 0); + + aResourceMgr->setValue("VISU", "scalar_bar_logarithmic", isLogarithmic()); + + //// + + if (myIsStoreTextProp) { + // "Title" + QColor aTitleColor (255, 255, 255); + int aTitleFontFamily = VTK_ARIAL; + bool isTitleBold = false; + bool isTitleItalic = false; + bool isTitleShadow = false; + + myTextDlg->myTitleFont->GetData(aTitleColor, aTitleFontFamily, + isTitleBold, isTitleItalic, isTitleShadow); + + QFont aTitleFont; + + aTitleFont.setBold(isTitleBold); + aTitleFont.setItalic(isTitleItalic); + aTitleFont.setUnderline(isTitleShadow); + + QString titleFontFamily; + switch (aTitleFontFamily) { + case VTK_ARIAL: + titleFontFamily = "Arial"; + break; + case VTK_COURIER: + titleFontFamily = "Courier"; + break; + case VTK_TIMES: + titleFontFamily = "Times"; + break; + } + aTitleFont.setFamily(titleFontFamily); + + aResourceMgr->setValue("VISU", "scalar_bar_title_font", aTitleFont); + + aResourceMgr->setValue("VISU", "scalar_bar_title_color", aTitleColor); + + // "Label" + QColor aLabelColor (255, 255, 255); + int aLabelFontFamily = VTK_ARIAL; + bool isLabelBold = false; + bool isLabelItalic = false; + bool isLabelShadow = false; + + myTextDlg->myLabelFont->GetData(aLabelColor, aLabelFontFamily, + isLabelBold, isLabelItalic, isLabelShadow); + + + QFont aLabelFont; + + aLabelFont.setBold(isLabelBold); + aLabelFont.setItalic(isLabelItalic); + aLabelFont.setUnderline(isLabelShadow); + + QString labelFontFamily; + switch (aLabelFontFamily) { + case VTK_ARIAL: + labelFontFamily = "Arial"; + break; + case VTK_COURIER: + labelFontFamily = "Courier"; + break; + case VTK_TIMES: + labelFontFamily = "Times"; + break; + } + + aLabelFont.setFamily(labelFontFamily); + + aResourceMgr->setValue("VISU", "scalar_bar_label_font", aLabelFont); + + aResourceMgr->setValue("VISU", "scalar_bar_label_color", aLabelColor); + } +} + +/** + * Initialise dialog box from presentation object + */ +void VisuGUI_ScalarBarPane::initFromPrsObject(VISU::ScalarMap_i* thePrs) { + initFromResources(); + myModeCombo->setCurrentItem(thePrs->GetScalarMode()); + setPosAndSize( thePrs->GetPosX(), + thePrs->GetPosY(), + thePrs->GetWidth(), + thePrs->GetHeight(), + thePrs->GetBarOrientation()); + switch(thePrs->GetScaling()){ + case VISU::LOGARITHMIC : + setLogarithmic(true); + break; + default: + setLogarithmic(false); + } + float aRange[2]; + thePrs->GetScalarMapPL()->GetSourceRange(aRange); + Rmin = aRange[0]; Rmax = aRange[1]; + setRange( thePrs->GetMin(), thePrs->GetMax(), + /*0.0, 0.0,*/ thePrs->IsRangeFixed() ); + setScalarBarData( thePrs->GetNbColors(), thePrs->GetLabels() ); + bool isScalarMode = (thePrs->GetField()->myNbComp > 1); + myModeLbl->setEnabled(isScalarMode); + myModeCombo->setEnabled(isScalarMode); + + // "Title" + myTextDlg->setTitleText(QString(thePrs->GetTitle())); + + float R, G, B; + thePrs->GetTitleColor(&R, &G, &B); + + myTextDlg->myTitleFont->SetData(QColor((int)(R*255.), (int)(G*255.), (int)(B*255.)), + thePrs->GetTitFontType(), + thePrs->IsBoldTitle(), + thePrs->IsItalicTitle(), + thePrs->IsShadowTitle()); + + // "Labels" + thePrs->GetLabelColor(&R, &G, &B); + + myTextDlg->myLabelFont->SetData(QColor((int)(R*255.), (int)(G*255.), (int)(B*255.)), + thePrs->GetLblFontType(), + thePrs->IsBoldLabel(), + thePrs->IsItalicLabel(), + thePrs->IsShadowLabel()); +} + +/** + * Store values to presentation object + */ +int VisuGUI_ScalarBarPane::storeToPrsObject(VISU::ScalarMap_i* thePrs) { + thePrs->SetScalarMode(myModeCombo->currentItem()); + thePrs->SetPosition(XSpin->value(), YSpin->value()); + thePrs->SetSize(WidthSpin->value(), HeightSpin->value()); + thePrs->SetBarOrientation((RBvert->isChecked())? VISU::ScalarMap::VERTICAL : VISU::ScalarMap::HORIZONTAL); + if(isLogarithmic()) + thePrs->SetScaling(VISU::LOGARITHMIC); + else + thePrs->SetScaling(VISU::LINEAR); + + if (RBFrange->isChecked()) { + thePrs->SetSourceRange(); + } else { + thePrs->SetRange(MinEdit->text().toDouble(), MaxEdit->text().toDouble()); + } + thePrs->SetNbColors(ColorSpin->value()); + thePrs->SetLabels(LabelSpin->value()); + + if (isToSave()) storeToResources(); + + if (myIsStoreTextProp) { + // "Title" + thePrs->SetTitle(myTextDlg->getTitleText().latin1()); + + QColor aTitColor (255, 255, 255); + int aTitleFontFamily = VTK_ARIAL; + bool isTitleBold = false; + bool isTitleItalic = false; + bool isTitleShadow = false; + + myTextDlg->myTitleFont->GetData(aTitColor, aTitleFontFamily, + isTitleBold, isTitleItalic, isTitleShadow); + + thePrs->SetBoldTitle(isTitleBold); + thePrs->SetItalicTitle(isTitleItalic); + thePrs->SetShadowTitle(isTitleShadow); + thePrs->SetTitFontType(aTitleFontFamily); + thePrs->SetTitleColor(aTitColor.red()/255., + aTitColor.green()/255., + aTitColor.blue()/255.); + + // "Label" + QColor aLblColor (255, 255, 255); + int aLabelFontFamily = VTK_ARIAL; + bool isLabelBold = false; + bool isLabelItalic = false; + bool isLabelShadow = false; + + myTextDlg->myLabelFont->GetData(aLblColor, aLabelFontFamily, + isLabelBold, isLabelItalic, isLabelShadow); + + thePrs->SetBoldLabel(isLabelBold); + thePrs->SetItalicLabel(isLabelItalic); + thePrs->SetShadowLabel(isLabelShadow); + thePrs->SetLblFontType(aLabelFontFamily); + thePrs->SetLabelColor(aLblColor.red()/255., + aLblColor.green()/255., + aLblColor.blue()/255.); + } + + return 1; +} + +/*! + Called when orientation is changed +*/ +void VisuGUI_ScalarBarPane::changeDefaults( int ) +{ + if ( RBvert->isChecked() ) { + XSpin->setValue( myVerX ); + YSpin->setValue( myVerY ); + WidthSpin->setValue( myVerW ); + HeightSpin->setValue( myVerH ); + } + else { + XSpin->setValue( myHorX ); + YSpin->setValue( myHorY ); + WidthSpin->setValue( myHorW ); + HeightSpin->setValue( myHorH ); + } +} + +/*! + Called when Range mode is changed +*/ +void VisuGUI_ScalarBarPane::changeRange( int ) +{ + int mode = -1; + if ( RBFrange->isChecked() ) + mode = 0; + if ( RBIrange->isChecked() ) + mode = 1; + if ( myRangeMode == mode ) + return; + //MinSpin->setMaxValue( Fmin ); + //MaxSpin->setMinValue( Fmax ); + if ( RBFrange->isChecked() ) { + //MinLabel->setEnabled( false ); + MinEdit->setEnabled( false ); + //MaxLabel->setEnabled( false ); + MaxEdit->setEnabled( false ); + if ( mode != -1 ) { + Imin = MinEdit->text().toDouble(); + Imax = MaxEdit->text().toDouble(); + } + MinEdit->setText( QString::number( Rmin ) ); + MaxEdit->setText( QString::number( Rmax ) ); + } + else { + //MinLabel->setEnabled( true ); + MinEdit->setEnabled( true ); + //MaxLabel->setEnabled( true ); + MaxEdit->setEnabled( true ); + MinEdit->setText( QString::number( Imin ) ); + MaxEdit->setText( QString::number( Imax ) ); + } + myRangeMode = mode; +} + +/*! + Called when X,Y position is changed +*/ +void VisuGUI_ScalarBarPane::XYChanged( double ) +{ + QtxDblSpinBox* snd = (QtxDblSpinBox*)sender(); + if ( snd == XSpin ) { + WidthSpin->setMaxValue( 1.0 - XSpin->value() ); + } + if ( snd == YSpin ) { + HeightSpin->setMaxValue( 1.0 - YSpin->value() ); + } +} + +/*! + Sets default values and range mode +*/ +void VisuGUI_ScalarBarPane::setRange( double imin, double imax/*, double fmin, double fmax*/, bool sbRange ) +{ + Imin = imin; Imax = imax;// Fmin = fmin; Fmax = fmax; + if ( RBIrange->isChecked() ) { + MinEdit->setText( QString::number( Imin ) ); + MaxEdit->setText( QString::number( Imax ) ); + } + else { + MinEdit->setText( QString::number( Rmin ) ); + MaxEdit->setText( QString::number( Rmax ) ); + } + myRangeMode = -1; + if( sbRange ) + RBIrange->setChecked( true ); + else + RBFrange->setChecked( true ); + changeRange( 0 ); +} + +/*! + Sets size and position +*/ +void VisuGUI_ScalarBarPane::setPosAndSize( double x, double y, double w, double h, bool vert ) +{ + if ( vert ) { + myVerX = x; + myVerY = y; + myVerW = w; + myVerH = h; + RBvert->setChecked( true ); + } + else { + myHorX = x; + myHorY = y; + myHorW = w; + myHorH = h; + RBhori->setChecked( true ); + } + changeDefaults( 0 ); +} + +/*! + Sets colors and labels number +*/ +void VisuGUI_ScalarBarPane::setScalarBarData( int colors, int labels ) +{ + ColorSpin->setValue( colors ); + LabelSpin->setValue( labels ); +} + +/*! + Gets orientation +*/ +int VisuGUI_ScalarBarPane::getOrientation() +{ + if (RBvert->isChecked() ) + return 1; + else + return 0; +} + +/*! + Called when button is clicked, validates data and closes dialog +*/ +bool VisuGUI_ScalarBarPane::check() +{ + double minVal = MinEdit->text().toDouble(); + double maxVal = MaxEdit->text().toDouble(); + if ( RBIrange->isChecked() ) { + if (minVal >= maxVal) { + SUIT_MessageBox::warn1( this,tr("WRN_VISU"), + tr("MSG_MINMAX_VALUES"), + tr("BUT_OK")); + return false; + } + } + // check if logarithmic mode is on and check imposed range to not contain negative values + if ( CBLog->isChecked() ) { + if ( RBIrange->isChecked() ) { + if ( (minVal > 0) && (maxVal > 0) ) { + // nothing to do + } + else { + SUIT_MessageBox::warn1( this, + tr("WRN_VISU"), + tr("WRN_LOGARITHMIC_RANGE"), + tr("BUT_OK")); + return false; + } + } + else { + if ( Rmin > 0 && Rmax > 0 ) { + // nothing to do + } + else { + SUIT_MessageBox::warn1( this, + tr("WRN_VISU"), + tr("WRN_LOGARITHMIC_FIELD_RANGE"), + tr("BUT_OK")); + RBIrange->setChecked(1); + changeRange(1); + //MinEdit->setText( QString::number( Rmin ) ); + //MaxEdit->setText( QString::number( Rmax ) ); + return false; + } + } + } + return true; +} + +void VisuGUI_ScalarBarPane::onTextPref() +{ + myIsStoreTextProp = myTextDlg->exec(); +} + + +//####################################################################################### + +/*! + Constructor +*/ +VisuGUI_ScalarBarDlg::VisuGUI_ScalarBarDlg (SalomeApp_Module* theModule, bool SetPref) + : QDialog(VISU::GetDesktop(theModule), 0, true, + WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu) +{ + setName("VisuGUI_ScalarBarDlg"); + setCaption(SetPref ? tr("DLG_PREF_TITLE") : tr("DLG_PROP_TITLE")); + setSizeGripEnabled(TRUE); + + QVBoxLayout* TopLayout = new QVBoxLayout(this); + TopLayout->setSpacing(6); + TopLayout->setMargin(11); + + myScalarPane = new VisuGUI_ScalarBarPane(this, SetPref); + TopLayout->addWidget(myScalarPane); + + // Common buttons =========================================================== + QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" ); + GroupButtons->setColumnLayout(0, Qt::Vertical ); + GroupButtons->layout()->setSpacing( 0 ); + GroupButtons->layout()->setMargin( 0 ); + QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() ); + GroupButtonsLayout->setAlignment( Qt::AlignTop ); + GroupButtonsLayout->setSpacing( 6 ); + GroupButtonsLayout->setMargin( 11 ); + + QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons, "buttonOk" ); + buttonOk->setAutoDefault( TRUE ); + buttonOk->setDefault( TRUE ); + GroupButtonsLayout->addWidget( buttonOk, 0, 0 ); + GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 ); + + QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons, "buttonCancel" ); + buttonCancel->setAutoDefault( TRUE ); + GroupButtonsLayout->addWidget( buttonCancel, 0, 2 ); + + TopLayout->addWidget( GroupButtons ); + + connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) ); + connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) ); +} + +/*! + Called when button is clicked, validates data and closes dialog +*/ +void VisuGUI_ScalarBarDlg::accept() +{ + if (myScalarPane->check()) QDialog::accept(); +} + + +//####################################################################################### +VisuGUI_TextPrefDlg::VisuGUI_TextPrefDlg (QWidget* parent) + : QDialog(parent, 0, true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu) +{ + setName("VisuGUI_TextPrefDlg"); + setCaption(tr("TIT_TEXT_PREF")); + setSizeGripEnabled(TRUE); + + QVBoxLayout* TopLayout = new QVBoxLayout(this); + TopLayout->setSpacing(6); + TopLayout->setMargin(11); + + // "Title" grp + QGroupBox* aTitleGrp = new QGroupBox (2, Qt::Vertical, tr("LBL_TITLE"), this); + + // edit line + myTitleEdt = new QLineEdit (aTitleGrp); + + // font + QHBox* aHBox = new QHBox (aTitleGrp); + aHBox->setSpacing(5); + myTitleFont = new VisuGUI_FontWg (aHBox); + + TopLayout->addWidget(aTitleGrp); + + // "Labels" grp + QGroupBox* aLabelsGrp = new QGroupBox (1, Qt::Vertical, tr("LBL_LABELS"), this); + + // font + aHBox = new QHBox (aLabelsGrp); + aHBox->setSpacing(5); + myLabelFont = new VisuGUI_FontWg (aHBox); + + TopLayout->addWidget(aLabelsGrp); + + // Common buttons =========================================================== + QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" ); + GroupButtons->setColumnLayout(0, Qt::Vertical ); + GroupButtons->layout()->setSpacing( 0 ); + GroupButtons->layout()->setMargin( 0 ); + QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() ); + GroupButtonsLayout->setAlignment( Qt::AlignTop ); + GroupButtonsLayout->setSpacing( 6 ); + GroupButtonsLayout->setMargin( 11 ); + + QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons, "buttonOk" ); + buttonOk->setAutoDefault( TRUE ); + buttonOk->setDefault( TRUE ); + GroupButtonsLayout->addWidget( buttonOk, 0, 0 ); + GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 ); + + QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons, "buttonCancel" ); + buttonCancel->setAutoDefault( TRUE ); + GroupButtonsLayout->addWidget( buttonCancel, 0, 2 ); + + TopLayout->addWidget( GroupButtons ); + + connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept())); + connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject())); +} diff --git a/src/VISUGUI/VisuGUI_ScalarBarDlg.h b/src/VISUGUI/VisuGUI_ScalarBarDlg.h new file mode 100644 index 00000000..c8ddc6ab --- /dev/null +++ b/src/VISUGUI/VisuGUI_ScalarBarDlg.h @@ -0,0 +1,184 @@ +// VISU VISUGUI : GUI of VISU component +// +// 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 : VisuGUI_ScalarBarDlg.h +// Author : Laurent CORNABE & Hubert ROLLAND +// Module : VISU +// $Header$ + +#ifndef VISUGUI_SCALARBARDLG_H +#define VISUGUI_SCALARBARDLG_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "QtxDblSpinBox.h" + +#include "VISU_ScalarMap_i.hh" + +class QButtonGroup; +class QGroupBox; +class QLabel; +class QRadioButton; +class QCheckBox; +class QPushButton; +class QSpinBox; +class QLineEdit; +class QComboBox; +class QVBox; +class QToolButton; + +class QtxDblSpinBox; +class SalomeApp_Module; +class VisuGUI_FontWg; + +class VisuGUI_TextPrefDlg: public QDialog +{ + Q_OBJECT; + + public: + VisuGUI_TextPrefDlg (QWidget* parent); + ~VisuGUI_TextPrefDlg() {}; + + QString getTitleText() { return myTitleEdt->text(); } + void setTitleText(QString theText) { myTitleEdt->setText(theText); } + + void setTitleVisible (bool isVisible) + { (isVisible)? myTitleEdt->show() : myTitleEdt->hide(); } + + public: + VisuGUI_FontWg* myTitleFont; + VisuGUI_FontWg* myLabelFont; + + private: + QLineEdit* myTitleEdt; +}; + + +class VisuGUI_ScalarBarPane : public QVBox +{ + Q_OBJECT; + + public: + VisuGUI_ScalarBarPane(QWidget* parent, bool SetPref); + ~VisuGUI_ScalarBarPane() {}; + + void setRange( double imin, double imax, /*double fmin, double fmax,*/ bool sbRange ); + bool isIRange() {return RBIrange->isChecked();} + double getMin() {return MinEdit->text().toDouble();} + double getMax() {return MaxEdit->text().toDouble();} + int getOrientation(); + void setPosAndSize( double x, double y, double w, double h, bool vert ); + double getX() {return XSpin->value();} + double getY() {return YSpin->value();} + double getWidth() {return WidthSpin->value();} + double getHeight() {return HeightSpin->value();} + void setScalarBarData( int colors, int labels ); + int getNbColors() {return ColorSpin->value();} + int getNbLabels() {return LabelSpin->value();} + bool isLogarithmic() {return CBLog->isChecked();} + void setLogarithmic( bool on ) {CBLog->setChecked( on );} + bool isToSave() {return CBSave ? CBSave->isChecked() : false;} + + void initFromResources(); + void storeToResources(); + + void initFromPrsObject(VISU::ScalarMap_i* thePrs); + int storeToPrsObject(VISU::ScalarMap_i* thePrs); + + bool check(); + + protected: + QButtonGroup* RangeGroup; + QRadioButton* RBFrange; + QRadioButton* RBIrange; + QLineEdit* MinEdit; + QLineEdit* MaxEdit; + + QRadioButton* RBhori; + QRadioButton* RBvert; + + QtxDblSpinBox* XSpin; + QtxDblSpinBox* YSpin; + + QtxDblSpinBox* WidthSpin; + QtxDblSpinBox* HeightSpin; + + QSpinBox* ColorSpin; + QSpinBox* LabelSpin; + + QCheckBox* CBSave; + QCheckBox* CBLog; + QLabel* myModeLbl; + QComboBox* myModeCombo; + QPushButton* myTextBtn; + VisuGUI_TextPrefDlg* myTextDlg; + + double Imin, Imax, /* Fmin, Fmax,*/ Rmin, Rmax; + double myHorX, myHorY, myHorW, myHorH; + double myVerX, myVerY, myVerW, myVerH; + int myRangeMode; + bool myIsStoreTextProp; + + private slots: + void changeDefaults( int ); + void changeRange( int ); + void XYChanged( double ); + void onTextPref(); +}; + + +class VisuGUI_ScalarBarDlg : public QDialog +{ + Q_OBJECT; + + public: + VisuGUI_ScalarBarDlg (SalomeApp_Module* theModule, bool SetPref = FALSE); + ~VisuGUI_ScalarBarDlg() {}; + + bool isToSave() {return myScalarPane->isToSave();} + + void initFromResources() {myScalarPane->initFromResources();} + void storeToResources() {myScalarPane->storeToResources();} + + void initFromPrsObject(VISU::ScalarMap_i* thePrs) {myScalarPane->initFromPrsObject(thePrs);} + int storeToPrsObject(VISU::ScalarMap_i* thePrs) {return myScalarPane->storeToPrsObject(thePrs);} + + protected slots: + void accept(); + + protected: + VisuGUI_ScalarBarPane* myScalarPane; +}; + +#endif // VISUGUI_SCALARBARDLG_H diff --git a/src/VISUGUI/VisuGUI_Selection.cxx b/src/VISUGUI/VisuGUI_Selection.cxx new file mode 100644 index 00000000..433b6467 --- /dev/null +++ b/src/VISUGUI/VisuGUI_Selection.cxx @@ -0,0 +1,600 @@ +// VISU VISUGUI : GUI of VISU component +// +// 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 : VisuGUI_Selection.cxx +// Author : Laurent CORNABE & Hubert ROLLAND +// Module : VISU +// $Header$ + +#include "VisuGUI_Selection.h" + +#include "VisuGUI.h" +#include "VisuGUI_Tools.h" + +#include "VISU_Actor.h" +#include "VISU_PrsObject_i.hh" +#include "VISU_Prs3d_i.hh" +#include "VISU_PipeLine.hxx" + +#include "SalomeApp_Study.h" +#include "SalomeApp_Application.h" +#include "SalomeApp_SelectionMgr.h" +#include "SalomeApp_VTKSelector.h" + +#include "SUIT_MessageBox.h" +#include "SUIT_ViewWindow.h" +#include "SUIT_Session.h" + +#include "SALOME_ListIO.hxx" +#include "SALOME_ListIteratorOfListIO.hxx" + +#include "SVTK_ViewWindow.h" +#include "SVTK_ViewModel.h" +#include "SVTK_Selector.h" + +#include "utilities.h" + +// OCCT Includes +#include +#include + +// QT Includes +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// VTK Includes +#include +#include +#include +#include +#include + +// STL Includes +#include + +using namespace std; + +static VisuGUI_SelectionDlg* mySelectionDlg = NULL; + +VisuGUI_SelectionDlg::VisuGUI_SelectionDlg (QWidget* parent) + : QDialog(parent, 0, false, WStyle_Customize | WStyle_NormalBorder | + WStyle_Title | WStyle_SysMenu | WDestructiveClose), + mySelectionMgr(NULL) +{ + if (mySelectionDlg) + mySelectionDlg->close(true); + + setCaption( "Data on elements" ); + setSizeGripEnabled(TRUE); + + QGridLayout* TopLayout = new QGridLayout (this); + TopLayout->setSpacing(6); + TopLayout->setMargin(11); + TopLayout->setRowStretch(0, 0); + TopLayout->setRowStretch(1, 0); + TopLayout->setRowStretch(2, 1); + TopLayout->setRowStretch(3, 0); + + QHButtonGroup* aTypeBox = new QHButtonGroup ("Selection", this); + + QRadioButton* aPointBtn = + new QRadioButton ("Point", aTypeBox); + new QRadioButton ("Cell" , aTypeBox); + new QRadioButton ("Actor", aTypeBox); + aPointBtn->setChecked(true); + + connect(aTypeBox, SIGNAL(clicked(int)), this, SLOT(onSelectionChange(int))); + + TopLayout->addWidget(aTypeBox, 0, 0); + + QWidget* aNamePane = new QWidget (this); + QGridLayout* aNameLay = new QGridLayout (aNamePane); + + QLabel* aMeshLbl = new QLabel ("Mesh name: ", aNamePane); + myMeshName = new QLabel (aNamePane); + + QLabel* aFieldLbl = new QLabel ("Field name: ", aNamePane); + myFieldName = new QLabel (aNamePane); + + aNameLay->addWidget(aMeshLbl, 0, 0); + aNameLay->addWidget(myMeshName, 0, 1); + aNameLay->addWidget(aFieldLbl, 1, 0); + aNameLay->addWidget(myFieldName, 1, 1); + + TopLayout->addWidget(aNamePane, 1, 0); + + myWidgetStack = new QWidgetStack (this); + + // Create Points pane + myPointsPane = new QVBox (myWidgetStack); + myPointsPane->layout()->setSpacing(6); + + QGroupBox* aDataGrp = new QGroupBox (2, Qt::Horizontal, "Data of Point", myPointsPane); + aDataGrp->layout()->setSpacing(6); + + new QLabel ("ID:", aDataGrp); + myIDValLbl = new QLineEdit ("", aDataGrp); + QIntValidator* aIntValidator = new QIntValidator (myIDValLbl); + aIntValidator->setBottom(0); + myIDValLbl->setValidator(aIntValidator); + connect(myIDValLbl, SIGNAL(textChanged(const QString&)), this, SLOT(onPointIdEdit(const QString&))); + + new QLabel ("Scalar Value:", aDataGrp); + myScalarValLbl = new QLabel ("", aDataGrp); + new QLabel ("Vector Value:", aDataGrp); + myVectorValLbl = new QLabel ("", aDataGrp); + myVectorValLbl->setMinimumWidth(150); + + QGroupBox* aCoordGrp = new QGroupBox (2, Qt::Horizontal, "Coordinates", myPointsPane); + aCoordGrp->layout()->setSpacing(6); + new QLabel ("X:", aCoordGrp); + myXValLbl = new QLabel ("", aCoordGrp); + new QLabel ("Y:", aCoordGrp); + myYValLbl = new QLabel ("", aCoordGrp); + new QLabel ("Z:",aCoordGrp ); + myZValLbl = new QLabel ("", aCoordGrp); + + + myWidgetStack->addWidget(myPointsPane, 0); + + // Create Cells pane + myCellsPane = new QWidget (myWidgetStack); + QGridLayout* aCellLayout = new QGridLayout (myCellsPane); + aCellLayout->setSpacing(6); + aCellLayout->setRowStretch(0, 0); + aCellLayout->setRowStretch(1, 1); + + QGroupBox* aCellGrp = new QGroupBox(2, Qt::Horizontal, "Data of Cell", myCellsPane); + + new QLabel ("ID:", aCellGrp); + myCellIDValLbl = new QLineEdit ("", aCellGrp); + myCellIDValLbl->setValidator(aIntValidator); + connect(myCellIDValLbl, SIGNAL(textChanged(const QString&)), this, SLOT(onCellIdEdit(const QString&))); + + new QLabel ("Scalar Value:", aCellGrp); + myCellScalarValLbl = new QLabel ("", aCellGrp); + new QLabel ("Vector Value:", aCellGrp); + myCellVectorValLbl = new QLabel ("", aCellGrp); + + aCellLayout->addWidget(aCellGrp, 0, 0); + + myListPoints = new QTable (myCellsPane); + myListPoints->setReadOnly(true); + myListPoints->setNumCols(6); + myListPoints->setNumRows(0); + myListPoints->setColumnWidth(0, 40); + myListPoints->setColumnWidth(1, 40); + myListPoints->setColumnWidth(2, 40); + myListPoints->setColumnWidth(3, 40); + myListPoints->setSelectionMode(QTable::NoSelection); + QHeader* aHeader = myListPoints->horizontalHeader(); + aHeader->setLabel( 0, "ID" ); + aHeader->setLabel( 1, "X" ); + aHeader->setLabel( 2, "Y" ); + aHeader->setLabel( 3, "Z" ); + aHeader->setLabel( 4, "Scalar" ); + aHeader->setLabel( 5, "Vector" ); + + aCellLayout->addWidget(myListPoints, 1, 0); + + myWidgetStack->addWidget(myCellsPane, 1); + + // Actor Pane + myActorsPane = new QVBox (myWidgetStack); + myActorsPane->layout()->setSpacing(6); + + QGroupBox* aPosGrp = new QGroupBox (2, Qt::Horizontal, "Position", myActorsPane); + aPosGrp->layout()->setSpacing(6); + new QLabel ("X:", aPosGrp); + myXPosLbl = new QLabel ("0", aPosGrp); + new QLabel ("Y:", aPosGrp); + myYPosLbl = new QLabel ("0", aPosGrp); + new QLabel ("Z:", aPosGrp); + myZPosLbl = new QLabel ("0", aPosGrp); + + QGroupBox* aSizeGrp = new QGroupBox (2, Qt::Horizontal, "Size", myActorsPane); + aSizeGrp->layout()->setSpacing(6); + new QLabel ("dX:", aSizeGrp); + myDXLbl = new QLabel ("0", aSizeGrp); + new QLabel ("dY:", aSizeGrp); + myDYLbl = new QLabel ("0", aSizeGrp); + new QLabel ("dZ:",aSizeGrp ); + myDZLbl = new QLabel ("0", aSizeGrp); + + myWidgetStack->addWidget(myActorsPane, 2); + + + TopLayout->addWidget(myWidgetStack, 2, 0); + + // Create buttons group + QHBox* aBtnBox = new QHBox (this); + QHBoxLayout* aBtnLayout = (QHBoxLayout*)aBtnBox->layout(); + aBtnLayout->addStretch(); + + QPushButton* aCloseBtn = new QPushButton (tr("BUT_CLOSE"), aBtnBox); + connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(close())); + + TopLayout->addWidget(aBtnBox, 3, 0); + + SalomeApp_Application* anApp = dynamic_cast + (SUIT_Session::session()->activeApplication()); + mySelectionMgr = anApp->selectionMgr(); + connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionEvent())); + + //connect(visuGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(close())); + + myFl = false; + + // Activate Points pane + SVTK_ViewWindow* aSVTKVW = VISU::GetViewWindow(); + myWidgetStack->raiseWidget(myPointsPane); + if (aSVTKVW) + aSVTKVW->SetSelectionMode(NodeSelection); + onSelectionEvent(); + + mySelectionDlg = this; +} + +VisuGUI_SelectionDlg::~VisuGUI_SelectionDlg() +{ +} + +void VisuGUI_SelectionDlg::onSelectionChange (int theId) +{ + SVTK_ViewWindow* aSVTKVW = VISU::GetViewWindow(); + if (!aSVTKVW) return; + + switch (theId) { + case 0: // Points + myWidgetStack->raiseWidget(myPointsPane); + aSVTKVW->SetSelectionMode(NodeSelection); + onPointIdEdit(myIDValLbl->text()); + break; + case 1: // Cells + myWidgetStack->raiseWidget(myCellsPane); + aSVTKVW->SetSelectionMode(CellSelection); + onCellIdEdit(myCellIDValLbl->text()); + break; + case 2: // Actor + myWidgetStack->raiseWidget(myActorsPane); + aSVTKVW->SetSelectionMode(ActorSelection); + onSelectionEvent(); + } +} + + +void VisuGUI_SelectionDlg::closeEvent (QCloseEvent* theEvent) +{ + SVTK_ViewWindow* aSVTKVW = VISU::GetViewWindow(); + + mySelectionDlg = NULL; + if (aSVTKVW) + aSVTKVW->SetSelectionMode(ActorSelection); + disconnect(mySelectionMgr,0,0,0); + QDialog::closeEvent(theEvent); +} + +template QString getValue(TData* theData, int theId){ + if (vtkDataArray *aScalar = theData->GetScalars()){ + float aVal = aScalar->GetTuple1(theId); + return QString::number(aVal); + } else { + return QString("No data"); + } +} + +template QString getVector(TData* theData, int theId){ + if (vtkDataArray *aVector = theData->GetVectors()) { + float *aVal = aVector->GetTuple3(theId); + return QString("%1; %2; %3").arg(aVal[0]).arg(aVal[1]).arg(aVal[2]); + } else { + return QString("No data"); + } +} + +#define ABS(a) (a>=0)?a:-a + +void VisuGUI_SelectionDlg::onSelectionEvent() { + SVTK_ViewWindow* aSVTKVW = VISU::GetViewWindow(); + if (!aSVTKVW) return; + + if (myFl) return; + myFl = true; + + int aType = myWidgetStack->id(myWidgetStack->visibleWidget()); + + SalomeApp_Application* anApp = dynamic_cast + (SUIT_Session::session()->activeApplication()); + + SVTK_Selector* aSelector = aSVTKVW->GetSelector(); + + VISU::Prs3d_i* aPrs3d = NULL; + _PTR(SObject) aSObject; + Handle(SALOME_InteractiveObject) anIO; + + SALOME_ListIO aListIO; + mySelectionMgr->selectedObjects(aListIO, SVTK_Viewer::Type()); + + if (aListIO.Extent() == 1) { + anIO = aListIO.First(); + + if (anIO->hasEntry()) { + SalomeApp_Study* theStudy = dynamic_cast(anApp->activeStudy()); + _PTR(Study) aStudy = theStudy->studyDS(); + aSObject = aStudy->FindObjectID(anIO->getEntry()); + + if (aSObject) { + CORBA::Object_var anObject = VISU::ClientSObjectToObject(aSObject); + + if (!CORBA::is_nil(anObject)) { + PortableServer::ServantBase_var aServant = VISU::GetServant(anObject); + + if (aServant.in()) { + aPrs3d = dynamic_cast(aServant.in()); + } + } + } + } + } + + if (aPrs3d) { + VISU::Storable::TRestoringMap aMap; + if (aSObject) { + _PTR(GenericAttribute) anAttr; + if (aSObject->FindAttribute(anAttr, "AttributeComment")) { + _PTR(AttributeComment) aComment (anAttr); + std::string aString = aComment->Value(); + QString strIn( aString.c_str() ); + VISU::Storable::StrToMap(strIn, aMap); + } + } + + QString aMeshName("NULL"), aFieldName("NULL"); + if (!aMap.empty()) { + aMeshName = VISU::Storable::FindValue(aMap, "myMeshName"); + aFieldName = VISU::Storable::FindValue(aMap, "myFieldName"); + } + + myMeshName ->setText((aMeshName == "NULL") ? QString("No name") : aMeshName); + myFieldName->setText((aFieldName == "NULL") ? QString("No name") : aFieldName); + + VISU_Actor* anVISUActor = + VISU::FindActor(aSVTKVW, aSObject->GetID().c_str()); + if (anVISUActor) { + float aCoord[6]; + anVISUActor->GetBounds(aCoord); + myXPosLbl->setText(QString::number( aCoord[0] )); + myYPosLbl->setText(QString::number( aCoord[2] )); + myZPosLbl->setText(QString::number( aCoord[4] )); + + myDXLbl->setText(QString::number( ABS(aCoord[1]-aCoord[0]) )); + myDYLbl->setText(QString::number( ABS(aCoord[3]-aCoord[2]) )); + myDZLbl->setText(QString::number( ABS(aCoord[5]-aCoord[4]) )); + + TColStd_IndexedMapOfInteger aMapIndex; + typedef map PointsMap; + PointsMap aPointsMap; + + aSelector->GetIndex(anIO, aMapIndex); + + vtkDataSet* aDataSet = anVISUActor->GetInput(); + vtkPointData* aPntData = aDataSet->GetPointData(); + + for (int ind = 1; ind <= aMapIndex.Extent(); ind++) { + int aID = aMapIndex(ind); + + switch (aType) { + case 0: + { + float aCoord[3]; + aDataSet->GetPoint(aID, aCoord); + myXValLbl->setText( QString::number( aCoord[0] ) ); + myYValLbl->setText( QString::number( aCoord[1] ) ); + myZValLbl->setText( QString::number( aCoord[2] ) ); + myIDValLbl->setText( QString::number(aID) ); + myScalarValLbl->setText(getValue(aPntData, aID)); + myVectorValLbl->setText(getVector(aPntData, aID)); + } + break; + case 1: + { + vtkCellData* aData = aDataSet->GetCellData(); + vtkCell* aCell = aDataSet->GetCell(aID); + if (aCell != NULL) { + int aNbOfPoints = aCell->GetNumberOfPoints(); + if (aNbOfPoints <=1 ) { // Cell is point + clearFields(); + } else { + myCellIDValLbl->setText( QString::number(aID) ); + myCellScalarValLbl->setText(getValue(aData, aID)); + myCellVectorValLbl->setText(getVector(aData, aID)); + + float* aCoord; + vtkIdList *aPointList = aCell->GetPointIds(); + + for (int i = 0; i < aNbOfPoints; i++) { + int idCurrent = aPointList->GetId(i); + aCoord = aDataSet->GetPoint(idCurrent); + aPointsMap.insert(PointsMap::value_type(idCurrent,aCoord)); + } + } + } + } + break; + } + } + + myListPoints->setNumRows(aPointsMap.size()); + PointsMap::const_iterator It = aPointsMap.begin(); + for (int i = 0; It != aPointsMap.end() && i < myListPoints->numRows(); It++, i++) { + myListPoints->verticalHeader()->setLabel(i, QString::number( i )); + int id = It->first; + myListPoints->setText(i, 0, QString::number( id )); + float* aCoord = It->second; + myListPoints->setText(i, 1, QString::number( aCoord[0] )); + myListPoints->setText(i, 2, QString::number( aCoord[1] )); + myListPoints->setText(i, 3, QString::number( aCoord[2] )); + myListPoints->setText(i, 4, getValue(aPntData, id)); + myListPoints->setText(i, 5, getVector(aPntData, id)); + } + } + } else { + clearFields(); + } + myFl = false; +} +#undef ABS + + +void VisuGUI_SelectionDlg::clearFields() { + int aType = myWidgetStack->id(myWidgetStack->visibleWidget()); + switch (aType) { + case 0: + myXValLbl->setText( "" ); + myYValLbl->setText( "" ); + myZValLbl->setText( "" ); + myIDValLbl->setText( "" ); + myScalarValLbl->setText(""); + myVectorValLbl->setText(""); + break; + case 1: + myCellIDValLbl->setText( "" ); + myCellScalarValLbl->setText(""); + myCellVectorValLbl->setText(""); + myListPoints->setNumRows(0); + break; + case 2: + myXPosLbl->setText(""); + myYPosLbl->setText(""); + myZPosLbl->setText(""); + myDXLbl->setText(""); + myDYLbl->setText(""); + myDZLbl->setText(""); + } +} + +typedef vtkIdType (vtkDataSet::* TDataSetMethod)(); + +bool onIdEdit (const QString& theText, + TDataSetMethod theMethod, + bool theIsCell, + SalomeApp_SelectionMgr* theSelectionMgr, + QLabel* theMeshName, + QString theValue, + QLabel* theFieldName) +{ + SalomeApp_Application* anApp = dynamic_cast + (SUIT_Session::session()->activeApplication()); + SVTK_ViewWindow* aSVTKVW = VISU::GetViewWindow(); + if (!aSVTKVW) return false; + SVTK_Selector* aSelector = aSVTKVW->GetSelector(); + + VISU::Prs3d_i* aPrs3d = NULL; + Handle(SALOME_InteractiveObject) anIO; + + SALOME_ListIO aListIO; + theSelectionMgr->selectedObjects(aListIO, SVTK_Viewer::Type()); + + if (aListIO.Extent() == 1) { + anIO = aListIO.First(); + + if (anIO->hasEntry()) { + SalomeApp_Study* theStudy = dynamic_cast(anApp->activeStudy()); + _PTR(Study) aStudy = theStudy->studyDS(); + _PTR(SObject) aSObject = aStudy->FindObjectID(anIO->getEntry()); + + if (aSObject) { + CORBA::Object_var anObject = VISU::ClientSObjectToObject(aSObject); + + if (!CORBA::is_nil(anObject)) { + PortableServer::ServantBase_var aServant = VISU::GetServant(anObject); + + if (aServant.in()) { + aPrs3d = dynamic_cast(aServant.in()); + } + } + } + } + } + + if (aPrs3d) { + int anId = theText.toInt(); + vtkDataSet* aDataSet = aPrs3d->GetPL()->GetMapper()->GetInput(); + int aMaxId = (aDataSet->*theMethod)(); + if (anId < 0) anId = 0; + if (anId >= aMaxId) anId = aMaxId - 1; + + TColStd_MapOfInteger newIndices; + newIndices.Add(anId); + aSelector->AddOrRemoveIndex(anIO, newIndices, false); + aSVTKVW->highlight(anIO, true, true); + + return true; + + } else { + theMeshName->setText(theValue); + theFieldName->setText(""); + } + return false; +} + +void VisuGUI_SelectionDlg::onPointIdEdit (const QString& theText) +{ + if (myFl) return; + TDataSetMethod aMethod = &vtkDataSet::GetNumberOfPoints; + bool anIsSelected = onIdEdit(theText,aMethod,false,mySelectionMgr, + myMeshName,tr("WRN_NO_AVAILABLE_DATA"), + myFieldName); + if (anIsSelected) + // as selection manager doesn't send signal currentSelectionChanged() + onSelectionEvent(); + else + clearFields(); +} + +void VisuGUI_SelectionDlg::onCellIdEdit (const QString& theText) +{ + if (myFl) return; + TDataSetMethod aMethod = &vtkDataSet::GetNumberOfCells; + bool anIsSelected = onIdEdit(theText,aMethod,true,mySelectionMgr, + myMeshName,tr("WRN_NO_AVAILABLE_DATA"), + myFieldName); + if (anIsSelected) + // as selection manager doesn't send signal currentSelectionChanged() + onSelectionEvent(); + else + clearFields(); +} diff --git a/src/VISUGUI/VisuGUI_TimeAnimation.h b/src/VISUGUI/VisuGUI_TimeAnimation.h new file mode 100644 index 00000000..f9fd9743 --- /dev/null +++ b/src/VISUGUI/VisuGUI_TimeAnimation.h @@ -0,0 +1,175 @@ +// VISU VISUGUI : GUI of VISU component +// +// Copyright (C) 2003 CEA/DEN, EDF R&D +// +// +// +// File : VisuGUI_TimeAnimation.h +// Author : Vitaly SMETANNIKOV +// Module : VISU + +#ifndef VISUGUI_TIMEANIMATION_H +#define VISUGUI_TIMEANIMATION_H + +#include "QtxDblSpinBox.h" + +#include "SALOMEDSClient_Study.hxx" + +#include +#include +#include + +class VisuGUI; +class VISU_TimeAnimation; + +namespace VISU { + class Prs3d_i; +} + +class SVTK_ViewWindow; + +class QtxDblSpinBox; + +class QLabel; +class QSlider; +class QListBox; +class QCheckBox; +class QComboBox; +class QToolButton; + +/*! + * Auxilliary class for presentations definition + */ +class ArrangeDlg: public QDialog +{ + Q_OBJECT + public: + enum { AutoMode, ManualMode }; + enum { XAxis, YAxis, ZAxis }; + + ArrangeDlg(QWidget* theParent, VISU_TimeAnimation* theAnimator); + ArrangeDlg(QWidget* theParent, SVTK_ViewWindow* theViewWindow); + ~ArrangeDlg() {}; + + int getMode() const { return myStackWgt->id(myStackWgt->visibleWidget()); } + double getDistance() const { return myDistVal->value(); } + int getAxis() const { return myAxisGrp->id(myAxisGrp->selected()); } + + protected slots: + virtual void accept(); + void onFieldChange(int); + + private: + struct Offset { + float myOffset[3]; + }; + + + void init(); + void acceptAnimation(); + void acceptViewWindow(); + + VISU_TimeAnimation* myAnimator; + SVTK_ViewWindow * myViewWindow; + + QWidgetStack* myStackWgt; + QButtonGroup* myAxisGrp; + QtxDblSpinBox* myDistVal; + QListBox* myFieldLst; + QtxDblSpinBox* myCoord[3]; + QValueList myOffsets; + + QCheckBox* mySaveChk; + + int myCurrent; + QMap myPrsMap; +}; + + +class SetupDlg: public QDialog { + Q_OBJECT + + public: + SetupDlg(VisuGUI* theModule, VISU_TimeAnimation* theAnimator); + ~SetupDlg() {}; + + private slots: + void onFieldChange(int theIndex); + void onTypeChanged(int theIndex); + // void onScalarBarDlg(); + void onPreferencesDlg(); + void onRangeCheck(bool theCheck); + void onMinValue(double theVal); + void onMaxValue(double theVal); + void onArrangeDlg(); + + private: + VisuGUI* myModule; + VISU_TimeAnimation* myAnimator; + QListBox* myFieldLst; + QComboBox* myTypeCombo; + QPushButton* myPropBtn; + QPushButton* myArrangeBtn; + QCheckBox* myUseRangeChk; + QtxDblSpinBox* myMinVal; + QtxDblSpinBox* myMaxVal; +}; + + +class VisuGUI_TimeAnimationDlg: public QDialog +{ + Q_OBJECT + public: + VisuGUI_TimeAnimationDlg(VisuGUI* theModule, _PTR(Study) theStudy); + ~VisuGUI_TimeAnimationDlg(); + + void addField(_PTR(SObject) theField); + void clearView(); + + void restoreFromStudy(_PTR(SObject) theAnimation); + + protected: + virtual void closeEvent(QCloseEvent* theEvent); + void stopAnimation(); + + private slots: + void onTypeChange(int index); + void onPlayPressed(); + void onBackPressed(); + void onForvardPressed(); + void onLastPressed(); + void onFirstPressed(); + void onSetupDlg(); + void onWindowChanged(int index); + void createFrames(); + void onSpeedChange(double theSpeed); + void onExecution(long theNewFrame, double theTime); + void onBrowse(); + void onStop(); + void saveToStudy(); + void publishToStudy(); + + private: + QSlider* mySlider; + QComboBox* myTypeCombo; + QPushButton* myPropBtn; + QToolButton* myPlayBtn; + QLabel* myTimeLbl; + QPushButton* mySetupBtn; + QPushButton* myGenBtn; + + QFrame* myPlayFrame; + _PTR(Study) myStudy; + VisuGUI* myModule; + + VISU_TimeAnimation* myAnimator; + QCheckBox* mySaveCheck; + QLineEdit* myPathEdit; + bool isClosing; + QCloseEvent* myEvent; + + QPushButton* myPublishBtn; + QPushButton* mySaveBtn; +}; + +#endif //VISUGUI_TIMEANIMATION_H diff --git a/src/VISUGUI/VisuGUI_Tools.cxx b/src/VISUGUI/VisuGUI_Tools.cxx new file mode 100644 index 00000000..4606134b --- /dev/null +++ b/src/VISUGUI/VisuGUI_Tools.cxx @@ -0,0 +1,1190 @@ +// VISU VISUGUI : GUI of VISU component +// +// Copyright (C) 2005 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 : VisuGUI_Tools.cxx +// Author : Sergey Anikin +// Module : VISU + + +#include "VisuGUI_Tools.h" + +#include "VISU_Gen_i.hh" +#include "VISU_Prs3d_i.hh" +#include "VISU_Result_i.hh" +#include "VISU_Table_i.hh" +#include "VISU_Mesh_i.hh" +#include "VISU_ViewManager_i.hh" + +#include "VISU_Actor.h" + +#include "SalomeApp_Module.h" +#include "SalomeApp_Study.h" +#include "SalomeApp_Application.h" +#include "SalomeApp_SelectionMgr.h" + +#include "SALOME_ListIO.hxx" +#include "SALOME_ListIteratorOfListIO.hxx" + +#include "SVTK_ViewWindow.h" +#include "SVTK_ViewModel.h" +#include "SVTK_Functor.h" + +#include "VTKViewer_Algorithm.h" + +#include "SPlot2d_ViewModel.h" +#include "Plot2d_ViewFrame.h" + +#include "SUIT_Session.h" +#include "SUIT_MessageBox.h" + +#include +#include + + +//============================================================================= +namespace VISU +{ + SUIT_Desktop* + GetDesktop(const CAM_Module* theModule) + { + return theModule->application()->desktop(); + } + + SalomeApp_SelectionMgr* + GetSelectionMgr(const SalomeApp_Module* theModule) + { + return theModule->getApp()->selectionMgr(); + } + + SalomeApp_Study* + GetAppStudy(const CAM_Module* theModule) + { + return + dynamic_cast(theModule->application()->activeStudy()); + } + + _PTR(Study) + GetCStudy(const SalomeApp_Study* theStudy) + { + return theStudy->studyDS(); + } + + bool + IsStudyLocked( _PTR(Study) theStudy ) + { + if( theStudy ) + return theStudy->GetProperties()->IsLocked(); + return true; + } + + bool + CheckLock( _PTR(Study) theStudy ) + { + if(IsStudyLocked(theStudy)) + throw std::runtime_error(QObject::tr("WRN_STUDY_LOCKED").latin1()); + return false; + } + + VISU_Gen_i* + GetVisuGen(const CAM_Module* theModule) + { + static VISU_Gen_i* aGen = NULL; + if(!aGen){ + SALOME_LifeCycleCORBA aLCC(SalomeApp_Application::namingService()); + Engines::Component_var aComponent = aLCC.FindOrLoad_Component("FactoryServer","VISU"); + VISU_Gen_var aVISU = VISU_Gen::_narrow(aComponent); + if(!CORBA::is_nil(aVISU)){ + aGen = VISU_Gen_i::GetVisuGenImpl(); + aGen->SetCurrentStudy(GetDSStudy(GetCStudy(GetAppStudy(theModule)))); + } + } + if(!aGen) + throw std::runtime_error(QObject::tr("ERR_CANT_FIND_VISU_COMPONENT").latin1()); + return aGen; + } + + SALOME_MED::MED_Gen_var + GetMEDEngine() + { + static SALOME_MED::MED_Gen_var aGen; + if(CORBA::is_nil(aGen)){ + SALOME_LifeCycleCORBA aLCC(SalomeApp_Application::namingService()); + Engines::Component_var aComponent = aLCC.FindOrLoad_Component("FactoryServer","MED"); + aGen = SALOME_MED::MED_Gen::_narrow(aComponent); + } + if(CORBA::is_nil(aGen)) + throw std::runtime_error(QObject::tr("ERR_CANT_FIND_MED_COMPONENT").latin1()); + return aGen; + } + + + VISU::Storable::TRestoringMap getMapOfValue (_PTR(SObject) theSObject) + { + VISU::Storable::TRestoringMap aMap; + if (theSObject) { + _PTR(GenericAttribute) anAttr; + if (theSObject->FindAttribute(anAttr, "AttributeComment")) { + _PTR(AttributeComment) aComment (anAttr); + std::string aValue = aComment->Value(); + QString aString (aValue.c_str()); + VISU::Storable::StrToMap(aString, aMap); + } + } + return aMap; + } + + QString getValue (_PTR(SObject) theSObject, QString theKey) + { + QString aStr(""); + VISU::Storable::TRestoringMap aMap = getMapOfValue(theSObject); + if (!aMap.empty()) + aStr = VISU::Storable::FindValue(aMap, theKey.latin1()); + return aStr; + } + + //************************************************************ + // Selection + CORBA::Object_var + GetSelectedObj(const SalomeApp_Study* theStudy, + const QString& theEntry, + VISU::Storable::TRestoringMap* theMap) + { + if (!theStudy || theEntry.isEmpty()) + return CORBA::Object::_nil(); + + _PTR(Study) aStudy = GetCStudy(theStudy); + _PTR(SObject) aSObject = aStudy->FindObjectID(theEntry.latin1()); + if (aSObject) { + _PTR(GenericAttribute) anAttr; + if (theMap && aSObject->FindAttribute(anAttr,"AttributeComment")) { + _PTR(AttributeComment) aComment (anAttr); + std::string aValue = aComment->Value(); + QString aString (aValue.c_str()); + VISU::Storable::StrToMap(aString, *theMap); + } + return VISU::ClientSObjectToObject(aSObject); + } + return CORBA::Object::_nil(); + } + + CORBA::Object_var + GetSelectedObj(const SalomeApp_Module* theModule, + Handle(SALOME_InteractiveObject)* theIO, + VISU::Storable::TRestoringMap* theMap) + { + SalomeApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule); + SALOME_ListIO aListIO; + aSelectionMgr->selectedObjects(aListIO); + SALOME_ListIteratorOfListIO anIter(aListIO); + if(anIter.More()){ + Handle(SALOME_InteractiveObject) anIO = anIter.Value(); + if(theIO) + *theIO = anIO; + if(anIO->hasEntry()) + return GetSelectedObj( GetAppStudy(theModule), anIO->getEntry(), theMap ); + } + return CORBA::Object::_nil(); + } + + void + Add(SalomeApp_SelectionMgr* theSelectionMgr, + const Handle(SALOME_InteractiveObject)& theIO) + { + SALOME_ListIO aListIO; + theSelectionMgr->selectedObjects(aListIO); + aListIO.Append(theIO); + theSelectionMgr->setSelectedObjects(aListIO); + } + + void + Remove(SalomeApp_SelectionMgr* theSelectionMgr, + const Handle(SALOME_InteractiveObject)& theIO) + { + if (theIO.IsNull()) return; + SALOME_ListIO aListIO, aNewListIO; + theSelectionMgr->selectedObjects(aListIO); + SALOME_ListIteratorOfListIO anIter (aListIO); + for (; anIter.More(); anIter.Next()) { + Handle(SALOME_InteractiveObject) anIO = anIter.Value(); + if (!anIO->isSame(theIO)) { + aNewListIO.Append(theIO); + } + } + theSelectionMgr->setSelectedObjects(aNewListIO); + } + + /*! + * \brief Check, if "Delete" popup-menu can be put on current selection + * + * \param theModule - is used to access SelectionManager, Study and VISU_Gen + * \retval bool - returns TRUE if all currently selected objects are removable + */ + bool + IsRemovableSelected (const SalomeApp_Module* theModule) + { + SalomeApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule); + SALOME_ListIO aListIO; + aSelectionMgr->selectedObjects(aListIO); + + if (aListIO.Extent() < 1) + return false; + + _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule)); + if (!aStudy) return false; + + // In some cases single selection can have its own popup-menu item for deletion + /*if (aListIO.Extent() == 1) { + Handle(SALOME_InteractiveObject) anIO = aListIO.First(); + _PTR(SObject) aSObject = aStudy->FindObjectID(anIO->getEntry()); + if (aSObject) { + VISU::VISUType aType = (VISU::VISUType)getValue(aSObject, "myType").toInt(); + if (aType == VISU::TVIEW3D) { + return false; // special case + } + } + }*/ + + SALOME_ListIteratorOfListIO anIter (aListIO); + for (; anIter.More(); anIter.Next()) { + Handle(SALOME_InteractiveObject) anIO = anIter.Value(); + if (anIO->hasEntry()) { + _PTR(SObject) aSObject = aStudy->FindObjectID(anIO->getEntry()); + VISU::Storable::TRestoringMap pMap; + if (aSObject) { + CORBA::Object_var aCORBAObject = VISU::ClientSObjectToObject(aSObject); + if (!CORBA::is_nil(aCORBAObject)) { + VISU::RemovableObject_var aRemovableObj = VISU::RemovableObject::_narrow(aCORBAObject); + if (CORBA::is_nil(aRemovableObj)) { + // Not removable CORBA object + return false; + } + } else { + // Can be removed, if lays directly under VISU + // (first sub-level) or is a child of such an object + string aNAME, aVisuNAME = GetVisuGen(theModule)->ComponentDataType(); + _PTR(GenericAttribute) anAttr; + _PTR(AttributeComment) aComment; + + bool isUnderVISU = false; + _PTR(SObject) aFatherSObject = aSObject->GetFather(); + if (aFatherSObject->FindAttribute(anAttr, "AttributeComment")) { + _PTR(AttributeComment) aComment (anAttr); + aNAME = aComment->Value(); + if (aNAME == aVisuNAME) { + isUnderVISU = true; + } + } + if (!isUnderVISU) { + // Not directly under VISU component, check father + aCORBAObject = VISU::ClientSObjectToObject(aFatherSObject); + if (!CORBA::is_nil(aCORBAObject)) { + // Father has IOR + return false; + } + + isUnderVISU = false; + aFatherSObject = aFatherSObject->GetFather(); + if (aFatherSObject->FindAttribute(anAttr, "AttributeComment")) { + _PTR(AttributeComment) aComment (anAttr); + aNAME = aComment->Value(); + if (aNAME == aVisuNAME) { + isUnderVISU = true; + } + } + if (!isUnderVISU) { + // Father is not directly under VISU component + return false; + } + } + } + } + } + } + return true; + } + + //************************************************************ + // Display/Erase + + void + ErasePrs (const SalomeApp_Module* theModule, + CORBA::Object_ptr theObject, bool theUpdate) + { + if (!CORBA::is_nil(theObject)) { + VISU::Base_var aBase = VISU::Base::_narrow(theObject); + if (CORBA::is_nil(aBase)) return; + VISU::VISUType aType = aBase->GetType(); + switch (aType) { + case VISU::TCURVE: + { + if (VISU::Curve_i* aCurve = dynamic_cast(VISU::GetServant(aBase).in())) + PlotCurve(theModule, aCurve, VISU::eErase ); + break; + } + case VISU::TCONTAINER: + { + if (VISU::Container_i* aContainer = dynamic_cast(VISU::GetServant(aBase).in())) + PlotContainer(theModule, aContainer, VISU::eErase ); + break; + } + case VISU::TTABLE: + { + if (VISU::Table_i* aTable = dynamic_cast(VISU::GetServant(aBase).in())) + PlotTable(theModule, aTable, VISU::eErase ); + break; + } + default: + { + if (VISU::Prs3d_i* aPrsObject = dynamic_cast(VISU::GetServant(aBase).in())) { + ErasePrs3d(theModule, aPrsObject); + if (theUpdate) { + if (SVTK_ViewWindow* vw = GetViewWindow(theModule)) + vw->Repaint(); + } + } + } + } // switch (aType) + } + } + + void + DeleteSObject (SalomeApp_Module* theModule, + _PTR(Study) theStudy, + _PTR(SObject) theSObject) + { + _PTR(ChildIterator) aChildIter = theStudy->NewChildIterator(theSObject); + for (aChildIter->InitEx(true); aChildIter->More(); aChildIter->Next()) { + _PTR(SObject) aChildSObject = aChildIter->Value(); + CORBA::Object_var aChildObj = VISU::ClientSObjectToObject(aChildSObject); + ErasePrs(theModule, aChildObj); + } + + CORBA::Object_var anObj = VISU::ClientSObjectToObject(theSObject); + if (!CORBA::is_nil(anObj)) { + ErasePrs(theModule, anObj); + + VISU::RemovableObject_var aRemovableObject = VISU::RemovableObject::_narrow(anObj); + if (!CORBA::is_nil(aRemovableObject)) { + aRemovableObject->RemoveFromStudy(); + } + } else { + // Remove aSObject together with all its sub-objects + VISU::RemoveFromStudy(theSObject, + false, // remove not only IOR attribute, but Object With Children + false); // not Destroy() sub-objects + } + } + + void + DeletePrs3d(SalomeApp_Module* theModule, + VISU::Prs3d_i* thePrs, + const Handle(SALOME_InteractiveObject)& theIO) + { + if (!thePrs) + return; + if (CheckLock(GetCStudy(GetAppStudy(theModule)))) + return; + SALOMEDS::SObject_var aSObject = thePrs->GetSObject(); + CORBA::String_var anEntry = aSObject->GetID(); + SalomeApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule); + Remove(aSelectionMgr,theIO); + TViewWindows aViewWindows = GetViews(theModule); + for(int i = 0, iEnd = aViewWindows.size(); i < iEnd; i++){ + SVTK_ViewWindow* aView = aViewWindows[i]; + if(VISU_Actor* anActor = FindActor(aView,anEntry.in())){ + aView->RemoveActor(anActor); + anActor->Delete(); + } + } + thePrs->RemoveFromStudy(); + } + + void + ErasePrs3d(const SalomeApp_Module* theModule, + VISU::Prs3d_i* thePrs) + { + if ( SVTK_ViewWindow* vw = GetViewWindow( theModule ) ){ + VISU_Actor* anVISUActor = FindActor( vw, thePrs ); + if (anVISUActor) { + anVISUActor->VisibilityOff(); + } + } + } + + //************************************************************ + // Presentation management + + void + ChangeRepresentation (const SalomeApp_Module* theModule, + VISU::PresentationType theType) + { + SUIT_ViewWindow* aView = GetActiveView(theModule, VTKViewer_Viewer::Type()); + if (!aView) return; + SVTK_ViewWindow* vw = (SVTK_ViewWindow*) aView; + + Handle(SALOME_InteractiveObject) anIO; + CORBA::Object_var anObject = GetSelectedObj(theModule, &anIO); + if (CORBA::is_nil(anObject)) return; + PortableServer::ServantBase_var aServant = VISU::GetServant(anObject); + if (!aServant.in()) return; + + VISU::Prs3d_i* aPrs3d = dynamic_cast(aServant.in()); + if (aPrs3d) { + if (VISU_Actor* anActor = GetActor(aPrs3d, vw)) { + switch (theType) { + case VISU::SHRINK: + if (anActor->IsShrunk()) + anActor->UnShrink(); + else + anActor->SetShrink(); + break; + default: + if (VISU::Mesh_i* aMesh = dynamic_cast(aPrs3d)) { + aMesh->SetPresentationType(theType); + RecreateActor(theModule, aMesh); + } else { + anActor->SetRepresentation(theType); + } + } + vw->Repaint(); + } + } + } + + //************************************************************ + // SObject type + + bool + CheckTimeStamp(const SalomeApp_Module* theModule, + _PTR(SObject)& theSObject, + Handle(SALOME_InteractiveObject)* theIO) + { + Handle(SALOME_InteractiveObject) anIO; + CORBA::Object_var anObject = GetSelectedObj(theModule, &anIO); + if (theIO) + *theIO = anIO; + if (!anIO.IsNull() && anIO->hasEntry()){ + _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule)); + theSObject = aStudy->FindObjectID(anIO->getEntry()); + QString aValue = getValue(theSObject,"myType"); + if (aValue.toInt() == int(VISU::TTIMESTAMP)) + return true; + } + SUIT_MessageBox::warn1(GetDesktop(theModule), + QObject::tr("WRN_VISU"), + QObject::tr("WRN_NO_AVAILABLE_DATA"), + QObject::tr("BUT_OK") ); + return false; + } + + VISU::Result_i* + CheckResult(const SalomeApp_Module* theModule, + _PTR(SObject) theSource, + VISU::Result_var& theResult) + { + _PTR(SObject) aSObj = theSource->GetFather(); + if (!aSObj) + return NULL; + + aSObj = aSObj->GetFather(); + if (!aSObj) + return NULL; + + aSObj = aSObj->GetFather(); + if (!aSObj) + return NULL; + + CORBA::Object_var anObject = VISU::ClientSObjectToObject(aSObj); + if (CORBA::is_nil(anObject)) { + aSObj = aSObj->GetFather(); + if (!aSObj) + return NULL; + anObject = VISU::ClientSObjectToObject(aSObj); + } + + if (CORBA::is_nil(anObject)) + return NULL; + + theResult = VISU::Result::_narrow(anObject); + VISU::Result_i* pResult = dynamic_cast(VISU::GetServant(anObject).in()); + if (pResult == NULL) + SUIT_MessageBox::warn1(GetDesktop(theModule), + QObject::tr("WRN_VISU"), + QObject::tr("WRN_NO_AVAILABLE_DATA"), + QObject::tr("BUT_OK")); + return pResult; + } + + //************************************************************ + // Views + + SUIT_ViewWindow* GetActiveView(const SalomeApp_Module* theModule, QString theType) + { + if(SalomeApp_Application* anApp = theModule->getApp()){ + if(SUIT_ViewManager* aViewManager = anApp->activeViewManager()){ + if (!theType.isNull()) { + if (aViewManager->getType() != theType) + return 0; + } + return aViewManager->getActiveView(); + } + } + return 0; + } + + //************************************************************ + // VTK View + + TViewWindows + GetViews(const SalomeApp_Module* theModule) + { + TViewWindows aViewWindows; + if(SalomeApp_Application* anApp = theModule->getApp()){ + ViewManagerList aViewManagerList; + anApp->viewManagers(SVTK_Viewer::Type(),aViewManagerList); + QPtrListIterator anIter(aViewManagerList); + while(SUIT_ViewManager* aViewManager = anIter.current()){ + QPtrVector aViews = aViewManager->getViews(); + for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){ + if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) + if(SVTK_ViewWindow* aView = dynamic_cast(aViewWindow)) + aViewWindows.push_back(aView); + } + ++anIter; + } + } + return aViewWindows; + } + + SVTK_ViewWindow* + GetViewWindow(const SalomeApp_Module* theModule, const bool theCreate ) + { + if(SalomeApp_Application* anApp = theModule->getApp()){ + if(SUIT_ViewManager* aViewManager = anApp->getViewManager( SVTK_Viewer::Type(), theCreate )){ + if(SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()){ + return dynamic_cast(aViewWindow); + } + } + } + return NULL; + } + + + SVTK_ViewWindow* + GetViewWindow() + { + SalomeApp_Application* anApp = dynamic_cast + (SUIT_Session::session()->activeApplication()); + if (anApp) { + if (SUIT_ViewManager* aViewManager = anApp->activeViewManager()) { + if (aViewManager->getType() == SVTK_Viewer::Type()) { + if (SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()) { + return dynamic_cast(aViewWindow); + } + } + } + } + return NULL; + } + + VISU_Actor* + PublishInView(const SalomeApp_Module* theModule, + VISU::Prs3d_i* thePrs) + { + VISU_Actor* aActor = NULL; + if(!thePrs) + return aActor; + if(SVTK_ViewWindow* aView = GetViewWindow(theModule)){ + QApplication::setOverrideCursor( Qt::waitCursor ); + try{ + if(aActor = thePrs->CreateActor()) + aView->AddActor(aActor); + }catch(std::exception& exc){ + SUIT_MessageBox::warn1(GetDesktop(theModule), + QObject::tr("WRN_VISU"), + QObject::tr("ERR_CANT_CREATE_ACTOR"), + QObject::tr("BUT_OK")); + } + QApplication::restoreOverrideCursor(); + } + return aActor; + } + + VISU_Actor* + UpdateViewer(const SalomeApp_Module* theModule, + VISU::Prs3d_i* thePrs, + bool theDispOnly) + { + SVTK_ViewWindow* vw = GetViewWindow( theModule ); + if (!vw) return NULL; + + vtkRenderer *aRen = vw->getRenderer(); + vtkActorCollection *anActColl = aRen->GetActors(); + + vtkActor *anActor; + VISU_Actor* anVISUActor = NULL; + VISU_Actor* aResActor = NULL; + for(anActColl->InitTraversal(); (anActor = anActColl->GetNextActor()) != NULL; ){ + if(!SALOME_Actor::SafeDownCast(anActor)) + continue; + if(anActor->IsA("VISU_Actor")){ + anVISUActor = VISU_Actor::SafeDownCast(anActor); + VISU::Prs3d_i* aPrs = anVISUActor->GetPrs3d(); + if(aPrs == NULL) continue; + if (thePrs == aPrs) { + aResActor = anVISUActor->GetParent(); + thePrs->UpdateActor(aResActor); + aResActor->VisibilityOn(); + + } else if (theDispOnly) { + anVISUActor->GetParent()->VisibilityOff(); + } else { + } + } else if (theDispOnly && anActor->GetVisibility()) { + anActor->VisibilityOff(); + } else { + } + } + if (aResActor) + return aResActor; + + anVISUActor = PublishInView( theModule, thePrs ); + return anVISUActor; + } + + void + RepaintViewWindows (const SalomeApp_Module* theModule, + const Handle(SALOME_InteractiveObject)& theIObject) + { + TViewWindows aViewWindows; + if (SalomeApp_Application* anApp = theModule->getApp()) { + ViewManagerList aViewManagerList; + anApp->viewManagers(SVTK_Viewer::Type(),aViewManagerList); + QPtrListIterator anIter (aViewManagerList); + while (SUIT_ViewManager* aViewManager = anIter.current()) { + QPtrVector aViews = aViewManager->getViews(); + for (int i = 0, iEnd = aViews.size(); i < iEnd; i++) { + if (SUIT_ViewWindow* aViewWindow = aViews.at(i)) { + if (SVTK_ViewWindow* vw = dynamic_cast(aViewWindow)) { + if (vw->isVisible(theIObject)) { + vw->getRenderer()->ResetCameraClippingRange(); + vw->Repaint(); + vw->highlight(theIObject, true, true); + } + } + } + } + ++anIter; + } + } + } + + VISU_Actor* + FindActor(SVTK_ViewWindow* theViewWindow, + const char* theEntry) + { + using namespace VTK; + if(vtkRenderer* aRenderer = theViewWindow->getRenderer()){ + if(vtkActorCollection* aCollection = aRenderer->GetActors()){ + if(VISU_Actor* anActor = Find(aCollection,TIsSameEntry(theEntry))){ + return anActor->GetParent(); + } + } + } + return NULL; + } + + VISU_Actor* + FindActor(SVTK_ViewWindow* theViewWindow, + VISU::Prs3d_i* thePrs) + { + SALOMEDS::SObject_var aSObject = thePrs->GetSObject(); + CORBA::String_var anEntry = aSObject->GetID(); + return FindActor(theViewWindow,anEntry.in()); + } + + void + RecreateActor (const SalomeApp_Module* theModule, + VISU::Prs3d_i* thePrs) + { + QApplication::setOverrideCursor(Qt::waitCursor); + + SALOMEDS::SObject_var aSObject = thePrs->GetSObject(); + CORBA::String_var anEntry = aSObject->GetID(); + + try { + thePrs->Update(); + + TViewWindows aViewWindows = GetViews(theModule); + for (int i = 0, iEnd = aViewWindows.size(); i < iEnd; i++) { + SVTK_ViewWindow* aView = aViewWindows[i]; + if (VISU_Actor* anActor = FindActor(aView, anEntry.in())) { + thePrs->UpdateActor(anActor); + } + } + } catch (std::runtime_error& ex) { + INFOS(ex.what()); + QApplication::restoreOverrideCursor(); + SUIT_MessageBox::warn1 (GetDesktop(theModule), QObject::tr("WRN_VISU"), + QObject::tr("ERR_CANT_BUILD_PRESENTATION") + " " + QObject::tr(ex.what()), + QObject::tr("BUT_OK")); + + TViewWindows aViewWindows = GetViews(theModule); + for (int i = 0, iEnd = aViewWindows.size(); i < iEnd; i++) { + SVTK_ViewWindow* aView = aViewWindows[i]; + if (VISU_Actor* anActor = FindActor(aView, anEntry.in())) { + aView->RemoveActor(anActor); + anActor->Delete(); + } + } + return; + } + QApplication::restoreOverrideCursor(); + } + + //************************************************************ + // Plot2d View + + SPlot2d_Viewer* + GetPlot2dViewer(const SalomeApp_Module* theModule, const bool theCreate) + { + if(SalomeApp_Application* anApp = theModule->getApp()){ + if(SUIT_ViewManager* aViewManager = anApp->getViewManager( Plot2d_Viewer::Type(), theCreate )){ + return dynamic_cast(aViewManager->getViewModel()); + } + } + return NULL; + } + + // Internal function used by several public functions below + void + UpdateCurve(VISU::Curve_i* theCurve, + Plot2d_ViewFrame* aPlot, + SPlot2d_Curve* plotCurve, + int theDisplaying) + { + if ( theDisplaying == VISU::eErase ) { + if ( plotCurve ) + aPlot->eraseCurve( plotCurve, false ); + } + else if ( theDisplaying == VISU::eDisplay || theDisplaying == VISU::eDisplayOnly ) { + if ( plotCurve ) { + plotCurve->setHorTitle( theCurve->GetHorTitle().c_str() ); + //plotCurve->setVerTitle( ( theCurve->GetVerTitle().c_str() ) ); + plotCurve->setVerTitle( theCurve->GetName() ); + plotCurve->setHorUnits( theCurve->GetHorUnits().c_str() ); + plotCurve->setVerUnits( theCurve->GetVerUnits().c_str() ); + double* xList = 0; + double* yList = 0; + int nbPoints = theCurve->GetData( xList, yList ); + if ( nbPoints > 0 && xList && yList ) { + plotCurve->setData( xList, yList, nbPoints ); + } + if ( !theCurve->IsAuto() ) { + plotCurve->setLine( (Plot2d_Curve::LineType)theCurve->GetLine(), theCurve->GetLineWidth() ); + plotCurve->setMarker( (Plot2d_Curve::MarkerType)theCurve->GetMarker() ); + SALOMEDS::Color color = theCurve->GetColor(); + plotCurve->setColor( QColor( (int)(color.R*255.), (int)(color.G*255.), (int)(color.B*255.) ) ); + } + plotCurve->setAutoAssign( theCurve->IsAuto() ); + aPlot->displayCurve( plotCurve, false ); + } + else { + Plot2d_Curve* crv = theCurve->CreatePresentation(); + if ( crv ) { + aPlot->displayCurve( crv, false ); + theCurve->SetLine( (VISU::Curve::LineType)crv->getLine(), crv->getLineWidth() ); + theCurve->SetMarker( (VISU::Curve::MarkerType)crv->getMarker()); + SALOMEDS::Color newColor; + newColor.R = crv->getColor().red()/255.; + newColor.G = crv->getColor().green()/255.; + newColor.B = crv->getColor().blue()/255.; + theCurve->SetColor( newColor ); + crv->setAutoAssign( theCurve->IsAuto() ); + } + } + } + } + + void + PlotTable(const SalomeApp_Module* theModule, + VISU::Table_i* table, + int theDisplaying) + { + SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true ); // create if necessary + if ( !aView ) + return; + Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame(); + if ( !aPlot ) + return; + + if ( theDisplaying == VISU::eDisplayOnly ) + aPlot->EraseAll(); + QList clist; + aPlot->getCurves( clist ); + _PTR(Study) aStudy = GetCStudy( GetAppStudy( theModule ) ); + _PTR(SObject) TableSO = aStudy->FindObjectID( table->GetEntry().latin1() ); + if ( TableSO ) { + _PTR(ChildIterator) Iter = aStudy->NewChildIterator( TableSO ); + for ( ; Iter->More(); Iter->Next() ) { + CORBA::Object_var childObject = VISU::ClientSObjectToObject( Iter->Value() ); + if( !CORBA::is_nil( childObject ) ) { + CORBA::Object_ptr aCurve = VISU::Curve::_narrow( childObject ); + if( !CORBA::is_nil( aCurve ) ) { + VISU::Curve_i* theCurve = dynamic_cast(VISU::GetServant(aCurve).in()); + SPlot2d_Curve* plotCurve = 0; + SPlot2d_Curve* tmpCurve; + for ( int i = 0; i < clist.count(); i++ ) { + tmpCurve = dynamic_cast( clist.at( i ) ); + if (tmpCurve && tmpCurve->hasIO() && + !strcmp(tmpCurve->getIO()->getEntry(), theCurve->GetEntry())) { + plotCurve = tmpCurve; + break; + } + } + + UpdateCurve( theCurve, aPlot, plotCurve, theDisplaying ); + + if ( theDisplaying == VISU::eErase && plotCurve ) { + clist.remove( plotCurve ); + } + } + } + } + aPlot->Repaint(); + } + } + + void + PlotCurve(const SalomeApp_Module* theModule, + VISU::Curve_i* theCurve, + int theDisplaying) + { + SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true ); + if ( !aView ) + return; + Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame(); + if ( !aPlot ) + return; + +// if ( theDisplaying == VISU::eDisplayOnly ) +// aPlot->EraseAll(); + QList clist; + aPlot->getCurves( clist ); + SPlot2d_Curve* plotCurve = 0; + SPlot2d_Curve* tmpCurve; + for (int i = 0; i < clist.count(); i++) { + tmpCurve = dynamic_cast(clist.at(i)); + if (tmpCurve && tmpCurve->hasIO() && + !strcmp(tmpCurve->getIO()->getEntry(), theCurve->GetEntry())) { + plotCurve = tmpCurve; + } else if (theDisplaying == VISU::eDisplayOnly) { + aPlot->eraseCurve(clist.at(i)); + } + } + + UpdateCurve(theCurve, aPlot, plotCurve, theDisplaying); + + aPlot->Repaint(); + } + + void + PlotContainer(const SalomeApp_Module* theModule, + VISU::Container_i* container, + int theDisplaying) + { + SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true ); + if ( !aView ) + return; + Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame(); + if ( !aPlot ) + return; + + if ( theDisplaying == VISU::eDisplayOnly ) + aPlot->EraseAll(); + QList clist; + aPlot->getCurves( clist ); + if ( container->GetNbCurves() > 0 ) { + int nbCurves = container->GetNbCurves(); + for ( int k = 1; k <= nbCurves; k++ ) { + VISU::Curve_i* theCurve = container->GetCurve( k ); + if ( theCurve && theCurve->IsValid() ) { + SPlot2d_Curve* plotCurve = dynamic_cast + (aView->getCurveByIO(new SALOME_InteractiveObject (theCurve->GetEntry(), "", ""))); + + UpdateCurve( theCurve, aPlot, plotCurve, theDisplaying ); + + if ( plotCurve && theDisplaying == VISU::eErase ) { + clist.remove( plotCurve ); + } + } + } + } + aPlot->Repaint(); + } + + void + CreatePlot(SalomeApp_Module* theModule, + _PTR(SObject) theTableSO) + { + if ( IsSObjectTable(theTableSO) ) { + CORBA::Object_var aTable = VISU::ClientSObjectToObject(theTableSO); + CORBA::Object_var aContainer = GetVisuGen( theModule )->CreateContainer(); + if ( !CORBA::is_nil( aTable ) && !CORBA::is_nil( aContainer ) ) { + VISU::Table_i* pTable = dynamic_cast(VISU::GetServant(aTable).in()); + VISU::Container_i* pContainer = dynamic_cast(VISU::GetServant(aContainer).in()); + + if ( pContainer && pTable ) { + for ( int i = 2; i <= pTable->GetNbRows(); i++ ) { + CORBA::Object_var aNewCurve = GetVisuGen( theModule )->CreateCurve( pTable->_this(), 1, i ); + if( !CORBA::is_nil( aNewCurve ) ) { + VISU::Curve_i* pCrv = dynamic_cast( VISU::GetServant(aNewCurve).in() ); + if ( pCrv ) { + pContainer->AddCurve( pCrv->_this() ); + } + } + } + PlotContainer( theModule, pContainer, VISU::eDisplay ); + } + } + } + } + + //************************************************************ + // Others + + void CreateMesh (const SalomeApp_Module* theModule, + const Handle(SALOME_InteractiveObject)& theIO) + { + _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule)); + //if (CheckLock(aStudy)) + // return; + + _PTR(SObject) aResultSObj = aStudy->FindObjectID(theIO->getEntry()); + + // Get VISU::Result + VISU::Result_var aResult; + VISU::Result_i* pResult = CheckResult(theModule, aResultSObj, aResult); + if (pResult == NULL) + return; + + Storable::TRestoringMap aMap = getMapOfValue(aResultSObj); + bool isExist; + string aComment = Storable::FindValue(aMap,"myComment",&isExist).latin1(); + if (!isExist) + return; + + CORBA::Object_var aMesh; + string aMeshName = Storable::FindValue(aMap,"myMeshName").latin1(); +#ifdef CHECKTIME + Utils_Timer timer; + timer.Start(); +#endif + if (aComment == "ENTITY") { + VISU::Entity anEntity = (VISU::Entity)Storable::FindValue(aMap,"myId").toInt(); + if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),anEntity)) + aMesh = GetVisuGen(theModule)->MeshOnEntity(aResult,aMeshName.c_str(),anEntity); + } else if (aComment == "FAMILY") { + VISU::Entity anEntity = (VISU::Entity)Storable::FindValue(aMap,"myEntityId").toInt(); + string aFamilyName = Storable::FindValue(aMap,"myName").latin1(); + if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),anEntity,aFamilyName.c_str())) + aMesh = GetVisuGen(theModule)->FamilyMeshOnEntity + (aResult,aMeshName.c_str(),anEntity,aFamilyName.c_str()); + } else if (aComment == "GROUP") { + string aGroupName = Storable::FindValue(aMap,"myName").latin1(); + if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),aGroupName.c_str())) + aMesh = GetVisuGen(theModule)->GroupMesh(aResult,aMeshName.c_str(),aGroupName.c_str()); + } +#ifdef CHECKTIME + timer.Stop(); + MESSAGE("VisuGUI::CreateMesh() - CREATE MESH"); + timer.Show(); +#endif + + QApplication::restoreOverrideCursor(); + VISU::Mesh_i* pPresent = NULL; + if (!CORBA::is_nil(aMesh)) + pPresent = dynamic_cast(VISU::GetServant(aMesh).in()); + if (pPresent == NULL) { + SUIT_MessageBox::warn1 (GetDesktop(theModule), + QObject::tr("WRN_VISU"), + QObject::tr("ERR_CANT_BUILD_PRESENTATION"), + QObject::tr("BUT_OK")); + return; + } + + if (SVTK_ViewWindow* aView = GetViewWindow(theModule)) { + try { +#ifdef CHECKTIME + Utils_Timer timer; + timer.Start(); +#endif + PublishInView(theModule, pPresent); + aView->onFitAll(); +#ifdef CHECKTIME + timer.Stop(); + MESSAGE("VisuGUI::CreateMesh() - DISPLAY MESH"); + timer.Show(); +#endif + theModule->application()->putInfo(QObject::tr("INF_DONE")); + // Make "Save" button active + theModule->getApp()->updateActions(); + } catch (std::runtime_error& exc) { + INFOS(exc.what()); + SUIT_MessageBox::warn1 (GetDesktop(theModule), + QObject::tr("WRN_VISU"), + QObject::tr("ERR_CANT_CREATE_ACTOR") + " " + QObject::tr(exc.what()), + QObject::tr("BUT_OK")); + } + } + } + + // ======================================================================================== + // GetPrs3dList: find list of presentations for the given object + // ======================================================================================== + std::vector GetPrs3dList (const SalomeApp_Module* theModule, + const Handle(SALOME_InteractiveObject)& theIO) + { + std::vector aList; + if (!theIO.IsNull() && theIO->hasEntry()) { + _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule)); + _PTR(SObject) aSObject = aCStudy->FindObjectID(theIO->getEntry()); + aList = GetPrs3dList(theModule, aSObject); + } + return aList; + } + + std::vector GetPrs3dList (const SalomeApp_Module* theModule, + _PTR(SObject) theObject) + { + std::vector aList; int k = 0; + if (!theObject) + return aList; + + _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule)); + + CORBA::Object_var aCORBAObject = VISU::ClientSObjectToObject(theObject); + if (!CORBA::is_nil(aCORBAObject)) { + VISU::Base_var aVisuObj = VISU::Base::_narrow(aCORBAObject); + if (!CORBA::is_nil(aVisuObj)) { + VISU::VISUType aType = aVisuObj->GetType(); + switch (aType) { + case VISU::TSCALARMAP: + case VISU::TISOSURFACE: + case VISU::TDEFORMEDSHAPE: + case VISU::TCUTPLANES: + case VISU::TCUTLINES: + case VISU::TVECTORS: + case VISU::TSTREAMLINES: + case VISU::TPLOT3D: + { + PortableServer::ServantBase_var aServant = VISU::GetServant(aCORBAObject); + if (aServant.in()) { + VISU::Prs3d_i* aPrsObject = dynamic_cast(aServant.in()); + aList.resize(k+1); + aList[k] = aPrsObject; + k++; + } + } + break; + case VISU::TFIELD: + { + _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject); + _PTR(SObject) aTimeStamp; + anIter->Next(); // First is reference on support + for (; anIter->More(); anIter->Next()) { + aTimeStamp = anIter->Value(); + if (!aTimeStamp) continue; + std::vector aSubList = GetPrs3dList(theModule, aTimeStamp); + if (!aSubList.empty()) { + int n = aSubList.size(); + aList.resize(k+n); + for (int i = 0; i < n; i++) { + aList[k] = aSubList[i]; + k++; + } + } + } + } + break; + } + } + } else { + _PTR(GenericAttribute) anAttr; + if (theObject->FindAttribute(anAttr, "AttributeComment")) { + _PTR(AttributeComment) aComment (anAttr); + string aComm = aComment->Value(); + QString strIn (aComm.c_str()); + VISU::Storable::TRestoringMap pMap; + VISU::Storable::StrToMap(strIn, pMap); + bool isExist; + VISU::VISUType aType = + (VISU::VISUType)VISU::Storable::FindValue(pMap,"myType",&isExist).toInt(); + if (isExist) { + switch (aType) { + case VISU::TFIELD: + { + _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject); + _PTR(SObject) aTimeStamp; + anIter->Next(); // First is reference on support + for (; anIter->More(); anIter->Next()) { + aTimeStamp = anIter->Value(); + if (!aTimeStamp) continue; + std::vector aSubList = GetPrs3dList(theModule, aTimeStamp); + if (!aSubList.empty()) { + int n = aSubList.size(); + aList.resize(k+n); + for (int i = 0; i < n; i++) { + aList[k] = aSubList[i]; + k++; + } + } + } + } + break; + case VISU::TTIMESTAMP: + { + _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject); + _PTR(SObject) aPrs; + for (; anIter->More(); anIter->Next()) { + aPrs = anIter->Value(); + if (!aPrs) continue; + std::vector aSubList = GetPrs3dList(theModule, aPrs); + if (!aSubList.empty()) { + int n = aSubList.size(); + aList.resize(k+n); + for (int i = 0; i < n; i++) { + aList[k] = aSubList[i]; + k++; + } + } + } + } + break; + } + } + } + } + return aList; + } +} diff --git a/src/VISUGUI/VisuGUI_Tools.h b/src/VISUGUI/VisuGUI_Tools.h new file mode 100644 index 00000000..2af898e6 --- /dev/null +++ b/src/VISUGUI/VisuGUI_Tools.h @@ -0,0 +1,194 @@ +// VISU VISUGUI : GUI of VISU component +// +// Copyright (C) 2005 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 : VisuGUI_Tools.h +// Author : Sergey Anikin +// Module : VISU + +#ifndef VisuGUI_Tools_HeaderFile +#define VisuGUI_Tools_HeaderFile + +#include "SALOME_InteractiveObject.hxx" + +#include "VISUConfig.hh" + +#include "SalomeApp_Module.h" +#include "SalomeApp_Application.h" + +#include "SALOMEDSClient_Study.hxx" + +#include "SALOMEconfig.h" +#include CORBA_SERVER_HEADER(MED_Gen) + +class SUIT_Desktop; +class SUIT_ViewWindow; +class VISU_Actor; +class SVTK_ViewWindow; +class SPlot2d_Viewer; +class CAM_Module; +class SalomeApp_SelectionMgr; +class SalomeApp_Study; + +namespace VISU { + class Prs3d_i; + class Result_i; + class Table_i; + class Curve_i; + class Container_i; + + typedef std::vector TViewWindows; + + SUIT_Desktop* GetDesktop(const CAM_Module* theModule); + SalomeApp_Study* GetAppStudy(const CAM_Module* theModule); + _PTR(Study) GetCStudy(const SalomeApp_Study* theStudy); + + bool IsStudyLocked( _PTR(Study) theStudy ); + bool CheckLock( _PTR(Study) theStudy ); + + inline void UpdateObjBrowser(SalomeApp_Module* theModule, + bool updateDataModel = true); + + VISU_Gen_i* GetVisuGen(const CAM_Module* theModule); + SALOME_MED::MED_Gen_var GetMEDEngine(); + + VISU::Storable::TRestoringMap getMapOfValue(_PTR(SObject) theSObject); + QString getValue(_PTR(SObject) theSObject, QString theKey); + + // Selection + SalomeApp_SelectionMgr* GetSelectionMgr(const SalomeApp_Module* theModule); + CORBA::Object_var GetSelectedObj(const SalomeApp_Study* theStudy, + const QString& theEntry, + VISU::Storable::TRestoringMap* theMap = NULL); + CORBA::Object_var GetSelectedObj(const SalomeApp_Module* theModule, + Handle(SALOME_InteractiveObject)* theIO = NULL, + VISU::Storable::TRestoringMap* theMap = NULL); + + void Add(SalomeApp_SelectionMgr* theSelectionMgr, + const Handle(SALOME_InteractiveObject)& theIO); + void Remove(SalomeApp_SelectionMgr* theSelectionMgr, + const Handle(SALOME_InteractiveObject)& theIO); + + bool IsRemovableSelected(const SalomeApp_Module* theModule); + + // Display/Erase + void ErasePrs(const SalomeApp_Module* theModule, + CORBA::Object_ptr theObject, + bool theUpdate = true); + void DeleteSObject(SalomeApp_Module* theModule, + _PTR(Study) theStudy, + _PTR(SObject) theSObject); + void DeletePrs3d(SalomeApp_Module* theModule, + VISU::Prs3d_i* thePrs, + const Handle(SALOME_InteractiveObject)& theIO); + void ErasePrs3d(const SalomeApp_Module* theModule, + VISU::Prs3d_i* thePrs); + + // Presentation management + void ChangeRepresentation (const SalomeApp_Module* theModule, + VISU::PresentationType theType); + + // SObject type + bool CheckTimeStamp(const SalomeApp_Module* theModule, + _PTR(SObject)& theSObject, + Handle(SALOME_InteractiveObject)* theIO = NULL); + VISU::Result_i* CheckResult(const SalomeApp_Module* theModule, + _PTR(SObject) theSource, + VISU::Result_var& theResult); + inline bool IsSObjectTable(_PTR(SObject) theSObject); + + // Views + SUIT_ViewWindow* GetActiveView(const SalomeApp_Module* theModule, + QString theType = QString::null); + + // VTK View + TViewWindows GetViews(const SalomeApp_Module* theModule); + SVTK_ViewWindow* GetViewWindow(const SalomeApp_Module* theModule, + const bool theCreate = false ); + SVTK_ViewWindow* GetViewWindow(); + + VISU_Actor* PublishInView(const SalomeApp_Module* theModule, + VISU::Prs3d_i* thePrs); + VISU_Actor* UpdateViewer(const SalomeApp_Module* theModule, + VISU::Prs3d_i* thePrs, + bool theDispOnly = false); + + /*! + * \brief Repaint all SVTK view windows, where the given object is displayed. + * \param theModule - is used to access application. + * \param theIObject - is supposed to be selected (is highlighted in this method). + */ + void RepaintViewWindows(const SalomeApp_Module* theModule, + const Handle(SALOME_InteractiveObject)& theIObject); + + VISU_Actor* FindActor(SVTK_ViewWindow* theViewWindow, + const char* theEntry); + VISU_Actor* FindActor(SVTK_ViewWindow* theViewWindow, + VISU::Prs3d_i* thePrs); + void RecreateActor(const SalomeApp_Module* theModule, + VISU::Prs3d_i* thePrs); + + // Plot2d View + SPlot2d_Viewer* GetPlot2dViewer(const SalomeApp_Module* theModule, + const bool theCreate = false); + void PlotTable( const SalomeApp_Module* theModule, + VISU::Table_i* table, + int theDisplaying ); + void PlotCurve( const SalomeApp_Module* theModule, + VISU::Curve_i* curve, + int theDisplaying ); + void PlotContainer( const SalomeApp_Module* theModule, + VISU::Container_i* container, + int theDisplaying ); + void CreatePlot( SalomeApp_Module* theModule, + _PTR(SObject) theSobj ); + + // Others + void CreateMesh (const SalomeApp_Module* theModule, + const Handle(SALOME_InteractiveObject)& theIO); + + std::vector GetPrs3dList (const SalomeApp_Module* theModule, + const Handle(SALOME_InteractiveObject)& theIO); + std::vector GetPrs3dList (const SalomeApp_Module* theModule, + _PTR(SObject) theObject); +} + +bool VISU::IsSObjectTable( _PTR(SObject) theSObject ) +{ + if ( theSObject ) { + _PTR(GenericAttribute) anAttr; + if (theSObject->FindAttribute( anAttr, "AttributeTableOfInteger" )) + return true; + if (theSObject->FindAttribute( anAttr, "AttributeTableOfReal" )) + return true; + } + return false; +} + +void VISU::UpdateObjBrowser(SalomeApp_Module* theModule, + bool updateDataModel) +{ + theModule->updateObjBrowser(updateDataModel); + theModule->getApp()->updateActions(); +} + +#endif diff --git a/src/VISU_I/VISUConfig.hh b/src/VISU_I/VISUConfig.hh new file mode 100644 index 00000000..3224f05a --- /dev/null +++ b/src/VISU_I/VISUConfig.hh @@ -0,0 +1,181 @@ +// VISU OBJECT : interactive object for VISU entities implementation +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// File : VISUConfig.hh +// Author : Alexey PETROV +// Module : VISU + +#ifndef __VISU_CONFIG_H__ +#define __VISU_CONFIG_H__ + +// IDL headers +#include "SALOMEconfig.h" +#include CORBA_SERVER_HEADER(VISU_Gen) +#include CORBA_SERVER_HEADER(MED) +#include CORBA_SERVER_HEADER(SALOMEDS) +#include CORBA_SERVER_HEADER(SALOMEDS_Attributes) + +#include "SALOME_NamingService.hxx" +#include "SALOME_LifeCycleCORBA.hxx" +#include "Utils_CorbaException.hxx" +#include "utilities.h" + +#include +#include + +// QT headers +#include +#include +#include +#include + +// standard C++ headers +#include + +// STL headers +#include +#include +#include +#include +#include + +class SUIT_Session; +class SUIT_ResourceMgr; + + +namespace VISU{ + + SUIT_Session *GetSession(); + SUIT_ResourceMgr *GetResourceMgr(); + + //=========================================================================== + + class VISU_Gen_i; + + class Base_i : public virtual POA_VISU::Base, + public virtual PortableServer::RefCountServantBase + { + public: + Base_i(); + virtual ~Base_i(); + virtual char* GetID(); + virtual VISU::VISUType GetType() = 0; + + protected: + std::string myID; + + protected: + static QMutex* myMutex; + static CORBA::ORB_var myOrb; + static PortableServer::POA_var myPoa; + static SALOME_NamingService* myNamingService; + static VISU_Gen_i* myVisuGenImpl; + static SALOME_LifeCycleCORBA* myEnginesLifeCycle; + + public: + static CORBA::ORB_var GetORB() { return myOrb;} + static PortableServer::POA_var GetPOA() { return myPoa;} + static SALOME_NamingService* GetNS() { return myNamingService;} + static SALOME_LifeCycleCORBA* GetLCC() { return myEnginesLifeCycle;} + static VISU_Gen_i* GetVisuGenImpl() { return myVisuGenImpl;} + }; + + + //=========================================================================== + class Mutex{ + QMutex* myMutex; + int isQAppLocked; + public: + Mutex(QMutex* theMutex); + ~Mutex(); + }; + + + //=========================================================================== + class Storable : public virtual Base_i { + protected: + virtual void ToStream(std::ostringstream& theStr) = 0; + public: + std::string ToString(); + virtual const char* GetComment() const = 0; + typedef std::map TRestoringMap; + typedef Storable* (*TStorableEngine)(SALOMEDS::SObject_ptr theSObject, + const std::string& thePrefix, const TRestoringMap& theMap); + typedef std::map TCallbackMap; + static void Registry(const char* theComment, TStorableEngine theEngine); + static Storable* Create(SALOMEDS::SObject_ptr, const std::string& thePrefix, const std::string& theString); + static QString FindValue(const TRestoringMap& theMap, const std::string& theArg, bool* isFind = NULL); + static void StrToMap(const QString& theStr, VISU::Storable::TRestoringMap& theMap); + static SALOMEDS::SObject_ptr GetResultSO(SALOMEDS::SObject_ptr theSObject); + static void DataToStream(std::ostringstream& theStr, const QString& theName, const QString& theVal); + static void DataToStream(std::ostringstream& theStr, const QString& theName, const int theVal); + static void DataToStream(std::ostringstream& theStr, const QString& theName, const double theVal); + }; + + //=========================================================================== + class RemovableObject_i : public virtual POA_VISU::RemovableObject, + public virtual Storable + { + public: + virtual void RemoveFromStudy() = 0; + }; + + //=========================================================================== + const CORBA::Boolean IsMultifile(); + QString GenerateName(const std::string& theFmt, int theId); + + PortableServer::ServantBase_var GetServant(CORBA::Object_ptr theObject); + CORBA::Object_var ClientSObjectToObject(_PTR(SObject) theSObject); + CORBA::Object_var SObjectToObject(SALOMEDS::SObject_ptr); + + _PTR(SComponent) ClientFindOrCreateVisuComponent(_PTR(Study) theStudyDocument); + SALOMEDS::SComponent_var FindOrCreateVisuComponent(SALOMEDS::Study_ptr theStudyDocument); + + std::string CreateAttributes(SALOMEDS::Study_ptr theStudyDocument, + const char* theFatherEntry, const char* theRefFatherEntry, + const char* theIOR, const char* theName, + const char* thePersistentRef, const char* theComment, + CORBA::Boolean theCreateNew = true); + + std::string CreateAttributes(_PTR(Study) theStudyDocument, + const char* theFatherEntry, const char* theRefFatherEntry, + const char* theIOR, const char* theName, + const char* thePersistentRef, const char* theComment, + CORBA::Boolean theCreateNew = true); + + std::string FindEntryWithComment(SALOMEDS::Study_ptr theStudyDocument, const char* theStartEntry, + const char* theComment, int IsAllLevels = true); + + SALOMEDS::SObject_var GetSObject(_PTR(SObject)); + _PTR(SObject) GetClientSObject(SALOMEDS::SObject_var, _PTR(Study)); + + SALOMEDS::Study_var GetDSStudy(_PTR(Study)); + + void RemoveFromStudy(SALOMEDS::SObject_ptr theSObject, + bool theIsAttrOnly = true, + bool theDestroySubObjects = false); + void RemoveFromStudy(_PTR(SObject) theSObject, + bool theIsAttrOnly = true, + bool theDestroySubObjects = false); +} + +#endif diff --git a/src/VISU_I/VISU_Gen_i.cc b/src/VISU_I/VISU_Gen_i.cc new file mode 100644 index 00000000..d1b47cf3 --- /dev/null +++ b/src/VISU_I/VISU_Gen_i.cc @@ -0,0 +1,979 @@ +// VISU OBJECT : interactive object for VISU entities implementation +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// File : VISU_Gen_i.cc +// Author : Alexey PETROV +// Module : VISU + +#include "VISU_Gen_i.hh" +#include "VISU_Result_i.hh" +#include "VISU_PrsObject_i.hh" +#include "VISU_ViewManager_i.hh" + +#include "VISU_Prs3d_i.hh" +#include "VISU_Mesh_i.hh" +#include "VISU_ScalarMap_i.hh" +#include "VISU_IsoSurfaces_i.hh" +#include "VISU_DeformedShape_i.hh" +#include "VISU_CutPlanes_i.hh" +#include "VISU_CutLines_i.hh" +#include "VISU_Vectors_i.hh" +#include "VISU_StreamLines_i.hh" +#include "VISU_Plot3D_i.hh" +#include "VISU_Table_i.hh" +#include "VISU_TimeAnimation.h" + +#include "VISU_Actor.h" + +#include "HDFascii.hxx" +#include "SALOMEDS_Tool.hxx" + +#include "SALOMEDSClient_AttributeName.hxx" +#include "SALOMEDSClient_AttributePixMap.hxx" + +#include "SUIT_Session.h" +#include "SalomeApp_Study.h" +#include "SalomeApp_Application.h" +#include "SalomeApp_SelectionMgr.h" +#include "SVTK_ViewModel.h" +#include "SVTK_ViewWindow.h" +#include "SALOME_Event.hxx" +#include "SALOME_ListIO.hxx" +#include "SALOME_ListIteratorOfListIO.hxx" + +#include "utilities.h" + +// IDL Headers +#include +#include CORBA_SERVER_HEADER(SALOME_Session) +#include CORBA_SERVER_HEADER(SALOME_ModuleCatalog) + +// QT Includes +#include +#include + +// VTK Includes +#include +#include + +// OCCT Includes +#include +#include + +// STL Includes +#include + +#include "Utils_ExceptHandlers.hxx" + +using namespace std; + +static QFileInfo aFileInfo; + +#ifdef _DEBUG_ +static int MYDEBUG = 1; +#else +static int MYDEBUG = 0; +#endif + +UNEXPECT_CATCH(SalomeException, SALOME::SALOME_Exception); + +extern "C" VISU::VISU_Gen_ptr GetImpl(CORBA::ORB_ptr theORB, + PortableServer::POA_ptr thePOA, + SALOME_NamingService* theNamingService, + QMutex* theMutex) +{ + if(MYDEBUG) MESSAGE("extern \"C\" GetImpl"); + VISU::VISU_Gen_i *aVISU_Gen = new VISU::VISU_Gen_i(theORB,thePOA,theNamingService,theMutex); + //return VISU::VISU_Gen::_duplicate(aVISU_Gen->_this()); + return aVISU_Gen->_this(); +} + +namespace VISU{ + static string VisuTmpDir; + + static CORBA::Boolean myIsMultiFile; + const CORBA::Boolean IsMultifile() { return myIsMultiFile;} + + //=========================================================================== + _PTR(SComponent) ClientFindOrCreateVisuComponent (_PTR(Study) theStudyDocument) + { + _PTR(SComponent) aSComponent = theStudyDocument->FindComponent("VISU"); + if (!aSComponent) { + _PTR(StudyBuilder) aStudyBuilder = theStudyDocument->NewBuilder(); + aStudyBuilder->NewCommand(); + int aLocked = theStudyDocument->GetProperties()->IsLocked(); + if (aLocked) theStudyDocument->GetProperties()->SetLocked(false); + aSComponent = aStudyBuilder->NewComponent("VISU"); + _PTR(GenericAttribute) anAttr = + aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributeName"); + _PTR(AttributeName) aName (anAttr); + + CORBA::ORB_var anORB = Base_i::GetORB(); + SALOME_NamingService *NamingService = new SALOME_NamingService( anORB ); + CORBA::Object_var objVarN = NamingService->Resolve("/Kernel/ModulCatalog"); + SALOME_ModuleCatalog::ModuleCatalog_var Catalogue = + SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN); + SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent( "VISU" ); + if (!Comp->_is_nil()) { + aName->SetValue(Comp->componentusername()); + } + + anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributePixMap"); + _PTR(AttributePixMap) aPixmap (anAttr); + aPixmap->SetPixMap( "ICON_OBJBROWSER_Visu" ); + + VISU_Gen_var aVisuGen = Base_i::GetVisuGenImpl()->_this(); + aStudyBuilder->DefineComponentInstance(aSComponent, aVisuGen->GetID()); + if (aLocked) theStudyDocument->GetProperties()->SetLocked(true); + aStudyBuilder->CommitCommand(); + } + return aSComponent; + } + + SALOMEDS::SComponent_var FindOrCreateVisuComponent(SALOMEDS::Study_ptr theStudyDocument){ + SALOMEDS::SComponent_var aSComponent = theStudyDocument->FindComponent("VISU"); + if (aSComponent->_is_nil()) { + SALOMEDS::StudyBuilder_var aStudyBuilder = theStudyDocument->NewBuilder(); + aStudyBuilder->NewCommand(); + int aLocked = theStudyDocument->GetProperties()->IsLocked(); + if (aLocked) theStudyDocument->GetProperties()->SetLocked(false); + aSComponent = aStudyBuilder->NewComponent("VISU"); + SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributeName"); + SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr); + + //NRI aName->SetValue("Visu"); + CORBA::ORB_var anORB = Base_i::GetORB(); + SALOME_NamingService *NamingService = new SALOME_NamingService( anORB ); + CORBA::Object_var objVarN = NamingService->Resolve("/Kernel/ModulCatalog"); + SALOME_ModuleCatalog::ModuleCatalog_var Catalogue = SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN); + SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent( "VISU" ); + if ( !Comp->_is_nil() ) { + aName->SetValue( Comp->componentusername() ); + } + + anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributePixMap"); + SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr); + aPixmap->SetPixMap( "ICON_OBJBROWSER_Visu" ); + + VISU_Gen_var aVisuGen = Base_i::GetVisuGenImpl()->_this(); + aStudyBuilder->DefineComponentInstance(aSComponent,aVisuGen); + if (aLocked) theStudyDocument->GetProperties()->SetLocked(true); + aStudyBuilder->CommitCommand(); + } + return aSComponent; + } + + void RegistryStorable() { + Storable::Registry(Result_i::myComment.c_str(),&(Result_i::Restore)); + Storable::Registry(Mesh_i::myComment.c_str(),&(Restore)); + Storable::Registry(ScalarMap_i::myComment.c_str(),&(Restore)); + Storable::Registry(DeformedShape_i::myComment.c_str(),&(Restore)); + Storable::Registry(CutPlanes_i::myComment.c_str(),&(Restore)); + Storable::Registry(CutLines_i::myComment.c_str(),&(Restore)); + Storable::Registry(IsoSurfaces_i::myComment.c_str(),&(Restore)); + Storable::Registry(StreamLines_i::myComment.c_str(),&(Restore)); + Storable::Registry(Plot3D_i::myComment.c_str(),&(Restore)); + Storable::Registry(Vectors_i::myComment.c_str(),&(Restore)); + Storable::Registry(Table_i::myComment.c_str(),&(Table_i::Restore)); + Storable::Registry(Curve_i::myComment.c_str(),&(Curve_i::Restore)); + Storable::Registry(Container_i::myComment.c_str(),&(Container_i::Restore)); + } + + + //=========================================================================== + VISU_Gen_i::VISU_Gen_i(CORBA::ORB_ptr theORB, PortableServer::POA_ptr thePOA, + SALOME_NamingService* theNamingService, QMutex* theMutex) : + Engines_Component_i() + { + if(MYDEBUG) MESSAGE("VISU_Gen_i::VISU_Gen_i : "<Resolve("/myStudyManager"); + SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow(anObj); + SALOMEDS::ListOfOpenStudies_var aListOfOpenStudies = aStudyManager->GetOpenStudies(); + if(aListOfOpenStudies->length() > 0) { + CORBA::String_var aStudyName = aListOfOpenStudies[0]; + //aFileInfo.setFile(aStudyName.in()); + myStudyDocument = aStudyManager->GetStudyByName(aStudyName/*aFileInfo.baseName()*/); + }else + if(MYDEBUG) MESSAGE("VISU_Gen_i::VISU_Gen_i : there is no opened study in StudyManager !!!"); + } + + VISU_Gen_i::~VISU_Gen_i(){ + if(MYDEBUG) MESSAGE("VISU_Gen_i::~VISU_Gen_i"); + } + //=========================================================================== + CORBA::Boolean VISU_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent, + const SALOMEDS::TMPFile & theStream, + const char* theURL, + bool isMultiFile) + { + Mutex mt(myMutex); + SALOMEDS::Study_var aStudy = theComponent->GetStudy(); + SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder(); + const char* aDir = isMultiFile? theURL: SALOMEDS_Tool::GetTmpDir().c_str(); + TCollection_AsciiString aTmpDir(const_cast(aDir)); + VisuTmpDir = aTmpDir.ToCString(); + SALOMEDS::ListOfFileNames_var aSeq = + SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.ToCString(),isMultiFile); + myIsMultiFile = isMultiFile; + return true; + } + + CORBA::Boolean VISU_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent, + const SALOMEDS::TMPFile & theStream, + const char* theURL, + bool isMultiFile) + { + return Load(theComponent, theStream, theURL, isMultiFile); + } + + char* VISU_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject, + const char* aLocalPersistentID, + CORBA::Boolean isMultiFile, + CORBA::Boolean isASCII) + { + CORBA::String_var aString(""); + if(strcmp(aLocalPersistentID,"") != 0) { + Mutex mt(myMutex); + Storable* aStorable = + Storable::Create(theSObject,VisuTmpDir.c_str(),aLocalPersistentID); + if(aStorable != NULL) aString = aStorable->GetID(); + } + return aString._retn(); + } + //=========================================================================== + SALOMEDS::TMPFile* VISU_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent, + const char* theURL, + bool isMultiFile) + { + Mutex mt(myMutex); + const char* aDir = isMultiFile? theURL: SALOMEDS_Tool::GetTmpDir().c_str(); + TCollection_AsciiString aTmpDir(const_cast(aDir)); + if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - "<GetStudy(); + + //CORBA::Boolean anIsValidScript; + //Engines::TMPFile_var aDump = DumpPython(aStudy,false,anIsValidScript); + + SALOMEDS::ChildIterator_var itBig = aStudy->NewChildIterator(theComponent); + for (; itBig->More(); itBig->Next()) { + SALOMEDS::SObject_var gotBranch = itBig->Value(); + CORBA::Object_var anObj = SObjectToObject(gotBranch); + if(CORBA::is_nil(anObj)) continue; + if(Result_i* pResult = dynamic_cast(GetServant(anObj).in())){ + switch(pResult->GetCreationId()){ + case Result_i::eImportFile: + case Result_i::eCopyAndImportFile: { + const QFileInfo& aFileInfo = pResult->GetFileInfo(); + QString aPrefix(""); + if (isMultiFile) aPrefix = SALOMEDS_Tool::GetNameFromPath(aStudy->URL()).c_str(); + QString aFileName = aPrefix + "_" + (pResult->GetName()).c_str(); + static QString aCommand; + aCommand.sprintf("cp %s %s%s",aFileInfo.filePath().latin1(),aTmpDir.ToCString(),aFileName.latin1()); + + int aRes = system(aCommand); + if(aRes){ + if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - Cann't execute the command :"< 0){ + SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames; + aSeq->length(aFileNames.Length()); + for(aCounter = aFileNames.Length(); aCounter > 0; aCounter--) + aSeq[aCounter-1] = CORBA::string_dup(aFileNames.Value(aCounter).ToCString()); + aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.ToCString(), aSeq.in(), isMultiFile); + if(!isMultiFile) + SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true); + } + return aStreamFile._retn(); + } + + SALOMEDS::TMPFile* VISU_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent, + const char* theURL, + bool isMultiFile) + { + Mutex mt(myMutex); + const char* aDir = isMultiFile? theURL: SALOMEDS_Tool::GetTmpDir().c_str(); + TCollection_AsciiString aTmpDir(const_cast(aDir)); + if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - "<GetStudy(); + SALOMEDS::ChildIterator_var itBig = aStudy->NewChildIterator(theComponent); + for (; itBig->More(); itBig->Next()) { + SALOMEDS::SObject_var gotBranch = itBig->Value(); + CORBA::Object_var anObj = SObjectToObject(gotBranch); + if(CORBA::is_nil(anObj)) continue; + if(Result_i* pResult = dynamic_cast(GetServant(anObj).in())){ + switch(pResult->GetCreationId()){ + case Result_i::eImportFile: + case Result_i::eCopyAndImportFile: { + const QFileInfo& aFileInfo = pResult->GetFileInfo(); + QString aPrefix(""); + if (isMultiFile) aPrefix = SALOMEDS_Tool::GetNameFromPath(aStudy->URL()).c_str(); + QString aFileName = aPrefix + "_" + (pResult->GetName()).c_str(); + static QString aCommand; + aCommand.sprintf("cp %s %s%s",aFileInfo.filePath().latin1(),aTmpDir.ToCString(),aFileName.latin1()); + + int aRes = system(aCommand); + if(aRes){ + if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - Can't execute the command :"< 0){ + SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames; + aSeq->length(aFileNames.Length()); + for(aCounter = aFileNames.Length(); aCounter > 0; aCounter--) + aSeq[aCounter-1] = CORBA::string_dup(aFileNames.Value(aCounter).ToCString()); + aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.ToCString(), aSeq.in(), isMultiFile); + if(!isMultiFile) + SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true); + } + return aStreamFile._retn(); + } + + char* VISU_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject, + const char* IORString, + CORBA::Boolean isMultiFile, + CORBA::Boolean isASCII) + { + CORBA::String_var aString(IORString); + if(strcmp(IORString,"") != 0){ + CORBA::ORB_ptr anORB = GetORB(); + CORBA::Object_var anObj = anORB->string_to_object(aString); + if(!CORBA::is_nil(anObj)){ + if(Storable* pStorable = dynamic_cast(GetServant(anObj).in())){ + Mutex mt(myMutex); + aString = pStorable->ToString().c_str(); + return aString._retn(); + } + } + } + return aString._retn(); + } + + char* VISU_Gen_i::GetID(){ + return Base_i::GetID(); + } + + void VISU_Gen_i::SetCurrentStudy (SALOMEDS::Study_ptr theStudy) + { + class TEvent: public SALOME_Event { + std::string myStudyName; + public: + TEvent(const std::string theStudyName):myStudyName(theStudyName) + {} + virtual void Execute() + { + bool isActive = false; + SUIT_Session* aSession = SUIT_Session::session(); + QPtrList anApplications = aSession->applications(); + QPtrListIterator anIter (anApplications); + SUIT_Application* aFirstApp = anIter.current(); + while (SUIT_Application* anApp = anIter.current()) { + ++anIter; + if (SUIT_Study* aSStudy = anApp->activeStudy()) { + if (SalomeApp_Study* aStudy = dynamic_cast(aSStudy)) { + if (_PTR(Study) aCStudy = aStudy->studyDS()) { + MESSAGE("There is an application with active study : StudyId = " + << aCStudy->StudyId() << "; Name = '" << aCStudy->Name() << "'"); + if (myStudyName == aCStudy->Name()) { + isActive = true; + break; + } + } + } + } + } + if (!isActive) { + MESSAGE("!!! anApp->onLoadDoc(myStudyName) !!!"); + // Has to be loaded in an empty or in a new application + SalomeApp_Application* anApp = dynamic_cast(aFirstApp); + anApp->onLoadDoc(myStudyName.c_str()); + } + } + }; + + if (!CORBA::is_nil(theStudy)) + { + CORBA::String_var aName = theStudy->Name(); + std::string aStudyName (aName.in()); + MESSAGE("StudyId = " << theStudy->StudyId() << "; Name = '" << aName.in() << "'"); + myStudyDocument = SALOMEDS::Study::_duplicate(theStudy); + + ProcessVoidEvent(new TEvent(aStudyName)); + } else { + MESSAGE("CORBA::is_nil(theStudy)"); + } + } + + SALOMEDS::Study_ptr VISU_Gen_i::GetCurrentStudy(){ + return SALOMEDS::Study::_duplicate(myStudyDocument); + } + + ViewManager_ptr VISU_Gen_i::GetViewManager(){ + Mutex mt(myMutex); + ViewManager_i * aViewManager = new ViewManager_i(myStudyDocument); + return ViewManager::_duplicate(aViewManager->_this()); + } + + SALOMEDS::SObject_ptr VISU_Gen_i::ImportTables(const char* theFileName){ + if(myStudyDocument->GetProperties()->IsLocked()) + return SALOMEDS::SObject::_nil(); + Mutex mt(myMutex); + SALOMEDS::SObject_var aRes = VISU::ImportTables(theFileName,myStudyDocument); + return aRes._retn(); + } + + CORBA::Boolean VISU_Gen_i::ExportTableToFile(SALOMEDS::SObject_ptr theTable, + const char* theFileName) + { + return VISU::ExportTableToFile(theTable, theFileName); + } + + Result_ptr VISU_Gen_i::ImportFile(const char* theFileName){ + if(myStudyDocument->GetProperties()->IsLocked()) + return Result::_nil(); + Mutex mt(myMutex); + aFileInfo.setFile(theFileName); + Result_i* pResult = new Result_i(myStudyDocument, + Result_i::eFile, + Result_i::eImportFile); + if(pResult->Create(theFileName) != NULL) + return pResult->_this(); + else{ + pResult->_remove_ref(); + return VISU::Result::_nil(); + } + } + + Result_ptr VISU_Gen_i::CopyAndImportFile(const char* theFileName){ + if(myStudyDocument->GetProperties()->IsLocked()) + return Result::_nil(); + Mutex mt(myMutex); + VISU::Result_var aResult; + aFileInfo.setFile(theFileName); + Result_i* pResult = new Result_i(myStudyDocument, + Result_i::eRestoredFile, + Result_i::eCopyAndImportFile); + if(pResult->Create(theFileName) != NULL) + aResult = pResult->_this(); + return aResult._retn(); + } + + Result_ptr VISU_Gen_i::ImportMed (SALOMEDS::SObject_ptr theMedSObject) + { + if (myStudyDocument->GetProperties()->IsLocked()) + return Result::_nil(); + Mutex mt(myMutex); + Result_i* pResult = new Result_i(myStudyDocument, + Result_i::eComponent, + Result_i::eImportMed); + if (pResult->Create(theMedSObject) != NULL) { + return pResult->_this(); + } else { + pResult->_remove_ref(); + return VISU::Result::_nil(); + } + } + + Result_ptr VISU_Gen_i::ImportMedField (SALOME_MED::FIELD_ptr theField) + { + if (myStudyDocument->GetProperties()->IsLocked()) + return Result::_nil(); + Mutex mt(myMutex); + Result_i* pResult = new Result_i(myStudyDocument, + Result_i::eComponent, + Result_i::eImportMedField); + if (pResult->Create(theField) != NULL) { + return pResult->_this(); + } else { + pResult->_remove_ref(); + return VISU::Result::_nil(); + } + } + + Mesh_ptr VISU_Gen_i::MeshOnEntity(Result_ptr theResult, + const char* theMeshName, + VISU::Entity theEntity) + { + if(myStudyDocument->GetProperties()->IsLocked()) + return Mesh::_nil(); + Mutex mt(myMutex); + if(Result_i* pResult = dynamic_cast(GetServant(theResult).in())){ + Mesh_i* aPresent = new Mesh_i(pResult); + if(aPresent->Create(theMeshName,theEntity) != NULL) + return aPresent->_this(); + else{ + aPresent->_remove_ref(); + } + } + return VISU::Mesh::_nil(); + } + + Mesh_ptr VISU_Gen_i::FamilyMeshOnEntity(Result_ptr theResult, + const char* theMeshName, + VISU::Entity theEntity, + const char* theFamilyName) + { + if(myStudyDocument->GetProperties()->IsLocked()) + return Mesh::_nil(); + Mutex mt(myMutex); + if(Result_i* pResult = dynamic_cast(GetServant(theResult).in())){ + Mesh_i* aPresent = new Mesh_i(pResult); + if(aPresent->Create(theMeshName,theEntity,theFamilyName) != NULL) + return aPresent->_this(); + else{ + aPresent->_remove_ref(); + } + } + return VISU::Mesh::_nil(); + } + + Mesh_ptr VISU_Gen_i::GroupMesh(Result_ptr theResult, + const char* theMeshName, + const char* theGroupName) + { + if(myStudyDocument->GetProperties()->IsLocked()) + return Mesh::_nil(); + Mutex mt(myMutex); + if(Result_i* pResult = dynamic_cast(GetServant(theResult).in())){ + Mesh_i* aPresent = new Mesh_i(pResult); + if(aPresent->Create(theMeshName,theGroupName) != NULL) + return aPresent->_this(); + else{ + aPresent->_remove_ref(); + } + } + return VISU::Mesh::_nil(); + } + + ScalarMap_ptr VISU_Gen_i::ScalarMapOnField(Result_ptr theResult, + const char* theMeshName, + VISU::Entity theEntity, + const char* theFieldName, + CORBA::Double theIteration) + { + return Prs3dOnField(theResult,theMeshName,theEntity,theFieldName,theIteration,true)._retn(); + } + + DeformedShape_ptr VISU_Gen_i::DeformedShapeOnField(Result_ptr theResult, + const char* theMeshName, + VISU::Entity theEntity, + const char* theFieldName, + CORBA::Double theIteration) + { + return Prs3dOnField(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn(); + } + + Vectors_ptr VISU_Gen_i::VectorsOnField(Result_ptr theResult, + const char* theMeshName, + VISU::Entity theEntity, + const char* theFieldName, + CORBA::Double theIteration) + { + return Prs3dOnField(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn(); + } + + IsoSurfaces_ptr VISU_Gen_i::IsoSurfacesOnField(Result_ptr theResult, + const char* theMeshName, + VISU::Entity theEntity, + const char* theFieldName, + CORBA::Double theIteration) + { + return Prs3dOnField(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn(); + } + + StreamLines_ptr VISU_Gen_i::StreamLinesOnField(Result_ptr theResult, + const char* theMeshName, + VISU::Entity theEntity, + const char* theFieldName, + CORBA::Double theIteration) + { + return Prs3dOnField(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn(); + } + + Plot3D_ptr VISU_Gen_i::Plot3DOnField(Result_ptr theResult, + const char* theMeshName, + VISU::Entity theEntity, + const char* theFieldName, + CORBA::Double theIteration) + { + return Prs3dOnField(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn(); + } + + CutPlanes_ptr VISU_Gen_i::CutPlanesOnField(Result_ptr theResult, + const char* theMeshName, + VISU::Entity theEntity, + const char* theFieldName, + CORBA::Double theIteration) + { + return Prs3dOnField(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn(); + } + + CutLines_ptr VISU_Gen_i::CutLinesOnField(Result_ptr theResult, + const char* theMeshName, + VISU::Entity theEntity, + const char* theFieldName, + CORBA::Double theIteration) + { + return Prs3dOnField(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn(); + } + + Table_ptr VISU_Gen_i::CreateTable(const char* theTableEntry){ + if(myStudyDocument->GetProperties()->IsLocked()) + return Table::_nil(); + Mutex mt(myMutex); + Table_i* pPresent = new Table_i(myStudyDocument,theTableEntry); + if(pPresent->Create() != NULL) + return pPresent->_this(); + else{ + pPresent->_remove_ref(); + return VISU::Table::_nil(); + } + } + + Curve_ptr VISU_Gen_i::CreateCurve(Table_ptr theTable, + CORBA::Long theHRow, + CORBA::Long theVRow) + { + if(myStudyDocument->GetProperties()->IsLocked()) + return Curve::_nil(); + Mutex mt(myMutex); + PortableServer::POA_ptr aPOA = GetPOA(); + Table_i* pTable = dynamic_cast(aPOA->reference_to_servant(theTable)); + Curve_i* pPresent = new Curve_i(myStudyDocument,pTable,theHRow,theVRow); + if(pPresent->Create() != NULL) + return pPresent->_this(); + else{ + pPresent->_remove_ref(); + return VISU::Curve::_nil(); + } + } + + Container_ptr VISU_Gen_i::CreateContainer(){ + if(myStudyDocument->GetProperties()->IsLocked()) + return Container::_nil(); + Mutex mt(myMutex); + Container_i* pPresent = new Container_i(myStudyDocument); + if(pPresent->Create() != NULL) + return pPresent->_this(); + else{ + pPresent->_remove_ref(); + return VISU::Container::_nil(); + } + } + + Animation_ptr VISU_Gen_i::CreateAnimation(View3D_ptr theView3D){ + if(myStudyDocument->GetProperties()->IsLocked()) + return Animation::_nil(); + Mutex mt(myMutex); + if(VISU_TimeAnimation_i* anAnim = new VISU_TimeAnimation_i(myStudyDocument,theView3D)){ + return anAnim->_this(); + }else + return VISU::Animation::_nil(); + } + + void VISU_Gen_i::DeleteResult (Result_ptr theResult) + { + class TEvent: public SALOME_Event { + Result_ptr myResult; + public: + TEvent(Result_ptr theResult): myResult(theResult) {} + virtual void Execute() + { + if (Result_i* aResult = dynamic_cast(GetServant(myResult).in())) { + SALOMEDS::SObject_var aSObject = aResult->GetSObject(); + VISU::RemoveFromStudy(aSObject, + false, // not only attribute + true); // destroy sub-objects + + //jfa tmp:if (QAD_Desktop* aDesktop = QAD_Application::getDesktop()) + //jfa tmp: if (QAD_Study* aStudy = aDesktop->findStudy(aStudyDocument)) + //jfa tmp: aStudy->updateObjBrowser(); //update Object browser + } + + myResult->Destroy(); + } + }; + + if (myStudyDocument->GetProperties()->IsLocked()) + return; + Mutex mt(myMutex); // jfa ??? + + ProcessVoidEvent(new TEvent(theResult)); + } + + void VISU_Gen_i::DeletePrs3d (Prs3d_ptr thePrs3d) + { + class TEvent: public SALOME_Event { + Prs3d_ptr myPrs3d; + public: + TEvent(Prs3d_ptr thePrs3d): myPrs3d(thePrs3d) {} + virtual void Execute() { + myPrs3d->RemoveFromStudy(); + + //update Object browser + /*jfa tmp:if (QAD_Desktop* aDesktop = QAD_Application::getDesktop()) { + if (Prs3d_i* aPrs3d = dynamic_cast(GetServant(myPrs3d).in())) { + SALOMEDS::SObject_var aSObject = aPrs3d->GetSObject(); + SALOMEDS::Study_var aStudyDocument = aSObject->GetStudy(); + if (QAD_Study* aStudy = aDesktop->findStudy(aStudyDocument)) + aStudy->updateObjBrowser(); + } + }*/ + + myPrs3d->Destroy(); + } + }; + + if (myStudyDocument->GetProperties()->IsLocked()) + return; + Mutex mt(myMutex); // jfa ??? + + ProcessVoidEvent(new TEvent(thePrs3d)); + } + + void VISU_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent){ + } + + char* VISU_Gen_i::ComponentDataType(){ + return CORBA::string_dup("VISU"); + } + + bool VISU_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR) { + Result_var aResultObj = Result::_narrow(theIOR); + return !(aResultObj->_is_nil()); + } + + SALOMEDS::SObject_ptr VISU_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy, + SALOMEDS::SObject_ptr theSObject, + CORBA::Object_ptr theObject, + const char* theName) + throw (SALOME::SALOME_Exception) + { + Unexpect aCatch(SalomeException); + if(MYDEBUG) MESSAGE("VISU_Gen_i::PublishInStudy : "<(GetServant(theObject).in()); + if (!aResultObj) return aResultSO._retn(); + const QFileInfo& aFileInfo = aResultObj->GetFileInfo(); + CORBA::String_var anEntry = aResultObj->Create(aFileInfo.filePath().latin1())->GetID(); + aResultSO = theStudy->FindObjectID(anEntry); + return aResultSO._retn(); + } + + CORBA::Boolean VISU_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) { + Mutex mt(myMutex); + SALOMEDS::GenericAttribute_var anAttr; + if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false; + try { + SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); + CORBA::String_var aValue = anIOR->Value(); + if(strcmp(aValue,"") != 0){ + CORBA::Object_ptr anObj = GetORB()->string_to_object(aValue); + if (!CORBA::is_nil(anObj)){ + Result_var aResultObj = Result::_narrow(anObj); + if(!aResultObj->_is_nil()){ + if(Result_i* pResult = dynamic_cast(GetServant(aResultObj).in())){ + switch(pResult->GetCreationId()){ + case Result_i::eImportFile: + case Result_i::eCopyAndImportFile: + return true; + } + } + } + } + } + }catch(std::exception& exc){ + INFOS("Follow exception was occured :\n"<FindAttribute(anAttr,"AttributeIOR")) return NULL; + SALOMEDS::AttributeIOR_var anIORAttr = SALOMEDS::AttributeIOR::_narrow(anAttr); + CORBA::Object_var aCorbaObj; + try { + aCorbaObj = GetORB()->string_to_object(anIORAttr->Value()); + } catch(...) { + aStreamFile->length(1); + aStreamFile[0] = strdup("E")[0]; + return aStreamFile._retn(); + } + if (CORBA::is_nil(aCorbaObj)) { + return NULL; + } + + Storable* pStorable = dynamic_cast(GetServant(aCorbaObj).in()); + if (!pStorable) { + return NULL; + } + + string aTmpDir = SALOMEDS_Tool::GetTmpDir(); + string aCopyPersist = aTmpDir + "copy_persistent"; + + ofstream stmOut2(aCopyPersist.c_str(),ios::out); + string aStr = pStorable->ToString().c_str(); + stmOut2<(aPOA->reference_to_servant(aCorbaObj))) { + string aFileName = string(SALOMEDS_Tool::GetNameFromPath(theObject->GetStudy()->URL())) + "_"; + if(strlen(aFileName.c_str()) == 1) aFileName=""; + const QFileInfo& aFileInfo = aResultObj->GetFileInfo(); + aFileName += aFileInfo.fileName().latin1(); + static QString aCommand; + string aFullFileName = aTmpDir + aFileName; + aCommand.sprintf("cp %s %s", + aFileInfo.filePath().latin1(), + aFullFileName.c_str()); + if(system(aCommand) == -1) { + if(MYDEBUG) MESSAGE("VISU_Gen_i::Copy - Cann't execute the command :"<length(2); + aSeq[0] = "copy_persistent"; + aSeq[1] = aFileName.c_str(); + } else { + aSeq->length(1); + aSeq[0] = "copy_persistent"; + } + + aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.c_str(), aSeq.in(), false); + SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true); + + // Assign an ID = 1 the the type VISU::Result + theObjectID = 1; + + + SALOMEDS::SComponent_var aSComponent = theObject->GetStudy()->FindComponent("VISU"); + return aStreamFile._retn(); + } + + CORBA::Boolean VISU_Gen_i::CanPaste(const char* theComponentName, CORBA::Long theObjectID) { + // The VISU component can paste only objects copied by VISU component + // and with the object type = 1 + if (strcmp(theComponentName, ComponentDataType()) != 0 || theObjectID != 1) + return false; + return true; + } + + SALOMEDS::SObject_ptr VISU_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream, + CORBA::Long theObjectID, + SALOMEDS::SObject_ptr theObject) + { + Mutex mt(myMutex); + SALOMEDS::SObject_var aResultSO; + if (theObjectID != 1) + return aResultSO._retn(); + + string aTmpDir = SALOMEDS_Tool::GetTmpDir(); + SALOMEDS::ListOfFileNames_var aSeq = SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.c_str(), false); + + ifstream stmIn((aTmpDir + string("copy_persistent")).c_str()); + stmIn.seekg(0, ios::end); + int aLength = stmIn.tellg(); + stmIn.seekg(0, ios::beg); + char* aString = new char[aLength+1]; + stmIn.read(aString, aLength); + aString[aLength] = 0; + myIsMultiFile = false; + + string aFileName(aTmpDir); + string aBasicFileName; + if(aSeq->length() > 1) { + aBasicFileName = aSeq[1].in(); + aFileName += aBasicFileName; + } + + SALOMEDS::SComponent_var aComponent = theObject->GetFatherComponent(); + SALOMEDS::Study_var aStudy = theObject->GetStudy(); + SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder(); + CORBA::String_var aComponentID(aComponent->GetID()), aSObjID(theObject->GetID()); + + if (strcmp(aComponentID, aSObjID) == 0) //create the new result SObject + aResultSO = aStudyBuilder->NewObject(aComponent); + else + aResultSO = SALOMEDS::SObject::_duplicate(theObject); + + //Just for Result::Restore to find the Comment attribute :( + SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeComment"); + + Storable* aStorable = Storable::Create(aResultSO,aFileName,aString); + + SALOMEDS::ListOfFileNames_var aSeqToRm = new SALOMEDS::ListOfFileNames; + aSeqToRm->length(1); + aSeqToRm[0] = "copy_persistent"; + + SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeqToRm.in(), true); + + anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR"); + SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); + CORBA::String_var anIORValue(aStorable->GetID()); + anIOR->SetValue(anIORValue); + return aResultSO._retn(); + } +} diff --git a/src/VISU_I/VISU_Result_i.cc b/src/VISU_I/VISU_Result_i.cc new file mode 100644 index 00000000..359aea09 --- /dev/null +++ b/src/VISU_I/VISU_Result_i.cc @@ -0,0 +1,858 @@ +// VISU OBJECT : interactive object for VISU entities implementation +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// File : VISU_Result_i.cc +// Author : Alexey PETROV +// Module : VISU + +#include "VISU_Result_i.hh" + +#include "VISU_Convertor_impl.hxx" +#include "VISU_CorbaMedConvertor.hxx" +#include "VISU_PipeLine.hxx" + +#include "SUIT_ResourceMgr.h" + +#include "SALOMEDS_Tool.hxx" +#include "HDFascii.hxx" + +// QT Includes +#include +#include + +// VTK Includes +#include +#include + +// OCCT Includes +#include + +using namespace VISU; +using namespace std; + +#ifdef _DEBUG_ +static int MYDEBUG = 0; +#else +static int MYDEBUG = 0; +#endif + +VISU::Result_var VISU::FindResult (SALOMEDS::SObject_ptr theSObject) +{ + SALOMEDS::SComponent_var aSComponent = theSObject->GetFatherComponent(); + SALOMEDS::SObject_var aFather = theSObject->GetFather(); + CORBA::String_var aComponentID (aSComponent->GetID()); + CORBA::String_var aFatherID (aFather->GetID()); + VISU::Result_var aResult; + while (strcmp(aComponentID, aFatherID) != 0) { + CORBA::Object_var anObject = VISU::SObjectToObject(aFather); + if (!CORBA::is_nil(anObject)) { + aResult = VISU::Result::_narrow(anObject); + if (!aResult->_is_nil()) return aResult; + } + aFather = aFather->GetFather(); + aFatherID = aFather->GetID(); + } + return aResult; +} + +QString GenerateName (const char* theName) +{ + typedef map TNameMap; + static TNameMap aMap; + TNameMap::const_iterator i = aMap.find(theName); + QString tmp; + if (i == aMap.end()) { + aMap[theName] = 0; + tmp = theName; + } else { + tmp = VISU::GenerateName(theName,++aMap[theName]); + } + if(MYDEBUG) MESSAGE("GenerateName - "<NewBuilder(); + SALOMEDS::SObject_var aFather = theStudyDocument->FindObjectID(theFatherEntry.c_str()); + SALOMEDS::SObject_var newObj = aStudyBuilder->NewObject(aFather); + SALOMEDS::SObject_var aRefSObj = theStudyDocument->FindObjectID(theRefEntry.c_str()); + aStudyBuilder->Addreference(newObj,aRefSObj); +} + +string GetComponentDataType (SALOMEDS::SObject_ptr theSObject) +{ + SALOMEDS::SComponent_var aCompRefSObj = theSObject->GetFatherComponent(); + CORBA::String_var aDataType = aCompRefSObj->ComponentDataType(); + return aDataType.in(); +} + +//============================================================================== + +const string VISU::Result_i::myComment = "RESULT"; +const char* VISU::Result_i::GetComment() const { return myComment.c_str();} + +VISU::Result_i::Result_i (SALOMEDS::Study_ptr theStudy, + const ESourceId& theSourceId, + const ECreationId& theCreationId): + myStudyDocument(SALOMEDS::Study::_duplicate(theStudy)), + myCreationId(theCreationId), + mySourceId(theSourceId), + myInput(NULL), + myIsDone(0) +{ +} + + +void VISU::Result_i::RemoveFromStudy() +{ + // Remove the result with all presentations and other possible sub-objects + VISU::RemoveFromStudy(mySObject,false); +} + + +int +VISU::Result_i:: +IsPossible() +{ + try{ + float aSize = myInput->GetSize(); + bool aResult = VISU_PipeLine::CheckAvailableMemory(aSize); + MESSAGE("Result_i::IsPossible - CheckAvailableMemory = "<myGroupMap; + VISU::TGroupMap::const_iterator aGroupMapIter = aGroupMap.begin(); + for(; aGroupMapIter != aGroupMap.end(); aGroupMapIter++){ + const string& aGroupName = aGroupMapIter->first; + try{ + myInput->GetMeshOnGroup(aMeshName,aGroupName); + }catch(std::exception& exc){ + INFOS("Follow exception was occured :\n"<myFamilyMap; + VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin(); + for(; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){ + const string& aFamilyName = aFamilyMapIter->first; + try{ + myInput->GetMeshOnEntity(aMeshName,anEntity,aFamilyName); + }catch(std::exception& exc){ + INFOS("Follow exception was occured :\n"<GetMeshOnEntity(aMeshName,anEntity); + }catch(std::exception& exc){ + INFOS("Follow exception was occured :\n"<NewBuilder(); + aStudyBuilder->NewCommand(); // There is a transaction + if(MYDEBUG) MESSAGE("Result_i::Build"); + try{ + const TMeshMap& aMeshMap = myInput->GetMeshMap(); + if(aMeshMap.empty()) + throw std::runtime_error("Build - There is no any mesh information in the file !!!"); + mySComponent = FindOrCreateVisuComponent(myStudyDocument); + CORBA::String_var aSComponentEntry = mySComponent->GetID(), anIOR(GetID()); + string aRefFatherEntry = GetRefFatherEntry(); + QString aComment; + aComment.sprintf("myComment=%s;myType=%d;myFileName=%s;myInitFileName=%s", + GetComment(), + VISU::TRESULT, + myFileInfo.filePath().latin1(), + myInitFileName.c_str()); // Restoring of Python dump + string aResultEntry = + CreateAttributes(myStudyDocument, + aSComponentEntry, + aRefFatherEntry.c_str(), + anIOR, + myName.c_str(), + "", + aComment.latin1(), + true); + mySObject = myStudyDocument->FindObjectID(aResultEntry.c_str()); + if(mySObject->_is_nil()) throw std::runtime_error("Build - There is no SObject for the Result !!!"); + if(!CORBA::is_nil(theSObject)){ + CORBA::String_var aString = theSObject->GetID(); + CreateReference(myStudyDocument,aResultEntry,aString.in()); + } + TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin(); + for(; aMeshMapIter != aMeshMap.end(); aMeshMapIter++){ + const string& aMeshName = aMeshMapIter->first; + const VISU::PMesh aMesh = aMeshMapIter->second; + const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap; + VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter; + aComment.sprintf("myComment=MESH;myName=%s;myDim=%d", + aMeshName.c_str(),aMesh->myDim); + string aMeshEntry = CreateAttributes(myStudyDocument,aResultEntry.c_str(),aRefFatherEntry.c_str(), + "",aMeshName.c_str(),"",aComment.latin1(),true); + if(aMeshOnEntityMap.empty()) continue; + aComment.sprintf("myComment=FAMILIES;myMeshName=%s",aMeshName.c_str()); + string aSubMeshesEntry = CreateAttributes(myStudyDocument,aMeshEntry.c_str(),aRefFatherEntry.c_str(), + "","Families","",aComment.latin1(),true); + //Import entities and according families + aMeshOnEntityMapIter = aMeshOnEntityMap.begin(); + typedef std::map TComment2EntryMap; + TComment2EntryMap aComment2EntryMap; + typedef std::map TEntity2EntryMap; + TEntity2EntryMap aEntity2EntryMap; + for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){ + const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first; + aComment.sprintf("myComment=ENTITY;myType=%d;myMeshName=%s;myId=%d", + VISU::TENTITY, + aMeshName.c_str(), + anEntity); + string anEntityName; + switch(anEntity){ + case VISU::NODE_ENTITY : anEntityName = "onNodes"; break; + case VISU::EDGE_ENTITY : anEntityName = "onEdges"; break; + case VISU::FACE_ENTITY : anEntityName = "onFaces"; break; + case VISU::CELL_ENTITY : anEntityName = "onCells"; break; + default: + throw std::runtime_error("Build >> Value of entity is incorrect!"); + } + aEntity2EntryMap[anEntity] = CreateAttributes + (myStudyDocument, aSubMeshesEntry.c_str(), aRefFatherEntry.c_str(), + "", anEntityName.c_str(), "", aComment.latin1(), true); + const VISU::PMeshOnEntity aMeshOnEntity = aMeshOnEntityMapIter->second; + const VISU::TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap; + VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin(); + for(; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){ + const string& aFamilyName = aFamilyMapIter->first; + aComment.sprintf("myComment=FAMILY;myType=%d;myMeshName=%s;myEntityId=%d;myName=%s", + VISU::TFAMILY, + aMeshName.c_str(), + anEntity, + aFamilyName.c_str()); + aComment2EntryMap[aComment.latin1()] = + CreateAttributes(myStudyDocument, + aEntity2EntryMap[anEntity].c_str(), + aRefFatherEntry.c_str(), + "", + aFamilyName.c_str(), + "", + aComment.latin1(), + true); + } + } + //Importing groups + const VISU::TGroupMap& aGroupMap = aMesh->myGroupMap; + if(aGroupMap.size() > 0){ + aComment.sprintf("myComment=GROUPS;myMeshName=%s", + aMeshName.c_str()); + string aGroupsEntry = + CreateAttributes(myStudyDocument, + aMeshEntry.c_str(), + aRefFatherEntry.c_str(), + "", + "Groups", + "", + aComment.latin1(), + true); + VISU::TGroupMap::const_iterator aGroupMapIter = aGroupMap.begin(); + for(; aGroupMapIter != aGroupMap.end(); aGroupMapIter++){ + const string& aGroupName = aGroupMapIter->first; + aComment.sprintf("myComment=GROUP;myType=%d;myMeshName=%s;myName=%s", + VISU::TGROUP,aMeshName.c_str(),aGroupName.c_str()); + string aGroupEntry = CreateAttributes(myStudyDocument,aGroupsEntry.c_str(),aRefFatherEntry.c_str(), + "",aGroupName.c_str(),"",aComment.latin1(),true); + const VISU::PGroup aGroup = aGroupMapIter->second; + const VISU::TFamilyAndEntitySet& aFamilyAndEntitySet = aGroup->myFamilyAndEntitySet; + VISU::TFamilyAndEntitySet::const_iterator aFamilyAndEntitySetIter = aFamilyAndEntitySet.begin(); + for(; aFamilyAndEntitySetIter != aFamilyAndEntitySet.end(); aFamilyAndEntitySetIter++){ + const VISU::TFamilyAndEntity& aFamilyAndEntity = *aFamilyAndEntitySetIter; + const string& aFamilyName = aFamilyAndEntity.first; + const VISU::TEntity& anEntity = aFamilyAndEntity.second; + aComment.sprintf("myComment=FAMILY;myType=%d;myMeshName=%s;myEntityId=%d;myName=%s", + VISU::TFAMILY, + aMeshName.c_str(), + anEntity, + aFamilyName.c_str()); + CreateReference(myStudyDocument,aGroupEntry,aComment2EntryMap[aComment.latin1()]); + } + } + } + //Import fields + string aFieldsEntry; + bool isFieldEntryCreated = 0; + aMeshOnEntityMapIter = aMeshOnEntityMap.begin(); + for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){ + const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first; + const VISU::PMeshOnEntity aMeshOnEntity = aMeshOnEntityMapIter->second; + const VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap; + VISU::TFieldMap::const_iterator aFieldMapIter = aFieldMap.begin(); + for(; aFieldMapIter != aFieldMap.end(); aFieldMapIter++){ + if(!isFieldEntryCreated){ + aComment.sprintf("myComment=FIELDS;myMeshName=%s", + aMeshName.c_str()); + aFieldsEntry = + CreateAttributes(myStudyDocument, + aMeshEntry.c_str(), + aRefFatherEntry.c_str(), + "", + "Fields", + "", + aComment.latin1(), + true); + isFieldEntryCreated = true; + } + const string& aFieldName = aFieldMapIter->first; + const VISU::PField aField = aFieldMapIter->second; + const VISU::TValField& aValField = aField->myValField; + QString aFieldNameWithUnit = ::GenerateFieldName(aFieldName,aField->myUnitNames[0]); + aComment.sprintf("myComment=FIELD;myType=%d;myMeshName=%s;myEntityId=%d;myName=%s;myNbTimeStamps=%d;myNumComponent=%d", + VISU::TFIELD,aMeshName.c_str(),anEntity,aFieldName.c_str(),aValField.size(),aField->myNbComp); + string aFieldEntry = CreateAttributes(myStudyDocument,aFieldsEntry.c_str(),aRefFatherEntry.c_str(), + "",aFieldNameWithUnit.latin1(),"",aComment.latin1(),true); + CreateReference(myStudyDocument,aFieldEntry,aEntity2EntryMap[anEntity]); + VISU::TValField::const_iterator aValFieldIter = aValField.begin(); + for(; aValFieldIter != aValField.end(); aValFieldIter++){ + int aTimeStamp = aValFieldIter->first; + const VISU::PValForTime aValForTime = aValFieldIter->second; + aComment.sprintf("myComment=TIMESTAMP;myType=%d;myMeshName=%s;myEntityId=%d;myFieldName=%s;myTimeStampId=%d;myNumComponent=%d", + VISU::TTIMESTAMP,aMeshName.c_str(),anEntity,aFieldName.c_str(),aTimeStamp,aField->myNbComp); + string aTimeStampId = VISU_Convertor::GenerateName(aValForTime->myTime); + CreateAttributes(myStudyDocument,aFieldEntry.c_str(),aRefFatherEntry.c_str(), + "",aTimeStampId.c_str(),"",aComment.latin1(),true); + } + } + } + } + bool isBuildAll = VISU::GetResourceMgr()->booleanValue("VISU", "full_med_loading", false); + if(isBuildAll) BuildAll(); + }catch(std::exception& exc){ + INFOS("Follow exception was occured :\n"<CommitCommand(); + return this; +} + + +VISU::Storable* +VISU::Result_i:: +Create(const char* theFileName) +{ + try{ + myFileInfo.setFile(theFileName); + myInitFileName = myFileInfo.filePath().latin1(); + myName = ::GenerateName(myFileInfo.fileName()).latin1(); + if(mySourceId == eRestoredFile){ + std::string aTmpDir(SALOMEDS_Tool::GetTmpDir()); + static QString aCommand; + aCommand.sprintf("cp %s %s",myFileInfo.absFilePath().latin1(),aTmpDir.c_str()); + if(system(aCommand) == -1){ + MESSAGE("Create - Can't execute the command :"<ConvertObjectToIOR(theField); + SALOMEDS::SObject_var aFieldSObject = myStudyDocument->FindObjectIOR(anIOR); + + VISU::Storable* aStorable = Build(aFieldSObject); + return aStorable; + }catch(std::exception& exc){ + INFOS("Follow exception was occured :\n"<GetStudy(); + mySComponent = mySObject->GetFatherComponent(); + myName = VISU::Storable::FindValue(theMap, "myName").latin1(); + myInitFileName = VISU::Storable::FindValue(theMap, "myInitFileName").latin1(); + + SALOMEDS::SObject_var aRefSObj, aTargetRefSObj; + if (mySObject->FindSubObject(1, aRefSObj) && + aRefSObj->ReferencedObject(aTargetRefSObj)) { + if(MYDEBUG) MESSAGE("Result_i::GetInput - There is some reference."); + SALOMEDS::SComponent_var aCompRefSObj = aTargetRefSObj->GetFatherComponent(); + CORBA::String_var aDataType = aCompRefSObj->ComponentDataType(); + myFileInfo.setFile(aDataType.in()); + if(MYDEBUG) MESSAGE("Result_i::GetInput - aDataType = " << aDataType); + Engines::Component_var aEngComp = + Base_i::myEnginesLifeCycle->FindOrLoad_Component("FactoryServer", aDataType.in()); + if (CORBA::is_nil(aEngComp)) + throw std::runtime_error("Restore - There is no aEngComp for the aDataType !!!"); + SALOMEDS::StudyBuilder_var aStudyBuilder = myStudyDocument->NewBuilder(); + SALOMEDS::Driver_var aDriver = SALOMEDS::Driver::_narrow(aEngComp); + aStudyBuilder->LoadWith(aCompRefSObj, aDriver); + if (strcmp(aDataType, "MED") == 0) + myInput = CreateMEDConvertor(aTargetRefSObj); + else + throw std::runtime_error("GetInput - There is no convertor for the aDataType !!!"); + } else { + myFileInfo.setFile(thePrefix.c_str()); + + string aStudyPrefix (""); + if (IsMultifile()) + aStudyPrefix = SALOMEDS_Tool::GetNameFromPath(myStudyDocument->URL()); + if (!myFileInfo.isFile()) { + string aFileName = thePrefix + aStudyPrefix + "_" + myName; + myFileInfo.setFile(aFileName.c_str()); + } + if(MYDEBUG) + MESSAGE("Result_i::Restore - aFileName = " << myFileInfo.filePath() << "; " << myFileInfo.isFile()); + + const char* aPathLatin = myFileInfo.filePath().latin1(); + if (HDFascii::isASCII(aPathLatin)) { + MESSAGE("ConvertFromASCIIToHDF(" << aPathLatin << ")"); + char* aResultPath = HDFascii::ConvertFromASCIIToHDF(aPathLatin); + MESSAGE("ConvertFromASCIIToHDF() DONE : " << aResultPath); + char* aHDFFileName = new char[strlen(aResultPath) + 19]; + sprintf(aHDFFileName, "%shdf_from_ascii.hdf", aResultPath); + + if (IsMultifile()) { // set this file as new - temporary + static QString aCommand; + aCommand.sprintf("mv %s %s%s",aHDFFileName, aResultPath, myFileInfo.baseName().latin1()); + if (system(aCommand) == -1) { + if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - Can't execute the command :" << aCommand); + return NULL; + } else { + if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - " << aCommand); + } + myFileInfo.setFile(QString(aResultPath) + QString(myFileInfo.baseName().latin1())); + } else { // change current temporary file to the new: with hdf-format + static QString aCommand; + aCommand.sprintf("mv %s %s\0",aHDFFileName, myFileInfo.filePath().latin1()); + if (system(aCommand.latin1()) == -1) { + if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - Can't execute the command :" << aCommand); + return NULL; + } else { + if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - " << aCommand); + } + SALOMEDS::ListOfFileNames_var anEmptyList = new SALOMEDS::ListOfFileNames; + SALOMEDS_Tool::RemoveTemporaryFiles(aResultPath, anEmptyList.in(), true); + } + mySourceId = eRestoredFile; + delete(aResultPath); + delete(aHDFFileName); + } else if (!IsMultifile()) { + mySourceId = eRestoredFile; + } else { + mySourceId = eFile; + } + if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - mySourceId = " << mySourceId); + myInput = CreateConvertor(myFileInfo.filePath().latin1()); + QString aComment; + aComment.sprintf("myComment=%s;myType=%d;myFileName=%s;myInitFileName=%s", + GetComment(), VISU::TRESULT, myFileInfo.filePath().latin1(), + myInitFileName.c_str()); // Restoring of Python dump + SALOMEDS::GenericAttribute_var anAttr; + if (!theSObject->FindAttribute(anAttr, "AttributeComment")) + throw std::runtime_error("Build - There is no AttributeComment for the SObject !!!"); + SALOMEDS::AttributeComment_var aCmnt = SALOMEDS::AttributeComment::_narrow(anAttr); + aCmnt->SetValue(aComment.latin1()); + } + bool isBuildAll = VISU::GetResourceMgr()->booleanValue("VISU", "full_med_loading", false); + if (isBuildAll) + BuildAll(); + return this; + } catch(std::exception& exc) { + INFOS("Follow exception was occured :\n"<GetStudy(); + + ECreationId aCreationId = ECreationId(Storable::FindValue(theMap,"myCreationId").toInt()); + ESourceId aSourceId = eRestoredFile; + if(aCreationId == eImportMed || aCreationId == eImportMedField) + aSourceId = eRestoredComponent; + + VISU::Result_i* pResult = new VISU::Result_i(aStudy,aSourceId,aCreationId); + if (pResult == NULL) + return NULL; + + return pResult->Restore(theSObject,theMap,thePrefix); +} + +string VISU::Result_i::GetRefFatherEntry() { + //return QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->entry(); + return ""; +} + +string VISU::Result_i::GetEntry(){ + CORBA::String_var anEntry = mySObject->GetID(); + return string(anEntry); +} + +const SALOMEDS::SObject_var& VISU::Result_i::GetSObject() const { return mySObject;} +const SALOMEDS::Study_var& VISU::Result_i::GetStudyDocument() const { return myStudyDocument;} +const SALOMEDS::SComponent_var& VISU::Result_i::GetSComponent() const { return mySComponent;} +std::string VISU::Result_i::GetEntry(const std::string& theComment) +{ + return FindEntryWithComment(myStudyDocument,GetEntry().c_str(),theComment.c_str()); +} + +VISU::Result_i::~Result_i() +{ + MESSAGE("Result_i::~Result_i() - this = "<::iterator name_info; + name_info = myMeshName2GridInfoMap.find( theMeshName ); + TGridInfo * gInfo = 0; + + if ( name_info != myMeshName2GridInfoMap.end() ) + { + gInfo = & name_info->second; + } + else if ( myInput && IsPossible() && theAxis >= AXIS_X && theAxis <= AXIS_Z ) + { + // check presence of theMeshName + const VISU::TMeshMap& meshMap = myInput->GetMeshMap(); + if ( meshMap.find( theMeshName ) == meshMap.end() ) { + MESSAGE("No mesh named " << theMeshName ); + return components; + } + VISU_Convertor::TOutput* vtkMesh = myInput->GetMeshOnEntity (theMeshName, + CELL_ENTITY); + if ( !vtkMesh || vtkMesh->GetNumberOfCells() == 0 ) { + MESSAGE( "No cells in the mesh: " << theMeshName ); + return components; + } + + // define axis directions and min cell size in each direction + const int nbAxes = 3; + int iAx; + gp_Vec axDirs[ nbAxes ]; + float minSize[3] = { FLT_MAX, FLT_MAX, FLT_MAX }; + bool axesComputed = false; + for ( vtkIdType iCell = 0; iCell < vtkMesh->GetNumberOfCells(); ++iCell ) + { + vtkCell* cell = vtkMesh->GetCell( iCell ); + int nbPnt = cell->GetNumberOfPoints(); + if ( nbPnt != 8 ) + continue; + vtkPoints * points = cell->GetPoints(); + float* coords[ 4 ]; + coords[0] = points->GetPoint( 0 ); + coords[1] = points->GetPoint( 1 ); + coords[2] = points->GetPoint( 3 ); + coords[3] = points->GetPoint( 4 ); + gp_Pnt p0( coords[0][0], coords[0][1], coords[0][2] ); + for ( iAx = 0; iAx < nbAxes; ++iAx ) + { + float* coo = coords[ iAx + 1 ]; + gp_Pnt p( coo[0], coo[1], coo[2] ); + // min size + float size = p0.SquareDistance( p ); + if ( size > FLT_MIN && size < minSize[ iAx ] ) + minSize[ iAx ] = size; + // axis direction + if ( !axesComputed ) { + gp_Vec dir( p0, p ); + if ( dir.SquareMagnitude() <= DBL_MIN ) + break; + axDirs[ iAx ] = dir; + } + } + if ( iAx == nbAxes ) + axesComputed = true; + } + if ( !axesComputed ) { + MESSAGE("No good hexahedrons in the mesh: " << theMeshName ); + return components; + } + + // compute axes dirs + gInfo = & myMeshName2GridInfoMap[ theMeshName ]; + for ( iAx = 0; iAx < nbAxes; ++iAx ) + { + int iPrev = ( iAx == 0 ) ? 2 : iAx - 1; + int iNext = ( iAx == 2 ) ? 0 : iAx + 1; + gInfo->myAxis[ iAx ] = axDirs[ iPrev ] ^ axDirs[ iNext ]; + } + + // get and sort intermediate component values - projections of nodes + // on axis direction; define bnd box + set< float > comps[ 3 ]; + Bnd_Box box; + vtkPoints * points = vtkMesh->GetPoints(); + vtkIdType iP, nbP = vtkMesh->GetNumberOfPoints(); + for ( iP = 0; iP < nbP; ++iP ) + { + float* coo = points->GetPoint( iP ); + gp_Pnt p( coo[0], coo[1], coo[2] ); + box.Add( p ); + for ( iAx = 0; iAx < nbAxes; ++iAx ) { + const gp_Dir& dir = gInfo->myAxis[ iAx ]; + float dot = dir.XYZ() * p.XYZ(); + comps[ iAx ].insert( dot ); + } + } + + // find a range of projections of bnd box corners on each axis + float range[3], firstValue[3]; + double x[2],y[2],z[2]; + box.Get(x[0],y[0],z[0],x[1],y[1],z[1]); + for ( iAx = 0; iAx < nbAxes; ++iAx ) { + set< float > bndComps; + const gp_Dir& dir = gInfo->myAxis[ iAx ]; + for ( int iX = 0; iX < 2; ++iX ) { + for ( int iY = 0; iY < 2; ++iY ) { + for ( int iZ = 0; iZ < 2; ++iZ ) { + gp_Pnt p( x[ iX ], y[ iY ], z[ iZ ] ); + float dot = dir.XYZ() * p.XYZ(); + bndComps.insert( dot ); + } + } + } + firstValue[ iAx ] = *bndComps.begin(); + range[ iAx ] = *bndComps.rbegin() - *bndComps.begin(); + } + + // compute component values + for ( iAx = 0; iAx < nbAxes; ++iAx ) + { + list< float > values; + int nbVals = 0; + set< float >& comp = comps[ iAx ]; + set< float >::iterator val = comp.begin(); + float bnd = -1., rng = range[ iAx ], first = firstValue[ iAx ]; + float tol = 0.1 * sqrt( minSize[ iAx ]) / rng; + for ( ; val != comp.end(); ++val ) { + float value = ( *val - first ) / rng; + if ( value > bnd ) { + values.push_back( value ); + bnd = value + tol; + nbVals++; + } + } + // store values in gInfo + vector< float >& myComp = gInfo->myComponets[ iAx ]; + myComp.resize( nbVals ); + list< float >::iterator v = values.begin(); + for ( int i = 0; v != values.end(); ++v ) + myComp[ i++ ] = *v; + } + } + + // set return values + if ( gInfo ) + { + thePlaneNormal = gInfo->myAxis[ theAxis ]; + components = & gInfo->myComponets[ theAxis ]; + } + + return components; +} diff --git a/src/VISU_I/VISU_Result_i.hh b/src/VISU_I/VISU_Result_i.hh new file mode 100644 index 00000000..beb1e558 --- /dev/null +++ b/src/VISU_I/VISU_Result_i.hh @@ -0,0 +1,132 @@ +// VISU OBJECT : interactive object for VISU entities implementation +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// File : VISU_Result_i.hh +// Author : Alexey PETROV +// Module : VISU + +#ifndef __VISU_RESULT_I_H__ +#define __VISU_RESULT_I_H__ + +#include "VISUConfig.hh" +#include "SALOME_GenericObj_i.hh" + +#include + +#include + +class VISU_Convertor; + +namespace VISU{ + class Result_i : public virtual POA_VISU::Result, + public virtual RemovableObject_i, + public virtual SALOME::GenericObj_i + { + Result_i(); + Result_i(const Result_i &); + + public: + enum ESourceId {eRestoredComponent = -2, eRestoredFile = -1, eFile = 1, eComponent = 2}; + enum ECreationId {eImportFile, eCopyAndImportFile, eImportMed, eImportMedField}; + + Result_i(SALOMEDS::Study_ptr theStudy, + const ESourceId& theSourceId, + const ECreationId& theCreationId); + + virtual ~Result_i(); + virtual void RemoveFromStudy(); + + virtual VISU::VISUType GetType() { return VISU::TRESULT;} + virtual CORBA::Boolean BuildAll(); + + typedef VISU_Convertor TInput; + + private: + ESourceId mySourceId; + ECreationId myCreationId; + + TInput *myInput; + CORBA::Boolean myIsDone; + std::string myName, myInitFileName; + QFileInfo myFileInfo; + + protected: + virtual Storable* Build(SALOMEDS::SObject_ptr theSObject = SALOMEDS::SObject::_nil()) ; + + public: + virtual int IsPossible(); + + virtual Storable* Create(const char* theFileName); + virtual Storable* Create(SALOMEDS::SObject_ptr theMedSObject); + virtual Storable* Create(SALOME_MED::FIELD_ptr theField); + + virtual Storable* Restore(SALOMEDS::SObject_ptr theSObject, + const Storable::TRestoringMap& theMap, + const std::string& thePrefix); + + static Storable* Restore(SALOMEDS::SObject_ptr theSObject, + const std::string& thePrefix, + const Storable::TRestoringMap& theMap); + + virtual void ToStream(std::ostringstream& theStr); + virtual const char* GetComment() const; + static const std::string myComment; + TInput* GetInput(); + + const std::string& GetName() const { return myName;} + const QFileInfo& GetFileInfo() const { return myFileInfo;} + const std::string& GetFileName() const { return myInitFileName;} + const ECreationId& GetCreationId() const { return myCreationId;} + + private: + SALOMEDS::SObject_var mySObject; + SALOMEDS::Study_var myStudyDocument; + SALOMEDS::SComponent_var mySComponent; + + public: + std::string GetRefFatherEntry(); + std::string GetEntry(); + const SALOMEDS::SObject_var& GetSObject() const; + const SALOMEDS::Study_var& GetStudyDocument() const; + const SALOMEDS::SComponent_var& GetSComponent() const; + std::string GetEntry(const std::string& theComment); + + // Info on structured mesh contained in TInput + public: + typedef enum { AXIS_X = 0, AXIS_Y, AXIS_Z } TAxis; + const std::vector< float >* GetAxisInfo(const std::string& theMeshName, + TAxis theAxis, + gp_Dir& thePlaneNormal); + // Return i,j or k values and cutting plane normal for theAxis. + // In the case of any problems, return NULL pointer + private: + struct TGridInfo { + std::vector< float > myComponets[ 3 ]; + gp_Dir myAxis [ 3 ]; + }; + map< string, TGridInfo > myMeshName2GridInfoMap; + }; + + Result_var FindResult(SALOMEDS::SObject_ptr theSObject); +} + +#endif diff --git a/src/VISU_I/VISU_View_i.cc b/src/VISU_I/VISU_View_i.cc new file mode 100644 index 00000000..a83055ce --- /dev/null +++ b/src/VISU_I/VISU_View_i.cc @@ -0,0 +1,1963 @@ +// VISU OBJECT : interactive object for VISU entities implementation +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// File : VISU_View_i.cc +// Author : Alexey PETROV +// Module : VISU + +#include "VISU_View_i.hh" + +#include "VISU_Gen_i.hh" +#include "VISU_Prs3d_i.hh" +#include "VISU_Table_i.hh" +#include "VISU_ViewManager_i.hh" + +#include "VisuGUI_TableDlg.h" + +#include "VISU_Actor.h" + +#include "SALOME_Event.hxx" + +#include "SUIT_ViewWindow.h" +#include "SUIT_ViewManager.h" +#include "SUIT_Tools.h" + +#include "STD_MDIDesktop.h" +#include "STD_TabDesktop.h" + +#include "SVTK_ViewWindow.h" +#include "SVTK_ViewModel.h" +#include "SVTK_RenderWindow.h" + +#include "SPlot2d_ViewModel.h" +#include "Plot2d_ViewFrame.h" +#include "Plot2d_ViewModel.h" + +#include "SalomeApp_Application.h" +#include "SalomeApp_Study.h" + +#include + +#include + +#include +#include + +using namespace std; + +#ifdef _DEBUG_ +static int MYDEBUG = 0; +#else +static int MYDEBUG = 0; +#endif + +namespace VISU { + + typedef TVoidMemFunEvent TFrameActionEvent; + + struct TNewViewEvent: public SALOME_Event + { + SalomeApp_Application* myApplication; + typedef QWidget* TResult; + TResult myResult; + + TNewViewEvent (SalomeApp_Application* theApplication): + myApplication(theApplication), + myResult(NULL) + {} + + virtual + void + Execute() + { + if (STD_MDIDesktop* aDesktop = dynamic_cast(myApplication->desktop())) { + myResult = aDesktop->workspace(); + } + } + }; + + View_i:: + View_i (SalomeApp_Application *theApplication, + SUIT_ViewManager* theViewManager): + myApplication(theApplication), + myWorkspace(NULL), + myViewManager(theViewManager) + { + if(MYDEBUG) MESSAGE("View_i::View_i - "<setWindowShown(SalomeApp_Application::WT_ObjectBrowser,myState); + break; + case VISU::View::PYTHON: + myApplication->setWindowShown(SalomeApp_Application::WT_PyConsole,myState); + break; + case VISU::View::MESSAGES: + myApplication->setWindowShown(SalomeApp_Application::WT_LogWindow,myState); + break; + case VISU::View::VIEWER:{ + ViewManagerList aViewManagerList = myApplication->viewManagers(); + // to do something + // ... + break; + }} + } + }; + + ProcessVoidEvent(new TEvent(myApplication,theViewRepresentation,theState)); + } + + struct TPartShownEvent: public TApplicationEvent + { + VISU::View::ViewRepresentation myViewRepresentation; + typedef bool TResult; + TResult myResult; + + TPartShownEvent(SalomeApp_Application* theApplication, + VISU::View::ViewRepresentation theViewRepresentation): + TApplicationEvent(theApplication), + myViewRepresentation(theViewRepresentation), + myResult(false) + {} + + virtual + void + Execute() + { + switch(myViewRepresentation){ + case VISU::View::OBJECTBROWSER: + myResult = myApplication->isWindowVisible(SalomeApp_Application::WT_ObjectBrowser); + break; + case VISU::View::PYTHON: + myResult = myApplication->isWindowVisible(SalomeApp_Application::WT_PyConsole); + break; + case VISU::View::MESSAGES: + myResult = myApplication->isWindowVisible(SalomeApp_Application::WT_LogWindow); + break; + case VISU::View::VIEWER:{ + ViewManagerList aViewManagerList = myApplication->viewManagers(); + // to do something + // ... + break; + }} + } + }; + + CORBA::Boolean + View_i:: + IsPartShown (VISU::View::ViewRepresentation theViewRepresentation) + { + return ProcessEvent(new TPartShownEvent(myApplication,theViewRepresentation)); + } + + // Begin: New methods for view parameters management + struct TSplitEvent: public SALOME_Event + { + SalomeApp_Application * myApplication; + SUIT_ViewWindow * myViewWindow; + Qt::Orientation myOrientation; + QtxWorkstack::SplitType mySplitType; + + public: + TSplitEvent (SalomeApp_Application * theApplication, + SUIT_ViewWindow * theViewWindow, + Qt::Orientation theOrientation, + QtxWorkstack::SplitType theSplitType): + myApplication(theApplication), + myViewWindow(theViewWindow), + myOrientation(theOrientation), + mySplitType(theSplitType) + {} + + virtual void Execute() + { + SUIT_Desktop* desk = myApplication->desktop(); + STD_TabDesktop* tabDesk = dynamic_cast(desk); + if (tabDesk) { + QtxWorkstack* workstack = tabDesk->workstack(); + if (workstack) { + workstack->Split(myViewWindow, myOrientation, mySplitType); + } + } + } + }; + + void + View_i:: + SplitRight() + { + ProcessVoidEvent(new TSplitEvent(myApplication,myViewWindow, + Qt::Horizontal,QtxWorkstack::SPLIT_MOVE)); + } + + void + View_i:: + SplitLeft() + { + ProcessVoidEvent(new TSplitEvent(myApplication,myViewWindow, + Qt::Horizontal,QtxWorkstack::SPLIT_STAY)); + } + + void + View_i:: + SplitBottom() + { + ProcessVoidEvent(new TSplitEvent(myApplication,myViewWindow, + Qt::Vertical,QtxWorkstack::SPLIT_MOVE)); + } + + void + View_i:: + SplitTop() + { + ProcessVoidEvent(new TSplitEvent(myApplication,myViewWindow, + Qt::Vertical,QtxWorkstack::SPLIT_STAY)); + } + + void + View_i:: + OnTop() + { + struct TOnTopEvent: public SALOME_Event + { + SUIT_ViewWindow * myViewWindow; + + public: + TOnTopEvent (SUIT_ViewWindow * theViewWindow): + myViewWindow(theViewWindow) + {} + + virtual void Execute() + { + if (myViewWindow) { + myViewWindow->setFocus(); + } + } + }; + + ProcessVoidEvent(new TOnTopEvent(myViewWindow)); + } + + struct TAttractEvent: public SALOME_Event + { + SalomeApp_Application * myApplication; + SUIT_ViewWindow * myViewWindow1; + SUIT_ViewWindow * myViewWindow2; + bool myAttractAll; + + public: + TAttractEvent (SalomeApp_Application * theApplication, + SUIT_ViewWindow * theViewWindow1, + SUIT_ViewWindow * theViewWindow2, + bool theAttractAll): + myApplication(theApplication), + myViewWindow1(theViewWindow1), + myViewWindow2(theViewWindow2), + myAttractAll(theAttractAll) + {} + + virtual void Execute() + { + SUIT_Desktop* desk = myApplication->desktop(); + STD_TabDesktop* tabDesk = dynamic_cast(desk); + if (tabDesk) { + QtxWorkstack* workstack = tabDesk->workstack(); + if (workstack) { + workstack->Attract(myViewWindow1, myViewWindow2, myAttractAll); + } + } + } + }; + + void + View_i:: + Attract (VISU::View_ptr theView) + { + if (!CORBA::is_nil(theView)) { + if (VISU::View_i* pView = dynamic_cast(VISU::GetServant(theView).in())) { + ProcessVoidEvent(new TAttractEvent(myApplication,myViewWindow,pView->myViewWindow,false)); + } + } + } + + void + View_i:: + AttractAll (VISU::View_ptr theView) + { + if (!CORBA::is_nil(theView)) { + if (VISU::View_i* pView = dynamic_cast(VISU::GetServant(theView).in())) { + ProcessVoidEvent(new TAttractEvent(myApplication,myViewWindow,pView->myViewWindow,true)); + } + } + } + + struct TSizePositionEvent: public SALOME_Event + { + SalomeApp_Application * myApplication; + SUIT_ViewWindow * myViewWindow; + double myValue; + bool myIsSize; + + public: + TSizePositionEvent (SalomeApp_Application * theApplication, + SUIT_ViewWindow * theViewWindow, + double theValue, + bool theIsSize): + myApplication(theApplication), + myViewWindow(theViewWindow), + myValue(theValue), + myIsSize(theIsSize) + {} + + virtual void Execute() + { + MESSAGE("TSizePositionEvent::Execute()"); + SUIT_Desktop* desk = myApplication->desktop(); + STD_TabDesktop* tabDesk = dynamic_cast(desk); + if (tabDesk) { + QtxWorkstack* workstack = tabDesk->workstack(); + if (workstack) { + if (myIsSize) { + //jfa to do:workstack->SetRelativeSizeInSplitter(myViewWindow, myValue); + } else { + workstack->SetRelativePositionInSplitter(myViewWindow, myValue); + } + } + } + } + }; + + void + View_i:: + SetRelativePositionInSplitter (CORBA::Double thePosition) + { + if (thePosition < 0.0 || 1.0 < thePosition) { + return; + } + ProcessVoidEvent(new TSizePositionEvent(myApplication,myViewWindow,thePosition,false)); + } + + void + View_i:: + SetRelativeSizeInSplitter (CORBA::Double theSize) + { + if (theSize < 0.0 || 1.0 < theSize) { + return; + } + ProcessVoidEvent(new TSizePositionEvent(myApplication,myViewWindow,theSize,true)); + } + + struct TWSSizePositionEvent: public SALOME_Event + { + SalomeApp_Application * myApplication; + SUIT_ViewWindow * myViewWindow; + Qt::Orientation myOrientation; + double myValue; + bool myIsSize; + + public: + TWSSizePositionEvent (SalomeApp_Application * theApplication, + SUIT_ViewWindow * theViewWindow, + Qt::Orientation theOrientation, + double theValue, + bool theIsSize): + myApplication(theApplication), + myViewWindow(theViewWindow), + myOrientation(theOrientation), + myValue(theValue), + myIsSize(theIsSize) + {} + + virtual void Execute() + { + MESSAGE("TWSSizePositionEvent::Execute()"); + SUIT_Desktop* desk = myApplication->desktop(); + STD_TabDesktop* tabDesk = dynamic_cast(desk); + if (tabDesk) { + QtxWorkstack* workstack = tabDesk->workstack(); + if (workstack) { + if (myIsSize) { + //jfa to do:workstack->SetRelativeSize(myViewWindow, myOrientation, myValue); + } else { + workstack->SetRelativePosition(myViewWindow, myOrientation, myValue); + } + } + } + } + }; + + void + View_i:: + SetRelativePositionX (CORBA::Double thePosition) + { + if (thePosition < 0.0 || 1.0 < thePosition) { + return; + } + ProcessVoidEvent(new TWSSizePositionEvent(myApplication,myViewWindow, + Qt::Horizontal,thePosition,false)); + } + + void + View_i:: + SetRelativePositionY (CORBA::Double thePosition) + { + if (thePosition < 0.0 || 1.0 < thePosition) { + return; + } + ProcessVoidEvent(new TWSSizePositionEvent(myApplication,myViewWindow, + Qt::Vertical,thePosition,false)); + } + + void + View_i:: + SetRelativeSizeX (CORBA::Double theSize) + { + if (theSize < 0.0 || 1.0 < theSize) { + return; + } + ProcessVoidEvent(new TWSSizePositionEvent(myApplication,myViewWindow, + Qt::Horizontal,theSize,true)); + } + + void + View_i:: + SetRelativeSizeY (CORBA::Double theSize) + { + if (theSize < 0.0 || 1.0 < theSize) { + return; + } + ProcessVoidEvent(new TWSSizePositionEvent(myApplication,myViewWindow, + Qt::Vertical,theSize,true)); + } + // End: New methods for view parameters management + + // Begin: Old methods for view parameters management, they don't work now + struct TSetViewSize: public SALOME_Event + { + SUIT_ViewWindow* myViewWindow; + typedef void (QRect::* TAction)(int); + TAction myAction; + CORBA::Long mySize; + + public: + TSetViewSize(SUIT_ViewWindow* theViewWindow, + TAction theAction, + CORBA::Long theSize): + myViewWindow(theViewWindow), + myAction(theAction), + mySize(theSize) + {} + + virtual + void + Execute() + { + if (QWidget* aParent = myViewWindow->parentWidget(true)) { + QRect aQRect = aParent->frameGeometry(); + (aQRect.*myAction)(mySize); + aParent->setGeometry(aQRect); + } + } + }; + + void + View_i:: + SetViewWidth(CORBA::Long theWidth) + { + ProcessVoidEvent(new TSetViewSize(myViewWindow,&QRect::setWidth,theWidth)); + } + + void + View_i:: + SetViewHeight(CORBA::Long theHeight) + { + ProcessVoidEvent(new TSetViewSize(myViewWindow,&QRect::setHeight,theHeight)); + } + + + struct TGetViewSize: public SALOME_Event + { + SUIT_ViewWindow* myViewWindow; + + typedef int (QRect::* TAction)() const; + TAction myAction; + + typedef CORBA::Long TResult; + TResult myResult; + + public: + TGetViewSize(SUIT_ViewWindow* theViewWindow, + TAction theAction): + myViewWindow(theViewWindow), + myAction(theAction) + {} + + virtual + void + Execute() + { + if(QWidget* aParent = myViewWindow->parentWidget(true)){ + QRect aQRect = aParent->frameGeometry(); + myResult = (aQRect.*myAction)(); + } + } + }; + + + CORBA::Long + View_i:: + GetViewWidth() + { + return ProcessEvent(new TGetViewSize(myViewWindow,&QRect::width)); + } + + CORBA::Long + View_i:: + GetViewHeight() + { + return ProcessEvent(new TGetViewSize(myViewWindow,&QRect::height)); + } + + + class TWorkspaceEvent: public SALOME_Event + { + protected: + QWidget* myViewWindow; + QWidget* myWorkspace; + + public: + TWorkspaceEvent(QWidget* theViewWindow, + QWidget* theWorkspace): + myViewWindow(theViewWindow), + myWorkspace(theWorkspace) + {} + }; + + + class TAlignEvent: public TWorkspaceEvent + { + protected: + Qt::AlignmentFlags myAligment; + + public: + TAlignEvent(QWidget* theViewWindow, + QWidget* theWorkspace, + Qt::AlignmentFlags theAligment): + TWorkspaceEvent(theViewWindow,theWorkspace), + myAligment(theAligment) + {} + + virtual + void + Execute() + { + if(QWidget* aParent = myViewWindow->parentWidget(true)) + SUIT_Tools::alignWidget(aParent,myWorkspace,myAligment); + } + }; + + + void + View_i:: + SetViewPositionHorizontal (VISU::View::ViewPosition theViewPosition) + { + if (myWorkspace) { + switch (theViewPosition) { + case VISU::View::LEFT: + ProcessVoidEvent(new TAlignEvent(myViewWindow,myWorkspace,Qt::AlignLeft)); + break; + case VISU::View::CENTER: + ProcessVoidEvent(new TAlignEvent(myViewWindow,myWorkspace,Qt::AlignHCenter)); + break; + case VISU::View::RIGHT: + ProcessVoidEvent(new TAlignEvent(myViewWindow,myWorkspace,Qt::AlignRight)); + break; + } + } + } + + + void + View_i:: + SetViewPositionVertical (VISU::View::ViewPosition theViewPosition) + { + if (myWorkspace) { + switch (theViewPosition) { + case VISU::View::TOP: + ProcessVoidEvent(new TAlignEvent(myViewWindow,myWorkspace,Qt::AlignTop)); + break; + case VISU::View::CENTER: + ProcessVoidEvent(new TAlignEvent(myViewWindow,myWorkspace,Qt::AlignVCenter)); + break; + case VISU::View::BOTTOM: + ProcessVoidEvent(new TAlignEvent(myViewWindow,myWorkspace,Qt::AlignBottom)); + break; + } + } + } + + + class TXYEvent: public TWorkspaceEvent + { + protected: + CORBA::Double myX, myY; + + public: + TXYEvent(QWidget* theViewWindow, + QWidget* theWorkspace, + CORBA::Double theX, + CORBA::Double theY): + TWorkspaceEvent(theViewWindow,theWorkspace), + myX(theX), + myY(theY) + {} + }; + + + void + View_i:: + SetRelativePosition (CORBA::Double theX, CORBA::Double theY) + { + struct TEvent: public TXYEvent + { + public: + TEvent(QWidget* theViewWindow, + QWidget* theWorkspace, + CORBA::Double theX, + CORBA::Double theY): + TXYEvent(theViewWindow,theWorkspace,theX,theY) + {} + + virtual + void + Execute() + { + if(QWidget* aParent = myViewWindow->parentWidget(true)) + aParent->move(int(myX*myWorkspace->width()),int(myY*myWorkspace->height())); + } + }; + + if (myWorkspace) + ProcessVoidEvent(new TEvent(myViewWindow,myWorkspace,theX,theY)); + } + + void + View_i:: + SetRelativeSize (CORBA::Double theX, CORBA::Double theY) + { + struct TEvent: public TXYEvent + { + public: + TEvent(QWidget* theViewWindow, + QWidget* theWorkspace, + CORBA::Double theX, + CORBA::Double theY): + TXYEvent(theViewWindow,theWorkspace,theX,theY) + {} + + virtual + void + Execute() + { + if(QWidget* aParent = myViewWindow->parentWidget(true)) + aParent->setGeometry(aParent->x(), + aParent->y(), + int(myX*myWorkspace->width()), + int(myY*myWorkspace->height())); + } + }; + + if (myWorkspace) + ProcessVoidEvent(new TEvent(myViewWindow,myWorkspace,theX,theY)); + } + // End: Old methods for view parameters management, they don't work now + + void + View_i:: + SetBackground (const SALOMEDS::Color& theColor) + { + struct TEvent: public SALOME_Event + { + QWidget* myWidget; + SALOMEDS::Color myColor; + public: + TEvent(QWidget* theWidget, + const SALOMEDS::Color& theColor): + myWidget(theWidget), + myColor(theColor) + {} + virtual void Execute(){ + int aColor[3]; + aColor[0] = int(255.0*myColor.R); + aColor[1] = int(255.0*myColor.G); + aColor[2] = int(255.0*myColor.B); + myWidget->setBackgroundColor(QColor(aColor[0],aColor[1],aColor[2])); + } + }; + + ProcessVoidEvent(new TEvent(myViewWindow,theColor)); + } + + + struct TBackgroundEvent: public SALOME_Event + { + QWidget* myWidget; + typedef SALOMEDS::Color TResult; + TResult myResult; + + TBackgroundEvent(QWidget* theWidget): + myWidget(theWidget) + {} + + virtual + void + Execute() + { + const QColor& aColor = myWidget->backgroundColor(); + myResult.R = aColor.red()/255.0; + myResult.G = aColor.green()/255.0; + myResult.B = aColor.blue()/255.0; + } + }; + + SALOMEDS::Color + View_i:: + GetBackground() + { + return ProcessEvent(new TBackgroundEvent(myViewWindow)); + } + + void + View_i:: + Minimize() + { + ProcessVoidEvent(new TFrameActionEvent(myViewWindow,&SUIT_ViewWindow::showMinimized)); + } + + void + View_i:: + Restore() + { + ProcessVoidEvent(new TFrameActionEvent(myViewWindow,&SUIT_ViewWindow::showNormal)); + } + + void + View_i:: + Maximize() + { + ProcessVoidEvent(new TFrameActionEvent(myViewWindow,&SUIT_ViewWindow::showMaximized)); + } + + void + View_i:: + EraseAll() + {} + + void + View_i:: + DisplayAll() + {} + + void + View_i:: + Erase (PrsObject_ptr thePrsObj) + {} + + void + View_i:: + Display (PrsObject_ptr thePrsObj) + {} + + void + View_i:: + DisplayOnly (PrsObject_ptr thePrsObj) + {} + + void + View_i:: + Update() + {} + + class TSavePictureEvent: public SALOME_Event + { + SUIT_ViewWindow * myViewWindow; + const char * myFileName; + public: + typedef CORBA::Boolean TResult; + TResult myResult; + TSavePictureEvent (SUIT_ViewWindow * theViewWindow, const char * theFileName) + : myViewWindow(theViewWindow), + myFileName(theFileName), + myResult(false) + { + } + + virtual void Execute() + { + if (myViewWindow) { + QImage img = myViewWindow->dumpView(); + if (!img.isNull()) { + QString fileName (myFileName); + if (!fileName.isEmpty()) { + QString fmt = SUIT_Tools::extension(fileName).upper(); + if (fmt.isEmpty()) fmt = QString("BMP"); // default format + if (fmt == "JPG" ) fmt = "JPEG"; + //QApplication::setOverrideCursor(Qt::waitCursor); + img.save(fileName, fmt.latin1()); + //QApplication::restoreOverrideCursor(); + } + } + } + } + }; + + CORBA::Boolean + View_i::SavePicture(const char* theFileName) + { + return ProcessEvent(new TSavePictureEvent (myViewWindow,theFileName)); + } + + const char* + View_i:: + GetComment() const + { + return ""; + } + + void + View_i:: + ToStream (std::ostringstream& theStr) + { + } + + + //================= OLD CODE =================== + + //QAD_Study* CheckStudy (SALOMEDS::Study_ptr theStudy) + //{ + // //QAD_Desktop* aDesktop = QAD_Application::getDesktop(); + // //QAD_Study* aStudy = aDesktop->findStudy(theStudy); + // if (!aStudy) { + // CORBA::String_var aName = theStudy->Name(); + // aFileInfo.setFile(aName.in()); + // if (aFileInfo.exists()) + // aStudy = aDesktop->loadStudy(aFileInfo.baseName()); + // else + // aStudy = aDesktop->loadStudy(aName.in()); + // if (!aStudy) { + // MESSAGE("CheckStudy()::ERROR: Can't load study"); + // } + // } + // return aStudy; + //} + + template + struct TNewSpecViewEvent: public SALOME_Event + { + SalomeApp_Application* myApplication; + + typedef SUIT_ViewManager* TResult; + TResult myResult; + + TNewSpecViewEvent (SalomeApp_Application* theApplication): + myApplication(theApplication), + myResult(NULL) + {} + + virtual + void + Execute() + { + myResult = myApplication->getViewManager(TViewer::Type(), true); + } + }; + + //=========================================================================== + XYPlot_i::XYPlot_i (SalomeApp_Application* theApplication) + : View_i(theApplication, NULL) + { + if (MYDEBUG) MESSAGE("XYPlot_i::XYPlot_i"); + if (theApplication) { + myViewManager = ProcessEvent(new TNewSpecViewEvent(theApplication)); + } + } + + + struct TCreatePlot2dViewEvent: public SALOME_Event + { + SUIT_ViewManager* myViewManager; + XYPlot_i * myPlot2dView; + int myNew; + + typedef Plot2d_ViewFrame* TResult; + TResult myResult; + + TCreatePlot2dViewEvent (SUIT_ViewManager* theViewManager, + XYPlot_i * thePlot2dView, + const int theNew): + myViewManager(theViewManager), + myPlot2dView(thePlot2dView), + myNew(theNew), + myResult(NULL) + {} + + virtual + void + Execute() + { + if (myNew) { + myPlot2dView->myViewWindow = myViewManager->createViewWindow(); + } else { + myPlot2dView->myViewWindow = myViewManager->getActiveView(); + } + if (myPlot2dView->myViewWindow) { + Plot2d_ViewWindow* aPlot2dVW = dynamic_cast(myPlot2dView->myViewWindow); + if (aPlot2dVW) { + myResult = aPlot2dVW->getViewFrame(); + if (myResult) { + myResult->Repaint(); + } + } + } + } + }; + + Storable* XYPlot_i::Create (int theNew) + { + myView = ProcessEvent(new TCreatePlot2dViewEvent(myViewManager, this, theNew)); + return this; + } + + void XYPlot_i::Update() + { + ProcessVoidEvent(new TVoidMemFunEvent(myView,&Plot2d_ViewFrame::Repaint)); + } + + void XYPlot_i::Close() + { + //jfa: may be need to be enclosed in SALOME_Event? + myViewWindow->close(); + } + + XYPlot_i::~XYPlot_i() { + if(MYDEBUG) MESSAGE("XYPlot_i::~XYPlot_i"); + } + + void XYPlot_i::SetTitle (const char* theTitle) + { + ProcessVoidEvent(new TVoidMemFun1ArgEvent + (myViewWindow, &SUIT_ViewWindow::setCaption, QString(theTitle))); + } + char* XYPlot_i::GetTitle() + { + //jfa: may be need to be enclosed in SALOME_Event? + return CORBA::string_dup(myViewWindow->caption().latin1()); + } + + void XYPlot_i::SetSubTitle (const char* theTitle) + { + ProcessVoidEvent(new TVoidMemFun1ArgEvent + (myView, &Plot2d_ViewFrame::setTitle, QString(theTitle))); + } + + char* XYPlot_i::GetSubTitle() + { + //jfa: may be need to be enclosed in SALOME_Event? + return CORBA::string_dup(myView->getTitle()); + } + + void XYPlot_i::SetCurveType (VISU::XYPlot::CurveType theType) + { + ProcessVoidEvent(new TVoidMemFun2ArgEvent + (myView,&Plot2d_ViewFrame::setCurveType,theType,true)); + } + + VISU::XYPlot::CurveType XYPlot_i::GetCurveType() + { + //jfa: may be need to be enclosed in SALOME_Event? + return (VISU::XYPlot::CurveType)myView->getCurveType(); + } + + void XYPlot_i::SetMarkerSize (CORBA::Long theSize) + { + ProcessVoidEvent(new TVoidMemFun2ArgEvent + (myView,&Plot2d_ViewFrame::setMarkerSize,theSize,true)); + } + + CORBA::Long XYPlot_i::GetMarkerSize() + { + //jfa: may be need to be enclosed in SALOME_Event? + return myView->getMarkerSize(); + } + + class TEnableGridEvent: public SALOME_Event + { + public: + typedef void (Plot2d_ViewFrame::* TFun)(bool, const int, bool, const int, bool); + TEnableGridEvent (Plot2d_ViewFrame* theView, TFun theFun, + CORBA::Boolean theMajor, CORBA::Long theNumMajor, + CORBA::Boolean theMinor, CORBA::Long theNumMinor): + myView(theView), myFun(theFun), + myMajor(theMajor), myNumMajor(theNumMajor), + myMinor(theMinor), myNumMinor(theNumMinor) + {} + + virtual void Execute() + { + (myView->*myFun)(myMajor,myNumMajor,myMinor,myNumMinor,true); + } + protected: + Plot2d_ViewFrame* myView; + TFun myFun; + CORBA::Boolean myMajor, myNumMajor; + CORBA::Boolean myMinor, myNumMinor; + }; + + void XYPlot_i::EnableXGrid (CORBA::Boolean theMajor, CORBA::Long theNumMajor, + CORBA::Boolean theMinor, CORBA::Long theNumMinor) + { + ProcessVoidEvent(new TEnableGridEvent(myView,&Plot2d_ViewFrame::setXGrid, + theMajor,theNumMajor,theMinor,theNumMinor)); + } + void XYPlot_i::EnableYGrid(CORBA::Boolean theMajor, CORBA::Long theNumMajor, + CORBA::Boolean theMinor, CORBA::Long theNumMinor) + { + //jfa tmp:ProcessVoidEvent(new TEnableGridEvent(myView,&Plot2d_ViewFrame::setYGrid, + //jfa tmp: theMajor,theNumMajor,theMinor,theNumMinor)); + } + + class TSetScaleModeEvent: public SALOME_Event + { + public: + typedef void (Plot2d_ViewFrame::* TFun)(const int, bool); + TSetScaleModeEvent (Plot2d_ViewFrame* theView, TFun theFun, int theScaling): + myView(theView), myFun(theFun), myScaling(theScaling) + {} + + virtual void Execute() + { + (myView->*myFun)(myScaling,true); + } + protected: + Plot2d_ViewFrame* myView; + TFun myFun; + int myScaling; + }; + + void XYPlot_i::SetHorScaling (VISU::Scaling theScaling) + { + ProcessVoidEvent(new TSetScaleModeEvent(myView,&Plot2d_ViewFrame::setHorScaleMode, + theScaling == VISU::LOGARITHMIC)); + } + + VISU::Scaling XYPlot_i::GetHorScaling() + { + //jfa: may be need to be enclosed in SALOME_Event? + return (VISU::Scaling)myView->getHorScaleMode(); + } + + void XYPlot_i::SetVerScaling(VISU::Scaling theScaling) + { + ProcessVoidEvent(new TSetScaleModeEvent(myView,&Plot2d_ViewFrame::setVerScaleMode, + theScaling == VISU::LOGARITHMIC)); + } + + VISU::Scaling XYPlot_i::GetVerScaling() + { + //jfa: may be need to be enclosed in SALOME_Event? + return (VISU::Scaling)myView->getVerScaleMode(); + } + + class TSetTitleEvent: public SALOME_Event + { + public: + TSetTitleEvent (Plot2d_ViewFrame* theView, Plot2d_ViewFrame::ObjectType theType, const char* theTitle): + myView(theView), myType(theType), myTitle(theTitle) + {} + virtual void Execute() + { + myView->setTitle(true,myTitle,myType); + } + protected: + Plot2d_ViewFrame* myView; + Plot2d_ViewFrame::ObjectType myType; + const char* myTitle; + }; + + void XYPlot_i::SetXTitle (const char* theTitle) + { + ProcessVoidEvent(new TSetTitleEvent(myView, Plot2d_ViewFrame::XTitle, theTitle)); + } + char* XYPlot_i::GetXTitle() + { + //jfa: may be need to be enclosed in SALOME_Event? + return CORBA::string_dup(myView->getTitle(Plot2d_ViewFrame::XTitle)); + } + + void XYPlot_i::SetYTitle (const char* theTitle) + { + ProcessVoidEvent(new TSetTitleEvent(myView, Plot2d_ViewFrame::YTitle, theTitle)); + } + char* XYPlot_i::GetYTitle() + { + //jfa: may be need to be enclosed in SALOME_Event? + return CORBA::string_dup(myView->getTitle(Plot2d_ViewFrame::YTitle)); + } + + void XYPlot_i::ShowLegend (CORBA::Boolean theShowing) + { + ProcessVoidEvent(new TVoidMemFun2ArgEvent + (myView,&Plot2d_ViewFrame::showLegend,theShowing,true)); + } + + class TXYPlotViewEvent: public SALOME_Event + { + SalomeApp_Application* myApplication; + Plot2d_ViewFrame* myView; + PrsObject_ptr myPrsObj; + int myDisplaing; + + public: + TXYPlotViewEvent(SalomeApp_Application* theApplication, + Plot2d_ViewFrame* theView, + PrsObject_ptr thePrsObj, + int theDisplaing) + : myApplication(theApplication), + myView(theView), + myPrsObj(thePrsObj), + myDisplaing(theDisplaing) + { + } + + virtual void Execute() + { + // is it Curve ? + if (Curve_i* aCurve = dynamic_cast(VISU::GetServant(myPrsObj).in())) { + UpdatePlot2d(myView,myDisplaing,aCurve); + } + // is it Container ? + if (Container_i* aContainer = dynamic_cast(VISU::GetServant(myPrsObj).in())) { + int nbCurves = aContainer->GetNbCurves(); + for ( int i = 1; i <= nbCurves; i++ ) { + VISU::Curve_i* aCurve = aContainer->GetCurve( i ); + if ( aCurve && aCurve->IsValid() ) { + UpdatePlot2d(myView,myDisplaing,aCurve); + } + } + myView->Repaint(); + } + // is it Table ? + if (Table_i* aTable = dynamic_cast(VISU::GetServant(myPrsObj).in())) { + _PTR(Study) aCStudy; + if (SUIT_Study* aSStudy = myApplication->activeStudy()) { + if (SalomeApp_Study* aStudy = dynamic_cast(aSStudy)) { + aCStudy = aStudy->studyDS(); + } + } + if (!aCStudy) return; + _PTR(SObject) TableSO = aCStudy->FindObjectID(aTable->GetEntry().latin1()); + if (TableSO) { + _PTR(ChildIterator) Iter = aCStudy->NewChildIterator(TableSO); + for (; Iter->More(); Iter->Next()) { + CORBA::Object_var childObject = VISU::ClientSObjectToObject(Iter->Value()); + if (!CORBA::is_nil(childObject)) { + CORBA::Object_ptr aCurve = VISU::Curve::_narrow(childObject); + if (!CORBA::is_nil(aCurve)) + UpdatePlot2d(myView, myDisplaing, + dynamic_cast(VISU::GetServant(aCurve).in())); + } + } + myView->Repaint(); + } + } + } + }; + + void XYPlot_i::Display (PrsObject_ptr thePrsObj) + { + ProcessVoidEvent(new TXYPlotViewEvent (myApplication,myView,thePrsObj,eDisplay)); + } + + void XYPlot_i::Erase (PrsObject_ptr thePrsObj) + { + ProcessVoidEvent(new TXYPlotViewEvent (myApplication,myView,thePrsObj,eErase)); + } + + void XYPlot_i::DisplayOnly (PrsObject_ptr thePrsObj) + { + ProcessVoidEvent(new TXYPlotViewEvent (myApplication,myView,thePrsObj,eDisplayOnly)); + } + + void XYPlot_i::EraseAll() + { + ProcessVoidEvent(new TVoidMemFunEvent (myView,&Plot2d_ViewFrame::EraseAll)); + } + + void XYPlot_i::FitAll() + { + ProcessVoidEvent(new TVoidMemFunEvent (myView,&Plot2d_ViewFrame::fitAll)); + } + + + //=========================================================================== + TableView_i::TableView_i (SalomeApp_Application* theApplication) + : View_i(theApplication, NULL) + { + } + + struct TCreateTableViewEvent: public SALOME_Event + { + SalomeApp_Application* myApplication; + VISU::Table_i* myTable; + + typedef VisuGUI_TableDlg* TResult; + TResult myResult; + + TCreateTableViewEvent (SalomeApp_Application* theApplication, + VISU::Table_i* theTable): + myApplication(theApplication), + myTable(theTable), + myResult(NULL) + {} + + virtual + void + Execute() + { + if (myTable != NULL) { + if (SUIT_Study* aSStudy = myApplication->activeStudy()) { + if (SalomeApp_Study* aStudy = dynamic_cast(aSStudy)) { + if (_PTR(Study) aCStudy = aStudy->studyDS()) { + _PTR(SObject) aSObject = aCStudy->FindObjectID(myTable->GetObjectEntry()); + if (aSObject) { + myResult = new VisuGUI_TableDlg (myApplication->desktop(), + aSObject, + false, + VisuGUI_TableDlg::ttAuto, + Qt::Vertical); + myResult->show(); + } + } + } + } + } + } + }; + + Storable* TableView_i::Create (VISU::Table_ptr theTable) + { + if (MYDEBUG) MESSAGE("TableView_i::Create - " << (!theTable->_is_nil())); + if (!theTable->_is_nil()) { + VISU::Table_i* table = + dynamic_cast(VISU::GetServant(theTable).in()); + if (MYDEBUG) MESSAGE("TableView_i::Create - dynamic_cast = " << table); + + myView = ProcessEvent(new TCreateTableViewEvent(myApplication, table)); + if (myView) + return this; + } + return NULL; + } + + TableView_i::~TableView_i() + { + if(MYDEBUG) MESSAGE("TableView_i::~TableView_i"); + delete myView; + } + + void TableView_i::SetTitle (const char* theTitle) + { + ProcessVoidEvent(new TVoidMemFun1ArgEvent + (myView, &VisuGUI_TableDlg::setCaption, QString(theTitle))); + } + + char* TableView_i::GetTitle() + { + //jfa: may be need to be enclosed in SALOME_Event? + return CORBA::string_dup(myView->caption().latin1()); + } + + void TableView_i::Close() + { + //jfa: may be need to be enclosed in SALOME_Event? + myView->close(); + } + + + //=========================================================================== + int View3D_i::myNbViewParams = 0; + const string View3D_i::myComment = "VIEW3D"; + const char* View3D_i::GetComment() const { return myComment.c_str();} + + QString View3D_i::GenerateViewParamsName() + { + return VISU::GenerateName("ViewParams", ++myNbViewParams); + } + + View3D_i::View3D_i (SalomeApp_Application* theApplication) + : View_i(theApplication, NULL) + { + if (MYDEBUG) MESSAGE("View3D_i::View3D_i"); + if (theApplication) { + myViewManager = ProcessEvent(new TNewSpecViewEvent(theApplication)); + } + } + + struct TCreateView3dEvent: public SALOME_Event + { + SUIT_ViewManager* myViewManager; + int myNew; + + typedef SUIT_ViewWindow* TResult; + TResult myResult; + + TCreateView3dEvent (SUIT_ViewManager* theViewManager, + const int theNew): + myViewManager(theViewManager), + myNew(theNew), + myResult(NULL) + {} + + virtual + void + Execute() + { + if (myNew) { + myResult = myViewManager->createViewWindow(); + } else { + myResult = myViewManager->getActiveView(); + } + } + }; + + Storable* View3D_i::Create (int theNew) + { + if (MYDEBUG) MESSAGE("View3D_i::Create"); + myViewWindow = ProcessEvent(new TCreateView3dEvent(myViewManager, theNew)); + return this; + } + + void View3D_i::Update() + { + class TEvent: public SALOME_Event + { + SUIT_ViewWindow* myViewWindow; + public: + TEvent(SUIT_ViewWindow* theStudyFrame): + myViewWindow(theStudyFrame) + {} + virtual void Execute() + { + SVTK_ViewWindow* vf = GetViewWindow(myViewWindow); + vtkRenderer* Renderer = vf->getRenderer(); + vtkActorCollection* theActors = Renderer->GetActors(); + theActors->InitTraversal(); + while (vtkActor *anAct = theActors->GetNextActor()) { + if (VISU_Actor* anActor = dynamic_cast(anAct)) { + VISU::Prs3d_i* aPrs3d = anActor->GetPrs3d(); + if (anActor->GetVisibility() && aPrs3d) { + aPrs3d->Update(); + aPrs3d->UpdateActor(anActor); + } + } + } + RepaintView(myViewWindow); + } + }; + ProcessVoidEvent(new TEvent(myViewWindow)); + } + + bool View3D_i::SaveViewParams (SUIT_ViewManager* theViewManager, const char* theName) + { + MESSAGE("View3D_i::SaveViewParams()"); + _PTR(Study) aCStudy; + if (SUIT_Study* aSStudy = theViewManager->study()) { + if (SalomeApp_Study* aStudy = dynamic_cast(aSStudy)) { + aCStudy = aStudy->studyDS(); + } + } + if (!aCStudy) + return false; + + if (theName) { + std::vector<_PTR(SObject)> aList = aCStudy->FindObjectByName(theName, "VISU"); + _PTR(GenericAttribute) anAttr; + int iEnd = aList.size(); + for (int i = 0; i < iEnd; i++) { + _PTR(SObject) anObj = aList[i]; + string anEntry = anObj->GetID(); + if(MYDEBUG) MESSAGE("View3D_i::SaveViewParams - anEntry = " << anEntry); + if (anObj->FindAttribute(anAttr, "AttributeComment")) { + _PTR(AttributeComment) aCmnt (anAttr); + string aComm (aCmnt->Value()); + if (MYDEBUG) MESSAGE("View3D_i::SaveViewPoint - aComm = " << aComm); + if (aComm.compare(View3D_i::myComment) >= 0) { + aCmnt->SetValue(ToString(theViewManager->getActiveView()).c_str()); + return true; + } + } + } + } + _PTR(SComponent) aSComponent = ClientFindOrCreateVisuComponent(aCStudy); + string aSComponentEntry = aSComponent->GetID(); + string anEntry = CreateAttributes(aCStudy, aSComponentEntry.c_str(), "", "", theName, "", + ToString(theViewManager->getActiveView()).c_str()); + return true; + } + + class TSaveViewParamsEvent: public SALOME_Event + { + SUIT_ViewManager* myViewManager; + const char* myName; + public: + TSaveViewParamsEvent (SUIT_ViewManager* theViewManager, + const char* theName): + myViewManager(theViewManager), + myName(theName) + {} + + virtual void Execute() + { + myResult = View3D_i::SaveViewParams(myViewManager, myName); + } + typedef CORBA::Boolean TResult; + TResult myResult; + }; + + CORBA::Boolean View3D_i::SaveViewParams (const char* theName) + { + return ProcessEvent(new TSaveViewParamsEvent (myViewManager, theName)); + } + + bool View3D_i::RestoreViewParams (SUIT_ViewManager* theViewManager, const char* theName) + { + _PTR(Study) aCStudy; + if (SUIT_Study* aSStudy = theViewManager->study()) { + if (SalomeApp_Study* aStudy = dynamic_cast(aSStudy)) { + aCStudy = aStudy->studyDS(); + } + } + if (!aCStudy) + return false; + + std::vector<_PTR(SObject)> aList = aCStudy->FindObjectByName(theName, "VISU"); + _PTR(GenericAttribute) anAttr; + int iEnd = aList.size(); + if (MYDEBUG) MESSAGE("View3D_i::RestoreViewPoint - iEnd = " << iEnd); + for (int i = 0; i < iEnd; i++) { + _PTR(SObject) anObj = aList[i]; + string anEntry = anObj->GetID(); + if (MYDEBUG) MESSAGE("View3D_i::RestoreViewPoint - anEntry = " << anEntry); + if (anObj->FindAttribute(anAttr, "AttributeComment")) { + _PTR(AttributeComment) aCmnt (anAttr); + QString strIn(aCmnt->Value().c_str()); + Storable::TRestoringMap aMap; + Storable::StrToMap(strIn, aMap); + if (Storable::FindValue(aMap, "myComment").compare + (View3D_i::myComment.c_str()) >= 0) { + if (MYDEBUG) MESSAGE("View3D_i::RestoreViewPoint - aComm = " << strIn); + Restore(theViewManager->getActiveView(), aMap); + return true; + } + } + } + return false; + } + + class TRestoreViewParamsEvent: public SALOME_Event + { + SUIT_ViewManager* myViewManager; + const char* myName; + public: + TRestoreViewParamsEvent (SUIT_ViewManager* theViewManager, + const char* theName): + myViewManager(theViewManager), + myName(theName) + {} + + virtual void Execute() + { + myResult = View3D_i::RestoreViewParams(myViewManager, myName); + } + typedef CORBA::Boolean TResult; + TResult myResult; + }; + + CORBA::Boolean View3D_i::RestoreViewParams (const char* theName) + { + return ProcessEvent(new TRestoreViewParamsEvent (myViewManager, theName)); + } + + void View3D_i::Restore (SUIT_ViewWindow* theStudyFrame, + const Storable::TRestoringMap& theMap) + { + SALOMEDS::Color aColor; + aColor.R = VISU::Storable::FindValue(theMap,"myColor.R").toDouble(); + aColor.G = VISU::Storable::FindValue(theMap,"myColor.G").toDouble(); + aColor.B = VISU::Storable::FindValue(theMap,"myColor.B").toDouble(); + + double aPosition[3]; + aPosition[0] = VISU::Storable::FindValue(theMap,"myPosition[0]").toDouble(); + aPosition[1] = VISU::Storable::FindValue(theMap,"myPosition[1]").toDouble(); + aPosition[2] = VISU::Storable::FindValue(theMap,"myPosition[2]").toDouble(); + + double aFocalPnt[3]; + aFocalPnt[0] = VISU::Storable::FindValue(theMap,"myFocalPnt[0]").toDouble(); + aFocalPnt[1] = VISU::Storable::FindValue(theMap,"myFocalPnt[1]").toDouble(); + aFocalPnt[2] = VISU::Storable::FindValue(theMap,"myFocalPnt[2]").toDouble(); + + double aViewUp[3]; + aViewUp[0] = VISU::Storable::FindValue(theMap,"myViewUp[0]").toDouble(); + aViewUp[1] = VISU::Storable::FindValue(theMap,"myViewUp[1]").toDouble(); + aViewUp[2] = VISU::Storable::FindValue(theMap,"myViewUp[2]").toDouble(); + + double aParallelScale = VISU::Storable::FindValue(theMap,"myParallelScale").toDouble(); + + double aScaleFactor[3]; + aScaleFactor[0] = VISU::Storable::FindValue(theMap,"myScaleFactor[0]").toDouble(); + aScaleFactor[1] = VISU::Storable::FindValue(theMap,"myScaleFactor[1]").toDouble(); + aScaleFactor[2] = VISU::Storable::FindValue(theMap,"myScaleFactor[2]").toDouble(); + + SetBackground(theStudyFrame,aColor); + SetPointOfView(theStudyFrame,aPosition); + SetViewUp(theStudyFrame,aViewUp); + SetFocalPoint(theStudyFrame,aFocalPnt); + SetParallelScale(theStudyFrame,aParallelScale); + ScaleView(theStudyFrame,VISU::View3D::XAxis,aScaleFactor[0]); + ScaleView(theStudyFrame,VISU::View3D::YAxis,aScaleFactor[1]); + ScaleView(theStudyFrame,VISU::View3D::ZAxis,aScaleFactor[2]); + } + + + string View3D_i::ToString (SUIT_ViewWindow* theStudyFrame) + { + ostringstream strOut; + Storable::DataToStream( strOut, "myComment", myComment.c_str() ); + ToStream(theStudyFrame,strOut); + strOut<GetBackground(backint); + Storable::DataToStream(theStr,"myColor.R",backint[0]); + Storable::DataToStream(theStr,"myColor.G",backint[1]); + Storable::DataToStream(theStr,"myColor.B",backint[2]); + + double aPosition[3]; + GetPointOfView(theStudyFrame,aPosition); + Storable::DataToStream(theStr,"myPosition[0]",aPosition[0]); + Storable::DataToStream(theStr,"myPosition[1]",aPosition[1]); + Storable::DataToStream(theStr,"myPosition[2]",aPosition[2]); + + double aFocalPnt[3]; + GetFocalPoint(theStudyFrame,aFocalPnt); + Storable::DataToStream(theStr,"myFocalPnt[0]",aFocalPnt[0]); + Storable::DataToStream(theStr,"myFocalPnt[1]",aFocalPnt[1]); + Storable::DataToStream(theStr,"myFocalPnt[2]",aFocalPnt[2]); + + double aViewUp[3]; + GetCamera(theStudyFrame)->GetViewUp(aViewUp); + Storable::DataToStream(theStr,"myViewUp[0]",aViewUp[0]); + Storable::DataToStream(theStr,"myViewUp[1]",aViewUp[1]); + Storable::DataToStream(theStr,"myViewUp[2]",aViewUp[2]); + + Storable::DataToStream(theStr,"myParallelScale",GetParallelScale(theStudyFrame)); + + double aScaleFactor[3]; + GetViewWindow(theStudyFrame)->GetScale(aScaleFactor); + Storable::DataToStream(theStr,"myScaleFactor[0]",aScaleFactor[0]); + Storable::DataToStream(theStr,"myScaleFactor[1]",aScaleFactor[1]); + Storable::DataToStream(theStr,"myScaleFactor[2]",aScaleFactor[2]); + } + + void View3D_i::ToStream(std::ostringstream& theStr) + { + ToStream(myViewWindow,theStr); + } + + void View3D_i::Close() + { + //jfa: may be need to be enclosed in SALOME_Event? + myViewWindow->close(); + } + + View3D_i::~View3D_i() + { + if(MYDEBUG) MESSAGE("View3D_i::~View3D_i"); + } + + void View3D_i::SetTitle (const char* theTitle) + { + ProcessVoidEvent(new TVoidMemFun1ArgEvent + (myViewWindow,&SUIT_ViewWindow::setCaption,QString(theTitle))); + } + + char* View3D_i::GetTitle() + { + //jfa: may be need to be enclosed in SALOME_Event? + return CORBA::string_dup(myViewWindow->caption().latin1()); + } + + void View3D_i::SetBackground (SUIT_ViewWindow* theStudyFrame, + const SALOMEDS::Color& theColor) + { + //jfa: may be need to be enclosed in SALOME_Event? + int aColor[3]; + aColor[0] = int(255.0*theColor.R); + aColor[1] = int(255.0*theColor.G); + aColor[2] = int(255.0*theColor.B); + QColor aNewColor(aColor[0],aColor[1],aColor[2]); + GetViewWindow(theStudyFrame)->setBackgroundColor(aNewColor); + } + + SALOMEDS::Color View3D_i::GetBackground (SUIT_ViewWindow* theStudyFrame) + { + //jfa: may be need to be enclosed in SALOME_Event? + SALOMEDS::Color aColor; + float backint[3]; + GetRenderer(theStudyFrame)->GetBackground(backint); + aColor.R = backint[0]; aColor.G = backint[1]; aColor.B = backint[2]; + return aColor; + } + + class TUpdateViewerEvent: public SALOME_Event + { + SUIT_ViewWindow* myViewWindow; + Prs3d_i* myPrs3d; + int myDisplaing; + public: + TUpdateViewerEvent(SUIT_ViewWindow* theStudyFrame, + Prs3d_i* thePrs3d, + int theDisplaing): + myViewWindow(theStudyFrame), + myPrs3d(thePrs3d), + myDisplaing(theDisplaing) + {} + virtual void Execute(){ + UpdateViewer(myViewWindow,myDisplaing,myPrs3d); + } + }; + + void View3D_i::EraseAll() + { + if(MYDEBUG) MESSAGE("View3D_i::EraseAll"); + ProcessVoidEvent(new TUpdateViewerEvent(myViewWindow,NULL,eEraseAll)); + } + + void View3D_i::DisplayAll() + { + if(MYDEBUG) MESSAGE("View3D_i::DisplayAll"); + ProcessVoidEvent(new TUpdateViewerEvent(myViewWindow,NULL,eDisplayAll)); + } + + void View3D_i::Erase (PrsObject_ptr thePrsObj) + { + if(MYDEBUG) MESSAGE("View3D_i::Erase"); + CORBA::Object_ptr anObj = thePrsObj; + if(Prs3d_i* aPrs = dynamic_cast(VISU::GetServant(anObj).in())){ + ProcessVoidEvent(new TUpdateViewerEvent(myViewWindow,aPrs,eErase)); + } + } + + void View3D_i::Display (PrsObject_ptr thePrsObj) + { + if(MYDEBUG) MESSAGE("View3D_i::Display"); + CORBA::Object_ptr anObj = thePrsObj; + if(Prs3d_i* aPrs = dynamic_cast(VISU::GetServant(anObj).in())){ + ProcessVoidEvent(new TUpdateViewerEvent(myViewWindow,aPrs,eDisplay)); + } + } + + void View3D_i::DisplayOnly (PrsObject_ptr thePrsObj) + { + if(MYDEBUG) MESSAGE("View3D_i::DisplayOnly"); + CORBA::Object_ptr anObj = thePrsObj; + if(Prs3d_i* aPrs = dynamic_cast(VISU::GetServant(anObj).in())){ + ProcessVoidEvent(new TUpdateViewerEvent(myViewWindow,aPrs,eDisplayOnly)); + } + } + + void View3D_i::FitAll() + { + ProcessVoidEvent(new TVoidMemFunEvent + (GetViewWindow(myViewWindow), &SVTK_ViewWindow::onFitAll)); + Update(); + } + + void View3D_i::SetView (VISU::View3D::ViewType theType) + { + switch (theType) { + case VISU::View3D::FRONT : + ProcessVoidEvent(new TVoidMemFunEvent + (GetViewWindow(myViewWindow), &SVTK_ViewWindow::onFrontView)); + break; + case VISU::View3D::BACK : + ProcessVoidEvent(new TVoidMemFunEvent + (GetViewWindow(myViewWindow), &SVTK_ViewWindow::onBackView)); + break; + case VISU::View3D::LEFT : + ProcessVoidEvent(new TVoidMemFunEvent + (GetViewWindow(myViewWindow),&SVTK_ViewWindow::onLeftView)); + break; + case VISU::View3D::RIGHT : + ProcessVoidEvent(new TVoidMemFunEvent + (GetViewWindow(myViewWindow),&SVTK_ViewWindow::onRightView)); + break; + case VISU::View3D::TOP : + ProcessVoidEvent(new TVoidMemFunEvent + (GetViewWindow(myViewWindow),&SVTK_ViewWindow::onTopView)); + break; + case VISU::View3D::BOTTOM : + ProcessVoidEvent(new TVoidMemFunEvent + (GetViewWindow(myViewWindow),&SVTK_ViewWindow::onBottomView)); + break; + } + Update(); + } + + class TSet3DViewParamEvent: public SALOME_Event + { + public: + typedef void (*TFun)(SUIT_ViewWindow* theStudyFrame, const CORBA::Double theParam[3]); + TSet3DViewParamEvent (TFun theFun, + SUIT_ViewWindow* theStudyFrame, + const CORBA::Double theParam[3]): + myFun(theFun), + myViewWindow(theStudyFrame), + myParam(theParam) + {} + virtual void Execute(){ + myFun(myViewWindow,myParam); + } + private: + TFun myFun; + SUIT_ViewWindow* myViewWindow; + const CORBA::Double* myParam; + }; + + void View3D_i::SetPointOfView (SUIT_ViewWindow* theStudyFrame, + const CORBA::Double thePosition[3]) + { + //jfa: may be need to be enclosed in SALOME_Event? + GetCamera(theStudyFrame)->SetPosition(thePosition); + } + + void View3D_i::SetPointOfView (const VISU::View3D::XYZ thePosition) + { + if(MYDEBUG) MESSAGE("View3D_i::SetPointOfView"); + ProcessVoidEvent(new TSet3DViewParamEvent(&SetPointOfView,myViewWindow,thePosition)); + } + + void View3D_i::GetPointOfView (SUIT_ViewWindow* theStudyFrame, + CORBA::Double thePosition[3]) + { + //jfa: may be need to be enclosed in SALOME_Event? + GetCamera(theStudyFrame)->GetPosition(thePosition); + } + + VISU::View3D::XYZ_slice* View3D_i::GetPointOfView() + { + //jfa: may be need to be enclosed in SALOME_Event? + if(MYDEBUG) MESSAGE("View3D_i::GetPointOfView"); + CORBA::Double aPosition[3]; + GetPointOfView(myViewWindow,aPosition); + return VISU::View3D::XYZ_dup(aPosition); + } + + void View3D_i::SetViewUp (SUIT_ViewWindow* theStudyFrame, + const CORBA::Double theViewUp[3]) + { + GetCamera(theStudyFrame)->SetViewUp(theViewUp); + } + + void View3D_i::SetViewUp (const VISU::View3D::XYZ theViewUp) + { + if(MYDEBUG) MESSAGE("View3D_i::SetViewUp"); + ProcessVoidEvent(new TSet3DViewParamEvent(&SetViewUp,myViewWindow,theViewUp)); + } + + void View3D_i::GetViewUp (SUIT_ViewWindow* theStudyFrame, + CORBA::Double theViewUp[3]) + { + GetCamera(theStudyFrame)->GetViewUp(theViewUp); + } + + VISU::View3D::XYZ_slice* View3D_i::GetViewUp() + { + //jfa: may be need to be enclosed in SALOME_Event? + if(MYDEBUG) MESSAGE("View3D_i::GetViewUp"); + CORBA::Double aViewUp[3]; + GetCamera(myViewWindow)->GetViewUp(aViewUp); + return VISU::View3D::XYZ_dup(aViewUp); + } + + void View3D_i::SetFocalPoint (SUIT_ViewWindow* theStudyFrame, + const CORBA::Double theFocalPnt[3]) + { + GetCamera(theStudyFrame)->SetFocalPoint(theFocalPnt); + } + + void View3D_i::SetFocalPoint (const VISU::View3D::XYZ theCoord) + { + if(MYDEBUG) MESSAGE("View3D_i::SetFocalPoint"); + ProcessVoidEvent(new TSet3DViewParamEvent(&SetFocalPoint,myViewWindow,theCoord)); + } + + + void View3D_i::GetFocalPoint (SUIT_ViewWindow* theStudyFrame, + CORBA::Double theFocalPnt[3]) + { + GetCamera(theStudyFrame)->GetFocalPoint(theFocalPnt); + } + + VISU::View3D::XYZ_slice* View3D_i::GetFocalPoint() + { + //jfa: may be need to be enclosed in SALOME_Event? + if(MYDEBUG) MESSAGE("View3D_i::GetFocalPoint"); + CORBA::Double aFocalPnt[3]; + GetFocalPoint(myViewWindow,aFocalPnt); + return VISU::View3D::XYZ_dup(aFocalPnt); + } + + class TSetViewParamEvent: public SALOME_Event + { + public: + typedef void (*TFun)(SUIT_ViewWindow* theStudyFrame, CORBA::Double theParam); + TSetViewParamEvent (TFun theFun, + SUIT_ViewWindow* theStudyFrame, + CORBA::Double theParam): + myFun(theFun), + myViewWindow(theStudyFrame), + myParam(theParam) + {} + virtual void Execute() + { + myFun(myViewWindow,myParam); + } + private: + TFun myFun; + SUIT_ViewWindow* myViewWindow; + CORBA::Double myParam; + }; + + void View3D_i::SetParallelScale (SUIT_ViewWindow* theStudyFrame, + CORBA::Double theScale) + { + GetCamera(theStudyFrame)->SetParallelScale(theScale); + } + + void View3D_i::SetParallelScale (CORBA::Double theScale) + { + if(MYDEBUG) MESSAGE("View3D_i::SetParallelScale"); + ProcessVoidEvent(new TSetViewParamEvent(&SetParallelScale,myViewWindow,theScale)); + } + + CORBA::Double View3D_i::GetParallelScale (SUIT_ViewWindow* theStudyFrame) + { + return GetCamera(theStudyFrame)->GetParallelScale(); + } + + CORBA::Double View3D_i::GetParallelScale() + { + //jfa: may be need to be enclosed in SALOME_Event? + if(MYDEBUG) MESSAGE("View3D_i::GetParallelScale"); + return GetParallelScale(myViewWindow); + } + + void View3D_i::ScaleView (SUIT_ViewWindow* theStudyFrame, + VISU::View3D::Axis theAxis, CORBA::Double theParam) + { + SVTK_ViewWindow* aViewFrame = GetViewWindow(theStudyFrame); + double aScaleFactor[3]; + aViewFrame->GetScale(aScaleFactor); + aScaleFactor[theAxis] = theParam; + aViewFrame->SetScale(aScaleFactor); + } + + void SetScaleView (SUIT_ViewWindow* theStudyFrame, const CORBA::Double theScale[3]) + { + double aScale[3] = {theScale[0], theScale[1], theScale[2]}; + GetViewWindow(theStudyFrame)->SetScale(aScale); + } + + void View3D_i::ScaleView(VISU::View3D::Axis theAxis, CORBA::Double theParam) + { + if(MYDEBUG) MESSAGE("View3D_i::ScaleView"); + double aScale[3]; + GetViewWindow(myViewWindow)->GetScale(aScale); + aScale[theAxis] = theParam; + ProcessVoidEvent(new TSet3DViewParamEvent(&SetScaleView,myViewWindow,aScale)); + } + + void View3D_i::RemoveScale() + { + if(MYDEBUG) MESSAGE("View3D_i::RemoveScale"); + double aScale[3] = {1.0, 1.0, 1.0}; + ProcessVoidEvent(new TSet3DViewParamEvent(&SetScaleView,myViewWindow,aScale)); + } +} diff --git a/src/VISU_SWIG/visu_split_views.py b/src/VISU_SWIG/visu_split_views.py new file mode 100644 index 00000000..545ed7a3 --- /dev/null +++ b/src/VISU_SWIG/visu_split_views.py @@ -0,0 +1,129 @@ + +import VISU +import SALOMEDS +from visu_gui import * + +myViewManager = myVisu.GetViewManager() + +################################################ + +myView1 = myViewManager.Create3DView() +myView1.SetTitle("The window will be soon destroyed!") +print "myView1 = myViewManager.Create3DView()" + +myView1.Maximize() +print "myView1.Maximize()" + +myView1.Restore() +print "myView1.Restore()" + +myView1.Minimize() +print "myView1.Minimize()" + +myViewManager.Destroy(myView1) +print "myViewManager.Destroy(myView1)" + +################################################ + +myView2 = myViewManager.Create3DView() +print "myView2 = myViewManager.Create3DView()" +myView2.SetTitle("myView2") + +aColor = SALOMEDS.Color(0.0,0.3,1.0) +myView2.SetBackground(aColor) +print "aColor = SALOMEDS.Color(0.0,0.3,1.0)" +print "myView2.SetBackground(aColor)" + +myView2.SetFocalPoint([0,0,0]) +print "myView2.SetFocalPoint([0,0,0])" +myView2.SetParallelScale(2) +print "myView2.SetParallelScale(2)" + +################################################ + +myView3 = myViewManager.Create3DView() +print "myView3 = myViewManager.Create3DView()" +myView3.SetTitle("myView3") + +myView3.SplitRight() +print "myView3.SplitRight()" + +aColor = SALOMEDS.Color(0.0,0.7,0.0) +print "aColor = SALOMEDS.Color(0.0,0.7,0.0)" +myView3.SetBackground(aColor) +print "myView3.SetBackground(aColor)" + +aPoint = myView3.GetPointOfView() +aPoint[0] = aPoint[0] + 10 +myView3.SetPointOfView(aPoint) +print "myView3.SetPointOfView(...)" +myView3.ScaleView(VISU.View3D.YAxis,10.0) +myView3.ScaleView(VISU.View3D.XAxis,3.0) +print "myView3.ScaleView(...)" + +myView3.FitAll() + +myView3.SaveViewParams('AAA') +print "myView3.SaveViewParams('AAA')" + +myView3.RemoveScale() +print "myView3.RemoveScale()" + +myView3.Update() +print "myView3.Update()" +myView3.FitAll() +print "myView3.FitAll()" + +################################################ + +myView4 = myViewManager.Create3DView() +print "myView4 = myViewManager.Create3DView()" +myView4.SetTitle("myView4") + +aColor = SALOMEDS.Color(1.0,0.7,0.0) +print "aColor = SALOMEDS.Color(1.0,0.7,0.0)" +myView4.SetBackground(aColor) +print "myView4.SetBackground(aColor)" + +################################################ + +myView5 = myViewManager.Create3DView() +print "myView5 = myViewManager.Create3DView()" +myView5.SetTitle("myView5") + +myView5.SplitTop() +print "myView5.SplitTop()" + +aColor = SALOMEDS.Color(0.7,0.7,0.7) +print "aColor = SALOMEDS.Color(0.7,0.7,0.7)" +myView5.SetBackground(aColor) +print "myView5.SetBackground(aColor)" + +################################################ + +myView6 = myViewManager.CreateXYPlot() +print "myView6 = myViewManager.CreateXYPlot()" +myView6.SetTitle("myView6") + +################################################ + +myView7 = myViewManager.Create3DView() +print "myView7 = myViewManager.Create3DView()" +myView7.SetTitle("myView7") + +################################################ + +myView6.OnTop() +print "myView6.OnTop()" + +myView4.Attract(myView2) +print "myView4.Attract(myView2)" + +myView4.SetRelativePositionInSplitter(0.7) +print "myView4.SetRelativePositionInSplitter(0.7)" + +myView4.SetRelativePositionX(0.2) +print "myView4.SetRelativePositionX(0.7)" + +#myView4.SetRelativePositionY(0.2) +#print "myView4.SetRelativePositionY(0.2)" -- 2.39.2