1 // File : SPlot2d_Viewer.cxx
2 // Author : Sergey RUIN
5 #include "SPlot2d_ViewModel.h"
7 #include "SPlot2d_Prs.h"
8 #include "SUIT_Session.h"
9 #include "SUIT_Application.h"
11 #include "utilities.h"
12 #include "qapplication.h"
14 #include <qtoolbutton.h>
16 #include <qcolordialog.h>
18 #include <qwt_plot_canvas.h>
20 #include "utilities.h"
24 #include "SALOMEDSClient.hxx"
25 #include "SALOMEDS_StudyManager.hxx"
27 // in order NOT TO link with SalomeApp, here the code returns SALOMEDS_Study.
28 // SalomeApp_Study::studyDS() does it as well, but -- here it is retrieved from
29 // SALOMEDS::StudyManager - no linkage with SalomeApp.
31 static _PTR(Study) getStudyDS()
33 SALOMEDSClient_Study* aStudy = NULL;
34 _PTR(StudyManager) aMgr( new SALOMEDS_StudyManager() );
36 // get id of SUIT_Study, if it's a SalomeApp_Study, it will return
37 // id of its underlying SALOMEDS::Study
38 SUIT_Application* app = SUIT_Session::session()->activeApplication();
39 if ( !app ) return _PTR(Study)(aStudy);
40 SUIT_Study* stud = app->activeStudy();
41 if ( !stud ) return _PTR(Study)(aStudy);
42 const int id = stud->id(); // virtual method, must return SALOMEDS_Study id
43 // get SALOMEDS_Study with this id from StudyMgr
44 return aMgr->GetStudyByID( id );
47 //=================================================================================
48 // SPlot2d_Viewer implementation
49 //=================================================================================
54 SPlot2d_Viewer::SPlot2d_Viewer( bool theAutoDel )
55 : Plot2d_Viewer( theAutoDel )
62 SPlot2d_Viewer::~SPlot2d_Viewer()
67 Renames curve if it is found
69 void SPlot2d_Viewer::rename( const Handle(SALOME_InteractiveObject)& IObject, QString newName )
71 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
72 if(aViewFrame == NULL) return;
74 Plot2d_Curve* curve = getCurveByIO( IObject );
76 curve->setVerTitle( newName );
77 int key = aViewFrame->hasCurve( curve );
79 aViewFrame->setCurveTitle( key, newName );
85 Returns true if interactive object is presented in the viewer
87 bool SPlot2d_Viewer::isInViewer( const Handle(SALOME_InteractiveObject)& IObject )
89 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
90 if(aViewFrame == NULL) return 0;
92 if( getCurveByIO( IObject ) != NULL )
95 if(!IObject.IsNull()){
96 QIntDictIterator<Plot2d_Curve> it(aViewFrame->getCurves());
97 for(; it.current();++it) {
98 SPlot2d_Curve* aCurve = dynamic_cast<SPlot2d_Curve*>(it.current());
99 if(aCurve->hasIO() && aCurve->getTableIO()->isSame(IObject))
109 Actually this method just re-displays curves which refers to the <IObject>
111 void SPlot2d_Viewer::Display( const Handle(SALOME_InteractiveObject)& IObject, bool update )
113 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
114 if(aViewFrame == NULL) return;
116 SPlot2d_Curve* curve = getCurveByIO( IObject );
118 aViewFrame->updateCurve( curve, update );
122 Actually this method just erases all curves which don't refer to <IOBject>
123 and re-displays curve which is of <IObject>
125 void SPlot2d_Viewer::DisplayOnly( const Handle(SALOME_InteractiveObject)& IObject )
127 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
128 if(aViewFrame == NULL) return;
130 Plot2d_Curve* curve = getCurveByIO( IObject );
131 QIntDictIterator<Plot2d_Curve> it( aViewFrame->getCurves() );
132 for ( ; it.current(); ++it ) {
133 if(it.current() != curve)
134 aViewFrame->eraseCurve( curve );
136 aViewFrame->updateCurve( curve, false );
139 aViewFrame->Repaint();
143 Removes from the viewer the curves which refer to <IObject>
145 void SPlot2d_Viewer::Erase( const Handle(SALOME_InteractiveObject)& IObject, bool update )
147 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
148 if(aViewFrame == NULL) return;
150 SPlot2d_Curve* curve = getCurveByIO( IObject );
152 aViewFrame->eraseCurve( curve, update );
154 // it can be table or container object selected
155 _PTR(Study) aStudy = getStudyDS();
156 _PTR(SObject) aSO = aStudy->FindObjectID(IObject->getEntry());
158 _PTR(ChildIterator) aIter = aStudy->NewChildIterator( aSO );
159 for ( ; aIter->More(); aIter->Next() ) {
160 _PTR(SObject) aChildSO = aIter->Value();
162 if ( aChildSO->ReferencedObject( refSO ) && refSO )
164 curve = getCurveByIO( new SALOME_InteractiveObject( aChildSO->GetID().c_str(), "") );
166 aViewFrame->eraseCurve( curve, update );
174 Removes all curves from the view
176 void SPlot2d_Viewer::EraseAll(const bool /*forced*/)
178 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
179 if(aViewFrame) aViewFrame->EraseAll();
183 Redraws Viewer contents
185 void SPlot2d_Viewer::Repaint()
187 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
188 if(aViewFrame) aViewFrame->Repaint();
191 //==========================================================
193 * SPlot2d_Viewer::Display
194 * Display presentation
196 //==========================================================
197 void SPlot2d_Viewer::Display( const SALOME_Prs2d* prs )
199 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
200 Plot2d_Prs* aPrs = dynamic_cast<Plot2d_Prs*>(const_cast<SALOME_Prs2d*>(prs));
201 if(aViewFrame && aPrs) aViewFrame->Display(aPrs);
204 //==========================================================
206 * SPlot2d_Viewer::Erase
209 //==========================================================
210 void SPlot2d_Viewer::Erase( const SALOME_Prs2d* prs, const bool )
212 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
213 Plot2d_Prs* aPrs = dynamic_cast<Plot2d_Prs*>(const_cast<SALOME_Prs2d*>(prs));
214 if(aViewFrame && aPrs) aViewFrame->Erase(aPrs);
217 //==========================================================
219 * SPlot2d_Viewer::CreatePrs
220 * Create presentation by entry
222 //==========================================================
223 SALOME_Prs* SPlot2d_Viewer::CreatePrs( const char* entry )
225 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
227 return new SPlot2d_Prs(aViewFrame->CreatePrs(entry));
233 //==========================================================
235 * SPlot2d_Viewer::BeforeDisplay
236 * Axiluary method called before displaying of objects
238 //==========================================================
239 void SPlot2d_Viewer::BeforeDisplay( SALOME_Displayer* d )
241 d->BeforeDisplay( this, SALOME_Plot2dViewType() );
244 //==========================================================
246 * SPlot2d_Viewer::AfterDisplay
247 * Axiluary method called after displaying of objects
249 //==========================================================
250 void SPlot2d_Viewer::AfterDisplay( SALOME_Displayer* d )
252 d->AfterDisplay( this, SALOME_Plot2dViewType() );
256 Returns true if interactive object is presented in the viewer and displayed
258 bool SPlot2d_Viewer::isVisible( const Handle(SALOME_InteractiveObject)& IObject )
260 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
261 if(aViewFrame == NULL) return false;
263 SPlot2d_Curve* curve = getCurveByIO( IObject );
264 return aViewFrame->isVisible( curve );
268 Return interactive obeject if is presented in the viewer
270 Handle(SALOME_InteractiveObject) SPlot2d_Viewer::FindIObject( const char* Entry )
272 Handle(SALOME_InteractiveObject) anIO;
273 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
274 if(aViewFrame == NULL) return anIO;
276 QIntDictIterator<Plot2d_Curve> it( aViewFrame->getCurves() );
277 for ( ; it.current(); ++it ) {
278 SPlot2d_Curve* aCurve = dynamic_cast<SPlot2d_Curve*>(it.current());
279 if ( aCurve->hasIO() && !strcmp( aCurve->getIO()->getEntry(), Entry ) ) {
280 anIO = aCurve->getIO();
287 //==========================================================
289 * SPlot2d_Viewer::getActiveViewFrame
290 * Returns an active Plot2d ViewFrame or NULL
292 //==========================================================
293 Plot2d_ViewFrame* SPlot2d_Viewer::getActiveViewFrame()
295 SUIT_ViewManager* aViewMgr = getViewManager();
297 Plot2d_ViewWindow* aViewWnd = dynamic_cast<Plot2d_ViewWindow*>(aViewMgr->getActiveView());
299 return aViewWnd->getViewFrame();
305 SPlot2d_Curve* SPlot2d_Viewer::getCurveByIO( const Handle(SALOME_InteractiveObject)& theIObject )
307 if ( !theIObject.IsNull() ) {
308 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
310 QIntDictIterator<Plot2d_Curve> it( aViewFrame->getCurves() );
311 for ( ; it.current(); ++it ) {
312 SPlot2d_Curve* aCurve = dynamic_cast<SPlot2d_Curve*>(it.current());
314 if ( aCurve->hasIO() && aCurve->getIO()->isSame( theIObject ) )