1 // VISU OBJECT : interactive object for VISU entities implementation
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
23 // File : VISU_View_i.cc
24 // Author : Alexey PETROV
27 #include "VISU_View_i.hh"
29 #include "VISU_Gen_i.hh"
30 #include "VISU_Prs3d_i.hh"
31 #include "VISU_Table_i.hh"
32 #include "VISU_ViewManager_i.hh"
34 #include "VisuGUI_TableDlg.h"
36 #include "VISU_Actor.h"
38 #include "SALOME_Event.hxx"
40 #include "SUIT_ViewWindow.h"
41 #include "SUIT_ViewManager.h"
42 #include "SUIT_Tools.h"
44 #include "STD_MDIDesktop.h"
46 #include "SVTK_ViewWindow.h"
47 #include "SVTK_ViewModel.h"
48 #include "SPlot2d_ViewModel.h"
50 #include "Plot2d_ViewFrame.h"
51 #include "Plot2d_ViewModel.h"
53 #include "SalomeApp_Application.h"
54 #include "SalomeApp_Study.h"
56 #include <qworkspace.h>
58 #include <vtkCamera.h>
59 #include <vtkRenderer.h>
64 static int MYDEBUG = 0;
66 static int MYDEBUG = 0;
71 typedef TVoidMemFunEvent<SUIT_ViewWindow> TFrameActionEvent;
74 View_i(SalomeApp_Application *theApplication,
75 SUIT_ViewManager* theViewManager):
76 myApplication(theApplication),
78 myViewManager(theViewManager)
80 if(MYDEBUG) MESSAGE("View_i::View_i - "<<this);
81 if(STD_MDIDesktop* aDesktop = dynamic_cast<STD_MDIDesktop*>(myApplication->desktop())){
82 myWorkspace = aDesktop->workspace();
89 if(MYDEBUG) MESSAGE("View_i::~View_i - "<<this);
93 struct TApplicationEvent: public SALOME_Event
95 SalomeApp_Application* myApplication;
97 TApplicationEvent(SalomeApp_Application* theApplication):
98 myApplication(theApplication)
105 ShowPart(VISU::View::ViewRepresentation theViewRepresentation,
106 CORBA::Boolean theState)
108 struct TEvent: public TApplicationEvent
110 VISU::View::ViewRepresentation myViewRepresentation;
111 CORBA::Boolean myState;
113 TEvent(SalomeApp_Application* theApplication,
114 VISU::View::ViewRepresentation theViewRepresentation,
115 CORBA::Boolean theState):
116 TApplicationEvent(theApplication),
117 myViewRepresentation(theViewRepresentation),
125 switch(myViewRepresentation){
126 case VISU::View::OBJECTBROWSER:
127 myApplication->setWindowShown(SalomeApp_Application::WT_ObjectBrowser,myState);
129 case VISU::View::PYTHON:
130 myApplication->setWindowShown(SalomeApp_Application::WT_PyConsole,myState);
132 case VISU::View::MESSAGES:
133 myApplication->setWindowShown(SalomeApp_Application::WT_LogWindow,myState);
135 case VISU::View::VIEWER:{
136 ViewManagerList aViewManagerList = myApplication->viewManagers();
144 ProcessVoidEvent(new TEvent(myApplication,theViewRepresentation,theState));
148 struct TPartShownEvent: public TApplicationEvent
150 VISU::View::ViewRepresentation myViewRepresentation;
151 typedef bool TResult;
154 TPartShownEvent(SalomeApp_Application* theApplication,
155 VISU::View::ViewRepresentation theViewRepresentation):
156 TApplicationEvent(theApplication),
157 myViewRepresentation(theViewRepresentation),
165 switch(myViewRepresentation){
166 case VISU::View::OBJECTBROWSER:
167 myResult = myApplication->isWindowVisible(SalomeApp_Application::WT_ObjectBrowser);
169 case VISU::View::PYTHON:
170 myResult = myApplication->isWindowVisible(SalomeApp_Application::WT_PyConsole);
172 case VISU::View::MESSAGES:
173 myResult = myApplication->isWindowVisible(SalomeApp_Application::WT_LogWindow);
175 case VISU::View::VIEWER:{
176 ViewManagerList aViewManagerList = myApplication->viewManagers();
187 IsPartShown(VISU::View::ViewRepresentation theViewRepresentation)
189 return ProcessEvent(new TPartShownEvent(myApplication,theViewRepresentation));
193 struct TSetViewSize: public SALOME_Event
195 SUIT_ViewWindow* myViewWindow;
196 typedef void (QRect::* TAction)(int);
201 TSetViewSize(SUIT_ViewWindow* theViewWindow,
203 CORBA::Long theSize):
204 myViewWindow(theViewWindow),
213 if (QWidget* aParent = myViewWindow->parentWidget(true)) {
214 QRect aQRect = aParent->frameGeometry();
215 (aQRect.*myAction)(mySize);
216 aParent->setGeometry(aQRect);
224 SetViewWidth(CORBA::Long theWidth)
226 ProcessVoidEvent(new TSetViewSize(myViewWindow,&QRect::setWidth,theWidth));
232 SetViewHeight(CORBA::Long theHeight)
234 ProcessVoidEvent(new TSetViewSize(myViewWindow,&QRect::setHeight,theHeight));
238 struct TGetViewSize: public SALOME_Event
240 SUIT_ViewWindow* myViewWindow;
242 typedef int (QRect::* TAction)() const;
245 typedef CORBA::Long TResult;
249 TGetViewSize(SUIT_ViewWindow* theViewWindow,
251 myViewWindow(theViewWindow),
259 if(QWidget* aParent = myViewWindow->parentWidget(true)){
260 QRect aQRect = aParent->frameGeometry();
261 myResult = (aQRect.*myAction)();
271 return ProcessEvent(new TGetViewSize(myViewWindow,&QRect::width));
278 return ProcessEvent(new TGetViewSize(myViewWindow,&QRect::height));
282 class TWorkspaceEvent: public SALOME_Event
285 QWidget* myViewWindow;
286 QWidget* myWorkspace;
289 TWorkspaceEvent(QWidget* theViewWindow,
290 QWidget* theWorkspace):
291 myViewWindow(theViewWindow),
292 myWorkspace(theWorkspace)
297 class TAlignEvent: public TWorkspaceEvent
300 Qt::AlignmentFlags myAligment;
303 TAlignEvent(QWidget* theViewWindow,
304 QWidget* theWorkspace,
305 Qt::AlignmentFlags theAligment):
306 TWorkspaceEvent(theViewWindow,theWorkspace),
307 myAligment(theAligment)
314 if(QWidget* aParent = myViewWindow->parentWidget(true))
315 SUIT_Tools::alignWidget(aParent,myWorkspace,myAligment);
322 SetViewPositionHorizontal(VISU::View::ViewPosition theViewPosition)
325 switch(theViewPosition){
326 case VISU::View::LEFT:
327 ProcessVoidEvent(new TAlignEvent(myViewWindow,myWorkspace,Qt::AlignLeft));
329 case VISU::View::CENTER:
330 ProcessVoidEvent(new TAlignEvent(myViewWindow,myWorkspace,Qt::AlignHCenter));
332 case VISU::View::RIGHT:
333 ProcessVoidEvent(new TAlignEvent(myViewWindow,myWorkspace,Qt::AlignRight));
342 SetViewPositionVertical(VISU::View::ViewPosition theViewPosition)
345 switch(theViewPosition){
346 case VISU::View::TOP:
347 ProcessVoidEvent(new TAlignEvent(myViewWindow,myWorkspace,Qt::AlignTop));
349 case VISU::View::CENTER:
350 ProcessVoidEvent(new TAlignEvent(myViewWindow,myWorkspace,Qt::AlignVCenter));
352 case VISU::View::BOTTOM:
353 ProcessVoidEvent(new TAlignEvent(myViewWindow,myWorkspace,Qt::AlignBottom));
360 class TXYEvent: public TWorkspaceEvent
363 CORBA::Double myX, myY;
366 TXYEvent(QWidget* theViewWindow,
367 QWidget* theWorkspace,
370 TWorkspaceEvent(theViewWindow,theWorkspace),
379 SetRelativePosition(CORBA::Double theX, CORBA::Double theY)
381 struct TEvent: public TXYEvent
384 TEvent(QWidget* theViewWindow,
385 QWidget* theWorkspace,
388 TXYEvent(theViewWindow,theWorkspace,theX,theY)
395 if(QWidget* aParent = myViewWindow->parentWidget(true))
396 aParent->move(int(myX*myWorkspace->width()),int(myY*myWorkspace->height()));
401 ProcessVoidEvent(new TEvent(myViewWindow,myWorkspace,theX,theY));
406 SetRelativeSize(CORBA::Double theX, CORBA::Double theY)
408 struct TEvent: public TXYEvent
411 TEvent(QWidget* theViewWindow,
412 QWidget* theWorkspace,
415 TXYEvent(theViewWindow,theWorkspace,theX,theY)
422 if(QWidget* aParent = myViewWindow->parentWidget(true))
423 aParent->setGeometry(aParent->x(),
425 int(myX*myWorkspace->width()),
426 int(myY*myWorkspace->height()));
431 ProcessVoidEvent(new TEvent(myViewWindow,myWorkspace,theX,theY));
436 SetBackground(const SALOMEDS::Color& theColor)
438 struct TEvent: public SALOME_Event
441 SALOMEDS::Color myColor;
443 TEvent(QWidget* theWidget,
444 const SALOMEDS::Color& theColor):
448 virtual void Execute(){
450 aColor[0] = int(255.0*myColor.R);
451 aColor[1] = int(255.0*myColor.G);
452 aColor[2] = int(255.0*myColor.B);
453 myWidget->setBackgroundColor(QColor(aColor[0],aColor[1],aColor[2]));
457 ProcessVoidEvent(new TEvent(myViewWindow,theColor));
461 struct TBackgroundEvent: public SALOME_Event
464 typedef SALOMEDS::Color TResult;
467 TBackgroundEvent(QWidget* theWidget):
475 const QColor& aColor = myWidget->backgroundColor();
476 myResult.R = aColor.red()/255.0;
477 myResult.G = aColor.green()/255.0;
478 myResult.B = aColor.blue()/255.0;
486 return ProcessEvent(new TBackgroundEvent(myViewWindow));
493 ProcessVoidEvent(new TFrameActionEvent(myViewWindow,&SUIT_ViewWindow::showMinimized));
500 ProcessVoidEvent(new TFrameActionEvent(myViewWindow,&SUIT_ViewWindow::showNormal));
507 ProcessVoidEvent(new TFrameActionEvent(myViewWindow,&SUIT_ViewWindow::showMaximized));
522 Erase(PrsObject_ptr thePrsObj)
527 Display(PrsObject_ptr thePrsObj)
532 DisplayOnly(PrsObject_ptr thePrsObj)
541 View_i::SavePicture(const char* theFileName)
554 ToStream(std::ostringstream& theStr)
558 //================= OLD CODE ===================
560 //QAD_Study* CheckStudy (SALOMEDS::Study_ptr theStudy)
562 // //QAD_Desktop* aDesktop = QAD_Application::getDesktop();
563 // //QAD_Study* aStudy = aDesktop->findStudy(theStudy);
565 // CORBA::String_var aName = theStudy->Name();
566 // aFileInfo.setFile(aName.in());
567 // if (aFileInfo.exists())
568 // aStudy = aDesktop->loadStudy(aFileInfo.baseName());
570 // aStudy = aDesktop->loadStudy(aName.in());
572 // MESSAGE("CheckStudy()::ERROR: Can't load study");
578 class TSavePictureEvent: public SALOME_Event
581 const char* myFileName;
583 typedef CORBA::Boolean TResult;
585 TSavePictureEvent (QWidget* theWidget, const char* theFileName)
586 : myWidget(theWidget),
587 myFileName(theFileName),
592 virtual void Execute()
595 QPixmap px = QPixmap::grabWindow(myWidget->winId());
596 if (!QString(myFileName).isNull()) {
597 QString fmt = SUIT_Tools::extension(myFileName).upper();
599 fmt = QString("BMP"); // default format
602 myResult = px.save(myFileName, fmt.latin1());
609 //===========================================================================
610 XYPlot_i::XYPlot_i (SalomeApp_Application* theApplication)
611 : View_i(theApplication, NULL)
613 if (MYDEBUG) MESSAGE("XYPlot_i::XYPlot_i");
614 if (theApplication) {
615 myViewManager = theApplication->getViewManager(Plot2d_Viewer::Type(), true);
619 Storable* XYPlot_i::Create (int theNew)
622 myViewWindow = myViewManager->createViewWindow();
624 myViewWindow = myViewManager->getActiveView();
626 ////myView = dynamic_cast<Plot2d_ViewFrame*>(myViewWindow->getRightFrame()->getViewFrame());
627 //SPlot2d_Viewer* aView = dynamic_cast<SPlot2d_Viewer*>(myViewManager->getViewModel());
628 //myView = aView->getActiveViewFrame();
630 Plot2d_ViewWindow* aPlot2dVW = dynamic_cast<Plot2d_ViewWindow*>(myViewWindow);
632 myView = aPlot2dVW->getViewFrame();
641 void XYPlot_i::Update()
643 ProcessVoidEvent(new TVoidMemFunEvent<Plot2d_ViewFrame>(myView,&Plot2d_ViewFrame::Repaint));
646 void XYPlot_i::Close()
648 myViewWindow->close();
651 XYPlot_i::~XYPlot_i() {
652 if(MYDEBUG) MESSAGE("XYPlot_i::~XYPlot_i");
655 void XYPlot_i::SetTitle (const char* theTitle)
657 ProcessVoidEvent(new TVoidMemFun1ArgEvent<SUIT_ViewWindow,const QString&,QString>
658 (myViewWindow, &SUIT_ViewWindow::setCaption, QString(theTitle)));
660 char* XYPlot_i::GetTitle()
662 return CORBA::string_dup(myViewWindow->caption().latin1());
665 void XYPlot_i::SetSubTitle (const char* theTitle)
667 ProcessVoidEvent(new TVoidMemFun1ArgEvent<Plot2d_ViewFrame,const QString&,QString>
668 (myView, &Plot2d_ViewFrame::setTitle, QString(theTitle)));
671 char* XYPlot_i::GetSubTitle()
673 return CORBA::string_dup(myView->getTitle());
676 void XYPlot_i::SetCurveType (VISU::XYPlot::CurveType theType)
678 ProcessVoidEvent(new TVoidMemFun2ArgEvent<Plot2d_ViewFrame,int,bool>
679 (myView,&Plot2d_ViewFrame::setCurveType,theType,true));
682 VISU::XYPlot::CurveType XYPlot_i::GetCurveType()
684 return (VISU::XYPlot::CurveType)myView->getCurveType();
687 void XYPlot_i::SetMarkerSize (CORBA::Long theSize)
689 ProcessVoidEvent(new TVoidMemFun2ArgEvent<Plot2d_ViewFrame,int,bool>
690 (myView,&Plot2d_ViewFrame::setMarkerSize,theSize,true));
693 CORBA::Long XYPlot_i::GetMarkerSize()
695 return myView->getMarkerSize();
698 class TEnableGridEvent: public SALOME_Event
701 typedef void (Plot2d_ViewFrame::* TFun)(bool, const int, bool, const int, bool);
702 TEnableGridEvent (Plot2d_ViewFrame* theView, TFun theFun,
703 CORBA::Boolean theMajor, CORBA::Long theNumMajor,
704 CORBA::Boolean theMinor, CORBA::Long theNumMinor):
705 myView(theView), myFun(theFun),
706 myMajor(theMajor), myNumMajor(theNumMajor),
707 myMinor(theMinor), myNumMinor(theNumMinor)
710 virtual void Execute()
712 (myView->*myFun)(myMajor,myNumMajor,myMinor,myNumMinor,true);
715 Plot2d_ViewFrame* myView;
717 CORBA::Boolean myMajor, myNumMajor;
718 CORBA::Boolean myMinor, myNumMinor;
721 void XYPlot_i::EnableXGrid (CORBA::Boolean theMajor, CORBA::Long theNumMajor,
722 CORBA::Boolean theMinor, CORBA::Long theNumMinor)
724 ProcessVoidEvent(new TEnableGridEvent(myView,&Plot2d_ViewFrame::setXGrid,
725 theMajor,theNumMajor,theMinor,theNumMinor));
727 void XYPlot_i::EnableYGrid(CORBA::Boolean theMajor, CORBA::Long theNumMajor,
728 CORBA::Boolean theMinor, CORBA::Long theNumMinor)
730 //jfa tmp:ProcessVoidEvent(new TEnableGridEvent(myView,&Plot2d_ViewFrame::setYGrid,
731 //jfa tmp: theMajor,theNumMajor,theMinor,theNumMinor));
734 class TSetScaleModeEvent: public SALOME_Event
737 typedef void (Plot2d_ViewFrame::* TFun)(const int, bool);
738 TSetScaleModeEvent (Plot2d_ViewFrame* theView, TFun theFun, int theScaling):
739 myView(theView), myFun(theFun), myScaling(theScaling)
742 virtual void Execute()
744 (myView->*myFun)(myScaling,true);
747 Plot2d_ViewFrame* myView;
752 void XYPlot_i::SetHorScaling (VISU::Scaling theScaling)
754 ProcessVoidEvent(new TSetScaleModeEvent(myView,&Plot2d_ViewFrame::setHorScaleMode,
755 theScaling == VISU::LOGARITHMIC));
758 VISU::Scaling XYPlot_i::GetHorScaling()
760 return (VISU::Scaling)myView->getHorScaleMode();
763 void XYPlot_i::SetVerScaling(VISU::Scaling theScaling)
765 ProcessVoidEvent(new TSetScaleModeEvent(myView,&Plot2d_ViewFrame::setVerScaleMode,
766 theScaling == VISU::LOGARITHMIC));
769 VISU::Scaling XYPlot_i::GetVerScaling()
771 return (VISU::Scaling)myView->getVerScaleMode();
774 class TSetTitleEvent: public SALOME_Event
777 //typedef void (Plot2d_ViewFrame::* TFun)(bool, const QString&, bool = true);
778 typedef void (Plot2d_ViewFrame::* TFun)(bool, const QString&, Plot2d_ViewFrame::ObjectType, bool = true);
779 //TSetTitleEvent (Plot2d_ViewFrame* theView, TFun theFun, const char* theTitle):
780 TSetTitleEvent (Plot2d_ViewFrame* theView, Plot2d_ViewFrame::ObjectType theType, const char* theTitle):
781 //myView(theView), myFun(theFun), myTitle(theTitle)
782 myView(theView), myType(theType), myTitle(theTitle)
784 virtual void Execute()
786 //(myView->*myFun)(true,myTitle,myType);
787 myView->setTitle(true,myTitle,myType);
790 Plot2d_ViewFrame* myView;
792 Plot2d_ViewFrame::ObjectType myType;
796 void XYPlot_i::SetXTitle (const char* theTitle)
798 //ProcessVoidEvent(new TSetTitleEvent(myView, &Plot2d_ViewFrame::setXTitle, theTitle));
799 ProcessVoidEvent(new TSetTitleEvent(myView, Plot2d_ViewFrame::XTitle, theTitle));
801 char* XYPlot_i::GetXTitle()
803 //return CORBA::string_dup(myView->getXTitle());
804 return CORBA::string_dup(myView->getTitle(Plot2d_ViewFrame::XTitle));
807 void XYPlot_i::SetYTitle (const char* theTitle)
809 //ProcessVoidEvent(new TSetTitleEvent(myView, &Plot2d_ViewFrame::setYTitle, theTitle));
810 ProcessVoidEvent(new TSetTitleEvent(myView, Plot2d_ViewFrame::YTitle, theTitle));
812 char* XYPlot_i::GetYTitle()
814 //return CORBA::string_dup(myView->getYTitle());
815 return CORBA::string_dup(myView->getTitle(Plot2d_ViewFrame::YTitle));
818 void XYPlot_i::ShowLegend (CORBA::Boolean theShowing)
820 ProcessVoidEvent(new TVoidMemFun2ArgEvent<Plot2d_ViewFrame,bool,bool>
821 (myView,&Plot2d_ViewFrame::showLegend,theShowing,true));
824 class TXYPlotViewEvent: public SALOME_Event
826 SalomeApp_Application* myApplication;
827 Plot2d_ViewFrame* myView;
828 PrsObject_ptr myPrsObj;
832 TXYPlotViewEvent(SalomeApp_Application* theApplication,
833 Plot2d_ViewFrame* theView,
834 PrsObject_ptr thePrsObj,
836 : myApplication(theApplication),
839 myDisplaing(theDisplaing)
843 virtual void Execute()
846 if (Curve_i* aCurve = dynamic_cast<Curve_i*>(VISU::GetServant(myPrsObj).in())) {
847 UpdatePlot2d(myView,myDisplaing,aCurve);
850 if (Container_i* aContainer = dynamic_cast<Container_i*>(VISU::GetServant(myPrsObj).in())) {
851 int nbCurves = aContainer->GetNbCurves();
852 for ( int i = 1; i <= nbCurves; i++ ) {
853 VISU::Curve_i* aCurve = aContainer->GetCurve( i );
854 if ( aCurve && aCurve->IsValid() ) {
855 UpdatePlot2d(myView,myDisplaing,aCurve);
861 if (Table_i* aTable = dynamic_cast<Table_i*>(VISU::GetServant(myPrsObj).in())) {
863 if (SUIT_Study* aSStudy = myApplication->activeStudy()) {
864 if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
865 aCStudy = aStudy->studyDS();
868 if (!aCStudy) return;
869 _PTR(SObject) TableSO = aCStudy->FindObjectID(aTable->GetEntry().latin1());
871 _PTR(ChildIterator) Iter = aCStudy->NewChildIterator(TableSO);
872 for (; Iter->More(); Iter->Next()) {
873 CORBA::Object_var childObject = VISU::ClientSObjectToObject(Iter->Value());
874 if (!CORBA::is_nil(childObject)) {
875 CORBA::Object_ptr aCurve = VISU::Curve::_narrow(childObject);
876 if (!CORBA::is_nil(aCurve))
877 UpdatePlot2d(myView, myDisplaing,
878 dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aCurve).in()));
887 void XYPlot_i::Display (PrsObject_ptr thePrsObj)
889 ProcessVoidEvent(new TXYPlotViewEvent (myApplication,myView,thePrsObj,eDisplay));
892 void XYPlot_i::Erase (PrsObject_ptr thePrsObj)
894 ProcessVoidEvent(new TXYPlotViewEvent (myApplication,myView,thePrsObj,eErase));
897 void XYPlot_i::DisplayOnly (PrsObject_ptr thePrsObj)
899 ProcessVoidEvent(new TXYPlotViewEvent (myApplication,myView,thePrsObj,eDisplayOnly));
902 void XYPlot_i::EraseAll()
904 ProcessVoidEvent(new TVoidMemFunEvent<Plot2d_ViewFrame> (myView,&Plot2d_ViewFrame::EraseAll));
907 void XYPlot_i::FitAll()
909 ProcessVoidEvent(new TVoidMemFunEvent<Plot2d_ViewFrame> (myView,&Plot2d_ViewFrame::fitAll));
912 CORBA::Boolean XYPlot_i::SavePicture (const char* theFileName)
914 return ProcessEvent(new TSavePictureEvent (myView->getViewWidget(),theFileName));
918 //===========================================================================
919 TableView_i::TableView_i (SalomeApp_Application* theApplication)
920 : View_i(theApplication, NULL)
924 Storable* TableView_i::Create (VISU::Table_ptr theTable)
926 if (MYDEBUG) MESSAGE("TableView_i::Create - " << (!theTable->_is_nil()));
927 if (!theTable->_is_nil()) {
928 VISU::Table_i* table = dynamic_cast<VISU::Table_i*>(VISU::GetServant(theTable).in());
929 if (MYDEBUG) MESSAGE("TableView_i::Create - dynamic_cast = " << table);
931 if (SUIT_Study* aSStudy = myApplication->activeStudy()) {
932 if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
933 if (_PTR(Study) aCStudy = aStudy->studyDS()) {
934 _PTR(SObject) aSObject = aCStudy->FindObjectID(table->GetObjectEntry());
936 myView = new VisuGUI_TableDlg (myApplication->desktop(),
939 VisuGUI_TableDlg::ttAuto,
952 TableView_i::~TableView_i()
954 if(MYDEBUG) MESSAGE("TableView_i::~TableView_i");
958 void TableView_i::SetTitle (const char* theTitle)
960 ProcessVoidEvent(new TVoidMemFun1ArgEvent<VisuGUI_TableDlg,const QString&,QString>
961 (myView, &VisuGUI_TableDlg::setCaption, QString(theTitle)));
964 char* TableView_i::GetTitle()
966 return CORBA::string_dup(myView->caption().latin1());
970 void TableView_i::Close()
976 //===========================================================================
977 int View3D_i::myNbViewParams = 0;
978 const string View3D_i::myComment = "VIEW3D";
979 const char* View3D_i::GetComment() const { return myComment.c_str();}
981 QString View3D_i::GenerateViewParamsName()
983 return VISU::GenerateName("ViewParams", ++myNbViewParams);
986 View3D_i::View3D_i (SalomeApp_Application* theApplication)
987 : View_i(theApplication, NULL)
989 if (MYDEBUG) MESSAGE("View3D_i::View3D_i");
990 if (theApplication) {
991 myViewManager = theApplication->getViewManager(SVTK_Viewer::Type(), true);
995 Storable* View3D_i::Create (int theNew)
997 if (MYDEBUG) MESSAGE("View3D_i::Create");
999 myViewWindow = myViewManager->createViewWindow();
1001 myViewWindow = myViewManager->getActiveView();
1006 void View3D_i::Update()
1008 class TEvent: public SALOME_Event
1010 SUIT_ViewWindow* myViewWindow;
1012 TEvent(SUIT_ViewWindow* theStudyFrame):
1013 myViewWindow(theStudyFrame)
1015 virtual void Execute()
1017 SVTK_ViewWindow* vf = GetViewWindow(myViewWindow);
1018 vtkRenderer* Renderer = vf->getRenderer();
1019 vtkActorCollection* theActors = Renderer->GetActors();
1020 theActors->InitTraversal();
1021 while (vtkActor *anAct = theActors->GetNextActor()) {
1022 if (VISU_Actor* anActor = dynamic_cast<VISU_Actor*>(anAct)) {
1023 VISU::Prs3d_i* aPrs3d = anActor->GetPrs3d();
1024 if (anActor->GetVisibility() && aPrs3d) {
1026 aPrs3d->UpdateActor(anActor);
1030 RepaintView(myViewWindow);
1033 ProcessVoidEvent(new TEvent(myViewWindow));
1036 CORBA::Boolean View3D_i::SavePicture (const char* theFileName)
1038 //jfa tmp:return ProcessEvent(new TSavePictureEvent(myView->getViewWidget(), theFileName));
1042 bool View3D_i::SaveViewParams (SUIT_ViewManager* theViewManager, const char* theName)
1044 _PTR(Study) aCStudy;
1045 if (SUIT_Study* aSStudy = theViewManager->study()) {
1046 if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
1047 aCStudy = aStudy->studyDS();
1054 std::vector<_PTR(SObject)> aList = aCStudy->FindObjectByName(theName, "VISU");
1055 _PTR(GenericAttribute) anAttr;
1056 int iEnd = aList.size();
1057 for (int i = 0; i < iEnd; i++) {
1058 _PTR(SObject) anObj = aList[i];
1059 string anEntry = anObj->GetID();
1060 if(MYDEBUG) MESSAGE("View3D_i::SaveViewParams - anEntry = " << anEntry);
1061 if (anObj->FindAttribute(anAttr, "AttributeComment")) {
1062 _PTR(AttributeComment) aCmnt (anAttr);
1063 string aComm (aCmnt->Value());
1064 if (MYDEBUG) MESSAGE("View3D_i::SaveViewPoint - aComm = " << aComm);
1065 if (aComm.compare(View3D_i::myComment) >= 0) {
1066 aCmnt->SetValue(ToString(theViewManager->getActiveView()).c_str());
1072 _PTR(SComponent) aSComponent = ClientFindOrCreateVisuComponent(aCStudy);
1073 string aSComponentEntry = aSComponent->GetID();
1074 string anEntry = CreateAttributes(aCStudy, aSComponentEntry.c_str(), "", "", theName, "",
1075 ToString(theViewManager->getActiveView()).c_str());
1079 CORBA::Boolean View3D_i::SaveViewParams (const char* theName)
1081 return SaveViewParams(myViewManager, theName);
1084 bool View3D_i::RestoreViewParams (SUIT_ViewManager* theViewManager, const char* theName)
1086 _PTR(Study) aCStudy;
1087 if (SUIT_Study* aSStudy = theViewManager->study()) {
1088 if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
1089 aCStudy = aStudy->studyDS();
1095 std::vector<_PTR(SObject)> aList = aCStudy->FindObjectByName(theName, "VISU");
1096 _PTR(GenericAttribute) anAttr;
1097 int iEnd = aList.size();
1098 if (MYDEBUG) MESSAGE("View3D_i::RestoreViewPoint - iEnd = " << iEnd);
1099 for (int i = 0; i < iEnd; i++) {
1100 _PTR(SObject) anObj = aList[i];
1101 string anEntry = anObj->GetID();
1102 if (MYDEBUG) MESSAGE("View3D_i::RestoreViewPoint - anEntry = " << anEntry);
1103 if (anObj->FindAttribute(anAttr, "AttributeComment")) {
1104 _PTR(AttributeComment) aCmnt (anAttr);
1105 QString strIn(aCmnt->Value().c_str());
1106 Storable::TRestoringMap aMap;
1107 Storable::StrToMap(strIn, aMap);
1108 if (Storable::FindValue(aMap, "myComment").compare
1109 (View3D_i::myComment.c_str()) >= 0) {
1110 if (MYDEBUG) MESSAGE("View3D_i::RestoreViewPoint - aComm = " << strIn);
1111 Restore(theViewManager->getActiveView(), aMap);
1119 class TRestoreViewParamsEvent: public SALOME_Event
1121 SUIT_ViewManager* myViewManager;
1124 TRestoreViewParamsEvent (SUIT_ViewManager* theViewManager,
1125 const char* theName):
1126 myViewManager(theViewManager),
1130 virtual void Execute()
1132 myResult = View3D_i::RestoreViewParams(myViewManager, myName);
1134 typedef CORBA::Boolean TResult;
1138 CORBA::Boolean View3D_i::RestoreViewParams (const char* theName)
1140 return ProcessEvent(new TRestoreViewParamsEvent (myViewManager, theName));
1143 void View3D_i::Restore (SUIT_ViewWindow* theStudyFrame,
1144 const Storable::TRestoringMap& theMap)
1146 SALOMEDS::Color aColor;
1147 aColor.R = VISU::Storable::FindValue(theMap,"myColor.R").toDouble();
1148 aColor.G = VISU::Storable::FindValue(theMap,"myColor.G").toDouble();
1149 aColor.B = VISU::Storable::FindValue(theMap,"myColor.B").toDouble();
1151 double aPosition[3];
1152 aPosition[0] = VISU::Storable::FindValue(theMap,"myPosition[0]").toDouble();
1153 aPosition[1] = VISU::Storable::FindValue(theMap,"myPosition[1]").toDouble();
1154 aPosition[2] = VISU::Storable::FindValue(theMap,"myPosition[2]").toDouble();
1156 double aFocalPnt[3];
1157 aFocalPnt[0] = VISU::Storable::FindValue(theMap,"myFocalPnt[0]").toDouble();
1158 aFocalPnt[1] = VISU::Storable::FindValue(theMap,"myFocalPnt[1]").toDouble();
1159 aFocalPnt[2] = VISU::Storable::FindValue(theMap,"myFocalPnt[2]").toDouble();
1162 aViewUp[0] = VISU::Storable::FindValue(theMap,"myViewUp[0]").toDouble();
1163 aViewUp[1] = VISU::Storable::FindValue(theMap,"myViewUp[1]").toDouble();
1164 aViewUp[2] = VISU::Storable::FindValue(theMap,"myViewUp[2]").toDouble();
1166 double aParallelScale = VISU::Storable::FindValue(theMap,"myParallelScale").toDouble();
1168 double aScaleFactor[3];
1169 aScaleFactor[0] = VISU::Storable::FindValue(theMap,"myScaleFactor[0]").toDouble();
1170 aScaleFactor[1] = VISU::Storable::FindValue(theMap,"myScaleFactor[1]").toDouble();
1171 aScaleFactor[2] = VISU::Storable::FindValue(theMap,"myScaleFactor[2]").toDouble();
1173 SetBackground(theStudyFrame,aColor);
1174 SetPointOfView(theStudyFrame,aPosition);
1175 SetViewUp(theStudyFrame,aViewUp);
1176 SetFocalPoint(theStudyFrame,aFocalPnt);
1177 SetParallelScale(theStudyFrame,aParallelScale);
1178 ScaleView(theStudyFrame,VISU::View3D::XAxis,aScaleFactor[0]);
1179 ScaleView(theStudyFrame,VISU::View3D::YAxis,aScaleFactor[1]);
1180 ScaleView(theStudyFrame,VISU::View3D::ZAxis,aScaleFactor[2]);
1184 string View3D_i::ToString (SUIT_ViewWindow* theStudyFrame)
1186 ostringstream strOut;
1187 Storable::DataToStream( strOut, "myComment", myComment.c_str() );
1188 ToStream(theStudyFrame,strOut);
1190 if(MYDEBUG) MESSAGE("View3D_i::ToString - "<<strOut.str());
1191 return strOut.str();
1194 void View3D_i::ToStream (SUIT_ViewWindow* theStudyFrame, std::ostringstream& theStr)
1196 Storable::DataToStream(theStr,"myType",VISU::TVIEW3D);
1199 GetRenderer(theStudyFrame)->GetBackground(backint);
1200 Storable::DataToStream(theStr,"myColor.R",backint[0]);
1201 Storable::DataToStream(theStr,"myColor.G",backint[1]);
1202 Storable::DataToStream(theStr,"myColor.B",backint[2]);
1204 double aPosition[3];
1205 GetPointOfView(theStudyFrame,aPosition);
1206 Storable::DataToStream(theStr,"myPosition[0]",aPosition[0]);
1207 Storable::DataToStream(theStr,"myPosition[1]",aPosition[1]);
1208 Storable::DataToStream(theStr,"myPosition[2]",aPosition[2]);
1210 double aFocalPnt[3];
1211 GetFocalPoint(theStudyFrame,aFocalPnt);
1212 Storable::DataToStream(theStr,"myFocalPnt[0]",aFocalPnt[0]);
1213 Storable::DataToStream(theStr,"myFocalPnt[1]",aFocalPnt[1]);
1214 Storable::DataToStream(theStr,"myFocalPnt[2]",aFocalPnt[2]);
1217 GetCamera(theStudyFrame)->GetViewUp(aViewUp);
1218 Storable::DataToStream(theStr,"myViewUp[0]",aViewUp[0]);
1219 Storable::DataToStream(theStr,"myViewUp[1]",aViewUp[1]);
1220 Storable::DataToStream(theStr,"myViewUp[2]",aViewUp[2]);
1222 Storable::DataToStream(theStr,"myParallelScale",GetParallelScale(theStudyFrame));
1224 double aScaleFactor[3];
1225 GetViewWindow(theStudyFrame)->GetScale(aScaleFactor);
1226 Storable::DataToStream(theStr,"myScaleFactor[0]",aScaleFactor[0]);
1227 Storable::DataToStream(theStr,"myScaleFactor[1]",aScaleFactor[1]);
1228 Storable::DataToStream(theStr,"myScaleFactor[2]",aScaleFactor[2]);
1231 void View3D_i::ToStream(std::ostringstream& theStr)
1233 ToStream(myViewWindow,theStr);
1236 void View3D_i::Close()
1238 myViewWindow->close();
1241 View3D_i::~View3D_i()
1243 if(MYDEBUG) MESSAGE("View3D_i::~View3D_i");
1246 void View3D_i::SetTitle (const char* theTitle)
1248 ProcessVoidEvent(new TVoidMemFun1ArgEvent<SUIT_ViewWindow,const QString&,QString>
1249 (myViewWindow,&SUIT_ViewWindow::setCaption,QString(theTitle)));
1252 char* View3D_i::GetTitle()
1254 return CORBA::string_dup(myViewWindow->caption().latin1());
1257 void View3D_i::SetBackground (SUIT_ViewWindow* theStudyFrame,
1258 const SALOMEDS::Color& theColor)
1261 aColor[0] = int(255.0*theColor.R);
1262 aColor[1] = int(255.0*theColor.G);
1263 aColor[2] = int(255.0*theColor.B);
1264 QColor aNewColor(aColor[0],aColor[1],aColor[2]);
1265 GetViewWindow(theStudyFrame)->setBackgroundColor(aNewColor);
1268 SALOMEDS::Color View3D_i::GetBackground (SUIT_ViewWindow* theStudyFrame)
1270 SALOMEDS::Color aColor;
1272 GetRenderer(theStudyFrame)->GetBackground(backint);
1273 aColor.R = backint[0]; aColor.G = backint[1]; aColor.B = backint[2];
1277 class TUpdateViewerEvent: public SALOME_Event
1279 SUIT_ViewWindow* myViewWindow;
1283 TUpdateViewerEvent(SUIT_ViewWindow* theStudyFrame,
1286 myViewWindow(theStudyFrame),
1288 myDisplaing(theDisplaing)
1290 virtual void Execute(){
1291 UpdateViewer(myViewWindow,myDisplaing,myPrs3d);
1295 void View3D_i::EraseAll()
1297 if(MYDEBUG) MESSAGE("View3D_i::EraseAll");
1298 ProcessVoidEvent(new TUpdateViewerEvent(myViewWindow,NULL,eEraseAll));
1301 void View3D_i::DisplayAll()
1303 if(MYDEBUG) MESSAGE("View3D_i::DisplayAll");
1304 ProcessVoidEvent(new TUpdateViewerEvent(myViewWindow,NULL,eDisplayAll));
1307 void View3D_i::Erase (PrsObject_ptr thePrsObj)
1309 if(MYDEBUG) MESSAGE("View3D_i::Erase");
1310 CORBA::Object_ptr anObj = thePrsObj;
1311 if(Prs3d_i* aPrs = dynamic_cast<Prs3d_i*>(VISU::GetServant(anObj).in())){
1312 ProcessVoidEvent(new TUpdateViewerEvent(myViewWindow,aPrs,eErase));
1316 void View3D_i::Display (PrsObject_ptr thePrsObj)
1318 if(MYDEBUG) MESSAGE("View3D_i::Display");
1319 CORBA::Object_ptr anObj = thePrsObj;
1320 if(Prs3d_i* aPrs = dynamic_cast<Prs3d_i*>(VISU::GetServant(anObj).in())){
1321 ProcessVoidEvent(new TUpdateViewerEvent(myViewWindow,aPrs,eDisplay));
1325 void View3D_i::DisplayOnly (PrsObject_ptr thePrsObj)
1327 if(MYDEBUG) MESSAGE("View3D_i::DisplayOnly");
1328 CORBA::Object_ptr anObj = thePrsObj;
1329 if(Prs3d_i* aPrs = dynamic_cast<Prs3d_i*>(VISU::GetServant(anObj).in())){
1330 ProcessVoidEvent(new TUpdateViewerEvent(myViewWindow,aPrs,eDisplayOnly));
1334 void View3D_i::FitAll()
1336 ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>
1337 (GetViewWindow(myViewWindow), &SVTK_ViewWindow::onFitAll));
1341 void View3D_i::SetView (VISU::View3D::ViewType theType)
1344 case VISU::View3D::FRONT :
1345 ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>
1346 (GetViewWindow(myViewWindow), &SVTK_ViewWindow::onFrontView));
1348 case VISU::View3D::BACK :
1349 ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>
1350 (GetViewWindow(myViewWindow), &SVTK_ViewWindow::onBackView));
1352 case VISU::View3D::LEFT :
1353 ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>
1354 (GetViewWindow(myViewWindow),&SVTK_ViewWindow::onLeftView));
1356 case VISU::View3D::RIGHT :
1357 ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>
1358 (GetViewWindow(myViewWindow),&SVTK_ViewWindow::onRightView));
1360 case VISU::View3D::TOP :
1361 ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>
1362 (GetViewWindow(myViewWindow),&SVTK_ViewWindow::onTopView));
1364 case VISU::View3D::BOTTOM :
1365 ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>
1366 (GetViewWindow(myViewWindow),&SVTK_ViewWindow::onBottomView));
1372 class TSet3DViewParamEvent: public SALOME_Event
1375 typedef void (*TFun)(SUIT_ViewWindow* theStudyFrame, const CORBA::Double theParam[3]);
1376 TSet3DViewParamEvent (TFun theFun,
1377 SUIT_ViewWindow* theStudyFrame,
1378 const CORBA::Double theParam[3]):
1380 myViewWindow(theStudyFrame),
1383 virtual void Execute(){
1384 myFun(myViewWindow,myParam);
1388 SUIT_ViewWindow* myViewWindow;
1389 const CORBA::Double* myParam;
1392 void View3D_i::SetPointOfView (SUIT_ViewWindow* theStudyFrame,
1393 const CORBA::Double thePosition[3])
1395 GetCamera(theStudyFrame)->SetPosition(thePosition);
1398 void View3D_i::SetPointOfView (const VISU::View3D::XYZ thePosition)
1400 if(MYDEBUG) MESSAGE("View3D_i::SetPointOfView");
1401 ProcessVoidEvent(new TSet3DViewParamEvent(&SetPointOfView,myViewWindow,thePosition));
1404 void View3D_i::GetPointOfView (SUIT_ViewWindow* theStudyFrame,
1405 CORBA::Double thePosition[3])
1407 GetCamera(theStudyFrame)->GetPosition(thePosition);
1410 VISU::View3D::XYZ_slice* View3D_i::GetPointOfView()
1412 if(MYDEBUG) MESSAGE("View3D_i::GetPointOfView");
1413 CORBA::Double aPosition[3];
1414 GetPointOfView(myViewWindow,aPosition);
1415 return VISU::View3D::XYZ_dup(aPosition);
1418 void View3D_i::SetViewUp (SUIT_ViewWindow* theStudyFrame,
1419 const CORBA::Double theViewUp[3])
1421 GetCamera(theStudyFrame)->SetViewUp(theViewUp);
1424 void View3D_i::SetViewUp (const VISU::View3D::XYZ theViewUp)
1426 if(MYDEBUG) MESSAGE("View3D_i::SetViewUp");
1427 ProcessVoidEvent(new TSet3DViewParamEvent(&SetViewUp,myViewWindow,theViewUp));
1430 void View3D_i::GetViewUp (SUIT_ViewWindow* theStudyFrame,
1431 CORBA::Double theViewUp[3])
1433 GetCamera(theStudyFrame)->GetViewUp(theViewUp);
1436 VISU::View3D::XYZ_slice* View3D_i::GetViewUp()
1438 if(MYDEBUG) MESSAGE("View3D_i::GetViewUp");
1439 CORBA::Double aViewUp[3];
1440 GetCamera(myViewWindow)->GetViewUp(aViewUp);
1441 return VISU::View3D::XYZ_dup(aViewUp);
1444 void View3D_i::SetFocalPoint (SUIT_ViewWindow* theStudyFrame,
1445 const CORBA::Double theFocalPnt[3])
1447 GetCamera(theStudyFrame)->SetFocalPoint(theFocalPnt);
1450 void View3D_i::SetFocalPoint (const VISU::View3D::XYZ theCoord)
1452 if(MYDEBUG) MESSAGE("View3D_i::SetFocalPoint");
1453 ProcessVoidEvent(new TSet3DViewParamEvent(&SetFocalPoint,myViewWindow,theCoord));
1457 void View3D_i::GetFocalPoint (SUIT_ViewWindow* theStudyFrame,
1458 CORBA::Double theFocalPnt[3])
1460 GetCamera(theStudyFrame)->GetFocalPoint(theFocalPnt);
1463 VISU::View3D::XYZ_slice* View3D_i::GetFocalPoint()
1465 if(MYDEBUG) MESSAGE("View3D_i::GetFocalPoint");
1466 CORBA::Double aFocalPnt[3];
1467 GetFocalPoint(myViewWindow,aFocalPnt);
1468 return VISU::View3D::XYZ_dup(aFocalPnt);
1471 class TSetViewParamEvent: public SALOME_Event
1474 typedef void (*TFun)(SUIT_ViewWindow* theStudyFrame, CORBA::Double theParam);
1475 TSetViewParamEvent (TFun theFun,
1476 SUIT_ViewWindow* theStudyFrame,
1477 CORBA::Double theParam):
1479 myViewWindow(theStudyFrame),
1482 virtual void Execute()
1484 myFun(myViewWindow,myParam);
1488 SUIT_ViewWindow* myViewWindow;
1489 CORBA::Double myParam;
1492 void View3D_i::SetParallelScale (SUIT_ViewWindow* theStudyFrame,
1493 CORBA::Double theScale)
1495 GetCamera(theStudyFrame)->SetParallelScale(theScale);
1498 void View3D_i::SetParallelScale (CORBA::Double theScale)
1500 if(MYDEBUG) MESSAGE("View3D_i::SetParallelScale");
1501 ProcessVoidEvent(new TSetViewParamEvent(&SetParallelScale,myViewWindow,theScale));
1504 CORBA::Double View3D_i::GetParallelScale (SUIT_ViewWindow* theStudyFrame)
1506 return GetCamera(theStudyFrame)->GetParallelScale();
1509 CORBA::Double View3D_i::GetParallelScale()
1511 if(MYDEBUG) MESSAGE("View3D_i::GetParallelScale");
1512 return GetParallelScale(myViewWindow);
1515 void View3D_i::ScaleView (SUIT_ViewWindow* theStudyFrame,
1516 VISU::View3D::Axis theAxis, CORBA::Double theParam)
1518 SVTK_ViewWindow* aViewFrame = GetViewWindow(theStudyFrame);
1519 double aScaleFactor[3];
1520 aViewFrame->GetScale(aScaleFactor);
1521 aScaleFactor[theAxis] = theParam;
1522 aViewFrame->SetScale(aScaleFactor);
1525 void SetScaleView (SUIT_ViewWindow* theStudyFrame, const CORBA::Double theScale[3])
1527 double aScale[3] = {theScale[0], theScale[1], theScale[2]};
1528 GetViewWindow(theStudyFrame)->SetScale(aScale);
1531 void View3D_i::ScaleView(VISU::View3D::Axis theAxis, CORBA::Double theParam)
1533 if(MYDEBUG) MESSAGE("View3D_i::ScaleView");
1535 GetViewWindow(myViewWindow)->GetScale(aScale);
1536 aScale[theAxis] = theParam;
1537 ProcessVoidEvent(new TSet3DViewParamEvent(&SetScaleView,myViewWindow,aScale));
1540 void View3D_i::RemoveScale()
1542 if(MYDEBUG) MESSAGE("View3D_i::RemoveScale");
1543 double aScale[3] = {1.0, 1.0, 1.0};
1544 ProcessVoidEvent(new TSet3DViewParamEvent(&SetScaleView,myViewWindow,aScale));