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, QString newName )
72 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
73 if(aViewFrame == NULL) return;
75 Plot2d_Curve* curve = getCurveByIO( IObject );
77 curve->setVerTitle( newName );
78 int key = aViewFrame->hasCurve( curve );
80 aViewFrame->setCurveTitle( key, newName );
86 Returns true if interactive object is presented in the viewer
88 bool SPlot2d_Viewer::isInViewer( const Handle(SALOME_InteractiveObject)& IObject )
90 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
91 if(aViewFrame == NULL) return 0;
93 if( getCurveByIO( IObject ) != NULL )
96 if(!IObject.IsNull()){
97 QIntDictIterator<Plot2d_Curve> it(aViewFrame->getCurves());
98 for(; it.current();++it) {
99 SPlot2d_Curve* aCurve = dynamic_cast<SPlot2d_Curve*>(it.current());
100 if(aCurve->hasIO() && aCurve->getTableIO()->isSame(IObject))
110 Actually this method just re-displays curves which refers to the <IObject>
112 void SPlot2d_Viewer::Display( const Handle(SALOME_InteractiveObject)& IObject, bool update )
114 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
115 if(aViewFrame == NULL) return;
117 SPlot2d_Curve* curve = getCurveByIO( IObject );
119 aViewFrame->updateCurve( curve, update );
123 Actually this method just erases all curves which don't refer to <IOBject>
124 and re-displays curve which is of <IObject>
126 void SPlot2d_Viewer::DisplayOnly( const Handle(SALOME_InteractiveObject)& IObject )
128 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
129 if(aViewFrame == NULL) return;
131 Plot2d_Curve* curve = getCurveByIO( IObject );
132 QIntDictIterator<Plot2d_Curve> it( aViewFrame->getCurves() );
133 for ( ; it.current(); ++it ) {
134 if(it.current() != curve)
135 aViewFrame->eraseCurve( curve );
137 aViewFrame->updateCurve( curve, false );
140 aViewFrame->Repaint();
144 Removes from the viewer the curves which refer to <IObject>
146 void SPlot2d_Viewer::Erase( const Handle(SALOME_InteractiveObject)& IObject, bool update )
148 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
149 if(aViewFrame == NULL) return;
151 SPlot2d_Curve* curve = getCurveByIO( IObject );
153 aViewFrame->eraseCurve( curve, update );
155 // it can be table or container object selected
156 //ASL: Temporary commented in order to avoid dependency on SALOMEDS
157 /* _PTR(Study) aStudy = getStudyDS();
158 _PTR(SObject) aSO = aStudy->FindObjectID(IObject->getEntry());
160 _PTR(ChildIterator) aIter = aStudy->NewChildIterator( aSO );
161 for ( ; aIter->More(); aIter->Next() ) {
162 _PTR(SObject) aChildSO = aIter->Value();
164 if ( aChildSO->ReferencedObject( refSO ) && refSO )
166 curve = getCurveByIO( new SALOME_InteractiveObject( aChildSO->GetID().c_str(), "") );
168 aViewFrame->eraseCurve( curve, update );
176 Removes all curves from the view
178 void SPlot2d_Viewer::EraseAll(const bool /*forced*/)
180 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
181 if(aViewFrame) aViewFrame->EraseAll();
185 Redraws Viewer contents
187 void SPlot2d_Viewer::Repaint()
189 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
190 if(aViewFrame) aViewFrame->Repaint();
193 //==========================================================
195 * SPlot2d_Viewer::Display
196 * Display presentation
198 //==========================================================
199 void SPlot2d_Viewer::Display( const SALOME_Prs2d* prs )
201 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
202 Plot2d_Prs* aPrs = dynamic_cast<Plot2d_Prs*>(const_cast<SALOME_Prs2d*>(prs));
203 if(aViewFrame && aPrs) aViewFrame->Display(aPrs);
206 //==========================================================
208 * SPlot2d_Viewer::Erase
211 //==========================================================
212 void SPlot2d_Viewer::Erase( const SALOME_Prs2d* prs, const bool )
214 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
215 Plot2d_Prs* aPrs = dynamic_cast<Plot2d_Prs*>(const_cast<SALOME_Prs2d*>(prs));
216 if(aViewFrame && aPrs) aViewFrame->Erase(aPrs);
219 //==========================================================
221 * SPlot2d_Viewer::CreatePrs
222 * Create presentation by entry
224 //==========================================================
225 SALOME_Prs* SPlot2d_Viewer::CreatePrs( const char* entry )
227 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
230 Plot2d_Prs* prs = aViewFrame->CreatePrs(entry);
232 return new SPlot2d_Prs( prs );
238 //==========================================================
240 * SPlot2d_Viewer::BeforeDisplay
241 * Axiluary method called before displaying of objects
243 //==========================================================
244 void SPlot2d_Viewer::BeforeDisplay( SALOME_Displayer* d )
246 d->BeforeDisplay( this, SALOME_Plot2dViewType() );
249 //==========================================================
251 * SPlot2d_Viewer::AfterDisplay
252 * Axiluary method called after displaying of objects
254 //==========================================================
255 void SPlot2d_Viewer::AfterDisplay( SALOME_Displayer* d )
257 d->AfterDisplay( this, SALOME_Plot2dViewType() );
261 Returns true if interactive object is presented in the viewer and displayed
263 bool SPlot2d_Viewer::isVisible( const Handle(SALOME_InteractiveObject)& IObject )
265 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
266 if(aViewFrame == NULL) return false;
268 SPlot2d_Curve* curve = getCurveByIO( IObject );
269 return aViewFrame->isVisible( curve );
273 Return interactive obeject if is presented in the viewer
275 Handle(SALOME_InteractiveObject) SPlot2d_Viewer::FindIObject( const char* Entry )
277 Handle(SALOME_InteractiveObject) anIO;
278 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
279 if(aViewFrame == NULL) return anIO;
281 QIntDictIterator<Plot2d_Curve> it( aViewFrame->getCurves() );
282 for ( ; it.current(); ++it ) {
283 SPlot2d_Curve* aCurve = dynamic_cast<SPlot2d_Curve*>(it.current());
284 if ( aCurve->hasIO() && !strcmp( aCurve->getIO()->getEntry(), Entry ) ) {
285 anIO = aCurve->getIO();
292 //==========================================================
294 * SPlot2d_Viewer::getActiveViewFrame
295 * Returns an active Plot2d ViewFrame or NULL
297 //==========================================================
298 Plot2d_ViewFrame* SPlot2d_Viewer::getActiveViewFrame()
300 SUIT_ViewManager* aViewMgr = getViewManager();
302 Plot2d_ViewWindow* aViewWnd = dynamic_cast<Plot2d_ViewWindow*>(aViewMgr->getActiveView());
304 return aViewWnd->getViewFrame();
310 SPlot2d_Curve* SPlot2d_Viewer::getCurveByIO( const Handle(SALOME_InteractiveObject)& theIObject )
312 if ( !theIObject.IsNull() ) {
313 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
315 QIntDictIterator<Plot2d_Curve> it( aViewFrame->getCurves() );
316 for ( ; it.current(); ++it ) {
317 SPlot2d_Curve* aCurve = dynamic_cast<SPlot2d_Curve*>(it.current());
319 if ( aCurve->hasIO() && aCurve->getIO()->isSame( theIObject ) )
328 void SPlot2d_Viewer::onCloneView( Plot2d_ViewFrame* clonedVF, Plot2d_ViewFrame* newVF )
330 if( !clonedVF || !newVF )
333 // 1) Copy all properties of view
335 newVF->copyPreferences( clonedVF );
337 // 2) Display all curves displayed in cloned view
339 QList<Plot2d_Curve> aCurves;
340 clonedVF->getCurves( aCurves );
341 QList<Plot2d_Curve>::const_iterator anIt = aCurves.begin(), aLast = aCurves.end();
343 for( ; anIt!=aLast; anIt++ )
344 if( clonedVF->isVisible( *anIt ) )
345 newVF->displayCurve( *anIt, false );