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 "VISU_Actor.h"
36 #include "SALOME_Event.hxx"
38 #include "SUIT_ViewWindow.h"
39 #include "SUIT_ViewManager.h"
40 #include "SUIT_Tools.h"
42 #include "STD_MDIDesktop.h"
44 #include "SVTK_ViewWindow.h"
45 #include "SVTK_ViewModel.h"
46 #include "Plot2d_ViewFrame.h"
47 #include "Plot2d_ViewModel.h"
49 #include "SalomeApp_Application.h"
50 #include "SalomeApp_Study.h"
52 #include <qworkspace.h>
54 #include <vtkCamera.h>
55 #include <vtkRenderer.h>
60 static int MYDEBUG = 0;
62 static int MYDEBUG = 0;
67 typedef TVoidMemFunEvent<SUIT_ViewWindow> TFrameActionEvent;
70 View_i(SalomeApp_Application *theApplication,
71 SUIT_ViewManager* theViewManager):
72 myApplication(theApplication),
74 myViewManager(theViewManager)
76 if(MYDEBUG) MESSAGE("View_i::View_i - "<<this);
77 if(STD_MDIDesktop* aDesktop = dynamic_cast<STD_MDIDesktop*>(myApplication->desktop())){
78 myWorkspace = aDesktop->workspace();
85 if(MYDEBUG) MESSAGE("View_i::~View_i - "<<this);
89 struct TApplicationEvent: public SALOME_Event
91 SalomeApp_Application* myApplication;
93 TApplicationEvent(SalomeApp_Application* theApplication):
94 myApplication(theApplication)
101 ShowPart(VISU::View::ViewRepresentation theViewRepresentation,
102 CORBA::Boolean theState)
104 struct TEvent: public TApplicationEvent
106 VISU::View::ViewRepresentation myViewRepresentation;
107 CORBA::Boolean myState;
109 TEvent(SalomeApp_Application* theApplication,
110 VISU::View::ViewRepresentation theViewRepresentation,
111 CORBA::Boolean theState):
112 TApplicationEvent(theApplication),
113 myViewRepresentation(theViewRepresentation),
121 switch(myViewRepresentation){
122 case VISU::View::OBJECTBROWSER:
123 myApplication->setWindowShown(SalomeApp_Application::WT_ObjectBrowser,myState);
125 case VISU::View::PYTHON:
126 myApplication->setWindowShown(SalomeApp_Application::WT_PyConsole,myState);
128 case VISU::View::MESSAGES:
129 myApplication->setWindowShown(SalomeApp_Application::WT_LogWindow,myState);
131 case VISU::View::VIEWER:{
132 ViewManagerList aViewManagerList = myApplication->viewManagers();
140 ProcessVoidEvent(new TEvent(myApplication,theViewRepresentation,theState));
144 struct TPartShownEvent: public TApplicationEvent
146 VISU::View::ViewRepresentation myViewRepresentation;
147 typedef bool TResult;
150 TPartShownEvent(SalomeApp_Application* theApplication,
151 VISU::View::ViewRepresentation theViewRepresentation):
152 TApplicationEvent(theApplication),
153 myViewRepresentation(theViewRepresentation),
161 switch(myViewRepresentation){
162 case VISU::View::OBJECTBROWSER:
163 myResult = myApplication->isWindowVisible(SalomeApp_Application::WT_ObjectBrowser);
165 case VISU::View::PYTHON:
166 myResult = myApplication->isWindowVisible(SalomeApp_Application::WT_PyConsole);
168 case VISU::View::MESSAGES:
169 myResult = myApplication->isWindowVisible(SalomeApp_Application::WT_LogWindow);
171 case VISU::View::VIEWER:{
172 ViewManagerList aViewManagerList = myApplication->viewManagers();
183 IsPartShown(VISU::View::ViewRepresentation theViewRepresentation)
185 return ProcessEvent(new TPartShownEvent(myApplication,theViewRepresentation));
189 struct TSetViewSize: public SALOME_Event
191 SUIT_ViewWindow* myViewWindow;
192 typedef void (QRect::* TAction)(int);
197 TSetViewSize(SUIT_ViewWindow* theViewWindow,
199 CORBA::Long theSize):
200 myViewWindow(theViewWindow),
209 if (QWidget* aParent = myViewWindow->parentWidget(true)) {
210 QRect aQRect = aParent->frameGeometry();
211 (aQRect.*myAction)(mySize);
212 aParent->setGeometry(aQRect);
220 SetViewWidth(CORBA::Long theWidth)
222 ProcessVoidEvent(new TSetViewSize(myViewWindow,&QRect::setWidth,theWidth));
228 SetViewHeight(CORBA::Long theHeight)
230 ProcessVoidEvent(new TSetViewSize(myViewWindow,&QRect::setHeight,theHeight));
234 struct TGetViewSize: public SALOME_Event
236 SUIT_ViewWindow* myViewWindow;
238 typedef int (QRect::* TAction)() const;
241 typedef CORBA::Long TResult;
245 TGetViewSize(SUIT_ViewWindow* theViewWindow,
247 myViewWindow(theViewWindow),
255 if(QWidget* aParent = myViewWindow->parentWidget(true)){
256 QRect aQRect = aParent->frameGeometry();
257 myResult = (aQRect.*myAction)();
267 return ProcessEvent(new TGetViewSize(myViewWindow,&QRect::width));
274 return ProcessEvent(new TGetViewSize(myViewWindow,&QRect::height));
278 class TWorkspaceEvent: public SALOME_Event
281 QWidget* myViewWindow;
282 QWidget* myWorkspace;
285 TWorkspaceEvent(QWidget* theViewWindow,
286 QWidget* theWorkspace):
287 myViewWindow(theViewWindow),
288 myWorkspace(theWorkspace)
293 class TAlignEvent: public TWorkspaceEvent
296 Qt::AlignmentFlags myAligment;
299 TAlignEvent(QWidget* theViewWindow,
300 QWidget* theWorkspace,
301 Qt::AlignmentFlags theAligment):
302 TWorkspaceEvent(theViewWindow,theWorkspace),
303 myAligment(theAligment)
310 if(QWidget* aParent = myViewWindow->parentWidget(true))
311 SUIT_Tools::alignWidget(aParent,myWorkspace,myAligment);
318 SetViewPositionHorizontal(VISU::View::ViewPosition theViewPosition)
321 switch(theViewPosition){
322 case VISU::View::LEFT:
323 ProcessVoidEvent(new TAlignEvent(myViewWindow,myWorkspace,Qt::AlignLeft));
325 case VISU::View::CENTER:
326 ProcessVoidEvent(new TAlignEvent(myViewWindow,myWorkspace,Qt::AlignHCenter));
328 case VISU::View::RIGHT:
329 ProcessVoidEvent(new TAlignEvent(myViewWindow,myWorkspace,Qt::AlignRight));
338 SetViewPositionVertical(VISU::View::ViewPosition theViewPosition)
341 switch(theViewPosition){
342 case VISU::View::TOP:
343 ProcessVoidEvent(new TAlignEvent(myViewWindow,myWorkspace,Qt::AlignTop));
345 case VISU::View::CENTER:
346 ProcessVoidEvent(new TAlignEvent(myViewWindow,myWorkspace,Qt::AlignVCenter));
348 case VISU::View::BOTTOM:
349 ProcessVoidEvent(new TAlignEvent(myViewWindow,myWorkspace,Qt::AlignBottom));
356 class TXYEvent: public TWorkspaceEvent
359 CORBA::Double myX, myY;
362 TXYEvent(QWidget* theViewWindow,
363 QWidget* theWorkspace,
366 TWorkspaceEvent(theViewWindow,theWorkspace),
375 SetRelativePosition(CORBA::Double theX, CORBA::Double theY)
377 struct TEvent: public TXYEvent
380 TEvent(QWidget* theViewWindow,
381 QWidget* theWorkspace,
384 TXYEvent(theViewWindow,theWorkspace,theX,theY)
391 if(QWidget* aParent = myViewWindow->parentWidget(true))
392 aParent->move(int(myX*myWorkspace->width()),int(myY*myWorkspace->height()));
397 ProcessVoidEvent(new TEvent(myViewWindow,myWorkspace,theX,theY));
402 SetRelativeSize(CORBA::Double theX, CORBA::Double theY)
404 struct TEvent: public TXYEvent
407 TEvent(QWidget* theViewWindow,
408 QWidget* theWorkspace,
411 TXYEvent(theViewWindow,theWorkspace,theX,theY)
418 if(QWidget* aParent = myViewWindow->parentWidget(true))
419 aParent->setGeometry(aParent->x(),
421 int(myX*myWorkspace->width()),
422 int(myY*myWorkspace->height()));
427 ProcessVoidEvent(new TEvent(myViewWindow,myWorkspace,theX,theY));
432 SetBackground(const SALOMEDS::Color& theColor)
434 struct TEvent: public SALOME_Event
437 SALOMEDS::Color myColor;
439 TEvent(QWidget* theWidget,
440 const SALOMEDS::Color& theColor):
444 virtual void Execute(){
446 aColor[0] = int(255.0*myColor.R);
447 aColor[1] = int(255.0*myColor.G);
448 aColor[2] = int(255.0*myColor.B);
449 myWidget->setBackgroundColor(QColor(aColor[0],aColor[1],aColor[2]));
453 ProcessVoidEvent(new TEvent(myViewWindow,theColor));
457 struct TBackgroundEvent: public SALOME_Event
460 typedef SALOMEDS::Color TResult;
463 TBackgroundEvent(QWidget* theWidget):
471 const QColor& aColor = myWidget->backgroundColor();
472 myResult.R = aColor.red()/255.0;
473 myResult.G = aColor.green()/255.0;
474 myResult.B = aColor.blue()/255.0;
482 return ProcessEvent(new TBackgroundEvent(myViewWindow));
489 ProcessVoidEvent(new TFrameActionEvent(myViewWindow,&SUIT_ViewWindow::showMinimized));
496 ProcessVoidEvent(new TFrameActionEvent(myViewWindow,&SUIT_ViewWindow::showNormal));
503 ProcessVoidEvent(new TFrameActionEvent(myViewWindow,&SUIT_ViewWindow::showMaximized));
518 Erase(PrsObject_ptr thePrsObj)
523 Display(PrsObject_ptr thePrsObj)
528 DisplayOnly(PrsObject_ptr thePrsObj)
537 View_i::SavePicture(const char* theFileName)
550 ToStream(std::ostringstream& theStr)
554 //================= OLD CODE ===================
556 //QAD_Study* CheckStudy (SALOMEDS::Study_ptr theStudy)
558 // //QAD_Desktop* aDesktop = QAD_Application::getDesktop();
559 // //QAD_Study* aStudy = aDesktop->findStudy(theStudy);
561 // CORBA::String_var aName = theStudy->Name();
562 // aFileInfo.setFile(aName.in());
563 // if (aFileInfo.exists())
564 // aStudy = aDesktop->loadStudy(aFileInfo.baseName());
566 // aStudy = aDesktop->loadStudy(aName.in());
568 // MESSAGE("CheckStudy()::ERROR: Can't load study");
574 class TSavePictureEvent: public SALOME_Event
577 const char* myFileName;
579 typedef CORBA::Boolean TResult;
581 TSavePictureEvent (QWidget* theWidget, const char* theFileName)
582 : myWidget(theWidget),
583 myFileName(theFileName),
588 virtual void Execute()
591 QPixmap px = QPixmap::grabWindow(myWidget->winId());
592 if (!QString(myFileName).isNull()) {
593 QString fmt = SUIT_Tools::extension(myFileName).upper();
595 fmt = QString("BMP"); // default format
598 myResult = px.save(myFileName, fmt.latin1());
605 //===========================================================================
606 XYPlot_i::XYPlot_i (SalomeApp_Application* theApplication)
607 : View_i(theApplication, theApplication->getViewManager(Plot2d_Viewer::Type(), true))
609 if (MYDEBUG) MESSAGE("XYPlot_i::XYPlot_i");
612 Storable* XYPlot_i::Create (int theNew)
615 myViewWindow = myViewManager->createViewWindow();
617 myViewWindow = myViewManager->getActiveView();
619 //jfa tmp:myView = dynamic_cast<Plot2d_ViewFrame*>(myViewWindow->getRightFrame()->getViewFrame());
620 //jfa tmp:myView->Repaint();
624 void XYPlot_i::Update()
626 ProcessVoidEvent(new TVoidMemFunEvent<Plot2d_ViewFrame>(myView,&Plot2d_ViewFrame::Repaint));
629 void XYPlot_i::Close()
631 myViewWindow->close();
634 XYPlot_i::~XYPlot_i() {
635 if(MYDEBUG) MESSAGE("XYPlot_i::~XYPlot_i");
638 void XYPlot_i::SetTitle (const char* theTitle)
640 ProcessVoidEvent(new TVoidMemFun1ArgEvent<SUIT_ViewWindow,const QString&,QString>
641 (myViewWindow, &SUIT_ViewWindow::setCaption, QString(theTitle)));
643 char* XYPlot_i::GetTitle()
645 return CORBA::string_dup(myViewWindow->caption().latin1());
648 void XYPlot_i::SetSubTitle (const char* theTitle)
650 ProcessVoidEvent(new TVoidMemFun1ArgEvent<Plot2d_ViewFrame,const QString&,QString>
651 (myView, &Plot2d_ViewFrame::setTitle, QString(theTitle)));
654 char* XYPlot_i::GetSubTitle()
656 return CORBA::string_dup(myView->getTitle());
659 void XYPlot_i::SetCurveType (VISU::XYPlot::CurveType theType)
661 ProcessVoidEvent(new TVoidMemFun2ArgEvent<Plot2d_ViewFrame,int,bool>
662 (myView,&Plot2d_ViewFrame::setCurveType,theType,true));
665 VISU::XYPlot::CurveType XYPlot_i::GetCurveType()
667 return (VISU::XYPlot::CurveType)myView->getCurveType();
670 void XYPlot_i::SetMarkerSize (CORBA::Long theSize)
672 ProcessVoidEvent(new TVoidMemFun2ArgEvent<Plot2d_ViewFrame,int,bool>
673 (myView,&Plot2d_ViewFrame::setMarkerSize,theSize,true));
676 CORBA::Long XYPlot_i::GetMarkerSize()
678 return myView->getMarkerSize();
681 class TEnableGridEvent: public SALOME_Event
684 typedef void (Plot2d_ViewFrame::* TFun)(bool, const int, bool, const int, bool);
685 TEnableGridEvent (Plot2d_ViewFrame* theView, TFun theFun,
686 CORBA::Boolean theMajor, CORBA::Long theNumMajor,
687 CORBA::Boolean theMinor, CORBA::Long theNumMinor):
688 myView(theView), myFun(theFun),
689 myMajor(theMajor), myNumMajor(theNumMajor),
690 myMinor(theMinor), myNumMinor(theNumMinor)
693 virtual void Execute()
695 (myView->*myFun)(myMajor,myNumMajor,myMinor,myNumMinor,true);
698 Plot2d_ViewFrame* myView;
700 CORBA::Boolean myMajor, myNumMajor;
701 CORBA::Boolean myMinor, myNumMinor;
704 void XYPlot_i::EnableXGrid (CORBA::Boolean theMajor, CORBA::Long theNumMajor,
705 CORBA::Boolean theMinor, CORBA::Long theNumMinor)
707 ProcessVoidEvent(new TEnableGridEvent(myView,&Plot2d_ViewFrame::setXGrid,
708 theMajor,theNumMajor,theMinor,theNumMinor));
710 void XYPlot_i::EnableYGrid(CORBA::Boolean theMajor, CORBA::Long theNumMajor,
711 CORBA::Boolean theMinor, CORBA::Long theNumMinor)
713 //jfa tmp:ProcessVoidEvent(new TEnableGridEvent(myView,&Plot2d_ViewFrame::setYGrid,
714 //jfa tmp: theMajor,theNumMajor,theMinor,theNumMinor));
717 class TSetScaleModeEvent: public SALOME_Event
720 typedef void (Plot2d_ViewFrame::* TFun)(const int, bool);
721 TSetScaleModeEvent (Plot2d_ViewFrame* theView, TFun theFun, int theScaling):
722 myView(theView), myFun(theFun), myScaling(theScaling)
725 virtual void Execute()
727 (myView->*myFun)(myScaling,true);
730 Plot2d_ViewFrame* myView;
735 void XYPlot_i::SetHorScaling (VISU::Scaling theScaling)
737 ProcessVoidEvent(new TSetScaleModeEvent(myView,&Plot2d_ViewFrame::setHorScaleMode,
738 theScaling == VISU::LOGARITHMIC));
741 VISU::Scaling XYPlot_i::GetHorScaling()
743 return (VISU::Scaling)myView->getHorScaleMode();
746 void XYPlot_i::SetVerScaling(VISU::Scaling theScaling)
748 ProcessVoidEvent(new TSetScaleModeEvent(myView,&Plot2d_ViewFrame::setVerScaleMode,
749 theScaling == VISU::LOGARITHMIC));
752 VISU::Scaling XYPlot_i::GetVerScaling()
754 return (VISU::Scaling)myView->getVerScaleMode();
757 class TSetTitleEvent: public SALOME_Event
760 //typedef void (Plot2d_ViewFrame::* TFun)(bool, const QString&, bool = true);
761 typedef void (Plot2d_ViewFrame::* TFun)(bool, const QString&, Plot2d_ViewFrame::ObjectType, bool = true);
762 //TSetTitleEvent (Plot2d_ViewFrame* theView, TFun theFun, const char* theTitle):
763 TSetTitleEvent (Plot2d_ViewFrame* theView, Plot2d_ViewFrame::ObjectType theType, const char* theTitle):
764 //myView(theView), myFun(theFun), myTitle(theTitle)
765 myView(theView), myType(theType), myTitle(theTitle)
767 virtual void Execute()
769 //(myView->*myFun)(true,myTitle,myType);
770 myView->setTitle(true,myTitle,myType);
773 Plot2d_ViewFrame* myView;
775 Plot2d_ViewFrame::ObjectType myType;
779 void XYPlot_i::SetXTitle (const char* theTitle)
781 //ProcessVoidEvent(new TSetTitleEvent(myView, &Plot2d_ViewFrame::setXTitle, theTitle));
782 ProcessVoidEvent(new TSetTitleEvent(myView, Plot2d_ViewFrame::XTitle, theTitle));
784 char* XYPlot_i::GetXTitle()
786 //return CORBA::string_dup(myView->getXTitle());
787 return CORBA::string_dup(myView->getTitle(Plot2d_ViewFrame::XTitle));
790 void XYPlot_i::SetYTitle (const char* theTitle)
792 //ProcessVoidEvent(new TSetTitleEvent(myView, &Plot2d_ViewFrame::setYTitle, theTitle));
793 ProcessVoidEvent(new TSetTitleEvent(myView, Plot2d_ViewFrame::YTitle, theTitle));
795 char* XYPlot_i::GetYTitle()
797 //return CORBA::string_dup(myView->getYTitle());
798 return CORBA::string_dup(myView->getTitle(Plot2d_ViewFrame::YTitle));
801 void XYPlot_i::ShowLegend (CORBA::Boolean theShowing)
803 ProcessVoidEvent(new TVoidMemFun2ArgEvent<Plot2d_ViewFrame,bool,bool>
804 (myView,&Plot2d_ViewFrame::showLegend,theShowing,true));
807 class TXYPlotViewEvent: public SALOME_Event
810 Plot2d_ViewFrame* myView;
811 PrsObject_ptr myPrsObj;
815 TXYPlotViewEvent(_PTR(Study) theStudy,
816 Plot2d_ViewFrame* theView,
817 PrsObject_ptr thePrsObj,
822 myDisplaing(theDisplaing)
826 virtual void Execute()
829 if (Curve_i* aCurve = dynamic_cast<Curve_i*>(VISU::GetServant(myPrsObj).in())) {
830 UpdatePlot2d(myView,myDisplaing,aCurve);
833 if (Container_i* aContainer = dynamic_cast<Container_i*>(VISU::GetServant(myPrsObj).in())) {
834 int nbCurves = aContainer->GetNbCurves();
835 for ( int i = 1; i <= nbCurves; i++ ) {
836 VISU::Curve_i* aCurve = aContainer->GetCurve( i );
837 if ( aCurve && aCurve->IsValid() ) {
838 UpdatePlot2d(myView,myDisplaing,aCurve);
844 if (Table_i* aTable = dynamic_cast<Table_i*>(VISU::GetServant(myPrsObj).in())) {
845 _PTR(SObject) TableSO = myStudy->FindObjectID(aTable->GetEntry().latin1());
847 _PTR(ChildIterator) Iter = myStudy->NewChildIterator(TableSO);
848 for (; Iter->More(); Iter->Next()) {
849 CORBA::Object_var childObject = VISU::ClientSObjectToObject(Iter->Value());
850 if (!CORBA::is_nil(childObject)) {
851 CORBA::Object_ptr aCurve = VISU::Curve::_narrow(childObject);
852 if (!CORBA::is_nil(aCurve))
853 UpdatePlot2d(myView, myDisplaing,
854 dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aCurve).in()));
863 void XYPlot_i::Display (PrsObject_ptr thePrsObj)
865 //jfa tmp:ProcessVoidEvent(new TXYPlotViewEvent (myStudy,myView,thePrsObj,eDisplay));
868 void XYPlot_i::Erase (PrsObject_ptr thePrsObj)
870 //jfa tmp:ProcessVoidEvent(new TXYPlotViewEvent (myStudy,myView,thePrsObj,eErase));
873 void XYPlot_i::DisplayOnly (PrsObject_ptr thePrsObj)
875 //jfa tmp:ProcessVoidEvent(new TXYPlotViewEvent (myStudy,myView,thePrsObj,eDisplayOnly));
878 void XYPlot_i::EraseAll()
880 ProcessVoidEvent(new TVoidMemFunEvent<Plot2d_ViewFrame> (myView,&Plot2d_ViewFrame::EraseAll));
883 void XYPlot_i::FitAll()
885 ProcessVoidEvent(new TVoidMemFunEvent<Plot2d_ViewFrame> (myView,&Plot2d_ViewFrame::fitAll));
888 CORBA::Boolean XYPlot_i::SavePicture (const char* theFileName)
890 return ProcessEvent(new TSavePictureEvent (myView->getViewWidget(),theFileName));
894 //===========================================================================
895 TableView_i::TableView_i (SalomeApp_Application* theApplication)
896 : View_i(theApplication, theApplication->getViewManager("???"/*jfa tmp*/, true))
900 Storable* TableView_i::Create (VISU::Table_ptr theTable)
902 if (MYDEBUG) MESSAGE("TableView_i::Create - " << (!theTable->_is_nil()));
903 if (!theTable->_is_nil()) {
904 VISU::Table_i* table = dynamic_cast<VISU::Table_i*>(VISU::GetServant(theTable).in());
905 if (MYDEBUG) MESSAGE("TableView_i::Create - dynamic_cast = " << table);
908 if (SUIT_Study* aSStudy = myViewManager->study()) {
909 if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
910 if (_PTR(Study) aCStudy = aStudy->studyDS()) {
911 _PTR(SObject) aSObject = aCStudy->FindObjectID(table->GetObjectEntry());
913 //jfa tmp:myView = new SALOMEGUI_TableDlg (QAD_Application::getDesktop(),
916 //jfa tmp: SALOMEGUI_TableDlg::ttAuto,
917 //jfa tmp: Qt::Vertical);
918 //jfa tmp:myView->show();
929 TableView_i::~TableView_i()
931 if(MYDEBUG) MESSAGE("TableView_i::~TableView_i");
932 //jfa tmp:delete myView;
935 void TableView_i::SetTitle (const char* theTitle)
937 //jfa tmp:ProcessVoidEvent(new TVoidMemFun1ArgEvent<SALOMEGUI_TableDlg,const QString&,QString>
938 //jfa tmp: (myView, &SALOMEGUI_TableDlg::setCaption, QString(theTitle)));
941 char* TableView_i::GetTitle()
943 //jfa tmp:return CORBA::string_dup(myView->caption().latin1());
947 void TableView_i::Close()
949 //jfa tmp:myView->close();
953 //===========================================================================
954 int View3D_i::myNbViewParams = 0;
955 const string View3D_i::myComment = "VIEW3D";
956 const char* View3D_i::GetComment() const { return myComment.c_str();}
958 QString View3D_i::GenerateViewParamsName()
960 return VISU::GenerateName("ViewParams", ++myNbViewParams);
963 View3D_i::View3D_i (SalomeApp_Application* theApplication)
964 : View_i(theApplication, theApplication->getViewManager(SVTK_Viewer::Type(), true))
966 if (MYDEBUG) MESSAGE("View3D_i::View3D_i");
969 Storable* View3D_i::Create (int theNew)
971 if (MYDEBUG) MESSAGE("View3D_i::Create");
973 myViewWindow = myViewManager->createViewWindow();
975 myViewWindow = myViewManager->getActiveView();
980 void View3D_i::Update()
982 class TEvent: public SALOME_Event
984 SUIT_ViewWindow* myViewWindow;
986 TEvent(SUIT_ViewWindow* theStudyFrame):
987 myViewWindow(theStudyFrame)
989 virtual void Execute()
991 SVTK_ViewWindow* vf = GetViewWindow(myViewWindow);
992 vtkRenderer* Renderer = vf->getRenderer();
993 vtkActorCollection* theActors = Renderer->GetActors();
994 theActors->InitTraversal();
995 while (vtkActor *anAct = theActors->GetNextActor()) {
996 if (VISU_Actor* anActor = dynamic_cast<VISU_Actor*>(anAct)) {
997 VISU::Prs3d_i* aPrs3d = anActor->GetPrs3d();
998 if (anActor->GetVisibility() && aPrs3d) {
1000 aPrs3d->UpdateActor(anActor);
1004 RepaintView(myViewWindow);
1007 ProcessVoidEvent(new TEvent(myViewWindow));
1010 CORBA::Boolean View3D_i::SavePicture (const char* theFileName)
1012 //jfa tmp:return ProcessEvent(new TSavePictureEvent
1013 //jfa tmp: (myView->getViewWidget(), theFileName));
1017 bool View3D_i::SaveViewParams (SUIT_ViewManager* theViewManager, const char* theName)
1019 _PTR(Study) aCStudy;
1020 if (SUIT_Study* aSStudy = theViewManager->study()) {
1021 if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
1022 aCStudy = aStudy->studyDS();
1029 std::vector<_PTR(SObject)> aList = aCStudy->FindObjectByName(theName, "VISU");
1030 _PTR(GenericAttribute) anAttr;
1031 int iEnd = aList.size();
1032 for (int i = 0; i < iEnd; i++) {
1033 _PTR(SObject) anObj = aList[i];
1034 string anEntry = anObj->GetID();
1035 if(MYDEBUG) MESSAGE("View3D_i::SaveViewParams - anEntry = " << anEntry);
1036 if (anObj->FindAttribute(anAttr, "AttributeComment")) {
1037 _PTR(AttributeComment) aCmnt (anAttr);
1038 string aComm (aCmnt->Value());
1039 if (MYDEBUG) MESSAGE("View3D_i::SaveViewPoint - aComm = " << aComm);
1040 if (aComm.compare(View3D_i::myComment) >= 0) {
1041 aCmnt->SetValue(ToString(theViewManager->getActiveView()).c_str());
1047 _PTR(SComponent) aSComponent = ClientFindOrCreateVisuComponent(aCStudy);
1048 string aSComponentEntry = aSComponent->GetID();
1049 string anEntry = CreateAttributes(aCStudy, aSComponentEntry.c_str(), "", "", theName, "",
1050 ToString(theViewManager->getActiveView()).c_str());
1054 CORBA::Boolean View3D_i::SaveViewParams (const char* theName)
1056 return SaveViewParams(myViewManager, theName);
1059 bool View3D_i::RestoreViewParams (SUIT_ViewManager* theViewManager, const char* theName)
1061 _PTR(Study) aCStudy;
1062 if (SUIT_Study* aSStudy = theViewManager->study()) {
1063 if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
1064 aCStudy = aStudy->studyDS();
1070 std::vector<_PTR(SObject)> aList = aCStudy->FindObjectByName(theName, "VISU");
1071 _PTR(GenericAttribute) anAttr;
1072 int iEnd = aList.size();
1073 if (MYDEBUG) MESSAGE("View3D_i::RestoreViewPoint - iEnd = " << iEnd);
1074 for (int i = 0; i < iEnd; i++) {
1075 _PTR(SObject) anObj = aList[i];
1076 string anEntry = anObj->GetID();
1077 if (MYDEBUG) MESSAGE("View3D_i::RestoreViewPoint - anEntry = " << anEntry);
1078 if (anObj->FindAttribute(anAttr, "AttributeComment")) {
1079 _PTR(AttributeComment) aCmnt (anAttr);
1080 QString strIn(aCmnt->Value().c_str());
1081 Storable::TRestoringMap aMap;
1082 Storable::StrToMap(strIn, aMap);
1083 if (Storable::FindValue(aMap, "myComment").compare
1084 (View3D_i::myComment.c_str()) >= 0) {
1085 if (MYDEBUG) MESSAGE("View3D_i::RestoreViewPoint - aComm = " << strIn);
1086 Restore(theViewManager->getActiveView(), aMap);
1094 class TRestoreViewParamsEvent: public SALOME_Event
1096 SUIT_ViewManager* myViewManager;
1099 TRestoreViewParamsEvent (SUIT_ViewManager* theViewManager,
1100 const char* theName):
1101 myViewManager(theViewManager),
1105 virtual void Execute()
1107 myResult = View3D_i::RestoreViewParams(myViewManager, myName);
1109 typedef CORBA::Boolean TResult;
1113 CORBA::Boolean View3D_i::RestoreViewParams (const char* theName)
1115 return ProcessEvent(new TRestoreViewParamsEvent (myViewManager, theName));
1118 void View3D_i::Restore (SUIT_ViewWindow* theStudyFrame,
1119 const Storable::TRestoringMap& theMap)
1121 SALOMEDS::Color aColor;
1122 aColor.R = VISU::Storable::FindValue(theMap,"myColor.R").toDouble();
1123 aColor.G = VISU::Storable::FindValue(theMap,"myColor.G").toDouble();
1124 aColor.B = VISU::Storable::FindValue(theMap,"myColor.B").toDouble();
1126 double aPosition[3];
1127 aPosition[0] = VISU::Storable::FindValue(theMap,"myPosition[0]").toDouble();
1128 aPosition[1] = VISU::Storable::FindValue(theMap,"myPosition[1]").toDouble();
1129 aPosition[2] = VISU::Storable::FindValue(theMap,"myPosition[2]").toDouble();
1131 double aFocalPnt[3];
1132 aFocalPnt[0] = VISU::Storable::FindValue(theMap,"myFocalPnt[0]").toDouble();
1133 aFocalPnt[1] = VISU::Storable::FindValue(theMap,"myFocalPnt[1]").toDouble();
1134 aFocalPnt[2] = VISU::Storable::FindValue(theMap,"myFocalPnt[2]").toDouble();
1137 aViewUp[0] = VISU::Storable::FindValue(theMap,"myViewUp[0]").toDouble();
1138 aViewUp[1] = VISU::Storable::FindValue(theMap,"myViewUp[1]").toDouble();
1139 aViewUp[2] = VISU::Storable::FindValue(theMap,"myViewUp[2]").toDouble();
1141 double aParallelScale = VISU::Storable::FindValue(theMap,"myParallelScale").toDouble();
1143 double aScaleFactor[3];
1144 aScaleFactor[0] = VISU::Storable::FindValue(theMap,"myScaleFactor[0]").toDouble();
1145 aScaleFactor[1] = VISU::Storable::FindValue(theMap,"myScaleFactor[1]").toDouble();
1146 aScaleFactor[2] = VISU::Storable::FindValue(theMap,"myScaleFactor[2]").toDouble();
1148 SetBackground(theStudyFrame,aColor);
1149 SetPointOfView(theStudyFrame,aPosition);
1150 SetViewUp(theStudyFrame,aViewUp);
1151 SetFocalPoint(theStudyFrame,aFocalPnt);
1152 SetParallelScale(theStudyFrame,aParallelScale);
1153 ScaleView(theStudyFrame,VISU::View3D::XAxis,aScaleFactor[0]);
1154 ScaleView(theStudyFrame,VISU::View3D::YAxis,aScaleFactor[1]);
1155 ScaleView(theStudyFrame,VISU::View3D::ZAxis,aScaleFactor[2]);
1159 string View3D_i::ToString (SUIT_ViewWindow* theStudyFrame)
1161 ostringstream strOut;
1162 Storable::DataToStream( strOut, "myComment", myComment.c_str() );
1163 ToStream(theStudyFrame,strOut);
1165 if(MYDEBUG) MESSAGE("View3D_i::ToString - "<<strOut.str());
1166 return strOut.str();
1169 void View3D_i::ToStream (SUIT_ViewWindow* theStudyFrame, std::ostringstream& theStr)
1171 Storable::DataToStream(theStr,"myType",VISU::TVIEW3D);
1174 GetRenderer(theStudyFrame)->GetBackground(backint);
1175 Storable::DataToStream(theStr,"myColor.R",backint[0]);
1176 Storable::DataToStream(theStr,"myColor.G",backint[1]);
1177 Storable::DataToStream(theStr,"myColor.B",backint[2]);
1179 double aPosition[3];
1180 GetPointOfView(theStudyFrame,aPosition);
1181 Storable::DataToStream(theStr,"myPosition[0]",aPosition[0]);
1182 Storable::DataToStream(theStr,"myPosition[1]",aPosition[1]);
1183 Storable::DataToStream(theStr,"myPosition[2]",aPosition[2]);
1185 double aFocalPnt[3];
1186 GetFocalPoint(theStudyFrame,aFocalPnt);
1187 Storable::DataToStream(theStr,"myFocalPnt[0]",aFocalPnt[0]);
1188 Storable::DataToStream(theStr,"myFocalPnt[1]",aFocalPnt[1]);
1189 Storable::DataToStream(theStr,"myFocalPnt[2]",aFocalPnt[2]);
1192 GetCamera(theStudyFrame)->GetViewUp(aViewUp);
1193 Storable::DataToStream(theStr,"myViewUp[0]",aViewUp[0]);
1194 Storable::DataToStream(theStr,"myViewUp[1]",aViewUp[1]);
1195 Storable::DataToStream(theStr,"myViewUp[2]",aViewUp[2]);
1197 Storable::DataToStream(theStr,"myParallelScale",GetParallelScale(theStudyFrame));
1199 double aScaleFactor[3];
1200 GetViewWindow(theStudyFrame)->GetScale(aScaleFactor);
1201 Storable::DataToStream(theStr,"myScaleFactor[0]",aScaleFactor[0]);
1202 Storable::DataToStream(theStr,"myScaleFactor[1]",aScaleFactor[1]);
1203 Storable::DataToStream(theStr,"myScaleFactor[2]",aScaleFactor[2]);
1206 void View3D_i::ToStream(std::ostringstream& theStr)
1208 ToStream(myViewWindow,theStr);
1211 void View3D_i::Close()
1213 myViewWindow->close();
1216 View3D_i::~View3D_i()
1218 if(MYDEBUG) MESSAGE("View3D_i::~View3D_i");
1221 void View3D_i::SetTitle (const char* theTitle)
1223 ProcessVoidEvent(new TVoidMemFun1ArgEvent<SUIT_ViewWindow,const QString&,QString>
1224 (myViewWindow,&SUIT_ViewWindow::setCaption,QString(theTitle)));
1227 char* View3D_i::GetTitle()
1229 return CORBA::string_dup(myViewWindow->caption().latin1());
1232 void View3D_i::SetBackground (SUIT_ViewWindow* theStudyFrame,
1233 const SALOMEDS::Color& theColor)
1236 aColor[0] = int(255.0*theColor.R);
1237 aColor[1] = int(255.0*theColor.G);
1238 aColor[2] = int(255.0*theColor.B);
1239 QColor aNewColor(aColor[0],aColor[1],aColor[2]);
1240 GetViewWindow(theStudyFrame)->setBackgroundColor(aNewColor);
1243 SALOMEDS::Color View3D_i::GetBackground (SUIT_ViewWindow* theStudyFrame)
1245 SALOMEDS::Color aColor;
1247 GetRenderer(theStudyFrame)->GetBackground(backint);
1248 aColor.R = backint[0]; aColor.G = backint[1]; aColor.B = backint[2];
1252 class TUpdateViewerEvent: public SALOME_Event
1254 SUIT_ViewWindow* myViewWindow;
1258 TUpdateViewerEvent(SUIT_ViewWindow* theStudyFrame,
1261 myViewWindow(theStudyFrame),
1263 myDisplaing(theDisplaing)
1265 virtual void Execute(){
1266 UpdateViewer(myViewWindow,myDisplaing,myPrs3d);
1270 void View3D_i::EraseAll()
1272 if(MYDEBUG) MESSAGE("View3D_i::EraseAll");
1273 ProcessVoidEvent(new TUpdateViewerEvent(myViewWindow,NULL,eEraseAll));
1276 void View3D_i::DisplayAll()
1278 if(MYDEBUG) MESSAGE("View3D_i::DisplayAll");
1279 ProcessVoidEvent(new TUpdateViewerEvent(myViewWindow,NULL,eDisplayAll));
1282 void View3D_i::Erase (PrsObject_ptr thePrsObj)
1284 if(MYDEBUG) MESSAGE("View3D_i::Erase");
1285 CORBA::Object_ptr anObj = thePrsObj;
1286 if(Prs3d_i* aPrs = dynamic_cast<Prs3d_i*>(VISU::GetServant(anObj).in())){
1287 ProcessVoidEvent(new TUpdateViewerEvent(myViewWindow,aPrs,eErase));
1291 void View3D_i::Display (PrsObject_ptr thePrsObj)
1293 if(MYDEBUG) MESSAGE("View3D_i::Display");
1294 CORBA::Object_ptr anObj = thePrsObj;
1295 if(Prs3d_i* aPrs = dynamic_cast<Prs3d_i*>(VISU::GetServant(anObj).in())){
1296 ProcessVoidEvent(new TUpdateViewerEvent(myViewWindow,aPrs,eDisplay));
1300 void View3D_i::DisplayOnly (PrsObject_ptr thePrsObj)
1302 if(MYDEBUG) MESSAGE("View3D_i::DisplayOnly");
1303 CORBA::Object_ptr anObj = thePrsObj;
1304 if(Prs3d_i* aPrs = dynamic_cast<Prs3d_i*>(VISU::GetServant(anObj).in())){
1305 ProcessVoidEvent(new TUpdateViewerEvent(myViewWindow,aPrs,eDisplayOnly));
1309 void View3D_i::FitAll()
1311 ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>
1312 (GetViewWindow(myViewWindow), &SVTK_ViewWindow::onFitAll));
1316 void View3D_i::SetView (VISU::View3D::ViewType theType)
1319 case VISU::View3D::FRONT :
1320 ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>
1321 (GetViewWindow(myViewWindow), &SVTK_ViewWindow::onFrontView));
1323 case VISU::View3D::BACK :
1324 ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>
1325 (GetViewWindow(myViewWindow), &SVTK_ViewWindow::onBackView));
1327 case VISU::View3D::LEFT :
1328 ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>
1329 (GetViewWindow(myViewWindow),&SVTK_ViewWindow::onLeftView));
1331 case VISU::View3D::RIGHT :
1332 ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>
1333 (GetViewWindow(myViewWindow),&SVTK_ViewWindow::onRightView));
1335 case VISU::View3D::TOP :
1336 ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>
1337 (GetViewWindow(myViewWindow),&SVTK_ViewWindow::onTopView));
1339 case VISU::View3D::BOTTOM :
1340 ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>
1341 (GetViewWindow(myViewWindow),&SVTK_ViewWindow::onBottomView));
1347 class TSet3DViewParamEvent: public SALOME_Event
1350 typedef void (*TFun)(SUIT_ViewWindow* theStudyFrame, const CORBA::Double theParam[3]);
1351 TSet3DViewParamEvent (TFun theFun,
1352 SUIT_ViewWindow* theStudyFrame,
1353 const CORBA::Double theParam[3]):
1355 myViewWindow(theStudyFrame),
1358 virtual void Execute(){
1359 myFun(myViewWindow,myParam);
1363 SUIT_ViewWindow* myViewWindow;
1364 const CORBA::Double* myParam;
1367 void View3D_i::SetPointOfView (SUIT_ViewWindow* theStudyFrame,
1368 const CORBA::Double thePosition[3])
1370 GetCamera(theStudyFrame)->SetPosition(thePosition);
1373 void View3D_i::SetPointOfView (const VISU::View3D::XYZ thePosition)
1375 if(MYDEBUG) MESSAGE("View3D_i::SetPointOfView");
1376 ProcessVoidEvent(new TSet3DViewParamEvent(&SetPointOfView,myViewWindow,thePosition));
1379 void View3D_i::GetPointOfView (SUIT_ViewWindow* theStudyFrame,
1380 CORBA::Double thePosition[3])
1382 GetCamera(theStudyFrame)->GetPosition(thePosition);
1385 VISU::View3D::XYZ_slice* View3D_i::GetPointOfView()
1387 if(MYDEBUG) MESSAGE("View3D_i::GetPointOfView");
1388 CORBA::Double aPosition[3];
1389 GetPointOfView(myViewWindow,aPosition);
1390 return VISU::View3D::XYZ_dup(aPosition);
1393 void View3D_i::SetViewUp (SUIT_ViewWindow* theStudyFrame,
1394 const CORBA::Double theViewUp[3])
1396 GetCamera(theStudyFrame)->SetViewUp(theViewUp);
1399 void View3D_i::SetViewUp (const VISU::View3D::XYZ theViewUp)
1401 if(MYDEBUG) MESSAGE("View3D_i::SetViewUp");
1402 ProcessVoidEvent(new TSet3DViewParamEvent(&SetViewUp,myViewWindow,theViewUp));
1405 void View3D_i::GetViewUp (SUIT_ViewWindow* theStudyFrame,
1406 CORBA::Double theViewUp[3])
1408 GetCamera(theStudyFrame)->GetViewUp(theViewUp);
1411 VISU::View3D::XYZ_slice* View3D_i::GetViewUp()
1413 if(MYDEBUG) MESSAGE("View3D_i::GetViewUp");
1414 CORBA::Double aViewUp[3];
1415 GetCamera(myViewWindow)->GetViewUp(aViewUp);
1416 return VISU::View3D::XYZ_dup(aViewUp);
1419 void View3D_i::SetFocalPoint (SUIT_ViewWindow* theStudyFrame,
1420 const CORBA::Double theFocalPnt[3])
1422 GetCamera(theStudyFrame)->SetFocalPoint(theFocalPnt);
1425 void View3D_i::SetFocalPoint (const VISU::View3D::XYZ theCoord)
1427 if(MYDEBUG) MESSAGE("View3D_i::SetFocalPoint");
1428 ProcessVoidEvent(new TSet3DViewParamEvent(&SetFocalPoint,myViewWindow,theCoord));
1432 void View3D_i::GetFocalPoint (SUIT_ViewWindow* theStudyFrame,
1433 CORBA::Double theFocalPnt[3])
1435 GetCamera(theStudyFrame)->GetFocalPoint(theFocalPnt);
1438 VISU::View3D::XYZ_slice* View3D_i::GetFocalPoint()
1440 if(MYDEBUG) MESSAGE("View3D_i::GetFocalPoint");
1441 CORBA::Double aFocalPnt[3];
1442 GetFocalPoint(myViewWindow,aFocalPnt);
1443 return VISU::View3D::XYZ_dup(aFocalPnt);
1446 class TSetViewParamEvent: public SALOME_Event
1449 typedef void (*TFun)(SUIT_ViewWindow* theStudyFrame, CORBA::Double theParam);
1450 TSetViewParamEvent (TFun theFun,
1451 SUIT_ViewWindow* theStudyFrame,
1452 CORBA::Double theParam):
1454 myViewWindow(theStudyFrame),
1457 virtual void Execute()
1459 myFun(myViewWindow,myParam);
1463 SUIT_ViewWindow* myViewWindow;
1464 CORBA::Double myParam;
1467 void View3D_i::SetParallelScale (SUIT_ViewWindow* theStudyFrame,
1468 CORBA::Double theScale)
1470 GetCamera(theStudyFrame)->SetParallelScale(theScale);
1473 void View3D_i::SetParallelScale (CORBA::Double theScale)
1475 if(MYDEBUG) MESSAGE("View3D_i::SetParallelScale");
1476 ProcessVoidEvent(new TSetViewParamEvent(&SetParallelScale,myViewWindow,theScale));
1479 CORBA::Double View3D_i::GetParallelScale (SUIT_ViewWindow* theStudyFrame)
1481 return GetCamera(theStudyFrame)->GetParallelScale();
1484 CORBA::Double View3D_i::GetParallelScale()
1486 if(MYDEBUG) MESSAGE("View3D_i::GetParallelScale");
1487 return GetParallelScale(myViewWindow);
1490 void View3D_i::ScaleView (SUIT_ViewWindow* theStudyFrame,
1491 VISU::View3D::Axis theAxis, CORBA::Double theParam)
1493 SVTK_ViewWindow* aViewFrame = GetViewWindow(theStudyFrame);
1494 double aScaleFactor[3];
1495 aViewFrame->GetScale(aScaleFactor);
1496 aScaleFactor[theAxis] = theParam;
1497 aViewFrame->SetScale(aScaleFactor);
1500 void SetScaleView (SUIT_ViewWindow* theStudyFrame, const CORBA::Double theScale[3])
1502 double aScale[3] = {theScale[0], theScale[1], theScale[2]};
1503 GetViewWindow(theStudyFrame)->SetScale(aScale);
1506 void View3D_i::ScaleView(VISU::View3D::Axis theAxis, CORBA::Double theParam)
1508 if(MYDEBUG) MESSAGE("View3D_i::ScaleView");
1510 GetViewWindow(myViewWindow)->GetScale(aScale);
1511 aScale[theAxis] = theParam;
1512 ProcessVoidEvent(new TSet3DViewParamEvent(&SetScaleView,myViewWindow,aScale));
1515 void View3D_i::RemoveScale()
1517 if(MYDEBUG) MESSAGE("View3D_i::RemoveScale");
1518 double aScale[3] = {1.0, 1.0, 1.0};
1519 ProcessVoidEvent(new TSet3DViewParamEvent(&SetScaleView,myViewWindow,aScale));