1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/
19 // File : SPlot2d_Viewer.cxx
20 // Author : Sergey RUIN
23 #include "SPlot2d_ViewModel.h"
25 #include "SPlot2d_Prs.h"
26 #include "SUIT_Session.h"
27 #include "SUIT_Application.h"
29 //#include "utilities.h"
30 #include "qapplication.h"
32 #include <qtoolbutton.h>
34 #include <qcolordialog.h>
36 #include <qwt_plot_canvas.h>
41 //ASL: Temporary commented in order to avoir dependency on SALOMEDS
43 //#include "SALOMEDSClient.hxx"
44 //#include "SALOMEDS_StudyManager.hxx"
46 // in order NOT TO link with SalomeApp, here the code returns SALOMEDS_Study.
47 // SalomeApp_Study::studyDS() does it as well, but -- here it is retrieved from
48 // SALOMEDS::StudyManager - no linkage with SalomeApp.
50 /*static _PTR(Study) getStudyDS()
52 SALOMEDSClient_Study* aStudy = NULL;
53 _PTR(StudyManager) aMgr( new SALOMEDS_StudyManager() );
55 // get id of SUIT_Study, if it's a SalomeApp_Study, it will return
56 // id of its underlying SALOMEDS::Study
57 SUIT_Application* app = SUIT_Session::session()->activeApplication();
58 if ( !app ) return _PTR(Study)(aStudy);
59 SUIT_Study* stud = app->activeStudy();
60 if ( !stud ) return _PTR(Study)(aStudy);
61 const int id = stud->id(); // virtual method, must return SALOMEDS_Study id
62 // get SALOMEDS_Study with this id from StudyMgr
63 return aMgr->GetStudyByID( id );
66 //=================================================================================
67 // SPlot2d_Viewer implementation
68 //=================================================================================
73 SPlot2d_Viewer::SPlot2d_Viewer( bool theAutoDel )
74 : Plot2d_Viewer( theAutoDel )
81 SPlot2d_Viewer::~SPlot2d_Viewer()
86 Renames curve if it is found
88 void SPlot2d_Viewer::rename( const Handle(SALOME_InteractiveObject)& IObject,
89 const QString& newName, Plot2d_ViewFrame* fr )
91 Plot2d_ViewFrame* aViewFrame = fr ? fr : getActiveViewFrame();
95 QIntDictIterator<Plot2d_Curve> it( aViewFrame->getCurves() );
96 for( ; it.current(); ++it )
98 SPlot2d_Curve* aCurve = dynamic_cast<SPlot2d_Curve*>( it.current() );
99 if( aCurve && aCurve->hasIO() && aCurve->getIO()->isSame( IObject ) )
101 aCurve->setVerTitle( newName );
102 int key = aViewFrame->hasCurve( aCurve );
104 aViewFrame->setCurveTitle( key, newName );
107 if( aCurve && aCurve->hasTableIO() && aCurve->getTableIO()->isSame( IObject ) )
108 aCurve->getTableIO()->setName( newName.latin1() );
110 aViewFrame->updateTitles();
113 void SPlot2d_Viewer::renameAll( const Handle(SALOME_InteractiveObject)& IObj, const QString& name )
115 SUIT_ViewManager* vm = getViewManager();
118 const QPtrVector<SUIT_ViewWindow>& wnds = vm->getViews();
119 for( int i=0; i<wnds.size(); i++ )
121 Plot2d_ViewWindow* pwnd = dynamic_cast<Plot2d_ViewWindow*>( wnds.at( i ) );
122 rename( IObj, name, pwnd->getViewFrame() );
128 Returns true if interactive object is presented in the viewer
130 bool SPlot2d_Viewer::isInViewer( const Handle(SALOME_InteractiveObject)& IObject )
132 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
133 if(aViewFrame == NULL) return 0;
135 if( getCurveByIO( IObject ) != NULL )
138 if(!IObject.IsNull()){
139 QIntDictIterator<Plot2d_Curve> it(aViewFrame->getCurves());
140 for(; it.current();++it) {
141 SPlot2d_Curve* aCurve = dynamic_cast<SPlot2d_Curve*>(it.current());
142 if(aCurve->hasIO() && aCurve->getTableIO()->isSame(IObject))
152 Actually this method just re-displays curves which refers to the <IObject>
154 void SPlot2d_Viewer::Display( const Handle(SALOME_InteractiveObject)& IObject, bool update )
156 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
157 if(aViewFrame == NULL) return;
159 SPlot2d_Curve* curve = getCurveByIO( IObject );
161 aViewFrame->updateCurve( curve, update );
165 Actually this method just erases all curves which don't refer to <IOBject>
166 and re-displays curve which is of <IObject>
168 void SPlot2d_Viewer::DisplayOnly( const Handle(SALOME_InteractiveObject)& IObject )
170 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
171 if(aViewFrame == NULL) return;
173 Plot2d_Curve* curve = getCurveByIO( IObject );
174 QIntDictIterator<Plot2d_Curve> it( aViewFrame->getCurves() );
175 for ( ; it.current(); ++it ) {
176 if(it.current() != curve)
177 aViewFrame->eraseCurve( curve );
179 aViewFrame->updateCurve( curve, false );
182 aViewFrame->Repaint();
186 Removes from the viewer the curves which refer to <IObject>
188 void SPlot2d_Viewer::Erase( const Handle(SALOME_InteractiveObject)& IObject, bool update )
190 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
191 if(aViewFrame == NULL) return;
193 SPlot2d_Curve* curve = getCurveByIO( IObject );
195 aViewFrame->eraseCurve( curve, update );
197 // it can be table or container object selected
198 //ASL: Temporary commented in order to avoid dependency on SALOMEDS
199 /* _PTR(Study) aStudy = getStudyDS();
200 _PTR(SObject) aSO = aStudy->FindObjectID(IObject->getEntry());
202 _PTR(ChildIterator) aIter = aStudy->NewChildIterator( aSO );
203 for ( ; aIter->More(); aIter->Next() ) {
204 _PTR(SObject) aChildSO = aIter->Value();
206 if ( aChildSO->ReferencedObject( refSO ) && refSO )
208 curve = getCurveByIO( new SALOME_InteractiveObject( aChildSO->GetID().c_str(), "") );
210 aViewFrame->eraseCurve( curve, update );
218 Removes all curves from the view
220 void SPlot2d_Viewer::EraseAll(const bool /*forced*/)
222 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
223 if(aViewFrame) aViewFrame->EraseAll();
227 Redraws Viewer contents
229 void SPlot2d_Viewer::Repaint()
231 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
232 if(aViewFrame) aViewFrame->Repaint();
235 //==========================================================
237 * SPlot2d_Viewer::Display
238 * Display presentation
240 //==========================================================
241 void SPlot2d_Viewer::Display( const SALOME_Prs2d* prs )
243 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
244 Plot2d_Prs* aPrs = dynamic_cast<Plot2d_Prs*>(const_cast<SALOME_Prs2d*>(prs));
245 if(aViewFrame && aPrs) aViewFrame->Display(aPrs);
248 //==========================================================
250 * SPlot2d_Viewer::Erase
253 //==========================================================
254 void SPlot2d_Viewer::Erase( const SALOME_Prs2d* prs, const bool )
256 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
257 Plot2d_Prs* aPrs = dynamic_cast<Plot2d_Prs*>(const_cast<SALOME_Prs2d*>(prs));
258 if(aViewFrame && aPrs) aViewFrame->Erase(aPrs);
261 //==========================================================
263 * SPlot2d_Viewer::CreatePrs
264 * Create presentation by entry
266 //==========================================================
267 SALOME_Prs* SPlot2d_Viewer::CreatePrs( const char* entry )
269 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
272 Plot2d_Prs* prs = aViewFrame->CreatePrs(entry);
274 return new SPlot2d_Prs( prs );
280 //==========================================================
282 * SPlot2d_Viewer::BeforeDisplay
283 * Axiluary method called before displaying of objects
285 //==========================================================
286 void SPlot2d_Viewer::BeforeDisplay( SALOME_Displayer* d )
288 d->BeforeDisplay( this, SALOME_Plot2dViewType() );
291 //==========================================================
293 * SPlot2d_Viewer::AfterDisplay
294 * Axiluary method called after displaying of objects
296 //==========================================================
297 void SPlot2d_Viewer::AfterDisplay( SALOME_Displayer* d )
299 d->AfterDisplay( this, SALOME_Plot2dViewType() );
303 Returns true if interactive object is presented in the viewer and displayed
305 bool SPlot2d_Viewer::isVisible( const Handle(SALOME_InteractiveObject)& IObject )
307 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
308 if(aViewFrame == NULL) return false;
310 SPlot2d_Curve* curve = getCurveByIO( IObject );
311 return aViewFrame->isVisible( curve );
315 Return interactive obeject if is presented in the viewer
317 Handle(SALOME_InteractiveObject) SPlot2d_Viewer::FindIObject( const char* Entry )
319 Handle(SALOME_InteractiveObject) anIO;
320 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
321 if(aViewFrame == NULL) return anIO;
323 QIntDictIterator<Plot2d_Curve> it( aViewFrame->getCurves() );
324 for ( ; it.current(); ++it ) {
325 SPlot2d_Curve* aCurve = dynamic_cast<SPlot2d_Curve*>(it.current());
326 if ( aCurve->hasIO() && !strcmp( aCurve->getIO()->getEntry(), Entry ) ) {
327 anIO = aCurve->getIO();
334 //==========================================================
336 * SPlot2d_Viewer::getActiveViewFrame
337 * Returns an active Plot2d ViewFrame or NULL
339 //==========================================================
340 Plot2d_ViewFrame* SPlot2d_Viewer::getActiveViewFrame()
342 SUIT_ViewManager* aViewMgr = getViewManager();
344 Plot2d_ViewWindow* aViewWnd = dynamic_cast<Plot2d_ViewWindow*>(aViewMgr->getActiveView());
346 return aViewWnd->getViewFrame();
352 SPlot2d_Curve* SPlot2d_Viewer::getCurveByIO( const Handle(SALOME_InteractiveObject)& theIObject,
353 Plot2d_ViewFrame* fr )
355 if ( !theIObject.IsNull() ) {
356 Plot2d_ViewFrame* aViewFrame = fr ? fr : getActiveViewFrame();
358 QIntDictIterator<Plot2d_Curve> it( aViewFrame->getCurves() );
359 for ( ; it.current(); ++it ) {
360 SPlot2d_Curve* aCurve = dynamic_cast<SPlot2d_Curve*>(it.current());
362 if ( aCurve->hasIO() && aCurve->getIO()->isSame( theIObject ) )
371 void SPlot2d_Viewer::onCloneView( Plot2d_ViewFrame* clonedVF, Plot2d_ViewFrame* newVF )
373 if( !clonedVF || !newVF )
376 // 1) Copy all properties of view
378 newVF->copyPreferences( clonedVF );
380 // 2) Display all curves displayed in cloned view
382 QList<Plot2d_Curve> aCurves;
383 clonedVF->getCurves( aCurves );
384 QList<Plot2d_Curve>::const_iterator anIt = aCurves.begin(), aLast = aCurves.end();
386 for( ; anIt!=aLast; anIt++ )
387 if( clonedVF->isVisible( *anIt ) )
388 newVF->displayCurve( *anIt, false );