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>
23 //ASL: Temporary commented in order to avoir dependency on SALOMEDS
25 //#include "SALOMEDSClient.hxx"
26 //#include "SALOMEDS_StudyManager.hxx"
28 // in order NOT TO link with SalomeApp, here the code returns SALOMEDS_Study.
29 // SalomeApp_Study::studyDS() does it as well, but -- here it is retrieved from
30 // SALOMEDS::StudyManager - no linkage with SalomeApp.
32 /*static _PTR(Study) getStudyDS()
34 SALOMEDSClient_Study* aStudy = NULL;
35 _PTR(StudyManager) aMgr( new SALOMEDS_StudyManager() );
37 // get id of SUIT_Study, if it's a SalomeApp_Study, it will return
38 // id of its underlying SALOMEDS::Study
39 SUIT_Application* app = SUIT_Session::session()->activeApplication();
40 if ( !app ) return _PTR(Study)(aStudy);
41 SUIT_Study* stud = app->activeStudy();
42 if ( !stud ) return _PTR(Study)(aStudy);
43 const int id = stud->id(); // virtual method, must return SALOMEDS_Study id
44 // get SALOMEDS_Study with this id from StudyMgr
45 return aMgr->GetStudyByID( id );
48 //=================================================================================
49 // SPlot2d_Viewer implementation
50 //=================================================================================
55 SPlot2d_Viewer::SPlot2d_Viewer( bool theAutoDel )
56 : Plot2d_Viewer( theAutoDel )
63 SPlot2d_Viewer::~SPlot2d_Viewer()
68 Renames curve if it is found
70 void SPlot2d_Viewer::rename( const Handle(SALOME_InteractiveObject)& IObject,
71 const QString& newName, Plot2d_ViewFrame* fr )
73 Plot2d_ViewFrame* aViewFrame = fr ? fr : getActiveViewFrame();
77 QIntDictIterator<Plot2d_Curve> it( aViewFrame->getCurves() );
78 for( ; it.current(); ++it )
80 SPlot2d_Curve* aCurve = dynamic_cast<SPlot2d_Curve*>( it.current() );
81 if( aCurve && aCurve->hasIO() && aCurve->getIO()->isSame( IObject ) )
83 aCurve->setVerTitle( newName );
84 int key = aViewFrame->hasCurve( aCurve );
86 aViewFrame->setCurveTitle( key, newName );
89 if( aCurve && aCurve->hasTableIO() && aCurve->getTableIO()->isSame( IObject ) )
90 aCurve->getTableIO()->setName( newName.latin1() );
92 aViewFrame->updateTitles();
95 void SPlot2d_Viewer::renameAll( const Handle(SALOME_InteractiveObject)& IObj, const QString& name )
97 SUIT_ViewManager* vm = getViewManager();
100 const QPtrVector<SUIT_ViewWindow>& wnds = vm->getViews();
101 for( int i=0; i<wnds.size(); i++ )
103 Plot2d_ViewWindow* pwnd = dynamic_cast<Plot2d_ViewWindow*>( wnds.at( i ) );
104 rename( IObj, name, pwnd->getViewFrame() );
110 Returns true if interactive object is presented in the viewer
112 bool SPlot2d_Viewer::isInViewer( const Handle(SALOME_InteractiveObject)& IObject )
114 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
115 if(aViewFrame == NULL) return 0;
117 if( getCurveByIO( IObject ) != NULL )
120 if(!IObject.IsNull()){
121 QIntDictIterator<Plot2d_Curve> it(aViewFrame->getCurves());
122 for(; it.current();++it) {
123 SPlot2d_Curve* aCurve = dynamic_cast<SPlot2d_Curve*>(it.current());
124 if(aCurve->hasIO() && aCurve->getTableIO()->isSame(IObject))
134 Actually this method just re-displays curves which refers to the <IObject>
136 void SPlot2d_Viewer::Display( const Handle(SALOME_InteractiveObject)& IObject, bool update )
138 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
139 if(aViewFrame == NULL) return;
141 SPlot2d_Curve* curve = getCurveByIO( IObject );
143 aViewFrame->updateCurve( curve, update );
147 Actually this method just erases all curves which don't refer to <IOBject>
148 and re-displays curve which is of <IObject>
150 void SPlot2d_Viewer::DisplayOnly( const Handle(SALOME_InteractiveObject)& IObject )
152 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
153 if(aViewFrame == NULL) return;
155 Plot2d_Curve* curve = getCurveByIO( IObject );
156 QIntDictIterator<Plot2d_Curve> it( aViewFrame->getCurves() );
157 for ( ; it.current(); ++it ) {
158 if(it.current() != curve)
159 aViewFrame->eraseCurve( curve );
161 aViewFrame->updateCurve( curve, false );
164 aViewFrame->Repaint();
168 Removes from the viewer the curves which refer to <IObject>
170 void SPlot2d_Viewer::Erase( const Handle(SALOME_InteractiveObject)& IObject, bool update )
172 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
173 if(aViewFrame == NULL) return;
175 SPlot2d_Curve* curve = getCurveByIO( IObject );
177 aViewFrame->eraseCurve( curve, update );
179 // it can be table or container object selected
180 //ASL: Temporary commented in order to avoid dependency on SALOMEDS
181 /* _PTR(Study) aStudy = getStudyDS();
182 _PTR(SObject) aSO = aStudy->FindObjectID(IObject->getEntry());
184 _PTR(ChildIterator) aIter = aStudy->NewChildIterator( aSO );
185 for ( ; aIter->More(); aIter->Next() ) {
186 _PTR(SObject) aChildSO = aIter->Value();
188 if ( aChildSO->ReferencedObject( refSO ) && refSO )
190 curve = getCurveByIO( new SALOME_InteractiveObject( aChildSO->GetID().c_str(), "") );
192 aViewFrame->eraseCurve( curve, update );
200 Removes all curves from the view
202 void SPlot2d_Viewer::EraseAll(const bool /*forced*/)
204 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
205 if(aViewFrame) aViewFrame->EraseAll();
209 Redraws Viewer contents
211 void SPlot2d_Viewer::Repaint()
213 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
214 if(aViewFrame) aViewFrame->Repaint();
217 //==========================================================
219 * SPlot2d_Viewer::Display
220 * Display presentation
222 //==========================================================
223 void SPlot2d_Viewer::Display( const SALOME_Prs2d* prs )
225 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
226 Plot2d_Prs* aPrs = dynamic_cast<Plot2d_Prs*>(const_cast<SALOME_Prs2d*>(prs));
227 if(aViewFrame && aPrs) aViewFrame->Display(aPrs);
230 //==========================================================
232 * SPlot2d_Viewer::Erase
235 //==========================================================
236 void SPlot2d_Viewer::Erase( const SALOME_Prs2d* prs, const bool )
238 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
239 Plot2d_Prs* aPrs = dynamic_cast<Plot2d_Prs*>(const_cast<SALOME_Prs2d*>(prs));
240 if(aViewFrame && aPrs) aViewFrame->Erase(aPrs);
243 //==========================================================
245 * SPlot2d_Viewer::CreatePrs
246 * Create presentation by entry
248 //==========================================================
249 SALOME_Prs* SPlot2d_Viewer::CreatePrs( const char* entry )
251 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
254 Plot2d_Prs* prs = aViewFrame->CreatePrs(entry);
256 return new SPlot2d_Prs( prs );
262 //==========================================================
264 * SPlot2d_Viewer::BeforeDisplay
265 * Axiluary method called before displaying of objects
267 //==========================================================
268 void SPlot2d_Viewer::BeforeDisplay( SALOME_Displayer* d )
270 d->BeforeDisplay( this, SALOME_Plot2dViewType() );
273 //==========================================================
275 * SPlot2d_Viewer::AfterDisplay
276 * Axiluary method called after displaying of objects
278 //==========================================================
279 void SPlot2d_Viewer::AfterDisplay( SALOME_Displayer* d )
281 d->AfterDisplay( this, SALOME_Plot2dViewType() );
285 Returns true if interactive object is presented in the viewer and displayed
287 bool SPlot2d_Viewer::isVisible( const Handle(SALOME_InteractiveObject)& IObject )
289 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
290 if(aViewFrame == NULL) return false;
292 SPlot2d_Curve* curve = getCurveByIO( IObject );
293 return aViewFrame->isVisible( curve );
297 Return interactive obeject if is presented in the viewer
299 Handle(SALOME_InteractiveObject) SPlot2d_Viewer::FindIObject( const char* Entry )
301 Handle(SALOME_InteractiveObject) anIO;
302 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
303 if(aViewFrame == NULL) return anIO;
305 QIntDictIterator<Plot2d_Curve> it( aViewFrame->getCurves() );
306 for ( ; it.current(); ++it ) {
307 SPlot2d_Curve* aCurve = dynamic_cast<SPlot2d_Curve*>(it.current());
308 if ( aCurve->hasIO() && !strcmp( aCurve->getIO()->getEntry(), Entry ) ) {
309 anIO = aCurve->getIO();
316 //==========================================================
318 * SPlot2d_Viewer::getActiveViewFrame
319 * Returns an active Plot2d ViewFrame or NULL
321 //==========================================================
322 Plot2d_ViewFrame* SPlot2d_Viewer::getActiveViewFrame()
324 SUIT_ViewManager* aViewMgr = getViewManager();
326 Plot2d_ViewWindow* aViewWnd = dynamic_cast<Plot2d_ViewWindow*>(aViewMgr->getActiveView());
328 return aViewWnd->getViewFrame();
334 SPlot2d_Curve* SPlot2d_Viewer::getCurveByIO( const Handle(SALOME_InteractiveObject)& theIObject,
335 Plot2d_ViewFrame* fr )
337 if ( !theIObject.IsNull() ) {
338 Plot2d_ViewFrame* aViewFrame = fr ? fr : getActiveViewFrame();
340 QIntDictIterator<Plot2d_Curve> it( aViewFrame->getCurves() );
341 for ( ; it.current(); ++it ) {
342 SPlot2d_Curve* aCurve = dynamic_cast<SPlot2d_Curve*>(it.current());
344 if ( aCurve->hasIO() && aCurve->getIO()->isSame( theIObject ) )
353 void SPlot2d_Viewer::onCloneView( Plot2d_ViewFrame* clonedVF, Plot2d_ViewFrame* newVF )
355 if( !clonedVF || !newVF )
358 // 1) Copy all properties of view
360 newVF->copyPreferences( clonedVF );
362 // 2) Display all curves displayed in cloned view
364 QList<Plot2d_Curve> aCurves;
365 clonedVF->getCurves( aCurves );
366 QList<Plot2d_Curve>::const_iterator anIt = aCurves.begin(), aLast = aCurves.end();
368 for( ; anIt!=aLast; anIt++ )
369 if( clonedVF->isVisible( *anIt ) )
370 newVF->displayCurve( *anIt, false );