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, theApplication->getViewManager(Plot2d_Viewer::Type(), true))
613 if (MYDEBUG) MESSAGE("XYPlot_i::XYPlot_i");
616 Storable* XYPlot_i::Create (int theNew)
619 myViewWindow = myViewManager->createViewWindow();
621 myViewWindow = myViewManager->getActiveView();
623 ////myView = dynamic_cast<Plot2d_ViewFrame*>(myViewWindow->getRightFrame()->getViewFrame());
624 //SPlot2d_Viewer* aView = dynamic_cast<SPlot2d_Viewer*>(myViewManager->getViewModel());
625 //myView = aView->getActiveViewFrame();
627 Plot2d_ViewWindow* aPlot2dVW = dynamic_cast<Plot2d_ViewWindow*>(myViewWindow);
629 myView = aPlot2dVW->getViewFrame();
638 void XYPlot_i::Update()
640 ProcessVoidEvent(new TVoidMemFunEvent<Plot2d_ViewFrame>(myView,&Plot2d_ViewFrame::Repaint));
643 void XYPlot_i::Close()
645 myViewWindow->close();
648 XYPlot_i::~XYPlot_i() {
649 if(MYDEBUG) MESSAGE("XYPlot_i::~XYPlot_i");
652 void XYPlot_i::SetTitle (const char* theTitle)
654 ProcessVoidEvent(new TVoidMemFun1ArgEvent<SUIT_ViewWindow,const QString&,QString>
655 (myViewWindow, &SUIT_ViewWindow::setCaption, QString(theTitle)));
657 char* XYPlot_i::GetTitle()
659 return CORBA::string_dup(myViewWindow->caption().latin1());
662 void XYPlot_i::SetSubTitle (const char* theTitle)
664 ProcessVoidEvent(new TVoidMemFun1ArgEvent<Plot2d_ViewFrame,const QString&,QString>
665 (myView, &Plot2d_ViewFrame::setTitle, QString(theTitle)));
668 char* XYPlot_i::GetSubTitle()
670 return CORBA::string_dup(myView->getTitle());
673 void XYPlot_i::SetCurveType (VISU::XYPlot::CurveType theType)
675 ProcessVoidEvent(new TVoidMemFun2ArgEvent<Plot2d_ViewFrame,int,bool>
676 (myView,&Plot2d_ViewFrame::setCurveType,theType,true));
679 VISU::XYPlot::CurveType XYPlot_i::GetCurveType()
681 return (VISU::XYPlot::CurveType)myView->getCurveType();
684 void XYPlot_i::SetMarkerSize (CORBA::Long theSize)
686 ProcessVoidEvent(new TVoidMemFun2ArgEvent<Plot2d_ViewFrame,int,bool>
687 (myView,&Plot2d_ViewFrame::setMarkerSize,theSize,true));
690 CORBA::Long XYPlot_i::GetMarkerSize()
692 return myView->getMarkerSize();
695 class TEnableGridEvent: public SALOME_Event
698 typedef void (Plot2d_ViewFrame::* TFun)(bool, const int, bool, const int, bool);
699 TEnableGridEvent (Plot2d_ViewFrame* theView, TFun theFun,
700 CORBA::Boolean theMajor, CORBA::Long theNumMajor,
701 CORBA::Boolean theMinor, CORBA::Long theNumMinor):
702 myView(theView), myFun(theFun),
703 myMajor(theMajor), myNumMajor(theNumMajor),
704 myMinor(theMinor), myNumMinor(theNumMinor)
707 virtual void Execute()
709 (myView->*myFun)(myMajor,myNumMajor,myMinor,myNumMinor,true);
712 Plot2d_ViewFrame* myView;
714 CORBA::Boolean myMajor, myNumMajor;
715 CORBA::Boolean myMinor, myNumMinor;
718 void XYPlot_i::EnableXGrid (CORBA::Boolean theMajor, CORBA::Long theNumMajor,
719 CORBA::Boolean theMinor, CORBA::Long theNumMinor)
721 ProcessVoidEvent(new TEnableGridEvent(myView,&Plot2d_ViewFrame::setXGrid,
722 theMajor,theNumMajor,theMinor,theNumMinor));
724 void XYPlot_i::EnableYGrid(CORBA::Boolean theMajor, CORBA::Long theNumMajor,
725 CORBA::Boolean theMinor, CORBA::Long theNumMinor)
727 //jfa tmp:ProcessVoidEvent(new TEnableGridEvent(myView,&Plot2d_ViewFrame::setYGrid,
728 //jfa tmp: theMajor,theNumMajor,theMinor,theNumMinor));
731 class TSetScaleModeEvent: public SALOME_Event
734 typedef void (Plot2d_ViewFrame::* TFun)(const int, bool);
735 TSetScaleModeEvent (Plot2d_ViewFrame* theView, TFun theFun, int theScaling):
736 myView(theView), myFun(theFun), myScaling(theScaling)
739 virtual void Execute()
741 (myView->*myFun)(myScaling,true);
744 Plot2d_ViewFrame* myView;
749 void XYPlot_i::SetHorScaling (VISU::Scaling theScaling)
751 ProcessVoidEvent(new TSetScaleModeEvent(myView,&Plot2d_ViewFrame::setHorScaleMode,
752 theScaling == VISU::LOGARITHMIC));
755 VISU::Scaling XYPlot_i::GetHorScaling()
757 return (VISU::Scaling)myView->getHorScaleMode();
760 void XYPlot_i::SetVerScaling(VISU::Scaling theScaling)
762 ProcessVoidEvent(new TSetScaleModeEvent(myView,&Plot2d_ViewFrame::setVerScaleMode,
763 theScaling == VISU::LOGARITHMIC));
766 VISU::Scaling XYPlot_i::GetVerScaling()
768 return (VISU::Scaling)myView->getVerScaleMode();
771 class TSetTitleEvent: public SALOME_Event
774 //typedef void (Plot2d_ViewFrame::* TFun)(bool, const QString&, bool = true);
775 typedef void (Plot2d_ViewFrame::* TFun)(bool, const QString&, Plot2d_ViewFrame::ObjectType, bool = true);
776 //TSetTitleEvent (Plot2d_ViewFrame* theView, TFun theFun, const char* theTitle):
777 TSetTitleEvent (Plot2d_ViewFrame* theView, Plot2d_ViewFrame::ObjectType theType, const char* theTitle):
778 //myView(theView), myFun(theFun), myTitle(theTitle)
779 myView(theView), myType(theType), myTitle(theTitle)
781 virtual void Execute()
783 //(myView->*myFun)(true,myTitle,myType);
784 myView->setTitle(true,myTitle,myType);
787 Plot2d_ViewFrame* myView;
789 Plot2d_ViewFrame::ObjectType myType;
793 void XYPlot_i::SetXTitle (const char* theTitle)
795 //ProcessVoidEvent(new TSetTitleEvent(myView, &Plot2d_ViewFrame::setXTitle, theTitle));
796 ProcessVoidEvent(new TSetTitleEvent(myView, Plot2d_ViewFrame::XTitle, theTitle));
798 char* XYPlot_i::GetXTitle()
800 //return CORBA::string_dup(myView->getXTitle());
801 return CORBA::string_dup(myView->getTitle(Plot2d_ViewFrame::XTitle));
804 void XYPlot_i::SetYTitle (const char* theTitle)
806 //ProcessVoidEvent(new TSetTitleEvent(myView, &Plot2d_ViewFrame::setYTitle, theTitle));
807 ProcessVoidEvent(new TSetTitleEvent(myView, Plot2d_ViewFrame::YTitle, theTitle));
809 char* XYPlot_i::GetYTitle()
811 //return CORBA::string_dup(myView->getYTitle());
812 return CORBA::string_dup(myView->getTitle(Plot2d_ViewFrame::YTitle));
815 void XYPlot_i::ShowLegend (CORBA::Boolean theShowing)
817 ProcessVoidEvent(new TVoidMemFun2ArgEvent<Plot2d_ViewFrame,bool,bool>
818 (myView,&Plot2d_ViewFrame::showLegend,theShowing,true));
821 class TXYPlotViewEvent: public SALOME_Event
823 SalomeApp_Application* myApplication;
824 Plot2d_ViewFrame* myView;
825 PrsObject_ptr myPrsObj;
829 TXYPlotViewEvent(SalomeApp_Application* theApplication,
830 Plot2d_ViewFrame* theView,
831 PrsObject_ptr thePrsObj,
833 : myApplication(theApplication),
836 myDisplaing(theDisplaing)
840 virtual void Execute()
843 if (Curve_i* aCurve = dynamic_cast<Curve_i*>(VISU::GetServant(myPrsObj).in())) {
844 UpdatePlot2d(myView,myDisplaing,aCurve);
847 if (Container_i* aContainer = dynamic_cast<Container_i*>(VISU::GetServant(myPrsObj).in())) {
848 int nbCurves = aContainer->GetNbCurves();
849 for ( int i = 1; i <= nbCurves; i++ ) {
850 VISU::Curve_i* aCurve = aContainer->GetCurve( i );
851 if ( aCurve && aCurve->IsValid() ) {
852 UpdatePlot2d(myView,myDisplaing,aCurve);
858 if (Table_i* aTable = dynamic_cast<Table_i*>(VISU::GetServant(myPrsObj).in())) {
860 if (SUIT_Study* aSStudy = myApplication->activeStudy()) {
861 if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
862 aCStudy = aStudy->studyDS();
865 if (!aCStudy) return;
866 _PTR(SObject) TableSO = aCStudy->FindObjectID(aTable->GetEntry().latin1());
868 _PTR(ChildIterator) Iter = aCStudy->NewChildIterator(TableSO);
869 for (; Iter->More(); Iter->Next()) {
870 CORBA::Object_var childObject = VISU::ClientSObjectToObject(Iter->Value());
871 if (!CORBA::is_nil(childObject)) {
872 CORBA::Object_ptr aCurve = VISU::Curve::_narrow(childObject);
873 if (!CORBA::is_nil(aCurve))
874 UpdatePlot2d(myView, myDisplaing,
875 dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aCurve).in()));
884 void XYPlot_i::Display (PrsObject_ptr thePrsObj)
886 ProcessVoidEvent(new TXYPlotViewEvent (myApplication,myView,thePrsObj,eDisplay));
889 void XYPlot_i::Erase (PrsObject_ptr thePrsObj)
891 ProcessVoidEvent(new TXYPlotViewEvent (myApplication,myView,thePrsObj,eErase));
894 void XYPlot_i::DisplayOnly (PrsObject_ptr thePrsObj)
896 ProcessVoidEvent(new TXYPlotViewEvent (myApplication,myView,thePrsObj,eDisplayOnly));
899 void XYPlot_i::EraseAll()
901 ProcessVoidEvent(new TVoidMemFunEvent<Plot2d_ViewFrame> (myView,&Plot2d_ViewFrame::EraseAll));
904 void XYPlot_i::FitAll()
906 ProcessVoidEvent(new TVoidMemFunEvent<Plot2d_ViewFrame> (myView,&Plot2d_ViewFrame::fitAll));
909 CORBA::Boolean XYPlot_i::SavePicture (const char* theFileName)
911 return ProcessEvent(new TSavePictureEvent (myView->getViewWidget(),theFileName));
915 //===========================================================================
916 TableView_i::TableView_i (SalomeApp_Application* theApplication)
917 : View_i(theApplication, NULL)
921 Storable* TableView_i::Create (VISU::Table_ptr theTable)
923 if (MYDEBUG) MESSAGE("TableView_i::Create - " << (!theTable->_is_nil()));
924 if (!theTable->_is_nil()) {
925 VISU::Table_i* table = dynamic_cast<VISU::Table_i*>(VISU::GetServant(theTable).in());
926 if (MYDEBUG) MESSAGE("TableView_i::Create - dynamic_cast = " << table);
928 if (SUIT_Study* aSStudy = myApplication->activeStudy()) {
929 if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
930 if (_PTR(Study) aCStudy = aStudy->studyDS()) {
931 _PTR(SObject) aSObject = aCStudy->FindObjectID(table->GetObjectEntry());
933 myView = new VisuGUI_TableDlg (myApplication->desktop(),
936 VisuGUI_TableDlg::ttAuto,
949 TableView_i::~TableView_i()
951 if(MYDEBUG) MESSAGE("TableView_i::~TableView_i");
955 void TableView_i::SetTitle (const char* theTitle)
957 ProcessVoidEvent(new TVoidMemFun1ArgEvent<VisuGUI_TableDlg,const QString&,QString>
958 (myView, &VisuGUI_TableDlg::setCaption, QString(theTitle)));
961 char* TableView_i::GetTitle()
963 return CORBA::string_dup(myView->caption().latin1());
967 void TableView_i::Close()
973 //===========================================================================
974 int View3D_i::myNbViewParams = 0;
975 const string View3D_i::myComment = "VIEW3D";
976 const char* View3D_i::GetComment() const { return myComment.c_str();}
978 QString View3D_i::GenerateViewParamsName()
980 return VISU::GenerateName("ViewParams", ++myNbViewParams);
983 View3D_i::View3D_i (SalomeApp_Application* theApplication)
984 : View_i(theApplication, theApplication->getViewManager(SVTK_Viewer::Type(), true))
986 if (MYDEBUG) MESSAGE("View3D_i::View3D_i");
989 Storable* View3D_i::Create (int theNew)
991 if (MYDEBUG) MESSAGE("View3D_i::Create");
993 myViewWindow = myViewManager->createViewWindow();
995 myViewWindow = myViewManager->getActiveView();
1000 void View3D_i::Update()
1002 class TEvent: public SALOME_Event
1004 SUIT_ViewWindow* myViewWindow;
1006 TEvent(SUIT_ViewWindow* theStudyFrame):
1007 myViewWindow(theStudyFrame)
1009 virtual void Execute()
1011 SVTK_ViewWindow* vf = GetViewWindow(myViewWindow);
1012 vtkRenderer* Renderer = vf->getRenderer();
1013 vtkActorCollection* theActors = Renderer->GetActors();
1014 theActors->InitTraversal();
1015 while (vtkActor *anAct = theActors->GetNextActor()) {
1016 if (VISU_Actor* anActor = dynamic_cast<VISU_Actor*>(anAct)) {
1017 VISU::Prs3d_i* aPrs3d = anActor->GetPrs3d();
1018 if (anActor->GetVisibility() && aPrs3d) {
1020 aPrs3d->UpdateActor(anActor);
1024 RepaintView(myViewWindow);
1027 ProcessVoidEvent(new TEvent(myViewWindow));
1030 CORBA::Boolean View3D_i::SavePicture (const char* theFileName)
1032 //jfa tmp:return ProcessEvent(new TSavePictureEvent(myView->getViewWidget(), theFileName));
1036 bool View3D_i::SaveViewParams (SUIT_ViewManager* theViewManager, const char* theName)
1038 _PTR(Study) aCStudy;
1039 if (SUIT_Study* aSStudy = theViewManager->study()) {
1040 if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
1041 aCStudy = aStudy->studyDS();
1048 std::vector<_PTR(SObject)> aList = aCStudy->FindObjectByName(theName, "VISU");
1049 _PTR(GenericAttribute) anAttr;
1050 int iEnd = aList.size();
1051 for (int i = 0; i < iEnd; i++) {
1052 _PTR(SObject) anObj = aList[i];
1053 string anEntry = anObj->GetID();
1054 if(MYDEBUG) MESSAGE("View3D_i::SaveViewParams - anEntry = " << anEntry);
1055 if (anObj->FindAttribute(anAttr, "AttributeComment")) {
1056 _PTR(AttributeComment) aCmnt (anAttr);
1057 string aComm (aCmnt->Value());
1058 if (MYDEBUG) MESSAGE("View3D_i::SaveViewPoint - aComm = " << aComm);
1059 if (aComm.compare(View3D_i::myComment) >= 0) {
1060 aCmnt->SetValue(ToString(theViewManager->getActiveView()).c_str());
1066 _PTR(SComponent) aSComponent = ClientFindOrCreateVisuComponent(aCStudy);
1067 string aSComponentEntry = aSComponent->GetID();
1068 string anEntry = CreateAttributes(aCStudy, aSComponentEntry.c_str(), "", "", theName, "",
1069 ToString(theViewManager->getActiveView()).c_str());
1073 CORBA::Boolean View3D_i::SaveViewParams (const char* theName)
1075 return SaveViewParams(myViewManager, theName);
1078 bool View3D_i::RestoreViewParams (SUIT_ViewManager* theViewManager, const char* theName)
1080 _PTR(Study) aCStudy;
1081 if (SUIT_Study* aSStudy = theViewManager->study()) {
1082 if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
1083 aCStudy = aStudy->studyDS();
1089 std::vector<_PTR(SObject)> aList = aCStudy->FindObjectByName(theName, "VISU");
1090 _PTR(GenericAttribute) anAttr;
1091 int iEnd = aList.size();
1092 if (MYDEBUG) MESSAGE("View3D_i::RestoreViewPoint - iEnd = " << iEnd);
1093 for (int i = 0; i < iEnd; i++) {
1094 _PTR(SObject) anObj = aList[i];
1095 string anEntry = anObj->GetID();
1096 if (MYDEBUG) MESSAGE("View3D_i::RestoreViewPoint - anEntry = " << anEntry);
1097 if (anObj->FindAttribute(anAttr, "AttributeComment")) {
1098 _PTR(AttributeComment) aCmnt (anAttr);
1099 QString strIn(aCmnt->Value().c_str());
1100 Storable::TRestoringMap aMap;
1101 Storable::StrToMap(strIn, aMap);
1102 if (Storable::FindValue(aMap, "myComment").compare
1103 (View3D_i::myComment.c_str()) >= 0) {
1104 if (MYDEBUG) MESSAGE("View3D_i::RestoreViewPoint - aComm = " << strIn);
1105 Restore(theViewManager->getActiveView(), aMap);
1113 class TRestoreViewParamsEvent: public SALOME_Event
1115 SUIT_ViewManager* myViewManager;
1118 TRestoreViewParamsEvent (SUIT_ViewManager* theViewManager,
1119 const char* theName):
1120 myViewManager(theViewManager),
1124 virtual void Execute()
1126 myResult = View3D_i::RestoreViewParams(myViewManager, myName);
1128 typedef CORBA::Boolean TResult;
1132 CORBA::Boolean View3D_i::RestoreViewParams (const char* theName)
1134 return ProcessEvent(new TRestoreViewParamsEvent (myViewManager, theName));
1137 void View3D_i::Restore (SUIT_ViewWindow* theStudyFrame,
1138 const Storable::TRestoringMap& theMap)
1140 SALOMEDS::Color aColor;
1141 aColor.R = VISU::Storable::FindValue(theMap,"myColor.R").toDouble();
1142 aColor.G = VISU::Storable::FindValue(theMap,"myColor.G").toDouble();
1143 aColor.B = VISU::Storable::FindValue(theMap,"myColor.B").toDouble();
1145 double aPosition[3];
1146 aPosition[0] = VISU::Storable::FindValue(theMap,"myPosition[0]").toDouble();
1147 aPosition[1] = VISU::Storable::FindValue(theMap,"myPosition[1]").toDouble();
1148 aPosition[2] = VISU::Storable::FindValue(theMap,"myPosition[2]").toDouble();
1150 double aFocalPnt[3];
1151 aFocalPnt[0] = VISU::Storable::FindValue(theMap,"myFocalPnt[0]").toDouble();
1152 aFocalPnt[1] = VISU::Storable::FindValue(theMap,"myFocalPnt[1]").toDouble();
1153 aFocalPnt[2] = VISU::Storable::FindValue(theMap,"myFocalPnt[2]").toDouble();
1156 aViewUp[0] = VISU::Storable::FindValue(theMap,"myViewUp[0]").toDouble();
1157 aViewUp[1] = VISU::Storable::FindValue(theMap,"myViewUp[1]").toDouble();
1158 aViewUp[2] = VISU::Storable::FindValue(theMap,"myViewUp[2]").toDouble();
1160 double aParallelScale = VISU::Storable::FindValue(theMap,"myParallelScale").toDouble();
1162 double aScaleFactor[3];
1163 aScaleFactor[0] = VISU::Storable::FindValue(theMap,"myScaleFactor[0]").toDouble();
1164 aScaleFactor[1] = VISU::Storable::FindValue(theMap,"myScaleFactor[1]").toDouble();
1165 aScaleFactor[2] = VISU::Storable::FindValue(theMap,"myScaleFactor[2]").toDouble();
1167 SetBackground(theStudyFrame,aColor);
1168 SetPointOfView(theStudyFrame,aPosition);
1169 SetViewUp(theStudyFrame,aViewUp);
1170 SetFocalPoint(theStudyFrame,aFocalPnt);
1171 SetParallelScale(theStudyFrame,aParallelScale);
1172 ScaleView(theStudyFrame,VISU::View3D::XAxis,aScaleFactor[0]);
1173 ScaleView(theStudyFrame,VISU::View3D::YAxis,aScaleFactor[1]);
1174 ScaleView(theStudyFrame,VISU::View3D::ZAxis,aScaleFactor[2]);
1178 string View3D_i::ToString (SUIT_ViewWindow* theStudyFrame)
1180 ostringstream strOut;
1181 Storable::DataToStream( strOut, "myComment", myComment.c_str() );
1182 ToStream(theStudyFrame,strOut);
1184 if(MYDEBUG) MESSAGE("View3D_i::ToString - "<<strOut.str());
1185 return strOut.str();
1188 void View3D_i::ToStream (SUIT_ViewWindow* theStudyFrame, std::ostringstream& theStr)
1190 Storable::DataToStream(theStr,"myType",VISU::TVIEW3D);
1193 GetRenderer(theStudyFrame)->GetBackground(backint);
1194 Storable::DataToStream(theStr,"myColor.R",backint[0]);
1195 Storable::DataToStream(theStr,"myColor.G",backint[1]);
1196 Storable::DataToStream(theStr,"myColor.B",backint[2]);
1198 double aPosition[3];
1199 GetPointOfView(theStudyFrame,aPosition);
1200 Storable::DataToStream(theStr,"myPosition[0]",aPosition[0]);
1201 Storable::DataToStream(theStr,"myPosition[1]",aPosition[1]);
1202 Storable::DataToStream(theStr,"myPosition[2]",aPosition[2]);
1204 double aFocalPnt[3];
1205 GetFocalPoint(theStudyFrame,aFocalPnt);
1206 Storable::DataToStream(theStr,"myFocalPnt[0]",aFocalPnt[0]);
1207 Storable::DataToStream(theStr,"myFocalPnt[1]",aFocalPnt[1]);
1208 Storable::DataToStream(theStr,"myFocalPnt[2]",aFocalPnt[2]);
1211 GetCamera(theStudyFrame)->GetViewUp(aViewUp);
1212 Storable::DataToStream(theStr,"myViewUp[0]",aViewUp[0]);
1213 Storable::DataToStream(theStr,"myViewUp[1]",aViewUp[1]);
1214 Storable::DataToStream(theStr,"myViewUp[2]",aViewUp[2]);
1216 Storable::DataToStream(theStr,"myParallelScale",GetParallelScale(theStudyFrame));
1218 double aScaleFactor[3];
1219 GetViewWindow(theStudyFrame)->GetScale(aScaleFactor);
1220 Storable::DataToStream(theStr,"myScaleFactor[0]",aScaleFactor[0]);
1221 Storable::DataToStream(theStr,"myScaleFactor[1]",aScaleFactor[1]);
1222 Storable::DataToStream(theStr,"myScaleFactor[2]",aScaleFactor[2]);
1225 void View3D_i::ToStream(std::ostringstream& theStr)
1227 ToStream(myViewWindow,theStr);
1230 void View3D_i::Close()
1232 myViewWindow->close();
1235 View3D_i::~View3D_i()
1237 if(MYDEBUG) MESSAGE("View3D_i::~View3D_i");
1240 void View3D_i::SetTitle (const char* theTitle)
1242 ProcessVoidEvent(new TVoidMemFun1ArgEvent<SUIT_ViewWindow,const QString&,QString>
1243 (myViewWindow,&SUIT_ViewWindow::setCaption,QString(theTitle)));
1246 char* View3D_i::GetTitle()
1248 return CORBA::string_dup(myViewWindow->caption().latin1());
1251 void View3D_i::SetBackground (SUIT_ViewWindow* theStudyFrame,
1252 const SALOMEDS::Color& theColor)
1255 aColor[0] = int(255.0*theColor.R);
1256 aColor[1] = int(255.0*theColor.G);
1257 aColor[2] = int(255.0*theColor.B);
1258 QColor aNewColor(aColor[0],aColor[1],aColor[2]);
1259 GetViewWindow(theStudyFrame)->setBackgroundColor(aNewColor);
1262 SALOMEDS::Color View3D_i::GetBackground (SUIT_ViewWindow* theStudyFrame)
1264 SALOMEDS::Color aColor;
1266 GetRenderer(theStudyFrame)->GetBackground(backint);
1267 aColor.R = backint[0]; aColor.G = backint[1]; aColor.B = backint[2];
1271 class TUpdateViewerEvent: public SALOME_Event
1273 SUIT_ViewWindow* myViewWindow;
1277 TUpdateViewerEvent(SUIT_ViewWindow* theStudyFrame,
1280 myViewWindow(theStudyFrame),
1282 myDisplaing(theDisplaing)
1284 virtual void Execute(){
1285 UpdateViewer(myViewWindow,myDisplaing,myPrs3d);
1289 void View3D_i::EraseAll()
1291 if(MYDEBUG) MESSAGE("View3D_i::EraseAll");
1292 ProcessVoidEvent(new TUpdateViewerEvent(myViewWindow,NULL,eEraseAll));
1295 void View3D_i::DisplayAll()
1297 if(MYDEBUG) MESSAGE("View3D_i::DisplayAll");
1298 ProcessVoidEvent(new TUpdateViewerEvent(myViewWindow,NULL,eDisplayAll));
1301 void View3D_i::Erase (PrsObject_ptr thePrsObj)
1303 if(MYDEBUG) MESSAGE("View3D_i::Erase");
1304 CORBA::Object_ptr anObj = thePrsObj;
1305 if(Prs3d_i* aPrs = dynamic_cast<Prs3d_i*>(VISU::GetServant(anObj).in())){
1306 ProcessVoidEvent(new TUpdateViewerEvent(myViewWindow,aPrs,eErase));
1310 void View3D_i::Display (PrsObject_ptr thePrsObj)
1312 if(MYDEBUG) MESSAGE("View3D_i::Display");
1313 CORBA::Object_ptr anObj = thePrsObj;
1314 if(Prs3d_i* aPrs = dynamic_cast<Prs3d_i*>(VISU::GetServant(anObj).in())){
1315 ProcessVoidEvent(new TUpdateViewerEvent(myViewWindow,aPrs,eDisplay));
1319 void View3D_i::DisplayOnly (PrsObject_ptr thePrsObj)
1321 if(MYDEBUG) MESSAGE("View3D_i::DisplayOnly");
1322 CORBA::Object_ptr anObj = thePrsObj;
1323 if(Prs3d_i* aPrs = dynamic_cast<Prs3d_i*>(VISU::GetServant(anObj).in())){
1324 ProcessVoidEvent(new TUpdateViewerEvent(myViewWindow,aPrs,eDisplayOnly));
1328 void View3D_i::FitAll()
1330 ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>
1331 (GetViewWindow(myViewWindow), &SVTK_ViewWindow::onFitAll));
1335 void View3D_i::SetView (VISU::View3D::ViewType theType)
1338 case VISU::View3D::FRONT :
1339 ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>
1340 (GetViewWindow(myViewWindow), &SVTK_ViewWindow::onFrontView));
1342 case VISU::View3D::BACK :
1343 ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>
1344 (GetViewWindow(myViewWindow), &SVTK_ViewWindow::onBackView));
1346 case VISU::View3D::LEFT :
1347 ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>
1348 (GetViewWindow(myViewWindow),&SVTK_ViewWindow::onLeftView));
1350 case VISU::View3D::RIGHT :
1351 ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>
1352 (GetViewWindow(myViewWindow),&SVTK_ViewWindow::onRightView));
1354 case VISU::View3D::TOP :
1355 ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>
1356 (GetViewWindow(myViewWindow),&SVTK_ViewWindow::onTopView));
1358 case VISU::View3D::BOTTOM :
1359 ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>
1360 (GetViewWindow(myViewWindow),&SVTK_ViewWindow::onBottomView));
1366 class TSet3DViewParamEvent: public SALOME_Event
1369 typedef void (*TFun)(SUIT_ViewWindow* theStudyFrame, const CORBA::Double theParam[3]);
1370 TSet3DViewParamEvent (TFun theFun,
1371 SUIT_ViewWindow* theStudyFrame,
1372 const CORBA::Double theParam[3]):
1374 myViewWindow(theStudyFrame),
1377 virtual void Execute(){
1378 myFun(myViewWindow,myParam);
1382 SUIT_ViewWindow* myViewWindow;
1383 const CORBA::Double* myParam;
1386 void View3D_i::SetPointOfView (SUIT_ViewWindow* theStudyFrame,
1387 const CORBA::Double thePosition[3])
1389 GetCamera(theStudyFrame)->SetPosition(thePosition);
1392 void View3D_i::SetPointOfView (const VISU::View3D::XYZ thePosition)
1394 if(MYDEBUG) MESSAGE("View3D_i::SetPointOfView");
1395 ProcessVoidEvent(new TSet3DViewParamEvent(&SetPointOfView,myViewWindow,thePosition));
1398 void View3D_i::GetPointOfView (SUIT_ViewWindow* theStudyFrame,
1399 CORBA::Double thePosition[3])
1401 GetCamera(theStudyFrame)->GetPosition(thePosition);
1404 VISU::View3D::XYZ_slice* View3D_i::GetPointOfView()
1406 if(MYDEBUG) MESSAGE("View3D_i::GetPointOfView");
1407 CORBA::Double aPosition[3];
1408 GetPointOfView(myViewWindow,aPosition);
1409 return VISU::View3D::XYZ_dup(aPosition);
1412 void View3D_i::SetViewUp (SUIT_ViewWindow* theStudyFrame,
1413 const CORBA::Double theViewUp[3])
1415 GetCamera(theStudyFrame)->SetViewUp(theViewUp);
1418 void View3D_i::SetViewUp (const VISU::View3D::XYZ theViewUp)
1420 if(MYDEBUG) MESSAGE("View3D_i::SetViewUp");
1421 ProcessVoidEvent(new TSet3DViewParamEvent(&SetViewUp,myViewWindow,theViewUp));
1424 void View3D_i::GetViewUp (SUIT_ViewWindow* theStudyFrame,
1425 CORBA::Double theViewUp[3])
1427 GetCamera(theStudyFrame)->GetViewUp(theViewUp);
1430 VISU::View3D::XYZ_slice* View3D_i::GetViewUp()
1432 if(MYDEBUG) MESSAGE("View3D_i::GetViewUp");
1433 CORBA::Double aViewUp[3];
1434 GetCamera(myViewWindow)->GetViewUp(aViewUp);
1435 return VISU::View3D::XYZ_dup(aViewUp);
1438 void View3D_i::SetFocalPoint (SUIT_ViewWindow* theStudyFrame,
1439 const CORBA::Double theFocalPnt[3])
1441 GetCamera(theStudyFrame)->SetFocalPoint(theFocalPnt);
1444 void View3D_i::SetFocalPoint (const VISU::View3D::XYZ theCoord)
1446 if(MYDEBUG) MESSAGE("View3D_i::SetFocalPoint");
1447 ProcessVoidEvent(new TSet3DViewParamEvent(&SetFocalPoint,myViewWindow,theCoord));
1451 void View3D_i::GetFocalPoint (SUIT_ViewWindow* theStudyFrame,
1452 CORBA::Double theFocalPnt[3])
1454 GetCamera(theStudyFrame)->GetFocalPoint(theFocalPnt);
1457 VISU::View3D::XYZ_slice* View3D_i::GetFocalPoint()
1459 if(MYDEBUG) MESSAGE("View3D_i::GetFocalPoint");
1460 CORBA::Double aFocalPnt[3];
1461 GetFocalPoint(myViewWindow,aFocalPnt);
1462 return VISU::View3D::XYZ_dup(aFocalPnt);
1465 class TSetViewParamEvent: public SALOME_Event
1468 typedef void (*TFun)(SUIT_ViewWindow* theStudyFrame, CORBA::Double theParam);
1469 TSetViewParamEvent (TFun theFun,
1470 SUIT_ViewWindow* theStudyFrame,
1471 CORBA::Double theParam):
1473 myViewWindow(theStudyFrame),
1476 virtual void Execute()
1478 myFun(myViewWindow,myParam);
1482 SUIT_ViewWindow* myViewWindow;
1483 CORBA::Double myParam;
1486 void View3D_i::SetParallelScale (SUIT_ViewWindow* theStudyFrame,
1487 CORBA::Double theScale)
1489 GetCamera(theStudyFrame)->SetParallelScale(theScale);
1492 void View3D_i::SetParallelScale (CORBA::Double theScale)
1494 if(MYDEBUG) MESSAGE("View3D_i::SetParallelScale");
1495 ProcessVoidEvent(new TSetViewParamEvent(&SetParallelScale,myViewWindow,theScale));
1498 CORBA::Double View3D_i::GetParallelScale (SUIT_ViewWindow* theStudyFrame)
1500 return GetCamera(theStudyFrame)->GetParallelScale();
1503 CORBA::Double View3D_i::GetParallelScale()
1505 if(MYDEBUG) MESSAGE("View3D_i::GetParallelScale");
1506 return GetParallelScale(myViewWindow);
1509 void View3D_i::ScaleView (SUIT_ViewWindow* theStudyFrame,
1510 VISU::View3D::Axis theAxis, CORBA::Double theParam)
1512 SVTK_ViewWindow* aViewFrame = GetViewWindow(theStudyFrame);
1513 double aScaleFactor[3];
1514 aViewFrame->GetScale(aScaleFactor);
1515 aScaleFactor[theAxis] = theParam;
1516 aViewFrame->SetScale(aScaleFactor);
1519 void SetScaleView (SUIT_ViewWindow* theStudyFrame, const CORBA::Double theScale[3])
1521 double aScale[3] = {theScale[0], theScale[1], theScale[2]};
1522 GetViewWindow(theStudyFrame)->SetScale(aScale);
1525 void View3D_i::ScaleView(VISU::View3D::Axis theAxis, CORBA::Double theParam)
1527 if(MYDEBUG) MESSAGE("View3D_i::ScaleView");
1529 GetViewWindow(myViewWindow)->GetScale(aScale);
1530 aScale[theAxis] = theParam;
1531 ProcessVoidEvent(new TSet3DViewParamEvent(&SetScaleView,myViewWindow,aScale));
1534 void View3D_i::RemoveScale()
1536 if(MYDEBUG) MESSAGE("View3D_i::RemoveScale");
1537 double aScale[3] = {1.0, 1.0, 1.0};
1538 ProcessVoidEvent(new TSet3DViewParamEvent(&SetScaleView,myViewWindow,aScale));