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 //ASL: Temporary commented in order to avoir dependency on SALOMEDS
26 //#include "SALOMEDSClient.hxx"
27 //#include "SALOMEDS_StudyManager.hxx"
29 // in order NOT TO link with SalomeApp, here the code returns SALOMEDS_Study.
30 // SalomeApp_Study::studyDS() does it as well, but -- here it is retrieved from
31 // SALOMEDS::StudyManager - no linkage with SalomeApp.
33 /*static _PTR(Study) getStudyDS()
35 SALOMEDSClient_Study* aStudy = NULL;
36 _PTR(StudyManager) aMgr( new SALOMEDS_StudyManager() );
38 // get id of SUIT_Study, if it's a SalomeApp_Study, it will return
39 // id of its underlying SALOMEDS::Study
40 SUIT_Application* app = SUIT_Session::session()->activeApplication();
41 if ( !app ) return _PTR(Study)(aStudy);
42 SUIT_Study* stud = app->activeStudy();
43 if ( !stud ) return _PTR(Study)(aStudy);
44 const int id = stud->id(); // virtual method, must return SALOMEDS_Study id
45 // get SALOMEDS_Study with this id from StudyMgr
46 return aMgr->GetStudyByID( id );
49 //=================================================================================
50 // SPlot2d_Viewer implementation
51 //=================================================================================
56 SPlot2d_Viewer::SPlot2d_Viewer( bool theAutoDel )
57 : Plot2d_Viewer( theAutoDel )
64 SPlot2d_Viewer::~SPlot2d_Viewer()
69 Renames curve if it is found
71 void SPlot2d_Viewer::rename( const Handle(SALOME_InteractiveObject)& IObject, QString newName )
73 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
74 if(aViewFrame == NULL) return;
76 Plot2d_Curve* curve = getCurveByIO( IObject );
78 curve->setVerTitle( newName );
79 int key = aViewFrame->hasCurve( curve );
81 aViewFrame->setCurveTitle( key, newName );
87 Returns true if interactive object is presented in the viewer
89 bool SPlot2d_Viewer::isInViewer( const Handle(SALOME_InteractiveObject)& IObject )
91 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
92 if(aViewFrame == NULL) return 0;
94 if( getCurveByIO( IObject ) != NULL )
97 if(!IObject.IsNull()){
98 QIntDictIterator<Plot2d_Curve> it(aViewFrame->getCurves());
99 for(; it.current();++it) {
100 SPlot2d_Curve* aCurve = dynamic_cast<SPlot2d_Curve*>(it.current());
101 if(aCurve->hasIO() && aCurve->getTableIO()->isSame(IObject))
111 Actually this method just re-displays curves which refers to the <IObject>
113 void SPlot2d_Viewer::Display( const Handle(SALOME_InteractiveObject)& IObject, bool update )
115 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
116 if(aViewFrame == NULL) return;
118 SPlot2d_Curve* curve = getCurveByIO( IObject );
120 aViewFrame->updateCurve( curve, update );
124 Actually this method just erases all curves which don't refer to <IOBject>
125 and re-displays curve which is of <IObject>
127 void SPlot2d_Viewer::DisplayOnly( const Handle(SALOME_InteractiveObject)& IObject )
129 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
130 if(aViewFrame == NULL) return;
132 Plot2d_Curve* curve = getCurveByIO( IObject );
133 QIntDictIterator<Plot2d_Curve> it( aViewFrame->getCurves() );
134 for ( ; it.current(); ++it ) {
135 if(it.current() != curve)
136 aViewFrame->eraseCurve( curve );
138 aViewFrame->updateCurve( curve, false );
141 aViewFrame->Repaint();
145 Removes from the viewer the curves which refer to <IObject>
147 void SPlot2d_Viewer::Erase( const Handle(SALOME_InteractiveObject)& IObject, bool update )
149 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
150 if(aViewFrame == NULL) return;
152 SPlot2d_Curve* curve = getCurveByIO( IObject );
154 aViewFrame->eraseCurve( curve, update );
156 // it can be table or container object selected
157 //ASL: Temporary commented in order to avoid dependency on SALOMEDS
158 /* _PTR(Study) aStudy = getStudyDS();
159 _PTR(SObject) aSO = aStudy->FindObjectID(IObject->getEntry());
161 _PTR(ChildIterator) aIter = aStudy->NewChildIterator( aSO );
162 for ( ; aIter->More(); aIter->Next() ) {
163 _PTR(SObject) aChildSO = aIter->Value();
165 if ( aChildSO->ReferencedObject( refSO ) && refSO )
167 curve = getCurveByIO( new SALOME_InteractiveObject( aChildSO->GetID().c_str(), "") );
169 aViewFrame->eraseCurve( curve, update );
177 Removes all curves from the view
179 void SPlot2d_Viewer::EraseAll(const bool /*forced*/)
181 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
182 if(aViewFrame) aViewFrame->EraseAll();
186 Redraws Viewer contents
188 void SPlot2d_Viewer::Repaint()
190 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
191 if(aViewFrame) aViewFrame->Repaint();
194 //==========================================================
196 * SPlot2d_Viewer::Display
197 * Display presentation
199 //==========================================================
200 void SPlot2d_Viewer::Display( const SALOME_Prs2d* prs )
202 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
203 Plot2d_Prs* aPrs = dynamic_cast<Plot2d_Prs*>(const_cast<SALOME_Prs2d*>(prs));
204 if(aViewFrame && aPrs) aViewFrame->Display(aPrs);
207 //==========================================================
209 * SPlot2d_Viewer::Erase
212 //==========================================================
213 void SPlot2d_Viewer::Erase( const SALOME_Prs2d* prs, const bool )
215 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
216 Plot2d_Prs* aPrs = dynamic_cast<Plot2d_Prs*>(const_cast<SALOME_Prs2d*>(prs));
217 if(aViewFrame && aPrs) aViewFrame->Erase(aPrs);
220 //==========================================================
222 * SPlot2d_Viewer::CreatePrs
223 * Create presentation by entry
225 //==========================================================
226 SALOME_Prs* SPlot2d_Viewer::CreatePrs( const char* entry )
228 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
231 Plot2d_Prs* prs = aViewFrame->CreatePrs(entry);
233 return new SPlot2d_Prs( prs );
239 //==========================================================
241 * SPlot2d_Viewer::BeforeDisplay
242 * Axiluary method called before displaying of objects
244 //==========================================================
245 void SPlot2d_Viewer::BeforeDisplay( SALOME_Displayer* d )
247 d->BeforeDisplay( this, SALOME_Plot2dViewType() );
250 //==========================================================
252 * SPlot2d_Viewer::AfterDisplay
253 * Axiluary method called after displaying of objects
255 //==========================================================
256 void SPlot2d_Viewer::AfterDisplay( SALOME_Displayer* d )
258 d->AfterDisplay( this, SALOME_Plot2dViewType() );
262 Returns true if interactive object is presented in the viewer and displayed
264 bool SPlot2d_Viewer::isVisible( const Handle(SALOME_InteractiveObject)& IObject )
266 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
267 if(aViewFrame == NULL) return false;
269 SPlot2d_Curve* curve = getCurveByIO( IObject );
270 return aViewFrame->isVisible( curve );
274 Return interactive obeject if is presented in the viewer
276 Handle(SALOME_InteractiveObject) SPlot2d_Viewer::FindIObject( const char* Entry )
278 Handle(SALOME_InteractiveObject) anIO;
279 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
280 if(aViewFrame == NULL) return anIO;
282 QIntDictIterator<Plot2d_Curve> it( aViewFrame->getCurves() );
283 for ( ; it.current(); ++it ) {
284 SPlot2d_Curve* aCurve = dynamic_cast<SPlot2d_Curve*>(it.current());
285 if ( aCurve->hasIO() && !strcmp( aCurve->getIO()->getEntry(), Entry ) ) {
286 anIO = aCurve->getIO();
293 //==========================================================
295 * SPlot2d_Viewer::getActiveViewFrame
296 * Returns an active Plot2d ViewFrame or NULL
298 //==========================================================
299 Plot2d_ViewFrame* SPlot2d_Viewer::getActiveViewFrame()
301 SUIT_ViewManager* aViewMgr = getViewManager();
303 Plot2d_ViewWindow* aViewWnd = dynamic_cast<Plot2d_ViewWindow*>(aViewMgr->getActiveView());
305 return aViewWnd->getViewFrame();
311 SPlot2d_Curve* SPlot2d_Viewer::getCurveByIO( const Handle(SALOME_InteractiveObject)& theIObject )
313 if ( !theIObject.IsNull() ) {
314 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
316 QIntDictIterator<Plot2d_Curve> it( aViewFrame->getCurves() );
317 for ( ; it.current(); ++it ) {
318 SPlot2d_Curve* aCurve = dynamic_cast<SPlot2d_Curve*>(it.current());
320 if ( aCurve->hasIO() && aCurve->getIO()->isSame( theIObject ) )
329 void SPlot2d_Viewer::onCloneView( Plot2d_ViewFrame* clonedVF, Plot2d_ViewFrame* newVF )
331 if( !clonedVF || !newVF )
334 // 1) Copy all properties of view
336 newVF->copyPreferences( clonedVF );
338 // 2) Display all curves displayed in cloned view
340 QList<Plot2d_Curve> aCurves;
341 clonedVF->getCurves( aCurves );
342 QList<Plot2d_Curve>::const_iterator anIt = aCurves.begin(), aLast = aCurves.end();
344 for( ; anIt!=aLast; anIt++ )
345 if( clonedVF->isVisible( *anIt ) )
346 newVF->displayCurve( *anIt, false );